Completed
Pull Request — master (#1143)
by Darren
11:54
created
admin_pages/registrations/EE_Registrations_List_Table.class.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -227,7 +227,7 @@
 block discarded – undo
227 227
      *    _get_table_filters
228 228
      *
229 229
      * @access protected
230
-     * @return array
230
+     * @return string[]
231 231
      */
232 232
     protected function _get_table_filters()
233 233
     {
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,4 @@
 block discarded – undo
1 1
 <?php use EventEspresso\core\exceptions\EntityNotFoundException;
2
-
3 2
 use EventEspresso\core\exceptions\InvalidDataTypeException;
4 3
 use EventEspresso\core\exceptions\InvalidInterfaceException;
5 4
 
Please login to merge, or discard this patch.
Indentation   +965 added lines, -965 removed lines patch added patch discarded remove patch
@@ -24,1046 +24,1046 @@
 block discarded – undo
24 24
 {
25 25
 
26 26
 
27
-    /**
28
-     * @var array
29
-     */
30
-    private $_status;
27
+	/**
28
+	 * @var array
29
+	 */
30
+	private $_status;
31 31
 
32 32
 
33
-    /**
34
-     * An array of transaction details for the related transaction to the registration being processed.
35
-     * This is set via the _set_related_details method.
36
-     *
37
-     * @var array
38
-     */
39
-    protected $_transaction_details = array();
33
+	/**
34
+	 * An array of transaction details for the related transaction to the registration being processed.
35
+	 * This is set via the _set_related_details method.
36
+	 *
37
+	 * @var array
38
+	 */
39
+	protected $_transaction_details = array();
40 40
 
41 41
 
42
-    /**
43
-     * An array of event details for the related event to the registration being processed.
44
-     * This is set via the _set_related_details method.
45
-     *
46
-     * @var array
47
-     */
48
-    protected $_event_details = array();
42
+	/**
43
+	 * An array of event details for the related event to the registration being processed.
44
+	 * This is set via the _set_related_details method.
45
+	 *
46
+	 * @var array
47
+	 */
48
+	protected $_event_details = array();
49 49
 
50 50
 
51
-    /**
52
-     * @param \Registrations_Admin_Page $admin_page
53
-     */
54
-    public function __construct(Registrations_Admin_Page $admin_page)
55
-    {
56
-        if (! empty($_GET['event_id'])) {
57
-            $extra_query_args = array();
58
-            foreach ($admin_page->get_views() as $key => $view_details) {
59
-                $extra_query_args[ $view_details['slug'] ] = array('event_id' => $_GET['event_id']);
60
-            }
61
-            $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
62
-        }
63
-        parent::__construct($admin_page);
64
-        $this->_status = $this->_admin_page->get_registration_status_array();
65
-    }
51
+	/**
52
+	 * @param \Registrations_Admin_Page $admin_page
53
+	 */
54
+	public function __construct(Registrations_Admin_Page $admin_page)
55
+	{
56
+		if (! empty($_GET['event_id'])) {
57
+			$extra_query_args = array();
58
+			foreach ($admin_page->get_views() as $key => $view_details) {
59
+				$extra_query_args[ $view_details['slug'] ] = array('event_id' => $_GET['event_id']);
60
+			}
61
+			$this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
62
+		}
63
+		parent::__construct($admin_page);
64
+		$this->_status = $this->_admin_page->get_registration_status_array();
65
+	}
66 66
 
67 67
 
68
-    /**
69
-     *    _setup_data
70
-     *
71
-     * @access protected
72
-     * @return void
73
-     */
74
-    protected function _setup_data()
75
-    {
76
-        $this->_data = $this->_admin_page->get_registrations($this->_per_page);
77
-        $this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true, false, false);
78
-    }
68
+	/**
69
+	 *    _setup_data
70
+	 *
71
+	 * @access protected
72
+	 * @return void
73
+	 */
74
+	protected function _setup_data()
75
+	{
76
+		$this->_data = $this->_admin_page->get_registrations($this->_per_page);
77
+		$this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true, false, false);
78
+	}
79 79
 
80 80
 
81
-    /**
82
-     *    _set_properties
83
-     *
84
-     * @access protected
85
-     * @return void
86
-     */
87
-    protected function _set_properties()
88
-    {
89
-        $this->_wp_list_args = array(
90
-            'singular' => __('registration', 'event_espresso'),
91
-            'plural'   => __('registrations', 'event_espresso'),
92
-            'ajax'     => true,
93
-            'screen'   => $this->_admin_page->get_current_screen()->id,
94
-        );
95
-        $ID_column_name = __('ID', 'event_espresso');
96
-        $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">';
97
-        $ID_column_name .= __('Registrant Name', 'event_espresso');
98
-        $ID_column_name .= '</span> ';
99
-        if (isset($_GET['event_id'])) {
100
-            $this->_columns = array(
101
-                'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
102
-                '_REG_ID'          => $ID_column_name,
103
-                'ATT_fname'        => __('Name', 'event_espresso'),
104
-                'ATT_email'        => __('Email', 'event_espresso'),
105
-                '_REG_date'        => __('Reg Date', 'event_espresso'),
106
-                'PRC_amount'       => __('TKT Price', 'event_espresso'),
107
-                '_REG_final_price' => __('Final Price', 'event_espresso'),
108
-                'TXN_total'        => __('Total Txn', 'event_espresso'),
109
-                'TXN_paid'         => __('Paid', 'event_espresso'),
110
-                'actions'          => __('Actions', 'event_espresso'),
111
-            );
112
-            $this->_bottom_buttons = array(
113
-                'report' => array(
114
-                    'route'         => 'registrations_report',
115
-                    'extra_request' => array(
116
-                        'EVT_ID'     => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
117
-                        'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
118
-                    ),
119
-                ),
120
-            );
121
-        } else {
122
-            $this->_columns = array(
123
-                'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
124
-                '_REG_ID'          => $ID_column_name,
125
-                'ATT_fname'        => __('Name', 'event_espresso'),
126
-                '_REG_date'        => __('TXN Date', 'event_espresso'),
127
-                'event_name'       => __('Event', 'event_espresso'),
128
-                'DTT_EVT_start'    => __('Event Date', 'event_espresso'),
129
-                '_REG_final_price' => __('Price', 'event_espresso'),
130
-                '_REG_paid'        => __('Paid', 'event_espresso'),
131
-                'actions'          => __('Actions', 'event_espresso'),
132
-            );
133
-            $this->_bottom_buttons = array(
134
-                'report_all' => array(
135
-                    'route'         => 'registrations_report',
136
-                    'extra_request' => array(
137
-                        'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
138
-                    ),
139
-                ),
140
-            );
141
-        }
142
-        $this->_bottom_buttons['report_filtered'] = array(
143
-            'route'         => 'registrations_report',
144
-            'extra_request' => array(
145
-                'use_filters' => true,
146
-                'return_url'  => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
147
-            ),
148
-        );
149
-        $filters = array_diff_key(
150
-            $this->_req_data,
151
-            array_flip(
152
-                array(
153
-                    'page',
154
-                    'action',
155
-                    'default_nonce',
156
-                )
157
-            )
158
-        );
159
-        if (!empty($filters)) {
160
-            $this->_bottom_buttons['report_filtered']['extra_request']['filters'] = $filters;
161
-        }
162
-        $this->_primary_column = '_REG_ID';
163
-        $this->_sortable_columns = array(
164
-            '_REG_date'     => array('_REG_date' => true),   // true means its already sorted
165
-            /**
166
-             * Allows users to change the default sort if they wish.
167
-             * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
168
-             * name.
169
-             */
170
-            'ATT_fname'     => array(
171
-                'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
172
-                true,
173
-                $this,
174
-            )
175
-                ? array('ATT_lname' => false)
176
-                : array('ATT_fname' => false),
177
-            'event_name'    => array('event_name' => false),
178
-            'DTT_EVT_start' => array('DTT_EVT_start' => false),
179
-            '_REG_ID'       => array('_REG_ID' => false),
180
-        );
181
-        $this->_hidden_columns = array();
182
-    }
81
+	/**
82
+	 *    _set_properties
83
+	 *
84
+	 * @access protected
85
+	 * @return void
86
+	 */
87
+	protected function _set_properties()
88
+	{
89
+		$this->_wp_list_args = array(
90
+			'singular' => __('registration', 'event_espresso'),
91
+			'plural'   => __('registrations', 'event_espresso'),
92
+			'ajax'     => true,
93
+			'screen'   => $this->_admin_page->get_current_screen()->id,
94
+		);
95
+		$ID_column_name = __('ID', 'event_espresso');
96
+		$ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">';
97
+		$ID_column_name .= __('Registrant Name', 'event_espresso');
98
+		$ID_column_name .= '</span> ';
99
+		if (isset($_GET['event_id'])) {
100
+			$this->_columns = array(
101
+				'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
102
+				'_REG_ID'          => $ID_column_name,
103
+				'ATT_fname'        => __('Name', 'event_espresso'),
104
+				'ATT_email'        => __('Email', 'event_espresso'),
105
+				'_REG_date'        => __('Reg Date', 'event_espresso'),
106
+				'PRC_amount'       => __('TKT Price', 'event_espresso'),
107
+				'_REG_final_price' => __('Final Price', 'event_espresso'),
108
+				'TXN_total'        => __('Total Txn', 'event_espresso'),
109
+				'TXN_paid'         => __('Paid', 'event_espresso'),
110
+				'actions'          => __('Actions', 'event_espresso'),
111
+			);
112
+			$this->_bottom_buttons = array(
113
+				'report' => array(
114
+					'route'         => 'registrations_report',
115
+					'extra_request' => array(
116
+						'EVT_ID'     => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
117
+						'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
118
+					),
119
+				),
120
+			);
121
+		} else {
122
+			$this->_columns = array(
123
+				'cb'               => '<input type="checkbox" />', // Render a checkbox instead of text
124
+				'_REG_ID'          => $ID_column_name,
125
+				'ATT_fname'        => __('Name', 'event_espresso'),
126
+				'_REG_date'        => __('TXN Date', 'event_espresso'),
127
+				'event_name'       => __('Event', 'event_espresso'),
128
+				'DTT_EVT_start'    => __('Event Date', 'event_espresso'),
129
+				'_REG_final_price' => __('Price', 'event_espresso'),
130
+				'_REG_paid'        => __('Paid', 'event_espresso'),
131
+				'actions'          => __('Actions', 'event_espresso'),
132
+			);
133
+			$this->_bottom_buttons = array(
134
+				'report_all' => array(
135
+					'route'         => 'registrations_report',
136
+					'extra_request' => array(
137
+						'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
138
+					),
139
+				),
140
+			);
141
+		}
142
+		$this->_bottom_buttons['report_filtered'] = array(
143
+			'route'         => 'registrations_report',
144
+			'extra_request' => array(
145
+				'use_filters' => true,
146
+				'return_url'  => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
147
+			),
148
+		);
149
+		$filters = array_diff_key(
150
+			$this->_req_data,
151
+			array_flip(
152
+				array(
153
+					'page',
154
+					'action',
155
+					'default_nonce',
156
+				)
157
+			)
158
+		);
159
+		if (!empty($filters)) {
160
+			$this->_bottom_buttons['report_filtered']['extra_request']['filters'] = $filters;
161
+		}
162
+		$this->_primary_column = '_REG_ID';
163
+		$this->_sortable_columns = array(
164
+			'_REG_date'     => array('_REG_date' => true),   // true means its already sorted
165
+			/**
166
+			 * Allows users to change the default sort if they wish.
167
+			 * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
168
+			 * name.
169
+			 */
170
+			'ATT_fname'     => array(
171
+				'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
172
+				true,
173
+				$this,
174
+			)
175
+				? array('ATT_lname' => false)
176
+				: array('ATT_fname' => false),
177
+			'event_name'    => array('event_name' => false),
178
+			'DTT_EVT_start' => array('DTT_EVT_start' => false),
179
+			'_REG_ID'       => array('_REG_ID' => false),
180
+		);
181
+		$this->_hidden_columns = array();
182
+	}
183 183
 
184 184
 
185
-    /**
186
-     * This simply sets up the row class for the table rows.
187
-     * Allows for easier overriding of child methods for setting up sorting.
188
-     *
189
-     * @param  EE_Registration $item the current item
190
-     * @return string
191
-     */
192
-    protected function _get_row_class($item)
193
-    {
194
-        $class = parent::_get_row_class($item);
195
-        // add status class
196
-        $class .= ' ee-status-strip reg-status-' . $item->status_ID();
197
-        if ($this->_has_checkbox_column) {
198
-            $class .= ' has-checkbox-column';
199
-        }
200
-        return $class;
201
-    }
185
+	/**
186
+	 * This simply sets up the row class for the table rows.
187
+	 * Allows for easier overriding of child methods for setting up sorting.
188
+	 *
189
+	 * @param  EE_Registration $item the current item
190
+	 * @return string
191
+	 */
192
+	protected function _get_row_class($item)
193
+	{
194
+		$class = parent::_get_row_class($item);
195
+		// add status class
196
+		$class .= ' ee-status-strip reg-status-' . $item->status_ID();
197
+		if ($this->_has_checkbox_column) {
198
+			$class .= ' has-checkbox-column';
199
+		}
200
+		return $class;
201
+	}
202 202
 
203 203
 
204
-    /**
205
-     * Set the $_transaction_details property if not set yet.
206
-     *
207
-     * @param EE_Registration $registration
208
-     * @throws EE_Error
209
-     * @throws InvalidArgumentException
210
-     * @throws ReflectionException
211
-     * @throws InvalidDataTypeException
212
-     * @throws InvalidInterfaceException
213
-     */
214
-    protected function _set_related_details(EE_Registration $registration)
215
-    {
216
-        $transaction = $registration->get_first_related('Transaction');
217
-        $status = $transaction instanceof EE_Transaction ? $transaction->status_ID()
218
-            : EEM_Transaction::failed_status_code;
219
-        $this->_transaction_details = array(
220
-            'transaction' => $transaction,
221
-            'status'      => $status,
222
-            'id'          => $transaction instanceof EE_Transaction ? $transaction->ID() : 0,
223
-            'title_attr'  => sprintf(
224
-                __('View Transaction Details (%s)', 'event_espresso'),
225
-                EEH_Template::pretty_status($status, false, 'sentence')
226
-            ),
227
-        );
228
-        try {
229
-            $event = $registration->event();
230
-        } catch (EntityNotFoundException $e) {
231
-            $event = null;
232
-        }
233
-        $status = $event instanceof EE_Event ? $event->get_active_status() : EE_Datetime::inactive;
234
-        $this->_event_details = array(
235
-            'event'      => $event,
236
-            'status'     => $status,
237
-            'id'         => $event instanceof EE_Event ? $event->ID() : 0,
238
-            'title_attr' => sprintf(
239
-                __('Edit Event (%s)', 'event_espresso'),
240
-                EEH_Template::pretty_status($status, false, 'sentence')
241
-            ),
242
-        );
243
-    }
204
+	/**
205
+	 * Set the $_transaction_details property if not set yet.
206
+	 *
207
+	 * @param EE_Registration $registration
208
+	 * @throws EE_Error
209
+	 * @throws InvalidArgumentException
210
+	 * @throws ReflectionException
211
+	 * @throws InvalidDataTypeException
212
+	 * @throws InvalidInterfaceException
213
+	 */
214
+	protected function _set_related_details(EE_Registration $registration)
215
+	{
216
+		$transaction = $registration->get_first_related('Transaction');
217
+		$status = $transaction instanceof EE_Transaction ? $transaction->status_ID()
218
+			: EEM_Transaction::failed_status_code;
219
+		$this->_transaction_details = array(
220
+			'transaction' => $transaction,
221
+			'status'      => $status,
222
+			'id'          => $transaction instanceof EE_Transaction ? $transaction->ID() : 0,
223
+			'title_attr'  => sprintf(
224
+				__('View Transaction Details (%s)', 'event_espresso'),
225
+				EEH_Template::pretty_status($status, false, 'sentence')
226
+			),
227
+		);
228
+		try {
229
+			$event = $registration->event();
230
+		} catch (EntityNotFoundException $e) {
231
+			$event = null;
232
+		}
233
+		$status = $event instanceof EE_Event ? $event->get_active_status() : EE_Datetime::inactive;
234
+		$this->_event_details = array(
235
+			'event'      => $event,
236
+			'status'     => $status,
237
+			'id'         => $event instanceof EE_Event ? $event->ID() : 0,
238
+			'title_attr' => sprintf(
239
+				__('Edit Event (%s)', 'event_espresso'),
240
+				EEH_Template::pretty_status($status, false, 'sentence')
241
+			),
242
+		);
243
+	}
244 244
 
245 245
 
246
-    /**
247
-     *    _get_table_filters
248
-     *
249
-     * @access protected
250
-     * @return array
251
-     */
252
-    protected function _get_table_filters()
253
-    {
254
-        $filters = array();
255
-        // todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as
256
-        // methods.
257
-        $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
258
-        $cur_category = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
259
-        $reg_status = isset($this->_req_data['_reg_status']) ? $this->_req_data['_reg_status'] : '';
260
-        $filters[] = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category);
261
-        $filters[] = EEH_Form_Fields::generate_event_category_dropdown($cur_category);
262
-        $status = array();
263
-        $status[] = array('id' => 0, 'text' => __('Select Status', 'event_espresso'));
264
-        foreach ($this->_status as $key => $value) {
265
-            $status[] = array('id' => $key, 'text' => $value);
266
-        }
267
-        if ($this->_view !== 'incomplete') {
268
-            $filters[] = EEH_Form_Fields::select_input(
269
-                '_reg_status',
270
-                $status,
271
-                isset($this->_req_data['_reg_status']) ? strtoupper(sanitize_key($this->_req_data['_reg_status']))
272
-                    : ''
273
-            );
274
-        }
275
-        if (isset($this->_req_data['event_id'])) {
276
-            $filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id');
277
-        }
278
-        return $filters;
279
-    }
246
+	/**
247
+	 *    _get_table_filters
248
+	 *
249
+	 * @access protected
250
+	 * @return array
251
+	 */
252
+	protected function _get_table_filters()
253
+	{
254
+		$filters = array();
255
+		// todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as
256
+		// methods.
257
+		$cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
258
+		$cur_category = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
259
+		$reg_status = isset($this->_req_data['_reg_status']) ? $this->_req_data['_reg_status'] : '';
260
+		$filters[] = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category);
261
+		$filters[] = EEH_Form_Fields::generate_event_category_dropdown($cur_category);
262
+		$status = array();
263
+		$status[] = array('id' => 0, 'text' => __('Select Status', 'event_espresso'));
264
+		foreach ($this->_status as $key => $value) {
265
+			$status[] = array('id' => $key, 'text' => $value);
266
+		}
267
+		if ($this->_view !== 'incomplete') {
268
+			$filters[] = EEH_Form_Fields::select_input(
269
+				'_reg_status',
270
+				$status,
271
+				isset($this->_req_data['_reg_status']) ? strtoupper(sanitize_key($this->_req_data['_reg_status']))
272
+					: ''
273
+			);
274
+		}
275
+		if (isset($this->_req_data['event_id'])) {
276
+			$filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id');
277
+		}
278
+		return $filters;
279
+	}
280 280
 
281 281
 
282
-    /**
283
-     *    _add_view_counts
284
-     *
285
-     * @access protected
286
-     * @return void
287
-     * @throws EE_Error
288
-     * @throws InvalidArgumentException
289
-     * @throws InvalidDataTypeException
290
-     * @throws InvalidInterfaceException
291
-     */
292
-    protected function _add_view_counts()
293
-    {
294
-        $this->_views['all']['count'] = $this->_total_registrations();
295
-        $this->_views['month']['count'] = $this->_total_registrations_this_month();
296
-        $this->_views['today']['count'] = $this->_total_registrations_today();
297
-        if (EE_Registry::instance()->CAP->current_user_can(
298
-            'ee_delete_registrations',
299
-            'espresso_registrations_trash_registrations'
300
-        )) {
301
-            $this->_views['incomplete']['count'] = $this->_total_registrations('incomplete');
302
-            $this->_views['trash']['count'] = $this->_total_registrations('trash');
303
-        }
304
-    }
282
+	/**
283
+	 *    _add_view_counts
284
+	 *
285
+	 * @access protected
286
+	 * @return void
287
+	 * @throws EE_Error
288
+	 * @throws InvalidArgumentException
289
+	 * @throws InvalidDataTypeException
290
+	 * @throws InvalidInterfaceException
291
+	 */
292
+	protected function _add_view_counts()
293
+	{
294
+		$this->_views['all']['count'] = $this->_total_registrations();
295
+		$this->_views['month']['count'] = $this->_total_registrations_this_month();
296
+		$this->_views['today']['count'] = $this->_total_registrations_today();
297
+		if (EE_Registry::instance()->CAP->current_user_can(
298
+			'ee_delete_registrations',
299
+			'espresso_registrations_trash_registrations'
300
+		)) {
301
+			$this->_views['incomplete']['count'] = $this->_total_registrations('incomplete');
302
+			$this->_views['trash']['count'] = $this->_total_registrations('trash');
303
+		}
304
+	}
305 305
 
306 306
 
307
-    /**
308
-     * _total_registrations
309
-     *
310
-     * @access protected
311
-     * @param string $view
312
-     * @return int
313
-     * @throws EE_Error
314
-     * @throws InvalidArgumentException
315
-     * @throws InvalidDataTypeException
316
-     * @throws InvalidInterfaceException
317
-     */
318
-    protected function _total_registrations($view = '')
319
-    {
320
-        $_where = array();
321
-        $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
322
-        if ($EVT_ID) {
323
-            $_where['EVT_ID'] = $EVT_ID;
324
-        }
325
-        switch ($view) {
326
-            case 'trash':
327
-                return EEM_Registration::instance()->count_deleted(array($_where));
328
-                break;
329
-            case 'incomplete':
330
-                $_where['STS_ID'] = EEM_Registration::status_id_incomplete;
331
-                break;
332
-            default:
333
-                $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
334
-        }
335
-        return EEM_Registration::instance()->count(array($_where));
336
-    }
307
+	/**
308
+	 * _total_registrations
309
+	 *
310
+	 * @access protected
311
+	 * @param string $view
312
+	 * @return int
313
+	 * @throws EE_Error
314
+	 * @throws InvalidArgumentException
315
+	 * @throws InvalidDataTypeException
316
+	 * @throws InvalidInterfaceException
317
+	 */
318
+	protected function _total_registrations($view = '')
319
+	{
320
+		$_where = array();
321
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
322
+		if ($EVT_ID) {
323
+			$_where['EVT_ID'] = $EVT_ID;
324
+		}
325
+		switch ($view) {
326
+			case 'trash':
327
+				return EEM_Registration::instance()->count_deleted(array($_where));
328
+				break;
329
+			case 'incomplete':
330
+				$_where['STS_ID'] = EEM_Registration::status_id_incomplete;
331
+				break;
332
+			default:
333
+				$_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
334
+		}
335
+		return EEM_Registration::instance()->count(array($_where));
336
+	}
337 337
 
338 338
 
339
-    /**
340
-     * _total_registrations_this_month
341
-     *
342
-     * @access protected
343
-     * @return int
344
-     * @throws EE_Error
345
-     * @throws InvalidArgumentException
346
-     * @throws InvalidDataTypeException
347
-     * @throws InvalidInterfaceException
348
-     */
349
-    protected function _total_registrations_this_month()
350
-    {
351
-        $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
352
-        $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
353
-        $this_year_r = date('Y', current_time('timestamp'));
354
-        $time_start = ' 00:00:00';
355
-        $time_end = ' 23:59:59';
356
-        $this_month_r = date('m', current_time('timestamp'));
357
-        $days_this_month = date('t', current_time('timestamp'));
358
-        // setup date query.
359
-        $beginning_string = EEM_Registration::instance()->convert_datetime_for_query(
360
-            'REG_date',
361
-            $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
362
-            'Y-m-d H:i:s'
363
-        );
364
-        $end_string = EEM_Registration::instance()->convert_datetime_for_query(
365
-            'REG_date',
366
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
367
-            'Y-m-d H:i:s'
368
-        );
369
-        $_where['REG_date'] = array(
370
-            'BETWEEN',
371
-            array(
372
-                $beginning_string,
373
-                $end_string,
374
-            ),
375
-        );
376
-        $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
377
-        return EEM_Registration::instance()->count(array($_where));
378
-    }
339
+	/**
340
+	 * _total_registrations_this_month
341
+	 *
342
+	 * @access protected
343
+	 * @return int
344
+	 * @throws EE_Error
345
+	 * @throws InvalidArgumentException
346
+	 * @throws InvalidDataTypeException
347
+	 * @throws InvalidInterfaceException
348
+	 */
349
+	protected function _total_registrations_this_month()
350
+	{
351
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
352
+		$_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
353
+		$this_year_r = date('Y', current_time('timestamp'));
354
+		$time_start = ' 00:00:00';
355
+		$time_end = ' 23:59:59';
356
+		$this_month_r = date('m', current_time('timestamp'));
357
+		$days_this_month = date('t', current_time('timestamp'));
358
+		// setup date query.
359
+		$beginning_string = EEM_Registration::instance()->convert_datetime_for_query(
360
+			'REG_date',
361
+			$this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
362
+			'Y-m-d H:i:s'
363
+		);
364
+		$end_string = EEM_Registration::instance()->convert_datetime_for_query(
365
+			'REG_date',
366
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
367
+			'Y-m-d H:i:s'
368
+		);
369
+		$_where['REG_date'] = array(
370
+			'BETWEEN',
371
+			array(
372
+				$beginning_string,
373
+				$end_string,
374
+			),
375
+		);
376
+		$_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
377
+		return EEM_Registration::instance()->count(array($_where));
378
+	}
379 379
 
380 380
 
381
-    /**
382
-     * _total_registrations_today
383
-     *
384
-     * @access protected
385
-     * @return int
386
-     * @throws EE_Error
387
-     * @throws InvalidArgumentException
388
-     * @throws InvalidDataTypeException
389
-     * @throws InvalidInterfaceException
390
-     */
391
-    protected function _total_registrations_today()
392
-    {
393
-        $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
394
-        $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
395
-        $current_date = date('Y-m-d', current_time('timestamp'));
396
-        $time_start = ' 00:00:00';
397
-        $time_end = ' 23:59:59';
398
-        $_where['REG_date'] = array(
399
-            'BETWEEN',
400
-            array(
401
-                EEM_Registration::instance()->convert_datetime_for_query(
402
-                    'REG_date',
403
-                    $current_date . $time_start,
404
-                    'Y-m-d H:i:s'
405
-                ),
406
-                EEM_Registration::instance()->convert_datetime_for_query(
407
-                    'REG_date',
408
-                    $current_date . $time_end,
409
-                    'Y-m-d H:i:s'
410
-                ),
411
-            ),
412
-        );
413
-        $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
414
-        return EEM_Registration::instance()->count(array($_where));
415
-    }
381
+	/**
382
+	 * _total_registrations_today
383
+	 *
384
+	 * @access protected
385
+	 * @return int
386
+	 * @throws EE_Error
387
+	 * @throws InvalidArgumentException
388
+	 * @throws InvalidDataTypeException
389
+	 * @throws InvalidInterfaceException
390
+	 */
391
+	protected function _total_registrations_today()
392
+	{
393
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
394
+		$_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array();
395
+		$current_date = date('Y-m-d', current_time('timestamp'));
396
+		$time_start = ' 00:00:00';
397
+		$time_end = ' 23:59:59';
398
+		$_where['REG_date'] = array(
399
+			'BETWEEN',
400
+			array(
401
+				EEM_Registration::instance()->convert_datetime_for_query(
402
+					'REG_date',
403
+					$current_date . $time_start,
404
+					'Y-m-d H:i:s'
405
+				),
406
+				EEM_Registration::instance()->convert_datetime_for_query(
407
+					'REG_date',
408
+					$current_date . $time_end,
409
+					'Y-m-d H:i:s'
410
+				),
411
+			),
412
+		);
413
+		$_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
414
+		return EEM_Registration::instance()->count(array($_where));
415
+	}
416 416
 
417 417
 
418
-    /**
419
-     * column_cb
420
-     *
421
-     * @access public
422
-     * @param \EE_Registration $item
423
-     * @return string
424
-     * @throws EE_Error
425
-     * @throws InvalidArgumentException
426
-     * @throws InvalidDataTypeException
427
-     * @throws InvalidInterfaceException
428
-     * @throws ReflectionException
429
-     */
430
-    public function column_cb($item)
431
-    {
432
-        /** checkbox/lock **/
433
-        $transaction = $item->get_first_related('Transaction');
434
-        $payment_count = $transaction instanceof EE_Transaction
435
-            ? $transaction->count_related('Payment')
436
-            : 0;
437
-        return $payment_count > 0
438
-               || ! EE_Registry::instance()->CAP->current_user_can(
439
-                   'ee_edit_registration',
440
-                   'registration_list_table_checkbox_input',
441
-                   $item->ID()
442
-               )
443
-            ? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID())
444
-              . '<span class="ee-lock-icon"></span>'
445
-            : sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID());
446
-    }
418
+	/**
419
+	 * column_cb
420
+	 *
421
+	 * @access public
422
+	 * @param \EE_Registration $item
423
+	 * @return string
424
+	 * @throws EE_Error
425
+	 * @throws InvalidArgumentException
426
+	 * @throws InvalidDataTypeException
427
+	 * @throws InvalidInterfaceException
428
+	 * @throws ReflectionException
429
+	 */
430
+	public function column_cb($item)
431
+	{
432
+		/** checkbox/lock **/
433
+		$transaction = $item->get_first_related('Transaction');
434
+		$payment_count = $transaction instanceof EE_Transaction
435
+			? $transaction->count_related('Payment')
436
+			: 0;
437
+		return $payment_count > 0
438
+			   || ! EE_Registry::instance()->CAP->current_user_can(
439
+				   'ee_edit_registration',
440
+				   'registration_list_table_checkbox_input',
441
+				   $item->ID()
442
+			   )
443
+			? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID())
444
+			  . '<span class="ee-lock-icon"></span>'
445
+			: sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID());
446
+	}
447 447
 
448 448
 
449
-    /**
450
-     * column__REG_ID
451
-     *
452
-     * @access public
453
-     * @param \EE_Registration $item
454
-     * @return string
455
-     * @throws EE_Error
456
-     * @throws InvalidArgumentException
457
-     * @throws InvalidDataTypeException
458
-     * @throws InvalidInterfaceException
459
-     * @throws ReflectionException
460
-     */
461
-    public function column__REG_ID(EE_Registration $item)
462
-    {
463
-        $attendee = $item->attendee();
464
-        $content = $item->ID();
465
-        $content .= '<div class="show-on-mobile-view-only">';
466
-        $content .= '<br>';
467
-        $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
468
-        $content .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
469
-        $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
470
-        $content .= '</div>';
471
-        return $content;
472
-    }
449
+	/**
450
+	 * column__REG_ID
451
+	 *
452
+	 * @access public
453
+	 * @param \EE_Registration $item
454
+	 * @return string
455
+	 * @throws EE_Error
456
+	 * @throws InvalidArgumentException
457
+	 * @throws InvalidDataTypeException
458
+	 * @throws InvalidInterfaceException
459
+	 * @throws ReflectionException
460
+	 */
461
+	public function column__REG_ID(EE_Registration $item)
462
+	{
463
+		$attendee = $item->attendee();
464
+		$content = $item->ID();
465
+		$content .= '<div class="show-on-mobile-view-only">';
466
+		$content .= '<br>';
467
+		$content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
468
+		$content .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
469
+		$content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
470
+		$content .= '</div>';
471
+		return $content;
472
+	}
473 473
 
474 474
 
475
-    /**
476
-     * column__REG_date
477
-     *
478
-     * @access public
479
-     * @param \EE_Registration $item
480
-     * @return string
481
-     * @throws EE_Error
482
-     * @throws InvalidArgumentException
483
-     * @throws InvalidDataTypeException
484
-     * @throws InvalidInterfaceException
485
-     * @throws ReflectionException
486
-     */
487
-    public function column__REG_date(EE_Registration $item)
488
-    {
489
-        $this->_set_related_details($item);
490
-        // Build row actions
491
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
492
-            array(
493
-                'action' => 'view_transaction',
494
-                'TXN_ID' => $this->_transaction_details['id'],
495
-            ),
496
-            TXN_ADMIN_URL
497
-        );
498
-        $view_link = EE_Registry::instance()->CAP->current_user_can(
499
-            'ee_read_transaction',
500
-            'espresso_transactions_view_transaction'
501
-        )
502
-            ? '<a class="ee-status-color-'
503
-              . $this->_transaction_details['status']
504
-              . '" href="'
505
-              . $view_lnk_url
506
-              . '" title="'
507
-              . esc_attr($this->_transaction_details['title_attr'])
508
-              . '">'
509
-              . $item->get_i18n_datetime('REG_date')
510
-              . '</a>' : $item->get_i18n_datetime('REG_date');
511
-        $view_link .= '<br><span class="ee-status-text-small">'
512
-                      . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence')
513
-                      . '</span>';
514
-        return $view_link;
515
-    }
475
+	/**
476
+	 * column__REG_date
477
+	 *
478
+	 * @access public
479
+	 * @param \EE_Registration $item
480
+	 * @return string
481
+	 * @throws EE_Error
482
+	 * @throws InvalidArgumentException
483
+	 * @throws InvalidDataTypeException
484
+	 * @throws InvalidInterfaceException
485
+	 * @throws ReflectionException
486
+	 */
487
+	public function column__REG_date(EE_Registration $item)
488
+	{
489
+		$this->_set_related_details($item);
490
+		// Build row actions
491
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
492
+			array(
493
+				'action' => 'view_transaction',
494
+				'TXN_ID' => $this->_transaction_details['id'],
495
+			),
496
+			TXN_ADMIN_URL
497
+		);
498
+		$view_link = EE_Registry::instance()->CAP->current_user_can(
499
+			'ee_read_transaction',
500
+			'espresso_transactions_view_transaction'
501
+		)
502
+			? '<a class="ee-status-color-'
503
+			  . $this->_transaction_details['status']
504
+			  . '" href="'
505
+			  . $view_lnk_url
506
+			  . '" title="'
507
+			  . esc_attr($this->_transaction_details['title_attr'])
508
+			  . '">'
509
+			  . $item->get_i18n_datetime('REG_date')
510
+			  . '</a>' : $item->get_i18n_datetime('REG_date');
511
+		$view_link .= '<br><span class="ee-status-text-small">'
512
+					  . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence')
513
+					  . '</span>';
514
+		return $view_link;
515
+	}
516 516
 
517 517
 
518
-    /**
519
-     * column_event_name
520
-     *
521
-     * @access public
522
-     * @param \EE_Registration $item
523
-     * @return string
524
-     * @throws EE_Error
525
-     * @throws InvalidArgumentException
526
-     * @throws InvalidDataTypeException
527
-     * @throws InvalidInterfaceException
528
-     * @throws ReflectionException
529
-     */
530
-    public function column_event_name(EE_Registration $item)
531
-    {
532
-        $this->_set_related_details($item);
533
-        // page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62
534
-        $EVT_ID = $item->event_ID();
535
-        $event_name = $item->event_name();
536
-        $event_name = $event_name ? $event_name : __("No Associated Event", 'event_espresso');
537
-        $event_name = wp_trim_words($event_name, 30, '...');
538
-        if ($EVT_ID) {
539
-            $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
540
-                array('action' => 'edit', 'post' => $EVT_ID),
541
-                EVENTS_ADMIN_URL
542
-            );
543
-            $edit_event = EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID)
544
-                ? '<a class="ee-status-color-'
545
-                  . $this->_event_details['status']
546
-                  . '" href="'
547
-                  . $edit_event_url
548
-                  . '" title="'
549
-                  . esc_attr($this->_event_details['title_attr'])
550
-                  . '">'
551
-                  . $event_name
552
-                  . '</a>' : $event_name;
553
-            $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL);
554
-            $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="';
555
-            $actions['event_filter'] .= sprintf(
556
-                esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
557
-                $event_name
558
-            );
559
-            $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>';
560
-        } else {
561
-            $edit_event = $event_name;
562
-            $actions['event_filter'] = '';
563
-        }
564
-        return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions));
565
-    }
518
+	/**
519
+	 * column_event_name
520
+	 *
521
+	 * @access public
522
+	 * @param \EE_Registration $item
523
+	 * @return string
524
+	 * @throws EE_Error
525
+	 * @throws InvalidArgumentException
526
+	 * @throws InvalidDataTypeException
527
+	 * @throws InvalidInterfaceException
528
+	 * @throws ReflectionException
529
+	 */
530
+	public function column_event_name(EE_Registration $item)
531
+	{
532
+		$this->_set_related_details($item);
533
+		// page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62
534
+		$EVT_ID = $item->event_ID();
535
+		$event_name = $item->event_name();
536
+		$event_name = $event_name ? $event_name : __("No Associated Event", 'event_espresso');
537
+		$event_name = wp_trim_words($event_name, 30, '...');
538
+		if ($EVT_ID) {
539
+			$edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
540
+				array('action' => 'edit', 'post' => $EVT_ID),
541
+				EVENTS_ADMIN_URL
542
+			);
543
+			$edit_event = EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID)
544
+				? '<a class="ee-status-color-'
545
+				  . $this->_event_details['status']
546
+				  . '" href="'
547
+				  . $edit_event_url
548
+				  . '" title="'
549
+				  . esc_attr($this->_event_details['title_attr'])
550
+				  . '">'
551
+				  . $event_name
552
+				  . '</a>' : $event_name;
553
+			$edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL);
554
+			$actions['event_filter'] = '<a href="' . $edit_event_url . '" title="';
555
+			$actions['event_filter'] .= sprintf(
556
+				esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
557
+				$event_name
558
+			);
559
+			$actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>';
560
+		} else {
561
+			$edit_event = $event_name;
562
+			$actions['event_filter'] = '';
563
+		}
564
+		return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions));
565
+	}
566 566
 
567 567
 
568
-    /**
569
-     * column_DTT_EVT_start
570
-     *
571
-     * @access public
572
-     * @param \EE_Registration $item
573
-     * @return string
574
-     * @throws EE_Error
575
-     * @throws InvalidArgumentException
576
-     * @throws InvalidDataTypeException
577
-     * @throws InvalidInterfaceException
578
-     * @throws ReflectionException
579
-     */
580
-    public function column_DTT_EVT_start(EE_Registration $item)
581
-    {
582
-        $datetime_strings = array();
583
-        $ticket = $item->ticket(true);
584
-        if ($ticket instanceof EE_Ticket) {
585
-            $remove_defaults = array('default_where_conditions' => 'none');
586
-            $datetimes = $ticket->datetimes($remove_defaults);
587
-            foreach ($datetimes as $datetime) {
588
-                $datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start');
589
-            }
590
-            return $this->generateDisplayForDatetimes($datetime_strings);
591
-        }
592
-        return __('There is no ticket on this registration', 'event_espresso');
593
-    }
568
+	/**
569
+	 * column_DTT_EVT_start
570
+	 *
571
+	 * @access public
572
+	 * @param \EE_Registration $item
573
+	 * @return string
574
+	 * @throws EE_Error
575
+	 * @throws InvalidArgumentException
576
+	 * @throws InvalidDataTypeException
577
+	 * @throws InvalidInterfaceException
578
+	 * @throws ReflectionException
579
+	 */
580
+	public function column_DTT_EVT_start(EE_Registration $item)
581
+	{
582
+		$datetime_strings = array();
583
+		$ticket = $item->ticket(true);
584
+		if ($ticket instanceof EE_Ticket) {
585
+			$remove_defaults = array('default_where_conditions' => 'none');
586
+			$datetimes = $ticket->datetimes($remove_defaults);
587
+			foreach ($datetimes as $datetime) {
588
+				$datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start');
589
+			}
590
+			return $this->generateDisplayForDatetimes($datetime_strings);
591
+		}
592
+		return __('There is no ticket on this registration', 'event_espresso');
593
+	}
594 594
 
595 595
 
596
-    /**
597
-     * Receives an array of datetime strings to display and converts them to the html container for the column.
598
-     *
599
-     * @param array $datetime_strings
600
-     * @return string
601
-     */
602
-    public function generateDisplayForDateTimes(array $datetime_strings)
603
-    {
604
-        $content = '<div class="ee-registration-event-datetimes-container">';
605
-        $expand_toggle = count($datetime_strings) > 1
606
-            ? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso')
607
-              . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>'
608
-            : '';
609
-        // get first item for initial visibility
610
-        $content .= '<div class="left">' . array_shift($datetime_strings) . '</div>';
611
-        $content .= $expand_toggle;
612
-        if ($datetime_strings) {
613
-            $content .= '<div style="clear:both"></div>';
614
-            $content .= '<div class="ee-registration-event-datetimes-container more-items hidden">';
615
-            $content .= implode("<br />", $datetime_strings);
616
-            $content .= '</div>';
617
-        }
618
-        $content .= '</div>';
619
-        return $content;
620
-    }
596
+	/**
597
+	 * Receives an array of datetime strings to display and converts them to the html container for the column.
598
+	 *
599
+	 * @param array $datetime_strings
600
+	 * @return string
601
+	 */
602
+	public function generateDisplayForDateTimes(array $datetime_strings)
603
+	{
604
+		$content = '<div class="ee-registration-event-datetimes-container">';
605
+		$expand_toggle = count($datetime_strings) > 1
606
+			? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso')
607
+			  . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>'
608
+			: '';
609
+		// get first item for initial visibility
610
+		$content .= '<div class="left">' . array_shift($datetime_strings) . '</div>';
611
+		$content .= $expand_toggle;
612
+		if ($datetime_strings) {
613
+			$content .= '<div style="clear:both"></div>';
614
+			$content .= '<div class="ee-registration-event-datetimes-container more-items hidden">';
615
+			$content .= implode("<br />", $datetime_strings);
616
+			$content .= '</div>';
617
+		}
618
+		$content .= '</div>';
619
+		return $content;
620
+	}
621 621
 
622 622
 
623
-    /**
624
-     * column_ATT_fname
625
-     *
626
-     * @access public
627
-     * @param \EE_Registration $item
628
-     * @return string
629
-     * @throws EE_Error
630
-     * @throws InvalidArgumentException
631
-     * @throws InvalidDataTypeException
632
-     * @throws InvalidInterfaceException
633
-     * @throws ReflectionException
634
-     */
635
-    public function column_ATT_fname(EE_Registration $item)
636
-    {
637
-        $attendee = $item->attendee();
638
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
639
-            array(
640
-                'action'  => 'view_registration',
641
-                '_REG_ID' => $item->ID(),
642
-            ),
643
-            REG_ADMIN_URL
644
-        );
645
-        $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
646
-        $link = EE_Registry::instance()->CAP->current_user_can(
647
-            'ee_read_registration',
648
-            'espresso_registrations_view_registration',
649
-            $item->ID()
650
-        )
651
-            ? '<a href="'
652
-              . $edit_lnk_url
653
-              . '" title="'
654
-              . esc_attr__('View Registration Details', 'event_espresso')
655
-              . '">'
656
-              . $attendee_name
657
-              . '</a>' : $attendee_name;
658
-        $link .= $item->count() === 1
659
-            ? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>' : '';
660
-        $t = $item->get_first_related('Transaction');
661
-        $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0;
662
-        // append group count to name
663
-        $link .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
664
-        // append reg_code
665
-        $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
666
-        // reg status text for accessibility
667
-        $link .= '<br><span class="ee-status-text-small">'
668
-                 . EEH_Template::pretty_status($item->status_ID(), false, 'sentence')
669
-                 . '</span>';
670
-        $action = [ '_REG_ID' => $item->ID() ];
671
-        if (isset($this->_req_data['event_id'])) {
672
-            $action['event_id'] = $item->event_ID();
673
-        }
674
-        // trash/restore/delete actions
675
-        $actions = array();
676
-        if ($this->_view !== 'trash'
677
-            && $payment_count === 0
678
-            && EE_Registry::instance()->CAP->current_user_can(
679
-                'ee_delete_registration',
680
-                'espresso_registrations_trash_registrations',
681
-                $item->ID()
682
-            )) {
683
-            $action['action'] = 'trash_registrations';
684
-            $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
685
-                $action,
686
-                REG_ADMIN_URL
687
-            );
688
-            $actions['trash'] = '<a href="'
689
-                                . $trash_lnk_url
690
-                                . '" title="'
691
-                                . esc_attr__('Trash Registration', 'event_espresso')
692
-                                . '">' . __('Trash', 'event_espresso') . '</a>';
693
-        } elseif ($this->_view === 'trash') {
694
-            // restore registration link
695
-            if (EE_Registry::instance()->CAP->current_user_can(
696
-                'ee_delete_registration',
697
-                'espresso_registrations_restore_registrations',
698
-                $item->ID()
699
-            )) {
700
-                $action['action'] = 'restore_registrations';
701
-                $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
702
-                    $action,
703
-                    REG_ADMIN_URL
704
-                );
705
-                $actions['restore'] = '<a href="'
706
-                                      . $restore_lnk_url
707
-                                      . '" title="'
708
-                                      . esc_attr__('Restore Registration', 'event_espresso') . '">'
709
-                                      . __('Restore', 'event_espresso') . '</a>';
710
-            }
711
-            if (EE_Registry::instance()->CAP->current_user_can(
712
-                'ee_delete_registration',
713
-                'espresso_registrations_ee_delete_registrations',
714
-                $item->ID()
715
-            )) {
716
-                $action['action'] = 'delete_registrations';
717
-                $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
718
-                    $action,
719
-                    REG_ADMIN_URL
720
-                );
721
-                $actions['delete'] = '<a href="'
722
-                                     . $delete_lnk_url
723
-                                     . '" title="'
724
-                                     . esc_attr__('Delete Registration Permanently', 'event_espresso')
725
-                                     . '">'
726
-                                     . __('Delete', 'event_espresso')
727
-                                     . '</a>';
728
-            }
729
-        }
730
-        return sprintf('%1$s %2$s', $link, $this->row_actions($actions));
731
-    }
623
+	/**
624
+	 * column_ATT_fname
625
+	 *
626
+	 * @access public
627
+	 * @param \EE_Registration $item
628
+	 * @return string
629
+	 * @throws EE_Error
630
+	 * @throws InvalidArgumentException
631
+	 * @throws InvalidDataTypeException
632
+	 * @throws InvalidInterfaceException
633
+	 * @throws ReflectionException
634
+	 */
635
+	public function column_ATT_fname(EE_Registration $item)
636
+	{
637
+		$attendee = $item->attendee();
638
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
639
+			array(
640
+				'action'  => 'view_registration',
641
+				'_REG_ID' => $item->ID(),
642
+			),
643
+			REG_ADMIN_URL
644
+		);
645
+		$attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
646
+		$link = EE_Registry::instance()->CAP->current_user_can(
647
+			'ee_read_registration',
648
+			'espresso_registrations_view_registration',
649
+			$item->ID()
650
+		)
651
+			? '<a href="'
652
+			  . $edit_lnk_url
653
+			  . '" title="'
654
+			  . esc_attr__('View Registration Details', 'event_espresso')
655
+			  . '">'
656
+			  . $attendee_name
657
+			  . '</a>' : $attendee_name;
658
+		$link .= $item->count() === 1
659
+			? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>' : '';
660
+		$t = $item->get_first_related('Transaction');
661
+		$payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0;
662
+		// append group count to name
663
+		$link .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
664
+		// append reg_code
665
+		$link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
666
+		// reg status text for accessibility
667
+		$link .= '<br><span class="ee-status-text-small">'
668
+				 . EEH_Template::pretty_status($item->status_ID(), false, 'sentence')
669
+				 . '</span>';
670
+		$action = [ '_REG_ID' => $item->ID() ];
671
+		if (isset($this->_req_data['event_id'])) {
672
+			$action['event_id'] = $item->event_ID();
673
+		}
674
+		// trash/restore/delete actions
675
+		$actions = array();
676
+		if ($this->_view !== 'trash'
677
+			&& $payment_count === 0
678
+			&& EE_Registry::instance()->CAP->current_user_can(
679
+				'ee_delete_registration',
680
+				'espresso_registrations_trash_registrations',
681
+				$item->ID()
682
+			)) {
683
+			$action['action'] = 'trash_registrations';
684
+			$trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
685
+				$action,
686
+				REG_ADMIN_URL
687
+			);
688
+			$actions['trash'] = '<a href="'
689
+								. $trash_lnk_url
690
+								. '" title="'
691
+								. esc_attr__('Trash Registration', 'event_espresso')
692
+								. '">' . __('Trash', 'event_espresso') . '</a>';
693
+		} elseif ($this->_view === 'trash') {
694
+			// restore registration link
695
+			if (EE_Registry::instance()->CAP->current_user_can(
696
+				'ee_delete_registration',
697
+				'espresso_registrations_restore_registrations',
698
+				$item->ID()
699
+			)) {
700
+				$action['action'] = 'restore_registrations';
701
+				$restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
702
+					$action,
703
+					REG_ADMIN_URL
704
+				);
705
+				$actions['restore'] = '<a href="'
706
+									  . $restore_lnk_url
707
+									  . '" title="'
708
+									  . esc_attr__('Restore Registration', 'event_espresso') . '">'
709
+									  . __('Restore', 'event_espresso') . '</a>';
710
+			}
711
+			if (EE_Registry::instance()->CAP->current_user_can(
712
+				'ee_delete_registration',
713
+				'espresso_registrations_ee_delete_registrations',
714
+				$item->ID()
715
+			)) {
716
+				$action['action'] = 'delete_registrations';
717
+				$delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
718
+					$action,
719
+					REG_ADMIN_URL
720
+				);
721
+				$actions['delete'] = '<a href="'
722
+									 . $delete_lnk_url
723
+									 . '" title="'
724
+									 . esc_attr__('Delete Registration Permanently', 'event_espresso')
725
+									 . '">'
726
+									 . __('Delete', 'event_espresso')
727
+									 . '</a>';
728
+			}
729
+		}
730
+		return sprintf('%1$s %2$s', $link, $this->row_actions($actions));
731
+	}
732 732
 
733 733
 
734
-    /**
735
-     * column_ATT_email
736
-     *
737
-     * @access public
738
-     * @param \EE_Registration $item
739
-     * @return string
740
-     * @throws EE_Error
741
-     * @throws InvalidArgumentException
742
-     * @throws InvalidDataTypeException
743
-     * @throws InvalidInterfaceException
744
-     * @throws ReflectionException
745
-     */
746
-    public function column_ATT_email(EE_Registration $item)
747
-    {
748
-        $attendee = $item->get_first_related('Attendee');
749
-        return ! $attendee instanceof EE_Attendee ? __('No attached contact record.', 'event_espresso')
750
-            : $attendee->email();
751
-    }
734
+	/**
735
+	 * column_ATT_email
736
+	 *
737
+	 * @access public
738
+	 * @param \EE_Registration $item
739
+	 * @return string
740
+	 * @throws EE_Error
741
+	 * @throws InvalidArgumentException
742
+	 * @throws InvalidDataTypeException
743
+	 * @throws InvalidInterfaceException
744
+	 * @throws ReflectionException
745
+	 */
746
+	public function column_ATT_email(EE_Registration $item)
747
+	{
748
+		$attendee = $item->get_first_related('Attendee');
749
+		return ! $attendee instanceof EE_Attendee ? __('No attached contact record.', 'event_espresso')
750
+			: $attendee->email();
751
+	}
752 752
 
753 753
 
754
-    /**
755
-     * column__REG_count
756
-     *
757
-     * @access public
758
-     * @param \EE_Registration $item
759
-     * @return string
760
-     */
761
-    public function column__REG_count(EE_Registration $item)
762
-    {
763
-        return sprintf(__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size());
764
-    }
754
+	/**
755
+	 * column__REG_count
756
+	 *
757
+	 * @access public
758
+	 * @param \EE_Registration $item
759
+	 * @return string
760
+	 */
761
+	public function column__REG_count(EE_Registration $item)
762
+	{
763
+		return sprintf(__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size());
764
+	}
765 765
 
766 766
 
767
-    /**
768
-     * column_PRC_amount
769
-     *
770
-     * @access public
771
-     * @param \EE_Registration $item
772
-     * @return string
773
-     * @throws EE_Error
774
-     */
775
-    public function column_PRC_amount(EE_Registration $item)
776
-    {
777
-        $ticket = $item->ticket();
778
-        $content = isset($_GET['event_id']) && $ticket instanceof EE_Ticket ? '<span class="TKT_name">'
779
-                                                                              . $ticket->name()
780
-                                                                              . '</span><br />' : '';
781
-        if ($item->final_price() > 0) {
782
-            $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
783
-        } else {
784
-            // free event
785
-            $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">'
786
-                        . __('free', 'event_espresso')
787
-                        . '</span>';
788
-        }
789
-        return $content;
790
-    }
767
+	/**
768
+	 * column_PRC_amount
769
+	 *
770
+	 * @access public
771
+	 * @param \EE_Registration $item
772
+	 * @return string
773
+	 * @throws EE_Error
774
+	 */
775
+	public function column_PRC_amount(EE_Registration $item)
776
+	{
777
+		$ticket = $item->ticket();
778
+		$content = isset($_GET['event_id']) && $ticket instanceof EE_Ticket ? '<span class="TKT_name">'
779
+																			  . $ticket->name()
780
+																			  . '</span><br />' : '';
781
+		if ($item->final_price() > 0) {
782
+			$content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
783
+		} else {
784
+			// free event
785
+			$content .= '<span class="reg-overview-free-event-spn reg-pad-rght">'
786
+						. __('free', 'event_espresso')
787
+						. '</span>';
788
+		}
789
+		return $content;
790
+	}
791 791
 
792 792
 
793
-    /**
794
-     * column__REG_final_price
795
-     *
796
-     * @access public
797
-     * @param \EE_Registration $item
798
-     * @return string
799
-     * @throws EE_Error
800
-     */
801
-    public function column__REG_final_price(EE_Registration $item)
802
-    {
803
-        $ticket = $item->ticket();
804
-        $content = isset($_GET['event_id']) || ! $ticket instanceof EE_Ticket
805
-            ? ''
806
-            : '<span class="TKT_name">'
807
-              . $ticket->name()
808
-              . '</span><br />';
809
-        $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
810
-        return $content;
811
-    }
793
+	/**
794
+	 * column__REG_final_price
795
+	 *
796
+	 * @access public
797
+	 * @param \EE_Registration $item
798
+	 * @return string
799
+	 * @throws EE_Error
800
+	 */
801
+	public function column__REG_final_price(EE_Registration $item)
802
+	{
803
+		$ticket = $item->ticket();
804
+		$content = isset($_GET['event_id']) || ! $ticket instanceof EE_Ticket
805
+			? ''
806
+			: '<span class="TKT_name">'
807
+			  . $ticket->name()
808
+			  . '</span><br />';
809
+		$content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
810
+		return $content;
811
+	}
812 812
 
813 813
 
814
-    /**
815
-     * column__REG_paid
816
-     *
817
-     * @access public
818
-     * @param \EE_Registration $item
819
-     * @return string
820
-     * @throws EE_Error
821
-     */
822
-    public function column__REG_paid(EE_Registration $item)
823
-    {
824
-        $payment_method = $item->payment_method();
825
-        $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name()
826
-            : __('Unknown', 'event_espresso');
827
-        $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>';
828
-        if ($item->paid() > 0) {
829
-            $content .= '<br><span class="ee-status-text-small">'
830
-                        . sprintf(
831
-                            __('...via %s', 'event_espresso'),
832
-                            $payment_method_name
833
-                        )
834
-                        . '</span>';
835
-        }
836
-        return $content;
837
-    }
814
+	/**
815
+	 * column__REG_paid
816
+	 *
817
+	 * @access public
818
+	 * @param \EE_Registration $item
819
+	 * @return string
820
+	 * @throws EE_Error
821
+	 */
822
+	public function column__REG_paid(EE_Registration $item)
823
+	{
824
+		$payment_method = $item->payment_method();
825
+		$payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name()
826
+			: __('Unknown', 'event_espresso');
827
+		$content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>';
828
+		if ($item->paid() > 0) {
829
+			$content .= '<br><span class="ee-status-text-small">'
830
+						. sprintf(
831
+							__('...via %s', 'event_espresso'),
832
+							$payment_method_name
833
+						)
834
+						. '</span>';
835
+		}
836
+		return $content;
837
+	}
838 838
 
839 839
 
840
-    /**
841
-     * column_TXN_total
842
-     *
843
-     * @access public
844
-     * @param \EE_Registration $item
845
-     * @return string
846
-     * @throws EE_Error
847
-     * @throws EntityNotFoundException
848
-     * @throws InvalidArgumentException
849
-     * @throws InvalidDataTypeException
850
-     * @throws InvalidInterfaceException
851
-     */
852
-    public function column_TXN_total(EE_Registration $item)
853
-    {
854
-        if ($item->transaction()) {
855
-            $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
856
-                array(
857
-                    'action' => 'view_transaction',
858
-                    'TXN_ID' => $item->transaction_ID(),
859
-                ),
860
-                TXN_ADMIN_URL
861
-            );
862
-            return EE_Registry::instance()->CAP->current_user_can(
863
-                'ee_read_transaction',
864
-                'espresso_transactions_view_transaction',
865
-                $item->transaction_ID()
866
-            )
867
-                ? '<span class="reg-pad-rght"><a class="status-'
868
-                  . $item->transaction()->status_ID()
869
-                  . '" href="'
870
-                  . $view_txn_lnk_url
871
-                  . '"  title="'
872
-                  . esc_attr__('View Transaction', 'event_espresso')
873
-                  . '">'
874
-                  . $item->transaction()->pretty_total()
875
-                  . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>';
876
-        } else {
877
-            return __("None", "event_espresso");
878
-        }
879
-    }
840
+	/**
841
+	 * column_TXN_total
842
+	 *
843
+	 * @access public
844
+	 * @param \EE_Registration $item
845
+	 * @return string
846
+	 * @throws EE_Error
847
+	 * @throws EntityNotFoundException
848
+	 * @throws InvalidArgumentException
849
+	 * @throws InvalidDataTypeException
850
+	 * @throws InvalidInterfaceException
851
+	 */
852
+	public function column_TXN_total(EE_Registration $item)
853
+	{
854
+		if ($item->transaction()) {
855
+			$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
856
+				array(
857
+					'action' => 'view_transaction',
858
+					'TXN_ID' => $item->transaction_ID(),
859
+				),
860
+				TXN_ADMIN_URL
861
+			);
862
+			return EE_Registry::instance()->CAP->current_user_can(
863
+				'ee_read_transaction',
864
+				'espresso_transactions_view_transaction',
865
+				$item->transaction_ID()
866
+			)
867
+				? '<span class="reg-pad-rght"><a class="status-'
868
+				  . $item->transaction()->status_ID()
869
+				  . '" href="'
870
+				  . $view_txn_lnk_url
871
+				  . '"  title="'
872
+				  . esc_attr__('View Transaction', 'event_espresso')
873
+				  . '">'
874
+				  . $item->transaction()->pretty_total()
875
+				  . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>';
876
+		} else {
877
+			return __("None", "event_espresso");
878
+		}
879
+	}
880 880
 
881 881
 
882
-    /**
883
-     * column_TXN_paid
884
-     *
885
-     * @access public
886
-     * @param \EE_Registration $item
887
-     * @return string
888
-     * @throws EE_Error
889
-     * @throws EntityNotFoundException
890
-     * @throws InvalidArgumentException
891
-     * @throws InvalidDataTypeException
892
-     * @throws InvalidInterfaceException
893
-     */
894
-    public function column_TXN_paid(EE_Registration $item)
895
-    {
896
-        if ($item->count() === 1) {
897
-            $transaction = $item->transaction() ? $item->transaction() : EE_Transaction::new_instance();
898
-            if ($transaction->paid() >= $transaction->total()) {
899
-                return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
900
-            } else {
901
-                $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
902
-                    array(
903
-                        'action' => 'view_transaction',
904
-                        'TXN_ID' => $item->transaction_ID(),
905
-                    ),
906
-                    TXN_ADMIN_URL
907
-                );
908
-                return EE_Registry::instance()->CAP->current_user_can(
909
-                    'ee_read_transaction',
910
-                    'espresso_transactions_view_transaction',
911
-                    $item->transaction_ID()
912
-                )
913
-                    ? '<span class="reg-pad-rght"><a class="status-'
914
-                      . $transaction->status_ID()
915
-                      . '" href="'
916
-                      . $view_txn_lnk_url
917
-                      . '"  title="'
918
-                      . esc_attr__('View Transaction', 'event_espresso')
919
-                      . '">'
920
-                      . $item->transaction()->pretty_paid()
921
-                      . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
922
-            }
923
-        }
924
-        return '&nbsp;';
925
-    }
882
+	/**
883
+	 * column_TXN_paid
884
+	 *
885
+	 * @access public
886
+	 * @param \EE_Registration $item
887
+	 * @return string
888
+	 * @throws EE_Error
889
+	 * @throws EntityNotFoundException
890
+	 * @throws InvalidArgumentException
891
+	 * @throws InvalidDataTypeException
892
+	 * @throws InvalidInterfaceException
893
+	 */
894
+	public function column_TXN_paid(EE_Registration $item)
895
+	{
896
+		if ($item->count() === 1) {
897
+			$transaction = $item->transaction() ? $item->transaction() : EE_Transaction::new_instance();
898
+			if ($transaction->paid() >= $transaction->total()) {
899
+				return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
900
+			} else {
901
+				$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
902
+					array(
903
+						'action' => 'view_transaction',
904
+						'TXN_ID' => $item->transaction_ID(),
905
+					),
906
+					TXN_ADMIN_URL
907
+				);
908
+				return EE_Registry::instance()->CAP->current_user_can(
909
+					'ee_read_transaction',
910
+					'espresso_transactions_view_transaction',
911
+					$item->transaction_ID()
912
+				)
913
+					? '<span class="reg-pad-rght"><a class="status-'
914
+					  . $transaction->status_ID()
915
+					  . '" href="'
916
+					  . $view_txn_lnk_url
917
+					  . '"  title="'
918
+					  . esc_attr__('View Transaction', 'event_espresso')
919
+					  . '">'
920
+					  . $item->transaction()->pretty_paid()
921
+					  . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
922
+			}
923
+		}
924
+		return '&nbsp;';
925
+	}
926 926
 
927 927
 
928
-    /**
929
-     * column_actions
930
-     *
931
-     * @access public
932
-     * @param \EE_Registration $item
933
-     * @return string
934
-     * @throws EE_Error
935
-     * @throws InvalidArgumentException
936
-     * @throws InvalidDataTypeException
937
-     * @throws InvalidInterfaceException
938
-     * @throws ReflectionException
939
-     */
940
-    public function column_actions(EE_Registration $item)
941
-    {
942
-        $actions = array();
943
-        $attendee = $item->attendee();
944
-        $this->_set_related_details($item);
945
-        // Build row actions
946
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
947
-            array(
948
-                'action'  => 'view_registration',
949
-                '_REG_ID' => $item->ID(),
950
-            ),
951
-            REG_ADMIN_URL
952
-        );
953
-        $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
954
-            array(
955
-                'action' => 'edit_attendee',
956
-                'post'   => $item->attendee_ID(),
957
-            ),
958
-            REG_ADMIN_URL
959
-        );
960
-        // page=attendees&event_admin_reports=resend_email&registration_id=43653465634&event_id=2&form_action=resend_email
961
-        // $resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID );
962
-        $resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
963
-            array(
964
-                'action'  => 'resend_registration',
965
-                '_REG_ID' => $item->ID(),
966
-            ),
967
-            REG_ADMIN_URL,
968
-            true
969
-        );
970
-        // Build row actions
971
-        $actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can(
972
-            'ee_read_registration',
973
-            'espresso_registrations_view_registration',
974
-            $item->ID()
975
-        ) ? '<li><a href="'
976
-            . $view_lnk_url
977
-            . '" title="'
978
-            . esc_attr__('View Registration Details', 'event_espresso')
979
-            . '" class="tiny-text">
928
+	/**
929
+	 * column_actions
930
+	 *
931
+	 * @access public
932
+	 * @param \EE_Registration $item
933
+	 * @return string
934
+	 * @throws EE_Error
935
+	 * @throws InvalidArgumentException
936
+	 * @throws InvalidDataTypeException
937
+	 * @throws InvalidInterfaceException
938
+	 * @throws ReflectionException
939
+	 */
940
+	public function column_actions(EE_Registration $item)
941
+	{
942
+		$actions = array();
943
+		$attendee = $item->attendee();
944
+		$this->_set_related_details($item);
945
+		// Build row actions
946
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
947
+			array(
948
+				'action'  => 'view_registration',
949
+				'_REG_ID' => $item->ID(),
950
+			),
951
+			REG_ADMIN_URL
952
+		);
953
+		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
954
+			array(
955
+				'action' => 'edit_attendee',
956
+				'post'   => $item->attendee_ID(),
957
+			),
958
+			REG_ADMIN_URL
959
+		);
960
+		// page=attendees&event_admin_reports=resend_email&registration_id=43653465634&event_id=2&form_action=resend_email
961
+		// $resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID );
962
+		$resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
963
+			array(
964
+				'action'  => 'resend_registration',
965
+				'_REG_ID' => $item->ID(),
966
+			),
967
+			REG_ADMIN_URL,
968
+			true
969
+		);
970
+		// Build row actions
971
+		$actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can(
972
+			'ee_read_registration',
973
+			'espresso_registrations_view_registration',
974
+			$item->ID()
975
+		) ? '<li><a href="'
976
+			. $view_lnk_url
977
+			. '" title="'
978
+			. esc_attr__('View Registration Details', 'event_espresso')
979
+			. '" class="tiny-text">
980 980
 				<div class="dashicons dashicons-clipboard"></div>
981 981
 			</a>
982 982
 			</li>'
983
-            : '';
984
-        $actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can(
985
-            'ee_edit_contacts',
986
-            'espresso_registrations_edit_attendee'
987
-        )
988
-                               && $attendee instanceof EE_Attendee
989
-            ? '
983
+			: '';
984
+		$actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can(
985
+			'ee_edit_contacts',
986
+			'espresso_registrations_edit_attendee'
987
+		)
988
+							   && $attendee instanceof EE_Attendee
989
+			? '
990 990
 			<li>
991 991
 			<a href="' . $edit_lnk_url . '" title="'
992
-              . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text">
992
+			  . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text">
993 993
 				<div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div>
994 994
 			</a>
995 995
 			</li>' : '';
996
-        $actions['resend_reg_lnk'] = $attendee instanceof EE_Attendee
997
-                                     && EE_Registry::instance()->CAP->current_user_can(
998
-                                         'ee_send_message',
999
-                                         'espresso_registrations_resend_registration',
1000
-                                         $item->ID()
1001
-                                     )
1002
-            ? '
996
+		$actions['resend_reg_lnk'] = $attendee instanceof EE_Attendee
997
+									 && EE_Registry::instance()->CAP->current_user_can(
998
+										 'ee_send_message',
999
+										 'espresso_registrations_resend_registration',
1000
+										 $item->ID()
1001
+									 )
1002
+			? '
1003 1003
 			<li>
1004 1004
 			<a href="'
1005
-              . $resend_reg_lnk_url
1006
-              . '" title="'
1007
-              . esc_attr__('Resend Registration Details', 'event_espresso')
1008
-              . '" class="tiny-text">
1005
+			  . $resend_reg_lnk_url
1006
+			  . '" title="'
1007
+			  . esc_attr__('Resend Registration Details', 'event_espresso')
1008
+			  . '" class="tiny-text">
1009 1009
 				<div class="dashicons dashicons-email-alt"></div>
1010 1010
 			</a>
1011 1011
 			</li>' : '';
1012
-        // page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb
1013
-        $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
1014
-            array(
1015
-                'action' => 'view_transaction',
1016
-                'TXN_ID' => $this->_transaction_details['id'],
1017
-            ),
1018
-            TXN_ADMIN_URL
1019
-        );
1020
-        $actions['view_txn_lnk'] = EE_Registry::instance()->CAP->current_user_can(
1021
-            'ee_read_transaction',
1022
-            'espresso_transactions_view_transaction',
1023
-            $this->_transaction_details['id']
1024
-        )
1025
-            ? '
1012
+		// page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb
1013
+		$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
1014
+			array(
1015
+				'action' => 'view_transaction',
1016
+				'TXN_ID' => $this->_transaction_details['id'],
1017
+			),
1018
+			TXN_ADMIN_URL
1019
+		);
1020
+		$actions['view_txn_lnk'] = EE_Registry::instance()->CAP->current_user_can(
1021
+			'ee_read_transaction',
1022
+			'espresso_transactions_view_transaction',
1023
+			$this->_transaction_details['id']
1024
+		)
1025
+			? '
1026 1026
 			<li>
1027 1027
 			<a class="ee-status-color-'
1028
-              . $this->_transaction_details['status']
1029
-              . ' tiny-text" href="'
1030
-              . $view_txn_lnk_url
1031
-              . '"  title="'
1032
-              . $this->_transaction_details['title_attr']
1033
-              . '">
1028
+			  . $this->_transaction_details['status']
1029
+			  . ' tiny-text" href="'
1030
+			  . $view_txn_lnk_url
1031
+			  . '"  title="'
1032
+			  . $this->_transaction_details['title_attr']
1033
+			  . '">
1034 1034
 				<div class="dashicons dashicons-cart"></div>
1035 1035
 			</a>
1036 1036
 			</li>' : '';
1037
-        // invoice link
1038
-        $actions['dl_invoice_lnk'] = '';
1039
-        $dl_invoice_lnk_url = $item->invoice_url();
1040
-        // only show invoice link if message type is active.
1041
-        if ($attendee instanceof EE_Attendee
1042
-            && $item->is_primary_registrant()
1043
-            && EEH_MSG_Template::is_mt_active('invoice')
1044
-        ) {
1045
-            $actions['dl_invoice_lnk'] = '
1037
+		// invoice link
1038
+		$actions['dl_invoice_lnk'] = '';
1039
+		$dl_invoice_lnk_url = $item->invoice_url();
1040
+		// only show invoice link if message type is active.
1041
+		if ($attendee instanceof EE_Attendee
1042
+			&& $item->is_primary_registrant()
1043
+			&& EEH_MSG_Template::is_mt_active('invoice')
1044
+		) {
1045
+			$actions['dl_invoice_lnk'] = '
1046 1046
 		<li>
1047 1047
 			<a title="'
1048
-                                         . esc_attr__('View Transaction Invoice', 'event_espresso')
1049
-                                         . '" target="_blank" href="'
1050
-                                         . $dl_invoice_lnk_url
1051
-                                         . '" class="tiny-text">
1048
+										 . esc_attr__('View Transaction Invoice', 'event_espresso')
1049
+										 . '" target="_blank" href="'
1050
+										 . $dl_invoice_lnk_url
1051
+										 . '" class="tiny-text">
1052 1052
 				<span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span>
1053 1053
 			</a>
1054 1054
 		</li>';
1055
-        }
1056
-        $actions['filtered_messages_link'] = '';
1057
-        // message list table link (filtered by REG_ID
1058
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
1059
-            $actions['filtered_messages_link'] = '<li>'
1060
-                                                 . EEH_MSG_Template::get_message_action_link(
1061
-                                                     'see_notifications_for',
1062
-                                                     null,
1063
-                                                     array('_REG_ID' => $item->ID())
1064
-                                                 ) . '</li>';
1065
-        }
1066
-        $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this);
1067
-        return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul');
1068
-    }
1055
+		}
1056
+		$actions['filtered_messages_link'] = '';
1057
+		// message list table link (filtered by REG_ID
1058
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
1059
+			$actions['filtered_messages_link'] = '<li>'
1060
+												 . EEH_MSG_Template::get_message_action_link(
1061
+													 'see_notifications_for',
1062
+													 null,
1063
+													 array('_REG_ID' => $item->ID())
1064
+												 ) . '</li>';
1065
+		}
1066
+		$actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this);
1067
+		return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul');
1068
+	}
1069 1069
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -53,10 +53,10 @@  discard block
 block discarded – undo
53 53
      */
54 54
     public function __construct(Registrations_Admin_Page $admin_page)
55 55
     {
56
-        if (! empty($_GET['event_id'])) {
56
+        if ( ! empty($_GET['event_id'])) {
57 57
             $extra_query_args = array();
58 58
             foreach ($admin_page->get_views() as $key => $view_details) {
59
-                $extra_query_args[ $view_details['slug'] ] = array('event_id' => $_GET['event_id']);
59
+                $extra_query_args[$view_details['slug']] = array('event_id' => $_GET['event_id']);
60 60
             }
61 61
             $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args);
62 62
         }
@@ -156,12 +156,12 @@  discard block
 block discarded – undo
156 156
                 )
157 157
             )
158 158
         );
159
-        if (!empty($filters)) {
159
+        if ( ! empty($filters)) {
160 160
             $this->_bottom_buttons['report_filtered']['extra_request']['filters'] = $filters;
161 161
         }
162 162
         $this->_primary_column = '_REG_ID';
163 163
         $this->_sortable_columns = array(
164
-            '_REG_date'     => array('_REG_date' => true),   // true means its already sorted
164
+            '_REG_date'     => array('_REG_date' => true), // true means its already sorted
165 165
             /**
166 166
              * Allows users to change the default sort if they wish.
167 167
              * Returning a falsey on this filter will result in the default sort to be by firstname rather than last
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
     {
194 194
         $class = parent::_get_row_class($item);
195 195
         // add status class
196
-        $class .= ' ee-status-strip reg-status-' . $item->status_ID();
196
+        $class .= ' ee-status-strip reg-status-'.$item->status_ID();
197 197
         if ($this->_has_checkbox_column) {
198 198
             $class .= ' has-checkbox-column';
199 199
         }
@@ -358,12 +358,12 @@  discard block
 block discarded – undo
358 358
         // setup date query.
359 359
         $beginning_string = EEM_Registration::instance()->convert_datetime_for_query(
360 360
             'REG_date',
361
-            $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start,
361
+            $this_year_r.'-'.$this_month_r.'-01'.' '.$time_start,
362 362
             'Y-m-d H:i:s'
363 363
         );
364 364
         $end_string = EEM_Registration::instance()->convert_datetime_for_query(
365 365
             'REG_date',
366
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end,
366
+            $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' '.$time_end,
367 367
             'Y-m-d H:i:s'
368 368
         );
369 369
         $_where['REG_date'] = array(
@@ -400,12 +400,12 @@  discard block
 block discarded – undo
400 400
             array(
401 401
                 EEM_Registration::instance()->convert_datetime_for_query(
402 402
                     'REG_date',
403
-                    $current_date . $time_start,
403
+                    $current_date.$time_start,
404 404
                     'Y-m-d H:i:s'
405 405
                 ),
406 406
                 EEM_Registration::instance()->convert_datetime_for_query(
407 407
                     'REG_date',
408
-                    $current_date . $time_end,
408
+                    $current_date.$time_end,
409 409
                     'Y-m-d H:i:s'
410 410
                 ),
411 411
             ),
@@ -465,8 +465,8 @@  discard block
 block discarded – undo
465 465
         $content .= '<div class="show-on-mobile-view-only">';
466 466
         $content .= '<br>';
467 467
         $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
468
-        $content .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
469
-        $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
468
+        $content .= '&nbsp;'.sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
469
+        $content .= '<br>'.sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
470 470
         $content .= '</div>';
471 471
         return $content;
472 472
     }
@@ -551,12 +551,12 @@  discard block
 block discarded – undo
551 551
                   . $event_name
552 552
                   . '</a>' : $event_name;
553 553
             $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL);
554
-            $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="';
554
+            $actions['event_filter'] = '<a href="'.$edit_event_url.'" title="';
555 555
             $actions['event_filter'] .= sprintf(
556 556
                 esc_attr__('Filter this list to only show registrations for %s', 'event_espresso'),
557 557
                 $event_name
558 558
             );
559
-            $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>';
559
+            $actions['event_filter'] .= '">'.__('View Registrations', 'event_espresso').'</a>';
560 560
         } else {
561 561
             $edit_event = $event_name;
562 562
             $actions['event_filter'] = '';
@@ -603,11 +603,11 @@  discard block
 block discarded – undo
603 603
     {
604 604
         $content = '<div class="ee-registration-event-datetimes-container">';
605 605
         $expand_toggle = count($datetime_strings) > 1
606
-            ? ' <span title="' . esc_attr__('Click to view all dates', 'event_espresso')
606
+            ? ' <span title="'.esc_attr__('Click to view all dates', 'event_espresso')
607 607
               . '" class="ee-js ee-more-datetimes-toggle dashicons dashicons-plus"></span>'
608 608
             : '';
609 609
         // get first item for initial visibility
610
-        $content .= '<div class="left">' . array_shift($datetime_strings) . '</div>';
610
+        $content .= '<div class="left">'.array_shift($datetime_strings).'</div>';
611 611
         $content .= $expand_toggle;
612 612
         if ($datetime_strings) {
613 613
             $content .= '<div style="clear:both"></div>';
@@ -660,14 +660,14 @@  discard block
 block discarded – undo
660 660
         $t = $item->get_first_related('Transaction');
661 661
         $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0;
662 662
         // append group count to name
663
-        $link .= '&nbsp;' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
663
+        $link .= '&nbsp;'.sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size());
664 664
         // append reg_code
665
-        $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
665
+        $link .= '<br>'.sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code'));
666 666
         // reg status text for accessibility
667 667
         $link .= '<br><span class="ee-status-text-small">'
668 668
                  . EEH_Template::pretty_status($item->status_ID(), false, 'sentence')
669 669
                  . '</span>';
670
-        $action = [ '_REG_ID' => $item->ID() ];
670
+        $action = ['_REG_ID' => $item->ID()];
671 671
         if (isset($this->_req_data['event_id'])) {
672 672
             $action['event_id'] = $item->event_ID();
673 673
         }
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
                                 . $trash_lnk_url
690 690
                                 . '" title="'
691 691
                                 . esc_attr__('Trash Registration', 'event_espresso')
692
-                                . '">' . __('Trash', 'event_espresso') . '</a>';
692
+                                . '">'.__('Trash', 'event_espresso').'</a>';
693 693
         } elseif ($this->_view === 'trash') {
694 694
             // restore registration link
695 695
             if (EE_Registry::instance()->CAP->current_user_can(
@@ -705,8 +705,8 @@  discard block
 block discarded – undo
705 705
                 $actions['restore'] = '<a href="'
706 706
                                       . $restore_lnk_url
707 707
                                       . '" title="'
708
-                                      . esc_attr__('Restore Registration', 'event_espresso') . '">'
709
-                                      . __('Restore', 'event_espresso') . '</a>';
708
+                                      . esc_attr__('Restore Registration', 'event_espresso').'">'
709
+                                      . __('Restore', 'event_espresso').'</a>';
710 710
             }
711 711
             if (EE_Registry::instance()->CAP->current_user_can(
712 712
                 'ee_delete_registration',
@@ -779,7 +779,7 @@  discard block
 block discarded – undo
779 779
                                                                               . $ticket->name()
780 780
                                                                               . '</span><br />' : '';
781 781
         if ($item->final_price() > 0) {
782
-            $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
782
+            $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>';
783 783
         } else {
784 784
             // free event
785 785
             $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">'
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
             : '<span class="TKT_name">'
807 807
               . $ticket->name()
808 808
               . '</span><br />';
809
-        $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>';
809
+        $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>';
810 810
         return $content;
811 811
     }
812 812
 
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
         $payment_method = $item->payment_method();
825 825
         $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name()
826 826
             : __('Unknown', 'event_espresso');
827
-        $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>';
827
+        $content = '<span class="reg-pad-rght">'.$item->pretty_paid().'</span>';
828 828
         if ($item->paid() > 0) {
829 829
             $content .= '<br><span class="ee-status-text-small">'
830 830
                         . sprintf(
@@ -872,7 +872,7 @@  discard block
 block discarded – undo
872 872
                   . esc_attr__('View Transaction', 'event_espresso')
873 873
                   . '">'
874 874
                   . $item->transaction()->pretty_total()
875
-                  . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>';
875
+                  . '</a></span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_total().'</span>';
876 876
         } else {
877 877
             return __("None", "event_espresso");
878 878
         }
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
                       . esc_attr__('View Transaction', 'event_espresso')
919 919
                       . '">'
920 920
                       . $item->transaction()->pretty_paid()
921
-                      . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
921
+                      . '</a><span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_paid().'</span>';
922 922
             }
923 923
         }
924 924
         return '&nbsp;';
@@ -988,8 +988,8 @@  discard block
 block discarded – undo
988 988
                                && $attendee instanceof EE_Attendee
989 989
             ? '
990 990
 			<li>
991
-			<a href="' . $edit_lnk_url . '" title="'
992
-              . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text">
991
+			<a href="' . $edit_lnk_url.'" title="'
992
+              . esc_attr__('Edit Contact Details', 'event_espresso').'" class="tiny-text">
993 993
 				<div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div>
994 994
 			</a>
995 995
 			</li>' : '';
@@ -1061,7 +1061,7 @@  discard block
 block discarded – undo
1061 1061
                                                      'see_notifications_for',
1062 1062
                                                      null,
1063 1063
                                                      array('_REG_ID' => $item->ID())
1064
-                                                 ) . '</li>';
1064
+                                                 ).'</li>';
1065 1065
         }
1066 1066
         $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this);
1067 1067
         return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul');
Please login to merge, or discard this patch.
core/EE_Capabilities.core.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
      * @since                        4.5.0
806 806
      *
807 807
      * @param string $meta_cap   What meta capability is this mapping.
808
-     * @param array  $map_values array {
808
+     * @param string[]  $map_values array {
809 809
      *                           //array of values that MUST match a count of 4.  It's okay to send an empty string for
810 810
      *                           capabilities that don't get mapped to.
811 811
      *
@@ -880,8 +880,8 @@  discard block
 block discarded – undo
880 880
      * @since 4.6.x
881 881
      *
882 882
      * @param $caps
883
-     * @param $cap
884
-     * @param $user_id
883
+     * @param string $cap
884
+     * @param integer $user_id
885 885
      * @param $args
886 886
      *
887 887
      * @return array
Please login to merge, or discard this patch.
Indentation   +1367 added lines, -1367 removed lines patch added patch discarded remove patch
@@ -14,979 +14,979 @@  discard block
 block discarded – undo
14 14
 final class EE_Capabilities extends EE_Base
15 15
 {
16 16
 
17
-    /**
18
-     * the name of the wp option used to store caps previously initialized
19
-     */
20
-    const option_name = 'ee_caps_initialized';
21
-
22
-    /**
23
-     * instance of EE_Capabilities object
24
-     *
25
-     * @var EE_Capabilities
26
-     */
27
-    private static $_instance;
28
-
29
-
30
-    /**
31
-     * This is a map of caps that correspond to a default WP_Role.
32
-     * Array is indexed by Role and values are ee capabilities.
33
-     *
34
-     * @since 4.5.0
35
-     *
36
-     * @var array
37
-     */
38
-    private $capabilities_map = array();
39
-
40
-    /**
41
-     * This used to hold an array of EE_Meta_Capability_Map objects
42
-     * that define the granular capabilities mapped to for a user depending on context.
43
-     *
44
-     * @var EE_Meta_Capability_Map[]
45
-     */
46
-    private $_meta_caps = array();
47
-
48
-    /**
49
-     * The internal $capabilities_map needs to be initialized before it can be used.
50
-     * This flag tracks whether that has happened or not.
51
-     * But for this to work, we need three states to indicate:
52
-     *      initialization has not occurred at all
53
-     *      initialization has started but is not complete
54
-     *      initialization is complete
55
-     * The reason this is needed is because the addCaps() method
56
-     * normally requires the $capabilities_map to be initialized,
57
-     * but is also used during the initialization process.
58
-     * So:
59
-     *      If initialized === null, init_caps() will be called before any other methods will run.
60
-     *      If initialized === false, then init_caps() is in the process of running it's logic.
61
-     *      If initialized === true, then init_caps() has completed the initialization process.
62
-     *
63
-     * @var boolean|null $initialized
64
-     */
65
-    private $initialized;
66
-
67
-    /**
68
-     * @var boolean $reset
69
-     */
70
-    private $reset = false;
71
-
72
-
73
-    /**
74
-     * singleton method used to instantiate class object
75
-     *
76
-     * @since 4.5.0
77
-     *
78
-     * @return EE_Capabilities
79
-     */
80
-    public static function instance()
81
-    {
82
-        // check if instantiated, and if not do so.
83
-        if (! self::$_instance instanceof EE_Capabilities) {
84
-            self::$_instance = new self();
85
-        }
86
-        return self::$_instance;
87
-    }
88
-
89
-
90
-    /**
91
-     * private constructor
92
-     *
93
-     * @since 4.5.0
94
-     */
95
-    private function __construct()
96
-    {
97
-    }
98
-
99
-
100
-    /**
101
-     * This delays the initialization of the capabilities class until EE_System core is loaded and ready.
102
-     *
103
-     * @param bool $reset allows for resetting the default capabilities saved on roles.  Note that this doesn't
104
-     *                    actually REMOVE any capabilities from existing roles, it just resaves defaults roles and
105
-     *                    ensures that they are up to date.
106
-     *
107
-     * @since 4.5.0
108
-     * @return bool
109
-     * @throws EE_Error
110
-     */
111
-    public function init_caps($reset = false)
112
-    {
113
-        if (! EE_Maintenance_Mode::instance()->models_can_query()) {
114
-            return false;
115
-        }
116
-        $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN);
117
-        // if reset, then completely delete the cache option and clear the $capabilities_map property.
118
-        if ($this->reset) {
119
-            $this->initialized = null;
120
-            $this->capabilities_map = array();
121
-            delete_option(self::option_name);
122
-        }
123
-        if ($this->initialized === null) {
124
-            $this->initialized = false;
125
-            do_action(
126
-                'AHEE__EE_Capabilities__init_caps__before_initialization',
127
-                $this->reset
128
-            );
129
-            $this->addCaps($this->_init_caps_map());
130
-            $this->_set_meta_caps();
131
-            do_action(
132
-                'AHEE__EE_Capabilities__init_caps__after_initialization',
133
-                $this->capabilities_map
134
-            );
135
-            $this->initialized = true;
136
-        }
137
-        // reset $this->reset so that it's not stuck on true if init_caps() gets called again
138
-        $this->reset = false;
139
-        return true;
140
-    }
141
-
142
-
143
-    /**
144
-     * This sets the meta caps property.
145
-     *
146
-     * @since 4.5.0
147
-     * @return void
148
-     * @throws EE_Error
149
-     */
150
-    private function _set_meta_caps()
151
-    {
152
-        // get default meta caps and filter the returned array
153
-        $this->_meta_caps = apply_filters(
154
-            'FHEE__EE_Capabilities___set_meta_caps__meta_caps',
155
-            $this->_get_default_meta_caps_array()
156
-        );
157
-        // add filter for map_meta_caps but only if models can query.
158
-        if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
159
-            add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4);
160
-        }
161
-    }
162
-
163
-
164
-    /**
165
-     * This builds and returns the default meta_caps array only once.
166
-     *
167
-     * @since  4.8.28.rc.012
168
-     * @return array
169
-     * @throws EE_Error
170
-     */
171
-    private function _get_default_meta_caps_array()
172
-    {
173
-        static $default_meta_caps = array();
174
-        // make sure we're only ever initializing the default _meta_caps array once if it's empty.
175
-        if (empty($default_meta_caps)) {
176
-            $default_meta_caps = array(
177
-                // edits
178
-                new EE_Meta_Capability_Map_Edit(
179
-                    'ee_edit_event',
180
-                    array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events')
181
-                ),
182
-                new EE_Meta_Capability_Map_Edit(
183
-                    'ee_edit_venue',
184
-                    array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues')
185
-                ),
186
-                new EE_Meta_Capability_Map_Edit(
187
-                    'ee_edit_registration',
188
-                    array('Registration', '', 'ee_edit_others_registrations', '')
189
-                ),
190
-                new EE_Meta_Capability_Map_Edit(
191
-                    'ee_edit_checkin',
192
-                    array('Registration', '', 'ee_edit_others_checkins', '')
193
-                ),
194
-                new EE_Meta_Capability_Map_Messages_Cap(
195
-                    'ee_edit_message',
196
-                    array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages')
197
-                ),
198
-                new EE_Meta_Capability_Map_Edit(
199
-                    'ee_edit_default_ticket',
200
-                    array('Ticket', '', 'ee_edit_others_default_tickets', '')
201
-                ),
202
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
203
-                    'ee_edit_question',
204
-                    array('Question', '', '', 'ee_edit_system_questions')
205
-                ),
206
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
207
-                    'ee_edit_question_group',
208
-                    array('Question_Group', '', '', 'ee_edit_system_question_groups')
209
-                ),
210
-                new EE_Meta_Capability_Map_Edit(
211
-                    'ee_edit_payment_method',
212
-                    array('Payment_Method', '', 'ee_edit_others_payment_methods', '')
213
-                ),
214
-                // reads
215
-                new EE_Meta_Capability_Map_Read(
216
-                    'ee_read_event',
217
-                    array('Event', '', 'ee_read_others_events', 'ee_read_private_events')
218
-                ),
219
-                new EE_Meta_Capability_Map_Read(
220
-                    'ee_read_venue',
221
-                    array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues')
222
-                ),
223
-                new EE_Meta_Capability_Map_Read(
224
-                    'ee_read_registration',
225
-                    array('Registration', '', 'ee_read_others_registrations', '')
226
-                ),
227
-                new EE_Meta_Capability_Map_Read(
228
-                    'ee_read_checkin',
229
-                    array('Registration', '', 'ee_read_others_checkins', '')
230
-                ),
231
-                new EE_Meta_Capability_Map_Messages_Cap(
232
-                    'ee_read_message',
233
-                    array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages')
234
-                ),
235
-                new EE_Meta_Capability_Map_Read(
236
-                    'ee_read_default_ticket',
237
-                    array('Ticket', '', 'ee_read_others_default_tickets', '')
238
-                ),
239
-                new EE_Meta_Capability_Map_Read(
240
-                    'ee_read_payment_method',
241
-                    array('Payment_Method', '', 'ee_read_others_payment_methods', '')
242
-                ),
243
-                // deletes
244
-                new EE_Meta_Capability_Map_Delete(
245
-                    'ee_delete_event',
246
-                    array(
247
-                        'Event',
248
-                        'ee_delete_published_events',
249
-                        'ee_delete_others_events',
250
-                        'ee_delete_private_events',
251
-                    )
252
-                ),
253
-                new EE_Meta_Capability_Map_Delete(
254
-                    'ee_delete_venue',
255
-                    array(
256
-                        'Venue',
257
-                        'ee_delete_published_venues',
258
-                        'ee_delete_others_venues',
259
-                        'ee_delete_private_venues',
260
-                    )
261
-                ),
262
-                new EE_Meta_Capability_Map_Delete(
263
-                    'ee_delete_registration',
264
-                    array('Registration', '', 'ee_delete_others_registrations', '')
265
-                ),
266
-                new EE_Meta_Capability_Map_Delete(
267
-                    'ee_delete_checkin',
268
-                    array('Registration', '', 'ee_delete_others_checkins', '')
269
-                ),
270
-                new EE_Meta_Capability_Map_Messages_Cap(
271
-                    'ee_delete_message',
272
-                    array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages')
273
-                ),
274
-                new EE_Meta_Capability_Map_Delete(
275
-                    'ee_delete_default_ticket',
276
-                    array('Ticket', '', 'ee_delete_others_default_tickets', '')
277
-                ),
278
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
279
-                    'ee_delete_question',
280
-                    array('Question', '', '', 'delete_system_questions')
281
-                ),
282
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
283
-                    'ee_delete_question_group',
284
-                    array('Question_Group', '', '', 'delete_system_question_groups')
285
-                ),
286
-                new EE_Meta_Capability_Map_Delete(
287
-                    'ee_delete_payment_method',
288
-                    array('Payment_Method', '', 'ee_delete_others_payment_methods', '')
289
-                ),
290
-            );
291
-        }
292
-        return $default_meta_caps;
293
-    }
294
-
295
-
296
-    /**
297
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
298
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
299
-     *
300
-     * The actual logic is carried out by implementer classes in their definition of _map_meta_caps.
301
-     *
302
-     * @since 4.5.0
303
-     * @see   wp-includes/capabilities.php
304
-     *
305
-     * @param array  $caps    actual users capabilities
306
-     * @param string $cap     initial capability name that is being checked (the "map" key)
307
-     * @param int    $user_id The user id
308
-     * @param array  $args    Adds context to the cap. Typically the object ID.
309
-     * @return array actual users capabilities
310
-     * @throws EE_Error
311
-     */
312
-    public function map_meta_caps($caps, $cap, $user_id, $args)
313
-    {
314
-        if (did_action('AHEE__EE_System__load_espresso_addons__complete')) {
315
-            // loop through our _meta_caps array
316
-            foreach ($this->_meta_caps as $meta_map) {
317
-                if (! $meta_map instanceof EE_Meta_Capability_Map) {
318
-                    continue;
319
-                }
320
-                // don't load models if there is no object ID in the args
321
-                if (! empty($args[0])) {
322
-                    $meta_map->ensure_is_model();
323
-                }
324
-                $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args);
325
-            }
326
-        }
327
-        return $caps;
328
-    }
329
-
330
-
331
-    /**
332
-     * This sets up and returns the initial capabilities map for Event Espresso
333
-     * Note this array is filtered.
334
-     * It is assumed that all available EE capabilities are assigned to the administrator role.
335
-     *
336
-     * @since 4.5.0
337
-     *
338
-     * @return array
339
-     */
340
-    private function _init_caps_map()
341
-    {
342
-        return apply_filters(
343
-            'FHEE__EE_Capabilities__init_caps_map__caps',
344
-            array(
345
-                'administrator'           => array(
346
-                    // basic access
347
-                    'ee_read_ee',
348
-                    // gateways
349
-                    /**
350
-                     * note that with payment method capabilities, although we've implemented
351
-                     * capability mapping which will be used for accessing payment methods owned by
352
-                     * other users.  This is not fully implemented yet in the payment method ui.
353
-                     * Currently only the "plural" caps are in active use.
354
-                     * (Specific payment method caps are in use as well).
355
-                     **/
356
-                    'ee_manage_gateways',
357
-                    'ee_read_payment_methods',
358
-                    'ee_read_others_payment_methods',
359
-                    'ee_edit_payment_methods',
360
-                    'ee_edit_others_payment_methods',
361
-                    'ee_delete_payment_methods',
362
-                    // events
363
-                    'ee_publish_events',
364
-                    'ee_read_private_events',
365
-                    'ee_read_others_events',
366
-                    'ee_read_events',
367
-                    'ee_edit_events',
368
-                    'ee_edit_published_events',
369
-                    'ee_edit_others_events',
370
-                    'ee_edit_private_events',
371
-                    'ee_delete_published_events',
372
-                    'ee_delete_private_events',
373
-                    'ee_delete_events',
374
-                    'ee_delete_others_events',
375
-                    // event categories
376
-                    'ee_manage_event_categories',
377
-                    'ee_edit_event_category',
378
-                    'ee_delete_event_category',
379
-                    'ee_assign_event_category',
380
-                    // venues
381
-                    'ee_publish_venues',
382
-                    'ee_read_venues',
383
-                    'ee_read_others_venues',
384
-                    'ee_read_private_venues',
385
-                    'ee_edit_venues',
386
-                    'ee_edit_others_venues',
387
-                    'ee_edit_published_venues',
388
-                    'ee_edit_private_venues',
389
-                    'ee_delete_venues',
390
-                    'ee_delete_others_venues',
391
-                    'ee_delete_private_venues',
392
-                    'ee_delete_published_venues',
393
-                    // venue categories
394
-                    'ee_manage_venue_categories',
395
-                    'ee_edit_venue_category',
396
-                    'ee_delete_venue_category',
397
-                    'ee_assign_venue_category',
398
-                    // contacts
399
-                    'ee_read_contacts',
400
-                    'ee_edit_contacts',
401
-                    'ee_delete_contacts',
402
-                    // registrations
403
-                    'ee_read_registrations',
404
-                    'ee_read_others_registrations',
405
-                    'ee_edit_registrations',
406
-                    'ee_edit_others_registrations',
407
-                    'ee_delete_registrations',
408
-                    // checkins
409
-                    'ee_read_others_checkins',
410
-                    'ee_read_checkins',
411
-                    'ee_edit_checkins',
412
-                    'ee_edit_others_checkins',
413
-                    'ee_delete_checkins',
414
-                    'ee_delete_others_checkins',
415
-                    // transactions && payments
416
-                    'ee_read_transaction',
417
-                    'ee_read_transactions',
418
-                    'ee_edit_payments',
419
-                    'ee_delete_payments',
420
-                    // messages
421
-                    'ee_read_messages',
422
-                    'ee_read_others_messages',
423
-                    'ee_read_global_messages',
424
-                    'ee_edit_global_messages',
425
-                    'ee_edit_messages',
426
-                    'ee_edit_others_messages',
427
-                    'ee_delete_messages',
428
-                    'ee_delete_others_messages',
429
-                    'ee_delete_global_messages',
430
-                    'ee_send_message',
431
-                    // tickets
432
-                    'ee_read_default_tickets',
433
-                    'ee_read_others_default_tickets',
434
-                    'ee_edit_default_tickets',
435
-                    'ee_edit_others_default_tickets',
436
-                    'ee_delete_default_tickets',
437
-                    'ee_delete_others_default_tickets',
438
-                    // prices
439
-                    'ee_edit_default_price',
440
-                    'ee_edit_default_prices',
441
-                    'ee_delete_default_price',
442
-                    'ee_delete_default_prices',
443
-                    'ee_edit_default_price_type',
444
-                    'ee_edit_default_price_types',
445
-                    'ee_delete_default_price_type',
446
-                    'ee_delete_default_price_types',
447
-                    'ee_read_default_prices',
448
-                    'ee_read_default_price_types',
449
-                    // registration form
450
-                    'ee_edit_questions',
451
-                    'ee_edit_system_questions',
452
-                    'ee_read_questions',
453
-                    'ee_delete_questions',
454
-                    'ee_edit_question_groups',
455
-                    'ee_read_question_groups',
456
-                    'ee_edit_system_question_groups',
457
-                    'ee_delete_question_groups',
458
-                    // event_type taxonomy
459
-                    'ee_assign_event_type',
460
-                    'ee_manage_event_types',
461
-                    'ee_edit_event_type',
462
-                    'ee_delete_event_type',
463
-                ),
464
-                'ee_events_administrator' => array(
465
-                    // core wp caps
466
-                    'read',
467
-                    'read_private_pages',
468
-                    'read_private_posts',
469
-                    'edit_users',
470
-                    'edit_posts',
471
-                    'edit_pages',
472
-                    'edit_published_posts',
473
-                    'edit_published_pages',
474
-                    'edit_private_pages',
475
-                    'edit_private_posts',
476
-                    'edit_others_posts',
477
-                    'edit_others_pages',
478
-                    'publish_posts',
479
-                    'publish_pages',
480
-                    'delete_posts',
481
-                    'delete_pages',
482
-                    'delete_private_pages',
483
-                    'delete_private_posts',
484
-                    'delete_published_pages',
485
-                    'delete_published_posts',
486
-                    'delete_others_posts',
487
-                    'delete_others_pages',
488
-                    'manage_categories',
489
-                    'manage_links',
490
-                    'moderate_comments',
491
-                    'unfiltered_html',
492
-                    'upload_files',
493
-                    'export',
494
-                    'import',
495
-                    'list_users',
496
-                    'level_1', // required if user with this role shows up in author dropdowns
497
-                    // basic ee access
498
-                    'ee_read_ee',
499
-                    // events
500
-                    'ee_publish_events',
501
-                    'ee_read_private_events',
502
-                    'ee_read_others_events',
503
-                    'ee_read_event',
504
-                    'ee_read_events',
505
-                    'ee_edit_event',
506
-                    'ee_edit_events',
507
-                    'ee_edit_published_events',
508
-                    'ee_edit_others_events',
509
-                    'ee_edit_private_events',
510
-                    'ee_delete_published_events',
511
-                    'ee_delete_private_events',
512
-                    'ee_delete_event',
513
-                    'ee_delete_events',
514
-                    'ee_delete_others_events',
515
-                    // event categories
516
-                    'ee_manage_event_categories',
517
-                    'ee_edit_event_category',
518
-                    'ee_delete_event_category',
519
-                    'ee_assign_event_category',
520
-                    // venues
521
-                    'ee_publish_venues',
522
-                    'ee_read_venue',
523
-                    'ee_read_venues',
524
-                    'ee_read_others_venues',
525
-                    'ee_read_private_venues',
526
-                    'ee_edit_venue',
527
-                    'ee_edit_venues',
528
-                    'ee_edit_others_venues',
529
-                    'ee_edit_published_venues',
530
-                    'ee_edit_private_venues',
531
-                    'ee_delete_venue',
532
-                    'ee_delete_venues',
533
-                    'ee_delete_others_venues',
534
-                    'ee_delete_private_venues',
535
-                    'ee_delete_published_venues',
536
-                    // venue categories
537
-                    'ee_manage_venue_categories',
538
-                    'ee_edit_venue_category',
539
-                    'ee_delete_venue_category',
540
-                    'ee_assign_venue_category',
541
-                    // contacts
542
-                    'ee_read_contacts',
543
-                    'ee_edit_contacts',
544
-                    'ee_delete_contacts',
545
-                    // registrations
546
-                    'ee_read_registrations',
547
-                    'ee_read_others_registrations',
548
-                    'ee_edit_registration',
549
-                    'ee_edit_registrations',
550
-                    'ee_edit_others_registrations',
551
-                    'ee_delete_registration',
552
-                    'ee_delete_registrations',
553
-                    // checkins
554
-                    'ee_read_others_checkins',
555
-                    'ee_read_checkins',
556
-                    'ee_edit_checkins',
557
-                    'ee_edit_others_checkins',
558
-                    'ee_delete_checkins',
559
-                    'ee_delete_others_checkins',
560
-                    // transactions && payments
561
-                    'ee_read_transaction',
562
-                    'ee_read_transactions',
563
-                    'ee_edit_payments',
564
-                    'ee_delete_payments',
565
-                    // messages
566
-                    'ee_read_messages',
567
-                    'ee_read_others_messages',
568
-                    'ee_read_global_messages',
569
-                    'ee_edit_global_messages',
570
-                    'ee_edit_messages',
571
-                    'ee_edit_others_messages',
572
-                    'ee_delete_messages',
573
-                    'ee_delete_others_messages',
574
-                    'ee_delete_global_messages',
575
-                    'ee_send_message',
576
-                    // tickets
577
-                    'ee_read_default_tickets',
578
-                    'ee_read_others_default_tickets',
579
-                    'ee_edit_default_tickets',
580
-                    'ee_edit_others_default_tickets',
581
-                    'ee_delete_default_tickets',
582
-                    'ee_delete_others_default_tickets',
583
-                    // prices
584
-                    'ee_edit_default_price',
585
-                    'ee_edit_default_prices',
586
-                    'ee_delete_default_price',
587
-                    'ee_delete_default_prices',
588
-                    'ee_edit_default_price_type',
589
-                    'ee_edit_default_price_types',
590
-                    'ee_delete_default_price_type',
591
-                    'ee_delete_default_price_types',
592
-                    'ee_read_default_prices',
593
-                    'ee_read_default_price_types',
594
-                    // registration form
595
-                    'ee_edit_questions',
596
-                    'ee_edit_system_questions',
597
-                    'ee_read_questions',
598
-                    'ee_delete_questions',
599
-                    'ee_edit_question_groups',
600
-                    'ee_read_question_groups',
601
-                    'ee_edit_system_question_groups',
602
-                    'ee_delete_question_groups',
603
-                    // event_type taxonomy
604
-                    'ee_assign_event_type',
605
-                    'ee_manage_event_types',
606
-                    'ee_edit_event_type',
607
-                    'ee_delete_event_type',
608
-                ),
609
-            )
610
-        );
611
-    }
612
-
613
-
614
-    /**
615
-     * @return bool
616
-     * @throws EE_Error
617
-     */
618
-    private function setupCapabilitiesMap()
619
-    {
620
-        // if the initialization process hasn't even started, then we need to call init_caps()
621
-        if ($this->initialized === null) {
622
-            return $this->init_caps();
623
-        }
624
-        // unless resetting, get caps from db if we haven't already
625
-        $this->capabilities_map = $this->reset || ! empty($this->capabilities_map)
626
-            ? $this->capabilities_map
627
-            : get_option(self::option_name, array());
628
-        return true;
629
-    }
630
-
631
-
632
-    /**
633
-     * @param bool $update
634
-     * @return bool
635
-     */
636
-    private function updateCapabilitiesMap($update = true)
637
-    {
638
-        return $update ? update_option(self::option_name, $this->capabilities_map) : false;
639
-    }
640
-
641
-
642
-    /**
643
-     * Adds capabilities to roles.
644
-     *
645
-     * @since 4.9.42
646
-     * @param array $capabilities_to_add array of capabilities to add, indexed by roles.
647
-     *                                   Note that this should ONLY be called on activation hook
648
-     *                                   otherwise the caps will be added on every request.
649
-     * @return bool
650
-     * @throws \EE_Error
651
-     */
652
-    public function addCaps(array $capabilities_to_add)
653
-    {
654
-        // don't do anything if the capabilities map can not be initialized
655
-        if (! $this->setupCapabilitiesMap()) {
656
-            return false;
657
-        }
658
-        // and filter the array so others can get in on the fun during resets
659
-        $capabilities_to_add = apply_filters(
660
-            'FHEE__EE_Capabilities__addCaps__capabilities_to_add',
661
-            $capabilities_to_add,
662
-            $this->reset,
663
-            $this->capabilities_map
664
-        );
665
-        $update_capabilities_map = false;
666
-        // if not reset, see what caps are new for each role. if they're new, add them.
667
-        foreach ($capabilities_to_add as $role => $caps_for_role) {
668
-            if (is_array($caps_for_role)) {
669
-                foreach ($caps_for_role as $cap) {
670
-                    if (! $this->capHasBeenAddedToRole($role, $cap)
671
-                        && $this->add_cap_to_role($role, $cap, true, false)
672
-                    ) {
673
-                        $update_capabilities_map = true;
674
-                    }
675
-                }
676
-            }
677
-        }
678
-        // now let's just save the cap that has been set but only if there's been a change.
679
-        $updated = $this->updateCapabilitiesMap($update_capabilities_map);
680
-        $this->flushWpUser($updated);
681
-        do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated);
682
-        return $updated;
683
-    }
684
-
685
-
686
-    /**
687
-     * Loops through the capabilities map and removes the role caps specified by the incoming array
688
-     *
689
-     * @param array $caps_map map of capabilities to be removed (indexed by roles)
690
-     * @return bool
691
-     * @throws \EE_Error
692
-     */
693
-    public function removeCaps($caps_map)
694
-    {
695
-        // don't do anything if the capabilities map can not be initialized
696
-        if (! $this->setupCapabilitiesMap()) {
697
-            return false;
698
-        }
699
-        $update_capabilities_map = false;
700
-        foreach ($caps_map as $role => $caps_for_role) {
701
-            if (is_array($caps_for_role)) {
702
-                foreach ($caps_for_role as $cap) {
703
-                    if ($this->capHasBeenAddedToRole($role, $cap)
704
-                        && $this->remove_cap_from_role($role, $cap, false)
705
-                    ) {
706
-                        $update_capabilities_map = true;
707
-                    }
708
-                }
709
-            }
710
-        }
711
-        // maybe resave the caps
712
-        $updated = $this->updateCapabilitiesMap($update_capabilities_map);
713
-        $this->flushWpUser($updated);
714
-        return $updated;
715
-    }
716
-
717
-
718
-    /**
719
-     * This ensures that the WP User object cached on the $current_user global in WP has the latest capabilities from
720
-     * the roles on that user.
721
-     *
722
-     * @param bool $flush Default is to flush the WP_User object.  If false, then this method effectively does nothing.
723
-     */
724
-    private function flushWpUser($flush = true)
725
-    {
726
-        if ($flush) {
727
-            $user = wp_get_current_user();
728
-            if ($user instanceof WP_User) {
729
-                $user->get_role_caps();
730
-            }
731
-        }
732
-    }
733
-
734
-
735
-    /**
736
-     * This method sets a capability on a role.  Note this should only be done on activation, or if you have something
737
-     * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note.
738
-     * this is a wrapper for $wp_role->add_cap()
739
-     *
740
-     * @see   wp-includes/capabilities.php
741
-     * @since 4.5.0
742
-     * @param string|WP_Role $role  A WordPress role the capability is being added to
743
-     * @param string         $cap   The capability being added to the role
744
-     * @param bool           $grant Whether to grant access to this cap on this role.
745
-     * @param bool           $update_capabilities_map
746
-     * @return bool
747
-     * @throws \EE_Error
748
-     */
749
-    public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true)
750
-    {
751
-        // capture incoming value for $role because we may need it to create a new WP_Role
752
-        $orig_role = $role;
753
-        $role = $role instanceof WP_Role ? $role : get_role($role);
754
-        // if the role isn't available then we create it.
755
-        if (! $role instanceof WP_Role) {
756
-            // if a plugin wants to create a specific role name then they should create the role before
757
-            // EE_Capabilities does.  Otherwise this function will create the role name from the slug:
758
-            // - removes any `ee_` namespacing from the start of the slug.
759
-            // - replaces `_` with ` ` (empty space).
760
-            // - sentence case on the resulting string.
761
-            $role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role));
762
-            $role = add_role($orig_role, $role_label);
763
-        }
764
-        if ($role instanceof WP_Role) {
765
-            // don't do anything if the capabilities map can not be initialized
766
-            if (! $this->setupCapabilitiesMap()) {
767
-                return false;
768
-            }
769
-            if (! $this->capHasBeenAddedToRole($role->name, $cap)) {
770
-                $role->add_cap($cap, $grant);
771
-                $this->capabilities_map[ $role->name ][] = $cap;
772
-                $this->updateCapabilitiesMap($update_capabilities_map);
773
-                return true;
774
-            }
775
-        }
776
-        return false;
777
-    }
778
-
779
-
780
-    /**
781
-     * Functions similarly to add_cap_to_role except removes cap from given role.
782
-     * Wrapper for $wp_role->remove_cap()
783
-     *
784
-     * @see   wp-includes/capabilities.php
785
-     * @since 4.5.0
786
-     * @param string|WP_Role $role A WordPress role the capability is being removed from.
787
-     * @param string         $cap  The capability being removed
788
-     * @param bool           $update_capabilities_map
789
-     * @return bool
790
-     * @throws \EE_Error
791
-     */
792
-    public function remove_cap_from_role($role, $cap, $update_capabilities_map = true)
793
-    {
794
-        // don't do anything if the capabilities map can not be initialized
795
-        if (! $this->setupCapabilitiesMap()) {
796
-            return false;
797
-        }
798
-
799
-        $role = $role instanceof WP_Role ? $role : get_role($role);
800
-        if ($role instanceof WP_Role && $index = $this->capHasBeenAddedToRole($role->name, $cap, true)) {
801
-            $role->remove_cap($cap);
802
-            unset($this->capabilities_map[ $role->name ][ $index ]);
803
-            $this->updateCapabilitiesMap($update_capabilities_map);
804
-            return true;
805
-        }
806
-        return false;
807
-    }
808
-
809
-
810
-    /**
811
-     * @param string $role_name
812
-     * @param string $cap
813
-     * @param bool   $get_index
814
-     * @return bool|mixed
815
-     */
816
-    private function capHasBeenAddedToRole($role_name = '', $cap = '', $get_index = false)
817
-    {
818
-        if (isset($this->capabilities_map[ $role_name ])
819
-            && ($index = array_search($cap, $this->capabilities_map[ $role_name ], true)) !== false
820
-        ) {
821
-            return $get_index ? $index : true;
822
-        }
823
-        return false;
824
-    }
825
-
826
-
827
-    /**
828
-     * Wrapper for the native WP current_user_can() method.
829
-     * This is provided as a handy method for a couple things:
830
-     * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
831
-     * write those filters wherever current_user_can is called).
832
-     * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
833
-     *
834
-     * @since 4.5.0
835
-     *
836
-     * @param string $cap     The cap being checked.
837
-     * @param string $context The context where the current_user_can is being called from.
838
-     * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
839
-     *                        filters.
840
-     *
841
-     * @return bool  Whether user can or not.
842
-     */
843
-    public function current_user_can($cap, $context, $id = 0)
844
-    {
845
-        // apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
846
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id);
847
-        $filtered_cap = apply_filters(
848
-            'FHEE__EE_Capabilities__current_user_can__cap',
849
-            $filtered_cap,
850
-            $context,
851
-            $cap,
852
-            $id
853
-        );
854
-        return ! empty($id)
855
-            ? current_user_can($filtered_cap, $id)
856
-            : current_user_can($filtered_cap);
857
-    }
858
-
859
-
860
-    /**
861
-     * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class.
862
-     *
863
-     * @param int|WP_User $user    Either the user_id or a WP_User object
864
-     * @param string      $cap     The capability string being checked
865
-     * @param string      $context The context where the user_can is being called from (used in filters).
866
-     * @param int         $id      Optional. Id for item where user_can is being called from ( used in map_meta_cap()
867
-     *                             filters)
868
-     *
869
-     * @return bool Whether user can or not.
870
-     */
871
-    public function user_can($user, $cap, $context, $id = 0)
872
-    {
873
-        // apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
874
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id);
875
-        $filtered_cap = apply_filters(
876
-            'FHEE__EE_Capabilities__user_can__cap',
877
-            $filtered_cap,
878
-            $context,
879
-            $cap,
880
-            $user,
881
-            $id
882
-        );
883
-        return ! empty($id)
884
-            ? user_can($user, $filtered_cap, $id)
885
-            : user_can($user, $filtered_cap);
886
-    }
887
-
888
-
889
-    /**
890
-     * Wrapper for the native WP current_user_can_for_blog() method.
891
-     * This is provided as a handy method for a couple things:
892
-     * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
893
-     * write those filters wherever current_user_can is called).
894
-     * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
895
-     *
896
-     * @since 4.5.0
897
-     *
898
-     * @param int    $blog_id The blog id that is being checked for.
899
-     * @param string $cap     The cap being checked.
900
-     * @param string $context The context where the current_user_can is being called from.
901
-     * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
902
-     *                        filters.
903
-     *
904
-     * @return bool  Whether user can or not.
905
-     */
906
-    public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0)
907
-    {
908
-        $user_can = ! empty($id)
909
-            ? current_user_can_for_blog($blog_id, $cap, $id)
910
-            : current_user_can($blog_id, $cap);
911
-        // apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
912
-        $user_can = apply_filters(
913
-            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context,
914
-            $user_can,
915
-            $blog_id,
916
-            $cap,
917
-            $id
918
-        );
919
-        $user_can = apply_filters(
920
-            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can',
921
-            $user_can,
922
-            $context,
923
-            $blog_id,
924
-            $cap,
925
-            $id
926
-        );
927
-        return $user_can;
928
-    }
929
-
930
-
931
-    /**
932
-     * This helper method just returns an array of registered EE capabilities.
933
-     *
934
-     * @since 4.5.0
935
-     * @param string $role If empty then the entire role/capability map is returned.
936
-     *                     Otherwise just the capabilities for the given role are returned.
937
-     * @return array
938
-     * @throws EE_Error
939
-     */
940
-    public function get_ee_capabilities($role = 'administrator')
941
-    {
942
-        if (! $this->initialized) {
943
-            $this->init_caps();
944
-        }
945
-        if (empty($role)) {
946
-            return $this->capabilities_map;
947
-        }
948
-        return isset($this->capabilities_map[ $role ])
949
-            ? $this->capabilities_map[ $role ]
950
-            : array();
951
-    }
952
-
953
-
954
-    /**
955
-     * @deprecated 4.9.42
956
-     * @param bool  $reset      If you need to reset Event Espresso's capabilities,
957
-     *                          then please use the init_caps() method with the "$reset" parameter set to "true"
958
-     * @param array $caps_map   Optional.
959
-     *                          Can be used to send a custom map of roles and capabilities for setting them up.
960
-     *                          Note that this should ONLY be called on activation hook or some other one-time
961
-     *                          task otherwise the caps will be added on every request.
962
-     * @return void
963
-     * @throws EE_Error
964
-     */
965
-    public function init_role_caps($reset = false, $caps_map = array())
966
-    {
967
-        // If this method is called directly and reset is set as 'true',
968
-        // then display a doing it wrong notice, because we want resets to go through init_caps()
969
-        // to guarantee that everything is set up correctly.
970
-        // This prevents the capabilities map getting reset incorrectly by direct calls to this method.
971
-        if ($reset) {
972
-            EE_Error::doing_it_wrong(
973
-                __METHOD__,
974
-                sprintf(
975
-                    esc_html__(
976
-                        'The "%1$s" parameter for the "%2$s" method is deprecated. If you need to reset Event Espresso\'s capabilities, then please use the "%3$s" method with the "%1$s" parameter set to "%4$s".',
977
-                        'event_espresso'
978
-                    ),
979
-                    '$reset',
980
-                    __METHOD__ . '()',
981
-                    'EE_Capabilities::init_caps()',
982
-                    'true'
983
-                ),
984
-                '4.9.42',
985
-                '5.0.0'
986
-            );
987
-        }
988
-        $this->addCaps($caps_map);
989
-    }
17
+	/**
18
+	 * the name of the wp option used to store caps previously initialized
19
+	 */
20
+	const option_name = 'ee_caps_initialized';
21
+
22
+	/**
23
+	 * instance of EE_Capabilities object
24
+	 *
25
+	 * @var EE_Capabilities
26
+	 */
27
+	private static $_instance;
28
+
29
+
30
+	/**
31
+	 * This is a map of caps that correspond to a default WP_Role.
32
+	 * Array is indexed by Role and values are ee capabilities.
33
+	 *
34
+	 * @since 4.5.0
35
+	 *
36
+	 * @var array
37
+	 */
38
+	private $capabilities_map = array();
39
+
40
+	/**
41
+	 * This used to hold an array of EE_Meta_Capability_Map objects
42
+	 * that define the granular capabilities mapped to for a user depending on context.
43
+	 *
44
+	 * @var EE_Meta_Capability_Map[]
45
+	 */
46
+	private $_meta_caps = array();
47
+
48
+	/**
49
+	 * The internal $capabilities_map needs to be initialized before it can be used.
50
+	 * This flag tracks whether that has happened or not.
51
+	 * But for this to work, we need three states to indicate:
52
+	 *      initialization has not occurred at all
53
+	 *      initialization has started but is not complete
54
+	 *      initialization is complete
55
+	 * The reason this is needed is because the addCaps() method
56
+	 * normally requires the $capabilities_map to be initialized,
57
+	 * but is also used during the initialization process.
58
+	 * So:
59
+	 *      If initialized === null, init_caps() will be called before any other methods will run.
60
+	 *      If initialized === false, then init_caps() is in the process of running it's logic.
61
+	 *      If initialized === true, then init_caps() has completed the initialization process.
62
+	 *
63
+	 * @var boolean|null $initialized
64
+	 */
65
+	private $initialized;
66
+
67
+	/**
68
+	 * @var boolean $reset
69
+	 */
70
+	private $reset = false;
71
+
72
+
73
+	/**
74
+	 * singleton method used to instantiate class object
75
+	 *
76
+	 * @since 4.5.0
77
+	 *
78
+	 * @return EE_Capabilities
79
+	 */
80
+	public static function instance()
81
+	{
82
+		// check if instantiated, and if not do so.
83
+		if (! self::$_instance instanceof EE_Capabilities) {
84
+			self::$_instance = new self();
85
+		}
86
+		return self::$_instance;
87
+	}
88
+
89
+
90
+	/**
91
+	 * private constructor
92
+	 *
93
+	 * @since 4.5.0
94
+	 */
95
+	private function __construct()
96
+	{
97
+	}
98
+
99
+
100
+	/**
101
+	 * This delays the initialization of the capabilities class until EE_System core is loaded and ready.
102
+	 *
103
+	 * @param bool $reset allows for resetting the default capabilities saved on roles.  Note that this doesn't
104
+	 *                    actually REMOVE any capabilities from existing roles, it just resaves defaults roles and
105
+	 *                    ensures that they are up to date.
106
+	 *
107
+	 * @since 4.5.0
108
+	 * @return bool
109
+	 * @throws EE_Error
110
+	 */
111
+	public function init_caps($reset = false)
112
+	{
113
+		if (! EE_Maintenance_Mode::instance()->models_can_query()) {
114
+			return false;
115
+		}
116
+		$this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN);
117
+		// if reset, then completely delete the cache option and clear the $capabilities_map property.
118
+		if ($this->reset) {
119
+			$this->initialized = null;
120
+			$this->capabilities_map = array();
121
+			delete_option(self::option_name);
122
+		}
123
+		if ($this->initialized === null) {
124
+			$this->initialized = false;
125
+			do_action(
126
+				'AHEE__EE_Capabilities__init_caps__before_initialization',
127
+				$this->reset
128
+			);
129
+			$this->addCaps($this->_init_caps_map());
130
+			$this->_set_meta_caps();
131
+			do_action(
132
+				'AHEE__EE_Capabilities__init_caps__after_initialization',
133
+				$this->capabilities_map
134
+			);
135
+			$this->initialized = true;
136
+		}
137
+		// reset $this->reset so that it's not stuck on true if init_caps() gets called again
138
+		$this->reset = false;
139
+		return true;
140
+	}
141
+
142
+
143
+	/**
144
+	 * This sets the meta caps property.
145
+	 *
146
+	 * @since 4.5.0
147
+	 * @return void
148
+	 * @throws EE_Error
149
+	 */
150
+	private function _set_meta_caps()
151
+	{
152
+		// get default meta caps and filter the returned array
153
+		$this->_meta_caps = apply_filters(
154
+			'FHEE__EE_Capabilities___set_meta_caps__meta_caps',
155
+			$this->_get_default_meta_caps_array()
156
+		);
157
+		// add filter for map_meta_caps but only if models can query.
158
+		if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
159
+			add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4);
160
+		}
161
+	}
162
+
163
+
164
+	/**
165
+	 * This builds and returns the default meta_caps array only once.
166
+	 *
167
+	 * @since  4.8.28.rc.012
168
+	 * @return array
169
+	 * @throws EE_Error
170
+	 */
171
+	private function _get_default_meta_caps_array()
172
+	{
173
+		static $default_meta_caps = array();
174
+		// make sure we're only ever initializing the default _meta_caps array once if it's empty.
175
+		if (empty($default_meta_caps)) {
176
+			$default_meta_caps = array(
177
+				// edits
178
+				new EE_Meta_Capability_Map_Edit(
179
+					'ee_edit_event',
180
+					array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events')
181
+				),
182
+				new EE_Meta_Capability_Map_Edit(
183
+					'ee_edit_venue',
184
+					array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues')
185
+				),
186
+				new EE_Meta_Capability_Map_Edit(
187
+					'ee_edit_registration',
188
+					array('Registration', '', 'ee_edit_others_registrations', '')
189
+				),
190
+				new EE_Meta_Capability_Map_Edit(
191
+					'ee_edit_checkin',
192
+					array('Registration', '', 'ee_edit_others_checkins', '')
193
+				),
194
+				new EE_Meta_Capability_Map_Messages_Cap(
195
+					'ee_edit_message',
196
+					array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages')
197
+				),
198
+				new EE_Meta_Capability_Map_Edit(
199
+					'ee_edit_default_ticket',
200
+					array('Ticket', '', 'ee_edit_others_default_tickets', '')
201
+				),
202
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
203
+					'ee_edit_question',
204
+					array('Question', '', '', 'ee_edit_system_questions')
205
+				),
206
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
207
+					'ee_edit_question_group',
208
+					array('Question_Group', '', '', 'ee_edit_system_question_groups')
209
+				),
210
+				new EE_Meta_Capability_Map_Edit(
211
+					'ee_edit_payment_method',
212
+					array('Payment_Method', '', 'ee_edit_others_payment_methods', '')
213
+				),
214
+				// reads
215
+				new EE_Meta_Capability_Map_Read(
216
+					'ee_read_event',
217
+					array('Event', '', 'ee_read_others_events', 'ee_read_private_events')
218
+				),
219
+				new EE_Meta_Capability_Map_Read(
220
+					'ee_read_venue',
221
+					array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues')
222
+				),
223
+				new EE_Meta_Capability_Map_Read(
224
+					'ee_read_registration',
225
+					array('Registration', '', 'ee_read_others_registrations', '')
226
+				),
227
+				new EE_Meta_Capability_Map_Read(
228
+					'ee_read_checkin',
229
+					array('Registration', '', 'ee_read_others_checkins', '')
230
+				),
231
+				new EE_Meta_Capability_Map_Messages_Cap(
232
+					'ee_read_message',
233
+					array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages')
234
+				),
235
+				new EE_Meta_Capability_Map_Read(
236
+					'ee_read_default_ticket',
237
+					array('Ticket', '', 'ee_read_others_default_tickets', '')
238
+				),
239
+				new EE_Meta_Capability_Map_Read(
240
+					'ee_read_payment_method',
241
+					array('Payment_Method', '', 'ee_read_others_payment_methods', '')
242
+				),
243
+				// deletes
244
+				new EE_Meta_Capability_Map_Delete(
245
+					'ee_delete_event',
246
+					array(
247
+						'Event',
248
+						'ee_delete_published_events',
249
+						'ee_delete_others_events',
250
+						'ee_delete_private_events',
251
+					)
252
+				),
253
+				new EE_Meta_Capability_Map_Delete(
254
+					'ee_delete_venue',
255
+					array(
256
+						'Venue',
257
+						'ee_delete_published_venues',
258
+						'ee_delete_others_venues',
259
+						'ee_delete_private_venues',
260
+					)
261
+				),
262
+				new EE_Meta_Capability_Map_Delete(
263
+					'ee_delete_registration',
264
+					array('Registration', '', 'ee_delete_others_registrations', '')
265
+				),
266
+				new EE_Meta_Capability_Map_Delete(
267
+					'ee_delete_checkin',
268
+					array('Registration', '', 'ee_delete_others_checkins', '')
269
+				),
270
+				new EE_Meta_Capability_Map_Messages_Cap(
271
+					'ee_delete_message',
272
+					array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages')
273
+				),
274
+				new EE_Meta_Capability_Map_Delete(
275
+					'ee_delete_default_ticket',
276
+					array('Ticket', '', 'ee_delete_others_default_tickets', '')
277
+				),
278
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
279
+					'ee_delete_question',
280
+					array('Question', '', '', 'delete_system_questions')
281
+				),
282
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
283
+					'ee_delete_question_group',
284
+					array('Question_Group', '', '', 'delete_system_question_groups')
285
+				),
286
+				new EE_Meta_Capability_Map_Delete(
287
+					'ee_delete_payment_method',
288
+					array('Payment_Method', '', 'ee_delete_others_payment_methods', '')
289
+				),
290
+			);
291
+		}
292
+		return $default_meta_caps;
293
+	}
294
+
295
+
296
+	/**
297
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
298
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
299
+	 *
300
+	 * The actual logic is carried out by implementer classes in their definition of _map_meta_caps.
301
+	 *
302
+	 * @since 4.5.0
303
+	 * @see   wp-includes/capabilities.php
304
+	 *
305
+	 * @param array  $caps    actual users capabilities
306
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
307
+	 * @param int    $user_id The user id
308
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
309
+	 * @return array actual users capabilities
310
+	 * @throws EE_Error
311
+	 */
312
+	public function map_meta_caps($caps, $cap, $user_id, $args)
313
+	{
314
+		if (did_action('AHEE__EE_System__load_espresso_addons__complete')) {
315
+			// loop through our _meta_caps array
316
+			foreach ($this->_meta_caps as $meta_map) {
317
+				if (! $meta_map instanceof EE_Meta_Capability_Map) {
318
+					continue;
319
+				}
320
+				// don't load models if there is no object ID in the args
321
+				if (! empty($args[0])) {
322
+					$meta_map->ensure_is_model();
323
+				}
324
+				$caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args);
325
+			}
326
+		}
327
+		return $caps;
328
+	}
329
+
330
+
331
+	/**
332
+	 * This sets up and returns the initial capabilities map for Event Espresso
333
+	 * Note this array is filtered.
334
+	 * It is assumed that all available EE capabilities are assigned to the administrator role.
335
+	 *
336
+	 * @since 4.5.0
337
+	 *
338
+	 * @return array
339
+	 */
340
+	private function _init_caps_map()
341
+	{
342
+		return apply_filters(
343
+			'FHEE__EE_Capabilities__init_caps_map__caps',
344
+			array(
345
+				'administrator'           => array(
346
+					// basic access
347
+					'ee_read_ee',
348
+					// gateways
349
+					/**
350
+					 * note that with payment method capabilities, although we've implemented
351
+					 * capability mapping which will be used for accessing payment methods owned by
352
+					 * other users.  This is not fully implemented yet in the payment method ui.
353
+					 * Currently only the "plural" caps are in active use.
354
+					 * (Specific payment method caps are in use as well).
355
+					 **/
356
+					'ee_manage_gateways',
357
+					'ee_read_payment_methods',
358
+					'ee_read_others_payment_methods',
359
+					'ee_edit_payment_methods',
360
+					'ee_edit_others_payment_methods',
361
+					'ee_delete_payment_methods',
362
+					// events
363
+					'ee_publish_events',
364
+					'ee_read_private_events',
365
+					'ee_read_others_events',
366
+					'ee_read_events',
367
+					'ee_edit_events',
368
+					'ee_edit_published_events',
369
+					'ee_edit_others_events',
370
+					'ee_edit_private_events',
371
+					'ee_delete_published_events',
372
+					'ee_delete_private_events',
373
+					'ee_delete_events',
374
+					'ee_delete_others_events',
375
+					// event categories
376
+					'ee_manage_event_categories',
377
+					'ee_edit_event_category',
378
+					'ee_delete_event_category',
379
+					'ee_assign_event_category',
380
+					// venues
381
+					'ee_publish_venues',
382
+					'ee_read_venues',
383
+					'ee_read_others_venues',
384
+					'ee_read_private_venues',
385
+					'ee_edit_venues',
386
+					'ee_edit_others_venues',
387
+					'ee_edit_published_venues',
388
+					'ee_edit_private_venues',
389
+					'ee_delete_venues',
390
+					'ee_delete_others_venues',
391
+					'ee_delete_private_venues',
392
+					'ee_delete_published_venues',
393
+					// venue categories
394
+					'ee_manage_venue_categories',
395
+					'ee_edit_venue_category',
396
+					'ee_delete_venue_category',
397
+					'ee_assign_venue_category',
398
+					// contacts
399
+					'ee_read_contacts',
400
+					'ee_edit_contacts',
401
+					'ee_delete_contacts',
402
+					// registrations
403
+					'ee_read_registrations',
404
+					'ee_read_others_registrations',
405
+					'ee_edit_registrations',
406
+					'ee_edit_others_registrations',
407
+					'ee_delete_registrations',
408
+					// checkins
409
+					'ee_read_others_checkins',
410
+					'ee_read_checkins',
411
+					'ee_edit_checkins',
412
+					'ee_edit_others_checkins',
413
+					'ee_delete_checkins',
414
+					'ee_delete_others_checkins',
415
+					// transactions && payments
416
+					'ee_read_transaction',
417
+					'ee_read_transactions',
418
+					'ee_edit_payments',
419
+					'ee_delete_payments',
420
+					// messages
421
+					'ee_read_messages',
422
+					'ee_read_others_messages',
423
+					'ee_read_global_messages',
424
+					'ee_edit_global_messages',
425
+					'ee_edit_messages',
426
+					'ee_edit_others_messages',
427
+					'ee_delete_messages',
428
+					'ee_delete_others_messages',
429
+					'ee_delete_global_messages',
430
+					'ee_send_message',
431
+					// tickets
432
+					'ee_read_default_tickets',
433
+					'ee_read_others_default_tickets',
434
+					'ee_edit_default_tickets',
435
+					'ee_edit_others_default_tickets',
436
+					'ee_delete_default_tickets',
437
+					'ee_delete_others_default_tickets',
438
+					// prices
439
+					'ee_edit_default_price',
440
+					'ee_edit_default_prices',
441
+					'ee_delete_default_price',
442
+					'ee_delete_default_prices',
443
+					'ee_edit_default_price_type',
444
+					'ee_edit_default_price_types',
445
+					'ee_delete_default_price_type',
446
+					'ee_delete_default_price_types',
447
+					'ee_read_default_prices',
448
+					'ee_read_default_price_types',
449
+					// registration form
450
+					'ee_edit_questions',
451
+					'ee_edit_system_questions',
452
+					'ee_read_questions',
453
+					'ee_delete_questions',
454
+					'ee_edit_question_groups',
455
+					'ee_read_question_groups',
456
+					'ee_edit_system_question_groups',
457
+					'ee_delete_question_groups',
458
+					// event_type taxonomy
459
+					'ee_assign_event_type',
460
+					'ee_manage_event_types',
461
+					'ee_edit_event_type',
462
+					'ee_delete_event_type',
463
+				),
464
+				'ee_events_administrator' => array(
465
+					// core wp caps
466
+					'read',
467
+					'read_private_pages',
468
+					'read_private_posts',
469
+					'edit_users',
470
+					'edit_posts',
471
+					'edit_pages',
472
+					'edit_published_posts',
473
+					'edit_published_pages',
474
+					'edit_private_pages',
475
+					'edit_private_posts',
476
+					'edit_others_posts',
477
+					'edit_others_pages',
478
+					'publish_posts',
479
+					'publish_pages',
480
+					'delete_posts',
481
+					'delete_pages',
482
+					'delete_private_pages',
483
+					'delete_private_posts',
484
+					'delete_published_pages',
485
+					'delete_published_posts',
486
+					'delete_others_posts',
487
+					'delete_others_pages',
488
+					'manage_categories',
489
+					'manage_links',
490
+					'moderate_comments',
491
+					'unfiltered_html',
492
+					'upload_files',
493
+					'export',
494
+					'import',
495
+					'list_users',
496
+					'level_1', // required if user with this role shows up in author dropdowns
497
+					// basic ee access
498
+					'ee_read_ee',
499
+					// events
500
+					'ee_publish_events',
501
+					'ee_read_private_events',
502
+					'ee_read_others_events',
503
+					'ee_read_event',
504
+					'ee_read_events',
505
+					'ee_edit_event',
506
+					'ee_edit_events',
507
+					'ee_edit_published_events',
508
+					'ee_edit_others_events',
509
+					'ee_edit_private_events',
510
+					'ee_delete_published_events',
511
+					'ee_delete_private_events',
512
+					'ee_delete_event',
513
+					'ee_delete_events',
514
+					'ee_delete_others_events',
515
+					// event categories
516
+					'ee_manage_event_categories',
517
+					'ee_edit_event_category',
518
+					'ee_delete_event_category',
519
+					'ee_assign_event_category',
520
+					// venues
521
+					'ee_publish_venues',
522
+					'ee_read_venue',
523
+					'ee_read_venues',
524
+					'ee_read_others_venues',
525
+					'ee_read_private_venues',
526
+					'ee_edit_venue',
527
+					'ee_edit_venues',
528
+					'ee_edit_others_venues',
529
+					'ee_edit_published_venues',
530
+					'ee_edit_private_venues',
531
+					'ee_delete_venue',
532
+					'ee_delete_venues',
533
+					'ee_delete_others_venues',
534
+					'ee_delete_private_venues',
535
+					'ee_delete_published_venues',
536
+					// venue categories
537
+					'ee_manage_venue_categories',
538
+					'ee_edit_venue_category',
539
+					'ee_delete_venue_category',
540
+					'ee_assign_venue_category',
541
+					// contacts
542
+					'ee_read_contacts',
543
+					'ee_edit_contacts',
544
+					'ee_delete_contacts',
545
+					// registrations
546
+					'ee_read_registrations',
547
+					'ee_read_others_registrations',
548
+					'ee_edit_registration',
549
+					'ee_edit_registrations',
550
+					'ee_edit_others_registrations',
551
+					'ee_delete_registration',
552
+					'ee_delete_registrations',
553
+					// checkins
554
+					'ee_read_others_checkins',
555
+					'ee_read_checkins',
556
+					'ee_edit_checkins',
557
+					'ee_edit_others_checkins',
558
+					'ee_delete_checkins',
559
+					'ee_delete_others_checkins',
560
+					// transactions && payments
561
+					'ee_read_transaction',
562
+					'ee_read_transactions',
563
+					'ee_edit_payments',
564
+					'ee_delete_payments',
565
+					// messages
566
+					'ee_read_messages',
567
+					'ee_read_others_messages',
568
+					'ee_read_global_messages',
569
+					'ee_edit_global_messages',
570
+					'ee_edit_messages',
571
+					'ee_edit_others_messages',
572
+					'ee_delete_messages',
573
+					'ee_delete_others_messages',
574
+					'ee_delete_global_messages',
575
+					'ee_send_message',
576
+					// tickets
577
+					'ee_read_default_tickets',
578
+					'ee_read_others_default_tickets',
579
+					'ee_edit_default_tickets',
580
+					'ee_edit_others_default_tickets',
581
+					'ee_delete_default_tickets',
582
+					'ee_delete_others_default_tickets',
583
+					// prices
584
+					'ee_edit_default_price',
585
+					'ee_edit_default_prices',
586
+					'ee_delete_default_price',
587
+					'ee_delete_default_prices',
588
+					'ee_edit_default_price_type',
589
+					'ee_edit_default_price_types',
590
+					'ee_delete_default_price_type',
591
+					'ee_delete_default_price_types',
592
+					'ee_read_default_prices',
593
+					'ee_read_default_price_types',
594
+					// registration form
595
+					'ee_edit_questions',
596
+					'ee_edit_system_questions',
597
+					'ee_read_questions',
598
+					'ee_delete_questions',
599
+					'ee_edit_question_groups',
600
+					'ee_read_question_groups',
601
+					'ee_edit_system_question_groups',
602
+					'ee_delete_question_groups',
603
+					// event_type taxonomy
604
+					'ee_assign_event_type',
605
+					'ee_manage_event_types',
606
+					'ee_edit_event_type',
607
+					'ee_delete_event_type',
608
+				),
609
+			)
610
+		);
611
+	}
612
+
613
+
614
+	/**
615
+	 * @return bool
616
+	 * @throws EE_Error
617
+	 */
618
+	private function setupCapabilitiesMap()
619
+	{
620
+		// if the initialization process hasn't even started, then we need to call init_caps()
621
+		if ($this->initialized === null) {
622
+			return $this->init_caps();
623
+		}
624
+		// unless resetting, get caps from db if we haven't already
625
+		$this->capabilities_map = $this->reset || ! empty($this->capabilities_map)
626
+			? $this->capabilities_map
627
+			: get_option(self::option_name, array());
628
+		return true;
629
+	}
630
+
631
+
632
+	/**
633
+	 * @param bool $update
634
+	 * @return bool
635
+	 */
636
+	private function updateCapabilitiesMap($update = true)
637
+	{
638
+		return $update ? update_option(self::option_name, $this->capabilities_map) : false;
639
+	}
640
+
641
+
642
+	/**
643
+	 * Adds capabilities to roles.
644
+	 *
645
+	 * @since 4.9.42
646
+	 * @param array $capabilities_to_add array of capabilities to add, indexed by roles.
647
+	 *                                   Note that this should ONLY be called on activation hook
648
+	 *                                   otherwise the caps will be added on every request.
649
+	 * @return bool
650
+	 * @throws \EE_Error
651
+	 */
652
+	public function addCaps(array $capabilities_to_add)
653
+	{
654
+		// don't do anything if the capabilities map can not be initialized
655
+		if (! $this->setupCapabilitiesMap()) {
656
+			return false;
657
+		}
658
+		// and filter the array so others can get in on the fun during resets
659
+		$capabilities_to_add = apply_filters(
660
+			'FHEE__EE_Capabilities__addCaps__capabilities_to_add',
661
+			$capabilities_to_add,
662
+			$this->reset,
663
+			$this->capabilities_map
664
+		);
665
+		$update_capabilities_map = false;
666
+		// if not reset, see what caps are new for each role. if they're new, add them.
667
+		foreach ($capabilities_to_add as $role => $caps_for_role) {
668
+			if (is_array($caps_for_role)) {
669
+				foreach ($caps_for_role as $cap) {
670
+					if (! $this->capHasBeenAddedToRole($role, $cap)
671
+						&& $this->add_cap_to_role($role, $cap, true, false)
672
+					) {
673
+						$update_capabilities_map = true;
674
+					}
675
+				}
676
+			}
677
+		}
678
+		// now let's just save the cap that has been set but only if there's been a change.
679
+		$updated = $this->updateCapabilitiesMap($update_capabilities_map);
680
+		$this->flushWpUser($updated);
681
+		do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated);
682
+		return $updated;
683
+	}
684
+
685
+
686
+	/**
687
+	 * Loops through the capabilities map and removes the role caps specified by the incoming array
688
+	 *
689
+	 * @param array $caps_map map of capabilities to be removed (indexed by roles)
690
+	 * @return bool
691
+	 * @throws \EE_Error
692
+	 */
693
+	public function removeCaps($caps_map)
694
+	{
695
+		// don't do anything if the capabilities map can not be initialized
696
+		if (! $this->setupCapabilitiesMap()) {
697
+			return false;
698
+		}
699
+		$update_capabilities_map = false;
700
+		foreach ($caps_map as $role => $caps_for_role) {
701
+			if (is_array($caps_for_role)) {
702
+				foreach ($caps_for_role as $cap) {
703
+					if ($this->capHasBeenAddedToRole($role, $cap)
704
+						&& $this->remove_cap_from_role($role, $cap, false)
705
+					) {
706
+						$update_capabilities_map = true;
707
+					}
708
+				}
709
+			}
710
+		}
711
+		// maybe resave the caps
712
+		$updated = $this->updateCapabilitiesMap($update_capabilities_map);
713
+		$this->flushWpUser($updated);
714
+		return $updated;
715
+	}
716
+
717
+
718
+	/**
719
+	 * This ensures that the WP User object cached on the $current_user global in WP has the latest capabilities from
720
+	 * the roles on that user.
721
+	 *
722
+	 * @param bool $flush Default is to flush the WP_User object.  If false, then this method effectively does nothing.
723
+	 */
724
+	private function flushWpUser($flush = true)
725
+	{
726
+		if ($flush) {
727
+			$user = wp_get_current_user();
728
+			if ($user instanceof WP_User) {
729
+				$user->get_role_caps();
730
+			}
731
+		}
732
+	}
733
+
734
+
735
+	/**
736
+	 * This method sets a capability on a role.  Note this should only be done on activation, or if you have something
737
+	 * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note.
738
+	 * this is a wrapper for $wp_role->add_cap()
739
+	 *
740
+	 * @see   wp-includes/capabilities.php
741
+	 * @since 4.5.0
742
+	 * @param string|WP_Role $role  A WordPress role the capability is being added to
743
+	 * @param string         $cap   The capability being added to the role
744
+	 * @param bool           $grant Whether to grant access to this cap on this role.
745
+	 * @param bool           $update_capabilities_map
746
+	 * @return bool
747
+	 * @throws \EE_Error
748
+	 */
749
+	public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true)
750
+	{
751
+		// capture incoming value for $role because we may need it to create a new WP_Role
752
+		$orig_role = $role;
753
+		$role = $role instanceof WP_Role ? $role : get_role($role);
754
+		// if the role isn't available then we create it.
755
+		if (! $role instanceof WP_Role) {
756
+			// if a plugin wants to create a specific role name then they should create the role before
757
+			// EE_Capabilities does.  Otherwise this function will create the role name from the slug:
758
+			// - removes any `ee_` namespacing from the start of the slug.
759
+			// - replaces `_` with ` ` (empty space).
760
+			// - sentence case on the resulting string.
761
+			$role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role));
762
+			$role = add_role($orig_role, $role_label);
763
+		}
764
+		if ($role instanceof WP_Role) {
765
+			// don't do anything if the capabilities map can not be initialized
766
+			if (! $this->setupCapabilitiesMap()) {
767
+				return false;
768
+			}
769
+			if (! $this->capHasBeenAddedToRole($role->name, $cap)) {
770
+				$role->add_cap($cap, $grant);
771
+				$this->capabilities_map[ $role->name ][] = $cap;
772
+				$this->updateCapabilitiesMap($update_capabilities_map);
773
+				return true;
774
+			}
775
+		}
776
+		return false;
777
+	}
778
+
779
+
780
+	/**
781
+	 * Functions similarly to add_cap_to_role except removes cap from given role.
782
+	 * Wrapper for $wp_role->remove_cap()
783
+	 *
784
+	 * @see   wp-includes/capabilities.php
785
+	 * @since 4.5.0
786
+	 * @param string|WP_Role $role A WordPress role the capability is being removed from.
787
+	 * @param string         $cap  The capability being removed
788
+	 * @param bool           $update_capabilities_map
789
+	 * @return bool
790
+	 * @throws \EE_Error
791
+	 */
792
+	public function remove_cap_from_role($role, $cap, $update_capabilities_map = true)
793
+	{
794
+		// don't do anything if the capabilities map can not be initialized
795
+		if (! $this->setupCapabilitiesMap()) {
796
+			return false;
797
+		}
798
+
799
+		$role = $role instanceof WP_Role ? $role : get_role($role);
800
+		if ($role instanceof WP_Role && $index = $this->capHasBeenAddedToRole($role->name, $cap, true)) {
801
+			$role->remove_cap($cap);
802
+			unset($this->capabilities_map[ $role->name ][ $index ]);
803
+			$this->updateCapabilitiesMap($update_capabilities_map);
804
+			return true;
805
+		}
806
+		return false;
807
+	}
808
+
809
+
810
+	/**
811
+	 * @param string $role_name
812
+	 * @param string $cap
813
+	 * @param bool   $get_index
814
+	 * @return bool|mixed
815
+	 */
816
+	private function capHasBeenAddedToRole($role_name = '', $cap = '', $get_index = false)
817
+	{
818
+		if (isset($this->capabilities_map[ $role_name ])
819
+			&& ($index = array_search($cap, $this->capabilities_map[ $role_name ], true)) !== false
820
+		) {
821
+			return $get_index ? $index : true;
822
+		}
823
+		return false;
824
+	}
825
+
826
+
827
+	/**
828
+	 * Wrapper for the native WP current_user_can() method.
829
+	 * This is provided as a handy method for a couple things:
830
+	 * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
831
+	 * write those filters wherever current_user_can is called).
832
+	 * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
833
+	 *
834
+	 * @since 4.5.0
835
+	 *
836
+	 * @param string $cap     The cap being checked.
837
+	 * @param string $context The context where the current_user_can is being called from.
838
+	 * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
839
+	 *                        filters.
840
+	 *
841
+	 * @return bool  Whether user can or not.
842
+	 */
843
+	public function current_user_can($cap, $context, $id = 0)
844
+	{
845
+		// apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
846
+		$filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id);
847
+		$filtered_cap = apply_filters(
848
+			'FHEE__EE_Capabilities__current_user_can__cap',
849
+			$filtered_cap,
850
+			$context,
851
+			$cap,
852
+			$id
853
+		);
854
+		return ! empty($id)
855
+			? current_user_can($filtered_cap, $id)
856
+			: current_user_can($filtered_cap);
857
+	}
858
+
859
+
860
+	/**
861
+	 * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class.
862
+	 *
863
+	 * @param int|WP_User $user    Either the user_id or a WP_User object
864
+	 * @param string      $cap     The capability string being checked
865
+	 * @param string      $context The context where the user_can is being called from (used in filters).
866
+	 * @param int         $id      Optional. Id for item where user_can is being called from ( used in map_meta_cap()
867
+	 *                             filters)
868
+	 *
869
+	 * @return bool Whether user can or not.
870
+	 */
871
+	public function user_can($user, $cap, $context, $id = 0)
872
+	{
873
+		// apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
874
+		$filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id);
875
+		$filtered_cap = apply_filters(
876
+			'FHEE__EE_Capabilities__user_can__cap',
877
+			$filtered_cap,
878
+			$context,
879
+			$cap,
880
+			$user,
881
+			$id
882
+		);
883
+		return ! empty($id)
884
+			? user_can($user, $filtered_cap, $id)
885
+			: user_can($user, $filtered_cap);
886
+	}
887
+
888
+
889
+	/**
890
+	 * Wrapper for the native WP current_user_can_for_blog() method.
891
+	 * This is provided as a handy method for a couple things:
892
+	 * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
893
+	 * write those filters wherever current_user_can is called).
894
+	 * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
895
+	 *
896
+	 * @since 4.5.0
897
+	 *
898
+	 * @param int    $blog_id The blog id that is being checked for.
899
+	 * @param string $cap     The cap being checked.
900
+	 * @param string $context The context where the current_user_can is being called from.
901
+	 * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
902
+	 *                        filters.
903
+	 *
904
+	 * @return bool  Whether user can or not.
905
+	 */
906
+	public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0)
907
+	{
908
+		$user_can = ! empty($id)
909
+			? current_user_can_for_blog($blog_id, $cap, $id)
910
+			: current_user_can($blog_id, $cap);
911
+		// apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
912
+		$user_can = apply_filters(
913
+			'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context,
914
+			$user_can,
915
+			$blog_id,
916
+			$cap,
917
+			$id
918
+		);
919
+		$user_can = apply_filters(
920
+			'FHEE__EE_Capabilities__current_user_can_for_blog__user_can',
921
+			$user_can,
922
+			$context,
923
+			$blog_id,
924
+			$cap,
925
+			$id
926
+		);
927
+		return $user_can;
928
+	}
929
+
930
+
931
+	/**
932
+	 * This helper method just returns an array of registered EE capabilities.
933
+	 *
934
+	 * @since 4.5.0
935
+	 * @param string $role If empty then the entire role/capability map is returned.
936
+	 *                     Otherwise just the capabilities for the given role are returned.
937
+	 * @return array
938
+	 * @throws EE_Error
939
+	 */
940
+	public function get_ee_capabilities($role = 'administrator')
941
+	{
942
+		if (! $this->initialized) {
943
+			$this->init_caps();
944
+		}
945
+		if (empty($role)) {
946
+			return $this->capabilities_map;
947
+		}
948
+		return isset($this->capabilities_map[ $role ])
949
+			? $this->capabilities_map[ $role ]
950
+			: array();
951
+	}
952
+
953
+
954
+	/**
955
+	 * @deprecated 4.9.42
956
+	 * @param bool  $reset      If you need to reset Event Espresso's capabilities,
957
+	 *                          then please use the init_caps() method with the "$reset" parameter set to "true"
958
+	 * @param array $caps_map   Optional.
959
+	 *                          Can be used to send a custom map of roles and capabilities for setting them up.
960
+	 *                          Note that this should ONLY be called on activation hook or some other one-time
961
+	 *                          task otherwise the caps will be added on every request.
962
+	 * @return void
963
+	 * @throws EE_Error
964
+	 */
965
+	public function init_role_caps($reset = false, $caps_map = array())
966
+	{
967
+		// If this method is called directly and reset is set as 'true',
968
+		// then display a doing it wrong notice, because we want resets to go through init_caps()
969
+		// to guarantee that everything is set up correctly.
970
+		// This prevents the capabilities map getting reset incorrectly by direct calls to this method.
971
+		if ($reset) {
972
+			EE_Error::doing_it_wrong(
973
+				__METHOD__,
974
+				sprintf(
975
+					esc_html__(
976
+						'The "%1$s" parameter for the "%2$s" method is deprecated. If you need to reset Event Espresso\'s capabilities, then please use the "%3$s" method with the "%1$s" parameter set to "%4$s".',
977
+						'event_espresso'
978
+					),
979
+					'$reset',
980
+					__METHOD__ . '()',
981
+					'EE_Capabilities::init_caps()',
982
+					'true'
983
+				),
984
+				'4.9.42',
985
+				'5.0.0'
986
+			);
987
+		}
988
+		$this->addCaps($caps_map);
989
+	}
990 990
 }
991 991
 
992 992
 
@@ -1003,142 +1003,142 @@  discard block
 block discarded – undo
1003 1003
 abstract class EE_Meta_Capability_Map
1004 1004
 {
1005 1005
 
1006
-    public $meta_cap;
1007
-
1008
-    /**
1009
-     * @var EEM_Base
1010
-     */
1011
-    protected $_model;
1012
-
1013
-    protected $_model_name;
1014
-
1015
-    public $published_cap = '';
1016
-
1017
-    public $others_cap = '';
1018
-
1019
-    public $private_cap = '';
1020
-
1021
-
1022
-    /**
1023
-     * constructor.
1024
-     * Receives the setup arguments for the map.
1025
-     *
1026
-     * @since                        4.5.0
1027
-     *
1028
-     * @param string $meta_cap   What meta capability is this mapping.
1029
-     * @param array  $map_values array {
1030
-     *                           //array of values that MUST match a count of 4.  It's okay to send an empty string for
1031
-     *                           capabilities that don't get mapped to.
1032
-     *
1033
-     * @type         $map_values [0] string A string representing the model name. Required.  String's
1034
-     *                               should always be used when Menu Maps are registered via the
1035
-     *                               plugin API as models are not allowed to be instantiated when
1036
-     *                               in maintenance mode 2 (migrations).
1037
-     * @type         $map_values [1] string represents the capability used for published. Optional.
1038
-     * @type         $map_values [2] string represents the capability used for "others". Optional.
1039
-     * @type         $map_values [3] string represents the capability used for private. Optional.
1040
-     *                               }
1041
-     * @throws EE_Error
1042
-     */
1043
-    public function __construct($meta_cap, $map_values)
1044
-    {
1045
-        $this->meta_cap = $meta_cap;
1046
-        // verify there are four args in the $map_values array;
1047
-        if (count($map_values) !== 4) {
1048
-            throw new EE_Error(
1049
-                sprintf(
1050
-                    __(
1051
-                        'Incoming $map_values array should have a count of four values in it.  This is what was given: %s',
1052
-                        'event_espresso'
1053
-                    ),
1054
-                    '<br>' . print_r($map_values, true)
1055
-                )
1056
-            );
1057
-        }
1058
-        // set properties
1059
-        $this->_model = null;
1060
-        $this->_model_name = $map_values[0];
1061
-        $this->published_cap = (string) $map_values[1];
1062
-        $this->others_cap = (string) $map_values[2];
1063
-        $this->private_cap = (string) $map_values[3];
1064
-    }
1065
-
1066
-    /**
1067
-     * Makes it so this object stops filtering caps
1068
-     */
1069
-    public function remove_filters()
1070
-    {
1071
-        remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10);
1072
-    }
1073
-
1074
-
1075
-    /**
1076
-     * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class
1077
-     *
1078
-     * @since 4.5.0
1079
-     * @throws EE_Error
1080
-     *
1081
-     * @return void
1082
-     */
1083
-    public function ensure_is_model()
1084
-    {
1085
-        // is it already instantiated?
1086
-        if ($this->_model instanceof EEM_Base) {
1087
-            return;
1088
-        }
1089
-        // ensure model name is string
1090
-        $this->_model_name = (string) $this->_model_name;
1091
-        // error proof if the name has EEM in it
1092
-        $this->_model_name = str_replace('EEM', '', $this->_model_name);
1093
-        $this->_model = EE_Registry::instance()->load_model($this->_model_name);
1094
-        if (! $this->_model instanceof EEM_Base) {
1095
-            throw new EE_Error(
1096
-                sprintf(
1097
-                    __(
1098
-                        'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class.   Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s',
1099
-                        'event_espresso'
1100
-                    ),
1101
-                    get_class($this),
1102
-                    $this->_model
1103
-                )
1104
-            );
1105
-        }
1106
-    }
1107
-
1108
-
1109
-    /**
1110
-     *
1111
-     * @see   EE_Meta_Capability_Map::_map_meta_caps() for docs on params.
1112
-     * @since 4.6.x
1113
-     *
1114
-     * @param $caps
1115
-     * @param $cap
1116
-     * @param $user_id
1117
-     * @param $args
1118
-     *
1119
-     * @return array
1120
-     */
1121
-    public function map_meta_caps($caps, $cap, $user_id, $args)
1122
-    {
1123
-        return $this->_map_meta_caps($caps, $cap, $user_id, $args);
1124
-    }
1125
-
1126
-
1127
-    /**
1128
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1129
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1130
-     *
1131
-     * @since 4.5.0
1132
-     * @see   wp-includes/capabilities.php
1133
-     *
1134
-     * @param array  $caps    actual users capabilities
1135
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1136
-     * @param int    $user_id The user id
1137
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1138
-     *
1139
-     * @return array   actual users capabilities
1140
-     */
1141
-    abstract protected function _map_meta_caps($caps, $cap, $user_id, $args);
1006
+	public $meta_cap;
1007
+
1008
+	/**
1009
+	 * @var EEM_Base
1010
+	 */
1011
+	protected $_model;
1012
+
1013
+	protected $_model_name;
1014
+
1015
+	public $published_cap = '';
1016
+
1017
+	public $others_cap = '';
1018
+
1019
+	public $private_cap = '';
1020
+
1021
+
1022
+	/**
1023
+	 * constructor.
1024
+	 * Receives the setup arguments for the map.
1025
+	 *
1026
+	 * @since                        4.5.0
1027
+	 *
1028
+	 * @param string $meta_cap   What meta capability is this mapping.
1029
+	 * @param array  $map_values array {
1030
+	 *                           //array of values that MUST match a count of 4.  It's okay to send an empty string for
1031
+	 *                           capabilities that don't get mapped to.
1032
+	 *
1033
+	 * @type         $map_values [0] string A string representing the model name. Required.  String's
1034
+	 *                               should always be used when Menu Maps are registered via the
1035
+	 *                               plugin API as models are not allowed to be instantiated when
1036
+	 *                               in maintenance mode 2 (migrations).
1037
+	 * @type         $map_values [1] string represents the capability used for published. Optional.
1038
+	 * @type         $map_values [2] string represents the capability used for "others". Optional.
1039
+	 * @type         $map_values [3] string represents the capability used for private. Optional.
1040
+	 *                               }
1041
+	 * @throws EE_Error
1042
+	 */
1043
+	public function __construct($meta_cap, $map_values)
1044
+	{
1045
+		$this->meta_cap = $meta_cap;
1046
+		// verify there are four args in the $map_values array;
1047
+		if (count($map_values) !== 4) {
1048
+			throw new EE_Error(
1049
+				sprintf(
1050
+					__(
1051
+						'Incoming $map_values array should have a count of four values in it.  This is what was given: %s',
1052
+						'event_espresso'
1053
+					),
1054
+					'<br>' . print_r($map_values, true)
1055
+				)
1056
+			);
1057
+		}
1058
+		// set properties
1059
+		$this->_model = null;
1060
+		$this->_model_name = $map_values[0];
1061
+		$this->published_cap = (string) $map_values[1];
1062
+		$this->others_cap = (string) $map_values[2];
1063
+		$this->private_cap = (string) $map_values[3];
1064
+	}
1065
+
1066
+	/**
1067
+	 * Makes it so this object stops filtering caps
1068
+	 */
1069
+	public function remove_filters()
1070
+	{
1071
+		remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10);
1072
+	}
1073
+
1074
+
1075
+	/**
1076
+	 * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class
1077
+	 *
1078
+	 * @since 4.5.0
1079
+	 * @throws EE_Error
1080
+	 *
1081
+	 * @return void
1082
+	 */
1083
+	public function ensure_is_model()
1084
+	{
1085
+		// is it already instantiated?
1086
+		if ($this->_model instanceof EEM_Base) {
1087
+			return;
1088
+		}
1089
+		// ensure model name is string
1090
+		$this->_model_name = (string) $this->_model_name;
1091
+		// error proof if the name has EEM in it
1092
+		$this->_model_name = str_replace('EEM', '', $this->_model_name);
1093
+		$this->_model = EE_Registry::instance()->load_model($this->_model_name);
1094
+		if (! $this->_model instanceof EEM_Base) {
1095
+			throw new EE_Error(
1096
+				sprintf(
1097
+					__(
1098
+						'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class.   Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s',
1099
+						'event_espresso'
1100
+					),
1101
+					get_class($this),
1102
+					$this->_model
1103
+				)
1104
+			);
1105
+		}
1106
+	}
1107
+
1108
+
1109
+	/**
1110
+	 *
1111
+	 * @see   EE_Meta_Capability_Map::_map_meta_caps() for docs on params.
1112
+	 * @since 4.6.x
1113
+	 *
1114
+	 * @param $caps
1115
+	 * @param $cap
1116
+	 * @param $user_id
1117
+	 * @param $args
1118
+	 *
1119
+	 * @return array
1120
+	 */
1121
+	public function map_meta_caps($caps, $cap, $user_id, $args)
1122
+	{
1123
+		return $this->_map_meta_caps($caps, $cap, $user_id, $args);
1124
+	}
1125
+
1126
+
1127
+	/**
1128
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1129
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1130
+	 *
1131
+	 * @since 4.5.0
1132
+	 * @see   wp-includes/capabilities.php
1133
+	 *
1134
+	 * @param array  $caps    actual users capabilities
1135
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1136
+	 * @param int    $user_id The user id
1137
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1138
+	 *
1139
+	 * @return array   actual users capabilities
1140
+	 */
1141
+	abstract protected function _map_meta_caps($caps, $cap, $user_id, $args);
1142 1142
 }
1143 1143
 
1144 1144
 
@@ -1154,81 +1154,81 @@  discard block
 block discarded – undo
1154 1154
 class EE_Meta_Capability_Map_Edit extends EE_Meta_Capability_Map
1155 1155
 {
1156 1156
 
1157
-    /**
1158
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1159
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1160
-     *
1161
-     * @since 4.5.0
1162
-     * @see   wp-includes/capabilities.php
1163
-     *
1164
-     * @param array  $caps    actual users capabilities
1165
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1166
-     * @param int    $user_id The user id
1167
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1168
-     *
1169
-     * @return array   actual users capabilities
1170
-     */
1171
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1172
-    {
1173
-        // only process if we're checking our mapped_cap
1174
-        if ($cap !== $this->meta_cap) {
1175
-            return $caps;
1176
-        }
1177
-
1178
-        // okay it is a meta cap so let's first remove that cap from the $caps array.
1179
-        if (($key = array_search($cap, $caps)) !== false) {
1180
-            unset($caps[ $key ]);
1181
-        }
1182
-
1183
-        // cast $user_id to int for later explicit comparisons
1184
-        $user_id = (int) $user_id;
1185
-
1186
-        /** @var EE_Base_Class $obj */
1187
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1188
-        // if no obj then let's just do cap
1189
-        if (! $obj instanceof EE_Base_Class) {
1190
-            $caps[] = 'do_not_allow';
1191
-            return $caps;
1192
-        }
1193
-        $caps[] = $cap . 's';
1194
-        if ($obj instanceof EE_CPT_Base) {
1195
-            // if the item author is set and the user is the author...
1196
-            if ($obj->wp_user() && $user_id === $obj->wp_user()) {
1197
-                // if obj is published...
1198
-                if ($obj->status() === 'publish') {
1199
-                    $caps[] = $this->published_cap;
1200
-                }
1201
-            } else {
1202
-                // the user is trying to edit someone else's obj
1203
-                if (! empty($this->others_cap)) {
1204
-                    $caps[] = $this->others_cap;
1205
-                }
1206
-                if (! empty($this->published_cap) && $obj->status() === 'publish') {
1207
-                    $caps[] = $this->published_cap;
1208
-                } elseif (! empty($this->private_cap) && $obj->status() === 'private') {
1209
-                    $caps[] = $this->private_cap;
1210
-                }
1211
-            }
1212
-        } else {
1213
-            // not a cpt object so handled differently
1214
-            $has_cap = false;
1215
-            try {
1216
-                $has_cap = method_exists($obj, 'wp_user')
1217
-                           && $obj->wp_user()
1218
-                           && $obj->wp_user() === $user_id;
1219
-            } catch (Exception $e) {
1220
-                if (WP_DEBUG) {
1221
-                    EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1222
-                }
1223
-            }
1224
-            if (! $has_cap) {
1225
-                if (! empty($this->others_cap)) {
1226
-                    $caps[] = $this->others_cap;
1227
-                }
1228
-            }
1229
-        }
1230
-        return $caps;
1231
-    }
1157
+	/**
1158
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1159
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1160
+	 *
1161
+	 * @since 4.5.0
1162
+	 * @see   wp-includes/capabilities.php
1163
+	 *
1164
+	 * @param array  $caps    actual users capabilities
1165
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1166
+	 * @param int    $user_id The user id
1167
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1168
+	 *
1169
+	 * @return array   actual users capabilities
1170
+	 */
1171
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1172
+	{
1173
+		// only process if we're checking our mapped_cap
1174
+		if ($cap !== $this->meta_cap) {
1175
+			return $caps;
1176
+		}
1177
+
1178
+		// okay it is a meta cap so let's first remove that cap from the $caps array.
1179
+		if (($key = array_search($cap, $caps)) !== false) {
1180
+			unset($caps[ $key ]);
1181
+		}
1182
+
1183
+		// cast $user_id to int for later explicit comparisons
1184
+		$user_id = (int) $user_id;
1185
+
1186
+		/** @var EE_Base_Class $obj */
1187
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1188
+		// if no obj then let's just do cap
1189
+		if (! $obj instanceof EE_Base_Class) {
1190
+			$caps[] = 'do_not_allow';
1191
+			return $caps;
1192
+		}
1193
+		$caps[] = $cap . 's';
1194
+		if ($obj instanceof EE_CPT_Base) {
1195
+			// if the item author is set and the user is the author...
1196
+			if ($obj->wp_user() && $user_id === $obj->wp_user()) {
1197
+				// if obj is published...
1198
+				if ($obj->status() === 'publish') {
1199
+					$caps[] = $this->published_cap;
1200
+				}
1201
+			} else {
1202
+				// the user is trying to edit someone else's obj
1203
+				if (! empty($this->others_cap)) {
1204
+					$caps[] = $this->others_cap;
1205
+				}
1206
+				if (! empty($this->published_cap) && $obj->status() === 'publish') {
1207
+					$caps[] = $this->published_cap;
1208
+				} elseif (! empty($this->private_cap) && $obj->status() === 'private') {
1209
+					$caps[] = $this->private_cap;
1210
+				}
1211
+			}
1212
+		} else {
1213
+			// not a cpt object so handled differently
1214
+			$has_cap = false;
1215
+			try {
1216
+				$has_cap = method_exists($obj, 'wp_user')
1217
+						   && $obj->wp_user()
1218
+						   && $obj->wp_user() === $user_id;
1219
+			} catch (Exception $e) {
1220
+				if (WP_DEBUG) {
1221
+					EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1222
+				}
1223
+			}
1224
+			if (! $has_cap) {
1225
+				if (! empty($this->others_cap)) {
1226
+					$caps[] = $this->others_cap;
1227
+				}
1228
+			}
1229
+		}
1230
+		return $caps;
1231
+	}
1232 1232
 }
1233 1233
 
1234 1234
 
@@ -1245,24 +1245,24 @@  discard block
 block discarded – undo
1245 1245
 class EE_Meta_Capability_Map_Delete extends EE_Meta_Capability_Map_Edit
1246 1246
 {
1247 1247
 
1248
-    /**
1249
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1250
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1251
-     *
1252
-     * @since 4.5.0
1253
-     * @see   wp-includes/capabilities.php
1254
-     *
1255
-     * @param array  $caps    actual users capabilities
1256
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1257
-     * @param int    $user_id The user id
1258
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1259
-     *
1260
-     * @return array   actual users capabilities
1261
-     */
1262
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1263
-    {
1264
-        return parent::_map_meta_caps($caps, $cap, $user_id, $args);
1265
-    }
1248
+	/**
1249
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1250
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1251
+	 *
1252
+	 * @since 4.5.0
1253
+	 * @see   wp-includes/capabilities.php
1254
+	 *
1255
+	 * @param array  $caps    actual users capabilities
1256
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1257
+	 * @param int    $user_id The user id
1258
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1259
+	 *
1260
+	 * @return array   actual users capabilities
1261
+	 */
1262
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1263
+	{
1264
+		return parent::_map_meta_caps($caps, $cap, $user_id, $args);
1265
+	}
1266 1266
 }
1267 1267
 
1268 1268
 
@@ -1278,85 +1278,85 @@  discard block
 block discarded – undo
1278 1278
 class EE_Meta_Capability_Map_Read extends EE_Meta_Capability_Map
1279 1279
 {
1280 1280
 
1281
-    /**
1282
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1283
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1284
-     *
1285
-     * @since 4.5.0
1286
-     * @see   wp-includes/capabilities.php
1287
-     *
1288
-     * @param array  $caps    actual users capabilities
1289
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1290
-     * @param int    $user_id The user id
1291
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1292
-     *
1293
-     * @return array   actual users capabilities
1294
-     */
1295
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1296
-    {
1297
-        // only process if we're checking our mapped cap;
1298
-        if ($cap !== $this->meta_cap) {
1299
-            return $caps;
1300
-        }
1301
-
1302
-        // okay it is a meta cap so let's first remove that cap from the $caps array.
1303
-        if (($key = array_search($cap, $caps)) !== false) {
1304
-            unset($caps[ $key ]);
1305
-        }
1306
-
1307
-        // cast $user_id to int for later explicit comparisons
1308
-        $user_id = (int) $user_id;
1309
-
1310
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1311
-        // if no obj then let's just do cap
1312
-        if (! $obj instanceof EE_Base_Class) {
1313
-            $caps[] = 'do_not_allow';
1314
-            return $caps;
1315
-        }
1316
-
1317
-        $caps[] = $cap . 's';
1318
-        if ($obj instanceof EE_CPT_Base) {
1319
-            $status_obj = get_post_status_object($obj->status());
1320
-            if ($status_obj->public) {
1321
-                return $caps;
1322
-            }
1323
-            // if the item author is set and the user is not the author...
1324
-            if ($obj->wp_user() && $obj->wp_user() !== $user_id) {
1325
-                if (! empty($this->others_cap)) {
1326
-                    $caps[] = $this->others_cap;
1327
-                }
1328
-            }
1329
-            // yes this means that if users created the private post, they are able to see it regardless of private cap.
1330
-            if ($status_obj->private
1331
-                && ! empty($this->private_cap)
1332
-                && $obj->wp_user() !== $user_id
1333
-            ) {
1334
-                // the user is trying to view a private object for an object they don't own.
1335
-                $caps[] = $this->private_cap;
1336
-            }
1337
-        } else {
1338
-            // not a cpt object so handled differently
1339
-            $has_cap = false;
1340
-            try {
1341
-                $has_cap = method_exists($obj, 'wp_user')
1342
-                           && $obj->wp_user()
1343
-                           && $obj->wp_user() === $user_id;
1344
-            } catch (Exception $e) {
1345
-                if (WP_DEBUG) {
1346
-                    EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1347
-                }
1348
-            }
1349
-            if (! $has_cap) {
1350
-                if (! empty($this->private_cap)) {
1351
-                    $caps[] = $this->private_cap;
1352
-                }
1353
-                if (! empty($this->others_cap)) {
1354
-                    $caps[] = $this->others_cap;
1355
-                }
1356
-            }
1357
-        }
1358
-        return $caps;
1359
-    }
1281
+	/**
1282
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1283
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1284
+	 *
1285
+	 * @since 4.5.0
1286
+	 * @see   wp-includes/capabilities.php
1287
+	 *
1288
+	 * @param array  $caps    actual users capabilities
1289
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1290
+	 * @param int    $user_id The user id
1291
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1292
+	 *
1293
+	 * @return array   actual users capabilities
1294
+	 */
1295
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1296
+	{
1297
+		// only process if we're checking our mapped cap;
1298
+		if ($cap !== $this->meta_cap) {
1299
+			return $caps;
1300
+		}
1301
+
1302
+		// okay it is a meta cap so let's first remove that cap from the $caps array.
1303
+		if (($key = array_search($cap, $caps)) !== false) {
1304
+			unset($caps[ $key ]);
1305
+		}
1306
+
1307
+		// cast $user_id to int for later explicit comparisons
1308
+		$user_id = (int) $user_id;
1309
+
1310
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1311
+		// if no obj then let's just do cap
1312
+		if (! $obj instanceof EE_Base_Class) {
1313
+			$caps[] = 'do_not_allow';
1314
+			return $caps;
1315
+		}
1316
+
1317
+		$caps[] = $cap . 's';
1318
+		if ($obj instanceof EE_CPT_Base) {
1319
+			$status_obj = get_post_status_object($obj->status());
1320
+			if ($status_obj->public) {
1321
+				return $caps;
1322
+			}
1323
+			// if the item author is set and the user is not the author...
1324
+			if ($obj->wp_user() && $obj->wp_user() !== $user_id) {
1325
+				if (! empty($this->others_cap)) {
1326
+					$caps[] = $this->others_cap;
1327
+				}
1328
+			}
1329
+			// yes this means that if users created the private post, they are able to see it regardless of private cap.
1330
+			if ($status_obj->private
1331
+				&& ! empty($this->private_cap)
1332
+				&& $obj->wp_user() !== $user_id
1333
+			) {
1334
+				// the user is trying to view a private object for an object they don't own.
1335
+				$caps[] = $this->private_cap;
1336
+			}
1337
+		} else {
1338
+			// not a cpt object so handled differently
1339
+			$has_cap = false;
1340
+			try {
1341
+				$has_cap = method_exists($obj, 'wp_user')
1342
+						   && $obj->wp_user()
1343
+						   && $obj->wp_user() === $user_id;
1344
+			} catch (Exception $e) {
1345
+				if (WP_DEBUG) {
1346
+					EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1347
+				}
1348
+			}
1349
+			if (! $has_cap) {
1350
+				if (! empty($this->private_cap)) {
1351
+					$caps[] = $this->private_cap;
1352
+				}
1353
+				if (! empty($this->others_cap)) {
1354
+					$caps[] = $this->others_cap;
1355
+				}
1356
+			}
1357
+		}
1358
+		return $caps;
1359
+	}
1360 1360
 }
1361 1361
 
1362 1362
 
@@ -1373,56 +1373,56 @@  discard block
 block discarded – undo
1373 1373
 class EE_Meta_Capability_Map_Messages_Cap extends EE_Meta_Capability_Map
1374 1374
 {
1375 1375
 
1376
-    /**
1377
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1378
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1379
-     *
1380
-     * @since 4.5.0
1381
-     * @see   wp-includes/capabilities.php
1382
-     *
1383
-     * @param array  $caps    actual users capabilities
1384
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1385
-     * @param int    $user_id The user id
1386
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1387
-     *
1388
-     * @return array   actual users capabilities
1389
-     */
1390
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1391
-    {
1392
-        // only process if we're checking our mapped_cap
1393
-        if ($cap !== $this->meta_cap) {
1394
-            return $caps;
1395
-        }
1396
-
1397
-        // okay it is a meta cap so let's first remove that cap from the $caps array.
1398
-        if (($key = array_search($cap, $caps)) !== false) {
1399
-            unset($caps[ $key ]);
1400
-        }
1401
-
1402
-        // cast $user_id to int for later explicit comparisons
1403
-        $user_id = (int) $user_id;
1404
-
1405
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1406
-        // if no obj then let's just do cap
1407
-        if (! $obj instanceof EE_Message_Template_Group) {
1408
-            $caps[] = 'do_not_allow';
1409
-            return $caps;
1410
-        }
1411
-        $caps[] = $cap . 's';
1412
-        $is_global = $obj->is_global();
1413
-        if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1414
-            if ($is_global) {
1415
-                $caps[] = $this->private_cap;
1416
-            }
1417
-        } else {
1418
-            if ($is_global) {
1419
-                $caps[] = $this->private_cap;
1420
-            } else {
1421
-                $caps[] = $this->others_cap;
1422
-            }
1423
-        }
1424
-        return $caps;
1425
-    }
1376
+	/**
1377
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1378
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1379
+	 *
1380
+	 * @since 4.5.0
1381
+	 * @see   wp-includes/capabilities.php
1382
+	 *
1383
+	 * @param array  $caps    actual users capabilities
1384
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1385
+	 * @param int    $user_id The user id
1386
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1387
+	 *
1388
+	 * @return array   actual users capabilities
1389
+	 */
1390
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1391
+	{
1392
+		// only process if we're checking our mapped_cap
1393
+		if ($cap !== $this->meta_cap) {
1394
+			return $caps;
1395
+		}
1396
+
1397
+		// okay it is a meta cap so let's first remove that cap from the $caps array.
1398
+		if (($key = array_search($cap, $caps)) !== false) {
1399
+			unset($caps[ $key ]);
1400
+		}
1401
+
1402
+		// cast $user_id to int for later explicit comparisons
1403
+		$user_id = (int) $user_id;
1404
+
1405
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1406
+		// if no obj then let's just do cap
1407
+		if (! $obj instanceof EE_Message_Template_Group) {
1408
+			$caps[] = 'do_not_allow';
1409
+			return $caps;
1410
+		}
1411
+		$caps[] = $cap . 's';
1412
+		$is_global = $obj->is_global();
1413
+		if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1414
+			if ($is_global) {
1415
+				$caps[] = $this->private_cap;
1416
+			}
1417
+		} else {
1418
+			if ($is_global) {
1419
+				$caps[] = $this->private_cap;
1420
+			} else {
1421
+				$caps[] = $this->others_cap;
1422
+			}
1423
+		}
1424
+		return $caps;
1425
+	}
1426 1426
 }
1427 1427
 
1428 1428
 
@@ -1439,40 +1439,40 @@  discard block
 block discarded – undo
1439 1439
 class EE_Meta_Capability_Map_Registration_Form_Cap extends EE_Meta_Capability_Map
1440 1440
 {
1441 1441
 
1442
-    /**
1443
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1444
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1445
-     *
1446
-     * @since 4.5.0
1447
-     * @see   wp-includes/capabilities.php
1448
-     * @param array  $caps    actual users capabilities
1449
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1450
-     * @param int    $user_id The user id
1451
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1452
-     * @return array   actual users capabilities
1453
-     */
1454
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1455
-    {
1456
-        // only process if we're checking our mapped_cap
1457
-        if ($cap !== $this->meta_cap) {
1458
-            return $caps;
1459
-        }
1460
-        // okay it is a meta cap so let's first remove that cap from the $caps array.
1461
-        if (($key = array_search($cap, $caps)) !== false) {
1462
-            unset($caps[ $key ]);
1463
-        }
1464
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1465
-        // if no obj then let's just do cap
1466
-        if (! $obj instanceof EE_Base_Class) {
1467
-            $caps[] = 'do_not_allow';
1468
-            return $caps;
1469
-        }
1470
-        $caps[] = $cap . 's';
1471
-        $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false;
1472
-        $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system;
1473
-        if ($is_system) {
1474
-            $caps[] = $this->private_cap;
1475
-        }
1476
-        return $caps;
1477
-    }
1442
+	/**
1443
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1444
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1445
+	 *
1446
+	 * @since 4.5.0
1447
+	 * @see   wp-includes/capabilities.php
1448
+	 * @param array  $caps    actual users capabilities
1449
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1450
+	 * @param int    $user_id The user id
1451
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1452
+	 * @return array   actual users capabilities
1453
+	 */
1454
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1455
+	{
1456
+		// only process if we're checking our mapped_cap
1457
+		if ($cap !== $this->meta_cap) {
1458
+			return $caps;
1459
+		}
1460
+		// okay it is a meta cap so let's first remove that cap from the $caps array.
1461
+		if (($key = array_search($cap, $caps)) !== false) {
1462
+			unset($caps[ $key ]);
1463
+		}
1464
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1465
+		// if no obj then let's just do cap
1466
+		if (! $obj instanceof EE_Base_Class) {
1467
+			$caps[] = 'do_not_allow';
1468
+			return $caps;
1469
+		}
1470
+		$caps[] = $cap . 's';
1471
+		$is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false;
1472
+		$is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system;
1473
+		if ($is_system) {
1474
+			$caps[] = $this->private_cap;
1475
+		}
1476
+		return $caps;
1477
+	}
1478 1478
 }
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
     public static function instance()
81 81
     {
82 82
         // check if instantiated, and if not do so.
83
-        if (! self::$_instance instanceof EE_Capabilities) {
83
+        if ( ! self::$_instance instanceof EE_Capabilities) {
84 84
             self::$_instance = new self();
85 85
         }
86 86
         return self::$_instance;
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
      */
111 111
     public function init_caps($reset = false)
112 112
     {
113
-        if (! EE_Maintenance_Mode::instance()->models_can_query()) {
113
+        if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
114 114
             return false;
115 115
         }
116 116
         $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN);
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
             $this->_get_default_meta_caps_array()
156 156
         );
157 157
         // add filter for map_meta_caps but only if models can query.
158
-        if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
158
+        if ( ! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
159 159
             add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4);
160 160
         }
161 161
     }
@@ -314,11 +314,11 @@  discard block
 block discarded – undo
314 314
         if (did_action('AHEE__EE_System__load_espresso_addons__complete')) {
315 315
             // loop through our _meta_caps array
316 316
             foreach ($this->_meta_caps as $meta_map) {
317
-                if (! $meta_map instanceof EE_Meta_Capability_Map) {
317
+                if ( ! $meta_map instanceof EE_Meta_Capability_Map) {
318 318
                     continue;
319 319
                 }
320 320
                 // don't load models if there is no object ID in the args
321
-                if (! empty($args[0])) {
321
+                if ( ! empty($args[0])) {
322 322
                     $meta_map->ensure_is_model();
323 323
                 }
324 324
                 $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args);
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
     public function addCaps(array $capabilities_to_add)
653 653
     {
654 654
         // don't do anything if the capabilities map can not be initialized
655
-        if (! $this->setupCapabilitiesMap()) {
655
+        if ( ! $this->setupCapabilitiesMap()) {
656 656
             return false;
657 657
         }
658 658
         // and filter the array so others can get in on the fun during resets
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
         foreach ($capabilities_to_add as $role => $caps_for_role) {
668 668
             if (is_array($caps_for_role)) {
669 669
                 foreach ($caps_for_role as $cap) {
670
-                    if (! $this->capHasBeenAddedToRole($role, $cap)
670
+                    if ( ! $this->capHasBeenAddedToRole($role, $cap)
671 671
                         && $this->add_cap_to_role($role, $cap, true, false)
672 672
                     ) {
673 673
                         $update_capabilities_map = true;
@@ -693,7 +693,7 @@  discard block
 block discarded – undo
693 693
     public function removeCaps($caps_map)
694 694
     {
695 695
         // don't do anything if the capabilities map can not be initialized
696
-        if (! $this->setupCapabilitiesMap()) {
696
+        if ( ! $this->setupCapabilitiesMap()) {
697 697
             return false;
698 698
         }
699 699
         $update_capabilities_map = false;
@@ -752,7 +752,7 @@  discard block
 block discarded – undo
752 752
         $orig_role = $role;
753 753
         $role = $role instanceof WP_Role ? $role : get_role($role);
754 754
         // if the role isn't available then we create it.
755
-        if (! $role instanceof WP_Role) {
755
+        if ( ! $role instanceof WP_Role) {
756 756
             // if a plugin wants to create a specific role name then they should create the role before
757 757
             // EE_Capabilities does.  Otherwise this function will create the role name from the slug:
758 758
             // - removes any `ee_` namespacing from the start of the slug.
@@ -763,12 +763,12 @@  discard block
 block discarded – undo
763 763
         }
764 764
         if ($role instanceof WP_Role) {
765 765
             // don't do anything if the capabilities map can not be initialized
766
-            if (! $this->setupCapabilitiesMap()) {
766
+            if ( ! $this->setupCapabilitiesMap()) {
767 767
                 return false;
768 768
             }
769
-            if (! $this->capHasBeenAddedToRole($role->name, $cap)) {
769
+            if ( ! $this->capHasBeenAddedToRole($role->name, $cap)) {
770 770
                 $role->add_cap($cap, $grant);
771
-                $this->capabilities_map[ $role->name ][] = $cap;
771
+                $this->capabilities_map[$role->name][] = $cap;
772 772
                 $this->updateCapabilitiesMap($update_capabilities_map);
773 773
                 return true;
774 774
             }
@@ -792,14 +792,14 @@  discard block
 block discarded – undo
792 792
     public function remove_cap_from_role($role, $cap, $update_capabilities_map = true)
793 793
     {
794 794
         // don't do anything if the capabilities map can not be initialized
795
-        if (! $this->setupCapabilitiesMap()) {
795
+        if ( ! $this->setupCapabilitiesMap()) {
796 796
             return false;
797 797
         }
798 798
 
799 799
         $role = $role instanceof WP_Role ? $role : get_role($role);
800 800
         if ($role instanceof WP_Role && $index = $this->capHasBeenAddedToRole($role->name, $cap, true)) {
801 801
             $role->remove_cap($cap);
802
-            unset($this->capabilities_map[ $role->name ][ $index ]);
802
+            unset($this->capabilities_map[$role->name][$index]);
803 803
             $this->updateCapabilitiesMap($update_capabilities_map);
804 804
             return true;
805 805
         }
@@ -815,8 +815,8 @@  discard block
 block discarded – undo
815 815
      */
816 816
     private function capHasBeenAddedToRole($role_name = '', $cap = '', $get_index = false)
817 817
     {
818
-        if (isset($this->capabilities_map[ $role_name ])
819
-            && ($index = array_search($cap, $this->capabilities_map[ $role_name ], true)) !== false
818
+        if (isset($this->capabilities_map[$role_name])
819
+            && ($index = array_search($cap, $this->capabilities_map[$role_name], true)) !== false
820 820
         ) {
821 821
             return $get_index ? $index : true;
822 822
         }
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
     public function current_user_can($cap, $context, $id = 0)
844 844
     {
845 845
         // apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
846
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id);
846
+        $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__'.$context, $cap, $id);
847 847
         $filtered_cap = apply_filters(
848 848
             'FHEE__EE_Capabilities__current_user_can__cap',
849 849
             $filtered_cap,
@@ -871,7 +871,7 @@  discard block
 block discarded – undo
871 871
     public function user_can($user, $cap, $context, $id = 0)
872 872
     {
873 873
         // apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
874
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id);
874
+        $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__'.$context, $cap, $user, $id);
875 875
         $filtered_cap = apply_filters(
876 876
             'FHEE__EE_Capabilities__user_can__cap',
877 877
             $filtered_cap,
@@ -910,7 +910,7 @@  discard block
 block discarded – undo
910 910
             : current_user_can($blog_id, $cap);
911 911
         // apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
912 912
         $user_can = apply_filters(
913
-            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context,
913
+            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__'.$context,
914 914
             $user_can,
915 915
             $blog_id,
916 916
             $cap,
@@ -939,14 +939,14 @@  discard block
 block discarded – undo
939 939
      */
940 940
     public function get_ee_capabilities($role = 'administrator')
941 941
     {
942
-        if (! $this->initialized) {
942
+        if ( ! $this->initialized) {
943 943
             $this->init_caps();
944 944
         }
945 945
         if (empty($role)) {
946 946
             return $this->capabilities_map;
947 947
         }
948
-        return isset($this->capabilities_map[ $role ])
949
-            ? $this->capabilities_map[ $role ]
948
+        return isset($this->capabilities_map[$role])
949
+            ? $this->capabilities_map[$role]
950 950
             : array();
951 951
     }
952 952
 
@@ -977,7 +977,7 @@  discard block
 block discarded – undo
977 977
                         'event_espresso'
978 978
                     ),
979 979
                     '$reset',
980
-                    __METHOD__ . '()',
980
+                    __METHOD__.'()',
981 981
                     'EE_Capabilities::init_caps()',
982 982
                     'true'
983 983
                 ),
@@ -1051,7 +1051,7 @@  discard block
 block discarded – undo
1051 1051
                         'Incoming $map_values array should have a count of four values in it.  This is what was given: %s',
1052 1052
                         'event_espresso'
1053 1053
                     ),
1054
-                    '<br>' . print_r($map_values, true)
1054
+                    '<br>'.print_r($map_values, true)
1055 1055
                 )
1056 1056
             );
1057 1057
         }
@@ -1091,7 +1091,7 @@  discard block
 block discarded – undo
1091 1091
         // error proof if the name has EEM in it
1092 1092
         $this->_model_name = str_replace('EEM', '', $this->_model_name);
1093 1093
         $this->_model = EE_Registry::instance()->load_model($this->_model_name);
1094
-        if (! $this->_model instanceof EEM_Base) {
1094
+        if ( ! $this->_model instanceof EEM_Base) {
1095 1095
             throw new EE_Error(
1096 1096
                 sprintf(
1097 1097
                     __(
@@ -1177,7 +1177,7 @@  discard block
 block discarded – undo
1177 1177
 
1178 1178
         // okay it is a meta cap so let's first remove that cap from the $caps array.
1179 1179
         if (($key = array_search($cap, $caps)) !== false) {
1180
-            unset($caps[ $key ]);
1180
+            unset($caps[$key]);
1181 1181
         }
1182 1182
 
1183 1183
         // cast $user_id to int for later explicit comparisons
@@ -1186,11 +1186,11 @@  discard block
 block discarded – undo
1186 1186
         /** @var EE_Base_Class $obj */
1187 1187
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1188 1188
         // if no obj then let's just do cap
1189
-        if (! $obj instanceof EE_Base_Class) {
1189
+        if ( ! $obj instanceof EE_Base_Class) {
1190 1190
             $caps[] = 'do_not_allow';
1191 1191
             return $caps;
1192 1192
         }
1193
-        $caps[] = $cap . 's';
1193
+        $caps[] = $cap.'s';
1194 1194
         if ($obj instanceof EE_CPT_Base) {
1195 1195
             // if the item author is set and the user is the author...
1196 1196
             if ($obj->wp_user() && $user_id === $obj->wp_user()) {
@@ -1200,12 +1200,12 @@  discard block
 block discarded – undo
1200 1200
                 }
1201 1201
             } else {
1202 1202
                 // the user is trying to edit someone else's obj
1203
-                if (! empty($this->others_cap)) {
1203
+                if ( ! empty($this->others_cap)) {
1204 1204
                     $caps[] = $this->others_cap;
1205 1205
                 }
1206
-                if (! empty($this->published_cap) && $obj->status() === 'publish') {
1206
+                if ( ! empty($this->published_cap) && $obj->status() === 'publish') {
1207 1207
                     $caps[] = $this->published_cap;
1208
-                } elseif (! empty($this->private_cap) && $obj->status() === 'private') {
1208
+                } elseif ( ! empty($this->private_cap) && $obj->status() === 'private') {
1209 1209
                     $caps[] = $this->private_cap;
1210 1210
                 }
1211 1211
             }
@@ -1221,8 +1221,8 @@  discard block
 block discarded – undo
1221 1221
                     EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1222 1222
                 }
1223 1223
             }
1224
-            if (! $has_cap) {
1225
-                if (! empty($this->others_cap)) {
1224
+            if ( ! $has_cap) {
1225
+                if ( ! empty($this->others_cap)) {
1226 1226
                     $caps[] = $this->others_cap;
1227 1227
                 }
1228 1228
             }
@@ -1301,7 +1301,7 @@  discard block
 block discarded – undo
1301 1301
 
1302 1302
         // okay it is a meta cap so let's first remove that cap from the $caps array.
1303 1303
         if (($key = array_search($cap, $caps)) !== false) {
1304
-            unset($caps[ $key ]);
1304
+            unset($caps[$key]);
1305 1305
         }
1306 1306
 
1307 1307
         // cast $user_id to int for later explicit comparisons
@@ -1309,12 +1309,12 @@  discard block
 block discarded – undo
1309 1309
 
1310 1310
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1311 1311
         // if no obj then let's just do cap
1312
-        if (! $obj instanceof EE_Base_Class) {
1312
+        if ( ! $obj instanceof EE_Base_Class) {
1313 1313
             $caps[] = 'do_not_allow';
1314 1314
             return $caps;
1315 1315
         }
1316 1316
 
1317
-        $caps[] = $cap . 's';
1317
+        $caps[] = $cap.'s';
1318 1318
         if ($obj instanceof EE_CPT_Base) {
1319 1319
             $status_obj = get_post_status_object($obj->status());
1320 1320
             if ($status_obj->public) {
@@ -1322,7 +1322,7 @@  discard block
 block discarded – undo
1322 1322
             }
1323 1323
             // if the item author is set and the user is not the author...
1324 1324
             if ($obj->wp_user() && $obj->wp_user() !== $user_id) {
1325
-                if (! empty($this->others_cap)) {
1325
+                if ( ! empty($this->others_cap)) {
1326 1326
                     $caps[] = $this->others_cap;
1327 1327
                 }
1328 1328
             }
@@ -1346,11 +1346,11 @@  discard block
 block discarded – undo
1346 1346
                     EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1347 1347
                 }
1348 1348
             }
1349
-            if (! $has_cap) {
1350
-                if (! empty($this->private_cap)) {
1349
+            if ( ! $has_cap) {
1350
+                if ( ! empty($this->private_cap)) {
1351 1351
                     $caps[] = $this->private_cap;
1352 1352
                 }
1353
-                if (! empty($this->others_cap)) {
1353
+                if ( ! empty($this->others_cap)) {
1354 1354
                     $caps[] = $this->others_cap;
1355 1355
                 }
1356 1356
             }
@@ -1396,7 +1396,7 @@  discard block
 block discarded – undo
1396 1396
 
1397 1397
         // okay it is a meta cap so let's first remove that cap from the $caps array.
1398 1398
         if (($key = array_search($cap, $caps)) !== false) {
1399
-            unset($caps[ $key ]);
1399
+            unset($caps[$key]);
1400 1400
         }
1401 1401
 
1402 1402
         // cast $user_id to int for later explicit comparisons
@@ -1404,11 +1404,11 @@  discard block
 block discarded – undo
1404 1404
 
1405 1405
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1406 1406
         // if no obj then let's just do cap
1407
-        if (! $obj instanceof EE_Message_Template_Group) {
1407
+        if ( ! $obj instanceof EE_Message_Template_Group) {
1408 1408
             $caps[] = 'do_not_allow';
1409 1409
             return $caps;
1410 1410
         }
1411
-        $caps[] = $cap . 's';
1411
+        $caps[] = $cap.'s';
1412 1412
         $is_global = $obj->is_global();
1413 1413
         if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1414 1414
             if ($is_global) {
@@ -1459,15 +1459,15 @@  discard block
 block discarded – undo
1459 1459
         }
1460 1460
         // okay it is a meta cap so let's first remove that cap from the $caps array.
1461 1461
         if (($key = array_search($cap, $caps)) !== false) {
1462
-            unset($caps[ $key ]);
1462
+            unset($caps[$key]);
1463 1463
         }
1464 1464
         $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1465 1465
         // if no obj then let's just do cap
1466
-        if (! $obj instanceof EE_Base_Class) {
1466
+        if ( ! $obj instanceof EE_Base_Class) {
1467 1467
             $caps[] = 'do_not_allow';
1468 1468
             return $caps;
1469 1469
         }
1470
-        $caps[] = $cap . 's';
1470
+        $caps[] = $cap.'s';
1471 1471
         $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false;
1472 1472
         $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system;
1473 1473
         if ($is_system) {
Please login to merge, or discard this patch.
admin/extend/transactions/Extend_Transactions_Admin_Page.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -198,7 +198,7 @@
 block discarded – undo
198 198
      *
199 199
      * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
200 200
      *
201
-     * @return int
201
+     * @return string
202 202
      */
203 203
     private function _revenue_per_event_report($period = '-1 month')
204 204
     {
Please login to merge, or discard this patch.
Indentation   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -16,239 +16,239 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * This is used to hold the reports template data which is setup early in the request.
21
-     *
22
-     * @type array
23
-     */
24
-    protected $_reports_template_data = array();
25
-
26
-    /**
27
-     * @Constructor
28
-     * @access public
29
-     *
30
-     * @param bool $routing
31
-     *
32
-     * @return \Extend_Transactions_Admin_Page
33
-     */
34
-    public function __construct($routing = true)
35
-    {
36
-        parent::__construct($routing);
37
-        define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/templates/');
38
-        define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/assets/');
39
-        define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'transactions/assets/');
40
-    }
41
-
42
-
43
-    /**
44
-     *    _extend_page_config
45
-     *
46
-     * @access protected
47
-     * @return void
48
-     */
49
-    protected function _extend_page_config()
50
-    {
51
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'transactions';
52
-
53
-        $new_page_routes = array(
54
-            'reports' => array(
55
-                'func'       => '_transaction_reports',
56
-                'capability' => 'ee_read_transactions',
57
-            ),
58
-        );
59
-
60
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
61
-
62
-        $new_page_config = array(
63
-            'reports' => array(
64
-                'nav'           => array(
65
-                    'label' => __('Reports', 'event_espresso'),
66
-                    'order' => 20,
67
-                ),
68
-                'help_tabs'     => array(
69
-                    'transactions_reports_help_tab' => array(
70
-                        'title'    => __('Transaction Reports', 'event_espresso'),
71
-                        'filename' => 'transactions_reports',
72
-                    ),
73
-                ),
74
-                /*'help_tour' => array( 'Transaction_Reports_Help_Tour' ),*/
75
-                'require_nonce' => false,
76
-            ),
77
-        );
78
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
79
-    }
80
-
81
-
82
-    /**
83
-     *    load_scripts_styles_reports
84
-     *
85
-     * @access public
86
-     * @return void
87
-     */
88
-    public function load_scripts_styles_reports()
89
-    {
90
-        wp_register_script(
91
-            'ee-txn-reports-js',
92
-            TXN_CAF_ASSETS_URL . 'ee-transaction-admin-reports.js',
93
-            array('google-charts'),
94
-            EVENT_ESPRESSO_VERSION,
95
-            true
96
-        );
97
-        wp_enqueue_script('ee-txn-reports-js');
98
-        $this->_transaction_reports_js_setup();
99
-        EE_Registry::$i18n_js_strings['currency_format'] = EEH_Money::get_format_for_google_charts();
100
-    }
101
-
102
-
103
-    /**
104
-     * This is called when javascript is being enqueued to setup the various data needed for the reports js.
105
-     * Also $this->{$_reports_template_data} property is set for later usage by the _transaction_reports method.
106
-     */
107
-    protected function _transaction_reports_js_setup()
108
-    {
109
-        $this->_reports_template_data['admin_reports'][] = $this->_revenue_per_day_report();
110
-        $this->_reports_template_data['admin_reports'][] = $this->_revenue_per_event_report();
111
-    }
112
-
113
-
114
-    /**
115
-     * _transaction_reports
116
-     *    generates Business Reports regarding Transactions
117
-     *
118
-     * @return void
119
-     */
120
-    protected function _transaction_reports()
121
-    {
122
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
123
-        $this->_admin_page_title = __('Transactions', 'event_espresso');
124
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
125
-            $template_path,
126
-            $this->_reports_template_data,
127
-            true
128
-        );
129
-
130
-        // the final template wrapper
131
-        $this->display_admin_page_with_no_sidebar();
132
-    }
133
-
134
-
135
-    /**
136
-     * _revenue_per_day_report
137
-     * generates Business Report showing Total Revenue per Day.
138
-     *
139
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
140
-     *
141
-     * @return string
142
-     */
143
-    private function _revenue_per_day_report($period = '-1 month')
144
-    {
145
-
146
-        $report_ID = 'txn-admin-revenue-per-day-report-dv';
147
-
148
-        $TXN = EEM_Transaction::instance();
149
-
150
-        $results = $TXN->get_revenue_per_day_report($period);
151
-        $results = (array) $results;
152
-        $revenue = array();
153
-        $subtitle = '';
154
-
155
-        if ($results) {
156
-            $revenue[] = array(
157
-                __('Date (only shows dates that have a revenue greater than 1)', 'event_espresso'),
158
-                __('Total Revenue', 'event_espresso'),
159
-            );
160
-            foreach ($results as $result) {
161
-                $revenue[] = array($result->txnDate, (float) $result->revenue);
162
-            }
163
-
164
-            // setup the date range.
165
-            $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
166
-            $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
167
-            $subtitle = sprintf(
168
-                _x('For the period: %s to %s', 'Used to give date range', 'event_espresso'),
169
-                $beginning_date->format('Y-m-d'),
170
-                $ending_date->format('Y-m-d')
171
-            );
172
-        }
173
-
174
-        $report_title = esc_html__('Total Revenue per Day', 'event_espresso');
175
-
176
-        $report_params = array(
177
-            'title'     => $report_title,
178
-            'subtitle'  => $subtitle,
179
-            'id'        => $report_ID,
180
-            'revenue'   => $revenue,
181
-            'noResults' => empty($revenue) || count($revenue) === 1,
182
-            'noTxnMsg'  => sprintf(
183
-                __('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'),
184
-                '<h2>' . $report_title . '</h2><p>',
185
-                '</p>'
186
-            ),
187
-        );
188
-        wp_localize_script('ee-txn-reports-js', 'txnRevPerDay', $report_params);
189
-
190
-        return $report_ID;
191
-    }
192
-
193
-
194
-    /**
195
-     * _revenue_per_event_report
196
-     * generates Business Report showing total revenue per event.
197
-     *
198
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
199
-     *
200
-     * @return int
201
-     */
202
-    private function _revenue_per_event_report($period = '-1 month')
203
-    {
204
-
205
-        $report_ID = 'txn-admin-revenue-per-event-report-dv';
206
-
207
-        $TXN = EEM_Transaction::instance();
208
-        $results = $TXN->get_revenue_per_event_report($period);
209
-        $results = (array) $results;
210
-        $revenue = array();
211
-        $subtitle = '';
212
-
213
-        if ($results) {
214
-            $revenue[] = array(
215
-                __('Event (only events that have a revenue greater than 1 are shown)', 'event_espresso'),
216
-                __('Total Revenue', 'event_espresso'),
217
-            );
218
-            foreach ($results as $result) {
219
-                if ($result->revenue > 1) {
220
-                    $event_name = stripslashes(html_entity_decode($result->event_name, ENT_QUOTES, 'UTF-8'));
221
-                    $event_name = wp_trim_words($event_name, 5, '...');
222
-                    $revenue[] = array($event_name, (float) $result->revenue);
223
-                }
224
-            }
225
-
226
-            // setup the date range.
227
-            $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
228
-            $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
229
-            $subtitle = sprintf(
230
-                _x('For the period: %s to %s', 'Used to give date range', 'event_espresso'),
231
-                $beginning_date->format('Y-m-d'),
232
-                $ending_date->format('Y-m-d')
233
-            );
234
-        }
235
-
236
-        $report_title = esc_html__('Total Revenue per Event', 'event_espresso');
237
-
238
-        $report_params = array(
239
-            'title'     => $report_title,
240
-            'subtitle'  => $subtitle,
241
-            'id'        => $report_ID,
242
-            'revenue'   => $revenue,
243
-            'noResults' => empty($revenue),
244
-            'noTxnMsg'  => sprintf(
245
-                __('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'),
246
-                '<h2>' . $report_title . '</h2><p>',
247
-                '</p>'
248
-            ),
249
-        );
250
-        wp_localize_script('ee-txn-reports-js', 'txnRevPerEvent', $report_params);
251
-
252
-        return $report_ID;
253
-    }
19
+	/**
20
+	 * This is used to hold the reports template data which is setup early in the request.
21
+	 *
22
+	 * @type array
23
+	 */
24
+	protected $_reports_template_data = array();
25
+
26
+	/**
27
+	 * @Constructor
28
+	 * @access public
29
+	 *
30
+	 * @param bool $routing
31
+	 *
32
+	 * @return \Extend_Transactions_Admin_Page
33
+	 */
34
+	public function __construct($routing = true)
35
+	{
36
+		parent::__construct($routing);
37
+		define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/templates/');
38
+		define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/assets/');
39
+		define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'transactions/assets/');
40
+	}
41
+
42
+
43
+	/**
44
+	 *    _extend_page_config
45
+	 *
46
+	 * @access protected
47
+	 * @return void
48
+	 */
49
+	protected function _extend_page_config()
50
+	{
51
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'transactions';
52
+
53
+		$new_page_routes = array(
54
+			'reports' => array(
55
+				'func'       => '_transaction_reports',
56
+				'capability' => 'ee_read_transactions',
57
+			),
58
+		);
59
+
60
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
61
+
62
+		$new_page_config = array(
63
+			'reports' => array(
64
+				'nav'           => array(
65
+					'label' => __('Reports', 'event_espresso'),
66
+					'order' => 20,
67
+				),
68
+				'help_tabs'     => array(
69
+					'transactions_reports_help_tab' => array(
70
+						'title'    => __('Transaction Reports', 'event_espresso'),
71
+						'filename' => 'transactions_reports',
72
+					),
73
+				),
74
+				/*'help_tour' => array( 'Transaction_Reports_Help_Tour' ),*/
75
+				'require_nonce' => false,
76
+			),
77
+		);
78
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
79
+	}
80
+
81
+
82
+	/**
83
+	 *    load_scripts_styles_reports
84
+	 *
85
+	 * @access public
86
+	 * @return void
87
+	 */
88
+	public function load_scripts_styles_reports()
89
+	{
90
+		wp_register_script(
91
+			'ee-txn-reports-js',
92
+			TXN_CAF_ASSETS_URL . 'ee-transaction-admin-reports.js',
93
+			array('google-charts'),
94
+			EVENT_ESPRESSO_VERSION,
95
+			true
96
+		);
97
+		wp_enqueue_script('ee-txn-reports-js');
98
+		$this->_transaction_reports_js_setup();
99
+		EE_Registry::$i18n_js_strings['currency_format'] = EEH_Money::get_format_for_google_charts();
100
+	}
101
+
102
+
103
+	/**
104
+	 * This is called when javascript is being enqueued to setup the various data needed for the reports js.
105
+	 * Also $this->{$_reports_template_data} property is set for later usage by the _transaction_reports method.
106
+	 */
107
+	protected function _transaction_reports_js_setup()
108
+	{
109
+		$this->_reports_template_data['admin_reports'][] = $this->_revenue_per_day_report();
110
+		$this->_reports_template_data['admin_reports'][] = $this->_revenue_per_event_report();
111
+	}
112
+
113
+
114
+	/**
115
+	 * _transaction_reports
116
+	 *    generates Business Reports regarding Transactions
117
+	 *
118
+	 * @return void
119
+	 */
120
+	protected function _transaction_reports()
121
+	{
122
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
123
+		$this->_admin_page_title = __('Transactions', 'event_espresso');
124
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
125
+			$template_path,
126
+			$this->_reports_template_data,
127
+			true
128
+		);
129
+
130
+		// the final template wrapper
131
+		$this->display_admin_page_with_no_sidebar();
132
+	}
133
+
134
+
135
+	/**
136
+	 * _revenue_per_day_report
137
+	 * generates Business Report showing Total Revenue per Day.
138
+	 *
139
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
140
+	 *
141
+	 * @return string
142
+	 */
143
+	private function _revenue_per_day_report($period = '-1 month')
144
+	{
145
+
146
+		$report_ID = 'txn-admin-revenue-per-day-report-dv';
147
+
148
+		$TXN = EEM_Transaction::instance();
149
+
150
+		$results = $TXN->get_revenue_per_day_report($period);
151
+		$results = (array) $results;
152
+		$revenue = array();
153
+		$subtitle = '';
154
+
155
+		if ($results) {
156
+			$revenue[] = array(
157
+				__('Date (only shows dates that have a revenue greater than 1)', 'event_espresso'),
158
+				__('Total Revenue', 'event_espresso'),
159
+			);
160
+			foreach ($results as $result) {
161
+				$revenue[] = array($result->txnDate, (float) $result->revenue);
162
+			}
163
+
164
+			// setup the date range.
165
+			$beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
166
+			$ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
167
+			$subtitle = sprintf(
168
+				_x('For the period: %s to %s', 'Used to give date range', 'event_espresso'),
169
+				$beginning_date->format('Y-m-d'),
170
+				$ending_date->format('Y-m-d')
171
+			);
172
+		}
173
+
174
+		$report_title = esc_html__('Total Revenue per Day', 'event_espresso');
175
+
176
+		$report_params = array(
177
+			'title'     => $report_title,
178
+			'subtitle'  => $subtitle,
179
+			'id'        => $report_ID,
180
+			'revenue'   => $revenue,
181
+			'noResults' => empty($revenue) || count($revenue) === 1,
182
+			'noTxnMsg'  => sprintf(
183
+				__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'),
184
+				'<h2>' . $report_title . '</h2><p>',
185
+				'</p>'
186
+			),
187
+		);
188
+		wp_localize_script('ee-txn-reports-js', 'txnRevPerDay', $report_params);
189
+
190
+		return $report_ID;
191
+	}
192
+
193
+
194
+	/**
195
+	 * _revenue_per_event_report
196
+	 * generates Business Report showing total revenue per event.
197
+	 *
198
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
199
+	 *
200
+	 * @return int
201
+	 */
202
+	private function _revenue_per_event_report($period = '-1 month')
203
+	{
204
+
205
+		$report_ID = 'txn-admin-revenue-per-event-report-dv';
206
+
207
+		$TXN = EEM_Transaction::instance();
208
+		$results = $TXN->get_revenue_per_event_report($period);
209
+		$results = (array) $results;
210
+		$revenue = array();
211
+		$subtitle = '';
212
+
213
+		if ($results) {
214
+			$revenue[] = array(
215
+				__('Event (only events that have a revenue greater than 1 are shown)', 'event_espresso'),
216
+				__('Total Revenue', 'event_espresso'),
217
+			);
218
+			foreach ($results as $result) {
219
+				if ($result->revenue > 1) {
220
+					$event_name = stripslashes(html_entity_decode($result->event_name, ENT_QUOTES, 'UTF-8'));
221
+					$event_name = wp_trim_words($event_name, 5, '...');
222
+					$revenue[] = array($event_name, (float) $result->revenue);
223
+				}
224
+			}
225
+
226
+			// setup the date range.
227
+			$beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
228
+			$ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
229
+			$subtitle = sprintf(
230
+				_x('For the period: %s to %s', 'Used to give date range', 'event_espresso'),
231
+				$beginning_date->format('Y-m-d'),
232
+				$ending_date->format('Y-m-d')
233
+			);
234
+		}
235
+
236
+		$report_title = esc_html__('Total Revenue per Event', 'event_espresso');
237
+
238
+		$report_params = array(
239
+			'title'     => $report_title,
240
+			'subtitle'  => $subtitle,
241
+			'id'        => $report_ID,
242
+			'revenue'   => $revenue,
243
+			'noResults' => empty($revenue),
244
+			'noTxnMsg'  => sprintf(
245
+				__('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'),
246
+				'<h2>' . $report_title . '</h2><p>',
247
+				'</p>'
248
+			),
249
+		);
250
+		wp_localize_script('ee-txn-reports-js', 'txnRevPerEvent', $report_params);
251
+
252
+		return $report_ID;
253
+	}
254 254
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -34,9 +34,9 @@  discard block
 block discarded – undo
34 34
     public function __construct($routing = true)
35 35
     {
36 36
         parent::__construct($routing);
37
-        define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/templates/');
38
-        define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'transactions/assets/');
39
-        define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'transactions/assets/');
37
+        define('TXN_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'transactions/templates/');
38
+        define('TXN_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'transactions/assets/');
39
+        define('TXN_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'transactions/assets/');
40 40
     }
41 41
 
42 42
 
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
      */
49 49
     protected function _extend_page_config()
50 50
     {
51
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'transactions';
51
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'transactions';
52 52
 
53 53
         $new_page_routes = array(
54 54
             'reports' => array(
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
     {
90 90
         wp_register_script(
91 91
             'ee-txn-reports-js',
92
-            TXN_CAF_ASSETS_URL . 'ee-transaction-admin-reports.js',
92
+            TXN_CAF_ASSETS_URL.'ee-transaction-admin-reports.js',
93 93
             array('google-charts'),
94 94
             EVENT_ESPRESSO_VERSION,
95 95
             true
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
      */
120 120
     protected function _transaction_reports()
121 121
     {
122
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
122
+        $template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php';
123 123
         $this->_admin_page_title = __('Transactions', 'event_espresso');
124 124
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
125 125
             $template_path,
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
             }
163 163
 
164 164
             // setup the date range.
165
-            $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
165
+            $beginning_date = new DateTime('now'.$period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
166 166
             $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
167 167
             $subtitle = sprintf(
168 168
                 _x('For the period: %s to %s', 'Used to give date range', 'event_espresso'),
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
             'noResults' => empty($revenue) || count($revenue) === 1,
182 182
             'noTxnMsg'  => sprintf(
183 183
                 __('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'),
184
-                '<h2>' . $report_title . '</h2><p>',
184
+                '<h2>'.$report_title.'</h2><p>',
185 185
                 '</p>'
186 186
             ),
187 187
         );
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
             }
225 225
 
226 226
             // setup the date range.
227
-            $beginning_date = new DateTime('now' . $period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
227
+            $beginning_date = new DateTime('now'.$period, new DateTimeZone(EEH_DTT_Helper::get_timezone()));
228 228
             $ending_date = new DateTime('now', new DateTimeZone(EEH_DTT_Helper::get_timezone()));
229 229
             $subtitle = sprintf(
230 230
                 _x('For the period: %s to %s', 'Used to give date range', 'event_espresso'),
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
             'noResults' => empty($revenue),
244 244
             'noTxnMsg'  => sprintf(
245 245
                 __('%sThere is no revenue to report for the last 30 days.%s', 'event_espresso'),
246
-                '<h2>' . $report_title . '</h2><p>',
246
+                '<h2>'.$report_title.'</h2><p>',
247 247
                 '</p>'
248 248
             ),
249 249
         );
Please login to merge, or discard this patch.
caffeinated/EE_Caf_Messages.class.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      *
92 92
      * @param  array $dir_ref original array of paths
93 93
      *
94
-     * @return array           appended paths
94
+     * @return string[]           appended paths
95 95
      */
96 96
     public function messages_autoload_paths($dir_ref)
97 97
     {
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
      * @param EE_Question[]  $questions        An array of questions indexed by answer id.
702 702
      * @param EE_Answer[]    $answers          An array of answer objects
703 703
      * @param string         $template         Template content to be parsed.
704
-     * @param array          $valid_shortcodes Valid shortcodes for the template being parsed.
704
+     * @param string[]          $valid_shortcodes Valid shortcodes for the template being parsed.
705 705
      * @param array          $extra_data       Extra data that might be used when parsing the template.
706 706
      */
707 707
     protected function _parse_question_list_for_primary_or_recipient_registration(
Please login to merge, or discard this patch.
Indentation   +799 added lines, -799 removed lines patch added patch discarded remove patch
@@ -13,803 +13,803 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * constructor.
18
-     */
19
-    public function __construct()
20
-    {
21
-        $this->_caf_hooks();
22
-    }
23
-
24
-
25
-    /**
26
-     * Contains all the hooks filters for setting up caffeinated messages functionality.
27
-     *
28
-     * @since 4.3.2
29
-     *
30
-     * @return void
31
-     */
32
-    private function _caf_hooks()
33
-    {
34
-        add_filter('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', array($this, 'messages_autoload_paths'), 5);
35
-        add_filter(
36
-            'FHEE__EE_Email_messenger__get_validator_config',
37
-            array($this, 'email_messenger_validator_config'),
38
-            5,
39
-            2
40
-        );
41
-        add_filter(
42
-            'FHEE__EE_Email_messenger__get_template_fields',
43
-            array($this, 'email_messenger_template_fields'),
44
-            5,
45
-            2
46
-        );
47
-        add_filter(
48
-            'FHEE__EE_Html_messenger__get_template_fields',
49
-            array($this, 'html_messenger_template_fields'),
50
-            5,
51
-            2
52
-        );
53
-        add_filter(
54
-            'FHEE__EE_Html_messenger__get_validator_config',
55
-            array($this, 'html_messenger_validator_config'),
56
-            5,
57
-            2
58
-        );
59
-        add_filter('FHEE__EE_Pdf_messenger__get_template_fields', array($this, 'pdf_messenger_template_fields'), 5, 2);
60
-        add_filter(
61
-            'FHEE__EE_Pdf_messenger__get_validator_config',
62
-            array($this, 'pdf_messenger_validator_config'),
63
-            5,
64
-            2
65
-        );
66
-        add_filter(
67
-            'FHEE__EE_Messages_Template_Pack__get_specific_template__contents',
68
-            array($this, 'new_default_templates'),
69
-            5,
70
-            7
71
-        );
72
-        add_filter(
73
-            'FHEE__EE_Messages_Base__get_valid_shortcodes',
74
-            array($this, 'message_types_valid_shortcodes'),
75
-            5,
76
-            2
77
-        );
78
-
79
-        // shortcode parsers
80
-        add_filter('FHEE__EE_Attendee_Shortcodes__shortcodes', array($this, 'additional_attendee_shortcodes'), 5, 2);
81
-        add_filter('FHEE__EE_Attendee_Shortcodes__parser_after', array($this, 'additional_attendee_parser'), 5, 5);
82
-        add_filter(
83
-            'FHEE__EE_Recipient_List_Shortcodes__shortcodes',
84
-            array($this, 'additional_recipient_details_shortcodes'),
85
-            5,
86
-            2
87
-        );
88
-        add_filter(
89
-            'FHEE__EE_Recipient_List_Shortcodes__parser_after',
90
-            array($this, 'additional_recipient_details_parser'),
91
-            5,
92
-            5
93
-        );
94
-        add_filter(
95
-            'FHEE__EE_Primary_Registration_List_Shortcodes__shortcodes',
96
-            array($this, 'additional_primary_registration_details_shortcodes'),
97
-            5,
98
-            2
99
-        );
100
-        add_filter(
101
-            'FHEE__EE_Primary_Registration_List_Shortcodes__parser_after',
102
-            array($this, 'additional_primary_registration_details_parser'),
103
-            5,
104
-            5
105
-        );
106
-
107
-        /**
108
-         * @since 4.2.0
109
-         */
110
-        add_filter('FHEE__EE_Datetime_Shortcodes__shortcodes', array($this, 'additional_datetime_shortcodes'), 10, 2);
111
-        add_filter('FHEE__EE_Datetime_Shortcodes__parser_after', array($this, 'additional_datetime_parser'), 10, 5);
112
-
113
-        /**
114
-         * @since 4.3.0
115
-         */
116
-        // eat our own dog food!
117
-        add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_message_types'));
118
-        add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_shortcodes'));
119
-        do_action('EE_Brewing_Regular___messages_caf');
120
-    }
121
-
122
-
123
-    /**
124
-     * This just allows us to add additional paths to the autoloader (EED_Messages::autoload_messages()) for the
125
-     * messages system.
126
-     *
127
-     * @param  array $dir_ref original array of paths
128
-     *
129
-     * @return array           appended paths
130
-     */
131
-    public function messages_autoload_paths($dir_ref)
132
-    {
133
-        $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/';
134
-
135
-        return $dir_ref;
136
-    }
137
-
138
-
139
-    public function email_messenger_validator_config($validator_config, EE_Email_messenger $messenger)
140
-    {
141
-        $validator_config['attendee_list'] = array(
142
-            'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'),
143
-            'required'   => array('[ATTENDEE_LIST]'),
144
-        );
145
-        $validator_config['question_list'] = array(
146
-            'shortcodes' => array('question'),
147
-            'required'   => array('[QUESTION_LIST]'),
148
-        );
149
-
150
-        return $validator_config;
151
-    }
152
-
153
-
154
-    public function html_messenger_validator_config($validator_config, EE_Html_messenger $messenger)
155
-    {
156
-        $validator_config['attendee_list'] = array(
157
-            'shortcodes' => array('attendee', 'question_list'),
158
-            'required'   => array('[ATTENDEE_LIST]'),
159
-        );
160
-        $validator_config['question_list'] = array(
161
-            'shortcodes' => array('question'),
162
-            'required'   => array('[QUESTION_LIST]'),
163
-        );
164
-
165
-        return $validator_config;
166
-    }
167
-
168
-
169
-    public function pdf_messenger_validator_config($validator_config, EE_Pdf_messenger $messenger)
170
-    {
171
-        $validator_config['attendee_list'] = array(
172
-            'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'),
173
-            'required'   => array('[ATTENDEE_LIST]'),
174
-        );
175
-        $validator_config['question_list'] = array(
176
-            'shortcodes' => array('question'),
177
-            'required'   => array('[QUESTION_LIST]'),
178
-        );
179
-
180
-        return $validator_config;
181
-    }
182
-
183
-
184
-    public function email_messenger_template_fields($template_fields, EE_Email_messenger $messenger)
185
-    {
186
-        $template_fields['extra']['content']['question_list'] = array(
187
-            'input'               => 'textarea',
188
-            'label'               => '[QUESTION_LIST]',
189
-            'type'                => 'string',
190
-            'required'            => true,
191
-            'validation'          => true,
192
-            'format'              => '%s',
193
-            'css_class'           => 'large-text',
194
-            'rows'                => '5',
195
-            'shortcodes_required' => array('[QUESTION_LIST]'),
196
-        );
197
-
198
-        return $template_fields;
199
-    }
200
-
201
-
202
-    public function html_messenger_template_fields($template_fields, EE_Html_messenger $messenger)
203
-    {
204
-        $template_fields['extra']['content']['question_list'] = array(
205
-            'input'               => 'textarea',
206
-            'label'               => '[QUESTION_LIST]',
207
-            'type'                => 'string',
208
-            'required'            => true,
209
-            'validation'          => true,
210
-            'format'              => '%s',
211
-            'css_class'           => 'large-text',
212
-            'rows'                => '5',
213
-            'shortcodes_required' => array('[QUESTION_LIST]'),
214
-        );
215
-
216
-        return $template_fields;
217
-    }
218
-
219
-
220
-    public function pdf_messenger_template_fields($template_fields, EE_Pdf_messenger $messenger)
221
-    {
222
-        $template_fields['extra']['content']['question_list'] = array(
223
-            'input'               => 'textarea',
224
-            'label'               => '[QUESTION_LIST]',
225
-            'type'                => 'string',
226
-            'required'            => true,
227
-            'validation'          => true,
228
-            'format'              => '%s',
229
-            'css_class'           => 'large-text',
230
-            'rows'                => '5',
231
-            'shortcodes_required' => array('[QUESTION_LIST]'),
232
-        );
233
-
234
-        return $template_fields;
235
-    }
236
-
237
-
238
-    public function new_default_templates(
239
-        $contents,
240
-        $actual_path,
241
-        EE_messenger $messenger,
242
-        EE_message_type $message_type,
243
-        $field,
244
-        $context,
245
-        EE_Messages_Template_Pack $template_pack
246
-    ) {
247
-
248
-        // we're only modifying templates for the default template pack
249
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
250
-            return $contents;
251
-        }
252
-
253
-        // the template file name we're replacing contents for.
254
-        $template_file_prefix = $field . '_' . $context;
255
-        $msg_prefix = $messenger->name . '_' . $message_type->name . '_';
256
-
257
-        $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/';
258
-
259
-        if ($messenger->name == 'email' && $message_type->name == 'registration') {
260
-            switch ($template_file_prefix) {
261
-                case 'question_list_admin':
262
-                case 'question_list_attendee':
263
-                case 'question_list_primary_attendee':
264
-                    $path = $base_path . $msg_prefix . 'question_list.template.php';
265
-                    $contents = EEH_Template::display_template($path, array(), true);
266
-                    break;
267
-
268
-                case 'attendee_list_primary_attendee':
269
-                    $path = $base_path . $msg_prefix . 'attendee_list.template.php';
270
-                    $contents = EEH_Template::display_template($path, array(), true);
271
-                    break;
272
-
273
-                case 'attendee_list_admin':
274
-                    $path = $base_path . $msg_prefix . 'attendee_list_admin.template.php';
275
-                    $contents = EEH_Template::display_template(
276
-                        $path,
277
-                        array(),
278
-                        true
279
-                    );
280
-                    break;
281
-
282
-                case 'attendee_list_attendee':
283
-                    $contents = '';
284
-                    break;
285
-
286
-                case 'event_list_attendee':
287
-                    $path = $base_path . $msg_prefix . 'event_list_attendee.template.php';
288
-                    $contents = EEH_Template::display_template($path, array(), true);
289
-                    break;
290
-            }
291
-        } elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') {
292
-            switch ($template_file_prefix) {
293
-                case 'content_attendee':
294
-                    $path = $base_path . $msg_prefix . 'content.template.php';
295
-                    $contents = EEH_Template::display_template($path, array(), true);
296
-                    break;
297
-
298
-                case 'newsletter_content_attendee':
299
-                    $path = $base_path . $msg_prefix . 'newsletter_content.template.php';
300
-                    $contents = EEH_Template::display_template($path, array(), true);
301
-                    break;
302
-
303
-                case 'newsletter_subject_attendee':
304
-                    $path = $base_path . $msg_prefix . 'subject.template.php';
305
-                    $contents = EEH_Template::display_template($path, array(), true);
306
-                    break;
307
-            }
308
-        } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') {
309
-            switch ($template_file_prefix) {
310
-                case 'attendee_list_purchaser':
311
-                    $path = $base_path . $msg_prefix . 'attendee_list.template.php';
312
-                    $contents = EEH_Template::display_template($path, array(), true);
313
-                    break;
314
-            }
315
-        }
316
-
317
-        return $contents;
318
-    }
319
-
320
-
321
-    public function message_types_valid_shortcodes($valid_shortcodes, EE_Messages_Base $msg)
322
-    {
323
-        // make sure question_list and question are ONLY added for the core message types.  Any other message types will have to explicitly set question_list as a valid shortcode.
324
-        $include_with = array(
325
-            'registration',
326
-            'cancelled_registration',
327
-            'declined_registration',
328
-            'not_approved_registration',
329
-            'payment_declined',
330
-            'payment_failed',
331
-            'payment_cancelled',
332
-            'payment',
333
-            'payment_reminder',
334
-            'pending_approval',
335
-            'registration_summary',
336
-            'invoice',
337
-            'receipt',
338
-        );
339
-        if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) {
340
-            $contexts = array_keys($msg->get_contexts());
341
-            foreach ($contexts as $context) {
342
-                $valid_shortcodes[ $context ][] = 'question_list';
343
-                $valid_shortcodes[ $context ][] = 'question';
344
-            }
345
-        }
346
-
347
-        return $valid_shortcodes;
348
-    }
349
-
350
-
351
-    public function additional_attendee_shortcodes($shortcodes, $shortcode_parser)
352
-    {
353
-        $shortcodes['[ANSWER_*]'] = __(
354
-            'This is a special dynamic shortcode. Right after the "*", add the exact text of a existing question, and if there is an answer for that question for this registrant, that will take the place of this shortcode.',
355
-            'event_espresso'
356
-        );
357
-
358
-        return $shortcodes;
359
-    }
360
-
361
-
362
-    public function additional_attendee_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
363
-    {
364
-
365
-        if (strpos($shortcode, '[ANSWER_*') === false
366
-            || ! isset($extra_data['data']->questions)
367
-            || ! isset($extra_data['data']->registrations)
368
-        ) {
369
-            return $parsed;
370
-        }
371
-
372
-        // let's get the question from the code.
373
-        $shortcode = str_replace('[ANSWER_*', '', $shortcode);
374
-        $shortcode = trim(str_replace(']', '', $shortcode));
375
-
376
-        $registration = $data instanceof EE_Registration ? $data : null;
377
-        $registration = ! $registration instanceof EE_Registration && is_array(
378
-            $extra_data
379
-        ) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Registration ? $extra_data['data'] : $registration;
380
-
381
-        $aee = $data instanceof EE_Messages_Addressee ? $data : null;
382
-        $aee = ! $aee instanceof EE_Messages_Addressee && is_array(
383
-            $extra_data
384
-        ) && isset($extra_data['data']) ? $extra_data['data'] : $aee;
385
-
386
-        if (! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) {
387
-            return $parsed;
388
-        }
389
-
390
-        // now let's figure out which question has this text.
391
-        foreach ($aee->questions as $ansid => $question) {
392
-            if ($question instanceof EE_Question
393
-                && trim($question->display_text()) == trim($shortcode)
394
-                && isset($aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ])
395
-            ) {
396
-                return $aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]->get_pretty(
397
-                    'ANS_value',
398
-                    'no_wpautop'
399
-                );
400
-            }
401
-        }
402
-
403
-        // nothing!
404
-        return $parsed;
405
-    }
406
-
407
-
408
-    /**
409
-     * Callback for additional shortcodes filter for adding additional datetime shortcodes.
410
-     *
411
-     * @since  4.2
412
-     *
413
-     * @param  array                  $shortcodes         array of shortcodes and
414
-     *                                                    descriptions
415
-     * @param  EE_Datetime_Shortcodes $shortcode_parser   EE_Shortcodes object
416
-     *
417
-     * @return array                                        array of shortcodes and
418
-     *                                                        descriptions
419
-     */
420
-    public function additional_datetime_shortcodes($shortcodes, $shortcode_parser)
421
-    {
422
-        $shortcodes['[DTT_NAME]'] = __(
423
-            'This will be parsed to the Title given for a Datetime',
424
-            'event_espresso'
425
-        );
426
-        $shortcodes['[DTT_DESCRIPTION]'] = __(
427
-            'This will be parsed to the description for a Datetime',
428
-            'event_espresso'
429
-        );
430
-        $shortcodes['[DTT_NAME_OR_DATES]'] = __(
431
-            'When parsed, if the Datetime has a name, it is used, otherwise a formatted string including the start date and end date will be used.',
432
-            'event_espresso'
433
-        );
434
-
435
-        return $shortcodes;
436
-    }
437
-
438
-
439
-    /**
440
-     * Callback for additional shortcodes parser filter used for adding parser for new
441
-     * Datetime shortcodes
442
-     *
443
-     * @since  4.2
444
-     *
445
-     * @param  string                 $parsed     The finished parsed string for the given shortcode.
446
-     * @param  string                 $shortcode  The shortcode being parsed.
447
-     * @param  object                 $data       The incoming data object for the Shortcode Parser.
448
-     * @param  object                 $extra_data The incoming extra date object for the Shortcode
449
-     *                                            Parser.
450
-     * @param  EE_Datetime_Shortcodes $shortcode_parser
451
-     *
452
-     * @return string                   The new parsed string.
453
-     */
454
-    public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
455
-    {
456
-
457
-        if (! $data instanceof EE_Datetime) {
458
-            return ''; // get out because we can only parse with the datetime object.
459
-        }
460
-
461
-        switch ($shortcode) {
462
-            case '[DTT_NAME]':
463
-                return $data->name();
464
-                break;
465
-            case '[DTT_DESCRIPTION]':
466
-                return $data->description();
467
-                break;
468
-            case '[DTT_NAME_OR_DATES]':
469
-                return $data->get_dtt_display_name(true);
470
-                break;
471
-            default:
472
-                return $parsed;
473
-                break;
474
-        }
475
-    }
476
-
477
-
478
-    public function additional_recipient_details_shortcodes($shortcodes, $shortcode_parser)
479
-    {
480
-        $shortcodes['[RECIPIENT_QUESTION_LIST]'] = __(
481
-            'This is used to indicate where you want the list of questions and answers to show for the person receiving the message.',
482
-            'event_espresso'
483
-        );
484
-
485
-        return $shortcodes;
486
-    }
487
-
488
-
489
-    /**
490
-     * Callback for FHEE__EE_Recipient_List_Shortcodes__parser_after filter (dynamic filter).
491
-     *
492
-     * @param string         $parsed           The original parsed content for the shortcode
493
-     * @param string         $shortcode        The shortcode being parsed
494
-     * @param array          $data             The shortcode parser data array
495
-     * @param array          $extra_data       The shortcode parser extra data array
496
-     * @param \EE_Shortcodes $shortcode_parser Shortcode parser.
497
-     *
498
-     * @return string
499
-     */
500
-    public function additional_recipient_details_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
501
-    {
502
-
503
-        if (array($data) && ! isset($data['data'])) {
504
-            return $parsed;
505
-        }
506
-
507
-        $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;
508
-        $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;
509
-
510
-        if (! $recipient instanceof EE_Messages_Addressee) {
511
-            return $parsed;
512
-        }
513
-
514
-        switch ($shortcode) {
515
-            case '[RECIPIENT_QUESTION_LIST]':
516
-                $att = $recipient->att_obj;
517
-                $registrations_on_attendee = $att instanceof EE_Attendee
518
-                    ? $recipient->attendees[ $att->ID() ]['reg_objs']
519
-                    : array();
520
-                $registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee;
521
-                $answers = array();
522
-
523
-                $template = is_array($data['template']) && isset($data['template']['question_list'])
524
-                    ? $data['template']['question_list']
525
-                    : $extra_data['template']['question_list'];
526
-                $valid_shortcodes = array('question');
527
-
528
-                // if the context is main_content then get all answers for all registrations on this attendee
529
-                if ($data['data'] instanceof EE_Messages_Addressee) {
530
-                    foreach ($registrations_on_attendee as $reg) {
531
-                        if ($reg instanceof EE_Registration) {
532
-                            $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs'])
533
-                                ? $recipient->registrations[ $reg->ID() ]['ans_objs']
534
-                                : array();
535
-                            foreach ($anss as $ans) {
536
-                                if ($ans instanceof EE_Answer) {
537
-                                    $answers[ $ans->ID() ] = $ans;
538
-                                }
539
-                            }
540
-                        }
541
-                    }
542
-                }
543
-
544
-                // if the context is the event list parser, then let's return just the answers for all registrations attached to the recipient for that event.
545
-                if ($data['data'] instanceof EE_Event) {
546
-                    $event = $data['data'];
547
-                    foreach ($registrations_on_attendee as $reg) {
548
-                        if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) {
549
-                            $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs'])
550
-                                ? $recipient->registrations[ $reg->ID() ]['ans_objs']
551
-                                : array();
552
-                            foreach ($anss as $ans) {
553
-                                if ($ans instanceof EE_Answer) {
554
-                                    $answers[ $ans->ID() ] = $ans;
555
-                                }
556
-                            }
557
-                        }
558
-                    }
559
-                }
560
-
561
-                $questions = $questions = isset($recipient->questions) ? $recipient->questions : array();
562
-
563
-                // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
564
-                // object on it.
565
-                if (! isset($extra_data['data'])) {
566
-                    $extra_data['data'] = $recipient;
567
-                }
568
-
569
-                return $this->_parse_question_list_for_primary_or_recipient_registration(
570
-                    $shortcode_parser,
571
-                    $questions,
572
-                    $answers,
573
-                    $template,
574
-                    $valid_shortcodes,
575
-                    $extra_data
576
-                );
577
-                break;
578
-
579
-            default:
580
-                return $parsed;
581
-                break;
582
-        }
583
-    }
584
-
585
-
586
-    public function additional_primary_registration_details_shortcodes($shortcodes, $shortcode_parser)
587
-    {
588
-        $shortcodes['[PRIMARY_REGISTRANT_QUESTION_LIST]'] = __(
589
-            'This is used to indicate the questions and answers for the primary_registrant. It should be placed in the "[attendee_list]" field',
590
-            'event_espresso'
591
-        );
592
-
593
-        return $shortcodes;
594
-    }
595
-
596
-
597
-    /**
598
-     * Callback for FHEE__EE_Primary_Registration_List_Shortcodes__parser_after filter (dynamic filter).
599
-     *
600
-     * @param string         $parsed           The original parsed content for the shortcode
601
-     * @param string         $shortcode        The shortcode being parsed
602
-     * @param array          $data             The shortcode parser data array
603
-     * @param array          $extra_data       The shortcode parser extra data array
604
-     * @param \EE_Shortcodes $shortcode_parser Shortcode parser.
605
-     *
606
-     * @return string
607
-     */
608
-    public function additional_primary_registration_details_parser(
609
-        $parsed,
610
-        $shortcode,
611
-        $data,
612
-        $extra_data,
613
-        $shortcode_parser
614
-    ) {
615
-        if (array($data) && ! isset($data['data'])) {
616
-            return $parsed;
617
-        }
618
-
619
-        $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;
620
-        $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;
621
-
622
-        if (! $recipient instanceof EE_Messages_Addressee) {
623
-            return $parsed;
624
-        }
625
-
626
-        switch ($shortcode) {
627
-            case '[PRIMARY_REGISTRANT_QUESTION_LIST]':
628
-                if (! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) {
629
-                    return '';
630
-                }
631
-                $registration = $recipient->primary_reg_obj;
632
-                $answers = isset($recipient->registrations[ $registration->ID() ]['ans_objs'])
633
-                    ? $recipient->registrations[ $registration->ID() ]['ans_objs']
634
-                    : array();
635
-                if (empty($answers)) {
636
-                    return '';
637
-                }
638
-                $template = is_array($data['template']) && isset($data['template']['question_list'])
639
-                    ? $data['template']['question_list']
640
-                    : $extra_data['template']['question_list'];
641
-                $valid_shortcodes = array('question');
642
-                $answers = $recipient->registrations[ $registration->ID() ]['ans_objs'];
643
-                $questions = isset($recipient->questions) ? $recipient->questions : array();
644
-                // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
645
-                // object on it.
646
-                if (! isset($extra_data['data'])) {
647
-                    $extra_data['data'] = $recipient;
648
-                }
649
-                return $this->_parse_question_list_for_primary_or_recipient_registration(
650
-                    $shortcode_parser,
651
-                    $questions,
652
-                    $answers,
653
-                    $template,
654
-                    $valid_shortcodes,
655
-                    $extra_data
656
-                );
657
-                break;
658
-
659
-            default:
660
-                return $parsed;
661
-                break;
662
-        }
663
-    }
664
-
665
-
666
-    /**
667
-     * Takes care of registering the  message types that are only available in caffeinated EE.
668
-     *
669
-     * @since   4.3.2
670
-     *
671
-     * @return  void
672
-     */
673
-    public function register_caf_message_types()
674
-    {
675
-        // register newsletter message type
676
-        $setup_args = array(
677
-            'mtfilename'                                       => 'EE_Newsletter_message_type.class.php',
678
-            'autoloadpaths'                                    => array(
679
-                EE_CAF_LIBRARIES . 'messages/message_type/newsletter/',
680
-            ),
681
-            'messengers_to_activate_with'                      => array('email'),
682
-            'messengers_to_validate_with'                      => array('email'),
683
-            'messengers_supporting_default_template_pack_with' => array('email'),
684
-        );
685
-        EE_Register_Message_Type::register('newsletter', $setup_args);
686
-
687
-        // register payment reminder message type
688
-        $setup_args = array(
689
-            'mtfilename'                                       => 'EE_Payment_Reminder_message_type.class.php',
690
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'),
691
-            'messengers_to_activate_with'                      => array('email'),
692
-            'messengers_to_validate_with'                      => array('email'),
693
-            'messengers_supporting_default_template_pack_with' => array('email'),
694
-        );
695
-        EE_Register_Message_Type::register('payment_reminder', $setup_args);
696
-
697
-        // register payment declined message type
698
-        $setup_args = array(
699
-            'mtfilename'                                       => 'EE_Payment_Declined_message_type.class.php',
700
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'),
701
-            'messengers_to_activate_with'                      => array('email'),
702
-            'messengers_to_validate_with'                      => array('email'),
703
-            'messengers_supporting_default_template_pack_with' => array('email'),
704
-        );
705
-        EE_Register_Message_Type::register('payment_declined', $setup_args);
706
-
707
-        // register registration declined message type
708
-        $setup_args = array(
709
-            'mtfilename'                                       => 'EE_Declined_Registration_message_type.class.php',
710
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'),
711
-            'messengers_to_activate_with'                      => array('email'),
712
-            'messengers_to_validate_with'                      => array('email'),
713
-            'messengers_supporting_default_template_pack_with' => array('email'),
714
-        );
715
-        EE_Register_Message_Type::register('declined_registration', $setup_args);
716
-
717
-        // register registration cancelled message type
718
-        $setup_args = array(
719
-            'mtfilename'                                       => 'EE_Cancelled_Registration_message_type.class.php',
720
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'),
721
-            'messengers_to_activate_with'                      => array('email'),
722
-            'messengers_to_validate_with'                      => array('email'),
723
-            'messengers_supporting_default_template_pack_with' => array('email'),
724
-        );
725
-        EE_Register_Message_Type::register('cancelled_registration', $setup_args);
726
-
727
-
728
-        // register payment failed message type
729
-        $setup_args = array(
730
-            'mtfilename'                                       => 'EE_Payment_Failed_message_type.class.php',
731
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'),
732
-            'messengers_to_activate_with'                      => array('email'),
733
-            'messengers_to_validate_with'                      => array('email'),
734
-            'messengers_supporting_default_template_pack_with' => array('email'),
735
-        );
736
-        EE_Register_Message_Type::register('payment_failed', $setup_args);
737
-
738
-        // register payment declined message type
739
-        $setup_args = array(
740
-            'mtfilename'                                       => 'EE_Payment_Cancelled_message_type.class.php',
741
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'),
742
-            'messengers_to_activate_with'                      => array('email'),
743
-            'messengers_to_validate_with'                      => array('email'),
744
-            'messengers_supporting_default_template_pack_with' => array('email'),
745
-        );
746
-        EE_Register_Message_Type::register('payment_cancelled', $setup_args);
747
-    }
748
-
749
-
750
-    /**
751
-     * Takes care of registering the  shortcode libraries implemented with caffeinated EE and set up related items.
752
-     *
753
-     * @since   4.3.2
754
-     *
755
-     * @return void
756
-     */
757
-    public function register_caf_shortcodes()
758
-    {
759
-        $setup_args = array(
760
-            'autoloadpaths'                 => array(
761
-                EE_CAF_LIBRARIES . 'shortcodes/',
762
-            ),
763
-            'msgr_validator_callback'       => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'),
764
-            'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'),
765
-            'list_type_shortcodes'          => array('[NEWSLETTER_CONTENT]'),
766
-        );
767
-        EE_Register_Messages_Shortcode_Library::register('newsletter', $setup_args);
768
-    }
769
-
770
-
771
-    /**
772
-     * Parses a question list shortcode using given data and template
773
-     *
774
-     * @param \EE_Shortcodes $shortcode_parser
775
-     * @param EE_Question[]  $questions        An array of questions indexed by answer id.
776
-     * @param EE_Answer[]    $answers          An array of answer objects
777
-     * @param string         $template         Template content to be parsed.
778
-     * @param array          $valid_shortcodes Valid shortcodes for the template being parsed.
779
-     * @param array          $extra_data       Extra data that might be used when parsing the template.
780
-     */
781
-    protected function _parse_question_list_for_primary_or_recipient_registration(
782
-        $shortcode_parser,
783
-        $questions,
784
-        $answers,
785
-        $template,
786
-        $valid_shortcodes,
787
-        $extra_data
788
-    ) {
789
-        $question_list = '';
790
-        /** @var EEH_Parse_Shortcodes $shortcode_helper */
791
-        $shortcode_helper = $shortcode_parser->get_shortcode_helper();
792
-        foreach ($answers as $answer) {
793
-            if ($answer instanceof EE_Answer) {
794
-                // first see if the question is in our $questions array. If not then try to get from answer object.
795
-                $question = isset($questions[ $answer->ID() ]) ? $questions[ $answer->ID() ] : null;
796
-                $question = ! $question instanceof EE_Question ? $answer->question() : $question;
797
-                if (! $question instanceof EE_Question
798
-                    || (
799
-                        $question instanceof EE_Question
800
-                        && $question->admin_only()
801
-                    )
802
-                ) {
803
-                    continue;
804
-                }
805
-                $question_list .= $shortcode_helper->parse_question_list_template(
806
-                    $template,
807
-                    $answer,
808
-                    $valid_shortcodes,
809
-                    $extra_data
810
-                );
811
-            }
812
-        }
813
-        return $question_list;
814
-    }
16
+	/**
17
+	 * constructor.
18
+	 */
19
+	public function __construct()
20
+	{
21
+		$this->_caf_hooks();
22
+	}
23
+
24
+
25
+	/**
26
+	 * Contains all the hooks filters for setting up caffeinated messages functionality.
27
+	 *
28
+	 * @since 4.3.2
29
+	 *
30
+	 * @return void
31
+	 */
32
+	private function _caf_hooks()
33
+	{
34
+		add_filter('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', array($this, 'messages_autoload_paths'), 5);
35
+		add_filter(
36
+			'FHEE__EE_Email_messenger__get_validator_config',
37
+			array($this, 'email_messenger_validator_config'),
38
+			5,
39
+			2
40
+		);
41
+		add_filter(
42
+			'FHEE__EE_Email_messenger__get_template_fields',
43
+			array($this, 'email_messenger_template_fields'),
44
+			5,
45
+			2
46
+		);
47
+		add_filter(
48
+			'FHEE__EE_Html_messenger__get_template_fields',
49
+			array($this, 'html_messenger_template_fields'),
50
+			5,
51
+			2
52
+		);
53
+		add_filter(
54
+			'FHEE__EE_Html_messenger__get_validator_config',
55
+			array($this, 'html_messenger_validator_config'),
56
+			5,
57
+			2
58
+		);
59
+		add_filter('FHEE__EE_Pdf_messenger__get_template_fields', array($this, 'pdf_messenger_template_fields'), 5, 2);
60
+		add_filter(
61
+			'FHEE__EE_Pdf_messenger__get_validator_config',
62
+			array($this, 'pdf_messenger_validator_config'),
63
+			5,
64
+			2
65
+		);
66
+		add_filter(
67
+			'FHEE__EE_Messages_Template_Pack__get_specific_template__contents',
68
+			array($this, 'new_default_templates'),
69
+			5,
70
+			7
71
+		);
72
+		add_filter(
73
+			'FHEE__EE_Messages_Base__get_valid_shortcodes',
74
+			array($this, 'message_types_valid_shortcodes'),
75
+			5,
76
+			2
77
+		);
78
+
79
+		// shortcode parsers
80
+		add_filter('FHEE__EE_Attendee_Shortcodes__shortcodes', array($this, 'additional_attendee_shortcodes'), 5, 2);
81
+		add_filter('FHEE__EE_Attendee_Shortcodes__parser_after', array($this, 'additional_attendee_parser'), 5, 5);
82
+		add_filter(
83
+			'FHEE__EE_Recipient_List_Shortcodes__shortcodes',
84
+			array($this, 'additional_recipient_details_shortcodes'),
85
+			5,
86
+			2
87
+		);
88
+		add_filter(
89
+			'FHEE__EE_Recipient_List_Shortcodes__parser_after',
90
+			array($this, 'additional_recipient_details_parser'),
91
+			5,
92
+			5
93
+		);
94
+		add_filter(
95
+			'FHEE__EE_Primary_Registration_List_Shortcodes__shortcodes',
96
+			array($this, 'additional_primary_registration_details_shortcodes'),
97
+			5,
98
+			2
99
+		);
100
+		add_filter(
101
+			'FHEE__EE_Primary_Registration_List_Shortcodes__parser_after',
102
+			array($this, 'additional_primary_registration_details_parser'),
103
+			5,
104
+			5
105
+		);
106
+
107
+		/**
108
+		 * @since 4.2.0
109
+		 */
110
+		add_filter('FHEE__EE_Datetime_Shortcodes__shortcodes', array($this, 'additional_datetime_shortcodes'), 10, 2);
111
+		add_filter('FHEE__EE_Datetime_Shortcodes__parser_after', array($this, 'additional_datetime_parser'), 10, 5);
112
+
113
+		/**
114
+		 * @since 4.3.0
115
+		 */
116
+		// eat our own dog food!
117
+		add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_message_types'));
118
+		add_action('EE_Brewing_Regular___messages_caf', array($this, 'register_caf_shortcodes'));
119
+		do_action('EE_Brewing_Regular___messages_caf');
120
+	}
121
+
122
+
123
+	/**
124
+	 * This just allows us to add additional paths to the autoloader (EED_Messages::autoload_messages()) for the
125
+	 * messages system.
126
+	 *
127
+	 * @param  array $dir_ref original array of paths
128
+	 *
129
+	 * @return array           appended paths
130
+	 */
131
+	public function messages_autoload_paths($dir_ref)
132
+	{
133
+		$dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/';
134
+
135
+		return $dir_ref;
136
+	}
137
+
138
+
139
+	public function email_messenger_validator_config($validator_config, EE_Email_messenger $messenger)
140
+	{
141
+		$validator_config['attendee_list'] = array(
142
+			'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'),
143
+			'required'   => array('[ATTENDEE_LIST]'),
144
+		);
145
+		$validator_config['question_list'] = array(
146
+			'shortcodes' => array('question'),
147
+			'required'   => array('[QUESTION_LIST]'),
148
+		);
149
+
150
+		return $validator_config;
151
+	}
152
+
153
+
154
+	public function html_messenger_validator_config($validator_config, EE_Html_messenger $messenger)
155
+	{
156
+		$validator_config['attendee_list'] = array(
157
+			'shortcodes' => array('attendee', 'question_list'),
158
+			'required'   => array('[ATTENDEE_LIST]'),
159
+		);
160
+		$validator_config['question_list'] = array(
161
+			'shortcodes' => array('question'),
162
+			'required'   => array('[QUESTION_LIST]'),
163
+		);
164
+
165
+		return $validator_config;
166
+	}
167
+
168
+
169
+	public function pdf_messenger_validator_config($validator_config, EE_Pdf_messenger $messenger)
170
+	{
171
+		$validator_config['attendee_list'] = array(
172
+			'shortcodes' => array('attendee', 'event_list', 'ticket_list', 'question_list'),
173
+			'required'   => array('[ATTENDEE_LIST]'),
174
+		);
175
+		$validator_config['question_list'] = array(
176
+			'shortcodes' => array('question'),
177
+			'required'   => array('[QUESTION_LIST]'),
178
+		);
179
+
180
+		return $validator_config;
181
+	}
182
+
183
+
184
+	public function email_messenger_template_fields($template_fields, EE_Email_messenger $messenger)
185
+	{
186
+		$template_fields['extra']['content']['question_list'] = array(
187
+			'input'               => 'textarea',
188
+			'label'               => '[QUESTION_LIST]',
189
+			'type'                => 'string',
190
+			'required'            => true,
191
+			'validation'          => true,
192
+			'format'              => '%s',
193
+			'css_class'           => 'large-text',
194
+			'rows'                => '5',
195
+			'shortcodes_required' => array('[QUESTION_LIST]'),
196
+		);
197
+
198
+		return $template_fields;
199
+	}
200
+
201
+
202
+	public function html_messenger_template_fields($template_fields, EE_Html_messenger $messenger)
203
+	{
204
+		$template_fields['extra']['content']['question_list'] = array(
205
+			'input'               => 'textarea',
206
+			'label'               => '[QUESTION_LIST]',
207
+			'type'                => 'string',
208
+			'required'            => true,
209
+			'validation'          => true,
210
+			'format'              => '%s',
211
+			'css_class'           => 'large-text',
212
+			'rows'                => '5',
213
+			'shortcodes_required' => array('[QUESTION_LIST]'),
214
+		);
215
+
216
+		return $template_fields;
217
+	}
218
+
219
+
220
+	public function pdf_messenger_template_fields($template_fields, EE_Pdf_messenger $messenger)
221
+	{
222
+		$template_fields['extra']['content']['question_list'] = array(
223
+			'input'               => 'textarea',
224
+			'label'               => '[QUESTION_LIST]',
225
+			'type'                => 'string',
226
+			'required'            => true,
227
+			'validation'          => true,
228
+			'format'              => '%s',
229
+			'css_class'           => 'large-text',
230
+			'rows'                => '5',
231
+			'shortcodes_required' => array('[QUESTION_LIST]'),
232
+		);
233
+
234
+		return $template_fields;
235
+	}
236
+
237
+
238
+	public function new_default_templates(
239
+		$contents,
240
+		$actual_path,
241
+		EE_messenger $messenger,
242
+		EE_message_type $message_type,
243
+		$field,
244
+		$context,
245
+		EE_Messages_Template_Pack $template_pack
246
+	) {
247
+
248
+		// we're only modifying templates for the default template pack
249
+		if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
250
+			return $contents;
251
+		}
252
+
253
+		// the template file name we're replacing contents for.
254
+		$template_file_prefix = $field . '_' . $context;
255
+		$msg_prefix = $messenger->name . '_' . $message_type->name . '_';
256
+
257
+		$base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/';
258
+
259
+		if ($messenger->name == 'email' && $message_type->name == 'registration') {
260
+			switch ($template_file_prefix) {
261
+				case 'question_list_admin':
262
+				case 'question_list_attendee':
263
+				case 'question_list_primary_attendee':
264
+					$path = $base_path . $msg_prefix . 'question_list.template.php';
265
+					$contents = EEH_Template::display_template($path, array(), true);
266
+					break;
267
+
268
+				case 'attendee_list_primary_attendee':
269
+					$path = $base_path . $msg_prefix . 'attendee_list.template.php';
270
+					$contents = EEH_Template::display_template($path, array(), true);
271
+					break;
272
+
273
+				case 'attendee_list_admin':
274
+					$path = $base_path . $msg_prefix . 'attendee_list_admin.template.php';
275
+					$contents = EEH_Template::display_template(
276
+						$path,
277
+						array(),
278
+						true
279
+					);
280
+					break;
281
+
282
+				case 'attendee_list_attendee':
283
+					$contents = '';
284
+					break;
285
+
286
+				case 'event_list_attendee':
287
+					$path = $base_path . $msg_prefix . 'event_list_attendee.template.php';
288
+					$contents = EEH_Template::display_template($path, array(), true);
289
+					break;
290
+			}
291
+		} elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') {
292
+			switch ($template_file_prefix) {
293
+				case 'content_attendee':
294
+					$path = $base_path . $msg_prefix . 'content.template.php';
295
+					$contents = EEH_Template::display_template($path, array(), true);
296
+					break;
297
+
298
+				case 'newsletter_content_attendee':
299
+					$path = $base_path . $msg_prefix . 'newsletter_content.template.php';
300
+					$contents = EEH_Template::display_template($path, array(), true);
301
+					break;
302
+
303
+				case 'newsletter_subject_attendee':
304
+					$path = $base_path . $msg_prefix . 'subject.template.php';
305
+					$contents = EEH_Template::display_template($path, array(), true);
306
+					break;
307
+			}
308
+		} elseif ($messenger->name == 'html' && $message_type->name == 'receipt') {
309
+			switch ($template_file_prefix) {
310
+				case 'attendee_list_purchaser':
311
+					$path = $base_path . $msg_prefix . 'attendee_list.template.php';
312
+					$contents = EEH_Template::display_template($path, array(), true);
313
+					break;
314
+			}
315
+		}
316
+
317
+		return $contents;
318
+	}
319
+
320
+
321
+	public function message_types_valid_shortcodes($valid_shortcodes, EE_Messages_Base $msg)
322
+	{
323
+		// make sure question_list and question are ONLY added for the core message types.  Any other message types will have to explicitly set question_list as a valid shortcode.
324
+		$include_with = array(
325
+			'registration',
326
+			'cancelled_registration',
327
+			'declined_registration',
328
+			'not_approved_registration',
329
+			'payment_declined',
330
+			'payment_failed',
331
+			'payment_cancelled',
332
+			'payment',
333
+			'payment_reminder',
334
+			'pending_approval',
335
+			'registration_summary',
336
+			'invoice',
337
+			'receipt',
338
+		);
339
+		if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) {
340
+			$contexts = array_keys($msg->get_contexts());
341
+			foreach ($contexts as $context) {
342
+				$valid_shortcodes[ $context ][] = 'question_list';
343
+				$valid_shortcodes[ $context ][] = 'question';
344
+			}
345
+		}
346
+
347
+		return $valid_shortcodes;
348
+	}
349
+
350
+
351
+	public function additional_attendee_shortcodes($shortcodes, $shortcode_parser)
352
+	{
353
+		$shortcodes['[ANSWER_*]'] = __(
354
+			'This is a special dynamic shortcode. Right after the "*", add the exact text of a existing question, and if there is an answer for that question for this registrant, that will take the place of this shortcode.',
355
+			'event_espresso'
356
+		);
357
+
358
+		return $shortcodes;
359
+	}
360
+
361
+
362
+	public function additional_attendee_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
363
+	{
364
+
365
+		if (strpos($shortcode, '[ANSWER_*') === false
366
+			|| ! isset($extra_data['data']->questions)
367
+			|| ! isset($extra_data['data']->registrations)
368
+		) {
369
+			return $parsed;
370
+		}
371
+
372
+		// let's get the question from the code.
373
+		$shortcode = str_replace('[ANSWER_*', '', $shortcode);
374
+		$shortcode = trim(str_replace(']', '', $shortcode));
375
+
376
+		$registration = $data instanceof EE_Registration ? $data : null;
377
+		$registration = ! $registration instanceof EE_Registration && is_array(
378
+			$extra_data
379
+		) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Registration ? $extra_data['data'] : $registration;
380
+
381
+		$aee = $data instanceof EE_Messages_Addressee ? $data : null;
382
+		$aee = ! $aee instanceof EE_Messages_Addressee && is_array(
383
+			$extra_data
384
+		) && isset($extra_data['data']) ? $extra_data['data'] : $aee;
385
+
386
+		if (! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) {
387
+			return $parsed;
388
+		}
389
+
390
+		// now let's figure out which question has this text.
391
+		foreach ($aee->questions as $ansid => $question) {
392
+			if ($question instanceof EE_Question
393
+				&& trim($question->display_text()) == trim($shortcode)
394
+				&& isset($aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ])
395
+			) {
396
+				return $aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]->get_pretty(
397
+					'ANS_value',
398
+					'no_wpautop'
399
+				);
400
+			}
401
+		}
402
+
403
+		// nothing!
404
+		return $parsed;
405
+	}
406
+
407
+
408
+	/**
409
+	 * Callback for additional shortcodes filter for adding additional datetime shortcodes.
410
+	 *
411
+	 * @since  4.2
412
+	 *
413
+	 * @param  array                  $shortcodes         array of shortcodes and
414
+	 *                                                    descriptions
415
+	 * @param  EE_Datetime_Shortcodes $shortcode_parser   EE_Shortcodes object
416
+	 *
417
+	 * @return array                                        array of shortcodes and
418
+	 *                                                        descriptions
419
+	 */
420
+	public function additional_datetime_shortcodes($shortcodes, $shortcode_parser)
421
+	{
422
+		$shortcodes['[DTT_NAME]'] = __(
423
+			'This will be parsed to the Title given for a Datetime',
424
+			'event_espresso'
425
+		);
426
+		$shortcodes['[DTT_DESCRIPTION]'] = __(
427
+			'This will be parsed to the description for a Datetime',
428
+			'event_espresso'
429
+		);
430
+		$shortcodes['[DTT_NAME_OR_DATES]'] = __(
431
+			'When parsed, if the Datetime has a name, it is used, otherwise a formatted string including the start date and end date will be used.',
432
+			'event_espresso'
433
+		);
434
+
435
+		return $shortcodes;
436
+	}
437
+
438
+
439
+	/**
440
+	 * Callback for additional shortcodes parser filter used for adding parser for new
441
+	 * Datetime shortcodes
442
+	 *
443
+	 * @since  4.2
444
+	 *
445
+	 * @param  string                 $parsed     The finished parsed string for the given shortcode.
446
+	 * @param  string                 $shortcode  The shortcode being parsed.
447
+	 * @param  object                 $data       The incoming data object for the Shortcode Parser.
448
+	 * @param  object                 $extra_data The incoming extra date object for the Shortcode
449
+	 *                                            Parser.
450
+	 * @param  EE_Datetime_Shortcodes $shortcode_parser
451
+	 *
452
+	 * @return string                   The new parsed string.
453
+	 */
454
+	public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
455
+	{
456
+
457
+		if (! $data instanceof EE_Datetime) {
458
+			return ''; // get out because we can only parse with the datetime object.
459
+		}
460
+
461
+		switch ($shortcode) {
462
+			case '[DTT_NAME]':
463
+				return $data->name();
464
+				break;
465
+			case '[DTT_DESCRIPTION]':
466
+				return $data->description();
467
+				break;
468
+			case '[DTT_NAME_OR_DATES]':
469
+				return $data->get_dtt_display_name(true);
470
+				break;
471
+			default:
472
+				return $parsed;
473
+				break;
474
+		}
475
+	}
476
+
477
+
478
+	public function additional_recipient_details_shortcodes($shortcodes, $shortcode_parser)
479
+	{
480
+		$shortcodes['[RECIPIENT_QUESTION_LIST]'] = __(
481
+			'This is used to indicate where you want the list of questions and answers to show for the person receiving the message.',
482
+			'event_espresso'
483
+		);
484
+
485
+		return $shortcodes;
486
+	}
487
+
488
+
489
+	/**
490
+	 * Callback for FHEE__EE_Recipient_List_Shortcodes__parser_after filter (dynamic filter).
491
+	 *
492
+	 * @param string         $parsed           The original parsed content for the shortcode
493
+	 * @param string         $shortcode        The shortcode being parsed
494
+	 * @param array          $data             The shortcode parser data array
495
+	 * @param array          $extra_data       The shortcode parser extra data array
496
+	 * @param \EE_Shortcodes $shortcode_parser Shortcode parser.
497
+	 *
498
+	 * @return string
499
+	 */
500
+	public function additional_recipient_details_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
501
+	{
502
+
503
+		if (array($data) && ! isset($data['data'])) {
504
+			return $parsed;
505
+		}
506
+
507
+		$recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;
508
+		$recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;
509
+
510
+		if (! $recipient instanceof EE_Messages_Addressee) {
511
+			return $parsed;
512
+		}
513
+
514
+		switch ($shortcode) {
515
+			case '[RECIPIENT_QUESTION_LIST]':
516
+				$att = $recipient->att_obj;
517
+				$registrations_on_attendee = $att instanceof EE_Attendee
518
+					? $recipient->attendees[ $att->ID() ]['reg_objs']
519
+					: array();
520
+				$registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee;
521
+				$answers = array();
522
+
523
+				$template = is_array($data['template']) && isset($data['template']['question_list'])
524
+					? $data['template']['question_list']
525
+					: $extra_data['template']['question_list'];
526
+				$valid_shortcodes = array('question');
527
+
528
+				// if the context is main_content then get all answers for all registrations on this attendee
529
+				if ($data['data'] instanceof EE_Messages_Addressee) {
530
+					foreach ($registrations_on_attendee as $reg) {
531
+						if ($reg instanceof EE_Registration) {
532
+							$anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs'])
533
+								? $recipient->registrations[ $reg->ID() ]['ans_objs']
534
+								: array();
535
+							foreach ($anss as $ans) {
536
+								if ($ans instanceof EE_Answer) {
537
+									$answers[ $ans->ID() ] = $ans;
538
+								}
539
+							}
540
+						}
541
+					}
542
+				}
543
+
544
+				// if the context is the event list parser, then let's return just the answers for all registrations attached to the recipient for that event.
545
+				if ($data['data'] instanceof EE_Event) {
546
+					$event = $data['data'];
547
+					foreach ($registrations_on_attendee as $reg) {
548
+						if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) {
549
+							$anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs'])
550
+								? $recipient->registrations[ $reg->ID() ]['ans_objs']
551
+								: array();
552
+							foreach ($anss as $ans) {
553
+								if ($ans instanceof EE_Answer) {
554
+									$answers[ $ans->ID() ] = $ans;
555
+								}
556
+							}
557
+						}
558
+					}
559
+				}
560
+
561
+				$questions = $questions = isset($recipient->questions) ? $recipient->questions : array();
562
+
563
+				// if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
564
+				// object on it.
565
+				if (! isset($extra_data['data'])) {
566
+					$extra_data['data'] = $recipient;
567
+				}
568
+
569
+				return $this->_parse_question_list_for_primary_or_recipient_registration(
570
+					$shortcode_parser,
571
+					$questions,
572
+					$answers,
573
+					$template,
574
+					$valid_shortcodes,
575
+					$extra_data
576
+				);
577
+				break;
578
+
579
+			default:
580
+				return $parsed;
581
+				break;
582
+		}
583
+	}
584
+
585
+
586
+	public function additional_primary_registration_details_shortcodes($shortcodes, $shortcode_parser)
587
+	{
588
+		$shortcodes['[PRIMARY_REGISTRANT_QUESTION_LIST]'] = __(
589
+			'This is used to indicate the questions and answers for the primary_registrant. It should be placed in the "[attendee_list]" field',
590
+			'event_espresso'
591
+		);
592
+
593
+		return $shortcodes;
594
+	}
595
+
596
+
597
+	/**
598
+	 * Callback for FHEE__EE_Primary_Registration_List_Shortcodes__parser_after filter (dynamic filter).
599
+	 *
600
+	 * @param string         $parsed           The original parsed content for the shortcode
601
+	 * @param string         $shortcode        The shortcode being parsed
602
+	 * @param array          $data             The shortcode parser data array
603
+	 * @param array          $extra_data       The shortcode parser extra data array
604
+	 * @param \EE_Shortcodes $shortcode_parser Shortcode parser.
605
+	 *
606
+	 * @return string
607
+	 */
608
+	public function additional_primary_registration_details_parser(
609
+		$parsed,
610
+		$shortcode,
611
+		$data,
612
+		$extra_data,
613
+		$shortcode_parser
614
+	) {
615
+		if (array($data) && ! isset($data['data'])) {
616
+			return $parsed;
617
+		}
618
+
619
+		$recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;
620
+		$recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;
621
+
622
+		if (! $recipient instanceof EE_Messages_Addressee) {
623
+			return $parsed;
624
+		}
625
+
626
+		switch ($shortcode) {
627
+			case '[PRIMARY_REGISTRANT_QUESTION_LIST]':
628
+				if (! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) {
629
+					return '';
630
+				}
631
+				$registration = $recipient->primary_reg_obj;
632
+				$answers = isset($recipient->registrations[ $registration->ID() ]['ans_objs'])
633
+					? $recipient->registrations[ $registration->ID() ]['ans_objs']
634
+					: array();
635
+				if (empty($answers)) {
636
+					return '';
637
+				}
638
+				$template = is_array($data['template']) && isset($data['template']['question_list'])
639
+					? $data['template']['question_list']
640
+					: $extra_data['template']['question_list'];
641
+				$valid_shortcodes = array('question');
642
+				$answers = $recipient->registrations[ $registration->ID() ]['ans_objs'];
643
+				$questions = isset($recipient->questions) ? $recipient->questions : array();
644
+				// if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
645
+				// object on it.
646
+				if (! isset($extra_data['data'])) {
647
+					$extra_data['data'] = $recipient;
648
+				}
649
+				return $this->_parse_question_list_for_primary_or_recipient_registration(
650
+					$shortcode_parser,
651
+					$questions,
652
+					$answers,
653
+					$template,
654
+					$valid_shortcodes,
655
+					$extra_data
656
+				);
657
+				break;
658
+
659
+			default:
660
+				return $parsed;
661
+				break;
662
+		}
663
+	}
664
+
665
+
666
+	/**
667
+	 * Takes care of registering the  message types that are only available in caffeinated EE.
668
+	 *
669
+	 * @since   4.3.2
670
+	 *
671
+	 * @return  void
672
+	 */
673
+	public function register_caf_message_types()
674
+	{
675
+		// register newsletter message type
676
+		$setup_args = array(
677
+			'mtfilename'                                       => 'EE_Newsletter_message_type.class.php',
678
+			'autoloadpaths'                                    => array(
679
+				EE_CAF_LIBRARIES . 'messages/message_type/newsletter/',
680
+			),
681
+			'messengers_to_activate_with'                      => array('email'),
682
+			'messengers_to_validate_with'                      => array('email'),
683
+			'messengers_supporting_default_template_pack_with' => array('email'),
684
+		);
685
+		EE_Register_Message_Type::register('newsletter', $setup_args);
686
+
687
+		// register payment reminder message type
688
+		$setup_args = array(
689
+			'mtfilename'                                       => 'EE_Payment_Reminder_message_type.class.php',
690
+			'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'),
691
+			'messengers_to_activate_with'                      => array('email'),
692
+			'messengers_to_validate_with'                      => array('email'),
693
+			'messengers_supporting_default_template_pack_with' => array('email'),
694
+		);
695
+		EE_Register_Message_Type::register('payment_reminder', $setup_args);
696
+
697
+		// register payment declined message type
698
+		$setup_args = array(
699
+			'mtfilename'                                       => 'EE_Payment_Declined_message_type.class.php',
700
+			'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'),
701
+			'messengers_to_activate_with'                      => array('email'),
702
+			'messengers_to_validate_with'                      => array('email'),
703
+			'messengers_supporting_default_template_pack_with' => array('email'),
704
+		);
705
+		EE_Register_Message_Type::register('payment_declined', $setup_args);
706
+
707
+		// register registration declined message type
708
+		$setup_args = array(
709
+			'mtfilename'                                       => 'EE_Declined_Registration_message_type.class.php',
710
+			'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'),
711
+			'messengers_to_activate_with'                      => array('email'),
712
+			'messengers_to_validate_with'                      => array('email'),
713
+			'messengers_supporting_default_template_pack_with' => array('email'),
714
+		);
715
+		EE_Register_Message_Type::register('declined_registration', $setup_args);
716
+
717
+		// register registration cancelled message type
718
+		$setup_args = array(
719
+			'mtfilename'                                       => 'EE_Cancelled_Registration_message_type.class.php',
720
+			'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'),
721
+			'messengers_to_activate_with'                      => array('email'),
722
+			'messengers_to_validate_with'                      => array('email'),
723
+			'messengers_supporting_default_template_pack_with' => array('email'),
724
+		);
725
+		EE_Register_Message_Type::register('cancelled_registration', $setup_args);
726
+
727
+
728
+		// register payment failed message type
729
+		$setup_args = array(
730
+			'mtfilename'                                       => 'EE_Payment_Failed_message_type.class.php',
731
+			'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'),
732
+			'messengers_to_activate_with'                      => array('email'),
733
+			'messengers_to_validate_with'                      => array('email'),
734
+			'messengers_supporting_default_template_pack_with' => array('email'),
735
+		);
736
+		EE_Register_Message_Type::register('payment_failed', $setup_args);
737
+
738
+		// register payment declined message type
739
+		$setup_args = array(
740
+			'mtfilename'                                       => 'EE_Payment_Cancelled_message_type.class.php',
741
+			'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'),
742
+			'messengers_to_activate_with'                      => array('email'),
743
+			'messengers_to_validate_with'                      => array('email'),
744
+			'messengers_supporting_default_template_pack_with' => array('email'),
745
+		);
746
+		EE_Register_Message_Type::register('payment_cancelled', $setup_args);
747
+	}
748
+
749
+
750
+	/**
751
+	 * Takes care of registering the  shortcode libraries implemented with caffeinated EE and set up related items.
752
+	 *
753
+	 * @since   4.3.2
754
+	 *
755
+	 * @return void
756
+	 */
757
+	public function register_caf_shortcodes()
758
+	{
759
+		$setup_args = array(
760
+			'autoloadpaths'                 => array(
761
+				EE_CAF_LIBRARIES . 'shortcodes/',
762
+			),
763
+			'msgr_validator_callback'       => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'),
764
+			'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'),
765
+			'list_type_shortcodes'          => array('[NEWSLETTER_CONTENT]'),
766
+		);
767
+		EE_Register_Messages_Shortcode_Library::register('newsletter', $setup_args);
768
+	}
769
+
770
+
771
+	/**
772
+	 * Parses a question list shortcode using given data and template
773
+	 *
774
+	 * @param \EE_Shortcodes $shortcode_parser
775
+	 * @param EE_Question[]  $questions        An array of questions indexed by answer id.
776
+	 * @param EE_Answer[]    $answers          An array of answer objects
777
+	 * @param string         $template         Template content to be parsed.
778
+	 * @param array          $valid_shortcodes Valid shortcodes for the template being parsed.
779
+	 * @param array          $extra_data       Extra data that might be used when parsing the template.
780
+	 */
781
+	protected function _parse_question_list_for_primary_or_recipient_registration(
782
+		$shortcode_parser,
783
+		$questions,
784
+		$answers,
785
+		$template,
786
+		$valid_shortcodes,
787
+		$extra_data
788
+	) {
789
+		$question_list = '';
790
+		/** @var EEH_Parse_Shortcodes $shortcode_helper */
791
+		$shortcode_helper = $shortcode_parser->get_shortcode_helper();
792
+		foreach ($answers as $answer) {
793
+			if ($answer instanceof EE_Answer) {
794
+				// first see if the question is in our $questions array. If not then try to get from answer object.
795
+				$question = isset($questions[ $answer->ID() ]) ? $questions[ $answer->ID() ] : null;
796
+				$question = ! $question instanceof EE_Question ? $answer->question() : $question;
797
+				if (! $question instanceof EE_Question
798
+					|| (
799
+						$question instanceof EE_Question
800
+						&& $question->admin_only()
801
+					)
802
+				) {
803
+					continue;
804
+				}
805
+				$question_list .= $shortcode_helper->parse_question_list_template(
806
+					$template,
807
+					$answer,
808
+					$valid_shortcodes,
809
+					$extra_data
810
+				);
811
+			}
812
+		}
813
+		return $question_list;
814
+	}
815 815
 }
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      */
131 131
     public function messages_autoload_paths($dir_ref)
132 132
     {
133
-        $dir_ref[] = EE_CAF_LIBRARIES . 'shortcodes/';
133
+        $dir_ref[] = EE_CAF_LIBRARIES.'shortcodes/';
134 134
 
135 135
         return $dir_ref;
136 136
     }
@@ -246,32 +246,32 @@  discard block
 block discarded – undo
246 246
     ) {
247 247
 
248 248
         // we're only modifying templates for the default template pack
249
-        if (! $template_pack instanceof EE_Messages_Template_Pack_Default) {
249
+        if ( ! $template_pack instanceof EE_Messages_Template_Pack_Default) {
250 250
             return $contents;
251 251
         }
252 252
 
253 253
         // the template file name we're replacing contents for.
254
-        $template_file_prefix = $field . '_' . $context;
255
-        $msg_prefix = $messenger->name . '_' . $message_type->name . '_';
254
+        $template_file_prefix = $field.'_'.$context;
255
+        $msg_prefix = $messenger->name.'_'.$message_type->name.'_';
256 256
 
257
-        $base_path = EE_CAF_LIBRARIES . 'messages/defaults/default/';
257
+        $base_path = EE_CAF_LIBRARIES.'messages/defaults/default/';
258 258
 
259 259
         if ($messenger->name == 'email' && $message_type->name == 'registration') {
260 260
             switch ($template_file_prefix) {
261 261
                 case 'question_list_admin':
262 262
                 case 'question_list_attendee':
263 263
                 case 'question_list_primary_attendee':
264
-                    $path = $base_path . $msg_prefix . 'question_list.template.php';
264
+                    $path = $base_path.$msg_prefix.'question_list.template.php';
265 265
                     $contents = EEH_Template::display_template($path, array(), true);
266 266
                     break;
267 267
 
268 268
                 case 'attendee_list_primary_attendee':
269
-                    $path = $base_path . $msg_prefix . 'attendee_list.template.php';
269
+                    $path = $base_path.$msg_prefix.'attendee_list.template.php';
270 270
                     $contents = EEH_Template::display_template($path, array(), true);
271 271
                     break;
272 272
 
273 273
                 case 'attendee_list_admin':
274
-                    $path = $base_path . $msg_prefix . 'attendee_list_admin.template.php';
274
+                    $path = $base_path.$msg_prefix.'attendee_list_admin.template.php';
275 275
                     $contents = EEH_Template::display_template(
276 276
                         $path,
277 277
                         array(),
@@ -284,31 +284,31 @@  discard block
 block discarded – undo
284 284
                     break;
285 285
 
286 286
                 case 'event_list_attendee':
287
-                    $path = $base_path . $msg_prefix . 'event_list_attendee.template.php';
287
+                    $path = $base_path.$msg_prefix.'event_list_attendee.template.php';
288 288
                     $contents = EEH_Template::display_template($path, array(), true);
289 289
                     break;
290 290
             }
291 291
         } elseif ($messenger->name == 'email' && $message_type->name == 'newsletter') {
292 292
             switch ($template_file_prefix) {
293 293
                 case 'content_attendee':
294
-                    $path = $base_path . $msg_prefix . 'content.template.php';
294
+                    $path = $base_path.$msg_prefix.'content.template.php';
295 295
                     $contents = EEH_Template::display_template($path, array(), true);
296 296
                     break;
297 297
 
298 298
                 case 'newsletter_content_attendee':
299
-                    $path = $base_path . $msg_prefix . 'newsletter_content.template.php';
299
+                    $path = $base_path.$msg_prefix.'newsletter_content.template.php';
300 300
                     $contents = EEH_Template::display_template($path, array(), true);
301 301
                     break;
302 302
 
303 303
                 case 'newsletter_subject_attendee':
304
-                    $path = $base_path . $msg_prefix . 'subject.template.php';
304
+                    $path = $base_path.$msg_prefix.'subject.template.php';
305 305
                     $contents = EEH_Template::display_template($path, array(), true);
306 306
                     break;
307 307
             }
308 308
         } elseif ($messenger->name == 'html' && $message_type->name == 'receipt') {
309 309
             switch ($template_file_prefix) {
310 310
                 case 'attendee_list_purchaser':
311
-                    $path = $base_path . $msg_prefix . 'attendee_list.template.php';
311
+                    $path = $base_path.$msg_prefix.'attendee_list.template.php';
312 312
                     $contents = EEH_Template::display_template($path, array(), true);
313 313
                     break;
314 314
             }
@@ -339,8 +339,8 @@  discard block
 block discarded – undo
339 339
         if ($msg instanceof EE_message_type && in_array($msg->name, $include_with)) {
340 340
             $contexts = array_keys($msg->get_contexts());
341 341
             foreach ($contexts as $context) {
342
-                $valid_shortcodes[ $context ][] = 'question_list';
343
-                $valid_shortcodes[ $context ][] = 'question';
342
+                $valid_shortcodes[$context][] = 'question_list';
343
+                $valid_shortcodes[$context][] = 'question';
344 344
             }
345 345
         }
346 346
 
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
             $extra_data
384 384
         ) && isset($extra_data['data']) ? $extra_data['data'] : $aee;
385 385
 
386
-        if (! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) {
386
+        if ( ! $registration instanceof EE_Registration || ! $aee instanceof EE_Messages_Addressee) {
387 387
             return $parsed;
388 388
         }
389 389
 
@@ -391,9 +391,9 @@  discard block
 block discarded – undo
391 391
         foreach ($aee->questions as $ansid => $question) {
392 392
             if ($question instanceof EE_Question
393 393
                 && trim($question->display_text()) == trim($shortcode)
394
-                && isset($aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ])
394
+                && isset($aee->registrations[$registration->ID()]['ans_objs'][$ansid])
395 395
             ) {
396
-                return $aee->registrations[ $registration->ID() ]['ans_objs'][ $ansid ]->get_pretty(
396
+                return $aee->registrations[$registration->ID()]['ans_objs'][$ansid]->get_pretty(
397 397
                     'ANS_value',
398 398
                     'no_wpautop'
399 399
                 );
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
     public function additional_datetime_parser($parsed, $shortcode, $data, $extra_data, $shortcode_parser)
455 455
     {
456 456
 
457
-        if (! $data instanceof EE_Datetime) {
457
+        if ( ! $data instanceof EE_Datetime) {
458 458
             return ''; // get out because we can only parse with the datetime object.
459 459
         }
460 460
 
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
         $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;
508 508
         $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;
509 509
 
510
-        if (! $recipient instanceof EE_Messages_Addressee) {
510
+        if ( ! $recipient instanceof EE_Messages_Addressee) {
511 511
             return $parsed;
512 512
         }
513 513
 
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
             case '[RECIPIENT_QUESTION_LIST]':
516 516
                 $att = $recipient->att_obj;
517 517
                 $registrations_on_attendee = $att instanceof EE_Attendee
518
-                    ? $recipient->attendees[ $att->ID() ]['reg_objs']
518
+                    ? $recipient->attendees[$att->ID()]['reg_objs']
519 519
                     : array();
520 520
                 $registrations_on_attendee = empty($registrations_on_attendee) && $recipient->reg_obj instanceof EE_Registration ? array($recipient->reg_obj) : $registrations_on_attendee;
521 521
                 $answers = array();
@@ -529,12 +529,12 @@  discard block
 block discarded – undo
529 529
                 if ($data['data'] instanceof EE_Messages_Addressee) {
530 530
                     foreach ($registrations_on_attendee as $reg) {
531 531
                         if ($reg instanceof EE_Registration) {
532
-                            $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs'])
533
-                                ? $recipient->registrations[ $reg->ID() ]['ans_objs']
532
+                            $anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs'])
533
+                                ? $recipient->registrations[$reg->ID()]['ans_objs']
534 534
                                 : array();
535 535
                             foreach ($anss as $ans) {
536 536
                                 if ($ans instanceof EE_Answer) {
537
-                                    $answers[ $ans->ID() ] = $ans;
537
+                                    $answers[$ans->ID()] = $ans;
538 538
                                 }
539 539
                             }
540 540
                         }
@@ -546,12 +546,12 @@  discard block
 block discarded – undo
546 546
                     $event = $data['data'];
547 547
                     foreach ($registrations_on_attendee as $reg) {
548 548
                         if ($reg instanceof EE_Registration && $reg->event_ID() == $event->ID()) {
549
-                            $anss = ! empty($recipient->registrations[ $reg->ID() ]['ans_objs'])
550
-                                ? $recipient->registrations[ $reg->ID() ]['ans_objs']
549
+                            $anss = ! empty($recipient->registrations[$reg->ID()]['ans_objs'])
550
+                                ? $recipient->registrations[$reg->ID()]['ans_objs']
551 551
                                 : array();
552 552
                             foreach ($anss as $ans) {
553 553
                                 if ($ans instanceof EE_Answer) {
554
-                                    $answers[ $ans->ID() ] = $ans;
554
+                                    $answers[$ans->ID()] = $ans;
555 555
                                 }
556 556
                             }
557 557
                         }
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
 
563 563
                 // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
564 564
                 // object on it.
565
-                if (! isset($extra_data['data'])) {
565
+                if ( ! isset($extra_data['data'])) {
566 566
                     $extra_data['data'] = $recipient;
567 567
                 }
568 568
 
@@ -619,18 +619,18 @@  discard block
 block discarded – undo
619 619
         $recipient = $data['data'] instanceof EE_Messages_Addressee ? $data['data'] : null;
620 620
         $recipient = ! $recipient instanceof EE_Messages_Addressee && array($extra_data) && isset($extra_data['data']) && $extra_data['data'] instanceof EE_Messages_Addressee ? $extra_data['data'] : $recipient;
621 621
 
622
-        if (! $recipient instanceof EE_Messages_Addressee) {
622
+        if ( ! $recipient instanceof EE_Messages_Addressee) {
623 623
             return $parsed;
624 624
         }
625 625
 
626 626
         switch ($shortcode) {
627 627
             case '[PRIMARY_REGISTRANT_QUESTION_LIST]':
628
-                if (! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) {
628
+                if ( ! $recipient->primary_att_obj instanceof EE_Attendee || ! $recipient->primary_reg_obj instanceof EE_Registration) {
629 629
                     return '';
630 630
                 }
631 631
                 $registration = $recipient->primary_reg_obj;
632
-                $answers = isset($recipient->registrations[ $registration->ID() ]['ans_objs'])
633
-                    ? $recipient->registrations[ $registration->ID() ]['ans_objs']
632
+                $answers = isset($recipient->registrations[$registration->ID()]['ans_objs'])
633
+                    ? $recipient->registrations[$registration->ID()]['ans_objs']
634 634
                     : array();
635 635
                 if (empty($answers)) {
636 636
                     return '';
@@ -639,11 +639,11 @@  discard block
 block discarded – undo
639 639
                     ? $data['template']['question_list']
640 640
                     : $extra_data['template']['question_list'];
641 641
                 $valid_shortcodes = array('question');
642
-                $answers = $recipient->registrations[ $registration->ID() ]['ans_objs'];
642
+                $answers = $recipient->registrations[$registration->ID()]['ans_objs'];
643 643
                 $questions = isset($recipient->questions) ? $recipient->questions : array();
644 644
                 // if $extra_data does not have a 'data' key then let's make sure we add it and set the EE_Messages_Addressee
645 645
                 // object on it.
646
-                if (! isset($extra_data['data'])) {
646
+                if ( ! isset($extra_data['data'])) {
647 647
                     $extra_data['data'] = $recipient;
648 648
                 }
649 649
                 return $this->_parse_question_list_for_primary_or_recipient_registration(
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
         $setup_args = array(
677 677
             'mtfilename'                                       => 'EE_Newsletter_message_type.class.php',
678 678
             'autoloadpaths'                                    => array(
679
-                EE_CAF_LIBRARIES . 'messages/message_type/newsletter/',
679
+                EE_CAF_LIBRARIES.'messages/message_type/newsletter/',
680 680
             ),
681 681
             'messengers_to_activate_with'                      => array('email'),
682 682
             'messengers_to_validate_with'                      => array('email'),
@@ -687,7 +687,7 @@  discard block
 block discarded – undo
687 687
         // register payment reminder message type
688 688
         $setup_args = array(
689 689
             'mtfilename'                                       => 'EE_Payment_Reminder_message_type.class.php',
690
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_reminder/'),
690
+            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES.'messages/message_type/payment_reminder/'),
691 691
             'messengers_to_activate_with'                      => array('email'),
692 692
             'messengers_to_validate_with'                      => array('email'),
693 693
             'messengers_supporting_default_template_pack_with' => array('email'),
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
         // register payment declined message type
698 698
         $setup_args = array(
699 699
             'mtfilename'                                       => 'EE_Payment_Declined_message_type.class.php',
700
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_declined/'),
700
+            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES.'messages/message_type/payment_declined/'),
701 701
             'messengers_to_activate_with'                      => array('email'),
702 702
             'messengers_to_validate_with'                      => array('email'),
703 703
             'messengers_supporting_default_template_pack_with' => array('email'),
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
         // register registration declined message type
708 708
         $setup_args = array(
709 709
             'mtfilename'                                       => 'EE_Declined_Registration_message_type.class.php',
710
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/declined_registration/'),
710
+            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES.'messages/message_type/declined_registration/'),
711 711
             'messengers_to_activate_with'                      => array('email'),
712 712
             'messengers_to_validate_with'                      => array('email'),
713 713
             'messengers_supporting_default_template_pack_with' => array('email'),
@@ -717,7 +717,7 @@  discard block
 block discarded – undo
717 717
         // register registration cancelled message type
718 718
         $setup_args = array(
719 719
             'mtfilename'                                       => 'EE_Cancelled_Registration_message_type.class.php',
720
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/cancelled_registration/'),
720
+            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES.'messages/message_type/cancelled_registration/'),
721 721
             'messengers_to_activate_with'                      => array('email'),
722 722
             'messengers_to_validate_with'                      => array('email'),
723 723
             'messengers_supporting_default_template_pack_with' => array('email'),
@@ -728,7 +728,7 @@  discard block
 block discarded – undo
728 728
         // register payment failed message type
729 729
         $setup_args = array(
730 730
             'mtfilename'                                       => 'EE_Payment_Failed_message_type.class.php',
731
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_failed/'),
731
+            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES.'messages/message_type/payment_failed/'),
732 732
             'messengers_to_activate_with'                      => array('email'),
733 733
             'messengers_to_validate_with'                      => array('email'),
734 734
             'messengers_supporting_default_template_pack_with' => array('email'),
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
         // register payment declined message type
739 739
         $setup_args = array(
740 740
             'mtfilename'                                       => 'EE_Payment_Cancelled_message_type.class.php',
741
-            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES . 'messages/message_type/payment_cancelled/'),
741
+            'autoloadpaths'                                    => array(EE_CAF_LIBRARIES.'messages/message_type/payment_cancelled/'),
742 742
             'messengers_to_activate_with'                      => array('email'),
743 743
             'messengers_to_validate_with'                      => array('email'),
744 744
             'messengers_supporting_default_template_pack_with' => array('email'),
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
     {
759 759
         $setup_args = array(
760 760
             'autoloadpaths'                 => array(
761
-                EE_CAF_LIBRARIES . 'shortcodes/',
761
+                EE_CAF_LIBRARIES.'shortcodes/',
762 762
             ),
763 763
             'msgr_validator_callback'       => array('EE_Newsletter_Shortcodes', 'messenger_validator_config'),
764 764
             'msgr_template_fields_callback' => array('EE_Newsletter_Shortcodes', 'messenger_template_fields'),
@@ -792,9 +792,9 @@  discard block
 block discarded – undo
792 792
         foreach ($answers as $answer) {
793 793
             if ($answer instanceof EE_Answer) {
794 794
                 // first see if the question is in our $questions array. If not then try to get from answer object.
795
-                $question = isset($questions[ $answer->ID() ]) ? $questions[ $answer->ID() ] : null;
795
+                $question = isset($questions[$answer->ID()]) ? $questions[$answer->ID()] : null;
796 796
                 $question = ! $question instanceof EE_Question ? $answer->question() : $question;
797
-                if (! $question instanceof EE_Question
797
+                if ( ! $question instanceof EE_Question
798 798
                     || (
799 799
                         $question instanceof EE_Question
800 800
                         && $question->admin_only()
Please login to merge, or discard this patch.
modules/single_page_checkout/EED_Single_Page_Checkout.module.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -781,7 +781,7 @@  discard block
 block discarded – undo
781 781
      * _get_transaction_and_cart_for_previous_visit
782 782
      *
783 783
      * @access private
784
-     * @return mixed EE_Transaction|NULL
784
+     * @return EE_Transaction|null EE_Transaction|NULL
785 785
      */
786 786
     private function _get_transaction_and_cart_for_previous_visit()
787 787
     {
@@ -863,7 +863,7 @@  discard block
 block discarded – undo
863 863
      *    generates a new EE_Transaction object and adds it to the $_transaction property.
864 864
      *
865 865
      * @access private
866
-     * @return mixed EE_Transaction|NULL
866
+     * @return EE_Transaction|null EE_Transaction|NULL
867 867
      */
868 868
     private function _initialize_transaction()
869 869
     {
Please login to merge, or discard this patch.
Indentation   +1796 added lines, -1796 removed lines patch added patch discarded remove patch
@@ -15,1800 +15,1800 @@
 block discarded – undo
15 15
 class EED_Single_Page_Checkout extends EED_Module
16 16
 {
17 17
 
18
-    /**
19
-     * $_initialized - has the SPCO controller already been initialized ?
20
-     *
21
-     * @access private
22
-     * @var bool $_initialized
23
-     */
24
-    private static $_initialized = false;
25
-
26
-
27
-    /**
28
-     * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
29
-     *
30
-     * @access private
31
-     * @var bool $_valid_checkout
32
-     */
33
-    private static $_checkout_verified = true;
34
-
35
-    /**
36
-     *    $_reg_steps_array - holds initial array of reg steps
37
-     *
38
-     * @access private
39
-     * @var array $_reg_steps_array
40
-     */
41
-    private static $_reg_steps_array = array();
42
-
43
-    /**
44
-     *    $checkout - EE_Checkout object for handling the properties of the current checkout process
45
-     *
46
-     * @access public
47
-     * @var EE_Checkout $checkout
48
-     */
49
-    public $checkout;
50
-
51
-
52
-    /**
53
-     * @return EED_Module|EED_Single_Page_Checkout
54
-     */
55
-    public static function instance()
56
-    {
57
-        add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
58
-        return parent::get_instance(__CLASS__);
59
-    }
60
-
61
-
62
-    /**
63
-     * @return EE_CART
64
-     */
65
-    public function cart()
66
-    {
67
-        return $this->checkout->cart;
68
-    }
69
-
70
-
71
-    /**
72
-     * @return EE_Transaction
73
-     */
74
-    public function transaction()
75
-    {
76
-        return $this->checkout->transaction;
77
-    }
78
-
79
-
80
-    /**
81
-     *    set_hooks - for hooking into EE Core, other modules, etc
82
-     *
83
-     * @access    public
84
-     * @return    void
85
-     * @throws EE_Error
86
-     */
87
-    public static function set_hooks()
88
-    {
89
-        EED_Single_Page_Checkout::set_definitions();
90
-    }
91
-
92
-
93
-    /**
94
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
95
-     *
96
-     * @access    public
97
-     * @return    void
98
-     * @throws EE_Error
99
-     */
100
-    public static function set_hooks_admin()
101
-    {
102
-        EED_Single_Page_Checkout::set_definitions();
103
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
104
-            return;
105
-        }
106
-        // going to start an output buffer in case anything gets accidentally output
107
-        // that might disrupt our JSON response
108
-        ob_start();
109
-        EED_Single_Page_Checkout::load_request_handler();
110
-        EED_Single_Page_Checkout::load_reg_steps();
111
-        // set ajax hooks
112
-        add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
113
-        add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
114
-        add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
115
-        add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
116
-        add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
117
-        add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
118
-    }
119
-
120
-
121
-    /**
122
-     *    process ajax request
123
-     *
124
-     * @param string $ajax_action
125
-     * @throws EE_Error
126
-     */
127
-    public static function process_ajax_request($ajax_action)
128
-    {
129
-        EE_Registry::instance()->REQ->set('action', $ajax_action);
130
-        EED_Single_Page_Checkout::instance()->_initialize();
131
-    }
132
-
133
-
134
-    /**
135
-     *    ajax display registration step
136
-     *
137
-     * @throws EE_Error
138
-     */
139
-    public static function display_reg_step()
140
-    {
141
-        EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
142
-    }
143
-
144
-
145
-    /**
146
-     *    ajax process registration step
147
-     *
148
-     * @throws EE_Error
149
-     */
150
-    public static function process_reg_step()
151
-    {
152
-        EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
153
-    }
154
-
155
-
156
-    /**
157
-     *    ajax process registration step
158
-     *
159
-     * @throws EE_Error
160
-     */
161
-    public static function update_reg_step()
162
-    {
163
-        EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
164
-    }
165
-
166
-
167
-    /**
168
-     *   update_checkout
169
-     *
170
-     * @access public
171
-     * @return void
172
-     * @throws EE_Error
173
-     */
174
-    public static function update_checkout()
175
-    {
176
-        EED_Single_Page_Checkout::process_ajax_request('update_checkout');
177
-    }
178
-
179
-
180
-    /**
181
-     *    load_request_handler
182
-     *
183
-     * @access    public
184
-     * @return    void
185
-     */
186
-    public static function load_request_handler()
187
-    {
188
-        // load core Request_Handler class
189
-        if (EE_Registry::instance()->REQ !== null) {
190
-            EE_Registry::instance()->load_core('Request_Handler');
191
-        }
192
-    }
193
-
194
-
195
-    /**
196
-     *    set_definitions
197
-     *
198
-     * @access    public
199
-     * @return    void
200
-     * @throws EE_Error
201
-     */
202
-    public static function set_definitions()
203
-    {
204
-        if (defined('SPCO_BASE_PATH')) {
205
-            return;
206
-        }
207
-        define(
208
-            'SPCO_BASE_PATH',
209
-            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
210
-        );
211
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
212
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
213
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
214
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
215
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
216
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
217
-        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
218
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
219
-        );
220
-    }
221
-
222
-
223
-    /**
224
-     * load_reg_steps
225
-     * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
226
-     *
227
-     * @access    private
228
-     * @throws EE_Error
229
-     */
230
-    public static function load_reg_steps()
231
-    {
232
-        static $reg_steps_loaded = false;
233
-        if ($reg_steps_loaded) {
234
-            return;
235
-        }
236
-        // filter list of reg_steps
237
-        $reg_steps_to_load = (array) apply_filters(
238
-            'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
239
-            EED_Single_Page_Checkout::get_reg_steps()
240
-        );
241
-        // sort by key (order)
242
-        ksort($reg_steps_to_load);
243
-        // loop through folders
244
-        foreach ($reg_steps_to_load as $order => $reg_step) {
245
-            // we need a
246
-            if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
247
-                // copy over to the reg_steps_array
248
-                EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step;
249
-                // register custom key route for each reg step
250
-                // ie: step=>"slug" - this is the entire reason we load the reg steps array now
251
-                EE_Config::register_route(
252
-                    $reg_step['slug'],
253
-                    'EED_Single_Page_Checkout',
254
-                    'run',
255
-                    'step'
256
-                );
257
-                // add AJAX or other hooks
258
-                if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
259
-                    // setup autoloaders if necessary
260
-                    if (! class_exists($reg_step['class_name'])) {
261
-                        EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
262
-                            $reg_step['file_path'],
263
-                            true
264
-                        );
265
-                    }
266
-                    if (is_callable($reg_step['class_name'], 'set_hooks')) {
267
-                        call_user_func(array($reg_step['class_name'], 'set_hooks'));
268
-                    }
269
-                }
270
-            }
271
-        }
272
-        $reg_steps_loaded = true;
273
-    }
274
-
275
-
276
-    /**
277
-     *    get_reg_steps
278
-     *
279
-     * @access    public
280
-     * @return    array
281
-     */
282
-    public static function get_reg_steps()
283
-    {
284
-        $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
285
-        if (empty($reg_steps)) {
286
-            $reg_steps = array(
287
-                10  => array(
288
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
289
-                    'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
290
-                    'slug'       => 'attendee_information',
291
-                    'has_hooks'  => false,
292
-                ),
293
-                30  => array(
294
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
295
-                    'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
296
-                    'slug'       => 'payment_options',
297
-                    'has_hooks'  => true,
298
-                ),
299
-                999 => array(
300
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
301
-                    'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
302
-                    'slug'       => 'finalize_registration',
303
-                    'has_hooks'  => false,
304
-                ),
305
-            );
306
-        }
307
-        return $reg_steps;
308
-    }
309
-
310
-
311
-    /**
312
-     *    registration_checkout_for_admin
313
-     *
314
-     * @access    public
315
-     * @return    string
316
-     * @throws EE_Error
317
-     */
318
-    public static function registration_checkout_for_admin()
319
-    {
320
-        EED_Single_Page_Checkout::load_request_handler();
321
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
322
-        EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
323
-        EE_Registry::instance()->REQ->set('process_form_submission', false);
324
-        EED_Single_Page_Checkout::instance()->_initialize();
325
-        EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
326
-        return EE_Registry::instance()->REQ->get_output();
327
-    }
328
-
329
-
330
-    /**
331
-     * process_registration_from_admin
332
-     *
333
-     * @access public
334
-     * @return \EE_Transaction
335
-     * @throws EE_Error
336
-     */
337
-    public static function process_registration_from_admin()
338
-    {
339
-        EED_Single_Page_Checkout::load_request_handler();
340
-        EE_Registry::instance()->REQ->set('step', 'attendee_information');
341
-        EE_Registry::instance()->REQ->set('action', 'process_reg_step');
342
-        EE_Registry::instance()->REQ->set('process_form_submission', true);
343
-        EED_Single_Page_Checkout::instance()->_initialize();
344
-        if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
345
-            $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
346
-            if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
347
-                EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
348
-                if ($final_reg_step->process_reg_step()) {
349
-                    $final_reg_step->set_completed();
350
-                    EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
351
-                    return EED_Single_Page_Checkout::instance()->checkout->transaction;
352
-                }
353
-            }
354
-        }
355
-        return null;
356
-    }
357
-
358
-
359
-    /**
360
-     *    run
361
-     *
362
-     * @access    public
363
-     * @param WP_Query $WP_Query
364
-     * @return    void
365
-     * @throws EE_Error
366
-     */
367
-    public function run($WP_Query)
368
-    {
369
-        if ($WP_Query instanceof WP_Query
370
-            && $WP_Query->is_main_query()
371
-            && apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
372
-            && $this->_is_reg_checkout()
373
-        ) {
374
-            $this->_initialize();
375
-        }
376
-    }
377
-
378
-
379
-    /**
380
-     * determines whether current url matches reg page url
381
-     *
382
-     * @return bool
383
-     */
384
-    protected function _is_reg_checkout()
385
-    {
386
-        // get current permalink for reg page without any extra query args
387
-        $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
388
-        // get request URI for current request, but without the scheme or host
389
-        $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
390
-        $current_request_uri = html_entity_decode($current_request_uri);
391
-        // get array of query args from the current request URI
392
-        $query_args = \EEH_URL::get_query_string($current_request_uri);
393
-        // grab page id if it is set
394
-        $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
395
-        // and remove the page id from the query args (we will re-add it later)
396
-        unset($query_args['page_id']);
397
-        // now strip all query args from current request URI
398
-        $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
399
-        // and re-add the page id if it was set
400
-        if ($page_id) {
401
-            $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
402
-        }
403
-        // remove slashes and ?
404
-        $current_request_uri = trim($current_request_uri, '?/');
405
-        // is current request URI part of the known full reg page URL ?
406
-        return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
407
-    }
408
-
409
-
410
-    /**
411
-     * @param WP_Query $wp_query
412
-     * @return    void
413
-     * @throws EE_Error
414
-     */
415
-    public static function init($wp_query)
416
-    {
417
-        EED_Single_Page_Checkout::instance()->run($wp_query);
418
-    }
419
-
420
-
421
-    /**
422
-     *    _initialize - initial module setup
423
-     *
424
-     * @access    private
425
-     * @throws EE_Error
426
-     * @return    void
427
-     */
428
-    private function _initialize()
429
-    {
430
-        // ensure SPCO doesn't run twice
431
-        if (EED_Single_Page_Checkout::$_initialized) {
432
-            return;
433
-        }
434
-        try {
435
-            EED_Single_Page_Checkout::load_reg_steps();
436
-            $this->_verify_session();
437
-            // setup the EE_Checkout object
438
-            $this->checkout = $this->_initialize_checkout();
439
-            // filter checkout
440
-            $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
441
-            // get the $_GET
442
-            $this->_get_request_vars();
443
-            if ($this->_block_bots()) {
444
-                return;
445
-            }
446
-            // filter continue_reg
447
-            $this->checkout->continue_reg = apply_filters(
448
-                'FHEE__EED_Single_Page_Checkout__init___continue_reg',
449
-                true,
450
-                $this->checkout
451
-            );
452
-            // load the reg steps array
453
-            if (! $this->_load_and_instantiate_reg_steps()) {
454
-                EED_Single_Page_Checkout::$_initialized = true;
455
-                return;
456
-            }
457
-            // set the current step
458
-            $this->checkout->set_current_step($this->checkout->step);
459
-            // and the next step
460
-            $this->checkout->set_next_step();
461
-            // verify that everything has been setup correctly
462
-            if (! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
463
-                EED_Single_Page_Checkout::$_initialized = true;
464
-                return;
465
-            }
466
-            // lock the transaction
467
-            $this->checkout->transaction->lock();
468
-            // make sure all of our cached objects are added to their respective model entity mappers
469
-            $this->checkout->refresh_all_entities();
470
-            // set amount owing
471
-            $this->checkout->amount_owing = $this->checkout->transaction->remaining();
472
-            // initialize each reg step, which gives them the chance to potentially alter the process
473
-            $this->_initialize_reg_steps();
474
-            // DEBUG LOG
475
-            // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
476
-            // get reg form
477
-            if (! $this->_check_form_submission()) {
478
-                EED_Single_Page_Checkout::$_initialized = true;
479
-                return;
480
-            }
481
-            // checkout the action!!!
482
-            $this->_process_form_action();
483
-            // add some style and make it dance
484
-            $this->add_styles_and_scripts();
485
-            // kk... SPCO has successfully run
486
-            EED_Single_Page_Checkout::$_initialized = true;
487
-            // set no cache headers and constants
488
-            EE_System::do_not_cache();
489
-            // add anchor
490
-            add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
491
-            // remove transaction lock
492
-            add_action('shutdown', array($this, 'unlock_transaction'), 1);
493
-        } catch (Exception $e) {
494
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
495
-        }
496
-    }
497
-
498
-
499
-    /**
500
-     *    _verify_session
501
-     * checks that the session is valid and not expired
502
-     *
503
-     * @access    private
504
-     * @throws EE_Error
505
-     */
506
-    private function _verify_session()
507
-    {
508
-        if (! EE_Registry::instance()->SSN instanceof EE_Session) {
509
-            throw new EE_Error(esc_html__('The EE_Session class could not be loaded.', 'event_espresso'));
510
-        }
511
-        $clear_session_requested = filter_var(
512
-            EE_Registry::instance()->REQ->get('clear_session', false),
513
-            FILTER_VALIDATE_BOOLEAN
514
-        );
515
-        // is session still valid ?
516
-        if ($clear_session_requested
517
-            || (EE_Registry::instance()->SSN->expired()
518
-                && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
519
-            )
520
-        ) {
521
-            $this->checkout = new EE_Checkout();
522
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
523
-            // EE_Registry::instance()->SSN->reset_cart();
524
-            // EE_Registry::instance()->SSN->reset_checkout();
525
-            // EE_Registry::instance()->SSN->reset_transaction();
526
-            if (! $clear_session_requested) {
527
-                EE_Error::add_attention(
528
-                    EE_Registry::$i18n_js_strings['registration_expiration_notice'],
529
-                    __FILE__,
530
-                    __FUNCTION__,
531
-                    __LINE__
532
-                );
533
-            }
534
-            // EE_Registry::instance()->SSN->reset_expired();
535
-        }
536
-    }
537
-
538
-
539
-    /**
540
-     *    _initialize_checkout
541
-     * loads and instantiates EE_Checkout
542
-     *
543
-     * @access    private
544
-     * @throws EE_Error
545
-     * @return EE_Checkout
546
-     */
547
-    private function _initialize_checkout()
548
-    {
549
-        // look in session for existing checkout
550
-        /** @type EE_Checkout $checkout */
551
-        $checkout = EE_Registry::instance()->SSN->checkout();
552
-        // verify
553
-        if (! $checkout instanceof EE_Checkout) {
554
-            // instantiate EE_Checkout object for handling the properties of the current checkout process
555
-            $checkout = EE_Registry::instance()->load_file(
556
-                SPCO_INC_PATH,
557
-                'EE_Checkout',
558
-                'class',
559
-                array(),
560
-                false
561
-            );
562
-        } else {
563
-            if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
564
-                $this->unlock_transaction();
565
-                wp_safe_redirect($checkout->redirect_url);
566
-                exit();
567
-            }
568
-        }
569
-        $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
570
-        // verify again
571
-        if (! $checkout instanceof EE_Checkout) {
572
-            throw new EE_Error(esc_html__('The EE_Checkout class could not be loaded.', 'event_espresso'));
573
-        }
574
-        // reset anything that needs a clean slate for each request
575
-        $checkout->reset_for_current_request();
576
-        return $checkout;
577
-    }
578
-
579
-
580
-    /**
581
-     *    _get_request_vars
582
-     *
583
-     * @access    private
584
-     * @return    void
585
-     * @throws EE_Error
586
-     */
587
-    private function _get_request_vars()
588
-    {
589
-        // load classes
590
-        EED_Single_Page_Checkout::load_request_handler();
591
-        // make sure this request is marked as belonging to EE
592
-        EE_Registry::instance()->REQ->set_espresso_page(true);
593
-        // which step is being requested ?
594
-        $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
595
-        // which step is being edited ?
596
-        $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
597
-        // and what we're doing on the current step
598
-        $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
599
-        // timestamp
600
-        $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
601
-        // returning to edit ?
602
-        $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
603
-        // add reg url link to registration query params
604
-        if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
605
-            $this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
606
-        }
607
-        // or some other kind of revisit ?
608
-        $this->checkout->revisit = filter_var(
609
-            EE_Registry::instance()->REQ->get('revisit', false),
610
-            FILTER_VALIDATE_BOOLEAN
611
-        );
612
-        // and whether or not to generate a reg form for this request
613
-        $this->checkout->generate_reg_form = filter_var(
614
-            EE_Registry::instance()->REQ->get('generate_reg_form', true),
615
-            FILTER_VALIDATE_BOOLEAN
616
-        );
617
-        // and whether or not to process a reg form submission for this request
618
-        $this->checkout->process_form_submission = filter_var(
619
-            EE_Registry::instance()->REQ->get(
620
-                'process_form_submission',
621
-                $this->checkout->action === 'process_reg_step'
622
-            ),
623
-            FILTER_VALIDATE_BOOLEAN
624
-        );
625
-        $this->checkout->process_form_submission = filter_var(
626
-            $this->checkout->action !== 'display_spco_reg_step'
627
-                ? $this->checkout->process_form_submission
628
-                : false,
629
-            FILTER_VALIDATE_BOOLEAN
630
-        );
631
-        // $this->_display_request_vars();
632
-    }
633
-
634
-
635
-    /**
636
-     *  _display_request_vars
637
-     *
638
-     * @access    protected
639
-     * @return    void
640
-     */
641
-    protected function _display_request_vars()
642
-    {
643
-        if (! WP_DEBUG) {
644
-            return;
645
-        }
646
-        EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
647
-        EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
648
-        EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
649
-        EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
650
-        EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
651
-        EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
652
-        EEH_Debug_Tools::printr(
653
-            $this->checkout->generate_reg_form,
654
-            '$this->checkout->generate_reg_form',
655
-            __FILE__,
656
-            __LINE__
657
-        );
658
-        EEH_Debug_Tools::printr(
659
-            $this->checkout->process_form_submission,
660
-            '$this->checkout->process_form_submission',
661
-            __FILE__,
662
-            __LINE__
663
-        );
664
-    }
665
-
666
-
667
-    /**
668
-     * _block_bots
669
-     * checks that the incoming request has either of the following set:
670
-     *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
671
-     *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
672
-     * so if you're not coming from the Ticket Selector nor returning for a valid IP...
673
-     * then where you coming from man?
674
-     *
675
-     * @return boolean
676
-     */
677
-    private function _block_bots()
678
-    {
679
-        $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
680
-        if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
681
-            return true;
682
-        }
683
-        return false;
684
-    }
685
-
686
-
687
-    /**
688
-     *    _get_first_step
689
-     *  gets slug for first step in $_reg_steps_array
690
-     *
691
-     * @access    private
692
-     * @throws EE_Error
693
-     * @return    string
694
-     */
695
-    private function _get_first_step()
696
-    {
697
-        $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
698
-        return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
699
-    }
700
-
701
-
702
-    /**
703
-     * instantiates each reg step based on the loaded reg_steps array
704
-     *
705
-     * @return    bool
706
-     * @throws EE_Error
707
-     * @throws InvalidArgumentException
708
-     * @throws InvalidDataTypeException
709
-     * @throws InvalidInterfaceException
710
-     */
711
-    private function _load_and_instantiate_reg_steps()
712
-    {
713
-        do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
714
-        // have reg_steps already been instantiated ?
715
-        if (empty($this->checkout->reg_steps)
716
-            || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
717
-        ) {
718
-            // if not, then loop through raw reg steps array
719
-            foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
720
-                if (! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
721
-                    return false;
722
-                }
723
-            }
724
-            if (isset($this->checkout->reg_steps['registration_confirmation'])) {
725
-                // skip the registration_confirmation page ?
726
-                if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
727
-                    // just remove it from the reg steps array
728
-                    $this->checkout->remove_reg_step('registration_confirmation', false);
729
-                } elseif (EE_Registry::instance()->CFG->registration->reg_confirmation_last
730
-                ) {
731
-                    // set the order to something big like 100
732
-                    $this->checkout->set_reg_step_order('registration_confirmation', 100);
733
-                }
734
-            }
735
-            // filter the array for good luck
736
-            $this->checkout->reg_steps = apply_filters(
737
-                'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
738
-                $this->checkout->reg_steps
739
-            );
740
-            // finally re-sort based on the reg step class order properties
741
-            $this->checkout->sort_reg_steps();
742
-        } else {
743
-            foreach ($this->checkout->reg_steps as $reg_step) {
744
-                // set all current step stati to FALSE
745
-                $reg_step->set_is_current_step(false);
746
-            }
747
-        }
748
-        if (empty($this->checkout->reg_steps)) {
749
-            EE_Error::add_error(
750
-                esc_html__('No Reg Steps were loaded..', 'event_espresso'),
751
-                __FILE__,
752
-                __FUNCTION__,
753
-                __LINE__
754
-            );
755
-            return false;
756
-        }
757
-        // make reg step details available to JS
758
-        $this->checkout->set_reg_step_JSON_info();
759
-        return true;
760
-    }
761
-
762
-
763
-    /**
764
-     *     _load_and_instantiate_reg_step
765
-     *
766
-     * @access    private
767
-     * @param array $reg_step
768
-     * @param int   $order
769
-     * @return bool
770
-     */
771
-    private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
772
-    {
773
-        // we need a file_path, class_name, and slug to add a reg step
774
-        if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
775
-            // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
776
-            if ($this->checkout->reg_url_link
777
-                && $this->checkout->step !== $reg_step['slug']
778
-                && $reg_step['slug'] !== 'finalize_registration'
779
-                // normally at this point we would NOT load the reg step, but this filter can change that
780
-                && apply_filters(
781
-                    'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
782
-                    true,
783
-                    $reg_step,
784
-                    $this->checkout
785
-                )
786
-            ) {
787
-                return true;
788
-            }
789
-            // instantiate step class using file path and class name
790
-            $reg_step_obj = EE_Registry::instance()->load_file(
791
-                $reg_step['file_path'],
792
-                $reg_step['class_name'],
793
-                'class',
794
-                $this->checkout,
795
-                false
796
-            );
797
-            // did we gets the goods ?
798
-            if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
799
-                // set reg step order based on config
800
-                $reg_step_obj->set_order($order);
801
-                // add instantiated reg step object to the master reg steps array
802
-                $this->checkout->add_reg_step($reg_step_obj);
803
-            } else {
804
-                EE_Error::add_error(
805
-                    esc_html__('The current step could not be set.', 'event_espresso'),
806
-                    __FILE__,
807
-                    __FUNCTION__,
808
-                    __LINE__
809
-                );
810
-                return false;
811
-            }
812
-        } else {
813
-            if (WP_DEBUG) {
814
-                EE_Error::add_error(
815
-                    sprintf(
816
-                        esc_html__(
817
-                            'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s',
818
-                            'event_espresso'
819
-                        ),
820
-                        isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
821
-                        isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
822
-                        isset($reg_step['slug']) ? $reg_step['slug'] : '',
823
-                        '<ul>',
824
-                        '<li>',
825
-                        '</li>',
826
-                        '</ul>'
827
-                    ),
828
-                    __FILE__,
829
-                    __FUNCTION__,
830
-                    __LINE__
831
-                );
832
-            }
833
-            return false;
834
-        }
835
-        return true;
836
-    }
837
-
838
-
839
-    /**
840
-     * _verify_transaction_and_get_registrations
841
-     *
842
-     * @access private
843
-     * @return bool
844
-     * @throws InvalidDataTypeException
845
-     * @throws InvalidEntityException
846
-     * @throws EE_Error
847
-     */
848
-    private function _verify_transaction_and_get_registrations()
849
-    {
850
-        // was there already a valid transaction in the checkout from the session ?
851
-        if (! $this->checkout->transaction instanceof EE_Transaction) {
852
-            // get transaction from db or session
853
-            $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
854
-                ? $this->_get_transaction_and_cart_for_previous_visit()
855
-                : $this->_get_cart_for_current_session_and_setup_new_transaction();
856
-            if (! $this->checkout->transaction instanceof EE_Transaction) {
857
-                EE_Error::add_error(
858
-                    esc_html__(
859
-                        'Your Registration and Transaction information could not be retrieved from the db.',
860
-                        'event_espresso'
861
-                    ),
862
-                    __FILE__,
863
-                    __FUNCTION__,
864
-                    __LINE__
865
-                );
866
-                $this->checkout->transaction = EE_Transaction::new_instance();
867
-                // add some style and make it dance
868
-                $this->add_styles_and_scripts();
869
-                EED_Single_Page_Checkout::$_initialized = true;
870
-                return false;
871
-            }
872
-            // and the registrations for the transaction
873
-            $this->_get_registrations($this->checkout->transaction);
874
-        }
875
-        return true;
876
-    }
877
-
878
-
879
-    /**
880
-     * _get_transaction_and_cart_for_previous_visit
881
-     *
882
-     * @access private
883
-     * @return mixed EE_Transaction|NULL
884
-     */
885
-    private function _get_transaction_and_cart_for_previous_visit()
886
-    {
887
-        /** @var $TXN_model EEM_Transaction */
888
-        $TXN_model = EE_Registry::instance()->load_model('Transaction');
889
-        // because the reg_url_link is present in the request,
890
-        // this is a return visit to SPCO, so we'll get the transaction data from the db
891
-        $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
892
-        // verify transaction
893
-        if ($transaction instanceof EE_Transaction) {
894
-            // and get the cart that was used for that transaction
895
-            $this->checkout->cart = $this->_get_cart_for_transaction($transaction);
896
-            return $transaction;
897
-        }
898
-        EE_Error::add_error(
899
-            esc_html__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
900
-            __FILE__,
901
-            __FUNCTION__,
902
-            __LINE__
903
-        );
904
-        return null;
905
-    }
906
-
907
-
908
-    /**
909
-     * _get_cart_for_transaction
910
-     *
911
-     * @access private
912
-     * @param EE_Transaction $transaction
913
-     * @return EE_Cart
914
-     */
915
-    private function _get_cart_for_transaction($transaction)
916
-    {
917
-        return $this->checkout->get_cart_for_transaction($transaction);
918
-    }
919
-
920
-
921
-    /**
922
-     * get_cart_for_transaction
923
-     *
924
-     * @access public
925
-     * @param EE_Transaction $transaction
926
-     * @return EE_Cart
927
-     */
928
-    public function get_cart_for_transaction(EE_Transaction $transaction)
929
-    {
930
-        return $this->checkout->get_cart_for_transaction($transaction);
931
-    }
932
-
933
-
934
-    /**
935
-     * _get_transaction_and_cart_for_current_session
936
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
937
-     *
938
-     * @access private
939
-     * @return EE_Transaction
940
-     * @throws EE_Error
941
-     */
942
-    private function _get_cart_for_current_session_and_setup_new_transaction()
943
-    {
944
-        //  if there's no transaction, then this is the FIRST visit to SPCO
945
-        // so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
946
-        $this->checkout->cart = $this->_get_cart_for_transaction(null);
947
-        // and then create a new transaction
948
-        $transaction = $this->_initialize_transaction();
949
-        // verify transaction
950
-        if ($transaction instanceof EE_Transaction) {
951
-            // save it so that we have an ID for other objects to use
952
-            $transaction->save();
953
-            // and save TXN data to the cart
954
-            $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
955
-        } else {
956
-            EE_Error::add_error(
957
-                esc_html__('A Valid Transaction could not be initialized.', 'event_espresso'),
958
-                __FILE__,
959
-                __FUNCTION__,
960
-                __LINE__
961
-            );
962
-        }
963
-        return $transaction;
964
-    }
965
-
966
-
967
-    /**
968
-     *    generates a new EE_Transaction object and adds it to the $_transaction property.
969
-     *
970
-     * @access private
971
-     * @return mixed EE_Transaction|NULL
972
-     */
973
-    private function _initialize_transaction()
974
-    {
975
-        try {
976
-            // ensure cart totals have been calculated
977
-            $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
978
-            // grab the cart grand total
979
-            $cart_total = $this->checkout->cart->get_cart_grand_total();
980
-            // create new TXN
981
-            $transaction = EE_Transaction::new_instance(
982
-                array(
983
-                    'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
984
-                    'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
985
-                    'TXN_paid'      => 0,
986
-                    'STS_ID'        => EEM_Transaction::failed_status_code,
987
-                )
988
-            );
989
-            // save it so that we have an ID for other objects to use
990
-            $transaction->save();
991
-            // set cron job for following up on TXNs after their session has expired
992
-            EE_Cron_Tasks::schedule_expired_transaction_check(
993
-                EE_Registry::instance()->SSN->expiration() + 1,
994
-                $transaction->ID()
995
-            );
996
-            return $transaction;
997
-        } catch (Exception $e) {
998
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
999
-        }
1000
-        return null;
1001
-    }
1002
-
1003
-
1004
-    /**
1005
-     * _get_registrations
1006
-     *
1007
-     * @access private
1008
-     * @param EE_Transaction $transaction
1009
-     * @return void
1010
-     * @throws InvalidDataTypeException
1011
-     * @throws InvalidEntityException
1012
-     * @throws EE_Error
1013
-     */
1014
-    private function _get_registrations(EE_Transaction $transaction)
1015
-    {
1016
-        // first step: grab the registrants  { : o
1017
-        $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1018
-        $this->checkout->total_ticket_count = count($registrations);
1019
-        // verify registrations have been set
1020
-        if (empty($registrations)) {
1021
-            // if no cached registrations, then check the db
1022
-            $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1023
-            // still nothing ? well as long as this isn't a revisit
1024
-            if (empty($registrations) && ! $this->checkout->revisit) {
1025
-                // generate new registrations from scratch
1026
-                $registrations = $this->_initialize_registrations($transaction);
1027
-            }
1028
-        }
1029
-        // sort by their original registration order
1030
-        usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1031
-        // then loop thru the array
1032
-        foreach ($registrations as $registration) {
1033
-            // verify each registration
1034
-            if ($registration instanceof EE_Registration) {
1035
-                // we display all attendee info for the primary registrant
1036
-                if ($this->checkout->reg_url_link === $registration->reg_url_link()
1037
-                    && $registration->is_primary_registrant()
1038
-                ) {
1039
-                    $this->checkout->primary_revisit = true;
1040
-                    break;
1041
-                }
1042
-                if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1043
-                    // but hide info if it doesn't belong to you
1044
-                    $transaction->clear_cache('Registration', $registration->ID());
1045
-                    $this->checkout->total_ticket_count--;
1046
-                }
1047
-                $this->checkout->set_reg_status_updated($registration->ID(), false);
1048
-            }
1049
-        }
1050
-    }
1051
-
1052
-
1053
-    /**
1054
-     *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1055
-     *
1056
-     * @access private
1057
-     * @param EE_Transaction $transaction
1058
-     * @return    array
1059
-     * @throws InvalidDataTypeException
1060
-     * @throws InvalidEntityException
1061
-     * @throws EE_Error
1062
-     */
1063
-    private function _initialize_registrations(EE_Transaction $transaction)
1064
-    {
1065
-        $att_nmbr = 0;
1066
-        $registrations = array();
1067
-        if ($transaction instanceof EE_Transaction) {
1068
-            /** @type EE_Registration_Processor $registration_processor */
1069
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1070
-            $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1071
-            // now let's add the cart items to the $transaction
1072
-            foreach ($this->checkout->cart->get_tickets() as $line_item) {
1073
-                // do the following for each ticket of this type they selected
1074
-                for ($x = 1; $x <= $line_item->quantity(); $x++) {
1075
-                    $att_nmbr++;
1076
-                    /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1077
-                    $CreateRegistrationCommand = EE_Registry::instance()->create(
1078
-                        'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1079
-                        array(
1080
-                            $transaction,
1081
-                            $line_item,
1082
-                            $att_nmbr,
1083
-                            $this->checkout->total_ticket_count,
1084
-                        )
1085
-                    );
1086
-                    // override capabilities for frontend registrations
1087
-                    if (! is_admin()) {
1088
-                        $CreateRegistrationCommand->setCapCheck(
1089
-                            new PublicCapabilities('', 'create_new_registration')
1090
-                        );
1091
-                    }
1092
-                    $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1093
-                    if (! $registration instanceof EE_Registration) {
1094
-                        throw new InvalidEntityException($registration, 'EE_Registration');
1095
-                    }
1096
-                    $registrations[ $registration->ID() ] = $registration;
1097
-                }
1098
-            }
1099
-            $registration_processor->fix_reg_final_price_rounding_issue($transaction);
1100
-        }
1101
-        return $registrations;
1102
-    }
1103
-
1104
-
1105
-    /**
1106
-     * sorts registrations by REG_count
1107
-     *
1108
-     * @access public
1109
-     * @param EE_Registration $reg_A
1110
-     * @param EE_Registration $reg_B
1111
-     * @return int
1112
-     */
1113
-    public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1114
-    {
1115
-        // this shouldn't ever happen within the same TXN, but oh well
1116
-        if ($reg_A->count() === $reg_B->count()) {
1117
-            return 0;
1118
-        }
1119
-        return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1120
-    }
1121
-
1122
-
1123
-    /**
1124
-     *    _final_verifications
1125
-     * just makes sure that everything is set up correctly before proceeding
1126
-     *
1127
-     * @access    private
1128
-     * @return    bool
1129
-     * @throws EE_Error
1130
-     */
1131
-    private function _final_verifications()
1132
-    {
1133
-        // filter checkout
1134
-        $this->checkout = apply_filters(
1135
-            'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1136
-            $this->checkout
1137
-        );
1138
-        // verify that current step is still set correctly
1139
-        if (! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1140
-            EE_Error::add_error(
1141
-                esc_html__(
1142
-                    'We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.',
1143
-                    'event_espresso'
1144
-                ),
1145
-                __FILE__,
1146
-                __FUNCTION__,
1147
-                __LINE__
1148
-            );
1149
-            return false;
1150
-        }
1151
-        // if returning to SPCO, then verify that primary registrant is set
1152
-        if (! empty($this->checkout->reg_url_link)) {
1153
-            $valid_registrant = $this->checkout->transaction->primary_registration();
1154
-            if (! $valid_registrant instanceof EE_Registration) {
1155
-                EE_Error::add_error(
1156
-                    esc_html__(
1157
-                        'We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.',
1158
-                        'event_espresso'
1159
-                    ),
1160
-                    __FILE__,
1161
-                    __FUNCTION__,
1162
-                    __LINE__
1163
-                );
1164
-                return false;
1165
-            }
1166
-            $valid_registrant = null;
1167
-            foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) {
1168
-                if ($registration instanceof EE_Registration
1169
-                    && $registration->reg_url_link() === $this->checkout->reg_url_link
1170
-                ) {
1171
-                    $valid_registrant = $registration;
1172
-                }
1173
-            }
1174
-            if (! $valid_registrant instanceof EE_Registration) {
1175
-                // hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1176
-                if (EED_Single_Page_Checkout::$_checkout_verified) {
1177
-                    // clear the session, mark the checkout as unverified, and try again
1178
-                    EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1179
-                    EED_Single_Page_Checkout::$_initialized = false;
1180
-                    EED_Single_Page_Checkout::$_checkout_verified = false;
1181
-                    $this->_initialize();
1182
-                    EE_Error::reset_notices();
1183
-                    return false;
1184
-                }
1185
-                EE_Error::add_error(
1186
-                    esc_html__(
1187
-                        'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.',
1188
-                        'event_espresso'
1189
-                    ),
1190
-                    __FILE__,
1191
-                    __FUNCTION__,
1192
-                    __LINE__
1193
-                );
1194
-                return false;
1195
-            }
1196
-        }
1197
-        // now that things have been kinda sufficiently verified,
1198
-        // let's add the checkout to the session so that it's available to other systems
1199
-        EE_Registry::instance()->SSN->set_checkout($this->checkout);
1200
-        return true;
1201
-    }
1202
-
1203
-
1204
-    /**
1205
-     *    _initialize_reg_steps
1206
-     * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1207
-     * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1208
-     *
1209
-     * @access    private
1210
-     * @param bool $reinitializing
1211
-     * @throws EE_Error
1212
-     */
1213
-    private function _initialize_reg_steps($reinitializing = false)
1214
-    {
1215
-        $this->checkout->set_reg_step_initiated($this->checkout->current_step);
1216
-        // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1217
-        foreach ($this->checkout->reg_steps as $reg_step) {
1218
-            if (! $reg_step->initialize_reg_step()) {
1219
-                // if not initialized then maybe this step is being removed...
1220
-                if (! $reinitializing && $reg_step->is_current_step()) {
1221
-                    // if it was the current step, then we need to start over here
1222
-                    $this->_initialize_reg_steps(true);
1223
-                    return;
1224
-                }
1225
-                continue;
1226
-            }
1227
-            // add css and JS for current step
1228
-            $reg_step->enqueue_styles_and_scripts();
1229
-            // i18n
1230
-            $reg_step->translate_js_strings();
1231
-            if ($reg_step->is_current_step()) {
1232
-                // the text that appears on the reg step form submit button
1233
-                $reg_step->set_submit_button_text();
1234
-            }
1235
-        }
1236
-        // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1237
-        do_action(
1238
-            "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1239
-            $this->checkout->current_step
1240
-        );
1241
-    }
1242
-
1243
-
1244
-    /**
1245
-     * _check_form_submission
1246
-     *
1247
-     * @access private
1248
-     * @return boolean
1249
-     */
1250
-    private function _check_form_submission()
1251
-    {
1252
-        // does this request require the reg form to be generated ?
1253
-        if ($this->checkout->generate_reg_form) {
1254
-            // ever heard that song by Blue Rodeo ?
1255
-            try {
1256
-                $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1257
-                // if not displaying a form, then check for form submission
1258
-                if ($this->checkout->process_form_submission
1259
-                    && $this->checkout->current_step->reg_form->was_submitted()
1260
-                ) {
1261
-                    // clear out any old data in case this step is being run again
1262
-                    $this->checkout->current_step->set_valid_data(array());
1263
-                    // capture submitted form data
1264
-                    $this->checkout->current_step->reg_form->receive_form_submission(
1265
-                        apply_filters(
1266
-                            'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1267
-                            EE_Registry::instance()->REQ->params(),
1268
-                            $this->checkout
1269
-                        )
1270
-                    );
1271
-                    // validate submitted form data
1272
-                    if (! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1273
-                        // thou shall not pass !!!
1274
-                        $this->checkout->continue_reg = false;
1275
-                        // any form validation errors?
1276
-                        if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1277
-                            EE_Error::add_error(
1278
-                                $this->checkout->current_step->reg_form->submission_error_message(),
1279
-                                __FILE__,
1280
-                                __FUNCTION__,
1281
-                                __LINE__
1282
-                            );
1283
-                        }
1284
-                        // well not really... what will happen is
1285
-                        // we'll just get redirected back to redo the current step
1286
-                        $this->go_to_next_step();
1287
-                        return false;
1288
-                    }
1289
-                }
1290
-            } catch (EE_Error $e) {
1291
-                $e->get_error();
1292
-            }
1293
-        }
1294
-        return true;
1295
-    }
1296
-
1297
-
1298
-    /**
1299
-     * _process_action
1300
-     *
1301
-     * @access private
1302
-     * @return void
1303
-     * @throws EE_Error
1304
-     */
1305
-    private function _process_form_action()
1306
-    {
1307
-        // what cha wanna do?
1308
-        switch ($this->checkout->action) {
1309
-            // AJAX next step reg form
1310
-            case 'display_spco_reg_step':
1311
-                $this->checkout->redirect = false;
1312
-                if (EE_Registry::instance()->REQ->ajax) {
1313
-                    $this->checkout->json_response->set_reg_step_html(
1314
-                        $this->checkout->current_step->display_reg_form()
1315
-                    );
1316
-                }
1317
-                break;
1318
-            default:
1319
-                // meh... do one of those other steps first
1320
-                if (! empty($this->checkout->action)
1321
-                    && is_callable(array($this->checkout->current_step, $this->checkout->action))
1322
-                ) {
1323
-                    // dynamically creates hook point like:
1324
-                    //   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1325
-                    do_action(
1326
-                        "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1327
-                        $this->checkout->current_step
1328
-                    );
1329
-                    // call action on current step
1330
-                    if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1331
-                        // good registrant, you get to proceed
1332
-                        if ($this->checkout->current_step->success_message() !== ''
1333
-                            && apply_filters(
1334
-                                'FHEE__Single_Page_Checkout___process_form_action__display_success',
1335
-                                false
1336
-                            )
1337
-                        ) {
1338
-                            EE_Error::add_success(
1339
-                                $this->checkout->current_step->success_message()
1340
-                                . '<br />' . $this->checkout->next_step->_instructions()
1341
-                            );
1342
-                        }
1343
-                        // pack it up, pack it in...
1344
-                        $this->_setup_redirect();
1345
-                    }
1346
-                    // dynamically creates hook point like:
1347
-                    //  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1348
-                    do_action(
1349
-                        "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1350
-                        $this->checkout->current_step
1351
-                    );
1352
-                } else {
1353
-                    EE_Error::add_error(
1354
-                        sprintf(
1355
-                            esc_html__(
1356
-                                'The requested form action "%s" does not exist for the current "%s" registration step.',
1357
-                                'event_espresso'
1358
-                            ),
1359
-                            $this->checkout->action,
1360
-                            $this->checkout->current_step->name()
1361
-                        ),
1362
-                        __FILE__,
1363
-                        __FUNCTION__,
1364
-                        __LINE__
1365
-                    );
1366
-                }
1367
-            // end default
1368
-        }
1369
-        // store our progress so far
1370
-        $this->checkout->stash_transaction_and_checkout();
1371
-        // advance to the next step! If you pass GO, collect $200
1372
-        $this->go_to_next_step();
1373
-    }
1374
-
1375
-
1376
-    /**
1377
-     *        add_styles_and_scripts
1378
-     *
1379
-     * @access        public
1380
-     * @return        void
1381
-     */
1382
-    public function add_styles_and_scripts()
1383
-    {
1384
-        // i18n
1385
-        $this->translate_js_strings();
1386
-        if ($this->checkout->admin_request) {
1387
-            add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1388
-        } else {
1389
-            add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1390
-        }
1391
-    }
1392
-
1393
-
1394
-    /**
1395
-     *        translate_js_strings
1396
-     *
1397
-     * @access        public
1398
-     * @return        void
1399
-     */
1400
-    public function translate_js_strings()
1401
-    {
1402
-        EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1403
-        EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1404
-        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
1405
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1406
-            'event_espresso'
1407
-        );
1408
-        EE_Registry::$i18n_js_strings['invalid_json_response'] = esc_html__(
1409
-            'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1410
-            'event_espresso'
1411
-        );
1412
-        EE_Registry::$i18n_js_strings['validation_error'] = esc_html__(
1413
-            'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1414
-            'event_espresso'
1415
-        );
1416
-        EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__(
1417
-            'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1418
-            'event_espresso'
1419
-        );
1420
-        EE_Registry::$i18n_js_strings['reg_step_error'] = esc_html__(
1421
-            'This registration step could not be completed. Please refresh the page and try again.',
1422
-            'event_espresso'
1423
-        );
1424
-        EE_Registry::$i18n_js_strings['invalid_coupon'] = esc_html__(
1425
-            'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1426
-            'event_espresso'
1427
-        );
1428
-        EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1429
-            esc_html__(
1430
-                'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1431
-                'event_espresso'
1432
-            ),
1433
-            '<br/>',
1434
-            '<br/>'
1435
-        );
1436
-        EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1437
-        EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1438
-        EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1439
-        EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1440
-        EE_Registry::$i18n_js_strings['timer_years'] = esc_html__('years', 'event_espresso');
1441
-        EE_Registry::$i18n_js_strings['timer_months'] = esc_html__('months', 'event_espresso');
1442
-        EE_Registry::$i18n_js_strings['timer_weeks'] = esc_html__('weeks', 'event_espresso');
1443
-        EE_Registry::$i18n_js_strings['timer_days'] = esc_html__('days', 'event_espresso');
1444
-        EE_Registry::$i18n_js_strings['timer_hours'] = esc_html__('hours', 'event_espresso');
1445
-        EE_Registry::$i18n_js_strings['timer_minutes'] = esc_html__('minutes', 'event_espresso');
1446
-        EE_Registry::$i18n_js_strings['timer_seconds'] = esc_html__('seconds', 'event_espresso');
1447
-        EE_Registry::$i18n_js_strings['timer_year'] = esc_html__('year', 'event_espresso');
1448
-        EE_Registry::$i18n_js_strings['timer_month'] = esc_html__('month', 'event_espresso');
1449
-        EE_Registry::$i18n_js_strings['timer_week'] = esc_html__('week', 'event_espresso');
1450
-        EE_Registry::$i18n_js_strings['timer_day'] = esc_html__('day', 'event_espresso');
1451
-        EE_Registry::$i18n_js_strings['timer_hour'] = esc_html__('hour', 'event_espresso');
1452
-        EE_Registry::$i18n_js_strings['timer_minute'] = esc_html__('minute', 'event_espresso');
1453
-        EE_Registry::$i18n_js_strings['timer_second'] = esc_html__('second', 'event_espresso');
1454
-        EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
1455
-        );
1456
-        EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1457
-            'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1458
-            true
1459
-        );
1460
-        EE_Registry::$i18n_js_strings['session_extension'] = absint(
1461
-            apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1462
-        );
1463
-        EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1464
-            'M d, Y H:i:s',
1465
-            EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1466
-        );
1467
-    }
1468
-
1469
-
1470
-    /**
1471
-     *    enqueue_styles_and_scripts
1472
-     *
1473
-     * @access        public
1474
-     * @return        void
1475
-     * @throws EE_Error
1476
-     */
1477
-    public function enqueue_styles_and_scripts()
1478
-    {
1479
-        // load css
1480
-        wp_register_style(
1481
-            'single_page_checkout',
1482
-            SPCO_CSS_URL . 'single_page_checkout.css',
1483
-            array('espresso_default'),
1484
-            EVENT_ESPRESSO_VERSION
1485
-        );
1486
-        wp_enqueue_style('single_page_checkout');
1487
-        // load JS
1488
-        wp_register_script(
1489
-            'jquery_plugin',
1490
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1491
-            array('jquery'),
1492
-            '1.0.1',
1493
-            true
1494
-        );
1495
-        wp_register_script(
1496
-            'jquery_countdown',
1497
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1498
-            array('jquery_plugin'),
1499
-            '2.1.0',
1500
-            true
1501
-        );
1502
-        wp_register_script(
1503
-            'single_page_checkout',
1504
-            SPCO_JS_URL . 'single_page_checkout.js',
1505
-            array('espresso_core', 'underscore', 'ee_form_section_validation'),
1506
-            EVENT_ESPRESSO_VERSION,
1507
-            true
1508
-        );
1509
-        if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1510
-            $this->checkout->registration_form->enqueue_js();
1511
-        }
1512
-        if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1513
-            $this->checkout->current_step->reg_form->enqueue_js();
1514
-        }
1515
-        wp_enqueue_script('single_page_checkout');
1516
-        if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) {
1517
-            wp_enqueue_script('jquery_countdown');
1518
-        }
1519
-        /**
1520
-         * global action hook for enqueueing styles and scripts with
1521
-         * spco calls.
1522
-         */
1523
-        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1524
-        /**
1525
-         * dynamic action hook for enqueueing styles and scripts with spco calls.
1526
-         * The hook will end up being something like:
1527
-         *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1528
-         */
1529
-        do_action(
1530
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1531
-            $this
1532
-        );
1533
-    }
1534
-
1535
-
1536
-    /**
1537
-     *    display the Registration Single Page Checkout Form
1538
-     *
1539
-     * @access    private
1540
-     * @return    void
1541
-     * @throws EE_Error
1542
-     */
1543
-    private function _display_spco_reg_form()
1544
-    {
1545
-        // if registering via the admin, just display the reg form for the current step
1546
-        if ($this->checkout->admin_request) {
1547
-            EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1548
-        } else {
1549
-            // add powered by EE msg
1550
-            add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1551
-            $empty_cart = count($this->checkout->transaction
1552
-                                    ->registrations($this->checkout->reg_cache_where_params)) < 1;
1553
-            EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1554
-            $cookies_not_set_msg = '';
1555
-            if ($empty_cart) {
1556
-                $cookies_not_set_msg = apply_filters(
1557
-                    'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1558
-                    sprintf(
1559
-                        esc_html__(
1560
-                            '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1561
-                            'event_espresso'
1562
-                        ),
1563
-                        '<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1564
-                        '</div>',
1565
-                        '<h6 class="important-notice">',
1566
-                        '</h6>',
1567
-                        '<p>',
1568
-                        '</p>',
1569
-                        '<br />',
1570
-                        '<a href="http://www.whatarecookies.com/enable.asp" target="_blank" rel="noopener noreferrer">',
1571
-                        '</a>'
1572
-                    )
1573
-                );
1574
-            }
1575
-            $this->checkout->registration_form = new EE_Form_Section_Proper(
1576
-                array(
1577
-                    'name'            => 'single-page-checkout',
1578
-                    'html_id'         => 'ee-single-page-checkout-dv',
1579
-                    'layout_strategy' =>
1580
-                        new EE_Template_Layout(
1581
-                            array(
1582
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1583
-                                'template_args'        => array(
1584
-                                    'empty_cart'              => $empty_cart,
1585
-                                    'revisit'                 => $this->checkout->revisit,
1586
-                                    'reg_steps'               => $this->checkout->reg_steps,
1587
-                                    'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1588
-                                        ? $this->checkout->next_step->slug()
1589
-                                        : '',
1590
-                                    'empty_msg'               => apply_filters(
1591
-                                        'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1592
-                                        sprintf(
1593
-                                            esc_html__(
1594
-                                                'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1595
-                                                'event_espresso'
1596
-                                            ),
1597
-                                            '<a href="'
1598
-                                            . get_post_type_archive_link('espresso_events')
1599
-                                            . '" title="',
1600
-                                            '">',
1601
-                                            '</a>'
1602
-                                        )
1603
-                                    ),
1604
-                                    'cookies_not_set_msg'     => $cookies_not_set_msg,
1605
-                                    'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1606
-                                    'session_expiration'      => gmdate(
1607
-                                        'M d, Y H:i:s',
1608
-                                        EE_Registry::instance()->SSN->expiration()
1609
-                                        + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1610
-                                    ),
1611
-                                ),
1612
-                            )
1613
-                        ),
1614
-                )
1615
-            );
1616
-            // load template and add to output sent that gets filtered into the_content()
1617
-            EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1618
-        }
1619
-    }
1620
-
1621
-
1622
-    /**
1623
-     *    add_extra_finalize_registration_inputs
1624
-     *
1625
-     * @access    public
1626
-     * @param $next_step
1627
-     * @internal  param string $label
1628
-     * @return void
1629
-     */
1630
-    public function add_extra_finalize_registration_inputs($next_step)
1631
-    {
1632
-        if ($next_step === 'finalize_registration') {
1633
-            echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1634
-        }
1635
-    }
1636
-
1637
-
1638
-    /**
1639
-     *    display_registration_footer
1640
-     *
1641
-     * @access    public
1642
-     * @return    string
1643
-     */
1644
-    public static function display_registration_footer()
1645
-    {
1646
-        if (apply_filters(
1647
-            'FHEE__EE_Front__Controller__show_reg_footer',
1648
-            EE_Registry::instance()->CFG->admin->show_reg_footer
1649
-        )) {
1650
-            add_filter(
1651
-                'FHEE__EEH_Template__powered_by_event_espresso__url',
1652
-                function ($url) {
1653
-                    return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1654
-                }
1655
-            );
1656
-            echo apply_filters(
1657
-                'FHEE__EE_Front_Controller__display_registration_footer',
1658
-                \EEH_Template::powered_by_event_espresso(
1659
-                    '',
1660
-                    'espresso-registration-footer-dv',
1661
-                    array('utm_content' => 'registration_checkout')
1662
-                )
1663
-            );
1664
-        }
1665
-        return '';
1666
-    }
1667
-
1668
-
1669
-    /**
1670
-     *    unlock_transaction
1671
-     *
1672
-     * @access    public
1673
-     * @return    void
1674
-     * @throws EE_Error
1675
-     */
1676
-    public function unlock_transaction()
1677
-    {
1678
-        if ($this->checkout->transaction instanceof EE_Transaction) {
1679
-            $this->checkout->transaction->unlock();
1680
-        }
1681
-    }
1682
-
1683
-
1684
-    /**
1685
-     *        _setup_redirect
1686
-     *
1687
-     * @access    private
1688
-     * @return void
1689
-     */
1690
-    private function _setup_redirect()
1691
-    {
1692
-        if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1693
-            $this->checkout->redirect = true;
1694
-            if (empty($this->checkout->redirect_url)) {
1695
-                $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1696
-            }
1697
-            $this->checkout->redirect_url = apply_filters(
1698
-                'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1699
-                $this->checkout->redirect_url,
1700
-                $this->checkout
1701
-            );
1702
-        }
1703
-    }
1704
-
1705
-
1706
-    /**
1707
-     *   handle ajax message responses and redirects
1708
-     *
1709
-     * @access public
1710
-     * @return void
1711
-     * @throws EE_Error
1712
-     */
1713
-    public function go_to_next_step()
1714
-    {
1715
-        if (EE_Registry::instance()->REQ->ajax) {
1716
-            // capture contents of output buffer we started earlier in the request, and insert into JSON response
1717
-            $this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1718
-        }
1719
-        $this->unlock_transaction();
1720
-        // just return for these conditions
1721
-        if ($this->checkout->admin_request
1722
-            || $this->checkout->action === 'redirect_form'
1723
-            || $this->checkout->action === 'update_checkout'
1724
-        ) {
1725
-            return;
1726
-        }
1727
-        // AJAX response
1728
-        $this->_handle_json_response();
1729
-        // redirect to next step or the Thank You page
1730
-        $this->_handle_html_redirects();
1731
-        // hmmm... must be something wrong, so let's just display the form again !
1732
-        $this->_display_spco_reg_form();
1733
-    }
1734
-
1735
-
1736
-    /**
1737
-     *   _handle_json_response
1738
-     *
1739
-     * @access protected
1740
-     * @return void
1741
-     */
1742
-    protected function _handle_json_response()
1743
-    {
1744
-        // if this is an ajax request
1745
-        if (EE_Registry::instance()->REQ->ajax) {
1746
-            $this->checkout->json_response->set_registration_time_limit(
1747
-                $this->checkout->get_registration_time_limit()
1748
-            );
1749
-            $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1750
-            // just send the ajax (
1751
-            $json_response = apply_filters(
1752
-                'FHEE__EE_Single_Page_Checkout__JSON_response',
1753
-                $this->checkout->json_response
1754
-            );
1755
-            echo $json_response;
1756
-            exit();
1757
-        }
1758
-    }
1759
-
1760
-
1761
-    /**
1762
-     *   _handle_redirects
1763
-     *
1764
-     * @access protected
1765
-     * @return void
1766
-     */
1767
-    protected function _handle_html_redirects()
1768
-    {
1769
-        // going somewhere ?
1770
-        if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1771
-            // store notices in a transient
1772
-            EE_Error::get_notices(false, true, true);
1773
-            wp_safe_redirect($this->checkout->redirect_url);
1774
-            exit();
1775
-        }
1776
-    }
1777
-
1778
-
1779
-    /**
1780
-     *   set_checkout_anchor
1781
-     *
1782
-     * @access public
1783
-     * @return void
1784
-     */
1785
-    public function set_checkout_anchor()
1786
-    {
1787
-        echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1788
-    }
1789
-
1790
-    /**
1791
-     *    getRegistrationExpirationNotice
1792
-     *
1793
-     * @since     4.9.59.p
1794
-     * @access    public
1795
-     * @return    string
1796
-     */
1797
-    public static function getRegistrationExpirationNotice()
1798
-    {
1799
-        return sprintf(
1800
-            esc_html__(
1801
-                '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s',
1802
-                'event_espresso'
1803
-            ),
1804
-            '<h4 class="important-notice">',
1805
-            '</h4>',
1806
-            '<br />',
1807
-            '<p>',
1808
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1809
-            '">',
1810
-            '</a>',
1811
-            '</p>'
1812
-        );
1813
-    }
18
+	/**
19
+	 * $_initialized - has the SPCO controller already been initialized ?
20
+	 *
21
+	 * @access private
22
+	 * @var bool $_initialized
23
+	 */
24
+	private static $_initialized = false;
25
+
26
+
27
+	/**
28
+	 * $_checkout_verified - is the EE_Checkout verified as correct for this request ?
29
+	 *
30
+	 * @access private
31
+	 * @var bool $_valid_checkout
32
+	 */
33
+	private static $_checkout_verified = true;
34
+
35
+	/**
36
+	 *    $_reg_steps_array - holds initial array of reg steps
37
+	 *
38
+	 * @access private
39
+	 * @var array $_reg_steps_array
40
+	 */
41
+	private static $_reg_steps_array = array();
42
+
43
+	/**
44
+	 *    $checkout - EE_Checkout object for handling the properties of the current checkout process
45
+	 *
46
+	 * @access public
47
+	 * @var EE_Checkout $checkout
48
+	 */
49
+	public $checkout;
50
+
51
+
52
+	/**
53
+	 * @return EED_Module|EED_Single_Page_Checkout
54
+	 */
55
+	public static function instance()
56
+	{
57
+		add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true');
58
+		return parent::get_instance(__CLASS__);
59
+	}
60
+
61
+
62
+	/**
63
+	 * @return EE_CART
64
+	 */
65
+	public function cart()
66
+	{
67
+		return $this->checkout->cart;
68
+	}
69
+
70
+
71
+	/**
72
+	 * @return EE_Transaction
73
+	 */
74
+	public function transaction()
75
+	{
76
+		return $this->checkout->transaction;
77
+	}
78
+
79
+
80
+	/**
81
+	 *    set_hooks - for hooking into EE Core, other modules, etc
82
+	 *
83
+	 * @access    public
84
+	 * @return    void
85
+	 * @throws EE_Error
86
+	 */
87
+	public static function set_hooks()
88
+	{
89
+		EED_Single_Page_Checkout::set_definitions();
90
+	}
91
+
92
+
93
+	/**
94
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
95
+	 *
96
+	 * @access    public
97
+	 * @return    void
98
+	 * @throws EE_Error
99
+	 */
100
+	public static function set_hooks_admin()
101
+	{
102
+		EED_Single_Page_Checkout::set_definitions();
103
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
104
+			return;
105
+		}
106
+		// going to start an output buffer in case anything gets accidentally output
107
+		// that might disrupt our JSON response
108
+		ob_start();
109
+		EED_Single_Page_Checkout::load_request_handler();
110
+		EED_Single_Page_Checkout::load_reg_steps();
111
+		// set ajax hooks
112
+		add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
113
+		add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step'));
114
+		add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
115
+		add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step'));
116
+		add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
117
+		add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step'));
118
+	}
119
+
120
+
121
+	/**
122
+	 *    process ajax request
123
+	 *
124
+	 * @param string $ajax_action
125
+	 * @throws EE_Error
126
+	 */
127
+	public static function process_ajax_request($ajax_action)
128
+	{
129
+		EE_Registry::instance()->REQ->set('action', $ajax_action);
130
+		EED_Single_Page_Checkout::instance()->_initialize();
131
+	}
132
+
133
+
134
+	/**
135
+	 *    ajax display registration step
136
+	 *
137
+	 * @throws EE_Error
138
+	 */
139
+	public static function display_reg_step()
140
+	{
141
+		EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step');
142
+	}
143
+
144
+
145
+	/**
146
+	 *    ajax process registration step
147
+	 *
148
+	 * @throws EE_Error
149
+	 */
150
+	public static function process_reg_step()
151
+	{
152
+		EED_Single_Page_Checkout::process_ajax_request('process_reg_step');
153
+	}
154
+
155
+
156
+	/**
157
+	 *    ajax process registration step
158
+	 *
159
+	 * @throws EE_Error
160
+	 */
161
+	public static function update_reg_step()
162
+	{
163
+		EED_Single_Page_Checkout::process_ajax_request('update_reg_step');
164
+	}
165
+
166
+
167
+	/**
168
+	 *   update_checkout
169
+	 *
170
+	 * @access public
171
+	 * @return void
172
+	 * @throws EE_Error
173
+	 */
174
+	public static function update_checkout()
175
+	{
176
+		EED_Single_Page_Checkout::process_ajax_request('update_checkout');
177
+	}
178
+
179
+
180
+	/**
181
+	 *    load_request_handler
182
+	 *
183
+	 * @access    public
184
+	 * @return    void
185
+	 */
186
+	public static function load_request_handler()
187
+	{
188
+		// load core Request_Handler class
189
+		if (EE_Registry::instance()->REQ !== null) {
190
+			EE_Registry::instance()->load_core('Request_Handler');
191
+		}
192
+	}
193
+
194
+
195
+	/**
196
+	 *    set_definitions
197
+	 *
198
+	 * @access    public
199
+	 * @return    void
200
+	 * @throws EE_Error
201
+	 */
202
+	public static function set_definitions()
203
+	{
204
+		if (defined('SPCO_BASE_PATH')) {
205
+			return;
206
+		}
207
+		define(
208
+			'SPCO_BASE_PATH',
209
+			rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
210
+		);
211
+		define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
212
+		define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
213
+		define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
214
+		define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
215
+		define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
216
+		define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
217
+		EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
218
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
219
+		);
220
+	}
221
+
222
+
223
+	/**
224
+	 * load_reg_steps
225
+	 * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array
226
+	 *
227
+	 * @access    private
228
+	 * @throws EE_Error
229
+	 */
230
+	public static function load_reg_steps()
231
+	{
232
+		static $reg_steps_loaded = false;
233
+		if ($reg_steps_loaded) {
234
+			return;
235
+		}
236
+		// filter list of reg_steps
237
+		$reg_steps_to_load = (array) apply_filters(
238
+			'AHEE__SPCO__load_reg_steps__reg_steps_to_load',
239
+			EED_Single_Page_Checkout::get_reg_steps()
240
+		);
241
+		// sort by key (order)
242
+		ksort($reg_steps_to_load);
243
+		// loop through folders
244
+		foreach ($reg_steps_to_load as $order => $reg_step) {
245
+			// we need a
246
+			if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
247
+				// copy over to the reg_steps_array
248
+				EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step;
249
+				// register custom key route for each reg step
250
+				// ie: step=>"slug" - this is the entire reason we load the reg steps array now
251
+				EE_Config::register_route(
252
+					$reg_step['slug'],
253
+					'EED_Single_Page_Checkout',
254
+					'run',
255
+					'step'
256
+				);
257
+				// add AJAX or other hooks
258
+				if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
259
+					// setup autoloaders if necessary
260
+					if (! class_exists($reg_step['class_name'])) {
261
+						EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
262
+							$reg_step['file_path'],
263
+							true
264
+						);
265
+					}
266
+					if (is_callable($reg_step['class_name'], 'set_hooks')) {
267
+						call_user_func(array($reg_step['class_name'], 'set_hooks'));
268
+					}
269
+				}
270
+			}
271
+		}
272
+		$reg_steps_loaded = true;
273
+	}
274
+
275
+
276
+	/**
277
+	 *    get_reg_steps
278
+	 *
279
+	 * @access    public
280
+	 * @return    array
281
+	 */
282
+	public static function get_reg_steps()
283
+	{
284
+		$reg_steps = EE_Registry::instance()->CFG->registration->reg_steps;
285
+		if (empty($reg_steps)) {
286
+			$reg_steps = array(
287
+				10  => array(
288
+					'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
289
+					'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
290
+					'slug'       => 'attendee_information',
291
+					'has_hooks'  => false,
292
+				),
293
+				30  => array(
294
+					'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
295
+					'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
296
+					'slug'       => 'payment_options',
297
+					'has_hooks'  => true,
298
+				),
299
+				999 => array(
300
+					'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
301
+					'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
302
+					'slug'       => 'finalize_registration',
303
+					'has_hooks'  => false,
304
+				),
305
+			);
306
+		}
307
+		return $reg_steps;
308
+	}
309
+
310
+
311
+	/**
312
+	 *    registration_checkout_for_admin
313
+	 *
314
+	 * @access    public
315
+	 * @return    string
316
+	 * @throws EE_Error
317
+	 */
318
+	public static function registration_checkout_for_admin()
319
+	{
320
+		EED_Single_Page_Checkout::load_request_handler();
321
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
322
+		EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step');
323
+		EE_Registry::instance()->REQ->set('process_form_submission', false);
324
+		EED_Single_Page_Checkout::instance()->_initialize();
325
+		EED_Single_Page_Checkout::instance()->_display_spco_reg_form();
326
+		return EE_Registry::instance()->REQ->get_output();
327
+	}
328
+
329
+
330
+	/**
331
+	 * process_registration_from_admin
332
+	 *
333
+	 * @access public
334
+	 * @return \EE_Transaction
335
+	 * @throws EE_Error
336
+	 */
337
+	public static function process_registration_from_admin()
338
+	{
339
+		EED_Single_Page_Checkout::load_request_handler();
340
+		EE_Registry::instance()->REQ->set('step', 'attendee_information');
341
+		EE_Registry::instance()->REQ->set('action', 'process_reg_step');
342
+		EE_Registry::instance()->REQ->set('process_form_submission', true);
343
+		EED_Single_Page_Checkout::instance()->_initialize();
344
+		if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) {
345
+			$final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps);
346
+			if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) {
347
+				EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step);
348
+				if ($final_reg_step->process_reg_step()) {
349
+					$final_reg_step->set_completed();
350
+					EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array();
351
+					return EED_Single_Page_Checkout::instance()->checkout->transaction;
352
+				}
353
+			}
354
+		}
355
+		return null;
356
+	}
357
+
358
+
359
+	/**
360
+	 *    run
361
+	 *
362
+	 * @access    public
363
+	 * @param WP_Query $WP_Query
364
+	 * @return    void
365
+	 * @throws EE_Error
366
+	 */
367
+	public function run($WP_Query)
368
+	{
369
+		if ($WP_Query instanceof WP_Query
370
+			&& $WP_Query->is_main_query()
371
+			&& apply_filters('FHEE__EED_Single_Page_Checkout__run', true)
372
+			&& $this->_is_reg_checkout()
373
+		) {
374
+			$this->_initialize();
375
+		}
376
+	}
377
+
378
+
379
+	/**
380
+	 * determines whether current url matches reg page url
381
+	 *
382
+	 * @return bool
383
+	 */
384
+	protected function _is_reg_checkout()
385
+	{
386
+		// get current permalink for reg page without any extra query args
387
+		$reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id);
388
+		// get request URI for current request, but without the scheme or host
389
+		$current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI');
390
+		$current_request_uri = html_entity_decode($current_request_uri);
391
+		// get array of query args from the current request URI
392
+		$query_args = \EEH_URL::get_query_string($current_request_uri);
393
+		// grab page id if it is set
394
+		$page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0;
395
+		// and remove the page id from the query args (we will re-add it later)
396
+		unset($query_args['page_id']);
397
+		// now strip all query args from current request URI
398
+		$current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri);
399
+		// and re-add the page id if it was set
400
+		if ($page_id) {
401
+			$current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri);
402
+		}
403
+		// remove slashes and ?
404
+		$current_request_uri = trim($current_request_uri, '?/');
405
+		// is current request URI part of the known full reg page URL ?
406
+		return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false;
407
+	}
408
+
409
+
410
+	/**
411
+	 * @param WP_Query $wp_query
412
+	 * @return    void
413
+	 * @throws EE_Error
414
+	 */
415
+	public static function init($wp_query)
416
+	{
417
+		EED_Single_Page_Checkout::instance()->run($wp_query);
418
+	}
419
+
420
+
421
+	/**
422
+	 *    _initialize - initial module setup
423
+	 *
424
+	 * @access    private
425
+	 * @throws EE_Error
426
+	 * @return    void
427
+	 */
428
+	private function _initialize()
429
+	{
430
+		// ensure SPCO doesn't run twice
431
+		if (EED_Single_Page_Checkout::$_initialized) {
432
+			return;
433
+		}
434
+		try {
435
+			EED_Single_Page_Checkout::load_reg_steps();
436
+			$this->_verify_session();
437
+			// setup the EE_Checkout object
438
+			$this->checkout = $this->_initialize_checkout();
439
+			// filter checkout
440
+			$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout);
441
+			// get the $_GET
442
+			$this->_get_request_vars();
443
+			if ($this->_block_bots()) {
444
+				return;
445
+			}
446
+			// filter continue_reg
447
+			$this->checkout->continue_reg = apply_filters(
448
+				'FHEE__EED_Single_Page_Checkout__init___continue_reg',
449
+				true,
450
+				$this->checkout
451
+			);
452
+			// load the reg steps array
453
+			if (! $this->_load_and_instantiate_reg_steps()) {
454
+				EED_Single_Page_Checkout::$_initialized = true;
455
+				return;
456
+			}
457
+			// set the current step
458
+			$this->checkout->set_current_step($this->checkout->step);
459
+			// and the next step
460
+			$this->checkout->set_next_step();
461
+			// verify that everything has been setup correctly
462
+			if (! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
463
+				EED_Single_Page_Checkout::$_initialized = true;
464
+				return;
465
+			}
466
+			// lock the transaction
467
+			$this->checkout->transaction->lock();
468
+			// make sure all of our cached objects are added to their respective model entity mappers
469
+			$this->checkout->refresh_all_entities();
470
+			// set amount owing
471
+			$this->checkout->amount_owing = $this->checkout->transaction->remaining();
472
+			// initialize each reg step, which gives them the chance to potentially alter the process
473
+			$this->_initialize_reg_steps();
474
+			// DEBUG LOG
475
+			// $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
476
+			// get reg form
477
+			if (! $this->_check_form_submission()) {
478
+				EED_Single_Page_Checkout::$_initialized = true;
479
+				return;
480
+			}
481
+			// checkout the action!!!
482
+			$this->_process_form_action();
483
+			// add some style and make it dance
484
+			$this->add_styles_and_scripts();
485
+			// kk... SPCO has successfully run
486
+			EED_Single_Page_Checkout::$_initialized = true;
487
+			// set no cache headers and constants
488
+			EE_System::do_not_cache();
489
+			// add anchor
490
+			add_action('loop_start', array($this, 'set_checkout_anchor'), 1);
491
+			// remove transaction lock
492
+			add_action('shutdown', array($this, 'unlock_transaction'), 1);
493
+		} catch (Exception $e) {
494
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
495
+		}
496
+	}
497
+
498
+
499
+	/**
500
+	 *    _verify_session
501
+	 * checks that the session is valid and not expired
502
+	 *
503
+	 * @access    private
504
+	 * @throws EE_Error
505
+	 */
506
+	private function _verify_session()
507
+	{
508
+		if (! EE_Registry::instance()->SSN instanceof EE_Session) {
509
+			throw new EE_Error(esc_html__('The EE_Session class could not be loaded.', 'event_espresso'));
510
+		}
511
+		$clear_session_requested = filter_var(
512
+			EE_Registry::instance()->REQ->get('clear_session', false),
513
+			FILTER_VALIDATE_BOOLEAN
514
+		);
515
+		// is session still valid ?
516
+		if ($clear_session_requested
517
+			|| (EE_Registry::instance()->SSN->expired()
518
+				&& EE_Registry::instance()->REQ->get('e_reg_url_link', '') === ''
519
+			)
520
+		) {
521
+			$this->checkout = new EE_Checkout();
522
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
523
+			// EE_Registry::instance()->SSN->reset_cart();
524
+			// EE_Registry::instance()->SSN->reset_checkout();
525
+			// EE_Registry::instance()->SSN->reset_transaction();
526
+			if (! $clear_session_requested) {
527
+				EE_Error::add_attention(
528
+					EE_Registry::$i18n_js_strings['registration_expiration_notice'],
529
+					__FILE__,
530
+					__FUNCTION__,
531
+					__LINE__
532
+				);
533
+			}
534
+			// EE_Registry::instance()->SSN->reset_expired();
535
+		}
536
+	}
537
+
538
+
539
+	/**
540
+	 *    _initialize_checkout
541
+	 * loads and instantiates EE_Checkout
542
+	 *
543
+	 * @access    private
544
+	 * @throws EE_Error
545
+	 * @return EE_Checkout
546
+	 */
547
+	private function _initialize_checkout()
548
+	{
549
+		// look in session for existing checkout
550
+		/** @type EE_Checkout $checkout */
551
+		$checkout = EE_Registry::instance()->SSN->checkout();
552
+		// verify
553
+		if (! $checkout instanceof EE_Checkout) {
554
+			// instantiate EE_Checkout object for handling the properties of the current checkout process
555
+			$checkout = EE_Registry::instance()->load_file(
556
+				SPCO_INC_PATH,
557
+				'EE_Checkout',
558
+				'class',
559
+				array(),
560
+				false
561
+			);
562
+		} else {
563
+			if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) {
564
+				$this->unlock_transaction();
565
+				wp_safe_redirect($checkout->redirect_url);
566
+				exit();
567
+			}
568
+		}
569
+		$checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
570
+		// verify again
571
+		if (! $checkout instanceof EE_Checkout) {
572
+			throw new EE_Error(esc_html__('The EE_Checkout class could not be loaded.', 'event_espresso'));
573
+		}
574
+		// reset anything that needs a clean slate for each request
575
+		$checkout->reset_for_current_request();
576
+		return $checkout;
577
+	}
578
+
579
+
580
+	/**
581
+	 *    _get_request_vars
582
+	 *
583
+	 * @access    private
584
+	 * @return    void
585
+	 * @throws EE_Error
586
+	 */
587
+	private function _get_request_vars()
588
+	{
589
+		// load classes
590
+		EED_Single_Page_Checkout::load_request_handler();
591
+		// make sure this request is marked as belonging to EE
592
+		EE_Registry::instance()->REQ->set_espresso_page(true);
593
+		// which step is being requested ?
594
+		$this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step());
595
+		// which step is being edited ?
596
+		$this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', '');
597
+		// and what we're doing on the current step
598
+		$this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step');
599
+		// timestamp
600
+		$this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0);
601
+		// returning to edit ?
602
+		$this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', '');
603
+		// add reg url link to registration query params
604
+		if ($this->checkout->reg_url_link && strpos($this->checkout->reg_url_link, '1-') !== 0) {
605
+			$this->checkout->reg_cache_where_params[0]['REG_url_link'] = $this->checkout->reg_url_link;
606
+		}
607
+		// or some other kind of revisit ?
608
+		$this->checkout->revisit = filter_var(
609
+			EE_Registry::instance()->REQ->get('revisit', false),
610
+			FILTER_VALIDATE_BOOLEAN
611
+		);
612
+		// and whether or not to generate a reg form for this request
613
+		$this->checkout->generate_reg_form = filter_var(
614
+			EE_Registry::instance()->REQ->get('generate_reg_form', true),
615
+			FILTER_VALIDATE_BOOLEAN
616
+		);
617
+		// and whether or not to process a reg form submission for this request
618
+		$this->checkout->process_form_submission = filter_var(
619
+			EE_Registry::instance()->REQ->get(
620
+				'process_form_submission',
621
+				$this->checkout->action === 'process_reg_step'
622
+			),
623
+			FILTER_VALIDATE_BOOLEAN
624
+		);
625
+		$this->checkout->process_form_submission = filter_var(
626
+			$this->checkout->action !== 'display_spco_reg_step'
627
+				? $this->checkout->process_form_submission
628
+				: false,
629
+			FILTER_VALIDATE_BOOLEAN
630
+		);
631
+		// $this->_display_request_vars();
632
+	}
633
+
634
+
635
+	/**
636
+	 *  _display_request_vars
637
+	 *
638
+	 * @access    protected
639
+	 * @return    void
640
+	 */
641
+	protected function _display_request_vars()
642
+	{
643
+		if (! WP_DEBUG) {
644
+			return;
645
+		}
646
+		EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
647
+		EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__);
648
+		EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__);
649
+		EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__);
650
+		EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__);
651
+		EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__);
652
+		EEH_Debug_Tools::printr(
653
+			$this->checkout->generate_reg_form,
654
+			'$this->checkout->generate_reg_form',
655
+			__FILE__,
656
+			__LINE__
657
+		);
658
+		EEH_Debug_Tools::printr(
659
+			$this->checkout->process_form_submission,
660
+			'$this->checkout->process_form_submission',
661
+			__FILE__,
662
+			__LINE__
663
+		);
664
+	}
665
+
666
+
667
+	/**
668
+	 * _block_bots
669
+	 * checks that the incoming request has either of the following set:
670
+	 *  a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector
671
+	 *  a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN
672
+	 * so if you're not coming from the Ticket Selector nor returning for a valid IP...
673
+	 * then where you coming from man?
674
+	 *
675
+	 * @return boolean
676
+	 */
677
+	private function _block_bots()
678
+	{
679
+		$invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess();
680
+		if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) {
681
+			return true;
682
+		}
683
+		return false;
684
+	}
685
+
686
+
687
+	/**
688
+	 *    _get_first_step
689
+	 *  gets slug for first step in $_reg_steps_array
690
+	 *
691
+	 * @access    private
692
+	 * @throws EE_Error
693
+	 * @return    string
694
+	 */
695
+	private function _get_first_step()
696
+	{
697
+		$first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array);
698
+		return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information';
699
+	}
700
+
701
+
702
+	/**
703
+	 * instantiates each reg step based on the loaded reg_steps array
704
+	 *
705
+	 * @return    bool
706
+	 * @throws EE_Error
707
+	 * @throws InvalidArgumentException
708
+	 * @throws InvalidDataTypeException
709
+	 * @throws InvalidInterfaceException
710
+	 */
711
+	private function _load_and_instantiate_reg_steps()
712
+	{
713
+		do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout);
714
+		// have reg_steps already been instantiated ?
715
+		if (empty($this->checkout->reg_steps)
716
+			|| apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout)
717
+		) {
718
+			// if not, then loop through raw reg steps array
719
+			foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
720
+				if (! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
721
+					return false;
722
+				}
723
+			}
724
+			if (isset($this->checkout->reg_steps['registration_confirmation'])) {
725
+				// skip the registration_confirmation page ?
726
+				if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) {
727
+					// just remove it from the reg steps array
728
+					$this->checkout->remove_reg_step('registration_confirmation', false);
729
+				} elseif (EE_Registry::instance()->CFG->registration->reg_confirmation_last
730
+				) {
731
+					// set the order to something big like 100
732
+					$this->checkout->set_reg_step_order('registration_confirmation', 100);
733
+				}
734
+			}
735
+			// filter the array for good luck
736
+			$this->checkout->reg_steps = apply_filters(
737
+				'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps',
738
+				$this->checkout->reg_steps
739
+			);
740
+			// finally re-sort based on the reg step class order properties
741
+			$this->checkout->sort_reg_steps();
742
+		} else {
743
+			foreach ($this->checkout->reg_steps as $reg_step) {
744
+				// set all current step stati to FALSE
745
+				$reg_step->set_is_current_step(false);
746
+			}
747
+		}
748
+		if (empty($this->checkout->reg_steps)) {
749
+			EE_Error::add_error(
750
+				esc_html__('No Reg Steps were loaded..', 'event_espresso'),
751
+				__FILE__,
752
+				__FUNCTION__,
753
+				__LINE__
754
+			);
755
+			return false;
756
+		}
757
+		// make reg step details available to JS
758
+		$this->checkout->set_reg_step_JSON_info();
759
+		return true;
760
+	}
761
+
762
+
763
+	/**
764
+	 *     _load_and_instantiate_reg_step
765
+	 *
766
+	 * @access    private
767
+	 * @param array $reg_step
768
+	 * @param int   $order
769
+	 * @return bool
770
+	 */
771
+	private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0)
772
+	{
773
+		// we need a file_path, class_name, and slug to add a reg step
774
+		if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
775
+			// if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step)
776
+			if ($this->checkout->reg_url_link
777
+				&& $this->checkout->step !== $reg_step['slug']
778
+				&& $reg_step['slug'] !== 'finalize_registration'
779
+				// normally at this point we would NOT load the reg step, but this filter can change that
780
+				&& apply_filters(
781
+					'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step',
782
+					true,
783
+					$reg_step,
784
+					$this->checkout
785
+				)
786
+			) {
787
+				return true;
788
+			}
789
+			// instantiate step class using file path and class name
790
+			$reg_step_obj = EE_Registry::instance()->load_file(
791
+				$reg_step['file_path'],
792
+				$reg_step['class_name'],
793
+				'class',
794
+				$this->checkout,
795
+				false
796
+			);
797
+			// did we gets the goods ?
798
+			if ($reg_step_obj instanceof EE_SPCO_Reg_Step) {
799
+				// set reg step order based on config
800
+				$reg_step_obj->set_order($order);
801
+				// add instantiated reg step object to the master reg steps array
802
+				$this->checkout->add_reg_step($reg_step_obj);
803
+			} else {
804
+				EE_Error::add_error(
805
+					esc_html__('The current step could not be set.', 'event_espresso'),
806
+					__FILE__,
807
+					__FUNCTION__,
808
+					__LINE__
809
+				);
810
+				return false;
811
+			}
812
+		} else {
813
+			if (WP_DEBUG) {
814
+				EE_Error::add_error(
815
+					sprintf(
816
+						esc_html__(
817
+							'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s',
818
+							'event_espresso'
819
+						),
820
+						isset($reg_step['file_path']) ? $reg_step['file_path'] : '',
821
+						isset($reg_step['class_name']) ? $reg_step['class_name'] : '',
822
+						isset($reg_step['slug']) ? $reg_step['slug'] : '',
823
+						'<ul>',
824
+						'<li>',
825
+						'</li>',
826
+						'</ul>'
827
+					),
828
+					__FILE__,
829
+					__FUNCTION__,
830
+					__LINE__
831
+				);
832
+			}
833
+			return false;
834
+		}
835
+		return true;
836
+	}
837
+
838
+
839
+	/**
840
+	 * _verify_transaction_and_get_registrations
841
+	 *
842
+	 * @access private
843
+	 * @return bool
844
+	 * @throws InvalidDataTypeException
845
+	 * @throws InvalidEntityException
846
+	 * @throws EE_Error
847
+	 */
848
+	private function _verify_transaction_and_get_registrations()
849
+	{
850
+		// was there already a valid transaction in the checkout from the session ?
851
+		if (! $this->checkout->transaction instanceof EE_Transaction) {
852
+			// get transaction from db or session
853
+			$this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
854
+				? $this->_get_transaction_and_cart_for_previous_visit()
855
+				: $this->_get_cart_for_current_session_and_setup_new_transaction();
856
+			if (! $this->checkout->transaction instanceof EE_Transaction) {
857
+				EE_Error::add_error(
858
+					esc_html__(
859
+						'Your Registration and Transaction information could not be retrieved from the db.',
860
+						'event_espresso'
861
+					),
862
+					__FILE__,
863
+					__FUNCTION__,
864
+					__LINE__
865
+				);
866
+				$this->checkout->transaction = EE_Transaction::new_instance();
867
+				// add some style and make it dance
868
+				$this->add_styles_and_scripts();
869
+				EED_Single_Page_Checkout::$_initialized = true;
870
+				return false;
871
+			}
872
+			// and the registrations for the transaction
873
+			$this->_get_registrations($this->checkout->transaction);
874
+		}
875
+		return true;
876
+	}
877
+
878
+
879
+	/**
880
+	 * _get_transaction_and_cart_for_previous_visit
881
+	 *
882
+	 * @access private
883
+	 * @return mixed EE_Transaction|NULL
884
+	 */
885
+	private function _get_transaction_and_cart_for_previous_visit()
886
+	{
887
+		/** @var $TXN_model EEM_Transaction */
888
+		$TXN_model = EE_Registry::instance()->load_model('Transaction');
889
+		// because the reg_url_link is present in the request,
890
+		// this is a return visit to SPCO, so we'll get the transaction data from the db
891
+		$transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link);
892
+		// verify transaction
893
+		if ($transaction instanceof EE_Transaction) {
894
+			// and get the cart that was used for that transaction
895
+			$this->checkout->cart = $this->_get_cart_for_transaction($transaction);
896
+			return $transaction;
897
+		}
898
+		EE_Error::add_error(
899
+			esc_html__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'),
900
+			__FILE__,
901
+			__FUNCTION__,
902
+			__LINE__
903
+		);
904
+		return null;
905
+	}
906
+
907
+
908
+	/**
909
+	 * _get_cart_for_transaction
910
+	 *
911
+	 * @access private
912
+	 * @param EE_Transaction $transaction
913
+	 * @return EE_Cart
914
+	 */
915
+	private function _get_cart_for_transaction($transaction)
916
+	{
917
+		return $this->checkout->get_cart_for_transaction($transaction);
918
+	}
919
+
920
+
921
+	/**
922
+	 * get_cart_for_transaction
923
+	 *
924
+	 * @access public
925
+	 * @param EE_Transaction $transaction
926
+	 * @return EE_Cart
927
+	 */
928
+	public function get_cart_for_transaction(EE_Transaction $transaction)
929
+	{
930
+		return $this->checkout->get_cart_for_transaction($transaction);
931
+	}
932
+
933
+
934
+	/**
935
+	 * _get_transaction_and_cart_for_current_session
936
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
937
+	 *
938
+	 * @access private
939
+	 * @return EE_Transaction
940
+	 * @throws EE_Error
941
+	 */
942
+	private function _get_cart_for_current_session_and_setup_new_transaction()
943
+	{
944
+		//  if there's no transaction, then this is the FIRST visit to SPCO
945
+		// so load up the cart ( passing nothing for the TXN because it doesn't exist yet )
946
+		$this->checkout->cart = $this->_get_cart_for_transaction(null);
947
+		// and then create a new transaction
948
+		$transaction = $this->_initialize_transaction();
949
+		// verify transaction
950
+		if ($transaction instanceof EE_Transaction) {
951
+			// save it so that we have an ID for other objects to use
952
+			$transaction->save();
953
+			// and save TXN data to the cart
954
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID());
955
+		} else {
956
+			EE_Error::add_error(
957
+				esc_html__('A Valid Transaction could not be initialized.', 'event_espresso'),
958
+				__FILE__,
959
+				__FUNCTION__,
960
+				__LINE__
961
+			);
962
+		}
963
+		return $transaction;
964
+	}
965
+
966
+
967
+	/**
968
+	 *    generates a new EE_Transaction object and adds it to the $_transaction property.
969
+	 *
970
+	 * @access private
971
+	 * @return mixed EE_Transaction|NULL
972
+	 */
973
+	private function _initialize_transaction()
974
+	{
975
+		try {
976
+			// ensure cart totals have been calculated
977
+			$this->checkout->cart->get_grand_total()->recalculate_total_including_taxes();
978
+			// grab the cart grand total
979
+			$cart_total = $this->checkout->cart->get_cart_grand_total();
980
+			// create new TXN
981
+			$transaction = EE_Transaction::new_instance(
982
+				array(
983
+					'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(),
984
+					'TXN_total'     => $cart_total > 0 ? $cart_total : 0,
985
+					'TXN_paid'      => 0,
986
+					'STS_ID'        => EEM_Transaction::failed_status_code,
987
+				)
988
+			);
989
+			// save it so that we have an ID for other objects to use
990
+			$transaction->save();
991
+			// set cron job for following up on TXNs after their session has expired
992
+			EE_Cron_Tasks::schedule_expired_transaction_check(
993
+				EE_Registry::instance()->SSN->expiration() + 1,
994
+				$transaction->ID()
995
+			);
996
+			return $transaction;
997
+		} catch (Exception $e) {
998
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
999
+		}
1000
+		return null;
1001
+	}
1002
+
1003
+
1004
+	/**
1005
+	 * _get_registrations
1006
+	 *
1007
+	 * @access private
1008
+	 * @param EE_Transaction $transaction
1009
+	 * @return void
1010
+	 * @throws InvalidDataTypeException
1011
+	 * @throws InvalidEntityException
1012
+	 * @throws EE_Error
1013
+	 */
1014
+	private function _get_registrations(EE_Transaction $transaction)
1015
+	{
1016
+		// first step: grab the registrants  { : o
1017
+		$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1018
+		$this->checkout->total_ticket_count = count($registrations);
1019
+		// verify registrations have been set
1020
+		if (empty($registrations)) {
1021
+			// if no cached registrations, then check the db
1022
+			$registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false);
1023
+			// still nothing ? well as long as this isn't a revisit
1024
+			if (empty($registrations) && ! $this->checkout->revisit) {
1025
+				// generate new registrations from scratch
1026
+				$registrations = $this->_initialize_registrations($transaction);
1027
+			}
1028
+		}
1029
+		// sort by their original registration order
1030
+		usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count'));
1031
+		// then loop thru the array
1032
+		foreach ($registrations as $registration) {
1033
+			// verify each registration
1034
+			if ($registration instanceof EE_Registration) {
1035
+				// we display all attendee info for the primary registrant
1036
+				if ($this->checkout->reg_url_link === $registration->reg_url_link()
1037
+					&& $registration->is_primary_registrant()
1038
+				) {
1039
+					$this->checkout->primary_revisit = true;
1040
+					break;
1041
+				}
1042
+				if ($this->checkout->revisit && $this->checkout->reg_url_link !== $registration->reg_url_link()) {
1043
+					// but hide info if it doesn't belong to you
1044
+					$transaction->clear_cache('Registration', $registration->ID());
1045
+					$this->checkout->total_ticket_count--;
1046
+				}
1047
+				$this->checkout->set_reg_status_updated($registration->ID(), false);
1048
+			}
1049
+		}
1050
+	}
1051
+
1052
+
1053
+	/**
1054
+	 *    adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
1055
+	 *
1056
+	 * @access private
1057
+	 * @param EE_Transaction $transaction
1058
+	 * @return    array
1059
+	 * @throws InvalidDataTypeException
1060
+	 * @throws InvalidEntityException
1061
+	 * @throws EE_Error
1062
+	 */
1063
+	private function _initialize_registrations(EE_Transaction $transaction)
1064
+	{
1065
+		$att_nmbr = 0;
1066
+		$registrations = array();
1067
+		if ($transaction instanceof EE_Transaction) {
1068
+			/** @type EE_Registration_Processor $registration_processor */
1069
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1070
+			$this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count();
1071
+			// now let's add the cart items to the $transaction
1072
+			foreach ($this->checkout->cart->get_tickets() as $line_item) {
1073
+				// do the following for each ticket of this type they selected
1074
+				for ($x = 1; $x <= $line_item->quantity(); $x++) {
1075
+					$att_nmbr++;
1076
+					/** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */
1077
+					$CreateRegistrationCommand = EE_Registry::instance()->create(
1078
+						'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
1079
+						array(
1080
+							$transaction,
1081
+							$line_item,
1082
+							$att_nmbr,
1083
+							$this->checkout->total_ticket_count,
1084
+						)
1085
+					);
1086
+					// override capabilities for frontend registrations
1087
+					if (! is_admin()) {
1088
+						$CreateRegistrationCommand->setCapCheck(
1089
+							new PublicCapabilities('', 'create_new_registration')
1090
+						);
1091
+					}
1092
+					$registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1093
+					if (! $registration instanceof EE_Registration) {
1094
+						throw new InvalidEntityException($registration, 'EE_Registration');
1095
+					}
1096
+					$registrations[ $registration->ID() ] = $registration;
1097
+				}
1098
+			}
1099
+			$registration_processor->fix_reg_final_price_rounding_issue($transaction);
1100
+		}
1101
+		return $registrations;
1102
+	}
1103
+
1104
+
1105
+	/**
1106
+	 * sorts registrations by REG_count
1107
+	 *
1108
+	 * @access public
1109
+	 * @param EE_Registration $reg_A
1110
+	 * @param EE_Registration $reg_B
1111
+	 * @return int
1112
+	 */
1113
+	public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B)
1114
+	{
1115
+		// this shouldn't ever happen within the same TXN, but oh well
1116
+		if ($reg_A->count() === $reg_B->count()) {
1117
+			return 0;
1118
+		}
1119
+		return ($reg_A->count() > $reg_B->count()) ? 1 : -1;
1120
+	}
1121
+
1122
+
1123
+	/**
1124
+	 *    _final_verifications
1125
+	 * just makes sure that everything is set up correctly before proceeding
1126
+	 *
1127
+	 * @access    private
1128
+	 * @return    bool
1129
+	 * @throws EE_Error
1130
+	 */
1131
+	private function _final_verifications()
1132
+	{
1133
+		// filter checkout
1134
+		$this->checkout = apply_filters(
1135
+			'FHEE__EED_Single_Page_Checkout___final_verifications__checkout',
1136
+			$this->checkout
1137
+		);
1138
+		// verify that current step is still set correctly
1139
+		if (! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1140
+			EE_Error::add_error(
1141
+				esc_html__(
1142
+					'We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.',
1143
+					'event_espresso'
1144
+				),
1145
+				__FILE__,
1146
+				__FUNCTION__,
1147
+				__LINE__
1148
+			);
1149
+			return false;
1150
+		}
1151
+		// if returning to SPCO, then verify that primary registrant is set
1152
+		if (! empty($this->checkout->reg_url_link)) {
1153
+			$valid_registrant = $this->checkout->transaction->primary_registration();
1154
+			if (! $valid_registrant instanceof EE_Registration) {
1155
+				EE_Error::add_error(
1156
+					esc_html__(
1157
+						'We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.',
1158
+						'event_espresso'
1159
+					),
1160
+					__FILE__,
1161
+					__FUNCTION__,
1162
+					__LINE__
1163
+				);
1164
+				return false;
1165
+			}
1166
+			$valid_registrant = null;
1167
+			foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) {
1168
+				if ($registration instanceof EE_Registration
1169
+					&& $registration->reg_url_link() === $this->checkout->reg_url_link
1170
+				) {
1171
+					$valid_registrant = $registration;
1172
+				}
1173
+			}
1174
+			if (! $valid_registrant instanceof EE_Registration) {
1175
+				// hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1176
+				if (EED_Single_Page_Checkout::$_checkout_verified) {
1177
+					// clear the session, mark the checkout as unverified, and try again
1178
+					EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
1179
+					EED_Single_Page_Checkout::$_initialized = false;
1180
+					EED_Single_Page_Checkout::$_checkout_verified = false;
1181
+					$this->_initialize();
1182
+					EE_Error::reset_notices();
1183
+					return false;
1184
+				}
1185
+				EE_Error::add_error(
1186
+					esc_html__(
1187
+						'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.',
1188
+						'event_espresso'
1189
+					),
1190
+					__FILE__,
1191
+					__FUNCTION__,
1192
+					__LINE__
1193
+				);
1194
+				return false;
1195
+			}
1196
+		}
1197
+		// now that things have been kinda sufficiently verified,
1198
+		// let's add the checkout to the session so that it's available to other systems
1199
+		EE_Registry::instance()->SSN->set_checkout($this->checkout);
1200
+		return true;
1201
+	}
1202
+
1203
+
1204
+	/**
1205
+	 *    _initialize_reg_steps
1206
+	 * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required
1207
+	 * then loops thru all of the active reg steps and calls the initialize_reg_step() method
1208
+	 *
1209
+	 * @access    private
1210
+	 * @param bool $reinitializing
1211
+	 * @throws EE_Error
1212
+	 */
1213
+	private function _initialize_reg_steps($reinitializing = false)
1214
+	{
1215
+		$this->checkout->set_reg_step_initiated($this->checkout->current_step);
1216
+		// loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1217
+		foreach ($this->checkout->reg_steps as $reg_step) {
1218
+			if (! $reg_step->initialize_reg_step()) {
1219
+				// if not initialized then maybe this step is being removed...
1220
+				if (! $reinitializing && $reg_step->is_current_step()) {
1221
+					// if it was the current step, then we need to start over here
1222
+					$this->_initialize_reg_steps(true);
1223
+					return;
1224
+				}
1225
+				continue;
1226
+			}
1227
+			// add css and JS for current step
1228
+			$reg_step->enqueue_styles_and_scripts();
1229
+			// i18n
1230
+			$reg_step->translate_js_strings();
1231
+			if ($reg_step->is_current_step()) {
1232
+				// the text that appears on the reg step form submit button
1233
+				$reg_step->set_submit_button_text();
1234
+			}
1235
+		}
1236
+		// dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information
1237
+		do_action(
1238
+			"AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}",
1239
+			$this->checkout->current_step
1240
+		);
1241
+	}
1242
+
1243
+
1244
+	/**
1245
+	 * _check_form_submission
1246
+	 *
1247
+	 * @access private
1248
+	 * @return boolean
1249
+	 */
1250
+	private function _check_form_submission()
1251
+	{
1252
+		// does this request require the reg form to be generated ?
1253
+		if ($this->checkout->generate_reg_form) {
1254
+			// ever heard that song by Blue Rodeo ?
1255
+			try {
1256
+				$this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form();
1257
+				// if not displaying a form, then check for form submission
1258
+				if ($this->checkout->process_form_submission
1259
+					&& $this->checkout->current_step->reg_form->was_submitted()
1260
+				) {
1261
+					// clear out any old data in case this step is being run again
1262
+					$this->checkout->current_step->set_valid_data(array());
1263
+					// capture submitted form data
1264
+					$this->checkout->current_step->reg_form->receive_form_submission(
1265
+						apply_filters(
1266
+							'FHEE__Single_Page_Checkout___check_form_submission__request_params',
1267
+							EE_Registry::instance()->REQ->params(),
1268
+							$this->checkout
1269
+						)
1270
+					);
1271
+					// validate submitted form data
1272
+					if (! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1273
+						// thou shall not pass !!!
1274
+						$this->checkout->continue_reg = false;
1275
+						// any form validation errors?
1276
+						if ($this->checkout->current_step->reg_form->submission_error_message() !== '') {
1277
+							EE_Error::add_error(
1278
+								$this->checkout->current_step->reg_form->submission_error_message(),
1279
+								__FILE__,
1280
+								__FUNCTION__,
1281
+								__LINE__
1282
+							);
1283
+						}
1284
+						// well not really... what will happen is
1285
+						// we'll just get redirected back to redo the current step
1286
+						$this->go_to_next_step();
1287
+						return false;
1288
+					}
1289
+				}
1290
+			} catch (EE_Error $e) {
1291
+				$e->get_error();
1292
+			}
1293
+		}
1294
+		return true;
1295
+	}
1296
+
1297
+
1298
+	/**
1299
+	 * _process_action
1300
+	 *
1301
+	 * @access private
1302
+	 * @return void
1303
+	 * @throws EE_Error
1304
+	 */
1305
+	private function _process_form_action()
1306
+	{
1307
+		// what cha wanna do?
1308
+		switch ($this->checkout->action) {
1309
+			// AJAX next step reg form
1310
+			case 'display_spco_reg_step':
1311
+				$this->checkout->redirect = false;
1312
+				if (EE_Registry::instance()->REQ->ajax) {
1313
+					$this->checkout->json_response->set_reg_step_html(
1314
+						$this->checkout->current_step->display_reg_form()
1315
+					);
1316
+				}
1317
+				break;
1318
+			default:
1319
+				// meh... do one of those other steps first
1320
+				if (! empty($this->checkout->action)
1321
+					&& is_callable(array($this->checkout->current_step, $this->checkout->action))
1322
+				) {
1323
+					// dynamically creates hook point like:
1324
+					//   AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step
1325
+					do_action(
1326
+						"AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1327
+						$this->checkout->current_step
1328
+					);
1329
+					// call action on current step
1330
+					if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) {
1331
+						// good registrant, you get to proceed
1332
+						if ($this->checkout->current_step->success_message() !== ''
1333
+							&& apply_filters(
1334
+								'FHEE__Single_Page_Checkout___process_form_action__display_success',
1335
+								false
1336
+							)
1337
+						) {
1338
+							EE_Error::add_success(
1339
+								$this->checkout->current_step->success_message()
1340
+								. '<br />' . $this->checkout->next_step->_instructions()
1341
+							);
1342
+						}
1343
+						// pack it up, pack it in...
1344
+						$this->_setup_redirect();
1345
+					}
1346
+					// dynamically creates hook point like:
1347
+					//  AHEE__Single_Page_Checkout__after_payment_options__process_reg_step
1348
+					do_action(
1349
+						"AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}",
1350
+						$this->checkout->current_step
1351
+					);
1352
+				} else {
1353
+					EE_Error::add_error(
1354
+						sprintf(
1355
+							esc_html__(
1356
+								'The requested form action "%s" does not exist for the current "%s" registration step.',
1357
+								'event_espresso'
1358
+							),
1359
+							$this->checkout->action,
1360
+							$this->checkout->current_step->name()
1361
+						),
1362
+						__FILE__,
1363
+						__FUNCTION__,
1364
+						__LINE__
1365
+					);
1366
+				}
1367
+			// end default
1368
+		}
1369
+		// store our progress so far
1370
+		$this->checkout->stash_transaction_and_checkout();
1371
+		// advance to the next step! If you pass GO, collect $200
1372
+		$this->go_to_next_step();
1373
+	}
1374
+
1375
+
1376
+	/**
1377
+	 *        add_styles_and_scripts
1378
+	 *
1379
+	 * @access        public
1380
+	 * @return        void
1381
+	 */
1382
+	public function add_styles_and_scripts()
1383
+	{
1384
+		// i18n
1385
+		$this->translate_js_strings();
1386
+		if ($this->checkout->admin_request) {
1387
+			add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1388
+		} else {
1389
+			add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10);
1390
+		}
1391
+	}
1392
+
1393
+
1394
+	/**
1395
+	 *        translate_js_strings
1396
+	 *
1397
+	 * @access        public
1398
+	 * @return        void
1399
+	 */
1400
+	public function translate_js_strings()
1401
+	{
1402
+		EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit;
1403
+		EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link;
1404
+		EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
1405
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
1406
+			'event_espresso'
1407
+		);
1408
+		EE_Registry::$i18n_js_strings['invalid_json_response'] = esc_html__(
1409
+			'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.',
1410
+			'event_espresso'
1411
+		);
1412
+		EE_Registry::$i18n_js_strings['validation_error'] = esc_html__(
1413
+			'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.',
1414
+			'event_espresso'
1415
+		);
1416
+		EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__(
1417
+			'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.',
1418
+			'event_espresso'
1419
+		);
1420
+		EE_Registry::$i18n_js_strings['reg_step_error'] = esc_html__(
1421
+			'This registration step could not be completed. Please refresh the page and try again.',
1422
+			'event_espresso'
1423
+		);
1424
+		EE_Registry::$i18n_js_strings['invalid_coupon'] = esc_html__(
1425
+			'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.',
1426
+			'event_espresso'
1427
+		);
1428
+		EE_Registry::$i18n_js_strings['process_registration'] = sprintf(
1429
+			esc_html__(
1430
+				'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.',
1431
+				'event_espresso'
1432
+			),
1433
+			'<br/>',
1434
+			'<br/>'
1435
+		);
1436
+		EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language');
1437
+		EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id();
1438
+		EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency;
1439
+		EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20';
1440
+		EE_Registry::$i18n_js_strings['timer_years'] = esc_html__('years', 'event_espresso');
1441
+		EE_Registry::$i18n_js_strings['timer_months'] = esc_html__('months', 'event_espresso');
1442
+		EE_Registry::$i18n_js_strings['timer_weeks'] = esc_html__('weeks', 'event_espresso');
1443
+		EE_Registry::$i18n_js_strings['timer_days'] = esc_html__('days', 'event_espresso');
1444
+		EE_Registry::$i18n_js_strings['timer_hours'] = esc_html__('hours', 'event_espresso');
1445
+		EE_Registry::$i18n_js_strings['timer_minutes'] = esc_html__('minutes', 'event_espresso');
1446
+		EE_Registry::$i18n_js_strings['timer_seconds'] = esc_html__('seconds', 'event_espresso');
1447
+		EE_Registry::$i18n_js_strings['timer_year'] = esc_html__('year', 'event_espresso');
1448
+		EE_Registry::$i18n_js_strings['timer_month'] = esc_html__('month', 'event_espresso');
1449
+		EE_Registry::$i18n_js_strings['timer_week'] = esc_html__('week', 'event_espresso');
1450
+		EE_Registry::$i18n_js_strings['timer_day'] = esc_html__('day', 'event_espresso');
1451
+		EE_Registry::$i18n_js_strings['timer_hour'] = esc_html__('hour', 'event_espresso');
1452
+		EE_Registry::$i18n_js_strings['timer_minute'] = esc_html__('minute', 'event_espresso');
1453
+		EE_Registry::$i18n_js_strings['timer_second'] = esc_html__('second', 'event_espresso');
1454
+		EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
1455
+		);
1456
+		EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters(
1457
+			'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit',
1458
+			true
1459
+		);
1460
+		EE_Registry::$i18n_js_strings['session_extension'] = absint(
1461
+			apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS)
1462
+		);
1463
+		EE_Registry::$i18n_js_strings['session_expiration'] = gmdate(
1464
+			'M d, Y H:i:s',
1465
+			EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1466
+		);
1467
+	}
1468
+
1469
+
1470
+	/**
1471
+	 *    enqueue_styles_and_scripts
1472
+	 *
1473
+	 * @access        public
1474
+	 * @return        void
1475
+	 * @throws EE_Error
1476
+	 */
1477
+	public function enqueue_styles_and_scripts()
1478
+	{
1479
+		// load css
1480
+		wp_register_style(
1481
+			'single_page_checkout',
1482
+			SPCO_CSS_URL . 'single_page_checkout.css',
1483
+			array('espresso_default'),
1484
+			EVENT_ESPRESSO_VERSION
1485
+		);
1486
+		wp_enqueue_style('single_page_checkout');
1487
+		// load JS
1488
+		wp_register_script(
1489
+			'jquery_plugin',
1490
+			EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1491
+			array('jquery'),
1492
+			'1.0.1',
1493
+			true
1494
+		);
1495
+		wp_register_script(
1496
+			'jquery_countdown',
1497
+			EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1498
+			array('jquery_plugin'),
1499
+			'2.1.0',
1500
+			true
1501
+		);
1502
+		wp_register_script(
1503
+			'single_page_checkout',
1504
+			SPCO_JS_URL . 'single_page_checkout.js',
1505
+			array('espresso_core', 'underscore', 'ee_form_section_validation'),
1506
+			EVENT_ESPRESSO_VERSION,
1507
+			true
1508
+		);
1509
+		if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) {
1510
+			$this->checkout->registration_form->enqueue_js();
1511
+		}
1512
+		if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) {
1513
+			$this->checkout->current_step->reg_form->enqueue_js();
1514
+		}
1515
+		wp_enqueue_script('single_page_checkout');
1516
+		if (apply_filters('FHEE__registration_page_wrapper_template__display_time_limit', false)) {
1517
+			wp_enqueue_script('jquery_countdown');
1518
+		}
1519
+		/**
1520
+		 * global action hook for enqueueing styles and scripts with
1521
+		 * spco calls.
1522
+		 */
1523
+		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this);
1524
+		/**
1525
+		 * dynamic action hook for enqueueing styles and scripts with spco calls.
1526
+		 * The hook will end up being something like:
1527
+		 *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1528
+		 */
1529
+		do_action(
1530
+			'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1531
+			$this
1532
+		);
1533
+	}
1534
+
1535
+
1536
+	/**
1537
+	 *    display the Registration Single Page Checkout Form
1538
+	 *
1539
+	 * @access    private
1540
+	 * @return    void
1541
+	 * @throws EE_Error
1542
+	 */
1543
+	private function _display_spco_reg_form()
1544
+	{
1545
+		// if registering via the admin, just display the reg form for the current step
1546
+		if ($this->checkout->admin_request) {
1547
+			EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form());
1548
+		} else {
1549
+			// add powered by EE msg
1550
+			add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer'));
1551
+			$empty_cart = count($this->checkout->transaction
1552
+									->registrations($this->checkout->reg_cache_where_params)) < 1;
1553
+			EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart;
1554
+			$cookies_not_set_msg = '';
1555
+			if ($empty_cart) {
1556
+				$cookies_not_set_msg = apply_filters(
1557
+					'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg',
1558
+					sprintf(
1559
+						esc_html__(
1560
+							'%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s',
1561
+							'event_espresso'
1562
+						),
1563
+						'<div class="ee-attention hidden" id="ee-cookies-not-set-msg">',
1564
+						'</div>',
1565
+						'<h6 class="important-notice">',
1566
+						'</h6>',
1567
+						'<p>',
1568
+						'</p>',
1569
+						'<br />',
1570
+						'<a href="http://www.whatarecookies.com/enable.asp" target="_blank" rel="noopener noreferrer">',
1571
+						'</a>'
1572
+					)
1573
+				);
1574
+			}
1575
+			$this->checkout->registration_form = new EE_Form_Section_Proper(
1576
+				array(
1577
+					'name'            => 'single-page-checkout',
1578
+					'html_id'         => 'ee-single-page-checkout-dv',
1579
+					'layout_strategy' =>
1580
+						new EE_Template_Layout(
1581
+							array(
1582
+								'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1583
+								'template_args'        => array(
1584
+									'empty_cart'              => $empty_cart,
1585
+									'revisit'                 => $this->checkout->revisit,
1586
+									'reg_steps'               => $this->checkout->reg_steps,
1587
+									'next_step'               => $this->checkout->next_step instanceof EE_SPCO_Reg_Step
1588
+										? $this->checkout->next_step->slug()
1589
+										: '',
1590
+									'empty_msg'               => apply_filters(
1591
+										'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg',
1592
+										sprintf(
1593
+											esc_html__(
1594
+												'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.',
1595
+												'event_espresso'
1596
+											),
1597
+											'<a href="'
1598
+											. get_post_type_archive_link('espresso_events')
1599
+											. '" title="',
1600
+											'">',
1601
+											'</a>'
1602
+										)
1603
+									),
1604
+									'cookies_not_set_msg'     => $cookies_not_set_msg,
1605
+									'registration_time_limit' => $this->checkout->get_registration_time_limit(),
1606
+									'session_expiration'      => gmdate(
1607
+										'M d, Y H:i:s',
1608
+										EE_Registry::instance()->SSN->expiration()
1609
+										+ (get_option('gmt_offset') * HOUR_IN_SECONDS)
1610
+									),
1611
+								),
1612
+							)
1613
+						),
1614
+				)
1615
+			);
1616
+			// load template and add to output sent that gets filtered into the_content()
1617
+			EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html());
1618
+		}
1619
+	}
1620
+
1621
+
1622
+	/**
1623
+	 *    add_extra_finalize_registration_inputs
1624
+	 *
1625
+	 * @access    public
1626
+	 * @param $next_step
1627
+	 * @internal  param string $label
1628
+	 * @return void
1629
+	 */
1630
+	public function add_extra_finalize_registration_inputs($next_step)
1631
+	{
1632
+		if ($next_step === 'finalize_registration') {
1633
+			echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>';
1634
+		}
1635
+	}
1636
+
1637
+
1638
+	/**
1639
+	 *    display_registration_footer
1640
+	 *
1641
+	 * @access    public
1642
+	 * @return    string
1643
+	 */
1644
+	public static function display_registration_footer()
1645
+	{
1646
+		if (apply_filters(
1647
+			'FHEE__EE_Front__Controller__show_reg_footer',
1648
+			EE_Registry::instance()->CFG->admin->show_reg_footer
1649
+		)) {
1650
+			add_filter(
1651
+				'FHEE__EEH_Template__powered_by_event_espresso__url',
1652
+				function ($url) {
1653
+					return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1654
+				}
1655
+			);
1656
+			echo apply_filters(
1657
+				'FHEE__EE_Front_Controller__display_registration_footer',
1658
+				\EEH_Template::powered_by_event_espresso(
1659
+					'',
1660
+					'espresso-registration-footer-dv',
1661
+					array('utm_content' => 'registration_checkout')
1662
+				)
1663
+			);
1664
+		}
1665
+		return '';
1666
+	}
1667
+
1668
+
1669
+	/**
1670
+	 *    unlock_transaction
1671
+	 *
1672
+	 * @access    public
1673
+	 * @return    void
1674
+	 * @throws EE_Error
1675
+	 */
1676
+	public function unlock_transaction()
1677
+	{
1678
+		if ($this->checkout->transaction instanceof EE_Transaction) {
1679
+			$this->checkout->transaction->unlock();
1680
+		}
1681
+	}
1682
+
1683
+
1684
+	/**
1685
+	 *        _setup_redirect
1686
+	 *
1687
+	 * @access    private
1688
+	 * @return void
1689
+	 */
1690
+	private function _setup_redirect()
1691
+	{
1692
+		if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) {
1693
+			$this->checkout->redirect = true;
1694
+			if (empty($this->checkout->redirect_url)) {
1695
+				$this->checkout->redirect_url = $this->checkout->next_step->reg_step_url();
1696
+			}
1697
+			$this->checkout->redirect_url = apply_filters(
1698
+				'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url',
1699
+				$this->checkout->redirect_url,
1700
+				$this->checkout
1701
+			);
1702
+		}
1703
+	}
1704
+
1705
+
1706
+	/**
1707
+	 *   handle ajax message responses and redirects
1708
+	 *
1709
+	 * @access public
1710
+	 * @return void
1711
+	 * @throws EE_Error
1712
+	 */
1713
+	public function go_to_next_step()
1714
+	{
1715
+		if (EE_Registry::instance()->REQ->ajax) {
1716
+			// capture contents of output buffer we started earlier in the request, and insert into JSON response
1717
+			$this->checkout->json_response->set_unexpected_errors(ob_get_clean());
1718
+		}
1719
+		$this->unlock_transaction();
1720
+		// just return for these conditions
1721
+		if ($this->checkout->admin_request
1722
+			|| $this->checkout->action === 'redirect_form'
1723
+			|| $this->checkout->action === 'update_checkout'
1724
+		) {
1725
+			return;
1726
+		}
1727
+		// AJAX response
1728
+		$this->_handle_json_response();
1729
+		// redirect to next step or the Thank You page
1730
+		$this->_handle_html_redirects();
1731
+		// hmmm... must be something wrong, so let's just display the form again !
1732
+		$this->_display_spco_reg_form();
1733
+	}
1734
+
1735
+
1736
+	/**
1737
+	 *   _handle_json_response
1738
+	 *
1739
+	 * @access protected
1740
+	 * @return void
1741
+	 */
1742
+	protected function _handle_json_response()
1743
+	{
1744
+		// if this is an ajax request
1745
+		if (EE_Registry::instance()->REQ->ajax) {
1746
+			$this->checkout->json_response->set_registration_time_limit(
1747
+				$this->checkout->get_registration_time_limit()
1748
+			);
1749
+			$this->checkout->json_response->set_payment_amount($this->checkout->amount_owing);
1750
+			// just send the ajax (
1751
+			$json_response = apply_filters(
1752
+				'FHEE__EE_Single_Page_Checkout__JSON_response',
1753
+				$this->checkout->json_response
1754
+			);
1755
+			echo $json_response;
1756
+			exit();
1757
+		}
1758
+	}
1759
+
1760
+
1761
+	/**
1762
+	 *   _handle_redirects
1763
+	 *
1764
+	 * @access protected
1765
+	 * @return void
1766
+	 */
1767
+	protected function _handle_html_redirects()
1768
+	{
1769
+		// going somewhere ?
1770
+		if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) {
1771
+			// store notices in a transient
1772
+			EE_Error::get_notices(false, true, true);
1773
+			wp_safe_redirect($this->checkout->redirect_url);
1774
+			exit();
1775
+		}
1776
+	}
1777
+
1778
+
1779
+	/**
1780
+	 *   set_checkout_anchor
1781
+	 *
1782
+	 * @access public
1783
+	 * @return void
1784
+	 */
1785
+	public function set_checkout_anchor()
1786
+	{
1787
+		echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>';
1788
+	}
1789
+
1790
+	/**
1791
+	 *    getRegistrationExpirationNotice
1792
+	 *
1793
+	 * @since     4.9.59.p
1794
+	 * @access    public
1795
+	 * @return    string
1796
+	 */
1797
+	public static function getRegistrationExpirationNotice()
1798
+	{
1799
+		return sprintf(
1800
+			esc_html__(
1801
+				'%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please accept our apologies for any inconvenience this may have caused.%8$s',
1802
+				'event_espresso'
1803
+			),
1804
+			'<h4 class="important-notice">',
1805
+			'</h4>',
1806
+			'<br />',
1807
+			'<p>',
1808
+			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1809
+			'">',
1810
+			'</a>',
1811
+			'</p>'
1812
+		);
1813
+	}
1814 1814
 }
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
     public static function set_hooks_admin()
101 101
     {
102 102
         EED_Single_Page_Checkout::set_definitions();
103
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
103
+        if ( ! (defined('DOING_AJAX') && DOING_AJAX)) {
104 104
             return;
105 105
         }
106 106
         // going to start an output buffer in case anything gets accidentally output
@@ -206,14 +206,14 @@  discard block
 block discarded – undo
206 206
         }
207 207
         define(
208 208
             'SPCO_BASE_PATH',
209
-            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS
209
+            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS).DS
210 210
         );
211
-        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS);
212
-        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS);
213
-        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS);
214
-        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS);
215
-        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS);
216
-        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS);
211
+        define('SPCO_CSS_URL', plugin_dir_url(__FILE__).'css'.DS);
212
+        define('SPCO_IMG_URL', plugin_dir_url(__FILE__).'img'.DS);
213
+        define('SPCO_JS_URL', plugin_dir_url(__FILE__).'js'.DS);
214
+        define('SPCO_INC_PATH', SPCO_BASE_PATH.'inc'.DS);
215
+        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH.'reg_steps'.DS);
216
+        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH.'templates'.DS);
217 217
         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true);
218 218
         EE_Registry::$i18n_js_strings['registration_expiration_notice'] = EED_Single_Page_Checkout::getRegistrationExpirationNotice(
219 219
         );
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
             // we need a
246 246
             if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) {
247 247
                 // copy over to the reg_steps_array
248
-                EED_Single_Page_Checkout::$_reg_steps_array[ $order ] = $reg_step;
248
+                EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step;
249 249
                 // register custom key route for each reg step
250 250
                 // ie: step=>"slug" - this is the entire reason we load the reg steps array now
251 251
                 EE_Config::register_route(
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
                 // add AJAX or other hooks
258 258
                 if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) {
259 259
                     // setup autoloaders if necessary
260
-                    if (! class_exists($reg_step['class_name'])) {
260
+                    if ( ! class_exists($reg_step['class_name'])) {
261 261
                         EEH_Autoloader::register_autoloaders_for_each_file_in_folder(
262 262
                             $reg_step['file_path'],
263 263
                             true
@@ -285,19 +285,19 @@  discard block
 block discarded – undo
285 285
         if (empty($reg_steps)) {
286 286
             $reg_steps = array(
287 287
                 10  => array(
288
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'attendee_information',
288
+                    'file_path'  => SPCO_REG_STEPS_PATH.'attendee_information',
289 289
                     'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information',
290 290
                     'slug'       => 'attendee_information',
291 291
                     'has_hooks'  => false,
292 292
                 ),
293 293
                 30  => array(
294
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'payment_options',
294
+                    'file_path'  => SPCO_REG_STEPS_PATH.'payment_options',
295 295
                     'class_name' => 'EE_SPCO_Reg_Step_Payment_Options',
296 296
                     'slug'       => 'payment_options',
297 297
                     'has_hooks'  => true,
298 298
                 ),
299 299
                 999 => array(
300
-                    'file_path'  => SPCO_REG_STEPS_PATH . 'finalize_registration',
300
+                    'file_path'  => SPCO_REG_STEPS_PATH.'finalize_registration',
301 301
                     'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration',
302 302
                     'slug'       => 'finalize_registration',
303 303
                     'has_hooks'  => false,
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
                 $this->checkout
451 451
             );
452 452
             // load the reg steps array
453
-            if (! $this->_load_and_instantiate_reg_steps()) {
453
+            if ( ! $this->_load_and_instantiate_reg_steps()) {
454 454
                 EED_Single_Page_Checkout::$_initialized = true;
455 455
                 return;
456 456
             }
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
             // and the next step
460 460
             $this->checkout->set_next_step();
461 461
             // verify that everything has been setup correctly
462
-            if (! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
462
+            if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) {
463 463
                 EED_Single_Page_Checkout::$_initialized = true;
464 464
                 return;
465 465
             }
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
             // DEBUG LOG
475 475
             // $this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
476 476
             // get reg form
477
-            if (! $this->_check_form_submission()) {
477
+            if ( ! $this->_check_form_submission()) {
478 478
                 EED_Single_Page_Checkout::$_initialized = true;
479 479
                 return;
480 480
             }
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
      */
506 506
     private function _verify_session()
507 507
     {
508
-        if (! EE_Registry::instance()->SSN instanceof EE_Session) {
508
+        if ( ! EE_Registry::instance()->SSN instanceof EE_Session) {
509 509
             throw new EE_Error(esc_html__('The EE_Session class could not be loaded.', 'event_espresso'));
510 510
         }
511 511
         $clear_session_requested = filter_var(
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
             // EE_Registry::instance()->SSN->reset_cart();
524 524
             // EE_Registry::instance()->SSN->reset_checkout();
525 525
             // EE_Registry::instance()->SSN->reset_transaction();
526
-            if (! $clear_session_requested) {
526
+            if ( ! $clear_session_requested) {
527 527
                 EE_Error::add_attention(
528 528
                     EE_Registry::$i18n_js_strings['registration_expiration_notice'],
529 529
                     __FILE__,
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
         /** @type EE_Checkout $checkout */
551 551
         $checkout = EE_Registry::instance()->SSN->checkout();
552 552
         // verify
553
-        if (! $checkout instanceof EE_Checkout) {
553
+        if ( ! $checkout instanceof EE_Checkout) {
554 554
             // instantiate EE_Checkout object for handling the properties of the current checkout process
555 555
             $checkout = EE_Registry::instance()->load_file(
556 556
                 SPCO_INC_PATH,
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
         }
569 569
         $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout);
570 570
         // verify again
571
-        if (! $checkout instanceof EE_Checkout) {
571
+        if ( ! $checkout instanceof EE_Checkout) {
572 572
             throw new EE_Error(esc_html__('The EE_Checkout class could not be loaded.', 'event_espresso'));
573 573
         }
574 574
         // reset anything that needs a clean slate for each request
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
      */
641 641
     protected function _display_request_vars()
642 642
     {
643
-        if (! WP_DEBUG) {
643
+        if ( ! WP_DEBUG) {
644 644
             return;
645 645
         }
646 646
         EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__);
@@ -717,7 +717,7 @@  discard block
 block discarded – undo
717 717
         ) {
718 718
             // if not, then loop through raw reg steps array
719 719
             foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) {
720
-                if (! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
720
+                if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) {
721 721
                     return false;
722 722
                 }
723 723
             }
@@ -848,12 +848,12 @@  discard block
 block discarded – undo
848 848
     private function _verify_transaction_and_get_registrations()
849 849
     {
850 850
         // was there already a valid transaction in the checkout from the session ?
851
-        if (! $this->checkout->transaction instanceof EE_Transaction) {
851
+        if ( ! $this->checkout->transaction instanceof EE_Transaction) {
852 852
             // get transaction from db or session
853 853
             $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin()
854 854
                 ? $this->_get_transaction_and_cart_for_previous_visit()
855 855
                 : $this->_get_cart_for_current_session_and_setup_new_transaction();
856
-            if (! $this->checkout->transaction instanceof EE_Transaction) {
856
+            if ( ! $this->checkout->transaction instanceof EE_Transaction) {
857 857
                 EE_Error::add_error(
858 858
                     esc_html__(
859 859
                         'Your Registration and Transaction information could not be retrieved from the db.',
@@ -1084,16 +1084,16 @@  discard block
 block discarded – undo
1084 1084
                         )
1085 1085
                     );
1086 1086
                     // override capabilities for frontend registrations
1087
-                    if (! is_admin()) {
1087
+                    if ( ! is_admin()) {
1088 1088
                         $CreateRegistrationCommand->setCapCheck(
1089 1089
                             new PublicCapabilities('', 'create_new_registration')
1090 1090
                         );
1091 1091
                     }
1092 1092
                     $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand);
1093
-                    if (! $registration instanceof EE_Registration) {
1093
+                    if ( ! $registration instanceof EE_Registration) {
1094 1094
                         throw new InvalidEntityException($registration, 'EE_Registration');
1095 1095
                     }
1096
-                    $registrations[ $registration->ID() ] = $registration;
1096
+                    $registrations[$registration->ID()] = $registration;
1097 1097
                 }
1098 1098
             }
1099 1099
             $registration_processor->fix_reg_final_price_rounding_issue($transaction);
@@ -1136,7 +1136,7 @@  discard block
 block discarded – undo
1136 1136
             $this->checkout
1137 1137
         );
1138 1138
         // verify that current step is still set correctly
1139
-        if (! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1139
+        if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) {
1140 1140
             EE_Error::add_error(
1141 1141
                 esc_html__(
1142 1142
                     'We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.',
@@ -1149,9 +1149,9 @@  discard block
 block discarded – undo
1149 1149
             return false;
1150 1150
         }
1151 1151
         // if returning to SPCO, then verify that primary registrant is set
1152
-        if (! empty($this->checkout->reg_url_link)) {
1152
+        if ( ! empty($this->checkout->reg_url_link)) {
1153 1153
             $valid_registrant = $this->checkout->transaction->primary_registration();
1154
-            if (! $valid_registrant instanceof EE_Registration) {
1154
+            if ( ! $valid_registrant instanceof EE_Registration) {
1155 1155
                 EE_Error::add_error(
1156 1156
                     esc_html__(
1157 1157
                         'We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.',
@@ -1171,7 +1171,7 @@  discard block
 block discarded – undo
1171 1171
                     $valid_registrant = $registration;
1172 1172
                 }
1173 1173
             }
1174
-            if (! $valid_registrant instanceof EE_Registration) {
1174
+            if ( ! $valid_registrant instanceof EE_Registration) {
1175 1175
                 // hmmm... maybe we have the wrong session because the user is opening multiple tabs ?
1176 1176
                 if (EED_Single_Page_Checkout::$_checkout_verified) {
1177 1177
                     // clear the session, mark the checkout as unverified, and try again
@@ -1215,9 +1215,9 @@  discard block
 block discarded – undo
1215 1215
         $this->checkout->set_reg_step_initiated($this->checkout->current_step);
1216 1216
         // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS
1217 1217
         foreach ($this->checkout->reg_steps as $reg_step) {
1218
-            if (! $reg_step->initialize_reg_step()) {
1218
+            if ( ! $reg_step->initialize_reg_step()) {
1219 1219
                 // if not initialized then maybe this step is being removed...
1220
-                if (! $reinitializing && $reg_step->is_current_step()) {
1220
+                if ( ! $reinitializing && $reg_step->is_current_step()) {
1221 1221
                     // if it was the current step, then we need to start over here
1222 1222
                     $this->_initialize_reg_steps(true);
1223 1223
                     return;
@@ -1269,7 +1269,7 @@  discard block
 block discarded – undo
1269 1269
                         )
1270 1270
                     );
1271 1271
                     // validate submitted form data
1272
-                    if (! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1272
+                    if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) {
1273 1273
                         // thou shall not pass !!!
1274 1274
                         $this->checkout->continue_reg = false;
1275 1275
                         // any form validation errors?
@@ -1317,7 +1317,7 @@  discard block
 block discarded – undo
1317 1317
                 break;
1318 1318
             default:
1319 1319
                 // meh... do one of those other steps first
1320
-                if (! empty($this->checkout->action)
1320
+                if ( ! empty($this->checkout->action)
1321 1321
                     && is_callable(array($this->checkout->current_step, $this->checkout->action))
1322 1322
                 ) {
1323 1323
                     // dynamically creates hook point like:
@@ -1337,7 +1337,7 @@  discard block
 block discarded – undo
1337 1337
                         ) {
1338 1338
                             EE_Error::add_success(
1339 1339
                                 $this->checkout->current_step->success_message()
1340
-                                . '<br />' . $this->checkout->next_step->_instructions()
1340
+                                . '<br />'.$this->checkout->next_step->_instructions()
1341 1341
                             );
1342 1342
                         }
1343 1343
                         // pack it up, pack it in...
@@ -1479,7 +1479,7 @@  discard block
 block discarded – undo
1479 1479
         // load css
1480 1480
         wp_register_style(
1481 1481
             'single_page_checkout',
1482
-            SPCO_CSS_URL . 'single_page_checkout.css',
1482
+            SPCO_CSS_URL.'single_page_checkout.css',
1483 1483
             array('espresso_default'),
1484 1484
             EVENT_ESPRESSO_VERSION
1485 1485
         );
@@ -1487,21 +1487,21 @@  discard block
 block discarded – undo
1487 1487
         // load JS
1488 1488
         wp_register_script(
1489 1489
             'jquery_plugin',
1490
-            EE_THIRD_PARTY_URL . 'jquery	.plugin.min.js',
1490
+            EE_THIRD_PARTY_URL.'jquery	.plugin.min.js',
1491 1491
             array('jquery'),
1492 1492
             '1.0.1',
1493 1493
             true
1494 1494
         );
1495 1495
         wp_register_script(
1496 1496
             'jquery_countdown',
1497
-            EE_THIRD_PARTY_URL . 'jquery	.countdown.min.js',
1497
+            EE_THIRD_PARTY_URL.'jquery	.countdown.min.js',
1498 1498
             array('jquery_plugin'),
1499 1499
             '2.1.0',
1500 1500
             true
1501 1501
         );
1502 1502
         wp_register_script(
1503 1503
             'single_page_checkout',
1504
-            SPCO_JS_URL . 'single_page_checkout.js',
1504
+            SPCO_JS_URL.'single_page_checkout.js',
1505 1505
             array('espresso_core', 'underscore', 'ee_form_section_validation'),
1506 1506
             EVENT_ESPRESSO_VERSION,
1507 1507
             true
@@ -1527,7 +1527,7 @@  discard block
 block discarded – undo
1527 1527
          *      AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information
1528 1528
          */
1529 1529
         do_action(
1530
-            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(),
1530
+            'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__'.$this->checkout->current_step->slug(),
1531 1531
             $this
1532 1532
         );
1533 1533
     }
@@ -1579,7 +1579,7 @@  discard block
 block discarded – undo
1579 1579
                     'layout_strategy' =>
1580 1580
                         new EE_Template_Layout(
1581 1581
                             array(
1582
-                                'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php',
1582
+                                'layout_template_file' => SPCO_TEMPLATES_PATH.'registration_page_wrapper.template.php',
1583 1583
                                 'template_args'        => array(
1584 1584
                                     'empty_cart'              => $empty_cart,
1585 1585
                                     'revisit'                 => $this->checkout->revisit,
@@ -1649,7 +1649,7 @@  discard block
 block discarded – undo
1649 1649
         )) {
1650 1650
             add_filter(
1651 1651
                 'FHEE__EEH_Template__powered_by_event_espresso__url',
1652
-                function ($url) {
1652
+                function($url) {
1653 1653
                     return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url);
1654 1654
                 }
1655 1655
             );
@@ -1805,7 +1805,7 @@  discard block
 block discarded – undo
1805 1805
             '</h4>',
1806 1806
             '<br />',
1807 1807
             '<p>',
1808
-            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="',
1808
+            '<a href="'.get_post_type_archive_link('espresso_events').'" title="',
1809 1809
             '">',
1810 1810
             '</a>',
1811 1811
             '</p>'
Please login to merge, or discard this patch.
core/EE_Cart.core.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
      * @access  public
261 261
      * @param EE_Ticket $ticket
262 262
      * @param int       $qty
263
-     * @return TRUE on success, FALSE on fail
263
+     * @return boolean on success, FALSE on fail
264 264
      * @throws \EE_Error
265 265
      */
266 266
     public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1)
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
      * @save   cart to session
386 386
      * @access public
387 387
      * @param bool $apply_taxes
388
-     * @return TRUE on success, FALSE on fail
388
+     * @return boolean on success, FALSE on fail
389 389
      * @throws \EE_Error
390 390
      */
391 391
     public function save_cart($apply_taxes = true)
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 
420 420
 
421 421
     /**
422
-     * @return array
422
+     * @return string[]
423 423
      */
424 424
     public function __sleep()
425 425
     {
Please login to merge, or discard this patch.
Indentation   +392 added lines, -392 removed lines patch added patch discarded remove patch
@@ -17,396 +17,396 @@
 block discarded – undo
17 17
 class EE_Cart implements ResettableInterface
18 18
 {
19 19
 
20
-    /**
21
-     * instance of the EE_Cart object
22
-     *
23
-     * @access    private
24
-     * @var EE_Cart $_instance
25
-     */
26
-    private static $_instance;
27
-
28
-    /**
29
-     * instance of the EE_Session object
30
-     *
31
-     * @access    protected
32
-     * @var EE_Session $_session
33
-     */
34
-    protected $_session;
35
-
36
-    /**
37
-     * The total Line item which comprises all the children line-item subtotals,
38
-     * which in turn each have their line items.
39
-     * Typically, the line item structure will look like:
40
-     * grand total
41
-     * -tickets-sub-total
42
-     * --ticket1
43
-     * --ticket2
44
-     * --...
45
-     * -taxes-sub-total
46
-     * --tax1
47
-     * --tax2
48
-     *
49
-     * @var EE_Line_Item
50
-     */
51
-    private $_grand_total;
52
-
53
-
54
-    /**
55
-     * @singleton method used to instantiate class object
56
-     * @access    public
57
-     * @param EE_Line_Item $grand_total
58
-     * @param EE_Session   $session
59
-     * @return \EE_Cart
60
-     * @throws \EE_Error
61
-     */
62
-    public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null)
63
-    {
64
-        if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) {
65
-            self::$_instance = new self($grand_total, $session);
66
-        }
67
-        // or maybe retrieve an existing one ?
68
-        if (! self::$_instance instanceof EE_Cart) {
69
-            // try getting the cart out of the session
70
-            $saved_cart = $session instanceof EE_Session ? $session->cart() : null;
71
-            self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
72
-            unset($saved_cart);
73
-        }
74
-        // verify that cart is ok and grand total line item exists
75
-        if (! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
76
-            self::$_instance = new self($grand_total, $session);
77
-        }
78
-        self::$_instance->get_grand_total();
79
-        // once everything is all said and done, save the cart to the EE_Session
80
-        add_action('shutdown', array(self::$_instance, 'save_cart'), 90);
81
-        return self::$_instance;
82
-    }
83
-
84
-
85
-    /**
86
-     * private constructor to prevent direct creation
87
-     *
88
-     * @Constructor
89
-     * @access private
90
-     * @param EE_Line_Item $grand_total
91
-     * @param EE_Session   $session
92
-     */
93
-    private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null)
94
-    {
95
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
96
-        $this->set_session($session);
97
-        if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) {
98
-            $this->set_grand_total_line_item($grand_total);
99
-        }
100
-    }
101
-
102
-
103
-    /**
104
-     * Resets the cart completely (whereas empty_cart
105
-     *
106
-     * @param EE_Line_Item $grand_total
107
-     * @param EE_Session   $session
108
-     * @return EE_Cart
109
-     * @throws \EE_Error
110
-     */
111
-    public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null)
112
-    {
113
-        remove_action('shutdown', array(self::$_instance, 'save_cart'), 90);
114
-        if ($session instanceof EE_Session) {
115
-            $session->reset_cart();
116
-        }
117
-        self::$_instance = null;
118
-        return self::instance($grand_total, $session);
119
-    }
120
-
121
-
122
-    /**
123
-     * @return \EE_Session
124
-     */
125
-    public function session()
126
-    {
127
-        if (! $this->_session instanceof EE_Session) {
128
-            $this->set_session();
129
-        }
130
-        return $this->_session;
131
-    }
132
-
133
-
134
-    /**
135
-     * @param EE_Session $session
136
-     */
137
-    public function set_session(EE_Session $session = null)
138
-    {
139
-        $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session');
140
-    }
141
-
142
-
143
-    /**
144
-     * Sets the cart to match the line item. Especially handy for loading an old cart where you
145
-     *  know the grand total line item on it
146
-     *
147
-     * @param EE_Line_Item $line_item
148
-     */
149
-    public function set_grand_total_line_item(EE_Line_Item $line_item)
150
-    {
151
-        $this->_grand_total = $line_item;
152
-    }
153
-
154
-
155
-    /**
156
-     * get_cart_from_reg_url_link
157
-     *
158
-     * @access public
159
-     * @param EE_Transaction $transaction
160
-     * @param EE_Session     $session
161
-     * @return \EE_Cart
162
-     * @throws \EE_Error
163
-     */
164
-    public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null)
165
-    {
166
-        $grand_total = $transaction->total_line_item();
167
-        $grand_total->get_items();
168
-        $grand_total->tax_descendants();
169
-        return EE_Cart::instance($grand_total, $session);
170
-    }
171
-
172
-
173
-    /**
174
-     * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items
175
-     *
176
-     * @return EE_Line_Item
177
-     * @throws \EE_Error
178
-     */
179
-    private function _create_grand_total()
180
-    {
181
-        $this->_grand_total = EEH_Line_Item::create_total_line_item();
182
-        return $this->_grand_total;
183
-    }
184
-
185
-
186
-    /**
187
-     * Gets all the line items of object type Ticket
188
-     *
189
-     * @access public
190
-     * @return \EE_Line_Item[]
191
-     */
192
-    public function get_tickets()
193
-    {
194
-        if ($this->_grand_total === null) {
195
-            return array();
196
-        }
197
-        return EEH_Line_Item::get_ticket_line_items($this->_grand_total);
198
-    }
199
-
200
-
201
-    /**
202
-     * returns the total quantity of tickets in the cart
203
-     *
204
-     * @access public
205
-     * @return int
206
-     * @throws \EE_Error
207
-     */
208
-    public function all_ticket_quantity_count()
209
-    {
210
-        $tickets = $this->get_tickets();
211
-        if (empty($tickets)) {
212
-            return 0;
213
-        }
214
-        $count = 0;
215
-        foreach ($tickets as $ticket) {
216
-            $count += $ticket->get('LIN_quantity');
217
-        }
218
-        return $count;
219
-    }
220
-
221
-
222
-    /**
223
-     * Gets all the tax line items
224
-     *
225
-     * @return \EE_Line_Item[]
226
-     * @throws \EE_Error
227
-     */
228
-    public function get_taxes()
229
-    {
230
-        return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children();
231
-    }
232
-
233
-
234
-    /**
235
-     * Gets the total line item (which is a parent of all other line items) on this cart
236
-     *
237
-     * @return EE_Line_Item
238
-     * @throws \EE_Error
239
-     */
240
-    public function get_grand_total()
241
-    {
242
-        return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total();
243
-    }
244
-
245
-
246
-    /**
247
-     * @process items for adding to cart
248
-     * @access  public
249
-     * @param EE_Ticket $ticket
250
-     * @param int       $qty
251
-     * @return TRUE on success, FALSE on fail
252
-     * @throws \EE_Error
253
-     */
254
-    public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1)
255
-    {
256
-        EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty);
257
-        return $this->save_cart() ? true : false;
258
-    }
259
-
260
-
261
-    /**
262
-     * get_cart_total_before_tax
263
-     *
264
-     * @access public
265
-     * @return float
266
-     * @throws \EE_Error
267
-     */
268
-    public function get_cart_total_before_tax()
269
-    {
270
-        return $this->get_grand_total()->recalculate_pre_tax_total();
271
-    }
272
-
273
-
274
-    /**
275
-     * gets the total amount of tax paid for items in this cart
276
-     *
277
-     * @access public
278
-     * @return float
279
-     * @throws \EE_Error
280
-     */
281
-    public function get_applied_taxes()
282
-    {
283
-        return EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
284
-    }
285
-
286
-
287
-    /**
288
-     * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
289
-     *
290
-     * @access public
291
-     * @return float
292
-     * @throws \EE_Error
293
-     */
294
-    public function get_cart_grand_total()
295
-    {
296
-        EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
297
-        return $this->get_grand_total()->total();
298
-    }
299
-
300
-
301
-    /**
302
-     * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
303
-     *
304
-     * @access public
305
-     * @return float
306
-     * @throws \EE_Error
307
-     */
308
-    public function recalculate_all_cart_totals()
309
-    {
310
-        $pre_tax_total = $this->get_cart_total_before_tax();
311
-        $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
312
-        $this->_grand_total->set_total($pre_tax_total + $taxes_total);
313
-        $this->_grand_total->save_this_and_descendants_to_txn();
314
-        return $this->get_grand_total()->total();
315
-    }
316
-
317
-
318
-    /**
319
-     * deletes an item from the cart
320
-     *
321
-     * @access public
322
-     * @param array|bool|string $line_item_codes
323
-     * @return int on success, FALSE on fail
324
-     * @throws \EE_Error
325
-     */
326
-    public function delete_items($line_item_codes = false)
327
-    {
328
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
329
-        return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes);
330
-    }
331
-
332
-
333
-    /**
334
-     * @remove ALL items from cart and zero ALL totals
335
-     * @access public
336
-     * @return bool
337
-     * @throws \EE_Error
338
-     */
339
-    public function empty_cart()
340
-    {
341
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
342
-        $this->_grand_total = $this->_create_grand_total();
343
-        return $this->save_cart(true);
344
-    }
345
-
346
-
347
-    /**
348
-     * @remove ALL items from cart and delete total as well
349
-     * @access public
350
-     * @return bool
351
-     * @throws \EE_Error
352
-     */
353
-    public function delete_cart()
354
-    {
355
-        if ($this->_grand_total instanceof EE_Line_Item) {
356
-            $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total);
357
-            if ($deleted) {
358
-                $deleted += $this->_grand_total->delete();
359
-                $this->_grand_total = null;
360
-                return true;
361
-            }
362
-        }
363
-        return false;
364
-    }
365
-
366
-
367
-    /**
368
-     * @save   cart to session
369
-     * @access public
370
-     * @param bool $apply_taxes
371
-     * @return TRUE on success, FALSE on fail
372
-     * @throws \EE_Error
373
-     */
374
-    public function save_cart($apply_taxes = true)
375
-    {
376
-        if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) {
377
-            EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
378
-            // make sure we don't cache the transaction because it can get stale
379
-            if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction
380
-                && $this->_grand_total->get_one_from_cache('Transaction')->ID()
381
-            ) {
382
-                $this->_grand_total->clear_cache('Transaction', null, true);
383
-            }
384
-        }
385
-        if ($this->session() instanceof EE_Session) {
386
-            return $this->session()->set_cart($this);
387
-        } else {
388
-            return false;
389
-        }
390
-    }
391
-
392
-
393
-    public function __wakeup()
394
-    {
395
-        if (! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
396
-            // $this->_grand_total is actually just an ID, so use it to get the object from the db
397
-            $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
398
-        }
399
-    }
400
-
401
-
402
-    /**
403
-     * @return array
404
-     */
405
-    public function __sleep()
406
-    {
407
-        if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) {
408
-            $this->_grand_total = $this->_grand_total->ID();
409
-        }
410
-        return array('_grand_total');
411
-    }
20
+	/**
21
+	 * instance of the EE_Cart object
22
+	 *
23
+	 * @access    private
24
+	 * @var EE_Cart $_instance
25
+	 */
26
+	private static $_instance;
27
+
28
+	/**
29
+	 * instance of the EE_Session object
30
+	 *
31
+	 * @access    protected
32
+	 * @var EE_Session $_session
33
+	 */
34
+	protected $_session;
35
+
36
+	/**
37
+	 * The total Line item which comprises all the children line-item subtotals,
38
+	 * which in turn each have their line items.
39
+	 * Typically, the line item structure will look like:
40
+	 * grand total
41
+	 * -tickets-sub-total
42
+	 * --ticket1
43
+	 * --ticket2
44
+	 * --...
45
+	 * -taxes-sub-total
46
+	 * --tax1
47
+	 * --tax2
48
+	 *
49
+	 * @var EE_Line_Item
50
+	 */
51
+	private $_grand_total;
52
+
53
+
54
+	/**
55
+	 * @singleton method used to instantiate class object
56
+	 * @access    public
57
+	 * @param EE_Line_Item $grand_total
58
+	 * @param EE_Session   $session
59
+	 * @return \EE_Cart
60
+	 * @throws \EE_Error
61
+	 */
62
+	public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null)
63
+	{
64
+		if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) {
65
+			self::$_instance = new self($grand_total, $session);
66
+		}
67
+		// or maybe retrieve an existing one ?
68
+		if (! self::$_instance instanceof EE_Cart) {
69
+			// try getting the cart out of the session
70
+			$saved_cart = $session instanceof EE_Session ? $session->cart() : null;
71
+			self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
72
+			unset($saved_cart);
73
+		}
74
+		// verify that cart is ok and grand total line item exists
75
+		if (! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
76
+			self::$_instance = new self($grand_total, $session);
77
+		}
78
+		self::$_instance->get_grand_total();
79
+		// once everything is all said and done, save the cart to the EE_Session
80
+		add_action('shutdown', array(self::$_instance, 'save_cart'), 90);
81
+		return self::$_instance;
82
+	}
83
+
84
+
85
+	/**
86
+	 * private constructor to prevent direct creation
87
+	 *
88
+	 * @Constructor
89
+	 * @access private
90
+	 * @param EE_Line_Item $grand_total
91
+	 * @param EE_Session   $session
92
+	 */
93
+	private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null)
94
+	{
95
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
96
+		$this->set_session($session);
97
+		if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) {
98
+			$this->set_grand_total_line_item($grand_total);
99
+		}
100
+	}
101
+
102
+
103
+	/**
104
+	 * Resets the cart completely (whereas empty_cart
105
+	 *
106
+	 * @param EE_Line_Item $grand_total
107
+	 * @param EE_Session   $session
108
+	 * @return EE_Cart
109
+	 * @throws \EE_Error
110
+	 */
111
+	public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null)
112
+	{
113
+		remove_action('shutdown', array(self::$_instance, 'save_cart'), 90);
114
+		if ($session instanceof EE_Session) {
115
+			$session->reset_cart();
116
+		}
117
+		self::$_instance = null;
118
+		return self::instance($grand_total, $session);
119
+	}
120
+
121
+
122
+	/**
123
+	 * @return \EE_Session
124
+	 */
125
+	public function session()
126
+	{
127
+		if (! $this->_session instanceof EE_Session) {
128
+			$this->set_session();
129
+		}
130
+		return $this->_session;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @param EE_Session $session
136
+	 */
137
+	public function set_session(EE_Session $session = null)
138
+	{
139
+		$this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session');
140
+	}
141
+
142
+
143
+	/**
144
+	 * Sets the cart to match the line item. Especially handy for loading an old cart where you
145
+	 *  know the grand total line item on it
146
+	 *
147
+	 * @param EE_Line_Item $line_item
148
+	 */
149
+	public function set_grand_total_line_item(EE_Line_Item $line_item)
150
+	{
151
+		$this->_grand_total = $line_item;
152
+	}
153
+
154
+
155
+	/**
156
+	 * get_cart_from_reg_url_link
157
+	 *
158
+	 * @access public
159
+	 * @param EE_Transaction $transaction
160
+	 * @param EE_Session     $session
161
+	 * @return \EE_Cart
162
+	 * @throws \EE_Error
163
+	 */
164
+	public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null)
165
+	{
166
+		$grand_total = $transaction->total_line_item();
167
+		$grand_total->get_items();
168
+		$grand_total->tax_descendants();
169
+		return EE_Cart::instance($grand_total, $session);
170
+	}
171
+
172
+
173
+	/**
174
+	 * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items
175
+	 *
176
+	 * @return EE_Line_Item
177
+	 * @throws \EE_Error
178
+	 */
179
+	private function _create_grand_total()
180
+	{
181
+		$this->_grand_total = EEH_Line_Item::create_total_line_item();
182
+		return $this->_grand_total;
183
+	}
184
+
185
+
186
+	/**
187
+	 * Gets all the line items of object type Ticket
188
+	 *
189
+	 * @access public
190
+	 * @return \EE_Line_Item[]
191
+	 */
192
+	public function get_tickets()
193
+	{
194
+		if ($this->_grand_total === null) {
195
+			return array();
196
+		}
197
+		return EEH_Line_Item::get_ticket_line_items($this->_grand_total);
198
+	}
199
+
200
+
201
+	/**
202
+	 * returns the total quantity of tickets in the cart
203
+	 *
204
+	 * @access public
205
+	 * @return int
206
+	 * @throws \EE_Error
207
+	 */
208
+	public function all_ticket_quantity_count()
209
+	{
210
+		$tickets = $this->get_tickets();
211
+		if (empty($tickets)) {
212
+			return 0;
213
+		}
214
+		$count = 0;
215
+		foreach ($tickets as $ticket) {
216
+			$count += $ticket->get('LIN_quantity');
217
+		}
218
+		return $count;
219
+	}
220
+
221
+
222
+	/**
223
+	 * Gets all the tax line items
224
+	 *
225
+	 * @return \EE_Line_Item[]
226
+	 * @throws \EE_Error
227
+	 */
228
+	public function get_taxes()
229
+	{
230
+		return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children();
231
+	}
232
+
233
+
234
+	/**
235
+	 * Gets the total line item (which is a parent of all other line items) on this cart
236
+	 *
237
+	 * @return EE_Line_Item
238
+	 * @throws \EE_Error
239
+	 */
240
+	public function get_grand_total()
241
+	{
242
+		return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total();
243
+	}
244
+
245
+
246
+	/**
247
+	 * @process items for adding to cart
248
+	 * @access  public
249
+	 * @param EE_Ticket $ticket
250
+	 * @param int       $qty
251
+	 * @return TRUE on success, FALSE on fail
252
+	 * @throws \EE_Error
253
+	 */
254
+	public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1)
255
+	{
256
+		EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty);
257
+		return $this->save_cart() ? true : false;
258
+	}
259
+
260
+
261
+	/**
262
+	 * get_cart_total_before_tax
263
+	 *
264
+	 * @access public
265
+	 * @return float
266
+	 * @throws \EE_Error
267
+	 */
268
+	public function get_cart_total_before_tax()
269
+	{
270
+		return $this->get_grand_total()->recalculate_pre_tax_total();
271
+	}
272
+
273
+
274
+	/**
275
+	 * gets the total amount of tax paid for items in this cart
276
+	 *
277
+	 * @access public
278
+	 * @return float
279
+	 * @throws \EE_Error
280
+	 */
281
+	public function get_applied_taxes()
282
+	{
283
+		return EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
284
+	}
285
+
286
+
287
+	/**
288
+	 * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
289
+	 *
290
+	 * @access public
291
+	 * @return float
292
+	 * @throws \EE_Error
293
+	 */
294
+	public function get_cart_grand_total()
295
+	{
296
+		EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
297
+		return $this->get_grand_total()->total();
298
+	}
299
+
300
+
301
+	/**
302
+	 * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
303
+	 *
304
+	 * @access public
305
+	 * @return float
306
+	 * @throws \EE_Error
307
+	 */
308
+	public function recalculate_all_cart_totals()
309
+	{
310
+		$pre_tax_total = $this->get_cart_total_before_tax();
311
+		$taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
312
+		$this->_grand_total->set_total($pre_tax_total + $taxes_total);
313
+		$this->_grand_total->save_this_and_descendants_to_txn();
314
+		return $this->get_grand_total()->total();
315
+	}
316
+
317
+
318
+	/**
319
+	 * deletes an item from the cart
320
+	 *
321
+	 * @access public
322
+	 * @param array|bool|string $line_item_codes
323
+	 * @return int on success, FALSE on fail
324
+	 * @throws \EE_Error
325
+	 */
326
+	public function delete_items($line_item_codes = false)
327
+	{
328
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
329
+		return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes);
330
+	}
331
+
332
+
333
+	/**
334
+	 * @remove ALL items from cart and zero ALL totals
335
+	 * @access public
336
+	 * @return bool
337
+	 * @throws \EE_Error
338
+	 */
339
+	public function empty_cart()
340
+	{
341
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
342
+		$this->_grand_total = $this->_create_grand_total();
343
+		return $this->save_cart(true);
344
+	}
345
+
346
+
347
+	/**
348
+	 * @remove ALL items from cart and delete total as well
349
+	 * @access public
350
+	 * @return bool
351
+	 * @throws \EE_Error
352
+	 */
353
+	public function delete_cart()
354
+	{
355
+		if ($this->_grand_total instanceof EE_Line_Item) {
356
+			$deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total);
357
+			if ($deleted) {
358
+				$deleted += $this->_grand_total->delete();
359
+				$this->_grand_total = null;
360
+				return true;
361
+			}
362
+		}
363
+		return false;
364
+	}
365
+
366
+
367
+	/**
368
+	 * @save   cart to session
369
+	 * @access public
370
+	 * @param bool $apply_taxes
371
+	 * @return TRUE on success, FALSE on fail
372
+	 * @throws \EE_Error
373
+	 */
374
+	public function save_cart($apply_taxes = true)
375
+	{
376
+		if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) {
377
+			EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
378
+			// make sure we don't cache the transaction because it can get stale
379
+			if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction
380
+				&& $this->_grand_total->get_one_from_cache('Transaction')->ID()
381
+			) {
382
+				$this->_grand_total->clear_cache('Transaction', null, true);
383
+			}
384
+		}
385
+		if ($this->session() instanceof EE_Session) {
386
+			return $this->session()->set_cart($this);
387
+		} else {
388
+			return false;
389
+		}
390
+	}
391
+
392
+
393
+	public function __wakeup()
394
+	{
395
+		if (! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
396
+			// $this->_grand_total is actually just an ID, so use it to get the object from the db
397
+			$this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
398
+		}
399
+	}
400
+
401
+
402
+	/**
403
+	 * @return array
404
+	 */
405
+	public function __sleep()
406
+	{
407
+		if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) {
408
+			$this->_grand_total = $this->_grand_total->ID();
409
+		}
410
+		return array('_grand_total');
411
+	}
412 412
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -65,14 +65,14 @@  discard block
 block discarded – undo
65 65
             self::$_instance = new self($grand_total, $session);
66 66
         }
67 67
         // or maybe retrieve an existing one ?
68
-        if (! self::$_instance instanceof EE_Cart) {
68
+        if ( ! self::$_instance instanceof EE_Cart) {
69 69
             // try getting the cart out of the session
70 70
             $saved_cart = $session instanceof EE_Session ? $session->cart() : null;
71 71
             self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
72 72
             unset($saved_cart);
73 73
         }
74 74
         // verify that cart is ok and grand total line item exists
75
-        if (! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
75
+        if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
76 76
             self::$_instance = new self($grand_total, $session);
77 77
         }
78 78
         self::$_instance->get_grand_total();
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
      */
125 125
     public function session()
126 126
     {
127
-        if (! $this->_session instanceof EE_Session) {
127
+        if ( ! $this->_session instanceof EE_Session) {
128 128
             $this->set_session();
129 129
         }
130 130
         return $this->_session;
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 
393 393
     public function __wakeup()
394 394
     {
395
-        if (! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
395
+        if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
396 396
             // $this->_grand_total is actually just an ID, so use it to get the object from the db
397 397
             $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
398 398
         }
Please login to merge, or discard this patch.
core/helpers/EEH_Activation.helper.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
      *
614 614
      * @since  4.6.0
615 615
      * @global WPDB $wpdb
616
-     * @return mixed null|int WP_user ID or NULL
616
+     * @return integer|null null|int WP_user ID or NULL
617 617
      */
618 618
     public static function get_default_creator_id()
619 619
     {
@@ -774,7 +774,7 @@  discard block
 block discarded – undo
774 774
      * @static
775 775
      * @deprecated instead use TableManager::dropTable()
776 776
      * @param string $table_name
777
-     * @return bool | int
777
+     * @return integer | int
778 778
      */
779 779
     public static function delete_unused_db_table($table_name)
780 780
     {
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
      * @deprecated instead use TableManager::dropIndex()
792 792
      * @param string $table_name
793 793
      * @param string $index_name
794
-     * @return bool | int
794
+     * @return integer | int
795 795
      */
796 796
     public static function drop_index($table_name, $index_name)
797 797
     {
Please login to merge, or discard this patch.
Indentation   +1576 added lines, -1576 removed lines patch added patch discarded remove patch
@@ -15,232 +15,232 @@  discard block
 block discarded – undo
15 15
 class EEH_Activation implements ResettableInterface
16 16
 {
17 17
 
18
-    /**
19
-     * constant used to indicate a cron task is no longer in use
20
-     */
21
-    const cron_task_no_longer_in_use = 'no_longer_in_use';
22
-
23
-    /**
24
-     * WP_User->ID
25
-     *
26
-     * @var int
27
-     */
28
-    private static $_default_creator_id;
29
-
30
-    /**
31
-     * indicates whether or not we've already verified core's default data during this request,
32
-     * because after migrations are done, any addons activated while in maintenance mode
33
-     * will want to setup their own default data, and they might hook into core's default data
34
-     * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
35
-     * This prevents doing that for EVERY single addon.
36
-     *
37
-     * @var boolean
38
-     */
39
-    protected static $_initialized_db_content_already_in_this_request = false;
40
-
41
-    /**
42
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
43
-     */
44
-    private static $table_analysis;
45
-
46
-    /**
47
-     * @var \EventEspresso\core\services\database\TableManager $table_manager
48
-     */
49
-    private static $table_manager;
50
-
51
-
52
-    /**
53
-     * @return \EventEspresso\core\services\database\TableAnalysis
54
-     */
55
-    public static function getTableAnalysis()
56
-    {
57
-        if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
58
-            self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
59
-        }
60
-        return self::$table_analysis;
61
-    }
62
-
63
-
64
-    /**
65
-     * @return \EventEspresso\core\services\database\TableManager
66
-     */
67
-    public static function getTableManager()
68
-    {
69
-        if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
70
-            self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
71
-        }
72
-        return self::$table_manager;
73
-    }
74
-
75
-
76
-    /**
77
-     *    _ensure_table_name_has_prefix
78
-     *
79
-     * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
80
-     * @access     public
81
-     * @static
82
-     * @param $table_name
83
-     * @return string
84
-     */
85
-    public static function ensure_table_name_has_prefix($table_name)
86
-    {
87
-        return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
88
-    }
89
-
90
-
91
-    /**
92
-     *    system_initialization
93
-     *    ensures the EE configuration settings are loaded with at least default options set
94
-     *    and that all critical EE pages have been generated with the appropriate shortcodes in place
95
-     *
96
-     * @access public
97
-     * @static
98
-     * @return void
99
-     */
100
-    public static function system_initialization()
101
-    {
102
-        EEH_Activation::reset_and_update_config();
103
-        // which is fired BEFORE activation of plugin anyways
104
-        EEH_Activation::verify_default_pages_exist();
105
-    }
106
-
107
-
108
-    /**
109
-     * Sets the database schema and creates folders. This should
110
-     * be called on plugin activation and reactivation
111
-     *
112
-     * @return boolean success, whether the database and folders are setup properly
113
-     * @throws \EE_Error
114
-     */
115
-    public static function initialize_db_and_folders()
116
-    {
117
-        return EEH_Activation::create_database_tables();
118
-    }
119
-
120
-
121
-    /**
122
-     * assuming we have an up-to-date database schema, this will populate it
123
-     * with default and initial data. This should be called
124
-     * upon activation of a new plugin, reactivation, and at the end
125
-     * of running migration scripts
126
-     *
127
-     * @throws \EE_Error
128
-     */
129
-    public static function initialize_db_content()
130
-    {
131
-        // let's avoid doing all this logic repeatedly, especially when addons are requesting it
132
-        if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
133
-            return;
134
-        }
135
-        EEH_Activation::$_initialized_db_content_already_in_this_request = true;
136
-
137
-        EEH_Activation::initialize_system_questions();
138
-        EEH_Activation::insert_default_status_codes();
139
-        EEH_Activation::generate_default_message_templates();
140
-        EEH_Activation::create_no_ticket_prices_array();
141
-
142
-        EEH_Activation::validate_messages_system();
143
-        EEH_Activation::insert_default_payment_methods();
144
-        // in case we've
145
-        EEH_Activation::remove_cron_tasks();
146
-        EEH_Activation::create_cron_tasks();
147
-        // remove all TXN locks since that is being done via extra meta now
148
-        delete_option('ee_locked_transactions');
149
-        // also, check for CAF default db content
150
-        do_action('AHEE__EEH_Activation__initialize_db_content');
151
-        // also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
152
-        // which users really won't care about on initial activation
153
-        EE_Error::overwrite_success();
154
-    }
155
-
156
-
157
-    /**
158
-     * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
159
-     * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
160
-     * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
161
-     * (null)
162
-     *
163
-     * @param string $which_to_include can be 'current' (ones that are currently in use),
164
-     *                                 'old' (only returns ones that should no longer be used),or 'all',
165
-     * @return array
166
-     * @throws \EE_Error
167
-     */
168
-    public static function get_cron_tasks($which_to_include)
169
-    {
170
-        $cron_tasks = apply_filters(
171
-            'FHEE__EEH_Activation__get_cron_tasks',
172
-            array(
173
-                'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
174
-            //              'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use
175
-                'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
176
-                // there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
177
-                'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
178
-            )
179
-        );
180
-        if ($which_to_include === 'old') {
181
-            $cron_tasks = array_filter(
182
-                $cron_tasks,
183
-                function ($value) {
184
-                    return $value === EEH_Activation::cron_task_no_longer_in_use;
185
-                }
186
-            );
187
-        } elseif ($which_to_include === 'current') {
188
-            $cron_tasks = array_filter($cron_tasks);
189
-        } elseif (WP_DEBUG && $which_to_include !== 'all') {
190
-            throw new EE_Error(
191
-                sprintf(
192
-                    __(
193
-                        'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
194
-                        'event_espresso'
195
-                    ),
196
-                    $which_to_include
197
-                )
198
-            );
199
-        }
200
-        return $cron_tasks;
201
-    }
202
-
203
-
204
-    /**
205
-     * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
206
-     *
207
-     * @throws \EE_Error
208
-     */
209
-    public static function create_cron_tasks()
210
-    {
211
-
212
-        foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
213
-            if (! wp_next_scheduled($hook_name)) {
214
-                /**
215
-                 * This allows client code to define the initial start timestamp for this schedule.
216
-                 */
217
-                if (is_array($frequency)
218
-                    && count($frequency) === 2
219
-                    && isset($frequency[0], $frequency[1])
220
-                ) {
221
-                    $start_timestamp = $frequency[0];
222
-                    $frequency = $frequency[1];
223
-                } else {
224
-                    $start_timestamp = time();
225
-                }
226
-                wp_schedule_event($start_timestamp, $frequency, $hook_name);
227
-            }
228
-        }
229
-    }
230
-
231
-
232
-    /**
233
-     * Remove the currently-existing and now-removed cron tasks.
234
-     *
235
-     * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
236
-     * @throws \EE_Error
237
-     */
238
-    public static function remove_cron_tasks($remove_all = true)
239
-    {
240
-        $cron_tasks_to_remove = $remove_all ? 'all' : 'old';
241
-        $crons                = _get_cron_array();
242
-        $crons                = is_array($crons) ? $crons : array();
243
-        /* reminder of what $crons look like:
18
+	/**
19
+	 * constant used to indicate a cron task is no longer in use
20
+	 */
21
+	const cron_task_no_longer_in_use = 'no_longer_in_use';
22
+
23
+	/**
24
+	 * WP_User->ID
25
+	 *
26
+	 * @var int
27
+	 */
28
+	private static $_default_creator_id;
29
+
30
+	/**
31
+	 * indicates whether or not we've already verified core's default data during this request,
32
+	 * because after migrations are done, any addons activated while in maintenance mode
33
+	 * will want to setup their own default data, and they might hook into core's default data
34
+	 * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
35
+	 * This prevents doing that for EVERY single addon.
36
+	 *
37
+	 * @var boolean
38
+	 */
39
+	protected static $_initialized_db_content_already_in_this_request = false;
40
+
41
+	/**
42
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
43
+	 */
44
+	private static $table_analysis;
45
+
46
+	/**
47
+	 * @var \EventEspresso\core\services\database\TableManager $table_manager
48
+	 */
49
+	private static $table_manager;
50
+
51
+
52
+	/**
53
+	 * @return \EventEspresso\core\services\database\TableAnalysis
54
+	 */
55
+	public static function getTableAnalysis()
56
+	{
57
+		if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
58
+			self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
59
+		}
60
+		return self::$table_analysis;
61
+	}
62
+
63
+
64
+	/**
65
+	 * @return \EventEspresso\core\services\database\TableManager
66
+	 */
67
+	public static function getTableManager()
68
+	{
69
+		if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
70
+			self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
71
+		}
72
+		return self::$table_manager;
73
+	}
74
+
75
+
76
+	/**
77
+	 *    _ensure_table_name_has_prefix
78
+	 *
79
+	 * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
80
+	 * @access     public
81
+	 * @static
82
+	 * @param $table_name
83
+	 * @return string
84
+	 */
85
+	public static function ensure_table_name_has_prefix($table_name)
86
+	{
87
+		return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
88
+	}
89
+
90
+
91
+	/**
92
+	 *    system_initialization
93
+	 *    ensures the EE configuration settings are loaded with at least default options set
94
+	 *    and that all critical EE pages have been generated with the appropriate shortcodes in place
95
+	 *
96
+	 * @access public
97
+	 * @static
98
+	 * @return void
99
+	 */
100
+	public static function system_initialization()
101
+	{
102
+		EEH_Activation::reset_and_update_config();
103
+		// which is fired BEFORE activation of plugin anyways
104
+		EEH_Activation::verify_default_pages_exist();
105
+	}
106
+
107
+
108
+	/**
109
+	 * Sets the database schema and creates folders. This should
110
+	 * be called on plugin activation and reactivation
111
+	 *
112
+	 * @return boolean success, whether the database and folders are setup properly
113
+	 * @throws \EE_Error
114
+	 */
115
+	public static function initialize_db_and_folders()
116
+	{
117
+		return EEH_Activation::create_database_tables();
118
+	}
119
+
120
+
121
+	/**
122
+	 * assuming we have an up-to-date database schema, this will populate it
123
+	 * with default and initial data. This should be called
124
+	 * upon activation of a new plugin, reactivation, and at the end
125
+	 * of running migration scripts
126
+	 *
127
+	 * @throws \EE_Error
128
+	 */
129
+	public static function initialize_db_content()
130
+	{
131
+		// let's avoid doing all this logic repeatedly, especially when addons are requesting it
132
+		if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
133
+			return;
134
+		}
135
+		EEH_Activation::$_initialized_db_content_already_in_this_request = true;
136
+
137
+		EEH_Activation::initialize_system_questions();
138
+		EEH_Activation::insert_default_status_codes();
139
+		EEH_Activation::generate_default_message_templates();
140
+		EEH_Activation::create_no_ticket_prices_array();
141
+
142
+		EEH_Activation::validate_messages_system();
143
+		EEH_Activation::insert_default_payment_methods();
144
+		// in case we've
145
+		EEH_Activation::remove_cron_tasks();
146
+		EEH_Activation::create_cron_tasks();
147
+		// remove all TXN locks since that is being done via extra meta now
148
+		delete_option('ee_locked_transactions');
149
+		// also, check for CAF default db content
150
+		do_action('AHEE__EEH_Activation__initialize_db_content');
151
+		// also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
152
+		// which users really won't care about on initial activation
153
+		EE_Error::overwrite_success();
154
+	}
155
+
156
+
157
+	/**
158
+	 * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
159
+	 * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
160
+	 * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
161
+	 * (null)
162
+	 *
163
+	 * @param string $which_to_include can be 'current' (ones that are currently in use),
164
+	 *                                 'old' (only returns ones that should no longer be used),or 'all',
165
+	 * @return array
166
+	 * @throws \EE_Error
167
+	 */
168
+	public static function get_cron_tasks($which_to_include)
169
+	{
170
+		$cron_tasks = apply_filters(
171
+			'FHEE__EEH_Activation__get_cron_tasks',
172
+			array(
173
+				'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
174
+			//              'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use
175
+				'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
176
+				// there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
177
+				'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
178
+			)
179
+		);
180
+		if ($which_to_include === 'old') {
181
+			$cron_tasks = array_filter(
182
+				$cron_tasks,
183
+				function ($value) {
184
+					return $value === EEH_Activation::cron_task_no_longer_in_use;
185
+				}
186
+			);
187
+		} elseif ($which_to_include === 'current') {
188
+			$cron_tasks = array_filter($cron_tasks);
189
+		} elseif (WP_DEBUG && $which_to_include !== 'all') {
190
+			throw new EE_Error(
191
+				sprintf(
192
+					__(
193
+						'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
194
+						'event_espresso'
195
+					),
196
+					$which_to_include
197
+				)
198
+			);
199
+		}
200
+		return $cron_tasks;
201
+	}
202
+
203
+
204
+	/**
205
+	 * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
206
+	 *
207
+	 * @throws \EE_Error
208
+	 */
209
+	public static function create_cron_tasks()
210
+	{
211
+
212
+		foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
213
+			if (! wp_next_scheduled($hook_name)) {
214
+				/**
215
+				 * This allows client code to define the initial start timestamp for this schedule.
216
+				 */
217
+				if (is_array($frequency)
218
+					&& count($frequency) === 2
219
+					&& isset($frequency[0], $frequency[1])
220
+				) {
221
+					$start_timestamp = $frequency[0];
222
+					$frequency = $frequency[1];
223
+				} else {
224
+					$start_timestamp = time();
225
+				}
226
+				wp_schedule_event($start_timestamp, $frequency, $hook_name);
227
+			}
228
+		}
229
+	}
230
+
231
+
232
+	/**
233
+	 * Remove the currently-existing and now-removed cron tasks.
234
+	 *
235
+	 * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
236
+	 * @throws \EE_Error
237
+	 */
238
+	public static function remove_cron_tasks($remove_all = true)
239
+	{
240
+		$cron_tasks_to_remove = $remove_all ? 'all' : 'old';
241
+		$crons                = _get_cron_array();
242
+		$crons                = is_array($crons) ? $crons : array();
243
+		/* reminder of what $crons look like:
244 244
          * Top-level keys are timestamps, and their values are arrays.
245 245
          * The 2nd level arrays have keys with each of the cron task hook names to run at that time
246 246
          * and their values are arrays.
@@ -257,909 +257,909 @@  discard block
 block discarded – undo
257 257
          *                  ...
258 258
          *      ...
259 259
          */
260
-        $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
261
-        foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
262
-            if (is_array($hooks_to_fire_at_time)) {
263
-                foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
264
-                    if (isset($ee_cron_tasks_to_remove[ $hook_name ])
265
-                        && is_array($ee_cron_tasks_to_remove[ $hook_name ])
266
-                    ) {
267
-                        unset($crons[ $timestamp ][ $hook_name ]);
268
-                    }
269
-                }
270
-                // also take care of any empty cron timestamps.
271
-                if (empty($hooks_to_fire_at_time)) {
272
-                    unset($crons[ $timestamp ]);
273
-                }
274
-            }
275
-        }
276
-        _set_cron_array($crons);
277
-    }
278
-
279
-
280
-    /**
281
-     *    CPT_initialization
282
-     *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
283
-     *
284
-     * @access public
285
-     * @static
286
-     * @return void
287
-     */
288
-    public static function CPT_initialization()
289
-    {
290
-        // register Custom Post Types
291
-        EE_Registry::instance()->load_core('Register_CPTs');
292
-        flush_rewrite_rules();
293
-    }
294
-
295
-
296
-
297
-    /**
298
-     *    reset_and_update_config
299
-     * The following code was moved over from EE_Config so that it will no longer run on every request.
300
-     * If there is old calendar config data saved, then it will get converted on activation.
301
-     * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
302
-     *
303
-     * @access public
304
-     * @static
305
-     * @return void
306
-     */
307
-    public static function reset_and_update_config()
308
-    {
309
-        do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
310
-        add_filter(
311
-            'FHEE__EE_Config___load_core_config__config_settings',
312
-            array('EEH_Activation', 'migrate_old_config_data'),
313
-            10,
314
-            3
315
-        );
316
-        // EE_Config::reset();
317
-        if (! EE_Config::logging_enabled()) {
318
-            delete_option(EE_Config::LOG_NAME);
319
-        }
320
-    }
321
-
322
-
323
-    /**
324
-     *    load_calendar_config
325
-     *
326
-     * @access    public
327
-     * @return    void
328
-     */
329
-    public static function load_calendar_config()
330
-    {
331
-        // grab array of all plugin folders and loop thru it
332
-        $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
333
-        if (empty($plugins)) {
334
-            return;
335
-        }
336
-        foreach ($plugins as $plugin_path) {
337
-            // grab plugin folder name from path
338
-            $plugin = basename($plugin_path);
339
-            // drill down to Espresso plugins
340
-            // then to calendar related plugins
341
-            if (strpos($plugin, 'espresso') !== false
342
-                || strpos($plugin, 'Espresso') !== false
343
-                || strpos($plugin, 'ee4') !== false
344
-                || strpos($plugin, 'EE4') !== false
345
-                || strpos($plugin, 'calendar') !== false
346
-            ) {
347
-                // this is what we are looking for
348
-                $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
349
-                // does it exist in this folder ?
350
-                if (is_readable($calendar_config)) {
351
-                    // YEAH! let's load it
352
-                    require_once($calendar_config);
353
-                }
354
-            }
355
-        }
356
-    }
357
-
358
-
359
-
360
-    /**
361
-     *    _migrate_old_config_data
362
-     *
363
-     * @access    public
364
-     * @param array|stdClass $settings
365
-     * @param string         $config
366
-     * @param \EE_Config     $EE_Config
367
-     * @return \stdClass
368
-     */
369
-    public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
370
-    {
371
-        $convert_from_array = array('addons');
372
-        // in case old settings were saved as an array
373
-        if (is_array($settings) && in_array($config, $convert_from_array)) {
374
-            // convert existing settings to an object
375
-            $config_array = $settings;
376
-            $settings = new stdClass();
377
-            foreach ($config_array as $key => $value) {
378
-                if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
379
-                    $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
380
-                } else {
381
-                    $settings->{$key} = $value;
382
-                }
383
-            }
384
-            add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
385
-        }
386
-        return $settings;
387
-    }
388
-
389
-
390
-    /**
391
-     * deactivate_event_espresso
392
-     *
393
-     * @access public
394
-     * @static
395
-     * @return void
396
-     */
397
-    public static function deactivate_event_espresso()
398
-    {
399
-        // check permissions
400
-        if (current_user_can('activate_plugins')) {
401
-            deactivate_plugins(EE_PLUGIN_BASENAME, true);
402
-        }
403
-    }
404
-
405
-
406
-
407
-    /**
408
-     * verify_default_pages_exist
409
-     *
410
-     * @access public
411
-     * @static
412
-     * @return void
413
-     * @throws InvalidDataTypeException
414
-     */
415
-    public static function verify_default_pages_exist()
416
-    {
417
-        $critical_page_problem = false;
418
-        $critical_pages = array(
419
-            array(
420
-                'id'   => 'reg_page_id',
421
-                'name' => __('Registration Checkout', 'event_espresso'),
422
-                'post' => null,
423
-                'code' => 'ESPRESSO_CHECKOUT',
424
-            ),
425
-            array(
426
-                'id'   => 'txn_page_id',
427
-                'name' => __('Transactions', 'event_espresso'),
428
-                'post' => null,
429
-                'code' => 'ESPRESSO_TXN_PAGE',
430
-            ),
431
-            array(
432
-                'id'   => 'thank_you_page_id',
433
-                'name' => __('Thank You', 'event_espresso'),
434
-                'post' => null,
435
-                'code' => 'ESPRESSO_THANK_YOU',
436
-            ),
437
-            array(
438
-                'id'   => 'cancel_page_id',
439
-                'name' => __('Registration Cancelled', 'event_espresso'),
440
-                'post' => null,
441
-                'code' => 'ESPRESSO_CANCELLED',
442
-            ),
443
-        );
444
-        $EE_Core_Config = EE_Registry::instance()->CFG->core;
445
-        foreach ($critical_pages as $critical_page) {
446
-            // is critical page ID set in config ?
447
-            if ($EE_Core_Config->{$critical_page['id']} !== false) {
448
-                // attempt to find post by ID
449
-                $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
450
-            }
451
-            // no dice?
452
-            if ($critical_page['post'] === null) {
453
-                // attempt to find post by title
454
-                $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
455
-                // still nothing?
456
-                if ($critical_page['post'] === null) {
457
-                    $critical_page = EEH_Activation::create_critical_page($critical_page);
458
-                    // REALLY? Still nothing ??!?!?
459
-                    if ($critical_page['post'] === null) {
460
-                        $msg = __(
461
-                            'The Event Espresso critical page configuration settings could not be updated.',
462
-                            'event_espresso'
463
-                        );
464
-                        EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
465
-                        break;
466
-                    }
467
-                }
468
-            }
469
-            // check that Post ID matches critical page ID in config
470
-            if (isset($critical_page['post']->ID)
471
-                && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
472
-            ) {
473
-                // update Config with post ID
474
-                $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
475
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
476
-                    $msg = __(
477
-                        'The Event Espresso critical page configuration settings could not be updated.',
478
-                        'event_espresso'
479
-                    );
480
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
481
-                }
482
-            }
483
-            $critical_page_problem =
484
-                ! isset($critical_page['post']->post_status)
485
-                || $critical_page['post']->post_status !== 'publish'
486
-                || strpos($critical_page['post']->post_content, $critical_page['code']) === false
487
-                    ? true
488
-                    : $critical_page_problem;
489
-        }
490
-        if ($critical_page_problem) {
491
-            new PersistentAdminNotice(
492
-                'critical_page_problem',
493
-                sprintf(
494
-                    esc_html__(
495
-                        'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
496
-                        'event_espresso'
497
-                    ),
498
-                    '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
499
-                    . __('Event Espresso Critical Pages Settings', 'event_espresso')
500
-                    . '</a>'
501
-                )
502
-            );
503
-        }
504
-        if (EE_Error::has_notices()) {
505
-            EE_Error::get_notices(false, true, true);
506
-        }
507
-    }
508
-
509
-
510
-
511
-    /**
512
-     * Returns the first post which uses the specified shortcode
513
-     *
514
-     * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
515
-     *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
516
-     *                             "[ESPRESSO_THANK_YOU"
517
-     *                             (we don't search for the closing shortcode bracket because they might have added
518
-     *                             parameter to the shortcode
519
-     * @return WP_Post or NULl
520
-     */
521
-    public static function get_page_by_ee_shortcode($ee_shortcode)
522
-    {
523
-        global $wpdb;
524
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
525
-        $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
526
-        if ($post_id) {
527
-            return get_post($post_id);
528
-        } else {
529
-            return null;
530
-        }
531
-    }
532
-
533
-
534
-    /**
535
-     *    This function generates a post for critical espresso pages
536
-     *
537
-     * @access public
538
-     * @static
539
-     * @param array $critical_page
540
-     * @return array
541
-     */
542
-    public static function create_critical_page($critical_page)
543
-    {
544
-
545
-        $post_args = array(
546
-            'post_title'     => $critical_page['name'],
547
-            'post_status'    => 'publish',
548
-            'post_type'      => 'page',
549
-            'comment_status' => 'closed',
550
-            'post_content'   => '[' . $critical_page['code'] . ']',
551
-        );
552
-
553
-        $post_id = wp_insert_post($post_args);
554
-        if (! $post_id) {
555
-            $msg = sprintf(
556
-                __('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
557
-                $critical_page['name']
558
-            );
559
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
560
-            return $critical_page;
561
-        }
562
-        // get newly created post's details
563
-        if (! $critical_page['post'] = get_post($post_id)) {
564
-            $msg = sprintf(
565
-                __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
566
-                $critical_page['name']
567
-            );
568
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
569
-        }
570
-
571
-        return $critical_page;
572
-    }
573
-
574
-
575
-
576
-
577
-    /**
578
-     * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
579
-     * The role being used to check is filterable.
580
-     *
581
-     * @since  4.6.0
582
-     * @global WPDB $wpdb
583
-     * @return mixed null|int WP_user ID or NULL
584
-     */
585
-    public static function get_default_creator_id()
586
-    {
587
-        global $wpdb;
588
-        if (! empty(self::$_default_creator_id)) {
589
-            return self::$_default_creator_id;
590
-        }/**/
591
-        $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
592
-        // let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
593
-        $pre_filtered_id = apply_filters(
594
-            'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
595
-            false,
596
-            $role_to_check
597
-        );
598
-        if ($pre_filtered_id !== false) {
599
-            return (int) $pre_filtered_id;
600
-        }
601
-        $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
602
-        $query = $wpdb->prepare(
603
-            "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
604
-            '%' . $role_to_check . '%'
605
-        );
606
-        $user_id = $wpdb->get_var($query);
607
-        $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
608
-        if ($user_id && (int) $user_id) {
609
-            self::$_default_creator_id = (int) $user_id;
610
-            return self::$_default_creator_id;
611
-        } else {
612
-            return null;
613
-        }
614
-    }
615
-
616
-
617
-
618
-    /**
619
-     * used by EE and EE addons during plugin activation to create tables.
620
-     * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
621
-     * but includes extra logic regarding activations.
622
-     *
623
-     * @access public
624
-     * @static
625
-     * @param string  $table_name              without the $wpdb->prefix
626
-     * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
627
-     *                                         table query)
628
-     * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
629
-     * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
630
-     *                                         and new once this function is done (ie, you really do want to CREATE a
631
-     *                                         table, and expect it to be empty once you're done) leave as FALSE when
632
-     *                                         you just want to verify the table exists and matches this definition
633
-     *                                         (and if it HAS data in it you want to leave it be)
634
-     * @return void
635
-     * @throws EE_Error if there are database errors
636
-     */
637
-    public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
638
-    {
639
-        if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
640
-            return;
641
-        }
642
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
643
-        if (! function_exists('dbDelta')) {
644
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
645
-        }
646
-        $tableAnalysis = \EEH_Activation::getTableAnalysis();
647
-        $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
648
-        // do we need to first delete an existing version of this table ?
649
-        if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
650
-            // ok, delete the table... but ONLY if it's empty
651
-            $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
652
-            // table is NOT empty, are you SURE you want to delete this table ???
653
-            if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
654
-                \EEH_Activation::getTableManager()->dropTable($wp_table_name);
655
-            } elseif (! $deleted_safely) {
656
-                // so we should be more cautious rather than just dropping tables so easily
657
-                error_log(
658
-                    sprintf(
659
-                        __(
660
-                            'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
661
-                            'event_espresso'
662
-                        ),
663
-                        $wp_table_name,
664
-                        '<br/>',
665
-                        'espresso_db_update'
666
-                    )
667
-                );
668
-            }
669
-        }
670
-        $engine = str_replace('ENGINE=', '', $engine);
671
-        \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
672
-    }
673
-
674
-
675
-
676
-    /**
677
-     *    add_column_if_it_doesn't_exist
678
-     *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
679
-     *
680
-     * @access     public
681
-     * @static
682
-     * @deprecated instead use TableManager::addColumn()
683
-     * @param string $table_name  (without "wp_", eg "esp_attendee"
684
-     * @param string $column_name
685
-     * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
686
-     *                            'VARCHAR(10)'
687
-     * @return bool|int
688
-     */
689
-    public static function add_column_if_it_doesnt_exist(
690
-        $table_name,
691
-        $column_name,
692
-        $column_info = 'INT UNSIGNED NOT NULL'
693
-    ) {
694
-        return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
695
-    }
696
-
697
-
698
-    /**
699
-     * get_fields_on_table
700
-     * Gets all the fields on the database table.
701
-     *
702
-     * @access     public
703
-     * @deprecated instead use TableManager::getTableColumns()
704
-     * @static
705
-     * @param string $table_name , without prefixed $wpdb->prefix
706
-     * @return array of database column names
707
-     */
708
-    public static function get_fields_on_table($table_name = null)
709
-    {
710
-        return \EEH_Activation::getTableManager()->getTableColumns($table_name);
711
-    }
712
-
713
-
714
-    /**
715
-     * db_table_is_empty
716
-     *
717
-     * @access     public\
718
-     * @deprecated instead use TableAnalysis::tableIsEmpty()
719
-     * @static
720
-     * @param string $table_name
721
-     * @return bool
722
-     */
723
-    public static function db_table_is_empty($table_name)
724
-    {
725
-        return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
726
-    }
727
-
728
-
729
-    /**
730
-     * delete_db_table_if_empty
731
-     *
732
-     * @access public
733
-     * @static
734
-     * @param string $table_name
735
-     * @return bool | int
736
-     */
737
-    public static function delete_db_table_if_empty($table_name)
738
-    {
739
-        if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
740
-            return \EEH_Activation::getTableManager()->dropTable($table_name);
741
-        }
742
-        return false;
743
-    }
744
-
745
-
746
-    /**
747
-     * delete_unused_db_table
748
-     *
749
-     * @access     public
750
-     * @static
751
-     * @deprecated instead use TableManager::dropTable()
752
-     * @param string $table_name
753
-     * @return bool | int
754
-     */
755
-    public static function delete_unused_db_table($table_name)
756
-    {
757
-        return \EEH_Activation::getTableManager()->dropTable($table_name);
758
-    }
759
-
760
-
761
-    /**
762
-     * drop_index
763
-     *
764
-     * @access     public
765
-     * @static
766
-     * @deprecated instead use TableManager::dropIndex()
767
-     * @param string $table_name
768
-     * @param string $index_name
769
-     * @return bool | int
770
-     */
771
-    public static function drop_index($table_name, $index_name)
772
-    {
773
-        return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
774
-    }
775
-
776
-
777
-
778
-    /**
779
-     * create_database_tables
780
-     *
781
-     * @access public
782
-     * @static
783
-     * @throws EE_Error
784
-     * @return boolean success (whether database is setup properly or not)
785
-     */
786
-    public static function create_database_tables()
787
-    {
788
-        EE_Registry::instance()->load_core('Data_Migration_Manager');
789
-        // find the migration script that sets the database to be compatible with the code
790
-        $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
791
-        if ($dms_name) {
792
-            $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
793
-            $current_data_migration_script->set_migrating(false);
794
-            $current_data_migration_script->schema_changes_before_migration();
795
-            $current_data_migration_script->schema_changes_after_migration();
796
-            if ($current_data_migration_script->get_errors()) {
797
-                if (WP_DEBUG) {
798
-                    foreach ($current_data_migration_script->get_errors() as $error) {
799
-                        EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
800
-                    }
801
-                } else {
802
-                    EE_Error::add_error(
803
-                        __(
804
-                            'There were errors creating the Event Espresso database tables and Event Espresso has been 
260
+		$ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
261
+		foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
262
+			if (is_array($hooks_to_fire_at_time)) {
263
+				foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
264
+					if (isset($ee_cron_tasks_to_remove[ $hook_name ])
265
+						&& is_array($ee_cron_tasks_to_remove[ $hook_name ])
266
+					) {
267
+						unset($crons[ $timestamp ][ $hook_name ]);
268
+					}
269
+				}
270
+				// also take care of any empty cron timestamps.
271
+				if (empty($hooks_to_fire_at_time)) {
272
+					unset($crons[ $timestamp ]);
273
+				}
274
+			}
275
+		}
276
+		_set_cron_array($crons);
277
+	}
278
+
279
+
280
+	/**
281
+	 *    CPT_initialization
282
+	 *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
283
+	 *
284
+	 * @access public
285
+	 * @static
286
+	 * @return void
287
+	 */
288
+	public static function CPT_initialization()
289
+	{
290
+		// register Custom Post Types
291
+		EE_Registry::instance()->load_core('Register_CPTs');
292
+		flush_rewrite_rules();
293
+	}
294
+
295
+
296
+
297
+	/**
298
+	 *    reset_and_update_config
299
+	 * The following code was moved over from EE_Config so that it will no longer run on every request.
300
+	 * If there is old calendar config data saved, then it will get converted on activation.
301
+	 * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
302
+	 *
303
+	 * @access public
304
+	 * @static
305
+	 * @return void
306
+	 */
307
+	public static function reset_and_update_config()
308
+	{
309
+		do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
310
+		add_filter(
311
+			'FHEE__EE_Config___load_core_config__config_settings',
312
+			array('EEH_Activation', 'migrate_old_config_data'),
313
+			10,
314
+			3
315
+		);
316
+		// EE_Config::reset();
317
+		if (! EE_Config::logging_enabled()) {
318
+			delete_option(EE_Config::LOG_NAME);
319
+		}
320
+	}
321
+
322
+
323
+	/**
324
+	 *    load_calendar_config
325
+	 *
326
+	 * @access    public
327
+	 * @return    void
328
+	 */
329
+	public static function load_calendar_config()
330
+	{
331
+		// grab array of all plugin folders and loop thru it
332
+		$plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
333
+		if (empty($plugins)) {
334
+			return;
335
+		}
336
+		foreach ($plugins as $plugin_path) {
337
+			// grab plugin folder name from path
338
+			$plugin = basename($plugin_path);
339
+			// drill down to Espresso plugins
340
+			// then to calendar related plugins
341
+			if (strpos($plugin, 'espresso') !== false
342
+				|| strpos($plugin, 'Espresso') !== false
343
+				|| strpos($plugin, 'ee4') !== false
344
+				|| strpos($plugin, 'EE4') !== false
345
+				|| strpos($plugin, 'calendar') !== false
346
+			) {
347
+				// this is what we are looking for
348
+				$calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
349
+				// does it exist in this folder ?
350
+				if (is_readable($calendar_config)) {
351
+					// YEAH! let's load it
352
+					require_once($calendar_config);
353
+				}
354
+			}
355
+		}
356
+	}
357
+
358
+
359
+
360
+	/**
361
+	 *    _migrate_old_config_data
362
+	 *
363
+	 * @access    public
364
+	 * @param array|stdClass $settings
365
+	 * @param string         $config
366
+	 * @param \EE_Config     $EE_Config
367
+	 * @return \stdClass
368
+	 */
369
+	public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
370
+	{
371
+		$convert_from_array = array('addons');
372
+		// in case old settings were saved as an array
373
+		if (is_array($settings) && in_array($config, $convert_from_array)) {
374
+			// convert existing settings to an object
375
+			$config_array = $settings;
376
+			$settings = new stdClass();
377
+			foreach ($config_array as $key => $value) {
378
+				if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
379
+					$EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
380
+				} else {
381
+					$settings->{$key} = $value;
382
+				}
383
+			}
384
+			add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
385
+		}
386
+		return $settings;
387
+	}
388
+
389
+
390
+	/**
391
+	 * deactivate_event_espresso
392
+	 *
393
+	 * @access public
394
+	 * @static
395
+	 * @return void
396
+	 */
397
+	public static function deactivate_event_espresso()
398
+	{
399
+		// check permissions
400
+		if (current_user_can('activate_plugins')) {
401
+			deactivate_plugins(EE_PLUGIN_BASENAME, true);
402
+		}
403
+	}
404
+
405
+
406
+
407
+	/**
408
+	 * verify_default_pages_exist
409
+	 *
410
+	 * @access public
411
+	 * @static
412
+	 * @return void
413
+	 * @throws InvalidDataTypeException
414
+	 */
415
+	public static function verify_default_pages_exist()
416
+	{
417
+		$critical_page_problem = false;
418
+		$critical_pages = array(
419
+			array(
420
+				'id'   => 'reg_page_id',
421
+				'name' => __('Registration Checkout', 'event_espresso'),
422
+				'post' => null,
423
+				'code' => 'ESPRESSO_CHECKOUT',
424
+			),
425
+			array(
426
+				'id'   => 'txn_page_id',
427
+				'name' => __('Transactions', 'event_espresso'),
428
+				'post' => null,
429
+				'code' => 'ESPRESSO_TXN_PAGE',
430
+			),
431
+			array(
432
+				'id'   => 'thank_you_page_id',
433
+				'name' => __('Thank You', 'event_espresso'),
434
+				'post' => null,
435
+				'code' => 'ESPRESSO_THANK_YOU',
436
+			),
437
+			array(
438
+				'id'   => 'cancel_page_id',
439
+				'name' => __('Registration Cancelled', 'event_espresso'),
440
+				'post' => null,
441
+				'code' => 'ESPRESSO_CANCELLED',
442
+			),
443
+		);
444
+		$EE_Core_Config = EE_Registry::instance()->CFG->core;
445
+		foreach ($critical_pages as $critical_page) {
446
+			// is critical page ID set in config ?
447
+			if ($EE_Core_Config->{$critical_page['id']} !== false) {
448
+				// attempt to find post by ID
449
+				$critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
450
+			}
451
+			// no dice?
452
+			if ($critical_page['post'] === null) {
453
+				// attempt to find post by title
454
+				$critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
455
+				// still nothing?
456
+				if ($critical_page['post'] === null) {
457
+					$critical_page = EEH_Activation::create_critical_page($critical_page);
458
+					// REALLY? Still nothing ??!?!?
459
+					if ($critical_page['post'] === null) {
460
+						$msg = __(
461
+							'The Event Espresso critical page configuration settings could not be updated.',
462
+							'event_espresso'
463
+						);
464
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
465
+						break;
466
+					}
467
+				}
468
+			}
469
+			// check that Post ID matches critical page ID in config
470
+			if (isset($critical_page['post']->ID)
471
+				&& $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
472
+			) {
473
+				// update Config with post ID
474
+				$EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
475
+				if (! EE_Config::instance()->update_espresso_config(false, false)) {
476
+					$msg = __(
477
+						'The Event Espresso critical page configuration settings could not be updated.',
478
+						'event_espresso'
479
+					);
480
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
481
+				}
482
+			}
483
+			$critical_page_problem =
484
+				! isset($critical_page['post']->post_status)
485
+				|| $critical_page['post']->post_status !== 'publish'
486
+				|| strpos($critical_page['post']->post_content, $critical_page['code']) === false
487
+					? true
488
+					: $critical_page_problem;
489
+		}
490
+		if ($critical_page_problem) {
491
+			new PersistentAdminNotice(
492
+				'critical_page_problem',
493
+				sprintf(
494
+					esc_html__(
495
+						'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
496
+						'event_espresso'
497
+					),
498
+					'<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
499
+					. __('Event Espresso Critical Pages Settings', 'event_espresso')
500
+					. '</a>'
501
+				)
502
+			);
503
+		}
504
+		if (EE_Error::has_notices()) {
505
+			EE_Error::get_notices(false, true, true);
506
+		}
507
+	}
508
+
509
+
510
+
511
+	/**
512
+	 * Returns the first post which uses the specified shortcode
513
+	 *
514
+	 * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
515
+	 *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
516
+	 *                             "[ESPRESSO_THANK_YOU"
517
+	 *                             (we don't search for the closing shortcode bracket because they might have added
518
+	 *                             parameter to the shortcode
519
+	 * @return WP_Post or NULl
520
+	 */
521
+	public static function get_page_by_ee_shortcode($ee_shortcode)
522
+	{
523
+		global $wpdb;
524
+		$shortcode_and_opening_bracket = '[' . $ee_shortcode;
525
+		$post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
526
+		if ($post_id) {
527
+			return get_post($post_id);
528
+		} else {
529
+			return null;
530
+		}
531
+	}
532
+
533
+
534
+	/**
535
+	 *    This function generates a post for critical espresso pages
536
+	 *
537
+	 * @access public
538
+	 * @static
539
+	 * @param array $critical_page
540
+	 * @return array
541
+	 */
542
+	public static function create_critical_page($critical_page)
543
+	{
544
+
545
+		$post_args = array(
546
+			'post_title'     => $critical_page['name'],
547
+			'post_status'    => 'publish',
548
+			'post_type'      => 'page',
549
+			'comment_status' => 'closed',
550
+			'post_content'   => '[' . $critical_page['code'] . ']',
551
+		);
552
+
553
+		$post_id = wp_insert_post($post_args);
554
+		if (! $post_id) {
555
+			$msg = sprintf(
556
+				__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
557
+				$critical_page['name']
558
+			);
559
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
560
+			return $critical_page;
561
+		}
562
+		// get newly created post's details
563
+		if (! $critical_page['post'] = get_post($post_id)) {
564
+			$msg = sprintf(
565
+				__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
566
+				$critical_page['name']
567
+			);
568
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
569
+		}
570
+
571
+		return $critical_page;
572
+	}
573
+
574
+
575
+
576
+
577
+	/**
578
+	 * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
579
+	 * The role being used to check is filterable.
580
+	 *
581
+	 * @since  4.6.0
582
+	 * @global WPDB $wpdb
583
+	 * @return mixed null|int WP_user ID or NULL
584
+	 */
585
+	public static function get_default_creator_id()
586
+	{
587
+		global $wpdb;
588
+		if (! empty(self::$_default_creator_id)) {
589
+			return self::$_default_creator_id;
590
+		}/**/
591
+		$role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
592
+		// let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
593
+		$pre_filtered_id = apply_filters(
594
+			'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
595
+			false,
596
+			$role_to_check
597
+		);
598
+		if ($pre_filtered_id !== false) {
599
+			return (int) $pre_filtered_id;
600
+		}
601
+		$capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
602
+		$query = $wpdb->prepare(
603
+			"SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
604
+			'%' . $role_to_check . '%'
605
+		);
606
+		$user_id = $wpdb->get_var($query);
607
+		$user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
608
+		if ($user_id && (int) $user_id) {
609
+			self::$_default_creator_id = (int) $user_id;
610
+			return self::$_default_creator_id;
611
+		} else {
612
+			return null;
613
+		}
614
+	}
615
+
616
+
617
+
618
+	/**
619
+	 * used by EE and EE addons during plugin activation to create tables.
620
+	 * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
621
+	 * but includes extra logic regarding activations.
622
+	 *
623
+	 * @access public
624
+	 * @static
625
+	 * @param string  $table_name              without the $wpdb->prefix
626
+	 * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
627
+	 *                                         table query)
628
+	 * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
629
+	 * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
630
+	 *                                         and new once this function is done (ie, you really do want to CREATE a
631
+	 *                                         table, and expect it to be empty once you're done) leave as FALSE when
632
+	 *                                         you just want to verify the table exists and matches this definition
633
+	 *                                         (and if it HAS data in it you want to leave it be)
634
+	 * @return void
635
+	 * @throws EE_Error if there are database errors
636
+	 */
637
+	public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
638
+	{
639
+		if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
640
+			return;
641
+		}
642
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
643
+		if (! function_exists('dbDelta')) {
644
+			require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
645
+		}
646
+		$tableAnalysis = \EEH_Activation::getTableAnalysis();
647
+		$wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
648
+		// do we need to first delete an existing version of this table ?
649
+		if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
650
+			// ok, delete the table... but ONLY if it's empty
651
+			$deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
652
+			// table is NOT empty, are you SURE you want to delete this table ???
653
+			if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
654
+				\EEH_Activation::getTableManager()->dropTable($wp_table_name);
655
+			} elseif (! $deleted_safely) {
656
+				// so we should be more cautious rather than just dropping tables so easily
657
+				error_log(
658
+					sprintf(
659
+						__(
660
+							'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
661
+							'event_espresso'
662
+						),
663
+						$wp_table_name,
664
+						'<br/>',
665
+						'espresso_db_update'
666
+					)
667
+				);
668
+			}
669
+		}
670
+		$engine = str_replace('ENGINE=', '', $engine);
671
+		\EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
672
+	}
673
+
674
+
675
+
676
+	/**
677
+	 *    add_column_if_it_doesn't_exist
678
+	 *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
679
+	 *
680
+	 * @access     public
681
+	 * @static
682
+	 * @deprecated instead use TableManager::addColumn()
683
+	 * @param string $table_name  (without "wp_", eg "esp_attendee"
684
+	 * @param string $column_name
685
+	 * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
686
+	 *                            'VARCHAR(10)'
687
+	 * @return bool|int
688
+	 */
689
+	public static function add_column_if_it_doesnt_exist(
690
+		$table_name,
691
+		$column_name,
692
+		$column_info = 'INT UNSIGNED NOT NULL'
693
+	) {
694
+		return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
695
+	}
696
+
697
+
698
+	/**
699
+	 * get_fields_on_table
700
+	 * Gets all the fields on the database table.
701
+	 *
702
+	 * @access     public
703
+	 * @deprecated instead use TableManager::getTableColumns()
704
+	 * @static
705
+	 * @param string $table_name , without prefixed $wpdb->prefix
706
+	 * @return array of database column names
707
+	 */
708
+	public static function get_fields_on_table($table_name = null)
709
+	{
710
+		return \EEH_Activation::getTableManager()->getTableColumns($table_name);
711
+	}
712
+
713
+
714
+	/**
715
+	 * db_table_is_empty
716
+	 *
717
+	 * @access     public\
718
+	 * @deprecated instead use TableAnalysis::tableIsEmpty()
719
+	 * @static
720
+	 * @param string $table_name
721
+	 * @return bool
722
+	 */
723
+	public static function db_table_is_empty($table_name)
724
+	{
725
+		return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
726
+	}
727
+
728
+
729
+	/**
730
+	 * delete_db_table_if_empty
731
+	 *
732
+	 * @access public
733
+	 * @static
734
+	 * @param string $table_name
735
+	 * @return bool | int
736
+	 */
737
+	public static function delete_db_table_if_empty($table_name)
738
+	{
739
+		if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
740
+			return \EEH_Activation::getTableManager()->dropTable($table_name);
741
+		}
742
+		return false;
743
+	}
744
+
745
+
746
+	/**
747
+	 * delete_unused_db_table
748
+	 *
749
+	 * @access     public
750
+	 * @static
751
+	 * @deprecated instead use TableManager::dropTable()
752
+	 * @param string $table_name
753
+	 * @return bool | int
754
+	 */
755
+	public static function delete_unused_db_table($table_name)
756
+	{
757
+		return \EEH_Activation::getTableManager()->dropTable($table_name);
758
+	}
759
+
760
+
761
+	/**
762
+	 * drop_index
763
+	 *
764
+	 * @access     public
765
+	 * @static
766
+	 * @deprecated instead use TableManager::dropIndex()
767
+	 * @param string $table_name
768
+	 * @param string $index_name
769
+	 * @return bool | int
770
+	 */
771
+	public static function drop_index($table_name, $index_name)
772
+	{
773
+		return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
774
+	}
775
+
776
+
777
+
778
+	/**
779
+	 * create_database_tables
780
+	 *
781
+	 * @access public
782
+	 * @static
783
+	 * @throws EE_Error
784
+	 * @return boolean success (whether database is setup properly or not)
785
+	 */
786
+	public static function create_database_tables()
787
+	{
788
+		EE_Registry::instance()->load_core('Data_Migration_Manager');
789
+		// find the migration script that sets the database to be compatible with the code
790
+		$dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
791
+		if ($dms_name) {
792
+			$current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
793
+			$current_data_migration_script->set_migrating(false);
794
+			$current_data_migration_script->schema_changes_before_migration();
795
+			$current_data_migration_script->schema_changes_after_migration();
796
+			if ($current_data_migration_script->get_errors()) {
797
+				if (WP_DEBUG) {
798
+					foreach ($current_data_migration_script->get_errors() as $error) {
799
+						EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
800
+					}
801
+				} else {
802
+					EE_Error::add_error(
803
+						__(
804
+							'There were errors creating the Event Espresso database tables and Event Espresso has been 
805 805
                             deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.',
806
-                            'event_espresso'
807
-                        )
808
-                    );
809
-                }
810
-                return false;
811
-            }
812
-            EE_Data_Migration_Manager::instance()->update_current_database_state_to();
813
-        } else {
814
-            EE_Error::add_error(
815
-                __(
816
-                    'Could not determine most up-to-date data migration script from which to pull database schema
806
+							'event_espresso'
807
+						)
808
+					);
809
+				}
810
+				return false;
811
+			}
812
+			EE_Data_Migration_Manager::instance()->update_current_database_state_to();
813
+		} else {
814
+			EE_Error::add_error(
815
+				__(
816
+					'Could not determine most up-to-date data migration script from which to pull database schema
817 817
                      structure. So database is probably not setup properly',
818
-                    'event_espresso'
819
-                ),
820
-                __FILE__,
821
-                __FUNCTION__,
822
-                __LINE__
823
-            );
824
-            return false;
825
-        }
826
-        return true;
827
-    }
828
-
829
-
830
-
831
-    /**
832
-     * initialize_system_questions
833
-     *
834
-     * @access public
835
-     * @static
836
-     * @return void
837
-     */
838
-    public static function initialize_system_questions()
839
-    {
840
-        // QUESTION GROUPS
841
-        global $wpdb;
842
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
843
-        $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
844
-        // what we have
845
-        $question_groups = $wpdb->get_col($SQL);
846
-        // check the response
847
-        $question_groups = is_array($question_groups) ? $question_groups : array();
848
-        // what we should have
849
-        $QSG_systems = array(1, 2);
850
-        // loop thru what we should have and compare to what we have
851
-        foreach ($QSG_systems as $QSG_system) {
852
-            // reset values array
853
-            $QSG_values = array();
854
-            // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
855
-            if (! in_array("$QSG_system", $question_groups)) {
856
-                // add it
857
-                switch ($QSG_system) {
858
-                    case 1:
859
-                        $QSG_values = array(
860
-                            'QSG_name'            => __('Personal Information', 'event_espresso'),
861
-                            'QSG_identifier'      => 'personal-information-' . time(),
862
-                            'QSG_desc'            => '',
863
-                            'QSG_order'           => 1,
864
-                            'QSG_show_group_name' => 1,
865
-                            'QSG_show_group_desc' => 1,
866
-                            'QSG_system'          => EEM_Question_Group::system_personal,
867
-                            'QSG_deleted'         => 0,
868
-                        );
869
-                        break;
870
-                    case 2:
871
-                        $QSG_values = array(
872
-                            'QSG_name'            => __('Address Information', 'event_espresso'),
873
-                            'QSG_identifier'      => 'address-information-' . time(),
874
-                            'QSG_desc'            => '',
875
-                            'QSG_order'           => 2,
876
-                            'QSG_show_group_name' => 1,
877
-                            'QSG_show_group_desc' => 1,
878
-                            'QSG_system'          => EEM_Question_Group::system_address,
879
-                            'QSG_deleted'         => 0,
880
-                        );
881
-                        break;
882
-                }
883
-                // make sure we have some values before inserting them
884
-                if (! empty($QSG_values)) {
885
-                    // insert system question
886
-                    $wpdb->insert(
887
-                        $table_name,
888
-                        $QSG_values,
889
-                        array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
890
-                    );
891
-                    $QSG_IDs[ $QSG_system ] = $wpdb->insert_id;
892
-                }
893
-            }
894
-        }
895
-        // QUESTIONS
896
-        global $wpdb;
897
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
898
-        $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
899
-        // what we have
900
-        $questions = $wpdb->get_col($SQL);
901
-        // what we should have
902
-        $QST_systems = array(
903
-            'fname',
904
-            'lname',
905
-            'email',
906
-            'address',
907
-            'address2',
908
-            'city',
909
-            'country',
910
-            'state',
911
-            'zip',
912
-            'phone',
913
-        );
914
-        $order_for_group_1 = 1;
915
-        $order_for_group_2 = 1;
916
-        // loop thru what we should have and compare to what we have
917
-        foreach ($QST_systems as $QST_system) {
918
-            // reset values array
919
-            $QST_values = array();
920
-            // if we don't have what we should have
921
-            if (! in_array($QST_system, $questions)) {
922
-                // add it
923
-                switch ($QST_system) {
924
-                    case 'fname':
925
-                        $QST_values = array(
926
-                            'QST_display_text'  => __('First Name', 'event_espresso'),
927
-                            'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
928
-                            'QST_system'        => 'fname',
929
-                            'QST_type'          => 'TEXT',
930
-                            'QST_required'      => 1,
931
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
932
-                            'QST_order'         => 1,
933
-                            'QST_admin_only'    => 0,
934
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
935
-                            'QST_wp_user'       => self::get_default_creator_id(),
936
-                            'QST_deleted'       => 0,
937
-                        );
938
-                        break;
939
-                    case 'lname':
940
-                        $QST_values = array(
941
-                            'QST_display_text'  => __('Last Name', 'event_espresso'),
942
-                            'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
943
-                            'QST_system'        => 'lname',
944
-                            'QST_type'          => 'TEXT',
945
-                            'QST_required'      => 1,
946
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
947
-                            'QST_order'         => 2,
948
-                            'QST_admin_only'    => 0,
949
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
950
-                            'QST_wp_user'       => self::get_default_creator_id(),
951
-                            'QST_deleted'       => 0,
952
-                        );
953
-                        break;
954
-                    case 'email':
955
-                        $QST_values = array(
956
-                            'QST_display_text'  => __('Email Address', 'event_espresso'),
957
-                            'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
958
-                            'QST_system'        => 'email',
959
-                            'QST_type'          => 'EMAIL',
960
-                            'QST_required'      => 1,
961
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
962
-                            'QST_order'         => 3,
963
-                            'QST_admin_only'    => 0,
964
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
965
-                            'QST_wp_user'       => self::get_default_creator_id(),
966
-                            'QST_deleted'       => 0,
967
-                        );
968
-                        break;
969
-                    case 'address':
970
-                        $QST_values = array(
971
-                            'QST_display_text'  => __('Address', 'event_espresso'),
972
-                            'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
973
-                            'QST_system'        => 'address',
974
-                            'QST_type'          => 'TEXT',
975
-                            'QST_required'      => 0,
976
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
977
-                            'QST_order'         => 4,
978
-                            'QST_admin_only'    => 0,
979
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
980
-                            'QST_wp_user'       => self::get_default_creator_id(),
981
-                            'QST_deleted'       => 0,
982
-                        );
983
-                        break;
984
-                    case 'address2':
985
-                        $QST_values = array(
986
-                            'QST_display_text'  => __('Address2', 'event_espresso'),
987
-                            'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
988
-                            'QST_system'        => 'address2',
989
-                            'QST_type'          => 'TEXT',
990
-                            'QST_required'      => 0,
991
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
992
-                            'QST_order'         => 5,
993
-                            'QST_admin_only'    => 0,
994
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
995
-                            'QST_wp_user'       => self::get_default_creator_id(),
996
-                            'QST_deleted'       => 0,
997
-                        );
998
-                        break;
999
-                    case 'city':
1000
-                        $QST_values = array(
1001
-                            'QST_display_text'  => __('City', 'event_espresso'),
1002
-                            'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1003
-                            'QST_system'        => 'city',
1004
-                            'QST_type'          => 'TEXT',
1005
-                            'QST_required'      => 0,
1006
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1007
-                            'QST_order'         => 6,
1008
-                            'QST_admin_only'    => 0,
1009
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1010
-                            'QST_wp_user'       => self::get_default_creator_id(),
1011
-                            'QST_deleted'       => 0,
1012
-                        );
1013
-                        break;
1014
-                    case 'country':
1015
-                        $QST_values = array(
1016
-                            'QST_display_text'  => __('Country', 'event_espresso'),
1017
-                            'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1018
-                            'QST_system'        => 'country',
1019
-                            'QST_type'          => 'COUNTRY',
1020
-                            'QST_required'      => 0,
1021
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1022
-                            'QST_order'         => 7,
1023
-                            'QST_admin_only'    => 0,
1024
-                            'QST_wp_user'       => self::get_default_creator_id(),
1025
-                            'QST_deleted'       => 0,
1026
-                        );
1027
-                        break;
1028
-                    case 'state':
1029
-                        $QST_values = array(
1030
-                            'QST_display_text'  => __('State/Province', 'event_espresso'),
1031
-                            'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1032
-                            'QST_system'        => 'state',
1033
-                            'QST_type'          => 'STATE',
1034
-                            'QST_required'      => 0,
1035
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1036
-                            'QST_order'         => 8,
1037
-                            'QST_admin_only'    => 0,
1038
-                            'QST_wp_user'       => self::get_default_creator_id(),
1039
-                            'QST_deleted'       => 0,
1040
-                        );
1041
-                        break;
1042
-                    case 'zip':
1043
-                        $QST_values = array(
1044
-                            'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1045
-                            'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1046
-                            'QST_system'        => 'zip',
1047
-                            'QST_type'          => 'TEXT',
1048
-                            'QST_required'      => 0,
1049
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1050
-                            'QST_order'         => 9,
1051
-                            'QST_admin_only'    => 0,
1052
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1053
-                            'QST_wp_user'       => self::get_default_creator_id(),
1054
-                            'QST_deleted'       => 0,
1055
-                        );
1056
-                        break;
1057
-                    case 'phone':
1058
-                        $QST_values = array(
1059
-                            'QST_display_text'  => __('Phone Number', 'event_espresso'),
1060
-                            'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1061
-                            'QST_system'        => 'phone',
1062
-                            'QST_type'          => 'TEXT',
1063
-                            'QST_required'      => 0,
1064
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1065
-                            'QST_order'         => 10,
1066
-                            'QST_admin_only'    => 0,
1067
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1068
-                            'QST_wp_user'       => self::get_default_creator_id(),
1069
-                            'QST_deleted'       => 0,
1070
-                        );
1071
-                        break;
1072
-                }
1073
-                if (! empty($QST_values)) {
1074
-                    // insert system question
1075
-                    $wpdb->insert(
1076
-                        $table_name,
1077
-                        $QST_values,
1078
-                        array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1079
-                    );
1080
-                    $QST_ID = $wpdb->insert_id;
1081
-                    // QUESTION GROUP QUESTIONS
1082
-                    if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1083
-                        $system_question_we_want = EEM_Question_Group::system_personal;
1084
-                    } else {
1085
-                        $system_question_we_want = EEM_Question_Group::system_address;
1086
-                    }
1087
-                    if (isset($QSG_IDs[ $system_question_we_want ])) {
1088
-                        $QSG_ID = $QSG_IDs[ $system_question_we_want ];
1089
-                    } else {
1090
-                        $id_col = EEM_Question_Group::instance()
1091
-                                                    ->get_col(array(array('QSG_system' => $system_question_we_want)));
1092
-                        if (is_array($id_col)) {
1093
-                            $QSG_ID = reset($id_col);
1094
-                        } else {
1095
-                            // ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1096
-                            EE_Log::instance()->log(
1097
-                                __FILE__,
1098
-                                __FUNCTION__,
1099
-                                sprintf(
1100
-                                    __(
1101
-                                        'Could not associate question %1$s to a question group because no system question
818
+					'event_espresso'
819
+				),
820
+				__FILE__,
821
+				__FUNCTION__,
822
+				__LINE__
823
+			);
824
+			return false;
825
+		}
826
+		return true;
827
+	}
828
+
829
+
830
+
831
+	/**
832
+	 * initialize_system_questions
833
+	 *
834
+	 * @access public
835
+	 * @static
836
+	 * @return void
837
+	 */
838
+	public static function initialize_system_questions()
839
+	{
840
+		// QUESTION GROUPS
841
+		global $wpdb;
842
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
843
+		$SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
844
+		// what we have
845
+		$question_groups = $wpdb->get_col($SQL);
846
+		// check the response
847
+		$question_groups = is_array($question_groups) ? $question_groups : array();
848
+		// what we should have
849
+		$QSG_systems = array(1, 2);
850
+		// loop thru what we should have and compare to what we have
851
+		foreach ($QSG_systems as $QSG_system) {
852
+			// reset values array
853
+			$QSG_values = array();
854
+			// if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
855
+			if (! in_array("$QSG_system", $question_groups)) {
856
+				// add it
857
+				switch ($QSG_system) {
858
+					case 1:
859
+						$QSG_values = array(
860
+							'QSG_name'            => __('Personal Information', 'event_espresso'),
861
+							'QSG_identifier'      => 'personal-information-' . time(),
862
+							'QSG_desc'            => '',
863
+							'QSG_order'           => 1,
864
+							'QSG_show_group_name' => 1,
865
+							'QSG_show_group_desc' => 1,
866
+							'QSG_system'          => EEM_Question_Group::system_personal,
867
+							'QSG_deleted'         => 0,
868
+						);
869
+						break;
870
+					case 2:
871
+						$QSG_values = array(
872
+							'QSG_name'            => __('Address Information', 'event_espresso'),
873
+							'QSG_identifier'      => 'address-information-' . time(),
874
+							'QSG_desc'            => '',
875
+							'QSG_order'           => 2,
876
+							'QSG_show_group_name' => 1,
877
+							'QSG_show_group_desc' => 1,
878
+							'QSG_system'          => EEM_Question_Group::system_address,
879
+							'QSG_deleted'         => 0,
880
+						);
881
+						break;
882
+				}
883
+				// make sure we have some values before inserting them
884
+				if (! empty($QSG_values)) {
885
+					// insert system question
886
+					$wpdb->insert(
887
+						$table_name,
888
+						$QSG_values,
889
+						array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
890
+					);
891
+					$QSG_IDs[ $QSG_system ] = $wpdb->insert_id;
892
+				}
893
+			}
894
+		}
895
+		// QUESTIONS
896
+		global $wpdb;
897
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
898
+		$SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
899
+		// what we have
900
+		$questions = $wpdb->get_col($SQL);
901
+		// what we should have
902
+		$QST_systems = array(
903
+			'fname',
904
+			'lname',
905
+			'email',
906
+			'address',
907
+			'address2',
908
+			'city',
909
+			'country',
910
+			'state',
911
+			'zip',
912
+			'phone',
913
+		);
914
+		$order_for_group_1 = 1;
915
+		$order_for_group_2 = 1;
916
+		// loop thru what we should have and compare to what we have
917
+		foreach ($QST_systems as $QST_system) {
918
+			// reset values array
919
+			$QST_values = array();
920
+			// if we don't have what we should have
921
+			if (! in_array($QST_system, $questions)) {
922
+				// add it
923
+				switch ($QST_system) {
924
+					case 'fname':
925
+						$QST_values = array(
926
+							'QST_display_text'  => __('First Name', 'event_espresso'),
927
+							'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
928
+							'QST_system'        => 'fname',
929
+							'QST_type'          => 'TEXT',
930
+							'QST_required'      => 1,
931
+							'QST_required_text' => __('This field is required', 'event_espresso'),
932
+							'QST_order'         => 1,
933
+							'QST_admin_only'    => 0,
934
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
935
+							'QST_wp_user'       => self::get_default_creator_id(),
936
+							'QST_deleted'       => 0,
937
+						);
938
+						break;
939
+					case 'lname':
940
+						$QST_values = array(
941
+							'QST_display_text'  => __('Last Name', 'event_espresso'),
942
+							'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
943
+							'QST_system'        => 'lname',
944
+							'QST_type'          => 'TEXT',
945
+							'QST_required'      => 1,
946
+							'QST_required_text' => __('This field is required', 'event_espresso'),
947
+							'QST_order'         => 2,
948
+							'QST_admin_only'    => 0,
949
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
950
+							'QST_wp_user'       => self::get_default_creator_id(),
951
+							'QST_deleted'       => 0,
952
+						);
953
+						break;
954
+					case 'email':
955
+						$QST_values = array(
956
+							'QST_display_text'  => __('Email Address', 'event_espresso'),
957
+							'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
958
+							'QST_system'        => 'email',
959
+							'QST_type'          => 'EMAIL',
960
+							'QST_required'      => 1,
961
+							'QST_required_text' => __('This field is required', 'event_espresso'),
962
+							'QST_order'         => 3,
963
+							'QST_admin_only'    => 0,
964
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
965
+							'QST_wp_user'       => self::get_default_creator_id(),
966
+							'QST_deleted'       => 0,
967
+						);
968
+						break;
969
+					case 'address':
970
+						$QST_values = array(
971
+							'QST_display_text'  => __('Address', 'event_espresso'),
972
+							'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
973
+							'QST_system'        => 'address',
974
+							'QST_type'          => 'TEXT',
975
+							'QST_required'      => 0,
976
+							'QST_required_text' => __('This field is required', 'event_espresso'),
977
+							'QST_order'         => 4,
978
+							'QST_admin_only'    => 0,
979
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
980
+							'QST_wp_user'       => self::get_default_creator_id(),
981
+							'QST_deleted'       => 0,
982
+						);
983
+						break;
984
+					case 'address2':
985
+						$QST_values = array(
986
+							'QST_display_text'  => __('Address2', 'event_espresso'),
987
+							'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
988
+							'QST_system'        => 'address2',
989
+							'QST_type'          => 'TEXT',
990
+							'QST_required'      => 0,
991
+							'QST_required_text' => __('This field is required', 'event_espresso'),
992
+							'QST_order'         => 5,
993
+							'QST_admin_only'    => 0,
994
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
995
+							'QST_wp_user'       => self::get_default_creator_id(),
996
+							'QST_deleted'       => 0,
997
+						);
998
+						break;
999
+					case 'city':
1000
+						$QST_values = array(
1001
+							'QST_display_text'  => __('City', 'event_espresso'),
1002
+							'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1003
+							'QST_system'        => 'city',
1004
+							'QST_type'          => 'TEXT',
1005
+							'QST_required'      => 0,
1006
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1007
+							'QST_order'         => 6,
1008
+							'QST_admin_only'    => 0,
1009
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1010
+							'QST_wp_user'       => self::get_default_creator_id(),
1011
+							'QST_deleted'       => 0,
1012
+						);
1013
+						break;
1014
+					case 'country':
1015
+						$QST_values = array(
1016
+							'QST_display_text'  => __('Country', 'event_espresso'),
1017
+							'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1018
+							'QST_system'        => 'country',
1019
+							'QST_type'          => 'COUNTRY',
1020
+							'QST_required'      => 0,
1021
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1022
+							'QST_order'         => 7,
1023
+							'QST_admin_only'    => 0,
1024
+							'QST_wp_user'       => self::get_default_creator_id(),
1025
+							'QST_deleted'       => 0,
1026
+						);
1027
+						break;
1028
+					case 'state':
1029
+						$QST_values = array(
1030
+							'QST_display_text'  => __('State/Province', 'event_espresso'),
1031
+							'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1032
+							'QST_system'        => 'state',
1033
+							'QST_type'          => 'STATE',
1034
+							'QST_required'      => 0,
1035
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1036
+							'QST_order'         => 8,
1037
+							'QST_admin_only'    => 0,
1038
+							'QST_wp_user'       => self::get_default_creator_id(),
1039
+							'QST_deleted'       => 0,
1040
+						);
1041
+						break;
1042
+					case 'zip':
1043
+						$QST_values = array(
1044
+							'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1045
+							'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1046
+							'QST_system'        => 'zip',
1047
+							'QST_type'          => 'TEXT',
1048
+							'QST_required'      => 0,
1049
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1050
+							'QST_order'         => 9,
1051
+							'QST_admin_only'    => 0,
1052
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1053
+							'QST_wp_user'       => self::get_default_creator_id(),
1054
+							'QST_deleted'       => 0,
1055
+						);
1056
+						break;
1057
+					case 'phone':
1058
+						$QST_values = array(
1059
+							'QST_display_text'  => __('Phone Number', 'event_espresso'),
1060
+							'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1061
+							'QST_system'        => 'phone',
1062
+							'QST_type'          => 'TEXT',
1063
+							'QST_required'      => 0,
1064
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1065
+							'QST_order'         => 10,
1066
+							'QST_admin_only'    => 0,
1067
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1068
+							'QST_wp_user'       => self::get_default_creator_id(),
1069
+							'QST_deleted'       => 0,
1070
+						);
1071
+						break;
1072
+				}
1073
+				if (! empty($QST_values)) {
1074
+					// insert system question
1075
+					$wpdb->insert(
1076
+						$table_name,
1077
+						$QST_values,
1078
+						array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1079
+					);
1080
+					$QST_ID = $wpdb->insert_id;
1081
+					// QUESTION GROUP QUESTIONS
1082
+					if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1083
+						$system_question_we_want = EEM_Question_Group::system_personal;
1084
+					} else {
1085
+						$system_question_we_want = EEM_Question_Group::system_address;
1086
+					}
1087
+					if (isset($QSG_IDs[ $system_question_we_want ])) {
1088
+						$QSG_ID = $QSG_IDs[ $system_question_we_want ];
1089
+					} else {
1090
+						$id_col = EEM_Question_Group::instance()
1091
+													->get_col(array(array('QSG_system' => $system_question_we_want)));
1092
+						if (is_array($id_col)) {
1093
+							$QSG_ID = reset($id_col);
1094
+						} else {
1095
+							// ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1096
+							EE_Log::instance()->log(
1097
+								__FILE__,
1098
+								__FUNCTION__,
1099
+								sprintf(
1100
+									__(
1101
+										'Could not associate question %1$s to a question group because no system question
1102 1102
                                          group existed',
1103
-                                        'event_espresso'
1104
-                                    ),
1105
-                                    $QST_ID
1106
-                                ),
1107
-                                'error'
1108
-                            );
1109
-                            continue;
1110
-                        }
1111
-                    }
1112
-                    // add system questions to groups
1113
-                    $wpdb->insert(
1114
-                        \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1115
-                        array(
1116
-                            'QSG_ID'    => $QSG_ID,
1117
-                            'QST_ID'    => $QST_ID,
1118
-                            'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1119
-                        ),
1120
-                        array('%d', '%d', '%d')
1121
-                    );
1122
-                }
1123
-            }
1124
-        }
1125
-    }
1126
-
1127
-
1128
-    /**
1129
-     * Makes sure the default payment method (Invoice) is active.
1130
-     * This used to be done automatically as part of constructing the old gateways config
1131
-     *
1132
-     * @throws \EE_Error
1133
-     */
1134
-    public static function insert_default_payment_methods()
1135
-    {
1136
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1137
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
1138
-            EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1139
-        } else {
1140
-            EEM_Payment_Method::instance()->verify_button_urls();
1141
-        }
1142
-    }
1143
-
1144
-    /**
1145
-     * insert_default_status_codes
1146
-     *
1147
-     * @access public
1148
-     * @static
1149
-     * @return void
1150
-     */
1151
-    public static function insert_default_status_codes()
1152
-    {
1153
-
1154
-        global $wpdb;
1155
-
1156
-        if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1157
-            $table_name = EEM_Status::instance()->table();
1158
-
1159
-            $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1160
-            $wpdb->query($SQL);
1161
-
1162
-            $SQL = "INSERT INTO $table_name
1103
+										'event_espresso'
1104
+									),
1105
+									$QST_ID
1106
+								),
1107
+								'error'
1108
+							);
1109
+							continue;
1110
+						}
1111
+					}
1112
+					// add system questions to groups
1113
+					$wpdb->insert(
1114
+						\EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1115
+						array(
1116
+							'QSG_ID'    => $QSG_ID,
1117
+							'QST_ID'    => $QST_ID,
1118
+							'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1119
+						),
1120
+						array('%d', '%d', '%d')
1121
+					);
1122
+				}
1123
+			}
1124
+		}
1125
+	}
1126
+
1127
+
1128
+	/**
1129
+	 * Makes sure the default payment method (Invoice) is active.
1130
+	 * This used to be done automatically as part of constructing the old gateways config
1131
+	 *
1132
+	 * @throws \EE_Error
1133
+	 */
1134
+	public static function insert_default_payment_methods()
1135
+	{
1136
+		if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1137
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
1138
+			EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1139
+		} else {
1140
+			EEM_Payment_Method::instance()->verify_button_urls();
1141
+		}
1142
+	}
1143
+
1144
+	/**
1145
+	 * insert_default_status_codes
1146
+	 *
1147
+	 * @access public
1148
+	 * @static
1149
+	 * @return void
1150
+	 */
1151
+	public static function insert_default_status_codes()
1152
+	{
1153
+
1154
+		global $wpdb;
1155
+
1156
+		if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1157
+			$table_name = EEM_Status::instance()->table();
1158
+
1159
+			$SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1160
+			$wpdb->query($SQL);
1161
+
1162
+			$SQL = "INSERT INTO $table_name
1163 1163
 					(STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES
1164 1164
 					('ACT', 'ACTIVE', 'event', 0, NULL, 1),
1165 1165
 					('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0),
@@ -1199,457 +1199,457 @@  discard block
 block discarded – undo
1199 1199
 					('MID', 'IDLE', 'message', 0, NULL, 1),
1200 1200
 					('MRS', 'RESEND', 'message', 0, NULL, 1),
1201 1201
 					('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);";
1202
-            $wpdb->query($SQL);
1203
-        }
1204
-    }
1205
-
1206
-
1207
-    /**
1208
-     * generate_default_message_templates
1209
-     *
1210
-     * @static
1211
-     * @throws EE_Error
1212
-     * @return bool     true means new templates were created.
1213
-     *                  false means no templates were created.
1214
-     *                  This is NOT an error flag. To check for errors you will want
1215
-     *                  to use either EE_Error or a try catch for an EE_Error exception.
1216
-     */
1217
-    public static function generate_default_message_templates()
1218
-    {
1219
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1220
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1221
-        /*
1202
+			$wpdb->query($SQL);
1203
+		}
1204
+	}
1205
+
1206
+
1207
+	/**
1208
+	 * generate_default_message_templates
1209
+	 *
1210
+	 * @static
1211
+	 * @throws EE_Error
1212
+	 * @return bool     true means new templates were created.
1213
+	 *                  false means no templates were created.
1214
+	 *                  This is NOT an error flag. To check for errors you will want
1215
+	 *                  to use either EE_Error or a try catch for an EE_Error exception.
1216
+	 */
1217
+	public static function generate_default_message_templates()
1218
+	{
1219
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1220
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1221
+		/*
1222 1222
          * This first method is taking care of ensuring any default messengers
1223 1223
          * that should be made active and have templates generated are done.
1224 1224
          */
1225
-        $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1226
-            $message_resource_manager
1227
-        );
1228
-        /**
1229
-         * This method is verifying there are no NEW default message types
1230
-         * for ACTIVE messengers that need activated (and corresponding templates setup).
1231
-         */
1232
-        $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1233
-            $message_resource_manager
1234
-        );
1235
-        // after all is done, let's persist these changes to the db.
1236
-        $message_resource_manager->update_has_activated_messengers_option();
1237
-        $message_resource_manager->update_active_messengers_option();
1238
-        // will return true if either of these are true.  Otherwise will return false.
1239
-        return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1240
-    }
1241
-
1242
-
1243
-
1244
-    /**
1245
-     * @param \EE_Message_Resource_Manager $message_resource_manager
1246
-     * @return array|bool
1247
-     * @throws \EE_Error
1248
-     */
1249
-    protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1250
-        EE_Message_Resource_Manager $message_resource_manager
1251
-    ) {
1252
-        /** @type EE_messenger[] $active_messengers */
1253
-        $active_messengers = $message_resource_manager->active_messengers();
1254
-        $installed_message_types = $message_resource_manager->installed_message_types();
1255
-        $templates_created = false;
1256
-        foreach ($active_messengers as $active_messenger) {
1257
-            $default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1258
-            $default_message_type_names_to_activate = array();
1259
-            // looping through each default message type reported by the messenger
1260
-            // and setup the actual message types to activate.
1261
-            foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1262
-                // if already active or has already been activated before we skip
1263
-                // (otherwise we might reactivate something user's intentionally deactivated.)
1264
-                // we also skip if the message type is not installed.
1265
-                if ($message_resource_manager->has_message_type_been_activated_for_messenger(
1266
-                    $default_message_type_name_for_messenger,
1267
-                    $active_messenger->name
1268
-                )
1269
-                    || $message_resource_manager->is_message_type_active_for_messenger(
1270
-                        $active_messenger->name,
1271
-                        $default_message_type_name_for_messenger
1272
-                    )
1273
-                    || ! isset($installed_message_types[ $default_message_type_name_for_messenger ])
1274
-                ) {
1275
-                    continue;
1276
-                }
1277
-                $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1278
-            }
1279
-            // let's activate!
1280
-            $message_resource_manager->ensure_message_types_are_active(
1281
-                $default_message_type_names_to_activate,
1282
-                $active_messenger->name,
1283
-                false
1284
-            );
1285
-            // activate the templates for these message types
1286
-            if (! empty($default_message_type_names_to_activate)) {
1287
-                $templates_created = EEH_MSG_Template::generate_new_templates(
1288
-                    $active_messenger->name,
1289
-                    $default_message_type_names_for_messenger,
1290
-                    '',
1291
-                    true
1292
-                );
1293
-            }
1294
-        }
1295
-        return $templates_created;
1296
-    }
1297
-
1298
-
1299
-
1300
-    /**
1301
-     * This will activate and generate default messengers and default message types for those messengers.
1302
-     *
1303
-     * @param EE_message_Resource_Manager $message_resource_manager
1304
-     * @return array|bool  True means there were default messengers and message type templates generated.
1305
-     *                     False means that there were no templates generated
1306
-     *                     (which could simply mean there are no default message types for a messenger).
1307
-     * @throws EE_Error
1308
-     */
1309
-    protected static function _activate_and_generate_default_messengers_and_message_templates(
1310
-        EE_Message_Resource_Manager $message_resource_manager
1311
-    ) {
1312
-        /** @type EE_messenger[] $messengers_to_generate */
1313
-        $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1314
-        $installed_message_types = $message_resource_manager->installed_message_types();
1315
-        $templates_generated = false;
1316
-        foreach ($messengers_to_generate as $messenger_to_generate) {
1317
-            $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1318
-            // verify the default message types match an installed message type.
1319
-            foreach ($default_message_type_names_for_messenger as $key => $name) {
1320
-                if (! isset($installed_message_types[ $name ])
1321
-                    || $message_resource_manager->has_message_type_been_activated_for_messenger(
1322
-                        $name,
1323
-                        $messenger_to_generate->name
1324
-                    )
1325
-                ) {
1326
-                    unset($default_message_type_names_for_messenger[ $key ]);
1327
-                }
1328
-            }
1329
-            // in previous iterations, the active_messengers option in the db
1330
-            // needed updated before calling create templates. however with the changes this may not be necessary.
1331
-            // This comment is left here just in case we discover that we _do_ need to update before
1332
-            // passing off to create templates (after the refactor is done).
1333
-            // @todo remove this comment when determined not necessary.
1334
-            $message_resource_manager->activate_messenger(
1335
-                $messenger_to_generate->name,
1336
-                $default_message_type_names_for_messenger,
1337
-                false
1338
-            );
1339
-            // create any templates needing created (or will reactivate templates already generated as necessary).
1340
-            if (! empty($default_message_type_names_for_messenger)) {
1341
-                $templates_generated = EEH_MSG_Template::generate_new_templates(
1342
-                    $messenger_to_generate->name,
1343
-                    $default_message_type_names_for_messenger,
1344
-                    '',
1345
-                    true
1346
-                );
1347
-            }
1348
-        }
1349
-        return $templates_generated;
1350
-    }
1351
-
1352
-
1353
-    /**
1354
-     * This returns the default messengers to generate templates for on activation of EE.
1355
-     * It considers:
1356
-     * - whether a messenger is already active in the db.
1357
-     * - whether a messenger has been made active at any time in the past.
1358
-     *
1359
-     * @static
1360
-     * @param  EE_Message_Resource_Manager $message_resource_manager
1361
-     * @return EE_messenger[]
1362
-     */
1363
-    protected static function _get_default_messengers_to_generate_on_activation(
1364
-        EE_Message_Resource_Manager $message_resource_manager
1365
-    ) {
1366
-        $active_messengers    = $message_resource_manager->active_messengers();
1367
-        $installed_messengers = $message_resource_manager->installed_messengers();
1368
-        $has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1369
-
1370
-        $messengers_to_generate = array();
1371
-        foreach ($installed_messengers as $installed_messenger) {
1372
-            // if installed messenger is a messenger that should be activated on install
1373
-            // and is not already active
1374
-            // and has never been activated
1375
-            if (! $installed_messenger->activate_on_install
1376
-                || isset($active_messengers[ $installed_messenger->name ])
1377
-                || isset($has_activated[ $installed_messenger->name ])
1378
-            ) {
1379
-                continue;
1380
-            }
1381
-            $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger;
1382
-        }
1383
-        return $messengers_to_generate;
1384
-    }
1385
-
1386
-
1387
-    /**
1388
-     * This simply validates active message types to ensure they actually match installed
1389
-     * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1390
-     * rows are set inactive.
1391
-     * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1392
-     * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1393
-     * are still handled in here.
1394
-     *
1395
-     * @since 4.3.1
1396
-     * @return void
1397
-     */
1398
-    public static function validate_messages_system()
1399
-    {
1400
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1401
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1402
-        $message_resource_manager->validate_active_message_types_are_installed();
1403
-        do_action('AHEE__EEH_Activation__validate_messages_system');
1404
-    }
1405
-
1406
-
1407
-    /**
1408
-     * create_no_ticket_prices_array
1409
-     *
1410
-     * @access public
1411
-     * @static
1412
-     * @return void
1413
-     */
1414
-    public static function create_no_ticket_prices_array()
1415
-    {
1416
-        // this creates an array for tracking events that have no active ticket prices created
1417
-        // this allows us to warn admins of the situation so that it can be corrected
1418
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1419
-        if (! $espresso_no_ticket_prices) {
1420
-            add_option('ee_no_ticket_prices', array(), '', false);
1421
-        }
1422
-    }
1423
-
1424
-
1425
-    /**
1426
-     * plugin_deactivation
1427
-     *
1428
-     * @access public
1429
-     * @static
1430
-     * @return void
1431
-     */
1432
-    public static function plugin_deactivation()
1433
-    {
1434
-    }
1435
-
1436
-
1437
-    /**
1438
-     * Finds all our EE4 custom post types, and deletes them and their associated data
1439
-     * (like post meta or term relations)
1440
-     *
1441
-     * @global wpdb $wpdb
1442
-     * @throws \EE_Error
1443
-     */
1444
-    public static function delete_all_espresso_cpt_data()
1445
-    {
1446
-        global $wpdb;
1447
-        // get all the CPT post_types
1448
-        $ee_post_types = array();
1449
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1450
-            if (method_exists($model_name, 'instance')) {
1451
-                $model_obj = call_user_func(array($model_name, 'instance'));
1452
-                if ($model_obj instanceof EEM_CPT_Base) {
1453
-                    $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1454
-                }
1455
-            }
1456
-        }
1457
-        // get all our CPTs
1458
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1459
-        $cpt_ids = $wpdb->get_col($query);
1460
-        // delete each post meta and term relations too
1461
-        foreach ($cpt_ids as $post_id) {
1462
-            wp_delete_post($post_id, true);
1463
-        }
1464
-    }
1465
-
1466
-    /**
1467
-     * Deletes all EE custom tables
1468
-     *
1469
-     * @return array
1470
-     */
1471
-    public static function drop_espresso_tables()
1472
-    {
1473
-        $tables = array();
1474
-        // load registry
1475
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1476
-            if (method_exists($model_name, 'instance')) {
1477
-                $model_obj = call_user_func(array($model_name, 'instance'));
1478
-                if ($model_obj instanceof EEM_Base) {
1479
-                    foreach ($model_obj->get_tables() as $table) {
1480
-                        if (strpos($table->get_table_name(), 'esp_')
1481
-                            &&
1482
-                            (
1483
-                                is_main_site()// main site? nuke them all
1484
-                                || ! $table->is_global()// not main site,but not global either. nuke it
1485
-                            )
1486
-                        ) {
1487
-                            $tables[ $table->get_table_name() ] = $table->get_table_name();
1488
-                        }
1489
-                    }
1490
-                }
1491
-            }
1492
-        }
1493
-
1494
-        // there are some tables whose models were removed.
1495
-        // they should be removed when removing all EE core's data
1496
-        $tables_without_models = array(
1497
-            'esp_promotion',
1498
-            'esp_promotion_applied',
1499
-            'esp_promotion_object',
1500
-            'esp_promotion_rule',
1501
-            'esp_rule',
1502
-        );
1503
-        foreach ($tables_without_models as $table) {
1504
-            $tables[ $table ] = $table;
1505
-        }
1506
-        return \EEH_Activation::getTableManager()->dropTables($tables);
1507
-    }
1508
-
1509
-
1510
-
1511
-    /**
1512
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
1513
-     * each table name provided has a wpdb prefix attached, and that it exists.
1514
-     * Returns the list actually deleted
1515
-     *
1516
-     * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1517
-     * @global WPDB $wpdb
1518
-     * @param array $table_names
1519
-     * @return array of table names which we deleted
1520
-     */
1521
-    public static function drop_tables($table_names)
1522
-    {
1523
-        return \EEH_Activation::getTableManager()->dropTables($table_names);
1524
-    }
1525
-
1526
-
1527
-
1528
-    /**
1529
-     * plugin_uninstall
1530
-     *
1531
-     * @access public
1532
-     * @static
1533
-     * @param bool $remove_all
1534
-     * @return void
1535
-     */
1536
-    public static function delete_all_espresso_tables_and_data($remove_all = true)
1537
-    {
1538
-        global $wpdb;
1539
-        self::drop_espresso_tables();
1540
-        $wp_options_to_delete = array(
1541
-            'ee_no_ticket_prices'                => true,
1542
-            'ee_active_messengers'               => true,
1543
-            'ee_has_activated_messenger'         => true,
1544
-            RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true,
1545
-            'ee_config'                          => false,
1546
-            'ee_data_migration_current_db_state' => true,
1547
-            'ee_data_migration_mapping_'         => false,
1548
-            'ee_data_migration_script_'          => false,
1549
-            'ee_data_migrations'                 => true,
1550
-            'ee_dms_map'                         => false,
1551
-            'ee_notices'                         => true,
1552
-            'lang_file_check_'                   => false,
1553
-            'ee_maintenance_mode'                => true,
1554
-            'ee_ueip_optin'                      => true,
1555
-            'ee_ueip_has_notified'               => true,
1556
-            'ee_plugin_activation_errors'        => true,
1557
-            'ee_id_mapping_from'                 => false,
1558
-            'espresso_persistent_admin_notices'  => true,
1559
-            'ee_encryption_key'                  => true,
1560
-            'pue_force_upgrade_'                 => false,
1561
-            'pue_json_error_'                    => false,
1562
-            'pue_install_key_'                   => false,
1563
-            'pue_verification_error_'            => false,
1564
-            'pu_dismissed_upgrade_'              => false,
1565
-            'external_updates-'                  => false,
1566
-            'ee_extra_data'                      => true,
1567
-            'ee_ssn_'                            => false,
1568
-            'ee_rss_'                            => false,
1569
-            'ee_rte_n_tx_'                       => false,
1570
-            'ee_pers_admin_notices'              => true,
1571
-            'ee_job_parameters_'                 => false,
1572
-            'ee_upload_directories_incomplete'   => true,
1573
-            'ee_verified_db_collations'          => true,
1574
-        );
1575
-        if (is_main_site()) {
1576
-            $wp_options_to_delete['ee_network_config'] = true;
1577
-        }
1578
-        $undeleted_options = array();
1579
-        foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1580
-            if ($no_wildcard) {
1581
-                if (! delete_option($option_name)) {
1582
-                    $undeleted_options[] = $option_name;
1583
-                }
1584
-            } else {
1585
-                $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1586
-                foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1587
-                    if (! delete_option($option_name_from_wildcard)) {
1588
-                        $undeleted_options[] = $option_name_from_wildcard;
1589
-                    }
1590
-                }
1591
-            }
1592
-        }
1593
-        // also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1594
-        remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1595
-        if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1596
-            $db_update_sans_ee4 = array();
1597
-            foreach ($espresso_db_update as $version => $times_activated) {
1598
-                if ((string) $version[0] === '3') {// if its NON EE4
1599
-                    $db_update_sans_ee4[ $version ] = $times_activated;
1600
-                }
1601
-            }
1602
-            update_option('espresso_db_update', $db_update_sans_ee4);
1603
-        }
1604
-        $errors = '';
1605
-        if (! empty($undeleted_options)) {
1606
-            $errors .= sprintf(
1607
-                __('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1608
-                '<br/>',
1609
-                implode(',<br/>', $undeleted_options)
1610
-            );
1611
-        }
1612
-        if (! empty($errors)) {
1613
-            EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1614
-        }
1615
-    }
1616
-
1617
-    /**
1618
-     * Gets the mysql error code from the last used query by wpdb
1619
-     *
1620
-     * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1621
-     */
1622
-    public static function last_wpdb_error_code()
1623
-    {
1624
-        // phpcs:disable PHPCompatibility.PHP.RemovedExtensions.mysql_DeprecatedRemoved
1625
-        global $wpdb;
1626
-        if ($wpdb->use_mysqli) {
1627
-            return mysqli_errno($wpdb->dbh);
1628
-        } else {
1629
-            return mysql_errno($wpdb->dbh);
1630
-        }
1631
-        // phpcs:enable
1632
-    }
1633
-
1634
-    /**
1635
-     * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1636
-     *
1637
-     * @global wpdb  $wpdb
1638
-     * @deprecated instead use TableAnalysis::tableExists()
1639
-     * @param string $table_name with or without $wpdb->prefix
1640
-     * @return boolean
1641
-     */
1642
-    public static function table_exists($table_name)
1643
-    {
1644
-        return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1645
-    }
1646
-
1647
-    /**
1648
-     * Resets the cache on EEH_Activation
1649
-     */
1650
-    public static function reset()
1651
-    {
1652
-        self::$_default_creator_id                             = null;
1653
-        self::$_initialized_db_content_already_in_this_request = false;
1654
-    }
1225
+		$new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1226
+			$message_resource_manager
1227
+		);
1228
+		/**
1229
+		 * This method is verifying there are no NEW default message types
1230
+		 * for ACTIVE messengers that need activated (and corresponding templates setup).
1231
+		 */
1232
+		$new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1233
+			$message_resource_manager
1234
+		);
1235
+		// after all is done, let's persist these changes to the db.
1236
+		$message_resource_manager->update_has_activated_messengers_option();
1237
+		$message_resource_manager->update_active_messengers_option();
1238
+		// will return true if either of these are true.  Otherwise will return false.
1239
+		return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1240
+	}
1241
+
1242
+
1243
+
1244
+	/**
1245
+	 * @param \EE_Message_Resource_Manager $message_resource_manager
1246
+	 * @return array|bool
1247
+	 * @throws \EE_Error
1248
+	 */
1249
+	protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1250
+		EE_Message_Resource_Manager $message_resource_manager
1251
+	) {
1252
+		/** @type EE_messenger[] $active_messengers */
1253
+		$active_messengers = $message_resource_manager->active_messengers();
1254
+		$installed_message_types = $message_resource_manager->installed_message_types();
1255
+		$templates_created = false;
1256
+		foreach ($active_messengers as $active_messenger) {
1257
+			$default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1258
+			$default_message_type_names_to_activate = array();
1259
+			// looping through each default message type reported by the messenger
1260
+			// and setup the actual message types to activate.
1261
+			foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1262
+				// if already active or has already been activated before we skip
1263
+				// (otherwise we might reactivate something user's intentionally deactivated.)
1264
+				// we also skip if the message type is not installed.
1265
+				if ($message_resource_manager->has_message_type_been_activated_for_messenger(
1266
+					$default_message_type_name_for_messenger,
1267
+					$active_messenger->name
1268
+				)
1269
+					|| $message_resource_manager->is_message_type_active_for_messenger(
1270
+						$active_messenger->name,
1271
+						$default_message_type_name_for_messenger
1272
+					)
1273
+					|| ! isset($installed_message_types[ $default_message_type_name_for_messenger ])
1274
+				) {
1275
+					continue;
1276
+				}
1277
+				$default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1278
+			}
1279
+			// let's activate!
1280
+			$message_resource_manager->ensure_message_types_are_active(
1281
+				$default_message_type_names_to_activate,
1282
+				$active_messenger->name,
1283
+				false
1284
+			);
1285
+			// activate the templates for these message types
1286
+			if (! empty($default_message_type_names_to_activate)) {
1287
+				$templates_created = EEH_MSG_Template::generate_new_templates(
1288
+					$active_messenger->name,
1289
+					$default_message_type_names_for_messenger,
1290
+					'',
1291
+					true
1292
+				);
1293
+			}
1294
+		}
1295
+		return $templates_created;
1296
+	}
1297
+
1298
+
1299
+
1300
+	/**
1301
+	 * This will activate and generate default messengers and default message types for those messengers.
1302
+	 *
1303
+	 * @param EE_message_Resource_Manager $message_resource_manager
1304
+	 * @return array|bool  True means there were default messengers and message type templates generated.
1305
+	 *                     False means that there were no templates generated
1306
+	 *                     (which could simply mean there are no default message types for a messenger).
1307
+	 * @throws EE_Error
1308
+	 */
1309
+	protected static function _activate_and_generate_default_messengers_and_message_templates(
1310
+		EE_Message_Resource_Manager $message_resource_manager
1311
+	) {
1312
+		/** @type EE_messenger[] $messengers_to_generate */
1313
+		$messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1314
+		$installed_message_types = $message_resource_manager->installed_message_types();
1315
+		$templates_generated = false;
1316
+		foreach ($messengers_to_generate as $messenger_to_generate) {
1317
+			$default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1318
+			// verify the default message types match an installed message type.
1319
+			foreach ($default_message_type_names_for_messenger as $key => $name) {
1320
+				if (! isset($installed_message_types[ $name ])
1321
+					|| $message_resource_manager->has_message_type_been_activated_for_messenger(
1322
+						$name,
1323
+						$messenger_to_generate->name
1324
+					)
1325
+				) {
1326
+					unset($default_message_type_names_for_messenger[ $key ]);
1327
+				}
1328
+			}
1329
+			// in previous iterations, the active_messengers option in the db
1330
+			// needed updated before calling create templates. however with the changes this may not be necessary.
1331
+			// This comment is left here just in case we discover that we _do_ need to update before
1332
+			// passing off to create templates (after the refactor is done).
1333
+			// @todo remove this comment when determined not necessary.
1334
+			$message_resource_manager->activate_messenger(
1335
+				$messenger_to_generate->name,
1336
+				$default_message_type_names_for_messenger,
1337
+				false
1338
+			);
1339
+			// create any templates needing created (or will reactivate templates already generated as necessary).
1340
+			if (! empty($default_message_type_names_for_messenger)) {
1341
+				$templates_generated = EEH_MSG_Template::generate_new_templates(
1342
+					$messenger_to_generate->name,
1343
+					$default_message_type_names_for_messenger,
1344
+					'',
1345
+					true
1346
+				);
1347
+			}
1348
+		}
1349
+		return $templates_generated;
1350
+	}
1351
+
1352
+
1353
+	/**
1354
+	 * This returns the default messengers to generate templates for on activation of EE.
1355
+	 * It considers:
1356
+	 * - whether a messenger is already active in the db.
1357
+	 * - whether a messenger has been made active at any time in the past.
1358
+	 *
1359
+	 * @static
1360
+	 * @param  EE_Message_Resource_Manager $message_resource_manager
1361
+	 * @return EE_messenger[]
1362
+	 */
1363
+	protected static function _get_default_messengers_to_generate_on_activation(
1364
+		EE_Message_Resource_Manager $message_resource_manager
1365
+	) {
1366
+		$active_messengers    = $message_resource_manager->active_messengers();
1367
+		$installed_messengers = $message_resource_manager->installed_messengers();
1368
+		$has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1369
+
1370
+		$messengers_to_generate = array();
1371
+		foreach ($installed_messengers as $installed_messenger) {
1372
+			// if installed messenger is a messenger that should be activated on install
1373
+			// and is not already active
1374
+			// and has never been activated
1375
+			if (! $installed_messenger->activate_on_install
1376
+				|| isset($active_messengers[ $installed_messenger->name ])
1377
+				|| isset($has_activated[ $installed_messenger->name ])
1378
+			) {
1379
+				continue;
1380
+			}
1381
+			$messengers_to_generate[ $installed_messenger->name ] = $installed_messenger;
1382
+		}
1383
+		return $messengers_to_generate;
1384
+	}
1385
+
1386
+
1387
+	/**
1388
+	 * This simply validates active message types to ensure they actually match installed
1389
+	 * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1390
+	 * rows are set inactive.
1391
+	 * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1392
+	 * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1393
+	 * are still handled in here.
1394
+	 *
1395
+	 * @since 4.3.1
1396
+	 * @return void
1397
+	 */
1398
+	public static function validate_messages_system()
1399
+	{
1400
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1401
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1402
+		$message_resource_manager->validate_active_message_types_are_installed();
1403
+		do_action('AHEE__EEH_Activation__validate_messages_system');
1404
+	}
1405
+
1406
+
1407
+	/**
1408
+	 * create_no_ticket_prices_array
1409
+	 *
1410
+	 * @access public
1411
+	 * @static
1412
+	 * @return void
1413
+	 */
1414
+	public static function create_no_ticket_prices_array()
1415
+	{
1416
+		// this creates an array for tracking events that have no active ticket prices created
1417
+		// this allows us to warn admins of the situation so that it can be corrected
1418
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1419
+		if (! $espresso_no_ticket_prices) {
1420
+			add_option('ee_no_ticket_prices', array(), '', false);
1421
+		}
1422
+	}
1423
+
1424
+
1425
+	/**
1426
+	 * plugin_deactivation
1427
+	 *
1428
+	 * @access public
1429
+	 * @static
1430
+	 * @return void
1431
+	 */
1432
+	public static function plugin_deactivation()
1433
+	{
1434
+	}
1435
+
1436
+
1437
+	/**
1438
+	 * Finds all our EE4 custom post types, and deletes them and their associated data
1439
+	 * (like post meta or term relations)
1440
+	 *
1441
+	 * @global wpdb $wpdb
1442
+	 * @throws \EE_Error
1443
+	 */
1444
+	public static function delete_all_espresso_cpt_data()
1445
+	{
1446
+		global $wpdb;
1447
+		// get all the CPT post_types
1448
+		$ee_post_types = array();
1449
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1450
+			if (method_exists($model_name, 'instance')) {
1451
+				$model_obj = call_user_func(array($model_name, 'instance'));
1452
+				if ($model_obj instanceof EEM_CPT_Base) {
1453
+					$ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1454
+				}
1455
+			}
1456
+		}
1457
+		// get all our CPTs
1458
+		$query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1459
+		$cpt_ids = $wpdb->get_col($query);
1460
+		// delete each post meta and term relations too
1461
+		foreach ($cpt_ids as $post_id) {
1462
+			wp_delete_post($post_id, true);
1463
+		}
1464
+	}
1465
+
1466
+	/**
1467
+	 * Deletes all EE custom tables
1468
+	 *
1469
+	 * @return array
1470
+	 */
1471
+	public static function drop_espresso_tables()
1472
+	{
1473
+		$tables = array();
1474
+		// load registry
1475
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1476
+			if (method_exists($model_name, 'instance')) {
1477
+				$model_obj = call_user_func(array($model_name, 'instance'));
1478
+				if ($model_obj instanceof EEM_Base) {
1479
+					foreach ($model_obj->get_tables() as $table) {
1480
+						if (strpos($table->get_table_name(), 'esp_')
1481
+							&&
1482
+							(
1483
+								is_main_site()// main site? nuke them all
1484
+								|| ! $table->is_global()// not main site,but not global either. nuke it
1485
+							)
1486
+						) {
1487
+							$tables[ $table->get_table_name() ] = $table->get_table_name();
1488
+						}
1489
+					}
1490
+				}
1491
+			}
1492
+		}
1493
+
1494
+		// there are some tables whose models were removed.
1495
+		// they should be removed when removing all EE core's data
1496
+		$tables_without_models = array(
1497
+			'esp_promotion',
1498
+			'esp_promotion_applied',
1499
+			'esp_promotion_object',
1500
+			'esp_promotion_rule',
1501
+			'esp_rule',
1502
+		);
1503
+		foreach ($tables_without_models as $table) {
1504
+			$tables[ $table ] = $table;
1505
+		}
1506
+		return \EEH_Activation::getTableManager()->dropTables($tables);
1507
+	}
1508
+
1509
+
1510
+
1511
+	/**
1512
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
1513
+	 * each table name provided has a wpdb prefix attached, and that it exists.
1514
+	 * Returns the list actually deleted
1515
+	 *
1516
+	 * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1517
+	 * @global WPDB $wpdb
1518
+	 * @param array $table_names
1519
+	 * @return array of table names which we deleted
1520
+	 */
1521
+	public static function drop_tables($table_names)
1522
+	{
1523
+		return \EEH_Activation::getTableManager()->dropTables($table_names);
1524
+	}
1525
+
1526
+
1527
+
1528
+	/**
1529
+	 * plugin_uninstall
1530
+	 *
1531
+	 * @access public
1532
+	 * @static
1533
+	 * @param bool $remove_all
1534
+	 * @return void
1535
+	 */
1536
+	public static function delete_all_espresso_tables_and_data($remove_all = true)
1537
+	{
1538
+		global $wpdb;
1539
+		self::drop_espresso_tables();
1540
+		$wp_options_to_delete = array(
1541
+			'ee_no_ticket_prices'                => true,
1542
+			'ee_active_messengers'               => true,
1543
+			'ee_has_activated_messenger'         => true,
1544
+			RewriteRules::OPTION_KEY_FLUSH_REWRITE_RULES => true,
1545
+			'ee_config'                          => false,
1546
+			'ee_data_migration_current_db_state' => true,
1547
+			'ee_data_migration_mapping_'         => false,
1548
+			'ee_data_migration_script_'          => false,
1549
+			'ee_data_migrations'                 => true,
1550
+			'ee_dms_map'                         => false,
1551
+			'ee_notices'                         => true,
1552
+			'lang_file_check_'                   => false,
1553
+			'ee_maintenance_mode'                => true,
1554
+			'ee_ueip_optin'                      => true,
1555
+			'ee_ueip_has_notified'               => true,
1556
+			'ee_plugin_activation_errors'        => true,
1557
+			'ee_id_mapping_from'                 => false,
1558
+			'espresso_persistent_admin_notices'  => true,
1559
+			'ee_encryption_key'                  => true,
1560
+			'pue_force_upgrade_'                 => false,
1561
+			'pue_json_error_'                    => false,
1562
+			'pue_install_key_'                   => false,
1563
+			'pue_verification_error_'            => false,
1564
+			'pu_dismissed_upgrade_'              => false,
1565
+			'external_updates-'                  => false,
1566
+			'ee_extra_data'                      => true,
1567
+			'ee_ssn_'                            => false,
1568
+			'ee_rss_'                            => false,
1569
+			'ee_rte_n_tx_'                       => false,
1570
+			'ee_pers_admin_notices'              => true,
1571
+			'ee_job_parameters_'                 => false,
1572
+			'ee_upload_directories_incomplete'   => true,
1573
+			'ee_verified_db_collations'          => true,
1574
+		);
1575
+		if (is_main_site()) {
1576
+			$wp_options_to_delete['ee_network_config'] = true;
1577
+		}
1578
+		$undeleted_options = array();
1579
+		foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1580
+			if ($no_wildcard) {
1581
+				if (! delete_option($option_name)) {
1582
+					$undeleted_options[] = $option_name;
1583
+				}
1584
+			} else {
1585
+				$option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1586
+				foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1587
+					if (! delete_option($option_name_from_wildcard)) {
1588
+						$undeleted_options[] = $option_name_from_wildcard;
1589
+					}
1590
+				}
1591
+			}
1592
+		}
1593
+		// also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1594
+		remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1595
+		if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1596
+			$db_update_sans_ee4 = array();
1597
+			foreach ($espresso_db_update as $version => $times_activated) {
1598
+				if ((string) $version[0] === '3') {// if its NON EE4
1599
+					$db_update_sans_ee4[ $version ] = $times_activated;
1600
+				}
1601
+			}
1602
+			update_option('espresso_db_update', $db_update_sans_ee4);
1603
+		}
1604
+		$errors = '';
1605
+		if (! empty($undeleted_options)) {
1606
+			$errors .= sprintf(
1607
+				__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1608
+				'<br/>',
1609
+				implode(',<br/>', $undeleted_options)
1610
+			);
1611
+		}
1612
+		if (! empty($errors)) {
1613
+			EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1614
+		}
1615
+	}
1616
+
1617
+	/**
1618
+	 * Gets the mysql error code from the last used query by wpdb
1619
+	 *
1620
+	 * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1621
+	 */
1622
+	public static function last_wpdb_error_code()
1623
+	{
1624
+		// phpcs:disable PHPCompatibility.PHP.RemovedExtensions.mysql_DeprecatedRemoved
1625
+		global $wpdb;
1626
+		if ($wpdb->use_mysqli) {
1627
+			return mysqli_errno($wpdb->dbh);
1628
+		} else {
1629
+			return mysql_errno($wpdb->dbh);
1630
+		}
1631
+		// phpcs:enable
1632
+	}
1633
+
1634
+	/**
1635
+	 * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1636
+	 *
1637
+	 * @global wpdb  $wpdb
1638
+	 * @deprecated instead use TableAnalysis::tableExists()
1639
+	 * @param string $table_name with or without $wpdb->prefix
1640
+	 * @return boolean
1641
+	 */
1642
+	public static function table_exists($table_name)
1643
+	{
1644
+		return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1645
+	}
1646
+
1647
+	/**
1648
+	 * Resets the cache on EEH_Activation
1649
+	 */
1650
+	public static function reset()
1651
+	{
1652
+		self::$_default_creator_id                             = null;
1653
+		self::$_initialized_db_content_already_in_this_request = false;
1654
+	}
1655 1655
 }
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
      */
55 55
     public static function getTableAnalysis()
56 56
     {
57
-        if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
57
+        if ( ! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
58 58
             self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
59 59
         }
60 60
         return self::$table_analysis;
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      */
67 67
     public static function getTableManager()
68 68
     {
69
-        if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
69
+        if ( ! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
70 70
             self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
71 71
         }
72 72
         return self::$table_manager;
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
         if ($which_to_include === 'old') {
181 181
             $cron_tasks = array_filter(
182 182
                 $cron_tasks,
183
-                function ($value) {
183
+                function($value) {
184 184
                     return $value === EEH_Activation::cron_task_no_longer_in_use;
185 185
                 }
186 186
             );
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
     {
211 211
 
212 212
         foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
213
-            if (! wp_next_scheduled($hook_name)) {
213
+            if ( ! wp_next_scheduled($hook_name)) {
214 214
                 /**
215 215
                  * This allows client code to define the initial start timestamp for this schedule.
216 216
                  */
@@ -261,15 +261,15 @@  discard block
 block discarded – undo
261 261
         foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
262 262
             if (is_array($hooks_to_fire_at_time)) {
263 263
                 foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
264
-                    if (isset($ee_cron_tasks_to_remove[ $hook_name ])
265
-                        && is_array($ee_cron_tasks_to_remove[ $hook_name ])
264
+                    if (isset($ee_cron_tasks_to_remove[$hook_name])
265
+                        && is_array($ee_cron_tasks_to_remove[$hook_name])
266 266
                     ) {
267
-                        unset($crons[ $timestamp ][ $hook_name ]);
267
+                        unset($crons[$timestamp][$hook_name]);
268 268
                     }
269 269
                 }
270 270
                 // also take care of any empty cron timestamps.
271 271
                 if (empty($hooks_to_fire_at_time)) {
272
-                    unset($crons[ $timestamp ]);
272
+                    unset($crons[$timestamp]);
273 273
                 }
274 274
             }
275 275
         }
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
             3
315 315
         );
316 316
         // EE_Config::reset();
317
-        if (! EE_Config::logging_enabled()) {
317
+        if ( ! EE_Config::logging_enabled()) {
318 318
             delete_option(EE_Config::LOG_NAME);
319 319
         }
320 320
     }
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
     public static function load_calendar_config()
330 330
     {
331 331
         // grab array of all plugin folders and loop thru it
332
-        $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
332
+        $plugins = glob(WP_PLUGIN_DIR.DS.'*', GLOB_ONLYDIR);
333 333
         if (empty($plugins)) {
334 334
             return;
335 335
         }
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
                 || strpos($plugin, 'calendar') !== false
346 346
             ) {
347 347
                 // this is what we are looking for
348
-                $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
348
+                $calendar_config = $plugin_path.DS.'EE_Calendar_Config.php';
349 349
                 // does it exist in this folder ?
350 350
                 if (is_readable($calendar_config)) {
351 351
                     // YEAH! let's load it
@@ -472,7 +472,7 @@  discard block
 block discarded – undo
472 472
             ) {
473 473
                 // update Config with post ID
474 474
                 $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
475
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
475
+                if ( ! EE_Config::instance()->update_espresso_config(false, false)) {
476 476
                     $msg = __(
477 477
                         'The Event Espresso critical page configuration settings could not be updated.',
478 478
                         'event_espresso'
@@ -495,7 +495,7 @@  discard block
 block discarded – undo
495 495
                         'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
496 496
                         'event_espresso'
497 497
                     ),
498
-                    '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
498
+                    '<a href="'.admin_url('admin.php?page=espresso_general_settings&action=critical_pages').'">'
499 499
                     . __('Event Espresso Critical Pages Settings', 'event_espresso')
500 500
                     . '</a>'
501 501
                 )
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
     public static function get_page_by_ee_shortcode($ee_shortcode)
522 522
     {
523 523
         global $wpdb;
524
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
524
+        $shortcode_and_opening_bracket = '['.$ee_shortcode;
525 525
         $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
526 526
         if ($post_id) {
527 527
             return get_post($post_id);
@@ -547,11 +547,11 @@  discard block
 block discarded – undo
547 547
             'post_status'    => 'publish',
548 548
             'post_type'      => 'page',
549 549
             'comment_status' => 'closed',
550
-            'post_content'   => '[' . $critical_page['code'] . ']',
550
+            'post_content'   => '['.$critical_page['code'].']',
551 551
         );
552 552
 
553 553
         $post_id = wp_insert_post($post_args);
554
-        if (! $post_id) {
554
+        if ( ! $post_id) {
555 555
             $msg = sprintf(
556 556
                 __('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
557 557
                 $critical_page['name']
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
             return $critical_page;
561 561
         }
562 562
         // get newly created post's details
563
-        if (! $critical_page['post'] = get_post($post_id)) {
563
+        if ( ! $critical_page['post'] = get_post($post_id)) {
564 564
             $msg = sprintf(
565 565
                 __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
566 566
                 $critical_page['name']
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
     public static function get_default_creator_id()
586 586
     {
587 587
         global $wpdb;
588
-        if (! empty(self::$_default_creator_id)) {
588
+        if ( ! empty(self::$_default_creator_id)) {
589 589
             return self::$_default_creator_id;
590 590
         }/**/
591 591
         $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
         $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
602 602
         $query = $wpdb->prepare(
603 603
             "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
604
-            '%' . $role_to_check . '%'
604
+            '%'.$role_to_check.'%'
605 605
         );
606 606
         $user_id = $wpdb->get_var($query);
607 607
         $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
@@ -640,8 +640,8 @@  discard block
 block discarded – undo
640 640
             return;
641 641
         }
642 642
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
643
-        if (! function_exists('dbDelta')) {
644
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
643
+        if ( ! function_exists('dbDelta')) {
644
+            require_once(ABSPATH.'wp-admin/includes/upgrade.php');
645 645
         }
646 646
         $tableAnalysis = \EEH_Activation::getTableAnalysis();
647 647
         $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
@@ -650,9 +650,9 @@  discard block
 block discarded – undo
650 650
             // ok, delete the table... but ONLY if it's empty
651 651
             $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
652 652
             // table is NOT empty, are you SURE you want to delete this table ???
653
-            if (! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
653
+            if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
654 654
                 \EEH_Activation::getTableManager()->dropTable($wp_table_name);
655
-            } elseif (! $deleted_safely) {
655
+            } elseif ( ! $deleted_safely) {
656 656
                 // so we should be more cautious rather than just dropping tables so easily
657 657
                 error_log(
658 658
                     sprintf(
@@ -852,13 +852,13 @@  discard block
 block discarded – undo
852 852
             // reset values array
853 853
             $QSG_values = array();
854 854
             // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
855
-            if (! in_array("$QSG_system", $question_groups)) {
855
+            if ( ! in_array("$QSG_system", $question_groups)) {
856 856
                 // add it
857 857
                 switch ($QSG_system) {
858 858
                     case 1:
859 859
                         $QSG_values = array(
860 860
                             'QSG_name'            => __('Personal Information', 'event_espresso'),
861
-                            'QSG_identifier'      => 'personal-information-' . time(),
861
+                            'QSG_identifier'      => 'personal-information-'.time(),
862 862
                             'QSG_desc'            => '',
863 863
                             'QSG_order'           => 1,
864 864
                             'QSG_show_group_name' => 1,
@@ -870,7 +870,7 @@  discard block
 block discarded – undo
870 870
                     case 2:
871 871
                         $QSG_values = array(
872 872
                             'QSG_name'            => __('Address Information', 'event_espresso'),
873
-                            'QSG_identifier'      => 'address-information-' . time(),
873
+                            'QSG_identifier'      => 'address-information-'.time(),
874 874
                             'QSG_desc'            => '',
875 875
                             'QSG_order'           => 2,
876 876
                             'QSG_show_group_name' => 1,
@@ -881,14 +881,14 @@  discard block
 block discarded – undo
881 881
                         break;
882 882
                 }
883 883
                 // make sure we have some values before inserting them
884
-                if (! empty($QSG_values)) {
884
+                if ( ! empty($QSG_values)) {
885 885
                     // insert system question
886 886
                     $wpdb->insert(
887 887
                         $table_name,
888 888
                         $QSG_values,
889 889
                         array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
890 890
                     );
891
-                    $QSG_IDs[ $QSG_system ] = $wpdb->insert_id;
891
+                    $QSG_IDs[$QSG_system] = $wpdb->insert_id;
892 892
                 }
893 893
             }
894 894
         }
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
             // reset values array
919 919
             $QST_values = array();
920 920
             // if we don't have what we should have
921
-            if (! in_array($QST_system, $questions)) {
921
+            if ( ! in_array($QST_system, $questions)) {
922 922
                 // add it
923 923
                 switch ($QST_system) {
924 924
                     case 'fname':
@@ -1070,7 +1070,7 @@  discard block
 block discarded – undo
1070 1070
                         );
1071 1071
                         break;
1072 1072
                 }
1073
-                if (! empty($QST_values)) {
1073
+                if ( ! empty($QST_values)) {
1074 1074
                     // insert system question
1075 1075
                     $wpdb->insert(
1076 1076
                         $table_name,
@@ -1084,8 +1084,8 @@  discard block
 block discarded – undo
1084 1084
                     } else {
1085 1085
                         $system_question_we_want = EEM_Question_Group::system_address;
1086 1086
                     }
1087
-                    if (isset($QSG_IDs[ $system_question_we_want ])) {
1088
-                        $QSG_ID = $QSG_IDs[ $system_question_we_want ];
1087
+                    if (isset($QSG_IDs[$system_question_we_want])) {
1088
+                        $QSG_ID = $QSG_IDs[$system_question_we_want];
1089 1089
                     } else {
1090 1090
                         $id_col = EEM_Question_Group::instance()
1091 1091
                                                     ->get_col(array(array('QSG_system' => $system_question_we_want)));
@@ -1133,7 +1133,7 @@  discard block
 block discarded – undo
1133 1133
      */
1134 1134
     public static function insert_default_payment_methods()
1135 1135
     {
1136
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1136
+        if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1137 1137
             EE_Registry::instance()->load_lib('Payment_Method_Manager');
1138 1138
             EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1139 1139
         } else {
@@ -1270,7 +1270,7 @@  discard block
 block discarded – undo
1270 1270
                         $active_messenger->name,
1271 1271
                         $default_message_type_name_for_messenger
1272 1272
                     )
1273
-                    || ! isset($installed_message_types[ $default_message_type_name_for_messenger ])
1273
+                    || ! isset($installed_message_types[$default_message_type_name_for_messenger])
1274 1274
                 ) {
1275 1275
                     continue;
1276 1276
                 }
@@ -1283,7 +1283,7 @@  discard block
 block discarded – undo
1283 1283
                 false
1284 1284
             );
1285 1285
             // activate the templates for these message types
1286
-            if (! empty($default_message_type_names_to_activate)) {
1286
+            if ( ! empty($default_message_type_names_to_activate)) {
1287 1287
                 $templates_created = EEH_MSG_Template::generate_new_templates(
1288 1288
                     $active_messenger->name,
1289 1289
                     $default_message_type_names_for_messenger,
@@ -1317,13 +1317,13 @@  discard block
 block discarded – undo
1317 1317
             $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1318 1318
             // verify the default message types match an installed message type.
1319 1319
             foreach ($default_message_type_names_for_messenger as $key => $name) {
1320
-                if (! isset($installed_message_types[ $name ])
1320
+                if ( ! isset($installed_message_types[$name])
1321 1321
                     || $message_resource_manager->has_message_type_been_activated_for_messenger(
1322 1322
                         $name,
1323 1323
                         $messenger_to_generate->name
1324 1324
                     )
1325 1325
                 ) {
1326
-                    unset($default_message_type_names_for_messenger[ $key ]);
1326
+                    unset($default_message_type_names_for_messenger[$key]);
1327 1327
                 }
1328 1328
             }
1329 1329
             // in previous iterations, the active_messengers option in the db
@@ -1337,7 +1337,7 @@  discard block
 block discarded – undo
1337 1337
                 false
1338 1338
             );
1339 1339
             // create any templates needing created (or will reactivate templates already generated as necessary).
1340
-            if (! empty($default_message_type_names_for_messenger)) {
1340
+            if ( ! empty($default_message_type_names_for_messenger)) {
1341 1341
                 $templates_generated = EEH_MSG_Template::generate_new_templates(
1342 1342
                     $messenger_to_generate->name,
1343 1343
                     $default_message_type_names_for_messenger,
@@ -1372,13 +1372,13 @@  discard block
 block discarded – undo
1372 1372
             // if installed messenger is a messenger that should be activated on install
1373 1373
             // and is not already active
1374 1374
             // and has never been activated
1375
-            if (! $installed_messenger->activate_on_install
1376
-                || isset($active_messengers[ $installed_messenger->name ])
1377
-                || isset($has_activated[ $installed_messenger->name ])
1375
+            if ( ! $installed_messenger->activate_on_install
1376
+                || isset($active_messengers[$installed_messenger->name])
1377
+                || isset($has_activated[$installed_messenger->name])
1378 1378
             ) {
1379 1379
                 continue;
1380 1380
             }
1381
-            $messengers_to_generate[ $installed_messenger->name ] = $installed_messenger;
1381
+            $messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1382 1382
         }
1383 1383
         return $messengers_to_generate;
1384 1384
     }
@@ -1416,7 +1416,7 @@  discard block
 block discarded – undo
1416 1416
         // this creates an array for tracking events that have no active ticket prices created
1417 1417
         // this allows us to warn admins of the situation so that it can be corrected
1418 1418
         $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1419
-        if (! $espresso_no_ticket_prices) {
1419
+        if ( ! $espresso_no_ticket_prices) {
1420 1420
             add_option('ee_no_ticket_prices', array(), '', false);
1421 1421
         }
1422 1422
     }
@@ -1455,7 +1455,7 @@  discard block
 block discarded – undo
1455 1455
             }
1456 1456
         }
1457 1457
         // get all our CPTs
1458
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1458
+        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")";
1459 1459
         $cpt_ids = $wpdb->get_col($query);
1460 1460
         // delete each post meta and term relations too
1461 1461
         foreach ($cpt_ids as $post_id) {
@@ -1484,7 +1484,7 @@  discard block
 block discarded – undo
1484 1484
                                 || ! $table->is_global()// not main site,but not global either. nuke it
1485 1485
                             )
1486 1486
                         ) {
1487
-                            $tables[ $table->get_table_name() ] = $table->get_table_name();
1487
+                            $tables[$table->get_table_name()] = $table->get_table_name();
1488 1488
                         }
1489 1489
                     }
1490 1490
                 }
@@ -1501,7 +1501,7 @@  discard block
 block discarded – undo
1501 1501
             'esp_rule',
1502 1502
         );
1503 1503
         foreach ($tables_without_models as $table) {
1504
-            $tables[ $table ] = $table;
1504
+            $tables[$table] = $table;
1505 1505
         }
1506 1506
         return \EEH_Activation::getTableManager()->dropTables($tables);
1507 1507
     }
@@ -1578,13 +1578,13 @@  discard block
 block discarded – undo
1578 1578
         $undeleted_options = array();
1579 1579
         foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1580 1580
             if ($no_wildcard) {
1581
-                if (! delete_option($option_name)) {
1581
+                if ( ! delete_option($option_name)) {
1582 1582
                     $undeleted_options[] = $option_name;
1583 1583
                 }
1584 1584
             } else {
1585 1585
                 $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1586 1586
                 foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1587
-                    if (! delete_option($option_name_from_wildcard)) {
1587
+                    if ( ! delete_option($option_name_from_wildcard)) {
1588 1588
                         $undeleted_options[] = $option_name_from_wildcard;
1589 1589
                     }
1590 1590
                 }
@@ -1596,20 +1596,20 @@  discard block
 block discarded – undo
1596 1596
             $db_update_sans_ee4 = array();
1597 1597
             foreach ($espresso_db_update as $version => $times_activated) {
1598 1598
                 if ((string) $version[0] === '3') {// if its NON EE4
1599
-                    $db_update_sans_ee4[ $version ] = $times_activated;
1599
+                    $db_update_sans_ee4[$version] = $times_activated;
1600 1600
                 }
1601 1601
             }
1602 1602
             update_option('espresso_db_update', $db_update_sans_ee4);
1603 1603
         }
1604 1604
         $errors = '';
1605
-        if (! empty($undeleted_options)) {
1605
+        if ( ! empty($undeleted_options)) {
1606 1606
             $errors .= sprintf(
1607 1607
                 __('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1608 1608
                 '<br/>',
1609 1609
                 implode(',<br/>', $undeleted_options)
1610 1610
             );
1611 1611
         }
1612
-        if (! empty($errors)) {
1612
+        if ( ! empty($errors)) {
1613 1613
             EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1614 1614
         }
1615 1615
     }
Please login to merge, or discard this patch.
core/db_models/EEM_Datetime.model.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -529,7 +529,7 @@
 block discarded – undo
529 529
     /**
530 530
      * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
531 531
      *
532
-     * @param  array $stati_to_include If included you can restrict the statuses we return counts for by including the
532
+     * @param  string[] $stati_to_include If included you can restrict the statuses we return counts for by including the
533 533
      *                                 stati you want counts for as values in the array.  An empty array returns counts
534 534
      *                                 for all valid stati.
535 535
      * @param  array $query_params     If included can be used to refine the conditions for returning the count (i.e.
Please login to merge, or discard this patch.
Indentation   +743 added lines, -743 removed lines patch added patch discarded remove patch
@@ -13,747 +13,747 @@
 block discarded – undo
13 13
 class EEM_Datetime extends EEM_Soft_Delete_Base
14 14
 {
15 15
 
16
-    /**
17
-     * @var EEM_Datetime $_instance
18
-     */
19
-    protected static $_instance;
20
-
21
-
22
-    /**
23
-     * private constructor to prevent direct creation
24
-     *
25
-     * @param string $timezone A string representing the timezone we want to set for returned Date Time Strings
26
-     *                         (and any incoming timezone data that gets saved).
27
-     *                         Note this just sends the timezone info to the date time model field objects.
28
-     *                         Default is NULL
29
-     *                         (and will be assumed using the set timezone in the 'timezone_string' wp option)
30
-     * @throws EE_Error
31
-     * @throws InvalidArgumentException
32
-     * @throws InvalidArgumentException
33
-     */
34
-    protected function __construct($timezone)
35
-    {
36
-        $this->singular_item           = esc_html__('Datetime', 'event_espresso');
37
-        $this->plural_item             = esc_html__('Datetimes', 'event_espresso');
38
-        $this->_tables                 = array(
39
-            'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'),
40
-        );
41
-        $this->_fields                 = array(
42
-            'Datetime' => array(
43
-                'DTT_ID'          => new EE_Primary_Key_Int_Field(
44
-                    'DTT_ID',
45
-                    esc_html__('Datetime ID', 'event_espresso')
46
-                ),
47
-                'EVT_ID'          => new EE_Foreign_Key_Int_Field(
48
-                    'EVT_ID',
49
-                    esc_html__('Event ID', 'event_espresso'),
50
-                    false,
51
-                    0,
52
-                    'Event'
53
-                ),
54
-                'DTT_name'        => new EE_Plain_Text_Field(
55
-                    'DTT_name',
56
-                    esc_html__('Datetime Name', 'event_espresso'),
57
-                    false,
58
-                    ''
59
-                ),
60
-                'DTT_description' => new EE_Post_Content_Field(
61
-                    'DTT_description',
62
-                    esc_html__('Description for Datetime', 'event_espresso'),
63
-                    false,
64
-                    ''
65
-                ),
66
-                'DTT_EVT_start'   => new EE_Datetime_Field(
67
-                    'DTT_EVT_start',
68
-                    esc_html__('Start time/date of Event', 'event_espresso'),
69
-                    false,
70
-                    EE_Datetime_Field::now,
71
-                    $timezone
72
-                ),
73
-                'DTT_EVT_end'     => new EE_Datetime_Field(
74
-                    'DTT_EVT_end',
75
-                    esc_html__('End time/date of Event', 'event_espresso'),
76
-                    false,
77
-                    EE_Datetime_Field::now,
78
-                    $timezone
79
-                ),
80
-                'DTT_reg_limit'   => new EE_Infinite_Integer_Field(
81
-                    'DTT_reg_limit',
82
-                    esc_html__('Registration Limit for this time', 'event_espresso'),
83
-                    true,
84
-                    EE_INF
85
-                ),
86
-                'DTT_sold'        => new EE_Integer_Field(
87
-                    'DTT_sold',
88
-                    esc_html__('How many sales for this Datetime that have occurred', 'event_espresso'),
89
-                    true,
90
-                    0
91
-                ),
92
-                'DTT_reserved'    => new EE_Integer_Field(
93
-                    'DTT_reserved',
94
-                    esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'),
95
-                    false,
96
-                    0
97
-                ),
98
-                'DTT_is_primary'  => new EE_Boolean_Field(
99
-                    'DTT_is_primary',
100
-                    esc_html__('Flag indicating datetime is primary one for event', 'event_espresso'),
101
-                    false,
102
-                    false
103
-                ),
104
-                'DTT_order'       => new EE_Integer_Field(
105
-                    'DTT_order',
106
-                    esc_html__('The order in which the Datetime is displayed', 'event_espresso'),
107
-                    false,
108
-                    0
109
-                ),
110
-                'DTT_parent'      => new EE_Integer_Field(
111
-                    'DTT_parent',
112
-                    esc_html__('Indicates what DTT_ID is the parent of this DTT_ID', 'event_espresso'),
113
-                    true,
114
-                    0
115
-                ),
116
-                'DTT_deleted'     => new EE_Trashed_Flag_Field(
117
-                    'DTT_deleted',
118
-                    esc_html__('Flag indicating datetime is archived', 'event_espresso'),
119
-                    false,
120
-                    false
121
-                ),
122
-            ),
123
-        );
124
-        $this->_model_relations        = array(
125
-            'Ticket'  => new EE_HABTM_Relation('Datetime_Ticket'),
126
-            'Event'   => new EE_Belongs_To_Relation(),
127
-            'Checkin' => new EE_Has_Many_Relation(),
128
-            'Datetime_Ticket' => new EE_Has_Many_Relation(),
129
-        );
130
-        $path_to_event_model = 'Event';
131
-        $this->model_chain_to_password = $path_to_event_model;
132
-        $this->_model_chain_to_wp_user = $path_to_event_model;
133
-        // this model is generally available for reading
134
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       = new EE_Restriction_Generator_Event_Related_Public(
135
-            $path_to_event_model
136
-        );
137
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected(
138
-            $path_to_event_model
139
-        );
140
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       = new EE_Restriction_Generator_Event_Related_Protected(
141
-            $path_to_event_model
142
-        );
143
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     = new EE_Restriction_Generator_Event_Related_Protected(
144
-            $path_to_event_model,
145
-            EEM_Base::caps_edit
146
-        );
147
-        parent::__construct($timezone);
148
-    }
149
-
150
-
151
-    /**
152
-     * create new blank datetime
153
-     *
154
-     * @access public
155
-     * @return EE_Datetime[] array on success, FALSE on fail
156
-     * @throws EE_Error
157
-     * @throws InvalidArgumentException
158
-     * @throws InvalidDataTypeException
159
-     * @throws ReflectionException
160
-     * @throws InvalidInterfaceException
161
-     */
162
-    public function create_new_blank_datetime()
163
-    {
164
-        // makes sure timezone is always set.
165
-        $timezone_string = $this->get_timezone();
166
-        /**
167
-         * Filters the initial start date for the new datetime.
168
-         * Any time included in this value will be overridden later so use additional filters to modify the time.
169
-         *
170
-         * @param int $start_date Unixtimestamp representing now + 30 days in seconds.
171
-         * @return int unixtimestamp
172
-         */
173
-        $start_date = apply_filters(
174
-            'FHEE__EEM_Datetime__create_new_blank_datetime__start_date',
175
-            $this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS
176
-        );
177
-        /**
178
-         * Filters the initial end date for the new datetime.
179
-         * Any time included in this value will be overridden later so use additional filters to modify the time.
180
-         *
181
-         * @param int $end_data Unixtimestamp representing now + 30 days in seconds.
182
-         * @return int unixtimestamp
183
-         */
184
-        $end_date = apply_filters(
185
-            'FHEE__EEM_Datetime__create_new_blank_datetime__end_date',
186
-            $this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS
187
-        );
188
-        $blank_datetime = EE_Datetime::new_instance(
189
-            array(
190
-                'DTT_EVT_start' => $start_date,
191
-                'DTT_EVT_end'   => $end_date,
192
-                'DTT_order'     => 1,
193
-                'DTT_reg_limit' => EE_INF,
194
-            ),
195
-            $timezone_string
196
-        );
197
-        /**
198
-         * Filters the initial start time and format for the new EE_Datetime instance.
199
-         *
200
-         * @param array $start_time An array having size 2.  First element is the time, second element is the time
201
-         *                          format.
202
-         * @return array
203
-         */
204
-        $start_time = apply_filters(
205
-            'FHEE__EEM_Datetime__create_new_blank_datetime__start_time',
206
-            ['8am', 'ga']
207
-        );
208
-        /**
209
-         * Filters the initial end time and format for the new EE_Datetime instance.
210
-         *
211
-         * @param array $end_time An array having size 2.  First element is the time, second element is the time
212
-         *                        format
213
-         * @return array
214
-         */
215
-        $end_time = apply_filters(
216
-            'FHEE__EEM_Datetime__create_new_blank_datetime__end_time',
217
-            ['5pm', 'ga']
218
-        );
219
-        $this->validateStartAndEndTimeForBlankDate($start_time, $end_time);
220
-        $blank_datetime->set_start_time(
221
-            $this->convert_datetime_for_query(
222
-                'DTT_EVT_start',
223
-                $start_time[0],
224
-                $start_time[1],
225
-                $timezone_string
226
-            )
227
-        );
228
-        $blank_datetime->set_end_time(
229
-            $this->convert_datetime_for_query(
230
-                'DTT_EVT_end',
231
-                $end_time[0],
232
-                $end_time[1],
233
-                $timezone_string
234
-            )
235
-        );
236
-        return array($blank_datetime);
237
-    }
238
-
239
-
240
-    /**
241
-     * Validates whether the start_time and end_time are in the expected format.
242
-     * @param array $start_time
243
-     * @param array $end_time
244
-     * @throws InvalidArgumentException
245
-     * @throws InvalidDataTypeException
246
-     */
247
-    private function validateStartAndEndTimeForBlankDate($start_time, $end_time)
248
-    {
249
-        if (! is_array($start_time)) {
250
-            throw new InvalidDataTypeException('start_time', $start_time, 'array');
251
-        }
252
-        if (! is_array($end_time)) {
253
-            throw new InvalidDataTypeException('end_time', $end_time, 'array');
254
-        }
255
-        if (count($start_time) !== 2) {
256
-            throw new InvalidArgumentException(
257
-                sprintf(
258
-                    'The variable %1$s is expected to be an array with two elements.  The first item in the '
259
-                    . 'array should be a valid time string, the second item in the array should be a valid time format',
260
-                    '$start_time'
261
-                )
262
-            );
263
-        }
264
-        if (count($end_time) !== 2) {
265
-            throw new InvalidArgumentException(
266
-                sprintf(
267
-                    'The variable %1$s is expected to be an array with two elements.  The first item in the '
268
-                    . 'array should be a valid time string, the second item in the array should be a valid time format',
269
-                    '$end_time'
270
-                )
271
-            );
272
-        }
273
-    }
274
-
275
-
276
-    /**
277
-     * get event start date from db
278
-     *
279
-     * @access public
280
-     * @param  int $EVT_ID
281
-     * @return EE_Datetime[] array on success, FALSE on fail
282
-     * @throws EE_Error
283
-     */
284
-    public function get_all_event_dates($EVT_ID = 0)
285
-    {
286
-        if (! $EVT_ID) { // on add_new_event event_id gets set to 0
287
-            return $this->create_new_blank_datetime();
288
-        }
289
-        $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
290
-        if (empty($results)) {
291
-            return $this->create_new_blank_datetime();
292
-        }
293
-        return $results;
294
-    }
295
-
296
-
297
-    /**
298
-     * get all datetimes attached to an event ordered by the DTT_order field
299
-     *
300
-     * @public
301
-     * @param  int    $EVT_ID     event id
302
-     * @param boolean $include_expired
303
-     * @param boolean $include_deleted
304
-     * @param  int    $limit      If included then limit the count of results by
305
-     *                            the given number
306
-     * @return EE_Datetime[]
307
-     * @throws EE_Error
308
-     */
309
-    public function get_datetimes_for_event_ordered_by_DTT_order(
310
-        $EVT_ID,
311
-        $include_expired = true,
312
-        $include_deleted = true,
313
-        $limit = null
314
-    ) {
315
-        // sanitize EVT_ID
316
-        $EVT_ID         = absint($EVT_ID);
317
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
318
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
319
-        $where_params = array('Event.EVT_ID' => $EVT_ID);
320
-        $query_params = ! empty($limit)
321
-            ? array(
322
-                $where_params,
323
-                'limit'                    => $limit,
324
-                'order_by'                 => array('DTT_order' => 'ASC'),
325
-                'default_where_conditions' => 'none',
326
-            )
327
-            : array(
328
-                $where_params,
329
-                'order_by'                 => array('DTT_order' => 'ASC'),
330
-                'default_where_conditions' => 'none',
331
-            );
332
-        if (! $include_expired) {
333
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
334
-        }
335
-        if ($include_deleted) {
336
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
337
-        }
338
-        /** @var EE_Datetime[] $result */
339
-        $result = $this->get_all($query_params);
340
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
341
-        return $result;
342
-    }
343
-
344
-
345
-    /**
346
-     * Gets the datetimes for the event (with the given limit), and orders them by "importance".
347
-     * By importance, we mean that the primary datetimes are most important (DEPRECATED FOR NOW),
348
-     * and then the earlier datetimes are the most important.
349
-     * Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet.
350
-     *
351
-     * @param int $EVT_ID
352
-     * @param int $limit
353
-     * @return EE_Datetime[]|EE_Base_Class[]
354
-     * @throws EE_Error
355
-     */
356
-    public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null)
357
-    {
358
-        return $this->get_all(
359
-            array(
360
-                array('Event.EVT_ID' => $EVT_ID),
361
-                'limit'                    => $limit,
362
-                'order_by'                 => array('DTT_EVT_start' => 'ASC'),
363
-                'default_where_conditions' => 'none',
364
-            )
365
-        );
366
-    }
367
-
368
-
369
-    /**
370
-     * @param int     $EVT_ID
371
-     * @param boolean $include_expired
372
-     * @param boolean $include_deleted
373
-     * @return EE_Datetime
374
-     * @throws EE_Error
375
-     */
376
-    public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false)
377
-    {
378
-        $results = $this->get_datetimes_for_event_ordered_by_start_time(
379
-            $EVT_ID,
380
-            $include_expired,
381
-            $include_deleted,
382
-            1
383
-        );
384
-        if ($results) {
385
-            return array_shift($results);
386
-        }
387
-        return null;
388
-    }
389
-
390
-
391
-    /**
392
-     * Gets the 'primary' datetime for an event.
393
-     *
394
-     * @param int  $EVT_ID
395
-     * @param bool $try_to_exclude_expired
396
-     * @param bool $try_to_exclude_deleted
397
-     * @return \EE_Datetime
398
-     * @throws EE_Error
399
-     */
400
-    public function get_primary_datetime_for_event(
401
-        $EVT_ID,
402
-        $try_to_exclude_expired = true,
403
-        $try_to_exclude_deleted = true
404
-    ) {
405
-        if ($try_to_exclude_expired) {
406
-            $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
407
-            if ($non_expired) {
408
-                return $non_expired;
409
-            }
410
-        }
411
-        if ($try_to_exclude_deleted) {
412
-            $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
413
-            if ($expired_even) {
414
-                return $expired_even;
415
-            }
416
-        }
417
-        return $this->get_oldest_datetime_for_event($EVT_ID, true, true);
418
-    }
419
-
420
-
421
-    /**
422
-     * Gets ALL the datetimes for an event (including trashed ones, for now), ordered
423
-     * only by start date
424
-     *
425
-     * @param int     $EVT_ID
426
-     * @param boolean $include_expired
427
-     * @param boolean $include_deleted
428
-     * @param int     $limit
429
-     * @return EE_Datetime[]
430
-     * @throws EE_Error
431
-     */
432
-    public function get_datetimes_for_event_ordered_by_start_time(
433
-        $EVT_ID,
434
-        $include_expired = true,
435
-        $include_deleted = true,
436
-        $limit = null
437
-    ) {
438
-        // sanitize EVT_ID
439
-        $EVT_ID         = absint($EVT_ID);
440
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
441
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
442
-        $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
443
-        if (! $include_expired) {
444
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
445
-        }
446
-        if ($include_deleted) {
447
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
448
-        }
449
-        if ($limit) {
450
-            $query_params['limit'] = $limit;
451
-        }
452
-        /** @var EE_Datetime[] $result */
453
-        $result = $this->get_all($query_params);
454
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
455
-        return $result;
456
-    }
457
-
458
-
459
-    /**
460
-     * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
461
-     * only by start date
462
-     *
463
-     * @param int     $TKT_ID
464
-     * @param boolean $include_expired
465
-     * @param boolean $include_deleted
466
-     * @param int     $limit
467
-     * @return EE_Datetime[]
468
-     * @throws EE_Error
469
-     */
470
-    public function get_datetimes_for_ticket_ordered_by_start_time(
471
-        $TKT_ID,
472
-        $include_expired = true,
473
-        $include_deleted = true,
474
-        $limit = null
475
-    ) {
476
-        // sanitize TKT_ID
477
-        $TKT_ID         = absint($TKT_ID);
478
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
479
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
480
-        $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
481
-        if (! $include_expired) {
482
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
483
-        }
484
-        if ($include_deleted) {
485
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
486
-        }
487
-        if ($limit) {
488
-            $query_params['limit'] = $limit;
489
-        }
490
-        /** @var EE_Datetime[] $result */
491
-        $result = $this->get_all($query_params);
492
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
493
-        return $result;
494
-    }
495
-
496
-
497
-    /**
498
-     * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
499
-     * datetimes.
500
-     *
501
-     * @param  int      $TKT_ID          ID of ticket to retrieve the datetimes for
502
-     * @param  boolean  $include_expired whether to include expired datetimes or not
503
-     * @param  boolean  $include_deleted whether to include trashed datetimes or not.
504
-     * @param  int|null $limit           if null, no limit, if int then limit results by
505
-     *                                   that number
506
-     * @return EE_Datetime[]
507
-     * @throws EE_Error
508
-     */
509
-    public function get_datetimes_for_ticket_ordered_by_DTT_order(
510
-        $TKT_ID,
511
-        $include_expired = true,
512
-        $include_deleted = true,
513
-        $limit = null
514
-    ) {
515
-        // sanitize id.
516
-        $TKT_ID         = absint($TKT_ID);
517
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
518
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
519
-        $where_params = array('Ticket.TKT_ID' => $TKT_ID);
520
-        $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
521
-        if (! $include_expired) {
522
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
523
-        }
524
-        if ($include_deleted) {
525
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
526
-        }
527
-        if ($limit) {
528
-            $query_params['limit'] = $limit;
529
-        }
530
-        /** @var EE_Datetime[] $result */
531
-        $result = $this->get_all($query_params);
532
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
533
-        return $result;
534
-    }
535
-
536
-
537
-    /**
538
-     * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
539
-     * reason it doesn't exist, we consider the earliest event the most important)
540
-     *
541
-     * @param int $EVT_ID
542
-     * @return EE_Datetime
543
-     * @throws EE_Error
544
-     */
545
-    public function get_most_important_datetime_for_event($EVT_ID)
546
-    {
547
-        $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
548
-        if ($results) {
549
-            return array_shift($results);
550
-        }
551
-        return null;
552
-    }
553
-
554
-
555
-    /**
556
-     * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
557
-     * grouped by month and year.
558
-     *
559
-     * @param  array  $where_params      @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
560
-     * @param  string $evt_active_status A string representing the evt active status to filter the months by.
561
-     *                                   Can be:
562
-     *                                   - '' = no filter
563
-     *                                   - upcoming = Published events with at least one upcoming datetime.
564
-     *                                   - expired = Events with all datetimes expired.
565
-     *                                   - active = Events that are published and have at least one datetime that
566
-     *                                   starts before now and ends after now.
567
-     *                                   - inactive = Events that are either not published.
568
-     * @return EE_Base_Class[]
569
-     * @throws EE_Error
570
-     * @throws InvalidArgumentException
571
-     * @throws InvalidArgumentException
572
-     */
573
-    public function get_dtt_months_and_years($where_params, $evt_active_status = '')
574
-    {
575
-        $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
576
-        $current_time_for_DTT_EVT_end   = $this->current_time_for_query('DTT_EVT_end');
577
-        switch ($evt_active_status) {
578
-            case 'upcoming':
579
-                $where_params['Event.status'] = 'publish';
580
-                // if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
581
-                if (isset($where_params['DTT_EVT_start'])) {
582
-                    $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
583
-                }
584
-                $where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start);
585
-                break;
586
-            case 'expired':
587
-                if (isset($where_params['Event.status'])) {
588
-                    unset($where_params['Event.status']);
589
-                }
590
-                // get events to exclude
591
-                $exclude_query[0] = array_merge(
592
-                    $where_params,
593
-                    array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end))
594
-                );
595
-                // first get all events that have datetimes where its not expired.
596
-                $event_ids = $this->_get_all_wpdb_results(
597
-                    $exclude_query,
598
-                    OBJECT_K,
599
-                    'Datetime.EVT_ID'
600
-                );
601
-                $event_ids = array_keys($event_ids);
602
-                if (isset($where_params['DTT_EVT_end'])) {
603
-                    $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
604
-                }
605
-                $where_params['DTT_EVT_end']  = array('<', $current_time_for_DTT_EVT_end);
606
-                $where_params['Event.EVT_ID'] = array('NOT IN', $event_ids);
607
-                break;
608
-            case 'active':
609
-                $where_params['Event.status'] = 'publish';
610
-                if (isset($where_params['DTT_EVT_start'])) {
611
-                    $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
612
-                }
613
-                if (isset($where_params['Datetime.DTT_EVT_end'])) {
614
-                    $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
615
-                }
616
-                $where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start);
617
-                $where_params['DTT_EVT_end']   = array('>', $current_time_for_DTT_EVT_end);
618
-                break;
619
-            case 'inactive':
620
-                if (isset($where_params['Event.status'])) {
621
-                    unset($where_params['Event.status']);
622
-                }
623
-                if (isset($where_params['OR'])) {
624
-                    $where_params['AND']['OR'] = $where_params['OR'];
625
-                }
626
-                if (isset($where_params['DTT_EVT_end'])) {
627
-                    $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
628
-                    unset($where_params['DTT_EVT_end']);
629
-                }
630
-                if (isset($where_params['DTT_EVT_start'])) {
631
-                    $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
632
-                    unset($where_params['DTT_EVT_start']);
633
-                }
634
-                $where_params['AND']['Event.status'] = array('!=', 'publish');
635
-                break;
636
-        }
637
-        $query_params[0]          = $where_params;
638
-        $query_params['group_by'] = array('dtt_year', 'dtt_month');
639
-        $query_params['order_by'] = array('DTT_EVT_start' => 'DESC');
640
-        $query_interval           = EEH_DTT_Helper::get_sql_query_interval_for_offset(
641
-            $this->get_timezone(),
642
-            'DTT_EVT_start'
643
-        );
644
-        $columns_to_select        = array(
645
-            'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
646
-            'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
647
-            'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
648
-        );
649
-        return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
650
-    }
651
-
652
-
653
-    /**
654
-     * Updates the DTT_sold attribute on each datetime (based on the registrations
655
-     * for the tickets for each datetime)
656
-     *
657
-     * @param EE_Base_Class[]|EE_Datetime[] $datetimes
658
-     * @throws EE_Error
659
-     */
660
-    public function update_sold($datetimes)
661
-    {
662
-        EE_Error::doing_it_wrong(
663
-            __FUNCTION__,
664
-            esc_html__(
665
-                'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.',
666
-                'event_espresso'
667
-            ),
668
-            '4.9.32.rc.005'
669
-        );
670
-        foreach ($datetimes as $datetime) {
671
-            $datetime->update_sold();
672
-        }
673
-    }
674
-
675
-
676
-    /**
677
-     *    Gets the total number of tickets available at a particular datetime
678
-     *    (does NOT take into account the datetime's spaces available)
679
-     *
680
-     * @param int   $DTT_ID
681
-     * @param array $query_params
682
-     * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
683
-     *             tickets attached to datetime then FALSE is returned.
684
-     */
685
-    public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array())
686
-    {
687
-        $datetime = $this->get_one_by_ID($DTT_ID);
688
-        if ($datetime instanceof EE_Datetime) {
689
-            return $datetime->tickets_remaining($query_params);
690
-        }
691
-        return 0;
692
-    }
693
-
694
-
695
-    /**
696
-     * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
697
-     *
698
-     * @param  array $stati_to_include If included you can restrict the statuses we return counts for by including the
699
-     *                                 stati you want counts for as values in the array.  An empty array returns counts
700
-     *                                 for all valid stati.
701
-     * @param  array $query_params     If included can be used to refine the conditions for returning the count (i.e.
702
-     *                                 only for Datetimes connected to a specific event, or specific ticket.
703
-     * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
704
-     * @throws EE_Error
705
-     *                                 stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming
706
-     *                                 EE_Datetime::expired
707
-     */
708
-    public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array())
709
-    {
710
-        // only accept where conditions for this query.
711
-        $_where            = isset($query_params[0]) ? $query_params[0] : array();
712
-        $status_query_args = array(
713
-            EE_Datetime::active   => array_merge(
714
-                $_where,
715
-                array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time()))
716
-            ),
717
-            EE_Datetime::upcoming => array_merge(
718
-                $_where,
719
-                array('DTT_EVT_start' => array('>', time()))
720
-            ),
721
-            EE_Datetime::expired  => array_merge(
722
-                $_where,
723
-                array('DTT_EVT_end' => array('<', time()))
724
-            ),
725
-        );
726
-        if (! empty($stati_to_include)) {
727
-            foreach (array_keys($status_query_args) as $status) {
728
-                if (! in_array($status, $stati_to_include, true)) {
729
-                    unset($status_query_args[ $status ]);
730
-                }
731
-            }
732
-        }
733
-        // loop through and query counts for each stati.
734
-        $status_query_results = array();
735
-        foreach ($status_query_args as $status => $status_where_conditions) {
736
-            $status_query_results[ $status ] = EEM_Datetime::count(
737
-                array($status_where_conditions),
738
-                'DTT_ID',
739
-                true
740
-            );
741
-        }
742
-        return $status_query_results;
743
-    }
744
-
745
-
746
-    /**
747
-     * Returns the specific count for a given Datetime status matching any given query_params.
748
-     *
749
-     * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
750
-     * @param array  $query_params
751
-     * @return int
752
-     * @throws EE_Error
753
-     */
754
-    public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array())
755
-    {
756
-        $count = $this->get_datetime_counts_by_status(array($status), $query_params);
757
-        return ! empty($count[ $status ]) ? $count[ $status ] : 0;
758
-    }
16
+	/**
17
+	 * @var EEM_Datetime $_instance
18
+	 */
19
+	protected static $_instance;
20
+
21
+
22
+	/**
23
+	 * private constructor to prevent direct creation
24
+	 *
25
+	 * @param string $timezone A string representing the timezone we want to set for returned Date Time Strings
26
+	 *                         (and any incoming timezone data that gets saved).
27
+	 *                         Note this just sends the timezone info to the date time model field objects.
28
+	 *                         Default is NULL
29
+	 *                         (and will be assumed using the set timezone in the 'timezone_string' wp option)
30
+	 * @throws EE_Error
31
+	 * @throws InvalidArgumentException
32
+	 * @throws InvalidArgumentException
33
+	 */
34
+	protected function __construct($timezone)
35
+	{
36
+		$this->singular_item           = esc_html__('Datetime', 'event_espresso');
37
+		$this->plural_item             = esc_html__('Datetimes', 'event_espresso');
38
+		$this->_tables                 = array(
39
+			'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'),
40
+		);
41
+		$this->_fields                 = array(
42
+			'Datetime' => array(
43
+				'DTT_ID'          => new EE_Primary_Key_Int_Field(
44
+					'DTT_ID',
45
+					esc_html__('Datetime ID', 'event_espresso')
46
+				),
47
+				'EVT_ID'          => new EE_Foreign_Key_Int_Field(
48
+					'EVT_ID',
49
+					esc_html__('Event ID', 'event_espresso'),
50
+					false,
51
+					0,
52
+					'Event'
53
+				),
54
+				'DTT_name'        => new EE_Plain_Text_Field(
55
+					'DTT_name',
56
+					esc_html__('Datetime Name', 'event_espresso'),
57
+					false,
58
+					''
59
+				),
60
+				'DTT_description' => new EE_Post_Content_Field(
61
+					'DTT_description',
62
+					esc_html__('Description for Datetime', 'event_espresso'),
63
+					false,
64
+					''
65
+				),
66
+				'DTT_EVT_start'   => new EE_Datetime_Field(
67
+					'DTT_EVT_start',
68
+					esc_html__('Start time/date of Event', 'event_espresso'),
69
+					false,
70
+					EE_Datetime_Field::now,
71
+					$timezone
72
+				),
73
+				'DTT_EVT_end'     => new EE_Datetime_Field(
74
+					'DTT_EVT_end',
75
+					esc_html__('End time/date of Event', 'event_espresso'),
76
+					false,
77
+					EE_Datetime_Field::now,
78
+					$timezone
79
+				),
80
+				'DTT_reg_limit'   => new EE_Infinite_Integer_Field(
81
+					'DTT_reg_limit',
82
+					esc_html__('Registration Limit for this time', 'event_espresso'),
83
+					true,
84
+					EE_INF
85
+				),
86
+				'DTT_sold'        => new EE_Integer_Field(
87
+					'DTT_sold',
88
+					esc_html__('How many sales for this Datetime that have occurred', 'event_espresso'),
89
+					true,
90
+					0
91
+				),
92
+				'DTT_reserved'    => new EE_Integer_Field(
93
+					'DTT_reserved',
94
+					esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso'),
95
+					false,
96
+					0
97
+				),
98
+				'DTT_is_primary'  => new EE_Boolean_Field(
99
+					'DTT_is_primary',
100
+					esc_html__('Flag indicating datetime is primary one for event', 'event_espresso'),
101
+					false,
102
+					false
103
+				),
104
+				'DTT_order'       => new EE_Integer_Field(
105
+					'DTT_order',
106
+					esc_html__('The order in which the Datetime is displayed', 'event_espresso'),
107
+					false,
108
+					0
109
+				),
110
+				'DTT_parent'      => new EE_Integer_Field(
111
+					'DTT_parent',
112
+					esc_html__('Indicates what DTT_ID is the parent of this DTT_ID', 'event_espresso'),
113
+					true,
114
+					0
115
+				),
116
+				'DTT_deleted'     => new EE_Trashed_Flag_Field(
117
+					'DTT_deleted',
118
+					esc_html__('Flag indicating datetime is archived', 'event_espresso'),
119
+					false,
120
+					false
121
+				),
122
+			),
123
+		);
124
+		$this->_model_relations        = array(
125
+			'Ticket'  => new EE_HABTM_Relation('Datetime_Ticket'),
126
+			'Event'   => new EE_Belongs_To_Relation(),
127
+			'Checkin' => new EE_Has_Many_Relation(),
128
+			'Datetime_Ticket' => new EE_Has_Many_Relation(),
129
+		);
130
+		$path_to_event_model = 'Event';
131
+		$this->model_chain_to_password = $path_to_event_model;
132
+		$this->_model_chain_to_wp_user = $path_to_event_model;
133
+		// this model is generally available for reading
134
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ]       = new EE_Restriction_Generator_Event_Related_Public(
135
+			$path_to_event_model
136
+		);
137
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected(
138
+			$path_to_event_model
139
+		);
140
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ]       = new EE_Restriction_Generator_Event_Related_Protected(
141
+			$path_to_event_model
142
+		);
143
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ]     = new EE_Restriction_Generator_Event_Related_Protected(
144
+			$path_to_event_model,
145
+			EEM_Base::caps_edit
146
+		);
147
+		parent::__construct($timezone);
148
+	}
149
+
150
+
151
+	/**
152
+	 * create new blank datetime
153
+	 *
154
+	 * @access public
155
+	 * @return EE_Datetime[] array on success, FALSE on fail
156
+	 * @throws EE_Error
157
+	 * @throws InvalidArgumentException
158
+	 * @throws InvalidDataTypeException
159
+	 * @throws ReflectionException
160
+	 * @throws InvalidInterfaceException
161
+	 */
162
+	public function create_new_blank_datetime()
163
+	{
164
+		// makes sure timezone is always set.
165
+		$timezone_string = $this->get_timezone();
166
+		/**
167
+		 * Filters the initial start date for the new datetime.
168
+		 * Any time included in this value will be overridden later so use additional filters to modify the time.
169
+		 *
170
+		 * @param int $start_date Unixtimestamp representing now + 30 days in seconds.
171
+		 * @return int unixtimestamp
172
+		 */
173
+		$start_date = apply_filters(
174
+			'FHEE__EEM_Datetime__create_new_blank_datetime__start_date',
175
+			$this->current_time_for_query('DTT_EVT_start', true) + MONTH_IN_SECONDS
176
+		);
177
+		/**
178
+		 * Filters the initial end date for the new datetime.
179
+		 * Any time included in this value will be overridden later so use additional filters to modify the time.
180
+		 *
181
+		 * @param int $end_data Unixtimestamp representing now + 30 days in seconds.
182
+		 * @return int unixtimestamp
183
+		 */
184
+		$end_date = apply_filters(
185
+			'FHEE__EEM_Datetime__create_new_blank_datetime__end_date',
186
+			$this->current_time_for_query('DTT_EVT_end', true) + MONTH_IN_SECONDS
187
+		);
188
+		$blank_datetime = EE_Datetime::new_instance(
189
+			array(
190
+				'DTT_EVT_start' => $start_date,
191
+				'DTT_EVT_end'   => $end_date,
192
+				'DTT_order'     => 1,
193
+				'DTT_reg_limit' => EE_INF,
194
+			),
195
+			$timezone_string
196
+		);
197
+		/**
198
+		 * Filters the initial start time and format for the new EE_Datetime instance.
199
+		 *
200
+		 * @param array $start_time An array having size 2.  First element is the time, second element is the time
201
+		 *                          format.
202
+		 * @return array
203
+		 */
204
+		$start_time = apply_filters(
205
+			'FHEE__EEM_Datetime__create_new_blank_datetime__start_time',
206
+			['8am', 'ga']
207
+		);
208
+		/**
209
+		 * Filters the initial end time and format for the new EE_Datetime instance.
210
+		 *
211
+		 * @param array $end_time An array having size 2.  First element is the time, second element is the time
212
+		 *                        format
213
+		 * @return array
214
+		 */
215
+		$end_time = apply_filters(
216
+			'FHEE__EEM_Datetime__create_new_blank_datetime__end_time',
217
+			['5pm', 'ga']
218
+		);
219
+		$this->validateStartAndEndTimeForBlankDate($start_time, $end_time);
220
+		$blank_datetime->set_start_time(
221
+			$this->convert_datetime_for_query(
222
+				'DTT_EVT_start',
223
+				$start_time[0],
224
+				$start_time[1],
225
+				$timezone_string
226
+			)
227
+		);
228
+		$blank_datetime->set_end_time(
229
+			$this->convert_datetime_for_query(
230
+				'DTT_EVT_end',
231
+				$end_time[0],
232
+				$end_time[1],
233
+				$timezone_string
234
+			)
235
+		);
236
+		return array($blank_datetime);
237
+	}
238
+
239
+
240
+	/**
241
+	 * Validates whether the start_time and end_time are in the expected format.
242
+	 * @param array $start_time
243
+	 * @param array $end_time
244
+	 * @throws InvalidArgumentException
245
+	 * @throws InvalidDataTypeException
246
+	 */
247
+	private function validateStartAndEndTimeForBlankDate($start_time, $end_time)
248
+	{
249
+		if (! is_array($start_time)) {
250
+			throw new InvalidDataTypeException('start_time', $start_time, 'array');
251
+		}
252
+		if (! is_array($end_time)) {
253
+			throw new InvalidDataTypeException('end_time', $end_time, 'array');
254
+		}
255
+		if (count($start_time) !== 2) {
256
+			throw new InvalidArgumentException(
257
+				sprintf(
258
+					'The variable %1$s is expected to be an array with two elements.  The first item in the '
259
+					. 'array should be a valid time string, the second item in the array should be a valid time format',
260
+					'$start_time'
261
+				)
262
+			);
263
+		}
264
+		if (count($end_time) !== 2) {
265
+			throw new InvalidArgumentException(
266
+				sprintf(
267
+					'The variable %1$s is expected to be an array with two elements.  The first item in the '
268
+					. 'array should be a valid time string, the second item in the array should be a valid time format',
269
+					'$end_time'
270
+				)
271
+			);
272
+		}
273
+	}
274
+
275
+
276
+	/**
277
+	 * get event start date from db
278
+	 *
279
+	 * @access public
280
+	 * @param  int $EVT_ID
281
+	 * @return EE_Datetime[] array on success, FALSE on fail
282
+	 * @throws EE_Error
283
+	 */
284
+	public function get_all_event_dates($EVT_ID = 0)
285
+	{
286
+		if (! $EVT_ID) { // on add_new_event event_id gets set to 0
287
+			return $this->create_new_blank_datetime();
288
+		}
289
+		$results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
290
+		if (empty($results)) {
291
+			return $this->create_new_blank_datetime();
292
+		}
293
+		return $results;
294
+	}
295
+
296
+
297
+	/**
298
+	 * get all datetimes attached to an event ordered by the DTT_order field
299
+	 *
300
+	 * @public
301
+	 * @param  int    $EVT_ID     event id
302
+	 * @param boolean $include_expired
303
+	 * @param boolean $include_deleted
304
+	 * @param  int    $limit      If included then limit the count of results by
305
+	 *                            the given number
306
+	 * @return EE_Datetime[]
307
+	 * @throws EE_Error
308
+	 */
309
+	public function get_datetimes_for_event_ordered_by_DTT_order(
310
+		$EVT_ID,
311
+		$include_expired = true,
312
+		$include_deleted = true,
313
+		$limit = null
314
+	) {
315
+		// sanitize EVT_ID
316
+		$EVT_ID         = absint($EVT_ID);
317
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
318
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
319
+		$where_params = array('Event.EVT_ID' => $EVT_ID);
320
+		$query_params = ! empty($limit)
321
+			? array(
322
+				$where_params,
323
+				'limit'                    => $limit,
324
+				'order_by'                 => array('DTT_order' => 'ASC'),
325
+				'default_where_conditions' => 'none',
326
+			)
327
+			: array(
328
+				$where_params,
329
+				'order_by'                 => array('DTT_order' => 'ASC'),
330
+				'default_where_conditions' => 'none',
331
+			);
332
+		if (! $include_expired) {
333
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
334
+		}
335
+		if ($include_deleted) {
336
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
337
+		}
338
+		/** @var EE_Datetime[] $result */
339
+		$result = $this->get_all($query_params);
340
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
341
+		return $result;
342
+	}
343
+
344
+
345
+	/**
346
+	 * Gets the datetimes for the event (with the given limit), and orders them by "importance".
347
+	 * By importance, we mean that the primary datetimes are most important (DEPRECATED FOR NOW),
348
+	 * and then the earlier datetimes are the most important.
349
+	 * Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet.
350
+	 *
351
+	 * @param int $EVT_ID
352
+	 * @param int $limit
353
+	 * @return EE_Datetime[]|EE_Base_Class[]
354
+	 * @throws EE_Error
355
+	 */
356
+	public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null)
357
+	{
358
+		return $this->get_all(
359
+			array(
360
+				array('Event.EVT_ID' => $EVT_ID),
361
+				'limit'                    => $limit,
362
+				'order_by'                 => array('DTT_EVT_start' => 'ASC'),
363
+				'default_where_conditions' => 'none',
364
+			)
365
+		);
366
+	}
367
+
368
+
369
+	/**
370
+	 * @param int     $EVT_ID
371
+	 * @param boolean $include_expired
372
+	 * @param boolean $include_deleted
373
+	 * @return EE_Datetime
374
+	 * @throws EE_Error
375
+	 */
376
+	public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false)
377
+	{
378
+		$results = $this->get_datetimes_for_event_ordered_by_start_time(
379
+			$EVT_ID,
380
+			$include_expired,
381
+			$include_deleted,
382
+			1
383
+		);
384
+		if ($results) {
385
+			return array_shift($results);
386
+		}
387
+		return null;
388
+	}
389
+
390
+
391
+	/**
392
+	 * Gets the 'primary' datetime for an event.
393
+	 *
394
+	 * @param int  $EVT_ID
395
+	 * @param bool $try_to_exclude_expired
396
+	 * @param bool $try_to_exclude_deleted
397
+	 * @return \EE_Datetime
398
+	 * @throws EE_Error
399
+	 */
400
+	public function get_primary_datetime_for_event(
401
+		$EVT_ID,
402
+		$try_to_exclude_expired = true,
403
+		$try_to_exclude_deleted = true
404
+	) {
405
+		if ($try_to_exclude_expired) {
406
+			$non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false);
407
+			if ($non_expired) {
408
+				return $non_expired;
409
+			}
410
+		}
411
+		if ($try_to_exclude_deleted) {
412
+			$expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true);
413
+			if ($expired_even) {
414
+				return $expired_even;
415
+			}
416
+		}
417
+		return $this->get_oldest_datetime_for_event($EVT_ID, true, true);
418
+	}
419
+
420
+
421
+	/**
422
+	 * Gets ALL the datetimes for an event (including trashed ones, for now), ordered
423
+	 * only by start date
424
+	 *
425
+	 * @param int     $EVT_ID
426
+	 * @param boolean $include_expired
427
+	 * @param boolean $include_deleted
428
+	 * @param int     $limit
429
+	 * @return EE_Datetime[]
430
+	 * @throws EE_Error
431
+	 */
432
+	public function get_datetimes_for_event_ordered_by_start_time(
433
+		$EVT_ID,
434
+		$include_expired = true,
435
+		$include_deleted = true,
436
+		$limit = null
437
+	) {
438
+		// sanitize EVT_ID
439
+		$EVT_ID         = absint($EVT_ID);
440
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
441
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
442
+		$query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
443
+		if (! $include_expired) {
444
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
445
+		}
446
+		if ($include_deleted) {
447
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
448
+		}
449
+		if ($limit) {
450
+			$query_params['limit'] = $limit;
451
+		}
452
+		/** @var EE_Datetime[] $result */
453
+		$result = $this->get_all($query_params);
454
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
455
+		return $result;
456
+	}
457
+
458
+
459
+	/**
460
+	 * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
461
+	 * only by start date
462
+	 *
463
+	 * @param int     $TKT_ID
464
+	 * @param boolean $include_expired
465
+	 * @param boolean $include_deleted
466
+	 * @param int     $limit
467
+	 * @return EE_Datetime[]
468
+	 * @throws EE_Error
469
+	 */
470
+	public function get_datetimes_for_ticket_ordered_by_start_time(
471
+		$TKT_ID,
472
+		$include_expired = true,
473
+		$include_deleted = true,
474
+		$limit = null
475
+	) {
476
+		// sanitize TKT_ID
477
+		$TKT_ID         = absint($TKT_ID);
478
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
479
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
480
+		$query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
481
+		if (! $include_expired) {
482
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
483
+		}
484
+		if ($include_deleted) {
485
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
486
+		}
487
+		if ($limit) {
488
+			$query_params['limit'] = $limit;
489
+		}
490
+		/** @var EE_Datetime[] $result */
491
+		$result = $this->get_all($query_params);
492
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
493
+		return $result;
494
+	}
495
+
496
+
497
+	/**
498
+	 * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
499
+	 * datetimes.
500
+	 *
501
+	 * @param  int      $TKT_ID          ID of ticket to retrieve the datetimes for
502
+	 * @param  boolean  $include_expired whether to include expired datetimes or not
503
+	 * @param  boolean  $include_deleted whether to include trashed datetimes or not.
504
+	 * @param  int|null $limit           if null, no limit, if int then limit results by
505
+	 *                                   that number
506
+	 * @return EE_Datetime[]
507
+	 * @throws EE_Error
508
+	 */
509
+	public function get_datetimes_for_ticket_ordered_by_DTT_order(
510
+		$TKT_ID,
511
+		$include_expired = true,
512
+		$include_deleted = true,
513
+		$limit = null
514
+	) {
515
+		// sanitize id.
516
+		$TKT_ID         = absint($TKT_ID);
517
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
518
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
519
+		$where_params = array('Ticket.TKT_ID' => $TKT_ID);
520
+		$query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
521
+		if (! $include_expired) {
522
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
523
+		}
524
+		if ($include_deleted) {
525
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
526
+		}
527
+		if ($limit) {
528
+			$query_params['limit'] = $limit;
529
+		}
530
+		/** @var EE_Datetime[] $result */
531
+		$result = $this->get_all($query_params);
532
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
533
+		return $result;
534
+	}
535
+
536
+
537
+	/**
538
+	 * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
539
+	 * reason it doesn't exist, we consider the earliest event the most important)
540
+	 *
541
+	 * @param int $EVT_ID
542
+	 * @return EE_Datetime
543
+	 * @throws EE_Error
544
+	 */
545
+	public function get_most_important_datetime_for_event($EVT_ID)
546
+	{
547
+		$results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
548
+		if ($results) {
549
+			return array_shift($results);
550
+		}
551
+		return null;
552
+	}
553
+
554
+
555
+	/**
556
+	 * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
557
+	 * grouped by month and year.
558
+	 *
559
+	 * @param  array  $where_params      @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
560
+	 * @param  string $evt_active_status A string representing the evt active status to filter the months by.
561
+	 *                                   Can be:
562
+	 *                                   - '' = no filter
563
+	 *                                   - upcoming = Published events with at least one upcoming datetime.
564
+	 *                                   - expired = Events with all datetimes expired.
565
+	 *                                   - active = Events that are published and have at least one datetime that
566
+	 *                                   starts before now and ends after now.
567
+	 *                                   - inactive = Events that are either not published.
568
+	 * @return EE_Base_Class[]
569
+	 * @throws EE_Error
570
+	 * @throws InvalidArgumentException
571
+	 * @throws InvalidArgumentException
572
+	 */
573
+	public function get_dtt_months_and_years($where_params, $evt_active_status = '')
574
+	{
575
+		$current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
576
+		$current_time_for_DTT_EVT_end   = $this->current_time_for_query('DTT_EVT_end');
577
+		switch ($evt_active_status) {
578
+			case 'upcoming':
579
+				$where_params['Event.status'] = 'publish';
580
+				// if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
581
+				if (isset($where_params['DTT_EVT_start'])) {
582
+					$where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
583
+				}
584
+				$where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start);
585
+				break;
586
+			case 'expired':
587
+				if (isset($where_params['Event.status'])) {
588
+					unset($where_params['Event.status']);
589
+				}
590
+				// get events to exclude
591
+				$exclude_query[0] = array_merge(
592
+					$where_params,
593
+					array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end))
594
+				);
595
+				// first get all events that have datetimes where its not expired.
596
+				$event_ids = $this->_get_all_wpdb_results(
597
+					$exclude_query,
598
+					OBJECT_K,
599
+					'Datetime.EVT_ID'
600
+				);
601
+				$event_ids = array_keys($event_ids);
602
+				if (isset($where_params['DTT_EVT_end'])) {
603
+					$where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
604
+				}
605
+				$where_params['DTT_EVT_end']  = array('<', $current_time_for_DTT_EVT_end);
606
+				$where_params['Event.EVT_ID'] = array('NOT IN', $event_ids);
607
+				break;
608
+			case 'active':
609
+				$where_params['Event.status'] = 'publish';
610
+				if (isset($where_params['DTT_EVT_start'])) {
611
+					$where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
612
+				}
613
+				if (isset($where_params['Datetime.DTT_EVT_end'])) {
614
+					$where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
615
+				}
616
+				$where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start);
617
+				$where_params['DTT_EVT_end']   = array('>', $current_time_for_DTT_EVT_end);
618
+				break;
619
+			case 'inactive':
620
+				if (isset($where_params['Event.status'])) {
621
+					unset($where_params['Event.status']);
622
+				}
623
+				if (isset($where_params['OR'])) {
624
+					$where_params['AND']['OR'] = $where_params['OR'];
625
+				}
626
+				if (isset($where_params['DTT_EVT_end'])) {
627
+					$where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
628
+					unset($where_params['DTT_EVT_end']);
629
+				}
630
+				if (isset($where_params['DTT_EVT_start'])) {
631
+					$where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
632
+					unset($where_params['DTT_EVT_start']);
633
+				}
634
+				$where_params['AND']['Event.status'] = array('!=', 'publish');
635
+				break;
636
+		}
637
+		$query_params[0]          = $where_params;
638
+		$query_params['group_by'] = array('dtt_year', 'dtt_month');
639
+		$query_params['order_by'] = array('DTT_EVT_start' => 'DESC');
640
+		$query_interval           = EEH_DTT_Helper::get_sql_query_interval_for_offset(
641
+			$this->get_timezone(),
642
+			'DTT_EVT_start'
643
+		);
644
+		$columns_to_select        = array(
645
+			'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
646
+			'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
647
+			'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
648
+		);
649
+		return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
650
+	}
651
+
652
+
653
+	/**
654
+	 * Updates the DTT_sold attribute on each datetime (based on the registrations
655
+	 * for the tickets for each datetime)
656
+	 *
657
+	 * @param EE_Base_Class[]|EE_Datetime[] $datetimes
658
+	 * @throws EE_Error
659
+	 */
660
+	public function update_sold($datetimes)
661
+	{
662
+		EE_Error::doing_it_wrong(
663
+			__FUNCTION__,
664
+			esc_html__(
665
+				'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.',
666
+				'event_espresso'
667
+			),
668
+			'4.9.32.rc.005'
669
+		);
670
+		foreach ($datetimes as $datetime) {
671
+			$datetime->update_sold();
672
+		}
673
+	}
674
+
675
+
676
+	/**
677
+	 *    Gets the total number of tickets available at a particular datetime
678
+	 *    (does NOT take into account the datetime's spaces available)
679
+	 *
680
+	 * @param int   $DTT_ID
681
+	 * @param array $query_params
682
+	 * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
683
+	 *             tickets attached to datetime then FALSE is returned.
684
+	 */
685
+	public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array())
686
+	{
687
+		$datetime = $this->get_one_by_ID($DTT_ID);
688
+		if ($datetime instanceof EE_Datetime) {
689
+			return $datetime->tickets_remaining($query_params);
690
+		}
691
+		return 0;
692
+	}
693
+
694
+
695
+	/**
696
+	 * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
697
+	 *
698
+	 * @param  array $stati_to_include If included you can restrict the statuses we return counts for by including the
699
+	 *                                 stati you want counts for as values in the array.  An empty array returns counts
700
+	 *                                 for all valid stati.
701
+	 * @param  array $query_params     If included can be used to refine the conditions for returning the count (i.e.
702
+	 *                                 only for Datetimes connected to a specific event, or specific ticket.
703
+	 * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
704
+	 * @throws EE_Error
705
+	 *                                 stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming
706
+	 *                                 EE_Datetime::expired
707
+	 */
708
+	public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array())
709
+	{
710
+		// only accept where conditions for this query.
711
+		$_where            = isset($query_params[0]) ? $query_params[0] : array();
712
+		$status_query_args = array(
713
+			EE_Datetime::active   => array_merge(
714
+				$_where,
715
+				array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time()))
716
+			),
717
+			EE_Datetime::upcoming => array_merge(
718
+				$_where,
719
+				array('DTT_EVT_start' => array('>', time()))
720
+			),
721
+			EE_Datetime::expired  => array_merge(
722
+				$_where,
723
+				array('DTT_EVT_end' => array('<', time()))
724
+			),
725
+		);
726
+		if (! empty($stati_to_include)) {
727
+			foreach (array_keys($status_query_args) as $status) {
728
+				if (! in_array($status, $stati_to_include, true)) {
729
+					unset($status_query_args[ $status ]);
730
+				}
731
+			}
732
+		}
733
+		// loop through and query counts for each stati.
734
+		$status_query_results = array();
735
+		foreach ($status_query_args as $status => $status_where_conditions) {
736
+			$status_query_results[ $status ] = EEM_Datetime::count(
737
+				array($status_where_conditions),
738
+				'DTT_ID',
739
+				true
740
+			);
741
+		}
742
+		return $status_query_results;
743
+	}
744
+
745
+
746
+	/**
747
+	 * Returns the specific count for a given Datetime status matching any given query_params.
748
+	 *
749
+	 * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
750
+	 * @param array  $query_params
751
+	 * @return int
752
+	 * @throws EE_Error
753
+	 */
754
+	public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array())
755
+	{
756
+		$count = $this->get_datetime_counts_by_status(array($status), $query_params);
757
+		return ! empty($count[ $status ]) ? $count[ $status ] : 0;
758
+	}
759 759
 }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
                 ),
122 122
             ),
123 123
         );
124
-        $this->_model_relations        = array(
124
+        $this->_model_relations = array(
125 125
             'Ticket'  => new EE_HABTM_Relation('Datetime_Ticket'),
126 126
             'Event'   => new EE_Belongs_To_Relation(),
127 127
             'Checkin' => new EE_Has_Many_Relation(),
@@ -131,16 +131,16 @@  discard block
 block discarded – undo
131 131
         $this->model_chain_to_password = $path_to_event_model;
132 132
         $this->_model_chain_to_wp_user = $path_to_event_model;
133 133
         // this model is generally available for reading
134
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       = new EE_Restriction_Generator_Event_Related_Public(
134
+        $this->_cap_restriction_generators[EEM_Base::caps_read]       = new EE_Restriction_Generator_Event_Related_Public(
135 135
             $path_to_event_model
136 136
         );
137
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected(
137
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected(
138 138
             $path_to_event_model
139 139
         );
140
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       = new EE_Restriction_Generator_Event_Related_Protected(
140
+        $this->_cap_restriction_generators[EEM_Base::caps_edit]       = new EE_Restriction_Generator_Event_Related_Protected(
141 141
             $path_to_event_model
142 142
         );
143
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     = new EE_Restriction_Generator_Event_Related_Protected(
143
+        $this->_cap_restriction_generators[EEM_Base::caps_delete]     = new EE_Restriction_Generator_Event_Related_Protected(
144 144
             $path_to_event_model,
145 145
             EEM_Base::caps_edit
146 146
         );
@@ -246,10 +246,10 @@  discard block
 block discarded – undo
246 246
      */
247 247
     private function validateStartAndEndTimeForBlankDate($start_time, $end_time)
248 248
     {
249
-        if (! is_array($start_time)) {
249
+        if ( ! is_array($start_time)) {
250 250
             throw new InvalidDataTypeException('start_time', $start_time, 'array');
251 251
         }
252
-        if (! is_array($end_time)) {
252
+        if ( ! is_array($end_time)) {
253 253
             throw new InvalidDataTypeException('end_time', $end_time, 'array');
254 254
         }
255 255
         if (count($start_time) !== 2) {
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
      */
284 284
     public function get_all_event_dates($EVT_ID = 0)
285 285
     {
286
-        if (! $EVT_ID) { // on add_new_event event_id gets set to 0
286
+        if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0
287 287
             return $this->create_new_blank_datetime();
288 288
         }
289 289
         $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID);
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
                 'order_by'                 => array('DTT_order' => 'ASC'),
330 330
                 'default_where_conditions' => 'none',
331 331
             );
332
-        if (! $include_expired) {
332
+        if ( ! $include_expired) {
333 333
             $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
334 334
         }
335 335
         if ($include_deleted) {
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
         $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
441 441
         $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
442 442
         $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
443
-        if (! $include_expired) {
443
+        if ( ! $include_expired) {
444 444
             $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
445 445
         }
446 446
         if ($include_deleted) {
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
         $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
479 479
         $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
480 480
         $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
481
-        if (! $include_expired) {
481
+        if ( ! $include_expired) {
482 482
             $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
483 483
         }
484 484
         if ($include_deleted) {
@@ -518,7 +518,7 @@  discard block
 block discarded – undo
518 518
         $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
519 519
         $where_params = array('Ticket.TKT_ID' => $TKT_ID);
520 520
         $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
521
-        if (! $include_expired) {
521
+        if ( ! $include_expired) {
522 522
             $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
523 523
         }
524 524
         if ($include_deleted) {
@@ -641,10 +641,10 @@  discard block
 block discarded – undo
641 641
             $this->get_timezone(),
642 642
             'DTT_EVT_start'
643 643
         );
644
-        $columns_to_select        = array(
645
-            'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
646
-            'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
647
-            'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
644
+        $columns_to_select = array(
645
+            'dtt_year'      => array('YEAR('.$query_interval.')', '%s'),
646
+            'dtt_month'     => array('MONTHNAME('.$query_interval.')', '%s'),
647
+            'dtt_month_num' => array('MONTH('.$query_interval.')', '%s'),
648 648
         );
649 649
         return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
650 650
     }
@@ -723,17 +723,17 @@  discard block
 block discarded – undo
723 723
                 array('DTT_EVT_end' => array('<', time()))
724 724
             ),
725 725
         );
726
-        if (! empty($stati_to_include)) {
726
+        if ( ! empty($stati_to_include)) {
727 727
             foreach (array_keys($status_query_args) as $status) {
728
-                if (! in_array($status, $stati_to_include, true)) {
729
-                    unset($status_query_args[ $status ]);
728
+                if ( ! in_array($status, $stati_to_include, true)) {
729
+                    unset($status_query_args[$status]);
730 730
                 }
731 731
             }
732 732
         }
733 733
         // loop through and query counts for each stati.
734 734
         $status_query_results = array();
735 735
         foreach ($status_query_args as $status => $status_where_conditions) {
736
-            $status_query_results[ $status ] = EEM_Datetime::count(
736
+            $status_query_results[$status] = EEM_Datetime::count(
737 737
                 array($status_where_conditions),
738 738
                 'DTT_ID',
739 739
                 true
@@ -754,6 +754,6 @@  discard block
 block discarded – undo
754 754
     public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array())
755 755
     {
756 756
         $count = $this->get_datetime_counts_by_status(array($status), $query_params);
757
-        return ! empty($count[ $status ]) ? $count[ $status ] : 0;
757
+        return ! empty($count[$status]) ? $count[$status] : 0;
758 758
     }
759 759
 }
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1247,7 +1247,7 @@
 block discarded – undo
1247 1247
     /**
1248 1248
      * Sets up the limit for the registrations query.
1249 1249
      *
1250
-     * @param $per_page
1250
+     * @param integer $per_page
1251 1251
      * @return array
1252 1252
      */
1253 1253
     protected function _get_limit($per_page)
Please login to merge, or discard this patch.
Indentation   +3823 added lines, -3823 removed lines patch added patch discarded remove patch
@@ -19,2396 +19,2396 @@  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 https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1168
-         *                             or if you have the development copy of EE you can view this at the path:
1169
-         *                             /docs/G--Model-System/model-query-params.md
1170
-         */
1171
-        $query_params['group_by'] = '';
1172
-
1173
-        return $count
1174
-            ? EEM_Registration::instance()->count($query_params)
1175
-            /** @type EE_Registration[] */
1176
-            : EEM_Registration::instance()->get_all($query_params);
1177
-    }
1178
-
1179
-
1180
-    /**
1181
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1182
-     * Note: this listens to values on the request for some of the query parameters.
1183
-     *
1184
-     * @param array $request
1185
-     * @param int   $per_page
1186
-     * @param bool  $count
1187
-     * @return array
1188
-     * @throws EE_Error
1189
-     */
1190
-    protected function _get_registration_query_parameters(
1191
-        $request = array(),
1192
-        $per_page = 10,
1193
-        $count = false
1194
-    ) {
1195
-
1196
-        $query_params = array(
1197
-            0                          => $this->_get_where_conditions_for_registrations_query(
1198
-                $request
1199
-            ),
1200
-            'caps'                     => EEM_Registration::caps_read_admin,
1201
-            'default_where_conditions' => 'this_model_only',
1202
-        );
1203
-        if (! $count) {
1204
-            $query_params = array_merge(
1205
-                $query_params,
1206
-                $this->_get_orderby_for_registrations_query(),
1207
-                $this->_get_limit($per_page)
1208
-            );
1209
-        }
1210
-
1211
-        return $query_params;
1212
-    }
1213
-
1214
-
1215
-    /**
1216
-     * This will add ATT_ID to the provided $where array for EE model query parameters.
1217
-     *
1218
-     * @param array $request usually the same as $this->_req_data but not necessarily
1219
-     * @return array
1220
-     */
1221
-    protected function addAttendeeIdToWhereConditions(array $request)
1222
-    {
1223
-        $where = array();
1224
-        if (! empty($request['ATT_ID'])) {
1225
-            $where['ATT_ID'] = absint($request['ATT_ID']);
1226
-        }
1227
-        return $where;
1228
-    }
1229
-
1230
-
1231
-    /**
1232
-     * This will add EVT_ID to the provided $where array for EE model query parameters.
1233
-     *
1234
-     * @param array $request usually the same as $this->_req_data but not necessarily
1235
-     * @return array
1236
-     */
1237
-    protected function _add_event_id_to_where_conditions(array $request)
1238
-    {
1239
-        $where = array();
1240
-        if (! empty($request['event_id'])) {
1241
-            $where['EVT_ID'] = absint($request['event_id']);
1242
-        }
1243
-        return $where;
1244
-    }
1245
-
1246
-
1247
-    /**
1248
-     * Adds category ID if it exists in the request to the where conditions for the registrations query.
1249
-     *
1250
-     * @param array $request usually the same as $this->_req_data but not necessarily
1251
-     * @return array
1252
-     */
1253
-    protected function _add_category_id_to_where_conditions(array $request)
1254
-    {
1255
-        $where = array();
1256
-        if (! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) {
1257
-            $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1258
-        }
1259
-        return $where;
1260
-    }
1261
-
1262
-
1263
-    /**
1264
-     * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1265
-     *
1266
-     * @param array $request usually the same as $this->_req_data but not necessarily
1267
-     * @return array
1268
-     */
1269
-    protected function _add_datetime_id_to_where_conditions(array $request)
1270
-    {
1271
-        $where = array();
1272
-        if (! empty($request['datetime_id'])) {
1273
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1274
-        }
1275
-        if (! empty($request['DTT_ID'])) {
1276
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1277
-        }
1278
-        return $where;
1279
-    }
1280
-
1281
-
1282
-    /**
1283
-     * Adds the correct registration status to the where conditions for the registrations query.
1284
-     *
1285
-     * @param array $request usually the same as $this->_req_data but not necessarily
1286
-     * @return array
1287
-     */
1288
-    protected function _add_registration_status_to_where_conditions(array $request)
1289
-    {
1290
-        $where = array();
1291
-        $view = EEH_Array::is_set($request, 'status', '');
1292
-        $registration_status = ! empty($request['_reg_status'])
1293
-            ? sanitize_text_field($request['_reg_status'])
1294
-            : '';
1295
-
1296
-        /*
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 https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1168
+		 *                             or if you have the development copy of EE you can view this at the path:
1169
+		 *                             /docs/G--Model-System/model-query-params.md
1170
+		 */
1171
+		$query_params['group_by'] = '';
1172
+
1173
+		return $count
1174
+			? EEM_Registration::instance()->count($query_params)
1175
+			/** @type EE_Registration[] */
1176
+			: EEM_Registration::instance()->get_all($query_params);
1177
+	}
1178
+
1179
+
1180
+	/**
1181
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1182
+	 * Note: this listens to values on the request for some of the query parameters.
1183
+	 *
1184
+	 * @param array $request
1185
+	 * @param int   $per_page
1186
+	 * @param bool  $count
1187
+	 * @return array
1188
+	 * @throws EE_Error
1189
+	 */
1190
+	protected function _get_registration_query_parameters(
1191
+		$request = array(),
1192
+		$per_page = 10,
1193
+		$count = false
1194
+	) {
1195
+
1196
+		$query_params = array(
1197
+			0                          => $this->_get_where_conditions_for_registrations_query(
1198
+				$request
1199
+			),
1200
+			'caps'                     => EEM_Registration::caps_read_admin,
1201
+			'default_where_conditions' => 'this_model_only',
1202
+		);
1203
+		if (! $count) {
1204
+			$query_params = array_merge(
1205
+				$query_params,
1206
+				$this->_get_orderby_for_registrations_query(),
1207
+				$this->_get_limit($per_page)
1208
+			);
1209
+		}
1210
+
1211
+		return $query_params;
1212
+	}
1213
+
1214
+
1215
+	/**
1216
+	 * This will add ATT_ID to the provided $where array for EE model query parameters.
1217
+	 *
1218
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1219
+	 * @return array
1220
+	 */
1221
+	protected function addAttendeeIdToWhereConditions(array $request)
1222
+	{
1223
+		$where = array();
1224
+		if (! empty($request['ATT_ID'])) {
1225
+			$where['ATT_ID'] = absint($request['ATT_ID']);
1226
+		}
1227
+		return $where;
1228
+	}
1229
+
1230
+
1231
+	/**
1232
+	 * This will add EVT_ID to the provided $where array for EE model query parameters.
1233
+	 *
1234
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1235
+	 * @return array
1236
+	 */
1237
+	protected function _add_event_id_to_where_conditions(array $request)
1238
+	{
1239
+		$where = array();
1240
+		if (! empty($request['event_id'])) {
1241
+			$where['EVT_ID'] = absint($request['event_id']);
1242
+		}
1243
+		return $where;
1244
+	}
1245
+
1246
+
1247
+	/**
1248
+	 * Adds category ID if it exists in the request to the where conditions for the registrations query.
1249
+	 *
1250
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1251
+	 * @return array
1252
+	 */
1253
+	protected function _add_category_id_to_where_conditions(array $request)
1254
+	{
1255
+		$where = array();
1256
+		if (! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) {
1257
+			$where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1258
+		}
1259
+		return $where;
1260
+	}
1261
+
1262
+
1263
+	/**
1264
+	 * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1265
+	 *
1266
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1267
+	 * @return array
1268
+	 */
1269
+	protected function _add_datetime_id_to_where_conditions(array $request)
1270
+	{
1271
+		$where = array();
1272
+		if (! empty($request['datetime_id'])) {
1273
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1274
+		}
1275
+		if (! empty($request['DTT_ID'])) {
1276
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1277
+		}
1278
+		return $where;
1279
+	}
1280
+
1281
+
1282
+	/**
1283
+	 * Adds the correct registration status to the where conditions for the registrations query.
1284
+	 *
1285
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1286
+	 * @return array
1287
+	 */
1288
+	protected function _add_registration_status_to_where_conditions(array $request)
1289
+	{
1290
+		$where = array();
1291
+		$view = EEH_Array::is_set($request, 'status', '');
1292
+		$registration_status = ! empty($request['_reg_status'])
1293
+			? sanitize_text_field($request['_reg_status'])
1294
+			: '';
1295
+
1296
+		/*
1297 1297
          * If filtering by registration status, then we show registrations matching that status.
1298 1298
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1299 1299
          * UNLESS viewing trashed registrations.
1300 1300
          */
1301
-        if (! empty($registration_status)) {
1302
-            $where['STS_ID'] = $registration_status;
1303
-        } else {
1304
-            // make sure we exclude incomplete registrations, but only if not trashed.
1305
-            if ($view === 'trash') {
1306
-                $where['REG_deleted'] = true;
1307
-            } elseif ($view === 'incomplete') {
1308
-                $where['STS_ID'] = EEM_Registration::status_id_incomplete;
1309
-            } else {
1310
-                $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1311
-            }
1312
-        }
1313
-        return $where;
1314
-    }
1315
-
1316
-
1317
-    /**
1318
-     * Adds any provided date restraints to the where conditions for the registrations query.
1319
-     *
1320
-     * @param array $request usually the same as $this->_req_data but not necessarily
1321
-     * @return array
1322
-     * @throws EE_Error
1323
-     * @throws InvalidArgumentException
1324
-     * @throws InvalidDataTypeException
1325
-     * @throws InvalidInterfaceException
1326
-     */
1327
-    protected function _add_date_to_where_conditions(array $request)
1328
-    {
1329
-        $where = array();
1330
-        $view = EEH_Array::is_set($request, 'status', '');
1331
-        $month_range = ! empty($request['month_range'])
1332
-            ? sanitize_text_field($request['month_range'])
1333
-            : '';
1334
-        $retrieve_for_today = $view === 'today';
1335
-        $retrieve_for_this_month = $view === 'month';
1336
-
1337
-        if ($retrieve_for_today) {
1338
-            $now = date('Y-m-d', current_time('timestamp'));
1339
-            $where['REG_date'] = array(
1340
-                'BETWEEN',
1341
-                array(
1342
-                    EEM_Registration::instance()->convert_datetime_for_query(
1343
-                        'REG_date',
1344
-                        $now . ' 00:00:00',
1345
-                        'Y-m-d H:i:s'
1346
-                    ),
1347
-                    EEM_Registration::instance()->convert_datetime_for_query(
1348
-                        'REG_date',
1349
-                        $now . ' 23:59:59',
1350
-                        'Y-m-d H:i:s'
1351
-                    ),
1352
-                ),
1353
-            );
1354
-        } elseif ($retrieve_for_this_month) {
1355
-            $current_year_and_month = date('Y-m', current_time('timestamp'));
1356
-            $days_this_month = date('t', current_time('timestamp'));
1357
-            $where['REG_date'] = array(
1358
-                'BETWEEN',
1359
-                array(
1360
-                    EEM_Registration::instance()->convert_datetime_for_query(
1361
-                        'REG_date',
1362
-                        $current_year_and_month . '-01 00:00:00',
1363
-                        'Y-m-d H:i:s'
1364
-                    ),
1365
-                    EEM_Registration::instance()->convert_datetime_for_query(
1366
-                        'REG_date',
1367
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1368
-                        'Y-m-d H:i:s'
1369
-                    ),
1370
-                ),
1371
-            );
1372
-        } elseif ($month_range) {
1373
-            $pieces = explode(' ', $month_range, 3);
1374
-            $month_requested = ! empty($pieces[0])
1375
-                ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1376
-                : '';
1377
-            $year_requested = ! empty($pieces[1])
1378
-                ? $pieces[1]
1379
-                : '';
1380
-            // if there is not a month or year then we can't go further
1381
-            if ($month_requested && $year_requested) {
1382
-                $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1383
-                $where['REG_date'] = array(
1384
-                    'BETWEEN',
1385
-                    array(
1386
-                        EEM_Registration::instance()->convert_datetime_for_query(
1387
-                            'REG_date',
1388
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1389
-                            'Y-m-d H:i:s'
1390
-                        ),
1391
-                        EEM_Registration::instance()->convert_datetime_for_query(
1392
-                            'REG_date',
1393
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1394
-                            'Y-m-d H:i:s'
1395
-                        ),
1396
-                    ),
1397
-                );
1398
-            }
1399
-        }
1400
-        return $where;
1401
-    }
1402
-
1403
-
1404
-    /**
1405
-     * Adds any provided search restraints to the where conditions for the registrations query
1406
-     *
1407
-     * @param array $request usually the same as $this->_req_data but not necessarily
1408
-     * @return array
1409
-     */
1410
-    protected function _add_search_to_where_conditions(array $request)
1411
-    {
1412
-        $where = array();
1413
-        if (! empty($request['s'])) {
1414
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1415
-            $where['OR*search_conditions'] = array(
1416
-                'Event.EVT_name'                          => array('LIKE', $search_string),
1417
-                'Event.EVT_desc'                          => array('LIKE', $search_string),
1418
-                'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1419
-                'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1420
-                'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1421
-                'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1422
-                'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1423
-                'Attendee.ATT_email'                      => array('LIKE', $search_string),
1424
-                'Attendee.ATT_address'                    => array('LIKE', $search_string),
1425
-                'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1426
-                'Attendee.ATT_city'                       => array('LIKE', $search_string),
1427
-                'REG_final_price'                         => array('LIKE', $search_string),
1428
-                'REG_code'                                => array('LIKE', $search_string),
1429
-                'REG_count'                               => array('LIKE', $search_string),
1430
-                'REG_group_size'                          => array('LIKE', $search_string),
1431
-                'Ticket.TKT_name'                         => array('LIKE', $search_string),
1432
-                'Ticket.TKT_description'                  => array('LIKE', $search_string),
1433
-                'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1434
-            );
1435
-        }
1436
-        return $where;
1437
-    }
1438
-
1439
-
1440
-    /**
1441
-     * Sets up the where conditions for the registrations query.
1442
-     *
1443
-     * @param array $request
1444
-     * @return array
1445
-     * @throws EE_Error
1446
-     */
1447
-    protected function _get_where_conditions_for_registrations_query($request)
1448
-    {
1449
-        return apply_filters(
1450
-            'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1451
-            array_merge(
1452
-                $this->addAttendeeIdToWhereConditions($request),
1453
-                $this->_add_event_id_to_where_conditions($request),
1454
-                $this->_add_category_id_to_where_conditions($request),
1455
-                $this->_add_datetime_id_to_where_conditions($request),
1456
-                $this->_add_registration_status_to_where_conditions($request),
1457
-                $this->_add_date_to_where_conditions($request),
1458
-                $this->_add_search_to_where_conditions($request)
1459
-            ),
1460
-            $request
1461
-        );
1462
-    }
1463
-
1464
-
1465
-    /**
1466
-     * Sets up the orderby for the registrations query.
1467
-     *
1468
-     * @return array
1469
-     */
1470
-    protected function _get_orderby_for_registrations_query()
1471
-    {
1472
-        $orderby_field = ! empty($this->_req_data['orderby'])
1473
-            ? sanitize_text_field($this->_req_data['orderby'])
1474
-            : '_REG_date';
1475
-        switch ($orderby_field) {
1476
-            case '_REG_ID':
1477
-                $orderby = array('REG_ID');
1478
-                break;
1479
-            case '_Reg_status':
1480
-                $orderby = array('STS_ID');
1481
-                break;
1482
-            case 'ATT_fname':
1483
-                $orderby = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1484
-                break;
1485
-            case 'ATT_lname':
1486
-                $orderby = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1487
-                break;
1488
-            case 'event_name':
1489
-                $orderby = array('Event.EVT_name');
1490
-                break;
1491
-            case 'DTT_EVT_start':
1492
-                $orderby = array('Event.Datetime.DTT_EVT_start');
1493
-                break;
1494
-            case '_REG_date':
1495
-                $orderby = array('REG_date');
1496
-                break;
1497
-            default:
1498
-                $orderby = array($orderby_field);
1499
-                break;
1500
-        }
1501
-
1502
-        // order
1503
-        $order = ! empty($this->_req_data['order'])
1504
-            ? sanitize_text_field($this->_req_data['order'])
1505
-            : 'DESC';
1506
-        $orderby = array_combine(
1507
-            $orderby,
1508
-            array_fill(0, count($orderby), $order)
1509
-        );
1510
-        // because there are many registrations with the same date, define
1511
-        // a secondary way to order them, otherwise MySQL seems to be a bit random
1512
-        if (empty($orderby['REG_ID'])) {
1513
-            $orderby['REG_ID'] = $order;
1514
-        }
1515
-
1516
-        $orderby = apply_filters(
1517
-            'FHEE__Registrations_Admin_Page___get_orderby_for_registrations_query',
1518
-            $orderby,
1519
-            $this->_req_data
1520
-        );
1521
-
1522
-        return array('order_by' => $orderby);
1523
-    }
1524
-
1525
-
1526
-    /**
1527
-     * Sets up the limit for the registrations query.
1528
-     *
1529
-     * @param $per_page
1530
-     * @return array
1531
-     */
1532
-    protected function _get_limit($per_page)
1533
-    {
1534
-        $current_page = ! empty($this->_req_data['paged'])
1535
-            ? absint($this->_req_data['paged'])
1536
-            : 1;
1537
-        $per_page = ! empty($this->_req_data['perpage'])
1538
-            ? $this->_req_data['perpage']
1539
-            : $per_page;
1540
-
1541
-        // -1 means return all results so get out if that's set.
1542
-        if ((int) $per_page === -1) {
1543
-            return array();
1544
-        }
1545
-        $per_page = absint($per_page);
1546
-        $offset = ($current_page - 1) * $per_page;
1547
-        return array('limit' => array($offset, $per_page));
1548
-    }
1549
-
1550
-
1551
-    public function get_registration_status_array()
1552
-    {
1553
-        return self::$_reg_status;
1554
-    }
1555
-
1556
-
1557
-
1558
-
1559
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1560
-    /**
1561
-     *        generates HTML for the View Registration Details Admin page
1562
-     *
1563
-     * @access protected
1564
-     * @return void
1565
-     * @throws DomainException
1566
-     * @throws EE_Error
1567
-     * @throws InvalidArgumentException
1568
-     * @throws InvalidDataTypeException
1569
-     * @throws InvalidInterfaceException
1570
-     * @throws EntityNotFoundException
1571
-     */
1572
-    protected function _registration_details()
1573
-    {
1574
-        $this->_template_args = array();
1575
-        $this->_set_registration_object();
1576
-        if (is_object($this->_registration)) {
1577
-            $transaction = $this->_registration->transaction()
1578
-                ? $this->_registration->transaction()
1579
-                : EE_Transaction::new_instance();
1580
-            $this->_session = $transaction->session_data();
1581
-            $event_id = $this->_registration->event_ID();
1582
-            $this->_template_args['reg_nmbr']['value'] = $this->_registration->ID();
1583
-            $this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso');
1584
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1585
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1586
-            $this->_template_args['grand_total'] = $transaction->total();
1587
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1588
-            // link back to overview
1589
-            $this->_template_args['reg_overview_url'] = REG_ADMIN_URL;
1590
-            $this->_template_args['registration'] = $this->_registration;
1591
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1592
-                array(
1593
-                    'action'   => 'default',
1594
-                    'event_id' => $event_id,
1595
-                ),
1596
-                REG_ADMIN_URL
1597
-            );
1598
-            $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1599
-                array(
1600
-                    'action' => 'default',
1601
-                    'EVT_ID' => $event_id,
1602
-                    'page'   => 'espresso_transactions',
1603
-                ),
1604
-                admin_url('admin.php')
1605
-            );
1606
-            $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1607
-                array(
1608
-                    'page'   => 'espresso_events',
1609
-                    'action' => 'edit',
1610
-                    'post'   => $event_id,
1611
-                ),
1612
-                admin_url('admin.php')
1613
-            );
1614
-            // next and previous links
1615
-            $next_reg = $this->_registration->next(
1616
-                null,
1617
-                array(),
1618
-                'REG_ID'
1619
-            );
1620
-            $this->_template_args['next_registration'] = $next_reg
1621
-                ? $this->_next_link(
1622
-                    EE_Admin_Page::add_query_args_and_nonce(
1623
-                        array(
1624
-                            'action'  => 'view_registration',
1625
-                            '_REG_ID' => $next_reg['REG_ID'],
1626
-                        ),
1627
-                        REG_ADMIN_URL
1628
-                    ),
1629
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1630
-                )
1631
-                : '';
1632
-            $previous_reg = $this->_registration->previous(
1633
-                null,
1634
-                array(),
1635
-                'REG_ID'
1636
-            );
1637
-            $this->_template_args['previous_registration'] = $previous_reg
1638
-                ? $this->_previous_link(
1639
-                    EE_Admin_Page::add_query_args_and_nonce(
1640
-                        array(
1641
-                            'action'  => 'view_registration',
1642
-                            '_REG_ID' => $previous_reg['REG_ID'],
1643
-                        ),
1644
-                        REG_ADMIN_URL
1645
-                    ),
1646
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1647
-                )
1648
-                : '';
1649
-            // grab header
1650
-            $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1651
-            $this->_template_args['REG_ID'] = $this->_registration->ID();
1652
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1653
-                $template_path,
1654
-                $this->_template_args,
1655
-                true
1656
-            );
1657
-        } else {
1658
-            $this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1659
-        }
1660
-        // the details template wrapper
1661
-        $this->display_admin_page_with_sidebar();
1662
-    }
1663
-
1664
-
1665
-    protected function _registration_details_metaboxes()
1666
-    {
1667
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1668
-        $this->_set_registration_object();
1669
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1670
-        add_meta_box(
1671
-            'edit-reg-status-mbox',
1672
-            esc_html__('Registration Status', 'event_espresso'),
1673
-            array($this, 'set_reg_status_buttons_metabox'),
1674
-            $this->wp_page_slug,
1675
-            'normal',
1676
-            'high'
1677
-        );
1678
-        add_meta_box(
1679
-            'edit-reg-details-mbox',
1680
-            esc_html__('Registration Details', 'event_espresso'),
1681
-            array($this, '_reg_details_meta_box'),
1682
-            $this->wp_page_slug,
1683
-            'normal',
1684
-            'high'
1685
-        );
1686
-        if ($attendee instanceof EE_Attendee
1687
-            && EE_Registry::instance()->CAP->current_user_can(
1688
-                'ee_read_registration',
1689
-                'edit-reg-questions-mbox',
1690
-                $this->_registration->ID()
1691
-            )
1692
-        ) {
1693
-            add_meta_box(
1694
-                'edit-reg-questions-mbox',
1695
-                esc_html__('Registration Form Answers', 'event_espresso'),
1696
-                array($this, '_reg_questions_meta_box'),
1697
-                $this->wp_page_slug,
1698
-                'normal',
1699
-                'high'
1700
-            );
1701
-        }
1702
-        add_meta_box(
1703
-            'edit-reg-registrant-mbox',
1704
-            esc_html__('Contact Details', 'event_espresso'),
1705
-            array($this, '_reg_registrant_side_meta_box'),
1706
-            $this->wp_page_slug,
1707
-            'side',
1708
-            'high'
1709
-        );
1710
-        if ($this->_registration->group_size() > 1) {
1711
-            add_meta_box(
1712
-                'edit-reg-attendees-mbox',
1713
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1714
-                array($this, '_reg_attendees_meta_box'),
1715
-                $this->wp_page_slug,
1716
-                'normal',
1717
-                'high'
1718
-            );
1719
-        }
1720
-    }
1721
-
1722
-
1723
-    /**
1724
-     * set_reg_status_buttons_metabox
1725
-     *
1726
-     * @access protected
1727
-     * @return string
1728
-     * @throws \EE_Error
1729
-     */
1730
-    public function set_reg_status_buttons_metabox()
1731
-    {
1732
-        $this->_set_registration_object();
1733
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1734
-        echo $change_reg_status_form->form_open(
1735
-            self::add_query_args_and_nonce(
1736
-                array(
1737
-                    'action' => 'change_reg_status',
1738
-                ),
1739
-                REG_ADMIN_URL
1740
-            )
1741
-        );
1742
-        echo $change_reg_status_form->get_html();
1743
-        echo $change_reg_status_form->form_close();
1744
-    }
1745
-
1746
-
1747
-    /**
1748
-     * @return EE_Form_Section_Proper
1749
-     * @throws EE_Error
1750
-     * @throws InvalidArgumentException
1751
-     * @throws InvalidDataTypeException
1752
-     * @throws InvalidInterfaceException
1753
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1754
-     */
1755
-    protected function _generate_reg_status_change_form()
1756
-    {
1757
-        $reg_status_change_form_array = array(
1758
-            'name'            => 'reg_status_change_form',
1759
-            'html_id'         => 'reg-status-change-form',
1760
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1761
-            'subsections'     => array(
1762
-                'return'             => new EE_Hidden_Input(
1763
-                    array(
1764
-                        'name'    => 'return',
1765
-                        'default' => 'view_registration',
1766
-                    )
1767
-                ),
1768
-                'REG_ID'             => new EE_Hidden_Input(
1769
-                    array(
1770
-                        'name'    => 'REG_ID',
1771
-                        'default' => $this->_registration->ID(),
1772
-                    )
1773
-                ),
1774
-                'current_status'     => new EE_Form_Section_HTML(
1775
-                    EEH_HTML::tr(
1776
-                        EEH_HTML::th(
1777
-                            EEH_HTML::label(
1778
-                                EEH_HTML::strong(
1779
-                                    esc_html__('Current Registration Status', 'event_espresso')
1780
-                                )
1781
-                            )
1782
-                        )
1783
-                        . EEH_HTML::td(
1784
-                            EEH_HTML::strong(
1785
-                                $this->_registration->pretty_status(),
1786
-                                '',
1787
-                                'status-' . $this->_registration->status_ID(),
1788
-                                'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1789
-                            )
1790
-                        )
1791
-                    )
1792
-                )
1793
-            )
1794
-        );
1795
-        if (EE_Registry::instance()->CAP->current_user_can(
1796
-            'ee_edit_registration',
1797
-            'toggle_registration_status',
1798
-            $this->_registration->ID()
1799
-        )) {
1800
-            $reg_status_change_form_array['subsections']['reg_status'] = new EE_Select_Input(
1801
-                $this->_get_reg_statuses(),
1802
-                array(
1803
-                    'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1804
-                    'default'         => $this->_registration->status_ID(),
1805
-                )
1806
-            );
1807
-            $reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1808
-                array(
1809
-                    'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1810
-                    'default'         => false,
1811
-                    'html_help_text'  => esc_html__(
1812
-                        'If set to "Yes", then the related messages will be sent to the registrant.',
1813
-                        'event_espresso'
1814
-                    )
1815
-                )
1816
-            );
1817
-            $reg_status_change_form_array['subsections']['submit'] = new EE_Submit_Input(
1818
-                array(
1819
-                    'html_class'      => 'button-primary',
1820
-                    'html_label_text' => '&nbsp;',
1821
-                    'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1822
-                )
1823
-            );
1824
-        }
1825
-        return new EE_Form_Section_Proper($reg_status_change_form_array);
1826
-    }
1827
-
1828
-
1829
-    /**
1830
-     * Returns an array of all the buttons for the various statuses and switch status actions
1831
-     *
1832
-     * @return array
1833
-     * @throws EE_Error
1834
-     * @throws InvalidArgumentException
1835
-     * @throws InvalidDataTypeException
1836
-     * @throws InvalidInterfaceException
1837
-     * @throws EntityNotFoundException
1838
-     */
1839
-    protected function _get_reg_statuses()
1840
-    {
1841
-        $reg_status_array = EEM_Registration::instance()->reg_status_array();
1842
-        unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1843
-        // get current reg status
1844
-        $current_status = $this->_registration->status_ID();
1845
-        // is registration for free event? This will determine whether to display the pending payment option
1846
-        if ($current_status !== EEM_Registration::status_id_pending_payment
1847
-            && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1848
-        ) {
1849
-            unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1850
-        }
1851
-        return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1852
-    }
1853
-
1854
-
1855
-    /**
1856
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1857
-     *
1858
-     * @param bool $status REG status given for changing registrations to.
1859
-     * @param bool $notify Whether to send messages notifications or not.
1860
-     * @return array (array with reg_id(s) updated and whether update was successful.
1861
-     * @throws EE_Error
1862
-     * @throws InvalidArgumentException
1863
-     * @throws InvalidDataTypeException
1864
-     * @throws InvalidInterfaceException
1865
-     * @throws ReflectionException
1866
-     * @throws RuntimeException
1867
-     * @throws EntityNotFoundException
1868
-     */
1869
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1870
-    {
1871
-        if (isset($this->_req_data['reg_status_change_form'])) {
1872
-            $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1873
-                ? (array) $this->_req_data['reg_status_change_form']['REG_ID']
1874
-                : array();
1875
-        } else {
1876
-            $REG_IDs = isset($this->_req_data['_REG_ID'])
1877
-                ? (array) $this->_req_data['_REG_ID']
1878
-                : array();
1879
-        }
1880
-        // sanitize $REG_IDs
1881
-        $REG_IDs = array_map('absint', $REG_IDs);
1882
-        // and remove empty entries
1883
-        $REG_IDs = array_filter($REG_IDs);
1884
-
1885
-        $result = $this->_set_registration_status($REG_IDs, $status, $notify);
1886
-
1887
-        /**
1888
-         * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1889
-         * Currently this value is used downstream by the _process_resend_registration method.
1890
-         *
1891
-         * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1892
-         * @param bool                     $status           The status registrations were changed to.
1893
-         * @param bool                     $success          If the status was changed successfully for all registrations.
1894
-         * @param Registrations_Admin_Page $admin_page_object
1895
-         */
1896
-        $this->_req_data['_REG_ID'] = apply_filters(
1897
-            'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1898
-            $result['REG_ID'],
1899
-            $status,
1900
-            $result['success'],
1901
-            $this
1902
-        );
1903
-
1904
-        // notify?
1905
-        if ($notify
1906
-            && $result['success']
1907
-            && ! empty($this->_req_data['_REG_ID'])
1908
-            && EE_Registry::instance()->CAP->current_user_can(
1909
-                'ee_send_message',
1910
-                'espresso_registrations_resend_registration'
1911
-            )
1912
-        ) {
1913
-            $this->_process_resend_registration();
1914
-        }
1915
-        return $result;
1916
-    }
1917
-
1918
-
1919
-    /**
1920
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1921
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1922
-     *
1923
-     * @param array  $REG_IDs
1924
-     * @param string $status
1925
-     * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1926
-     *                        slug sent with setting the registration status.
1927
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1928
-     * @throws EE_Error
1929
-     * @throws InvalidArgumentException
1930
-     * @throws InvalidDataTypeException
1931
-     * @throws InvalidInterfaceException
1932
-     * @throws ReflectionException
1933
-     * @throws RuntimeException
1934
-     * @throws EntityNotFoundException
1935
-     */
1936
-    protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1937
-    {
1938
-        $success = false;
1939
-        // typecast $REG_IDs
1940
-        $REG_IDs = (array) $REG_IDs;
1941
-        if (! empty($REG_IDs)) {
1942
-            $success = true;
1943
-            // set default status if none is passed
1944
-            $status = $status ? $status : EEM_Registration::status_id_pending_payment;
1945
-            $status_context = $notify
1946
-                ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1947
-                : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1948
-            // loop through REG_ID's and change status
1949
-            foreach ($REG_IDs as $REG_ID) {
1950
-                $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1951
-                if ($registration instanceof EE_Registration) {
1952
-                    $registration->set_status(
1953
-                        $status,
1954
-                        false,
1955
-                        new Context(
1956
-                            $status_context,
1957
-                            esc_html__(
1958
-                                'Manually triggered status change on a Registration Admin Page route.',
1959
-                                'event_espresso'
1960
-                            )
1961
-                        )
1962
-                    );
1963
-                    $result = $registration->save();
1964
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1965
-                    $success = $result !== false ? $success : false;
1966
-                }
1967
-            }
1968
-        }
1969
-
1970
-        // return $success and processed registrations
1971
-        return array('REG_ID' => $REG_IDs, 'success' => $success);
1972
-    }
1973
-
1974
-
1975
-    /**
1976
-     * Common logic for setting up success message and redirecting to appropriate route
1977
-     *
1978
-     * @param  string $STS_ID status id for the registration changed to
1979
-     * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1980
-     * @return void
1981
-     * @throws EE_Error
1982
-     */
1983
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1984
-    {
1985
-        $result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1986
-            : array('success' => false);
1987
-        $success = isset($result['success']) && $result['success'];
1988
-        // setup success message
1989
-        if ($success) {
1990
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1991
-                $msg = sprintf(
1992
-                    esc_html__('Registration status has been set to %s', 'event_espresso'),
1993
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1994
-                );
1995
-            } else {
1996
-                $msg = sprintf(
1997
-                    esc_html__('Registrations have been set to %s.', 'event_espresso'),
1998
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1999
-                );
2000
-            }
2001
-            EE_Error::add_success($msg);
2002
-        } else {
2003
-            EE_Error::add_error(
2004
-                esc_html__(
2005
-                    'Something went wrong, and the status was not changed',
2006
-                    'event_espresso'
2007
-                ),
2008
-                __FILE__,
2009
-                __LINE__,
2010
-                __FUNCTION__
2011
-            );
2012
-        }
2013
-        if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
2014
-            $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
2015
-        } else {
2016
-            $route = array('action' => 'default');
2017
-        }
2018
-        $route = $this->mergeExistingRequestParamsWithRedirectArgs($route);
2019
-        $this->_redirect_after_action($success, '', '', $route, true);
2020
-    }
2021
-
2022
-
2023
-    /**
2024
-     * incoming reg status change from reg details page.
2025
-     *
2026
-     * @return void
2027
-     */
2028
-    protected function _change_reg_status()
2029
-    {
2030
-        $this->_req_data['return'] = 'view_registration';
2031
-        // set notify based on whether the send notifications toggle is set or not
2032
-        $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
2033
-        // $notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
2034
-        $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
2035
-            ? $this->_req_data['reg_status_change_form']['reg_status'] : '';
2036
-        switch ($this->_req_data['reg_status_change_form']['reg_status']) {
2037
-            case EEM_Registration::status_id_approved:
2038
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
2039
-                $this->approve_registration($notify);
2040
-                break;
2041
-            case EEM_Registration::status_id_pending_payment:
2042
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
2043
-                $this->pending_registration($notify);
2044
-                break;
2045
-            case EEM_Registration::status_id_not_approved:
2046
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
2047
-                $this->not_approve_registration($notify);
2048
-                break;
2049
-            case EEM_Registration::status_id_declined:
2050
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
2051
-                $this->decline_registration($notify);
2052
-                break;
2053
-            case EEM_Registration::status_id_cancelled:
2054
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
2055
-                $this->cancel_registration($notify);
2056
-                break;
2057
-            case EEM_Registration::status_id_wait_list:
2058
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
2059
-                $this->wait_list_registration($notify);
2060
-                break;
2061
-            case EEM_Registration::status_id_incomplete:
2062
-            default:
2063
-                $result['success'] = false;
2064
-                unset($this->_req_data['return']);
2065
-                $this->_reg_status_change_return('', false);
2066
-                break;
2067
-        }
2068
-    }
2069
-
2070
-
2071
-    /**
2072
-     * Callback for bulk action routes.
2073
-     * Note: although we could just register the singular route callbacks for each bulk action route as well, this
2074
-     * method was chosen so there is one central place all the registration status bulk actions are going through.
2075
-     * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
2076
-     * when an action is happening on just a single registration).
2077
-     *
2078
-     * @param      $action
2079
-     * @param bool $notify
2080
-     */
2081
-    protected function bulk_action_on_registrations($action, $notify = false)
2082
-    {
2083
-        do_action(
2084
-            'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
2085
-            $this,
2086
-            $action,
2087
-            $notify
2088
-        );
2089
-        $method = $action . '_registration';
2090
-        if (method_exists($this, $method)) {
2091
-            $this->$method($notify);
2092
-        }
2093
-    }
2094
-
2095
-
2096
-    /**
2097
-     * approve_registration
2098
-     *
2099
-     * @access protected
2100
-     * @param bool $notify whether or not to notify the registrant about their approval.
2101
-     * @return void
2102
-     */
2103
-    protected function approve_registration($notify = false)
2104
-    {
2105
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
2106
-    }
2107
-
2108
-
2109
-    /**
2110
-     *        decline_registration
2111
-     *
2112
-     * @access protected
2113
-     * @param bool $notify whether or not to notify the registrant about their status change.
2114
-     * @return void
2115
-     */
2116
-    protected function decline_registration($notify = false)
2117
-    {
2118
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
2119
-    }
2120
-
2121
-
2122
-    /**
2123
-     *        cancel_registration
2124
-     *
2125
-     * @access protected
2126
-     * @param bool $notify whether or not to notify the registrant about their status change.
2127
-     * @return void
2128
-     */
2129
-    protected function cancel_registration($notify = false)
2130
-    {
2131
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
2132
-    }
2133
-
2134
-
2135
-    /**
2136
-     *        not_approve_registration
2137
-     *
2138
-     * @access protected
2139
-     * @param bool $notify whether or not to notify the registrant about their status change.
2140
-     * @return void
2141
-     */
2142
-    protected function not_approve_registration($notify = false)
2143
-    {
2144
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
2145
-    }
2146
-
2147
-
2148
-    /**
2149
-     *        decline_registration
2150
-     *
2151
-     * @access protected
2152
-     * @param bool $notify whether or not to notify the registrant about their status change.
2153
-     * @return void
2154
-     */
2155
-    protected function pending_registration($notify = false)
2156
-    {
2157
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
2158
-    }
2159
-
2160
-
2161
-    /**
2162
-     * waitlist_registration
2163
-     *
2164
-     * @access protected
2165
-     * @param bool $notify whether or not to notify the registrant about their status change.
2166
-     * @return void
2167
-     */
2168
-    protected function wait_list_registration($notify = false)
2169
-    {
2170
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2171
-    }
2172
-
2173
-
2174
-    /**
2175
-     *        generates HTML for the Registration main meta box
2176
-     *
2177
-     * @access public
2178
-     * @return void
2179
-     * @throws DomainException
2180
-     * @throws EE_Error
2181
-     * @throws InvalidArgumentException
2182
-     * @throws InvalidDataTypeException
2183
-     * @throws InvalidInterfaceException
2184
-     * @throws ReflectionException
2185
-     * @throws EntityNotFoundException
2186
-     */
2187
-    public function _reg_details_meta_box()
2188
-    {
2189
-        EEH_Autoloader::register_line_item_display_autoloaders();
2190
-        EEH_Autoloader::register_line_item_filter_autoloaders();
2191
-        EE_Registry::instance()->load_helper('Line_Item');
2192
-        $transaction = $this->_registration->transaction() ? $this->_registration->transaction()
2193
-            : EE_Transaction::new_instance();
2194
-        $this->_session = $transaction->session_data();
2195
-        $filters = new EE_Line_Item_Filter_Collection();
2196
-        // $filters->add( new EE_Non_Zero_Line_Item_Filter() );
2197
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2198
-        $line_item_filter_processor = new EE_Line_Item_Filter_Processor(
2199
-            $filters,
2200
-            $transaction->total_line_item()
2201
-        );
2202
-        $filtered_line_item_tree = $line_item_filter_processor->process();
2203
-        $line_item_display = new EE_Line_Item_Display(
2204
-            'reg_admin_table',
2205
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2206
-        );
2207
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2208
-            $filtered_line_item_tree,
2209
-            array('EE_Registration' => $this->_registration)
2210
-        );
2211
-        $attendee = $this->_registration->attendee();
2212
-        if (EE_Registry::instance()->CAP->current_user_can(
2213
-            'ee_read_transaction',
2214
-            'espresso_transactions_view_transaction'
2215
-        )) {
2216
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2217
-                EE_Admin_Page::add_query_args_and_nonce(
2218
-                    array(
2219
-                        'action' => 'view_transaction',
2220
-                        'TXN_ID' => $transaction->ID(),
2221
-                    ),
2222
-                    TXN_ADMIN_URL
2223
-                ),
2224
-                esc_html__(' View Transaction', 'event_espresso'),
2225
-                'button secondary-button right',
2226
-                'dashicons dashicons-cart'
2227
-            );
2228
-        } else {
2229
-            $this->_template_args['view_transaction_button'] = '';
2230
-        }
2231
-        if ($attendee instanceof EE_Attendee
2232
-            && EE_Registry::instance()->CAP->current_user_can(
2233
-                'ee_send_message',
2234
-                'espresso_registrations_resend_registration'
2235
-            )
2236
-        ) {
2237
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2238
-                EE_Admin_Page::add_query_args_and_nonce(
2239
-                    array(
2240
-                        'action'      => 'resend_registration',
2241
-                        '_REG_ID'     => $this->_registration->ID(),
2242
-                        'redirect_to' => 'view_registration',
2243
-                    ),
2244
-                    REG_ADMIN_URL
2245
-                ),
2246
-                esc_html__(' Resend Registration', 'event_espresso'),
2247
-                'button secondary-button right',
2248
-                'dashicons dashicons-email-alt'
2249
-            );
2250
-        } else {
2251
-            $this->_template_args['resend_registration_button'] = '';
2252
-        }
2253
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2254
-        $payment = $transaction->get_first_related('Payment');
2255
-        $payment = ! $payment instanceof EE_Payment
2256
-            ? EE_Payment::new_instance()
2257
-            : $payment;
2258
-        $payment_method = $payment->get_first_related('Payment_Method');
2259
-        $payment_method = ! $payment_method instanceof EE_Payment_Method
2260
-            ? EE_Payment_Method::new_instance()
2261
-            : $payment_method;
2262
-        $reg_details = array(
2263
-            'payment_method'       => $payment_method->name(),
2264
-            'response_msg'         => $payment->gateway_response(),
2265
-            'registration_id'      => $this->_registration->get('REG_code'),
2266
-            'registration_session' => $this->_registration->session_ID(),
2267
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2268
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2269
-        );
2270
-        if (isset($reg_details['registration_id'])) {
2271
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2272
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2273
-                'Registration ID',
2274
-                'event_espresso'
2275
-            );
2276
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2277
-        }
2278
-        if (isset($reg_details['payment_method'])) {
2279
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2280
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2281
-                'Most Recent Payment Method',
2282
-                'event_espresso'
2283
-            );
2284
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2285
-            $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg'];
2286
-            $this->_template_args['reg_details']['response_msg']['label'] = esc_html__(
2287
-                'Payment method response',
2288
-                'event_espresso'
2289
-            );
2290
-            $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2291
-        }
2292
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2293
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2294
-            'Registration Session',
2295
-            'event_espresso'
2296
-        );
2297
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2298
-        $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address'];
2299
-        $this->_template_args['reg_details']['ip_address']['label'] = esc_html__(
2300
-            'Registration placed from IP',
2301
-            'event_espresso'
2302
-        );
2303
-        $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text';
2304
-        $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent'];
2305
-        $this->_template_args['reg_details']['user_agent']['label'] = esc_html__(
2306
-            'Registrant User Agent',
2307
-            'event_espresso'
2308
-        );
2309
-        $this->_template_args['reg_details']['user_agent']['class'] = 'large-text';
2310
-        $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
2311
-            array(
2312
-                'action'   => 'default',
2313
-                'event_id' => $this->_registration->event_ID(),
2314
-            ),
2315
-            REG_ADMIN_URL
2316
-        );
2317
-        $this->_template_args['REG_ID'] = $this->_registration->ID();
2318
-        $this->_template_args['event_id'] = $this->_registration->event_ID();
2319
-        $template_path =
2320
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2321
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2322
-    }
2323
-
2324
-
2325
-    /**
2326
-     * generates HTML for the Registration Questions meta box.
2327
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2328
-     * otherwise uses new forms system
2329
-     *
2330
-     * @access public
2331
-     * @return void
2332
-     * @throws DomainException
2333
-     * @throws EE_Error
2334
-     */
2335
-    public function _reg_questions_meta_box()
2336
-    {
2337
-        // allow someone to override this method entirely
2338
-        if (apply_filters(
2339
-            'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2340
-            true,
2341
-            $this,
2342
-            $this->_registration
2343
-        )) {
2344
-            $form = $this->_get_reg_custom_questions_form(
2345
-                $this->_registration->ID()
2346
-            );
2347
-            $this->_template_args['att_questions'] = count($form->subforms()) > 0
2348
-                ? $form->get_html_and_js()
2349
-                : '';
2350
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2351
-            $this->_template_args['REG_ID'] = $this->_registration->ID();
2352
-            $template_path =
2353
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2354
-            echo EEH_Template::display_template($template_path, $this->_template_args, true);
2355
-        }
2356
-    }
2357
-
2358
-
2359
-    /**
2360
-     * form_before_question_group
2361
-     *
2362
-     * @deprecated    as of 4.8.32.rc.000
2363
-     * @access        public
2364
-     * @param        string $output
2365
-     * @return        string
2366
-     */
2367
-    public function form_before_question_group($output)
2368
-    {
2369
-        EE_Error::doing_it_wrong(
2370
-            __CLASS__ . '::' . __FUNCTION__,
2371
-            esc_html__(
2372
-                '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.',
2373
-                'event_espresso'
2374
-            ),
2375
-            '4.8.32.rc.000'
2376
-        );
2377
-        return '
1301
+		if (! empty($registration_status)) {
1302
+			$where['STS_ID'] = $registration_status;
1303
+		} else {
1304
+			// make sure we exclude incomplete registrations, but only if not trashed.
1305
+			if ($view === 'trash') {
1306
+				$where['REG_deleted'] = true;
1307
+			} elseif ($view === 'incomplete') {
1308
+				$where['STS_ID'] = EEM_Registration::status_id_incomplete;
1309
+			} else {
1310
+				$where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1311
+			}
1312
+		}
1313
+		return $where;
1314
+	}
1315
+
1316
+
1317
+	/**
1318
+	 * Adds any provided date restraints to the where conditions for the registrations query.
1319
+	 *
1320
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1321
+	 * @return array
1322
+	 * @throws EE_Error
1323
+	 * @throws InvalidArgumentException
1324
+	 * @throws InvalidDataTypeException
1325
+	 * @throws InvalidInterfaceException
1326
+	 */
1327
+	protected function _add_date_to_where_conditions(array $request)
1328
+	{
1329
+		$where = array();
1330
+		$view = EEH_Array::is_set($request, 'status', '');
1331
+		$month_range = ! empty($request['month_range'])
1332
+			? sanitize_text_field($request['month_range'])
1333
+			: '';
1334
+		$retrieve_for_today = $view === 'today';
1335
+		$retrieve_for_this_month = $view === 'month';
1336
+
1337
+		if ($retrieve_for_today) {
1338
+			$now = date('Y-m-d', current_time('timestamp'));
1339
+			$where['REG_date'] = array(
1340
+				'BETWEEN',
1341
+				array(
1342
+					EEM_Registration::instance()->convert_datetime_for_query(
1343
+						'REG_date',
1344
+						$now . ' 00:00:00',
1345
+						'Y-m-d H:i:s'
1346
+					),
1347
+					EEM_Registration::instance()->convert_datetime_for_query(
1348
+						'REG_date',
1349
+						$now . ' 23:59:59',
1350
+						'Y-m-d H:i:s'
1351
+					),
1352
+				),
1353
+			);
1354
+		} elseif ($retrieve_for_this_month) {
1355
+			$current_year_and_month = date('Y-m', current_time('timestamp'));
1356
+			$days_this_month = date('t', current_time('timestamp'));
1357
+			$where['REG_date'] = array(
1358
+				'BETWEEN',
1359
+				array(
1360
+					EEM_Registration::instance()->convert_datetime_for_query(
1361
+						'REG_date',
1362
+						$current_year_and_month . '-01 00:00:00',
1363
+						'Y-m-d H:i:s'
1364
+					),
1365
+					EEM_Registration::instance()->convert_datetime_for_query(
1366
+						'REG_date',
1367
+						$current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1368
+						'Y-m-d H:i:s'
1369
+					),
1370
+				),
1371
+			);
1372
+		} elseif ($month_range) {
1373
+			$pieces = explode(' ', $month_range, 3);
1374
+			$month_requested = ! empty($pieces[0])
1375
+				? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1376
+				: '';
1377
+			$year_requested = ! empty($pieces[1])
1378
+				? $pieces[1]
1379
+				: '';
1380
+			// if there is not a month or year then we can't go further
1381
+			if ($month_requested && $year_requested) {
1382
+				$days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1383
+				$where['REG_date'] = array(
1384
+					'BETWEEN',
1385
+					array(
1386
+						EEM_Registration::instance()->convert_datetime_for_query(
1387
+							'REG_date',
1388
+							$year_requested . '-' . $month_requested . '-01 00:00:00',
1389
+							'Y-m-d H:i:s'
1390
+						),
1391
+						EEM_Registration::instance()->convert_datetime_for_query(
1392
+							'REG_date',
1393
+							$year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1394
+							'Y-m-d H:i:s'
1395
+						),
1396
+					),
1397
+				);
1398
+			}
1399
+		}
1400
+		return $where;
1401
+	}
1402
+
1403
+
1404
+	/**
1405
+	 * Adds any provided search restraints to the where conditions for the registrations query
1406
+	 *
1407
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1408
+	 * @return array
1409
+	 */
1410
+	protected function _add_search_to_where_conditions(array $request)
1411
+	{
1412
+		$where = array();
1413
+		if (! empty($request['s'])) {
1414
+			$search_string = '%' . sanitize_text_field($request['s']) . '%';
1415
+			$where['OR*search_conditions'] = array(
1416
+				'Event.EVT_name'                          => array('LIKE', $search_string),
1417
+				'Event.EVT_desc'                          => array('LIKE', $search_string),
1418
+				'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1419
+				'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1420
+				'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1421
+				'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1422
+				'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1423
+				'Attendee.ATT_email'                      => array('LIKE', $search_string),
1424
+				'Attendee.ATT_address'                    => array('LIKE', $search_string),
1425
+				'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1426
+				'Attendee.ATT_city'                       => array('LIKE', $search_string),
1427
+				'REG_final_price'                         => array('LIKE', $search_string),
1428
+				'REG_code'                                => array('LIKE', $search_string),
1429
+				'REG_count'                               => array('LIKE', $search_string),
1430
+				'REG_group_size'                          => array('LIKE', $search_string),
1431
+				'Ticket.TKT_name'                         => array('LIKE', $search_string),
1432
+				'Ticket.TKT_description'                  => array('LIKE', $search_string),
1433
+				'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1434
+			);
1435
+		}
1436
+		return $where;
1437
+	}
1438
+
1439
+
1440
+	/**
1441
+	 * Sets up the where conditions for the registrations query.
1442
+	 *
1443
+	 * @param array $request
1444
+	 * @return array
1445
+	 * @throws EE_Error
1446
+	 */
1447
+	protected function _get_where_conditions_for_registrations_query($request)
1448
+	{
1449
+		return apply_filters(
1450
+			'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1451
+			array_merge(
1452
+				$this->addAttendeeIdToWhereConditions($request),
1453
+				$this->_add_event_id_to_where_conditions($request),
1454
+				$this->_add_category_id_to_where_conditions($request),
1455
+				$this->_add_datetime_id_to_where_conditions($request),
1456
+				$this->_add_registration_status_to_where_conditions($request),
1457
+				$this->_add_date_to_where_conditions($request),
1458
+				$this->_add_search_to_where_conditions($request)
1459
+			),
1460
+			$request
1461
+		);
1462
+	}
1463
+
1464
+
1465
+	/**
1466
+	 * Sets up the orderby for the registrations query.
1467
+	 *
1468
+	 * @return array
1469
+	 */
1470
+	protected function _get_orderby_for_registrations_query()
1471
+	{
1472
+		$orderby_field = ! empty($this->_req_data['orderby'])
1473
+			? sanitize_text_field($this->_req_data['orderby'])
1474
+			: '_REG_date';
1475
+		switch ($orderby_field) {
1476
+			case '_REG_ID':
1477
+				$orderby = array('REG_ID');
1478
+				break;
1479
+			case '_Reg_status':
1480
+				$orderby = array('STS_ID');
1481
+				break;
1482
+			case 'ATT_fname':
1483
+				$orderby = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1484
+				break;
1485
+			case 'ATT_lname':
1486
+				$orderby = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1487
+				break;
1488
+			case 'event_name':
1489
+				$orderby = array('Event.EVT_name');
1490
+				break;
1491
+			case 'DTT_EVT_start':
1492
+				$orderby = array('Event.Datetime.DTT_EVT_start');
1493
+				break;
1494
+			case '_REG_date':
1495
+				$orderby = array('REG_date');
1496
+				break;
1497
+			default:
1498
+				$orderby = array($orderby_field);
1499
+				break;
1500
+		}
1501
+
1502
+		// order
1503
+		$order = ! empty($this->_req_data['order'])
1504
+			? sanitize_text_field($this->_req_data['order'])
1505
+			: 'DESC';
1506
+		$orderby = array_combine(
1507
+			$orderby,
1508
+			array_fill(0, count($orderby), $order)
1509
+		);
1510
+		// because there are many registrations with the same date, define
1511
+		// a secondary way to order them, otherwise MySQL seems to be a bit random
1512
+		if (empty($orderby['REG_ID'])) {
1513
+			$orderby['REG_ID'] = $order;
1514
+		}
1515
+
1516
+		$orderby = apply_filters(
1517
+			'FHEE__Registrations_Admin_Page___get_orderby_for_registrations_query',
1518
+			$orderby,
1519
+			$this->_req_data
1520
+		);
1521
+
1522
+		return array('order_by' => $orderby);
1523
+	}
1524
+
1525
+
1526
+	/**
1527
+	 * Sets up the limit for the registrations query.
1528
+	 *
1529
+	 * @param $per_page
1530
+	 * @return array
1531
+	 */
1532
+	protected function _get_limit($per_page)
1533
+	{
1534
+		$current_page = ! empty($this->_req_data['paged'])
1535
+			? absint($this->_req_data['paged'])
1536
+			: 1;
1537
+		$per_page = ! empty($this->_req_data['perpage'])
1538
+			? $this->_req_data['perpage']
1539
+			: $per_page;
1540
+
1541
+		// -1 means return all results so get out if that's set.
1542
+		if ((int) $per_page === -1) {
1543
+			return array();
1544
+		}
1545
+		$per_page = absint($per_page);
1546
+		$offset = ($current_page - 1) * $per_page;
1547
+		return array('limit' => array($offset, $per_page));
1548
+	}
1549
+
1550
+
1551
+	public function get_registration_status_array()
1552
+	{
1553
+		return self::$_reg_status;
1554
+	}
1555
+
1556
+
1557
+
1558
+
1559
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1560
+	/**
1561
+	 *        generates HTML for the View Registration Details Admin page
1562
+	 *
1563
+	 * @access protected
1564
+	 * @return void
1565
+	 * @throws DomainException
1566
+	 * @throws EE_Error
1567
+	 * @throws InvalidArgumentException
1568
+	 * @throws InvalidDataTypeException
1569
+	 * @throws InvalidInterfaceException
1570
+	 * @throws EntityNotFoundException
1571
+	 */
1572
+	protected function _registration_details()
1573
+	{
1574
+		$this->_template_args = array();
1575
+		$this->_set_registration_object();
1576
+		if (is_object($this->_registration)) {
1577
+			$transaction = $this->_registration->transaction()
1578
+				? $this->_registration->transaction()
1579
+				: EE_Transaction::new_instance();
1580
+			$this->_session = $transaction->session_data();
1581
+			$event_id = $this->_registration->event_ID();
1582
+			$this->_template_args['reg_nmbr']['value'] = $this->_registration->ID();
1583
+			$this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso');
1584
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1585
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1586
+			$this->_template_args['grand_total'] = $transaction->total();
1587
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1588
+			// link back to overview
1589
+			$this->_template_args['reg_overview_url'] = REG_ADMIN_URL;
1590
+			$this->_template_args['registration'] = $this->_registration;
1591
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1592
+				array(
1593
+					'action'   => 'default',
1594
+					'event_id' => $event_id,
1595
+				),
1596
+				REG_ADMIN_URL
1597
+			);
1598
+			$this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1599
+				array(
1600
+					'action' => 'default',
1601
+					'EVT_ID' => $event_id,
1602
+					'page'   => 'espresso_transactions',
1603
+				),
1604
+				admin_url('admin.php')
1605
+			);
1606
+			$this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1607
+				array(
1608
+					'page'   => 'espresso_events',
1609
+					'action' => 'edit',
1610
+					'post'   => $event_id,
1611
+				),
1612
+				admin_url('admin.php')
1613
+			);
1614
+			// next and previous links
1615
+			$next_reg = $this->_registration->next(
1616
+				null,
1617
+				array(),
1618
+				'REG_ID'
1619
+			);
1620
+			$this->_template_args['next_registration'] = $next_reg
1621
+				? $this->_next_link(
1622
+					EE_Admin_Page::add_query_args_and_nonce(
1623
+						array(
1624
+							'action'  => 'view_registration',
1625
+							'_REG_ID' => $next_reg['REG_ID'],
1626
+						),
1627
+						REG_ADMIN_URL
1628
+					),
1629
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1630
+				)
1631
+				: '';
1632
+			$previous_reg = $this->_registration->previous(
1633
+				null,
1634
+				array(),
1635
+				'REG_ID'
1636
+			);
1637
+			$this->_template_args['previous_registration'] = $previous_reg
1638
+				? $this->_previous_link(
1639
+					EE_Admin_Page::add_query_args_and_nonce(
1640
+						array(
1641
+							'action'  => 'view_registration',
1642
+							'_REG_ID' => $previous_reg['REG_ID'],
1643
+						),
1644
+						REG_ADMIN_URL
1645
+					),
1646
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1647
+				)
1648
+				: '';
1649
+			// grab header
1650
+			$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1651
+			$this->_template_args['REG_ID'] = $this->_registration->ID();
1652
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1653
+				$template_path,
1654
+				$this->_template_args,
1655
+				true
1656
+			);
1657
+		} else {
1658
+			$this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1659
+		}
1660
+		// the details template wrapper
1661
+		$this->display_admin_page_with_sidebar();
1662
+	}
1663
+
1664
+
1665
+	protected function _registration_details_metaboxes()
1666
+	{
1667
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1668
+		$this->_set_registration_object();
1669
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1670
+		add_meta_box(
1671
+			'edit-reg-status-mbox',
1672
+			esc_html__('Registration Status', 'event_espresso'),
1673
+			array($this, 'set_reg_status_buttons_metabox'),
1674
+			$this->wp_page_slug,
1675
+			'normal',
1676
+			'high'
1677
+		);
1678
+		add_meta_box(
1679
+			'edit-reg-details-mbox',
1680
+			esc_html__('Registration Details', 'event_espresso'),
1681
+			array($this, '_reg_details_meta_box'),
1682
+			$this->wp_page_slug,
1683
+			'normal',
1684
+			'high'
1685
+		);
1686
+		if ($attendee instanceof EE_Attendee
1687
+			&& EE_Registry::instance()->CAP->current_user_can(
1688
+				'ee_read_registration',
1689
+				'edit-reg-questions-mbox',
1690
+				$this->_registration->ID()
1691
+			)
1692
+		) {
1693
+			add_meta_box(
1694
+				'edit-reg-questions-mbox',
1695
+				esc_html__('Registration Form Answers', 'event_espresso'),
1696
+				array($this, '_reg_questions_meta_box'),
1697
+				$this->wp_page_slug,
1698
+				'normal',
1699
+				'high'
1700
+			);
1701
+		}
1702
+		add_meta_box(
1703
+			'edit-reg-registrant-mbox',
1704
+			esc_html__('Contact Details', 'event_espresso'),
1705
+			array($this, '_reg_registrant_side_meta_box'),
1706
+			$this->wp_page_slug,
1707
+			'side',
1708
+			'high'
1709
+		);
1710
+		if ($this->_registration->group_size() > 1) {
1711
+			add_meta_box(
1712
+				'edit-reg-attendees-mbox',
1713
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1714
+				array($this, '_reg_attendees_meta_box'),
1715
+				$this->wp_page_slug,
1716
+				'normal',
1717
+				'high'
1718
+			);
1719
+		}
1720
+	}
1721
+
1722
+
1723
+	/**
1724
+	 * set_reg_status_buttons_metabox
1725
+	 *
1726
+	 * @access protected
1727
+	 * @return string
1728
+	 * @throws \EE_Error
1729
+	 */
1730
+	public function set_reg_status_buttons_metabox()
1731
+	{
1732
+		$this->_set_registration_object();
1733
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1734
+		echo $change_reg_status_form->form_open(
1735
+			self::add_query_args_and_nonce(
1736
+				array(
1737
+					'action' => 'change_reg_status',
1738
+				),
1739
+				REG_ADMIN_URL
1740
+			)
1741
+		);
1742
+		echo $change_reg_status_form->get_html();
1743
+		echo $change_reg_status_form->form_close();
1744
+	}
1745
+
1746
+
1747
+	/**
1748
+	 * @return EE_Form_Section_Proper
1749
+	 * @throws EE_Error
1750
+	 * @throws InvalidArgumentException
1751
+	 * @throws InvalidDataTypeException
1752
+	 * @throws InvalidInterfaceException
1753
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1754
+	 */
1755
+	protected function _generate_reg_status_change_form()
1756
+	{
1757
+		$reg_status_change_form_array = array(
1758
+			'name'            => 'reg_status_change_form',
1759
+			'html_id'         => 'reg-status-change-form',
1760
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1761
+			'subsections'     => array(
1762
+				'return'             => new EE_Hidden_Input(
1763
+					array(
1764
+						'name'    => 'return',
1765
+						'default' => 'view_registration',
1766
+					)
1767
+				),
1768
+				'REG_ID'             => new EE_Hidden_Input(
1769
+					array(
1770
+						'name'    => 'REG_ID',
1771
+						'default' => $this->_registration->ID(),
1772
+					)
1773
+				),
1774
+				'current_status'     => new EE_Form_Section_HTML(
1775
+					EEH_HTML::tr(
1776
+						EEH_HTML::th(
1777
+							EEH_HTML::label(
1778
+								EEH_HTML::strong(
1779
+									esc_html__('Current Registration Status', 'event_espresso')
1780
+								)
1781
+							)
1782
+						)
1783
+						. EEH_HTML::td(
1784
+							EEH_HTML::strong(
1785
+								$this->_registration->pretty_status(),
1786
+								'',
1787
+								'status-' . $this->_registration->status_ID(),
1788
+								'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1789
+							)
1790
+						)
1791
+					)
1792
+				)
1793
+			)
1794
+		);
1795
+		if (EE_Registry::instance()->CAP->current_user_can(
1796
+			'ee_edit_registration',
1797
+			'toggle_registration_status',
1798
+			$this->_registration->ID()
1799
+		)) {
1800
+			$reg_status_change_form_array['subsections']['reg_status'] = new EE_Select_Input(
1801
+				$this->_get_reg_statuses(),
1802
+				array(
1803
+					'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1804
+					'default'         => $this->_registration->status_ID(),
1805
+				)
1806
+			);
1807
+			$reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1808
+				array(
1809
+					'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1810
+					'default'         => false,
1811
+					'html_help_text'  => esc_html__(
1812
+						'If set to "Yes", then the related messages will be sent to the registrant.',
1813
+						'event_espresso'
1814
+					)
1815
+				)
1816
+			);
1817
+			$reg_status_change_form_array['subsections']['submit'] = new EE_Submit_Input(
1818
+				array(
1819
+					'html_class'      => 'button-primary',
1820
+					'html_label_text' => '&nbsp;',
1821
+					'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1822
+				)
1823
+			);
1824
+		}
1825
+		return new EE_Form_Section_Proper($reg_status_change_form_array);
1826
+	}
1827
+
1828
+
1829
+	/**
1830
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1831
+	 *
1832
+	 * @return array
1833
+	 * @throws EE_Error
1834
+	 * @throws InvalidArgumentException
1835
+	 * @throws InvalidDataTypeException
1836
+	 * @throws InvalidInterfaceException
1837
+	 * @throws EntityNotFoundException
1838
+	 */
1839
+	protected function _get_reg_statuses()
1840
+	{
1841
+		$reg_status_array = EEM_Registration::instance()->reg_status_array();
1842
+		unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1843
+		// get current reg status
1844
+		$current_status = $this->_registration->status_ID();
1845
+		// is registration for free event? This will determine whether to display the pending payment option
1846
+		if ($current_status !== EEM_Registration::status_id_pending_payment
1847
+			&& EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1848
+		) {
1849
+			unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1850
+		}
1851
+		return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1852
+	}
1853
+
1854
+
1855
+	/**
1856
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1857
+	 *
1858
+	 * @param bool $status REG status given for changing registrations to.
1859
+	 * @param bool $notify Whether to send messages notifications or not.
1860
+	 * @return array (array with reg_id(s) updated and whether update was successful.
1861
+	 * @throws EE_Error
1862
+	 * @throws InvalidArgumentException
1863
+	 * @throws InvalidDataTypeException
1864
+	 * @throws InvalidInterfaceException
1865
+	 * @throws ReflectionException
1866
+	 * @throws RuntimeException
1867
+	 * @throws EntityNotFoundException
1868
+	 */
1869
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1870
+	{
1871
+		if (isset($this->_req_data['reg_status_change_form'])) {
1872
+			$REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1873
+				? (array) $this->_req_data['reg_status_change_form']['REG_ID']
1874
+				: array();
1875
+		} else {
1876
+			$REG_IDs = isset($this->_req_data['_REG_ID'])
1877
+				? (array) $this->_req_data['_REG_ID']
1878
+				: array();
1879
+		}
1880
+		// sanitize $REG_IDs
1881
+		$REG_IDs = array_map('absint', $REG_IDs);
1882
+		// and remove empty entries
1883
+		$REG_IDs = array_filter($REG_IDs);
1884
+
1885
+		$result = $this->_set_registration_status($REG_IDs, $status, $notify);
1886
+
1887
+		/**
1888
+		 * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1889
+		 * Currently this value is used downstream by the _process_resend_registration method.
1890
+		 *
1891
+		 * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1892
+		 * @param bool                     $status           The status registrations were changed to.
1893
+		 * @param bool                     $success          If the status was changed successfully for all registrations.
1894
+		 * @param Registrations_Admin_Page $admin_page_object
1895
+		 */
1896
+		$this->_req_data['_REG_ID'] = apply_filters(
1897
+			'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1898
+			$result['REG_ID'],
1899
+			$status,
1900
+			$result['success'],
1901
+			$this
1902
+		);
1903
+
1904
+		// notify?
1905
+		if ($notify
1906
+			&& $result['success']
1907
+			&& ! empty($this->_req_data['_REG_ID'])
1908
+			&& EE_Registry::instance()->CAP->current_user_can(
1909
+				'ee_send_message',
1910
+				'espresso_registrations_resend_registration'
1911
+			)
1912
+		) {
1913
+			$this->_process_resend_registration();
1914
+		}
1915
+		return $result;
1916
+	}
1917
+
1918
+
1919
+	/**
1920
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1921
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1922
+	 *
1923
+	 * @param array  $REG_IDs
1924
+	 * @param string $status
1925
+	 * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1926
+	 *                        slug sent with setting the registration status.
1927
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1928
+	 * @throws EE_Error
1929
+	 * @throws InvalidArgumentException
1930
+	 * @throws InvalidDataTypeException
1931
+	 * @throws InvalidInterfaceException
1932
+	 * @throws ReflectionException
1933
+	 * @throws RuntimeException
1934
+	 * @throws EntityNotFoundException
1935
+	 */
1936
+	protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1937
+	{
1938
+		$success = false;
1939
+		// typecast $REG_IDs
1940
+		$REG_IDs = (array) $REG_IDs;
1941
+		if (! empty($REG_IDs)) {
1942
+			$success = true;
1943
+			// set default status if none is passed
1944
+			$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1945
+			$status_context = $notify
1946
+				? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1947
+				: Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1948
+			// loop through REG_ID's and change status
1949
+			foreach ($REG_IDs as $REG_ID) {
1950
+				$registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1951
+				if ($registration instanceof EE_Registration) {
1952
+					$registration->set_status(
1953
+						$status,
1954
+						false,
1955
+						new Context(
1956
+							$status_context,
1957
+							esc_html__(
1958
+								'Manually triggered status change on a Registration Admin Page route.',
1959
+								'event_espresso'
1960
+							)
1961
+						)
1962
+					);
1963
+					$result = $registration->save();
1964
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1965
+					$success = $result !== false ? $success : false;
1966
+				}
1967
+			}
1968
+		}
1969
+
1970
+		// return $success and processed registrations
1971
+		return array('REG_ID' => $REG_IDs, 'success' => $success);
1972
+	}
1973
+
1974
+
1975
+	/**
1976
+	 * Common logic for setting up success message and redirecting to appropriate route
1977
+	 *
1978
+	 * @param  string $STS_ID status id for the registration changed to
1979
+	 * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1980
+	 * @return void
1981
+	 * @throws EE_Error
1982
+	 */
1983
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1984
+	{
1985
+		$result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1986
+			: array('success' => false);
1987
+		$success = isset($result['success']) && $result['success'];
1988
+		// setup success message
1989
+		if ($success) {
1990
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1991
+				$msg = sprintf(
1992
+					esc_html__('Registration status has been set to %s', 'event_espresso'),
1993
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1994
+				);
1995
+			} else {
1996
+				$msg = sprintf(
1997
+					esc_html__('Registrations have been set to %s.', 'event_espresso'),
1998
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1999
+				);
2000
+			}
2001
+			EE_Error::add_success($msg);
2002
+		} else {
2003
+			EE_Error::add_error(
2004
+				esc_html__(
2005
+					'Something went wrong, and the status was not changed',
2006
+					'event_espresso'
2007
+				),
2008
+				__FILE__,
2009
+				__LINE__,
2010
+				__FUNCTION__
2011
+			);
2012
+		}
2013
+		if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
2014
+			$route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
2015
+		} else {
2016
+			$route = array('action' => 'default');
2017
+		}
2018
+		$route = $this->mergeExistingRequestParamsWithRedirectArgs($route);
2019
+		$this->_redirect_after_action($success, '', '', $route, true);
2020
+	}
2021
+
2022
+
2023
+	/**
2024
+	 * incoming reg status change from reg details page.
2025
+	 *
2026
+	 * @return void
2027
+	 */
2028
+	protected function _change_reg_status()
2029
+	{
2030
+		$this->_req_data['return'] = 'view_registration';
2031
+		// set notify based on whether the send notifications toggle is set or not
2032
+		$notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
2033
+		// $notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
2034
+		$this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
2035
+			? $this->_req_data['reg_status_change_form']['reg_status'] : '';
2036
+		switch ($this->_req_data['reg_status_change_form']['reg_status']) {
2037
+			case EEM_Registration::status_id_approved:
2038
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
2039
+				$this->approve_registration($notify);
2040
+				break;
2041
+			case EEM_Registration::status_id_pending_payment:
2042
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
2043
+				$this->pending_registration($notify);
2044
+				break;
2045
+			case EEM_Registration::status_id_not_approved:
2046
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
2047
+				$this->not_approve_registration($notify);
2048
+				break;
2049
+			case EEM_Registration::status_id_declined:
2050
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
2051
+				$this->decline_registration($notify);
2052
+				break;
2053
+			case EEM_Registration::status_id_cancelled:
2054
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
2055
+				$this->cancel_registration($notify);
2056
+				break;
2057
+			case EEM_Registration::status_id_wait_list:
2058
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
2059
+				$this->wait_list_registration($notify);
2060
+				break;
2061
+			case EEM_Registration::status_id_incomplete:
2062
+			default:
2063
+				$result['success'] = false;
2064
+				unset($this->_req_data['return']);
2065
+				$this->_reg_status_change_return('', false);
2066
+				break;
2067
+		}
2068
+	}
2069
+
2070
+
2071
+	/**
2072
+	 * Callback for bulk action routes.
2073
+	 * Note: although we could just register the singular route callbacks for each bulk action route as well, this
2074
+	 * method was chosen so there is one central place all the registration status bulk actions are going through.
2075
+	 * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
2076
+	 * when an action is happening on just a single registration).
2077
+	 *
2078
+	 * @param      $action
2079
+	 * @param bool $notify
2080
+	 */
2081
+	protected function bulk_action_on_registrations($action, $notify = false)
2082
+	{
2083
+		do_action(
2084
+			'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
2085
+			$this,
2086
+			$action,
2087
+			$notify
2088
+		);
2089
+		$method = $action . '_registration';
2090
+		if (method_exists($this, $method)) {
2091
+			$this->$method($notify);
2092
+		}
2093
+	}
2094
+
2095
+
2096
+	/**
2097
+	 * approve_registration
2098
+	 *
2099
+	 * @access protected
2100
+	 * @param bool $notify whether or not to notify the registrant about their approval.
2101
+	 * @return void
2102
+	 */
2103
+	protected function approve_registration($notify = false)
2104
+	{
2105
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
2106
+	}
2107
+
2108
+
2109
+	/**
2110
+	 *        decline_registration
2111
+	 *
2112
+	 * @access protected
2113
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2114
+	 * @return void
2115
+	 */
2116
+	protected function decline_registration($notify = false)
2117
+	{
2118
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
2119
+	}
2120
+
2121
+
2122
+	/**
2123
+	 *        cancel_registration
2124
+	 *
2125
+	 * @access protected
2126
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2127
+	 * @return void
2128
+	 */
2129
+	protected function cancel_registration($notify = false)
2130
+	{
2131
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
2132
+	}
2133
+
2134
+
2135
+	/**
2136
+	 *        not_approve_registration
2137
+	 *
2138
+	 * @access protected
2139
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2140
+	 * @return void
2141
+	 */
2142
+	protected function not_approve_registration($notify = false)
2143
+	{
2144
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
2145
+	}
2146
+
2147
+
2148
+	/**
2149
+	 *        decline_registration
2150
+	 *
2151
+	 * @access protected
2152
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2153
+	 * @return void
2154
+	 */
2155
+	protected function pending_registration($notify = false)
2156
+	{
2157
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
2158
+	}
2159
+
2160
+
2161
+	/**
2162
+	 * waitlist_registration
2163
+	 *
2164
+	 * @access protected
2165
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2166
+	 * @return void
2167
+	 */
2168
+	protected function wait_list_registration($notify = false)
2169
+	{
2170
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2171
+	}
2172
+
2173
+
2174
+	/**
2175
+	 *        generates HTML for the Registration main meta box
2176
+	 *
2177
+	 * @access public
2178
+	 * @return void
2179
+	 * @throws DomainException
2180
+	 * @throws EE_Error
2181
+	 * @throws InvalidArgumentException
2182
+	 * @throws InvalidDataTypeException
2183
+	 * @throws InvalidInterfaceException
2184
+	 * @throws ReflectionException
2185
+	 * @throws EntityNotFoundException
2186
+	 */
2187
+	public function _reg_details_meta_box()
2188
+	{
2189
+		EEH_Autoloader::register_line_item_display_autoloaders();
2190
+		EEH_Autoloader::register_line_item_filter_autoloaders();
2191
+		EE_Registry::instance()->load_helper('Line_Item');
2192
+		$transaction = $this->_registration->transaction() ? $this->_registration->transaction()
2193
+			: EE_Transaction::new_instance();
2194
+		$this->_session = $transaction->session_data();
2195
+		$filters = new EE_Line_Item_Filter_Collection();
2196
+		// $filters->add( new EE_Non_Zero_Line_Item_Filter() );
2197
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2198
+		$line_item_filter_processor = new EE_Line_Item_Filter_Processor(
2199
+			$filters,
2200
+			$transaction->total_line_item()
2201
+		);
2202
+		$filtered_line_item_tree = $line_item_filter_processor->process();
2203
+		$line_item_display = new EE_Line_Item_Display(
2204
+			'reg_admin_table',
2205
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2206
+		);
2207
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2208
+			$filtered_line_item_tree,
2209
+			array('EE_Registration' => $this->_registration)
2210
+		);
2211
+		$attendee = $this->_registration->attendee();
2212
+		if (EE_Registry::instance()->CAP->current_user_can(
2213
+			'ee_read_transaction',
2214
+			'espresso_transactions_view_transaction'
2215
+		)) {
2216
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2217
+				EE_Admin_Page::add_query_args_and_nonce(
2218
+					array(
2219
+						'action' => 'view_transaction',
2220
+						'TXN_ID' => $transaction->ID(),
2221
+					),
2222
+					TXN_ADMIN_URL
2223
+				),
2224
+				esc_html__(' View Transaction', 'event_espresso'),
2225
+				'button secondary-button right',
2226
+				'dashicons dashicons-cart'
2227
+			);
2228
+		} else {
2229
+			$this->_template_args['view_transaction_button'] = '';
2230
+		}
2231
+		if ($attendee instanceof EE_Attendee
2232
+			&& EE_Registry::instance()->CAP->current_user_can(
2233
+				'ee_send_message',
2234
+				'espresso_registrations_resend_registration'
2235
+			)
2236
+		) {
2237
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2238
+				EE_Admin_Page::add_query_args_and_nonce(
2239
+					array(
2240
+						'action'      => 'resend_registration',
2241
+						'_REG_ID'     => $this->_registration->ID(),
2242
+						'redirect_to' => 'view_registration',
2243
+					),
2244
+					REG_ADMIN_URL
2245
+				),
2246
+				esc_html__(' Resend Registration', 'event_espresso'),
2247
+				'button secondary-button right',
2248
+				'dashicons dashicons-email-alt'
2249
+			);
2250
+		} else {
2251
+			$this->_template_args['resend_registration_button'] = '';
2252
+		}
2253
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2254
+		$payment = $transaction->get_first_related('Payment');
2255
+		$payment = ! $payment instanceof EE_Payment
2256
+			? EE_Payment::new_instance()
2257
+			: $payment;
2258
+		$payment_method = $payment->get_first_related('Payment_Method');
2259
+		$payment_method = ! $payment_method instanceof EE_Payment_Method
2260
+			? EE_Payment_Method::new_instance()
2261
+			: $payment_method;
2262
+		$reg_details = array(
2263
+			'payment_method'       => $payment_method->name(),
2264
+			'response_msg'         => $payment->gateway_response(),
2265
+			'registration_id'      => $this->_registration->get('REG_code'),
2266
+			'registration_session' => $this->_registration->session_ID(),
2267
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2268
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2269
+		);
2270
+		if (isset($reg_details['registration_id'])) {
2271
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2272
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2273
+				'Registration ID',
2274
+				'event_espresso'
2275
+			);
2276
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2277
+		}
2278
+		if (isset($reg_details['payment_method'])) {
2279
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2280
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2281
+				'Most Recent Payment Method',
2282
+				'event_espresso'
2283
+			);
2284
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2285
+			$this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg'];
2286
+			$this->_template_args['reg_details']['response_msg']['label'] = esc_html__(
2287
+				'Payment method response',
2288
+				'event_espresso'
2289
+			);
2290
+			$this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2291
+		}
2292
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2293
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2294
+			'Registration Session',
2295
+			'event_espresso'
2296
+		);
2297
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2298
+		$this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address'];
2299
+		$this->_template_args['reg_details']['ip_address']['label'] = esc_html__(
2300
+			'Registration placed from IP',
2301
+			'event_espresso'
2302
+		);
2303
+		$this->_template_args['reg_details']['ip_address']['class'] = 'regular-text';
2304
+		$this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent'];
2305
+		$this->_template_args['reg_details']['user_agent']['label'] = esc_html__(
2306
+			'Registrant User Agent',
2307
+			'event_espresso'
2308
+		);
2309
+		$this->_template_args['reg_details']['user_agent']['class'] = 'large-text';
2310
+		$this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
2311
+			array(
2312
+				'action'   => 'default',
2313
+				'event_id' => $this->_registration->event_ID(),
2314
+			),
2315
+			REG_ADMIN_URL
2316
+		);
2317
+		$this->_template_args['REG_ID'] = $this->_registration->ID();
2318
+		$this->_template_args['event_id'] = $this->_registration->event_ID();
2319
+		$template_path =
2320
+			REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2321
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2322
+	}
2323
+
2324
+
2325
+	/**
2326
+	 * generates HTML for the Registration Questions meta box.
2327
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2328
+	 * otherwise uses new forms system
2329
+	 *
2330
+	 * @access public
2331
+	 * @return void
2332
+	 * @throws DomainException
2333
+	 * @throws EE_Error
2334
+	 */
2335
+	public function _reg_questions_meta_box()
2336
+	{
2337
+		// allow someone to override this method entirely
2338
+		if (apply_filters(
2339
+			'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2340
+			true,
2341
+			$this,
2342
+			$this->_registration
2343
+		)) {
2344
+			$form = $this->_get_reg_custom_questions_form(
2345
+				$this->_registration->ID()
2346
+			);
2347
+			$this->_template_args['att_questions'] = count($form->subforms()) > 0
2348
+				? $form->get_html_and_js()
2349
+				: '';
2350
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2351
+			$this->_template_args['REG_ID'] = $this->_registration->ID();
2352
+			$template_path =
2353
+				REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2354
+			echo EEH_Template::display_template($template_path, $this->_template_args, true);
2355
+		}
2356
+	}
2357
+
2358
+
2359
+	/**
2360
+	 * form_before_question_group
2361
+	 *
2362
+	 * @deprecated    as of 4.8.32.rc.000
2363
+	 * @access        public
2364
+	 * @param        string $output
2365
+	 * @return        string
2366
+	 */
2367
+	public function form_before_question_group($output)
2368
+	{
2369
+		EE_Error::doing_it_wrong(
2370
+			__CLASS__ . '::' . __FUNCTION__,
2371
+			esc_html__(
2372
+				'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.',
2373
+				'event_espresso'
2374
+			),
2375
+			'4.8.32.rc.000'
2376
+		);
2377
+		return '
2378 2378
 	<table class="form-table ee-width-100">
2379 2379
 		<tbody>
2380 2380
 			';
2381
-    }
2382
-
2383
-
2384
-    /**
2385
-     * form_after_question_group
2386
-     *
2387
-     * @deprecated    as of 4.8.32.rc.000
2388
-     * @access        public
2389
-     * @param        string $output
2390
-     * @return        string
2391
-     */
2392
-    public function form_after_question_group($output)
2393
-    {
2394
-        EE_Error::doing_it_wrong(
2395
-            __CLASS__ . '::' . __FUNCTION__,
2396
-            esc_html__(
2397
-                '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.',
2398
-                'event_espresso'
2399
-            ),
2400
-            '4.8.32.rc.000'
2401
-        );
2402
-        return '
2381
+	}
2382
+
2383
+
2384
+	/**
2385
+	 * form_after_question_group
2386
+	 *
2387
+	 * @deprecated    as of 4.8.32.rc.000
2388
+	 * @access        public
2389
+	 * @param        string $output
2390
+	 * @return        string
2391
+	 */
2392
+	public function form_after_question_group($output)
2393
+	{
2394
+		EE_Error::doing_it_wrong(
2395
+			__CLASS__ . '::' . __FUNCTION__,
2396
+			esc_html__(
2397
+				'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.',
2398
+				'event_espresso'
2399
+			),
2400
+			'4.8.32.rc.000'
2401
+		);
2402
+		return '
2403 2403
 			<tr class="hide-if-no-js">
2404 2404
 				<th> </th>
2405 2405
 				<td class="reg-admin-edit-attendee-question-td">
2406 2406
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2407
-               . esc_attr__('click to edit question', 'event_espresso')
2408
-               . '">
2407
+			   . esc_attr__('click to edit question', 'event_espresso')
2408
+			   . '">
2409 2409
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2410
-               . esc_html__('edit the above question group', 'event_espresso')
2411
-               . '</span>
2410
+			   . esc_html__('edit the above question group', 'event_espresso')
2411
+			   . '</span>
2412 2412
 						<div class="dashicons dashicons-edit"></div>
2413 2413
 					</a>
2414 2414
 				</td>
@@ -2416,608 +2416,608 @@  discard block
 block discarded – undo
2416 2416
 		</tbody>
2417 2417
 	</table>
2418 2418
 ';
2419
-    }
2420
-
2421
-
2422
-    /**
2423
-     * form_form_field_label_wrap
2424
-     *
2425
-     * @deprecated    as of 4.8.32.rc.000
2426
-     * @access        public
2427
-     * @param        string $label
2428
-     * @return        string
2429
-     */
2430
-    public function form_form_field_label_wrap($label)
2431
-    {
2432
-        EE_Error::doing_it_wrong(
2433
-            __CLASS__ . '::' . __FUNCTION__,
2434
-            esc_html__(
2435
-                '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.',
2436
-                'event_espresso'
2437
-            ),
2438
-            '4.8.32.rc.000'
2439
-        );
2440
-        return '
2419
+	}
2420
+
2421
+
2422
+	/**
2423
+	 * form_form_field_label_wrap
2424
+	 *
2425
+	 * @deprecated    as of 4.8.32.rc.000
2426
+	 * @access        public
2427
+	 * @param        string $label
2428
+	 * @return        string
2429
+	 */
2430
+	public function form_form_field_label_wrap($label)
2431
+	{
2432
+		EE_Error::doing_it_wrong(
2433
+			__CLASS__ . '::' . __FUNCTION__,
2434
+			esc_html__(
2435
+				'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.',
2436
+				'event_espresso'
2437
+			),
2438
+			'4.8.32.rc.000'
2439
+		);
2440
+		return '
2441 2441
 			<tr>
2442 2442
 				<th>
2443 2443
 					' . $label . '
2444 2444
 				</th>';
2445
-    }
2446
-
2447
-
2448
-    /**
2449
-     * form_form_field_input__wrap
2450
-     *
2451
-     * @deprecated    as of 4.8.32.rc.000
2452
-     * @access        public
2453
-     * @param        string $input
2454
-     * @return        string
2455
-     */
2456
-    public function form_form_field_input__wrap($input)
2457
-    {
2458
-        EE_Error::doing_it_wrong(
2459
-            __CLASS__ . '::' . __FUNCTION__,
2460
-            esc_html__(
2461
-                '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.',
2462
-                'event_espresso'
2463
-            ),
2464
-            '4.8.32.rc.000'
2465
-        );
2466
-        return '
2445
+	}
2446
+
2447
+
2448
+	/**
2449
+	 * form_form_field_input__wrap
2450
+	 *
2451
+	 * @deprecated    as of 4.8.32.rc.000
2452
+	 * @access        public
2453
+	 * @param        string $input
2454
+	 * @return        string
2455
+	 */
2456
+	public function form_form_field_input__wrap($input)
2457
+	{
2458
+		EE_Error::doing_it_wrong(
2459
+			__CLASS__ . '::' . __FUNCTION__,
2460
+			esc_html__(
2461
+				'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.',
2462
+				'event_espresso'
2463
+			),
2464
+			'4.8.32.rc.000'
2465
+		);
2466
+		return '
2467 2467
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2468 2468
 					' . $input . '
2469 2469
 				</td>
2470 2470
 			</tr>';
2471
-    }
2472
-
2473
-
2474
-    /**
2475
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2476
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2477
-     * to display the page
2478
-     *
2479
-     * @access protected
2480
-     * @return void
2481
-     * @throws EE_Error
2482
-     */
2483
-    protected function _update_attendee_registration_form()
2484
-    {
2485
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2486
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2487
-            $REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2488
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2489
-            if ($success) {
2490
-                $what = esc_html__('Registration Form', 'event_espresso');
2491
-                $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2492
-                    : array('action' => 'default');
2493
-                $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2494
-            }
2495
-        }
2496
-    }
2497
-
2498
-
2499
-    /**
2500
-     * Gets the form for saving registrations custom questions (if done
2501
-     * previously retrieves the cached form object, which may have validation errors in it)
2502
-     *
2503
-     * @param int $REG_ID
2504
-     * @return EE_Registration_Custom_Questions_Form
2505
-     * @throws EE_Error
2506
-     * @throws InvalidArgumentException
2507
-     * @throws InvalidDataTypeException
2508
-     * @throws InvalidInterfaceException
2509
-     */
2510
-    protected function _get_reg_custom_questions_form($REG_ID)
2511
-    {
2512
-        if (! $this->_reg_custom_questions_form) {
2513
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2514
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2515
-                EEM_Registration::instance()->get_one_by_ID($REG_ID)
2516
-            );
2517
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2518
-        }
2519
-        return $this->_reg_custom_questions_form;
2520
-    }
2521
-
2522
-
2523
-    /**
2524
-     * Saves
2525
-     *
2526
-     * @access private
2527
-     * @param bool $REG_ID
2528
-     * @return bool
2529
-     * @throws EE_Error
2530
-     * @throws InvalidArgumentException
2531
-     * @throws InvalidDataTypeException
2532
-     * @throws InvalidInterfaceException
2533
-     */
2534
-    private function _save_reg_custom_questions_form($REG_ID = false)
2535
-    {
2536
-        if (! $REG_ID) {
2537
-            EE_Error::add_error(
2538
-                esc_html__(
2539
-                    'An error occurred. No registration ID was received.',
2540
-                    'event_espresso'
2541
-                ),
2542
-                __FILE__,
2543
-                __FUNCTION__,
2544
-                __LINE__
2545
-            );
2546
-        }
2547
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2548
-        $form->receive_form_submission($this->_req_data);
2549
-        $success = false;
2550
-        if ($form->is_valid()) {
2551
-            foreach ($form->subforms() as $question_group_id => $question_group_form) {
2552
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2553
-                    $where_conditions = array(
2554
-                        'QST_ID' => $question_id,
2555
-                        'REG_ID' => $REG_ID,
2556
-                    );
2557
-                    $possibly_new_values = array(
2558
-                        'ANS_value' => $input->normalized_value(),
2559
-                    );
2560
-                    $answer = EEM_Answer::instance()->get_one(array($where_conditions));
2561
-                    if ($answer instanceof EE_Answer) {
2562
-                        $success = $answer->save($possibly_new_values);
2563
-                    } else {
2564
-                        // insert it then
2565
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2566
-                        $answer = EE_Answer::new_instance($cols_n_vals);
2567
-                        $success = $answer->save();
2568
-                    }
2569
-                }
2570
-            }
2571
-        } else {
2572
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2573
-        }
2574
-        return $success;
2575
-    }
2576
-
2577
-
2578
-    /**
2579
-     *        generates HTML for the Registration main meta box
2580
-     *
2581
-     * @access public
2582
-     * @return void
2583
-     * @throws DomainException
2584
-     * @throws EE_Error
2585
-     * @throws InvalidArgumentException
2586
-     * @throws InvalidDataTypeException
2587
-     * @throws InvalidInterfaceException
2588
-     */
2589
-    public function _reg_attendees_meta_box()
2590
-    {
2591
-        $REG = EEM_Registration::instance();
2592
-        // get all other registrations on this transaction, and cache
2593
-        // the attendees for them so we don't have to run another query using force_join
2594
-        $registrations = $REG->get_all(
2595
-            array(
2596
-                array(
2597
-                    'TXN_ID' => $this->_registration->transaction_ID(),
2598
-                    'REG_ID' => array('!=', $this->_registration->ID()),
2599
-                ),
2600
-                'force_join' => array('Attendee'),
2601
-            )
2602
-        );
2603
-        $this->_template_args['attendees'] = array();
2604
-        $this->_template_args['attendee_notice'] = '';
2605
-        if (empty($registrations)
2606
-            || (is_array($registrations)
2607
-                && ! EEH_Array::get_one_item_from_array($registrations))
2608
-        ) {
2609
-            EE_Error::add_error(
2610
-                esc_html__(
2611
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2612
-                    'event_espresso'
2613
-                ),
2614
-                __FILE__,
2615
-                __FUNCTION__,
2616
-                __LINE__
2617
-            );
2618
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2619
-        } else {
2620
-            $att_nmbr = 1;
2621
-            foreach ($registrations as $registration) {
2622
-                /* @var $registration EE_Registration */
2623
-                $attendee = $registration->attendee()
2624
-                    ? $registration->attendee()
2625
-                    : EEM_Attendee::instance()
2626
-                                  ->create_default_object();
2627
-                $this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID();
2628
-                $this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname();
2629
-                $this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname();
2630
-                $this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email();
2631
-                $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2632
-                $this->_template_args['attendees'][ $att_nmbr ]['address'] = implode(
2633
-                    ', ',
2634
-                    $attendee->full_address_as_array()
2635
-                );
2636
-                $this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce(
2637
-                    array(
2638
-                        'action' => 'edit_attendee',
2639
-                        'post'   => $attendee->ID(),
2640
-                    ),
2641
-                    REG_ADMIN_URL
2642
-                );
2643
-                $this->_template_args['attendees'][ $att_nmbr ]['event_name'] = $registration->event_obj() instanceof EE_Event
2644
-                    ? $registration->event_obj()->name()
2645
-                    : '';
2646
-                $att_nmbr++;
2647
-            }
2648
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2649
-        }
2650
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2651
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2652
-    }
2653
-
2654
-
2655
-    /**
2656
-     *        generates HTML for the Edit Registration side meta box
2657
-     *
2658
-     * @access public
2659
-     * @return void
2660
-     * @throws DomainException
2661
-     * @throws EE_Error
2662
-     * @throws InvalidArgumentException
2663
-     * @throws InvalidDataTypeException
2664
-     * @throws InvalidInterfaceException
2665
-     */
2666
-    public function _reg_registrant_side_meta_box()
2667
-    {
2668
-        /*@var $attendee EE_Attendee */
2669
-        $att_check = $this->_registration->attendee();
2670
-        $attendee = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2671
-        // now let's determine if this is not the primary registration.  If it isn't then we set the
2672
-        // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2673
-        // primary registration object (that way we know if we need to show create button or not)
2674
-        if (! $this->_registration->is_primary_registrant()) {
2675
-            $primary_registration = $this->_registration->get_primary_registration();
2676
-            $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2677
-                : null;
2678
-            if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2679
-                // in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2680
-                // custom attendee object so let's not worry about the primary reg.
2681
-                $primary_registration = null;
2682
-            }
2683
-        } else {
2684
-            $primary_registration = null;
2685
-        }
2686
-        $this->_template_args['ATT_ID'] = $attendee->ID();
2687
-        $this->_template_args['fname'] = $attendee->fname();
2688
-        $this->_template_args['lname'] = $attendee->lname();
2689
-        $this->_template_args['email'] = $attendee->email();
2690
-        $this->_template_args['phone'] = $attendee->phone();
2691
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2692
-        // edit link
2693
-        $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(
2694
-            array(
2695
-                'action' => 'edit_attendee',
2696
-                'post'   => $attendee->ID(),
2697
-            ),
2698
-            REG_ADMIN_URL
2699
-        );
2700
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2701
-        // create link
2702
-        $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2703
-            ? EE_Admin_Page::add_query_args_and_nonce(
2704
-                array(
2705
-                    'action'  => 'duplicate_attendee',
2706
-                    '_REG_ID' => $this->_registration->ID(),
2707
-                ),
2708
-                REG_ADMIN_URL
2709
-            ) : '';
2710
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2711
-        $this->_template_args['att_check'] = $att_check;
2712
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2713
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2714
-    }
2715
-
2716
-
2717
-    /**
2718
-     * trash or restore registrations
2719
-     *
2720
-     * @param  boolean $trash whether to archive or restore
2721
-     * @return void
2722
-     * @throws EE_Error
2723
-     * @throws InvalidArgumentException
2724
-     * @throws InvalidDataTypeException
2725
-     * @throws InvalidInterfaceException
2726
-     * @throws RuntimeException
2727
-     * @access protected
2728
-     */
2729
-    protected function _trash_or_restore_registrations($trash = true)
2730
-    {
2731
-        // if empty _REG_ID then get out because there's nothing to do
2732
-        if (empty($this->_req_data['_REG_ID'])) {
2733
-            EE_Error::add_error(
2734
-                sprintf(
2735
-                    esc_html__(
2736
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2737
-                        'event_espresso'
2738
-                    ),
2739
-                    $trash ? 'trash' : 'restore'
2740
-                ),
2741
-                __FILE__,
2742
-                __LINE__,
2743
-                __FUNCTION__
2744
-            );
2745
-            $this->_redirect_after_action(false, '', '', array(), true);
2746
-        }
2747
-        $success = 0;
2748
-        $overwrite_msgs = false;
2749
-        // Checkboxes
2750
-        if (! is_array($this->_req_data['_REG_ID'])) {
2751
-            $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2752
-        }
2753
-        $reg_count = count($this->_req_data['_REG_ID']);
2754
-        // cycle thru checkboxes
2755
-        foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2756
-            /** @var EE_Registration $REG */
2757
-            $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2758
-            $payments = $REG->registration_payments();
2759
-            if (! empty($payments)) {
2760
-                $name = $REG->attendee() instanceof EE_Attendee
2761
-                    ? $REG->attendee()->full_name()
2762
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2763
-                $overwrite_msgs = true;
2764
-                EE_Error::add_error(
2765
-                    sprintf(
2766
-                        esc_html__(
2767
-                            '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.',
2768
-                            'event_espresso'
2769
-                        ),
2770
-                        $name
2771
-                    ),
2772
-                    __FILE__,
2773
-                    __FUNCTION__,
2774
-                    __LINE__
2775
-                );
2776
-                // can't trash this registration because it has payments.
2777
-                continue;
2778
-            }
2779
-            $updated = $trash ? $REG->delete() : $REG->restore();
2780
-            if ($updated) {
2781
-                $success++;
2782
-            }
2783
-        }
2784
-        $this->_redirect_after_action(
2785
-            $success === $reg_count, // were ALL registrations affected?
2786
-            $success > 1
2787
-                ? esc_html__('Registrations', 'event_espresso')
2788
-                : esc_html__('Registration', 'event_espresso'),
2789
-            $trash
2790
-                ? esc_html__('moved to the trash', 'event_espresso')
2791
-                : esc_html__('restored', 'event_espresso'),
2792
-            $this->mergeExistingRequestParamsWithRedirectArgs(array('action' => 'default')),
2793
-            $overwrite_msgs
2794
-        );
2795
-    }
2796
-
2797
-
2798
-    /**
2799
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2800
-     * registration but also.
2801
-     * 1. Removing relations to EE_Attendee
2802
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2803
-     * ALSO trashed.
2804
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2805
-     * 4. Removing relationships between all tickets and the related registrations
2806
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2807
-     * 6. Deleting permanently any related Checkins.
2808
-     *
2809
-     * @return void
2810
-     * @throws EE_Error
2811
-     * @throws InvalidArgumentException
2812
-     * @throws InvalidDataTypeException
2813
-     * @throws InvalidInterfaceException
2814
-     */
2815
-    protected function _delete_registrations()
2816
-    {
2817
-        $REG_MDL = EEM_Registration::instance();
2818
-        $success = 1;
2819
-        // Checkboxes
2820
-        if (! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2821
-            // if array has more than one element than success message should be plural
2822
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2823
-            // cycle thru checkboxes
2824
-            while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2825
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2826
-                if (! $REG instanceof EE_Registration) {
2827
-                    continue;
2828
-                }
2829
-                $deleted = $this->_delete_registration($REG);
2830
-                if (! $deleted) {
2831
-                    $success = 0;
2832
-                }
2833
-            }
2834
-        } else {
2835
-            // grab single id and delete
2836
-            $REG_ID = $this->_req_data['_REG_ID'];
2837
-            $REG = $REG_MDL->get_one_by_ID($REG_ID);
2838
-            $deleted = $this->_delete_registration($REG);
2839
-            if (! $deleted) {
2840
-                $success = 0;
2841
-            }
2842
-        }
2843
-        $what = $success > 1
2844
-            ? esc_html__('Registrations', 'event_espresso')
2845
-            : esc_html__('Registration', 'event_espresso');
2846
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2847
-        $this->_redirect_after_action(
2848
-            $success,
2849
-            $what,
2850
-            $action_desc,
2851
-            $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2852
-            true
2853
-        );
2854
-    }
2855
-
2856
-
2857
-    /**
2858
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2859
-     * models get affected.
2860
-     *
2861
-     * @param  EE_Registration $REG registration to be deleted permenantly
2862
-     * @return bool true = successful deletion, false = fail.
2863
-     * @throws EE_Error
2864
-     */
2865
-    protected function _delete_registration(EE_Registration $REG)
2866
-    {
2867
-        // first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2868
-        // registrations on the transaction that are NOT trashed.
2869
-        $TXN = $REG->get_first_related('Transaction');
2870
-        $REGS = $TXN->get_many_related('Registration');
2871
-        $all_trashed = true;
2872
-        foreach ($REGS as $registration) {
2873
-            if (! $registration->get('REG_deleted')) {
2874
-                $all_trashed = false;
2875
-            }
2876
-        }
2877
-        if (! $all_trashed) {
2878
-            EE_Error::add_error(
2879
-                esc_html__(
2880
-                    '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.',
2881
-                    'event_espresso'
2882
-                ),
2883
-                __FILE__,
2884
-                __FUNCTION__,
2885
-                __LINE__
2886
-            );
2887
-            return false;
2888
-        }
2889
-        // k made it here so that means we can delete all the related transactions and their answers (but let's do them
2890
-        // separately from THIS one).
2891
-        foreach ($REGS as $registration) {
2892
-            // delete related answers
2893
-            $registration->delete_related_permanently('Answer');
2894
-            // remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2895
-            $attendee = $registration->get_first_related('Attendee');
2896
-            if ($attendee instanceof EE_Attendee) {
2897
-                $registration->_remove_relation_to($attendee, 'Attendee');
2898
-            }
2899
-            // now remove relationships to tickets on this registration.
2900
-            $registration->_remove_relations('Ticket');
2901
-            // now delete permanently the checkins related to this registration.
2902
-            $registration->delete_related_permanently('Checkin');
2903
-            if ($registration->ID() === $REG->ID()) {
2904
-                continue;
2905
-            } //we don't want to delete permanently the existing registration just yet.
2906
-            // remove relation to transaction for these registrations if NOT the existing registrations
2907
-            $registration->_remove_relations('Transaction');
2908
-            // delete permanently any related messages.
2909
-            $registration->delete_related_permanently('Message');
2910
-            // now delete this registration permanently
2911
-            $registration->delete_permanently();
2912
-        }
2913
-        // now all related registrations on the transaction are handled.  So let's just handle this registration itself
2914
-        // (the transaction and line items should be all that's left).
2915
-        // delete the line items related to the transaction for this registration.
2916
-        $TXN->delete_related_permanently('Line_Item');
2917
-        // we need to remove all the relationships on the transaction
2918
-        $TXN->delete_related_permanently('Payment');
2919
-        $TXN->delete_related_permanently('Extra_Meta');
2920
-        $TXN->delete_related_permanently('Message');
2921
-        // now we can delete this REG permanently (and the transaction of course)
2922
-        $REG->delete_related_permanently('Transaction');
2923
-        return $REG->delete_permanently();
2924
-    }
2925
-
2926
-
2927
-    /**
2928
-     *    generates HTML for the Register New Attendee Admin page
2929
-     *
2930
-     * @access private
2931
-     * @throws DomainException
2932
-     * @throws EE_Error
2933
-     */
2934
-    public function new_registration()
2935
-    {
2936
-        if (! $this->_set_reg_event()) {
2937
-            throw new EE_Error(
2938
-                esc_html__(
2939
-                    'Unable to continue with registering because there is no Event ID in the request',
2940
-                    'event_espresso'
2941
-                )
2942
-            );
2943
-        }
2944
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2945
-        // gotta start with a clean slate if we're not coming here via ajax
2946
-        if (! defined('DOING_AJAX')
2947
-            && (! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2948
-        ) {
2949
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2950
-        }
2951
-        $this->_template_args['event_name'] = '';
2952
-        // event name
2953
-        if ($this->_reg_event) {
2954
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2955
-            $edit_event_url = self::add_query_args_and_nonce(
2956
-                array(
2957
-                    'action' => 'edit',
2958
-                    'post'   => $this->_reg_event->ID(),
2959
-                ),
2960
-                EVENTS_ADMIN_URL
2961
-            );
2962
-            $edit_event_lnk = '<a href="'
2963
-                              . $edit_event_url
2964
-                              . '" title="'
2965
-                              . esc_attr__('Edit ', 'event_espresso')
2966
-                              . $this->_reg_event->name()
2967
-                              . '">'
2968
-                              . esc_html__('Edit Event', 'event_espresso')
2969
-                              . '</a>';
2970
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2971
-                                                   . $edit_event_lnk
2972
-                                                   . '</span>';
2973
-        }
2974
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2975
-        if (defined('DOING_AJAX')) {
2976
-            $this->_return_json();
2977
-        }
2978
-        // grab header
2979
-        $template_path =
2980
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2981
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2982
-            $template_path,
2983
-            $this->_template_args,
2984
-            true
2985
-        );
2986
-        // $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2987
-        // the details template wrapper
2988
-        $this->display_admin_page_with_sidebar();
2989
-    }
2990
-
2991
-
2992
-    /**
2993
-     * This returns the content for a registration step
2994
-     *
2995
-     * @access protected
2996
-     * @return string html
2997
-     * @throws DomainException
2998
-     * @throws EE_Error
2999
-     * @throws InvalidArgumentException
3000
-     * @throws InvalidDataTypeException
3001
-     * @throws InvalidInterfaceException
3002
-     */
3003
-    protected function _get_registration_step_content()
3004
-    {
3005
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
3006
-            $warning_msg = sprintf(
3007
-                esc_html__(
3008
-                    '%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',
3009
-                    'event_espresso'
3010
-                ),
3011
-                '<br />',
3012
-                '<h3 class="important-notice">',
3013
-                '</h3>',
3014
-                '<div class="float-right">',
3015
-                '<span id="redirect_timer" class="important-notice">30</span>',
3016
-                '</div>',
3017
-                '<b>',
3018
-                '</b>'
3019
-            );
3020
-            return '
2471
+	}
2472
+
2473
+
2474
+	/**
2475
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2476
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2477
+	 * to display the page
2478
+	 *
2479
+	 * @access protected
2480
+	 * @return void
2481
+	 * @throws EE_Error
2482
+	 */
2483
+	protected function _update_attendee_registration_form()
2484
+	{
2485
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2486
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2487
+			$REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2488
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2489
+			if ($success) {
2490
+				$what = esc_html__('Registration Form', 'event_espresso');
2491
+				$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2492
+					: array('action' => 'default');
2493
+				$this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2494
+			}
2495
+		}
2496
+	}
2497
+
2498
+
2499
+	/**
2500
+	 * Gets the form for saving registrations custom questions (if done
2501
+	 * previously retrieves the cached form object, which may have validation errors in it)
2502
+	 *
2503
+	 * @param int $REG_ID
2504
+	 * @return EE_Registration_Custom_Questions_Form
2505
+	 * @throws EE_Error
2506
+	 * @throws InvalidArgumentException
2507
+	 * @throws InvalidDataTypeException
2508
+	 * @throws InvalidInterfaceException
2509
+	 */
2510
+	protected function _get_reg_custom_questions_form($REG_ID)
2511
+	{
2512
+		if (! $this->_reg_custom_questions_form) {
2513
+			require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2514
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2515
+				EEM_Registration::instance()->get_one_by_ID($REG_ID)
2516
+			);
2517
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2518
+		}
2519
+		return $this->_reg_custom_questions_form;
2520
+	}
2521
+
2522
+
2523
+	/**
2524
+	 * Saves
2525
+	 *
2526
+	 * @access private
2527
+	 * @param bool $REG_ID
2528
+	 * @return bool
2529
+	 * @throws EE_Error
2530
+	 * @throws InvalidArgumentException
2531
+	 * @throws InvalidDataTypeException
2532
+	 * @throws InvalidInterfaceException
2533
+	 */
2534
+	private function _save_reg_custom_questions_form($REG_ID = false)
2535
+	{
2536
+		if (! $REG_ID) {
2537
+			EE_Error::add_error(
2538
+				esc_html__(
2539
+					'An error occurred. No registration ID was received.',
2540
+					'event_espresso'
2541
+				),
2542
+				__FILE__,
2543
+				__FUNCTION__,
2544
+				__LINE__
2545
+			);
2546
+		}
2547
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2548
+		$form->receive_form_submission($this->_req_data);
2549
+		$success = false;
2550
+		if ($form->is_valid()) {
2551
+			foreach ($form->subforms() as $question_group_id => $question_group_form) {
2552
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2553
+					$where_conditions = array(
2554
+						'QST_ID' => $question_id,
2555
+						'REG_ID' => $REG_ID,
2556
+					);
2557
+					$possibly_new_values = array(
2558
+						'ANS_value' => $input->normalized_value(),
2559
+					);
2560
+					$answer = EEM_Answer::instance()->get_one(array($where_conditions));
2561
+					if ($answer instanceof EE_Answer) {
2562
+						$success = $answer->save($possibly_new_values);
2563
+					} else {
2564
+						// insert it then
2565
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2566
+						$answer = EE_Answer::new_instance($cols_n_vals);
2567
+						$success = $answer->save();
2568
+					}
2569
+				}
2570
+			}
2571
+		} else {
2572
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2573
+		}
2574
+		return $success;
2575
+	}
2576
+
2577
+
2578
+	/**
2579
+	 *        generates HTML for the Registration main meta box
2580
+	 *
2581
+	 * @access public
2582
+	 * @return void
2583
+	 * @throws DomainException
2584
+	 * @throws EE_Error
2585
+	 * @throws InvalidArgumentException
2586
+	 * @throws InvalidDataTypeException
2587
+	 * @throws InvalidInterfaceException
2588
+	 */
2589
+	public function _reg_attendees_meta_box()
2590
+	{
2591
+		$REG = EEM_Registration::instance();
2592
+		// get all other registrations on this transaction, and cache
2593
+		// the attendees for them so we don't have to run another query using force_join
2594
+		$registrations = $REG->get_all(
2595
+			array(
2596
+				array(
2597
+					'TXN_ID' => $this->_registration->transaction_ID(),
2598
+					'REG_ID' => array('!=', $this->_registration->ID()),
2599
+				),
2600
+				'force_join' => array('Attendee'),
2601
+			)
2602
+		);
2603
+		$this->_template_args['attendees'] = array();
2604
+		$this->_template_args['attendee_notice'] = '';
2605
+		if (empty($registrations)
2606
+			|| (is_array($registrations)
2607
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2608
+		) {
2609
+			EE_Error::add_error(
2610
+				esc_html__(
2611
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2612
+					'event_espresso'
2613
+				),
2614
+				__FILE__,
2615
+				__FUNCTION__,
2616
+				__LINE__
2617
+			);
2618
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2619
+		} else {
2620
+			$att_nmbr = 1;
2621
+			foreach ($registrations as $registration) {
2622
+				/* @var $registration EE_Registration */
2623
+				$attendee = $registration->attendee()
2624
+					? $registration->attendee()
2625
+					: EEM_Attendee::instance()
2626
+								  ->create_default_object();
2627
+				$this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID();
2628
+				$this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname();
2629
+				$this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname();
2630
+				$this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email();
2631
+				$this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2632
+				$this->_template_args['attendees'][ $att_nmbr ]['address'] = implode(
2633
+					', ',
2634
+					$attendee->full_address_as_array()
2635
+				);
2636
+				$this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce(
2637
+					array(
2638
+						'action' => 'edit_attendee',
2639
+						'post'   => $attendee->ID(),
2640
+					),
2641
+					REG_ADMIN_URL
2642
+				);
2643
+				$this->_template_args['attendees'][ $att_nmbr ]['event_name'] = $registration->event_obj() instanceof EE_Event
2644
+					? $registration->event_obj()->name()
2645
+					: '';
2646
+				$att_nmbr++;
2647
+			}
2648
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2649
+		}
2650
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2651
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2652
+	}
2653
+
2654
+
2655
+	/**
2656
+	 *        generates HTML for the Edit Registration side meta box
2657
+	 *
2658
+	 * @access public
2659
+	 * @return void
2660
+	 * @throws DomainException
2661
+	 * @throws EE_Error
2662
+	 * @throws InvalidArgumentException
2663
+	 * @throws InvalidDataTypeException
2664
+	 * @throws InvalidInterfaceException
2665
+	 */
2666
+	public function _reg_registrant_side_meta_box()
2667
+	{
2668
+		/*@var $attendee EE_Attendee */
2669
+		$att_check = $this->_registration->attendee();
2670
+		$attendee = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2671
+		// now let's determine if this is not the primary registration.  If it isn't then we set the
2672
+		// primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2673
+		// primary registration object (that way we know if we need to show create button or not)
2674
+		if (! $this->_registration->is_primary_registrant()) {
2675
+			$primary_registration = $this->_registration->get_primary_registration();
2676
+			$primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2677
+				: null;
2678
+			if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2679
+				// in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2680
+				// custom attendee object so let's not worry about the primary reg.
2681
+				$primary_registration = null;
2682
+			}
2683
+		} else {
2684
+			$primary_registration = null;
2685
+		}
2686
+		$this->_template_args['ATT_ID'] = $attendee->ID();
2687
+		$this->_template_args['fname'] = $attendee->fname();
2688
+		$this->_template_args['lname'] = $attendee->lname();
2689
+		$this->_template_args['email'] = $attendee->email();
2690
+		$this->_template_args['phone'] = $attendee->phone();
2691
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2692
+		// edit link
2693
+		$this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(
2694
+			array(
2695
+				'action' => 'edit_attendee',
2696
+				'post'   => $attendee->ID(),
2697
+			),
2698
+			REG_ADMIN_URL
2699
+		);
2700
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2701
+		// create link
2702
+		$this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2703
+			? EE_Admin_Page::add_query_args_and_nonce(
2704
+				array(
2705
+					'action'  => 'duplicate_attendee',
2706
+					'_REG_ID' => $this->_registration->ID(),
2707
+				),
2708
+				REG_ADMIN_URL
2709
+			) : '';
2710
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2711
+		$this->_template_args['att_check'] = $att_check;
2712
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2713
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2714
+	}
2715
+
2716
+
2717
+	/**
2718
+	 * trash or restore registrations
2719
+	 *
2720
+	 * @param  boolean $trash whether to archive or restore
2721
+	 * @return void
2722
+	 * @throws EE_Error
2723
+	 * @throws InvalidArgumentException
2724
+	 * @throws InvalidDataTypeException
2725
+	 * @throws InvalidInterfaceException
2726
+	 * @throws RuntimeException
2727
+	 * @access protected
2728
+	 */
2729
+	protected function _trash_or_restore_registrations($trash = true)
2730
+	{
2731
+		// if empty _REG_ID then get out because there's nothing to do
2732
+		if (empty($this->_req_data['_REG_ID'])) {
2733
+			EE_Error::add_error(
2734
+				sprintf(
2735
+					esc_html__(
2736
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2737
+						'event_espresso'
2738
+					),
2739
+					$trash ? 'trash' : 'restore'
2740
+				),
2741
+				__FILE__,
2742
+				__LINE__,
2743
+				__FUNCTION__
2744
+			);
2745
+			$this->_redirect_after_action(false, '', '', array(), true);
2746
+		}
2747
+		$success = 0;
2748
+		$overwrite_msgs = false;
2749
+		// Checkboxes
2750
+		if (! is_array($this->_req_data['_REG_ID'])) {
2751
+			$this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2752
+		}
2753
+		$reg_count = count($this->_req_data['_REG_ID']);
2754
+		// cycle thru checkboxes
2755
+		foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2756
+			/** @var EE_Registration $REG */
2757
+			$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2758
+			$payments = $REG->registration_payments();
2759
+			if (! empty($payments)) {
2760
+				$name = $REG->attendee() instanceof EE_Attendee
2761
+					? $REG->attendee()->full_name()
2762
+					: esc_html__('Unknown Attendee', 'event_espresso');
2763
+				$overwrite_msgs = true;
2764
+				EE_Error::add_error(
2765
+					sprintf(
2766
+						esc_html__(
2767
+							'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.',
2768
+							'event_espresso'
2769
+						),
2770
+						$name
2771
+					),
2772
+					__FILE__,
2773
+					__FUNCTION__,
2774
+					__LINE__
2775
+				);
2776
+				// can't trash this registration because it has payments.
2777
+				continue;
2778
+			}
2779
+			$updated = $trash ? $REG->delete() : $REG->restore();
2780
+			if ($updated) {
2781
+				$success++;
2782
+			}
2783
+		}
2784
+		$this->_redirect_after_action(
2785
+			$success === $reg_count, // were ALL registrations affected?
2786
+			$success > 1
2787
+				? esc_html__('Registrations', 'event_espresso')
2788
+				: esc_html__('Registration', 'event_espresso'),
2789
+			$trash
2790
+				? esc_html__('moved to the trash', 'event_espresso')
2791
+				: esc_html__('restored', 'event_espresso'),
2792
+			$this->mergeExistingRequestParamsWithRedirectArgs(array('action' => 'default')),
2793
+			$overwrite_msgs
2794
+		);
2795
+	}
2796
+
2797
+
2798
+	/**
2799
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2800
+	 * registration but also.
2801
+	 * 1. Removing relations to EE_Attendee
2802
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2803
+	 * ALSO trashed.
2804
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2805
+	 * 4. Removing relationships between all tickets and the related registrations
2806
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2807
+	 * 6. Deleting permanently any related Checkins.
2808
+	 *
2809
+	 * @return void
2810
+	 * @throws EE_Error
2811
+	 * @throws InvalidArgumentException
2812
+	 * @throws InvalidDataTypeException
2813
+	 * @throws InvalidInterfaceException
2814
+	 */
2815
+	protected function _delete_registrations()
2816
+	{
2817
+		$REG_MDL = EEM_Registration::instance();
2818
+		$success = 1;
2819
+		// Checkboxes
2820
+		if (! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2821
+			// if array has more than one element than success message should be plural
2822
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2823
+			// cycle thru checkboxes
2824
+			while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2825
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2826
+				if (! $REG instanceof EE_Registration) {
2827
+					continue;
2828
+				}
2829
+				$deleted = $this->_delete_registration($REG);
2830
+				if (! $deleted) {
2831
+					$success = 0;
2832
+				}
2833
+			}
2834
+		} else {
2835
+			// grab single id and delete
2836
+			$REG_ID = $this->_req_data['_REG_ID'];
2837
+			$REG = $REG_MDL->get_one_by_ID($REG_ID);
2838
+			$deleted = $this->_delete_registration($REG);
2839
+			if (! $deleted) {
2840
+				$success = 0;
2841
+			}
2842
+		}
2843
+		$what = $success > 1
2844
+			? esc_html__('Registrations', 'event_espresso')
2845
+			: esc_html__('Registration', 'event_espresso');
2846
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2847
+		$this->_redirect_after_action(
2848
+			$success,
2849
+			$what,
2850
+			$action_desc,
2851
+			$this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']),
2852
+			true
2853
+		);
2854
+	}
2855
+
2856
+
2857
+	/**
2858
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2859
+	 * models get affected.
2860
+	 *
2861
+	 * @param  EE_Registration $REG registration to be deleted permenantly
2862
+	 * @return bool true = successful deletion, false = fail.
2863
+	 * @throws EE_Error
2864
+	 */
2865
+	protected function _delete_registration(EE_Registration $REG)
2866
+	{
2867
+		// first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2868
+		// registrations on the transaction that are NOT trashed.
2869
+		$TXN = $REG->get_first_related('Transaction');
2870
+		$REGS = $TXN->get_many_related('Registration');
2871
+		$all_trashed = true;
2872
+		foreach ($REGS as $registration) {
2873
+			if (! $registration->get('REG_deleted')) {
2874
+				$all_trashed = false;
2875
+			}
2876
+		}
2877
+		if (! $all_trashed) {
2878
+			EE_Error::add_error(
2879
+				esc_html__(
2880
+					'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.',
2881
+					'event_espresso'
2882
+				),
2883
+				__FILE__,
2884
+				__FUNCTION__,
2885
+				__LINE__
2886
+			);
2887
+			return false;
2888
+		}
2889
+		// k made it here so that means we can delete all the related transactions and their answers (but let's do them
2890
+		// separately from THIS one).
2891
+		foreach ($REGS as $registration) {
2892
+			// delete related answers
2893
+			$registration->delete_related_permanently('Answer');
2894
+			// remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2895
+			$attendee = $registration->get_first_related('Attendee');
2896
+			if ($attendee instanceof EE_Attendee) {
2897
+				$registration->_remove_relation_to($attendee, 'Attendee');
2898
+			}
2899
+			// now remove relationships to tickets on this registration.
2900
+			$registration->_remove_relations('Ticket');
2901
+			// now delete permanently the checkins related to this registration.
2902
+			$registration->delete_related_permanently('Checkin');
2903
+			if ($registration->ID() === $REG->ID()) {
2904
+				continue;
2905
+			} //we don't want to delete permanently the existing registration just yet.
2906
+			// remove relation to transaction for these registrations if NOT the existing registrations
2907
+			$registration->_remove_relations('Transaction');
2908
+			// delete permanently any related messages.
2909
+			$registration->delete_related_permanently('Message');
2910
+			// now delete this registration permanently
2911
+			$registration->delete_permanently();
2912
+		}
2913
+		// now all related registrations on the transaction are handled.  So let's just handle this registration itself
2914
+		// (the transaction and line items should be all that's left).
2915
+		// delete the line items related to the transaction for this registration.
2916
+		$TXN->delete_related_permanently('Line_Item');
2917
+		// we need to remove all the relationships on the transaction
2918
+		$TXN->delete_related_permanently('Payment');
2919
+		$TXN->delete_related_permanently('Extra_Meta');
2920
+		$TXN->delete_related_permanently('Message');
2921
+		// now we can delete this REG permanently (and the transaction of course)
2922
+		$REG->delete_related_permanently('Transaction');
2923
+		return $REG->delete_permanently();
2924
+	}
2925
+
2926
+
2927
+	/**
2928
+	 *    generates HTML for the Register New Attendee Admin page
2929
+	 *
2930
+	 * @access private
2931
+	 * @throws DomainException
2932
+	 * @throws EE_Error
2933
+	 */
2934
+	public function new_registration()
2935
+	{
2936
+		if (! $this->_set_reg_event()) {
2937
+			throw new EE_Error(
2938
+				esc_html__(
2939
+					'Unable to continue with registering because there is no Event ID in the request',
2940
+					'event_espresso'
2941
+				)
2942
+			);
2943
+		}
2944
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2945
+		// gotta start with a clean slate if we're not coming here via ajax
2946
+		if (! defined('DOING_AJAX')
2947
+			&& (! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2948
+		) {
2949
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2950
+		}
2951
+		$this->_template_args['event_name'] = '';
2952
+		// event name
2953
+		if ($this->_reg_event) {
2954
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2955
+			$edit_event_url = self::add_query_args_and_nonce(
2956
+				array(
2957
+					'action' => 'edit',
2958
+					'post'   => $this->_reg_event->ID(),
2959
+				),
2960
+				EVENTS_ADMIN_URL
2961
+			);
2962
+			$edit_event_lnk = '<a href="'
2963
+							  . $edit_event_url
2964
+							  . '" title="'
2965
+							  . esc_attr__('Edit ', 'event_espresso')
2966
+							  . $this->_reg_event->name()
2967
+							  . '">'
2968
+							  . esc_html__('Edit Event', 'event_espresso')
2969
+							  . '</a>';
2970
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2971
+												   . $edit_event_lnk
2972
+												   . '</span>';
2973
+		}
2974
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2975
+		if (defined('DOING_AJAX')) {
2976
+			$this->_return_json();
2977
+		}
2978
+		// grab header
2979
+		$template_path =
2980
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2981
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2982
+			$template_path,
2983
+			$this->_template_args,
2984
+			true
2985
+		);
2986
+		// $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2987
+		// the details template wrapper
2988
+		$this->display_admin_page_with_sidebar();
2989
+	}
2990
+
2991
+
2992
+	/**
2993
+	 * This returns the content for a registration step
2994
+	 *
2995
+	 * @access protected
2996
+	 * @return string html
2997
+	 * @throws DomainException
2998
+	 * @throws EE_Error
2999
+	 * @throws InvalidArgumentException
3000
+	 * @throws InvalidDataTypeException
3001
+	 * @throws InvalidInterfaceException
3002
+	 */
3003
+	protected function _get_registration_step_content()
3004
+	{
3005
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
3006
+			$warning_msg = sprintf(
3007
+				esc_html__(
3008
+					'%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',
3009
+					'event_espresso'
3010
+				),
3011
+				'<br />',
3012
+				'<h3 class="important-notice">',
3013
+				'</h3>',
3014
+				'<div class="float-right">',
3015
+				'<span id="redirect_timer" class="important-notice">30</span>',
3016
+				'</div>',
3017
+				'<b>',
3018
+				'</b>'
3019
+			);
3020
+			return '
3021 3021
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
3022 3022
 	<script >
3023 3023
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -3030,855 +3030,855 @@  discard block
 block discarded – undo
3030 3030
 	        }
3031 3031
 	    }, 800 );
3032 3032
 	</script >';
3033
-        }
3034
-        $template_args = array(
3035
-            'title'                    => '',
3036
-            'content'                  => '',
3037
-            'step_button_text'         => '',
3038
-            'show_notification_toggle' => false,
3039
-        );
3040
-        // to indicate we're processing a new registration
3041
-        $hidden_fields = array(
3042
-            'processing_registration' => array(
3043
-                'type'  => 'hidden',
3044
-                'value' => 0,
3045
-            ),
3046
-            'event_id'                => array(
3047
-                'type'  => 'hidden',
3048
-                'value' => $this->_reg_event->ID(),
3049
-            ),
3050
-        );
3051
-        // if the cart is empty then we know we're at step one so we'll display ticket selector
3052
-        $cart = EE_Registry::instance()->SSN->cart();
3053
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3054
-        switch ($step) {
3055
-            case 'ticket':
3056
-                $hidden_fields['processing_registration']['value'] = 1;
3057
-                $template_args['title'] = esc_html__(
3058
-                    'Step One: Select the Ticket for this registration',
3059
-                    'event_espresso'
3060
-                );
3061
-                $template_args['content'] =
3062
-                    EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
3063
-                $template_args['step_button_text'] = esc_html__(
3064
-                    'Add Tickets and Continue to Registrant Details',
3065
-                    'event_espresso'
3066
-                );
3067
-                $template_args['show_notification_toggle'] = false;
3068
-                break;
3069
-            case 'questions':
3070
-                $hidden_fields['processing_registration']['value'] = 2;
3071
-                $template_args['title'] = esc_html__(
3072
-                    'Step Two: Add Registrant Details for this Registration',
3073
-                    'event_espresso'
3074
-                );
3075
-                // in theory we should be able to run EED_SPCO at this point because the cart should have been setup
3076
-                // properly by the first process_reg_step run.
3077
-                $template_args['content'] =
3078
-                    EED_Single_Page_Checkout::registration_checkout_for_admin();
3079
-                $template_args['step_button_text'] = esc_html__(
3080
-                    'Save Registration and Continue to Details',
3081
-                    'event_espresso'
3082
-                );
3083
-                $template_args['show_notification_toggle'] = true;
3084
-                break;
3085
-        }
3086
-        // we come back to the process_registration_step route.
3087
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
3088
-        return EEH_Template::display_template(
3089
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
3090
-            $template_args,
3091
-            true
3092
-        );
3093
-    }
3094
-
3095
-
3096
-    /**
3097
-     *        set_reg_event
3098
-     *
3099
-     * @access private
3100
-     * @return bool
3101
-     * @throws EE_Error
3102
-     * @throws InvalidArgumentException
3103
-     * @throws InvalidDataTypeException
3104
-     * @throws InvalidInterfaceException
3105
-     */
3106
-    private function _set_reg_event()
3107
-    {
3108
-        if (is_object($this->_reg_event)) {
3109
-            return true;
3110
-        }
3111
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
3112
-        if (! $EVT_ID) {
3113
-            return false;
3114
-        }
3115
-        $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
3116
-        return true;
3117
-    }
3118
-
3119
-
3120
-    /**
3121
-     * process_reg_step
3122
-     *
3123
-     * @access        public
3124
-     * @return string
3125
-     * @throws DomainException
3126
-     * @throws EE_Error
3127
-     * @throws InvalidArgumentException
3128
-     * @throws InvalidDataTypeException
3129
-     * @throws InvalidInterfaceException
3130
-     * @throws ReflectionException
3131
-     * @throws RuntimeException
3132
-     */
3133
-    public function process_reg_step()
3134
-    {
3135
-        EE_System::do_not_cache();
3136
-        $this->_set_reg_event();
3137
-        EE_Registry::instance()->REQ->set_espresso_page(true);
3138
-        EE_Registry::instance()->REQ->set('uts', time());
3139
-        // what step are we on?
3140
-        $cart = EE_Registry::instance()->SSN->cart();
3141
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3142
-        // if doing ajax then we need to verify the nonce
3143
-        if (defined('DOING_AJAX')) {
3144
-            $nonce = isset($this->_req_data[ $this->_req_nonce ])
3145
-                ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) : '';
3146
-            $this->_verify_nonce($nonce, $this->_req_nonce);
3147
-        }
3148
-        switch ($step) {
3149
-            case 'ticket':
3150
-                // process ticket selection
3151
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
3152
-                if ($success) {
3153
-                    EE_Error::add_success(
3154
-                        esc_html__(
3155
-                            'Tickets Selected. Now complete the registration.',
3156
-                            'event_espresso'
3157
-                        )
3158
-                    );
3159
-                } else {
3160
-                    $query_args['step_error'] = $this->_req_data['step_error'] = true;
3161
-                }
3162
-                if (defined('DOING_AJAX')) {
3163
-                    $this->new_registration(); // display next step
3164
-                } else {
3165
-                    $query_args = array(
3166
-                        'action'                  => 'new_registration',
3167
-                        'processing_registration' => 1,
3168
-                        'event_id'                => $this->_reg_event->ID(),
3169
-                        'uts'                     => time(),
3170
-                    );
3171
-                    $this->_redirect_after_action(
3172
-                        false,
3173
-                        '',
3174
-                        '',
3175
-                        $query_args,
3176
-                        true
3177
-                    );
3178
-                }
3179
-                break;
3180
-            case 'questions':
3181
-                if (! isset(
3182
-                    $this->_req_data['txn_reg_status_change'],
3183
-                    $this->_req_data['txn_reg_status_change']['send_notifications']
3184
-                )
3185
-                ) {
3186
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3187
-                }
3188
-                // process registration
3189
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3190
-                if ($cart instanceof EE_Cart) {
3191
-                    $grand_total = $cart->get_cart_grand_total();
3192
-                    if ($grand_total instanceof EE_Line_Item) {
3193
-                        $grand_total->save_this_and_descendants_to_txn();
3194
-                    }
3195
-                }
3196
-                if (! $transaction instanceof EE_Transaction) {
3197
-                    $query_args = array(
3198
-                        'action'                  => 'new_registration',
3199
-                        'processing_registration' => 2,
3200
-                        'event_id'                => $this->_reg_event->ID(),
3201
-                        'uts'                     => time(),
3202
-                    );
3203
-                    if (defined('DOING_AJAX')) {
3204
-                        // display registration form again because there are errors (maybe validation?)
3205
-                        $this->new_registration();
3206
-                        return;
3207
-                    } else {
3208
-                        $this->_redirect_after_action(
3209
-                            false,
3210
-                            '',
3211
-                            '',
3212
-                            $query_args,
3213
-                            true
3214
-                        );
3215
-                        return;
3216
-                    }
3217
-                }
3218
-                // maybe update status, and make sure to save transaction if not done already
3219
-                if (! $transaction->update_status_based_on_total_paid()) {
3220
-                    $transaction->save();
3221
-                }
3222
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3223
-                $this->_req_data = array();
3224
-                $query_args = array(
3225
-                    'action'        => 'redirect_to_txn',
3226
-                    'TXN_ID'        => $transaction->ID(),
3227
-                    'EVT_ID'        => $this->_reg_event->ID(),
3228
-                    'event_name'    => urlencode($this->_reg_event->name()),
3229
-                    'redirect_from' => 'new_registration',
3230
-                );
3231
-                $this->_redirect_after_action(false, '', '', $query_args, true);
3232
-                break;
3233
-        }
3234
-        // what are you looking here for?  Should be nothing to do at this point.
3235
-    }
3236
-
3237
-
3238
-    /**
3239
-     * redirect_to_txn
3240
-     *
3241
-     * @access public
3242
-     * @return void
3243
-     * @throws EE_Error
3244
-     * @throws InvalidArgumentException
3245
-     * @throws InvalidDataTypeException
3246
-     * @throws InvalidInterfaceException
3247
-     */
3248
-    public function redirect_to_txn()
3249
-    {
3250
-        EE_System::do_not_cache();
3251
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3252
-        $query_args = array(
3253
-            'action' => 'view_transaction',
3254
-            'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3255
-            'page'   => 'espresso_transactions',
3256
-        );
3257
-        if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3258
-            $query_args['EVT_ID'] = $this->_req_data['EVT_ID'];
3259
-            $query_args['event_name'] = urlencode($this->_req_data['event_name']);
3260
-            $query_args['redirect_from'] = $this->_req_data['redirect_from'];
3261
-        }
3262
-        EE_Error::add_success(
3263
-            esc_html__(
3264
-                'Registration Created.  Please review the transaction and add any payments as necessary',
3265
-                'event_espresso'
3266
-            )
3267
-        );
3268
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3269
-    }
3270
-
3271
-
3272
-    /**
3273
-     *        generates HTML for the Attendee Contact List
3274
-     *
3275
-     * @access protected
3276
-     * @return void
3277
-     */
3278
-    protected function _attendee_contact_list_table()
3279
-    {
3280
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3281
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3282
-        $this->display_admin_list_table_page_with_no_sidebar();
3283
-    }
3284
-
3285
-
3286
-    /**
3287
-     *        get_attendees
3288
-     *
3289
-     * @param      $per_page
3290
-     * @param bool $count whether to return count or data.
3291
-     * @param bool $trash
3292
-     * @return array
3293
-     * @throws EE_Error
3294
-     * @throws InvalidArgumentException
3295
-     * @throws InvalidDataTypeException
3296
-     * @throws InvalidInterfaceException
3297
-     * @access public
3298
-     */
3299
-    public function get_attendees($per_page, $count = false, $trash = false)
3300
-    {
3301
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3302
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3303
-        $ATT_MDL = EEM_Attendee::instance();
3304
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3305
-        switch ($this->_req_data['orderby']) {
3306
-            case 'ATT_ID':
3307
-                $orderby = 'ATT_ID';
3308
-                break;
3309
-            case 'ATT_fname':
3310
-                $orderby = 'ATT_fname';
3311
-                break;
3312
-            case 'ATT_email':
3313
-                $orderby = 'ATT_email';
3314
-                break;
3315
-            case 'ATT_city':
3316
-                $orderby = 'ATT_city';
3317
-                break;
3318
-            case 'STA_ID':
3319
-                $orderby = 'STA_ID';
3320
-                break;
3321
-            case 'CNT_ID':
3322
-                $orderby = 'CNT_ID';
3323
-                break;
3324
-            case 'Registration_Count':
3325
-                $orderby = 'Registration_Count';
3326
-                break;
3327
-            default:
3328
-                $orderby = 'ATT_lname';
3329
-        }
3330
-        $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3331
-            ? $this->_req_data['order']
3332
-            : 'ASC';
3333
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3334
-            ? $this->_req_data['paged']
3335
-            : 1;
3336
-        $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3337
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3338
-            ? $this->_req_data['perpage']
3339
-            : $per_page;
3340
-        $_where = array();
3341
-        if (! empty($this->_req_data['s'])) {
3342
-            $sstr = '%' . $this->_req_data['s'] . '%';
3343
-            $_where['OR'] = array(
3344
-                'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3345
-                'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3346
-                'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3347
-                'ATT_fname'                         => array('LIKE', $sstr),
3348
-                'ATT_lname'                         => array('LIKE', $sstr),
3349
-                'ATT_short_bio'                     => array('LIKE', $sstr),
3350
-                'ATT_email'                         => array('LIKE', $sstr),
3351
-                'ATT_address'                       => array('LIKE', $sstr),
3352
-                'ATT_address2'                      => array('LIKE', $sstr),
3353
-                'ATT_city'                          => array('LIKE', $sstr),
3354
-                'Country.CNT_name'                  => array('LIKE', $sstr),
3355
-                'State.STA_name'                    => array('LIKE', $sstr),
3356
-                'ATT_phone'                         => array('LIKE', $sstr),
3357
-                'Registration.REG_final_price'      => array('LIKE', $sstr),
3358
-                'Registration.REG_code'             => array('LIKE', $sstr),
3359
-                'Registration.REG_group_size'       => array('LIKE', $sstr),
3360
-            );
3361
-        }
3362
-        $offset = ($current_page - 1) * $per_page;
3363
-        $limit = $count ? null : array($offset, $per_page);
3364
-        $query_args = array(
3365
-            $_where,
3366
-            'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')),
3367
-            'limit'         => $limit,
3368
-        );
3369
-        if (! $count) {
3370
-            $query_args['order_by'] = array($orderby => $sort);
3371
-        }
3372
-        if ($trash) {
3373
-            $query_args[0]['status'] = array('!=', 'publish');
3374
-            $all_attendees = $count
3375
-                ? $ATT_MDL->count($query_args, 'ATT_ID', true)
3376
-                : $ATT_MDL->get_all($query_args);
3377
-        } else {
3378
-            $query_args[0]['status'] = array('IN', array('publish'));
3379
-            $all_attendees = $count
3380
-                ? $ATT_MDL->count($query_args, 'ATT_ID', true)
3381
-                : $ATT_MDL->get_all($query_args);
3382
-        }
3383
-        return $all_attendees;
3384
-    }
3385
-
3386
-
3387
-    /**
3388
-     * This is just taking care of resending the registration confirmation
3389
-     *
3390
-     * @access protected
3391
-     * @return void
3392
-     */
3393
-    protected function _resend_registration()
3394
-    {
3395
-        $this->_process_resend_registration();
3396
-        $query_args = isset($this->_req_data['redirect_to'])
3397
-            ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3398
-            : array('action' => 'default');
3399
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3400
-    }
3401
-
3402
-    /**
3403
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3404
-     * to use when selecting registrations
3405
-     *
3406
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3407
-     *                                                     the query parameters from the request
3408
-     * @return void ends the request with a redirect or download
3409
-     */
3410
-    public function _registrations_report_base($method_name_for_getting_query_params)
3411
-    {
3412
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3413
-            wp_redirect(
3414
-                EE_Admin_Page::add_query_args_and_nonce(
3415
-                    array(
3416
-                        'page'        => 'espresso_batch',
3417
-                        'batch'       => 'file',
3418
-                        'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3419
-                        'filters'     => urlencode(
3420
-                            serialize(
3421
-                                call_user_func(
3422
-                                    array($this, $method_name_for_getting_query_params),
3423
-                                    EEH_Array::is_set(
3424
-                                        $this->_req_data,
3425
-                                        'filters',
3426
-                                        array()
3427
-                                    )
3428
-                                )
3429
-                            )
3430
-                        ),
3431
-                        'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3432
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3433
-                        'return_url'  => urlencode($this->_req_data['return_url']),
3434
-                    )
3435
-                )
3436
-            );
3437
-        } else {
3438
-            $new_request_args = array(
3439
-                'export' => 'report',
3440
-                'action' => 'registrations_report_for_event',
3441
-                'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3442
-            );
3443
-            $this->_req_data = array_merge($this->_req_data, $new_request_args);
3444
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3445
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3446
-                $EE_Export = EE_Export::instance($this->_req_data);
3447
-                $EE_Export->export();
3448
-            }
3449
-        }
3450
-    }
3451
-
3452
-
3453
-    /**
3454
-     * Creates a registration report using only query parameters in the request
3455
-     *
3456
-     * @return void
3457
-     */
3458
-    public function _registrations_report()
3459
-    {
3460
-        $this->_registrations_report_base('_get_registration_query_parameters');
3461
-    }
3462
-
3463
-
3464
-    public function _contact_list_export()
3465
-    {
3466
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3467
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3468
-            $EE_Export = EE_Export::instance($this->_req_data);
3469
-            $EE_Export->export_attendees();
3470
-        }
3471
-    }
3472
-
3473
-
3474
-    public function _contact_list_report()
3475
-    {
3476
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3477
-            wp_redirect(
3478
-                EE_Admin_Page::add_query_args_and_nonce(
3479
-                    array(
3480
-                        'page'        => 'espresso_batch',
3481
-                        'batch'       => 'file',
3482
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3483
-                        'return_url'  => urlencode($this->_req_data['return_url']),
3484
-                    )
3485
-                )
3486
-            );
3487
-        } else {
3488
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3489
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3490
-                $EE_Export = EE_Export::instance($this->_req_data);
3491
-                $EE_Export->report_attendees();
3492
-            }
3493
-        }
3494
-    }
3495
-
3496
-
3497
-
3498
-
3499
-
3500
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3501
-    /**
3502
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3503
-     *
3504
-     * @return void
3505
-     * @throws EE_Error
3506
-     * @throws InvalidArgumentException
3507
-     * @throws InvalidDataTypeException
3508
-     * @throws InvalidInterfaceException
3509
-     */
3510
-    protected function _duplicate_attendee()
3511
-    {
3512
-        $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3513
-        // verify we have necessary info
3514
-        if (empty($this->_req_data['_REG_ID'])) {
3515
-            EE_Error::add_error(
3516
-                esc_html__(
3517
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3518
-                    'event_espresso'
3519
-                ),
3520
-                __FILE__,
3521
-                __LINE__,
3522
-                __FUNCTION__
3523
-            );
3524
-            $query_args = array('action' => $action);
3525
-            $this->_redirect_after_action('', '', '', $query_args, true);
3526
-        }
3527
-        // okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3528
-        $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3529
-        $attendee = $registration->attendee();
3530
-        // remove relation of existing attendee on registration
3531
-        $registration->_remove_relation_to($attendee, 'Attendee');
3532
-        // new attendee
3533
-        $new_attendee = clone $attendee;
3534
-        $new_attendee->set('ATT_ID', 0);
3535
-        $new_attendee->save();
3536
-        // add new attendee to reg
3537
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3538
-        EE_Error::add_success(
3539
-            esc_html__(
3540
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3541
-                'event_espresso'
3542
-            )
3543
-        );
3544
-        // redirect to edit page for attendee
3545
-        $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3546
-        $this->_redirect_after_action('', '', '', $query_args, true);
3547
-    }
3548
-
3549
-
3550
-    /**
3551
-     * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3552
-     *
3553
-     * @param int     $post_id
3554
-     * @param WP_POST $post
3555
-     * @throws DomainException
3556
-     * @throws EE_Error
3557
-     * @throws InvalidArgumentException
3558
-     * @throws InvalidDataTypeException
3559
-     * @throws InvalidInterfaceException
3560
-     * @throws LogicException
3561
-     * @throws InvalidFormSubmissionException
3562
-     */
3563
-    protected function _insert_update_cpt_item($post_id, $post)
3564
-    {
3565
-        $success = true;
3566
-        $attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3567
-            ? EEM_Attendee::instance()->get_one_by_ID($post_id)
3568
-            : null;
3569
-        // for attendee updates
3570
-        if ($attendee instanceof EE_Attendee) {
3571
-            // note we should only be UPDATING attendees at this point.
3572
-            $updated_fields = array(
3573
-                'ATT_fname'     => $this->_req_data['ATT_fname'],
3574
-                'ATT_lname'     => $this->_req_data['ATT_lname'],
3575
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3576
-                'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3577
-                'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3578
-                'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3579
-                'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3580
-                'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3581
-                'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3582
-            );
3583
-            foreach ($updated_fields as $field => $value) {
3584
-                $attendee->set($field, $value);
3585
-            }
3586
-
3587
-            // process contact details metabox form handler (which will also save the attendee)
3588
-            $contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3589
-            $success = $contact_details_form->process($this->_req_data);
3590
-
3591
-            $attendee_update_callbacks = apply_filters(
3592
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3593
-                array()
3594
-            );
3595
-            foreach ($attendee_update_callbacks as $a_callback) {
3596
-                if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3597
-                    throw new EE_Error(
3598
-                        sprintf(
3599
-                            esc_html__(
3600
-                                '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.',
3601
-                                'event_espresso'
3602
-                            ),
3603
-                            $a_callback
3604
-                        )
3605
-                    );
3606
-                }
3607
-            }
3608
-        }
3609
-
3610
-        if ($success === false) {
3611
-            EE_Error::add_error(
3612
-                esc_html__(
3613
-                    'Something went wrong with updating the meta table data for the registration.',
3614
-                    'event_espresso'
3615
-                ),
3616
-                __FILE__,
3617
-                __FUNCTION__,
3618
-                __LINE__
3619
-            );
3620
-        }
3621
-    }
3622
-
3623
-
3624
-    public function trash_cpt_item($post_id)
3625
-    {
3626
-    }
3627
-
3628
-
3629
-    public function delete_cpt_item($post_id)
3630
-    {
3631
-    }
3632
-
3633
-
3634
-    public function restore_cpt_item($post_id)
3635
-    {
3636
-    }
3637
-
3638
-
3639
-    protected function _restore_cpt_item($post_id, $revision_id)
3640
-    {
3641
-    }
3642
-
3643
-
3644
-    public function attendee_editor_metaboxes()
3645
-    {
3646
-        $this->verify_cpt_object();
3647
-        remove_meta_box(
3648
-            'postexcerpt',
3649
-            esc_html__('Excerpt', 'event_espresso'),
3650
-            'post_excerpt_meta_box',
3651
-            $this->_cpt_routes[ $this->_req_action ],
3652
-            'normal',
3653
-            'core'
3654
-        );
3655
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal', 'core');
3656
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3657
-            add_meta_box(
3658
-                'postexcerpt',
3659
-                esc_html__('Short Biography', 'event_espresso'),
3660
-                'post_excerpt_meta_box',
3661
-                $this->_cpt_routes[ $this->_req_action ],
3662
-                'normal'
3663
-            );
3664
-        }
3665
-        if (post_type_supports('espresso_attendees', 'comments')) {
3666
-            add_meta_box(
3667
-                'commentsdiv',
3668
-                esc_html__('Notes on the Contact', 'event_espresso'),
3669
-                'post_comment_meta_box',
3670
-                $this->_cpt_routes[ $this->_req_action ],
3671
-                'normal',
3672
-                'core'
3673
-            );
3674
-        }
3675
-        add_meta_box(
3676
-            'attendee_contact_info',
3677
-            esc_html__('Contact Info', 'event_espresso'),
3678
-            array($this, 'attendee_contact_info'),
3679
-            $this->_cpt_routes[ $this->_req_action ],
3680
-            'side',
3681
-            'core'
3682
-        );
3683
-        add_meta_box(
3684
-            'attendee_details_address',
3685
-            esc_html__('Address Details', 'event_espresso'),
3686
-            array($this, 'attendee_address_details'),
3687
-            $this->_cpt_routes[ $this->_req_action ],
3688
-            'normal',
3689
-            'core'
3690
-        );
3691
-        add_meta_box(
3692
-            'attendee_registrations',
3693
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3694
-            array($this, 'attendee_registrations_meta_box'),
3695
-            $this->_cpt_routes[ $this->_req_action ],
3696
-            'normal',
3697
-            'high'
3698
-        );
3699
-    }
3700
-
3701
-
3702
-    /**
3703
-     * Metabox for attendee contact info
3704
-     *
3705
-     * @param  WP_Post $post wp post object
3706
-     * @return string attendee contact info ( and form )
3707
-     * @throws EE_Error
3708
-     * @throws InvalidArgumentException
3709
-     * @throws InvalidDataTypeException
3710
-     * @throws InvalidInterfaceException
3711
-     * @throws LogicException
3712
-     * @throws DomainException
3713
-     */
3714
-    public function attendee_contact_info($post)
3715
-    {
3716
-        // get attendee object ( should already have it )
3717
-        $form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3718
-        $form->enqueueStylesAndScripts();
3719
-        echo $form->display();
3720
-    }
3721
-
3722
-
3723
-    /**
3724
-     * Return form handler for the contact details metabox
3725
-     *
3726
-     * @param EE_Attendee $attendee
3727
-     * @return AttendeeContactDetailsMetaboxFormHandler
3728
-     * @throws DomainException
3729
-     * @throws InvalidArgumentException
3730
-     * @throws InvalidDataTypeException
3731
-     * @throws InvalidInterfaceException
3732
-     */
3733
-    protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3734
-    {
3735
-        return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3736
-    }
3737
-
3738
-
3739
-    /**
3740
-     * Metabox for attendee details
3741
-     *
3742
-     * @param  WP_Post $post wp post object
3743
-     * @throws DomainException
3744
-     */
3745
-    public function attendee_address_details($post)
3746
-    {
3747
-        // get attendee object (should already have it)
3748
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
3749
-        $this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input(
3750
-            new EE_Question_Form_Input(
3751
-                EE_Question::new_instance(
3752
-                    array(
3753
-                        'QST_ID'           => 0,
3754
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3755
-                        'QST_system'       => 'admin-state',
3756
-                    )
3757
-                ),
3758
-                EE_Answer::new_instance(
3759
-                    array(
3760
-                        'ANS_ID'    => 0,
3761
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3762
-                    )
3763
-                ),
3764
-                array(
3765
-                    'input_id'       => 'STA_ID',
3766
-                    'input_name'     => 'STA_ID',
3767
-                    'input_prefix'   => '',
3768
-                    'append_qstn_id' => false,
3769
-                )
3770
-            )
3771
-        );
3772
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3773
-            new EE_Question_Form_Input(
3774
-                EE_Question::new_instance(
3775
-                    array(
3776
-                        'QST_ID'           => 0,
3777
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3778
-                        'QST_system'       => 'admin-country',
3779
-                    )
3780
-                ),
3781
-                EE_Answer::new_instance(
3782
-                    array(
3783
-                        'ANS_ID'    => 0,
3784
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3785
-                    )
3786
-                ),
3787
-                array(
3788
-                    'input_id'       => 'CNT_ISO',
3789
-                    'input_name'     => 'CNT_ISO',
3790
-                    'input_prefix'   => '',
3791
-                    'append_qstn_id' => false,
3792
-                )
3793
-            )
3794
-        );
3795
-        $template =
3796
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3797
-        EEH_Template::display_template($template, $this->_template_args);
3798
-    }
3799
-
3800
-
3801
-    /**
3802
-     *        _attendee_details
3803
-     *
3804
-     * @access protected
3805
-     * @param $post
3806
-     * @return void
3807
-     * @throws DomainException
3808
-     * @throws EE_Error
3809
-     */
3810
-    public function attendee_registrations_meta_box($post)
3811
-    {
3812
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
3813
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3814
-        $template =
3815
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3816
-        EEH_Template::display_template($template, $this->_template_args);
3817
-    }
3818
-
3819
-
3820
-    /**
3821
-     * add in the form fields for the attendee edit
3822
-     *
3823
-     * @param  WP_Post $post wp post object
3824
-     * @return string html for new form.
3825
-     * @throws DomainException
3826
-     */
3827
-    public function after_title_form_fields($post)
3828
-    {
3829
-        if ($post->post_type == 'espresso_attendees') {
3830
-            $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3831
-            $template_args['attendee'] = $this->_cpt_model_obj;
3832
-            EEH_Template::display_template($template, $template_args);
3833
-        }
3834
-    }
3835
-
3836
-
3837
-    /**
3838
-     *        _trash_or_restore_attendee
3839
-     *
3840
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3841
-     * @return void
3842
-     * @throws EE_Error
3843
-     * @throws InvalidArgumentException
3844
-     * @throws InvalidDataTypeException
3845
-     * @throws InvalidInterfaceException
3846
-     * @access protected
3847
-     */
3848
-    protected function _trash_or_restore_attendees($trash = true)
3849
-    {
3850
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3851
-        $ATT_MDL = EEM_Attendee::instance();
3852
-        $success = 1;
3853
-        // Checkboxes
3854
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3855
-            // if array has more than one element than success message should be plural
3856
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3857
-            // cycle thru checkboxes
3858
-            while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3859
-                $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3860
-                    : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3861
-                if (! $updated) {
3862
-                    $success = 0;
3863
-                }
3864
-            }
3865
-        } else {
3866
-            // grab single id and delete
3867
-            $ATT_ID = absint($this->_req_data['ATT_ID']);
3868
-            // get attendee
3869
-            $att = $ATT_MDL->get_one_by_ID($ATT_ID);
3870
-            $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3871
-            $updated = $att->save();
3872
-            if (! $updated) {
3873
-                $success = 0;
3874
-            }
3875
-        }
3876
-        $what = $success > 1
3877
-            ? esc_html__('Contacts', 'event_espresso')
3878
-            : esc_html__('Contact', 'event_espresso');
3879
-        $action_desc = $trash
3880
-            ? esc_html__('moved to the trash', 'event_espresso')
3881
-            : esc_html__('restored', 'event_espresso');
3882
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3883
-    }
3033
+		}
3034
+		$template_args = array(
3035
+			'title'                    => '',
3036
+			'content'                  => '',
3037
+			'step_button_text'         => '',
3038
+			'show_notification_toggle' => false,
3039
+		);
3040
+		// to indicate we're processing a new registration
3041
+		$hidden_fields = array(
3042
+			'processing_registration' => array(
3043
+				'type'  => 'hidden',
3044
+				'value' => 0,
3045
+			),
3046
+			'event_id'                => array(
3047
+				'type'  => 'hidden',
3048
+				'value' => $this->_reg_event->ID(),
3049
+			),
3050
+		);
3051
+		// if the cart is empty then we know we're at step one so we'll display ticket selector
3052
+		$cart = EE_Registry::instance()->SSN->cart();
3053
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3054
+		switch ($step) {
3055
+			case 'ticket':
3056
+				$hidden_fields['processing_registration']['value'] = 1;
3057
+				$template_args['title'] = esc_html__(
3058
+					'Step One: Select the Ticket for this registration',
3059
+					'event_espresso'
3060
+				);
3061
+				$template_args['content'] =
3062
+					EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
3063
+				$template_args['step_button_text'] = esc_html__(
3064
+					'Add Tickets and Continue to Registrant Details',
3065
+					'event_espresso'
3066
+				);
3067
+				$template_args['show_notification_toggle'] = false;
3068
+				break;
3069
+			case 'questions':
3070
+				$hidden_fields['processing_registration']['value'] = 2;
3071
+				$template_args['title'] = esc_html__(
3072
+					'Step Two: Add Registrant Details for this Registration',
3073
+					'event_espresso'
3074
+				);
3075
+				// in theory we should be able to run EED_SPCO at this point because the cart should have been setup
3076
+				// properly by the first process_reg_step run.
3077
+				$template_args['content'] =
3078
+					EED_Single_Page_Checkout::registration_checkout_for_admin();
3079
+				$template_args['step_button_text'] = esc_html__(
3080
+					'Save Registration and Continue to Details',
3081
+					'event_espresso'
3082
+				);
3083
+				$template_args['show_notification_toggle'] = true;
3084
+				break;
3085
+		}
3086
+		// we come back to the process_registration_step route.
3087
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
3088
+		return EEH_Template::display_template(
3089
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
3090
+			$template_args,
3091
+			true
3092
+		);
3093
+	}
3094
+
3095
+
3096
+	/**
3097
+	 *        set_reg_event
3098
+	 *
3099
+	 * @access private
3100
+	 * @return bool
3101
+	 * @throws EE_Error
3102
+	 * @throws InvalidArgumentException
3103
+	 * @throws InvalidDataTypeException
3104
+	 * @throws InvalidInterfaceException
3105
+	 */
3106
+	private function _set_reg_event()
3107
+	{
3108
+		if (is_object($this->_reg_event)) {
3109
+			return true;
3110
+		}
3111
+		$EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
3112
+		if (! $EVT_ID) {
3113
+			return false;
3114
+		}
3115
+		$this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
3116
+		return true;
3117
+	}
3118
+
3119
+
3120
+	/**
3121
+	 * process_reg_step
3122
+	 *
3123
+	 * @access        public
3124
+	 * @return string
3125
+	 * @throws DomainException
3126
+	 * @throws EE_Error
3127
+	 * @throws InvalidArgumentException
3128
+	 * @throws InvalidDataTypeException
3129
+	 * @throws InvalidInterfaceException
3130
+	 * @throws ReflectionException
3131
+	 * @throws RuntimeException
3132
+	 */
3133
+	public function process_reg_step()
3134
+	{
3135
+		EE_System::do_not_cache();
3136
+		$this->_set_reg_event();
3137
+		EE_Registry::instance()->REQ->set_espresso_page(true);
3138
+		EE_Registry::instance()->REQ->set('uts', time());
3139
+		// what step are we on?
3140
+		$cart = EE_Registry::instance()->SSN->cart();
3141
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3142
+		// if doing ajax then we need to verify the nonce
3143
+		if (defined('DOING_AJAX')) {
3144
+			$nonce = isset($this->_req_data[ $this->_req_nonce ])
3145
+				? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) : '';
3146
+			$this->_verify_nonce($nonce, $this->_req_nonce);
3147
+		}
3148
+		switch ($step) {
3149
+			case 'ticket':
3150
+				// process ticket selection
3151
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
3152
+				if ($success) {
3153
+					EE_Error::add_success(
3154
+						esc_html__(
3155
+							'Tickets Selected. Now complete the registration.',
3156
+							'event_espresso'
3157
+						)
3158
+					);
3159
+				} else {
3160
+					$query_args['step_error'] = $this->_req_data['step_error'] = true;
3161
+				}
3162
+				if (defined('DOING_AJAX')) {
3163
+					$this->new_registration(); // display next step
3164
+				} else {
3165
+					$query_args = array(
3166
+						'action'                  => 'new_registration',
3167
+						'processing_registration' => 1,
3168
+						'event_id'                => $this->_reg_event->ID(),
3169
+						'uts'                     => time(),
3170
+					);
3171
+					$this->_redirect_after_action(
3172
+						false,
3173
+						'',
3174
+						'',
3175
+						$query_args,
3176
+						true
3177
+					);
3178
+				}
3179
+				break;
3180
+			case 'questions':
3181
+				if (! isset(
3182
+					$this->_req_data['txn_reg_status_change'],
3183
+					$this->_req_data['txn_reg_status_change']['send_notifications']
3184
+				)
3185
+				) {
3186
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3187
+				}
3188
+				// process registration
3189
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3190
+				if ($cart instanceof EE_Cart) {
3191
+					$grand_total = $cart->get_cart_grand_total();
3192
+					if ($grand_total instanceof EE_Line_Item) {
3193
+						$grand_total->save_this_and_descendants_to_txn();
3194
+					}
3195
+				}
3196
+				if (! $transaction instanceof EE_Transaction) {
3197
+					$query_args = array(
3198
+						'action'                  => 'new_registration',
3199
+						'processing_registration' => 2,
3200
+						'event_id'                => $this->_reg_event->ID(),
3201
+						'uts'                     => time(),
3202
+					);
3203
+					if (defined('DOING_AJAX')) {
3204
+						// display registration form again because there are errors (maybe validation?)
3205
+						$this->new_registration();
3206
+						return;
3207
+					} else {
3208
+						$this->_redirect_after_action(
3209
+							false,
3210
+							'',
3211
+							'',
3212
+							$query_args,
3213
+							true
3214
+						);
3215
+						return;
3216
+					}
3217
+				}
3218
+				// maybe update status, and make sure to save transaction if not done already
3219
+				if (! $transaction->update_status_based_on_total_paid()) {
3220
+					$transaction->save();
3221
+				}
3222
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3223
+				$this->_req_data = array();
3224
+				$query_args = array(
3225
+					'action'        => 'redirect_to_txn',
3226
+					'TXN_ID'        => $transaction->ID(),
3227
+					'EVT_ID'        => $this->_reg_event->ID(),
3228
+					'event_name'    => urlencode($this->_reg_event->name()),
3229
+					'redirect_from' => 'new_registration',
3230
+				);
3231
+				$this->_redirect_after_action(false, '', '', $query_args, true);
3232
+				break;
3233
+		}
3234
+		// what are you looking here for?  Should be nothing to do at this point.
3235
+	}
3236
+
3237
+
3238
+	/**
3239
+	 * redirect_to_txn
3240
+	 *
3241
+	 * @access public
3242
+	 * @return void
3243
+	 * @throws EE_Error
3244
+	 * @throws InvalidArgumentException
3245
+	 * @throws InvalidDataTypeException
3246
+	 * @throws InvalidInterfaceException
3247
+	 */
3248
+	public function redirect_to_txn()
3249
+	{
3250
+		EE_System::do_not_cache();
3251
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3252
+		$query_args = array(
3253
+			'action' => 'view_transaction',
3254
+			'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3255
+			'page'   => 'espresso_transactions',
3256
+		);
3257
+		if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3258
+			$query_args['EVT_ID'] = $this->_req_data['EVT_ID'];
3259
+			$query_args['event_name'] = urlencode($this->_req_data['event_name']);
3260
+			$query_args['redirect_from'] = $this->_req_data['redirect_from'];
3261
+		}
3262
+		EE_Error::add_success(
3263
+			esc_html__(
3264
+				'Registration Created.  Please review the transaction and add any payments as necessary',
3265
+				'event_espresso'
3266
+			)
3267
+		);
3268
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3269
+	}
3270
+
3271
+
3272
+	/**
3273
+	 *        generates HTML for the Attendee Contact List
3274
+	 *
3275
+	 * @access protected
3276
+	 * @return void
3277
+	 */
3278
+	protected function _attendee_contact_list_table()
3279
+	{
3280
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3281
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3282
+		$this->display_admin_list_table_page_with_no_sidebar();
3283
+	}
3284
+
3285
+
3286
+	/**
3287
+	 *        get_attendees
3288
+	 *
3289
+	 * @param      $per_page
3290
+	 * @param bool $count whether to return count or data.
3291
+	 * @param bool $trash
3292
+	 * @return array
3293
+	 * @throws EE_Error
3294
+	 * @throws InvalidArgumentException
3295
+	 * @throws InvalidDataTypeException
3296
+	 * @throws InvalidInterfaceException
3297
+	 * @access public
3298
+	 */
3299
+	public function get_attendees($per_page, $count = false, $trash = false)
3300
+	{
3301
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3302
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3303
+		$ATT_MDL = EEM_Attendee::instance();
3304
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3305
+		switch ($this->_req_data['orderby']) {
3306
+			case 'ATT_ID':
3307
+				$orderby = 'ATT_ID';
3308
+				break;
3309
+			case 'ATT_fname':
3310
+				$orderby = 'ATT_fname';
3311
+				break;
3312
+			case 'ATT_email':
3313
+				$orderby = 'ATT_email';
3314
+				break;
3315
+			case 'ATT_city':
3316
+				$orderby = 'ATT_city';
3317
+				break;
3318
+			case 'STA_ID':
3319
+				$orderby = 'STA_ID';
3320
+				break;
3321
+			case 'CNT_ID':
3322
+				$orderby = 'CNT_ID';
3323
+				break;
3324
+			case 'Registration_Count':
3325
+				$orderby = 'Registration_Count';
3326
+				break;
3327
+			default:
3328
+				$orderby = 'ATT_lname';
3329
+		}
3330
+		$sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3331
+			? $this->_req_data['order']
3332
+			: 'ASC';
3333
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3334
+			? $this->_req_data['paged']
3335
+			: 1;
3336
+		$per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3337
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3338
+			? $this->_req_data['perpage']
3339
+			: $per_page;
3340
+		$_where = array();
3341
+		if (! empty($this->_req_data['s'])) {
3342
+			$sstr = '%' . $this->_req_data['s'] . '%';
3343
+			$_where['OR'] = array(
3344
+				'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3345
+				'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3346
+				'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3347
+				'ATT_fname'                         => array('LIKE', $sstr),
3348
+				'ATT_lname'                         => array('LIKE', $sstr),
3349
+				'ATT_short_bio'                     => array('LIKE', $sstr),
3350
+				'ATT_email'                         => array('LIKE', $sstr),
3351
+				'ATT_address'                       => array('LIKE', $sstr),
3352
+				'ATT_address2'                      => array('LIKE', $sstr),
3353
+				'ATT_city'                          => array('LIKE', $sstr),
3354
+				'Country.CNT_name'                  => array('LIKE', $sstr),
3355
+				'State.STA_name'                    => array('LIKE', $sstr),
3356
+				'ATT_phone'                         => array('LIKE', $sstr),
3357
+				'Registration.REG_final_price'      => array('LIKE', $sstr),
3358
+				'Registration.REG_code'             => array('LIKE', $sstr),
3359
+				'Registration.REG_group_size'       => array('LIKE', $sstr),
3360
+			);
3361
+		}
3362
+		$offset = ($current_page - 1) * $per_page;
3363
+		$limit = $count ? null : array($offset, $per_page);
3364
+		$query_args = array(
3365
+			$_where,
3366
+			'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')),
3367
+			'limit'         => $limit,
3368
+		);
3369
+		if (! $count) {
3370
+			$query_args['order_by'] = array($orderby => $sort);
3371
+		}
3372
+		if ($trash) {
3373
+			$query_args[0]['status'] = array('!=', 'publish');
3374
+			$all_attendees = $count
3375
+				? $ATT_MDL->count($query_args, 'ATT_ID', true)
3376
+				: $ATT_MDL->get_all($query_args);
3377
+		} else {
3378
+			$query_args[0]['status'] = array('IN', array('publish'));
3379
+			$all_attendees = $count
3380
+				? $ATT_MDL->count($query_args, 'ATT_ID', true)
3381
+				: $ATT_MDL->get_all($query_args);
3382
+		}
3383
+		return $all_attendees;
3384
+	}
3385
+
3386
+
3387
+	/**
3388
+	 * This is just taking care of resending the registration confirmation
3389
+	 *
3390
+	 * @access protected
3391
+	 * @return void
3392
+	 */
3393
+	protected function _resend_registration()
3394
+	{
3395
+		$this->_process_resend_registration();
3396
+		$query_args = isset($this->_req_data['redirect_to'])
3397
+			? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3398
+			: array('action' => 'default');
3399
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3400
+	}
3401
+
3402
+	/**
3403
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3404
+	 * to use when selecting registrations
3405
+	 *
3406
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3407
+	 *                                                     the query parameters from the request
3408
+	 * @return void ends the request with a redirect or download
3409
+	 */
3410
+	public function _registrations_report_base($method_name_for_getting_query_params)
3411
+	{
3412
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3413
+			wp_redirect(
3414
+				EE_Admin_Page::add_query_args_and_nonce(
3415
+					array(
3416
+						'page'        => 'espresso_batch',
3417
+						'batch'       => 'file',
3418
+						'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3419
+						'filters'     => urlencode(
3420
+							serialize(
3421
+								call_user_func(
3422
+									array($this, $method_name_for_getting_query_params),
3423
+									EEH_Array::is_set(
3424
+										$this->_req_data,
3425
+										'filters',
3426
+										array()
3427
+									)
3428
+								)
3429
+							)
3430
+						),
3431
+						'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3432
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3433
+						'return_url'  => urlencode($this->_req_data['return_url']),
3434
+					)
3435
+				)
3436
+			);
3437
+		} else {
3438
+			$new_request_args = array(
3439
+				'export' => 'report',
3440
+				'action' => 'registrations_report_for_event',
3441
+				'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3442
+			);
3443
+			$this->_req_data = array_merge($this->_req_data, $new_request_args);
3444
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3445
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3446
+				$EE_Export = EE_Export::instance($this->_req_data);
3447
+				$EE_Export->export();
3448
+			}
3449
+		}
3450
+	}
3451
+
3452
+
3453
+	/**
3454
+	 * Creates a registration report using only query parameters in the request
3455
+	 *
3456
+	 * @return void
3457
+	 */
3458
+	public function _registrations_report()
3459
+	{
3460
+		$this->_registrations_report_base('_get_registration_query_parameters');
3461
+	}
3462
+
3463
+
3464
+	public function _contact_list_export()
3465
+	{
3466
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3467
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3468
+			$EE_Export = EE_Export::instance($this->_req_data);
3469
+			$EE_Export->export_attendees();
3470
+		}
3471
+	}
3472
+
3473
+
3474
+	public function _contact_list_report()
3475
+	{
3476
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3477
+			wp_redirect(
3478
+				EE_Admin_Page::add_query_args_and_nonce(
3479
+					array(
3480
+						'page'        => 'espresso_batch',
3481
+						'batch'       => 'file',
3482
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3483
+						'return_url'  => urlencode($this->_req_data['return_url']),
3484
+					)
3485
+				)
3486
+			);
3487
+		} else {
3488
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3489
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3490
+				$EE_Export = EE_Export::instance($this->_req_data);
3491
+				$EE_Export->report_attendees();
3492
+			}
3493
+		}
3494
+	}
3495
+
3496
+
3497
+
3498
+
3499
+
3500
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3501
+	/**
3502
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3503
+	 *
3504
+	 * @return void
3505
+	 * @throws EE_Error
3506
+	 * @throws InvalidArgumentException
3507
+	 * @throws InvalidDataTypeException
3508
+	 * @throws InvalidInterfaceException
3509
+	 */
3510
+	protected function _duplicate_attendee()
3511
+	{
3512
+		$action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3513
+		// verify we have necessary info
3514
+		if (empty($this->_req_data['_REG_ID'])) {
3515
+			EE_Error::add_error(
3516
+				esc_html__(
3517
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3518
+					'event_espresso'
3519
+				),
3520
+				__FILE__,
3521
+				__LINE__,
3522
+				__FUNCTION__
3523
+			);
3524
+			$query_args = array('action' => $action);
3525
+			$this->_redirect_after_action('', '', '', $query_args, true);
3526
+		}
3527
+		// okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3528
+		$registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3529
+		$attendee = $registration->attendee();
3530
+		// remove relation of existing attendee on registration
3531
+		$registration->_remove_relation_to($attendee, 'Attendee');
3532
+		// new attendee
3533
+		$new_attendee = clone $attendee;
3534
+		$new_attendee->set('ATT_ID', 0);
3535
+		$new_attendee->save();
3536
+		// add new attendee to reg
3537
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3538
+		EE_Error::add_success(
3539
+			esc_html__(
3540
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3541
+				'event_espresso'
3542
+			)
3543
+		);
3544
+		// redirect to edit page for attendee
3545
+		$query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3546
+		$this->_redirect_after_action('', '', '', $query_args, true);
3547
+	}
3548
+
3549
+
3550
+	/**
3551
+	 * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3552
+	 *
3553
+	 * @param int     $post_id
3554
+	 * @param WP_POST $post
3555
+	 * @throws DomainException
3556
+	 * @throws EE_Error
3557
+	 * @throws InvalidArgumentException
3558
+	 * @throws InvalidDataTypeException
3559
+	 * @throws InvalidInterfaceException
3560
+	 * @throws LogicException
3561
+	 * @throws InvalidFormSubmissionException
3562
+	 */
3563
+	protected function _insert_update_cpt_item($post_id, $post)
3564
+	{
3565
+		$success = true;
3566
+		$attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3567
+			? EEM_Attendee::instance()->get_one_by_ID($post_id)
3568
+			: null;
3569
+		// for attendee updates
3570
+		if ($attendee instanceof EE_Attendee) {
3571
+			// note we should only be UPDATING attendees at this point.
3572
+			$updated_fields = array(
3573
+				'ATT_fname'     => $this->_req_data['ATT_fname'],
3574
+				'ATT_lname'     => $this->_req_data['ATT_lname'],
3575
+				'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3576
+				'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3577
+				'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3578
+				'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3579
+				'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3580
+				'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3581
+				'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3582
+			);
3583
+			foreach ($updated_fields as $field => $value) {
3584
+				$attendee->set($field, $value);
3585
+			}
3586
+
3587
+			// process contact details metabox form handler (which will also save the attendee)
3588
+			$contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3589
+			$success = $contact_details_form->process($this->_req_data);
3590
+
3591
+			$attendee_update_callbacks = apply_filters(
3592
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3593
+				array()
3594
+			);
3595
+			foreach ($attendee_update_callbacks as $a_callback) {
3596
+				if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3597
+					throw new EE_Error(
3598
+						sprintf(
3599
+							esc_html__(
3600
+								'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.',
3601
+								'event_espresso'
3602
+							),
3603
+							$a_callback
3604
+						)
3605
+					);
3606
+				}
3607
+			}
3608
+		}
3609
+
3610
+		if ($success === false) {
3611
+			EE_Error::add_error(
3612
+				esc_html__(
3613
+					'Something went wrong with updating the meta table data for the registration.',
3614
+					'event_espresso'
3615
+				),
3616
+				__FILE__,
3617
+				__FUNCTION__,
3618
+				__LINE__
3619
+			);
3620
+		}
3621
+	}
3622
+
3623
+
3624
+	public function trash_cpt_item($post_id)
3625
+	{
3626
+	}
3627
+
3628
+
3629
+	public function delete_cpt_item($post_id)
3630
+	{
3631
+	}
3632
+
3633
+
3634
+	public function restore_cpt_item($post_id)
3635
+	{
3636
+	}
3637
+
3638
+
3639
+	protected function _restore_cpt_item($post_id, $revision_id)
3640
+	{
3641
+	}
3642
+
3643
+
3644
+	public function attendee_editor_metaboxes()
3645
+	{
3646
+		$this->verify_cpt_object();
3647
+		remove_meta_box(
3648
+			'postexcerpt',
3649
+			esc_html__('Excerpt', 'event_espresso'),
3650
+			'post_excerpt_meta_box',
3651
+			$this->_cpt_routes[ $this->_req_action ],
3652
+			'normal',
3653
+			'core'
3654
+		);
3655
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal', 'core');
3656
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3657
+			add_meta_box(
3658
+				'postexcerpt',
3659
+				esc_html__('Short Biography', 'event_espresso'),
3660
+				'post_excerpt_meta_box',
3661
+				$this->_cpt_routes[ $this->_req_action ],
3662
+				'normal'
3663
+			);
3664
+		}
3665
+		if (post_type_supports('espresso_attendees', 'comments')) {
3666
+			add_meta_box(
3667
+				'commentsdiv',
3668
+				esc_html__('Notes on the Contact', 'event_espresso'),
3669
+				'post_comment_meta_box',
3670
+				$this->_cpt_routes[ $this->_req_action ],
3671
+				'normal',
3672
+				'core'
3673
+			);
3674
+		}
3675
+		add_meta_box(
3676
+			'attendee_contact_info',
3677
+			esc_html__('Contact Info', 'event_espresso'),
3678
+			array($this, 'attendee_contact_info'),
3679
+			$this->_cpt_routes[ $this->_req_action ],
3680
+			'side',
3681
+			'core'
3682
+		);
3683
+		add_meta_box(
3684
+			'attendee_details_address',
3685
+			esc_html__('Address Details', 'event_espresso'),
3686
+			array($this, 'attendee_address_details'),
3687
+			$this->_cpt_routes[ $this->_req_action ],
3688
+			'normal',
3689
+			'core'
3690
+		);
3691
+		add_meta_box(
3692
+			'attendee_registrations',
3693
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3694
+			array($this, 'attendee_registrations_meta_box'),
3695
+			$this->_cpt_routes[ $this->_req_action ],
3696
+			'normal',
3697
+			'high'
3698
+		);
3699
+	}
3700
+
3701
+
3702
+	/**
3703
+	 * Metabox for attendee contact info
3704
+	 *
3705
+	 * @param  WP_Post $post wp post object
3706
+	 * @return string attendee contact info ( and form )
3707
+	 * @throws EE_Error
3708
+	 * @throws InvalidArgumentException
3709
+	 * @throws InvalidDataTypeException
3710
+	 * @throws InvalidInterfaceException
3711
+	 * @throws LogicException
3712
+	 * @throws DomainException
3713
+	 */
3714
+	public function attendee_contact_info($post)
3715
+	{
3716
+		// get attendee object ( should already have it )
3717
+		$form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3718
+		$form->enqueueStylesAndScripts();
3719
+		echo $form->display();
3720
+	}
3721
+
3722
+
3723
+	/**
3724
+	 * Return form handler for the contact details metabox
3725
+	 *
3726
+	 * @param EE_Attendee $attendee
3727
+	 * @return AttendeeContactDetailsMetaboxFormHandler
3728
+	 * @throws DomainException
3729
+	 * @throws InvalidArgumentException
3730
+	 * @throws InvalidDataTypeException
3731
+	 * @throws InvalidInterfaceException
3732
+	 */
3733
+	protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3734
+	{
3735
+		return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3736
+	}
3737
+
3738
+
3739
+	/**
3740
+	 * Metabox for attendee details
3741
+	 *
3742
+	 * @param  WP_Post $post wp post object
3743
+	 * @throws DomainException
3744
+	 */
3745
+	public function attendee_address_details($post)
3746
+	{
3747
+		// get attendee object (should already have it)
3748
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
3749
+		$this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input(
3750
+			new EE_Question_Form_Input(
3751
+				EE_Question::new_instance(
3752
+					array(
3753
+						'QST_ID'           => 0,
3754
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3755
+						'QST_system'       => 'admin-state',
3756
+					)
3757
+				),
3758
+				EE_Answer::new_instance(
3759
+					array(
3760
+						'ANS_ID'    => 0,
3761
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3762
+					)
3763
+				),
3764
+				array(
3765
+					'input_id'       => 'STA_ID',
3766
+					'input_name'     => 'STA_ID',
3767
+					'input_prefix'   => '',
3768
+					'append_qstn_id' => false,
3769
+				)
3770
+			)
3771
+		);
3772
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3773
+			new EE_Question_Form_Input(
3774
+				EE_Question::new_instance(
3775
+					array(
3776
+						'QST_ID'           => 0,
3777
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3778
+						'QST_system'       => 'admin-country',
3779
+					)
3780
+				),
3781
+				EE_Answer::new_instance(
3782
+					array(
3783
+						'ANS_ID'    => 0,
3784
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3785
+					)
3786
+				),
3787
+				array(
3788
+					'input_id'       => 'CNT_ISO',
3789
+					'input_name'     => 'CNT_ISO',
3790
+					'input_prefix'   => '',
3791
+					'append_qstn_id' => false,
3792
+				)
3793
+			)
3794
+		);
3795
+		$template =
3796
+			REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3797
+		EEH_Template::display_template($template, $this->_template_args);
3798
+	}
3799
+
3800
+
3801
+	/**
3802
+	 *        _attendee_details
3803
+	 *
3804
+	 * @access protected
3805
+	 * @param $post
3806
+	 * @return void
3807
+	 * @throws DomainException
3808
+	 * @throws EE_Error
3809
+	 */
3810
+	public function attendee_registrations_meta_box($post)
3811
+	{
3812
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
3813
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3814
+		$template =
3815
+			REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3816
+		EEH_Template::display_template($template, $this->_template_args);
3817
+	}
3818
+
3819
+
3820
+	/**
3821
+	 * add in the form fields for the attendee edit
3822
+	 *
3823
+	 * @param  WP_Post $post wp post object
3824
+	 * @return string html for new form.
3825
+	 * @throws DomainException
3826
+	 */
3827
+	public function after_title_form_fields($post)
3828
+	{
3829
+		if ($post->post_type == 'espresso_attendees') {
3830
+			$template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3831
+			$template_args['attendee'] = $this->_cpt_model_obj;
3832
+			EEH_Template::display_template($template, $template_args);
3833
+		}
3834
+	}
3835
+
3836
+
3837
+	/**
3838
+	 *        _trash_or_restore_attendee
3839
+	 *
3840
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3841
+	 * @return void
3842
+	 * @throws EE_Error
3843
+	 * @throws InvalidArgumentException
3844
+	 * @throws InvalidDataTypeException
3845
+	 * @throws InvalidInterfaceException
3846
+	 * @access protected
3847
+	 */
3848
+	protected function _trash_or_restore_attendees($trash = true)
3849
+	{
3850
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3851
+		$ATT_MDL = EEM_Attendee::instance();
3852
+		$success = 1;
3853
+		// Checkboxes
3854
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3855
+			// if array has more than one element than success message should be plural
3856
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3857
+			// cycle thru checkboxes
3858
+			while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3859
+				$updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3860
+					: $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3861
+				if (! $updated) {
3862
+					$success = 0;
3863
+				}
3864
+			}
3865
+		} else {
3866
+			// grab single id and delete
3867
+			$ATT_ID = absint($this->_req_data['ATT_ID']);
3868
+			// get attendee
3869
+			$att = $ATT_MDL->get_one_by_ID($ATT_ID);
3870
+			$updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3871
+			$updated = $att->save();
3872
+			if (! $updated) {
3873
+				$success = 0;
3874
+			}
3875
+		}
3876
+		$what = $success > 1
3877
+			? esc_html__('Contacts', 'event_espresso')
3878
+			: esc_html__('Contact', 'event_espresso');
3879
+		$action_desc = $trash
3880
+			? esc_html__('moved to the trash', 'event_espresso')
3881
+			: esc_html__('restored', 'event_espresso');
3882
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3883
+	}
3884 3884
 }
Please login to merge, or discard this patch.
Spacing   +109 added lines, -109 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 {
@@ -1200,7 +1200,7 @@  discard block
 block discarded – undo
1200 1200
             'caps'                     => EEM_Registration::caps_read_admin,
1201 1201
             'default_where_conditions' => 'this_model_only',
1202 1202
         );
1203
-        if (! $count) {
1203
+        if ( ! $count) {
1204 1204
             $query_params = array_merge(
1205 1205
                 $query_params,
1206 1206
                 $this->_get_orderby_for_registrations_query(),
@@ -1221,7 +1221,7 @@  discard block
 block discarded – undo
1221 1221
     protected function addAttendeeIdToWhereConditions(array $request)
1222 1222
     {
1223 1223
         $where = array();
1224
-        if (! empty($request['ATT_ID'])) {
1224
+        if ( ! empty($request['ATT_ID'])) {
1225 1225
             $where['ATT_ID'] = absint($request['ATT_ID']);
1226 1226
         }
1227 1227
         return $where;
@@ -1237,7 +1237,7 @@  discard block
 block discarded – undo
1237 1237
     protected function _add_event_id_to_where_conditions(array $request)
1238 1238
     {
1239 1239
         $where = array();
1240
-        if (! empty($request['event_id'])) {
1240
+        if ( ! empty($request['event_id'])) {
1241 1241
             $where['EVT_ID'] = absint($request['event_id']);
1242 1242
         }
1243 1243
         return $where;
@@ -1253,7 +1253,7 @@  discard block
 block discarded – undo
1253 1253
     protected function _add_category_id_to_where_conditions(array $request)
1254 1254
     {
1255 1255
         $where = array();
1256
-        if (! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) {
1256
+        if ( ! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) {
1257 1257
             $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1258 1258
         }
1259 1259
         return $where;
@@ -1269,10 +1269,10 @@  discard block
 block discarded – undo
1269 1269
     protected function _add_datetime_id_to_where_conditions(array $request)
1270 1270
     {
1271 1271
         $where = array();
1272
-        if (! empty($request['datetime_id'])) {
1272
+        if ( ! empty($request['datetime_id'])) {
1273 1273
             $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1274 1274
         }
1275
-        if (! empty($request['DTT_ID'])) {
1275
+        if ( ! empty($request['DTT_ID'])) {
1276 1276
             $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1277 1277
         }
1278 1278
         return $where;
@@ -1298,7 +1298,7 @@  discard block
 block discarded – undo
1298 1298
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1299 1299
          * UNLESS viewing trashed registrations.
1300 1300
          */
1301
-        if (! empty($registration_status)) {
1301
+        if ( ! empty($registration_status)) {
1302 1302
             $where['STS_ID'] = $registration_status;
1303 1303
         } else {
1304 1304
             // make sure we exclude incomplete registrations, but only if not trashed.
@@ -1341,12 +1341,12 @@  discard block
 block discarded – undo
1341 1341
                 array(
1342 1342
                     EEM_Registration::instance()->convert_datetime_for_query(
1343 1343
                         'REG_date',
1344
-                        $now . ' 00:00:00',
1344
+                        $now.' 00:00:00',
1345 1345
                         'Y-m-d H:i:s'
1346 1346
                     ),
1347 1347
                     EEM_Registration::instance()->convert_datetime_for_query(
1348 1348
                         'REG_date',
1349
-                        $now . ' 23:59:59',
1349
+                        $now.' 23:59:59',
1350 1350
                         'Y-m-d H:i:s'
1351 1351
                     ),
1352 1352
                 ),
@@ -1359,12 +1359,12 @@  discard block
 block discarded – undo
1359 1359
                 array(
1360 1360
                     EEM_Registration::instance()->convert_datetime_for_query(
1361 1361
                         'REG_date',
1362
-                        $current_year_and_month . '-01 00:00:00',
1362
+                        $current_year_and_month.'-01 00:00:00',
1363 1363
                         'Y-m-d H:i:s'
1364 1364
                     ),
1365 1365
                     EEM_Registration::instance()->convert_datetime_for_query(
1366 1366
                         'REG_date',
1367
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1367
+                        $current_year_and_month.'-'.$days_this_month.' 23:59:59',
1368 1368
                         'Y-m-d H:i:s'
1369 1369
                     ),
1370 1370
                 ),
@@ -1379,18 +1379,18 @@  discard block
 block discarded – undo
1379 1379
                 : '';
1380 1380
             // if there is not a month or year then we can't go further
1381 1381
             if ($month_requested && $year_requested) {
1382
-                $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1382
+                $days_in_month = date('t', strtotime($year_requested.'-'.$month_requested.'-'.'01'));
1383 1383
                 $where['REG_date'] = array(
1384 1384
                     'BETWEEN',
1385 1385
                     array(
1386 1386
                         EEM_Registration::instance()->convert_datetime_for_query(
1387 1387
                             'REG_date',
1388
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1388
+                            $year_requested.'-'.$month_requested.'-01 00:00:00',
1389 1389
                             'Y-m-d H:i:s'
1390 1390
                         ),
1391 1391
                         EEM_Registration::instance()->convert_datetime_for_query(
1392 1392
                             'REG_date',
1393
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1393
+                            $year_requested.'-'.$month_requested.'-'.$days_in_month.' 23:59:59',
1394 1394
                             'Y-m-d H:i:s'
1395 1395
                         ),
1396 1396
                     ),
@@ -1410,8 +1410,8 @@  discard block
 block discarded – undo
1410 1410
     protected function _add_search_to_where_conditions(array $request)
1411 1411
     {
1412 1412
         $where = array();
1413
-        if (! empty($request['s'])) {
1414
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1413
+        if ( ! empty($request['s'])) {
1414
+            $search_string = '%'.sanitize_text_field($request['s']).'%';
1415 1415
             $where['OR*search_conditions'] = array(
1416 1416
                 'Event.EVT_name'                          => array('LIKE', $search_string),
1417 1417
                 'Event.EVT_desc'                          => array('LIKE', $search_string),
@@ -1647,7 +1647,7 @@  discard block
 block discarded – undo
1647 1647
                 )
1648 1648
                 : '';
1649 1649
             // grab header
1650
-            $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1650
+            $template_path = REG_TEMPLATE_PATH.'reg_admin_details_header.template.php';
1651 1651
             $this->_template_args['REG_ID'] = $this->_registration->ID();
1652 1652
             $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1653 1653
                 $template_path,
@@ -1784,7 +1784,7 @@  discard block
 block discarded – undo
1784 1784
                             EEH_HTML::strong(
1785 1785
                                 $this->_registration->pretty_status(),
1786 1786
                                 '',
1787
-                                'status-' . $this->_registration->status_ID(),
1787
+                                'status-'.$this->_registration->status_ID(),
1788 1788
                                 'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1789 1789
                             )
1790 1790
                         )
@@ -1839,14 +1839,14 @@  discard block
 block discarded – undo
1839 1839
     protected function _get_reg_statuses()
1840 1840
     {
1841 1841
         $reg_status_array = EEM_Registration::instance()->reg_status_array();
1842
-        unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1842
+        unset($reg_status_array[EEM_Registration::status_id_incomplete]);
1843 1843
         // get current reg status
1844 1844
         $current_status = $this->_registration->status_ID();
1845 1845
         // is registration for free event? This will determine whether to display the pending payment option
1846 1846
         if ($current_status !== EEM_Registration::status_id_pending_payment
1847 1847
             && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1848 1848
         ) {
1849
-            unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1849
+            unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1850 1850
         }
1851 1851
         return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1852 1852
     }
@@ -1938,7 +1938,7 @@  discard block
 block discarded – undo
1938 1938
         $success = false;
1939 1939
         // typecast $REG_IDs
1940 1940
         $REG_IDs = (array) $REG_IDs;
1941
-        if (! empty($REG_IDs)) {
1941
+        if ( ! empty($REG_IDs)) {
1942 1942
             $success = true;
1943 1943
             // set default status if none is passed
1944 1944
             $status = $status ? $status : EEM_Registration::status_id_pending_payment;
@@ -2086,7 +2086,7 @@  discard block
 block discarded – undo
2086 2086
             $action,
2087 2087
             $notify
2088 2088
         );
2089
-        $method = $action . '_registration';
2089
+        $method = $action.'_registration';
2090 2090
         if (method_exists($this, $method)) {
2091 2091
             $this->$method($notify);
2092 2092
         }
@@ -2317,7 +2317,7 @@  discard block
 block discarded – undo
2317 2317
         $this->_template_args['REG_ID'] = $this->_registration->ID();
2318 2318
         $this->_template_args['event_id'] = $this->_registration->event_ID();
2319 2319
         $template_path =
2320
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2320
+            REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_details.template.php';
2321 2321
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2322 2322
     }
2323 2323
 
@@ -2350,7 +2350,7 @@  discard block
 block discarded – undo
2350 2350
             $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2351 2351
             $this->_template_args['REG_ID'] = $this->_registration->ID();
2352 2352
             $template_path =
2353
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2353
+                REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php';
2354 2354
             echo EEH_Template::display_template($template_path, $this->_template_args, true);
2355 2355
         }
2356 2356
     }
@@ -2367,7 +2367,7 @@  discard block
 block discarded – undo
2367 2367
     public function form_before_question_group($output)
2368 2368
     {
2369 2369
         EE_Error::doing_it_wrong(
2370
-            __CLASS__ . '::' . __FUNCTION__,
2370
+            __CLASS__.'::'.__FUNCTION__,
2371 2371
             esc_html__(
2372 2372
                 '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.',
2373 2373
                 'event_espresso'
@@ -2392,7 +2392,7 @@  discard block
 block discarded – undo
2392 2392
     public function form_after_question_group($output)
2393 2393
     {
2394 2394
         EE_Error::doing_it_wrong(
2395
-            __CLASS__ . '::' . __FUNCTION__,
2395
+            __CLASS__.'::'.__FUNCTION__,
2396 2396
             esc_html__(
2397 2397
                 '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.',
2398 2398
                 'event_espresso'
@@ -2430,7 +2430,7 @@  discard block
 block discarded – undo
2430 2430
     public function form_form_field_label_wrap($label)
2431 2431
     {
2432 2432
         EE_Error::doing_it_wrong(
2433
-            __CLASS__ . '::' . __FUNCTION__,
2433
+            __CLASS__.'::'.__FUNCTION__,
2434 2434
             esc_html__(
2435 2435
                 '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.',
2436 2436
                 'event_espresso'
@@ -2440,7 +2440,7 @@  discard block
 block discarded – undo
2440 2440
         return '
2441 2441
 			<tr>
2442 2442
 				<th>
2443
-					' . $label . '
2443
+					' . $label.'
2444 2444
 				</th>';
2445 2445
     }
2446 2446
 
@@ -2456,7 +2456,7 @@  discard block
 block discarded – undo
2456 2456
     public function form_form_field_input__wrap($input)
2457 2457
     {
2458 2458
         EE_Error::doing_it_wrong(
2459
-            __CLASS__ . '::' . __FUNCTION__,
2459
+            __CLASS__.'::'.__FUNCTION__,
2460 2460
             esc_html__(
2461 2461
                 '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.',
2462 2462
                 'event_espresso'
@@ -2465,7 +2465,7 @@  discard block
 block discarded – undo
2465 2465
         );
2466 2466
         return '
2467 2467
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2468
-					' . $input . '
2468
+					' . $input.'
2469 2469
 				</td>
2470 2470
 			</tr>';
2471 2471
     }
@@ -2509,8 +2509,8 @@  discard block
 block discarded – undo
2509 2509
      */
2510 2510
     protected function _get_reg_custom_questions_form($REG_ID)
2511 2511
     {
2512
-        if (! $this->_reg_custom_questions_form) {
2513
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2512
+        if ( ! $this->_reg_custom_questions_form) {
2513
+            require_once(REG_ADMIN.'form_sections'.DS.'EE_Registration_Custom_Questions_Form.form.php');
2514 2514
             $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2515 2515
                 EEM_Registration::instance()->get_one_by_ID($REG_ID)
2516 2516
             );
@@ -2533,7 +2533,7 @@  discard block
 block discarded – undo
2533 2533
      */
2534 2534
     private function _save_reg_custom_questions_form($REG_ID = false)
2535 2535
     {
2536
-        if (! $REG_ID) {
2536
+        if ( ! $REG_ID) {
2537 2537
             EE_Error::add_error(
2538 2538
                 esc_html__(
2539 2539
                     'An error occurred. No registration ID was received.',
@@ -2624,30 +2624,30 @@  discard block
 block discarded – undo
2624 2624
                     ? $registration->attendee()
2625 2625
                     : EEM_Attendee::instance()
2626 2626
                                   ->create_default_object();
2627
-                $this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID();
2628
-                $this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname();
2629
-                $this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname();
2630
-                $this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email();
2631
-                $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2632
-                $this->_template_args['attendees'][ $att_nmbr ]['address'] = implode(
2627
+                $this->_template_args['attendees'][$att_nmbr]['STS_ID'] = $registration->status_ID();
2628
+                $this->_template_args['attendees'][$att_nmbr]['fname'] = $attendee->fname();
2629
+                $this->_template_args['attendees'][$att_nmbr]['lname'] = $attendee->lname();
2630
+                $this->_template_args['attendees'][$att_nmbr]['email'] = $attendee->email();
2631
+                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2632
+                $this->_template_args['attendees'][$att_nmbr]['address'] = implode(
2633 2633
                     ', ',
2634 2634
                     $attendee->full_address_as_array()
2635 2635
                 );
2636
-                $this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce(
2636
+                $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce(
2637 2637
                     array(
2638 2638
                         'action' => 'edit_attendee',
2639 2639
                         'post'   => $attendee->ID(),
2640 2640
                     ),
2641 2641
                     REG_ADMIN_URL
2642 2642
                 );
2643
-                $this->_template_args['attendees'][ $att_nmbr ]['event_name'] = $registration->event_obj() instanceof EE_Event
2643
+                $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj() instanceof EE_Event
2644 2644
                     ? $registration->event_obj()->name()
2645 2645
                     : '';
2646 2646
                 $att_nmbr++;
2647 2647
             }
2648 2648
             $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2649 2649
         }
2650
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2650
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_attendees.template.php';
2651 2651
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2652 2652
     }
2653 2653
 
@@ -2671,11 +2671,11 @@  discard block
 block discarded – undo
2671 2671
         // now let's determine if this is not the primary registration.  If it isn't then we set the
2672 2672
         // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2673 2673
         // primary registration object (that way we know if we need to show create button or not)
2674
-        if (! $this->_registration->is_primary_registrant()) {
2674
+        if ( ! $this->_registration->is_primary_registrant()) {
2675 2675
             $primary_registration = $this->_registration->get_primary_registration();
2676 2676
             $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2677 2677
                 : null;
2678
-            if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2678
+            if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2679 2679
                 // in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2680 2680
                 // custom attendee object so let's not worry about the primary reg.
2681 2681
                 $primary_registration = null;
@@ -2709,7 +2709,7 @@  discard block
 block discarded – undo
2709 2709
             ) : '';
2710 2710
         $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2711 2711
         $this->_template_args['att_check'] = $att_check;
2712
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2712
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_side_meta_box_registrant.template.php';
2713 2713
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2714 2714
     }
2715 2715
 
@@ -2747,7 +2747,7 @@  discard block
 block discarded – undo
2747 2747
         $success = 0;
2748 2748
         $overwrite_msgs = false;
2749 2749
         // Checkboxes
2750
-        if (! is_array($this->_req_data['_REG_ID'])) {
2750
+        if ( ! is_array($this->_req_data['_REG_ID'])) {
2751 2751
             $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2752 2752
         }
2753 2753
         $reg_count = count($this->_req_data['_REG_ID']);
@@ -2756,7 +2756,7 @@  discard block
 block discarded – undo
2756 2756
             /** @var EE_Registration $REG */
2757 2757
             $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2758 2758
             $payments = $REG->registration_payments();
2759
-            if (! empty($payments)) {
2759
+            if ( ! empty($payments)) {
2760 2760
                 $name = $REG->attendee() instanceof EE_Attendee
2761 2761
                     ? $REG->attendee()->full_name()
2762 2762
                     : esc_html__('Unknown Attendee', 'event_espresso');
@@ -2817,17 +2817,17 @@  discard block
 block discarded – undo
2817 2817
         $REG_MDL = EEM_Registration::instance();
2818 2818
         $success = 1;
2819 2819
         // Checkboxes
2820
-        if (! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2820
+        if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2821 2821
             // if array has more than one element than success message should be plural
2822 2822
             $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2823 2823
             // cycle thru checkboxes
2824 2824
             while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2825 2825
                 $REG = $REG_MDL->get_one_by_ID($REG_ID);
2826
-                if (! $REG instanceof EE_Registration) {
2826
+                if ( ! $REG instanceof EE_Registration) {
2827 2827
                     continue;
2828 2828
                 }
2829 2829
                 $deleted = $this->_delete_registration($REG);
2830
-                if (! $deleted) {
2830
+                if ( ! $deleted) {
2831 2831
                     $success = 0;
2832 2832
                 }
2833 2833
             }
@@ -2836,7 +2836,7 @@  discard block
 block discarded – undo
2836 2836
             $REG_ID = $this->_req_data['_REG_ID'];
2837 2837
             $REG = $REG_MDL->get_one_by_ID($REG_ID);
2838 2838
             $deleted = $this->_delete_registration($REG);
2839
-            if (! $deleted) {
2839
+            if ( ! $deleted) {
2840 2840
                 $success = 0;
2841 2841
             }
2842 2842
         }
@@ -2870,11 +2870,11 @@  discard block
 block discarded – undo
2870 2870
         $REGS = $TXN->get_many_related('Registration');
2871 2871
         $all_trashed = true;
2872 2872
         foreach ($REGS as $registration) {
2873
-            if (! $registration->get('REG_deleted')) {
2873
+            if ( ! $registration->get('REG_deleted')) {
2874 2874
                 $all_trashed = false;
2875 2875
             }
2876 2876
         }
2877
-        if (! $all_trashed) {
2877
+        if ( ! $all_trashed) {
2878 2878
             EE_Error::add_error(
2879 2879
                 esc_html__(
2880 2880
                     '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.',
@@ -2933,7 +2933,7 @@  discard block
 block discarded – undo
2933 2933
      */
2934 2934
     public function new_registration()
2935 2935
     {
2936
-        if (! $this->_set_reg_event()) {
2936
+        if ( ! $this->_set_reg_event()) {
2937 2937
             throw new EE_Error(
2938 2938
                 esc_html__(
2939 2939
                     'Unable to continue with registering because there is no Event ID in the request',
@@ -2943,8 +2943,8 @@  discard block
 block discarded – undo
2943 2943
         }
2944 2944
         EE_Registry::instance()->REQ->set_espresso_page(true);
2945 2945
         // gotta start with a clean slate if we're not coming here via ajax
2946
-        if (! defined('DOING_AJAX')
2947
-            && (! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2946
+        if ( ! defined('DOING_AJAX')
2947
+            && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2948 2948
         ) {
2949 2949
             EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2950 2950
         }
@@ -2977,7 +2977,7 @@  discard block
 block discarded – undo
2977 2977
         }
2978 2978
         // grab header
2979 2979
         $template_path =
2980
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2980
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee.template.php';
2981 2981
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2982 2982
             $template_path,
2983 2983
             $this->_template_args,
@@ -3018,7 +3018,7 @@  discard block
 block discarded – undo
3018 3018
                 '</b>'
3019 3019
             );
3020 3020
             return '
3021
-	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
3021
+	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg.'</p></div>
3022 3022
 	<script >
3023 3023
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
3024 3024
 		// after just adding a new registration... we gotta try to put a stop to that !!!
@@ -3086,7 +3086,7 @@  discard block
 block discarded – undo
3086 3086
         // we come back to the process_registration_step route.
3087 3087
         $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
3088 3088
         return EEH_Template::display_template(
3089
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
3089
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee_step_content.template.php',
3090 3090
             $template_args,
3091 3091
             true
3092 3092
         );
@@ -3108,8 +3108,8 @@  discard block
 block discarded – undo
3108 3108
         if (is_object($this->_reg_event)) {
3109 3109
             return true;
3110 3110
         }
3111
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
3112
-        if (! $EVT_ID) {
3111
+        $EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
3112
+        if ( ! $EVT_ID) {
3113 3113
             return false;
3114 3114
         }
3115 3115
         $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
@@ -3141,8 +3141,8 @@  discard block
 block discarded – undo
3141 3141
         $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3142 3142
         // if doing ajax then we need to verify the nonce
3143 3143
         if (defined('DOING_AJAX')) {
3144
-            $nonce = isset($this->_req_data[ $this->_req_nonce ])
3145
-                ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) : '';
3144
+            $nonce = isset($this->_req_data[$this->_req_nonce])
3145
+                ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
3146 3146
             $this->_verify_nonce($nonce, $this->_req_nonce);
3147 3147
         }
3148 3148
         switch ($step) {
@@ -3178,7 +3178,7 @@  discard block
 block discarded – undo
3178 3178
                 }
3179 3179
                 break;
3180 3180
             case 'questions':
3181
-                if (! isset(
3181
+                if ( ! isset(
3182 3182
                     $this->_req_data['txn_reg_status_change'],
3183 3183
                     $this->_req_data['txn_reg_status_change']['send_notifications']
3184 3184
                 )
@@ -3193,7 +3193,7 @@  discard block
 block discarded – undo
3193 3193
                         $grand_total->save_this_and_descendants_to_txn();
3194 3194
                     }
3195 3195
                 }
3196
-                if (! $transaction instanceof EE_Transaction) {
3196
+                if ( ! $transaction instanceof EE_Transaction) {
3197 3197
                     $query_args = array(
3198 3198
                         'action'                  => 'new_registration',
3199 3199
                         'processing_registration' => 2,
@@ -3216,7 +3216,7 @@  discard block
 block discarded – undo
3216 3216
                     }
3217 3217
                 }
3218 3218
                 // maybe update status, and make sure to save transaction if not done already
3219
-                if (! $transaction->update_status_based_on_total_paid()) {
3219
+                if ( ! $transaction->update_status_based_on_total_paid()) {
3220 3220
                     $transaction->save();
3221 3221
                 }
3222 3222
                 EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
@@ -3299,7 +3299,7 @@  discard block
 block discarded – undo
3299 3299
     public function get_attendees($per_page, $count = false, $trash = false)
3300 3300
     {
3301 3301
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3302
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3302
+        require_once(REG_ADMIN.'EE_Attendee_Contact_List_Table.class.php');
3303 3303
         $ATT_MDL = EEM_Attendee::instance();
3304 3304
         $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3305 3305
         switch ($this->_req_data['orderby']) {
@@ -3338,8 +3338,8 @@  discard block
 block discarded – undo
3338 3338
             ? $this->_req_data['perpage']
3339 3339
             : $per_page;
3340 3340
         $_where = array();
3341
-        if (! empty($this->_req_data['s'])) {
3342
-            $sstr = '%' . $this->_req_data['s'] . '%';
3341
+        if ( ! empty($this->_req_data['s'])) {
3342
+            $sstr = '%'.$this->_req_data['s'].'%';
3343 3343
             $_where['OR'] = array(
3344 3344
                 'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3345 3345
                 'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
@@ -3366,7 +3366,7 @@  discard block
 block discarded – undo
3366 3366
             'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')),
3367 3367
             'limit'         => $limit,
3368 3368
         );
3369
-        if (! $count) {
3369
+        if ( ! $count) {
3370 3370
             $query_args['order_by'] = array($orderby => $sort);
3371 3371
         }
3372 3372
         if ($trash) {
@@ -3409,7 +3409,7 @@  discard block
 block discarded – undo
3409 3409
      */
3410 3410
     public function _registrations_report_base($method_name_for_getting_query_params)
3411 3411
     {
3412
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3412
+        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3413 3413
             wp_redirect(
3414 3414
                 EE_Admin_Page::add_query_args_and_nonce(
3415 3415
                     array(
@@ -3441,8 +3441,8 @@  discard block
 block discarded – undo
3441 3441
                 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3442 3442
             );
3443 3443
             $this->_req_data = array_merge($this->_req_data, $new_request_args);
3444
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3445
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3444
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3445
+                require_once(EE_CLASSES.'EE_Export.class.php');
3446 3446
                 $EE_Export = EE_Export::instance($this->_req_data);
3447 3447
                 $EE_Export->export();
3448 3448
             }
@@ -3463,8 +3463,8 @@  discard block
 block discarded – undo
3463 3463
 
3464 3464
     public function _contact_list_export()
3465 3465
     {
3466
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3467
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3466
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3467
+            require_once(EE_CLASSES.'EE_Export.class.php');
3468 3468
             $EE_Export = EE_Export::instance($this->_req_data);
3469 3469
             $EE_Export->export_attendees();
3470 3470
         }
@@ -3473,7 +3473,7 @@  discard block
 block discarded – undo
3473 3473
 
3474 3474
     public function _contact_list_report()
3475 3475
     {
3476
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3476
+        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3477 3477
             wp_redirect(
3478 3478
                 EE_Admin_Page::add_query_args_and_nonce(
3479 3479
                     array(
@@ -3485,8 +3485,8 @@  discard block
 block discarded – undo
3485 3485
                 )
3486 3486
             );
3487 3487
         } else {
3488
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3489
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3488
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3489
+                require_once(EE_CLASSES.'EE_Export.class.php');
3490 3490
                 $EE_Export = EE_Export::instance($this->_req_data);
3491 3491
                 $EE_Export->report_attendees();
3492 3492
             }
@@ -3572,7 +3572,7 @@  discard block
 block discarded – undo
3572 3572
             $updated_fields = array(
3573 3573
                 'ATT_fname'     => $this->_req_data['ATT_fname'],
3574 3574
                 'ATT_lname'     => $this->_req_data['ATT_lname'],
3575
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3575
+                'ATT_full_name' => $this->_req_data['ATT_fname'].' '.$this->_req_data['ATT_lname'],
3576 3576
                 'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3577 3577
                 'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3578 3578
                 'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
@@ -3648,17 +3648,17 @@  discard block
 block discarded – undo
3648 3648
             'postexcerpt',
3649 3649
             esc_html__('Excerpt', 'event_espresso'),
3650 3650
             'post_excerpt_meta_box',
3651
-            $this->_cpt_routes[ $this->_req_action ],
3651
+            $this->_cpt_routes[$this->_req_action],
3652 3652
             'normal',
3653 3653
             'core'
3654 3654
         );
3655
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal', 'core');
3655
+        remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3656 3656
         if (post_type_supports('espresso_attendees', 'excerpt')) {
3657 3657
             add_meta_box(
3658 3658
                 'postexcerpt',
3659 3659
                 esc_html__('Short Biography', 'event_espresso'),
3660 3660
                 'post_excerpt_meta_box',
3661
-                $this->_cpt_routes[ $this->_req_action ],
3661
+                $this->_cpt_routes[$this->_req_action],
3662 3662
                 'normal'
3663 3663
             );
3664 3664
         }
@@ -3667,7 +3667,7 @@  discard block
 block discarded – undo
3667 3667
                 'commentsdiv',
3668 3668
                 esc_html__('Notes on the Contact', 'event_espresso'),
3669 3669
                 'post_comment_meta_box',
3670
-                $this->_cpt_routes[ $this->_req_action ],
3670
+                $this->_cpt_routes[$this->_req_action],
3671 3671
                 'normal',
3672 3672
                 'core'
3673 3673
             );
@@ -3676,7 +3676,7 @@  discard block
 block discarded – undo
3676 3676
             'attendee_contact_info',
3677 3677
             esc_html__('Contact Info', 'event_espresso'),
3678 3678
             array($this, 'attendee_contact_info'),
3679
-            $this->_cpt_routes[ $this->_req_action ],
3679
+            $this->_cpt_routes[$this->_req_action],
3680 3680
             'side',
3681 3681
             'core'
3682 3682
         );
@@ -3684,7 +3684,7 @@  discard block
 block discarded – undo
3684 3684
             'attendee_details_address',
3685 3685
             esc_html__('Address Details', 'event_espresso'),
3686 3686
             array($this, 'attendee_address_details'),
3687
-            $this->_cpt_routes[ $this->_req_action ],
3687
+            $this->_cpt_routes[$this->_req_action],
3688 3688
             'normal',
3689 3689
             'core'
3690 3690
         );
@@ -3692,7 +3692,7 @@  discard block
 block discarded – undo
3692 3692
             'attendee_registrations',
3693 3693
             esc_html__('Registrations for this Contact', 'event_espresso'),
3694 3694
             array($this, 'attendee_registrations_meta_box'),
3695
-            $this->_cpt_routes[ $this->_req_action ],
3695
+            $this->_cpt_routes[$this->_req_action],
3696 3696
             'normal',
3697 3697
             'high'
3698 3698
         );
@@ -3793,7 +3793,7 @@  discard block
 block discarded – undo
3793 3793
             )
3794 3794
         );
3795 3795
         $template =
3796
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3796
+            REG_TEMPLATE_PATH.'attendee_address_details_metabox_content.template.php';
3797 3797
         EEH_Template::display_template($template, $this->_template_args);
3798 3798
     }
3799 3799
 
@@ -3812,7 +3812,7 @@  discard block
 block discarded – undo
3812 3812
         $this->_template_args['attendee'] = $this->_cpt_model_obj;
3813 3813
         $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3814 3814
         $template =
3815
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3815
+            REG_TEMPLATE_PATH.'attendee_registrations_main_meta_box.template.php';
3816 3816
         EEH_Template::display_template($template, $this->_template_args);
3817 3817
     }
3818 3818
 
@@ -3827,7 +3827,7 @@  discard block
 block discarded – undo
3827 3827
     public function after_title_form_fields($post)
3828 3828
     {
3829 3829
         if ($post->post_type == 'espresso_attendees') {
3830
-            $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3830
+            $template = REG_TEMPLATE_PATH.'attendee_details_after_title_form_fields.template.php';
3831 3831
             $template_args['attendee'] = $this->_cpt_model_obj;
3832 3832
             EEH_Template::display_template($template, $template_args);
3833 3833
         }
@@ -3851,14 +3851,14 @@  discard block
 block discarded – undo
3851 3851
         $ATT_MDL = EEM_Attendee::instance();
3852 3852
         $success = 1;
3853 3853
         // Checkboxes
3854
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3854
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3855 3855
             // if array has more than one element than success message should be plural
3856 3856
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3857 3857
             // cycle thru checkboxes
3858 3858
             while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3859 3859
                 $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3860 3860
                     : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3861
-                if (! $updated) {
3861
+                if ( ! $updated) {
3862 3862
                     $success = 0;
3863 3863
                 }
3864 3864
             }
@@ -3869,7 +3869,7 @@  discard block
 block discarded – undo
3869 3869
             $att = $ATT_MDL->get_one_by_ID($ATT_ID);
3870 3870
             $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3871 3871
             $updated = $att->save();
3872
-            if (! $updated) {
3872
+            if ( ! $updated) {
3873 3873
                 $success = 0;
3874 3874
             }
3875 3875
         }
Please login to merge, or discard this patch.