Completed
Branch GDPR/consent (53a229)
by
unknown
75:36 queued 61:02
created
admin_pages/transactions/EE_Admin_Transactions_List_Table.class.php 2 patches
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
     {
97 97
         $class = parent::_get_row_class($transaction);
98 98
         // add status class
99
-        $class .= ' ee-status-strip txn-status-' . $transaction->status_ID();
99
+        $class .= ' ee-status-strip txn-status-'.$transaction->status_ID();
100 100
         if ($this->_has_checkbox_column) {
101 101
             $class .= ' has-checkbox-column';
102 102
         }
@@ -170,13 +170,13 @@  discard block
 block discarded – undo
170 170
             ),
171 171
             TXN_ADMIN_URL
172 172
         );
173
-        $content = '<a href="' . $view_lnk_url . '"'
174
-                   . ' title="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">'
173
+        $content = '<a href="'.$view_lnk_url.'"'
174
+                   . ' title="'.esc_attr__('Go to Transaction Details', 'event_espresso').'">'
175 175
                    . $transaction->ID()
176 176
                    . '</a>';
177 177
 
178 178
         // txn timestamp
179
-        $content .= '  <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>';
179
+        $content .= '  <span class="show-on-mobile-view-only">'.$this->_get_txn_timestamp($transaction).'</span>';
180 180
         return $content;
181 181
     }
182 182
 
@@ -236,9 +236,9 @@  discard block
 block discarded – undo
236 236
             ),
237 237
             TXN_ADMIN_URL
238 238
         );
239
-        $txn_date = '<a href="' . $view_lnk_url . '"'
239
+        $txn_date = '<a href="'.$view_lnk_url.'"'
240 240
                     . ' title="'
241
-                    . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID() . '">'
241
+                    . esc_attr__('View Transaction Details for TXN #', 'event_espresso').$transaction->ID().'">'
242 242
                     . $this->_get_txn_timestamp($transaction)
243 243
                     . '</a>';
244 244
         // status
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
                    )
272 272
                    . '</span>';
273 273
         } else {
274
-            return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
274
+            return '<span class="txn-overview-free-event-spn">'.esc_html__('free', 'event_espresso').'</span>';
275 275
         }
276 276
     }
277 277
 
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
             ? $payment_method->admin_name()
309 309
             : esc_html__('Unknown', 'event_espresso');
310 310
 
311
-        $content = '<span class="' . $span_class . ' txn-pad-rght">'
311
+        $content = '<span class="'.$span_class.' txn-pad-rght">'
312 312
                    . $transaction->get_pretty('TXN_paid')
313 313
                    . '</span>';
314 314
         if ($transaction_paid > 0) {
@@ -350,12 +350,12 @@  discard block
 block discarded – undo
350 350
                 'espresso_registrations_view_registration',
351 351
                 $primary_reg->ID()
352 352
             )
353
-                ? '<a href="' . $edit_lnk_url . '"'
354
-                  . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
353
+                ? '<a href="'.$edit_lnk_url.'"'
354
+                  . ' title="'.esc_attr__('View Registration Details', 'event_espresso').'">'
355 355
                   . $attendee->full_name()
356 356
                   . '</a>'
357 357
                 : $attendee->full_name();
358
-            $content .= '<br>' . $attendee->email();
358
+            $content .= '<br>'.$attendee->email();
359 359
             return $content;
360 360
         }
361 361
         return $transaction->failed() || $transaction->is_abandoned()
@@ -377,8 +377,8 @@  discard block
 block discarded – undo
377 377
     public function column_ATT_email(EE_Transaction $transaction)
378 378
     {
379 379
         $attendee = $transaction->primary_registration()->get_first_related('Attendee');
380
-        if (! empty($attendee)) {
381
-            return '<a href="mailto:' . $attendee->get('ATT_email') . '">'
380
+        if ( ! empty($attendee)) {
381
+            return '<a href="mailto:'.$attendee->get('ATT_email').'">'
382 382
                    . $attendee->get('ATT_email')
383 383
                    . '</a>';
384 384
         } else {
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
     {
407 407
         $actions = array();
408 408
         $event = $transaction->primary_registration()->get_first_related('Event');
409
-        if (! empty($event)) {
409
+        if ( ! empty($event)) {
410 410
             $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
411 411
                 array('action' => 'edit', 'post' => $event->ID()),
412 412
                 EVENTS_ADMIN_URL
@@ -427,11 +427,11 @@  discard block
 block discarded – undo
427 427
                     $event->ID()
428 428
                 )
429 429
             ) {
430
-                $actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '"'
431
-                                              . ' title="' . esc_attr__(
430
+                $actions['filter_by_event'] = '<a href="'.$txn_by_event_lnk.'"'
431
+                                              . ' title="'.esc_attr__(
432 432
                                                   'Filter transactions by this event',
433 433
                                                   'event_espresso'
434
-                                              ) . '">'
434
+                                              ).'">'
435 435
                                               . esc_html__('View Transactions for this event', 'event_espresso')
436 436
                                               . '</a>';
437 437
             }
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
                     'espresso_events_edit',
444 444
                     $event->ID()
445 445
                 )
446
-                    ? '<a href="' . $edit_event_url . '"'
446
+                    ? '<a href="'.$edit_event_url.'"'
447 447
                       . ' title="'
448 448
                       . sprintf(
449 449
                           esc_attr__('Edit Event: %s', 'event_espresso'),
@@ -510,8 +510,8 @@  discard block
 block discarded – undo
510 510
         );
511 511
         return '
512 512
 			<li>
513
-				<a href="' . $url . '"'
514
-               . ' title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text">
513
+				<a href="' . $url.'"'
514
+               . ' title="'.esc_attr__('View Transaction Details', 'event_espresso').'" class="tiny-text">
515 515
 					<span class="dashicons dashicons-cart"></span>
516 516
 				</a>
517 517
 			</li>';
@@ -536,8 +536,8 @@  discard block
 block discarded – undo
536 536
             ) {
537 537
                 return '
538 538
                 <li>
539
-                    <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '"'
540
-                       . ' target="_blank" href="' . $url . '" class="tiny-text">
539
+                    <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso').'"'
540
+                       . ' target="_blank" href="'.$url.'" class="tiny-text">
541 541
                         <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span>
542 542
                     </a>
543 543
                 </li>';
@@ -564,8 +564,8 @@  discard block
 block discarded – undo
564 564
                 && EEH_MSG_Template::is_mt_active('receipt')) {
565 565
                 return '
566 566
 			<li>
567
-				<a title="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '"'
568
-                       . ' target="_blank" href="' . $url . '" class="tiny-text">
567
+				<a title="' . esc_attr__('View Transaction Receipt', 'event_espresso').'"'
568
+                       . ' target="_blank" href="'.$url.'" class="tiny-text">
569 569
 					<span class="dashicons dashicons-media-default ee-icon-size-18"></span>
570 570
 				</a>
571 571
 			</li>';
@@ -603,8 +603,8 @@  discard block
 block discarded – undo
603 603
             )
604 604
                 ? '
605 605
 				<li>
606
-					<a href="' . $url . '"'
607
-                  . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text">
606
+					<a href="' . $url.'"'
607
+                  . ' title="'.esc_attr__('View Registration Details', 'event_espresso').'" class="tiny-text">
608 608
 						<span class="dashicons dashicons-clipboard"></span>
609 609
 					</a>
610 610
 				</li>'
@@ -649,8 +649,8 @@  discard block
 block discarded – undo
649 649
             );
650 650
             return '
651 651
             <li>
652
-                <a href="' . $url . '"'
653
-                   . ' title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text">
652
+                <a href="' . $url.'"'
653
+                   . ' title="'.esc_attr__('Send Payment Reminder', 'event_espresso').'" class="tiny-text">
654 654
                     <span class="dashicons dashicons-email-alt"></span>
655 655
                 </a>
656 656
             </li>';
@@ -680,7 +680,7 @@  discard block
 block discarded – undo
680 680
             'ee_read_global_messages',
681 681
             'view_filtered_messages'
682 682
         )
683
-            ? '<li>' . $url . '</li>'
683
+            ? '<li>'.$url.'</li>'
684 684
             : '';
685 685
     }
686 686
 
@@ -701,8 +701,8 @@  discard block
 block discarded – undo
701 701
         ) {
702 702
             return '
703 703
             <li>
704
-                <a title="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso') . '"'
705
-                   . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"'
704
+                <a title="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso').'"'
705
+                   . ' target="_blank" href="'.$registration->payment_overview_url(true).'"'
706 706
                    . ' class="tiny-text">
707 707
                     <span class="dashicons dashicons-money ee-icon-size-18"></span>
708 708
                 </a>
Please login to merge, or discard this patch.
Indentation   +658 added lines, -658 removed lines patch added patch discarded remove patch
@@ -15,121 +15,121 @@  discard block
 block discarded – undo
15 15
 class EE_Admin_Transactions_List_Table extends EE_Admin_List_Table
16 16
 {
17 17
 
18
-    /**
19
-     * @var SessionLifespan $session_lifespan
20
-     */
21
-    private $session_lifespan;
22
-
23
-    private $_status;
24
-
25
-
26
-    /**
27
-     * @param \Transactions_Admin_Page $admin_page
28
-     * @param SessionLifespan          $lifespan
29
-     */
30
-    public function __construct(\Transactions_Admin_Page $admin_page, SessionLifespan $lifespan)
31
-    {
32
-        parent::__construct($admin_page);
33
-        $this->session_lifespan = $lifespan;
34
-        $this->_status = $this->_admin_page->get_transaction_status_array();
35
-    }
36
-
37
-
38
-    /**
39
-     *_setup_data
40
-     */
41
-    protected function _setup_data()
42
-    {
43
-        $this->_data = $this->_admin_page->get_transactions($this->_per_page);
44
-        $status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all';
45
-        $this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status);
46
-    }
47
-
48
-
49
-    /**
50
-     *_set_properties
51
-     */
52
-    protected function _set_properties()
53
-    {
54
-        $this->_wp_list_args = array(
55
-            'singular' => __('transaction', 'event_espresso'),
56
-            'plural'   => __('transactions', 'event_espresso'),
57
-            'ajax'     => true,
58
-            'screen'   => $this->_admin_page->get_current_screen()->id,
59
-        );
60
-        $ID_column_name = __('ID', 'event_espresso');
61
-        $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">';
62
-        $ID_column_name .= __('Transaction Date', 'event_espresso');
63
-        $ID_column_name .= '</span> ';
64
-        $this->_columns = array(
65
-            'TXN_ID'        => $ID_column_name,
66
-            'TXN_timestamp' => __('Transaction Date', 'event_espresso'),
67
-            'TXN_total'     => __('Total', 'event_espresso'),
68
-            'TXN_paid'      => __('Paid', 'event_espresso'),
69
-            'ATT_fname'     => __('Primary Registrant', 'event_espresso'),
70
-            'event_name'    => __('Event', 'event_espresso'),
71
-            'actions'       => __('Actions', 'event_espresso'),
72
-        );
73
-
74
-        $this->_sortable_columns = array(
75
-            'TXN_ID'        => array('TXN_ID' => false),
76
-            'event_name'    => array('event_name' => false),
77
-            'ATT_fname'     => array('ATT_fname' => false),
78
-            'TXN_timestamp' => array('TXN_timestamp' => true) // true means its already sorted
79
-        );
80
-
81
-        $this->_primary_column = 'TXN_ID';
82
-
83
-        $this->_hidden_columns = array();
84
-    }
85
-
86
-
87
-    /**
88
-     * This simply sets up the row class for the table rows.
89
-     * Allows for easier overriding of child methods for setting up sorting.
90
-     *
91
-     * @param  EE_Transaction $transaction the current item
92
-     * @return string
93
-     * @throws \EE_Error
94
-     */
95
-    protected function _get_row_class($transaction)
96
-    {
97
-        $class = parent::_get_row_class($transaction);
98
-        // add status class
99
-        $class .= ' ee-status-strip txn-status-' . $transaction->status_ID();
100
-        if ($this->_has_checkbox_column) {
101
-            $class .= ' has-checkbox-column';
102
-        }
103
-        return $class;
104
-    }
105
-
106
-
107
-    /**
108
-     * _get_table_filters
109
-     * We use this to assemble and return any filters that are associated with this table that help further refine what
110
-     * get's shown in the table.
111
-     *
112
-     * @abstract
113
-     * @access protected
114
-     * @return array
115
-     */
116
-    protected function _get_table_filters()
117
-    {
118
-        $filters = array();
119
-        $start_date = isset($this->_req_data['txn-filter-start-date'])
120
-            ? wp_strip_all_tags($this->_req_data['txn-filter-start-date'])
121
-            : date(
122
-                'm/d/Y',
123
-                strtotime('-10 year')
124
-            );
125
-        $end_date = isset($this->_req_data['txn-filter-end-date'])
126
-            ? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
127
-            : date(
128
-                'm/d/Y',
129
-                current_time('timestamp')
130
-            );
131
-        ob_start();
132
-        ?>
18
+	/**
19
+	 * @var SessionLifespan $session_lifespan
20
+	 */
21
+	private $session_lifespan;
22
+
23
+	private $_status;
24
+
25
+
26
+	/**
27
+	 * @param \Transactions_Admin_Page $admin_page
28
+	 * @param SessionLifespan          $lifespan
29
+	 */
30
+	public function __construct(\Transactions_Admin_Page $admin_page, SessionLifespan $lifespan)
31
+	{
32
+		parent::__construct($admin_page);
33
+		$this->session_lifespan = $lifespan;
34
+		$this->_status = $this->_admin_page->get_transaction_status_array();
35
+	}
36
+
37
+
38
+	/**
39
+	 *_setup_data
40
+	 */
41
+	protected function _setup_data()
42
+	{
43
+		$this->_data = $this->_admin_page->get_transactions($this->_per_page);
44
+		$status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all';
45
+		$this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status);
46
+	}
47
+
48
+
49
+	/**
50
+	 *_set_properties
51
+	 */
52
+	protected function _set_properties()
53
+	{
54
+		$this->_wp_list_args = array(
55
+			'singular' => __('transaction', 'event_espresso'),
56
+			'plural'   => __('transactions', 'event_espresso'),
57
+			'ajax'     => true,
58
+			'screen'   => $this->_admin_page->get_current_screen()->id,
59
+		);
60
+		$ID_column_name = __('ID', 'event_espresso');
61
+		$ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">';
62
+		$ID_column_name .= __('Transaction Date', 'event_espresso');
63
+		$ID_column_name .= '</span> ';
64
+		$this->_columns = array(
65
+			'TXN_ID'        => $ID_column_name,
66
+			'TXN_timestamp' => __('Transaction Date', 'event_espresso'),
67
+			'TXN_total'     => __('Total', 'event_espresso'),
68
+			'TXN_paid'      => __('Paid', 'event_espresso'),
69
+			'ATT_fname'     => __('Primary Registrant', 'event_espresso'),
70
+			'event_name'    => __('Event', 'event_espresso'),
71
+			'actions'       => __('Actions', 'event_espresso'),
72
+		);
73
+
74
+		$this->_sortable_columns = array(
75
+			'TXN_ID'        => array('TXN_ID' => false),
76
+			'event_name'    => array('event_name' => false),
77
+			'ATT_fname'     => array('ATT_fname' => false),
78
+			'TXN_timestamp' => array('TXN_timestamp' => true) // true means its already sorted
79
+		);
80
+
81
+		$this->_primary_column = 'TXN_ID';
82
+
83
+		$this->_hidden_columns = array();
84
+	}
85
+
86
+
87
+	/**
88
+	 * This simply sets up the row class for the table rows.
89
+	 * Allows for easier overriding of child methods for setting up sorting.
90
+	 *
91
+	 * @param  EE_Transaction $transaction the current item
92
+	 * @return string
93
+	 * @throws \EE_Error
94
+	 */
95
+	protected function _get_row_class($transaction)
96
+	{
97
+		$class = parent::_get_row_class($transaction);
98
+		// add status class
99
+		$class .= ' ee-status-strip txn-status-' . $transaction->status_ID();
100
+		if ($this->_has_checkbox_column) {
101
+			$class .= ' has-checkbox-column';
102
+		}
103
+		return $class;
104
+	}
105
+
106
+
107
+	/**
108
+	 * _get_table_filters
109
+	 * We use this to assemble and return any filters that are associated with this table that help further refine what
110
+	 * get's shown in the table.
111
+	 *
112
+	 * @abstract
113
+	 * @access protected
114
+	 * @return array
115
+	 */
116
+	protected function _get_table_filters()
117
+	{
118
+		$filters = array();
119
+		$start_date = isset($this->_req_data['txn-filter-start-date'])
120
+			? wp_strip_all_tags($this->_req_data['txn-filter-start-date'])
121
+			: date(
122
+				'm/d/Y',
123
+				strtotime('-10 year')
124
+			);
125
+		$end_date = isset($this->_req_data['txn-filter-end-date'])
126
+			? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
127
+			: date(
128
+				'm/d/Y',
129
+				current_time('timestamp')
130
+			);
131
+		ob_start();
132
+		?>
133 133
         <label for="txn-filter-start-date">Display Transactions from </label>
134 134
         <input id="txn-filter-start-date" class="datepicker" type="text" value="<?php echo $start_date; ?>"
135 135
                name="txn-filter-start-date" size="15"/>
@@ -137,578 +137,578 @@  discard block
 block discarded – undo
137 137
         <input id="txn-filter-end-date" class="datepicker" type="text" value="<?php echo $end_date; ?>"
138 138
                name="txn-filter-end-date" size="15"/>
139 139
         <?php
140
-        $filters[] = ob_get_contents();
141
-        ob_end_clean();
142
-        return $filters;
143
-    }
144
-
145
-
146
-    /**
147
-     *_add_view_counts
148
-     */
149
-    protected function _add_view_counts()
150
-    {
151
-        $this->_views['all']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'all');
152
-        $this->_views['abandoned']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'abandoned');
153
-        $this->_views['failed']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'failed');
154
-    }
155
-
156
-
157
-    /**
158
-     *    column TXN_ID
159
-     *
160
-     * @param \EE_Transaction $transaction
161
-     * @return string
162
-     * @throws \EE_Error
163
-     */
164
-    public function column_TXN_ID(EE_Transaction $transaction)
165
-    {
166
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
167
-            array(
168
-                'action' => 'view_transaction',
169
-                'TXN_ID' => $transaction->ID(),
170
-            ),
171
-            TXN_ADMIN_URL
172
-        );
173
-        $content = '<a href="' . $view_lnk_url . '"'
174
-                   . ' title="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">'
175
-                   . $transaction->ID()
176
-                   . '</a>';
177
-
178
-        // txn timestamp
179
-        $content .= '  <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>';
180
-        return $content;
181
-    }
182
-
183
-
184
-    /**
185
-     * @param \EE_Transaction $transaction
186
-     * @return string
187
-     * @throws EE_Error
188
-     * @throws InvalidArgumentException
189
-     * @throws InvalidDataTypeException
190
-     * @throws InvalidInterfaceException
191
-     */
192
-    protected function _get_txn_timestamp(EE_Transaction $transaction)
193
-    {
194
-        // is TXN less than 2 hours old ?
195
-        if (($transaction->failed() || $transaction->is_abandoned())
196
-            && $this->session_lifespan->expiration() < $transaction->datetime(false, true)
197
-        ) {
198
-            $timestamp = esc_html__('TXN in progress...', 'event_espresso');
199
-        } else {
200
-            $timestamp = $transaction->get_i18n_datetime('TXN_timestamp');
201
-        }
202
-        return $timestamp;
203
-    }
204
-
205
-
206
-    /**
207
-     *    column_cb
208
-     *
209
-     * @param \EE_Transaction $transaction
210
-     * @return string
211
-     * @throws \EE_Error
212
-     */
213
-    public function column_cb($transaction)
214
-    {
215
-        return sprintf(
216
-            '<input type="checkbox" name="%1$s[]" value="%2$s" />',
217
-            $this->_wp_list_args['singular'],
218
-            $transaction->ID()
219
-        );
220
-    }
221
-
222
-
223
-    /**
224
-     *    column_TXN_timestamp
225
-     *
226
-     * @param \EE_Transaction $transaction
227
-     * @return string
228
-     * @throws \EE_Error
229
-     */
230
-    public function column_TXN_timestamp(EE_Transaction $transaction)
231
-    {
232
-        $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
233
-            array(
234
-                'action' => 'view_transaction',
235
-                'TXN_ID' => $transaction->ID(),
236
-            ),
237
-            TXN_ADMIN_URL
238
-        );
239
-        $txn_date = '<a href="' . $view_lnk_url . '"'
240
-                    . ' title="'
241
-                    . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID() . '">'
242
-                    . $this->_get_txn_timestamp($transaction)
243
-                    . '</a>';
244
-        // status
245
-        $txn_date .= '<br><span class="ee-status-text-small">'
246
-                    . EEH_Template::pretty_status(
247
-                        $transaction->status_ID(),
248
-                        false,
249
-                        'sentence'
250
-                    )
251
-                     . '</span>';
252
-        return $txn_date;
253
-    }
254
-
255
-
256
-    /**
257
-     *    column_TXN_total
258
-     *
259
-     * @param \EE_Transaction $transaction
260
-     * @return string
261
-     * @throws \EE_Error
262
-     */
263
-    public function column_TXN_total(EE_Transaction $transaction)
264
-    {
265
-        if ($transaction->get('TXN_total') > 0) {
266
-            return '<span class="txn-pad-rght">'
267
-                   . apply_filters(
268
-                       'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total',
269
-                       $transaction->get_pretty('TXN_total'),
270
-                       $transaction
271
-                   )
272
-                   . '</span>';
273
-        } else {
274
-            return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
275
-        }
276
-    }
277
-
278
-
279
-    /**
280
-     *    column_TXN_paid
281
-     *
282
-     * @param \EE_Transaction $transaction
283
-     * @return mixed|string
284
-     * @throws \EE_Error
285
-     */
286
-    public function column_TXN_paid(EE_Transaction $transaction)
287
-    {
288
-        $transaction_total = $transaction->get('TXN_total');
289
-        $transaction_paid = $transaction->get('TXN_paid');
290
-
291
-        if (\EEH_Money::compare_floats($transaction_total, 0, '>')) {
292
-            // monies owing
293
-            $span_class = 'txn-overview-part-payment-spn';
294
-            if (\EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) {
295
-                // paid in full
296
-                $span_class = 'txn-overview-full-payment-spn';
297
-            } elseif (\EEH_Money::compare_floats($transaction_paid, 0, '==')) {
298
-                // no payments made
299
-                $span_class = 'txn-overview-no-payment-spn';
300
-            }
301
-        } else {
302
-            // transaction_total == 0 so this is a free event
303
-            $span_class = 'txn-overview-free-event-spn';
304
-        }
305
-
306
-        $payment_method = $transaction->payment_method();
307
-        $payment_method_name = $payment_method instanceof EE_Payment_Method
308
-            ? $payment_method->admin_name()
309
-            : esc_html__('Unknown', 'event_espresso');
310
-
311
-        $content = '<span class="' . $span_class . ' txn-pad-rght">'
312
-                   . $transaction->get_pretty('TXN_paid')
313
-                   . '</span>';
314
-        if ($transaction_paid > 0) {
315
-            $content .= '<br><span class="ee-status-text-small">'
316
-                        . sprintf(
317
-                            esc_html__('...via %s', 'event_espresso'),
318
-                            $payment_method_name
319
-                        )
320
-                        . '</span>';
321
-        }
322
-        return $content;
323
-    }
324
-
325
-
326
-    /**
327
-     *    column_ATT_fname
328
-     *
329
-     * @param \EE_Transaction $transaction
330
-     * @return string
331
-     * @throws EE_Error
332
-     * @throws InvalidArgumentException
333
-     * @throws InvalidDataTypeException
334
-     * @throws InvalidInterfaceException
335
-     */
336
-    public function column_ATT_fname(EE_Transaction $transaction)
337
-    {
338
-        $primary_reg = $transaction->primary_registration();
339
-        $attendee = $primary_reg->get_first_related('Attendee');
340
-        if ($attendee instanceof EE_Attendee) {
341
-            $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
342
-                array(
343
-                    'action'  => 'view_registration',
344
-                    '_REG_ID' => $primary_reg->ID(),
345
-                ),
346
-                REG_ADMIN_URL
347
-            );
348
-            $content = EE_Registry::instance()->CAP->current_user_can(
349
-                'ee_read_registration',
350
-                'espresso_registrations_view_registration',
351
-                $primary_reg->ID()
352
-            )
353
-                ? '<a href="' . $edit_lnk_url . '"'
354
-                  . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
355
-                  . $attendee->full_name()
356
-                  . '</a>'
357
-                : $attendee->full_name();
358
-            $content .= '<br>' . $attendee->email();
359
-            return $content;
360
-        }
361
-        return $transaction->failed() || $transaction->is_abandoned()
362
-            ? esc_html__('no contact record.', 'event_espresso')
363
-            : esc_html__(
364
-                'No contact record, because the transaction was abandoned or the registration process failed.',
365
-                'event_espresso'
366
-            );
367
-    }
368
-
369
-
370
-    /**
371
-     *    column_ATT_email
372
-     *
373
-     * @param \EE_Transaction $transaction
374
-     * @return string
375
-     * @throws \EE_Error
376
-     */
377
-    public function column_ATT_email(EE_Transaction $transaction)
378
-    {
379
-        $attendee = $transaction->primary_registration()->get_first_related('Attendee');
380
-        if (! empty($attendee)) {
381
-            return '<a href="mailto:' . $attendee->get('ATT_email') . '">'
382
-                   . $attendee->get('ATT_email')
383
-                   . '</a>';
384
-        } else {
385
-            return $transaction->failed() || $transaction->is_abandoned()
386
-                ? esc_html__('no contact record.', 'event_espresso')
387
-                : esc_html__(
388
-                    'No contact record, because the transaction was abandoned or the registration process failed.',
389
-                    'event_espresso'
390
-                );
391
-        }
392
-    }
393
-
394
-
395
-    /**
396
-     *    column_event_name
397
-     *
398
-     * @param \EE_Transaction $transaction
399
-     * @return string
400
-     * @throws EE_Error
401
-     * @throws InvalidArgumentException
402
-     * @throws InvalidDataTypeException
403
-     * @throws InvalidInterfaceException
404
-     */
405
-    public function column_event_name(EE_Transaction $transaction)
406
-    {
407
-        $actions = array();
408
-        $event = $transaction->primary_registration()->get_first_related('Event');
409
-        if (! empty($event)) {
410
-            $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
411
-                array('action' => 'edit', 'post' => $event->ID()),
412
-                EVENTS_ADMIN_URL
413
-            );
414
-            $event_name = $event->get('EVT_name');
415
-
416
-            // filter this view by transactions for this event
417
-            $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce(
418
-                array(
419
-                    'action' => 'default',
420
-                    'EVT_ID' => $event->ID(),
421
-                )
422
-            );
423
-            if (empty($this->_req_data['EVT_ID'])
424
-                && EE_Registry::instance()->CAP->current_user_can(
425
-                    'ee_edit_event',
426
-                    'espresso_events_edit',
427
-                    $event->ID()
428
-                )
429
-            ) {
430
-                $actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '"'
431
-                                              . ' title="' . esc_attr__(
432
-                                                  'Filter transactions by this event',
433
-                                                  'event_espresso'
434
-                                              ) . '">'
435
-                                              . esc_html__('View Transactions for this event', 'event_espresso')
436
-                                              . '</a>';
437
-            }
438
-
439
-            return sprintf(
440
-                '%1$s %2$s',
441
-                EE_Registry::instance()->CAP->current_user_can(
442
-                    'ee_edit_event',
443
-                    'espresso_events_edit',
444
-                    $event->ID()
445
-                )
446
-                    ? '<a href="' . $edit_event_url . '"'
447
-                      . ' title="'
448
-                      . sprintf(
449
-                          esc_attr__('Edit Event: %s', 'event_espresso'),
450
-                          $event->get('EVT_name')
451
-                      )
452
-                      . '">'
453
-                      . wp_trim_words(
454
-                          $event_name,
455
-                          30,
456
-                          '...'
457
-                      )
458
-                      . '</a>'
459
-                    : wp_trim_words($event_name, 30, '...'),
460
-                $this->row_actions($actions)
461
-            );
462
-        } else {
463
-            return esc_html__(
464
-                'The event associated with this transaction via the primary registration cannot be retrieved.',
465
-                'event_espresso'
466
-            );
467
-        }
468
-    }
469
-
470
-
471
-    /**
472
-     *    column_actions
473
-     *
474
-     * @param \EE_Transaction $transaction
475
-     * @return string
476
-     * @throws \EE_Error
477
-     */
478
-    public function column_actions(EE_Transaction $transaction)
479
-    {
480
-        return $this->_action_string(
481
-            $this->get_transaction_details_link($transaction)
482
-            . $this->get_invoice_link($transaction)
483
-            . $this->get_receipt_link($transaction)
484
-            . $this->get_primary_registration_details_link($transaction)
485
-            . $this->get_send_payment_reminder_trigger_link($transaction)
486
-            . $this->get_payment_overview_link($transaction)
487
-            . $this->get_related_messages_link($transaction),
488
-            $transaction,
489
-            'ul',
490
-            'txn-overview-actions-ul'
491
-        );
492
-    }
493
-
494
-
495
-    /**
496
-     * Get the transaction details link.
497
-     *
498
-     * @param EE_Transaction $transaction
499
-     * @return string
500
-     * @throws EE_Error
501
-     */
502
-    protected function get_transaction_details_link(EE_Transaction $transaction)
503
-    {
504
-        $url = EE_Admin_Page::add_query_args_and_nonce(
505
-            array(
506
-                'action' => 'view_transaction',
507
-                'TXN_ID' => $transaction->ID(),
508
-            ),
509
-            TXN_ADMIN_URL
510
-        );
511
-        return '
140
+		$filters[] = ob_get_contents();
141
+		ob_end_clean();
142
+		return $filters;
143
+	}
144
+
145
+
146
+	/**
147
+	 *_add_view_counts
148
+	 */
149
+	protected function _add_view_counts()
150
+	{
151
+		$this->_views['all']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'all');
152
+		$this->_views['abandoned']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'abandoned');
153
+		$this->_views['failed']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'failed');
154
+	}
155
+
156
+
157
+	/**
158
+	 *    column TXN_ID
159
+	 *
160
+	 * @param \EE_Transaction $transaction
161
+	 * @return string
162
+	 * @throws \EE_Error
163
+	 */
164
+	public function column_TXN_ID(EE_Transaction $transaction)
165
+	{
166
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
167
+			array(
168
+				'action' => 'view_transaction',
169
+				'TXN_ID' => $transaction->ID(),
170
+			),
171
+			TXN_ADMIN_URL
172
+		);
173
+		$content = '<a href="' . $view_lnk_url . '"'
174
+				   . ' title="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">'
175
+				   . $transaction->ID()
176
+				   . '</a>';
177
+
178
+		// txn timestamp
179
+		$content .= '  <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>';
180
+		return $content;
181
+	}
182
+
183
+
184
+	/**
185
+	 * @param \EE_Transaction $transaction
186
+	 * @return string
187
+	 * @throws EE_Error
188
+	 * @throws InvalidArgumentException
189
+	 * @throws InvalidDataTypeException
190
+	 * @throws InvalidInterfaceException
191
+	 */
192
+	protected function _get_txn_timestamp(EE_Transaction $transaction)
193
+	{
194
+		// is TXN less than 2 hours old ?
195
+		if (($transaction->failed() || $transaction->is_abandoned())
196
+			&& $this->session_lifespan->expiration() < $transaction->datetime(false, true)
197
+		) {
198
+			$timestamp = esc_html__('TXN in progress...', 'event_espresso');
199
+		} else {
200
+			$timestamp = $transaction->get_i18n_datetime('TXN_timestamp');
201
+		}
202
+		return $timestamp;
203
+	}
204
+
205
+
206
+	/**
207
+	 *    column_cb
208
+	 *
209
+	 * @param \EE_Transaction $transaction
210
+	 * @return string
211
+	 * @throws \EE_Error
212
+	 */
213
+	public function column_cb($transaction)
214
+	{
215
+		return sprintf(
216
+			'<input type="checkbox" name="%1$s[]" value="%2$s" />',
217
+			$this->_wp_list_args['singular'],
218
+			$transaction->ID()
219
+		);
220
+	}
221
+
222
+
223
+	/**
224
+	 *    column_TXN_timestamp
225
+	 *
226
+	 * @param \EE_Transaction $transaction
227
+	 * @return string
228
+	 * @throws \EE_Error
229
+	 */
230
+	public function column_TXN_timestamp(EE_Transaction $transaction)
231
+	{
232
+		$view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
233
+			array(
234
+				'action' => 'view_transaction',
235
+				'TXN_ID' => $transaction->ID(),
236
+			),
237
+			TXN_ADMIN_URL
238
+		);
239
+		$txn_date = '<a href="' . $view_lnk_url . '"'
240
+					. ' title="'
241
+					. esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID() . '">'
242
+					. $this->_get_txn_timestamp($transaction)
243
+					. '</a>';
244
+		// status
245
+		$txn_date .= '<br><span class="ee-status-text-small">'
246
+					. EEH_Template::pretty_status(
247
+						$transaction->status_ID(),
248
+						false,
249
+						'sentence'
250
+					)
251
+					 . '</span>';
252
+		return $txn_date;
253
+	}
254
+
255
+
256
+	/**
257
+	 *    column_TXN_total
258
+	 *
259
+	 * @param \EE_Transaction $transaction
260
+	 * @return string
261
+	 * @throws \EE_Error
262
+	 */
263
+	public function column_TXN_total(EE_Transaction $transaction)
264
+	{
265
+		if ($transaction->get('TXN_total') > 0) {
266
+			return '<span class="txn-pad-rght">'
267
+				   . apply_filters(
268
+					   'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total',
269
+					   $transaction->get_pretty('TXN_total'),
270
+					   $transaction
271
+				   )
272
+				   . '</span>';
273
+		} else {
274
+			return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>';
275
+		}
276
+	}
277
+
278
+
279
+	/**
280
+	 *    column_TXN_paid
281
+	 *
282
+	 * @param \EE_Transaction $transaction
283
+	 * @return mixed|string
284
+	 * @throws \EE_Error
285
+	 */
286
+	public function column_TXN_paid(EE_Transaction $transaction)
287
+	{
288
+		$transaction_total = $transaction->get('TXN_total');
289
+		$transaction_paid = $transaction->get('TXN_paid');
290
+
291
+		if (\EEH_Money::compare_floats($transaction_total, 0, '>')) {
292
+			// monies owing
293
+			$span_class = 'txn-overview-part-payment-spn';
294
+			if (\EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) {
295
+				// paid in full
296
+				$span_class = 'txn-overview-full-payment-spn';
297
+			} elseif (\EEH_Money::compare_floats($transaction_paid, 0, '==')) {
298
+				// no payments made
299
+				$span_class = 'txn-overview-no-payment-spn';
300
+			}
301
+		} else {
302
+			// transaction_total == 0 so this is a free event
303
+			$span_class = 'txn-overview-free-event-spn';
304
+		}
305
+
306
+		$payment_method = $transaction->payment_method();
307
+		$payment_method_name = $payment_method instanceof EE_Payment_Method
308
+			? $payment_method->admin_name()
309
+			: esc_html__('Unknown', 'event_espresso');
310
+
311
+		$content = '<span class="' . $span_class . ' txn-pad-rght">'
312
+				   . $transaction->get_pretty('TXN_paid')
313
+				   . '</span>';
314
+		if ($transaction_paid > 0) {
315
+			$content .= '<br><span class="ee-status-text-small">'
316
+						. sprintf(
317
+							esc_html__('...via %s', 'event_espresso'),
318
+							$payment_method_name
319
+						)
320
+						. '</span>';
321
+		}
322
+		return $content;
323
+	}
324
+
325
+
326
+	/**
327
+	 *    column_ATT_fname
328
+	 *
329
+	 * @param \EE_Transaction $transaction
330
+	 * @return string
331
+	 * @throws EE_Error
332
+	 * @throws InvalidArgumentException
333
+	 * @throws InvalidDataTypeException
334
+	 * @throws InvalidInterfaceException
335
+	 */
336
+	public function column_ATT_fname(EE_Transaction $transaction)
337
+	{
338
+		$primary_reg = $transaction->primary_registration();
339
+		$attendee = $primary_reg->get_first_related('Attendee');
340
+		if ($attendee instanceof EE_Attendee) {
341
+			$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
342
+				array(
343
+					'action'  => 'view_registration',
344
+					'_REG_ID' => $primary_reg->ID(),
345
+				),
346
+				REG_ADMIN_URL
347
+			);
348
+			$content = EE_Registry::instance()->CAP->current_user_can(
349
+				'ee_read_registration',
350
+				'espresso_registrations_view_registration',
351
+				$primary_reg->ID()
352
+			)
353
+				? '<a href="' . $edit_lnk_url . '"'
354
+				  . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '">'
355
+				  . $attendee->full_name()
356
+				  . '</a>'
357
+				: $attendee->full_name();
358
+			$content .= '<br>' . $attendee->email();
359
+			return $content;
360
+		}
361
+		return $transaction->failed() || $transaction->is_abandoned()
362
+			? esc_html__('no contact record.', 'event_espresso')
363
+			: esc_html__(
364
+				'No contact record, because the transaction was abandoned or the registration process failed.',
365
+				'event_espresso'
366
+			);
367
+	}
368
+
369
+
370
+	/**
371
+	 *    column_ATT_email
372
+	 *
373
+	 * @param \EE_Transaction $transaction
374
+	 * @return string
375
+	 * @throws \EE_Error
376
+	 */
377
+	public function column_ATT_email(EE_Transaction $transaction)
378
+	{
379
+		$attendee = $transaction->primary_registration()->get_first_related('Attendee');
380
+		if (! empty($attendee)) {
381
+			return '<a href="mailto:' . $attendee->get('ATT_email') . '">'
382
+				   . $attendee->get('ATT_email')
383
+				   . '</a>';
384
+		} else {
385
+			return $transaction->failed() || $transaction->is_abandoned()
386
+				? esc_html__('no contact record.', 'event_espresso')
387
+				: esc_html__(
388
+					'No contact record, because the transaction was abandoned or the registration process failed.',
389
+					'event_espresso'
390
+				);
391
+		}
392
+	}
393
+
394
+
395
+	/**
396
+	 *    column_event_name
397
+	 *
398
+	 * @param \EE_Transaction $transaction
399
+	 * @return string
400
+	 * @throws EE_Error
401
+	 * @throws InvalidArgumentException
402
+	 * @throws InvalidDataTypeException
403
+	 * @throws InvalidInterfaceException
404
+	 */
405
+	public function column_event_name(EE_Transaction $transaction)
406
+	{
407
+		$actions = array();
408
+		$event = $transaction->primary_registration()->get_first_related('Event');
409
+		if (! empty($event)) {
410
+			$edit_event_url = EE_Admin_Page::add_query_args_and_nonce(
411
+				array('action' => 'edit', 'post' => $event->ID()),
412
+				EVENTS_ADMIN_URL
413
+			);
414
+			$event_name = $event->get('EVT_name');
415
+
416
+			// filter this view by transactions for this event
417
+			$txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce(
418
+				array(
419
+					'action' => 'default',
420
+					'EVT_ID' => $event->ID(),
421
+				)
422
+			);
423
+			if (empty($this->_req_data['EVT_ID'])
424
+				&& EE_Registry::instance()->CAP->current_user_can(
425
+					'ee_edit_event',
426
+					'espresso_events_edit',
427
+					$event->ID()
428
+				)
429
+			) {
430
+				$actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '"'
431
+											  . ' title="' . esc_attr__(
432
+												  'Filter transactions by this event',
433
+												  'event_espresso'
434
+											  ) . '">'
435
+											  . esc_html__('View Transactions for this event', 'event_espresso')
436
+											  . '</a>';
437
+			}
438
+
439
+			return sprintf(
440
+				'%1$s %2$s',
441
+				EE_Registry::instance()->CAP->current_user_can(
442
+					'ee_edit_event',
443
+					'espresso_events_edit',
444
+					$event->ID()
445
+				)
446
+					? '<a href="' . $edit_event_url . '"'
447
+					  . ' title="'
448
+					  . sprintf(
449
+						  esc_attr__('Edit Event: %s', 'event_espresso'),
450
+						  $event->get('EVT_name')
451
+					  )
452
+					  . '">'
453
+					  . wp_trim_words(
454
+						  $event_name,
455
+						  30,
456
+						  '...'
457
+					  )
458
+					  . '</a>'
459
+					: wp_trim_words($event_name, 30, '...'),
460
+				$this->row_actions($actions)
461
+			);
462
+		} else {
463
+			return esc_html__(
464
+				'The event associated with this transaction via the primary registration cannot be retrieved.',
465
+				'event_espresso'
466
+			);
467
+		}
468
+	}
469
+
470
+
471
+	/**
472
+	 *    column_actions
473
+	 *
474
+	 * @param \EE_Transaction $transaction
475
+	 * @return string
476
+	 * @throws \EE_Error
477
+	 */
478
+	public function column_actions(EE_Transaction $transaction)
479
+	{
480
+		return $this->_action_string(
481
+			$this->get_transaction_details_link($transaction)
482
+			. $this->get_invoice_link($transaction)
483
+			. $this->get_receipt_link($transaction)
484
+			. $this->get_primary_registration_details_link($transaction)
485
+			. $this->get_send_payment_reminder_trigger_link($transaction)
486
+			. $this->get_payment_overview_link($transaction)
487
+			. $this->get_related_messages_link($transaction),
488
+			$transaction,
489
+			'ul',
490
+			'txn-overview-actions-ul'
491
+		);
492
+	}
493
+
494
+
495
+	/**
496
+	 * Get the transaction details link.
497
+	 *
498
+	 * @param EE_Transaction $transaction
499
+	 * @return string
500
+	 * @throws EE_Error
501
+	 */
502
+	protected function get_transaction_details_link(EE_Transaction $transaction)
503
+	{
504
+		$url = EE_Admin_Page::add_query_args_and_nonce(
505
+			array(
506
+				'action' => 'view_transaction',
507
+				'TXN_ID' => $transaction->ID(),
508
+			),
509
+			TXN_ADMIN_URL
510
+		);
511
+		return '
512 512
 			<li>
513 513
 				<a href="' . $url . '"'
514
-               . ' title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text">
514
+			   . ' title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text">
515 515
 					<span class="dashicons dashicons-cart"></span>
516 516
 				</a>
517 517
 			</li>';
518
-    }
519
-
520
-
521
-    /**
522
-     * Get the invoice link for the given registration.
523
-     *
524
-     * @param EE_Transaction $transaction
525
-     * @return string
526
-     * @throws EE_Error
527
-     */
528
-    protected function get_invoice_link(EE_Transaction $transaction)
529
-    {
530
-        $registration = $transaction->primary_registration();
531
-        if ($registration instanceof EE_Registration) {
532
-            $url = $registration->invoice_url();
533
-            // only show invoice link if message type is active.
534
-            if ($registration->attendee() instanceof EE_Attendee
535
-                && EEH_MSG_Template::is_mt_active('invoice')
536
-            ) {
537
-                return '
518
+	}
519
+
520
+
521
+	/**
522
+	 * Get the invoice link for the given registration.
523
+	 *
524
+	 * @param EE_Transaction $transaction
525
+	 * @return string
526
+	 * @throws EE_Error
527
+	 */
528
+	protected function get_invoice_link(EE_Transaction $transaction)
529
+	{
530
+		$registration = $transaction->primary_registration();
531
+		if ($registration instanceof EE_Registration) {
532
+			$url = $registration->invoice_url();
533
+			// only show invoice link if message type is active.
534
+			if ($registration->attendee() instanceof EE_Attendee
535
+				&& EEH_MSG_Template::is_mt_active('invoice')
536
+			) {
537
+				return '
538 538
                 <li>
539 539
                     <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '"'
540
-                       . ' target="_blank" href="' . $url . '" class="tiny-text">
540
+					   . ' target="_blank" href="' . $url . '" class="tiny-text">
541 541
                         <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span>
542 542
                     </a>
543 543
                 </li>';
544
-            }
545
-        }
546
-        return '';
547
-    }
548
-
549
-
550
-    /**
551
-     * Get the receipt link for the transaction.
552
-     *
553
-     * @param EE_Transaction $transaction
554
-     * @return string
555
-     * @throws EE_Error
556
-     */
557
-    protected function get_receipt_link(EE_Transaction $transaction)
558
-    {
559
-        $registration = $transaction->primary_registration();
560
-        if ($registration instanceof EE_Registration) {
561
-            $url = $registration->receipt_url();
562
-            // only show receipt link if message type is active.
563
-            if ($registration->attendee() instanceof EE_Attendee
564
-                && EEH_MSG_Template::is_mt_active('receipt')) {
565
-                return '
544
+			}
545
+		}
546
+		return '';
547
+	}
548
+
549
+
550
+	/**
551
+	 * Get the receipt link for the transaction.
552
+	 *
553
+	 * @param EE_Transaction $transaction
554
+	 * @return string
555
+	 * @throws EE_Error
556
+	 */
557
+	protected function get_receipt_link(EE_Transaction $transaction)
558
+	{
559
+		$registration = $transaction->primary_registration();
560
+		if ($registration instanceof EE_Registration) {
561
+			$url = $registration->receipt_url();
562
+			// only show receipt link if message type is active.
563
+			if ($registration->attendee() instanceof EE_Attendee
564
+				&& EEH_MSG_Template::is_mt_active('receipt')) {
565
+				return '
566 566
 			<li>
567 567
 				<a title="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '"'
568
-                       . ' target="_blank" href="' . $url . '" class="tiny-text">
568
+					   . ' target="_blank" href="' . $url . '" class="tiny-text">
569 569
 					<span class="dashicons dashicons-media-default ee-icon-size-18"></span>
570 570
 				</a>
571 571
 			</li>';
572
-            }
573
-        }
574
-        return '';
575
-    }
576
-
577
-
578
-    /**
579
-     * Get the link to view the details for the primary registration.
580
-     *
581
-     * @param EE_Transaction $transaction
582
-     * @return string
583
-     * @throws EE_Error
584
-     * @throws InvalidArgumentException
585
-     * @throws InvalidDataTypeException
586
-     * @throws InvalidInterfaceException
587
-     */
588
-    protected function get_primary_registration_details_link(EE_Transaction $transaction)
589
-    {
590
-        $registration = $transaction->primary_registration();
591
-        if ($registration instanceof EE_Registration) {
592
-            $url = EE_Admin_Page::add_query_args_and_nonce(
593
-                array(
594
-                    'action'  => 'view_registration',
595
-                    '_REG_ID' => $registration->ID(),
596
-                ),
597
-                REG_ADMIN_URL
598
-            );
599
-            return EE_Registry::instance()->CAP->current_user_can(
600
-                'ee_read_registration',
601
-                'espresso_registrations_view_registration',
602
-                $registration->ID()
603
-            )
604
-                ? '
572
+			}
573
+		}
574
+		return '';
575
+	}
576
+
577
+
578
+	/**
579
+	 * Get the link to view the details for the primary registration.
580
+	 *
581
+	 * @param EE_Transaction $transaction
582
+	 * @return string
583
+	 * @throws EE_Error
584
+	 * @throws InvalidArgumentException
585
+	 * @throws InvalidDataTypeException
586
+	 * @throws InvalidInterfaceException
587
+	 */
588
+	protected function get_primary_registration_details_link(EE_Transaction $transaction)
589
+	{
590
+		$registration = $transaction->primary_registration();
591
+		if ($registration instanceof EE_Registration) {
592
+			$url = EE_Admin_Page::add_query_args_and_nonce(
593
+				array(
594
+					'action'  => 'view_registration',
595
+					'_REG_ID' => $registration->ID(),
596
+				),
597
+				REG_ADMIN_URL
598
+			);
599
+			return EE_Registry::instance()->CAP->current_user_can(
600
+				'ee_read_registration',
601
+				'espresso_registrations_view_registration',
602
+				$registration->ID()
603
+			)
604
+				? '
605 605
 				<li>
606 606
 					<a href="' . $url . '"'
607
-                  . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text">
607
+				  . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text">
608 608
 						<span class="dashicons dashicons-clipboard"></span>
609 609
 					</a>
610 610
 				</li>'
611
-                : '';
612
-        }
613
-        return '';
614
-    }
615
-
616
-
617
-    /**
618
-     * Get send payment reminder trigger link
619
-     *
620
-     * @param EE_Transaction $transaction
621
-     * @return string
622
-     * @throws EE_Error
623
-     * @throws InvalidArgumentException
624
-     * @throws InvalidDataTypeException
625
-     * @throws InvalidInterfaceException
626
-     */
627
-    protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction)
628
-    {
629
-        $registration = $transaction->primary_registration();
630
-        if ($registration instanceof EE_Registration
631
-            && $registration->attendee() instanceof EE_Attendee
632
-            && EEH_MSG_Template::is_mt_active('payment_reminder')
633
-            && ! in_array(
634
-                $transaction->status_ID(),
635
-                array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code),
636
-                true
637
-            )
638
-            && EE_Registry::instance()->CAP->current_user_can(
639
-                'ee_send_message',
640
-                'espresso_transactions_send_payment_reminder'
641
-            )
642
-        ) {
643
-            $url = EE_Admin_Page::add_query_args_and_nonce(
644
-                array(
645
-                    'action' => 'send_payment_reminder',
646
-                    'TXN_ID' => $transaction->ID(),
647
-                ),
648
-                TXN_ADMIN_URL
649
-            );
650
-            return '
611
+				: '';
612
+		}
613
+		return '';
614
+	}
615
+
616
+
617
+	/**
618
+	 * Get send payment reminder trigger link
619
+	 *
620
+	 * @param EE_Transaction $transaction
621
+	 * @return string
622
+	 * @throws EE_Error
623
+	 * @throws InvalidArgumentException
624
+	 * @throws InvalidDataTypeException
625
+	 * @throws InvalidInterfaceException
626
+	 */
627
+	protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction)
628
+	{
629
+		$registration = $transaction->primary_registration();
630
+		if ($registration instanceof EE_Registration
631
+			&& $registration->attendee() instanceof EE_Attendee
632
+			&& EEH_MSG_Template::is_mt_active('payment_reminder')
633
+			&& ! in_array(
634
+				$transaction->status_ID(),
635
+				array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code),
636
+				true
637
+			)
638
+			&& EE_Registry::instance()->CAP->current_user_can(
639
+				'ee_send_message',
640
+				'espresso_transactions_send_payment_reminder'
641
+			)
642
+		) {
643
+			$url = EE_Admin_Page::add_query_args_and_nonce(
644
+				array(
645
+					'action' => 'send_payment_reminder',
646
+					'TXN_ID' => $transaction->ID(),
647
+				),
648
+				TXN_ADMIN_URL
649
+			);
650
+			return '
651 651
             <li>
652 652
                 <a href="' . $url . '"'
653
-                   . ' title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text">
653
+				   . ' title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text">
654 654
                     <span class="dashicons dashicons-email-alt"></span>
655 655
                 </a>
656 656
             </li>';
657
-        }
658
-        return '';
659
-    }
660
-
661
-
662
-    /**
663
-     * Get link to filtered view in the message activity list table of messages for this transaction.
664
-     *
665
-     * @param EE_Transaction $transaction
666
-     * @return string
667
-     * @throws EE_Error
668
-     * @throws InvalidArgumentException
669
-     * @throws InvalidDataTypeException
670
-     * @throws InvalidInterfaceException
671
-     */
672
-    protected function get_related_messages_link(EE_Transaction $transaction)
673
-    {
674
-        $url = EEH_MSG_Template::get_message_action_link(
675
-            'see_notifications_for',
676
-            null,
677
-            array('TXN_ID' => $transaction->ID())
678
-        );
679
-        return EE_Registry::instance()->CAP->current_user_can(
680
-            'ee_read_global_messages',
681
-            'view_filtered_messages'
682
-        )
683
-            ? '<li>' . $url . '</li>'
684
-            : '';
685
-    }
686
-
687
-
688
-    /**
689
-     * Return the link to make a payment on the frontend
690
-     *
691
-     * @param EE_Transaction $transaction
692
-     * @return string
693
-     * @throws EE_Error
694
-     */
695
-    protected function get_payment_overview_link(EE_Transaction $transaction)
696
-    {
697
-        $registration = $transaction->primary_registration();
698
-        if ($registration instanceof EE_Registration
699
-            && $transaction->status_ID() !== EEM_Transaction::complete_status_code
700
-            && $registration->owes_monies_and_can_pay()
701
-        ) {
702
-            return '
657
+		}
658
+		return '';
659
+	}
660
+
661
+
662
+	/**
663
+	 * Get link to filtered view in the message activity list table of messages for this transaction.
664
+	 *
665
+	 * @param EE_Transaction $transaction
666
+	 * @return string
667
+	 * @throws EE_Error
668
+	 * @throws InvalidArgumentException
669
+	 * @throws InvalidDataTypeException
670
+	 * @throws InvalidInterfaceException
671
+	 */
672
+	protected function get_related_messages_link(EE_Transaction $transaction)
673
+	{
674
+		$url = EEH_MSG_Template::get_message_action_link(
675
+			'see_notifications_for',
676
+			null,
677
+			array('TXN_ID' => $transaction->ID())
678
+		);
679
+		return EE_Registry::instance()->CAP->current_user_can(
680
+			'ee_read_global_messages',
681
+			'view_filtered_messages'
682
+		)
683
+			? '<li>' . $url . '</li>'
684
+			: '';
685
+	}
686
+
687
+
688
+	/**
689
+	 * Return the link to make a payment on the frontend
690
+	 *
691
+	 * @param EE_Transaction $transaction
692
+	 * @return string
693
+	 * @throws EE_Error
694
+	 */
695
+	protected function get_payment_overview_link(EE_Transaction $transaction)
696
+	{
697
+		$registration = $transaction->primary_registration();
698
+		if ($registration instanceof EE_Registration
699
+			&& $transaction->status_ID() !== EEM_Transaction::complete_status_code
700
+			&& $registration->owes_monies_and_can_pay()
701
+		) {
702
+			return '
703 703
             <li>
704 704
                 <a title="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso') . '"'
705
-                   . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"'
706
-                   . ' class="tiny-text">
705
+				   . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"'
706
+				   . ' class="tiny-text">
707 707
                     <span class="dashicons dashicons-money ee-icon-size-18"></span>
708 708
                 </a>
709 709
             </li>
710 710
             ';
711
-        }
712
-        return '';
713
-    }
711
+		}
712
+		return '';
713
+	}
714 714
 }
Please login to merge, or discard this patch.
core/services/assets/AssetCollection.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
             /** @var Asset $asset */
76 76
             $asset = $this->current();
77 77
             if ($asset->type() === $type) {
78
-                $files[ $asset->handle() ] = $asset;
78
+                $files[$asset->handle()] = $asset;
79 79
             }
80 80
             $this->next();
81 81
         }
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
             /** @var JavascriptAsset $asset */
97 97
             $asset = $this->current();
98 98
             if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) {
99
-                $files[ $asset->handle() ] = $asset;
99
+                $files[$asset->handle()] = $asset;
100 100
             }
101 101
             $this->next();
102 102
         }
Please login to merge, or discard this patch.
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -21,201 +21,201 @@
 block discarded – undo
21 21
 {
22 22
 
23 23
 
24
-    /**
25
-     * AssetCollection constructor
26
-     *
27
-     * @throws InvalidInterfaceException
28
-     */
29
-    public function __construct()
30
-    {
31
-        parent::__construct('EventEspresso\core\domain\values\assets\Asset');
32
-    }
33
-
34
-
35
-    /**
36
-     * @return StylesheetAsset[]
37
-     * @since 4.9.62.p
38
-     */
39
-    public function getStylesheetAssets()
40
-    {
41
-        return $this->getAssetsOfType(Asset::TYPE_CSS);
42
-    }
43
-
44
-
45
-    /**
46
-     * @return JavascriptAsset[]
47
-     * @since 4.9.62.p
48
-     */
49
-    public function getJavascriptAssets()
50
-    {
51
-        return $this->getAssetsOfType(Asset::TYPE_JS);
52
-    }
53
-
54
-
55
-    /**
56
-     * @return ManifestFile[]
57
-     * @since 4.9.62.p
58
-     */
59
-    public function getManifestFiles()
60
-    {
61
-        return $this->getAssetsOfType(Asset::TYPE_MANIFEST);
62
-    }
63
-
64
-
65
-    /**
66
-     * @param $type
67
-     * @return JavascriptAsset[]|StylesheetAsset[]|ManifestFile[]
68
-     * @since 4.9.62.p
69
-     */
70
-    protected function getAssetsOfType($type)
71
-    {
72
-        $files = array();
73
-        $this->rewind();
74
-        while ($this->valid()) {
75
-            /** @var Asset $asset */
76
-            $asset = $this->current();
77
-            if ($asset->type() === $type) {
78
-                $files[ $asset->handle() ] = $asset;
79
-            }
80
-            $this->next();
81
-        }
82
-        $this->rewind();
83
-        return $files;
84
-    }
85
-
86
-
87
-    /**
88
-     * @return JavascriptAsset[]
89
-     * @since 4.9.62.p
90
-     */
91
-    public function getJavascriptAssetsWithData()
92
-    {
93
-        $files = array();
94
-        $this->rewind();
95
-        while ($this->valid()) {
96
-            /** @var JavascriptAsset $asset */
97
-            $asset = $this->current();
98
-            if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) {
99
-                $files[ $asset->handle() ] = $asset;
100
-            }
101
-            $this->next();
102
-        }
103
-        $this->rewind();
104
-        return $files;
105
-    }
106
-
107
-
108
-    /**
109
-     * has
110
-     * returns TRUE or FALSE
111
-     * depending on whether the object is within the Collection
112
-     * based on the supplied $identifier and type
113
-     *
114
-     * @param  mixed $identifier
115
-     * @param string $type
116
-     * @return bool
117
-     * @since $VID:$
118
-     */
119
-    public function hasAssetOfType($identifier, $type = Asset::TYPE_JS)
120
-    {
121
-        $this->rewind();
122
-        while ($this->valid()) {
123
-            if ($this->getInfo() === $identifier && $this->current()->type() === $type) {
124
-                $this->rewind();
125
-                return true;
126
-            }
127
-            $this->next();
128
-        }
129
-        return false;
130
-    }
131
-
132
-
133
-    /**
134
-     * has
135
-     * returns TRUE or FALSE
136
-     * depending on whether the Stylesheet Asset is within the Collection
137
-     * based on the supplied $identifier
138
-     *
139
-     * @param  mixed $identifier
140
-     * @return bool
141
-     * @since $VID:$
142
-     */
143
-    public function hasStylesheetAsset($identifier)
144
-    {
145
-        return $this->hasAssetOfType($identifier, Asset::TYPE_CSS);
146
-    }
147
-
148
-
149
-    /**
150
-     * has
151
-     * returns TRUE or FALSE
152
-     * depending on whether the Javascript Asset is within the Collection
153
-     * based on the supplied $identifier
154
-     *
155
-     * @param  mixed $identifier
156
-     * @return bool
157
-     * @since $VID:$
158
-     */
159
-    public function hasJavascriptAsset($identifier)
160
-    {
161
-        return $this->hasAssetOfType($identifier, Asset::TYPE_JS);
162
-    }
163
-
164
-    /**
165
-     * has
166
-     * returns TRUE or FALSE
167
-     * depending on whether the object is within the Collection
168
-     * based on the supplied $identifier and type
169
-     *
170
-     * @param  mixed $identifier
171
-     * @param string $type
172
-     * @return JavascriptAsset|StylesheetAsset
173
-     * @since $VID:$
174
-     */
175
-    public function getAssetOfType($identifier, $type = Asset::TYPE_JS)
176
-    {
177
-        $this->rewind();
178
-        while ($this->valid()) {
179
-            if ($this->getInfo() === $identifier && $this->current()->type() === $type) {
180
-                /** @var JavascriptAsset|StylesheetAsset $object */
181
-                $object = $this->current();
182
-                $this->rewind();
183
-                return $object;
184
-            }
185
-            $this->next();
186
-        }
187
-        return null;
188
-    }
189
-
190
-
191
-    /**
192
-     * has
193
-     * returns TRUE or FALSE
194
-     * depending on whether the Stylesheet Asset is within the Collection
195
-     * based on the supplied $identifier
196
-     *
197
-     * @param  mixed $identifier
198
-     * @return StylesheetAsset
199
-     * @since $VID:$
200
-     */
201
-    public function getStylesheetAsset($identifier)
202
-    {
203
-        return $this->getAssetOfType($identifier, Asset::TYPE_CSS);
204
-    }
205
-
206
-
207
-    /**
208
-     * has
209
-     * returns TRUE or FALSE
210
-     * depending on whether the Javascript Asset is within the Collection
211
-     * based on the supplied $identifier
212
-     *
213
-     * @param  mixed $identifier
214
-     * @return JavascriptAsset
215
-     * @since $VID:$
216
-     */
217
-    public function getJavascriptAsset($identifier)
218
-    {
219
-        return $this->getAssetOfType($identifier, Asset::TYPE_JS);
220
-    }
24
+	/**
25
+	 * AssetCollection constructor
26
+	 *
27
+	 * @throws InvalidInterfaceException
28
+	 */
29
+	public function __construct()
30
+	{
31
+		parent::__construct('EventEspresso\core\domain\values\assets\Asset');
32
+	}
33
+
34
+
35
+	/**
36
+	 * @return StylesheetAsset[]
37
+	 * @since 4.9.62.p
38
+	 */
39
+	public function getStylesheetAssets()
40
+	{
41
+		return $this->getAssetsOfType(Asset::TYPE_CSS);
42
+	}
43
+
44
+
45
+	/**
46
+	 * @return JavascriptAsset[]
47
+	 * @since 4.9.62.p
48
+	 */
49
+	public function getJavascriptAssets()
50
+	{
51
+		return $this->getAssetsOfType(Asset::TYPE_JS);
52
+	}
53
+
54
+
55
+	/**
56
+	 * @return ManifestFile[]
57
+	 * @since 4.9.62.p
58
+	 */
59
+	public function getManifestFiles()
60
+	{
61
+		return $this->getAssetsOfType(Asset::TYPE_MANIFEST);
62
+	}
63
+
64
+
65
+	/**
66
+	 * @param $type
67
+	 * @return JavascriptAsset[]|StylesheetAsset[]|ManifestFile[]
68
+	 * @since 4.9.62.p
69
+	 */
70
+	protected function getAssetsOfType($type)
71
+	{
72
+		$files = array();
73
+		$this->rewind();
74
+		while ($this->valid()) {
75
+			/** @var Asset $asset */
76
+			$asset = $this->current();
77
+			if ($asset->type() === $type) {
78
+				$files[ $asset->handle() ] = $asset;
79
+			}
80
+			$this->next();
81
+		}
82
+		$this->rewind();
83
+		return $files;
84
+	}
85
+
86
+
87
+	/**
88
+	 * @return JavascriptAsset[]
89
+	 * @since 4.9.62.p
90
+	 */
91
+	public function getJavascriptAssetsWithData()
92
+	{
93
+		$files = array();
94
+		$this->rewind();
95
+		while ($this->valid()) {
96
+			/** @var JavascriptAsset $asset */
97
+			$asset = $this->current();
98
+			if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) {
99
+				$files[ $asset->handle() ] = $asset;
100
+			}
101
+			$this->next();
102
+		}
103
+		$this->rewind();
104
+		return $files;
105
+	}
106
+
107
+
108
+	/**
109
+	 * has
110
+	 * returns TRUE or FALSE
111
+	 * depending on whether the object is within the Collection
112
+	 * based on the supplied $identifier and type
113
+	 *
114
+	 * @param  mixed $identifier
115
+	 * @param string $type
116
+	 * @return bool
117
+	 * @since $VID:$
118
+	 */
119
+	public function hasAssetOfType($identifier, $type = Asset::TYPE_JS)
120
+	{
121
+		$this->rewind();
122
+		while ($this->valid()) {
123
+			if ($this->getInfo() === $identifier && $this->current()->type() === $type) {
124
+				$this->rewind();
125
+				return true;
126
+			}
127
+			$this->next();
128
+		}
129
+		return false;
130
+	}
131
+
132
+
133
+	/**
134
+	 * has
135
+	 * returns TRUE or FALSE
136
+	 * depending on whether the Stylesheet Asset is within the Collection
137
+	 * based on the supplied $identifier
138
+	 *
139
+	 * @param  mixed $identifier
140
+	 * @return bool
141
+	 * @since $VID:$
142
+	 */
143
+	public function hasStylesheetAsset($identifier)
144
+	{
145
+		return $this->hasAssetOfType($identifier, Asset::TYPE_CSS);
146
+	}
147
+
148
+
149
+	/**
150
+	 * has
151
+	 * returns TRUE or FALSE
152
+	 * depending on whether the Javascript Asset is within the Collection
153
+	 * based on the supplied $identifier
154
+	 *
155
+	 * @param  mixed $identifier
156
+	 * @return bool
157
+	 * @since $VID:$
158
+	 */
159
+	public function hasJavascriptAsset($identifier)
160
+	{
161
+		return $this->hasAssetOfType($identifier, Asset::TYPE_JS);
162
+	}
163
+
164
+	/**
165
+	 * has
166
+	 * returns TRUE or FALSE
167
+	 * depending on whether the object is within the Collection
168
+	 * based on the supplied $identifier and type
169
+	 *
170
+	 * @param  mixed $identifier
171
+	 * @param string $type
172
+	 * @return JavascriptAsset|StylesheetAsset
173
+	 * @since $VID:$
174
+	 */
175
+	public function getAssetOfType($identifier, $type = Asset::TYPE_JS)
176
+	{
177
+		$this->rewind();
178
+		while ($this->valid()) {
179
+			if ($this->getInfo() === $identifier && $this->current()->type() === $type) {
180
+				/** @var JavascriptAsset|StylesheetAsset $object */
181
+				$object = $this->current();
182
+				$this->rewind();
183
+				return $object;
184
+			}
185
+			$this->next();
186
+		}
187
+		return null;
188
+	}
189
+
190
+
191
+	/**
192
+	 * has
193
+	 * returns TRUE or FALSE
194
+	 * depending on whether the Stylesheet Asset is within the Collection
195
+	 * based on the supplied $identifier
196
+	 *
197
+	 * @param  mixed $identifier
198
+	 * @return StylesheetAsset
199
+	 * @since $VID:$
200
+	 */
201
+	public function getStylesheetAsset($identifier)
202
+	{
203
+		return $this->getAssetOfType($identifier, Asset::TYPE_CSS);
204
+	}
205
+
206
+
207
+	/**
208
+	 * has
209
+	 * returns TRUE or FALSE
210
+	 * depending on whether the Javascript Asset is within the Collection
211
+	 * based on the supplied $identifier
212
+	 *
213
+	 * @param  mixed $identifier
214
+	 * @return JavascriptAsset
215
+	 * @since $VID:$
216
+	 */
217
+	public function getJavascriptAsset($identifier)
218
+	{
219
+		return $this->getAssetOfType($identifier, Asset::TYPE_JS);
220
+	}
221 221
 }
Please login to merge, or discard this patch.
core/services/assets/Registry.php 1 patch
Indentation   +548 added lines, -548 removed lines patch added patch discarded remove patch
@@ -23,559 +23,559 @@
 block discarded – undo
23 23
 class Registry
24 24
 {
25 25
 
26
-    const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
27
-
28
-    /**
29
-     * @var AssetCollection $assets
30
-     */
31
-    protected $assets;
32
-
33
-    /**
34
-     * @var I18nRegistry
35
-     */
36
-    private $i18n_registry;
37
-
38
-    /**
39
-     * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
40
-     *
41
-     * @var array
42
-     */
43
-    protected $jsdata = array();
44
-
45
-    /**
46
-     * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
47
-     * page source.
48
-     *
49
-     * @var array
50
-     */
51
-    private $script_handles_with_data = array();
52
-
53
-    /**
54
-     * Holds the manifest data obtained from registered manifest files.
55
-     * Manifests are maps of asset chunk name to actual built asset file names.
56
-     * Shape of this array is:
57
-     * array(
58
-     *  'some_namespace_slug' => array(
59
-     *      'some_chunk_name' => array(
60
-     *          'js' => 'filename.js'
61
-     *          'css' => 'filename.js'
62
-     *      ),
63
-     *      'url_base' => 'https://baseurl.com/to/assets
64
-     *  )
65
-     * )
66
-     *
67
-     * @var array
68
-     */
69
-    private $manifest_data = array();
70
-
71
-
72
-    /**
73
-     * Registry constructor.
74
-     * Hooking into WP actions for script registry.
75
-     *
76
-     * @param AssetCollection $assets
77
-     * @param I18nRegistry    $i18n_registry
78
-     */
79
-    public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry)
80
-    {
81
-        $this->assets = $assets;
82
-        $this->i18n_registry = $i18n_registry;
83
-        add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
84
-        add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
85
-        add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
86
-        add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
87
-        add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4);
88
-        add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4);
89
-        add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
90
-        add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
91
-    }
92
-
93
-
94
-    /**
95
-     * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
96
-     * translation handling.
97
-     *
98
-     * @return I18nRegistry
99
-     */
100
-    public function getI18nRegistry()
101
-    {
102
-        return $this->i18n_registry;
103
-    }
104
-
105
-
106
-    /**
107
-     * Callback for the wp_enqueue_scripts actions used to register assets.
108
-     *
109
-     * @since 4.9.62.p
110
-     * @throws Exception
111
-     */
112
-    public function registerScriptsAndStyles()
113
-    {
114
-        try {
115
-            $this->registerScripts($this->assets->getJavascriptAssets());
116
-            $this->registerStyles($this->assets->getStylesheetAssets());
117
-        } catch (Exception $exception) {
118
-            new ExceptionStackTraceDisplay($exception);
119
-        }
120
-    }
121
-
122
-
123
-    /**
124
-     * Registers JS assets with WP core
125
-     *
126
-     * @since 4.9.62.p
127
-     * @param JavascriptAsset[] $scripts
128
-     * @throws AssetRegistrationException
129
-     * @throws InvalidDataTypeException
130
-     */
131
-    public function registerScripts(array $scripts)
132
-    {
133
-        foreach ($scripts as $script) {
134
-            // skip to next script if this has already been done
135
-            if ($script->isRegistered()) {
136
-                continue;
137
-            }
138
-            do_action(
139
-                'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
140
-                $script
141
-            );
142
-            $registered = wp_register_script(
143
-                $script->handle(),
144
-                $script->source(),
145
-                $script->dependencies(),
146
-                $script->version(),
147
-                $script->loadInFooter()
148
-            );
149
-            if (! $registered && defined('EE_DEBUG') && EE_DEBUG) {
150
-                throw new AssetRegistrationException($script->handle());
151
-            }
152
-            $script->setRegistered($registered);
153
-            if ($script->requiresTranslation()) {
154
-                $this->registerTranslation($script->handle());
155
-            }
156
-            do_action(
157
-                'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script',
158
-                $script
159
-            );
160
-        }
161
-    }
162
-
163
-
164
-    /**
165
-     * Registers CSS assets with WP core
166
-     *
167
-     * @since 4.9.62.p
168
-     * @param StylesheetAsset[] $styles
169
-     * @throws InvalidDataTypeException
170
-     */
171
-    public function registerStyles(array $styles)
172
-    {
173
-        foreach ($styles as $style) {
174
-            // skip to next style if this has already been done
175
-            if ($style->isRegistered()) {
176
-                continue;
177
-            }
178
-            do_action(
179
-                'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style',
180
-                $style
181
-            );
182
-            wp_register_style(
183
-                $style->handle(),
184
-                $style->source(),
185
-                $style->dependencies(),
186
-                $style->version(),
187
-                $style->media()
188
-            );
189
-            $style->setRegistered();
190
-            do_action(
191
-                'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style',
192
-                $style
193
-            );
194
-        }
195
-    }
196
-
197
-
198
-    /**
199
-     * Call back for the script print in frontend and backend.
200
-     * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
201
-     *
202
-     * @since 4.9.31.rc.015
203
-     */
204
-    public function enqueueData()
205
-    {
206
-        $this->removeAlreadyRegisteredDataForScriptHandles();
207
-        wp_add_inline_script(
208
-            'eejs-core',
209
-            'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
210
-            'before'
211
-        );
212
-        $scripts = $this->assets->getJavascriptAssetsWithData();
213
-        foreach ($scripts as $script) {
214
-            $this->addRegisteredScriptHandlesWithData($script->handle());
215
-            if ($script->hasInlineDataCallback()) {
216
-                $localize = $script->inlineDataCallback();
217
-                $localize();
218
-            }
219
-        }
220
-    }
221
-
222
-
223
-    /**
224
-     * Used to add data to eejs.data object.
225
-     * Note:  Overriding existing data is not allowed.
226
-     * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
227
-     * If the data you add is something like this:
228
-     *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
229
-     * It will be exposed in the page source as:
230
-     *  eejs.data.my_plugin_data.foo == gar
231
-     *
232
-     * @param string       $key   Key used to access your data
233
-     * @param string|array $value Value to attach to key
234
-     * @throws InvalidArgumentException
235
-     */
236
-    public function addData($key, $value)
237
-    {
238
-        if ($this->verifyDataNotExisting($key)) {
239
-            $this->jsdata[ $key ] = $value;
240
-        }
241
-    }
242
-
243
-
244
-    /**
245
-     * Similar to addData except this allows for users to push values to an existing key where the values on key are
246
-     * elements in an array.
247
-     * When you use this method, the value you include will be appended to the end of an array on $key.
248
-     * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
249
-     * object like this, eejs.data.test = [ my_data,
250
-     * ]
251
-     * If there has already been a scalar value attached to the data object given key, then
252
-     * this will throw an exception.
253
-     *
254
-     * @param string       $key   Key to attach data to.
255
-     * @param string|array $value Value being registered.
256
-     * @throws InvalidArgumentException
257
-     */
258
-    public function pushData($key, $value)
259
-    {
260
-        if (isset($this->jsdata[ $key ])
261
-            && ! is_array($this->jsdata[ $key ])
262
-        ) {
263
-            throw new InvalidArgumentException(
264
-                sprintf(
265
-                    __(
266
-                        'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
26
+	const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
27
+
28
+	/**
29
+	 * @var AssetCollection $assets
30
+	 */
31
+	protected $assets;
32
+
33
+	/**
34
+	 * @var I18nRegistry
35
+	 */
36
+	private $i18n_registry;
37
+
38
+	/**
39
+	 * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
40
+	 *
41
+	 * @var array
42
+	 */
43
+	protected $jsdata = array();
44
+
45
+	/**
46
+	 * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
47
+	 * page source.
48
+	 *
49
+	 * @var array
50
+	 */
51
+	private $script_handles_with_data = array();
52
+
53
+	/**
54
+	 * Holds the manifest data obtained from registered manifest files.
55
+	 * Manifests are maps of asset chunk name to actual built asset file names.
56
+	 * Shape of this array is:
57
+	 * array(
58
+	 *  'some_namespace_slug' => array(
59
+	 *      'some_chunk_name' => array(
60
+	 *          'js' => 'filename.js'
61
+	 *          'css' => 'filename.js'
62
+	 *      ),
63
+	 *      'url_base' => 'https://baseurl.com/to/assets
64
+	 *  )
65
+	 * )
66
+	 *
67
+	 * @var array
68
+	 */
69
+	private $manifest_data = array();
70
+
71
+
72
+	/**
73
+	 * Registry constructor.
74
+	 * Hooking into WP actions for script registry.
75
+	 *
76
+	 * @param AssetCollection $assets
77
+	 * @param I18nRegistry    $i18n_registry
78
+	 */
79
+	public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry)
80
+	{
81
+		$this->assets = $assets;
82
+		$this->i18n_registry = $i18n_registry;
83
+		add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
84
+		add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
85
+		add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
86
+		add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
87
+		add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4);
88
+		add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4);
89
+		add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
90
+		add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
91
+	}
92
+
93
+
94
+	/**
95
+	 * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
96
+	 * translation handling.
97
+	 *
98
+	 * @return I18nRegistry
99
+	 */
100
+	public function getI18nRegistry()
101
+	{
102
+		return $this->i18n_registry;
103
+	}
104
+
105
+
106
+	/**
107
+	 * Callback for the wp_enqueue_scripts actions used to register assets.
108
+	 *
109
+	 * @since 4.9.62.p
110
+	 * @throws Exception
111
+	 */
112
+	public function registerScriptsAndStyles()
113
+	{
114
+		try {
115
+			$this->registerScripts($this->assets->getJavascriptAssets());
116
+			$this->registerStyles($this->assets->getStylesheetAssets());
117
+		} catch (Exception $exception) {
118
+			new ExceptionStackTraceDisplay($exception);
119
+		}
120
+	}
121
+
122
+
123
+	/**
124
+	 * Registers JS assets with WP core
125
+	 *
126
+	 * @since 4.9.62.p
127
+	 * @param JavascriptAsset[] $scripts
128
+	 * @throws AssetRegistrationException
129
+	 * @throws InvalidDataTypeException
130
+	 */
131
+	public function registerScripts(array $scripts)
132
+	{
133
+		foreach ($scripts as $script) {
134
+			// skip to next script if this has already been done
135
+			if ($script->isRegistered()) {
136
+				continue;
137
+			}
138
+			do_action(
139
+				'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
140
+				$script
141
+			);
142
+			$registered = wp_register_script(
143
+				$script->handle(),
144
+				$script->source(),
145
+				$script->dependencies(),
146
+				$script->version(),
147
+				$script->loadInFooter()
148
+			);
149
+			if (! $registered && defined('EE_DEBUG') && EE_DEBUG) {
150
+				throw new AssetRegistrationException($script->handle());
151
+			}
152
+			$script->setRegistered($registered);
153
+			if ($script->requiresTranslation()) {
154
+				$this->registerTranslation($script->handle());
155
+			}
156
+			do_action(
157
+				'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script',
158
+				$script
159
+			);
160
+		}
161
+	}
162
+
163
+
164
+	/**
165
+	 * Registers CSS assets with WP core
166
+	 *
167
+	 * @since 4.9.62.p
168
+	 * @param StylesheetAsset[] $styles
169
+	 * @throws InvalidDataTypeException
170
+	 */
171
+	public function registerStyles(array $styles)
172
+	{
173
+		foreach ($styles as $style) {
174
+			// skip to next style if this has already been done
175
+			if ($style->isRegistered()) {
176
+				continue;
177
+			}
178
+			do_action(
179
+				'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style',
180
+				$style
181
+			);
182
+			wp_register_style(
183
+				$style->handle(),
184
+				$style->source(),
185
+				$style->dependencies(),
186
+				$style->version(),
187
+				$style->media()
188
+			);
189
+			$style->setRegistered();
190
+			do_action(
191
+				'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style',
192
+				$style
193
+			);
194
+		}
195
+	}
196
+
197
+
198
+	/**
199
+	 * Call back for the script print in frontend and backend.
200
+	 * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
201
+	 *
202
+	 * @since 4.9.31.rc.015
203
+	 */
204
+	public function enqueueData()
205
+	{
206
+		$this->removeAlreadyRegisteredDataForScriptHandles();
207
+		wp_add_inline_script(
208
+			'eejs-core',
209
+			'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
210
+			'before'
211
+		);
212
+		$scripts = $this->assets->getJavascriptAssetsWithData();
213
+		foreach ($scripts as $script) {
214
+			$this->addRegisteredScriptHandlesWithData($script->handle());
215
+			if ($script->hasInlineDataCallback()) {
216
+				$localize = $script->inlineDataCallback();
217
+				$localize();
218
+			}
219
+		}
220
+	}
221
+
222
+
223
+	/**
224
+	 * Used to add data to eejs.data object.
225
+	 * Note:  Overriding existing data is not allowed.
226
+	 * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
227
+	 * If the data you add is something like this:
228
+	 *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
229
+	 * It will be exposed in the page source as:
230
+	 *  eejs.data.my_plugin_data.foo == gar
231
+	 *
232
+	 * @param string       $key   Key used to access your data
233
+	 * @param string|array $value Value to attach to key
234
+	 * @throws InvalidArgumentException
235
+	 */
236
+	public function addData($key, $value)
237
+	{
238
+		if ($this->verifyDataNotExisting($key)) {
239
+			$this->jsdata[ $key ] = $value;
240
+		}
241
+	}
242
+
243
+
244
+	/**
245
+	 * Similar to addData except this allows for users to push values to an existing key where the values on key are
246
+	 * elements in an array.
247
+	 * When you use this method, the value you include will be appended to the end of an array on $key.
248
+	 * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
249
+	 * object like this, eejs.data.test = [ my_data,
250
+	 * ]
251
+	 * If there has already been a scalar value attached to the data object given key, then
252
+	 * this will throw an exception.
253
+	 *
254
+	 * @param string       $key   Key to attach data to.
255
+	 * @param string|array $value Value being registered.
256
+	 * @throws InvalidArgumentException
257
+	 */
258
+	public function pushData($key, $value)
259
+	{
260
+		if (isset($this->jsdata[ $key ])
261
+			&& ! is_array($this->jsdata[ $key ])
262
+		) {
263
+			throw new InvalidArgumentException(
264
+				sprintf(
265
+					__(
266
+						'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
267 267
                          push values to this data element when it is an array.',
268
-                        'event_espresso'
269
-                    ),
270
-                    $key,
271
-                    __METHOD__
272
-                )
273
-            );
274
-        }
275
-        $this->jsdata[ $key ][] = $value;
276
-    }
277
-
278
-
279
-    /**
280
-     * Used to set content used by javascript for a template.
281
-     * Note: Overrides of existing registered templates are not allowed.
282
-     *
283
-     * @param string $template_reference
284
-     * @param string $template_content
285
-     * @throws InvalidArgumentException
286
-     */
287
-    public function addTemplate($template_reference, $template_content)
288
-    {
289
-        if (! isset($this->jsdata['templates'])) {
290
-            $this->jsdata['templates'] = array();
291
-        }
292
-        //no overrides allowed.
293
-        if (isset($this->jsdata['templates'][ $template_reference ])) {
294
-            throw new InvalidArgumentException(
295
-                sprintf(
296
-                    __(
297
-                        'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
298
-                        'event_espresso'
299
-                    ),
300
-                    $template_reference
301
-                )
302
-            );
303
-        }
304
-        $this->jsdata['templates'][ $template_reference ] = $template_content;
305
-    }
306
-
307
-
308
-    /**
309
-     * Retrieve the template content already registered for the given reference.
310
-     *
311
-     * @param string $template_reference
312
-     * @return string
313
-     */
314
-    public function getTemplate($template_reference)
315
-    {
316
-        return isset($this->jsdata['templates'][ $template_reference ])
317
-            ? $this->jsdata['templates'][ $template_reference ]
318
-            : '';
319
-    }
320
-
321
-
322
-    /**
323
-     * Retrieve registered data.
324
-     *
325
-     * @param string $key Name of key to attach data to.
326
-     * @return mixed                If there is no for the given key, then false is returned.
327
-     */
328
-    public function getData($key)
329
-    {
330
-        return isset($this->jsdata[ $key ])
331
-            ? $this->jsdata[ $key ]
332
-            : false;
333
-    }
334
-
335
-
336
-    /**
337
-     * Verifies whether the given data exists already on the jsdata array.
338
-     * Overriding data is not allowed.
339
-     *
340
-     * @param string $key Index for data.
341
-     * @return bool        If valid then return true.
342
-     * @throws InvalidArgumentException if data already exists.
343
-     */
344
-    protected function verifyDataNotExisting($key)
345
-    {
346
-        if (isset($this->jsdata[ $key ])) {
347
-            if (is_array($this->jsdata[ $key ])) {
348
-                throw new InvalidArgumentException(
349
-                    sprintf(
350
-                        __(
351
-                            'The value for %1$s already exists in the Registry::eejs object.
268
+						'event_espresso'
269
+					),
270
+					$key,
271
+					__METHOD__
272
+				)
273
+			);
274
+		}
275
+		$this->jsdata[ $key ][] = $value;
276
+	}
277
+
278
+
279
+	/**
280
+	 * Used to set content used by javascript for a template.
281
+	 * Note: Overrides of existing registered templates are not allowed.
282
+	 *
283
+	 * @param string $template_reference
284
+	 * @param string $template_content
285
+	 * @throws InvalidArgumentException
286
+	 */
287
+	public function addTemplate($template_reference, $template_content)
288
+	{
289
+		if (! isset($this->jsdata['templates'])) {
290
+			$this->jsdata['templates'] = array();
291
+		}
292
+		//no overrides allowed.
293
+		if (isset($this->jsdata['templates'][ $template_reference ])) {
294
+			throw new InvalidArgumentException(
295
+				sprintf(
296
+					__(
297
+						'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
298
+						'event_espresso'
299
+					),
300
+					$template_reference
301
+				)
302
+			);
303
+		}
304
+		$this->jsdata['templates'][ $template_reference ] = $template_content;
305
+	}
306
+
307
+
308
+	/**
309
+	 * Retrieve the template content already registered for the given reference.
310
+	 *
311
+	 * @param string $template_reference
312
+	 * @return string
313
+	 */
314
+	public function getTemplate($template_reference)
315
+	{
316
+		return isset($this->jsdata['templates'][ $template_reference ])
317
+			? $this->jsdata['templates'][ $template_reference ]
318
+			: '';
319
+	}
320
+
321
+
322
+	/**
323
+	 * Retrieve registered data.
324
+	 *
325
+	 * @param string $key Name of key to attach data to.
326
+	 * @return mixed                If there is no for the given key, then false is returned.
327
+	 */
328
+	public function getData($key)
329
+	{
330
+		return isset($this->jsdata[ $key ])
331
+			? $this->jsdata[ $key ]
332
+			: false;
333
+	}
334
+
335
+
336
+	/**
337
+	 * Verifies whether the given data exists already on the jsdata array.
338
+	 * Overriding data is not allowed.
339
+	 *
340
+	 * @param string $key Index for data.
341
+	 * @return bool        If valid then return true.
342
+	 * @throws InvalidArgumentException if data already exists.
343
+	 */
344
+	protected function verifyDataNotExisting($key)
345
+	{
346
+		if (isset($this->jsdata[ $key ])) {
347
+			if (is_array($this->jsdata[ $key ])) {
348
+				throw new InvalidArgumentException(
349
+					sprintf(
350
+						__(
351
+							'The value for %1$s already exists in the Registry::eejs object.
352 352
                             Overrides are not allowed. Since the value of this data is an array, you may want to use the
353 353
                             %2$s method to push your value to the array.',
354
-                            'event_espresso'
355
-                        ),
356
-                        $key,
357
-                        'pushData()'
358
-                    )
359
-                );
360
-            }
361
-            throw new InvalidArgumentException(
362
-                sprintf(
363
-                    __(
364
-                        'The value for %1$s already exists in the Registry::eejs object. Overrides are not
354
+							'event_espresso'
355
+						),
356
+						$key,
357
+						'pushData()'
358
+					)
359
+				);
360
+			}
361
+			throw new InvalidArgumentException(
362
+				sprintf(
363
+					__(
364
+						'The value for %1$s already exists in the Registry::eejs object. Overrides are not
365 365
                         allowed.  Consider attaching your value to a different key',
366
-                        'event_espresso'
367
-                    ),
368
-                    $key
369
-                )
370
-            );
371
-        }
372
-        return true;
373
-    }
374
-
375
-
376
-    /**
377
-     * Get the actual asset path for asset manifests.
378
-     * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
379
-     *
380
-     * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
381
-     *                           asset file location.
382
-     * @param string $chunk_name
383
-     * @param string $asset_type
384
-     * @return string
385
-     * @since 4.9.59.p
386
-     */
387
-    public function getAssetUrl($namespace, $chunk_name, $asset_type)
388
-    {
389
-        $url = isset(
390
-            $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ],
391
-            $this->manifest_data[ $namespace ]['url_base']
392
-        )
393
-            ? $this->manifest_data[ $namespace ]['url_base']
394
-              . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ]
395
-            : $chunk_name;
396
-        return apply_filters(
397
-            'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
398
-            $url,
399
-            $namespace,
400
-            $chunk_name,
401
-            $asset_type
402
-        );
403
-    }
404
-
405
-
406
-    /**
407
-     * Return the url to a js file for the given namespace and chunk name.
408
-     *
409
-     * @param string $namespace
410
-     * @param string $chunk_name
411
-     * @return string
412
-     */
413
-    public function getJsUrl($namespace, $chunk_name)
414
-    {
415
-        return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS);
416
-    }
417
-
418
-
419
-    /**
420
-     * Return the url to a css file for the given namespace and chunk name.
421
-     *
422
-     * @param string $namespace
423
-     * @param string $chunk_name
424
-     * @return string
425
-     */
426
-    public function getCssUrl($namespace, $chunk_name)
427
-    {
428
-        return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS);
429
-    }
430
-
431
-
432
-    /**
433
-     * @since 4.9.62.p
434
-     * @throws InvalidArgumentException
435
-     * @throws InvalidFilePathException
436
-     */
437
-    public function registerManifestFiles()
438
-    {
439
-        $manifest_files = $this->assets->getManifestFiles();
440
-        foreach ($manifest_files as $manifest_file) {
441
-            $this->registerManifestFile(
442
-                $manifest_file->assetNamespace(),
443
-                $manifest_file->urlBase(),
444
-                $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST
445
-            );
446
-        }
447
-    }
448
-
449
-
450
-    /**
451
-     * Used to register a js/css manifest file with the registered_manifest_files property.
452
-     *
453
-     * @param string $namespace     Provided to associate the manifest file with a specific namespace.
454
-     * @param string $url_base      The url base for the manifest file location.
455
-     * @param string $manifest_file The absolute path to the manifest file.
456
-     * @throws InvalidArgumentException
457
-     * @throws InvalidFilePathException
458
-     * @since 4.9.59.p
459
-     */
460
-    public function registerManifestFile($namespace, $url_base, $manifest_file)
461
-    {
462
-        if (isset($this->manifest_data[ $namespace ])) {
463
-            throw new InvalidArgumentException(
464
-                sprintf(
465
-                    esc_html__(
466
-                        'The namespace for this manifest file has already been registered, choose a namespace other than %s',
467
-                        'event_espresso'
468
-                    ),
469
-                    $namespace
470
-                )
471
-            );
472
-        }
473
-        if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
474
-            if (is_admin()) {
475
-                EE_Error::add_error(
476
-                    sprintf(
477
-                        esc_html__(
478
-                            'The url given for %1$s assets is invalid.  The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant',
479
-                            'event_espresso'
480
-                        ),
481
-                        'Event Espresso',
482
-                        $url_base,
483
-                        'plugins_url',
484
-                        'WP_PLUGIN_URL'
485
-                    ),
486
-                    __FILE__,
487
-                    __FUNCTION__,
488
-                    __LINE__
489
-                );
490
-            }
491
-            return;
492
-        }
493
-        $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
494
-        if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
495
-            $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base);
496
-        }
497
-    }
498
-
499
-
500
-    /**
501
-     * Decodes json from the provided manifest file.
502
-     *
503
-     * @since 4.9.59.p
504
-     * @param string $manifest_file Path to manifest file.
505
-     * @return array
506
-     * @throws InvalidFilePathException
507
-     */
508
-    private function decodeManifestFile($manifest_file)
509
-    {
510
-        if (! file_exists($manifest_file)) {
511
-            throw new InvalidFilePathException($manifest_file);
512
-        }
513
-        return json_decode(file_get_contents($manifest_file), true);
514
-    }
515
-
516
-
517
-    /**
518
-     * This is used to set registered script handles that have data.
519
-     *
520
-     * @param string $script_handle
521
-     */
522
-    private function addRegisteredScriptHandlesWithData($script_handle)
523
-    {
524
-        $this->script_handles_with_data[ $script_handle ] = $script_handle;
525
-    }
526
-
527
-
528
-    /**i
366
+						'event_espresso'
367
+					),
368
+					$key
369
+				)
370
+			);
371
+		}
372
+		return true;
373
+	}
374
+
375
+
376
+	/**
377
+	 * Get the actual asset path for asset manifests.
378
+	 * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
379
+	 *
380
+	 * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
381
+	 *                           asset file location.
382
+	 * @param string $chunk_name
383
+	 * @param string $asset_type
384
+	 * @return string
385
+	 * @since 4.9.59.p
386
+	 */
387
+	public function getAssetUrl($namespace, $chunk_name, $asset_type)
388
+	{
389
+		$url = isset(
390
+			$this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ],
391
+			$this->manifest_data[ $namespace ]['url_base']
392
+		)
393
+			? $this->manifest_data[ $namespace ]['url_base']
394
+			  . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ]
395
+			: $chunk_name;
396
+		return apply_filters(
397
+			'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
398
+			$url,
399
+			$namespace,
400
+			$chunk_name,
401
+			$asset_type
402
+		);
403
+	}
404
+
405
+
406
+	/**
407
+	 * Return the url to a js file for the given namespace and chunk name.
408
+	 *
409
+	 * @param string $namespace
410
+	 * @param string $chunk_name
411
+	 * @return string
412
+	 */
413
+	public function getJsUrl($namespace, $chunk_name)
414
+	{
415
+		return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS);
416
+	}
417
+
418
+
419
+	/**
420
+	 * Return the url to a css file for the given namespace and chunk name.
421
+	 *
422
+	 * @param string $namespace
423
+	 * @param string $chunk_name
424
+	 * @return string
425
+	 */
426
+	public function getCssUrl($namespace, $chunk_name)
427
+	{
428
+		return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS);
429
+	}
430
+
431
+
432
+	/**
433
+	 * @since 4.9.62.p
434
+	 * @throws InvalidArgumentException
435
+	 * @throws InvalidFilePathException
436
+	 */
437
+	public function registerManifestFiles()
438
+	{
439
+		$manifest_files = $this->assets->getManifestFiles();
440
+		foreach ($manifest_files as $manifest_file) {
441
+			$this->registerManifestFile(
442
+				$manifest_file->assetNamespace(),
443
+				$manifest_file->urlBase(),
444
+				$manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST
445
+			);
446
+		}
447
+	}
448
+
449
+
450
+	/**
451
+	 * Used to register a js/css manifest file with the registered_manifest_files property.
452
+	 *
453
+	 * @param string $namespace     Provided to associate the manifest file with a specific namespace.
454
+	 * @param string $url_base      The url base for the manifest file location.
455
+	 * @param string $manifest_file The absolute path to the manifest file.
456
+	 * @throws InvalidArgumentException
457
+	 * @throws InvalidFilePathException
458
+	 * @since 4.9.59.p
459
+	 */
460
+	public function registerManifestFile($namespace, $url_base, $manifest_file)
461
+	{
462
+		if (isset($this->manifest_data[ $namespace ])) {
463
+			throw new InvalidArgumentException(
464
+				sprintf(
465
+					esc_html__(
466
+						'The namespace for this manifest file has already been registered, choose a namespace other than %s',
467
+						'event_espresso'
468
+					),
469
+					$namespace
470
+				)
471
+			);
472
+		}
473
+		if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
474
+			if (is_admin()) {
475
+				EE_Error::add_error(
476
+					sprintf(
477
+						esc_html__(
478
+							'The url given for %1$s assets is invalid.  The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant',
479
+							'event_espresso'
480
+						),
481
+						'Event Espresso',
482
+						$url_base,
483
+						'plugins_url',
484
+						'WP_PLUGIN_URL'
485
+					),
486
+					__FILE__,
487
+					__FUNCTION__,
488
+					__LINE__
489
+				);
490
+			}
491
+			return;
492
+		}
493
+		$this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
494
+		if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
495
+			$this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base);
496
+		}
497
+	}
498
+
499
+
500
+	/**
501
+	 * Decodes json from the provided manifest file.
502
+	 *
503
+	 * @since 4.9.59.p
504
+	 * @param string $manifest_file Path to manifest file.
505
+	 * @return array
506
+	 * @throws InvalidFilePathException
507
+	 */
508
+	private function decodeManifestFile($manifest_file)
509
+	{
510
+		if (! file_exists($manifest_file)) {
511
+			throw new InvalidFilePathException($manifest_file);
512
+		}
513
+		return json_decode(file_get_contents($manifest_file), true);
514
+	}
515
+
516
+
517
+	/**
518
+	 * This is used to set registered script handles that have data.
519
+	 *
520
+	 * @param string $script_handle
521
+	 */
522
+	private function addRegisteredScriptHandlesWithData($script_handle)
523
+	{
524
+		$this->script_handles_with_data[ $script_handle ] = $script_handle;
525
+	}
526
+
527
+
528
+	/**i
529 529
      * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the
530 530
      * Dependency stored in WP_Scripts if its set.
531 531
      */
532
-    private function removeAlreadyRegisteredDataForScriptHandles()
533
-    {
534
-        if (empty($this->script_handles_with_data)) {
535
-            return;
536
-        }
537
-        foreach ($this->script_handles_with_data as $script_handle) {
538
-            $this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
539
-        }
540
-    }
541
-
542
-
543
-    /**
544
-     * Removes any data dependency registered in WP_Scripts if its set.
545
-     *
546
-     * @param string $script_handle
547
-     */
548
-    private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
549
-    {
550
-        if (isset($this->script_handles_with_data[ $script_handle ])) {
551
-            global $wp_scripts;
552
-            $unset_handle = false;
553
-            if ($wp_scripts->get_data($script_handle, 'data')) {
554
-                unset($wp_scripts->registered[ $script_handle ]->extra['data']);
555
-                $unset_handle = true;
556
-            }
557
-            //deal with inline_scripts
558
-            if ($wp_scripts->get_data($script_handle, 'before')) {
559
-                unset($wp_scripts->registered[ $script_handle ]->extra['before']);
560
-                $unset_handle = true;
561
-            }
562
-            if ($wp_scripts->get_data($script_handle, 'after')) {
563
-                unset($wp_scripts->registered[ $script_handle ]->extra['after']);
564
-            }
565
-            if ($unset_handle) {
566
-                unset($this->script_handles_with_data[ $script_handle ]);
567
-            }
568
-        }
569
-    }
570
-
571
-
572
-    /**
573
-     * register translations for a registered script
574
-     *
575
-     * @param string $handle
576
-     */
577
-    public function registerTranslation($handle)
578
-    {
579
-        $this->i18n_registry->registerScriptI18n($handle);
580
-    }
532
+	private function removeAlreadyRegisteredDataForScriptHandles()
533
+	{
534
+		if (empty($this->script_handles_with_data)) {
535
+			return;
536
+		}
537
+		foreach ($this->script_handles_with_data as $script_handle) {
538
+			$this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
539
+		}
540
+	}
541
+
542
+
543
+	/**
544
+	 * Removes any data dependency registered in WP_Scripts if its set.
545
+	 *
546
+	 * @param string $script_handle
547
+	 */
548
+	private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
549
+	{
550
+		if (isset($this->script_handles_with_data[ $script_handle ])) {
551
+			global $wp_scripts;
552
+			$unset_handle = false;
553
+			if ($wp_scripts->get_data($script_handle, 'data')) {
554
+				unset($wp_scripts->registered[ $script_handle ]->extra['data']);
555
+				$unset_handle = true;
556
+			}
557
+			//deal with inline_scripts
558
+			if ($wp_scripts->get_data($script_handle, 'before')) {
559
+				unset($wp_scripts->registered[ $script_handle ]->extra['before']);
560
+				$unset_handle = true;
561
+			}
562
+			if ($wp_scripts->get_data($script_handle, 'after')) {
563
+				unset($wp_scripts->registered[ $script_handle ]->extra['after']);
564
+			}
565
+			if ($unset_handle) {
566
+				unset($this->script_handles_with_data[ $script_handle ]);
567
+			}
568
+		}
569
+	}
570
+
571
+
572
+	/**
573
+	 * register translations for a registered script
574
+	 *
575
+	 * @param string $handle
576
+	 */
577
+	public function registerTranslation($handle)
578
+	{
579
+		$this->i18n_registry->registerScriptI18n($handle);
580
+	}
581 581
 }
Please login to merge, or discard this patch.
core/services/assets/I18nRegistry.php 1 patch
Indentation   +234 added lines, -234 removed lines patch added patch discarded remove patch
@@ -14,238 +14,238 @@
 block discarded – undo
14 14
  */
15 15
 class I18nRegistry
16 16
 {
17
-    /**
18
-     * @var DomainInterface
19
-     */
20
-    private $domain;
21
-
22
-    /**
23
-     * Will hold all registered i18n scripts.  Prevents script handles from being registered more than once.
24
-     *
25
-     * @var array
26
-     */
27
-    private $registered_i18n = array();
28
-
29
-
30
-    /**
31
-     * Used to hold queued translations for the chunks loading in a view.
32
-     *
33
-     * @var array
34
-     */
35
-    private $queued_handle_translations = array();
36
-
37
-    /**
38
-     * Used to track script handles queued for adding translation strings as inline data in the dom.
39
-     *
40
-     * @var array
41
-     */
42
-    private $queued_scripts = array();
43
-
44
-
45
-    /**
46
-     * Obtained from the generated json file from the all javascript using wp.i18n with a map of script handle names to
47
-     * translation strings.
48
-     *
49
-     * @var array
50
-     */
51
-    private $i18n_map;
52
-
53
-
54
-    /**
55
-     * I18nRegistry constructor.
56
-     *
57
-     * @param array() $i18n_map  An array of script handle names and the strings translated for those handles.  If not
58
-     *                            provided, the class will look for map in root of plugin with filename of
59
-     *                            'translation-map.json'.
60
-     * @param DomainInterface $domain
61
-     */
62
-    public function __construct(array $i18n_map = array(), DomainInterface $domain)
63
-    {
64
-        $this->domain = $domain;
65
-        $this->setI18nMap($i18n_map);
66
-        add_filter('print_scripts_array', array($this, 'queueI18n'));
67
-    }
68
-
69
-
70
-    /**
71
-     * Used to register a script that has i18n strings for its $handle
72
-     *
73
-     * @param string $handle The script handle reference.
74
-     * @param string $domain The i18n domain for the strings.
75
-     */
76
-    public function registerScriptI18n($handle, $domain = 'event_espresso')
77
-    {
78
-        if(! isset($this->registered_i18n[$handle])) {
79
-            $this->registered_i18n[ $handle ] = 1;
80
-            $this->queued_scripts[ $handle ] = $domain;
81
-        }
82
-    }
83
-
84
-
85
-
86
-    /**
87
-     * Callback on print_scripts_array to listen for scripts enqueued and handle setting up the localized data.
88
-     *
89
-     * @param array $handles Array of registered script handles.
90
-     * @return array
91
-     */
92
-    public function queueI18n(array $handles)
93
-    {
94
-        if (empty($this->queued_scripts)) {
95
-            return $handles;
96
-        }
97
-        foreach ($handles as $handle) {
98
-            $this->queueI18nTranslationsForHandle($handle);
99
-        }
100
-        if ($this->queued_handle_translations) {
101
-            foreach ($this->queued_handle_translations as $handle => $translations_for_domain) {
102
-                $this->registerInlineScript(
103
-                    $handle,
104
-                    $translations_for_domain['translations'],
105
-                    $translations_for_domain['domain']
106
-                );
107
-            }
108
-        }
109
-        return $handles;
110
-    }
111
-
112
-
113
-    /**
114
-     * Registers inline script with translations for given handle and domain.
115
-     *
116
-     * @param string $handle       Handle used to register javascript file containing translations.
117
-     * @param array  $translations Array of string translations.
118
-     * @param string $domain       Domain for translations.  If left empty then strings are registered with the default
119
-     *                             domain for the javascript.
120
-     */
121
-    protected function registerInlineScript($handle, array $translations, $domain)
122
-    {
123
-        $script = $domain ?
124
-            'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ', "' . $domain . '" );' :
125
-            'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ' );';
126
-        wp_add_inline_script($handle, $script, 'before');
127
-    }
128
-
129
-
130
-    /**
131
-     * Queues up the translation strings for the given handle.
132
-     *
133
-     * @param string $handle The script handle being queued up.
134
-     */
135
-    private function queueI18nTranslationsForHandle($handle)
136
-    {
137
-        if (isset($this->queued_scripts[$handle])) {
138
-            $domain = $this->queued_scripts[$handle];
139
-            $translations = $this->getJedLocaleDataForDomainAndChunk($handle, $domain);
140
-            if (count($translations) > 0) {
141
-                $this->queued_handle_translations[$handle] = array(
142
-                    'domain'       => $domain,
143
-                    'translations' => $translations,
144
-                );
145
-            }
146
-            unset($this->queued_scripts[$handle]);
147
-        }
148
-    }
149
-
150
-
151
-    /**
152
-     * Sets the internal i18n_map property.
153
-     * If $chunk_map is empty or not an array, will attempt to load a chunk map from a default named map.
154
-     *
155
-     * @param array $i18n_map  If provided, an array of translation strings indexed by script handle names they
156
-     *                         correspond to.
157
-     */
158
-    private function setI18nMap(array $i18n_map)
159
-    {
160
-        if (empty($i18n_map)) {
161
-            $i18n_map = file_exists($this->domain->pluginPath() . 'translation-map.json')
162
-                ? json_decode(
163
-                        file_get_contents($this->domain->pluginPath() . 'translation-map.json'),
164
-                        true
165
-                    )
166
-                : array();
167
-        }
168
-        $this->i18n_map = $i18n_map;
169
-    }
170
-
171
-
172
-    /**
173
-     * Get the jed locale data for a given $handle and domain
174
-     *
175
-     * @param string $handle The name for the script handle we want strings returned for.
176
-     * @param string $domain The i18n domain.
177
-     * @return array
178
-     */
179
-    protected function getJedLocaleDataForDomainAndChunk($handle, $domain)
180
-    {
181
-        $translations = $this->getJedLocaleData($domain);
182
-        // get index for adding back after extracting strings for this $chunk.
183
-        $index = $translations[''];
184
-        $translations = $this->getLocaleDataMatchingMap(
185
-            $this->getOriginalStringsForHandleFromMap($handle),
186
-            $translations
187
-        );
188
-        $translations[''] = $index;
189
-        return $translations;
190
-    }
191
-
192
-
193
-    /**
194
-     * Get locale data for given strings from given translations
195
-     *
196
-     * @param array $string_set   This is the subset of strings (msgIds) we want to extract from the translations array.
197
-     * @param array $translations Translation data to extra strings from.
198
-     * @return array
199
-     */
200
-    protected function getLocaleDataMatchingMap(array $string_set, array $translations)
201
-    {
202
-        if (empty($string_set)) {
203
-            return array();
204
-        }
205
-        // some strings with quotes in them will break on the array_flip, so making sure quotes in the string are
206
-        // slashed also filter falsey values.
207
-        $string_set = array_unique(array_filter(wp_slash($string_set)));
208
-        return array_intersect_key($translations, array_flip($string_set));
209
-    }
210
-
211
-
212
-    /**
213
-     * Get original strings to translate for the given chunk from the map
214
-     *
215
-     * @param string $handle The script handle name to get strings from the map for.
216
-     * @return array
217
-     */
218
-    protected function getOriginalStringsForHandleFromMap($handle)
219
-    {
220
-        return isset($this->i18n_map[$handle]) ? $this->i18n_map[$handle] : array();
221
-    }
222
-
223
-
224
-    /**
225
-     * Returns Jed-formatted localization data.
226
-     *
227
-     * @param  string $domain Translation domain.
228
-     * @return array
229
-     */
230
-    private function getJedLocaleData($domain)
231
-    {
232
-        $translations = get_translations_for_domain($domain);
233
-
234
-        $locale = array(
235
-            '' => array(
236
-                'domain' => $domain,
237
-                'lang'   => is_admin() ? get_user_locale() : get_locale(),
238
-            ),
239
-        );
240
-
241
-        if (! empty($translations->headers['Plural-Forms'])) {
242
-            $locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
243
-        }
244
-
245
-        foreach ($translations->entries as $msgid => $entry) {
246
-            $locale[$msgid] = $entry->translations;
247
-        }
248
-
249
-        return $locale;
250
-    }
17
+	/**
18
+	 * @var DomainInterface
19
+	 */
20
+	private $domain;
21
+
22
+	/**
23
+	 * Will hold all registered i18n scripts.  Prevents script handles from being registered more than once.
24
+	 *
25
+	 * @var array
26
+	 */
27
+	private $registered_i18n = array();
28
+
29
+
30
+	/**
31
+	 * Used to hold queued translations for the chunks loading in a view.
32
+	 *
33
+	 * @var array
34
+	 */
35
+	private $queued_handle_translations = array();
36
+
37
+	/**
38
+	 * Used to track script handles queued for adding translation strings as inline data in the dom.
39
+	 *
40
+	 * @var array
41
+	 */
42
+	private $queued_scripts = array();
43
+
44
+
45
+	/**
46
+	 * Obtained from the generated json file from the all javascript using wp.i18n with a map of script handle names to
47
+	 * translation strings.
48
+	 *
49
+	 * @var array
50
+	 */
51
+	private $i18n_map;
52
+
53
+
54
+	/**
55
+	 * I18nRegistry constructor.
56
+	 *
57
+	 * @param array() $i18n_map  An array of script handle names and the strings translated for those handles.  If not
58
+	 *                            provided, the class will look for map in root of plugin with filename of
59
+	 *                            'translation-map.json'.
60
+	 * @param DomainInterface $domain
61
+	 */
62
+	public function __construct(array $i18n_map = array(), DomainInterface $domain)
63
+	{
64
+		$this->domain = $domain;
65
+		$this->setI18nMap($i18n_map);
66
+		add_filter('print_scripts_array', array($this, 'queueI18n'));
67
+	}
68
+
69
+
70
+	/**
71
+	 * Used to register a script that has i18n strings for its $handle
72
+	 *
73
+	 * @param string $handle The script handle reference.
74
+	 * @param string $domain The i18n domain for the strings.
75
+	 */
76
+	public function registerScriptI18n($handle, $domain = 'event_espresso')
77
+	{
78
+		if(! isset($this->registered_i18n[$handle])) {
79
+			$this->registered_i18n[ $handle ] = 1;
80
+			$this->queued_scripts[ $handle ] = $domain;
81
+		}
82
+	}
83
+
84
+
85
+
86
+	/**
87
+	 * Callback on print_scripts_array to listen for scripts enqueued and handle setting up the localized data.
88
+	 *
89
+	 * @param array $handles Array of registered script handles.
90
+	 * @return array
91
+	 */
92
+	public function queueI18n(array $handles)
93
+	{
94
+		if (empty($this->queued_scripts)) {
95
+			return $handles;
96
+		}
97
+		foreach ($handles as $handle) {
98
+			$this->queueI18nTranslationsForHandle($handle);
99
+		}
100
+		if ($this->queued_handle_translations) {
101
+			foreach ($this->queued_handle_translations as $handle => $translations_for_domain) {
102
+				$this->registerInlineScript(
103
+					$handle,
104
+					$translations_for_domain['translations'],
105
+					$translations_for_domain['domain']
106
+				);
107
+			}
108
+		}
109
+		return $handles;
110
+	}
111
+
112
+
113
+	/**
114
+	 * Registers inline script with translations for given handle and domain.
115
+	 *
116
+	 * @param string $handle       Handle used to register javascript file containing translations.
117
+	 * @param array  $translations Array of string translations.
118
+	 * @param string $domain       Domain for translations.  If left empty then strings are registered with the default
119
+	 *                             domain for the javascript.
120
+	 */
121
+	protected function registerInlineScript($handle, array $translations, $domain)
122
+	{
123
+		$script = $domain ?
124
+			'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ', "' . $domain . '" );' :
125
+			'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ' );';
126
+		wp_add_inline_script($handle, $script, 'before');
127
+	}
128
+
129
+
130
+	/**
131
+	 * Queues up the translation strings for the given handle.
132
+	 *
133
+	 * @param string $handle The script handle being queued up.
134
+	 */
135
+	private function queueI18nTranslationsForHandle($handle)
136
+	{
137
+		if (isset($this->queued_scripts[$handle])) {
138
+			$domain = $this->queued_scripts[$handle];
139
+			$translations = $this->getJedLocaleDataForDomainAndChunk($handle, $domain);
140
+			if (count($translations) > 0) {
141
+				$this->queued_handle_translations[$handle] = array(
142
+					'domain'       => $domain,
143
+					'translations' => $translations,
144
+				);
145
+			}
146
+			unset($this->queued_scripts[$handle]);
147
+		}
148
+	}
149
+
150
+
151
+	/**
152
+	 * Sets the internal i18n_map property.
153
+	 * If $chunk_map is empty or not an array, will attempt to load a chunk map from a default named map.
154
+	 *
155
+	 * @param array $i18n_map  If provided, an array of translation strings indexed by script handle names they
156
+	 *                         correspond to.
157
+	 */
158
+	private function setI18nMap(array $i18n_map)
159
+	{
160
+		if (empty($i18n_map)) {
161
+			$i18n_map = file_exists($this->domain->pluginPath() . 'translation-map.json')
162
+				? json_decode(
163
+						file_get_contents($this->domain->pluginPath() . 'translation-map.json'),
164
+						true
165
+					)
166
+				: array();
167
+		}
168
+		$this->i18n_map = $i18n_map;
169
+	}
170
+
171
+
172
+	/**
173
+	 * Get the jed locale data for a given $handle and domain
174
+	 *
175
+	 * @param string $handle The name for the script handle we want strings returned for.
176
+	 * @param string $domain The i18n domain.
177
+	 * @return array
178
+	 */
179
+	protected function getJedLocaleDataForDomainAndChunk($handle, $domain)
180
+	{
181
+		$translations = $this->getJedLocaleData($domain);
182
+		// get index for adding back after extracting strings for this $chunk.
183
+		$index = $translations[''];
184
+		$translations = $this->getLocaleDataMatchingMap(
185
+			$this->getOriginalStringsForHandleFromMap($handle),
186
+			$translations
187
+		);
188
+		$translations[''] = $index;
189
+		return $translations;
190
+	}
191
+
192
+
193
+	/**
194
+	 * Get locale data for given strings from given translations
195
+	 *
196
+	 * @param array $string_set   This is the subset of strings (msgIds) we want to extract from the translations array.
197
+	 * @param array $translations Translation data to extra strings from.
198
+	 * @return array
199
+	 */
200
+	protected function getLocaleDataMatchingMap(array $string_set, array $translations)
201
+	{
202
+		if (empty($string_set)) {
203
+			return array();
204
+		}
205
+		// some strings with quotes in them will break on the array_flip, so making sure quotes in the string are
206
+		// slashed also filter falsey values.
207
+		$string_set = array_unique(array_filter(wp_slash($string_set)));
208
+		return array_intersect_key($translations, array_flip($string_set));
209
+	}
210
+
211
+
212
+	/**
213
+	 * Get original strings to translate for the given chunk from the map
214
+	 *
215
+	 * @param string $handle The script handle name to get strings from the map for.
216
+	 * @return array
217
+	 */
218
+	protected function getOriginalStringsForHandleFromMap($handle)
219
+	{
220
+		return isset($this->i18n_map[$handle]) ? $this->i18n_map[$handle] : array();
221
+	}
222
+
223
+
224
+	/**
225
+	 * Returns Jed-formatted localization data.
226
+	 *
227
+	 * @param  string $domain Translation domain.
228
+	 * @return array
229
+	 */
230
+	private function getJedLocaleData($domain)
231
+	{
232
+		$translations = get_translations_for_domain($domain);
233
+
234
+		$locale = array(
235
+			'' => array(
236
+				'domain' => $domain,
237
+				'lang'   => is_admin() ? get_user_locale() : get_locale(),
238
+			),
239
+		);
240
+
241
+		if (! empty($translations->headers['Plural-Forms'])) {
242
+			$locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
243
+		}
244
+
245
+		foreach ($translations->entries as $msgid => $entry) {
246
+			$locale[$msgid] = $entry->translations;
247
+		}
248
+
249
+		return $locale;
250
+	}
251 251
 }
252 252
\ No newline at end of file
Please login to merge, or discard this patch.
core/services/assets/AssetManager.php 1 patch
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -21,142 +21,142 @@
 block discarded – undo
21 21
 abstract class AssetManager implements AssetManagerInterface
22 22
 {
23 23
 
24
-    /**
25
-     * @var AssetCollection $assets
26
-     */
27
-    protected $assets;
28
-
29
-    /**
30
-     * @var DomainInterface
31
-     */
32
-    protected $domain;
33
-
34
-    /**
35
-     * @var Registry $registry
36
-     */
37
-    protected $registry;
38
-
39
-
40
-    /**
41
-     * AssetRegister constructor.
42
-     *
43
-     * @param DomainInterface $domain
44
-     * @param AssetCollection $assets
45
-     * @param Registry        $registry
46
-     */
47
-    public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry)
48
-    {
49
-        $this->domain = $domain;
50
-        $this->assets = $assets;
51
-        $this->registry = $registry;
52
-        add_action('wp_enqueue_scripts', array($this, 'addManifestFile'), 0);
53
-        add_action('admin_enqueue_scripts', array($this, 'addManifestFile'), 0);
54
-        add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2);
55
-        add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2);
56
-    }
57
-
58
-
59
-    /**
60
-     * @return void
61
-     * @throws DuplicateCollectionIdentifierException
62
-     * @throws InvalidDataTypeException
63
-     * @throws InvalidEntityException
64
-     * @since 4.9.62.p
65
-     */
66
-    public function addManifestFile()
67
-    {
68
-        // if a manifest file has already been added for this domain, then just return that one
69
-        if ($this->assets->has($this->domain->assetNamespace())) {
70
-            return;
71
-        }
72
-        $asset = new ManifestFile($this->domain);
73
-        $this->assets->add($asset, $this->domain->assetNamespace());
74
-    }
75
-
76
-
77
-    /**
78
-     * @return ManifestFile[]
79
-     * @since 4.9.62.p
80
-     */
81
-    public function getManifestFile()
82
-    {
83
-        return $this->assets->getManifestFiles();
84
-    }
85
-
86
-
87
-    /**
88
-     * @param string $handle
89
-     * @param string $source
90
-     * @param array  $dependencies
91
-     * @param bool   $load_in_footer
92
-     * @return JavascriptAsset
93
-     * @throws DuplicateCollectionIdentifierException
94
-     * @throws InvalidDataTypeException
95
-     * @throws InvalidEntityException
96
-     * @since 4.9.62.p
97
-     */
98
-    public function addJavascript(
99
-        $handle,
100
-        $source,
101
-        array $dependencies = array(),
102
-        $load_in_footer = true
103
-    ) {
104
-        $asset = new JavascriptAsset(
105
-            $handle,
106
-            $source,
107
-            $dependencies,
108
-            $load_in_footer,
109
-            $this->domain
110
-        );
111
-        $this->assets->add($asset, $handle);
112
-        return $asset;
113
-    }
114
-
115
-
116
-
117
-    /**
118
-     * @param string $handle
119
-     * @param string $source
120
-     * @param array  $dependencies
121
-     * @param string $media
122
-     * @return StylesheetAsset
123
-     * @throws DuplicateCollectionIdentifierException
124
-     * @throws InvalidDataTypeException
125
-     * @throws InvalidEntityException
126
-     * @since 4.9.62.p
127
-     */
128
-    public function addStylesheet(
129
-        $handle,
130
-        $source,
131
-        array $dependencies = array(),
132
-        $media = 'all'
133
-    ) {
134
-        $asset = new StylesheetAsset(
135
-            $handle,
136
-            $source,
137
-            $dependencies,
138
-            $this->domain,
139
-            $media
140
-        );
141
-        $this->assets->add($asset, $handle);
142
-        return $asset;
143
-    }
144
-
145
-
146
-    /**
147
-     * @param string $handle
148
-     * @return bool
149
-     * @since 4.9.62.p
150
-     */
151
-    public function enqueueAsset($handle)
152
-    {
153
-        if ($this->assets->has($handle)) {
154
-            $asset = $this->assets->get($handle);
155
-            if ($asset->isRegistered()) {
156
-                $asset->enqueueAsset();
157
-                return true;
158
-            }
159
-        }
160
-        return false;
161
-    }
24
+	/**
25
+	 * @var AssetCollection $assets
26
+	 */
27
+	protected $assets;
28
+
29
+	/**
30
+	 * @var DomainInterface
31
+	 */
32
+	protected $domain;
33
+
34
+	/**
35
+	 * @var Registry $registry
36
+	 */
37
+	protected $registry;
38
+
39
+
40
+	/**
41
+	 * AssetRegister constructor.
42
+	 *
43
+	 * @param DomainInterface $domain
44
+	 * @param AssetCollection $assets
45
+	 * @param Registry        $registry
46
+	 */
47
+	public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry)
48
+	{
49
+		$this->domain = $domain;
50
+		$this->assets = $assets;
51
+		$this->registry = $registry;
52
+		add_action('wp_enqueue_scripts', array($this, 'addManifestFile'), 0);
53
+		add_action('admin_enqueue_scripts', array($this, 'addManifestFile'), 0);
54
+		add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2);
55
+		add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2);
56
+	}
57
+
58
+
59
+	/**
60
+	 * @return void
61
+	 * @throws DuplicateCollectionIdentifierException
62
+	 * @throws InvalidDataTypeException
63
+	 * @throws InvalidEntityException
64
+	 * @since 4.9.62.p
65
+	 */
66
+	public function addManifestFile()
67
+	{
68
+		// if a manifest file has already been added for this domain, then just return that one
69
+		if ($this->assets->has($this->domain->assetNamespace())) {
70
+			return;
71
+		}
72
+		$asset = new ManifestFile($this->domain);
73
+		$this->assets->add($asset, $this->domain->assetNamespace());
74
+	}
75
+
76
+
77
+	/**
78
+	 * @return ManifestFile[]
79
+	 * @since 4.9.62.p
80
+	 */
81
+	public function getManifestFile()
82
+	{
83
+		return $this->assets->getManifestFiles();
84
+	}
85
+
86
+
87
+	/**
88
+	 * @param string $handle
89
+	 * @param string $source
90
+	 * @param array  $dependencies
91
+	 * @param bool   $load_in_footer
92
+	 * @return JavascriptAsset
93
+	 * @throws DuplicateCollectionIdentifierException
94
+	 * @throws InvalidDataTypeException
95
+	 * @throws InvalidEntityException
96
+	 * @since 4.9.62.p
97
+	 */
98
+	public function addJavascript(
99
+		$handle,
100
+		$source,
101
+		array $dependencies = array(),
102
+		$load_in_footer = true
103
+	) {
104
+		$asset = new JavascriptAsset(
105
+			$handle,
106
+			$source,
107
+			$dependencies,
108
+			$load_in_footer,
109
+			$this->domain
110
+		);
111
+		$this->assets->add($asset, $handle);
112
+		return $asset;
113
+	}
114
+
115
+
116
+
117
+	/**
118
+	 * @param string $handle
119
+	 * @param string $source
120
+	 * @param array  $dependencies
121
+	 * @param string $media
122
+	 * @return StylesheetAsset
123
+	 * @throws DuplicateCollectionIdentifierException
124
+	 * @throws InvalidDataTypeException
125
+	 * @throws InvalidEntityException
126
+	 * @since 4.9.62.p
127
+	 */
128
+	public function addStylesheet(
129
+		$handle,
130
+		$source,
131
+		array $dependencies = array(),
132
+		$media = 'all'
133
+	) {
134
+		$asset = new StylesheetAsset(
135
+			$handle,
136
+			$source,
137
+			$dependencies,
138
+			$this->domain,
139
+			$media
140
+		);
141
+		$this->assets->add($asset, $handle);
142
+		return $asset;
143
+	}
144
+
145
+
146
+	/**
147
+	 * @param string $handle
148
+	 * @return bool
149
+	 * @since 4.9.62.p
150
+	 */
151
+	public function enqueueAsset($handle)
152
+	{
153
+		if ($this->assets->has($handle)) {
154
+			$asset = $this->assets->get($handle);
155
+			if ($asset->isRegistered()) {
156
+				$asset->enqueueAsset();
157
+				return true;
158
+			}
159
+		}
160
+		return false;
161
+	}
162 162
 }
Please login to merge, or discard this patch.
core/services/assets/AssetManagerInterface.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -20,72 +20,72 @@
 block discarded – undo
20 20
 interface AssetManagerInterface
21 21
 {
22 22
 
23
-    /**
24
-     * @since 4.9.62.p
25
-     */
26
-    public function addAssets();
23
+	/**
24
+	 * @since 4.9.62.p
25
+	 */
26
+	public function addAssets();
27 27
 
28 28
 
29
-    /**
30
-     * @return ManifestFile
31
-     * @throws DuplicateCollectionIdentifierException
32
-     * @throws InvalidDataTypeException
33
-     * @throws InvalidEntityException
34
-     * @since 4.9.62.p
35
-     */
36
-    public function addManifestFile();
29
+	/**
30
+	 * @return ManifestFile
31
+	 * @throws DuplicateCollectionIdentifierException
32
+	 * @throws InvalidDataTypeException
33
+	 * @throws InvalidEntityException
34
+	 * @since 4.9.62.p
35
+	 */
36
+	public function addManifestFile();
37 37
 
38 38
 
39
-    /**
40
-     * @return ManifestFile[]
41
-     * @since 4.9.62.p
42
-     */
43
-    public function getManifestFile();
39
+	/**
40
+	 * @return ManifestFile[]
41
+	 * @since 4.9.62.p
42
+	 */
43
+	public function getManifestFile();
44 44
 
45 45
 
46
-    /**
47
-     * @param string $handle
48
-     * @param string $source
49
-     * @param array  $dependencies
50
-     * @param bool   $load_in_footer
51
-     * @return JavascriptAsset
52
-     * @throws DuplicateCollectionIdentifierException
53
-     * @throws InvalidDataTypeException
54
-     * @throws InvalidEntityException
55
-     * @since 4.9.62.p
56
-     */
57
-    public function addJavascript(
58
-        $handle,
59
-        $source,
60
-        array $dependencies = array(),
61
-        $load_in_footer = true
62
-    );
46
+	/**
47
+	 * @param string $handle
48
+	 * @param string $source
49
+	 * @param array  $dependencies
50
+	 * @param bool   $load_in_footer
51
+	 * @return JavascriptAsset
52
+	 * @throws DuplicateCollectionIdentifierException
53
+	 * @throws InvalidDataTypeException
54
+	 * @throws InvalidEntityException
55
+	 * @since 4.9.62.p
56
+	 */
57
+	public function addJavascript(
58
+		$handle,
59
+		$source,
60
+		array $dependencies = array(),
61
+		$load_in_footer = true
62
+	);
63 63
 
64 64
 
65 65
 
66
-    /**
67
-     * @param string $handle
68
-     * @param string $source
69
-     * @param array  $dependencies
70
-     * @param string $media
71
-     * @return StylesheetAsset
72
-     * @throws DuplicateCollectionIdentifierException
73
-     * @throws InvalidDataTypeException
74
-     * @throws InvalidEntityException
75
-     * @since 4.9.62.p
76
-     */
77
-    public function addStylesheet(
78
-        $handle,
79
-        $source,
80
-        array $dependencies = array(),
81
-        $media = 'all'
82
-    );
66
+	/**
67
+	 * @param string $handle
68
+	 * @param string $source
69
+	 * @param array  $dependencies
70
+	 * @param string $media
71
+	 * @return StylesheetAsset
72
+	 * @throws DuplicateCollectionIdentifierException
73
+	 * @throws InvalidDataTypeException
74
+	 * @throws InvalidEntityException
75
+	 * @since 4.9.62.p
76
+	 */
77
+	public function addStylesheet(
78
+		$handle,
79
+		$source,
80
+		array $dependencies = array(),
81
+		$media = 'all'
82
+	);
83 83
 
84 84
 
85
-    /**
86
-     * @param string $handle
87
-     * @return bool
88
-     * @since 4.9.62.p
89
-     */
90
-    public function enqueueAsset($handle);
85
+	/**
86
+	 * @param string $handle
87
+	 * @return bool
88
+	 * @since 4.9.62.p
89
+	 */
90
+	public function enqueueAsset($handle);
91 91
 }
Please login to merge, or discard this patch.
core/CPTs/CptQueryModifier.php 2 patches
Indentation   +565 added lines, -565 removed lines patch added patch discarded remove patch
@@ -28,569 +28,569 @@
 block discarded – undo
28 28
 class CptQueryModifier
29 29
 {
30 30
 
31
-    /**
32
-     * @var string $post_type
33
-     */
34
-    protected $post_type = '';
35
-
36
-    /**
37
-     * CPT details from CustomPostTypeDefinitions for specific post type
38
-     *
39
-     * @var array $cpt_details
40
-     */
41
-    protected $cpt_details = array();
42
-
43
-    /**
44
-     * @var EE_Table_Base[] $model_tables
45
-     */
46
-    protected $model_tables = array();
47
-
48
-    /**
49
-     * @var array $taxonomies
50
-     */
51
-    protected $taxonomies = array();
52
-
53
-    /**
54
-     * meta table for the related CPT
55
-     *
56
-     * @var EE_Secondary_Table $meta_table
57
-     */
58
-    protected $meta_table;
59
-
60
-    /**
61
-     * EEM_CPT_Base model for the related CPT
62
-     *
63
-     * @var EEM_CPT_Base $model
64
-     */
65
-    protected $model;
66
-
67
-    /**
68
-     * @var EE_Request_Handler $request_handler
69
-     */
70
-    protected $request_handler;
71
-
72
-    /**
73
-     * @var WP_Query $wp_query
74
-     */
75
-    protected $wp_query;
76
-
77
-    /**
78
-     * @var LoaderInterface $loader
79
-     */
80
-    protected $loader;
81
-
82
-    /**
83
-     * @var RequestInterface $request
84
-     */
85
-    protected $request;
86
-
87
-
88
-    /**
89
-     * CptQueryModifier constructor
90
-     *
91
-     * @param string             $post_type
92
-     * @param array              $cpt_details
93
-     * @param WP_Query           $WP_Query
94
-     * @param EE_Request_Handler $request_handler
95
-     * @param RequestInterface   $request
96
-     * @param LoaderInterface    $loader
97
-     * @throws EE_Error
98
-     */
99
-    public function __construct(
100
-        $post_type,
101
-        array $cpt_details,
102
-        WP_Query $WP_Query,
103
-        EE_Request_Handler $request_handler,
104
-        RequestInterface $request,
105
-        LoaderInterface $loader
106
-    ) {
107
-        $this->loader = $loader;
108
-        $this->request = $request;
109
-        $this->request_handler = $request_handler;
110
-        $this->setWpQuery($WP_Query);
111
-        $this->setPostType($post_type);
112
-        $this->setCptDetails($cpt_details);
113
-        $this->init();
114
-    }
115
-
116
-
117
-    /**
118
-     * @return string
119
-     */
120
-    public function postType()
121
-    {
122
-        return $this->post_type;
123
-    }
124
-
125
-
126
-    /**
127
-     * @param string $post_type
128
-     */
129
-    protected function setPostType($post_type)
130
-    {
131
-        $this->post_type = $post_type;
132
-    }
133
-
134
-
135
-    /**
136
-     * @return array
137
-     */
138
-    public function cptDetails()
139
-    {
140
-        return $this->cpt_details;
141
-    }
142
-
143
-
144
-    /**
145
-     * @param array $cpt_details
146
-     */
147
-    protected function setCptDetails($cpt_details)
148
-    {
149
-        $this->cpt_details = $cpt_details;
150
-    }
151
-
152
-
153
-    /**
154
-     * @return EE_Table_Base[]
155
-     */
156
-    public function modelTables()
157
-    {
158
-        return $this->model_tables;
159
-    }
160
-
161
-
162
-    /**
163
-     * @param EE_Table_Base[] $model_tables
164
-     */
165
-    protected function setModelTables($model_tables)
166
-    {
167
-        $this->model_tables = $model_tables;
168
-    }
169
-
170
-
171
-    /**
172
-     * @return array
173
-     * @throws InvalidArgumentException
174
-     * @throws InvalidDataTypeException
175
-     * @throws InvalidInterfaceException
176
-     */
177
-    public function taxonomies()
178
-    {
179
-        if (empty($this->taxonomies)) {
180
-            $this->initializeTaxonomies();
181
-        }
182
-        return $this->taxonomies;
183
-    }
184
-
185
-
186
-    /**
187
-     * @param array $taxonomies
188
-     */
189
-    protected function setTaxonomies(array $taxonomies)
190
-    {
191
-        $this->taxonomies = $taxonomies;
192
-    }
193
-
194
-
195
-    /**
196
-     * @return EE_Secondary_Table
197
-     */
198
-    public function metaTable()
199
-    {
200
-        return $this->meta_table;
201
-    }
202
-
203
-
204
-    /**
205
-     * @param EE_Secondary_Table $meta_table
206
-     */
207
-    public function setMetaTable(EE_Secondary_Table $meta_table)
208
-    {
209
-        $this->meta_table = $meta_table;
210
-    }
211
-
212
-
213
-    /**
214
-     * @return EEM_Base
215
-     */
216
-    public function model()
217
-    {
218
-        return $this->model;
219
-    }
220
-
221
-
222
-    /**
223
-     * @param EEM_Base $CPT_model
224
-     */
225
-    protected function setModel(EEM_Base $CPT_model)
226
-    {
227
-        $this->model = $CPT_model;
228
-    }
229
-
230
-
231
-    /**
232
-     * @deprecated $VID:$
233
-     * @return EE_Request_Handler
234
-     */
235
-    public function request()
236
-    {
237
-        return $this->request_handler;
238
-    }
239
-
240
-
241
-
242
-    // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
243
-
244
-
245
-    /**
246
-     * @return WP_Query
247
-     */
248
-    public function WpQuery()
249
-    {
250
-        return $this->wp_query;
251
-    }
252
-    // phpcs:enable
253
-
254
-
255
-    /**
256
-     * @param WP_Query $wp_query
257
-     */
258
-    public function setWpQuery(WP_Query $wp_query)
259
-    {
260
-        $this->wp_query = $wp_query;
261
-    }
262
-
263
-
264
-    /**
265
-     * @return void
266
-     * @throws InvalidDataTypeException
267
-     * @throws InvalidInterfaceException
268
-     * @throws InvalidArgumentException
269
-     */
270
-    protected function initializeTaxonomies()
271
-    {
272
-        // check if taxonomies have already been set and that this CPT has taxonomies registered for it
273
-        if (empty($this->taxonomies)
274
-            && isset($this->cpt_details['args']['taxonomies'])
275
-        ) {
276
-            // if so then grab them, but we want the taxonomy name as the key
277
-            $taxonomies = array_flip($this->cpt_details['args']['taxonomies']);
278
-            // then grab the list of ALL taxonomies
279
-            /** @var \EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions
280
-             * $taxonomy_definitions
281
-             */
282
-            $taxonomy_definitions = $this->loader->getShared(
283
-                'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'
284
-            );
285
-            $all_taxonomies = $taxonomy_definitions->getCustomTaxonomyDefinitions();
286
-            foreach ($taxonomies as $taxonomy => &$details) {
287
-                // add details to our taxonomies if they exist
288
-                $details = isset($all_taxonomies[ $taxonomy ])
289
-                    ? $all_taxonomies[ $taxonomy ]
290
-                    : array();
291
-            }
292
-            // ALWAYS unset() variables that were passed by reference
293
-            unset($details);
294
-            $this->setTaxonomies($taxonomies);
295
-        }
296
-    }
297
-
298
-
299
-    /**
300
-     * @since $VID:$
301
-     * @throws EE_Error
302
-     */
303
-    protected function init()
304
-    {
305
-        $this->setAdditionalCptDetails();
306
-        $this->setRequestVarsIfCpt();
307
-        // convert post_type to model name
308
-        $model_name = str_replace('EE_', '', $this->cpt_details['class_name']);
309
-        // load all tables related to CPT
310
-        $this->setupModelsAndTables($model_name);
311
-        // load and instantiate CPT_*_Strategy
312
-        $CPT_Strategy = $this->cptStrategyClass($model_name);
313
-        // !!!!!!!!!!  IMPORTANT !!!!!!!!!!!!
314
-        // here's the list of available filters in the WP_Query object
315
-        // 'posts_where_paged'
316
-        // 'posts_groupby'
317
-        // 'posts_join_paged'
318
-        // 'posts_orderby'
319
-        // 'posts_distinct'
320
-        // 'post_limits'
321
-        // 'posts_fields'
322
-        // 'posts_join'
323
-        add_filter('posts_fields', array($this, 'postsFields'));
324
-        add_filter('posts_join', array($this, 'postsJoin'));
325
-        add_filter(
326
-            'get_' . $this->post_type . '_metadata',
327
-            array($CPT_Strategy, 'get_EE_post_type_metadata'),
328
-            1,
329
-            4
330
-        );
331
-        add_filter('the_posts', array($this, 'thePosts'), 1, 1);
332
-        if ($this->wp_query->is_main_query()) {
333
-            add_filter('get_edit_post_link', array($this, 'getEditPostLink'), 10, 2);
334
-            $this->addTemplateFilters();
335
-        }
336
-    }
337
-
338
-
339
-    /**
340
-     * sets some basic query vars that pertain to the CPT
341
-     *
342
-     * @access protected
343
-     * @return void
344
-     */
345
-    protected function setAdditionalCptDetails()
346
-    {
347
-        // the post or category or term that is triggering EE
348
-        $this->cpt_details['espresso_page'] = $this->request_handler->is_espresso_page();
349
-        // requested post name
350
-        $this->cpt_details['post_name'] = $this->request->getRequestParam('post_name');
351
-        // add support for viewing 'private', 'draft', or 'pending' posts
352
-        if (isset($this->wp_query->query_vars['p'])
353
-            && $this->wp_query->query_vars['p'] !== 0
354
-            && is_user_logged_in()
355
-            && current_user_can('edit_post', $this->wp_query->query_vars['p'])
356
-        ) {
357
-            // we can just inject directly into the WP_Query object
358
-            $this->wp_query->query['post_status'] = array('publish', 'private', 'draft', 'pending');
359
-            // now set the main 'ee' request var so that the appropriate module can load the appropriate template(s)
360
-            $this->request->setRequestParam('ee', $this->cpt_details['singular_slug']);
361
-        }
362
-    }
363
-
364
-
365
-    /**
366
-     * Checks if we're on a EE-CPT archive-or-single page, and if we've never set the EE request var.
367
-     * If so, sets the 'ee' request variable
368
-     * so other parts of EE can know what CPT is getting queried.
369
-     * To Mike's knowledge, this must be called from during or after the pre_get_posts hook
370
-     * in order for is_archive() and is_single() methods to work properly.
371
-     *
372
-     * @return void
373
-     */
374
-    public function setRequestVarsIfCpt()
375
-    {
376
-        // check if ee action var has been set
377
-        if (! $this->request->requestParamIsSet('ee')) {
378
-            // check that route exists for CPT archive slug
379
-            if (is_archive() && EE_Config::get_route($this->cpt_details['plural_slug'])) {
380
-                // ie: set "ee" to "events"
381
-                $this->request->setRequestParam('ee', $this->cpt_details['plural_slug']);
382
-                // or does it match a single page CPT like /event/
383
-            } elseif (is_single() && EE_Config::get_route($this->cpt_details['singular_slug'])) {
384
-                // ie: set "ee" to "event"
385
-                $this->request->setRequestParam('ee', $this->cpt_details['singular_slug']);
386
-            }
387
-        }
388
-    }
389
-
390
-
391
-    /**
392
-     * setupModelsAndTables
393
-     *
394
-     * @access protected
395
-     * @param string $model_name
396
-     * @throws EE_Error
397
-     */
398
-    protected function setupModelsAndTables($model_name)
399
-    {
400
-        // get CPT table data via CPT Model
401
-        $full_model_name = strpos($model_name, 'EEM_') !== 0
402
-            ? 'EEM_' . $model_name
403
-            : $model_name;
404
-        $model = $this->loader->getShared($full_model_name);
405
-        if (! $model instanceof EEM_Base) {
406
-            throw new EE_Error(
407
-                sprintf(
408
-                    __(
409
-                        'The "%1$s" model could not be loaded.',
410
-                        'event_espresso'
411
-                    ),
412
-                    $full_model_name
413
-                )
414
-            );
415
-        }
416
-        $this->setModel($model);
417
-        $this->setModelTables($this->model->get_tables());
418
-        $meta_model = $model_name . '_Meta';
419
-        // is there a Meta Table for this CPT?
420
-        if (isset($this->cpt_details['tables'][ $meta_model ])
421
-            && $this->cpt_details['tables'][ $meta_model ] instanceof EE_Secondary_Table
422
-        ) {
423
-            $this->setMetaTable($this->cpt_details['tables'][ $meta_model ]);
424
-        }
425
-    }
426
-
427
-
428
-    /**
429
-     * cptStrategyClass
430
-     *
431
-     * @access protected
432
-     * @param  string $model_name
433
-     * @return string
434
-     */
435
-    protected function cptStrategyClass($model_name)
436
-    {
437
-        // creates classname like:  CPT_Event_Strategy
438
-        $CPT_Strategy_class_name = 'EE_CPT_' . $model_name . '_Strategy';
439
-        // load and instantiate
440
-        $CPT_Strategy = $this->loader->getShared(
441
-            $CPT_Strategy_class_name,
442
-            array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details)
443
-        );
444
-        if ($CPT_Strategy === null) {
445
-            $CPT_Strategy = $this->loader->getShared(
446
-                'EE_CPT_Default_Strategy',
447
-                array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details)
448
-            );
449
-        }
450
-        return $CPT_Strategy;
451
-    }
452
-
453
-
454
-    /**
455
-     * postsFields
456
-     *
457
-     * @access public
458
-     * @param  $SQL
459
-     * @return string
460
-     */
461
-    public function postsFields($SQL)
462
-    {
463
-        // does this CPT have a meta table ?
464
-        if ($this->meta_table instanceof EE_Secondary_Table) {
465
-            // adds something like ", wp_esp_event_meta.* " to WP Query SELECT statement
466
-            $SQL .= ', ' . $this->meta_table->get_table_name() . '.* ';
467
-        }
468
-        remove_filter('posts_fields', array($this, 'postsFields'));
469
-        return $SQL;
470
-    }
471
-
472
-
473
-    /**
474
-     * postsJoin
475
-     *
476
-     * @access public
477
-     * @param  $SQL
478
-     * @return string
479
-     */
480
-    public function postsJoin($SQL)
481
-    {
482
-        // does this CPT have a meta table ?
483
-        if ($this->meta_table instanceof EE_Secondary_Table) {
484
-            global $wpdb;
485
-            // adds something like " LEFT JOIN wp_esp_event_meta ON ( wp_esp_event_meta.EVT_ID = wp_posts.ID ) " to WP Query JOIN statement
486
-            $SQL .= ' LEFT JOIN '
487
-                    . $this->meta_table->get_table_name()
488
-                    . ' ON ( '
489
-                    . $this->meta_table->get_table_name()
490
-                    . '.'
491
-                    . $this->meta_table->get_fk_on_table()
492
-                    . ' = '
493
-                    . $wpdb->posts
494
-                    . '.ID ) ';
495
-        }
496
-        remove_filter('posts_join', array($this, 'postsJoin'));
497
-        return $SQL;
498
-    }
499
-
500
-
501
-    /**
502
-     * thePosts
503
-     *
504
-     * @access public
505
-     * @param  WP_Post[] $posts
506
-     * @return WP_Post[]
507
-     */
508
-    public function thePosts($posts)
509
-    {
510
-        $CPT_class = $this->cpt_details['class_name'];
511
-        // loop thru posts
512
-        if (is_array($posts) && $this->model instanceof EEM_CPT_Base) {
513
-            foreach ($posts as $key => $post) {
514
-                if ($post->post_type === $this->post_type) {
515
-                    $post->{$CPT_class} = $this->model->instantiate_class_from_post_object($post);
516
-                }
517
-            }
518
-        }
519
-        remove_filter('the_posts', array($this, 'thePosts'), 1);
520
-        return $posts;
521
-    }
522
-
523
-
524
-    /**
525
-     * @param $url
526
-     * @param $ID
527
-     * @return string
528
-     */
529
-    public function getEditPostLink($url, $ID)
530
-    {
531
-        // need to make sure we only edit links if our cpt
532
-        global $post;
533
-        // notice if the cpt is registered with `show_ee_ui` set to false, we take that to mean that the WordPress core ui
534
-        // for interacting with the CPT is desired and there is no EE UI for interacting with the CPT in the admin.
535
-        if (! $post instanceof WP_Post
536
-            || $post->post_type !== $this->post_type
537
-            || (
538
-                isset($this->cpt_details['args']['show_ee_ui'])
539
-                && ! $this->cpt_details['args']['show_ee_ui']
540
-            )
541
-        ) {
542
-            return $url;
543
-        }
544
-        // k made it here so all is good.
545
-        return wp_nonce_url(
546
-            add_query_arg(
547
-                array('page' => $this->post_type, 'post' => $ID, 'action' => 'edit'),
548
-                admin_url('admin.php')
549
-            ),
550
-            'edit',
551
-            'edit_nonce'
552
-        );
553
-    }
554
-
555
-
556
-    /**
557
-     * Execute any template filters.
558
-     * This method is only called if in main query.
559
-     *
560
-     * @return void
561
-     */
562
-    public function addTemplateFilters()
563
-    {
564
-        // if requested cpt supports page_templates and it's the main query
565
-        if (! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) {
566
-            // then let's hook into the appropriate query_template hook
567
-            add_filter('single_template', array($this, 'singleCptTemplate'));
568
-        }
569
-    }
570
-
571
-
572
-    /**
573
-     * Callback for single_template wp filter.
574
-     * This is used to load the set page_template for a single ee cpt if its set.  If "default" then we load the normal
575
-     * hierarchy.
576
-     *
577
-     * @access public
578
-     * @param string $current_template Existing default template path derived for this page call.
579
-     * @return string the path to the full template file.
580
-     */
581
-    public function singleCptTemplate($current_template)
582
-    {
583
-        $object = get_queried_object();
584
-        // does this called object HAVE a page template set that is something other than the default.
585
-        $template = get_post_meta($object->ID, '_wp_page_template', true);
586
-        // exit early if default or not set or invalid path (accounts for theme changes)
587
-        if ($template === 'default'
588
-            || empty($template)
589
-            || ! is_readable(get_stylesheet_directory() . '/' . $template)
590
-        ) {
591
-            return $current_template;
592
-        }
593
-        // made it here so we SHOULD be able to just locate the template and then return it.
594
-        return locate_template(array($template));
595
-    }
31
+	/**
32
+	 * @var string $post_type
33
+	 */
34
+	protected $post_type = '';
35
+
36
+	/**
37
+	 * CPT details from CustomPostTypeDefinitions for specific post type
38
+	 *
39
+	 * @var array $cpt_details
40
+	 */
41
+	protected $cpt_details = array();
42
+
43
+	/**
44
+	 * @var EE_Table_Base[] $model_tables
45
+	 */
46
+	protected $model_tables = array();
47
+
48
+	/**
49
+	 * @var array $taxonomies
50
+	 */
51
+	protected $taxonomies = array();
52
+
53
+	/**
54
+	 * meta table for the related CPT
55
+	 *
56
+	 * @var EE_Secondary_Table $meta_table
57
+	 */
58
+	protected $meta_table;
59
+
60
+	/**
61
+	 * EEM_CPT_Base model for the related CPT
62
+	 *
63
+	 * @var EEM_CPT_Base $model
64
+	 */
65
+	protected $model;
66
+
67
+	/**
68
+	 * @var EE_Request_Handler $request_handler
69
+	 */
70
+	protected $request_handler;
71
+
72
+	/**
73
+	 * @var WP_Query $wp_query
74
+	 */
75
+	protected $wp_query;
76
+
77
+	/**
78
+	 * @var LoaderInterface $loader
79
+	 */
80
+	protected $loader;
81
+
82
+	/**
83
+	 * @var RequestInterface $request
84
+	 */
85
+	protected $request;
86
+
87
+
88
+	/**
89
+	 * CptQueryModifier constructor
90
+	 *
91
+	 * @param string             $post_type
92
+	 * @param array              $cpt_details
93
+	 * @param WP_Query           $WP_Query
94
+	 * @param EE_Request_Handler $request_handler
95
+	 * @param RequestInterface   $request
96
+	 * @param LoaderInterface    $loader
97
+	 * @throws EE_Error
98
+	 */
99
+	public function __construct(
100
+		$post_type,
101
+		array $cpt_details,
102
+		WP_Query $WP_Query,
103
+		EE_Request_Handler $request_handler,
104
+		RequestInterface $request,
105
+		LoaderInterface $loader
106
+	) {
107
+		$this->loader = $loader;
108
+		$this->request = $request;
109
+		$this->request_handler = $request_handler;
110
+		$this->setWpQuery($WP_Query);
111
+		$this->setPostType($post_type);
112
+		$this->setCptDetails($cpt_details);
113
+		$this->init();
114
+	}
115
+
116
+
117
+	/**
118
+	 * @return string
119
+	 */
120
+	public function postType()
121
+	{
122
+		return $this->post_type;
123
+	}
124
+
125
+
126
+	/**
127
+	 * @param string $post_type
128
+	 */
129
+	protected function setPostType($post_type)
130
+	{
131
+		$this->post_type = $post_type;
132
+	}
133
+
134
+
135
+	/**
136
+	 * @return array
137
+	 */
138
+	public function cptDetails()
139
+	{
140
+		return $this->cpt_details;
141
+	}
142
+
143
+
144
+	/**
145
+	 * @param array $cpt_details
146
+	 */
147
+	protected function setCptDetails($cpt_details)
148
+	{
149
+		$this->cpt_details = $cpt_details;
150
+	}
151
+
152
+
153
+	/**
154
+	 * @return EE_Table_Base[]
155
+	 */
156
+	public function modelTables()
157
+	{
158
+		return $this->model_tables;
159
+	}
160
+
161
+
162
+	/**
163
+	 * @param EE_Table_Base[] $model_tables
164
+	 */
165
+	protected function setModelTables($model_tables)
166
+	{
167
+		$this->model_tables = $model_tables;
168
+	}
169
+
170
+
171
+	/**
172
+	 * @return array
173
+	 * @throws InvalidArgumentException
174
+	 * @throws InvalidDataTypeException
175
+	 * @throws InvalidInterfaceException
176
+	 */
177
+	public function taxonomies()
178
+	{
179
+		if (empty($this->taxonomies)) {
180
+			$this->initializeTaxonomies();
181
+		}
182
+		return $this->taxonomies;
183
+	}
184
+
185
+
186
+	/**
187
+	 * @param array $taxonomies
188
+	 */
189
+	protected function setTaxonomies(array $taxonomies)
190
+	{
191
+		$this->taxonomies = $taxonomies;
192
+	}
193
+
194
+
195
+	/**
196
+	 * @return EE_Secondary_Table
197
+	 */
198
+	public function metaTable()
199
+	{
200
+		return $this->meta_table;
201
+	}
202
+
203
+
204
+	/**
205
+	 * @param EE_Secondary_Table $meta_table
206
+	 */
207
+	public function setMetaTable(EE_Secondary_Table $meta_table)
208
+	{
209
+		$this->meta_table = $meta_table;
210
+	}
211
+
212
+
213
+	/**
214
+	 * @return EEM_Base
215
+	 */
216
+	public function model()
217
+	{
218
+		return $this->model;
219
+	}
220
+
221
+
222
+	/**
223
+	 * @param EEM_Base $CPT_model
224
+	 */
225
+	protected function setModel(EEM_Base $CPT_model)
226
+	{
227
+		$this->model = $CPT_model;
228
+	}
229
+
230
+
231
+	/**
232
+	 * @deprecated $VID:$
233
+	 * @return EE_Request_Handler
234
+	 */
235
+	public function request()
236
+	{
237
+		return $this->request_handler;
238
+	}
239
+
240
+
241
+
242
+	// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
243
+
244
+
245
+	/**
246
+	 * @return WP_Query
247
+	 */
248
+	public function WpQuery()
249
+	{
250
+		return $this->wp_query;
251
+	}
252
+	// phpcs:enable
253
+
254
+
255
+	/**
256
+	 * @param WP_Query $wp_query
257
+	 */
258
+	public function setWpQuery(WP_Query $wp_query)
259
+	{
260
+		$this->wp_query = $wp_query;
261
+	}
262
+
263
+
264
+	/**
265
+	 * @return void
266
+	 * @throws InvalidDataTypeException
267
+	 * @throws InvalidInterfaceException
268
+	 * @throws InvalidArgumentException
269
+	 */
270
+	protected function initializeTaxonomies()
271
+	{
272
+		// check if taxonomies have already been set and that this CPT has taxonomies registered for it
273
+		if (empty($this->taxonomies)
274
+			&& isset($this->cpt_details['args']['taxonomies'])
275
+		) {
276
+			// if so then grab them, but we want the taxonomy name as the key
277
+			$taxonomies = array_flip($this->cpt_details['args']['taxonomies']);
278
+			// then grab the list of ALL taxonomies
279
+			/** @var \EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions
280
+			 * $taxonomy_definitions
281
+			 */
282
+			$taxonomy_definitions = $this->loader->getShared(
283
+				'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'
284
+			);
285
+			$all_taxonomies = $taxonomy_definitions->getCustomTaxonomyDefinitions();
286
+			foreach ($taxonomies as $taxonomy => &$details) {
287
+				// add details to our taxonomies if they exist
288
+				$details = isset($all_taxonomies[ $taxonomy ])
289
+					? $all_taxonomies[ $taxonomy ]
290
+					: array();
291
+			}
292
+			// ALWAYS unset() variables that were passed by reference
293
+			unset($details);
294
+			$this->setTaxonomies($taxonomies);
295
+		}
296
+	}
297
+
298
+
299
+	/**
300
+	 * @since $VID:$
301
+	 * @throws EE_Error
302
+	 */
303
+	protected function init()
304
+	{
305
+		$this->setAdditionalCptDetails();
306
+		$this->setRequestVarsIfCpt();
307
+		// convert post_type to model name
308
+		$model_name = str_replace('EE_', '', $this->cpt_details['class_name']);
309
+		// load all tables related to CPT
310
+		$this->setupModelsAndTables($model_name);
311
+		// load and instantiate CPT_*_Strategy
312
+		$CPT_Strategy = $this->cptStrategyClass($model_name);
313
+		// !!!!!!!!!!  IMPORTANT !!!!!!!!!!!!
314
+		// here's the list of available filters in the WP_Query object
315
+		// 'posts_where_paged'
316
+		// 'posts_groupby'
317
+		// 'posts_join_paged'
318
+		// 'posts_orderby'
319
+		// 'posts_distinct'
320
+		// 'post_limits'
321
+		// 'posts_fields'
322
+		// 'posts_join'
323
+		add_filter('posts_fields', array($this, 'postsFields'));
324
+		add_filter('posts_join', array($this, 'postsJoin'));
325
+		add_filter(
326
+			'get_' . $this->post_type . '_metadata',
327
+			array($CPT_Strategy, 'get_EE_post_type_metadata'),
328
+			1,
329
+			4
330
+		);
331
+		add_filter('the_posts', array($this, 'thePosts'), 1, 1);
332
+		if ($this->wp_query->is_main_query()) {
333
+			add_filter('get_edit_post_link', array($this, 'getEditPostLink'), 10, 2);
334
+			$this->addTemplateFilters();
335
+		}
336
+	}
337
+
338
+
339
+	/**
340
+	 * sets some basic query vars that pertain to the CPT
341
+	 *
342
+	 * @access protected
343
+	 * @return void
344
+	 */
345
+	protected function setAdditionalCptDetails()
346
+	{
347
+		// the post or category or term that is triggering EE
348
+		$this->cpt_details['espresso_page'] = $this->request_handler->is_espresso_page();
349
+		// requested post name
350
+		$this->cpt_details['post_name'] = $this->request->getRequestParam('post_name');
351
+		// add support for viewing 'private', 'draft', or 'pending' posts
352
+		if (isset($this->wp_query->query_vars['p'])
353
+			&& $this->wp_query->query_vars['p'] !== 0
354
+			&& is_user_logged_in()
355
+			&& current_user_can('edit_post', $this->wp_query->query_vars['p'])
356
+		) {
357
+			// we can just inject directly into the WP_Query object
358
+			$this->wp_query->query['post_status'] = array('publish', 'private', 'draft', 'pending');
359
+			// now set the main 'ee' request var so that the appropriate module can load the appropriate template(s)
360
+			$this->request->setRequestParam('ee', $this->cpt_details['singular_slug']);
361
+		}
362
+	}
363
+
364
+
365
+	/**
366
+	 * Checks if we're on a EE-CPT archive-or-single page, and if we've never set the EE request var.
367
+	 * If so, sets the 'ee' request variable
368
+	 * so other parts of EE can know what CPT is getting queried.
369
+	 * To Mike's knowledge, this must be called from during or after the pre_get_posts hook
370
+	 * in order for is_archive() and is_single() methods to work properly.
371
+	 *
372
+	 * @return void
373
+	 */
374
+	public function setRequestVarsIfCpt()
375
+	{
376
+		// check if ee action var has been set
377
+		if (! $this->request->requestParamIsSet('ee')) {
378
+			// check that route exists for CPT archive slug
379
+			if (is_archive() && EE_Config::get_route($this->cpt_details['plural_slug'])) {
380
+				// ie: set "ee" to "events"
381
+				$this->request->setRequestParam('ee', $this->cpt_details['plural_slug']);
382
+				// or does it match a single page CPT like /event/
383
+			} elseif (is_single() && EE_Config::get_route($this->cpt_details['singular_slug'])) {
384
+				// ie: set "ee" to "event"
385
+				$this->request->setRequestParam('ee', $this->cpt_details['singular_slug']);
386
+			}
387
+		}
388
+	}
389
+
390
+
391
+	/**
392
+	 * setupModelsAndTables
393
+	 *
394
+	 * @access protected
395
+	 * @param string $model_name
396
+	 * @throws EE_Error
397
+	 */
398
+	protected function setupModelsAndTables($model_name)
399
+	{
400
+		// get CPT table data via CPT Model
401
+		$full_model_name = strpos($model_name, 'EEM_') !== 0
402
+			? 'EEM_' . $model_name
403
+			: $model_name;
404
+		$model = $this->loader->getShared($full_model_name);
405
+		if (! $model instanceof EEM_Base) {
406
+			throw new EE_Error(
407
+				sprintf(
408
+					__(
409
+						'The "%1$s" model could not be loaded.',
410
+						'event_espresso'
411
+					),
412
+					$full_model_name
413
+				)
414
+			);
415
+		}
416
+		$this->setModel($model);
417
+		$this->setModelTables($this->model->get_tables());
418
+		$meta_model = $model_name . '_Meta';
419
+		// is there a Meta Table for this CPT?
420
+		if (isset($this->cpt_details['tables'][ $meta_model ])
421
+			&& $this->cpt_details['tables'][ $meta_model ] instanceof EE_Secondary_Table
422
+		) {
423
+			$this->setMetaTable($this->cpt_details['tables'][ $meta_model ]);
424
+		}
425
+	}
426
+
427
+
428
+	/**
429
+	 * cptStrategyClass
430
+	 *
431
+	 * @access protected
432
+	 * @param  string $model_name
433
+	 * @return string
434
+	 */
435
+	protected function cptStrategyClass($model_name)
436
+	{
437
+		// creates classname like:  CPT_Event_Strategy
438
+		$CPT_Strategy_class_name = 'EE_CPT_' . $model_name . '_Strategy';
439
+		// load and instantiate
440
+		$CPT_Strategy = $this->loader->getShared(
441
+			$CPT_Strategy_class_name,
442
+			array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details)
443
+		);
444
+		if ($CPT_Strategy === null) {
445
+			$CPT_Strategy = $this->loader->getShared(
446
+				'EE_CPT_Default_Strategy',
447
+				array('WP_Query' => $this->wp_query, 'CPT' => $this->cpt_details)
448
+			);
449
+		}
450
+		return $CPT_Strategy;
451
+	}
452
+
453
+
454
+	/**
455
+	 * postsFields
456
+	 *
457
+	 * @access public
458
+	 * @param  $SQL
459
+	 * @return string
460
+	 */
461
+	public function postsFields($SQL)
462
+	{
463
+		// does this CPT have a meta table ?
464
+		if ($this->meta_table instanceof EE_Secondary_Table) {
465
+			// adds something like ", wp_esp_event_meta.* " to WP Query SELECT statement
466
+			$SQL .= ', ' . $this->meta_table->get_table_name() . '.* ';
467
+		}
468
+		remove_filter('posts_fields', array($this, 'postsFields'));
469
+		return $SQL;
470
+	}
471
+
472
+
473
+	/**
474
+	 * postsJoin
475
+	 *
476
+	 * @access public
477
+	 * @param  $SQL
478
+	 * @return string
479
+	 */
480
+	public function postsJoin($SQL)
481
+	{
482
+		// does this CPT have a meta table ?
483
+		if ($this->meta_table instanceof EE_Secondary_Table) {
484
+			global $wpdb;
485
+			// adds something like " LEFT JOIN wp_esp_event_meta ON ( wp_esp_event_meta.EVT_ID = wp_posts.ID ) " to WP Query JOIN statement
486
+			$SQL .= ' LEFT JOIN '
487
+					. $this->meta_table->get_table_name()
488
+					. ' ON ( '
489
+					. $this->meta_table->get_table_name()
490
+					. '.'
491
+					. $this->meta_table->get_fk_on_table()
492
+					. ' = '
493
+					. $wpdb->posts
494
+					. '.ID ) ';
495
+		}
496
+		remove_filter('posts_join', array($this, 'postsJoin'));
497
+		return $SQL;
498
+	}
499
+
500
+
501
+	/**
502
+	 * thePosts
503
+	 *
504
+	 * @access public
505
+	 * @param  WP_Post[] $posts
506
+	 * @return WP_Post[]
507
+	 */
508
+	public function thePosts($posts)
509
+	{
510
+		$CPT_class = $this->cpt_details['class_name'];
511
+		// loop thru posts
512
+		if (is_array($posts) && $this->model instanceof EEM_CPT_Base) {
513
+			foreach ($posts as $key => $post) {
514
+				if ($post->post_type === $this->post_type) {
515
+					$post->{$CPT_class} = $this->model->instantiate_class_from_post_object($post);
516
+				}
517
+			}
518
+		}
519
+		remove_filter('the_posts', array($this, 'thePosts'), 1);
520
+		return $posts;
521
+	}
522
+
523
+
524
+	/**
525
+	 * @param $url
526
+	 * @param $ID
527
+	 * @return string
528
+	 */
529
+	public function getEditPostLink($url, $ID)
530
+	{
531
+		// need to make sure we only edit links if our cpt
532
+		global $post;
533
+		// notice if the cpt is registered with `show_ee_ui` set to false, we take that to mean that the WordPress core ui
534
+		// for interacting with the CPT is desired and there is no EE UI for interacting with the CPT in the admin.
535
+		if (! $post instanceof WP_Post
536
+			|| $post->post_type !== $this->post_type
537
+			|| (
538
+				isset($this->cpt_details['args']['show_ee_ui'])
539
+				&& ! $this->cpt_details['args']['show_ee_ui']
540
+			)
541
+		) {
542
+			return $url;
543
+		}
544
+		// k made it here so all is good.
545
+		return wp_nonce_url(
546
+			add_query_arg(
547
+				array('page' => $this->post_type, 'post' => $ID, 'action' => 'edit'),
548
+				admin_url('admin.php')
549
+			),
550
+			'edit',
551
+			'edit_nonce'
552
+		);
553
+	}
554
+
555
+
556
+	/**
557
+	 * Execute any template filters.
558
+	 * This method is only called if in main query.
559
+	 *
560
+	 * @return void
561
+	 */
562
+	public function addTemplateFilters()
563
+	{
564
+		// if requested cpt supports page_templates and it's the main query
565
+		if (! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) {
566
+			// then let's hook into the appropriate query_template hook
567
+			add_filter('single_template', array($this, 'singleCptTemplate'));
568
+		}
569
+	}
570
+
571
+
572
+	/**
573
+	 * Callback for single_template wp filter.
574
+	 * This is used to load the set page_template for a single ee cpt if its set.  If "default" then we load the normal
575
+	 * hierarchy.
576
+	 *
577
+	 * @access public
578
+	 * @param string $current_template Existing default template path derived for this page call.
579
+	 * @return string the path to the full template file.
580
+	 */
581
+	public function singleCptTemplate($current_template)
582
+	{
583
+		$object = get_queried_object();
584
+		// does this called object HAVE a page template set that is something other than the default.
585
+		$template = get_post_meta($object->ID, '_wp_page_template', true);
586
+		// exit early if default or not set or invalid path (accounts for theme changes)
587
+		if ($template === 'default'
588
+			|| empty($template)
589
+			|| ! is_readable(get_stylesheet_directory() . '/' . $template)
590
+		) {
591
+			return $current_template;
592
+		}
593
+		// made it here so we SHOULD be able to just locate the template and then return it.
594
+		return locate_template(array($template));
595
+	}
596 596
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -285,8 +285,8 @@  discard block
 block discarded – undo
285 285
             $all_taxonomies = $taxonomy_definitions->getCustomTaxonomyDefinitions();
286 286
             foreach ($taxonomies as $taxonomy => &$details) {
287 287
                 // add details to our taxonomies if they exist
288
-                $details = isset($all_taxonomies[ $taxonomy ])
289
-                    ? $all_taxonomies[ $taxonomy ]
288
+                $details = isset($all_taxonomies[$taxonomy])
289
+                    ? $all_taxonomies[$taxonomy]
290 290
                     : array();
291 291
             }
292 292
             // ALWAYS unset() variables that were passed by reference
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
         add_filter('posts_fields', array($this, 'postsFields'));
324 324
         add_filter('posts_join', array($this, 'postsJoin'));
325 325
         add_filter(
326
-            'get_' . $this->post_type . '_metadata',
326
+            'get_'.$this->post_type.'_metadata',
327 327
             array($CPT_Strategy, 'get_EE_post_type_metadata'),
328 328
             1,
329 329
             4
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
     public function setRequestVarsIfCpt()
375 375
     {
376 376
         // check if ee action var has been set
377
-        if (! $this->request->requestParamIsSet('ee')) {
377
+        if ( ! $this->request->requestParamIsSet('ee')) {
378 378
             // check that route exists for CPT archive slug
379 379
             if (is_archive() && EE_Config::get_route($this->cpt_details['plural_slug'])) {
380 380
                 // ie: set "ee" to "events"
@@ -399,10 +399,10 @@  discard block
 block discarded – undo
399 399
     {
400 400
         // get CPT table data via CPT Model
401 401
         $full_model_name = strpos($model_name, 'EEM_') !== 0
402
-            ? 'EEM_' . $model_name
402
+            ? 'EEM_'.$model_name
403 403
             : $model_name;
404 404
         $model = $this->loader->getShared($full_model_name);
405
-        if (! $model instanceof EEM_Base) {
405
+        if ( ! $model instanceof EEM_Base) {
406 406
             throw new EE_Error(
407 407
                 sprintf(
408 408
                     __(
@@ -415,12 +415,12 @@  discard block
 block discarded – undo
415 415
         }
416 416
         $this->setModel($model);
417 417
         $this->setModelTables($this->model->get_tables());
418
-        $meta_model = $model_name . '_Meta';
418
+        $meta_model = $model_name.'_Meta';
419 419
         // is there a Meta Table for this CPT?
420
-        if (isset($this->cpt_details['tables'][ $meta_model ])
421
-            && $this->cpt_details['tables'][ $meta_model ] instanceof EE_Secondary_Table
420
+        if (isset($this->cpt_details['tables'][$meta_model])
421
+            && $this->cpt_details['tables'][$meta_model] instanceof EE_Secondary_Table
422 422
         ) {
423
-            $this->setMetaTable($this->cpt_details['tables'][ $meta_model ]);
423
+            $this->setMetaTable($this->cpt_details['tables'][$meta_model]);
424 424
         }
425 425
     }
426 426
 
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
     protected function cptStrategyClass($model_name)
436 436
     {
437 437
         // creates classname like:  CPT_Event_Strategy
438
-        $CPT_Strategy_class_name = 'EE_CPT_' . $model_name . '_Strategy';
438
+        $CPT_Strategy_class_name = 'EE_CPT_'.$model_name.'_Strategy';
439 439
         // load and instantiate
440 440
         $CPT_Strategy = $this->loader->getShared(
441 441
             $CPT_Strategy_class_name,
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
         // does this CPT have a meta table ?
464 464
         if ($this->meta_table instanceof EE_Secondary_Table) {
465 465
             // adds something like ", wp_esp_event_meta.* " to WP Query SELECT statement
466
-            $SQL .= ', ' . $this->meta_table->get_table_name() . '.* ';
466
+            $SQL .= ', '.$this->meta_table->get_table_name().'.* ';
467 467
         }
468 468
         remove_filter('posts_fields', array($this, 'postsFields'));
469 469
         return $SQL;
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
         global $post;
533 533
         // notice if the cpt is registered with `show_ee_ui` set to false, we take that to mean that the WordPress core ui
534 534
         // for interacting with the CPT is desired and there is no EE UI for interacting with the CPT in the admin.
535
-        if (! $post instanceof WP_Post
535
+        if ( ! $post instanceof WP_Post
536 536
             || $post->post_type !== $this->post_type
537 537
             || (
538 538
                 isset($this->cpt_details['args']['show_ee_ui'])
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
     public function addTemplateFilters()
563 563
     {
564 564
         // if requested cpt supports page_templates and it's the main query
565
-        if (! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) {
565
+        if ( ! empty($this->cpt_details['args']['page_templates']) && $this->wp_query->is_main_query()) {
566 566
             // then let's hook into the appropriate query_template hook
567 567
             add_filter('single_template', array($this, 'singleCptTemplate'));
568 568
         }
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
         // exit early if default or not set or invalid path (accounts for theme changes)
587 587
         if ($template === 'default'
588 588
             || empty($template)
589
-            || ! is_readable(get_stylesheet_directory() . '/' . $template)
589
+            || ! is_readable(get_stylesheet_directory().'/'.$template)
590 590
         ) {
591 591
             return $current_template;
592 592
         }
Please login to merge, or discard this patch.
core/CPTs/EE_CPT_Strategy.core.php 2 patches
Indentation   +445 added lines, -445 removed lines patch added patch discarded remove patch
@@ -16,449 +16,449 @@
 block discarded – undo
16 16
 class EE_CPT_Strategy extends EE_Base
17 17
 {
18 18
 
19
-    /**
20
-     * @var EE_CPT_Strategy $_instance
21
-     */
22
-    private static $_instance;
23
-
24
-    /**
25
-     * the current page, if it utilizes CPTs
26
-     *
27
-     * @var array $CPT
28
-     */
29
-    protected $CPT;
30
-
31
-    /**
32
-     * return value from CustomPostTypeDefinitions::getDefinitions()
33
-     *
34
-     * @var array $_CPTs
35
-     */
36
-    protected $_CPTs = array();
37
-
38
-    /**
39
-     * @var array $_CPT_taxonomies
40
-     */
41
-    protected $_CPT_taxonomies = array();
42
-
43
-    /**
44
-     * @var array $_CPT_terms
45
-     */
46
-    protected $_CPT_terms = array();
47
-
48
-    /**
49
-     * @var array $_CPT_endpoints
50
-     */
51
-    protected $_CPT_endpoints = array();
52
-
53
-    /**
54
-     * @var EEM_Base $CPT_model
55
-     */
56
-    protected $CPT_model;
57
-
58
-    /**
59
-     * @var EventEspresso\Core\CPTs\CptQueryModifier $query_modifier
60
-     */
61
-    protected $query_modifier;
62
-
63
-
64
-    /**
65
-     * @singleton method used to instantiate class object
66
-     * @param CustomPostTypeDefinitions|null $custom_post_types
67
-     * @param CustomTaxonomyDefinitions|null $taxonomies
68
-     * @return EE_CPT_Strategy
69
-     */
70
-    public static function instance(
71
-        CustomPostTypeDefinitions $custom_post_types = null,
72
-        CustomTaxonomyDefinitions $taxonomies = null
73
-    ) {
74
-        // check if class object is instantiated
75
-        if (! self::$_instance instanceof EE_CPT_Strategy
76
-            && $custom_post_types instanceof CustomPostTypeDefinitions
77
-            && $taxonomies instanceof CustomTaxonomyDefinitions
78
-        ) {
79
-            self::$_instance = new self($custom_post_types, $taxonomies);
80
-        }
81
-        return self::$_instance;
82
-    }
83
-
84
-
85
-    /**
86
-     * @param CustomPostTypeDefinitions $custom_post_types
87
-     * @param CustomTaxonomyDefinitions $taxonomies
88
-     */
89
-    protected function __construct(
90
-        CustomPostTypeDefinitions $custom_post_types,
91
-        CustomTaxonomyDefinitions $taxonomies
92
-    ) {
93
-        // get CPT data
94
-        $this->_CPTs = $custom_post_types->getDefinitions();
95
-        $this->_CPT_endpoints = $this->_set_CPT_endpoints();
96
-        $this->_CPT_taxonomies = $taxonomies->getCustomTaxonomyDefinitions();
97
-        add_action('pre_get_posts', array($this, 'pre_get_posts'), 5);
98
-    }
99
-
100
-
101
-    /**
102
-     * @return array
103
-     */
104
-    public function get_CPT_endpoints()
105
-    {
106
-        return $this->_CPT_endpoints;
107
-    }
108
-
109
-
110
-    /**
111
-     * @return array
112
-     */
113
-    public function get_CPT_taxonomies()
114
-    {
115
-        return $this->_CPT_taxonomies;
116
-    }
117
-
118
-
119
-    /**
120
-     * add CPT "slugs" to array of default espresso "pages"
121
-     *
122
-     * @return array
123
-     */
124
-    private function _set_CPT_endpoints()
125
-    {
126
-        $_CPT_endpoints = array();
127
-        if (is_array($this->_CPTs)) {
128
-            foreach ($this->_CPTs as $CPT_type => $CPT) {
129
-                $_CPT_endpoints [ $CPT['plural_slug'] ] = $CPT_type;
130
-            }
131
-        }
132
-        return $_CPT_endpoints;
133
-    }
134
-
135
-
136
-    /**
137
-     * If this query (not just "main" queries (ie, for WP's infamous "loop")) is for an EE CPT, then we want to
138
-     * supercharge the get_posts query to add our EE stuff (like joining to our tables, selecting extra columns, and
139
-     * adding EE objects to the post to facilitate further querying of related data etc)
140
-     *
141
-     * @param WP_Query $WP_Query
142
-     * @return void
143
-     * @throws \EE_Error
144
-     * @throws \InvalidArgumentException
145
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
146
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
147
-     */
148
-    public function pre_get_posts($WP_Query)
149
-    {
150
-        // check that post-type is set
151
-        if (! $WP_Query instanceof WP_Query) {
152
-            return;
153
-        }
154
-        // add our conditionals
155
-        $this->_set_EE_tags_on_WP_Query($WP_Query);
156
-        // check for terms
157
-        $this->_set_post_type_for_terms($WP_Query);
158
-        // make sure paging is always set
159
-        $this->_set_paging($WP_Query);
160
-        // is a taxonomy set ?
161
-        $this->_set_CPT_taxonomies_on_WP_Query($WP_Query);
162
-        // loop thru post_types if set
163
-        $this->_process_WP_Query_post_types($WP_Query);
164
-    }
165
-
166
-
167
-    /**
168
-     * @param WP_Query $WP_Query
169
-     * @return void
170
-     */
171
-    private function _set_EE_tags_on_WP_Query(WP_Query $WP_Query)
172
-    {
173
-        $WP_Query->is_espresso_event_single = false;
174
-        $WP_Query->is_espresso_event_archive = false;
175
-        $WP_Query->is_espresso_event_taxonomy = false;
176
-        $WP_Query->is_espresso_venue_single = false;
177
-        $WP_Query->is_espresso_venue_archive = false;
178
-        $WP_Query->is_espresso_venue_taxonomy = false;
179
-    }
180
-
181
-
182
-    /**
183
-     * @return void
184
-     * @throws EE_Error
185
-     * @throws InvalidArgumentException
186
-     * @throws InvalidDataTypeException
187
-     * @throws InvalidInterfaceException
188
-     */
189
-    private function _set_CPT_terms()
190
-    {
191
-        if (empty($this->_CPT_terms)) {
192
-            $terms = EEM_Term::instance()->get_all_CPT_post_tags();
193
-            foreach ($terms as $term) {
194
-                if ($term instanceof EE_Term) {
195
-                    $this->_CPT_terms[ $term->slug() ] = $term;
196
-                }
197
-            }
198
-        }
199
-    }
200
-
201
-
202
-    /**
203
-     * @param WP_Query $WP_Query
204
-     * @return void
205
-     * @throws EE_Error
206
-     * @throws InvalidArgumentException
207
-     * @throws InvalidDataTypeException
208
-     * @throws InvalidInterfaceException
209
-     */
210
-    private function _set_post_type_for_terms(WP_Query $WP_Query)
211
-    {
212
-        // is a tag set ?
213
-        if (isset($WP_Query->query['tag'])) {
214
-            // set post_tags
215
-            $this->_set_CPT_terms();
216
-            // is this tag archive term in the list of terms used by our CPTs ?
217
-            $term = isset($this->_CPT_terms[ $WP_Query->query['tag'] ])
218
-                ? $this->_CPT_terms[ $WP_Query->query['tag'] ]
219
-                : null;
220
-            // verify the term
221
-            if ($term instanceof EE_Term) {
222
-                $term->post_type = array_merge(array('post', 'page'), (array) $term->post_type);
223
-                $term->post_type = apply_filters(
224
-                    'FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type',
225
-                    $term->post_type,
226
-                    $term
227
-                );
228
-                // if a post type is already set
229
-                if (isset($WP_Query->query_vars['post_type'])) {
230
-                    // add to existing array
231
-                    $term->post_type = array_merge((array) $WP_Query->query_vars['post_type'], $term->post_type);
232
-                }
233
-                // just set post_type to our CPT
234
-                $WP_Query->set('post_type', array_unique($term->post_type));
235
-            }
236
-        }
237
-    }
238
-
239
-
240
-    /**
241
-     * @param WP_Query $WP_Query
242
-     * @return void
243
-     */
244
-    public function _set_paging($WP_Query)
245
-    {
246
-        if ($WP_Query->is_main_query() && apply_filters('FHEE__EE_CPT_Strategy___set_paging', true)) {
247
-            $page = get_query_var('page') ? get_query_var('page') : null;
248
-            $paged = get_query_var('paged') ? get_query_var('paged') : $page;
249
-            $WP_Query->set('paged', $paged);
250
-        }
251
-    }
252
-
253
-
254
-    /**
255
-     * @param \WP_Query $WP_Query
256
-     */
257
-    protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $WP_Query)
258
-    {
259
-        // is a taxonomy set ?
260
-        if ($WP_Query->is_tax) {
261
-            // loop thru our taxonomies
262
-            foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) {
263
-                // check if one of our taxonomies is set as a query var
264
-                if (isset($WP_Query->query[ $CPT_taxonomy ])) {
265
-                    // but which CPT does that correspond to??? hmmm... guess we gotta go looping
266
-                    foreach ($this->_CPTs as $post_type => $CPT) {
267
-                        // verify our CPT has args, is public and has taxonomies set
268
-                        if (isset($CPT['args']['public'])
269
-                            && $CPT['args']['public']
270
-                            && ! empty($CPT['args']['taxonomies'])
271
-                            && in_array($CPT_taxonomy, $CPT['args']['taxonomies'], true)
272
-                        ) {
273
-                            // if so, then add this CPT post_type to the current query's array of post_types'
274
-                            $WP_Query->query_vars['post_type'] = isset($WP_Query->query_vars['post_type'])
275
-                                ? (array) $WP_Query->query_vars['post_type']
276
-                                : array();
277
-                            $WP_Query->query_vars['post_type'][] = $post_type;
278
-                            switch ($post_type) {
279
-                                case 'espresso_events':
280
-                                    $WP_Query->is_espresso_event_taxonomy = true;
281
-                                    break;
282
-                                case 'espresso_venues':
283
-                                    $WP_Query->is_espresso_venue_taxonomy = true;
284
-                                    break;
285
-                                default:
286
-                                    do_action(
287
-                                        'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type',
288
-                                        $WP_Query,
289
-                                        $this
290
-                                    );
291
-                            }
292
-                        }
293
-                    }
294
-                }
295
-            }
296
-        }
297
-    }
298
-
299
-
300
-    /**
301
-     * @param \WP_Query $WP_Query
302
-     * @throws InvalidArgumentException
303
-     * @throws InvalidDataTypeException
304
-     * @throws InvalidInterfaceException
305
-     */
306
-    protected function _process_WP_Query_post_types(WP_Query $WP_Query)
307
-    {
308
-        if (isset($WP_Query->query_vars['post_type'])) {
309
-            // loop thru post_types as array
310
-            foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) {
311
-                // is current query for an EE CPT ?
312
-                if (isset($this->_CPTs[ $post_type ])) {
313
-                    // is EE on or off ?
314
-                    if (EE_Maintenance_Mode::instance()->level()) {
315
-                        // reroute CPT template view to maintenance_mode.template.php
316
-                        if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) {
317
-                            add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999);
318
-                        }
319
-                        if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) {
320
-                            add_filter('the_content', array($this, 'inject_EE_shortcode_placeholder'), 1);
321
-                        }
322
-                        return;
323
-                    }
324
-                    $this->_generate_CptQueryModifier($WP_Query, $post_type);
325
-                }
326
-            }
327
-        }
328
-    }
329
-
330
-
331
-    /**
332
-     * @param \WP_Query $WP_Query
333
-     * @param string    $post_type
334
-     * @throws InvalidArgumentException
335
-     * @throws InvalidDataTypeException
336
-     * @throws InvalidInterfaceException
337
-     */
338
-    protected function _generate_CptQueryModifier(WP_Query $WP_Query, $post_type)
339
-    {
340
-        $this->query_modifier = LoaderFactory::getLoader()->getShared(
341
-            'EventEspresso\core\CPTs\CptQueryModifier',
342
-            array(
343
-                $post_type,
344
-                $this->_CPTs[ $post_type ],
345
-                $WP_Query,
346
-            )
347
-        );
348
-        $this->_CPT_taxonomies = $this->query_modifier->taxonomies();
349
-    }
350
-
351
-
352
-    /**
353
-     * inject_EE_shortcode_placeholder
354
-     * in order to display the M-Mode notice on our CPT routes,
355
-     * we need to first inject what looks like one of our shortcodes,
356
-     * so that it can be replaced with the actual M-Mode notice
357
-     *
358
-     * @return string
359
-     */
360
-    public function inject_EE_shortcode_placeholder()
361
-    {
362
-        return '[ESPRESSO_';
363
-    }
364
-
365
-
366
-    /**
367
-     * @deprecated
368
-     * @since  4.8.41
369
-     * @return void
370
-     */
371
-    public function _possibly_set_ee_request_var()
372
-    {
373
-        $this->query_modifier->setRequestVarsIfCpt();
374
-    }
375
-
376
-
377
-    /**
378
-     * @deprecated
379
-     * @since  4.8.41
380
-     * @param  $SQL
381
-     * @return string
382
-     */
383
-    public function posts_fields($SQL)
384
-    {
385
-        if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
386
-            return $this->query_modifier->postsFields($SQL);
387
-        }
388
-        return $SQL;
389
-    }
390
-
391
-
392
-    /**
393
-     * @deprecated
394
-     * @since  4.8.41
395
-     * @param  $SQL
396
-     * @return string
397
-     */
398
-    public function posts_join($SQL)
399
-    {
400
-        if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
401
-            return $this->query_modifier->postsJoin($SQL);
402
-        }
403
-        return $SQL;
404
-    }
405
-
406
-
407
-    /**
408
-     * @deprecated
409
-     * @since  4.8.41
410
-     * @param  \WP_Post[] $posts
411
-     * @return \WP_Post[]
412
-     */
413
-    public function the_posts($posts)
414
-    {
415
-        if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
416
-            $this->query_modifier->thePosts($posts);
417
-        }
418
-        return $posts;
419
-    }
420
-
421
-
422
-    /**
423
-     * @deprecated
424
-     * @since  4.8.41
425
-     * @param $url
426
-     * @param $ID
427
-     * @return string
428
-     */
429
-    public function get_edit_post_link($url, $ID)
430
-    {
431
-        if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
432
-            return $this->query_modifier->getEditPostLink($url, $ID);
433
-        }
434
-        return '';
435
-    }
436
-
437
-
438
-    /**
439
-     * @deprecated
440
-     * @since  4.8.41
441
-     * @param null $WP_Query
442
-     */
443
-    protected function _do_template_filters($WP_Query = null)
444
-    {
445
-        if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
446
-            $this->query_modifier->addTemplateFilters();
447
-        }
448
-    }
449
-
450
-
451
-    /**
452
-     * @deprecated
453
-     * @since  4.8.41
454
-     * @param string $current_template Existing default template path derived for this page call.
455
-     * @return string the path to the full template file.
456
-     */
457
-    public function single_cpt_template($current_template)
458
-    {
459
-        if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
460
-            return $this->query_modifier->singleCptTemplate($current_template);
461
-        }
462
-        return $current_template;
463
-    }
19
+	/**
20
+	 * @var EE_CPT_Strategy $_instance
21
+	 */
22
+	private static $_instance;
23
+
24
+	/**
25
+	 * the current page, if it utilizes CPTs
26
+	 *
27
+	 * @var array $CPT
28
+	 */
29
+	protected $CPT;
30
+
31
+	/**
32
+	 * return value from CustomPostTypeDefinitions::getDefinitions()
33
+	 *
34
+	 * @var array $_CPTs
35
+	 */
36
+	protected $_CPTs = array();
37
+
38
+	/**
39
+	 * @var array $_CPT_taxonomies
40
+	 */
41
+	protected $_CPT_taxonomies = array();
42
+
43
+	/**
44
+	 * @var array $_CPT_terms
45
+	 */
46
+	protected $_CPT_terms = array();
47
+
48
+	/**
49
+	 * @var array $_CPT_endpoints
50
+	 */
51
+	protected $_CPT_endpoints = array();
52
+
53
+	/**
54
+	 * @var EEM_Base $CPT_model
55
+	 */
56
+	protected $CPT_model;
57
+
58
+	/**
59
+	 * @var EventEspresso\Core\CPTs\CptQueryModifier $query_modifier
60
+	 */
61
+	protected $query_modifier;
62
+
63
+
64
+	/**
65
+	 * @singleton method used to instantiate class object
66
+	 * @param CustomPostTypeDefinitions|null $custom_post_types
67
+	 * @param CustomTaxonomyDefinitions|null $taxonomies
68
+	 * @return EE_CPT_Strategy
69
+	 */
70
+	public static function instance(
71
+		CustomPostTypeDefinitions $custom_post_types = null,
72
+		CustomTaxonomyDefinitions $taxonomies = null
73
+	) {
74
+		// check if class object is instantiated
75
+		if (! self::$_instance instanceof EE_CPT_Strategy
76
+			&& $custom_post_types instanceof CustomPostTypeDefinitions
77
+			&& $taxonomies instanceof CustomTaxonomyDefinitions
78
+		) {
79
+			self::$_instance = new self($custom_post_types, $taxonomies);
80
+		}
81
+		return self::$_instance;
82
+	}
83
+
84
+
85
+	/**
86
+	 * @param CustomPostTypeDefinitions $custom_post_types
87
+	 * @param CustomTaxonomyDefinitions $taxonomies
88
+	 */
89
+	protected function __construct(
90
+		CustomPostTypeDefinitions $custom_post_types,
91
+		CustomTaxonomyDefinitions $taxonomies
92
+	) {
93
+		// get CPT data
94
+		$this->_CPTs = $custom_post_types->getDefinitions();
95
+		$this->_CPT_endpoints = $this->_set_CPT_endpoints();
96
+		$this->_CPT_taxonomies = $taxonomies->getCustomTaxonomyDefinitions();
97
+		add_action('pre_get_posts', array($this, 'pre_get_posts'), 5);
98
+	}
99
+
100
+
101
+	/**
102
+	 * @return array
103
+	 */
104
+	public function get_CPT_endpoints()
105
+	{
106
+		return $this->_CPT_endpoints;
107
+	}
108
+
109
+
110
+	/**
111
+	 * @return array
112
+	 */
113
+	public function get_CPT_taxonomies()
114
+	{
115
+		return $this->_CPT_taxonomies;
116
+	}
117
+
118
+
119
+	/**
120
+	 * add CPT "slugs" to array of default espresso "pages"
121
+	 *
122
+	 * @return array
123
+	 */
124
+	private function _set_CPT_endpoints()
125
+	{
126
+		$_CPT_endpoints = array();
127
+		if (is_array($this->_CPTs)) {
128
+			foreach ($this->_CPTs as $CPT_type => $CPT) {
129
+				$_CPT_endpoints [ $CPT['plural_slug'] ] = $CPT_type;
130
+			}
131
+		}
132
+		return $_CPT_endpoints;
133
+	}
134
+
135
+
136
+	/**
137
+	 * If this query (not just "main" queries (ie, for WP's infamous "loop")) is for an EE CPT, then we want to
138
+	 * supercharge the get_posts query to add our EE stuff (like joining to our tables, selecting extra columns, and
139
+	 * adding EE objects to the post to facilitate further querying of related data etc)
140
+	 *
141
+	 * @param WP_Query $WP_Query
142
+	 * @return void
143
+	 * @throws \EE_Error
144
+	 * @throws \InvalidArgumentException
145
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
146
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
147
+	 */
148
+	public function pre_get_posts($WP_Query)
149
+	{
150
+		// check that post-type is set
151
+		if (! $WP_Query instanceof WP_Query) {
152
+			return;
153
+		}
154
+		// add our conditionals
155
+		$this->_set_EE_tags_on_WP_Query($WP_Query);
156
+		// check for terms
157
+		$this->_set_post_type_for_terms($WP_Query);
158
+		// make sure paging is always set
159
+		$this->_set_paging($WP_Query);
160
+		// is a taxonomy set ?
161
+		$this->_set_CPT_taxonomies_on_WP_Query($WP_Query);
162
+		// loop thru post_types if set
163
+		$this->_process_WP_Query_post_types($WP_Query);
164
+	}
165
+
166
+
167
+	/**
168
+	 * @param WP_Query $WP_Query
169
+	 * @return void
170
+	 */
171
+	private function _set_EE_tags_on_WP_Query(WP_Query $WP_Query)
172
+	{
173
+		$WP_Query->is_espresso_event_single = false;
174
+		$WP_Query->is_espresso_event_archive = false;
175
+		$WP_Query->is_espresso_event_taxonomy = false;
176
+		$WP_Query->is_espresso_venue_single = false;
177
+		$WP_Query->is_espresso_venue_archive = false;
178
+		$WP_Query->is_espresso_venue_taxonomy = false;
179
+	}
180
+
181
+
182
+	/**
183
+	 * @return void
184
+	 * @throws EE_Error
185
+	 * @throws InvalidArgumentException
186
+	 * @throws InvalidDataTypeException
187
+	 * @throws InvalidInterfaceException
188
+	 */
189
+	private function _set_CPT_terms()
190
+	{
191
+		if (empty($this->_CPT_terms)) {
192
+			$terms = EEM_Term::instance()->get_all_CPT_post_tags();
193
+			foreach ($terms as $term) {
194
+				if ($term instanceof EE_Term) {
195
+					$this->_CPT_terms[ $term->slug() ] = $term;
196
+				}
197
+			}
198
+		}
199
+	}
200
+
201
+
202
+	/**
203
+	 * @param WP_Query $WP_Query
204
+	 * @return void
205
+	 * @throws EE_Error
206
+	 * @throws InvalidArgumentException
207
+	 * @throws InvalidDataTypeException
208
+	 * @throws InvalidInterfaceException
209
+	 */
210
+	private function _set_post_type_for_terms(WP_Query $WP_Query)
211
+	{
212
+		// is a tag set ?
213
+		if (isset($WP_Query->query['tag'])) {
214
+			// set post_tags
215
+			$this->_set_CPT_terms();
216
+			// is this tag archive term in the list of terms used by our CPTs ?
217
+			$term = isset($this->_CPT_terms[ $WP_Query->query['tag'] ])
218
+				? $this->_CPT_terms[ $WP_Query->query['tag'] ]
219
+				: null;
220
+			// verify the term
221
+			if ($term instanceof EE_Term) {
222
+				$term->post_type = array_merge(array('post', 'page'), (array) $term->post_type);
223
+				$term->post_type = apply_filters(
224
+					'FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type',
225
+					$term->post_type,
226
+					$term
227
+				);
228
+				// if a post type is already set
229
+				if (isset($WP_Query->query_vars['post_type'])) {
230
+					// add to existing array
231
+					$term->post_type = array_merge((array) $WP_Query->query_vars['post_type'], $term->post_type);
232
+				}
233
+				// just set post_type to our CPT
234
+				$WP_Query->set('post_type', array_unique($term->post_type));
235
+			}
236
+		}
237
+	}
238
+
239
+
240
+	/**
241
+	 * @param WP_Query $WP_Query
242
+	 * @return void
243
+	 */
244
+	public function _set_paging($WP_Query)
245
+	{
246
+		if ($WP_Query->is_main_query() && apply_filters('FHEE__EE_CPT_Strategy___set_paging', true)) {
247
+			$page = get_query_var('page') ? get_query_var('page') : null;
248
+			$paged = get_query_var('paged') ? get_query_var('paged') : $page;
249
+			$WP_Query->set('paged', $paged);
250
+		}
251
+	}
252
+
253
+
254
+	/**
255
+	 * @param \WP_Query $WP_Query
256
+	 */
257
+	protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $WP_Query)
258
+	{
259
+		// is a taxonomy set ?
260
+		if ($WP_Query->is_tax) {
261
+			// loop thru our taxonomies
262
+			foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) {
263
+				// check if one of our taxonomies is set as a query var
264
+				if (isset($WP_Query->query[ $CPT_taxonomy ])) {
265
+					// but which CPT does that correspond to??? hmmm... guess we gotta go looping
266
+					foreach ($this->_CPTs as $post_type => $CPT) {
267
+						// verify our CPT has args, is public and has taxonomies set
268
+						if (isset($CPT['args']['public'])
269
+							&& $CPT['args']['public']
270
+							&& ! empty($CPT['args']['taxonomies'])
271
+							&& in_array($CPT_taxonomy, $CPT['args']['taxonomies'], true)
272
+						) {
273
+							// if so, then add this CPT post_type to the current query's array of post_types'
274
+							$WP_Query->query_vars['post_type'] = isset($WP_Query->query_vars['post_type'])
275
+								? (array) $WP_Query->query_vars['post_type']
276
+								: array();
277
+							$WP_Query->query_vars['post_type'][] = $post_type;
278
+							switch ($post_type) {
279
+								case 'espresso_events':
280
+									$WP_Query->is_espresso_event_taxonomy = true;
281
+									break;
282
+								case 'espresso_venues':
283
+									$WP_Query->is_espresso_venue_taxonomy = true;
284
+									break;
285
+								default:
286
+									do_action(
287
+										'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type',
288
+										$WP_Query,
289
+										$this
290
+									);
291
+							}
292
+						}
293
+					}
294
+				}
295
+			}
296
+		}
297
+	}
298
+
299
+
300
+	/**
301
+	 * @param \WP_Query $WP_Query
302
+	 * @throws InvalidArgumentException
303
+	 * @throws InvalidDataTypeException
304
+	 * @throws InvalidInterfaceException
305
+	 */
306
+	protected function _process_WP_Query_post_types(WP_Query $WP_Query)
307
+	{
308
+		if (isset($WP_Query->query_vars['post_type'])) {
309
+			// loop thru post_types as array
310
+			foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) {
311
+				// is current query for an EE CPT ?
312
+				if (isset($this->_CPTs[ $post_type ])) {
313
+					// is EE on or off ?
314
+					if (EE_Maintenance_Mode::instance()->level()) {
315
+						// reroute CPT template view to maintenance_mode.template.php
316
+						if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) {
317
+							add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999);
318
+						}
319
+						if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) {
320
+							add_filter('the_content', array($this, 'inject_EE_shortcode_placeholder'), 1);
321
+						}
322
+						return;
323
+					}
324
+					$this->_generate_CptQueryModifier($WP_Query, $post_type);
325
+				}
326
+			}
327
+		}
328
+	}
329
+
330
+
331
+	/**
332
+	 * @param \WP_Query $WP_Query
333
+	 * @param string    $post_type
334
+	 * @throws InvalidArgumentException
335
+	 * @throws InvalidDataTypeException
336
+	 * @throws InvalidInterfaceException
337
+	 */
338
+	protected function _generate_CptQueryModifier(WP_Query $WP_Query, $post_type)
339
+	{
340
+		$this->query_modifier = LoaderFactory::getLoader()->getShared(
341
+			'EventEspresso\core\CPTs\CptQueryModifier',
342
+			array(
343
+				$post_type,
344
+				$this->_CPTs[ $post_type ],
345
+				$WP_Query,
346
+			)
347
+		);
348
+		$this->_CPT_taxonomies = $this->query_modifier->taxonomies();
349
+	}
350
+
351
+
352
+	/**
353
+	 * inject_EE_shortcode_placeholder
354
+	 * in order to display the M-Mode notice on our CPT routes,
355
+	 * we need to first inject what looks like one of our shortcodes,
356
+	 * so that it can be replaced with the actual M-Mode notice
357
+	 *
358
+	 * @return string
359
+	 */
360
+	public function inject_EE_shortcode_placeholder()
361
+	{
362
+		return '[ESPRESSO_';
363
+	}
364
+
365
+
366
+	/**
367
+	 * @deprecated
368
+	 * @since  4.8.41
369
+	 * @return void
370
+	 */
371
+	public function _possibly_set_ee_request_var()
372
+	{
373
+		$this->query_modifier->setRequestVarsIfCpt();
374
+	}
375
+
376
+
377
+	/**
378
+	 * @deprecated
379
+	 * @since  4.8.41
380
+	 * @param  $SQL
381
+	 * @return string
382
+	 */
383
+	public function posts_fields($SQL)
384
+	{
385
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
386
+			return $this->query_modifier->postsFields($SQL);
387
+		}
388
+		return $SQL;
389
+	}
390
+
391
+
392
+	/**
393
+	 * @deprecated
394
+	 * @since  4.8.41
395
+	 * @param  $SQL
396
+	 * @return string
397
+	 */
398
+	public function posts_join($SQL)
399
+	{
400
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
401
+			return $this->query_modifier->postsJoin($SQL);
402
+		}
403
+		return $SQL;
404
+	}
405
+
406
+
407
+	/**
408
+	 * @deprecated
409
+	 * @since  4.8.41
410
+	 * @param  \WP_Post[] $posts
411
+	 * @return \WP_Post[]
412
+	 */
413
+	public function the_posts($posts)
414
+	{
415
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
416
+			$this->query_modifier->thePosts($posts);
417
+		}
418
+		return $posts;
419
+	}
420
+
421
+
422
+	/**
423
+	 * @deprecated
424
+	 * @since  4.8.41
425
+	 * @param $url
426
+	 * @param $ID
427
+	 * @return string
428
+	 */
429
+	public function get_edit_post_link($url, $ID)
430
+	{
431
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
432
+			return $this->query_modifier->getEditPostLink($url, $ID);
433
+		}
434
+		return '';
435
+	}
436
+
437
+
438
+	/**
439
+	 * @deprecated
440
+	 * @since  4.8.41
441
+	 * @param null $WP_Query
442
+	 */
443
+	protected function _do_template_filters($WP_Query = null)
444
+	{
445
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
446
+			$this->query_modifier->addTemplateFilters();
447
+		}
448
+	}
449
+
450
+
451
+	/**
452
+	 * @deprecated
453
+	 * @since  4.8.41
454
+	 * @param string $current_template Existing default template path derived for this page call.
455
+	 * @return string the path to the full template file.
456
+	 */
457
+	public function single_cpt_template($current_template)
458
+	{
459
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
460
+			return $this->query_modifier->singleCptTemplate($current_template);
461
+		}
462
+		return $current_template;
463
+	}
464 464
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
         CustomTaxonomyDefinitions $taxonomies = null
73 73
     ) {
74 74
         // check if class object is instantiated
75
-        if (! self::$_instance instanceof EE_CPT_Strategy
75
+        if ( ! self::$_instance instanceof EE_CPT_Strategy
76 76
             && $custom_post_types instanceof CustomPostTypeDefinitions
77 77
             && $taxonomies instanceof CustomTaxonomyDefinitions
78 78
         ) {
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
         $_CPT_endpoints = array();
127 127
         if (is_array($this->_CPTs)) {
128 128
             foreach ($this->_CPTs as $CPT_type => $CPT) {
129
-                $_CPT_endpoints [ $CPT['plural_slug'] ] = $CPT_type;
129
+                $_CPT_endpoints [$CPT['plural_slug']] = $CPT_type;
130 130
             }
131 131
         }
132 132
         return $_CPT_endpoints;
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
     public function pre_get_posts($WP_Query)
149 149
     {
150 150
         // check that post-type is set
151
-        if (! $WP_Query instanceof WP_Query) {
151
+        if ( ! $WP_Query instanceof WP_Query) {
152 152
             return;
153 153
         }
154 154
         // add our conditionals
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
             $terms = EEM_Term::instance()->get_all_CPT_post_tags();
193 193
             foreach ($terms as $term) {
194 194
                 if ($term instanceof EE_Term) {
195
-                    $this->_CPT_terms[ $term->slug() ] = $term;
195
+                    $this->_CPT_terms[$term->slug()] = $term;
196 196
                 }
197 197
             }
198 198
         }
@@ -214,8 +214,8 @@  discard block
 block discarded – undo
214 214
             // set post_tags
215 215
             $this->_set_CPT_terms();
216 216
             // is this tag archive term in the list of terms used by our CPTs ?
217
-            $term = isset($this->_CPT_terms[ $WP_Query->query['tag'] ])
218
-                ? $this->_CPT_terms[ $WP_Query->query['tag'] ]
217
+            $term = isset($this->_CPT_terms[$WP_Query->query['tag']])
218
+                ? $this->_CPT_terms[$WP_Query->query['tag']]
219 219
                 : null;
220 220
             // verify the term
221 221
             if ($term instanceof EE_Term) {
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
             // loop thru our taxonomies
262 262
             foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) {
263 263
                 // check if one of our taxonomies is set as a query var
264
-                if (isset($WP_Query->query[ $CPT_taxonomy ])) {
264
+                if (isset($WP_Query->query[$CPT_taxonomy])) {
265 265
                     // but which CPT does that correspond to??? hmmm... guess we gotta go looping
266 266
                     foreach ($this->_CPTs as $post_type => $CPT) {
267 267
                         // verify our CPT has args, is public and has taxonomies set
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
                                     break;
285 285
                                 default:
286 286
                                     do_action(
287
-                                        'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type',
287
+                                        'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_'.$post_type.'_post_type',
288 288
                                         $WP_Query,
289 289
                                         $this
290 290
                                     );
@@ -309,11 +309,11 @@  discard block
 block discarded – undo
309 309
             // loop thru post_types as array
310 310
             foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) {
311 311
                 // is current query for an EE CPT ?
312
-                if (isset($this->_CPTs[ $post_type ])) {
312
+                if (isset($this->_CPTs[$post_type])) {
313 313
                     // is EE on or off ?
314 314
                     if (EE_Maintenance_Mode::instance()->level()) {
315 315
                         // reroute CPT template view to maintenance_mode.template.php
316
-                        if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) {
316
+                        if ( ! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) {
317 317
                             add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999);
318 318
                         }
319 319
                         if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) {
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
             'EventEspresso\core\CPTs\CptQueryModifier',
342 342
             array(
343 343
                 $post_type,
344
-                $this->_CPTs[ $post_type ],
344
+                $this->_CPTs[$post_type],
345 345
                 $WP_Query,
346 346
             )
347 347
         );
Please login to merge, or discard this patch.
core/CPTs/EE_CPT_Event_Strategy.core.php 2 patches
Indentation   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -13,252 +13,252 @@
 block discarded – undo
13 13
 class EE_CPT_Event_Strategy
14 14
 {
15 15
 
16
-    /**
17
-     * the current page, if it utilizes CPTs
18
-     *
19
-     * @var object $CPT
20
-     */
21
-    protected $CPT;
16
+	/**
17
+	 * the current page, if it utilizes CPTs
18
+	 *
19
+	 * @var object $CPT
20
+	 */
21
+	protected $CPT;
22 22
 
23 23
 
24
-    /**
25
-     * @param WP_Query $wp_query
26
-     * @param array    $CPT
27
-     */
28
-    public function __construct($wp_query, $CPT = array())
29
-    {
30
-        if ($wp_query instanceof WP_Query) {
31
-            $WP_Query = $wp_query;
32
-            $this->CPT = $CPT;
33
-        } else {
34
-            $WP_Query = isset($wp_query['WP_Query']) ? $wp_query['WP_Query'] : null;
35
-            $this->CPT = isset($wp_query['CPT']) ? $wp_query['CPT'] : null;
36
-        }
37
-        // !!!!!!!!!!  IMPORTANT !!!!!!!!!!!!
38
-        // here's the list of available filters in the WP_Query object
39
-        // 'posts_where'
40
-        // 'posts_where_paged'
41
-        // 'posts_groupby'
42
-        // 'posts_join_paged'
43
-        // 'posts_orderby'
44
-        // 'posts_distinct'
45
-        // 'post_limits'
46
-        // 'posts_fields'
47
-        // 'posts_join'
48
-        $this->_add_filters();
49
-        if ($WP_Query instanceof WP_Query) {
50
-            $WP_Query->is_espresso_event_single = is_singular()
51
-                                                  && isset($WP_Query->query->post_type)
52
-                                                  && $WP_Query->query->post_type === 'espresso_events';
53
-            $WP_Query->is_espresso_event_archive = is_post_type_archive('espresso_events');
54
-            $WP_Query->is_espresso_event_taxonomy = is_tax('espresso_event_categories');
55
-        }
56
-    }
24
+	/**
25
+	 * @param WP_Query $wp_query
26
+	 * @param array    $CPT
27
+	 */
28
+	public function __construct($wp_query, $CPT = array())
29
+	{
30
+		if ($wp_query instanceof WP_Query) {
31
+			$WP_Query = $wp_query;
32
+			$this->CPT = $CPT;
33
+		} else {
34
+			$WP_Query = isset($wp_query['WP_Query']) ? $wp_query['WP_Query'] : null;
35
+			$this->CPT = isset($wp_query['CPT']) ? $wp_query['CPT'] : null;
36
+		}
37
+		// !!!!!!!!!!  IMPORTANT !!!!!!!!!!!!
38
+		// here's the list of available filters in the WP_Query object
39
+		// 'posts_where'
40
+		// 'posts_where_paged'
41
+		// 'posts_groupby'
42
+		// 'posts_join_paged'
43
+		// 'posts_orderby'
44
+		// 'posts_distinct'
45
+		// 'post_limits'
46
+		// 'posts_fields'
47
+		// 'posts_join'
48
+		$this->_add_filters();
49
+		if ($WP_Query instanceof WP_Query) {
50
+			$WP_Query->is_espresso_event_single = is_singular()
51
+												  && isset($WP_Query->query->post_type)
52
+												  && $WP_Query->query->post_type === 'espresso_events';
53
+			$WP_Query->is_espresso_event_archive = is_post_type_archive('espresso_events');
54
+			$WP_Query->is_espresso_event_taxonomy = is_tax('espresso_event_categories');
55
+		}
56
+	}
57 57
 
58 58
 
59
-    /**
60
-     * When an instance of this class is created, we add our filters
61
-     * (which will get removed in case the next call to get_posts ISN'T
62
-     * for event CPTs)
63
-     */
64
-    protected function _add_filters()
65
-    {
66
-        add_filter('posts_fields', array($this, 'posts_fields'), 1, 2);
67
-        add_filter('posts_join', array($this, 'posts_join'), 1, 2);
68
-        add_filter('posts_where', array($this, 'posts_where'), 10, 2);
69
-        // add_filter( 'the_posts', array( $this, 'the_posts' ), 1, 2 );
70
-        add_filter('posts_orderby', array($this, 'posts_orderby'), 1, 2);
71
-        add_filter('posts_groupby', array($this, 'posts_groupby'), 1, 2);
72
-        add_action('posts_selection', array($this, 'remove_filters'));
73
-    }
59
+	/**
60
+	 * When an instance of this class is created, we add our filters
61
+	 * (which will get removed in case the next call to get_posts ISN'T
62
+	 * for event CPTs)
63
+	 */
64
+	protected function _add_filters()
65
+	{
66
+		add_filter('posts_fields', array($this, 'posts_fields'), 1, 2);
67
+		add_filter('posts_join', array($this, 'posts_join'), 1, 2);
68
+		add_filter('posts_where', array($this, 'posts_where'), 10, 2);
69
+		// add_filter( 'the_posts', array( $this, 'the_posts' ), 1, 2 );
70
+		add_filter('posts_orderby', array($this, 'posts_orderby'), 1, 2);
71
+		add_filter('posts_groupby', array($this, 'posts_groupby'), 1, 2);
72
+		add_action('posts_selection', array($this, 'remove_filters'));
73
+	}
74 74
 
75 75
 
76
-    /**
77
-     * public access to _remove_filters()
78
-     *
79
-     * @since $VID:$
80
-     */
81
-    public function remove_filters()
82
-    {
83
-        $this->_remove_filters();
84
-    }
76
+	/**
77
+	 * public access to _remove_filters()
78
+	 *
79
+	 * @since $VID:$
80
+	 */
81
+	public function remove_filters()
82
+	{
83
+		$this->_remove_filters();
84
+	}
85 85
 
86 86
 
87
-    /**
88
-     * Should eb called when the last filter or hook is fired for this CPT strategy.
89
-     * This is to avoid applying this CPT strategy for other posts or CPTs (eg,
90
-     * we don't want to join to the datetime table when querying for venues, do we!?)
91
-     */
92
-    protected function _remove_filters()
93
-    {
94
-        remove_filter('posts_fields', array($this, 'posts_fields'), 1);
95
-        remove_filter('posts_join', array($this, 'posts_join'), 1);
96
-        remove_filter('posts_where', array($this, 'posts_where'), 10);
97
-        // remove_filter( 'the_posts', array( $this, 'the_posts' ), 1 );
98
-        remove_filter('posts_orderby', array($this, 'posts_orderby'), 1);
99
-        remove_filter('posts_groupby', array($this, 'posts_groupby'), 1);
100
-        remove_action('posts_selection', array($this, 'remove_filters'));
101
-    }
87
+	/**
88
+	 * Should eb called when the last filter or hook is fired for this CPT strategy.
89
+	 * This is to avoid applying this CPT strategy for other posts or CPTs (eg,
90
+	 * we don't want to join to the datetime table when querying for venues, do we!?)
91
+	 */
92
+	protected function _remove_filters()
93
+	{
94
+		remove_filter('posts_fields', array($this, 'posts_fields'), 1);
95
+		remove_filter('posts_join', array($this, 'posts_join'), 1);
96
+		remove_filter('posts_where', array($this, 'posts_where'), 10);
97
+		// remove_filter( 'the_posts', array( $this, 'the_posts' ), 1 );
98
+		remove_filter('posts_orderby', array($this, 'posts_orderby'), 1);
99
+		remove_filter('posts_groupby', array($this, 'posts_groupby'), 1);
100
+		remove_action('posts_selection', array($this, 'remove_filters'));
101
+	}
102 102
 
103 103
 
104
-    /**
105
-     * @param string   $SQL
106
-     * @param WP_Query $wp_query
107
-     * @return    string
108
-     * @throws EE_Error
109
-     * @throws InvalidArgumentException
110
-     * @throws InvalidDataTypeException
111
-     * @throws InvalidInterfaceException
112
-     */
113
-    public function posts_fields($SQL, WP_Query $wp_query)
114
-    {
115
-        if ($wp_query instanceof WP_Query
116
-            &&
117
-            (
118
-                $wp_query->is_espresso_event_single
119
-                || $wp_query->is_espresso_event_archive
120
-                || $wp_query->is_espresso_event_taxonomy
121
-            )
122
-        ) {
123
-            // adds something like ", wp_esp_datetime.* " to WP Query SELECT statement
124
-            $SQL .= ', ' . EEM_Datetime::instance()->table() . '.* ';
125
-            if ($wp_query->is_espresso_event_archive || $wp_query->is_espresso_event_taxonomy) {
126
-                // because we only want to retrieve the next upcoming datetime for each event:
127
-                // add something like:
128
-                // ", MIN( wp_esp_datetime.DTT_EVT_start ) as event_start_date "
129
-                // to WP Query SELECT statement
130
-                $SQL .= ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ';
131
-            }
132
-        }
133
-        return $SQL;
134
-    }
104
+	/**
105
+	 * @param string   $SQL
106
+	 * @param WP_Query $wp_query
107
+	 * @return    string
108
+	 * @throws EE_Error
109
+	 * @throws InvalidArgumentException
110
+	 * @throws InvalidDataTypeException
111
+	 * @throws InvalidInterfaceException
112
+	 */
113
+	public function posts_fields($SQL, WP_Query $wp_query)
114
+	{
115
+		if ($wp_query instanceof WP_Query
116
+			&&
117
+			(
118
+				$wp_query->is_espresso_event_single
119
+				|| $wp_query->is_espresso_event_archive
120
+				|| $wp_query->is_espresso_event_taxonomy
121
+			)
122
+		) {
123
+			// adds something like ", wp_esp_datetime.* " to WP Query SELECT statement
124
+			$SQL .= ', ' . EEM_Datetime::instance()->table() . '.* ';
125
+			if ($wp_query->is_espresso_event_archive || $wp_query->is_espresso_event_taxonomy) {
126
+				// because we only want to retrieve the next upcoming datetime for each event:
127
+				// add something like:
128
+				// ", MIN( wp_esp_datetime.DTT_EVT_start ) as event_start_date "
129
+				// to WP Query SELECT statement
130
+				$SQL .= ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ';
131
+			}
132
+		}
133
+		return $SQL;
134
+	}
135 135
 
136 136
 
137
-    /**
138
-     * @param string   $SQL
139
-     * @param WP_Query $wp_query
140
-     * @return string
141
-     * @throws EE_Error
142
-     * @throws InvalidArgumentException
143
-     * @throws InvalidDataTypeException
144
-     * @throws InvalidInterfaceException
145
-     */
146
-    public function posts_join($SQL, WP_Query $wp_query)
147
-    {
148
-        if ($wp_query instanceof WP_Query
149
-            &&
150
-            (
151
-                $wp_query->is_espresso_event_single
152
-                || $wp_query->is_espresso_event_archive
153
-                || $wp_query->is_espresso_event_taxonomy
154
-            )
155
-        ) {
156
-            // adds something like:
157
-            // " LEFT JOIN wp_esp_datetime ON ( wp_esp_datetime.EVT_ID = wp_posts.ID ) "
158
-            // to WP Query JOIN statement
159
-            $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . EEM_Event::instance()->table()
160
-                    . '.ID = ' . EEM_Datetime::instance()->table() . '.'
161
-                    . EEM_Event::instance()->primary_key_name() . ' ) ';
162
-        }
163
-        return $SQL;
164
-    }
137
+	/**
138
+	 * @param string   $SQL
139
+	 * @param WP_Query $wp_query
140
+	 * @return string
141
+	 * @throws EE_Error
142
+	 * @throws InvalidArgumentException
143
+	 * @throws InvalidDataTypeException
144
+	 * @throws InvalidInterfaceException
145
+	 */
146
+	public function posts_join($SQL, WP_Query $wp_query)
147
+	{
148
+		if ($wp_query instanceof WP_Query
149
+			&&
150
+			(
151
+				$wp_query->is_espresso_event_single
152
+				|| $wp_query->is_espresso_event_archive
153
+				|| $wp_query->is_espresso_event_taxonomy
154
+			)
155
+		) {
156
+			// adds something like:
157
+			// " LEFT JOIN wp_esp_datetime ON ( wp_esp_datetime.EVT_ID = wp_posts.ID ) "
158
+			// to WP Query JOIN statement
159
+			$SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . EEM_Event::instance()->table()
160
+					. '.ID = ' . EEM_Datetime::instance()->table() . '.'
161
+					. EEM_Event::instance()->primary_key_name() . ' ) ';
162
+		}
163
+		return $SQL;
164
+	}
165 165
 
166 166
 
167
-    /**
168
-     * @param string   $SQL
169
-     * @param WP_Query $wp_query
170
-     * @return string
171
-     * @throws EE_Error
172
-     * @throws InvalidArgumentException
173
-     * @throws InvalidDataTypeException
174
-     * @throws InvalidInterfaceException
175
-     */
176
-    public function posts_where($SQL, WP_Query $wp_query)
177
-    {
178
-        if ($wp_query instanceof WP_Query
179
-            &&
180
-            (
181
-                $wp_query->is_espresso_event_archive
182
-                || $wp_query->is_espresso_event_taxonomy
183
-            )
184
-        ) {
185
-            if (! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive)
186
-                || ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events)
187
-                || ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events
188
-            ) {
189
-                $SQL .= ' AND ' . EEM_Datetime::instance()->table() . ".DTT_EVT_end > '"
190
-                        . current_time('mysql', true) . "' ";
191
-            }
192
-        }
193
-        return $SQL;
194
-    }
167
+	/**
168
+	 * @param string   $SQL
169
+	 * @param WP_Query $wp_query
170
+	 * @return string
171
+	 * @throws EE_Error
172
+	 * @throws InvalidArgumentException
173
+	 * @throws InvalidDataTypeException
174
+	 * @throws InvalidInterfaceException
175
+	 */
176
+	public function posts_where($SQL, WP_Query $wp_query)
177
+	{
178
+		if ($wp_query instanceof WP_Query
179
+			&&
180
+			(
181
+				$wp_query->is_espresso_event_archive
182
+				|| $wp_query->is_espresso_event_taxonomy
183
+			)
184
+		) {
185
+			if (! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive)
186
+				|| ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events)
187
+				|| ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events
188
+			) {
189
+				$SQL .= ' AND ' . EEM_Datetime::instance()->table() . ".DTT_EVT_end > '"
190
+						. current_time('mysql', true) . "' ";
191
+			}
192
+		}
193
+		return $SQL;
194
+	}
195 195
 
196 196
 
197
-    /**
198
-     * @param string   $SQL
199
-     * @param WP_Query $wp_query
200
-     * @return string
201
-     */
202
-    public function posts_orderby($SQL, WP_Query $wp_query)
203
-    {
204
-        if ($wp_query instanceof WP_Query
205
-            &&
206
-            (
207
-                $wp_query->is_espresso_event_archive
208
-                || $wp_query->is_espresso_event_taxonomy
209
-            )
210
-        ) {
211
-            $SQL = ' event_start_date ASC ';
212
-        }
213
-        return $SQL;
214
-    }
197
+	/**
198
+	 * @param string   $SQL
199
+	 * @param WP_Query $wp_query
200
+	 * @return string
201
+	 */
202
+	public function posts_orderby($SQL, WP_Query $wp_query)
203
+	{
204
+		if ($wp_query instanceof WP_Query
205
+			&&
206
+			(
207
+				$wp_query->is_espresso_event_archive
208
+				|| $wp_query->is_espresso_event_taxonomy
209
+			)
210
+		) {
211
+			$SQL = ' event_start_date ASC ';
212
+		}
213
+		return $SQL;
214
+	}
215 215
 
216 216
 
217
-    /**
218
-     * @param string   $SQL
219
-     * @param WP_Query $wp_query
220
-     * @return string
221
-     */
222
-    public function posts_groupby($SQL, WP_Query $wp_query)
223
-    {
224
-        if ($wp_query instanceof WP_Query
225
-            &&
226
-            (
227
-                $wp_query->is_espresso_event_archive
228
-                || $wp_query->is_espresso_event_taxonomy
229
-            )
230
-        ) {
231
-            // TODO: add event list option for displaying ALL datetimes in event list or only primary datetime (default)
232
-            // we're joining to the datetimes table, where there can be MANY datetimes for a single event,
233
-            // but we want to only show each event only once
234
-            // (whereas if we didn't group them by the post's ID, then we would end up with many repeats)
235
-            global $wpdb;
236
-            $SQL = $wpdb->posts . '.ID ';
237
-        }
238
-        return $SQL;
239
-    }
217
+	/**
218
+	 * @param string   $SQL
219
+	 * @param WP_Query $wp_query
220
+	 * @return string
221
+	 */
222
+	public function posts_groupby($SQL, WP_Query $wp_query)
223
+	{
224
+		if ($wp_query instanceof WP_Query
225
+			&&
226
+			(
227
+				$wp_query->is_espresso_event_archive
228
+				|| $wp_query->is_espresso_event_taxonomy
229
+			)
230
+		) {
231
+			// TODO: add event list option for displaying ALL datetimes in event list or only primary datetime (default)
232
+			// we're joining to the datetimes table, where there can be MANY datetimes for a single event,
233
+			// but we want to only show each event only once
234
+			// (whereas if we didn't group them by the post's ID, then we would end up with many repeats)
235
+			global $wpdb;
236
+			$SQL = $wpdb->posts . '.ID ';
237
+		}
238
+		return $SQL;
239
+	}
240 240
 
241 241
 
242
-    /**
243
-     * @param array    $posts
244
-     * @param WP_Query $wp_query
245
-     * @return array
246
-     */
247
-    public function the_posts($posts, WP_Query $wp_query)
248
-    {
249
-        return $posts;
250
-    }
242
+	/**
243
+	 * @param array    $posts
244
+	 * @param WP_Query $wp_query
245
+	 * @return array
246
+	 */
247
+	public function the_posts($posts, WP_Query $wp_query)
248
+	{
249
+		return $posts;
250
+	}
251 251
 
252 252
 
253
-    /**
254
-     * @param null $meta_value
255
-     * @param      $post_id
256
-     * @param      $meta_key
257
-     * @param      $single
258
-     * @return    string
259
-     */
260
-    public function get_EE_post_type_metadata($meta_value = null, $post_id, $meta_key, $single)
261
-    {
262
-        return $meta_value;
263
-    }
253
+	/**
254
+	 * @param null $meta_value
255
+	 * @param      $post_id
256
+	 * @param      $meta_key
257
+	 * @param      $single
258
+	 * @return    string
259
+	 */
260
+	public function get_EE_post_type_metadata($meta_value = null, $post_id, $meta_key, $single)
261
+	{
262
+		return $meta_value;
263
+	}
264 264
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -121,13 +121,13 @@  discard block
 block discarded – undo
121 121
             )
122 122
         ) {
123 123
             // adds something like ", wp_esp_datetime.* " to WP Query SELECT statement
124
-            $SQL .= ', ' . EEM_Datetime::instance()->table() . '.* ';
124
+            $SQL .= ', '.EEM_Datetime::instance()->table().'.* ';
125 125
             if ($wp_query->is_espresso_event_archive || $wp_query->is_espresso_event_taxonomy) {
126 126
                 // because we only want to retrieve the next upcoming datetime for each event:
127 127
                 // add something like:
128 128
                 // ", MIN( wp_esp_datetime.DTT_EVT_start ) as event_start_date "
129 129
                 // to WP Query SELECT statement
130
-                $SQL .= ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ';
130
+                $SQL .= ', MIN( '.EEM_Datetime::instance()->table().'.DTT_EVT_start ) as event_start_date ';
131 131
             }
132 132
         }
133 133
         return $SQL;
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
             // adds something like:
157 157
             // " LEFT JOIN wp_esp_datetime ON ( wp_esp_datetime.EVT_ID = wp_posts.ID ) "
158 158
             // to WP Query JOIN statement
159
-            $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . EEM_Event::instance()->table()
160
-                    . '.ID = ' . EEM_Datetime::instance()->table() . '.'
161
-                    . EEM_Event::instance()->primary_key_name() . ' ) ';
159
+            $SQL .= ' INNER JOIN '.EEM_Datetime::instance()->table().' ON ( '.EEM_Event::instance()->table()
160
+                    . '.ID = '.EEM_Datetime::instance()->table().'.'
161
+                    . EEM_Event::instance()->primary_key_name().' ) ';
162 162
         }
163 163
         return $SQL;
164 164
     }
@@ -182,12 +182,12 @@  discard block
 block discarded – undo
182 182
                 || $wp_query->is_espresso_event_taxonomy
183 183
             )
184 184
         ) {
185
-            if (! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive)
185
+            if ( ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive)
186 186
                 || ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events)
187 187
                 || ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events
188 188
             ) {
189
-                $SQL .= ' AND ' . EEM_Datetime::instance()->table() . ".DTT_EVT_end > '"
190
-                        . current_time('mysql', true) . "' ";
189
+                $SQL .= ' AND '.EEM_Datetime::instance()->table().".DTT_EVT_end > '"
190
+                        . current_time('mysql', true)."' ";
191 191
             }
192 192
         }
193 193
         return $SQL;
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
             // but we want to only show each event only once
234 234
             // (whereas if we didn't group them by the post's ID, then we would end up with many repeats)
235 235
             global $wpdb;
236
-            $SQL = $wpdb->posts . '.ID ';
236
+            $SQL = $wpdb->posts.'.ID ';
237 237
         }
238 238
         return $SQL;
239 239
     }
Please login to merge, or discard this patch.