Completed
Branch dependabot/npm_and_yarn/wordpr... (bdc6c0)
by
unknown
87:38 queued 77:25
created
core/domain/services/capabilities/PublicCapabilities.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -20,13 +20,13 @@
 block discarded – undo
20 20
 {
21 21
 
22 22
 
23
-    /**
24
-     * @return string
25
-     */
26
-    public function capability()
27
-    {
28
-        return '';
29
-    }
23
+	/**
24
+	 * @return string
25
+	 */
26
+	public function capability()
27
+	{
28
+		return '';
29
+	}
30 30
 
31 31
 
32 32
 }
Please login to merge, or discard this patch.
modules/gateways/Invoice/lib/invoice_functions.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -8,9 +8,9 @@  discard block
 block discarded – undo
8 8
  * @param $class_file
9 9
  * @return array
10 10
  */
11
-function espresso_invoice_template_files( $class_file) {
11
+function espresso_invoice_template_files($class_file) {
12 12
 	// read our template dir and build an array of files
13
-	$dhandle = opendir(dirname($class_file) . '/lib/templates/css/'); //If the template files have been moved to the uploads folder
13
+	$dhandle = opendir(dirname($class_file).'/lib/templates/css/'); //If the template files have been moved to the uploads folder
14 14
 	//} else return FALSE;
15 15
 
16 16
 	$files = array();
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
  * @param string $selected
51 51
  * @return string
52 52
  */
53
-function espresso_invoice_is_selected( $input_item, $selected='') {
54
-	if ( $input_item === $selected ) {
53
+function espresso_invoice_is_selected($input_item, $selected = '') {
54
+	if ($input_item === $selected) {
55 55
 		return 'selected="selected"';
56 56
 	} else {
57 57
 		return '';
Please login to merge, or discard this patch.
admin_pages/registrations/EE_Registrations_List_Table.class.php 3 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.
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.
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.
Indentation   +1369 added lines, -1369 removed lines patch added patch discarded remove patch
@@ -14,981 +14,981 @@  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
-                    'ee_delete_others_registrations',
409
-                    // checkins
410
-                    'ee_read_others_checkins',
411
-                    'ee_read_checkins',
412
-                    'ee_edit_checkins',
413
-                    'ee_edit_others_checkins',
414
-                    'ee_delete_checkins',
415
-                    'ee_delete_others_checkins',
416
-                    // transactions && payments
417
-                    'ee_read_transaction',
418
-                    'ee_read_transactions',
419
-                    'ee_edit_payments',
420
-                    'ee_delete_payments',
421
-                    // messages
422
-                    'ee_read_messages',
423
-                    'ee_read_others_messages',
424
-                    'ee_read_global_messages',
425
-                    'ee_edit_global_messages',
426
-                    'ee_edit_messages',
427
-                    'ee_edit_others_messages',
428
-                    'ee_delete_messages',
429
-                    'ee_delete_others_messages',
430
-                    'ee_delete_global_messages',
431
-                    'ee_send_message',
432
-                    // tickets
433
-                    'ee_read_default_tickets',
434
-                    'ee_read_others_default_tickets',
435
-                    'ee_edit_default_tickets',
436
-                    'ee_edit_others_default_tickets',
437
-                    'ee_delete_default_tickets',
438
-                    'ee_delete_others_default_tickets',
439
-                    // prices
440
-                    'ee_edit_default_price',
441
-                    'ee_edit_default_prices',
442
-                    'ee_delete_default_price',
443
-                    'ee_delete_default_prices',
444
-                    'ee_edit_default_price_type',
445
-                    'ee_edit_default_price_types',
446
-                    'ee_delete_default_price_type',
447
-                    'ee_delete_default_price_types',
448
-                    'ee_read_default_prices',
449
-                    'ee_read_default_price_types',
450
-                    // registration form
451
-                    'ee_edit_questions',
452
-                    'ee_edit_system_questions',
453
-                    'ee_read_questions',
454
-                    'ee_delete_questions',
455
-                    'ee_edit_question_groups',
456
-                    'ee_read_question_groups',
457
-                    'ee_edit_system_question_groups',
458
-                    'ee_delete_question_groups',
459
-                    // event_type taxonomy
460
-                    'ee_assign_event_type',
461
-                    'ee_manage_event_types',
462
-                    'ee_edit_event_type',
463
-                    'ee_delete_event_type',
464
-                ),
465
-                'ee_events_administrator' => array(
466
-                    // core wp caps
467
-                    'read',
468
-                    'read_private_pages',
469
-                    'read_private_posts',
470
-                    'edit_users',
471
-                    'edit_posts',
472
-                    'edit_pages',
473
-                    'edit_published_posts',
474
-                    'edit_published_pages',
475
-                    'edit_private_pages',
476
-                    'edit_private_posts',
477
-                    'edit_others_posts',
478
-                    'edit_others_pages',
479
-                    'publish_posts',
480
-                    'publish_pages',
481
-                    'delete_posts',
482
-                    'delete_pages',
483
-                    'delete_private_pages',
484
-                    'delete_private_posts',
485
-                    'delete_published_pages',
486
-                    'delete_published_posts',
487
-                    'delete_others_posts',
488
-                    'delete_others_pages',
489
-                    'manage_categories',
490
-                    'manage_links',
491
-                    'moderate_comments',
492
-                    'unfiltered_html',
493
-                    'upload_files',
494
-                    'export',
495
-                    'import',
496
-                    'list_users',
497
-                    'level_1', // required if user with this role shows up in author dropdowns
498
-                    // basic ee access
499
-                    'ee_read_ee',
500
-                    // events
501
-                    'ee_publish_events',
502
-                    'ee_read_private_events',
503
-                    'ee_read_others_events',
504
-                    'ee_read_event',
505
-                    'ee_read_events',
506
-                    'ee_edit_event',
507
-                    'ee_edit_events',
508
-                    'ee_edit_published_events',
509
-                    'ee_edit_others_events',
510
-                    'ee_edit_private_events',
511
-                    'ee_delete_published_events',
512
-                    'ee_delete_private_events',
513
-                    'ee_delete_event',
514
-                    'ee_delete_events',
515
-                    'ee_delete_others_events',
516
-                    // event categories
517
-                    'ee_manage_event_categories',
518
-                    'ee_edit_event_category',
519
-                    'ee_delete_event_category',
520
-                    'ee_assign_event_category',
521
-                    // venues
522
-                    'ee_publish_venues',
523
-                    'ee_read_venue',
524
-                    'ee_read_venues',
525
-                    'ee_read_others_venues',
526
-                    'ee_read_private_venues',
527
-                    'ee_edit_venue',
528
-                    'ee_edit_venues',
529
-                    'ee_edit_others_venues',
530
-                    'ee_edit_published_venues',
531
-                    'ee_edit_private_venues',
532
-                    'ee_delete_venue',
533
-                    'ee_delete_venues',
534
-                    'ee_delete_others_venues',
535
-                    'ee_delete_private_venues',
536
-                    'ee_delete_published_venues',
537
-                    // venue categories
538
-                    'ee_manage_venue_categories',
539
-                    'ee_edit_venue_category',
540
-                    'ee_delete_venue_category',
541
-                    'ee_assign_venue_category',
542
-                    // contacts
543
-                    'ee_read_contacts',
544
-                    'ee_edit_contacts',
545
-                    'ee_delete_contacts',
546
-                    // registrations
547
-                    'ee_read_registrations',
548
-                    'ee_read_others_registrations',
549
-                    'ee_edit_registration',
550
-                    'ee_edit_registrations',
551
-                    'ee_edit_others_registrations',
552
-                    'ee_delete_registration',
553
-                    'ee_delete_registrations',
554
-                    'ee_delete_others_registrations',
555
-                    // checkins
556
-                    'ee_read_others_checkins',
557
-                    'ee_read_checkins',
558
-                    'ee_edit_checkins',
559
-                    'ee_edit_others_checkins',
560
-                    'ee_delete_checkins',
561
-                    'ee_delete_others_checkins',
562
-                    // transactions && payments
563
-                    'ee_read_transaction',
564
-                    'ee_read_transactions',
565
-                    'ee_edit_payments',
566
-                    'ee_delete_payments',
567
-                    // messages
568
-                    'ee_read_messages',
569
-                    'ee_read_others_messages',
570
-                    'ee_read_global_messages',
571
-                    'ee_edit_global_messages',
572
-                    'ee_edit_messages',
573
-                    'ee_edit_others_messages',
574
-                    'ee_delete_messages',
575
-                    'ee_delete_others_messages',
576
-                    'ee_delete_global_messages',
577
-                    'ee_send_message',
578
-                    // tickets
579
-                    'ee_read_default_tickets',
580
-                    'ee_read_others_default_tickets',
581
-                    'ee_edit_default_tickets',
582
-                    'ee_edit_others_default_tickets',
583
-                    'ee_delete_default_tickets',
584
-                    'ee_delete_others_default_tickets',
585
-                    // prices
586
-                    'ee_edit_default_price',
587
-                    'ee_edit_default_prices',
588
-                    'ee_delete_default_price',
589
-                    'ee_delete_default_prices',
590
-                    'ee_edit_default_price_type',
591
-                    'ee_edit_default_price_types',
592
-                    'ee_delete_default_price_type',
593
-                    'ee_delete_default_price_types',
594
-                    'ee_read_default_prices',
595
-                    'ee_read_default_price_types',
596
-                    // registration form
597
-                    'ee_edit_questions',
598
-                    'ee_edit_system_questions',
599
-                    'ee_read_questions',
600
-                    'ee_delete_questions',
601
-                    'ee_edit_question_groups',
602
-                    'ee_read_question_groups',
603
-                    'ee_edit_system_question_groups',
604
-                    'ee_delete_question_groups',
605
-                    // event_type taxonomy
606
-                    'ee_assign_event_type',
607
-                    'ee_manage_event_types',
608
-                    'ee_edit_event_type',
609
-                    'ee_delete_event_type',
610
-                ),
611
-            )
612
-        );
613
-    }
614
-
615
-
616
-    /**
617
-     * @return bool
618
-     * @throws EE_Error
619
-     */
620
-    private function setupCapabilitiesMap()
621
-    {
622
-        // if the initialization process hasn't even started, then we need to call init_caps()
623
-        if ($this->initialized === null) {
624
-            return $this->init_caps();
625
-        }
626
-        // unless resetting, get caps from db if we haven't already
627
-        $this->capabilities_map = $this->reset || ! empty($this->capabilities_map)
628
-            ? $this->capabilities_map
629
-            : get_option(self::option_name, array());
630
-        return true;
631
-    }
632
-
633
-
634
-    /**
635
-     * @param bool $update
636
-     * @return bool
637
-     */
638
-    private function updateCapabilitiesMap($update = true)
639
-    {
640
-        return $update ? update_option(self::option_name, $this->capabilities_map) : false;
641
-    }
642
-
643
-
644
-    /**
645
-     * Adds capabilities to roles.
646
-     *
647
-     * @since 4.9.42
648
-     * @param array $capabilities_to_add array of capabilities to add, indexed by roles.
649
-     *                                   Note that this should ONLY be called on activation hook
650
-     *                                   otherwise the caps will be added on every request.
651
-     * @return bool
652
-     * @throws \EE_Error
653
-     */
654
-    public function addCaps(array $capabilities_to_add)
655
-    {
656
-        // don't do anything if the capabilities map can not be initialized
657
-        if (! $this->setupCapabilitiesMap()) {
658
-            return false;
659
-        }
660
-        // and filter the array so others can get in on the fun during resets
661
-        $capabilities_to_add = apply_filters(
662
-            'FHEE__EE_Capabilities__addCaps__capabilities_to_add',
663
-            $capabilities_to_add,
664
-            $this->reset,
665
-            $this->capabilities_map
666
-        );
667
-        $update_capabilities_map = false;
668
-        // if not reset, see what caps are new for each role. if they're new, add them.
669
-        foreach ($capabilities_to_add as $role => $caps_for_role) {
670
-            if (is_array($caps_for_role)) {
671
-                foreach ($caps_for_role as $cap) {
672
-                    if (! $this->capHasBeenAddedToRole($role, $cap)
673
-                        && $this->add_cap_to_role($role, $cap, true, false)
674
-                    ) {
675
-                        $update_capabilities_map = true;
676
-                    }
677
-                }
678
-            }
679
-        }
680
-        // now let's just save the cap that has been set but only if there's been a change.
681
-        $updated = $this->updateCapabilitiesMap($update_capabilities_map);
682
-        $this->flushWpUser($updated);
683
-        do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated);
684
-        return $updated;
685
-    }
686
-
687
-
688
-    /**
689
-     * Loops through the capabilities map and removes the role caps specified by the incoming array
690
-     *
691
-     * @param array $caps_map map of capabilities to be removed (indexed by roles)
692
-     * @return bool
693
-     * @throws \EE_Error
694
-     */
695
-    public function removeCaps($caps_map)
696
-    {
697
-        // don't do anything if the capabilities map can not be initialized
698
-        if (! $this->setupCapabilitiesMap()) {
699
-            return false;
700
-        }
701
-        $update_capabilities_map = false;
702
-        foreach ($caps_map as $role => $caps_for_role) {
703
-            if (is_array($caps_for_role)) {
704
-                foreach ($caps_for_role as $cap) {
705
-                    if ($this->capHasBeenAddedToRole($role, $cap)
706
-                        && $this->remove_cap_from_role($role, $cap, false)
707
-                    ) {
708
-                        $update_capabilities_map = true;
709
-                    }
710
-                }
711
-            }
712
-        }
713
-        // maybe resave the caps
714
-        $updated = $this->updateCapabilitiesMap($update_capabilities_map);
715
-        $this->flushWpUser($updated);
716
-        return $updated;
717
-    }
718
-
719
-
720
-    /**
721
-     * This ensures that the WP User object cached on the $current_user global in WP has the latest capabilities from
722
-     * the roles on that user.
723
-     *
724
-     * @param bool $flush Default is to flush the WP_User object.  If false, then this method effectively does nothing.
725
-     */
726
-    private function flushWpUser($flush = true)
727
-    {
728
-        if ($flush) {
729
-            $user = wp_get_current_user();
730
-            if ($user instanceof WP_User) {
731
-                $user->get_role_caps();
732
-            }
733
-        }
734
-    }
735
-
736
-
737
-    /**
738
-     * This method sets a capability on a role.  Note this should only be done on activation, or if you have something
739
-     * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note.
740
-     * this is a wrapper for $wp_role->add_cap()
741
-     *
742
-     * @see   wp-includes/capabilities.php
743
-     * @since 4.5.0
744
-     * @param string|WP_Role $role  A WordPress role the capability is being added to
745
-     * @param string         $cap   The capability being added to the role
746
-     * @param bool           $grant Whether to grant access to this cap on this role.
747
-     * @param bool           $update_capabilities_map
748
-     * @return bool
749
-     * @throws \EE_Error
750
-     */
751
-    public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true)
752
-    {
753
-        // capture incoming value for $role because we may need it to create a new WP_Role
754
-        $orig_role = $role;
755
-        $role = $role instanceof WP_Role ? $role : get_role($role);
756
-        // if the role isn't available then we create it.
757
-        if (! $role instanceof WP_Role) {
758
-            // if a plugin wants to create a specific role name then they should create the role before
759
-            // EE_Capabilities does.  Otherwise this function will create the role name from the slug:
760
-            // - removes any `ee_` namespacing from the start of the slug.
761
-            // - replaces `_` with ` ` (empty space).
762
-            // - sentence case on the resulting string.
763
-            $role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role));
764
-            $role = add_role($orig_role, $role_label);
765
-        }
766
-        if ($role instanceof WP_Role) {
767
-            // don't do anything if the capabilities map can not be initialized
768
-            if (! $this->setupCapabilitiesMap()) {
769
-                return false;
770
-            }
771
-            if (! $this->capHasBeenAddedToRole($role->name, $cap)) {
772
-                $role->add_cap($cap, $grant);
773
-                $this->capabilities_map[ $role->name ][] = $cap;
774
-                $this->updateCapabilitiesMap($update_capabilities_map);
775
-                return true;
776
-            }
777
-        }
778
-        return false;
779
-    }
780
-
781
-
782
-    /**
783
-     * Functions similarly to add_cap_to_role except removes cap from given role.
784
-     * Wrapper for $wp_role->remove_cap()
785
-     *
786
-     * @see   wp-includes/capabilities.php
787
-     * @since 4.5.0
788
-     * @param string|WP_Role $role A WordPress role the capability is being removed from.
789
-     * @param string         $cap  The capability being removed
790
-     * @param bool           $update_capabilities_map
791
-     * @return bool
792
-     * @throws \EE_Error
793
-     */
794
-    public function remove_cap_from_role($role, $cap, $update_capabilities_map = true)
795
-    {
796
-        // don't do anything if the capabilities map can not be initialized
797
-        if (! $this->setupCapabilitiesMap()) {
798
-            return false;
799
-        }
800
-
801
-        $role = $role instanceof WP_Role ? $role : get_role($role);
802
-        if ($role instanceof WP_Role && $index = $this->capHasBeenAddedToRole($role->name, $cap, true)) {
803
-            $role->remove_cap($cap);
804
-            unset($this->capabilities_map[ $role->name ][ $index ]);
805
-            $this->updateCapabilitiesMap($update_capabilities_map);
806
-            return true;
807
-        }
808
-        return false;
809
-    }
810
-
811
-
812
-    /**
813
-     * @param string $role_name
814
-     * @param string $cap
815
-     * @param bool   $get_index
816
-     * @return bool|mixed
817
-     */
818
-    private function capHasBeenAddedToRole($role_name = '', $cap = '', $get_index = false)
819
-    {
820
-        if (isset($this->capabilities_map[ $role_name ])
821
-            && ($index = array_search($cap, $this->capabilities_map[ $role_name ], true)) !== false
822
-        ) {
823
-            return $get_index ? $index : true;
824
-        }
825
-        return false;
826
-    }
827
-
828
-
829
-    /**
830
-     * Wrapper for the native WP current_user_can() method.
831
-     * This is provided as a handy method for a couple things:
832
-     * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
833
-     * write those filters wherever current_user_can is called).
834
-     * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
835
-     *
836
-     * @since 4.5.0
837
-     *
838
-     * @param string $cap     The cap being checked.
839
-     * @param string $context The context where the current_user_can is being called from.
840
-     * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
841
-     *                        filters.
842
-     *
843
-     * @return bool  Whether user can or not.
844
-     */
845
-    public function current_user_can($cap, $context, $id = 0)
846
-    {
847
-        // apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
848
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id);
849
-        $filtered_cap = apply_filters(
850
-            'FHEE__EE_Capabilities__current_user_can__cap',
851
-            $filtered_cap,
852
-            $context,
853
-            $cap,
854
-            $id
855
-        );
856
-        return ! empty($id)
857
-            ? current_user_can($filtered_cap, $id)
858
-            : current_user_can($filtered_cap);
859
-    }
860
-
861
-
862
-    /**
863
-     * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class.
864
-     *
865
-     * @param int|WP_User $user    Either the user_id or a WP_User object
866
-     * @param string      $cap     The capability string being checked
867
-     * @param string      $context The context where the user_can is being called from (used in filters).
868
-     * @param int         $id      Optional. Id for item where user_can is being called from ( used in map_meta_cap()
869
-     *                             filters)
870
-     *
871
-     * @return bool Whether user can or not.
872
-     */
873
-    public function user_can($user, $cap, $context, $id = 0)
874
-    {
875
-        // apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
876
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id);
877
-        $filtered_cap = apply_filters(
878
-            'FHEE__EE_Capabilities__user_can__cap',
879
-            $filtered_cap,
880
-            $context,
881
-            $cap,
882
-            $user,
883
-            $id
884
-        );
885
-        return ! empty($id)
886
-            ? user_can($user, $filtered_cap, $id)
887
-            : user_can($user, $filtered_cap);
888
-    }
889
-
890
-
891
-    /**
892
-     * Wrapper for the native WP current_user_can_for_blog() method.
893
-     * This is provided as a handy method for a couple things:
894
-     * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
895
-     * write those filters wherever current_user_can is called).
896
-     * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
897
-     *
898
-     * @since 4.5.0
899
-     *
900
-     * @param int    $blog_id The blog id that is being checked for.
901
-     * @param string $cap     The cap being checked.
902
-     * @param string $context The context where the current_user_can is being called from.
903
-     * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
904
-     *                        filters.
905
-     *
906
-     * @return bool  Whether user can or not.
907
-     */
908
-    public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0)
909
-    {
910
-        $user_can = ! empty($id)
911
-            ? current_user_can_for_blog($blog_id, $cap, $id)
912
-            : current_user_can($blog_id, $cap);
913
-        // apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
914
-        $user_can = apply_filters(
915
-            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context,
916
-            $user_can,
917
-            $blog_id,
918
-            $cap,
919
-            $id
920
-        );
921
-        $user_can = apply_filters(
922
-            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can',
923
-            $user_can,
924
-            $context,
925
-            $blog_id,
926
-            $cap,
927
-            $id
928
-        );
929
-        return $user_can;
930
-    }
931
-
932
-
933
-    /**
934
-     * This helper method just returns an array of registered EE capabilities.
935
-     *
936
-     * @since 4.5.0
937
-     * @param string $role If empty then the entire role/capability map is returned.
938
-     *                     Otherwise just the capabilities for the given role are returned.
939
-     * @return array
940
-     * @throws EE_Error
941
-     */
942
-    public function get_ee_capabilities($role = 'administrator')
943
-    {
944
-        if (! $this->initialized) {
945
-            $this->init_caps();
946
-        }
947
-        if (empty($role)) {
948
-            return $this->capabilities_map;
949
-        }
950
-        return isset($this->capabilities_map[ $role ])
951
-            ? $this->capabilities_map[ $role ]
952
-            : array();
953
-    }
954
-
955
-
956
-    /**
957
-     * @deprecated 4.9.42
958
-     * @param bool  $reset      If you need to reset Event Espresso's capabilities,
959
-     *                          then please use the init_caps() method with the "$reset" parameter set to "true"
960
-     * @param array $caps_map   Optional.
961
-     *                          Can be used to send a custom map of roles and capabilities for setting them up.
962
-     *                          Note that this should ONLY be called on activation hook or some other one-time
963
-     *                          task otherwise the caps will be added on every request.
964
-     * @return void
965
-     * @throws EE_Error
966
-     */
967
-    public function init_role_caps($reset = false, $caps_map = array())
968
-    {
969
-        // If this method is called directly and reset is set as 'true',
970
-        // then display a doing it wrong notice, because we want resets to go through init_caps()
971
-        // to guarantee that everything is set up correctly.
972
-        // This prevents the capabilities map getting reset incorrectly by direct calls to this method.
973
-        if ($reset) {
974
-            EE_Error::doing_it_wrong(
975
-                __METHOD__,
976
-                sprintf(
977
-                    esc_html__(
978
-                        '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".',
979
-                        'event_espresso'
980
-                    ),
981
-                    '$reset',
982
-                    __METHOD__ . '()',
983
-                    'EE_Capabilities::init_caps()',
984
-                    'true'
985
-                ),
986
-                '4.9.42',
987
-                '5.0.0'
988
-            );
989
-        }
990
-        $this->addCaps($caps_map);
991
-    }
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
+					'ee_delete_others_registrations',
409
+					// checkins
410
+					'ee_read_others_checkins',
411
+					'ee_read_checkins',
412
+					'ee_edit_checkins',
413
+					'ee_edit_others_checkins',
414
+					'ee_delete_checkins',
415
+					'ee_delete_others_checkins',
416
+					// transactions && payments
417
+					'ee_read_transaction',
418
+					'ee_read_transactions',
419
+					'ee_edit_payments',
420
+					'ee_delete_payments',
421
+					// messages
422
+					'ee_read_messages',
423
+					'ee_read_others_messages',
424
+					'ee_read_global_messages',
425
+					'ee_edit_global_messages',
426
+					'ee_edit_messages',
427
+					'ee_edit_others_messages',
428
+					'ee_delete_messages',
429
+					'ee_delete_others_messages',
430
+					'ee_delete_global_messages',
431
+					'ee_send_message',
432
+					// tickets
433
+					'ee_read_default_tickets',
434
+					'ee_read_others_default_tickets',
435
+					'ee_edit_default_tickets',
436
+					'ee_edit_others_default_tickets',
437
+					'ee_delete_default_tickets',
438
+					'ee_delete_others_default_tickets',
439
+					// prices
440
+					'ee_edit_default_price',
441
+					'ee_edit_default_prices',
442
+					'ee_delete_default_price',
443
+					'ee_delete_default_prices',
444
+					'ee_edit_default_price_type',
445
+					'ee_edit_default_price_types',
446
+					'ee_delete_default_price_type',
447
+					'ee_delete_default_price_types',
448
+					'ee_read_default_prices',
449
+					'ee_read_default_price_types',
450
+					// registration form
451
+					'ee_edit_questions',
452
+					'ee_edit_system_questions',
453
+					'ee_read_questions',
454
+					'ee_delete_questions',
455
+					'ee_edit_question_groups',
456
+					'ee_read_question_groups',
457
+					'ee_edit_system_question_groups',
458
+					'ee_delete_question_groups',
459
+					// event_type taxonomy
460
+					'ee_assign_event_type',
461
+					'ee_manage_event_types',
462
+					'ee_edit_event_type',
463
+					'ee_delete_event_type',
464
+				),
465
+				'ee_events_administrator' => array(
466
+					// core wp caps
467
+					'read',
468
+					'read_private_pages',
469
+					'read_private_posts',
470
+					'edit_users',
471
+					'edit_posts',
472
+					'edit_pages',
473
+					'edit_published_posts',
474
+					'edit_published_pages',
475
+					'edit_private_pages',
476
+					'edit_private_posts',
477
+					'edit_others_posts',
478
+					'edit_others_pages',
479
+					'publish_posts',
480
+					'publish_pages',
481
+					'delete_posts',
482
+					'delete_pages',
483
+					'delete_private_pages',
484
+					'delete_private_posts',
485
+					'delete_published_pages',
486
+					'delete_published_posts',
487
+					'delete_others_posts',
488
+					'delete_others_pages',
489
+					'manage_categories',
490
+					'manage_links',
491
+					'moderate_comments',
492
+					'unfiltered_html',
493
+					'upload_files',
494
+					'export',
495
+					'import',
496
+					'list_users',
497
+					'level_1', // required if user with this role shows up in author dropdowns
498
+					// basic ee access
499
+					'ee_read_ee',
500
+					// events
501
+					'ee_publish_events',
502
+					'ee_read_private_events',
503
+					'ee_read_others_events',
504
+					'ee_read_event',
505
+					'ee_read_events',
506
+					'ee_edit_event',
507
+					'ee_edit_events',
508
+					'ee_edit_published_events',
509
+					'ee_edit_others_events',
510
+					'ee_edit_private_events',
511
+					'ee_delete_published_events',
512
+					'ee_delete_private_events',
513
+					'ee_delete_event',
514
+					'ee_delete_events',
515
+					'ee_delete_others_events',
516
+					// event categories
517
+					'ee_manage_event_categories',
518
+					'ee_edit_event_category',
519
+					'ee_delete_event_category',
520
+					'ee_assign_event_category',
521
+					// venues
522
+					'ee_publish_venues',
523
+					'ee_read_venue',
524
+					'ee_read_venues',
525
+					'ee_read_others_venues',
526
+					'ee_read_private_venues',
527
+					'ee_edit_venue',
528
+					'ee_edit_venues',
529
+					'ee_edit_others_venues',
530
+					'ee_edit_published_venues',
531
+					'ee_edit_private_venues',
532
+					'ee_delete_venue',
533
+					'ee_delete_venues',
534
+					'ee_delete_others_venues',
535
+					'ee_delete_private_venues',
536
+					'ee_delete_published_venues',
537
+					// venue categories
538
+					'ee_manage_venue_categories',
539
+					'ee_edit_venue_category',
540
+					'ee_delete_venue_category',
541
+					'ee_assign_venue_category',
542
+					// contacts
543
+					'ee_read_contacts',
544
+					'ee_edit_contacts',
545
+					'ee_delete_contacts',
546
+					// registrations
547
+					'ee_read_registrations',
548
+					'ee_read_others_registrations',
549
+					'ee_edit_registration',
550
+					'ee_edit_registrations',
551
+					'ee_edit_others_registrations',
552
+					'ee_delete_registration',
553
+					'ee_delete_registrations',
554
+					'ee_delete_others_registrations',
555
+					// checkins
556
+					'ee_read_others_checkins',
557
+					'ee_read_checkins',
558
+					'ee_edit_checkins',
559
+					'ee_edit_others_checkins',
560
+					'ee_delete_checkins',
561
+					'ee_delete_others_checkins',
562
+					// transactions && payments
563
+					'ee_read_transaction',
564
+					'ee_read_transactions',
565
+					'ee_edit_payments',
566
+					'ee_delete_payments',
567
+					// messages
568
+					'ee_read_messages',
569
+					'ee_read_others_messages',
570
+					'ee_read_global_messages',
571
+					'ee_edit_global_messages',
572
+					'ee_edit_messages',
573
+					'ee_edit_others_messages',
574
+					'ee_delete_messages',
575
+					'ee_delete_others_messages',
576
+					'ee_delete_global_messages',
577
+					'ee_send_message',
578
+					// tickets
579
+					'ee_read_default_tickets',
580
+					'ee_read_others_default_tickets',
581
+					'ee_edit_default_tickets',
582
+					'ee_edit_others_default_tickets',
583
+					'ee_delete_default_tickets',
584
+					'ee_delete_others_default_tickets',
585
+					// prices
586
+					'ee_edit_default_price',
587
+					'ee_edit_default_prices',
588
+					'ee_delete_default_price',
589
+					'ee_delete_default_prices',
590
+					'ee_edit_default_price_type',
591
+					'ee_edit_default_price_types',
592
+					'ee_delete_default_price_type',
593
+					'ee_delete_default_price_types',
594
+					'ee_read_default_prices',
595
+					'ee_read_default_price_types',
596
+					// registration form
597
+					'ee_edit_questions',
598
+					'ee_edit_system_questions',
599
+					'ee_read_questions',
600
+					'ee_delete_questions',
601
+					'ee_edit_question_groups',
602
+					'ee_read_question_groups',
603
+					'ee_edit_system_question_groups',
604
+					'ee_delete_question_groups',
605
+					// event_type taxonomy
606
+					'ee_assign_event_type',
607
+					'ee_manage_event_types',
608
+					'ee_edit_event_type',
609
+					'ee_delete_event_type',
610
+				),
611
+			)
612
+		);
613
+	}
614
+
615
+
616
+	/**
617
+	 * @return bool
618
+	 * @throws EE_Error
619
+	 */
620
+	private function setupCapabilitiesMap()
621
+	{
622
+		// if the initialization process hasn't even started, then we need to call init_caps()
623
+		if ($this->initialized === null) {
624
+			return $this->init_caps();
625
+		}
626
+		// unless resetting, get caps from db if we haven't already
627
+		$this->capabilities_map = $this->reset || ! empty($this->capabilities_map)
628
+			? $this->capabilities_map
629
+			: get_option(self::option_name, array());
630
+		return true;
631
+	}
632
+
633
+
634
+	/**
635
+	 * @param bool $update
636
+	 * @return bool
637
+	 */
638
+	private function updateCapabilitiesMap($update = true)
639
+	{
640
+		return $update ? update_option(self::option_name, $this->capabilities_map) : false;
641
+	}
642
+
643
+
644
+	/**
645
+	 * Adds capabilities to roles.
646
+	 *
647
+	 * @since 4.9.42
648
+	 * @param array $capabilities_to_add array of capabilities to add, indexed by roles.
649
+	 *                                   Note that this should ONLY be called on activation hook
650
+	 *                                   otherwise the caps will be added on every request.
651
+	 * @return bool
652
+	 * @throws \EE_Error
653
+	 */
654
+	public function addCaps(array $capabilities_to_add)
655
+	{
656
+		// don't do anything if the capabilities map can not be initialized
657
+		if (! $this->setupCapabilitiesMap()) {
658
+			return false;
659
+		}
660
+		// and filter the array so others can get in on the fun during resets
661
+		$capabilities_to_add = apply_filters(
662
+			'FHEE__EE_Capabilities__addCaps__capabilities_to_add',
663
+			$capabilities_to_add,
664
+			$this->reset,
665
+			$this->capabilities_map
666
+		);
667
+		$update_capabilities_map = false;
668
+		// if not reset, see what caps are new for each role. if they're new, add them.
669
+		foreach ($capabilities_to_add as $role => $caps_for_role) {
670
+			if (is_array($caps_for_role)) {
671
+				foreach ($caps_for_role as $cap) {
672
+					if (! $this->capHasBeenAddedToRole($role, $cap)
673
+						&& $this->add_cap_to_role($role, $cap, true, false)
674
+					) {
675
+						$update_capabilities_map = true;
676
+					}
677
+				}
678
+			}
679
+		}
680
+		// now let's just save the cap that has been set but only if there's been a change.
681
+		$updated = $this->updateCapabilitiesMap($update_capabilities_map);
682
+		$this->flushWpUser($updated);
683
+		do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated);
684
+		return $updated;
685
+	}
686
+
687
+
688
+	/**
689
+	 * Loops through the capabilities map and removes the role caps specified by the incoming array
690
+	 *
691
+	 * @param array $caps_map map of capabilities to be removed (indexed by roles)
692
+	 * @return bool
693
+	 * @throws \EE_Error
694
+	 */
695
+	public function removeCaps($caps_map)
696
+	{
697
+		// don't do anything if the capabilities map can not be initialized
698
+		if (! $this->setupCapabilitiesMap()) {
699
+			return false;
700
+		}
701
+		$update_capabilities_map = false;
702
+		foreach ($caps_map as $role => $caps_for_role) {
703
+			if (is_array($caps_for_role)) {
704
+				foreach ($caps_for_role as $cap) {
705
+					if ($this->capHasBeenAddedToRole($role, $cap)
706
+						&& $this->remove_cap_from_role($role, $cap, false)
707
+					) {
708
+						$update_capabilities_map = true;
709
+					}
710
+				}
711
+			}
712
+		}
713
+		// maybe resave the caps
714
+		$updated = $this->updateCapabilitiesMap($update_capabilities_map);
715
+		$this->flushWpUser($updated);
716
+		return $updated;
717
+	}
718
+
719
+
720
+	/**
721
+	 * This ensures that the WP User object cached on the $current_user global in WP has the latest capabilities from
722
+	 * the roles on that user.
723
+	 *
724
+	 * @param bool $flush Default is to flush the WP_User object.  If false, then this method effectively does nothing.
725
+	 */
726
+	private function flushWpUser($flush = true)
727
+	{
728
+		if ($flush) {
729
+			$user = wp_get_current_user();
730
+			if ($user instanceof WP_User) {
731
+				$user->get_role_caps();
732
+			}
733
+		}
734
+	}
735
+
736
+
737
+	/**
738
+	 * This method sets a capability on a role.  Note this should only be done on activation, or if you have something
739
+	 * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note.
740
+	 * this is a wrapper for $wp_role->add_cap()
741
+	 *
742
+	 * @see   wp-includes/capabilities.php
743
+	 * @since 4.5.0
744
+	 * @param string|WP_Role $role  A WordPress role the capability is being added to
745
+	 * @param string         $cap   The capability being added to the role
746
+	 * @param bool           $grant Whether to grant access to this cap on this role.
747
+	 * @param bool           $update_capabilities_map
748
+	 * @return bool
749
+	 * @throws \EE_Error
750
+	 */
751
+	public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true)
752
+	{
753
+		// capture incoming value for $role because we may need it to create a new WP_Role
754
+		$orig_role = $role;
755
+		$role = $role instanceof WP_Role ? $role : get_role($role);
756
+		// if the role isn't available then we create it.
757
+		if (! $role instanceof WP_Role) {
758
+			// if a plugin wants to create a specific role name then they should create the role before
759
+			// EE_Capabilities does.  Otherwise this function will create the role name from the slug:
760
+			// - removes any `ee_` namespacing from the start of the slug.
761
+			// - replaces `_` with ` ` (empty space).
762
+			// - sentence case on the resulting string.
763
+			$role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role));
764
+			$role = add_role($orig_role, $role_label);
765
+		}
766
+		if ($role instanceof WP_Role) {
767
+			// don't do anything if the capabilities map can not be initialized
768
+			if (! $this->setupCapabilitiesMap()) {
769
+				return false;
770
+			}
771
+			if (! $this->capHasBeenAddedToRole($role->name, $cap)) {
772
+				$role->add_cap($cap, $grant);
773
+				$this->capabilities_map[ $role->name ][] = $cap;
774
+				$this->updateCapabilitiesMap($update_capabilities_map);
775
+				return true;
776
+			}
777
+		}
778
+		return false;
779
+	}
780
+
781
+
782
+	/**
783
+	 * Functions similarly to add_cap_to_role except removes cap from given role.
784
+	 * Wrapper for $wp_role->remove_cap()
785
+	 *
786
+	 * @see   wp-includes/capabilities.php
787
+	 * @since 4.5.0
788
+	 * @param string|WP_Role $role A WordPress role the capability is being removed from.
789
+	 * @param string         $cap  The capability being removed
790
+	 * @param bool           $update_capabilities_map
791
+	 * @return bool
792
+	 * @throws \EE_Error
793
+	 */
794
+	public function remove_cap_from_role($role, $cap, $update_capabilities_map = true)
795
+	{
796
+		// don't do anything if the capabilities map can not be initialized
797
+		if (! $this->setupCapabilitiesMap()) {
798
+			return false;
799
+		}
800
+
801
+		$role = $role instanceof WP_Role ? $role : get_role($role);
802
+		if ($role instanceof WP_Role && $index = $this->capHasBeenAddedToRole($role->name, $cap, true)) {
803
+			$role->remove_cap($cap);
804
+			unset($this->capabilities_map[ $role->name ][ $index ]);
805
+			$this->updateCapabilitiesMap($update_capabilities_map);
806
+			return true;
807
+		}
808
+		return false;
809
+	}
810
+
811
+
812
+	/**
813
+	 * @param string $role_name
814
+	 * @param string $cap
815
+	 * @param bool   $get_index
816
+	 * @return bool|mixed
817
+	 */
818
+	private function capHasBeenAddedToRole($role_name = '', $cap = '', $get_index = false)
819
+	{
820
+		if (isset($this->capabilities_map[ $role_name ])
821
+			&& ($index = array_search($cap, $this->capabilities_map[ $role_name ], true)) !== false
822
+		) {
823
+			return $get_index ? $index : true;
824
+		}
825
+		return false;
826
+	}
827
+
828
+
829
+	/**
830
+	 * Wrapper for the native WP current_user_can() method.
831
+	 * This is provided as a handy method for a couple things:
832
+	 * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
833
+	 * write those filters wherever current_user_can is called).
834
+	 * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
835
+	 *
836
+	 * @since 4.5.0
837
+	 *
838
+	 * @param string $cap     The cap being checked.
839
+	 * @param string $context The context where the current_user_can is being called from.
840
+	 * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
841
+	 *                        filters.
842
+	 *
843
+	 * @return bool  Whether user can or not.
844
+	 */
845
+	public function current_user_can($cap, $context, $id = 0)
846
+	{
847
+		// apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
848
+		$filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id);
849
+		$filtered_cap = apply_filters(
850
+			'FHEE__EE_Capabilities__current_user_can__cap',
851
+			$filtered_cap,
852
+			$context,
853
+			$cap,
854
+			$id
855
+		);
856
+		return ! empty($id)
857
+			? current_user_can($filtered_cap, $id)
858
+			: current_user_can($filtered_cap);
859
+	}
860
+
861
+
862
+	/**
863
+	 * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class.
864
+	 *
865
+	 * @param int|WP_User $user    Either the user_id or a WP_User object
866
+	 * @param string      $cap     The capability string being checked
867
+	 * @param string      $context The context where the user_can is being called from (used in filters).
868
+	 * @param int         $id      Optional. Id for item where user_can is being called from ( used in map_meta_cap()
869
+	 *                             filters)
870
+	 *
871
+	 * @return bool Whether user can or not.
872
+	 */
873
+	public function user_can($user, $cap, $context, $id = 0)
874
+	{
875
+		// apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
876
+		$filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id);
877
+		$filtered_cap = apply_filters(
878
+			'FHEE__EE_Capabilities__user_can__cap',
879
+			$filtered_cap,
880
+			$context,
881
+			$cap,
882
+			$user,
883
+			$id
884
+		);
885
+		return ! empty($id)
886
+			? user_can($user, $filtered_cap, $id)
887
+			: user_can($user, $filtered_cap);
888
+	}
889
+
890
+
891
+	/**
892
+	 * Wrapper for the native WP current_user_can_for_blog() method.
893
+	 * This is provided as a handy method for a couple things:
894
+	 * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
895
+	 * write those filters wherever current_user_can is called).
896
+	 * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
897
+	 *
898
+	 * @since 4.5.0
899
+	 *
900
+	 * @param int    $blog_id The blog id that is being checked for.
901
+	 * @param string $cap     The cap being checked.
902
+	 * @param string $context The context where the current_user_can is being called from.
903
+	 * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
904
+	 *                        filters.
905
+	 *
906
+	 * @return bool  Whether user can or not.
907
+	 */
908
+	public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0)
909
+	{
910
+		$user_can = ! empty($id)
911
+			? current_user_can_for_blog($blog_id, $cap, $id)
912
+			: current_user_can($blog_id, $cap);
913
+		// apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
914
+		$user_can = apply_filters(
915
+			'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context,
916
+			$user_can,
917
+			$blog_id,
918
+			$cap,
919
+			$id
920
+		);
921
+		$user_can = apply_filters(
922
+			'FHEE__EE_Capabilities__current_user_can_for_blog__user_can',
923
+			$user_can,
924
+			$context,
925
+			$blog_id,
926
+			$cap,
927
+			$id
928
+		);
929
+		return $user_can;
930
+	}
931
+
932
+
933
+	/**
934
+	 * This helper method just returns an array of registered EE capabilities.
935
+	 *
936
+	 * @since 4.5.0
937
+	 * @param string $role If empty then the entire role/capability map is returned.
938
+	 *                     Otherwise just the capabilities for the given role are returned.
939
+	 * @return array
940
+	 * @throws EE_Error
941
+	 */
942
+	public function get_ee_capabilities($role = 'administrator')
943
+	{
944
+		if (! $this->initialized) {
945
+			$this->init_caps();
946
+		}
947
+		if (empty($role)) {
948
+			return $this->capabilities_map;
949
+		}
950
+		return isset($this->capabilities_map[ $role ])
951
+			? $this->capabilities_map[ $role ]
952
+			: array();
953
+	}
954
+
955
+
956
+	/**
957
+	 * @deprecated 4.9.42
958
+	 * @param bool  $reset      If you need to reset Event Espresso's capabilities,
959
+	 *                          then please use the init_caps() method with the "$reset" parameter set to "true"
960
+	 * @param array $caps_map   Optional.
961
+	 *                          Can be used to send a custom map of roles and capabilities for setting them up.
962
+	 *                          Note that this should ONLY be called on activation hook or some other one-time
963
+	 *                          task otherwise the caps will be added on every request.
964
+	 * @return void
965
+	 * @throws EE_Error
966
+	 */
967
+	public function init_role_caps($reset = false, $caps_map = array())
968
+	{
969
+		// If this method is called directly and reset is set as 'true',
970
+		// then display a doing it wrong notice, because we want resets to go through init_caps()
971
+		// to guarantee that everything is set up correctly.
972
+		// This prevents the capabilities map getting reset incorrectly by direct calls to this method.
973
+		if ($reset) {
974
+			EE_Error::doing_it_wrong(
975
+				__METHOD__,
976
+				sprintf(
977
+					esc_html__(
978
+						'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".',
979
+						'event_espresso'
980
+					),
981
+					'$reset',
982
+					__METHOD__ . '()',
983
+					'EE_Capabilities::init_caps()',
984
+					'true'
985
+				),
986
+				'4.9.42',
987
+				'5.0.0'
988
+			);
989
+		}
990
+		$this->addCaps($caps_map);
991
+	}
992 992
 }
993 993
 
994 994
 
@@ -1005,142 +1005,142 @@  discard block
 block discarded – undo
1005 1005
 abstract class EE_Meta_Capability_Map
1006 1006
 {
1007 1007
 
1008
-    public $meta_cap;
1009
-
1010
-    /**
1011
-     * @var EEM_Base
1012
-     */
1013
-    protected $_model;
1014
-
1015
-    protected $_model_name;
1016
-
1017
-    public $published_cap = '';
1018
-
1019
-    public $others_cap = '';
1020
-
1021
-    public $private_cap = '';
1022
-
1023
-
1024
-    /**
1025
-     * constructor.
1026
-     * Receives the setup arguments for the map.
1027
-     *
1028
-     * @since                        4.5.0
1029
-     *
1030
-     * @param string $meta_cap   What meta capability is this mapping.
1031
-     * @param array  $map_values array {
1032
-     *                           //array of values that MUST match a count of 4.  It's okay to send an empty string for
1033
-     *                           capabilities that don't get mapped to.
1034
-     *
1035
-     * @type         $map_values [0] string A string representing the model name. Required.  String's
1036
-     *                               should always be used when Menu Maps are registered via the
1037
-     *                               plugin API as models are not allowed to be instantiated when
1038
-     *                               in maintenance mode 2 (migrations).
1039
-     * @type         $map_values [1] string represents the capability used for published. Optional.
1040
-     * @type         $map_values [2] string represents the capability used for "others". Optional.
1041
-     * @type         $map_values [3] string represents the capability used for private. Optional.
1042
-     *                               }
1043
-     * @throws EE_Error
1044
-     */
1045
-    public function __construct($meta_cap, $map_values)
1046
-    {
1047
-        $this->meta_cap = $meta_cap;
1048
-        // verify there are four args in the $map_values array;
1049
-        if (count($map_values) !== 4) {
1050
-            throw new EE_Error(
1051
-                sprintf(
1052
-                    __(
1053
-                        'Incoming $map_values array should have a count of four values in it.  This is what was given: %s',
1054
-                        'event_espresso'
1055
-                    ),
1056
-                    '<br>' . print_r($map_values, true)
1057
-                )
1058
-            );
1059
-        }
1060
-        // set properties
1061
-        $this->_model = null;
1062
-        $this->_model_name = $map_values[0];
1063
-        $this->published_cap = (string) $map_values[1];
1064
-        $this->others_cap = (string) $map_values[2];
1065
-        $this->private_cap = (string) $map_values[3];
1066
-    }
1067
-
1068
-    /**
1069
-     * Makes it so this object stops filtering caps
1070
-     */
1071
-    public function remove_filters()
1072
-    {
1073
-        remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10);
1074
-    }
1075
-
1076
-
1077
-    /**
1078
-     * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class
1079
-     *
1080
-     * @since 4.5.0
1081
-     * @throws EE_Error
1082
-     *
1083
-     * @return void
1084
-     */
1085
-    public function ensure_is_model()
1086
-    {
1087
-        // is it already instantiated?
1088
-        if ($this->_model instanceof EEM_Base) {
1089
-            return;
1090
-        }
1091
-        // ensure model name is string
1092
-        $this->_model_name = (string) $this->_model_name;
1093
-        // error proof if the name has EEM in it
1094
-        $this->_model_name = str_replace('EEM', '', $this->_model_name);
1095
-        $this->_model = EE_Registry::instance()->load_model($this->_model_name);
1096
-        if (! $this->_model instanceof EEM_Base) {
1097
-            throw new EE_Error(
1098
-                sprintf(
1099
-                    __(
1100
-                        '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',
1101
-                        'event_espresso'
1102
-                    ),
1103
-                    get_class($this),
1104
-                    $this->_model
1105
-                )
1106
-            );
1107
-        }
1108
-    }
1109
-
1110
-
1111
-    /**
1112
-     *
1113
-     * @see   EE_Meta_Capability_Map::_map_meta_caps() for docs on params.
1114
-     * @since 4.6.x
1115
-     *
1116
-     * @param $caps
1117
-     * @param $cap
1118
-     * @param $user_id
1119
-     * @param $args
1120
-     *
1121
-     * @return array
1122
-     */
1123
-    public function map_meta_caps($caps, $cap, $user_id, $args)
1124
-    {
1125
-        return $this->_map_meta_caps($caps, $cap, $user_id, $args);
1126
-    }
1127
-
1128
-
1129
-    /**
1130
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1131
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1132
-     *
1133
-     * @since 4.5.0
1134
-     * @see   wp-includes/capabilities.php
1135
-     *
1136
-     * @param array  $caps    actual users capabilities
1137
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1138
-     * @param int    $user_id The user id
1139
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1140
-     *
1141
-     * @return array   actual users capabilities
1142
-     */
1143
-    abstract protected function _map_meta_caps($caps, $cap, $user_id, $args);
1008
+	public $meta_cap;
1009
+
1010
+	/**
1011
+	 * @var EEM_Base
1012
+	 */
1013
+	protected $_model;
1014
+
1015
+	protected $_model_name;
1016
+
1017
+	public $published_cap = '';
1018
+
1019
+	public $others_cap = '';
1020
+
1021
+	public $private_cap = '';
1022
+
1023
+
1024
+	/**
1025
+	 * constructor.
1026
+	 * Receives the setup arguments for the map.
1027
+	 *
1028
+	 * @since                        4.5.0
1029
+	 *
1030
+	 * @param string $meta_cap   What meta capability is this mapping.
1031
+	 * @param array  $map_values array {
1032
+	 *                           //array of values that MUST match a count of 4.  It's okay to send an empty string for
1033
+	 *                           capabilities that don't get mapped to.
1034
+	 *
1035
+	 * @type         $map_values [0] string A string representing the model name. Required.  String's
1036
+	 *                               should always be used when Menu Maps are registered via the
1037
+	 *                               plugin API as models are not allowed to be instantiated when
1038
+	 *                               in maintenance mode 2 (migrations).
1039
+	 * @type         $map_values [1] string represents the capability used for published. Optional.
1040
+	 * @type         $map_values [2] string represents the capability used for "others". Optional.
1041
+	 * @type         $map_values [3] string represents the capability used for private. Optional.
1042
+	 *                               }
1043
+	 * @throws EE_Error
1044
+	 */
1045
+	public function __construct($meta_cap, $map_values)
1046
+	{
1047
+		$this->meta_cap = $meta_cap;
1048
+		// verify there are four args in the $map_values array;
1049
+		if (count($map_values) !== 4) {
1050
+			throw new EE_Error(
1051
+				sprintf(
1052
+					__(
1053
+						'Incoming $map_values array should have a count of four values in it.  This is what was given: %s',
1054
+						'event_espresso'
1055
+					),
1056
+					'<br>' . print_r($map_values, true)
1057
+				)
1058
+			);
1059
+		}
1060
+		// set properties
1061
+		$this->_model = null;
1062
+		$this->_model_name = $map_values[0];
1063
+		$this->published_cap = (string) $map_values[1];
1064
+		$this->others_cap = (string) $map_values[2];
1065
+		$this->private_cap = (string) $map_values[3];
1066
+	}
1067
+
1068
+	/**
1069
+	 * Makes it so this object stops filtering caps
1070
+	 */
1071
+	public function remove_filters()
1072
+	{
1073
+		remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10);
1074
+	}
1075
+
1076
+
1077
+	/**
1078
+	 * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class
1079
+	 *
1080
+	 * @since 4.5.0
1081
+	 * @throws EE_Error
1082
+	 *
1083
+	 * @return void
1084
+	 */
1085
+	public function ensure_is_model()
1086
+	{
1087
+		// is it already instantiated?
1088
+		if ($this->_model instanceof EEM_Base) {
1089
+			return;
1090
+		}
1091
+		// ensure model name is string
1092
+		$this->_model_name = (string) $this->_model_name;
1093
+		// error proof if the name has EEM in it
1094
+		$this->_model_name = str_replace('EEM', '', $this->_model_name);
1095
+		$this->_model = EE_Registry::instance()->load_model($this->_model_name);
1096
+		if (! $this->_model instanceof EEM_Base) {
1097
+			throw new EE_Error(
1098
+				sprintf(
1099
+					__(
1100
+						'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',
1101
+						'event_espresso'
1102
+					),
1103
+					get_class($this),
1104
+					$this->_model
1105
+				)
1106
+			);
1107
+		}
1108
+	}
1109
+
1110
+
1111
+	/**
1112
+	 *
1113
+	 * @see   EE_Meta_Capability_Map::_map_meta_caps() for docs on params.
1114
+	 * @since 4.6.x
1115
+	 *
1116
+	 * @param $caps
1117
+	 * @param $cap
1118
+	 * @param $user_id
1119
+	 * @param $args
1120
+	 *
1121
+	 * @return array
1122
+	 */
1123
+	public function map_meta_caps($caps, $cap, $user_id, $args)
1124
+	{
1125
+		return $this->_map_meta_caps($caps, $cap, $user_id, $args);
1126
+	}
1127
+
1128
+
1129
+	/**
1130
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1131
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1132
+	 *
1133
+	 * @since 4.5.0
1134
+	 * @see   wp-includes/capabilities.php
1135
+	 *
1136
+	 * @param array  $caps    actual users capabilities
1137
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1138
+	 * @param int    $user_id The user id
1139
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1140
+	 *
1141
+	 * @return array   actual users capabilities
1142
+	 */
1143
+	abstract protected function _map_meta_caps($caps, $cap, $user_id, $args);
1144 1144
 }
1145 1145
 
1146 1146
 
@@ -1156,81 +1156,81 @@  discard block
 block discarded – undo
1156 1156
 class EE_Meta_Capability_Map_Edit extends EE_Meta_Capability_Map
1157 1157
 {
1158 1158
 
1159
-    /**
1160
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1161
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1162
-     *
1163
-     * @since 4.5.0
1164
-     * @see   wp-includes/capabilities.php
1165
-     *
1166
-     * @param array  $caps    actual users capabilities
1167
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1168
-     * @param int    $user_id The user id
1169
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1170
-     *
1171
-     * @return array   actual users capabilities
1172
-     */
1173
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1174
-    {
1175
-        // only process if we're checking our mapped_cap
1176
-        if ($cap !== $this->meta_cap) {
1177
-            return $caps;
1178
-        }
1179
-
1180
-        // okay it is a meta cap so let's first remove that cap from the $caps array.
1181
-        if (($key = array_search($cap, $caps)) !== false) {
1182
-            unset($caps[ $key ]);
1183
-        }
1184
-
1185
-        // cast $user_id to int for later explicit comparisons
1186
-        $user_id = (int) $user_id;
1187
-
1188
-        /** @var EE_Base_Class $obj */
1189
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1190
-        // if no obj then let's just do cap
1191
-        if (! $obj instanceof EE_Base_Class) {
1192
-            $caps[] = 'do_not_allow';
1193
-            return $caps;
1194
-        }
1195
-        $caps[] = $cap . 's';
1196
-        if ($obj instanceof EE_CPT_Base) {
1197
-            // if the item author is set and the user is the author...
1198
-            if ($obj->wp_user() && $user_id === $obj->wp_user()) {
1199
-                // if obj is published...
1200
-                if ($obj->status() === 'publish') {
1201
-                    $caps[] = $this->published_cap;
1202
-                }
1203
-            } else {
1204
-                // the user is trying to edit someone else's obj
1205
-                if (! empty($this->others_cap)) {
1206
-                    $caps[] = $this->others_cap;
1207
-                }
1208
-                if (! empty($this->published_cap) && $obj->status() === 'publish') {
1209
-                    $caps[] = $this->published_cap;
1210
-                } elseif (! empty($this->private_cap) && $obj->status() === 'private') {
1211
-                    $caps[] = $this->private_cap;
1212
-                }
1213
-            }
1214
-        } else {
1215
-            // not a cpt object so handled differently
1216
-            $has_cap = false;
1217
-            try {
1218
-                $has_cap = method_exists($obj, 'wp_user')
1219
-                           && $obj->wp_user()
1220
-                           && $obj->wp_user() === $user_id;
1221
-            } catch (Exception $e) {
1222
-                if (WP_DEBUG) {
1223
-                    EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1224
-                }
1225
-            }
1226
-            if (! $has_cap) {
1227
-                if (! empty($this->others_cap)) {
1228
-                    $caps[] = $this->others_cap;
1229
-                }
1230
-            }
1231
-        }
1232
-        return $caps;
1233
-    }
1159
+	/**
1160
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1161
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1162
+	 *
1163
+	 * @since 4.5.0
1164
+	 * @see   wp-includes/capabilities.php
1165
+	 *
1166
+	 * @param array  $caps    actual users capabilities
1167
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1168
+	 * @param int    $user_id The user id
1169
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1170
+	 *
1171
+	 * @return array   actual users capabilities
1172
+	 */
1173
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1174
+	{
1175
+		// only process if we're checking our mapped_cap
1176
+		if ($cap !== $this->meta_cap) {
1177
+			return $caps;
1178
+		}
1179
+
1180
+		// okay it is a meta cap so let's first remove that cap from the $caps array.
1181
+		if (($key = array_search($cap, $caps)) !== false) {
1182
+			unset($caps[ $key ]);
1183
+		}
1184
+
1185
+		// cast $user_id to int for later explicit comparisons
1186
+		$user_id = (int) $user_id;
1187
+
1188
+		/** @var EE_Base_Class $obj */
1189
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1190
+		// if no obj then let's just do cap
1191
+		if (! $obj instanceof EE_Base_Class) {
1192
+			$caps[] = 'do_not_allow';
1193
+			return $caps;
1194
+		}
1195
+		$caps[] = $cap . 's';
1196
+		if ($obj instanceof EE_CPT_Base) {
1197
+			// if the item author is set and the user is the author...
1198
+			if ($obj->wp_user() && $user_id === $obj->wp_user()) {
1199
+				// if obj is published...
1200
+				if ($obj->status() === 'publish') {
1201
+					$caps[] = $this->published_cap;
1202
+				}
1203
+			} else {
1204
+				// the user is trying to edit someone else's obj
1205
+				if (! empty($this->others_cap)) {
1206
+					$caps[] = $this->others_cap;
1207
+				}
1208
+				if (! empty($this->published_cap) && $obj->status() === 'publish') {
1209
+					$caps[] = $this->published_cap;
1210
+				} elseif (! empty($this->private_cap) && $obj->status() === 'private') {
1211
+					$caps[] = $this->private_cap;
1212
+				}
1213
+			}
1214
+		} else {
1215
+			// not a cpt object so handled differently
1216
+			$has_cap = false;
1217
+			try {
1218
+				$has_cap = method_exists($obj, 'wp_user')
1219
+						   && $obj->wp_user()
1220
+						   && $obj->wp_user() === $user_id;
1221
+			} catch (Exception $e) {
1222
+				if (WP_DEBUG) {
1223
+					EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1224
+				}
1225
+			}
1226
+			if (! $has_cap) {
1227
+				if (! empty($this->others_cap)) {
1228
+					$caps[] = $this->others_cap;
1229
+				}
1230
+			}
1231
+		}
1232
+		return $caps;
1233
+	}
1234 1234
 }
1235 1235
 
1236 1236
 
@@ -1247,24 +1247,24 @@  discard block
 block discarded – undo
1247 1247
 class EE_Meta_Capability_Map_Delete extends EE_Meta_Capability_Map_Edit
1248 1248
 {
1249 1249
 
1250
-    /**
1251
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1252
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1253
-     *
1254
-     * @since 4.5.0
1255
-     * @see   wp-includes/capabilities.php
1256
-     *
1257
-     * @param array  $caps    actual users capabilities
1258
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1259
-     * @param int    $user_id The user id
1260
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1261
-     *
1262
-     * @return array   actual users capabilities
1263
-     */
1264
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1265
-    {
1266
-        return parent::_map_meta_caps($caps, $cap, $user_id, $args);
1267
-    }
1250
+	/**
1251
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1252
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1253
+	 *
1254
+	 * @since 4.5.0
1255
+	 * @see   wp-includes/capabilities.php
1256
+	 *
1257
+	 * @param array  $caps    actual users capabilities
1258
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1259
+	 * @param int    $user_id The user id
1260
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1261
+	 *
1262
+	 * @return array   actual users capabilities
1263
+	 */
1264
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1265
+	{
1266
+		return parent::_map_meta_caps($caps, $cap, $user_id, $args);
1267
+	}
1268 1268
 }
1269 1269
 
1270 1270
 
@@ -1280,85 +1280,85 @@  discard block
 block discarded – undo
1280 1280
 class EE_Meta_Capability_Map_Read extends EE_Meta_Capability_Map
1281 1281
 {
1282 1282
 
1283
-    /**
1284
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1285
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1286
-     *
1287
-     * @since 4.5.0
1288
-     * @see   wp-includes/capabilities.php
1289
-     *
1290
-     * @param array  $caps    actual users capabilities
1291
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1292
-     * @param int    $user_id The user id
1293
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1294
-     *
1295
-     * @return array   actual users capabilities
1296
-     */
1297
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1298
-    {
1299
-        // only process if we're checking our mapped cap;
1300
-        if ($cap !== $this->meta_cap) {
1301
-            return $caps;
1302
-        }
1303
-
1304
-        // okay it is a meta cap so let's first remove that cap from the $caps array.
1305
-        if (($key = array_search($cap, $caps)) !== false) {
1306
-            unset($caps[ $key ]);
1307
-        }
1308
-
1309
-        // cast $user_id to int for later explicit comparisons
1310
-        $user_id = (int) $user_id;
1311
-
1312
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1313
-        // if no obj then let's just do cap
1314
-        if (! $obj instanceof EE_Base_Class) {
1315
-            $caps[] = 'do_not_allow';
1316
-            return $caps;
1317
-        }
1318
-
1319
-        $caps[] = $cap . 's';
1320
-        if ($obj instanceof EE_CPT_Base) {
1321
-            $status_obj = get_post_status_object($obj->status());
1322
-            if ($status_obj->public) {
1323
-                return $caps;
1324
-            }
1325
-            // if the item author is set and the user is not the author...
1326
-            if ($obj->wp_user() && $obj->wp_user() !== $user_id) {
1327
-                if (! empty($this->others_cap)) {
1328
-                    $caps[] = $this->others_cap;
1329
-                }
1330
-            }
1331
-            // yes this means that if users created the private post, they are able to see it regardless of private cap.
1332
-            if ($status_obj->private
1333
-                && ! empty($this->private_cap)
1334
-                && $obj->wp_user() !== $user_id
1335
-            ) {
1336
-                // the user is trying to view a private object for an object they don't own.
1337
-                $caps[] = $this->private_cap;
1338
-            }
1339
-        } else {
1340
-            // not a cpt object so handled differently
1341
-            $has_cap = false;
1342
-            try {
1343
-                $has_cap = method_exists($obj, 'wp_user')
1344
-                           && $obj->wp_user()
1345
-                           && $obj->wp_user() === $user_id;
1346
-            } catch (Exception $e) {
1347
-                if (WP_DEBUG) {
1348
-                    EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1349
-                }
1350
-            }
1351
-            if (! $has_cap) {
1352
-                if (! empty($this->private_cap)) {
1353
-                    $caps[] = $this->private_cap;
1354
-                }
1355
-                if (! empty($this->others_cap)) {
1356
-                    $caps[] = $this->others_cap;
1357
-                }
1358
-            }
1359
-        }
1360
-        return $caps;
1361
-    }
1283
+	/**
1284
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1285
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1286
+	 *
1287
+	 * @since 4.5.0
1288
+	 * @see   wp-includes/capabilities.php
1289
+	 *
1290
+	 * @param array  $caps    actual users capabilities
1291
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1292
+	 * @param int    $user_id The user id
1293
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1294
+	 *
1295
+	 * @return array   actual users capabilities
1296
+	 */
1297
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1298
+	{
1299
+		// only process if we're checking our mapped cap;
1300
+		if ($cap !== $this->meta_cap) {
1301
+			return $caps;
1302
+		}
1303
+
1304
+		// okay it is a meta cap so let's first remove that cap from the $caps array.
1305
+		if (($key = array_search($cap, $caps)) !== false) {
1306
+			unset($caps[ $key ]);
1307
+		}
1308
+
1309
+		// cast $user_id to int for later explicit comparisons
1310
+		$user_id = (int) $user_id;
1311
+
1312
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1313
+		// if no obj then let's just do cap
1314
+		if (! $obj instanceof EE_Base_Class) {
1315
+			$caps[] = 'do_not_allow';
1316
+			return $caps;
1317
+		}
1318
+
1319
+		$caps[] = $cap . 's';
1320
+		if ($obj instanceof EE_CPT_Base) {
1321
+			$status_obj = get_post_status_object($obj->status());
1322
+			if ($status_obj->public) {
1323
+				return $caps;
1324
+			}
1325
+			// if the item author is set and the user is not the author...
1326
+			if ($obj->wp_user() && $obj->wp_user() !== $user_id) {
1327
+				if (! empty($this->others_cap)) {
1328
+					$caps[] = $this->others_cap;
1329
+				}
1330
+			}
1331
+			// yes this means that if users created the private post, they are able to see it regardless of private cap.
1332
+			if ($status_obj->private
1333
+				&& ! empty($this->private_cap)
1334
+				&& $obj->wp_user() !== $user_id
1335
+			) {
1336
+				// the user is trying to view a private object for an object they don't own.
1337
+				$caps[] = $this->private_cap;
1338
+			}
1339
+		} else {
1340
+			// not a cpt object so handled differently
1341
+			$has_cap = false;
1342
+			try {
1343
+				$has_cap = method_exists($obj, 'wp_user')
1344
+						   && $obj->wp_user()
1345
+						   && $obj->wp_user() === $user_id;
1346
+			} catch (Exception $e) {
1347
+				if (WP_DEBUG) {
1348
+					EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1349
+				}
1350
+			}
1351
+			if (! $has_cap) {
1352
+				if (! empty($this->private_cap)) {
1353
+					$caps[] = $this->private_cap;
1354
+				}
1355
+				if (! empty($this->others_cap)) {
1356
+					$caps[] = $this->others_cap;
1357
+				}
1358
+			}
1359
+		}
1360
+		return $caps;
1361
+	}
1362 1362
 }
1363 1363
 
1364 1364
 
@@ -1375,56 +1375,56 @@  discard block
 block discarded – undo
1375 1375
 class EE_Meta_Capability_Map_Messages_Cap extends EE_Meta_Capability_Map
1376 1376
 {
1377 1377
 
1378
-    /**
1379
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1380
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1381
-     *
1382
-     * @since 4.5.0
1383
-     * @see   wp-includes/capabilities.php
1384
-     *
1385
-     * @param array  $caps    actual users capabilities
1386
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1387
-     * @param int    $user_id The user id
1388
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1389
-     *
1390
-     * @return array   actual users capabilities
1391
-     */
1392
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1393
-    {
1394
-        // only process if we're checking our mapped_cap
1395
-        if ($cap !== $this->meta_cap) {
1396
-            return $caps;
1397
-        }
1398
-
1399
-        // okay it is a meta cap so let's first remove that cap from the $caps array.
1400
-        if (($key = array_search($cap, $caps)) !== false) {
1401
-            unset($caps[ $key ]);
1402
-        }
1403
-
1404
-        // cast $user_id to int for later explicit comparisons
1405
-        $user_id = (int) $user_id;
1406
-
1407
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1408
-        // if no obj then let's just do cap
1409
-        if (! $obj instanceof EE_Message_Template_Group) {
1410
-            $caps[] = 'do_not_allow';
1411
-            return $caps;
1412
-        }
1413
-        $caps[] = $cap . 's';
1414
-        $is_global = $obj->is_global();
1415
-        if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1416
-            if ($is_global) {
1417
-                $caps[] = $this->private_cap;
1418
-            }
1419
-        } else {
1420
-            if ($is_global) {
1421
-                $caps[] = $this->private_cap;
1422
-            } else {
1423
-                $caps[] = $this->others_cap;
1424
-            }
1425
-        }
1426
-        return $caps;
1427
-    }
1378
+	/**
1379
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1380
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1381
+	 *
1382
+	 * @since 4.5.0
1383
+	 * @see   wp-includes/capabilities.php
1384
+	 *
1385
+	 * @param array  $caps    actual users capabilities
1386
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1387
+	 * @param int    $user_id The user id
1388
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1389
+	 *
1390
+	 * @return array   actual users capabilities
1391
+	 */
1392
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1393
+	{
1394
+		// only process if we're checking our mapped_cap
1395
+		if ($cap !== $this->meta_cap) {
1396
+			return $caps;
1397
+		}
1398
+
1399
+		// okay it is a meta cap so let's first remove that cap from the $caps array.
1400
+		if (($key = array_search($cap, $caps)) !== false) {
1401
+			unset($caps[ $key ]);
1402
+		}
1403
+
1404
+		// cast $user_id to int for later explicit comparisons
1405
+		$user_id = (int) $user_id;
1406
+
1407
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1408
+		// if no obj then let's just do cap
1409
+		if (! $obj instanceof EE_Message_Template_Group) {
1410
+			$caps[] = 'do_not_allow';
1411
+			return $caps;
1412
+		}
1413
+		$caps[] = $cap . 's';
1414
+		$is_global = $obj->is_global();
1415
+		if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1416
+			if ($is_global) {
1417
+				$caps[] = $this->private_cap;
1418
+			}
1419
+		} else {
1420
+			if ($is_global) {
1421
+				$caps[] = $this->private_cap;
1422
+			} else {
1423
+				$caps[] = $this->others_cap;
1424
+			}
1425
+		}
1426
+		return $caps;
1427
+	}
1428 1428
 }
1429 1429
 
1430 1430
 
@@ -1441,40 +1441,40 @@  discard block
 block discarded – undo
1441 1441
 class EE_Meta_Capability_Map_Registration_Form_Cap extends EE_Meta_Capability_Map
1442 1442
 {
1443 1443
 
1444
-    /**
1445
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1446
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1447
-     *
1448
-     * @since 4.5.0
1449
-     * @see   wp-includes/capabilities.php
1450
-     * @param array  $caps    actual users capabilities
1451
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1452
-     * @param int    $user_id The user id
1453
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1454
-     * @return array   actual users capabilities
1455
-     */
1456
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1457
-    {
1458
-        // only process if we're checking our mapped_cap
1459
-        if ($cap !== $this->meta_cap) {
1460
-            return $caps;
1461
-        }
1462
-        // okay it is a meta cap so let's first remove that cap from the $caps array.
1463
-        if (($key = array_search($cap, $caps)) !== false) {
1464
-            unset($caps[ $key ]);
1465
-        }
1466
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1467
-        // if no obj then let's just do cap
1468
-        if (! $obj instanceof EE_Base_Class) {
1469
-            $caps[] = 'do_not_allow';
1470
-            return $caps;
1471
-        }
1472
-        $caps[] = $cap . 's';
1473
-        $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false;
1474
-        $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system;
1475
-        if ($is_system) {
1476
-            $caps[] = $this->private_cap;
1477
-        }
1478
-        return $caps;
1479
-    }
1444
+	/**
1445
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1446
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1447
+	 *
1448
+	 * @since 4.5.0
1449
+	 * @see   wp-includes/capabilities.php
1450
+	 * @param array  $caps    actual users capabilities
1451
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1452
+	 * @param int    $user_id The user id
1453
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1454
+	 * @return array   actual users capabilities
1455
+	 */
1456
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1457
+	{
1458
+		// only process if we're checking our mapped_cap
1459
+		if ($cap !== $this->meta_cap) {
1460
+			return $caps;
1461
+		}
1462
+		// okay it is a meta cap so let's first remove that cap from the $caps array.
1463
+		if (($key = array_search($cap, $caps)) !== false) {
1464
+			unset($caps[ $key ]);
1465
+		}
1466
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1467
+		// if no obj then let's just do cap
1468
+		if (! $obj instanceof EE_Base_Class) {
1469
+			$caps[] = 'do_not_allow';
1470
+			return $caps;
1471
+		}
1472
+		$caps[] = $cap . 's';
1473
+		$is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false;
1474
+		$is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system;
1475
+		if ($is_system) {
1476
+			$caps[] = $this->private_cap;
1477
+		}
1478
+		return $caps;
1479
+	}
1480 1480
 }
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.
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/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   +751 added lines, -751 removed lines patch added patch discarded remove patch
@@ -13,755 +13,755 @@
 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(
443
-            array(
444
-                'Event.EVT_ID' => $EVT_ID
445
-            ),
446
-            'order_by' => array(
447
-                'DTT_EVT_start' => 'asc'
448
-            ),
449
-            'default_where_conditions' => EEM_Base::default_where_conditions_this_only
450
-        );
451
-        if (! $include_expired) {
452
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
453
-        }
454
-        if ($include_deleted) {
455
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
456
-        }
457
-        if ($limit) {
458
-            $query_params['limit'] = $limit;
459
-        }
460
-        /** @var EE_Datetime[] $result */
461
-        $result = $this->get_all($query_params);
462
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
463
-        return $result;
464
-    }
465
-
466
-
467
-    /**
468
-     * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
469
-     * only by start date
470
-     *
471
-     * @param int     $TKT_ID
472
-     * @param boolean $include_expired
473
-     * @param boolean $include_deleted
474
-     * @param int     $limit
475
-     * @return EE_Datetime[]
476
-     * @throws EE_Error
477
-     */
478
-    public function get_datetimes_for_ticket_ordered_by_start_time(
479
-        $TKT_ID,
480
-        $include_expired = true,
481
-        $include_deleted = true,
482
-        $limit = null
483
-    ) {
484
-        // sanitize TKT_ID
485
-        $TKT_ID         = absint($TKT_ID);
486
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
487
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
488
-        $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
489
-        if (! $include_expired) {
490
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
491
-        }
492
-        if ($include_deleted) {
493
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
494
-        }
495
-        if ($limit) {
496
-            $query_params['limit'] = $limit;
497
-        }
498
-        /** @var EE_Datetime[] $result */
499
-        $result = $this->get_all($query_params);
500
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
501
-        return $result;
502
-    }
503
-
504
-
505
-    /**
506
-     * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
507
-     * datetimes.
508
-     *
509
-     * @param  int      $TKT_ID          ID of ticket to retrieve the datetimes for
510
-     * @param  boolean  $include_expired whether to include expired datetimes or not
511
-     * @param  boolean  $include_deleted whether to include trashed datetimes or not.
512
-     * @param  int|null $limit           if null, no limit, if int then limit results by
513
-     *                                   that number
514
-     * @return EE_Datetime[]
515
-     * @throws EE_Error
516
-     */
517
-    public function get_datetimes_for_ticket_ordered_by_DTT_order(
518
-        $TKT_ID,
519
-        $include_expired = true,
520
-        $include_deleted = true,
521
-        $limit = null
522
-    ) {
523
-        // sanitize id.
524
-        $TKT_ID         = absint($TKT_ID);
525
-        $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
526
-        $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
527
-        $where_params = array('Ticket.TKT_ID' => $TKT_ID);
528
-        $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
529
-        if (! $include_expired) {
530
-            $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
531
-        }
532
-        if ($include_deleted) {
533
-            $query_params[0]['DTT_deleted'] = array('IN', array(true, false));
534
-        }
535
-        if ($limit) {
536
-            $query_params['limit'] = $limit;
537
-        }
538
-        /** @var EE_Datetime[] $result */
539
-        $result = $this->get_all($query_params);
540
-        $this->assume_values_already_prepared_by_model_object($old_assumption);
541
-        return $result;
542
-    }
543
-
544
-
545
-    /**
546
-     * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
547
-     * reason it doesn't exist, we consider the earliest event the most important)
548
-     *
549
-     * @param int $EVT_ID
550
-     * @return EE_Datetime
551
-     * @throws EE_Error
552
-     */
553
-    public function get_most_important_datetime_for_event($EVT_ID)
554
-    {
555
-        $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
556
-        if ($results) {
557
-            return array_shift($results);
558
-        }
559
-        return null;
560
-    }
561
-
562
-
563
-    /**
564
-     * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
565
-     * grouped by month and year.
566
-     *
567
-     * @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
568
-     * @param  string $evt_active_status A string representing the evt active status to filter the months by.
569
-     *                                   Can be:
570
-     *                                   - '' = no filter
571
-     *                                   - upcoming = Published events with at least one upcoming datetime.
572
-     *                                   - expired = Events with all datetimes expired.
573
-     *                                   - active = Events that are published and have at least one datetime that
574
-     *                                   starts before now and ends after now.
575
-     *                                   - inactive = Events that are either not published.
576
-     * @return EE_Base_Class[]
577
-     * @throws EE_Error
578
-     * @throws InvalidArgumentException
579
-     * @throws InvalidArgumentException
580
-     */
581
-    public function get_dtt_months_and_years($where_params, $evt_active_status = '')
582
-    {
583
-        $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
584
-        $current_time_for_DTT_EVT_end   = $this->current_time_for_query('DTT_EVT_end');
585
-        switch ($evt_active_status) {
586
-            case 'upcoming':
587
-                $where_params['Event.status'] = 'publish';
588
-                // if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
589
-                if (isset($where_params['DTT_EVT_start'])) {
590
-                    $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
591
-                }
592
-                $where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start);
593
-                break;
594
-            case 'expired':
595
-                if (isset($where_params['Event.status'])) {
596
-                    unset($where_params['Event.status']);
597
-                }
598
-                // get events to exclude
599
-                $exclude_query[0] = array_merge(
600
-                    $where_params,
601
-                    array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end))
602
-                );
603
-                // first get all events that have datetimes where its not expired.
604
-                $event_ids = $this->_get_all_wpdb_results(
605
-                    $exclude_query,
606
-                    OBJECT_K,
607
-                    'Datetime.EVT_ID'
608
-                );
609
-                $event_ids = array_keys($event_ids);
610
-                if (isset($where_params['DTT_EVT_end'])) {
611
-                    $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
612
-                }
613
-                $where_params['DTT_EVT_end']  = array('<', $current_time_for_DTT_EVT_end);
614
-                $where_params['Event.EVT_ID'] = array('NOT IN', $event_ids);
615
-                break;
616
-            case 'active':
617
-                $where_params['Event.status'] = 'publish';
618
-                if (isset($where_params['DTT_EVT_start'])) {
619
-                    $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
620
-                }
621
-                if (isset($where_params['Datetime.DTT_EVT_end'])) {
622
-                    $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
623
-                }
624
-                $where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start);
625
-                $where_params['DTT_EVT_end']   = array('>', $current_time_for_DTT_EVT_end);
626
-                break;
627
-            case 'inactive':
628
-                if (isset($where_params['Event.status'])) {
629
-                    unset($where_params['Event.status']);
630
-                }
631
-                if (isset($where_params['OR'])) {
632
-                    $where_params['AND']['OR'] = $where_params['OR'];
633
-                }
634
-                if (isset($where_params['DTT_EVT_end'])) {
635
-                    $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
636
-                    unset($where_params['DTT_EVT_end']);
637
-                }
638
-                if (isset($where_params['DTT_EVT_start'])) {
639
-                    $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
640
-                    unset($where_params['DTT_EVT_start']);
641
-                }
642
-                $where_params['AND']['Event.status'] = array('!=', 'publish');
643
-                break;
644
-        }
645
-        $query_params[0]          = $where_params;
646
-        $query_params['group_by'] = array('dtt_year', 'dtt_month');
647
-        $query_params['order_by'] = array('DTT_EVT_start' => 'DESC');
648
-        $query_interval           = EEH_DTT_Helper::get_sql_query_interval_for_offset(
649
-            $this->get_timezone(),
650
-            'DTT_EVT_start'
651
-        );
652
-        $columns_to_select        = array(
653
-            'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
654
-            'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
655
-            'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
656
-        );
657
-        return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
658
-    }
659
-
660
-
661
-    /**
662
-     * Updates the DTT_sold attribute on each datetime (based on the registrations
663
-     * for the tickets for each datetime)
664
-     *
665
-     * @param EE_Base_Class[]|EE_Datetime[] $datetimes
666
-     * @throws EE_Error
667
-     */
668
-    public function update_sold($datetimes)
669
-    {
670
-        EE_Error::doing_it_wrong(
671
-            __FUNCTION__,
672
-            esc_html__(
673
-                'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.',
674
-                'event_espresso'
675
-            ),
676
-            '4.9.32.rc.005'
677
-        );
678
-        foreach ($datetimes as $datetime) {
679
-            $datetime->update_sold();
680
-        }
681
-    }
682
-
683
-
684
-    /**
685
-     *    Gets the total number of tickets available at a particular datetime
686
-     *    (does NOT take into account the datetime's spaces available)
687
-     *
688
-     * @param int   $DTT_ID
689
-     * @param array $query_params
690
-     * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
691
-     *             tickets attached to datetime then FALSE is returned.
692
-     */
693
-    public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array())
694
-    {
695
-        $datetime = $this->get_one_by_ID($DTT_ID);
696
-        if ($datetime instanceof EE_Datetime) {
697
-            return $datetime->tickets_remaining($query_params);
698
-        }
699
-        return 0;
700
-    }
701
-
702
-
703
-    /**
704
-     * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
705
-     *
706
-     * @param  array $stati_to_include If included you can restrict the statuses we return counts for by including the
707
-     *                                 stati you want counts for as values in the array.  An empty array returns counts
708
-     *                                 for all valid stati.
709
-     * @param  array $query_params     If included can be used to refine the conditions for returning the count (i.e.
710
-     *                                 only for Datetimes connected to a specific event, or specific ticket.
711
-     * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
712
-     * @throws EE_Error
713
-     *                                 stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming
714
-     *                                 EE_Datetime::expired
715
-     */
716
-    public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array())
717
-    {
718
-        // only accept where conditions for this query.
719
-        $_where            = isset($query_params[0]) ? $query_params[0] : array();
720
-        $status_query_args = array(
721
-            EE_Datetime::active   => array_merge(
722
-                $_where,
723
-                array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time()))
724
-            ),
725
-            EE_Datetime::upcoming => array_merge(
726
-                $_where,
727
-                array('DTT_EVT_start' => array('>', time()))
728
-            ),
729
-            EE_Datetime::expired  => array_merge(
730
-                $_where,
731
-                array('DTT_EVT_end' => array('<', time()))
732
-            ),
733
-        );
734
-        if (! empty($stati_to_include)) {
735
-            foreach (array_keys($status_query_args) as $status) {
736
-                if (! in_array($status, $stati_to_include, true)) {
737
-                    unset($status_query_args[ $status ]);
738
-                }
739
-            }
740
-        }
741
-        // loop through and query counts for each stati.
742
-        $status_query_results = array();
743
-        foreach ($status_query_args as $status => $status_where_conditions) {
744
-            $status_query_results[ $status ] = EEM_Datetime::count(
745
-                array($status_where_conditions),
746
-                'DTT_ID',
747
-                true
748
-            );
749
-        }
750
-        return $status_query_results;
751
-    }
752
-
753
-
754
-    /**
755
-     * Returns the specific count for a given Datetime status matching any given query_params.
756
-     *
757
-     * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
758
-     * @param array  $query_params
759
-     * @return int
760
-     * @throws EE_Error
761
-     */
762
-    public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array())
763
-    {
764
-        $count = $this->get_datetime_counts_by_status(array($status), $query_params);
765
-        return ! empty($count[ $status ]) ? $count[ $status ] : 0;
766
-    }
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(
443
+			array(
444
+				'Event.EVT_ID' => $EVT_ID
445
+			),
446
+			'order_by' => array(
447
+				'DTT_EVT_start' => 'asc'
448
+			),
449
+			'default_where_conditions' => EEM_Base::default_where_conditions_this_only
450
+		);
451
+		if (! $include_expired) {
452
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
453
+		}
454
+		if ($include_deleted) {
455
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
456
+		}
457
+		if ($limit) {
458
+			$query_params['limit'] = $limit;
459
+		}
460
+		/** @var EE_Datetime[] $result */
461
+		$result = $this->get_all($query_params);
462
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
463
+		return $result;
464
+	}
465
+
466
+
467
+	/**
468
+	 * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered
469
+	 * only by start date
470
+	 *
471
+	 * @param int     $TKT_ID
472
+	 * @param boolean $include_expired
473
+	 * @param boolean $include_deleted
474
+	 * @param int     $limit
475
+	 * @return EE_Datetime[]
476
+	 * @throws EE_Error
477
+	 */
478
+	public function get_datetimes_for_ticket_ordered_by_start_time(
479
+		$TKT_ID,
480
+		$include_expired = true,
481
+		$include_deleted = true,
482
+		$limit = null
483
+	) {
484
+		// sanitize TKT_ID
485
+		$TKT_ID         = absint($TKT_ID);
486
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
487
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
488
+		$query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
489
+		if (! $include_expired) {
490
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
491
+		}
492
+		if ($include_deleted) {
493
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
494
+		}
495
+		if ($limit) {
496
+			$query_params['limit'] = $limit;
497
+		}
498
+		/** @var EE_Datetime[] $result */
499
+		$result = $this->get_all($query_params);
500
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
501
+		return $result;
502
+	}
503
+
504
+
505
+	/**
506
+	 * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the
507
+	 * datetimes.
508
+	 *
509
+	 * @param  int      $TKT_ID          ID of ticket to retrieve the datetimes for
510
+	 * @param  boolean  $include_expired whether to include expired datetimes or not
511
+	 * @param  boolean  $include_deleted whether to include trashed datetimes or not.
512
+	 * @param  int|null $limit           if null, no limit, if int then limit results by
513
+	 *                                   that number
514
+	 * @return EE_Datetime[]
515
+	 * @throws EE_Error
516
+	 */
517
+	public function get_datetimes_for_ticket_ordered_by_DTT_order(
518
+		$TKT_ID,
519
+		$include_expired = true,
520
+		$include_deleted = true,
521
+		$limit = null
522
+	) {
523
+		// sanitize id.
524
+		$TKT_ID         = absint($TKT_ID);
525
+		$old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
526
+		$this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
527
+		$where_params = array('Ticket.TKT_ID' => $TKT_ID);
528
+		$query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
529
+		if (! $include_expired) {
530
+			$query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
531
+		}
532
+		if ($include_deleted) {
533
+			$query_params[0]['DTT_deleted'] = array('IN', array(true, false));
534
+		}
535
+		if ($limit) {
536
+			$query_params['limit'] = $limit;
537
+		}
538
+		/** @var EE_Datetime[] $result */
539
+		$result = $this->get_all($query_params);
540
+		$this->assume_values_already_prepared_by_model_object($old_assumption);
541
+		return $result;
542
+	}
543
+
544
+
545
+	/**
546
+	 * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK
547
+	 * reason it doesn't exist, we consider the earliest event the most important)
548
+	 *
549
+	 * @param int $EVT_ID
550
+	 * @return EE_Datetime
551
+	 * @throws EE_Error
552
+	 */
553
+	public function get_most_important_datetime_for_event($EVT_ID)
554
+	{
555
+		$results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1);
556
+		if ($results) {
557
+			return array_shift($results);
558
+		}
559
+		return null;
560
+	}
561
+
562
+
563
+	/**
564
+	 * This returns a wpdb->results        Array of all DTT month and years matching the incoming query params and
565
+	 * grouped by month and year.
566
+	 *
567
+	 * @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
568
+	 * @param  string $evt_active_status A string representing the evt active status to filter the months by.
569
+	 *                                   Can be:
570
+	 *                                   - '' = no filter
571
+	 *                                   - upcoming = Published events with at least one upcoming datetime.
572
+	 *                                   - expired = Events with all datetimes expired.
573
+	 *                                   - active = Events that are published and have at least one datetime that
574
+	 *                                   starts before now and ends after now.
575
+	 *                                   - inactive = Events that are either not published.
576
+	 * @return EE_Base_Class[]
577
+	 * @throws EE_Error
578
+	 * @throws InvalidArgumentException
579
+	 * @throws InvalidArgumentException
580
+	 */
581
+	public function get_dtt_months_and_years($where_params, $evt_active_status = '')
582
+	{
583
+		$current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start');
584
+		$current_time_for_DTT_EVT_end   = $this->current_time_for_query('DTT_EVT_end');
585
+		switch ($evt_active_status) {
586
+			case 'upcoming':
587
+				$where_params['Event.status'] = 'publish';
588
+				// if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
589
+				if (isset($where_params['DTT_EVT_start'])) {
590
+					$where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start'];
591
+				}
592
+				$where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start);
593
+				break;
594
+			case 'expired':
595
+				if (isset($where_params['Event.status'])) {
596
+					unset($where_params['Event.status']);
597
+				}
598
+				// get events to exclude
599
+				$exclude_query[0] = array_merge(
600
+					$where_params,
601
+					array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end))
602
+				);
603
+				// first get all events that have datetimes where its not expired.
604
+				$event_ids = $this->_get_all_wpdb_results(
605
+					$exclude_query,
606
+					OBJECT_K,
607
+					'Datetime.EVT_ID'
608
+				);
609
+				$event_ids = array_keys($event_ids);
610
+				if (isset($where_params['DTT_EVT_end'])) {
611
+					$where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
612
+				}
613
+				$where_params['DTT_EVT_end']  = array('<', $current_time_for_DTT_EVT_end);
614
+				$where_params['Event.EVT_ID'] = array('NOT IN', $event_ids);
615
+				break;
616
+			case 'active':
617
+				$where_params['Event.status'] = 'publish';
618
+				if (isset($where_params['DTT_EVT_start'])) {
619
+					$where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start'];
620
+				}
621
+				if (isset($where_params['Datetime.DTT_EVT_end'])) {
622
+					$where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end'];
623
+				}
624
+				$where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start);
625
+				$where_params['DTT_EVT_end']   = array('>', $current_time_for_DTT_EVT_end);
626
+				break;
627
+			case 'inactive':
628
+				if (isset($where_params['Event.status'])) {
629
+					unset($where_params['Event.status']);
630
+				}
631
+				if (isset($where_params['OR'])) {
632
+					$where_params['AND']['OR'] = $where_params['OR'];
633
+				}
634
+				if (isset($where_params['DTT_EVT_end'])) {
635
+					$where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end'];
636
+					unset($where_params['DTT_EVT_end']);
637
+				}
638
+				if (isset($where_params['DTT_EVT_start'])) {
639
+					$where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start'];
640
+					unset($where_params['DTT_EVT_start']);
641
+				}
642
+				$where_params['AND']['Event.status'] = array('!=', 'publish');
643
+				break;
644
+		}
645
+		$query_params[0]          = $where_params;
646
+		$query_params['group_by'] = array('dtt_year', 'dtt_month');
647
+		$query_params['order_by'] = array('DTT_EVT_start' => 'DESC');
648
+		$query_interval           = EEH_DTT_Helper::get_sql_query_interval_for_offset(
649
+			$this->get_timezone(),
650
+			'DTT_EVT_start'
651
+		);
652
+		$columns_to_select        = array(
653
+			'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
654
+			'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
655
+			'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
656
+		);
657
+		return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
658
+	}
659
+
660
+
661
+	/**
662
+	 * Updates the DTT_sold attribute on each datetime (based on the registrations
663
+	 * for the tickets for each datetime)
664
+	 *
665
+	 * @param EE_Base_Class[]|EE_Datetime[] $datetimes
666
+	 * @throws EE_Error
667
+	 */
668
+	public function update_sold($datetimes)
669
+	{
670
+		EE_Error::doing_it_wrong(
671
+			__FUNCTION__,
672
+			esc_html__(
673
+				'Please use \EEM_Ticket::update_tickets_sold() instead which will in turn correctly update both the Ticket AND Datetime counts.',
674
+				'event_espresso'
675
+			),
676
+			'4.9.32.rc.005'
677
+		);
678
+		foreach ($datetimes as $datetime) {
679
+			$datetime->update_sold();
680
+		}
681
+	}
682
+
683
+
684
+	/**
685
+	 *    Gets the total number of tickets available at a particular datetime
686
+	 *    (does NOT take into account the datetime's spaces available)
687
+	 *
688
+	 * @param int   $DTT_ID
689
+	 * @param array $query_params
690
+	 * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF,  IF there are NO
691
+	 *             tickets attached to datetime then FALSE is returned.
692
+	 */
693
+	public function sum_tickets_currently_available_at_datetime($DTT_ID, array $query_params = array())
694
+	{
695
+		$datetime = $this->get_one_by_ID($DTT_ID);
696
+		if ($datetime instanceof EE_Datetime) {
697
+			return $datetime->tickets_remaining($query_params);
698
+		}
699
+		return 0;
700
+	}
701
+
702
+
703
+	/**
704
+	 * This returns an array of counts of datetimes in the database for each Datetime status that can be queried.
705
+	 *
706
+	 * @param  array $stati_to_include If included you can restrict the statuses we return counts for by including the
707
+	 *                                 stati you want counts for as values in the array.  An empty array returns counts
708
+	 *                                 for all valid stati.
709
+	 * @param  array $query_params     If included can be used to refine the conditions for returning the count (i.e.
710
+	 *                                 only for Datetimes connected to a specific event, or specific ticket.
711
+	 * @return array  The value returned is an array indexed by Datetime Status and the values are the counts.  The
712
+	 * @throws EE_Error
713
+	 *                                 stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming
714
+	 *                                 EE_Datetime::expired
715
+	 */
716
+	public function get_datetime_counts_by_status(array $stati_to_include = array(), array $query_params = array())
717
+	{
718
+		// only accept where conditions for this query.
719
+		$_where            = isset($query_params[0]) ? $query_params[0] : array();
720
+		$status_query_args = array(
721
+			EE_Datetime::active   => array_merge(
722
+				$_where,
723
+				array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time()))
724
+			),
725
+			EE_Datetime::upcoming => array_merge(
726
+				$_where,
727
+				array('DTT_EVT_start' => array('>', time()))
728
+			),
729
+			EE_Datetime::expired  => array_merge(
730
+				$_where,
731
+				array('DTT_EVT_end' => array('<', time()))
732
+			),
733
+		);
734
+		if (! empty($stati_to_include)) {
735
+			foreach (array_keys($status_query_args) as $status) {
736
+				if (! in_array($status, $stati_to_include, true)) {
737
+					unset($status_query_args[ $status ]);
738
+				}
739
+			}
740
+		}
741
+		// loop through and query counts for each stati.
742
+		$status_query_results = array();
743
+		foreach ($status_query_args as $status => $status_where_conditions) {
744
+			$status_query_results[ $status ] = EEM_Datetime::count(
745
+				array($status_where_conditions),
746
+				'DTT_ID',
747
+				true
748
+			);
749
+		}
750
+		return $status_query_results;
751
+	}
752
+
753
+
754
+	/**
755
+	 * Returns the specific count for a given Datetime status matching any given query_params.
756
+	 *
757
+	 * @param string $status Valid string representation for Datetime status requested. (Defaults to Active).
758
+	 * @param array  $query_params
759
+	 * @return int
760
+	 * @throws EE_Error
761
+	 */
762
+	public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array())
763
+	{
764
+		$count = $this->get_datetime_counts_by_status(array($status), $query_params);
765
+		return ! empty($count[ $status ]) ? $count[ $status ] : 0;
766
+	}
767 767
 }
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) {
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
             ),
449 449
             'default_where_conditions' => EEM_Base::default_where_conditions_this_only
450 450
         );
451
-        if (! $include_expired) {
451
+        if ( ! $include_expired) {
452 452
             $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
453 453
         }
454 454
         if ($include_deleted) {
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
         $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object();
487 487
         $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
488 488
         $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc'));
489
-        if (! $include_expired) {
489
+        if ( ! $include_expired) {
490 490
             $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
491 491
         }
492 492
         if ($include_deleted) {
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
         $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db);
527 527
         $where_params = array('Ticket.TKT_ID' => $TKT_ID);
528 528
         $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC'));
529
-        if (! $include_expired) {
529
+        if ( ! $include_expired) {
530 530
             $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true));
531 531
         }
532 532
         if ($include_deleted) {
@@ -649,10 +649,10 @@  discard block
 block discarded – undo
649 649
             $this->get_timezone(),
650 650
             'DTT_EVT_start'
651 651
         );
652
-        $columns_to_select        = array(
653
-            'dtt_year'      => array('YEAR(' . $query_interval . ')', '%s'),
654
-            'dtt_month'     => array('MONTHNAME(' . $query_interval . ')', '%s'),
655
-            'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'),
652
+        $columns_to_select = array(
653
+            'dtt_year'      => array('YEAR('.$query_interval.')', '%s'),
654
+            'dtt_month'     => array('MONTHNAME('.$query_interval.')', '%s'),
655
+            'dtt_month_num' => array('MONTH('.$query_interval.')', '%s'),
656 656
         );
657 657
         return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select);
658 658
     }
@@ -731,17 +731,17 @@  discard block
 block discarded – undo
731 731
                 array('DTT_EVT_end' => array('<', time()))
732 732
             ),
733 733
         );
734
-        if (! empty($stati_to_include)) {
734
+        if ( ! empty($stati_to_include)) {
735 735
             foreach (array_keys($status_query_args) as $status) {
736
-                if (! in_array($status, $stati_to_include, true)) {
737
-                    unset($status_query_args[ $status ]);
736
+                if ( ! in_array($status, $stati_to_include, true)) {
737
+                    unset($status_query_args[$status]);
738 738
                 }
739 739
             }
740 740
         }
741 741
         // loop through and query counts for each stati.
742 742
         $status_query_results = array();
743 743
         foreach ($status_query_args as $status => $status_where_conditions) {
744
-            $status_query_results[ $status ] = EEM_Datetime::count(
744
+            $status_query_results[$status] = EEM_Datetime::count(
745 745
                 array($status_where_conditions),
746 746
                 'DTT_ID',
747 747
                 true
@@ -762,6 +762,6 @@  discard block
 block discarded – undo
762 762
     public function get_datetime_count_for_status($status = EE_Datetime::active, array $query_params = array())
763 763
     {
764 764
         $count = $this->get_datetime_counts_by_status(array($status), $query_params);
765
-        return ! empty($count[ $status ]) ? $count[ $status ] : 0;
765
+        return ! empty($count[$status]) ? $count[$status] : 0;
766 766
     }
767 767
 }
Please login to merge, or discard this patch.
public/Espresso_Arabica_2014/content-espresso_events-datetimes.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,15 +1,15 @@
 block discarded – undo
1 1
 <?php
2 2
 //echo '<br/><h6 style="color:#2EA2CC;">'. __FILE__ . ' &nbsp; <span style="font-weight:normal;color:#E76700"> Line #: ' . __LINE__ . '</span></h6>';
3 3
 
4
-if ( is_single() || ( is_archive() && espresso_display_datetimes_in_event_list() ) ) :
4
+if (is_single() || (is_archive() && espresso_display_datetimes_in_event_list())) :
5 5
 global $post;
6
-do_action( 'AHEE_event_details_before_event_date', $post );
6
+do_action('AHEE_event_details_before_event_date', $post);
7 7
 ?>
8 8
 	<div class="event-datetimes">
9
-		<?php espresso_list_of_event_dates( $post->ID );?>
9
+		<?php espresso_list_of_event_dates($post->ID); ?>
10 10
 	</div>
11 11
 	<!-- .event-datetimes -->
12 12
 <?php
13
-do_action( 'AHEE_event_details_after_event_date', $post );
13
+do_action('AHEE_event_details_after_event_date', $post);
14 14
 endif;
15 15
 ?>
16 16
\ No newline at end of file
Please login to merge, or discard this patch.