@@ -20,8 +20,8 @@ |
||
20 | 20 | * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
21 | 21 | * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
22 | 22 | * @param $string |
23 | - * @param $start |
|
24 | - * @param $length |
|
23 | + * @param integer $start |
|
24 | + * @param integer $length |
|
25 | 25 | * @return bool|string |
26 | 26 | */ |
27 | 27 | function mb_strcut($string, $start, $length = null) |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * ---------------------------------------------- |
11 | 11 | */ |
12 | 12 | // Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP |
13 | -if (! function_exists('mb_strcut')) { |
|
13 | +if ( ! function_exists('mb_strcut')) { |
|
14 | 14 | /** |
15 | 15 | * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
16 | 16 | * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | $notify_url = null, |
142 | 142 | $cancel_url = null |
143 | 143 | ) { |
144 | - if (! $payment instanceof EEI_Payment) { |
|
144 | + if ( ! $payment instanceof EEI_Payment) { |
|
145 | 145 | $payment->set_gateway_response( |
146 | 146 | esc_html__( |
147 | 147 | 'Error. No associated payment was found.', |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | return $payment; |
153 | 153 | } |
154 | 154 | $transaction = $payment->transaction(); |
155 | - if (! $transaction instanceof EEI_Transaction) { |
|
155 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
156 | 156 | $payment->set_gateway_response( |
157 | 157 | esc_html__( |
158 | 158 | 'Could not process this payment because it has no associated transaction.', |
@@ -199,13 +199,13 @@ discard block |
||
199 | 199 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
200 | 200 | $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
201 | 201 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
202 | - } elseif (! $this->_request_shipping_addr) { |
|
202 | + } elseif ( ! $this->_request_shipping_addr) { |
|
203 | 203 | // Do not request shipping details on the PP Checkout page. |
204 | 204 | $token_request_dtls['NOSHIPPING'] = '1'; |
205 | 205 | $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
206 | 206 | } |
207 | 207 | // Used a business/personal logo on the PayPal page. |
208 | - if (! empty($this->_image_url)) { |
|
208 | + if ( ! empty($this->_image_url)) { |
|
209 | 209 | $token_request_dtls['LOGOIMG'] = $this->_image_url; |
210 | 210 | } |
211 | 211 | $token_request_dtls = apply_filters( |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | ); |
231 | 231 | } else { |
232 | 232 | if (isset($response_args['L_ERRORCODE'])) { |
233 | - $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
233 | + $payment->set_gateway_response($response_args['L_ERRORCODE'].'; '.$response_args['L_SHORTMESSAGE']); |
|
234 | 234 | } else { |
235 | 235 | $payment->set_gateway_response( |
236 | 236 | esc_html__( |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | if ($payment instanceof EEI_Payment) { |
262 | 262 | $this->log(array('Return from Authorization' => $update_info), $payment); |
263 | 263 | $transaction = $payment->transaction(); |
264 | - if (! $transaction instanceof EEI_Transaction) { |
|
264 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
265 | 265 | $payment->set_gateway_response( |
266 | 266 | esc_html__( |
267 | 267 | 'Could not process this payment because it has no associated transaction.', |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | $primary_registrant = $transaction->primary_registration(); |
275 | 275 | $payment_details = $payment->details(); |
276 | 276 | // Check if we still have the token. |
277 | - if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
277 | + if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
278 | 278 | $payment->set_status($this->_pay_model->failed_status()); |
279 | 279 | return $payment; |
280 | 280 | } |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | $itemized_list = array(); |
400 | 400 | $gateway_formatter = $this->_get_gateway_formatter(); |
401 | 401 | // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
402 | - if (! empty($request_response_args) |
|
402 | + if ( ! empty($request_response_args) |
|
403 | 403 | && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
404 | 404 | && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
405 | 405 | ) { |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | if (strpos($arg_key, 'PAYMENTREQUEST_') !== false |
408 | 408 | && strpos($arg_key, 'NOTIFYURL') === false |
409 | 409 | ) { |
410 | - $itemized_list[ $arg_key ] = $arg_val; |
|
410 | + $itemized_list[$arg_key] = $arg_val; |
|
411 | 411 | } |
412 | 412 | } |
413 | 413 | // If we got only a few Items then something is not right. |
@@ -460,25 +460,25 @@ discard block |
||
460 | 460 | $line_item_quantity = 1; |
461 | 461 | } |
462 | 462 | // Item Name. |
463 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
463 | + $itemized_list['L_PAYMENTREQUEST_0_NAME'.$item_num] = mb_strcut( |
|
464 | 464 | $gateway_formatter->formatLineItemName($line_item, $payment), |
465 | 465 | 0, |
466 | 466 | 127 |
467 | 467 | ); |
468 | 468 | // Item description. |
469 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
469 | + $itemized_list['L_PAYMENTREQUEST_0_DESC'.$item_num] = mb_strcut( |
|
470 | 470 | $gateway_formatter->formatLineItemDesc($line_item, $payment), |
471 | 471 | 0, |
472 | 472 | 127 |
473 | 473 | ); |
474 | 474 | // Cost of individual item. |
475 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price); |
|
475 | + $itemized_list['L_PAYMENTREQUEST_0_AMT'.$item_num] = $gateway_formatter->formatCurrency($unit_price); |
|
476 | 476 | // Item Number. |
477 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
477 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
|
478 | 478 | // Item quantity. |
479 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
479 | + $itemized_list['L_PAYMENTREQUEST_0_QTY'.$item_num] = $line_item_quantity; |
|
480 | 480 | // Digital item is sold. |
481 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
481 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
|
482 | 482 | $itemized_sum += $line_item->total(); |
483 | 483 | ++$item_num; |
484 | 484 | } |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | // add the difference as an extra line item. |
497 | 497 | if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
498 | 498 | // Item Name. |
499 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
499 | + $itemized_list['L_PAYMENTREQUEST_0_NAME'.$item_num] = mb_strcut( |
|
500 | 500 | esc_html__( |
501 | 501 | 'Other (promotion/surcharge/cancellation)', |
502 | 502 | 'event_espresso' |
@@ -505,17 +505,17 @@ discard block |
||
505 | 505 | 127 |
506 | 506 | ); |
507 | 507 | // Item description. |
508 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
508 | + $itemized_list['L_PAYMENTREQUEST_0_DESC'.$item_num] = ''; |
|
509 | 509 | // Cost of individual item. |
510 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
510 | + $itemized_list['L_PAYMENTREQUEST_0_AMT'.$item_num] = $gateway_formatter->formatCurrency( |
|
511 | 511 | $itemized_sum_diff_from_txn_total |
512 | 512 | ); |
513 | 513 | // Item Number. |
514 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
514 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
|
515 | 515 | // Item quantity. |
516 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
516 | + $itemized_list['L_PAYMENTREQUEST_0_QTY'.$item_num] = 1; |
|
517 | 517 | // Digital item is sold. |
518 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
518 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
|
519 | 519 | $item_num++; |
520 | 520 | } |
521 | 521 | } else { |
@@ -570,7 +570,7 @@ discard block |
||
570 | 570 | 'BUTTONSOURCE' => 'EventEspresso_SP', |
571 | 571 | ); |
572 | 572 | $dtls = array_merge($request_dtls, $request_params); |
573 | - $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
573 | + $this->_log_clean_request($dtls, $payment, $request_text.' Request'); |
|
574 | 574 | // Request Customer Details. |
575 | 575 | $request_response = wp_remote_post( |
576 | 576 | $this->_base_gateway_url, |
@@ -584,7 +584,7 @@ discard block |
||
584 | 584 | ) |
585 | 585 | ); |
586 | 586 | // Log the response. |
587 | - $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
587 | + $this->log(array($request_text.' Response' => $request_response), $payment); |
|
588 | 588 | return $request_response; |
589 | 589 | } |
590 | 590 | |
@@ -604,7 +604,7 @@ discard block |
||
604 | 604 | } |
605 | 605 | $response_args = array(); |
606 | 606 | parse_str(urldecode($request_response['body']), $response_args); |
607 | - if (! isset($response_args['ACK'])) { |
|
607 | + if ( ! isset($response_args['ACK'])) { |
|
608 | 608 | return array('status' => false, 'args' => $request_response); |
609 | 609 | } |
610 | 610 | if (( |
@@ -651,18 +651,18 @@ discard block |
||
651 | 651 | { |
652 | 652 | $errors = array(); |
653 | 653 | $n = 0; |
654 | - while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
655 | - $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
656 | - ? $data_array[ "L_ERRORCODE{$n}" ] |
|
654 | + while (isset($data_array["L_ERRORCODE{$n}"])) { |
|
655 | + $l_error_code = isset($data_array["L_ERRORCODE{$n}"]) |
|
656 | + ? $data_array["L_ERRORCODE{$n}"] |
|
657 | 657 | : ''; |
658 | - $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
659 | - ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
658 | + $l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"]) |
|
659 | + ? $data_array["L_SEVERITYCODE{$n}"] |
|
660 | 660 | : ''; |
661 | - $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
662 | - ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
661 | + $l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"]) |
|
662 | + ? $data_array["L_SHORTMESSAGE{$n}"] |
|
663 | 663 | : ''; |
664 | - $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
665 | - ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
664 | + $l_long_message = isset($data_array["L_LONGMESSAGE{$n}"]) |
|
665 | + ? $data_array["L_LONGMESSAGE{$n}"] |
|
666 | 666 | : ''; |
667 | 667 | if ($n === 0) { |
668 | 668 | $errors = array( |
@@ -672,10 +672,10 @@ discard block |
||
672 | 672 | 'L_SEVERITYCODE' => $l_severity_code, |
673 | 673 | ); |
674 | 674 | } else { |
675 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
676 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
677 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
678 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
675 | + $errors['L_ERRORCODE'] .= ', '.$l_error_code; |
|
676 | + $errors['L_SHORTMESSAGE'] .= ', '.$l_short_message; |
|
677 | + $errors['L_LONGMESSAGE'] .= ', '.$l_long_message; |
|
678 | + $errors['L_SEVERITYCODE'] .= ', '.$l_severity_code; |
|
679 | 679 | } |
680 | 680 | $n++; |
681 | 681 | } |
@@ -11,674 +11,674 @@ |
||
11 | 11 | */ |
12 | 12 | // Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP |
13 | 13 | if (! function_exists('mb_strcut')) { |
14 | - /** |
|
15 | - * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
|
16 | - * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
|
17 | - * @param $string |
|
18 | - * @param $start |
|
19 | - * @param $length |
|
20 | - * @return bool|string |
|
21 | - */ |
|
22 | - function mb_strcut($string, $start, $length = null) |
|
23 | - { |
|
24 | - return mb_substr($string, $start, $length); |
|
25 | - } |
|
14 | + /** |
|
15 | + * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
|
16 | + * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
|
17 | + * @param $string |
|
18 | + * @param $start |
|
19 | + * @param $length |
|
20 | + * @return bool|string |
|
21 | + */ |
|
22 | + function mb_strcut($string, $start, $length = null) |
|
23 | + { |
|
24 | + return mb_substr($string, $start, $length); |
|
25 | + } |
|
26 | 26 | } |
27 | 27 | class EEG_Paypal_Express extends EE_Offsite_Gateway |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * Merchant API Username. |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - protected $_api_username; |
|
36 | - |
|
37 | - /** |
|
38 | - * Merchant API Password. |
|
39 | - * |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - protected $_api_password; |
|
43 | - |
|
44 | - /** |
|
45 | - * API Signature. |
|
46 | - * |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - protected $_api_signature; |
|
50 | - |
|
51 | - /** |
|
52 | - * Request Shipping address on PP checkout page. |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - protected $_request_shipping_addr; |
|
57 | - |
|
58 | - /** |
|
59 | - * Business/personal logo. |
|
60 | - * |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - protected $_image_url; |
|
64 | - |
|
65 | - /** |
|
66 | - * gateway URL variable |
|
67 | - * |
|
68 | - * @var string |
|
69 | - */ |
|
70 | - protected $_base_gateway_url = ''; |
|
71 | - |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * EEG_Paypal_Express constructor. |
|
76 | - */ |
|
77 | - public function __construct() |
|
78 | - { |
|
79 | - $this->_currencies_supported = array( |
|
80 | - 'USD', |
|
81 | - 'AUD', |
|
82 | - 'BRL', |
|
83 | - 'CAD', |
|
84 | - 'CZK', |
|
85 | - 'DKK', |
|
86 | - 'EUR', |
|
87 | - 'HKD', |
|
88 | - 'HUF', |
|
89 | - 'ILS', |
|
90 | - 'JPY', |
|
91 | - 'MYR', |
|
92 | - 'MXN', |
|
93 | - 'NOK', |
|
94 | - 'NZD', |
|
95 | - 'PHP', |
|
96 | - 'PLN', |
|
97 | - 'GBP', |
|
98 | - 'RUB', |
|
99 | - 'SGD', |
|
100 | - 'SEK', |
|
101 | - 'CHF', |
|
102 | - 'TWD', |
|
103 | - 'THB', |
|
104 | - 'TRY', |
|
105 | - 'INR', |
|
106 | - ); |
|
107 | - parent::__construct(); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
114 | - * |
|
115 | - * @param array $settings_array |
|
116 | - */ |
|
117 | - public function set_settings($settings_array) |
|
118 | - { |
|
119 | - parent::set_settings($settings_array); |
|
120 | - // Redirect URL. |
|
121 | - $this->_base_gateway_url = $this->_debug_mode |
|
122 | - ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
123 | - : 'https://api-3t.paypal.com/nvp'; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * @param EEI_Payment $payment |
|
130 | - * @param array $billing_info |
|
131 | - * @param string $return_url |
|
132 | - * @param string $notify_url |
|
133 | - * @param string $cancel_url |
|
134 | - * @return \EE_Payment|\EEI_Payment |
|
135 | - * @throws \EE_Error |
|
136 | - */ |
|
137 | - public function set_redirection_info( |
|
138 | - $payment, |
|
139 | - $billing_info = array(), |
|
140 | - $return_url = null, |
|
141 | - $notify_url = null, |
|
142 | - $cancel_url = null |
|
143 | - ) { |
|
144 | - if (! $payment instanceof EEI_Payment) { |
|
145 | - $payment->set_gateway_response( |
|
146 | - esc_html__( |
|
147 | - 'Error. No associated payment was found.', |
|
148 | - 'event_espresso' |
|
149 | - ) |
|
150 | - ); |
|
151 | - $payment->set_status($this->_pay_model->failed_status()); |
|
152 | - return $payment; |
|
153 | - } |
|
154 | - $transaction = $payment->transaction(); |
|
155 | - if (! $transaction instanceof EEI_Transaction) { |
|
156 | - $payment->set_gateway_response( |
|
157 | - esc_html__( |
|
158 | - 'Could not process this payment because it has no associated transaction.', |
|
159 | - 'event_espresso' |
|
160 | - ) |
|
161 | - ); |
|
162 | - $payment->set_status($this->_pay_model->failed_status()); |
|
163 | - return $payment; |
|
164 | - } |
|
165 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
166 | - $order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
167 | - $primary_registration = $transaction->primary_registration(); |
|
168 | - $primary_attendee = $primary_registration instanceof EE_Registration |
|
169 | - ? $primary_registration->attendee() |
|
170 | - : false; |
|
171 | - $locale = explode('-', get_bloginfo('language')); |
|
172 | - // Gather request parameters. |
|
173 | - $token_request_dtls = array( |
|
174 | - 'METHOD' => 'SetExpressCheckout', |
|
175 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
176 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
177 | - 'PAYMENTREQUEST_0_DESC' => $order_description, |
|
178 | - 'RETURNURL' => $return_url, |
|
179 | - 'CANCELURL' => $cancel_url, |
|
180 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
181 | - // Buyer does not need to create a PayPal account to check out. |
|
182 | - // This is referred to as PayPal Account Optional. |
|
183 | - 'SOLUTIONTYPE' => 'Sole', |
|
184 | - // Locale of the pages displayed by PayPal during Express Checkout. |
|
185 | - 'LOCALECODE' => $locale[1] |
|
186 | - ); |
|
187 | - // Show itemized list. |
|
188 | - $itemized_list = $this->itemize_list($payment, $transaction); |
|
189 | - $token_request_dtls = array_merge($token_request_dtls, $itemized_list); |
|
190 | - // Automatically filling out shipping and contact information. |
|
191 | - if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
192 | - // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
193 | - $token_request_dtls['NOSHIPPING'] = '2'; |
|
194 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
195 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
196 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
197 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
198 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
199 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
200 | - $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
201 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
202 | - } elseif (! $this->_request_shipping_addr) { |
|
203 | - // Do not request shipping details on the PP Checkout page. |
|
204 | - $token_request_dtls['NOSHIPPING'] = '1'; |
|
205 | - $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
206 | - } |
|
207 | - // Used a business/personal logo on the PayPal page. |
|
208 | - if (! empty($this->_image_url)) { |
|
209 | - $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
210 | - } |
|
211 | - $token_request_dtls = apply_filters( |
|
212 | - 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
213 | - $token_request_dtls, |
|
214 | - $this |
|
215 | - ); |
|
216 | - // Request PayPal token. |
|
217 | - $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
218 | - $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
219 | - $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
220 | - ? $token_rstatus['args'] |
|
221 | - : array(); |
|
222 | - if ($token_rstatus['status']) { |
|
223 | - // We got the Token so we may continue with the payment and redirect the client. |
|
224 | - $payment->set_details($response_args); |
|
225 | - $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
226 | - $payment->set_redirect_url( |
|
227 | - $gateway_url |
|
228 | - . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
229 | - . $response_args['TOKEN'] |
|
230 | - ); |
|
231 | - } else { |
|
232 | - if (isset($response_args['L_ERRORCODE'])) { |
|
233 | - $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
234 | - } else { |
|
235 | - $payment->set_gateway_response( |
|
236 | - esc_html__( |
|
237 | - 'Error occurred while trying to setup the Express Checkout.', |
|
238 | - 'event_espresso' |
|
239 | - ) |
|
240 | - ); |
|
241 | - } |
|
242 | - $payment->set_details($response_args); |
|
243 | - $payment->set_status($this->_pay_model->failed_status()); |
|
244 | - } |
|
245 | - return $payment; |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * @param array $update_info { |
|
252 | - * @type string $gateway_txn_id |
|
253 | - * @type string status an EEMI_Payment status |
|
254 | - * } |
|
255 | - * @param EEI_Transaction $transaction |
|
256 | - * @return EEI_Payment |
|
257 | - */ |
|
258 | - public function handle_payment_update($update_info, $transaction) |
|
259 | - { |
|
260 | - $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
261 | - if ($payment instanceof EEI_Payment) { |
|
262 | - $this->log(array('Return from Authorization' => $update_info), $payment); |
|
263 | - $transaction = $payment->transaction(); |
|
264 | - if (! $transaction instanceof EEI_Transaction) { |
|
265 | - $payment->set_gateway_response( |
|
266 | - esc_html__( |
|
267 | - 'Could not process this payment because it has no associated transaction.', |
|
268 | - 'event_espresso' |
|
269 | - ) |
|
270 | - ); |
|
271 | - $payment->set_status($this->_pay_model->failed_status()); |
|
272 | - return $payment; |
|
273 | - } |
|
274 | - $primary_registrant = $transaction->primary_registration(); |
|
275 | - $payment_details = $payment->details(); |
|
276 | - // Check if we still have the token. |
|
277 | - if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
278 | - $payment->set_status($this->_pay_model->failed_status()); |
|
279 | - return $payment; |
|
280 | - } |
|
281 | - $cdetails_request_dtls = array( |
|
282 | - 'METHOD' => 'GetExpressCheckoutDetails', |
|
283 | - 'TOKEN' => $payment_details['TOKEN'], |
|
284 | - ); |
|
285 | - // Request Customer Details. |
|
286 | - $cdetails_request_response = $this->_ppExpress_request( |
|
287 | - $cdetails_request_dtls, |
|
288 | - 'Customer Details', |
|
289 | - $payment |
|
290 | - ); |
|
291 | - $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
292 | - $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
293 | - ? $cdetails_rstatus['args'] |
|
294 | - : array(); |
|
295 | - if ($cdetails_rstatus['status']) { |
|
296 | - // We got the PayerID so now we can Complete the transaction. |
|
297 | - $docheckout_request_dtls = array( |
|
298 | - 'METHOD' => 'DoExpressCheckoutPayment', |
|
299 | - 'PAYERID' => $cdata_response_args['PAYERID'], |
|
300 | - 'TOKEN' => $payment_details['TOKEN'], |
|
301 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
302 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
303 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
304 | - ); |
|
305 | - // Include itemized list. |
|
306 | - $itemized_list = $this->itemize_list( |
|
307 | - $payment, |
|
308 | - $transaction, |
|
309 | - $cdata_response_args |
|
310 | - ); |
|
311 | - $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list); |
|
312 | - // Payment Checkout/Capture. |
|
313 | - $docheckout_request_response = $this->_ppExpress_request( |
|
314 | - $docheckout_request_dtls, |
|
315 | - 'Do Payment', |
|
316 | - $payment |
|
317 | - ); |
|
318 | - $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
319 | - $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
320 | - ? $docheckout_rstatus['args'] |
|
321 | - : array(); |
|
322 | - if ($docheckout_rstatus['status']) { |
|
323 | - // All is well, payment approved. |
|
324 | - $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
325 | - $primary_registrant->reg_code() |
|
326 | - : ''; |
|
327 | - $payment->set_extra_accntng($primary_registration_code); |
|
328 | - $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
329 | - ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
330 | - : 0); |
|
331 | - $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
332 | - ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
333 | - : null); |
|
334 | - $payment->set_details($cdata_response_args); |
|
335 | - $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
336 | - ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
337 | - : ''); |
|
338 | - $payment->set_status($this->_pay_model->approved_status()); |
|
339 | - } else { |
|
340 | - if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
341 | - $payment->set_gateway_response( |
|
342 | - $docheckout_response_args['L_ERRORCODE'] |
|
343 | - . '; ' |
|
344 | - . $docheckout_response_args['L_SHORTMESSAGE'] |
|
345 | - ); |
|
346 | - } else { |
|
347 | - $payment->set_gateway_response( |
|
348 | - esc_html__( |
|
349 | - 'Error occurred while trying to Capture the funds.', |
|
350 | - 'event_espresso' |
|
351 | - ) |
|
352 | - ); |
|
353 | - } |
|
354 | - $payment->set_details($docheckout_response_args); |
|
355 | - $payment->set_status($this->_pay_model->declined_status()); |
|
356 | - } |
|
357 | - } else { |
|
358 | - if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
359 | - $payment->set_gateway_response( |
|
360 | - $cdata_response_args['L_ERRORCODE'] |
|
361 | - . '; ' |
|
362 | - . $cdata_response_args['L_SHORTMESSAGE'] |
|
363 | - ); |
|
364 | - } else { |
|
365 | - $payment->set_gateway_response( |
|
366 | - esc_html__( |
|
367 | - 'Error occurred while trying to get payment Details from PayPal.', |
|
368 | - 'event_espresso' |
|
369 | - ) |
|
370 | - ); |
|
371 | - } |
|
372 | - $payment->set_details($cdata_response_args); |
|
373 | - $payment->set_status($this->_pay_model->failed_status()); |
|
374 | - } |
|
375 | - } else { |
|
376 | - $payment->set_gateway_response( |
|
377 | - esc_html__( |
|
378 | - 'Error occurred while trying to process the payment.', |
|
379 | - 'event_espresso' |
|
380 | - ) |
|
381 | - ); |
|
382 | - $payment->set_status($this->_pay_model->failed_status()); |
|
383 | - } |
|
384 | - return $payment; |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * Make a list of items that are in the giver transaction. |
|
391 | - * |
|
392 | - * @param EEI_Payment $payment |
|
393 | - * @param EEI_Transaction $transaction |
|
394 | - * @param array $request_response_args Data from a previous communication with PP. |
|
395 | - * @return array |
|
396 | - */ |
|
397 | - public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array()) |
|
398 | - { |
|
399 | - $itemized_list = array(); |
|
400 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
401 | - // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
|
402 | - if (! empty($request_response_args) |
|
403 | - && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
|
404 | - && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
|
405 | - ) { |
|
406 | - foreach ($request_response_args as $arg_key => $arg_val) { |
|
407 | - if (strpos($arg_key, 'PAYMENTREQUEST_') !== false |
|
408 | - && strpos($arg_key, 'NOTIFYURL') === false |
|
409 | - ) { |
|
410 | - $itemized_list[ $arg_key ] = $arg_val; |
|
411 | - } |
|
412 | - } |
|
413 | - // If we got only a few Items then something is not right. |
|
414 | - if (count($itemized_list) > 2) { |
|
415 | - return $itemized_list; |
|
416 | - } else { |
|
417 | - if (WP_DEBUG) { |
|
418 | - throw new EE_Error( |
|
419 | - sprintf( |
|
420 | - esc_html__( |
|
421 | - // @codingStandardsIgnoreStart |
|
422 | - 'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s', |
|
423 | - // @codingStandardsIgnoreEnd |
|
424 | - 'event_espresso' |
|
425 | - ), |
|
426 | - wp_json_encode($itemized_list) |
|
427 | - ) |
|
428 | - ); |
|
429 | - } |
|
430 | - // Reset the list and log an error, maybe allow to try and generate a new list (below). |
|
431 | - $itemized_list = array(); |
|
432 | - $this->log( |
|
433 | - array( |
|
434 | - (string) esc_html__( |
|
435 | - 'Could not generate a proper item list with:', |
|
436 | - 'event_espresso' |
|
437 | - ) => $request_response_args |
|
438 | - ), |
|
439 | - $payment |
|
440 | - ); |
|
441 | - } |
|
442 | - } |
|
443 | - // ...otherwise we generate a new list for this transaction. |
|
444 | - if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
445 | - $item_num = 0; |
|
446 | - $itemized_sum = 0; |
|
447 | - $total_line_items = $transaction->total_line_item(); |
|
448 | - // Go through each item in the list. |
|
449 | - foreach ($total_line_items->get_items() as $line_item) { |
|
450 | - if ($line_item instanceof EE_Line_Item) { |
|
451 | - // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
452 | - if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
453 | - continue; |
|
454 | - } |
|
455 | - $unit_price = $line_item->unit_price(); |
|
456 | - $line_item_quantity = $line_item->quantity(); |
|
457 | - // This is a discount. |
|
458 | - if ($line_item->is_percent()) { |
|
459 | - $unit_price = $line_item->total(); |
|
460 | - $line_item_quantity = 1; |
|
461 | - } |
|
462 | - // Item Name. |
|
463 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
464 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
465 | - 0, |
|
466 | - 127 |
|
467 | - ); |
|
468 | - // Item description. |
|
469 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
470 | - $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
471 | - 0, |
|
472 | - 127 |
|
473 | - ); |
|
474 | - // Cost of individual item. |
|
475 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price); |
|
476 | - // Item Number. |
|
477 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
478 | - // Item quantity. |
|
479 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
480 | - // Digital item is sold. |
|
481 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
482 | - $itemized_sum += $line_item->total(); |
|
483 | - ++$item_num; |
|
484 | - } |
|
485 | - } |
|
486 | - // Item's sales S/H and tax amount. |
|
487 | - $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
488 | - $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
489 | - $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
490 | - $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
491 | - $itemized_sum_diff_from_txn_total = round( |
|
492 | - $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
493 | - 2 |
|
494 | - ); |
|
495 | - // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
496 | - // add the difference as an extra line item. |
|
497 | - if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
498 | - // Item Name. |
|
499 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
500 | - esc_html__( |
|
501 | - 'Other (promotion/surcharge/cancellation)', |
|
502 | - 'event_espresso' |
|
503 | - ), |
|
504 | - 0, |
|
505 | - 127 |
|
506 | - ); |
|
507 | - // Item description. |
|
508 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
509 | - // Cost of individual item. |
|
510 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
511 | - $itemized_sum_diff_from_txn_total |
|
512 | - ); |
|
513 | - // Item Number. |
|
514 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
515 | - // Item quantity. |
|
516 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
517 | - // Digital item is sold. |
|
518 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
519 | - $item_num++; |
|
520 | - } |
|
521 | - } else { |
|
522 | - // Just one Item. |
|
523 | - // Item Name. |
|
524 | - $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut( |
|
525 | - $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
526 | - 0, |
|
527 | - 127 |
|
528 | - ); |
|
529 | - // Item description. |
|
530 | - $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut( |
|
531 | - $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
532 | - 0, |
|
533 | - 127 |
|
534 | - ); |
|
535 | - // Cost of individual item. |
|
536 | - $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
537 | - // Item Number. |
|
538 | - $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
539 | - // Item quantity. |
|
540 | - $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
541 | - // Digital item is sold. |
|
542 | - $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
543 | - // Item's sales S/H and tax amount. |
|
544 | - $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
545 | - $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
546 | - $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
547 | - $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
548 | - } |
|
549 | - return $itemized_list; |
|
550 | - } |
|
551 | - |
|
552 | - |
|
553 | - |
|
554 | - /** |
|
555 | - * Make the Express checkout request. |
|
556 | - * |
|
557 | - * @param array $request_params |
|
558 | - * @param string $request_text |
|
559 | - * @param EEI_Payment $payment |
|
560 | - * @return mixed |
|
561 | - */ |
|
562 | - public function _ppExpress_request($request_params, $request_text, $payment) |
|
563 | - { |
|
564 | - $request_dtls = array( |
|
565 | - 'VERSION' => '204.0', |
|
566 | - 'USER' => $this->_api_username, |
|
567 | - 'PWD' => $this->_api_password, |
|
568 | - 'SIGNATURE' => $this->_api_signature, |
|
569 | - // EE will blow up if you change this |
|
570 | - 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
571 | - ); |
|
572 | - $dtls = array_merge($request_dtls, $request_params); |
|
573 | - $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
574 | - // Request Customer Details. |
|
575 | - $request_response = wp_remote_post( |
|
576 | - $this->_base_gateway_url, |
|
577 | - array( |
|
578 | - 'method' => 'POST', |
|
579 | - 'timeout' => 45, |
|
580 | - 'httpversion' => '1.1', |
|
581 | - 'cookies' => array(), |
|
582 | - 'headers' => array(), |
|
583 | - 'body' => http_build_query($dtls, '', '&'), |
|
584 | - ) |
|
585 | - ); |
|
586 | - // Log the response. |
|
587 | - $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
588 | - return $request_response; |
|
589 | - } |
|
590 | - |
|
591 | - |
|
592 | - |
|
593 | - /** |
|
594 | - * Check the response status. |
|
595 | - * |
|
596 | - * @param mixed $request_response |
|
597 | - * @return array |
|
598 | - */ |
|
599 | - public function _ppExpress_check_response($request_response) |
|
600 | - { |
|
601 | - if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
602 | - // If we got here then there was an error in this request. |
|
603 | - return array('status' => false, 'args' => $request_response); |
|
604 | - } |
|
605 | - $response_args = array(); |
|
606 | - parse_str(urldecode($request_response['body']), $response_args); |
|
607 | - if (! isset($response_args['ACK'])) { |
|
608 | - return array('status' => false, 'args' => $request_response); |
|
609 | - } |
|
610 | - if (( |
|
611 | - isset($response_args['PAYERID']) |
|
612 | - || isset($response_args['TOKEN']) |
|
613 | - || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
614 | - || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
615 | - ) |
|
616 | - && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
617 | - ) { |
|
618 | - // Response status OK, return response parameters for further processing. |
|
619 | - return array('status' => true, 'args' => $response_args); |
|
620 | - } |
|
621 | - $errors = $this->_get_errors($response_args); |
|
622 | - return array('status' => false, 'args' => $errors); |
|
623 | - } |
|
624 | - |
|
625 | - |
|
626 | - |
|
627 | - /** |
|
628 | - * Log a "Cleared" request. |
|
629 | - * |
|
630 | - * @param array $request |
|
631 | - * @param EEI_Payment $payment |
|
632 | - * @param string $info |
|
633 | - * @return void |
|
634 | - */ |
|
635 | - private function _log_clean_request($request, $payment, $info) |
|
636 | - { |
|
637 | - $cleaned_request_data = $request; |
|
638 | - unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
639 | - $this->log(array($info => $cleaned_request_data), $payment); |
|
640 | - } |
|
641 | - |
|
642 | - |
|
643 | - |
|
644 | - /** |
|
645 | - * Get error from the response data. |
|
646 | - * |
|
647 | - * @param array $data_array |
|
648 | - * @return array |
|
649 | - */ |
|
650 | - private function _get_errors($data_array) |
|
651 | - { |
|
652 | - $errors = array(); |
|
653 | - $n = 0; |
|
654 | - while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
655 | - $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
656 | - ? $data_array[ "L_ERRORCODE{$n}" ] |
|
657 | - : ''; |
|
658 | - $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
659 | - ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
660 | - : ''; |
|
661 | - $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
662 | - ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
663 | - : ''; |
|
664 | - $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
665 | - ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
666 | - : ''; |
|
667 | - if ($n === 0) { |
|
668 | - $errors = array( |
|
669 | - 'L_ERRORCODE' => $l_error_code, |
|
670 | - 'L_SHORTMESSAGE' => $l_short_message, |
|
671 | - 'L_LONGMESSAGE' => $l_long_message, |
|
672 | - 'L_SEVERITYCODE' => $l_severity_code, |
|
673 | - ); |
|
674 | - } else { |
|
675 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
676 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
677 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
678 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
679 | - } |
|
680 | - $n++; |
|
681 | - } |
|
682 | - return $errors; |
|
683 | - } |
|
30 | + /** |
|
31 | + * Merchant API Username. |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + protected $_api_username; |
|
36 | + |
|
37 | + /** |
|
38 | + * Merchant API Password. |
|
39 | + * |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + protected $_api_password; |
|
43 | + |
|
44 | + /** |
|
45 | + * API Signature. |
|
46 | + * |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + protected $_api_signature; |
|
50 | + |
|
51 | + /** |
|
52 | + * Request Shipping address on PP checkout page. |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + protected $_request_shipping_addr; |
|
57 | + |
|
58 | + /** |
|
59 | + * Business/personal logo. |
|
60 | + * |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + protected $_image_url; |
|
64 | + |
|
65 | + /** |
|
66 | + * gateway URL variable |
|
67 | + * |
|
68 | + * @var string |
|
69 | + */ |
|
70 | + protected $_base_gateway_url = ''; |
|
71 | + |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * EEG_Paypal_Express constructor. |
|
76 | + */ |
|
77 | + public function __construct() |
|
78 | + { |
|
79 | + $this->_currencies_supported = array( |
|
80 | + 'USD', |
|
81 | + 'AUD', |
|
82 | + 'BRL', |
|
83 | + 'CAD', |
|
84 | + 'CZK', |
|
85 | + 'DKK', |
|
86 | + 'EUR', |
|
87 | + 'HKD', |
|
88 | + 'HUF', |
|
89 | + 'ILS', |
|
90 | + 'JPY', |
|
91 | + 'MYR', |
|
92 | + 'MXN', |
|
93 | + 'NOK', |
|
94 | + 'NZD', |
|
95 | + 'PHP', |
|
96 | + 'PLN', |
|
97 | + 'GBP', |
|
98 | + 'RUB', |
|
99 | + 'SGD', |
|
100 | + 'SEK', |
|
101 | + 'CHF', |
|
102 | + 'TWD', |
|
103 | + 'THB', |
|
104 | + 'TRY', |
|
105 | + 'INR', |
|
106 | + ); |
|
107 | + parent::__construct(); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * Sets the gateway URL variable based on whether debug mode is enabled or not. |
|
114 | + * |
|
115 | + * @param array $settings_array |
|
116 | + */ |
|
117 | + public function set_settings($settings_array) |
|
118 | + { |
|
119 | + parent::set_settings($settings_array); |
|
120 | + // Redirect URL. |
|
121 | + $this->_base_gateway_url = $this->_debug_mode |
|
122 | + ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
123 | + : 'https://api-3t.paypal.com/nvp'; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * @param EEI_Payment $payment |
|
130 | + * @param array $billing_info |
|
131 | + * @param string $return_url |
|
132 | + * @param string $notify_url |
|
133 | + * @param string $cancel_url |
|
134 | + * @return \EE_Payment|\EEI_Payment |
|
135 | + * @throws \EE_Error |
|
136 | + */ |
|
137 | + public function set_redirection_info( |
|
138 | + $payment, |
|
139 | + $billing_info = array(), |
|
140 | + $return_url = null, |
|
141 | + $notify_url = null, |
|
142 | + $cancel_url = null |
|
143 | + ) { |
|
144 | + if (! $payment instanceof EEI_Payment) { |
|
145 | + $payment->set_gateway_response( |
|
146 | + esc_html__( |
|
147 | + 'Error. No associated payment was found.', |
|
148 | + 'event_espresso' |
|
149 | + ) |
|
150 | + ); |
|
151 | + $payment->set_status($this->_pay_model->failed_status()); |
|
152 | + return $payment; |
|
153 | + } |
|
154 | + $transaction = $payment->transaction(); |
|
155 | + if (! $transaction instanceof EEI_Transaction) { |
|
156 | + $payment->set_gateway_response( |
|
157 | + esc_html__( |
|
158 | + 'Could not process this payment because it has no associated transaction.', |
|
159 | + 'event_espresso' |
|
160 | + ) |
|
161 | + ); |
|
162 | + $payment->set_status($this->_pay_model->failed_status()); |
|
163 | + return $payment; |
|
164 | + } |
|
165 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
166 | + $order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127); |
|
167 | + $primary_registration = $transaction->primary_registration(); |
|
168 | + $primary_attendee = $primary_registration instanceof EE_Registration |
|
169 | + ? $primary_registration->attendee() |
|
170 | + : false; |
|
171 | + $locale = explode('-', get_bloginfo('language')); |
|
172 | + // Gather request parameters. |
|
173 | + $token_request_dtls = array( |
|
174 | + 'METHOD' => 'SetExpressCheckout', |
|
175 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
176 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
177 | + 'PAYMENTREQUEST_0_DESC' => $order_description, |
|
178 | + 'RETURNURL' => $return_url, |
|
179 | + 'CANCELURL' => $cancel_url, |
|
180 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
181 | + // Buyer does not need to create a PayPal account to check out. |
|
182 | + // This is referred to as PayPal Account Optional. |
|
183 | + 'SOLUTIONTYPE' => 'Sole', |
|
184 | + // Locale of the pages displayed by PayPal during Express Checkout. |
|
185 | + 'LOCALECODE' => $locale[1] |
|
186 | + ); |
|
187 | + // Show itemized list. |
|
188 | + $itemized_list = $this->itemize_list($payment, $transaction); |
|
189 | + $token_request_dtls = array_merge($token_request_dtls, $itemized_list); |
|
190 | + // Automatically filling out shipping and contact information. |
|
191 | + if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
192 | + // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
193 | + $token_request_dtls['NOSHIPPING'] = '2'; |
|
194 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
195 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
196 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
197 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
198 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
199 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
200 | + $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
201 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
202 | + } elseif (! $this->_request_shipping_addr) { |
|
203 | + // Do not request shipping details on the PP Checkout page. |
|
204 | + $token_request_dtls['NOSHIPPING'] = '1'; |
|
205 | + $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
206 | + } |
|
207 | + // Used a business/personal logo on the PayPal page. |
|
208 | + if (! empty($this->_image_url)) { |
|
209 | + $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
210 | + } |
|
211 | + $token_request_dtls = apply_filters( |
|
212 | + 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
213 | + $token_request_dtls, |
|
214 | + $this |
|
215 | + ); |
|
216 | + // Request PayPal token. |
|
217 | + $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
218 | + $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
219 | + $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
220 | + ? $token_rstatus['args'] |
|
221 | + : array(); |
|
222 | + if ($token_rstatus['status']) { |
|
223 | + // We got the Token so we may continue with the payment and redirect the client. |
|
224 | + $payment->set_details($response_args); |
|
225 | + $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
226 | + $payment->set_redirect_url( |
|
227 | + $gateway_url |
|
228 | + . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
229 | + . $response_args['TOKEN'] |
|
230 | + ); |
|
231 | + } else { |
|
232 | + if (isset($response_args['L_ERRORCODE'])) { |
|
233 | + $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
234 | + } else { |
|
235 | + $payment->set_gateway_response( |
|
236 | + esc_html__( |
|
237 | + 'Error occurred while trying to setup the Express Checkout.', |
|
238 | + 'event_espresso' |
|
239 | + ) |
|
240 | + ); |
|
241 | + } |
|
242 | + $payment->set_details($response_args); |
|
243 | + $payment->set_status($this->_pay_model->failed_status()); |
|
244 | + } |
|
245 | + return $payment; |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * @param array $update_info { |
|
252 | + * @type string $gateway_txn_id |
|
253 | + * @type string status an EEMI_Payment status |
|
254 | + * } |
|
255 | + * @param EEI_Transaction $transaction |
|
256 | + * @return EEI_Payment |
|
257 | + */ |
|
258 | + public function handle_payment_update($update_info, $transaction) |
|
259 | + { |
|
260 | + $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
261 | + if ($payment instanceof EEI_Payment) { |
|
262 | + $this->log(array('Return from Authorization' => $update_info), $payment); |
|
263 | + $transaction = $payment->transaction(); |
|
264 | + if (! $transaction instanceof EEI_Transaction) { |
|
265 | + $payment->set_gateway_response( |
|
266 | + esc_html__( |
|
267 | + 'Could not process this payment because it has no associated transaction.', |
|
268 | + 'event_espresso' |
|
269 | + ) |
|
270 | + ); |
|
271 | + $payment->set_status($this->_pay_model->failed_status()); |
|
272 | + return $payment; |
|
273 | + } |
|
274 | + $primary_registrant = $transaction->primary_registration(); |
|
275 | + $payment_details = $payment->details(); |
|
276 | + // Check if we still have the token. |
|
277 | + if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
278 | + $payment->set_status($this->_pay_model->failed_status()); |
|
279 | + return $payment; |
|
280 | + } |
|
281 | + $cdetails_request_dtls = array( |
|
282 | + 'METHOD' => 'GetExpressCheckoutDetails', |
|
283 | + 'TOKEN' => $payment_details['TOKEN'], |
|
284 | + ); |
|
285 | + // Request Customer Details. |
|
286 | + $cdetails_request_response = $this->_ppExpress_request( |
|
287 | + $cdetails_request_dtls, |
|
288 | + 'Customer Details', |
|
289 | + $payment |
|
290 | + ); |
|
291 | + $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
292 | + $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
293 | + ? $cdetails_rstatus['args'] |
|
294 | + : array(); |
|
295 | + if ($cdetails_rstatus['status']) { |
|
296 | + // We got the PayerID so now we can Complete the transaction. |
|
297 | + $docheckout_request_dtls = array( |
|
298 | + 'METHOD' => 'DoExpressCheckoutPayment', |
|
299 | + 'PAYERID' => $cdata_response_args['PAYERID'], |
|
300 | + 'TOKEN' => $payment_details['TOKEN'], |
|
301 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
302 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
303 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
304 | + ); |
|
305 | + // Include itemized list. |
|
306 | + $itemized_list = $this->itemize_list( |
|
307 | + $payment, |
|
308 | + $transaction, |
|
309 | + $cdata_response_args |
|
310 | + ); |
|
311 | + $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list); |
|
312 | + // Payment Checkout/Capture. |
|
313 | + $docheckout_request_response = $this->_ppExpress_request( |
|
314 | + $docheckout_request_dtls, |
|
315 | + 'Do Payment', |
|
316 | + $payment |
|
317 | + ); |
|
318 | + $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
319 | + $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
320 | + ? $docheckout_rstatus['args'] |
|
321 | + : array(); |
|
322 | + if ($docheckout_rstatus['status']) { |
|
323 | + // All is well, payment approved. |
|
324 | + $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
325 | + $primary_registrant->reg_code() |
|
326 | + : ''; |
|
327 | + $payment->set_extra_accntng($primary_registration_code); |
|
328 | + $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
329 | + ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
330 | + : 0); |
|
331 | + $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
332 | + ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
333 | + : null); |
|
334 | + $payment->set_details($cdata_response_args); |
|
335 | + $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
336 | + ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
337 | + : ''); |
|
338 | + $payment->set_status($this->_pay_model->approved_status()); |
|
339 | + } else { |
|
340 | + if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
341 | + $payment->set_gateway_response( |
|
342 | + $docheckout_response_args['L_ERRORCODE'] |
|
343 | + . '; ' |
|
344 | + . $docheckout_response_args['L_SHORTMESSAGE'] |
|
345 | + ); |
|
346 | + } else { |
|
347 | + $payment->set_gateway_response( |
|
348 | + esc_html__( |
|
349 | + 'Error occurred while trying to Capture the funds.', |
|
350 | + 'event_espresso' |
|
351 | + ) |
|
352 | + ); |
|
353 | + } |
|
354 | + $payment->set_details($docheckout_response_args); |
|
355 | + $payment->set_status($this->_pay_model->declined_status()); |
|
356 | + } |
|
357 | + } else { |
|
358 | + if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
359 | + $payment->set_gateway_response( |
|
360 | + $cdata_response_args['L_ERRORCODE'] |
|
361 | + . '; ' |
|
362 | + . $cdata_response_args['L_SHORTMESSAGE'] |
|
363 | + ); |
|
364 | + } else { |
|
365 | + $payment->set_gateway_response( |
|
366 | + esc_html__( |
|
367 | + 'Error occurred while trying to get payment Details from PayPal.', |
|
368 | + 'event_espresso' |
|
369 | + ) |
|
370 | + ); |
|
371 | + } |
|
372 | + $payment->set_details($cdata_response_args); |
|
373 | + $payment->set_status($this->_pay_model->failed_status()); |
|
374 | + } |
|
375 | + } else { |
|
376 | + $payment->set_gateway_response( |
|
377 | + esc_html__( |
|
378 | + 'Error occurred while trying to process the payment.', |
|
379 | + 'event_espresso' |
|
380 | + ) |
|
381 | + ); |
|
382 | + $payment->set_status($this->_pay_model->failed_status()); |
|
383 | + } |
|
384 | + return $payment; |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * Make a list of items that are in the giver transaction. |
|
391 | + * |
|
392 | + * @param EEI_Payment $payment |
|
393 | + * @param EEI_Transaction $transaction |
|
394 | + * @param array $request_response_args Data from a previous communication with PP. |
|
395 | + * @return array |
|
396 | + */ |
|
397 | + public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array()) |
|
398 | + { |
|
399 | + $itemized_list = array(); |
|
400 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
401 | + // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
|
402 | + if (! empty($request_response_args) |
|
403 | + && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
|
404 | + && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
|
405 | + ) { |
|
406 | + foreach ($request_response_args as $arg_key => $arg_val) { |
|
407 | + if (strpos($arg_key, 'PAYMENTREQUEST_') !== false |
|
408 | + && strpos($arg_key, 'NOTIFYURL') === false |
|
409 | + ) { |
|
410 | + $itemized_list[ $arg_key ] = $arg_val; |
|
411 | + } |
|
412 | + } |
|
413 | + // If we got only a few Items then something is not right. |
|
414 | + if (count($itemized_list) > 2) { |
|
415 | + return $itemized_list; |
|
416 | + } else { |
|
417 | + if (WP_DEBUG) { |
|
418 | + throw new EE_Error( |
|
419 | + sprintf( |
|
420 | + esc_html__( |
|
421 | + // @codingStandardsIgnoreStart |
|
422 | + 'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s', |
|
423 | + // @codingStandardsIgnoreEnd |
|
424 | + 'event_espresso' |
|
425 | + ), |
|
426 | + wp_json_encode($itemized_list) |
|
427 | + ) |
|
428 | + ); |
|
429 | + } |
|
430 | + // Reset the list and log an error, maybe allow to try and generate a new list (below). |
|
431 | + $itemized_list = array(); |
|
432 | + $this->log( |
|
433 | + array( |
|
434 | + (string) esc_html__( |
|
435 | + 'Could not generate a proper item list with:', |
|
436 | + 'event_espresso' |
|
437 | + ) => $request_response_args |
|
438 | + ), |
|
439 | + $payment |
|
440 | + ); |
|
441 | + } |
|
442 | + } |
|
443 | + // ...otherwise we generate a new list for this transaction. |
|
444 | + if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
445 | + $item_num = 0; |
|
446 | + $itemized_sum = 0; |
|
447 | + $total_line_items = $transaction->total_line_item(); |
|
448 | + // Go through each item in the list. |
|
449 | + foreach ($total_line_items->get_items() as $line_item) { |
|
450 | + if ($line_item instanceof EE_Line_Item) { |
|
451 | + // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
452 | + if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
453 | + continue; |
|
454 | + } |
|
455 | + $unit_price = $line_item->unit_price(); |
|
456 | + $line_item_quantity = $line_item->quantity(); |
|
457 | + // This is a discount. |
|
458 | + if ($line_item->is_percent()) { |
|
459 | + $unit_price = $line_item->total(); |
|
460 | + $line_item_quantity = 1; |
|
461 | + } |
|
462 | + // Item Name. |
|
463 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
464 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
465 | + 0, |
|
466 | + 127 |
|
467 | + ); |
|
468 | + // Item description. |
|
469 | + $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
470 | + $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
471 | + 0, |
|
472 | + 127 |
|
473 | + ); |
|
474 | + // Cost of individual item. |
|
475 | + $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price); |
|
476 | + // Item Number. |
|
477 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
478 | + // Item quantity. |
|
479 | + $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
480 | + // Digital item is sold. |
|
481 | + $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
482 | + $itemized_sum += $line_item->total(); |
|
483 | + ++$item_num; |
|
484 | + } |
|
485 | + } |
|
486 | + // Item's sales S/H and tax amount. |
|
487 | + $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
488 | + $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
489 | + $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
490 | + $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
491 | + $itemized_sum_diff_from_txn_total = round( |
|
492 | + $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
493 | + 2 |
|
494 | + ); |
|
495 | + // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
496 | + // add the difference as an extra line item. |
|
497 | + if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
498 | + // Item Name. |
|
499 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
500 | + esc_html__( |
|
501 | + 'Other (promotion/surcharge/cancellation)', |
|
502 | + 'event_espresso' |
|
503 | + ), |
|
504 | + 0, |
|
505 | + 127 |
|
506 | + ); |
|
507 | + // Item description. |
|
508 | + $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
509 | + // Cost of individual item. |
|
510 | + $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
511 | + $itemized_sum_diff_from_txn_total |
|
512 | + ); |
|
513 | + // Item Number. |
|
514 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
515 | + // Item quantity. |
|
516 | + $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
517 | + // Digital item is sold. |
|
518 | + $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
519 | + $item_num++; |
|
520 | + } |
|
521 | + } else { |
|
522 | + // Just one Item. |
|
523 | + // Item Name. |
|
524 | + $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut( |
|
525 | + $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
526 | + 0, |
|
527 | + 127 |
|
528 | + ); |
|
529 | + // Item description. |
|
530 | + $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut( |
|
531 | + $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
532 | + 0, |
|
533 | + 127 |
|
534 | + ); |
|
535 | + // Cost of individual item. |
|
536 | + $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
537 | + // Item Number. |
|
538 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
539 | + // Item quantity. |
|
540 | + $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
541 | + // Digital item is sold. |
|
542 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
543 | + // Item's sales S/H and tax amount. |
|
544 | + $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
545 | + $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
546 | + $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
547 | + $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
548 | + } |
|
549 | + return $itemized_list; |
|
550 | + } |
|
551 | + |
|
552 | + |
|
553 | + |
|
554 | + /** |
|
555 | + * Make the Express checkout request. |
|
556 | + * |
|
557 | + * @param array $request_params |
|
558 | + * @param string $request_text |
|
559 | + * @param EEI_Payment $payment |
|
560 | + * @return mixed |
|
561 | + */ |
|
562 | + public function _ppExpress_request($request_params, $request_text, $payment) |
|
563 | + { |
|
564 | + $request_dtls = array( |
|
565 | + 'VERSION' => '204.0', |
|
566 | + 'USER' => $this->_api_username, |
|
567 | + 'PWD' => $this->_api_password, |
|
568 | + 'SIGNATURE' => $this->_api_signature, |
|
569 | + // EE will blow up if you change this |
|
570 | + 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
571 | + ); |
|
572 | + $dtls = array_merge($request_dtls, $request_params); |
|
573 | + $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
574 | + // Request Customer Details. |
|
575 | + $request_response = wp_remote_post( |
|
576 | + $this->_base_gateway_url, |
|
577 | + array( |
|
578 | + 'method' => 'POST', |
|
579 | + 'timeout' => 45, |
|
580 | + 'httpversion' => '1.1', |
|
581 | + 'cookies' => array(), |
|
582 | + 'headers' => array(), |
|
583 | + 'body' => http_build_query($dtls, '', '&'), |
|
584 | + ) |
|
585 | + ); |
|
586 | + // Log the response. |
|
587 | + $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
588 | + return $request_response; |
|
589 | + } |
|
590 | + |
|
591 | + |
|
592 | + |
|
593 | + /** |
|
594 | + * Check the response status. |
|
595 | + * |
|
596 | + * @param mixed $request_response |
|
597 | + * @return array |
|
598 | + */ |
|
599 | + public function _ppExpress_check_response($request_response) |
|
600 | + { |
|
601 | + if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
602 | + // If we got here then there was an error in this request. |
|
603 | + return array('status' => false, 'args' => $request_response); |
|
604 | + } |
|
605 | + $response_args = array(); |
|
606 | + parse_str(urldecode($request_response['body']), $response_args); |
|
607 | + if (! isset($response_args['ACK'])) { |
|
608 | + return array('status' => false, 'args' => $request_response); |
|
609 | + } |
|
610 | + if (( |
|
611 | + isset($response_args['PAYERID']) |
|
612 | + || isset($response_args['TOKEN']) |
|
613 | + || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
614 | + || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
615 | + ) |
|
616 | + && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
617 | + ) { |
|
618 | + // Response status OK, return response parameters for further processing. |
|
619 | + return array('status' => true, 'args' => $response_args); |
|
620 | + } |
|
621 | + $errors = $this->_get_errors($response_args); |
|
622 | + return array('status' => false, 'args' => $errors); |
|
623 | + } |
|
624 | + |
|
625 | + |
|
626 | + |
|
627 | + /** |
|
628 | + * Log a "Cleared" request. |
|
629 | + * |
|
630 | + * @param array $request |
|
631 | + * @param EEI_Payment $payment |
|
632 | + * @param string $info |
|
633 | + * @return void |
|
634 | + */ |
|
635 | + private function _log_clean_request($request, $payment, $info) |
|
636 | + { |
|
637 | + $cleaned_request_data = $request; |
|
638 | + unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
639 | + $this->log(array($info => $cleaned_request_data), $payment); |
|
640 | + } |
|
641 | + |
|
642 | + |
|
643 | + |
|
644 | + /** |
|
645 | + * Get error from the response data. |
|
646 | + * |
|
647 | + * @param array $data_array |
|
648 | + * @return array |
|
649 | + */ |
|
650 | + private function _get_errors($data_array) |
|
651 | + { |
|
652 | + $errors = array(); |
|
653 | + $n = 0; |
|
654 | + while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
655 | + $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
656 | + ? $data_array[ "L_ERRORCODE{$n}" ] |
|
657 | + : ''; |
|
658 | + $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
659 | + ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
660 | + : ''; |
|
661 | + $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
662 | + ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
663 | + : ''; |
|
664 | + $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
665 | + ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
666 | + : ''; |
|
667 | + if ($n === 0) { |
|
668 | + $errors = array( |
|
669 | + 'L_ERRORCODE' => $l_error_code, |
|
670 | + 'L_SHORTMESSAGE' => $l_short_message, |
|
671 | + 'L_LONGMESSAGE' => $l_long_message, |
|
672 | + 'L_SEVERITYCODE' => $l_severity_code, |
|
673 | + ); |
|
674 | + } else { |
|
675 | + $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
676 | + $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
677 | + $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
678 | + $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
679 | + } |
|
680 | + $n++; |
|
681 | + } |
|
682 | + return $errors; |
|
683 | + } |
|
684 | 684 | } |
@@ -897,7 +897,7 @@ discard block |
||
897 | 897 | * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
898 | 898 | * |
899 | 899 | * @param string $route the route name we're verifying |
900 | - * @return mixed (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
900 | + * @return boolean (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
901 | 901 | * @throws EE_Error |
902 | 902 | */ |
903 | 903 | protected function _verify_route($route) |
@@ -4039,7 +4039,7 @@ discard block |
||
4039 | 4039 | |
4040 | 4040 | |
4041 | 4041 | /** |
4042 | - * @return mixed |
|
4042 | + * @return string[] |
|
4043 | 4043 | */ |
4044 | 4044 | public function default_espresso_metaboxes() |
4045 | 4045 | { |
@@ -4059,7 +4059,7 @@ discard block |
||
4059 | 4059 | |
4060 | 4060 | |
4061 | 4061 | /** |
4062 | - * @return mixed |
|
4062 | + * @return string |
|
4063 | 4063 | */ |
4064 | 4064 | public function wp_page_slug() |
4065 | 4065 | { |
@@ -17,4111 +17,4111 @@ |
||
17 | 17 | abstract class EE_Admin_Page extends EE_Base implements InterminableInterface |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var LoaderInterface $loader |
|
22 | - */ |
|
23 | - protected $loader; |
|
20 | + /** |
|
21 | + * @var LoaderInterface $loader |
|
22 | + */ |
|
23 | + protected $loader; |
|
24 | 24 | |
25 | - // set in _init_page_props() |
|
26 | - public $page_slug; |
|
25 | + // set in _init_page_props() |
|
26 | + public $page_slug; |
|
27 | 27 | |
28 | - public $page_label; |
|
28 | + public $page_label; |
|
29 | 29 | |
30 | - public $page_folder; |
|
30 | + public $page_folder; |
|
31 | 31 | |
32 | - // set in define_page_props() |
|
33 | - protected $_admin_base_url; |
|
32 | + // set in define_page_props() |
|
33 | + protected $_admin_base_url; |
|
34 | 34 | |
35 | - protected $_admin_base_path; |
|
35 | + protected $_admin_base_path; |
|
36 | 36 | |
37 | - protected $_admin_page_title; |
|
37 | + protected $_admin_page_title; |
|
38 | 38 | |
39 | - protected $_labels; |
|
39 | + protected $_labels; |
|
40 | 40 | |
41 | 41 | |
42 | - // set early within EE_Admin_Init |
|
43 | - protected $_wp_page_slug; |
|
42 | + // set early within EE_Admin_Init |
|
43 | + protected $_wp_page_slug; |
|
44 | 44 | |
45 | - // navtabs |
|
46 | - protected $_nav_tabs; |
|
45 | + // navtabs |
|
46 | + protected $_nav_tabs; |
|
47 | 47 | |
48 | - protected $_default_nav_tab_name; |
|
48 | + protected $_default_nav_tab_name; |
|
49 | 49 | |
50 | - /** |
|
51 | - * @var array $_help_tour |
|
52 | - */ |
|
53 | - protected $_help_tour = array(); |
|
50 | + /** |
|
51 | + * @var array $_help_tour |
|
52 | + */ |
|
53 | + protected $_help_tour = array(); |
|
54 | 54 | |
55 | 55 | |
56 | - // template variables (used by templates) |
|
57 | - protected $_template_path; |
|
56 | + // template variables (used by templates) |
|
57 | + protected $_template_path; |
|
58 | 58 | |
59 | - protected $_column_template_path; |
|
59 | + protected $_column_template_path; |
|
60 | 60 | |
61 | - /** |
|
62 | - * @var array $_template_args |
|
63 | - */ |
|
64 | - protected $_template_args = array(); |
|
61 | + /** |
|
62 | + * @var array $_template_args |
|
63 | + */ |
|
64 | + protected $_template_args = array(); |
|
65 | 65 | |
66 | - /** |
|
67 | - * this will hold the list table object for a given view. |
|
68 | - * |
|
69 | - * @var EE_Admin_List_Table $_list_table_object |
|
70 | - */ |
|
71 | - protected $_list_table_object; |
|
66 | + /** |
|
67 | + * this will hold the list table object for a given view. |
|
68 | + * |
|
69 | + * @var EE_Admin_List_Table $_list_table_object |
|
70 | + */ |
|
71 | + protected $_list_table_object; |
|
72 | 72 | |
73 | - // bools |
|
74 | - protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states. |
|
73 | + // bools |
|
74 | + protected $_is_UI_request = null; // this starts at null so we can have no header routes progress through two states. |
|
75 | 75 | |
76 | - protected $_routing; |
|
76 | + protected $_routing; |
|
77 | 77 | |
78 | - // list table args |
|
79 | - protected $_view; |
|
78 | + // list table args |
|
79 | + protected $_view; |
|
80 | 80 | |
81 | - protected $_views; |
|
81 | + protected $_views; |
|
82 | 82 | |
83 | 83 | |
84 | - // action => method pairs used for routing incoming requests |
|
85 | - protected $_page_routes; |
|
84 | + // action => method pairs used for routing incoming requests |
|
85 | + protected $_page_routes; |
|
86 | 86 | |
87 | - /** |
|
88 | - * @var array $_page_config |
|
89 | - */ |
|
90 | - protected $_page_config; |
|
87 | + /** |
|
88 | + * @var array $_page_config |
|
89 | + */ |
|
90 | + protected $_page_config; |
|
91 | 91 | |
92 | - /** |
|
93 | - * the current page route and route config |
|
94 | - * |
|
95 | - * @var string $_route |
|
96 | - */ |
|
97 | - protected $_route; |
|
92 | + /** |
|
93 | + * the current page route and route config |
|
94 | + * |
|
95 | + * @var string $_route |
|
96 | + */ |
|
97 | + protected $_route; |
|
98 | 98 | |
99 | - /** |
|
100 | - * @var string $_cpt_route |
|
101 | - */ |
|
102 | - protected $_cpt_route; |
|
99 | + /** |
|
100 | + * @var string $_cpt_route |
|
101 | + */ |
|
102 | + protected $_cpt_route; |
|
103 | 103 | |
104 | - /** |
|
105 | - * @var array $_route_config |
|
106 | - */ |
|
107 | - protected $_route_config; |
|
108 | - |
|
109 | - /** |
|
110 | - * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
111 | - * actions. |
|
112 | - * |
|
113 | - * @since 4.6.x |
|
114 | - * @var array. |
|
115 | - */ |
|
116 | - protected $_default_route_query_args; |
|
117 | - |
|
118 | - // set via request page and action args. |
|
119 | - protected $_current_page; |
|
120 | - |
|
121 | - protected $_current_view; |
|
122 | - |
|
123 | - protected $_current_page_view_url; |
|
124 | - |
|
125 | - // sanitized request action (and nonce) |
|
126 | - |
|
127 | - /** |
|
128 | - * @var string $_req_action |
|
129 | - */ |
|
130 | - protected $_req_action; |
|
131 | - |
|
132 | - /** |
|
133 | - * @var string $_req_nonce |
|
134 | - */ |
|
135 | - protected $_req_nonce; |
|
136 | - |
|
137 | - // search related |
|
138 | - protected $_search_btn_label; |
|
139 | - |
|
140 | - protected $_search_box_callback; |
|
141 | - |
|
142 | - /** |
|
143 | - * WP Current Screen object |
|
144 | - * |
|
145 | - * @var WP_Screen |
|
146 | - */ |
|
147 | - protected $_current_screen; |
|
148 | - |
|
149 | - // for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
150 | - protected $_hook_obj; |
|
151 | - |
|
152 | - // for holding incoming request data |
|
153 | - protected $_req_data; |
|
154 | - |
|
155 | - // yes / no array for admin form fields |
|
156 | - protected $_yes_no_values = array(); |
|
157 | - |
|
158 | - // some default things shared by all child classes |
|
159 | - protected $_default_espresso_metaboxes; |
|
160 | - |
|
161 | - /** |
|
162 | - * EE_Registry Object |
|
163 | - * |
|
164 | - * @var EE_Registry |
|
165 | - */ |
|
166 | - protected $EE = null; |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * This is just a property that flags whether the given route is a caffeinated route or not. |
|
171 | - * |
|
172 | - * @var boolean |
|
173 | - */ |
|
174 | - protected $_is_caf = false; |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * @Constructor |
|
179 | - * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
180 | - * @throws EE_Error |
|
181 | - * @throws InvalidArgumentException |
|
182 | - * @throws ReflectionException |
|
183 | - * @throws InvalidDataTypeException |
|
184 | - * @throws InvalidInterfaceException |
|
185 | - */ |
|
186 | - public function __construct($routing = true) |
|
187 | - { |
|
188 | - $this->loader = LoaderFactory::getLoader(); |
|
189 | - if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
190 | - $this->_is_caf = true; |
|
191 | - } |
|
192 | - $this->_yes_no_values = array( |
|
193 | - array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
194 | - array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
195 | - ); |
|
196 | - // set the _req_data property. |
|
197 | - $this->_req_data = array_merge($_GET, $_POST); |
|
198 | - // routing enabled? |
|
199 | - $this->_routing = $routing; |
|
200 | - // set initial page props (child method) |
|
201 | - $this->_init_page_props(); |
|
202 | - // set global defaults |
|
203 | - $this->_set_defaults(); |
|
204 | - // set early because incoming requests could be ajax related and we need to register those hooks. |
|
205 | - $this->_global_ajax_hooks(); |
|
206 | - $this->_ajax_hooks(); |
|
207 | - // other_page_hooks have to be early too. |
|
208 | - $this->_do_other_page_hooks(); |
|
209 | - // This just allows us to have extending classes do something specific |
|
210 | - // before the parent constructor runs _page_setup(). |
|
211 | - if (method_exists($this, '_before_page_setup')) { |
|
212 | - $this->_before_page_setup(); |
|
213 | - } |
|
214 | - // set up page dependencies |
|
215 | - $this->_page_setup(); |
|
216 | - } |
|
217 | - |
|
218 | - |
|
219 | - /** |
|
220 | - * _init_page_props |
|
221 | - * Child classes use to set at least the following properties: |
|
222 | - * $page_slug. |
|
223 | - * $page_label. |
|
224 | - * |
|
225 | - * @abstract |
|
226 | - * @return void |
|
227 | - */ |
|
228 | - abstract protected function _init_page_props(); |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * _ajax_hooks |
|
233 | - * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
234 | - * Note: within the ajax callback methods. |
|
235 | - * |
|
236 | - * @abstract |
|
237 | - * @return void |
|
238 | - */ |
|
239 | - abstract protected function _ajax_hooks(); |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * _define_page_props |
|
244 | - * child classes define page properties in here. Must include at least: |
|
245 | - * $_admin_base_url = base_url for all admin pages |
|
246 | - * $_admin_page_title = default admin_page_title for admin pages |
|
247 | - * $_labels = array of default labels for various automatically generated elements: |
|
248 | - * array( |
|
249 | - * 'buttons' => array( |
|
250 | - * 'add' => esc_html__('label for add new button'), |
|
251 | - * 'edit' => esc_html__('label for edit button'), |
|
252 | - * 'delete' => esc_html__('label for delete button') |
|
253 | - * ) |
|
254 | - * ) |
|
255 | - * |
|
256 | - * @abstract |
|
257 | - * @return void |
|
258 | - */ |
|
259 | - abstract protected function _define_page_props(); |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * _set_page_routes |
|
264 | - * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
265 | - * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
266 | - * have a 'default' route. Here's the format |
|
267 | - * $this->_page_routes = array( |
|
268 | - * 'default' => array( |
|
269 | - * 'func' => '_default_method_handling_route', |
|
270 | - * 'args' => array('array','of','args'), |
|
271 | - * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
272 | - * ajax request, backend processing) |
|
273 | - * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
274 | - * headers route after. The string you enter here should match the defined route reference for a |
|
275 | - * headers sent route. |
|
276 | - * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
277 | - * this route. |
|
278 | - * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
279 | - * checks). |
|
280 | - * ), |
|
281 | - * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
282 | - * handling method. |
|
283 | - * ) |
|
284 | - * ) |
|
285 | - * |
|
286 | - * @abstract |
|
287 | - * @return void |
|
288 | - */ |
|
289 | - abstract protected function _set_page_routes(); |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * _set_page_config |
|
294 | - * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
295 | - * array corresponds to the page_route for the loaded page. Format: |
|
296 | - * $this->_page_config = array( |
|
297 | - * 'default' => array( |
|
298 | - * 'labels' => array( |
|
299 | - * 'buttons' => array( |
|
300 | - * 'add' => esc_html__('label for adding item'), |
|
301 | - * 'edit' => esc_html__('label for editing item'), |
|
302 | - * 'delete' => esc_html__('label for deleting item') |
|
303 | - * ), |
|
304 | - * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
305 | - * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
306 | - * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
307 | - * _define_page_props() method |
|
308 | - * 'nav' => array( |
|
309 | - * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
310 | - * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
311 | - * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
312 | - * 'order' => 10, //required to indicate tab position. |
|
313 | - * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
314 | - * displayed then add this parameter. |
|
315 | - * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
316 | - * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
317 | - * metaboxes set for eventespresso admin pages. |
|
318 | - * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
319 | - * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
320 | - * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
321 | - * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
322 | - * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
323 | - * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
324 | - * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
325 | - * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
326 | - * want to display. |
|
327 | - * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
328 | - * 'tab_id' => array( |
|
329 | - * 'title' => 'tab_title', |
|
330 | - * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
331 | - * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
332 | - * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
333 | - * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
334 | - * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
335 | - * attempt to use the callback which should match the name of a method in the class |
|
336 | - * ), |
|
337 | - * 'tab2_id' => array( |
|
338 | - * 'title' => 'tab2 title', |
|
339 | - * 'filename' => 'file_name_2' |
|
340 | - * 'callback' => 'callback_method_for_content', |
|
341 | - * ), |
|
342 | - * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
343 | - * help tab area on an admin page. @link |
|
344 | - * http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
345 | - * 'help_tour' => array( |
|
346 | - * 'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located |
|
347 | - * in a folder for this admin page named "help_tours", a file name matching the key given here |
|
348 | - * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
349 | - * ), |
|
350 | - * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is |
|
351 | - * true if it isn't present). To remove the requirement for a nonce check when this route is visited |
|
352 | - * just set |
|
353 | - * 'require_nonce' to FALSE |
|
354 | - * ) |
|
355 | - * ) |
|
356 | - * |
|
357 | - * @abstract |
|
358 | - * @return void |
|
359 | - */ |
|
360 | - abstract protected function _set_page_config(); |
|
361 | - |
|
362 | - |
|
363 | - |
|
364 | - |
|
365 | - |
|
366 | - /** end sample help_tour methods **/ |
|
367 | - /** |
|
368 | - * _add_screen_options |
|
369 | - * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
370 | - * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
371 | - * to a particular view. |
|
372 | - * |
|
373 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
374 | - * see also WP_Screen object documents... |
|
375 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
376 | - * @abstract |
|
377 | - * @return void |
|
378 | - */ |
|
379 | - abstract protected function _add_screen_options(); |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * _add_feature_pointers |
|
384 | - * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
385 | - * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
386 | - * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
387 | - * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
388 | - * extended) also see: |
|
389 | - * |
|
390 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
391 | - * @abstract |
|
392 | - * @return void |
|
393 | - */ |
|
394 | - abstract protected function _add_feature_pointers(); |
|
395 | - |
|
396 | - |
|
397 | - /** |
|
398 | - * load_scripts_styles |
|
399 | - * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
400 | - * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
401 | - * scripts/styles per view by putting them in a dynamic function in this format |
|
402 | - * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
403 | - * |
|
404 | - * @abstract |
|
405 | - * @return void |
|
406 | - */ |
|
407 | - abstract public function load_scripts_styles(); |
|
408 | - |
|
409 | - |
|
410 | - /** |
|
411 | - * admin_init |
|
412 | - * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
413 | - * all pages/views loaded by child class. |
|
414 | - * |
|
415 | - * @abstract |
|
416 | - * @return void |
|
417 | - */ |
|
418 | - abstract public function admin_init(); |
|
419 | - |
|
420 | - |
|
421 | - /** |
|
422 | - * admin_notices |
|
423 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
424 | - * all pages/views loaded by child class. |
|
425 | - * |
|
426 | - * @abstract |
|
427 | - * @return void |
|
428 | - */ |
|
429 | - abstract public function admin_notices(); |
|
430 | - |
|
431 | - |
|
432 | - /** |
|
433 | - * admin_footer_scripts |
|
434 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
435 | - * will apply to all pages/views loaded by child class. |
|
436 | - * |
|
437 | - * @return void |
|
438 | - */ |
|
439 | - abstract public function admin_footer_scripts(); |
|
440 | - |
|
441 | - |
|
442 | - /** |
|
443 | - * admin_footer |
|
444 | - * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
445 | - * apply to all pages/views loaded by child class. |
|
446 | - * |
|
447 | - * @return void |
|
448 | - */ |
|
449 | - public function admin_footer() |
|
450 | - { |
|
451 | - } |
|
452 | - |
|
453 | - |
|
454 | - /** |
|
455 | - * _global_ajax_hooks |
|
456 | - * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
457 | - * Note: within the ajax callback methods. |
|
458 | - * |
|
459 | - * @abstract |
|
460 | - * @return void |
|
461 | - */ |
|
462 | - protected function _global_ajax_hooks() |
|
463 | - { |
|
464 | - // for lazy loading of metabox content |
|
465 | - add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10); |
|
466 | - } |
|
467 | - |
|
468 | - |
|
469 | - public function ajax_metabox_content() |
|
470 | - { |
|
471 | - $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : ''; |
|
472 | - $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : ''; |
|
473 | - self::cached_rss_display($contentid, $url); |
|
474 | - wp_die(); |
|
475 | - } |
|
476 | - |
|
477 | - |
|
478 | - /** |
|
479 | - * _page_setup |
|
480 | - * Makes sure any things that need to be loaded early get handled. We also escape early here if the page requested |
|
481 | - * doesn't match the object. |
|
482 | - * |
|
483 | - * @final |
|
484 | - * @return void |
|
485 | - * @throws EE_Error |
|
486 | - * @throws InvalidArgumentException |
|
487 | - * @throws ReflectionException |
|
488 | - * @throws InvalidDataTypeException |
|
489 | - * @throws InvalidInterfaceException |
|
490 | - */ |
|
491 | - final protected function _page_setup() |
|
492 | - { |
|
493 | - // requires? |
|
494 | - // admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can. But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
495 | - add_action('admin_init', array($this, 'admin_init_global'), 5); |
|
496 | - // next verify if we need to load anything... |
|
497 | - $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
|
498 | - $this->page_folder = strtolower( |
|
499 | - str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this)) |
|
500 | - ); |
|
501 | - global $ee_menu_slugs; |
|
502 | - $ee_menu_slugs = (array) $ee_menu_slugs; |
|
503 | - if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) { |
|
504 | - return; |
|
505 | - } |
|
506 | - // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first |
|
507 | - if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') { |
|
508 | - $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1' |
|
509 | - ? $this->_req_data['action2'] |
|
510 | - : $this->_req_data['action']; |
|
511 | - } |
|
512 | - // then set blank or -1 action values to 'default' |
|
513 | - $this->_req_action = isset($this->_req_data['action']) |
|
514 | - && ! empty($this->_req_data['action']) |
|
515 | - && $this->_req_data['action'] !== '-1' |
|
516 | - ? sanitize_key($this->_req_data['action']) |
|
517 | - : 'default'; |
|
518 | - // if action is 'default' after the above BUT we have 'route' var set, then let's use the route as the action. |
|
519 | - // This covers cases where we're coming in from a list table that isn't on the default route. |
|
520 | - $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) |
|
521 | - ? $this->_req_data['route'] : $this->_req_action; |
|
522 | - // however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be |
|
523 | - $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) |
|
524 | - ? $this->_req_data['route'] |
|
525 | - : $this->_req_action; |
|
526 | - $this->_current_view = $this->_req_action; |
|
527 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
528 | - $this->_define_page_props(); |
|
529 | - $this->_current_page_view_url = add_query_arg( |
|
530 | - array('page' => $this->_current_page, 'action' => $this->_current_view), |
|
531 | - $this->_admin_base_url |
|
532 | - ); |
|
533 | - // default things |
|
534 | - $this->_default_espresso_metaboxes = array( |
|
535 | - '_espresso_news_post_box', |
|
536 | - '_espresso_links_post_box', |
|
537 | - '_espresso_ratings_request', |
|
538 | - '_espresso_sponsors_post_box', |
|
539 | - ); |
|
540 | - // set page configs |
|
541 | - $this->_set_page_routes(); |
|
542 | - $this->_set_page_config(); |
|
543 | - // let's include any referrer data in our default_query_args for this route for "stickiness". |
|
544 | - if (isset($this->_req_data['wp_referer'])) { |
|
545 | - $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer']; |
|
546 | - } |
|
547 | - // for caffeinated and other extended functionality. |
|
548 | - // If there is a _extend_page_config method |
|
549 | - // then let's run that to modify the all the various page configuration arrays |
|
550 | - if (method_exists($this, '_extend_page_config')) { |
|
551 | - $this->_extend_page_config(); |
|
552 | - } |
|
553 | - // for CPT and other extended functionality. |
|
554 | - // If there is an _extend_page_config_for_cpt |
|
555 | - // then let's run that to modify all the various page configuration arrays. |
|
556 | - if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
557 | - $this->_extend_page_config_for_cpt(); |
|
558 | - } |
|
559 | - // filter routes and page_config so addons can add their stuff. Filtering done per class |
|
560 | - $this->_page_routes = apply_filters( |
|
561 | - 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
562 | - $this->_page_routes, |
|
563 | - $this |
|
564 | - ); |
|
565 | - $this->_page_config = apply_filters( |
|
566 | - 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
567 | - $this->_page_config, |
|
568 | - $this |
|
569 | - ); |
|
570 | - // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
571 | - // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
572 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
573 | - add_action( |
|
574 | - 'AHEE__EE_Admin_Page__route_admin_request', |
|
575 | - array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), |
|
576 | - 10, |
|
577 | - 2 |
|
578 | - ); |
|
579 | - } |
|
580 | - // next route only if routing enabled |
|
581 | - if ($this->_routing && ! defined('DOING_AJAX')) { |
|
582 | - $this->_verify_routes(); |
|
583 | - // next let's just check user_access and kill if no access |
|
584 | - $this->check_user_access(); |
|
585 | - if ($this->_is_UI_request) { |
|
586 | - // admin_init stuff - global, all views for this page class, specific view |
|
587 | - add_action('admin_init', array($this, 'admin_init'), 10); |
|
588 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
589 | - add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
590 | - } |
|
591 | - } else { |
|
592 | - // hijack regular WP loading and route admin request immediately |
|
593 | - @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
594 | - $this->route_admin_request(); |
|
595 | - } |
|
596 | - } |
|
597 | - } |
|
598 | - |
|
599 | - |
|
600 | - /** |
|
601 | - * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
602 | - * |
|
603 | - * @return void |
|
604 | - * @throws ReflectionException |
|
605 | - * @throws EE_Error |
|
606 | - */ |
|
607 | - private function _do_other_page_hooks() |
|
608 | - { |
|
609 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
610 | - foreach ($registered_pages as $page) { |
|
611 | - // now let's setup the file name and class that should be present |
|
612 | - $classname = str_replace('.class.php', '', $page); |
|
613 | - // autoloaders should take care of loading file |
|
614 | - if (! class_exists($classname)) { |
|
615 | - $error_msg[] = sprintf( |
|
616 | - esc_html__( |
|
617 | - 'Something went wrong with loading the %s admin hooks page.', |
|
618 | - 'event_espresso' |
|
619 | - ), |
|
620 | - $page |
|
621 | - ); |
|
622 | - $error_msg[] = $error_msg[0] |
|
623 | - . "\r\n" |
|
624 | - . sprintf( |
|
625 | - esc_html__( |
|
626 | - 'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
627 | - 'event_espresso' |
|
628 | - ), |
|
629 | - $page, |
|
630 | - '<br />', |
|
631 | - '<strong>' . $classname . '</strong>' |
|
632 | - ); |
|
633 | - throw new EE_Error(implode('||', $error_msg)); |
|
634 | - } |
|
635 | - $a = new ReflectionClass($classname); |
|
636 | - // notice we are passing the instance of this class to the hook object. |
|
637 | - $hookobj[] = $a->newInstance($this); |
|
638 | - } |
|
639 | - } |
|
640 | - |
|
641 | - |
|
642 | - public function load_page_dependencies() |
|
643 | - { |
|
644 | - try { |
|
645 | - $this->_load_page_dependencies(); |
|
646 | - } catch (EE_Error $e) { |
|
647 | - $e->get_error(); |
|
648 | - } |
|
649 | - } |
|
650 | - |
|
651 | - |
|
652 | - /** |
|
653 | - * load_page_dependencies |
|
654 | - * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
655 | - * |
|
656 | - * @return void |
|
657 | - * @throws DomainException |
|
658 | - * @throws EE_Error |
|
659 | - * @throws InvalidArgumentException |
|
660 | - * @throws InvalidDataTypeException |
|
661 | - * @throws InvalidInterfaceException |
|
662 | - * @throws ReflectionException |
|
663 | - */ |
|
664 | - protected function _load_page_dependencies() |
|
665 | - { |
|
666 | - // let's set the current_screen and screen options to override what WP set |
|
667 | - $this->_current_screen = get_current_screen(); |
|
668 | - // load admin_notices - global, page class, and view specific |
|
669 | - add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
|
670 | - add_action('admin_notices', array($this, 'admin_notices'), 10); |
|
671 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
672 | - add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
673 | - } |
|
674 | - // load network admin_notices - global, page class, and view specific |
|
675 | - add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
|
676 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
677 | - add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
678 | - } |
|
679 | - // this will save any per_page screen options if they are present |
|
680 | - $this->_set_per_page_screen_options(); |
|
681 | - // setup list table properties |
|
682 | - $this->_set_list_table(); |
|
683 | - // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
684 | - // However in some cases the metaboxes will need to be added within a route handling callback. |
|
685 | - $this->_add_registered_meta_boxes(); |
|
686 | - $this->_add_screen_columns(); |
|
687 | - // add screen options - global, page child class, and view specific |
|
688 | - $this->_add_global_screen_options(); |
|
689 | - $this->_add_screen_options(); |
|
690 | - $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
691 | - if (method_exists($this, $add_screen_options)) { |
|
692 | - $this->{$add_screen_options}(); |
|
693 | - } |
|
694 | - // add help tab(s) and tours- set via page_config and qtips. |
|
695 | - $this->_add_help_tour(); |
|
696 | - $this->_add_help_tabs(); |
|
697 | - $this->_add_qtips(); |
|
698 | - // add feature_pointers - global, page child class, and view specific |
|
699 | - $this->_add_feature_pointers(); |
|
700 | - $this->_add_global_feature_pointers(); |
|
701 | - $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
702 | - if (method_exists($this, $add_feature_pointer)) { |
|
703 | - $this->{$add_feature_pointer}(); |
|
704 | - } |
|
705 | - // enqueue scripts/styles - global, page class, and view specific |
|
706 | - add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5); |
|
707 | - add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10); |
|
708 | - if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
709 | - add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15); |
|
710 | - } |
|
711 | - add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100); |
|
712 | - // admin_print_footer_scripts - global, page child class, and view specific. |
|
713 | - // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
714 | - // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
715 | - // is a good use case. Notice the late priority we're giving these |
|
716 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99); |
|
717 | - add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100); |
|
718 | - if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
719 | - add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101); |
|
720 | - } |
|
721 | - // admin footer scripts |
|
722 | - add_action('admin_footer', array($this, 'admin_footer_global'), 99); |
|
723 | - add_action('admin_footer', array($this, 'admin_footer'), 100); |
|
724 | - if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
725 | - add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101); |
|
726 | - } |
|
727 | - do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
728 | - // targeted hook |
|
729 | - do_action( |
|
730 | - "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
731 | - ); |
|
732 | - } |
|
733 | - |
|
734 | - |
|
735 | - /** |
|
736 | - * _set_defaults |
|
737 | - * This sets some global defaults for class properties. |
|
738 | - */ |
|
739 | - private function _set_defaults() |
|
740 | - { |
|
741 | - $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
742 | - $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
743 | - $this->_nav_tabs = $this->_views = $this->_page_routes = array(); |
|
744 | - $this->_page_config = $this->_default_route_query_args = array(); |
|
745 | - $this->_default_nav_tab_name = 'overview'; |
|
746 | - // init template args |
|
747 | - $this->_template_args = array( |
|
748 | - 'admin_page_header' => '', |
|
749 | - 'admin_page_content' => '', |
|
750 | - 'post_body_content' => '', |
|
751 | - 'before_list_table' => '', |
|
752 | - 'after_list_table' => '', |
|
753 | - ); |
|
754 | - } |
|
755 | - |
|
756 | - |
|
757 | - /** |
|
758 | - * route_admin_request |
|
759 | - * |
|
760 | - * @see _route_admin_request() |
|
761 | - * @return exception|void error |
|
762 | - * @throws InvalidArgumentException |
|
763 | - * @throws InvalidInterfaceException |
|
764 | - * @throws InvalidDataTypeException |
|
765 | - * @throws EE_Error |
|
766 | - * @throws ReflectionException |
|
767 | - */ |
|
768 | - public function route_admin_request() |
|
769 | - { |
|
770 | - try { |
|
771 | - $this->_route_admin_request(); |
|
772 | - } catch (EE_Error $e) { |
|
773 | - $e->get_error(); |
|
774 | - } |
|
775 | - } |
|
776 | - |
|
777 | - |
|
778 | - public function set_wp_page_slug($wp_page_slug) |
|
779 | - { |
|
780 | - $this->_wp_page_slug = $wp_page_slug; |
|
781 | - // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
782 | - if (is_network_admin()) { |
|
783 | - $this->_wp_page_slug .= '-network'; |
|
784 | - } |
|
785 | - } |
|
786 | - |
|
787 | - |
|
788 | - /** |
|
789 | - * _verify_routes |
|
790 | - * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
791 | - * we know if we need to drop out. |
|
792 | - * |
|
793 | - * @return bool |
|
794 | - * @throws EE_Error |
|
795 | - */ |
|
796 | - protected function _verify_routes() |
|
797 | - { |
|
798 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
799 | - if (! $this->_current_page && ! defined('DOING_AJAX')) { |
|
800 | - return false; |
|
801 | - } |
|
802 | - $this->_route = false; |
|
803 | - // check that the page_routes array is not empty |
|
804 | - if (empty($this->_page_routes)) { |
|
805 | - // user error msg |
|
806 | - $error_msg = sprintf( |
|
807 | - esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
808 | - $this->_admin_page_title |
|
809 | - ); |
|
810 | - // developer error msg |
|
811 | - $error_msg .= '||' . $error_msg |
|
812 | - . esc_html__( |
|
813 | - ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
814 | - 'event_espresso' |
|
815 | - ); |
|
816 | - throw new EE_Error($error_msg); |
|
817 | - } |
|
818 | - // and that the requested page route exists |
|
819 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
820 | - $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
821 | - $this->_route_config = isset($this->_page_config[ $this->_req_action ]) |
|
822 | - ? $this->_page_config[ $this->_req_action ] : array(); |
|
823 | - } else { |
|
824 | - // user error msg |
|
825 | - $error_msg = sprintf( |
|
826 | - esc_html__( |
|
827 | - 'The requested page route does not exist for the %s admin page.', |
|
828 | - 'event_espresso' |
|
829 | - ), |
|
830 | - $this->_admin_page_title |
|
831 | - ); |
|
832 | - // developer error msg |
|
833 | - $error_msg .= '||' . $error_msg |
|
834 | - . sprintf( |
|
835 | - esc_html__( |
|
836 | - ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
837 | - 'event_espresso' |
|
838 | - ), |
|
839 | - $this->_req_action |
|
840 | - ); |
|
841 | - throw new EE_Error($error_msg); |
|
842 | - } |
|
843 | - // and that a default route exists |
|
844 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
845 | - // user error msg |
|
846 | - $error_msg = sprintf( |
|
847 | - esc_html__( |
|
848 | - 'A default page route has not been set for the % admin page.', |
|
849 | - 'event_espresso' |
|
850 | - ), |
|
851 | - $this->_admin_page_title |
|
852 | - ); |
|
853 | - // developer error msg |
|
854 | - $error_msg .= '||' . $error_msg |
|
855 | - . esc_html__( |
|
856 | - ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
857 | - 'event_espresso' |
|
858 | - ); |
|
859 | - throw new EE_Error($error_msg); |
|
860 | - } |
|
861 | - // first lets' catch if the UI request has EVER been set. |
|
862 | - if ($this->_is_UI_request === null) { |
|
863 | - // lets set if this is a UI request or not. |
|
864 | - $this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true; |
|
865 | - // wait a minute... we might have a noheader in the route array |
|
866 | - $this->_is_UI_request = is_array($this->_route) |
|
867 | - && isset($this->_route['noheader']) |
|
868 | - && $this->_route['noheader'] ? false : $this->_is_UI_request; |
|
869 | - } |
|
870 | - $this->_set_current_labels(); |
|
871 | - return true; |
|
872 | - } |
|
873 | - |
|
874 | - |
|
875 | - /** |
|
876 | - * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
877 | - * |
|
878 | - * @param string $route the route name we're verifying |
|
879 | - * @return mixed (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
880 | - * @throws EE_Error |
|
881 | - */ |
|
882 | - protected function _verify_route($route) |
|
883 | - { |
|
884 | - if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
885 | - return true; |
|
886 | - } |
|
887 | - // user error msg |
|
888 | - $error_msg = sprintf( |
|
889 | - esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
890 | - $this->_admin_page_title |
|
891 | - ); |
|
892 | - // developer error msg |
|
893 | - $error_msg .= '||' . $error_msg |
|
894 | - . sprintf( |
|
895 | - esc_html__( |
|
896 | - ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
897 | - 'event_espresso' |
|
898 | - ), |
|
899 | - $route |
|
900 | - ); |
|
901 | - throw new EE_Error($error_msg); |
|
902 | - } |
|
903 | - |
|
904 | - |
|
905 | - /** |
|
906 | - * perform nonce verification |
|
907 | - * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
908 | - * using this method (and save retyping!) |
|
909 | - * |
|
910 | - * @param string $nonce The nonce sent |
|
911 | - * @param string $nonce_ref The nonce reference string (name0) |
|
912 | - * @return void |
|
913 | - * @throws EE_Error |
|
914 | - */ |
|
915 | - protected function _verify_nonce($nonce, $nonce_ref) |
|
916 | - { |
|
917 | - // verify nonce against expected value |
|
918 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
919 | - // these are not the droids you are looking for !!! |
|
920 | - $msg = sprintf( |
|
921 | - esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
922 | - '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
923 | - '</a>' |
|
924 | - ); |
|
925 | - if (WP_DEBUG) { |
|
926 | - $msg .= "\n " |
|
927 | - . sprintf( |
|
928 | - esc_html__( |
|
929 | - 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
930 | - 'event_espresso' |
|
931 | - ), |
|
932 | - __CLASS__ |
|
933 | - ); |
|
934 | - } |
|
935 | - if (! defined('DOING_AJAX')) { |
|
936 | - wp_die($msg); |
|
937 | - } else { |
|
938 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
939 | - $this->_return_json(); |
|
940 | - } |
|
941 | - } |
|
942 | - } |
|
943 | - |
|
944 | - |
|
945 | - /** |
|
946 | - * _route_admin_request() |
|
947 | - * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
948 | - * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
949 | - * in the page routes and then will try to load the corresponding method. |
|
950 | - * |
|
951 | - * @return void |
|
952 | - * @throws EE_Error |
|
953 | - * @throws InvalidArgumentException |
|
954 | - * @throws InvalidDataTypeException |
|
955 | - * @throws InvalidInterfaceException |
|
956 | - * @throws ReflectionException |
|
957 | - */ |
|
958 | - protected function _route_admin_request() |
|
959 | - { |
|
960 | - if (! $this->_is_UI_request) { |
|
961 | - $this->_verify_routes(); |
|
962 | - } |
|
963 | - $nonce_check = isset($this->_route_config['require_nonce']) |
|
964 | - ? $this->_route_config['require_nonce'] |
|
965 | - : true; |
|
966 | - if ($this->_req_action !== 'default' && $nonce_check) { |
|
967 | - // set nonce from post data |
|
968 | - $nonce = isset($this->_req_data[ $this->_req_nonce ]) |
|
969 | - ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) |
|
970 | - : ''; |
|
971 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
972 | - } |
|
973 | - // set the nav_tabs array but ONLY if this is UI_request |
|
974 | - if ($this->_is_UI_request) { |
|
975 | - $this->_set_nav_tabs(); |
|
976 | - } |
|
977 | - // grab callback function |
|
978 | - $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
979 | - // check if callback has args |
|
980 | - $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array(); |
|
981 | - $error_msg = ''; |
|
982 | - // action right before calling route |
|
983 | - // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
984 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
985 | - do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
986 | - } |
|
987 | - // right before calling the route, let's remove _wp_http_referer from the |
|
988 | - // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing). |
|
989 | - $_SERVER['REQUEST_URI'] = remove_query_arg( |
|
990 | - '_wp_http_referer', |
|
991 | - wp_unslash($_SERVER['REQUEST_URI']) |
|
992 | - ); |
|
993 | - if (! empty($func)) { |
|
994 | - if (is_array($func)) { |
|
995 | - list($class, $method) = $func; |
|
996 | - } elseif (strpos($func, '::') !== false) { |
|
997 | - list($class, $method) = explode('::', $func); |
|
998 | - } else { |
|
999 | - $class = $this; |
|
1000 | - $method = $func; |
|
1001 | - } |
|
1002 | - if (! (is_object($class) && $class === $this)) { |
|
1003 | - // send along this admin page object for access by addons. |
|
1004 | - $args['admin_page_object'] = $this; |
|
1005 | - } |
|
1006 | - if (// is it a method on a class that doesn't work? |
|
1007 | - ( |
|
1008 | - ( |
|
1009 | - method_exists($class, $method) |
|
1010 | - && call_user_func_array(array($class, $method), $args) === false |
|
1011 | - ) |
|
1012 | - && ( |
|
1013 | - // is it a standalone function that doesn't work? |
|
1014 | - function_exists($method) |
|
1015 | - && call_user_func_array( |
|
1016 | - $func, |
|
1017 | - array_merge(array('admin_page_object' => $this), $args) |
|
1018 | - ) === false |
|
1019 | - ) |
|
1020 | - ) |
|
1021 | - || ( |
|
1022 | - // is it neither a class method NOR a standalone function? |
|
1023 | - ! method_exists($class, $method) |
|
1024 | - && ! function_exists($method) |
|
1025 | - ) |
|
1026 | - ) { |
|
1027 | - // user error msg |
|
1028 | - $error_msg = esc_html__( |
|
1029 | - 'An error occurred. The requested page route could not be found.', |
|
1030 | - 'event_espresso' |
|
1031 | - ); |
|
1032 | - // developer error msg |
|
1033 | - $error_msg .= '||'; |
|
1034 | - $error_msg .= sprintf( |
|
1035 | - esc_html__( |
|
1036 | - 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
1037 | - 'event_espresso' |
|
1038 | - ), |
|
1039 | - $method |
|
1040 | - ); |
|
1041 | - } |
|
1042 | - if (! empty($error_msg)) { |
|
1043 | - throw new EE_Error($error_msg); |
|
1044 | - } |
|
1045 | - } |
|
1046 | - // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
1047 | - // then we need to reset the routing properties to the new route. |
|
1048 | - // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
1049 | - if ($this->_is_UI_request === false |
|
1050 | - && is_array($this->_route) |
|
1051 | - && ! empty($this->_route['headers_sent_route']) |
|
1052 | - ) { |
|
1053 | - $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
1054 | - } |
|
1055 | - } |
|
1056 | - |
|
1057 | - |
|
1058 | - /** |
|
1059 | - * This method just allows the resetting of page properties in the case where a no headers |
|
1060 | - * route redirects to a headers route in its route config. |
|
1061 | - * |
|
1062 | - * @since 4.3.0 |
|
1063 | - * @param string $new_route New (non header) route to redirect to. |
|
1064 | - * @return void |
|
1065 | - * @throws ReflectionException |
|
1066 | - * @throws InvalidArgumentException |
|
1067 | - * @throws InvalidInterfaceException |
|
1068 | - * @throws InvalidDataTypeException |
|
1069 | - * @throws EE_Error |
|
1070 | - */ |
|
1071 | - protected function _reset_routing_properties($new_route) |
|
1072 | - { |
|
1073 | - $this->_is_UI_request = true; |
|
1074 | - // now we set the current route to whatever the headers_sent_route is set at |
|
1075 | - $this->_req_data['action'] = $new_route; |
|
1076 | - // rerun page setup |
|
1077 | - $this->_page_setup(); |
|
1078 | - } |
|
1079 | - |
|
1080 | - |
|
1081 | - /** |
|
1082 | - * _add_query_arg |
|
1083 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
1084 | - *(internally just uses EEH_URL's function with the same name) |
|
1085 | - * |
|
1086 | - * @param array $args |
|
1087 | - * @param string $url |
|
1088 | - * @param bool $sticky if true, then the existing Request params will be appended to the |
|
1089 | - * generated url in an associative array indexed by the key 'wp_referer'; |
|
1090 | - * Example usage: If the current page is: |
|
1091 | - * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
1092 | - * &action=default&event_id=20&month_range=March%202015 |
|
1093 | - * &_wpnonce=5467821 |
|
1094 | - * and you call: |
|
1095 | - * EE_Admin_Page::add_query_args_and_nonce( |
|
1096 | - * array( |
|
1097 | - * 'action' => 'resend_something', |
|
1098 | - * 'page=>espresso_registrations' |
|
1099 | - * ), |
|
1100 | - * $some_url, |
|
1101 | - * true |
|
1102 | - * ); |
|
1103 | - * It will produce a url in this structure: |
|
1104 | - * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
1105 | - * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
1106 | - * month_range]=March%202015 |
|
1107 | - * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
1108 | - * @return string |
|
1109 | - */ |
|
1110 | - public static function add_query_args_and_nonce( |
|
1111 | - $args = array(), |
|
1112 | - $url = false, |
|
1113 | - $sticky = false, |
|
1114 | - $exclude_nonce = false |
|
1115 | - ) { |
|
1116 | - // if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
1117 | - if ($sticky) { |
|
1118 | - $request = $_REQUEST; |
|
1119 | - unset($request['_wp_http_referer']); |
|
1120 | - unset($request['wp_referer']); |
|
1121 | - foreach ($request as $key => $value) { |
|
1122 | - // do not add nonces |
|
1123 | - if (strpos($key, 'nonce') !== false) { |
|
1124 | - continue; |
|
1125 | - } |
|
1126 | - $args[ 'wp_referer[' . $key . ']' ] = $value; |
|
1127 | - } |
|
1128 | - } |
|
1129 | - return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
1130 | - } |
|
1131 | - |
|
1132 | - |
|
1133 | - /** |
|
1134 | - * This returns a generated link that will load the related help tab. |
|
1135 | - * |
|
1136 | - * @param string $help_tab_id the id for the connected help tab |
|
1137 | - * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
1138 | - * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
1139 | - * @uses EEH_Template::get_help_tab_link() |
|
1140 | - * @return string generated link |
|
1141 | - */ |
|
1142 | - protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
1143 | - { |
|
1144 | - return EEH_Template::get_help_tab_link( |
|
1145 | - $help_tab_id, |
|
1146 | - $this->page_slug, |
|
1147 | - $this->_req_action, |
|
1148 | - $icon_style, |
|
1149 | - $help_text |
|
1150 | - ); |
|
1151 | - } |
|
1152 | - |
|
1153 | - |
|
1154 | - /** |
|
1155 | - * _add_help_tabs |
|
1156 | - * Note child classes define their help tabs within the page_config array. |
|
1157 | - * |
|
1158 | - * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
1159 | - * @return void |
|
1160 | - * @throws DomainException |
|
1161 | - * @throws EE_Error |
|
1162 | - */ |
|
1163 | - protected function _add_help_tabs() |
|
1164 | - { |
|
1165 | - $tour_buttons = ''; |
|
1166 | - if (isset($this->_page_config[ $this->_req_action ])) { |
|
1167 | - $config = $this->_page_config[ $this->_req_action ]; |
|
1168 | - // is there a help tour for the current route? if there is let's setup the tour buttons |
|
1169 | - if (isset($this->_help_tour[ $this->_req_action ])) { |
|
1170 | - $tb = array(); |
|
1171 | - $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
1172 | - foreach ($this->_help_tour['tours'] as $tour) { |
|
1173 | - // if this is the end tour then we don't need to setup a button |
|
1174 | - if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) { |
|
1175 | - continue; |
|
1176 | - } |
|
1177 | - $tb[] = '<button id="trigger-tour-' |
|
1178 | - . $tour->get_slug() |
|
1179 | - . '" class="button-primary trigger-ee-help-tour">' |
|
1180 | - . $tour->get_label() |
|
1181 | - . '</button>'; |
|
1182 | - } |
|
1183 | - $tour_buttons .= implode('<br />', $tb); |
|
1184 | - $tour_buttons .= '</div></div>'; |
|
1185 | - } |
|
1186 | - // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
1187 | - if (is_array($config) && isset($config['help_sidebar'])) { |
|
1188 | - // check that the callback given is valid |
|
1189 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
1190 | - throw new EE_Error( |
|
1191 | - sprintf( |
|
1192 | - esc_html__( |
|
1193 | - 'The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
1194 | - 'event_espresso' |
|
1195 | - ), |
|
1196 | - $config['help_sidebar'], |
|
1197 | - get_class($this) |
|
1198 | - ) |
|
1199 | - ); |
|
1200 | - } |
|
1201 | - $content = apply_filters( |
|
1202 | - 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
1203 | - $this->{$config['help_sidebar']}() |
|
1204 | - ); |
|
1205 | - $content .= $tour_buttons; // add help tour buttons. |
|
1206 | - // do we have any help tours setup? Cause if we do we want to add the buttons |
|
1207 | - $this->_current_screen->set_help_sidebar($content); |
|
1208 | - } |
|
1209 | - // if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar. |
|
1210 | - if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
1211 | - $this->_current_screen->set_help_sidebar($tour_buttons); |
|
1212 | - } |
|
1213 | - // handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
1214 | - if (! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
1215 | - $_ht['id'] = $this->page_slug; |
|
1216 | - $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
|
1217 | - $_ht['content'] = '<p>' |
|
1218 | - . esc_html__( |
|
1219 | - 'The buttons to the right allow you to start/restart any help tours available for this page', |
|
1220 | - 'event_espresso' |
|
1221 | - ) . '</p>'; |
|
1222 | - $this->_current_screen->add_help_tab($_ht); |
|
1223 | - } |
|
1224 | - if (! isset($config['help_tabs'])) { |
|
1225 | - return; |
|
1226 | - } //no help tabs for this route |
|
1227 | - foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
1228 | - // we're here so there ARE help tabs! |
|
1229 | - // make sure we've got what we need |
|
1230 | - if (! isset($cfg['title'])) { |
|
1231 | - throw new EE_Error( |
|
1232 | - esc_html__( |
|
1233 | - 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
1234 | - 'event_espresso' |
|
1235 | - ) |
|
1236 | - ); |
|
1237 | - } |
|
1238 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
1239 | - throw new EE_Error( |
|
1240 | - esc_html__( |
|
1241 | - 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
1242 | - 'event_espresso' |
|
1243 | - ) |
|
1244 | - ); |
|
1245 | - } |
|
1246 | - // first priority goes to content. |
|
1247 | - if (! empty($cfg['content'])) { |
|
1248 | - $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
1249 | - // second priority goes to filename |
|
1250 | - } elseif (! empty($cfg['filename'])) { |
|
1251 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
1252 | - // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
1253 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
1254 | - . basename($this->_get_dir()) |
|
1255 | - . '/help_tabs/' |
|
1256 | - . $cfg['filename'] |
|
1257 | - . '.help_tab.php' : $file_path; |
|
1258 | - // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
1259 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
1260 | - EE_Error::add_error( |
|
1261 | - sprintf( |
|
1262 | - esc_html__( |
|
1263 | - 'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
1264 | - 'event_espresso' |
|
1265 | - ), |
|
1266 | - $tab_id, |
|
1267 | - key($config), |
|
1268 | - $file_path |
|
1269 | - ), |
|
1270 | - __FILE__, |
|
1271 | - __FUNCTION__, |
|
1272 | - __LINE__ |
|
1273 | - ); |
|
1274 | - return; |
|
1275 | - } |
|
1276 | - $template_args['admin_page_obj'] = $this; |
|
1277 | - $content = EEH_Template::display_template( |
|
1278 | - $file_path, |
|
1279 | - $template_args, |
|
1280 | - true |
|
1281 | - ); |
|
1282 | - } else { |
|
1283 | - $content = ''; |
|
1284 | - } |
|
1285 | - // check if callback is valid |
|
1286 | - if (empty($content) && ( |
|
1287 | - ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
1288 | - ) |
|
1289 | - ) { |
|
1290 | - EE_Error::add_error( |
|
1291 | - sprintf( |
|
1292 | - esc_html__( |
|
1293 | - 'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
1294 | - 'event_espresso' |
|
1295 | - ), |
|
1296 | - $cfg['title'] |
|
1297 | - ), |
|
1298 | - __FILE__, |
|
1299 | - __FUNCTION__, |
|
1300 | - __LINE__ |
|
1301 | - ); |
|
1302 | - return; |
|
1303 | - } |
|
1304 | - // setup config array for help tab method |
|
1305 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
1306 | - $_ht = array( |
|
1307 | - 'id' => $id, |
|
1308 | - 'title' => $cfg['title'], |
|
1309 | - 'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null, |
|
1310 | - 'content' => $content, |
|
1311 | - ); |
|
1312 | - $this->_current_screen->add_help_tab($_ht); |
|
1313 | - } |
|
1314 | - } |
|
1315 | - } |
|
1316 | - |
|
1317 | - |
|
1318 | - /** |
|
1319 | - * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is |
|
1320 | - * an array with properties for setting up usage of the joyride plugin |
|
1321 | - * |
|
1322 | - * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
1323 | - * @see instructions regarding the format and construction of the "help_tour" array element is found in the |
|
1324 | - * _set_page_config() comments |
|
1325 | - * @return void |
|
1326 | - * @throws EE_Error |
|
1327 | - * @throws InvalidArgumentException |
|
1328 | - * @throws InvalidDataTypeException |
|
1329 | - * @throws InvalidInterfaceException |
|
1330 | - */ |
|
1331 | - protected function _add_help_tour() |
|
1332 | - { |
|
1333 | - $tours = array(); |
|
1334 | - $this->_help_tour = array(); |
|
1335 | - // exit early if help tours are turned off globally |
|
1336 | - if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS) |
|
1337 | - || ! EE_Registry::instance()->CFG->admin->help_tour_activation |
|
1338 | - ) { |
|
1339 | - return; |
|
1340 | - } |
|
1341 | - // loop through _page_config to find any help_tour defined |
|
1342 | - foreach ($this->_page_config as $route => $config) { |
|
1343 | - // we're only going to set things up for this route |
|
1344 | - if ($route !== $this->_req_action) { |
|
1345 | - continue; |
|
1346 | - } |
|
1347 | - if (isset($config['help_tour'])) { |
|
1348 | - foreach ($config['help_tour'] as $tour) { |
|
1349 | - $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
1350 | - // let's see if we can get that file... |
|
1351 | - // if not its possible this is a decaf route not set in caffeinated |
|
1352 | - // so lets try and get the caffeinated equivalent |
|
1353 | - $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
1354 | - . basename($this->_get_dir()) |
|
1355 | - . '/help_tours/' |
|
1356 | - . $tour |
|
1357 | - . '.class.php' : $file_path; |
|
1358 | - // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
1359 | - if (! is_readable($file_path)) { |
|
1360 | - EE_Error::add_error( |
|
1361 | - sprintf( |
|
1362 | - esc_html__( |
|
1363 | - 'The file path given for the help tour (%s) is not a valid path. Please check that the string you set for the help tour on this route (%s) is the correct spelling', |
|
1364 | - 'event_espresso' |
|
1365 | - ), |
|
1366 | - $file_path, |
|
1367 | - $tour |
|
1368 | - ), |
|
1369 | - __FILE__, |
|
1370 | - __FUNCTION__, |
|
1371 | - __LINE__ |
|
1372 | - ); |
|
1373 | - return; |
|
1374 | - } |
|
1375 | - require_once $file_path; |
|
1376 | - if (! class_exists($tour)) { |
|
1377 | - $error_msg[] = sprintf( |
|
1378 | - esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), |
|
1379 | - $tour |
|
1380 | - ); |
|
1381 | - $error_msg[] = $error_msg[0] . "\r\n" |
|
1382 | - . sprintf( |
|
1383 | - esc_html__( |
|
1384 | - 'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
|
1385 | - 'event_espresso' |
|
1386 | - ), |
|
1387 | - $tour, |
|
1388 | - '<br />', |
|
1389 | - $tour, |
|
1390 | - $this->_req_action, |
|
1391 | - get_class($this) |
|
1392 | - ); |
|
1393 | - throw new EE_Error(implode('||', $error_msg)); |
|
1394 | - } |
|
1395 | - $tour_obj = new $tour($this->_is_caf); |
|
1396 | - $tours[] = $tour_obj; |
|
1397 | - $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
1398 | - } |
|
1399 | - // let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
1400 | - $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
1401 | - $tours[] = $end_stop_tour; |
|
1402 | - $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
1403 | - } |
|
1404 | - } |
|
1405 | - if (! empty($tours)) { |
|
1406 | - $this->_help_tour['tours'] = $tours; |
|
1407 | - } |
|
1408 | - // that's it! Now that the $_help_tours property is set (or not) |
|
1409 | - // the scripts and html should be taken care of automatically. |
|
1410 | - } |
|
1411 | - |
|
1412 | - |
|
1413 | - /** |
|
1414 | - * This simply sets up any qtips that have been defined in the page config |
|
1415 | - * |
|
1416 | - * @return void |
|
1417 | - */ |
|
1418 | - protected function _add_qtips() |
|
1419 | - { |
|
1420 | - if (isset($this->_route_config['qtips'])) { |
|
1421 | - $qtips = (array) $this->_route_config['qtips']; |
|
1422 | - // load qtip loader |
|
1423 | - $path = array( |
|
1424 | - $this->_get_dir() . '/qtips/', |
|
1425 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
1426 | - ); |
|
1427 | - EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
1428 | - } |
|
1429 | - } |
|
1430 | - |
|
1431 | - |
|
1432 | - /** |
|
1433 | - * _set_nav_tabs |
|
1434 | - * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
1435 | - * wish to add additional tabs or modify accordingly. |
|
1436 | - * |
|
1437 | - * @return void |
|
1438 | - * @throws InvalidArgumentException |
|
1439 | - * @throws InvalidInterfaceException |
|
1440 | - * @throws InvalidDataTypeException |
|
1441 | - */ |
|
1442 | - protected function _set_nav_tabs() |
|
1443 | - { |
|
1444 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1445 | - $i = 0; |
|
1446 | - foreach ($this->_page_config as $slug => $config) { |
|
1447 | - if (! is_array($config) |
|
1448 | - || ( |
|
1449 | - is_array($config) |
|
1450 | - && ( |
|
1451 | - (isset($config['nav']) && ! $config['nav']) |
|
1452 | - || ! isset($config['nav']) |
|
1453 | - ) |
|
1454 | - ) |
|
1455 | - ) { |
|
1456 | - continue; |
|
1457 | - } |
|
1458 | - // no nav tab for this config |
|
1459 | - // check for persistent flag |
|
1460 | - if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
1461 | - // nav tab is only to appear when route requested. |
|
1462 | - continue; |
|
1463 | - } |
|
1464 | - if (! $this->check_user_access($slug, true)) { |
|
1465 | - // no nav tab because current user does not have access. |
|
1466 | - continue; |
|
1467 | - } |
|
1468 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
1469 | - $this->_nav_tabs[ $slug ] = array( |
|
1470 | - 'url' => isset($config['nav']['url']) |
|
1471 | - ? $config['nav']['url'] |
|
1472 | - : self::add_query_args_and_nonce( |
|
1473 | - array('action' => $slug), |
|
1474 | - $this->_admin_base_url |
|
1475 | - ), |
|
1476 | - 'link_text' => isset($config['nav']['label']) |
|
1477 | - ? $config['nav']['label'] |
|
1478 | - : ucwords( |
|
1479 | - str_replace('_', ' ', $slug) |
|
1480 | - ), |
|
1481 | - 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
1482 | - 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
1483 | - ); |
|
1484 | - $i++; |
|
1485 | - } |
|
1486 | - // if $this->_nav_tabs is empty then lets set the default |
|
1487 | - if (empty($this->_nav_tabs)) { |
|
1488 | - $this->_nav_tabs[ $this->_default_nav_tab_name ] = array( |
|
1489 | - 'url' => $this->_admin_base_url, |
|
1490 | - 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
1491 | - 'css_class' => 'nav-tab-active', |
|
1492 | - 'order' => 10, |
|
1493 | - ); |
|
1494 | - } |
|
1495 | - // now let's sort the tabs according to order |
|
1496 | - usort($this->_nav_tabs, array($this, '_sort_nav_tabs')); |
|
1497 | - } |
|
1498 | - |
|
1499 | - |
|
1500 | - /** |
|
1501 | - * _set_current_labels |
|
1502 | - * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
1503 | - * property array |
|
1504 | - * |
|
1505 | - * @return void |
|
1506 | - */ |
|
1507 | - private function _set_current_labels() |
|
1508 | - { |
|
1509 | - if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
1510 | - foreach ($this->_route_config['labels'] as $label => $text) { |
|
1511 | - if (is_array($text)) { |
|
1512 | - foreach ($text as $sublabel => $subtext) { |
|
1513 | - $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
1514 | - } |
|
1515 | - } else { |
|
1516 | - $this->_labels[ $label ] = $text; |
|
1517 | - } |
|
1518 | - } |
|
1519 | - } |
|
1520 | - } |
|
1521 | - |
|
1522 | - |
|
1523 | - /** |
|
1524 | - * verifies user access for this admin page |
|
1525 | - * |
|
1526 | - * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
1527 | - * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
1528 | - * return false if verify fail. |
|
1529 | - * @return bool |
|
1530 | - * @throws InvalidArgumentException |
|
1531 | - * @throws InvalidDataTypeException |
|
1532 | - * @throws InvalidInterfaceException |
|
1533 | - */ |
|
1534 | - public function check_user_access($route_to_check = '', $verify_only = false) |
|
1535 | - { |
|
1536 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1537 | - $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
1538 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
1539 | - && is_array( |
|
1540 | - $this->_page_routes[ $route_to_check ] |
|
1541 | - ) |
|
1542 | - && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
1543 | - ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
1544 | - if (empty($capability) && empty($route_to_check)) { |
|
1545 | - $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
1546 | - : $this->_route['capability']; |
|
1547 | - } else { |
|
1548 | - $capability = empty($capability) ? 'manage_options' : $capability; |
|
1549 | - } |
|
1550 | - $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
1551 | - if (! defined('DOING_AJAX') |
|
1552 | - && ( |
|
1553 | - ! function_exists('is_admin') |
|
1554 | - || ! EE_Registry::instance()->CAP->current_user_can( |
|
1555 | - $capability, |
|
1556 | - $this->page_slug |
|
1557 | - . '_' |
|
1558 | - . $route_to_check, |
|
1559 | - $id |
|
1560 | - ) |
|
1561 | - ) |
|
1562 | - ) { |
|
1563 | - if ($verify_only) { |
|
1564 | - return false; |
|
1565 | - } |
|
1566 | - if (is_user_logged_in()) { |
|
1567 | - wp_die(__('You do not have access to this route.', 'event_espresso')); |
|
1568 | - } else { |
|
1569 | - return false; |
|
1570 | - } |
|
1571 | - } |
|
1572 | - return true; |
|
1573 | - } |
|
1574 | - |
|
1575 | - |
|
1576 | - /** |
|
1577 | - * admin_init_global |
|
1578 | - * This runs all the code that we want executed within the WP admin_init hook. |
|
1579 | - * This method executes for ALL EE Admin pages. |
|
1580 | - * |
|
1581 | - * @return void |
|
1582 | - */ |
|
1583 | - public function admin_init_global() |
|
1584 | - { |
|
1585 | - } |
|
1586 | - |
|
1587 | - |
|
1588 | - /** |
|
1589 | - * wp_loaded_global |
|
1590 | - * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
1591 | - * EE_Admin page and will execute on every EE Admin Page load |
|
1592 | - * |
|
1593 | - * @return void |
|
1594 | - */ |
|
1595 | - public function wp_loaded() |
|
1596 | - { |
|
1597 | - } |
|
1598 | - |
|
1599 | - |
|
1600 | - /** |
|
1601 | - * admin_notices |
|
1602 | - * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
1603 | - * ALL EE_Admin pages. |
|
1604 | - * |
|
1605 | - * @return void |
|
1606 | - */ |
|
1607 | - public function admin_notices_global() |
|
1608 | - { |
|
1609 | - $this->_display_no_javascript_warning(); |
|
1610 | - $this->_display_espresso_notices(); |
|
1611 | - } |
|
1612 | - |
|
1613 | - |
|
1614 | - public function network_admin_notices_global() |
|
1615 | - { |
|
1616 | - $this->_display_no_javascript_warning(); |
|
1617 | - $this->_display_espresso_notices(); |
|
1618 | - } |
|
1619 | - |
|
1620 | - |
|
1621 | - /** |
|
1622 | - * admin_footer_scripts_global |
|
1623 | - * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
1624 | - * will apply on ALL EE_Admin pages. |
|
1625 | - * |
|
1626 | - * @return void |
|
1627 | - */ |
|
1628 | - public function admin_footer_scripts_global() |
|
1629 | - { |
|
1630 | - $this->_add_admin_page_ajax_loading_img(); |
|
1631 | - $this->_add_admin_page_overlay(); |
|
1632 | - // if metaboxes are present we need to add the nonce field |
|
1633 | - if (isset($this->_route_config['metaboxes']) |
|
1634 | - || isset($this->_route_config['list_table']) |
|
1635 | - || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
1636 | - ) { |
|
1637 | - wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
1638 | - wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
1639 | - } |
|
1640 | - } |
|
1641 | - |
|
1642 | - |
|
1643 | - /** |
|
1644 | - * admin_footer_global |
|
1645 | - * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on |
|
1646 | - * ALL EE_Admin Pages. |
|
1647 | - * |
|
1648 | - * @return void |
|
1649 | - * @throws EE_Error |
|
1650 | - */ |
|
1651 | - public function admin_footer_global() |
|
1652 | - { |
|
1653 | - // dialog container for dialog helper |
|
1654 | - $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
1655 | - $d_cont .= '<div class="ee-notices"></div>'; |
|
1656 | - $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
|
1657 | - $d_cont .= '</div>'; |
|
1658 | - echo $d_cont; |
|
1659 | - // help tour stuff? |
|
1660 | - if (isset($this->_help_tour[ $this->_req_action ])) { |
|
1661 | - echo implode('<br />', $this->_help_tour[ $this->_req_action ]); |
|
1662 | - } |
|
1663 | - // current set timezone for timezone js |
|
1664 | - echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
1665 | - } |
|
1666 | - |
|
1667 | - |
|
1668 | - /** |
|
1669 | - * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
1670 | - * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
1671 | - * help popups then in your templates or your content you set "triggers" for the content using the |
|
1672 | - * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
1673 | - * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
1674 | - * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
1675 | - * for the |
|
1676 | - * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
1677 | - * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
1678 | - * 'help_trigger_id' => array( |
|
1679 | - * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
1680 | - * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
1681 | - * ) |
|
1682 | - * ); |
|
1683 | - * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
1684 | - * |
|
1685 | - * @param array $help_array |
|
1686 | - * @param bool $display |
|
1687 | - * @return string content |
|
1688 | - * @throws DomainException |
|
1689 | - * @throws EE_Error |
|
1690 | - */ |
|
1691 | - protected function _set_help_popup_content($help_array = array(), $display = false) |
|
1692 | - { |
|
1693 | - $content = ''; |
|
1694 | - $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
1695 | - // loop through the array and setup content |
|
1696 | - foreach ($help_array as $trigger => $help) { |
|
1697 | - // make sure the array is setup properly |
|
1698 | - if (! isset($help['title']) || ! isset($help['content'])) { |
|
1699 | - throw new EE_Error( |
|
1700 | - esc_html__( |
|
1701 | - 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
1702 | - 'event_espresso' |
|
1703 | - ) |
|
1704 | - ); |
|
1705 | - } |
|
1706 | - // we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
1707 | - $template_args = array( |
|
1708 | - 'help_popup_id' => $trigger, |
|
1709 | - 'help_popup_title' => $help['title'], |
|
1710 | - 'help_popup_content' => $help['content'], |
|
1711 | - ); |
|
1712 | - $content .= EEH_Template::display_template( |
|
1713 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
1714 | - $template_args, |
|
1715 | - true |
|
1716 | - ); |
|
1717 | - } |
|
1718 | - if ($display) { |
|
1719 | - echo $content; |
|
1720 | - return ''; |
|
1721 | - } |
|
1722 | - return $content; |
|
1723 | - } |
|
1724 | - |
|
1725 | - |
|
1726 | - /** |
|
1727 | - * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
1728 | - * |
|
1729 | - * @return array properly formatted array for help popup content |
|
1730 | - * @throws EE_Error |
|
1731 | - */ |
|
1732 | - private function _get_help_content() |
|
1733 | - { |
|
1734 | - // what is the method we're looking for? |
|
1735 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
1736 | - // if method doesn't exist let's get out. |
|
1737 | - if (! method_exists($this, $method_name)) { |
|
1738 | - return array(); |
|
1739 | - } |
|
1740 | - // k we're good to go let's retrieve the help array |
|
1741 | - $help_array = call_user_func(array($this, $method_name)); |
|
1742 | - // make sure we've got an array! |
|
1743 | - if (! is_array($help_array)) { |
|
1744 | - throw new EE_Error( |
|
1745 | - esc_html__( |
|
1746 | - 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
1747 | - 'event_espresso' |
|
1748 | - ) |
|
1749 | - ); |
|
1750 | - } |
|
1751 | - return $help_array; |
|
1752 | - } |
|
1753 | - |
|
1754 | - |
|
1755 | - /** |
|
1756 | - * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
1757 | - * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
1758 | - * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
1759 | - * |
|
1760 | - * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
1761 | - * @param boolean $display if false then we return the trigger string |
|
1762 | - * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
1763 | - * @return string |
|
1764 | - * @throws DomainException |
|
1765 | - * @throws EE_Error |
|
1766 | - */ |
|
1767 | - protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640')) |
|
1768 | - { |
|
1769 | - if (defined('DOING_AJAX')) { |
|
1770 | - return ''; |
|
1771 | - } |
|
1772 | - // let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
1773 | - $help_array = $this->_get_help_content(); |
|
1774 | - $help_content = ''; |
|
1775 | - if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
1776 | - $help_array[ $trigger_id ] = array( |
|
1777 | - 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
1778 | - 'content' => esc_html__( |
|
1779 | - 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
1780 | - 'event_espresso' |
|
1781 | - ), |
|
1782 | - ); |
|
1783 | - $help_content = $this->_set_help_popup_content($help_array, false); |
|
1784 | - } |
|
1785 | - // let's setup the trigger |
|
1786 | - $content = '<a class="ee-dialog" href="?height=' |
|
1787 | - . $dimensions[0] |
|
1788 | - . '&width=' |
|
1789 | - . $dimensions[1] |
|
1790 | - . '&inlineId=' |
|
1791 | - . $trigger_id |
|
1792 | - . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
1793 | - $content .= $help_content; |
|
1794 | - if ($display) { |
|
1795 | - echo $content; |
|
1796 | - return ''; |
|
1797 | - } |
|
1798 | - return $content; |
|
1799 | - } |
|
1800 | - |
|
1801 | - |
|
1802 | - /** |
|
1803 | - * _add_global_screen_options |
|
1804 | - * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
1805 | - * This particular method will add_screen_options on ALL EE_Admin Pages |
|
1806 | - * |
|
1807 | - * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
1808 | - * see also WP_Screen object documents... |
|
1809 | - * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
1810 | - * @abstract |
|
1811 | - * @return void |
|
1812 | - */ |
|
1813 | - private function _add_global_screen_options() |
|
1814 | - { |
|
1815 | - } |
|
1816 | - |
|
1817 | - |
|
1818 | - /** |
|
1819 | - * _add_global_feature_pointers |
|
1820 | - * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
1821 | - * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
1822 | - * Note: this is just a placeholder for now. Implementation will come down the road |
|
1823 | - * |
|
1824 | - * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
1825 | - * extended) also see: |
|
1826 | - * @link http://eamann.com/tech/wordpress-portland/ |
|
1827 | - * @abstract |
|
1828 | - * @return void |
|
1829 | - */ |
|
1830 | - private function _add_global_feature_pointers() |
|
1831 | - { |
|
1832 | - } |
|
1833 | - |
|
1834 | - |
|
1835 | - /** |
|
1836 | - * load_global_scripts_styles |
|
1837 | - * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
1838 | - * |
|
1839 | - * @return void |
|
1840 | - * @throws EE_Error |
|
1841 | - */ |
|
1842 | - public function load_global_scripts_styles() |
|
1843 | - { |
|
1844 | - /** STYLES **/ |
|
1845 | - // add debugging styles |
|
1846 | - if (WP_DEBUG) { |
|
1847 | - add_action('admin_head', array($this, 'add_xdebug_style')); |
|
1848 | - } |
|
1849 | - // register all styles |
|
1850 | - wp_register_style( |
|
1851 | - 'espresso-ui-theme', |
|
1852 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
1853 | - array(), |
|
1854 | - EVENT_ESPRESSO_VERSION |
|
1855 | - ); |
|
1856 | - wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
1857 | - // helpers styles |
|
1858 | - wp_register_style( |
|
1859 | - 'ee-text-links', |
|
1860 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
1861 | - array(), |
|
1862 | - EVENT_ESPRESSO_VERSION |
|
1863 | - ); |
|
1864 | - /** SCRIPTS **/ |
|
1865 | - // register all scripts |
|
1866 | - wp_register_script( |
|
1867 | - 'ee-dialog', |
|
1868 | - EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
1869 | - array('jquery', 'jquery-ui-draggable'), |
|
1870 | - EVENT_ESPRESSO_VERSION, |
|
1871 | - true |
|
1872 | - ); |
|
1873 | - wp_register_script( |
|
1874 | - 'ee_admin_js', |
|
1875 | - EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
1876 | - array('espresso_core', 'ee-parse-uri', 'ee-dialog'), |
|
1877 | - EVENT_ESPRESSO_VERSION, |
|
1878 | - true |
|
1879 | - ); |
|
1880 | - wp_register_script( |
|
1881 | - 'jquery-ui-timepicker-addon', |
|
1882 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
1883 | - array('jquery-ui-datepicker', 'jquery-ui-slider'), |
|
1884 | - EVENT_ESPRESSO_VERSION, |
|
1885 | - true |
|
1886 | - ); |
|
1887 | - add_filter('FHEE_load_joyride', '__return_true'); |
|
1888 | - // script for sorting tables |
|
1889 | - wp_register_script( |
|
1890 | - 'espresso_ajax_table_sorting', |
|
1891 | - EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
1892 | - array('ee_admin_js', 'jquery-ui-sortable'), |
|
1893 | - EVENT_ESPRESSO_VERSION, |
|
1894 | - true |
|
1895 | - ); |
|
1896 | - // script for parsing uri's |
|
1897 | - wp_register_script( |
|
1898 | - 'ee-parse-uri', |
|
1899 | - EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
1900 | - array(), |
|
1901 | - EVENT_ESPRESSO_VERSION, |
|
1902 | - true |
|
1903 | - ); |
|
1904 | - // and parsing associative serialized form elements |
|
1905 | - wp_register_script( |
|
1906 | - 'ee-serialize-full-array', |
|
1907 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
1908 | - array('jquery'), |
|
1909 | - EVENT_ESPRESSO_VERSION, |
|
1910 | - true |
|
1911 | - ); |
|
1912 | - // helpers scripts |
|
1913 | - wp_register_script( |
|
1914 | - 'ee-text-links', |
|
1915 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
1916 | - array('jquery'), |
|
1917 | - EVENT_ESPRESSO_VERSION, |
|
1918 | - true |
|
1919 | - ); |
|
1920 | - wp_register_script( |
|
1921 | - 'ee-moment-core', |
|
1922 | - EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
1923 | - array(), |
|
1924 | - EVENT_ESPRESSO_VERSION, |
|
1925 | - true |
|
1926 | - ); |
|
1927 | - wp_register_script( |
|
1928 | - 'ee-moment', |
|
1929 | - EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
1930 | - array('ee-moment-core'), |
|
1931 | - EVENT_ESPRESSO_VERSION, |
|
1932 | - true |
|
1933 | - ); |
|
1934 | - wp_register_script( |
|
1935 | - 'ee-datepicker', |
|
1936 | - EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
1937 | - array('jquery-ui-timepicker-addon', 'ee-moment'), |
|
1938 | - EVENT_ESPRESSO_VERSION, |
|
1939 | - true |
|
1940 | - ); |
|
1941 | - // google charts |
|
1942 | - wp_register_script( |
|
1943 | - 'google-charts', |
|
1944 | - 'https://www.gstatic.com/charts/loader.js', |
|
1945 | - array(), |
|
1946 | - EVENT_ESPRESSO_VERSION, |
|
1947 | - false |
|
1948 | - ); |
|
1949 | - // ENQUEUE ALL BASICS BY DEFAULT |
|
1950 | - wp_enqueue_style('ee-admin-css'); |
|
1951 | - wp_enqueue_script('ee_admin_js'); |
|
1952 | - wp_enqueue_script('ee-accounting'); |
|
1953 | - wp_enqueue_script('jquery-validate'); |
|
1954 | - // taking care of metaboxes |
|
1955 | - if (empty($this->_cpt_route) |
|
1956 | - && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
1957 | - ) { |
|
1958 | - wp_enqueue_script('dashboard'); |
|
1959 | - } |
|
1960 | - // LOCALIZED DATA |
|
1961 | - // localize script for ajax lazy loading |
|
1962 | - $lazy_loader_container_ids = apply_filters( |
|
1963 | - 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
1964 | - array('espresso_news_post_box_content') |
|
1965 | - ); |
|
1966 | - wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
1967 | - /** |
|
1968 | - * help tour stuff |
|
1969 | - */ |
|
1970 | - if (! empty($this->_help_tour)) { |
|
1971 | - // register the js for kicking things off |
|
1972 | - wp_enqueue_script( |
|
1973 | - 'ee-help-tour', |
|
1974 | - EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
1975 | - array('jquery-joyride'), |
|
1976 | - EVENT_ESPRESSO_VERSION, |
|
1977 | - true |
|
1978 | - ); |
|
1979 | - $tours = array(); |
|
1980 | - // setup tours for the js tour object |
|
1981 | - foreach ($this->_help_tour['tours'] as $tour) { |
|
1982 | - if ($tour instanceof EE_Help_Tour) { |
|
1983 | - $tours[] = array( |
|
1984 | - 'id' => $tour->get_slug(), |
|
1985 | - 'options' => $tour->get_options(), |
|
1986 | - ); |
|
1987 | - } |
|
1988 | - } |
|
1989 | - wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
1990 | - // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
1991 | - } |
|
1992 | - } |
|
1993 | - |
|
1994 | - |
|
1995 | - /** |
|
1996 | - * admin_footer_scripts_eei18n_js_strings |
|
1997 | - * |
|
1998 | - * @return void |
|
1999 | - */ |
|
2000 | - public function admin_footer_scripts_eei18n_js_strings() |
|
2001 | - { |
|
2002 | - EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
2003 | - EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__( |
|
2004 | - 'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', |
|
2005 | - 'event_espresso' |
|
2006 | - ); |
|
2007 | - EE_Registry::$i18n_js_strings['January'] = esc_html__('January', 'event_espresso'); |
|
2008 | - EE_Registry::$i18n_js_strings['February'] = esc_html__('February', 'event_espresso'); |
|
2009 | - EE_Registry::$i18n_js_strings['March'] = esc_html__('March', 'event_espresso'); |
|
2010 | - EE_Registry::$i18n_js_strings['April'] = esc_html__('April', 'event_espresso'); |
|
2011 | - EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
2012 | - EE_Registry::$i18n_js_strings['June'] = esc_html__('June', 'event_espresso'); |
|
2013 | - EE_Registry::$i18n_js_strings['July'] = esc_html__('July', 'event_espresso'); |
|
2014 | - EE_Registry::$i18n_js_strings['August'] = esc_html__('August', 'event_espresso'); |
|
2015 | - EE_Registry::$i18n_js_strings['September'] = esc_html__('September', 'event_espresso'); |
|
2016 | - EE_Registry::$i18n_js_strings['October'] = esc_html__('October', 'event_espresso'); |
|
2017 | - EE_Registry::$i18n_js_strings['November'] = esc_html__('November', 'event_espresso'); |
|
2018 | - EE_Registry::$i18n_js_strings['December'] = esc_html__('December', 'event_espresso'); |
|
2019 | - EE_Registry::$i18n_js_strings['Jan'] = esc_html__('Jan', 'event_espresso'); |
|
2020 | - EE_Registry::$i18n_js_strings['Feb'] = esc_html__('Feb', 'event_espresso'); |
|
2021 | - EE_Registry::$i18n_js_strings['Mar'] = esc_html__('Mar', 'event_espresso'); |
|
2022 | - EE_Registry::$i18n_js_strings['Apr'] = esc_html__('Apr', 'event_espresso'); |
|
2023 | - EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
2024 | - EE_Registry::$i18n_js_strings['Jun'] = esc_html__('Jun', 'event_espresso'); |
|
2025 | - EE_Registry::$i18n_js_strings['Jul'] = esc_html__('Jul', 'event_espresso'); |
|
2026 | - EE_Registry::$i18n_js_strings['Aug'] = esc_html__('Aug', 'event_espresso'); |
|
2027 | - EE_Registry::$i18n_js_strings['Sep'] = esc_html__('Sep', 'event_espresso'); |
|
2028 | - EE_Registry::$i18n_js_strings['Oct'] = esc_html__('Oct', 'event_espresso'); |
|
2029 | - EE_Registry::$i18n_js_strings['Nov'] = esc_html__('Nov', 'event_espresso'); |
|
2030 | - EE_Registry::$i18n_js_strings['Dec'] = esc_html__('Dec', 'event_espresso'); |
|
2031 | - EE_Registry::$i18n_js_strings['Sunday'] = esc_html__('Sunday', 'event_espresso'); |
|
2032 | - EE_Registry::$i18n_js_strings['Monday'] = esc_html__('Monday', 'event_espresso'); |
|
2033 | - EE_Registry::$i18n_js_strings['Tuesday'] = esc_html__('Tuesday', 'event_espresso'); |
|
2034 | - EE_Registry::$i18n_js_strings['Wednesday'] = esc_html__('Wednesday', 'event_espresso'); |
|
2035 | - EE_Registry::$i18n_js_strings['Thursday'] = esc_html__('Thursday', 'event_espresso'); |
|
2036 | - EE_Registry::$i18n_js_strings['Friday'] = esc_html__('Friday', 'event_espresso'); |
|
2037 | - EE_Registry::$i18n_js_strings['Saturday'] = esc_html__('Saturday', 'event_espresso'); |
|
2038 | - EE_Registry::$i18n_js_strings['Sun'] = esc_html__('Sun', 'event_espresso'); |
|
2039 | - EE_Registry::$i18n_js_strings['Mon'] = esc_html__('Mon', 'event_espresso'); |
|
2040 | - EE_Registry::$i18n_js_strings['Tue'] = esc_html__('Tue', 'event_espresso'); |
|
2041 | - EE_Registry::$i18n_js_strings['Wed'] = esc_html__('Wed', 'event_espresso'); |
|
2042 | - EE_Registry::$i18n_js_strings['Thu'] = esc_html__('Thu', 'event_espresso'); |
|
2043 | - EE_Registry::$i18n_js_strings['Fri'] = esc_html__('Fri', 'event_espresso'); |
|
2044 | - EE_Registry::$i18n_js_strings['Sat'] = esc_html__('Sat', 'event_espresso'); |
|
2045 | - } |
|
2046 | - |
|
2047 | - |
|
2048 | - /** |
|
2049 | - * load enhanced xdebug styles for ppl with failing eyesight |
|
2050 | - * |
|
2051 | - * @return void |
|
2052 | - */ |
|
2053 | - public function add_xdebug_style() |
|
2054 | - { |
|
2055 | - echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
2056 | - } |
|
2057 | - |
|
2058 | - |
|
2059 | - /************************/ |
|
2060 | - /** LIST TABLE METHODS **/ |
|
2061 | - /************************/ |
|
2062 | - /** |
|
2063 | - * this sets up the list table if the current view requires it. |
|
2064 | - * |
|
2065 | - * @return void |
|
2066 | - * @throws EE_Error |
|
2067 | - */ |
|
2068 | - protected function _set_list_table() |
|
2069 | - { |
|
2070 | - // first is this a list_table view? |
|
2071 | - if (! isset($this->_route_config['list_table'])) { |
|
2072 | - return; |
|
2073 | - } //not a list_table view so get out. |
|
2074 | - // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
2075 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
2076 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
2077 | - // user error msg |
|
2078 | - $error_msg = esc_html__( |
|
2079 | - 'An error occurred. The requested list table views could not be found.', |
|
2080 | - 'event_espresso' |
|
2081 | - ); |
|
2082 | - // developer error msg |
|
2083 | - $error_msg .= '||' |
|
2084 | - . sprintf( |
|
2085 | - esc_html__( |
|
2086 | - 'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', |
|
2087 | - 'event_espresso' |
|
2088 | - ), |
|
2089 | - $this->_req_action, |
|
2090 | - $list_table_view |
|
2091 | - ); |
|
2092 | - throw new EE_Error($error_msg); |
|
2093 | - } |
|
2094 | - // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
2095 | - $this->_views = apply_filters( |
|
2096 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
2097 | - $this->_views |
|
2098 | - ); |
|
2099 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
2100 | - $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
2101 | - $this->_set_list_table_view(); |
|
2102 | - $this->_set_list_table_object(); |
|
2103 | - } |
|
2104 | - |
|
2105 | - |
|
2106 | - /** |
|
2107 | - * set current view for List Table |
|
2108 | - * |
|
2109 | - * @return void |
|
2110 | - */ |
|
2111 | - protected function _set_list_table_view() |
|
2112 | - { |
|
2113 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2114 | - // looking at active items or dumpster diving ? |
|
2115 | - if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
2116 | - $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
2117 | - } else { |
|
2118 | - $this->_view = sanitize_key($this->_req_data['status']); |
|
2119 | - } |
|
2120 | - } |
|
2121 | - |
|
2122 | - |
|
2123 | - /** |
|
2124 | - * _set_list_table_object |
|
2125 | - * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
2126 | - * |
|
2127 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2128 | - * @throws \InvalidArgumentException |
|
2129 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2130 | - * @throws EE_Error |
|
2131 | - * @throws InvalidInterfaceException |
|
2132 | - */ |
|
2133 | - protected function _set_list_table_object() |
|
2134 | - { |
|
2135 | - if (isset($this->_route_config['list_table'])) { |
|
2136 | - if (! class_exists($this->_route_config['list_table'])) { |
|
2137 | - throw new EE_Error( |
|
2138 | - sprintf( |
|
2139 | - esc_html__( |
|
2140 | - 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
2141 | - 'event_espresso' |
|
2142 | - ), |
|
2143 | - $this->_route_config['list_table'], |
|
2144 | - get_class($this) |
|
2145 | - ) |
|
2146 | - ); |
|
2147 | - } |
|
2148 | - $this->_list_table_object = $this->loader->getShared( |
|
2149 | - $this->_route_config['list_table'], |
|
2150 | - array($this) |
|
2151 | - ); |
|
2152 | - } |
|
2153 | - } |
|
2154 | - |
|
2155 | - |
|
2156 | - /** |
|
2157 | - * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
2158 | - * |
|
2159 | - * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
2160 | - * urls. The array should be indexed by the view it is being |
|
2161 | - * added to. |
|
2162 | - * @return array |
|
2163 | - */ |
|
2164 | - public function get_list_table_view_RLs($extra_query_args = array()) |
|
2165 | - { |
|
2166 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2167 | - if (empty($this->_views)) { |
|
2168 | - $this->_views = array(); |
|
2169 | - } |
|
2170 | - // cycle thru views |
|
2171 | - foreach ($this->_views as $key => $view) { |
|
2172 | - $query_args = array(); |
|
2173 | - // check for current view |
|
2174 | - $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
2175 | - $query_args['action'] = $this->_req_action; |
|
2176 | - $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
2177 | - $query_args['status'] = $view['slug']; |
|
2178 | - // merge any other arguments sent in. |
|
2179 | - if (isset($extra_query_args[ $view['slug'] ])) { |
|
2180 | - $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]); |
|
2181 | - } |
|
2182 | - $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
2183 | - } |
|
2184 | - return $this->_views; |
|
2185 | - } |
|
2186 | - |
|
2187 | - |
|
2188 | - /** |
|
2189 | - * _entries_per_page_dropdown |
|
2190 | - * generates a drop down box for selecting the number of visible rows in an admin page list table |
|
2191 | - * |
|
2192 | - * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
2193 | - * WP does it. |
|
2194 | - * @param int $max_entries total number of rows in the table |
|
2195 | - * @return string |
|
2196 | - */ |
|
2197 | - protected function _entries_per_page_dropdown($max_entries = 0) |
|
2198 | - { |
|
2199 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2200 | - $values = array(10, 25, 50, 100); |
|
2201 | - $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
2202 | - if ($max_entries) { |
|
2203 | - $values[] = $max_entries; |
|
2204 | - sort($values); |
|
2205 | - } |
|
2206 | - $entries_per_page_dropdown = ' |
|
104 | + /** |
|
105 | + * @var array $_route_config |
|
106 | + */ |
|
107 | + protected $_route_config; |
|
108 | + |
|
109 | + /** |
|
110 | + * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out |
|
111 | + * actions. |
|
112 | + * |
|
113 | + * @since 4.6.x |
|
114 | + * @var array. |
|
115 | + */ |
|
116 | + protected $_default_route_query_args; |
|
117 | + |
|
118 | + // set via request page and action args. |
|
119 | + protected $_current_page; |
|
120 | + |
|
121 | + protected $_current_view; |
|
122 | + |
|
123 | + protected $_current_page_view_url; |
|
124 | + |
|
125 | + // sanitized request action (and nonce) |
|
126 | + |
|
127 | + /** |
|
128 | + * @var string $_req_action |
|
129 | + */ |
|
130 | + protected $_req_action; |
|
131 | + |
|
132 | + /** |
|
133 | + * @var string $_req_nonce |
|
134 | + */ |
|
135 | + protected $_req_nonce; |
|
136 | + |
|
137 | + // search related |
|
138 | + protected $_search_btn_label; |
|
139 | + |
|
140 | + protected $_search_box_callback; |
|
141 | + |
|
142 | + /** |
|
143 | + * WP Current Screen object |
|
144 | + * |
|
145 | + * @var WP_Screen |
|
146 | + */ |
|
147 | + protected $_current_screen; |
|
148 | + |
|
149 | + // for holding EE_Admin_Hooks object when needed (set via set_hook_object()) |
|
150 | + protected $_hook_obj; |
|
151 | + |
|
152 | + // for holding incoming request data |
|
153 | + protected $_req_data; |
|
154 | + |
|
155 | + // yes / no array for admin form fields |
|
156 | + protected $_yes_no_values = array(); |
|
157 | + |
|
158 | + // some default things shared by all child classes |
|
159 | + protected $_default_espresso_metaboxes; |
|
160 | + |
|
161 | + /** |
|
162 | + * EE_Registry Object |
|
163 | + * |
|
164 | + * @var EE_Registry |
|
165 | + */ |
|
166 | + protected $EE = null; |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * This is just a property that flags whether the given route is a caffeinated route or not. |
|
171 | + * |
|
172 | + * @var boolean |
|
173 | + */ |
|
174 | + protected $_is_caf = false; |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * @Constructor |
|
179 | + * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object. |
|
180 | + * @throws EE_Error |
|
181 | + * @throws InvalidArgumentException |
|
182 | + * @throws ReflectionException |
|
183 | + * @throws InvalidDataTypeException |
|
184 | + * @throws InvalidInterfaceException |
|
185 | + */ |
|
186 | + public function __construct($routing = true) |
|
187 | + { |
|
188 | + $this->loader = LoaderFactory::getLoader(); |
|
189 | + if (strpos($this->_get_dir(), 'caffeinated') !== false) { |
|
190 | + $this->_is_caf = true; |
|
191 | + } |
|
192 | + $this->_yes_no_values = array( |
|
193 | + array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
194 | + array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
195 | + ); |
|
196 | + // set the _req_data property. |
|
197 | + $this->_req_data = array_merge($_GET, $_POST); |
|
198 | + // routing enabled? |
|
199 | + $this->_routing = $routing; |
|
200 | + // set initial page props (child method) |
|
201 | + $this->_init_page_props(); |
|
202 | + // set global defaults |
|
203 | + $this->_set_defaults(); |
|
204 | + // set early because incoming requests could be ajax related and we need to register those hooks. |
|
205 | + $this->_global_ajax_hooks(); |
|
206 | + $this->_ajax_hooks(); |
|
207 | + // other_page_hooks have to be early too. |
|
208 | + $this->_do_other_page_hooks(); |
|
209 | + // This just allows us to have extending classes do something specific |
|
210 | + // before the parent constructor runs _page_setup(). |
|
211 | + if (method_exists($this, '_before_page_setup')) { |
|
212 | + $this->_before_page_setup(); |
|
213 | + } |
|
214 | + // set up page dependencies |
|
215 | + $this->_page_setup(); |
|
216 | + } |
|
217 | + |
|
218 | + |
|
219 | + /** |
|
220 | + * _init_page_props |
|
221 | + * Child classes use to set at least the following properties: |
|
222 | + * $page_slug. |
|
223 | + * $page_label. |
|
224 | + * |
|
225 | + * @abstract |
|
226 | + * @return void |
|
227 | + */ |
|
228 | + abstract protected function _init_page_props(); |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * _ajax_hooks |
|
233 | + * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
234 | + * Note: within the ajax callback methods. |
|
235 | + * |
|
236 | + * @abstract |
|
237 | + * @return void |
|
238 | + */ |
|
239 | + abstract protected function _ajax_hooks(); |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * _define_page_props |
|
244 | + * child classes define page properties in here. Must include at least: |
|
245 | + * $_admin_base_url = base_url for all admin pages |
|
246 | + * $_admin_page_title = default admin_page_title for admin pages |
|
247 | + * $_labels = array of default labels for various automatically generated elements: |
|
248 | + * array( |
|
249 | + * 'buttons' => array( |
|
250 | + * 'add' => esc_html__('label for add new button'), |
|
251 | + * 'edit' => esc_html__('label for edit button'), |
|
252 | + * 'delete' => esc_html__('label for delete button') |
|
253 | + * ) |
|
254 | + * ) |
|
255 | + * |
|
256 | + * @abstract |
|
257 | + * @return void |
|
258 | + */ |
|
259 | + abstract protected function _define_page_props(); |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * _set_page_routes |
|
264 | + * child classes use this to define the page routes for all subpages handled by the class. Page routes are |
|
265 | + * assigned to a action => method pairs in an array and to the $_page_routes property. Each page route must also |
|
266 | + * have a 'default' route. Here's the format |
|
267 | + * $this->_page_routes = array( |
|
268 | + * 'default' => array( |
|
269 | + * 'func' => '_default_method_handling_route', |
|
270 | + * 'args' => array('array','of','args'), |
|
271 | + * 'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e. |
|
272 | + * ajax request, backend processing) |
|
273 | + * 'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a |
|
274 | + * headers route after. The string you enter here should match the defined route reference for a |
|
275 | + * headers sent route. |
|
276 | + * 'capability' => 'route_capability', //indicate a string for minimum capability required to access |
|
277 | + * this route. |
|
278 | + * 'obj_id' => 10 // if this route has an object id, then this can include it (used for capability |
|
279 | + * checks). |
|
280 | + * ), |
|
281 | + * 'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a |
|
282 | + * handling method. |
|
283 | + * ) |
|
284 | + * ) |
|
285 | + * |
|
286 | + * @abstract |
|
287 | + * @return void |
|
288 | + */ |
|
289 | + abstract protected function _set_page_routes(); |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * _set_page_config |
|
294 | + * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the |
|
295 | + * array corresponds to the page_route for the loaded page. Format: |
|
296 | + * $this->_page_config = array( |
|
297 | + * 'default' => array( |
|
298 | + * 'labels' => array( |
|
299 | + * 'buttons' => array( |
|
300 | + * 'add' => esc_html__('label for adding item'), |
|
301 | + * 'edit' => esc_html__('label for editing item'), |
|
302 | + * 'delete' => esc_html__('label for deleting item') |
|
303 | + * ), |
|
304 | + * 'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso') |
|
305 | + * ), //optional an array of custom labels for various automatically generated elements to use on the |
|
306 | + * page. If this isn't present then the defaults will be used as set for the $this->_labels in |
|
307 | + * _define_page_props() method |
|
308 | + * 'nav' => array( |
|
309 | + * 'label' => esc_html__('Label for Tab', 'event_espresso'). |
|
310 | + * 'url' => 'http://someurl', //automatically generated UNLESS you define |
|
311 | + * 'css_class' => 'css-class', //automatically generated UNLESS you define |
|
312 | + * 'order' => 10, //required to indicate tab position. |
|
313 | + * 'persistent' => false //if you want the nav tab to ONLY display when the specific route is |
|
314 | + * displayed then add this parameter. |
|
315 | + * 'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page. |
|
316 | + * 'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load |
|
317 | + * metaboxes set for eventespresso admin pages. |
|
318 | + * 'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have |
|
319 | + * metaboxes. Typically this is used if the 'metaboxes' index is not used because metaboxes are added |
|
320 | + * later. We just use this flag to make sure the necessary js gets enqueued on page load. |
|
321 | + * 'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the |
|
322 | + * given route has help popups setup and if it does then we need to make sure thickbox is enqueued. |
|
323 | + * 'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes). The |
|
324 | + * array indicates the max number of columns (4) and the default number of columns on page load (2). |
|
325 | + * There is an option in the "screen_options" dropdown that is setup so users can pick what columns they |
|
326 | + * want to display. |
|
327 | + * 'help_tabs' => array( //this is used for adding help tabs to a page |
|
328 | + * 'tab_id' => array( |
|
329 | + * 'title' => 'tab_title', |
|
330 | + * 'filename' => 'name_of_file_containing_content', //this is the primary method for setting |
|
331 | + * help tab content. The fallback if it isn't present is to try a the callback. Filename |
|
332 | + * should match a file in the admin folder's "help_tabs" dir (ie.. |
|
333 | + * events/help_tabs/name_of_file_containing_content.help_tab.php) |
|
334 | + * 'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will |
|
335 | + * attempt to use the callback which should match the name of a method in the class |
|
336 | + * ), |
|
337 | + * 'tab2_id' => array( |
|
338 | + * 'title' => 'tab2 title', |
|
339 | + * 'filename' => 'file_name_2' |
|
340 | + * 'callback' => 'callback_method_for_content', |
|
341 | + * ), |
|
342 | + * 'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the |
|
343 | + * help tab area on an admin page. @link |
|
344 | + * http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/ |
|
345 | + * 'help_tour' => array( |
|
346 | + * 'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located |
|
347 | + * in a folder for this admin page named "help_tours", a file name matching the key given here |
|
348 | + * (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class) |
|
349 | + * ), |
|
350 | + * 'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is |
|
351 | + * true if it isn't present). To remove the requirement for a nonce check when this route is visited |
|
352 | + * just set |
|
353 | + * 'require_nonce' to FALSE |
|
354 | + * ) |
|
355 | + * ) |
|
356 | + * |
|
357 | + * @abstract |
|
358 | + * @return void |
|
359 | + */ |
|
360 | + abstract protected function _set_page_config(); |
|
361 | + |
|
362 | + |
|
363 | + |
|
364 | + |
|
365 | + |
|
366 | + /** end sample help_tour methods **/ |
|
367 | + /** |
|
368 | + * _add_screen_options |
|
369 | + * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for |
|
370 | + * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options |
|
371 | + * to a particular view. |
|
372 | + * |
|
373 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
374 | + * see also WP_Screen object documents... |
|
375 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
376 | + * @abstract |
|
377 | + * @return void |
|
378 | + */ |
|
379 | + abstract protected function _add_screen_options(); |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * _add_feature_pointers |
|
384 | + * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js). |
|
385 | + * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a |
|
386 | + * particular view. Note: this is just a placeholder for now. Implementation will come down the road See: |
|
387 | + * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
388 | + * extended) also see: |
|
389 | + * |
|
390 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
391 | + * @abstract |
|
392 | + * @return void |
|
393 | + */ |
|
394 | + abstract protected function _add_feature_pointers(); |
|
395 | + |
|
396 | + |
|
397 | + /** |
|
398 | + * load_scripts_styles |
|
399 | + * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for |
|
400 | + * their pages/subpages. Note this is for all pages/subpages of the system. You can also load only specific |
|
401 | + * scripts/styles per view by putting them in a dynamic function in this format |
|
402 | + * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg) |
|
403 | + * |
|
404 | + * @abstract |
|
405 | + * @return void |
|
406 | + */ |
|
407 | + abstract public function load_scripts_styles(); |
|
408 | + |
|
409 | + |
|
410 | + /** |
|
411 | + * admin_init |
|
412 | + * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here. This will apply to |
|
413 | + * all pages/views loaded by child class. |
|
414 | + * |
|
415 | + * @abstract |
|
416 | + * @return void |
|
417 | + */ |
|
418 | + abstract public function admin_init(); |
|
419 | + |
|
420 | + |
|
421 | + /** |
|
422 | + * admin_notices |
|
423 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply to |
|
424 | + * all pages/views loaded by child class. |
|
425 | + * |
|
426 | + * @abstract |
|
427 | + * @return void |
|
428 | + */ |
|
429 | + abstract public function admin_notices(); |
|
430 | + |
|
431 | + |
|
432 | + /** |
|
433 | + * admin_footer_scripts |
|
434 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
435 | + * will apply to all pages/views loaded by child class. |
|
436 | + * |
|
437 | + * @return void |
|
438 | + */ |
|
439 | + abstract public function admin_footer_scripts(); |
|
440 | + |
|
441 | + |
|
442 | + /** |
|
443 | + * admin_footer |
|
444 | + * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will |
|
445 | + * apply to all pages/views loaded by child class. |
|
446 | + * |
|
447 | + * @return void |
|
448 | + */ |
|
449 | + public function admin_footer() |
|
450 | + { |
|
451 | + } |
|
452 | + |
|
453 | + |
|
454 | + /** |
|
455 | + * _global_ajax_hooks |
|
456 | + * all global add_action('wp_ajax_{name_of_hook}') hooks in here. |
|
457 | + * Note: within the ajax callback methods. |
|
458 | + * |
|
459 | + * @abstract |
|
460 | + * @return void |
|
461 | + */ |
|
462 | + protected function _global_ajax_hooks() |
|
463 | + { |
|
464 | + // for lazy loading of metabox content |
|
465 | + add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10); |
|
466 | + } |
|
467 | + |
|
468 | + |
|
469 | + public function ajax_metabox_content() |
|
470 | + { |
|
471 | + $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : ''; |
|
472 | + $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : ''; |
|
473 | + self::cached_rss_display($contentid, $url); |
|
474 | + wp_die(); |
|
475 | + } |
|
476 | + |
|
477 | + |
|
478 | + /** |
|
479 | + * _page_setup |
|
480 | + * Makes sure any things that need to be loaded early get handled. We also escape early here if the page requested |
|
481 | + * doesn't match the object. |
|
482 | + * |
|
483 | + * @final |
|
484 | + * @return void |
|
485 | + * @throws EE_Error |
|
486 | + * @throws InvalidArgumentException |
|
487 | + * @throws ReflectionException |
|
488 | + * @throws InvalidDataTypeException |
|
489 | + * @throws InvalidInterfaceException |
|
490 | + */ |
|
491 | + final protected function _page_setup() |
|
492 | + { |
|
493 | + // requires? |
|
494 | + // admin_init stuff - global - we're setting this REALLY early so if EE_Admin pages have to hook into other WP pages they can. But keep in mind, not everything is available from the EE_Admin Page object at this point. |
|
495 | + add_action('admin_init', array($this, 'admin_init_global'), 5); |
|
496 | + // next verify if we need to load anything... |
|
497 | + $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : ''; |
|
498 | + $this->page_folder = strtolower( |
|
499 | + str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this)) |
|
500 | + ); |
|
501 | + global $ee_menu_slugs; |
|
502 | + $ee_menu_slugs = (array) $ee_menu_slugs; |
|
503 | + if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) { |
|
504 | + return; |
|
505 | + } |
|
506 | + // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first |
|
507 | + if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') { |
|
508 | + $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1' |
|
509 | + ? $this->_req_data['action2'] |
|
510 | + : $this->_req_data['action']; |
|
511 | + } |
|
512 | + // then set blank or -1 action values to 'default' |
|
513 | + $this->_req_action = isset($this->_req_data['action']) |
|
514 | + && ! empty($this->_req_data['action']) |
|
515 | + && $this->_req_data['action'] !== '-1' |
|
516 | + ? sanitize_key($this->_req_data['action']) |
|
517 | + : 'default'; |
|
518 | + // if action is 'default' after the above BUT we have 'route' var set, then let's use the route as the action. |
|
519 | + // This covers cases where we're coming in from a list table that isn't on the default route. |
|
520 | + $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route']) |
|
521 | + ? $this->_req_data['route'] : $this->_req_action; |
|
522 | + // however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be |
|
523 | + $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route']) |
|
524 | + ? $this->_req_data['route'] |
|
525 | + : $this->_req_action; |
|
526 | + $this->_current_view = $this->_req_action; |
|
527 | + $this->_req_nonce = $this->_req_action . '_nonce'; |
|
528 | + $this->_define_page_props(); |
|
529 | + $this->_current_page_view_url = add_query_arg( |
|
530 | + array('page' => $this->_current_page, 'action' => $this->_current_view), |
|
531 | + $this->_admin_base_url |
|
532 | + ); |
|
533 | + // default things |
|
534 | + $this->_default_espresso_metaboxes = array( |
|
535 | + '_espresso_news_post_box', |
|
536 | + '_espresso_links_post_box', |
|
537 | + '_espresso_ratings_request', |
|
538 | + '_espresso_sponsors_post_box', |
|
539 | + ); |
|
540 | + // set page configs |
|
541 | + $this->_set_page_routes(); |
|
542 | + $this->_set_page_config(); |
|
543 | + // let's include any referrer data in our default_query_args for this route for "stickiness". |
|
544 | + if (isset($this->_req_data['wp_referer'])) { |
|
545 | + $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer']; |
|
546 | + } |
|
547 | + // for caffeinated and other extended functionality. |
|
548 | + // If there is a _extend_page_config method |
|
549 | + // then let's run that to modify the all the various page configuration arrays |
|
550 | + if (method_exists($this, '_extend_page_config')) { |
|
551 | + $this->_extend_page_config(); |
|
552 | + } |
|
553 | + // for CPT and other extended functionality. |
|
554 | + // If there is an _extend_page_config_for_cpt |
|
555 | + // then let's run that to modify all the various page configuration arrays. |
|
556 | + if (method_exists($this, '_extend_page_config_for_cpt')) { |
|
557 | + $this->_extend_page_config_for_cpt(); |
|
558 | + } |
|
559 | + // filter routes and page_config so addons can add their stuff. Filtering done per class |
|
560 | + $this->_page_routes = apply_filters( |
|
561 | + 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
562 | + $this->_page_routes, |
|
563 | + $this |
|
564 | + ); |
|
565 | + $this->_page_config = apply_filters( |
|
566 | + 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
567 | + $this->_page_config, |
|
568 | + $this |
|
569 | + ); |
|
570 | + // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
|
571 | + // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
|
572 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
573 | + add_action( |
|
574 | + 'AHEE__EE_Admin_Page__route_admin_request', |
|
575 | + array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), |
|
576 | + 10, |
|
577 | + 2 |
|
578 | + ); |
|
579 | + } |
|
580 | + // next route only if routing enabled |
|
581 | + if ($this->_routing && ! defined('DOING_AJAX')) { |
|
582 | + $this->_verify_routes(); |
|
583 | + // next let's just check user_access and kill if no access |
|
584 | + $this->check_user_access(); |
|
585 | + if ($this->_is_UI_request) { |
|
586 | + // admin_init stuff - global, all views for this page class, specific view |
|
587 | + add_action('admin_init', array($this, 'admin_init'), 10); |
|
588 | + if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
589 | + add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
590 | + } |
|
591 | + } else { |
|
592 | + // hijack regular WP loading and route admin request immediately |
|
593 | + @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT)); |
|
594 | + $this->route_admin_request(); |
|
595 | + } |
|
596 | + } |
|
597 | + } |
|
598 | + |
|
599 | + |
|
600 | + /** |
|
601 | + * Provides a way for related child admin pages to load stuff on the loaded admin page. |
|
602 | + * |
|
603 | + * @return void |
|
604 | + * @throws ReflectionException |
|
605 | + * @throws EE_Error |
|
606 | + */ |
|
607 | + private function _do_other_page_hooks() |
|
608 | + { |
|
609 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
610 | + foreach ($registered_pages as $page) { |
|
611 | + // now let's setup the file name and class that should be present |
|
612 | + $classname = str_replace('.class.php', '', $page); |
|
613 | + // autoloaders should take care of loading file |
|
614 | + if (! class_exists($classname)) { |
|
615 | + $error_msg[] = sprintf( |
|
616 | + esc_html__( |
|
617 | + 'Something went wrong with loading the %s admin hooks page.', |
|
618 | + 'event_espresso' |
|
619 | + ), |
|
620 | + $page |
|
621 | + ); |
|
622 | + $error_msg[] = $error_msg[0] |
|
623 | + . "\r\n" |
|
624 | + . sprintf( |
|
625 | + esc_html__( |
|
626 | + 'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class', |
|
627 | + 'event_espresso' |
|
628 | + ), |
|
629 | + $page, |
|
630 | + '<br />', |
|
631 | + '<strong>' . $classname . '</strong>' |
|
632 | + ); |
|
633 | + throw new EE_Error(implode('||', $error_msg)); |
|
634 | + } |
|
635 | + $a = new ReflectionClass($classname); |
|
636 | + // notice we are passing the instance of this class to the hook object. |
|
637 | + $hookobj[] = $a->newInstance($this); |
|
638 | + } |
|
639 | + } |
|
640 | + |
|
641 | + |
|
642 | + public function load_page_dependencies() |
|
643 | + { |
|
644 | + try { |
|
645 | + $this->_load_page_dependencies(); |
|
646 | + } catch (EE_Error $e) { |
|
647 | + $e->get_error(); |
|
648 | + } |
|
649 | + } |
|
650 | + |
|
651 | + |
|
652 | + /** |
|
653 | + * load_page_dependencies |
|
654 | + * loads things specific to this page class when its loaded. Really helps with efficiency. |
|
655 | + * |
|
656 | + * @return void |
|
657 | + * @throws DomainException |
|
658 | + * @throws EE_Error |
|
659 | + * @throws InvalidArgumentException |
|
660 | + * @throws InvalidDataTypeException |
|
661 | + * @throws InvalidInterfaceException |
|
662 | + * @throws ReflectionException |
|
663 | + */ |
|
664 | + protected function _load_page_dependencies() |
|
665 | + { |
|
666 | + // let's set the current_screen and screen options to override what WP set |
|
667 | + $this->_current_screen = get_current_screen(); |
|
668 | + // load admin_notices - global, page class, and view specific |
|
669 | + add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
|
670 | + add_action('admin_notices', array($this, 'admin_notices'), 10); |
|
671 | + if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
672 | + add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
673 | + } |
|
674 | + // load network admin_notices - global, page class, and view specific |
|
675 | + add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
|
676 | + if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
677 | + add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
678 | + } |
|
679 | + // this will save any per_page screen options if they are present |
|
680 | + $this->_set_per_page_screen_options(); |
|
681 | + // setup list table properties |
|
682 | + $this->_set_list_table(); |
|
683 | + // child classes can "register" a metabox to be automatically handled via the _page_config array property. |
|
684 | + // However in some cases the metaboxes will need to be added within a route handling callback. |
|
685 | + $this->_add_registered_meta_boxes(); |
|
686 | + $this->_add_screen_columns(); |
|
687 | + // add screen options - global, page child class, and view specific |
|
688 | + $this->_add_global_screen_options(); |
|
689 | + $this->_add_screen_options(); |
|
690 | + $add_screen_options = "_add_screen_options_{$this->_current_view}"; |
|
691 | + if (method_exists($this, $add_screen_options)) { |
|
692 | + $this->{$add_screen_options}(); |
|
693 | + } |
|
694 | + // add help tab(s) and tours- set via page_config and qtips. |
|
695 | + $this->_add_help_tour(); |
|
696 | + $this->_add_help_tabs(); |
|
697 | + $this->_add_qtips(); |
|
698 | + // add feature_pointers - global, page child class, and view specific |
|
699 | + $this->_add_feature_pointers(); |
|
700 | + $this->_add_global_feature_pointers(); |
|
701 | + $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}"; |
|
702 | + if (method_exists($this, $add_feature_pointer)) { |
|
703 | + $this->{$add_feature_pointer}(); |
|
704 | + } |
|
705 | + // enqueue scripts/styles - global, page class, and view specific |
|
706 | + add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5); |
|
707 | + add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10); |
|
708 | + if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) { |
|
709 | + add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15); |
|
710 | + } |
|
711 | + add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100); |
|
712 | + // admin_print_footer_scripts - global, page child class, and view specific. |
|
713 | + // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this. |
|
714 | + // In most cases that's doing_it_wrong(). But adding hidden container elements etc. |
|
715 | + // is a good use case. Notice the late priority we're giving these |
|
716 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99); |
|
717 | + add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100); |
|
718 | + if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) { |
|
719 | + add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101); |
|
720 | + } |
|
721 | + // admin footer scripts |
|
722 | + add_action('admin_footer', array($this, 'admin_footer_global'), 99); |
|
723 | + add_action('admin_footer', array($this, 'admin_footer'), 100); |
|
724 | + if (method_exists($this, "admin_footer_{$this->_current_view}")) { |
|
725 | + add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101); |
|
726 | + } |
|
727 | + do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug); |
|
728 | + // targeted hook |
|
729 | + do_action( |
|
730 | + "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}" |
|
731 | + ); |
|
732 | + } |
|
733 | + |
|
734 | + |
|
735 | + /** |
|
736 | + * _set_defaults |
|
737 | + * This sets some global defaults for class properties. |
|
738 | + */ |
|
739 | + private function _set_defaults() |
|
740 | + { |
|
741 | + $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null; |
|
742 | + $this->_event = $this->_template_path = $this->_column_template_path = null; |
|
743 | + $this->_nav_tabs = $this->_views = $this->_page_routes = array(); |
|
744 | + $this->_page_config = $this->_default_route_query_args = array(); |
|
745 | + $this->_default_nav_tab_name = 'overview'; |
|
746 | + // init template args |
|
747 | + $this->_template_args = array( |
|
748 | + 'admin_page_header' => '', |
|
749 | + 'admin_page_content' => '', |
|
750 | + 'post_body_content' => '', |
|
751 | + 'before_list_table' => '', |
|
752 | + 'after_list_table' => '', |
|
753 | + ); |
|
754 | + } |
|
755 | + |
|
756 | + |
|
757 | + /** |
|
758 | + * route_admin_request |
|
759 | + * |
|
760 | + * @see _route_admin_request() |
|
761 | + * @return exception|void error |
|
762 | + * @throws InvalidArgumentException |
|
763 | + * @throws InvalidInterfaceException |
|
764 | + * @throws InvalidDataTypeException |
|
765 | + * @throws EE_Error |
|
766 | + * @throws ReflectionException |
|
767 | + */ |
|
768 | + public function route_admin_request() |
|
769 | + { |
|
770 | + try { |
|
771 | + $this->_route_admin_request(); |
|
772 | + } catch (EE_Error $e) { |
|
773 | + $e->get_error(); |
|
774 | + } |
|
775 | + } |
|
776 | + |
|
777 | + |
|
778 | + public function set_wp_page_slug($wp_page_slug) |
|
779 | + { |
|
780 | + $this->_wp_page_slug = $wp_page_slug; |
|
781 | + // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls... |
|
782 | + if (is_network_admin()) { |
|
783 | + $this->_wp_page_slug .= '-network'; |
|
784 | + } |
|
785 | + } |
|
786 | + |
|
787 | + |
|
788 | + /** |
|
789 | + * _verify_routes |
|
790 | + * All this method does is verify the incoming request and make sure that routes exist for it. We do this early so |
|
791 | + * we know if we need to drop out. |
|
792 | + * |
|
793 | + * @return bool |
|
794 | + * @throws EE_Error |
|
795 | + */ |
|
796 | + protected function _verify_routes() |
|
797 | + { |
|
798 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
799 | + if (! $this->_current_page && ! defined('DOING_AJAX')) { |
|
800 | + return false; |
|
801 | + } |
|
802 | + $this->_route = false; |
|
803 | + // check that the page_routes array is not empty |
|
804 | + if (empty($this->_page_routes)) { |
|
805 | + // user error msg |
|
806 | + $error_msg = sprintf( |
|
807 | + esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'), |
|
808 | + $this->_admin_page_title |
|
809 | + ); |
|
810 | + // developer error msg |
|
811 | + $error_msg .= '||' . $error_msg |
|
812 | + . esc_html__( |
|
813 | + ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
|
814 | + 'event_espresso' |
|
815 | + ); |
|
816 | + throw new EE_Error($error_msg); |
|
817 | + } |
|
818 | + // and that the requested page route exists |
|
819 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
820 | + $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
821 | + $this->_route_config = isset($this->_page_config[ $this->_req_action ]) |
|
822 | + ? $this->_page_config[ $this->_req_action ] : array(); |
|
823 | + } else { |
|
824 | + // user error msg |
|
825 | + $error_msg = sprintf( |
|
826 | + esc_html__( |
|
827 | + 'The requested page route does not exist for the %s admin page.', |
|
828 | + 'event_espresso' |
|
829 | + ), |
|
830 | + $this->_admin_page_title |
|
831 | + ); |
|
832 | + // developer error msg |
|
833 | + $error_msg .= '||' . $error_msg |
|
834 | + . sprintf( |
|
835 | + esc_html__( |
|
836 | + ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
|
837 | + 'event_espresso' |
|
838 | + ), |
|
839 | + $this->_req_action |
|
840 | + ); |
|
841 | + throw new EE_Error($error_msg); |
|
842 | + } |
|
843 | + // and that a default route exists |
|
844 | + if (! array_key_exists('default', $this->_page_routes)) { |
|
845 | + // user error msg |
|
846 | + $error_msg = sprintf( |
|
847 | + esc_html__( |
|
848 | + 'A default page route has not been set for the % admin page.', |
|
849 | + 'event_espresso' |
|
850 | + ), |
|
851 | + $this->_admin_page_title |
|
852 | + ); |
|
853 | + // developer error msg |
|
854 | + $error_msg .= '||' . $error_msg |
|
855 | + . esc_html__( |
|
856 | + ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
|
857 | + 'event_espresso' |
|
858 | + ); |
|
859 | + throw new EE_Error($error_msg); |
|
860 | + } |
|
861 | + // first lets' catch if the UI request has EVER been set. |
|
862 | + if ($this->_is_UI_request === null) { |
|
863 | + // lets set if this is a UI request or not. |
|
864 | + $this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true; |
|
865 | + // wait a minute... we might have a noheader in the route array |
|
866 | + $this->_is_UI_request = is_array($this->_route) |
|
867 | + && isset($this->_route['noheader']) |
|
868 | + && $this->_route['noheader'] ? false : $this->_is_UI_request; |
|
869 | + } |
|
870 | + $this->_set_current_labels(); |
|
871 | + return true; |
|
872 | + } |
|
873 | + |
|
874 | + |
|
875 | + /** |
|
876 | + * this method simply verifies a given route and makes sure its an actual route available for the loaded page |
|
877 | + * |
|
878 | + * @param string $route the route name we're verifying |
|
879 | + * @return mixed (bool|Exception) we'll throw an exception if this isn't a valid route. |
|
880 | + * @throws EE_Error |
|
881 | + */ |
|
882 | + protected function _verify_route($route) |
|
883 | + { |
|
884 | + if (array_key_exists($this->_req_action, $this->_page_routes)) { |
|
885 | + return true; |
|
886 | + } |
|
887 | + // user error msg |
|
888 | + $error_msg = sprintf( |
|
889 | + esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'), |
|
890 | + $this->_admin_page_title |
|
891 | + ); |
|
892 | + // developer error msg |
|
893 | + $error_msg .= '||' . $error_msg |
|
894 | + . sprintf( |
|
895 | + esc_html__( |
|
896 | + ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
|
897 | + 'event_espresso' |
|
898 | + ), |
|
899 | + $route |
|
900 | + ); |
|
901 | + throw new EE_Error($error_msg); |
|
902 | + } |
|
903 | + |
|
904 | + |
|
905 | + /** |
|
906 | + * perform nonce verification |
|
907 | + * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces |
|
908 | + * using this method (and save retyping!) |
|
909 | + * |
|
910 | + * @param string $nonce The nonce sent |
|
911 | + * @param string $nonce_ref The nonce reference string (name0) |
|
912 | + * @return void |
|
913 | + * @throws EE_Error |
|
914 | + */ |
|
915 | + protected function _verify_nonce($nonce, $nonce_ref) |
|
916 | + { |
|
917 | + // verify nonce against expected value |
|
918 | + if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
919 | + // these are not the droids you are looking for !!! |
|
920 | + $msg = sprintf( |
|
921 | + esc_html__('%sNonce Fail.%s', 'event_espresso'), |
|
922 | + '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">', |
|
923 | + '</a>' |
|
924 | + ); |
|
925 | + if (WP_DEBUG) { |
|
926 | + $msg .= "\n " |
|
927 | + . sprintf( |
|
928 | + esc_html__( |
|
929 | + 'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!', |
|
930 | + 'event_espresso' |
|
931 | + ), |
|
932 | + __CLASS__ |
|
933 | + ); |
|
934 | + } |
|
935 | + if (! defined('DOING_AJAX')) { |
|
936 | + wp_die($msg); |
|
937 | + } else { |
|
938 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
939 | + $this->_return_json(); |
|
940 | + } |
|
941 | + } |
|
942 | + } |
|
943 | + |
|
944 | + |
|
945 | + /** |
|
946 | + * _route_admin_request() |
|
947 | + * Meat and potatoes of the class. Basically, this dude checks out what's being requested and sees if theres are |
|
948 | + * some doodads to work the magic and handle the flingjangy. Translation: Checks if the requested action is listed |
|
949 | + * in the page routes and then will try to load the corresponding method. |
|
950 | + * |
|
951 | + * @return void |
|
952 | + * @throws EE_Error |
|
953 | + * @throws InvalidArgumentException |
|
954 | + * @throws InvalidDataTypeException |
|
955 | + * @throws InvalidInterfaceException |
|
956 | + * @throws ReflectionException |
|
957 | + */ |
|
958 | + protected function _route_admin_request() |
|
959 | + { |
|
960 | + if (! $this->_is_UI_request) { |
|
961 | + $this->_verify_routes(); |
|
962 | + } |
|
963 | + $nonce_check = isset($this->_route_config['require_nonce']) |
|
964 | + ? $this->_route_config['require_nonce'] |
|
965 | + : true; |
|
966 | + if ($this->_req_action !== 'default' && $nonce_check) { |
|
967 | + // set nonce from post data |
|
968 | + $nonce = isset($this->_req_data[ $this->_req_nonce ]) |
|
969 | + ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) |
|
970 | + : ''; |
|
971 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
972 | + } |
|
973 | + // set the nav_tabs array but ONLY if this is UI_request |
|
974 | + if ($this->_is_UI_request) { |
|
975 | + $this->_set_nav_tabs(); |
|
976 | + } |
|
977 | + // grab callback function |
|
978 | + $func = is_array($this->_route) ? $this->_route['func'] : $this->_route; |
|
979 | + // check if callback has args |
|
980 | + $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array(); |
|
981 | + $error_msg = ''; |
|
982 | + // action right before calling route |
|
983 | + // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
|
984 | + if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
985 | + do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
|
986 | + } |
|
987 | + // right before calling the route, let's remove _wp_http_referer from the |
|
988 | + // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing). |
|
989 | + $_SERVER['REQUEST_URI'] = remove_query_arg( |
|
990 | + '_wp_http_referer', |
|
991 | + wp_unslash($_SERVER['REQUEST_URI']) |
|
992 | + ); |
|
993 | + if (! empty($func)) { |
|
994 | + if (is_array($func)) { |
|
995 | + list($class, $method) = $func; |
|
996 | + } elseif (strpos($func, '::') !== false) { |
|
997 | + list($class, $method) = explode('::', $func); |
|
998 | + } else { |
|
999 | + $class = $this; |
|
1000 | + $method = $func; |
|
1001 | + } |
|
1002 | + if (! (is_object($class) && $class === $this)) { |
|
1003 | + // send along this admin page object for access by addons. |
|
1004 | + $args['admin_page_object'] = $this; |
|
1005 | + } |
|
1006 | + if (// is it a method on a class that doesn't work? |
|
1007 | + ( |
|
1008 | + ( |
|
1009 | + method_exists($class, $method) |
|
1010 | + && call_user_func_array(array($class, $method), $args) === false |
|
1011 | + ) |
|
1012 | + && ( |
|
1013 | + // is it a standalone function that doesn't work? |
|
1014 | + function_exists($method) |
|
1015 | + && call_user_func_array( |
|
1016 | + $func, |
|
1017 | + array_merge(array('admin_page_object' => $this), $args) |
|
1018 | + ) === false |
|
1019 | + ) |
|
1020 | + ) |
|
1021 | + || ( |
|
1022 | + // is it neither a class method NOR a standalone function? |
|
1023 | + ! method_exists($class, $method) |
|
1024 | + && ! function_exists($method) |
|
1025 | + ) |
|
1026 | + ) { |
|
1027 | + // user error msg |
|
1028 | + $error_msg = esc_html__( |
|
1029 | + 'An error occurred. The requested page route could not be found.', |
|
1030 | + 'event_espresso' |
|
1031 | + ); |
|
1032 | + // developer error msg |
|
1033 | + $error_msg .= '||'; |
|
1034 | + $error_msg .= sprintf( |
|
1035 | + esc_html__( |
|
1036 | + 'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.', |
|
1037 | + 'event_espresso' |
|
1038 | + ), |
|
1039 | + $method |
|
1040 | + ); |
|
1041 | + } |
|
1042 | + if (! empty($error_msg)) { |
|
1043 | + throw new EE_Error($error_msg); |
|
1044 | + } |
|
1045 | + } |
|
1046 | + // if we've routed and this route has a no headers route AND a sent_headers_route, |
|
1047 | + // then we need to reset the routing properties to the new route. |
|
1048 | + // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent. |
|
1049 | + if ($this->_is_UI_request === false |
|
1050 | + && is_array($this->_route) |
|
1051 | + && ! empty($this->_route['headers_sent_route']) |
|
1052 | + ) { |
|
1053 | + $this->_reset_routing_properties($this->_route['headers_sent_route']); |
|
1054 | + } |
|
1055 | + } |
|
1056 | + |
|
1057 | + |
|
1058 | + /** |
|
1059 | + * This method just allows the resetting of page properties in the case where a no headers |
|
1060 | + * route redirects to a headers route in its route config. |
|
1061 | + * |
|
1062 | + * @since 4.3.0 |
|
1063 | + * @param string $new_route New (non header) route to redirect to. |
|
1064 | + * @return void |
|
1065 | + * @throws ReflectionException |
|
1066 | + * @throws InvalidArgumentException |
|
1067 | + * @throws InvalidInterfaceException |
|
1068 | + * @throws InvalidDataTypeException |
|
1069 | + * @throws EE_Error |
|
1070 | + */ |
|
1071 | + protected function _reset_routing_properties($new_route) |
|
1072 | + { |
|
1073 | + $this->_is_UI_request = true; |
|
1074 | + // now we set the current route to whatever the headers_sent_route is set at |
|
1075 | + $this->_req_data['action'] = $new_route; |
|
1076 | + // rerun page setup |
|
1077 | + $this->_page_setup(); |
|
1078 | + } |
|
1079 | + |
|
1080 | + |
|
1081 | + /** |
|
1082 | + * _add_query_arg |
|
1083 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
1084 | + *(internally just uses EEH_URL's function with the same name) |
|
1085 | + * |
|
1086 | + * @param array $args |
|
1087 | + * @param string $url |
|
1088 | + * @param bool $sticky if true, then the existing Request params will be appended to the |
|
1089 | + * generated url in an associative array indexed by the key 'wp_referer'; |
|
1090 | + * Example usage: If the current page is: |
|
1091 | + * http://mydomain.com/wp-admin/admin.php?page=espresso_registrations |
|
1092 | + * &action=default&event_id=20&month_range=March%202015 |
|
1093 | + * &_wpnonce=5467821 |
|
1094 | + * and you call: |
|
1095 | + * EE_Admin_Page::add_query_args_and_nonce( |
|
1096 | + * array( |
|
1097 | + * 'action' => 'resend_something', |
|
1098 | + * 'page=>espresso_registrations' |
|
1099 | + * ), |
|
1100 | + * $some_url, |
|
1101 | + * true |
|
1102 | + * ); |
|
1103 | + * It will produce a url in this structure: |
|
1104 | + * http://{$some_url}/?page=espresso_registrations&action=resend_something |
|
1105 | + * &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[ |
|
1106 | + * month_range]=March%202015 |
|
1107 | + * @param bool $exclude_nonce If true, the the nonce will be excluded from the generated nonce. |
|
1108 | + * @return string |
|
1109 | + */ |
|
1110 | + public static function add_query_args_and_nonce( |
|
1111 | + $args = array(), |
|
1112 | + $url = false, |
|
1113 | + $sticky = false, |
|
1114 | + $exclude_nonce = false |
|
1115 | + ) { |
|
1116 | + // if there is a _wp_http_referer include the values from the request but only if sticky = true |
|
1117 | + if ($sticky) { |
|
1118 | + $request = $_REQUEST; |
|
1119 | + unset($request['_wp_http_referer']); |
|
1120 | + unset($request['wp_referer']); |
|
1121 | + foreach ($request as $key => $value) { |
|
1122 | + // do not add nonces |
|
1123 | + if (strpos($key, 'nonce') !== false) { |
|
1124 | + continue; |
|
1125 | + } |
|
1126 | + $args[ 'wp_referer[' . $key . ']' ] = $value; |
|
1127 | + } |
|
1128 | + } |
|
1129 | + return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
|
1130 | + } |
|
1131 | + |
|
1132 | + |
|
1133 | + /** |
|
1134 | + * This returns a generated link that will load the related help tab. |
|
1135 | + * |
|
1136 | + * @param string $help_tab_id the id for the connected help tab |
|
1137 | + * @param string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
1138 | + * @param string $help_text (optional) send help text you want to use for the link if default not to be used |
|
1139 | + * @uses EEH_Template::get_help_tab_link() |
|
1140 | + * @return string generated link |
|
1141 | + */ |
|
1142 | + protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '') |
|
1143 | + { |
|
1144 | + return EEH_Template::get_help_tab_link( |
|
1145 | + $help_tab_id, |
|
1146 | + $this->page_slug, |
|
1147 | + $this->_req_action, |
|
1148 | + $icon_style, |
|
1149 | + $help_text |
|
1150 | + ); |
|
1151 | + } |
|
1152 | + |
|
1153 | + |
|
1154 | + /** |
|
1155 | + * _add_help_tabs |
|
1156 | + * Note child classes define their help tabs within the page_config array. |
|
1157 | + * |
|
1158 | + * @link http://codex.wordpress.org/Function_Reference/add_help_tab |
|
1159 | + * @return void |
|
1160 | + * @throws DomainException |
|
1161 | + * @throws EE_Error |
|
1162 | + */ |
|
1163 | + protected function _add_help_tabs() |
|
1164 | + { |
|
1165 | + $tour_buttons = ''; |
|
1166 | + if (isset($this->_page_config[ $this->_req_action ])) { |
|
1167 | + $config = $this->_page_config[ $this->_req_action ]; |
|
1168 | + // is there a help tour for the current route? if there is let's setup the tour buttons |
|
1169 | + if (isset($this->_help_tour[ $this->_req_action ])) { |
|
1170 | + $tb = array(); |
|
1171 | + $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
|
1172 | + foreach ($this->_help_tour['tours'] as $tour) { |
|
1173 | + // if this is the end tour then we don't need to setup a button |
|
1174 | + if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) { |
|
1175 | + continue; |
|
1176 | + } |
|
1177 | + $tb[] = '<button id="trigger-tour-' |
|
1178 | + . $tour->get_slug() |
|
1179 | + . '" class="button-primary trigger-ee-help-tour">' |
|
1180 | + . $tour->get_label() |
|
1181 | + . '</button>'; |
|
1182 | + } |
|
1183 | + $tour_buttons .= implode('<br />', $tb); |
|
1184 | + $tour_buttons .= '</div></div>'; |
|
1185 | + } |
|
1186 | + // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
|
1187 | + if (is_array($config) && isset($config['help_sidebar'])) { |
|
1188 | + // check that the callback given is valid |
|
1189 | + if (! method_exists($this, $config['help_sidebar'])) { |
|
1190 | + throw new EE_Error( |
|
1191 | + sprintf( |
|
1192 | + esc_html__( |
|
1193 | + 'The _page_config array has a callback set for the "help_sidebar" option. However the callback given (%s) is not a valid callback. Doublecheck the spelling and make sure this method exists for the class %s', |
|
1194 | + 'event_espresso' |
|
1195 | + ), |
|
1196 | + $config['help_sidebar'], |
|
1197 | + get_class($this) |
|
1198 | + ) |
|
1199 | + ); |
|
1200 | + } |
|
1201 | + $content = apply_filters( |
|
1202 | + 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
1203 | + $this->{$config['help_sidebar']}() |
|
1204 | + ); |
|
1205 | + $content .= $tour_buttons; // add help tour buttons. |
|
1206 | + // do we have any help tours setup? Cause if we do we want to add the buttons |
|
1207 | + $this->_current_screen->set_help_sidebar($content); |
|
1208 | + } |
|
1209 | + // if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar. |
|
1210 | + if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
1211 | + $this->_current_screen->set_help_sidebar($tour_buttons); |
|
1212 | + } |
|
1213 | + // handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
|
1214 | + if (! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
1215 | + $_ht['id'] = $this->page_slug; |
|
1216 | + $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
|
1217 | + $_ht['content'] = '<p>' |
|
1218 | + . esc_html__( |
|
1219 | + 'The buttons to the right allow you to start/restart any help tours available for this page', |
|
1220 | + 'event_espresso' |
|
1221 | + ) . '</p>'; |
|
1222 | + $this->_current_screen->add_help_tab($_ht); |
|
1223 | + } |
|
1224 | + if (! isset($config['help_tabs'])) { |
|
1225 | + return; |
|
1226 | + } //no help tabs for this route |
|
1227 | + foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
|
1228 | + // we're here so there ARE help tabs! |
|
1229 | + // make sure we've got what we need |
|
1230 | + if (! isset($cfg['title'])) { |
|
1231 | + throw new EE_Error( |
|
1232 | + esc_html__( |
|
1233 | + 'The _page_config array is not set up properly for help tabs. It is missing a title', |
|
1234 | + 'event_espresso' |
|
1235 | + ) |
|
1236 | + ); |
|
1237 | + } |
|
1238 | + if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
1239 | + throw new EE_Error( |
|
1240 | + esc_html__( |
|
1241 | + 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
|
1242 | + 'event_espresso' |
|
1243 | + ) |
|
1244 | + ); |
|
1245 | + } |
|
1246 | + // first priority goes to content. |
|
1247 | + if (! empty($cfg['content'])) { |
|
1248 | + $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
|
1249 | + // second priority goes to filename |
|
1250 | + } elseif (! empty($cfg['filename'])) { |
|
1251 | + $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
1252 | + // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
|
1253 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
1254 | + . basename($this->_get_dir()) |
|
1255 | + . '/help_tabs/' |
|
1256 | + . $cfg['filename'] |
|
1257 | + . '.help_tab.php' : $file_path; |
|
1258 | + // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
1259 | + if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
1260 | + EE_Error::add_error( |
|
1261 | + sprintf( |
|
1262 | + esc_html__( |
|
1263 | + 'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content. Please check that the string you set for the help tab on this route (%s) is the correct spelling. The file should be in %s', |
|
1264 | + 'event_espresso' |
|
1265 | + ), |
|
1266 | + $tab_id, |
|
1267 | + key($config), |
|
1268 | + $file_path |
|
1269 | + ), |
|
1270 | + __FILE__, |
|
1271 | + __FUNCTION__, |
|
1272 | + __LINE__ |
|
1273 | + ); |
|
1274 | + return; |
|
1275 | + } |
|
1276 | + $template_args['admin_page_obj'] = $this; |
|
1277 | + $content = EEH_Template::display_template( |
|
1278 | + $file_path, |
|
1279 | + $template_args, |
|
1280 | + true |
|
1281 | + ); |
|
1282 | + } else { |
|
1283 | + $content = ''; |
|
1284 | + } |
|
1285 | + // check if callback is valid |
|
1286 | + if (empty($content) && ( |
|
1287 | + ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback']) |
|
1288 | + ) |
|
1289 | + ) { |
|
1290 | + EE_Error::add_error( |
|
1291 | + sprintf( |
|
1292 | + esc_html__( |
|
1293 | + 'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content. Check the spelling or make sure the method is present.', |
|
1294 | + 'event_espresso' |
|
1295 | + ), |
|
1296 | + $cfg['title'] |
|
1297 | + ), |
|
1298 | + __FILE__, |
|
1299 | + __FUNCTION__, |
|
1300 | + __LINE__ |
|
1301 | + ); |
|
1302 | + return; |
|
1303 | + } |
|
1304 | + // setup config array for help tab method |
|
1305 | + $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
1306 | + $_ht = array( |
|
1307 | + 'id' => $id, |
|
1308 | + 'title' => $cfg['title'], |
|
1309 | + 'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null, |
|
1310 | + 'content' => $content, |
|
1311 | + ); |
|
1312 | + $this->_current_screen->add_help_tab($_ht); |
|
1313 | + } |
|
1314 | + } |
|
1315 | + } |
|
1316 | + |
|
1317 | + |
|
1318 | + /** |
|
1319 | + * This basically checks loaded $_page_config property to see if there are any help_tours defined. "help_tours" is |
|
1320 | + * an array with properties for setting up usage of the joyride plugin |
|
1321 | + * |
|
1322 | + * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
1323 | + * @see instructions regarding the format and construction of the "help_tour" array element is found in the |
|
1324 | + * _set_page_config() comments |
|
1325 | + * @return void |
|
1326 | + * @throws EE_Error |
|
1327 | + * @throws InvalidArgumentException |
|
1328 | + * @throws InvalidDataTypeException |
|
1329 | + * @throws InvalidInterfaceException |
|
1330 | + */ |
|
1331 | + protected function _add_help_tour() |
|
1332 | + { |
|
1333 | + $tours = array(); |
|
1334 | + $this->_help_tour = array(); |
|
1335 | + // exit early if help tours are turned off globally |
|
1336 | + if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS) |
|
1337 | + || ! EE_Registry::instance()->CFG->admin->help_tour_activation |
|
1338 | + ) { |
|
1339 | + return; |
|
1340 | + } |
|
1341 | + // loop through _page_config to find any help_tour defined |
|
1342 | + foreach ($this->_page_config as $route => $config) { |
|
1343 | + // we're only going to set things up for this route |
|
1344 | + if ($route !== $this->_req_action) { |
|
1345 | + continue; |
|
1346 | + } |
|
1347 | + if (isset($config['help_tour'])) { |
|
1348 | + foreach ($config['help_tour'] as $tour) { |
|
1349 | + $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
1350 | + // let's see if we can get that file... |
|
1351 | + // if not its possible this is a decaf route not set in caffeinated |
|
1352 | + // so lets try and get the caffeinated equivalent |
|
1353 | + $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
|
1354 | + . basename($this->_get_dir()) |
|
1355 | + . '/help_tours/' |
|
1356 | + . $tour |
|
1357 | + . '.class.php' : $file_path; |
|
1358 | + // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
|
1359 | + if (! is_readable($file_path)) { |
|
1360 | + EE_Error::add_error( |
|
1361 | + sprintf( |
|
1362 | + esc_html__( |
|
1363 | + 'The file path given for the help tour (%s) is not a valid path. Please check that the string you set for the help tour on this route (%s) is the correct spelling', |
|
1364 | + 'event_espresso' |
|
1365 | + ), |
|
1366 | + $file_path, |
|
1367 | + $tour |
|
1368 | + ), |
|
1369 | + __FILE__, |
|
1370 | + __FUNCTION__, |
|
1371 | + __LINE__ |
|
1372 | + ); |
|
1373 | + return; |
|
1374 | + } |
|
1375 | + require_once $file_path; |
|
1376 | + if (! class_exists($tour)) { |
|
1377 | + $error_msg[] = sprintf( |
|
1378 | + esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), |
|
1379 | + $tour |
|
1380 | + ); |
|
1381 | + $error_msg[] = $error_msg[0] . "\r\n" |
|
1382 | + . sprintf( |
|
1383 | + esc_html__( |
|
1384 | + 'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
|
1385 | + 'event_espresso' |
|
1386 | + ), |
|
1387 | + $tour, |
|
1388 | + '<br />', |
|
1389 | + $tour, |
|
1390 | + $this->_req_action, |
|
1391 | + get_class($this) |
|
1392 | + ); |
|
1393 | + throw new EE_Error(implode('||', $error_msg)); |
|
1394 | + } |
|
1395 | + $tour_obj = new $tour($this->_is_caf); |
|
1396 | + $tours[] = $tour_obj; |
|
1397 | + $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
1398 | + } |
|
1399 | + // let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
|
1400 | + $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
|
1401 | + $tours[] = $end_stop_tour; |
|
1402 | + $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
1403 | + } |
|
1404 | + } |
|
1405 | + if (! empty($tours)) { |
|
1406 | + $this->_help_tour['tours'] = $tours; |
|
1407 | + } |
|
1408 | + // that's it! Now that the $_help_tours property is set (or not) |
|
1409 | + // the scripts and html should be taken care of automatically. |
|
1410 | + } |
|
1411 | + |
|
1412 | + |
|
1413 | + /** |
|
1414 | + * This simply sets up any qtips that have been defined in the page config |
|
1415 | + * |
|
1416 | + * @return void |
|
1417 | + */ |
|
1418 | + protected function _add_qtips() |
|
1419 | + { |
|
1420 | + if (isset($this->_route_config['qtips'])) { |
|
1421 | + $qtips = (array) $this->_route_config['qtips']; |
|
1422 | + // load qtip loader |
|
1423 | + $path = array( |
|
1424 | + $this->_get_dir() . '/qtips/', |
|
1425 | + EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
1426 | + ); |
|
1427 | + EEH_Qtip_Loader::instance()->register($qtips, $path); |
|
1428 | + } |
|
1429 | + } |
|
1430 | + |
|
1431 | + |
|
1432 | + /** |
|
1433 | + * _set_nav_tabs |
|
1434 | + * This sets up the nav tabs from the page_routes array. This method can be overwritten by child classes if you |
|
1435 | + * wish to add additional tabs or modify accordingly. |
|
1436 | + * |
|
1437 | + * @return void |
|
1438 | + * @throws InvalidArgumentException |
|
1439 | + * @throws InvalidInterfaceException |
|
1440 | + * @throws InvalidDataTypeException |
|
1441 | + */ |
|
1442 | + protected function _set_nav_tabs() |
|
1443 | + { |
|
1444 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1445 | + $i = 0; |
|
1446 | + foreach ($this->_page_config as $slug => $config) { |
|
1447 | + if (! is_array($config) |
|
1448 | + || ( |
|
1449 | + is_array($config) |
|
1450 | + && ( |
|
1451 | + (isset($config['nav']) && ! $config['nav']) |
|
1452 | + || ! isset($config['nav']) |
|
1453 | + ) |
|
1454 | + ) |
|
1455 | + ) { |
|
1456 | + continue; |
|
1457 | + } |
|
1458 | + // no nav tab for this config |
|
1459 | + // check for persistent flag |
|
1460 | + if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) { |
|
1461 | + // nav tab is only to appear when route requested. |
|
1462 | + continue; |
|
1463 | + } |
|
1464 | + if (! $this->check_user_access($slug, true)) { |
|
1465 | + // no nav tab because current user does not have access. |
|
1466 | + continue; |
|
1467 | + } |
|
1468 | + $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
1469 | + $this->_nav_tabs[ $slug ] = array( |
|
1470 | + 'url' => isset($config['nav']['url']) |
|
1471 | + ? $config['nav']['url'] |
|
1472 | + : self::add_query_args_and_nonce( |
|
1473 | + array('action' => $slug), |
|
1474 | + $this->_admin_base_url |
|
1475 | + ), |
|
1476 | + 'link_text' => isset($config['nav']['label']) |
|
1477 | + ? $config['nav']['label'] |
|
1478 | + : ucwords( |
|
1479 | + str_replace('_', ' ', $slug) |
|
1480 | + ), |
|
1481 | + 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
1482 | + 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
|
1483 | + ); |
|
1484 | + $i++; |
|
1485 | + } |
|
1486 | + // if $this->_nav_tabs is empty then lets set the default |
|
1487 | + if (empty($this->_nav_tabs)) { |
|
1488 | + $this->_nav_tabs[ $this->_default_nav_tab_name ] = array( |
|
1489 | + 'url' => $this->_admin_base_url, |
|
1490 | + 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
|
1491 | + 'css_class' => 'nav-tab-active', |
|
1492 | + 'order' => 10, |
|
1493 | + ); |
|
1494 | + } |
|
1495 | + // now let's sort the tabs according to order |
|
1496 | + usort($this->_nav_tabs, array($this, '_sort_nav_tabs')); |
|
1497 | + } |
|
1498 | + |
|
1499 | + |
|
1500 | + /** |
|
1501 | + * _set_current_labels |
|
1502 | + * This method modifies the _labels property with any optional specific labels indicated in the _page_routes |
|
1503 | + * property array |
|
1504 | + * |
|
1505 | + * @return void |
|
1506 | + */ |
|
1507 | + private function _set_current_labels() |
|
1508 | + { |
|
1509 | + if (is_array($this->_route_config) && isset($this->_route_config['labels'])) { |
|
1510 | + foreach ($this->_route_config['labels'] as $label => $text) { |
|
1511 | + if (is_array($text)) { |
|
1512 | + foreach ($text as $sublabel => $subtext) { |
|
1513 | + $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
1514 | + } |
|
1515 | + } else { |
|
1516 | + $this->_labels[ $label ] = $text; |
|
1517 | + } |
|
1518 | + } |
|
1519 | + } |
|
1520 | + } |
|
1521 | + |
|
1522 | + |
|
1523 | + /** |
|
1524 | + * verifies user access for this admin page |
|
1525 | + * |
|
1526 | + * @param string $route_to_check if present then the capability for the route matching this string is checked. |
|
1527 | + * @param bool $verify_only Default is FALSE which means if user check fails then wp_die(). Otherwise just |
|
1528 | + * return false if verify fail. |
|
1529 | + * @return bool |
|
1530 | + * @throws InvalidArgumentException |
|
1531 | + * @throws InvalidDataTypeException |
|
1532 | + * @throws InvalidInterfaceException |
|
1533 | + */ |
|
1534 | + public function check_user_access($route_to_check = '', $verify_only = false) |
|
1535 | + { |
|
1536 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1537 | + $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
|
1538 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
1539 | + && is_array( |
|
1540 | + $this->_page_routes[ $route_to_check ] |
|
1541 | + ) |
|
1542 | + && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
1543 | + ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
1544 | + if (empty($capability) && empty($route_to_check)) { |
|
1545 | + $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
|
1546 | + : $this->_route['capability']; |
|
1547 | + } else { |
|
1548 | + $capability = empty($capability) ? 'manage_options' : $capability; |
|
1549 | + } |
|
1550 | + $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
|
1551 | + if (! defined('DOING_AJAX') |
|
1552 | + && ( |
|
1553 | + ! function_exists('is_admin') |
|
1554 | + || ! EE_Registry::instance()->CAP->current_user_can( |
|
1555 | + $capability, |
|
1556 | + $this->page_slug |
|
1557 | + . '_' |
|
1558 | + . $route_to_check, |
|
1559 | + $id |
|
1560 | + ) |
|
1561 | + ) |
|
1562 | + ) { |
|
1563 | + if ($verify_only) { |
|
1564 | + return false; |
|
1565 | + } |
|
1566 | + if (is_user_logged_in()) { |
|
1567 | + wp_die(__('You do not have access to this route.', 'event_espresso')); |
|
1568 | + } else { |
|
1569 | + return false; |
|
1570 | + } |
|
1571 | + } |
|
1572 | + return true; |
|
1573 | + } |
|
1574 | + |
|
1575 | + |
|
1576 | + /** |
|
1577 | + * admin_init_global |
|
1578 | + * This runs all the code that we want executed within the WP admin_init hook. |
|
1579 | + * This method executes for ALL EE Admin pages. |
|
1580 | + * |
|
1581 | + * @return void |
|
1582 | + */ |
|
1583 | + public function admin_init_global() |
|
1584 | + { |
|
1585 | + } |
|
1586 | + |
|
1587 | + |
|
1588 | + /** |
|
1589 | + * wp_loaded_global |
|
1590 | + * This runs all the code that we want executed within the WP wp_loaded hook. This method is optional for an |
|
1591 | + * EE_Admin page and will execute on every EE Admin Page load |
|
1592 | + * |
|
1593 | + * @return void |
|
1594 | + */ |
|
1595 | + public function wp_loaded() |
|
1596 | + { |
|
1597 | + } |
|
1598 | + |
|
1599 | + |
|
1600 | + /** |
|
1601 | + * admin_notices |
|
1602 | + * Anything triggered by the 'admin_notices' WP hook should be put in here. This particular method will apply on |
|
1603 | + * ALL EE_Admin pages. |
|
1604 | + * |
|
1605 | + * @return void |
|
1606 | + */ |
|
1607 | + public function admin_notices_global() |
|
1608 | + { |
|
1609 | + $this->_display_no_javascript_warning(); |
|
1610 | + $this->_display_espresso_notices(); |
|
1611 | + } |
|
1612 | + |
|
1613 | + |
|
1614 | + public function network_admin_notices_global() |
|
1615 | + { |
|
1616 | + $this->_display_no_javascript_warning(); |
|
1617 | + $this->_display_espresso_notices(); |
|
1618 | + } |
|
1619 | + |
|
1620 | + |
|
1621 | + /** |
|
1622 | + * admin_footer_scripts_global |
|
1623 | + * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method |
|
1624 | + * will apply on ALL EE_Admin pages. |
|
1625 | + * |
|
1626 | + * @return void |
|
1627 | + */ |
|
1628 | + public function admin_footer_scripts_global() |
|
1629 | + { |
|
1630 | + $this->_add_admin_page_ajax_loading_img(); |
|
1631 | + $this->_add_admin_page_overlay(); |
|
1632 | + // if metaboxes are present we need to add the nonce field |
|
1633 | + if (isset($this->_route_config['metaboxes']) |
|
1634 | + || isset($this->_route_config['list_table']) |
|
1635 | + || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes']) |
|
1636 | + ) { |
|
1637 | + wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); |
|
1638 | + wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); |
|
1639 | + } |
|
1640 | + } |
|
1641 | + |
|
1642 | + |
|
1643 | + /** |
|
1644 | + * admin_footer_global |
|
1645 | + * Anything triggered by the wp 'admin_footer' wp hook should be put in here. This particular method will apply on |
|
1646 | + * ALL EE_Admin Pages. |
|
1647 | + * |
|
1648 | + * @return void |
|
1649 | + * @throws EE_Error |
|
1650 | + */ |
|
1651 | + public function admin_footer_global() |
|
1652 | + { |
|
1653 | + // dialog container for dialog helper |
|
1654 | + $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
1655 | + $d_cont .= '<div class="ee-notices"></div>'; |
|
1656 | + $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
|
1657 | + $d_cont .= '</div>'; |
|
1658 | + echo $d_cont; |
|
1659 | + // help tour stuff? |
|
1660 | + if (isset($this->_help_tour[ $this->_req_action ])) { |
|
1661 | + echo implode('<br />', $this->_help_tour[ $this->_req_action ]); |
|
1662 | + } |
|
1663 | + // current set timezone for timezone js |
|
1664 | + echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
1665 | + } |
|
1666 | + |
|
1667 | + |
|
1668 | + /** |
|
1669 | + * This function sees if there is a method for help popup content existing for the given route. If there is then |
|
1670 | + * we'll use the retrieved array to output the content using the template. For child classes: If you want to have |
|
1671 | + * help popups then in your templates or your content you set "triggers" for the content using the |
|
1672 | + * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method |
|
1673 | + * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup |
|
1674 | + * method for the content in the format "_help_popup_content_{route_name}()" So if you are setting help content |
|
1675 | + * for the |
|
1676 | + * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined |
|
1677 | + * "help_popup_content_..." method. You must prepare and return an array in the following format array( |
|
1678 | + * 'help_trigger_id' => array( |
|
1679 | + * 'title' => esc_html__('localized title for popup', 'event_espresso'), |
|
1680 | + * 'content' => esc_html__('localized content for popup', 'event_espresso') |
|
1681 | + * ) |
|
1682 | + * ); |
|
1683 | + * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route. |
|
1684 | + * |
|
1685 | + * @param array $help_array |
|
1686 | + * @param bool $display |
|
1687 | + * @return string content |
|
1688 | + * @throws DomainException |
|
1689 | + * @throws EE_Error |
|
1690 | + */ |
|
1691 | + protected function _set_help_popup_content($help_array = array(), $display = false) |
|
1692 | + { |
|
1693 | + $content = ''; |
|
1694 | + $help_array = empty($help_array) ? $this->_get_help_content() : $help_array; |
|
1695 | + // loop through the array and setup content |
|
1696 | + foreach ($help_array as $trigger => $help) { |
|
1697 | + // make sure the array is setup properly |
|
1698 | + if (! isset($help['title']) || ! isset($help['content'])) { |
|
1699 | + throw new EE_Error( |
|
1700 | + esc_html__( |
|
1701 | + 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
|
1702 | + 'event_espresso' |
|
1703 | + ) |
|
1704 | + ); |
|
1705 | + } |
|
1706 | + // we're good so let'd setup the template vars and then assign parsed template content to our content. |
|
1707 | + $template_args = array( |
|
1708 | + 'help_popup_id' => $trigger, |
|
1709 | + 'help_popup_title' => $help['title'], |
|
1710 | + 'help_popup_content' => $help['content'], |
|
1711 | + ); |
|
1712 | + $content .= EEH_Template::display_template( |
|
1713 | + EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
1714 | + $template_args, |
|
1715 | + true |
|
1716 | + ); |
|
1717 | + } |
|
1718 | + if ($display) { |
|
1719 | + echo $content; |
|
1720 | + return ''; |
|
1721 | + } |
|
1722 | + return $content; |
|
1723 | + } |
|
1724 | + |
|
1725 | + |
|
1726 | + /** |
|
1727 | + * All this does is retrieve the help content array if set by the EE_Admin_Page child |
|
1728 | + * |
|
1729 | + * @return array properly formatted array for help popup content |
|
1730 | + * @throws EE_Error |
|
1731 | + */ |
|
1732 | + private function _get_help_content() |
|
1733 | + { |
|
1734 | + // what is the method we're looking for? |
|
1735 | + $method_name = '_help_popup_content_' . $this->_req_action; |
|
1736 | + // if method doesn't exist let's get out. |
|
1737 | + if (! method_exists($this, $method_name)) { |
|
1738 | + return array(); |
|
1739 | + } |
|
1740 | + // k we're good to go let's retrieve the help array |
|
1741 | + $help_array = call_user_func(array($this, $method_name)); |
|
1742 | + // make sure we've got an array! |
|
1743 | + if (! is_array($help_array)) { |
|
1744 | + throw new EE_Error( |
|
1745 | + esc_html__( |
|
1746 | + 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
|
1747 | + 'event_espresso' |
|
1748 | + ) |
|
1749 | + ); |
|
1750 | + } |
|
1751 | + return $help_array; |
|
1752 | + } |
|
1753 | + |
|
1754 | + |
|
1755 | + /** |
|
1756 | + * EE Admin Pages can use this to set a properly formatted trigger for a help popup. |
|
1757 | + * By default the trigger html is printed. Otherwise it can be returned if the $display flag is set "false" |
|
1758 | + * See comments made on the _set_help_content method for understanding other parts to the help popup tool. |
|
1759 | + * |
|
1760 | + * @param string $trigger_id reference for retrieving the trigger content for the popup |
|
1761 | + * @param boolean $display if false then we return the trigger string |
|
1762 | + * @param array $dimensions an array of dimensions for the box (array(h,w)) |
|
1763 | + * @return string |
|
1764 | + * @throws DomainException |
|
1765 | + * @throws EE_Error |
|
1766 | + */ |
|
1767 | + protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640')) |
|
1768 | + { |
|
1769 | + if (defined('DOING_AJAX')) { |
|
1770 | + return ''; |
|
1771 | + } |
|
1772 | + // let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
|
1773 | + $help_array = $this->_get_help_content(); |
|
1774 | + $help_content = ''; |
|
1775 | + if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
1776 | + $help_array[ $trigger_id ] = array( |
|
1777 | + 'title' => esc_html__('Missing Content', 'event_espresso'), |
|
1778 | + 'content' => esc_html__( |
|
1779 | + 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
|
1780 | + 'event_espresso' |
|
1781 | + ), |
|
1782 | + ); |
|
1783 | + $help_content = $this->_set_help_popup_content($help_array, false); |
|
1784 | + } |
|
1785 | + // let's setup the trigger |
|
1786 | + $content = '<a class="ee-dialog" href="?height=' |
|
1787 | + . $dimensions[0] |
|
1788 | + . '&width=' |
|
1789 | + . $dimensions[1] |
|
1790 | + . '&inlineId=' |
|
1791 | + . $trigger_id |
|
1792 | + . '" target="_blank"><span class="question ee-help-popup-question"></span></a>'; |
|
1793 | + $content .= $help_content; |
|
1794 | + if ($display) { |
|
1795 | + echo $content; |
|
1796 | + return ''; |
|
1797 | + } |
|
1798 | + return $content; |
|
1799 | + } |
|
1800 | + |
|
1801 | + |
|
1802 | + /** |
|
1803 | + * _add_global_screen_options |
|
1804 | + * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so. |
|
1805 | + * This particular method will add_screen_options on ALL EE_Admin Pages |
|
1806 | + * |
|
1807 | + * @link http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/ |
|
1808 | + * see also WP_Screen object documents... |
|
1809 | + * @link http://codex.wordpress.org/Class_Reference/WP_Screen |
|
1810 | + * @abstract |
|
1811 | + * @return void |
|
1812 | + */ |
|
1813 | + private function _add_global_screen_options() |
|
1814 | + { |
|
1815 | + } |
|
1816 | + |
|
1817 | + |
|
1818 | + /** |
|
1819 | + * _add_global_feature_pointers |
|
1820 | + * This method is used for implementing any "feature pointers" (using built-in WP styling js). |
|
1821 | + * This particular method will implement feature pointers for ALL EE_Admin pages. |
|
1822 | + * Note: this is just a placeholder for now. Implementation will come down the road |
|
1823 | + * |
|
1824 | + * @see WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be |
|
1825 | + * extended) also see: |
|
1826 | + * @link http://eamann.com/tech/wordpress-portland/ |
|
1827 | + * @abstract |
|
1828 | + * @return void |
|
1829 | + */ |
|
1830 | + private function _add_global_feature_pointers() |
|
1831 | + { |
|
1832 | + } |
|
1833 | + |
|
1834 | + |
|
1835 | + /** |
|
1836 | + * load_global_scripts_styles |
|
1837 | + * The scripts and styles enqueued in here will be loaded on every EE Admin page |
|
1838 | + * |
|
1839 | + * @return void |
|
1840 | + * @throws EE_Error |
|
1841 | + */ |
|
1842 | + public function load_global_scripts_styles() |
|
1843 | + { |
|
1844 | + /** STYLES **/ |
|
1845 | + // add debugging styles |
|
1846 | + if (WP_DEBUG) { |
|
1847 | + add_action('admin_head', array($this, 'add_xdebug_style')); |
|
1848 | + } |
|
1849 | + // register all styles |
|
1850 | + wp_register_style( |
|
1851 | + 'espresso-ui-theme', |
|
1852 | + EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
1853 | + array(), |
|
1854 | + EVENT_ESPRESSO_VERSION |
|
1855 | + ); |
|
1856 | + wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
1857 | + // helpers styles |
|
1858 | + wp_register_style( |
|
1859 | + 'ee-text-links', |
|
1860 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
1861 | + array(), |
|
1862 | + EVENT_ESPRESSO_VERSION |
|
1863 | + ); |
|
1864 | + /** SCRIPTS **/ |
|
1865 | + // register all scripts |
|
1866 | + wp_register_script( |
|
1867 | + 'ee-dialog', |
|
1868 | + EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
1869 | + array('jquery', 'jquery-ui-draggable'), |
|
1870 | + EVENT_ESPRESSO_VERSION, |
|
1871 | + true |
|
1872 | + ); |
|
1873 | + wp_register_script( |
|
1874 | + 'ee_admin_js', |
|
1875 | + EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
1876 | + array('espresso_core', 'ee-parse-uri', 'ee-dialog'), |
|
1877 | + EVENT_ESPRESSO_VERSION, |
|
1878 | + true |
|
1879 | + ); |
|
1880 | + wp_register_script( |
|
1881 | + 'jquery-ui-timepicker-addon', |
|
1882 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
1883 | + array('jquery-ui-datepicker', 'jquery-ui-slider'), |
|
1884 | + EVENT_ESPRESSO_VERSION, |
|
1885 | + true |
|
1886 | + ); |
|
1887 | + add_filter('FHEE_load_joyride', '__return_true'); |
|
1888 | + // script for sorting tables |
|
1889 | + wp_register_script( |
|
1890 | + 'espresso_ajax_table_sorting', |
|
1891 | + EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
1892 | + array('ee_admin_js', 'jquery-ui-sortable'), |
|
1893 | + EVENT_ESPRESSO_VERSION, |
|
1894 | + true |
|
1895 | + ); |
|
1896 | + // script for parsing uri's |
|
1897 | + wp_register_script( |
|
1898 | + 'ee-parse-uri', |
|
1899 | + EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
1900 | + array(), |
|
1901 | + EVENT_ESPRESSO_VERSION, |
|
1902 | + true |
|
1903 | + ); |
|
1904 | + // and parsing associative serialized form elements |
|
1905 | + wp_register_script( |
|
1906 | + 'ee-serialize-full-array', |
|
1907 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
1908 | + array('jquery'), |
|
1909 | + EVENT_ESPRESSO_VERSION, |
|
1910 | + true |
|
1911 | + ); |
|
1912 | + // helpers scripts |
|
1913 | + wp_register_script( |
|
1914 | + 'ee-text-links', |
|
1915 | + EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
1916 | + array('jquery'), |
|
1917 | + EVENT_ESPRESSO_VERSION, |
|
1918 | + true |
|
1919 | + ); |
|
1920 | + wp_register_script( |
|
1921 | + 'ee-moment-core', |
|
1922 | + EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
1923 | + array(), |
|
1924 | + EVENT_ESPRESSO_VERSION, |
|
1925 | + true |
|
1926 | + ); |
|
1927 | + wp_register_script( |
|
1928 | + 'ee-moment', |
|
1929 | + EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
1930 | + array('ee-moment-core'), |
|
1931 | + EVENT_ESPRESSO_VERSION, |
|
1932 | + true |
|
1933 | + ); |
|
1934 | + wp_register_script( |
|
1935 | + 'ee-datepicker', |
|
1936 | + EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
1937 | + array('jquery-ui-timepicker-addon', 'ee-moment'), |
|
1938 | + EVENT_ESPRESSO_VERSION, |
|
1939 | + true |
|
1940 | + ); |
|
1941 | + // google charts |
|
1942 | + wp_register_script( |
|
1943 | + 'google-charts', |
|
1944 | + 'https://www.gstatic.com/charts/loader.js', |
|
1945 | + array(), |
|
1946 | + EVENT_ESPRESSO_VERSION, |
|
1947 | + false |
|
1948 | + ); |
|
1949 | + // ENQUEUE ALL BASICS BY DEFAULT |
|
1950 | + wp_enqueue_style('ee-admin-css'); |
|
1951 | + wp_enqueue_script('ee_admin_js'); |
|
1952 | + wp_enqueue_script('ee-accounting'); |
|
1953 | + wp_enqueue_script('jquery-validate'); |
|
1954 | + // taking care of metaboxes |
|
1955 | + if (empty($this->_cpt_route) |
|
1956 | + && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes'])) |
|
1957 | + ) { |
|
1958 | + wp_enqueue_script('dashboard'); |
|
1959 | + } |
|
1960 | + // LOCALIZED DATA |
|
1961 | + // localize script for ajax lazy loading |
|
1962 | + $lazy_loader_container_ids = apply_filters( |
|
1963 | + 'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers', |
|
1964 | + array('espresso_news_post_box_content') |
|
1965 | + ); |
|
1966 | + wp_localize_script('ee_admin_js', 'eeLazyLoadingContainers', $lazy_loader_container_ids); |
|
1967 | + /** |
|
1968 | + * help tour stuff |
|
1969 | + */ |
|
1970 | + if (! empty($this->_help_tour)) { |
|
1971 | + // register the js for kicking things off |
|
1972 | + wp_enqueue_script( |
|
1973 | + 'ee-help-tour', |
|
1974 | + EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
1975 | + array('jquery-joyride'), |
|
1976 | + EVENT_ESPRESSO_VERSION, |
|
1977 | + true |
|
1978 | + ); |
|
1979 | + $tours = array(); |
|
1980 | + // setup tours for the js tour object |
|
1981 | + foreach ($this->_help_tour['tours'] as $tour) { |
|
1982 | + if ($tour instanceof EE_Help_Tour) { |
|
1983 | + $tours[] = array( |
|
1984 | + 'id' => $tour->get_slug(), |
|
1985 | + 'options' => $tour->get_options(), |
|
1986 | + ); |
|
1987 | + } |
|
1988 | + } |
|
1989 | + wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours)); |
|
1990 | + // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour |
|
1991 | + } |
|
1992 | + } |
|
1993 | + |
|
1994 | + |
|
1995 | + /** |
|
1996 | + * admin_footer_scripts_eei18n_js_strings |
|
1997 | + * |
|
1998 | + * @return void |
|
1999 | + */ |
|
2000 | + public function admin_footer_scripts_eei18n_js_strings() |
|
2001 | + { |
|
2002 | + EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL; |
|
2003 | + EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__( |
|
2004 | + 'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!', |
|
2005 | + 'event_espresso' |
|
2006 | + ); |
|
2007 | + EE_Registry::$i18n_js_strings['January'] = esc_html__('January', 'event_espresso'); |
|
2008 | + EE_Registry::$i18n_js_strings['February'] = esc_html__('February', 'event_espresso'); |
|
2009 | + EE_Registry::$i18n_js_strings['March'] = esc_html__('March', 'event_espresso'); |
|
2010 | + EE_Registry::$i18n_js_strings['April'] = esc_html__('April', 'event_espresso'); |
|
2011 | + EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
2012 | + EE_Registry::$i18n_js_strings['June'] = esc_html__('June', 'event_espresso'); |
|
2013 | + EE_Registry::$i18n_js_strings['July'] = esc_html__('July', 'event_espresso'); |
|
2014 | + EE_Registry::$i18n_js_strings['August'] = esc_html__('August', 'event_espresso'); |
|
2015 | + EE_Registry::$i18n_js_strings['September'] = esc_html__('September', 'event_espresso'); |
|
2016 | + EE_Registry::$i18n_js_strings['October'] = esc_html__('October', 'event_espresso'); |
|
2017 | + EE_Registry::$i18n_js_strings['November'] = esc_html__('November', 'event_espresso'); |
|
2018 | + EE_Registry::$i18n_js_strings['December'] = esc_html__('December', 'event_espresso'); |
|
2019 | + EE_Registry::$i18n_js_strings['Jan'] = esc_html__('Jan', 'event_espresso'); |
|
2020 | + EE_Registry::$i18n_js_strings['Feb'] = esc_html__('Feb', 'event_espresso'); |
|
2021 | + EE_Registry::$i18n_js_strings['Mar'] = esc_html__('Mar', 'event_espresso'); |
|
2022 | + EE_Registry::$i18n_js_strings['Apr'] = esc_html__('Apr', 'event_espresso'); |
|
2023 | + EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso'); |
|
2024 | + EE_Registry::$i18n_js_strings['Jun'] = esc_html__('Jun', 'event_espresso'); |
|
2025 | + EE_Registry::$i18n_js_strings['Jul'] = esc_html__('Jul', 'event_espresso'); |
|
2026 | + EE_Registry::$i18n_js_strings['Aug'] = esc_html__('Aug', 'event_espresso'); |
|
2027 | + EE_Registry::$i18n_js_strings['Sep'] = esc_html__('Sep', 'event_espresso'); |
|
2028 | + EE_Registry::$i18n_js_strings['Oct'] = esc_html__('Oct', 'event_espresso'); |
|
2029 | + EE_Registry::$i18n_js_strings['Nov'] = esc_html__('Nov', 'event_espresso'); |
|
2030 | + EE_Registry::$i18n_js_strings['Dec'] = esc_html__('Dec', 'event_espresso'); |
|
2031 | + EE_Registry::$i18n_js_strings['Sunday'] = esc_html__('Sunday', 'event_espresso'); |
|
2032 | + EE_Registry::$i18n_js_strings['Monday'] = esc_html__('Monday', 'event_espresso'); |
|
2033 | + EE_Registry::$i18n_js_strings['Tuesday'] = esc_html__('Tuesday', 'event_espresso'); |
|
2034 | + EE_Registry::$i18n_js_strings['Wednesday'] = esc_html__('Wednesday', 'event_espresso'); |
|
2035 | + EE_Registry::$i18n_js_strings['Thursday'] = esc_html__('Thursday', 'event_espresso'); |
|
2036 | + EE_Registry::$i18n_js_strings['Friday'] = esc_html__('Friday', 'event_espresso'); |
|
2037 | + EE_Registry::$i18n_js_strings['Saturday'] = esc_html__('Saturday', 'event_espresso'); |
|
2038 | + EE_Registry::$i18n_js_strings['Sun'] = esc_html__('Sun', 'event_espresso'); |
|
2039 | + EE_Registry::$i18n_js_strings['Mon'] = esc_html__('Mon', 'event_espresso'); |
|
2040 | + EE_Registry::$i18n_js_strings['Tue'] = esc_html__('Tue', 'event_espresso'); |
|
2041 | + EE_Registry::$i18n_js_strings['Wed'] = esc_html__('Wed', 'event_espresso'); |
|
2042 | + EE_Registry::$i18n_js_strings['Thu'] = esc_html__('Thu', 'event_espresso'); |
|
2043 | + EE_Registry::$i18n_js_strings['Fri'] = esc_html__('Fri', 'event_espresso'); |
|
2044 | + EE_Registry::$i18n_js_strings['Sat'] = esc_html__('Sat', 'event_espresso'); |
|
2045 | + } |
|
2046 | + |
|
2047 | + |
|
2048 | + /** |
|
2049 | + * load enhanced xdebug styles for ppl with failing eyesight |
|
2050 | + * |
|
2051 | + * @return void |
|
2052 | + */ |
|
2053 | + public function add_xdebug_style() |
|
2054 | + { |
|
2055 | + echo '<style>.xdebug-error { font-size:1.5em; }</style>'; |
|
2056 | + } |
|
2057 | + |
|
2058 | + |
|
2059 | + /************************/ |
|
2060 | + /** LIST TABLE METHODS **/ |
|
2061 | + /************************/ |
|
2062 | + /** |
|
2063 | + * this sets up the list table if the current view requires it. |
|
2064 | + * |
|
2065 | + * @return void |
|
2066 | + * @throws EE_Error |
|
2067 | + */ |
|
2068 | + protected function _set_list_table() |
|
2069 | + { |
|
2070 | + // first is this a list_table view? |
|
2071 | + if (! isset($this->_route_config['list_table'])) { |
|
2072 | + return; |
|
2073 | + } //not a list_table view so get out. |
|
2074 | + // list table functions are per view specific (because some admin pages might have more than one list table!) |
|
2075 | + $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
2076 | + if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
2077 | + // user error msg |
|
2078 | + $error_msg = esc_html__( |
|
2079 | + 'An error occurred. The requested list table views could not be found.', |
|
2080 | + 'event_espresso' |
|
2081 | + ); |
|
2082 | + // developer error msg |
|
2083 | + $error_msg .= '||' |
|
2084 | + . sprintf( |
|
2085 | + esc_html__( |
|
2086 | + 'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.', |
|
2087 | + 'event_espresso' |
|
2088 | + ), |
|
2089 | + $this->_req_action, |
|
2090 | + $list_table_view |
|
2091 | + ); |
|
2092 | + throw new EE_Error($error_msg); |
|
2093 | + } |
|
2094 | + // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
|
2095 | + $this->_views = apply_filters( |
|
2096 | + 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
2097 | + $this->_views |
|
2098 | + ); |
|
2099 | + $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
2100 | + $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
|
2101 | + $this->_set_list_table_view(); |
|
2102 | + $this->_set_list_table_object(); |
|
2103 | + } |
|
2104 | + |
|
2105 | + |
|
2106 | + /** |
|
2107 | + * set current view for List Table |
|
2108 | + * |
|
2109 | + * @return void |
|
2110 | + */ |
|
2111 | + protected function _set_list_table_view() |
|
2112 | + { |
|
2113 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2114 | + // looking at active items or dumpster diving ? |
|
2115 | + if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
2116 | + $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
|
2117 | + } else { |
|
2118 | + $this->_view = sanitize_key($this->_req_data['status']); |
|
2119 | + } |
|
2120 | + } |
|
2121 | + |
|
2122 | + |
|
2123 | + /** |
|
2124 | + * _set_list_table_object |
|
2125 | + * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of. |
|
2126 | + * |
|
2127 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
2128 | + * @throws \InvalidArgumentException |
|
2129 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
2130 | + * @throws EE_Error |
|
2131 | + * @throws InvalidInterfaceException |
|
2132 | + */ |
|
2133 | + protected function _set_list_table_object() |
|
2134 | + { |
|
2135 | + if (isset($this->_route_config['list_table'])) { |
|
2136 | + if (! class_exists($this->_route_config['list_table'])) { |
|
2137 | + throw new EE_Error( |
|
2138 | + sprintf( |
|
2139 | + esc_html__( |
|
2140 | + 'The %s class defined for the list table does not exist. Please check the spelling of the class ref in the $_page_config property on %s.', |
|
2141 | + 'event_espresso' |
|
2142 | + ), |
|
2143 | + $this->_route_config['list_table'], |
|
2144 | + get_class($this) |
|
2145 | + ) |
|
2146 | + ); |
|
2147 | + } |
|
2148 | + $this->_list_table_object = $this->loader->getShared( |
|
2149 | + $this->_route_config['list_table'], |
|
2150 | + array($this) |
|
2151 | + ); |
|
2152 | + } |
|
2153 | + } |
|
2154 | + |
|
2155 | + |
|
2156 | + /** |
|
2157 | + * get_list_table_view_RLs - get it? View RL ?? VU-RL??? URL ?? |
|
2158 | + * |
|
2159 | + * @param array $extra_query_args Optional. An array of extra query args to add to the generated |
|
2160 | + * urls. The array should be indexed by the view it is being |
|
2161 | + * added to. |
|
2162 | + * @return array |
|
2163 | + */ |
|
2164 | + public function get_list_table_view_RLs($extra_query_args = array()) |
|
2165 | + { |
|
2166 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2167 | + if (empty($this->_views)) { |
|
2168 | + $this->_views = array(); |
|
2169 | + } |
|
2170 | + // cycle thru views |
|
2171 | + foreach ($this->_views as $key => $view) { |
|
2172 | + $query_args = array(); |
|
2173 | + // check for current view |
|
2174 | + $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
2175 | + $query_args['action'] = $this->_req_action; |
|
2176 | + $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
2177 | + $query_args['status'] = $view['slug']; |
|
2178 | + // merge any other arguments sent in. |
|
2179 | + if (isset($extra_query_args[ $view['slug'] ])) { |
|
2180 | + $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]); |
|
2181 | + } |
|
2182 | + $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
2183 | + } |
|
2184 | + return $this->_views; |
|
2185 | + } |
|
2186 | + |
|
2187 | + |
|
2188 | + /** |
|
2189 | + * _entries_per_page_dropdown |
|
2190 | + * generates a drop down box for selecting the number of visible rows in an admin page list table |
|
2191 | + * |
|
2192 | + * @todo : Note: ideally this should be added to the screen options dropdown as that would be consistent with how |
|
2193 | + * WP does it. |
|
2194 | + * @param int $max_entries total number of rows in the table |
|
2195 | + * @return string |
|
2196 | + */ |
|
2197 | + protected function _entries_per_page_dropdown($max_entries = 0) |
|
2198 | + { |
|
2199 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2200 | + $values = array(10, 25, 50, 100); |
|
2201 | + $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
2202 | + if ($max_entries) { |
|
2203 | + $values[] = $max_entries; |
|
2204 | + sort($values); |
|
2205 | + } |
|
2206 | + $entries_per_page_dropdown = ' |
|
2207 | 2207 | <div id="entries-per-page-dv" class="alignleft actions"> |
2208 | 2208 | <label class="hide-if-no-js"> |
2209 | 2209 | Show |
2210 | 2210 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
2211 | - foreach ($values as $value) { |
|
2212 | - if ($value < $max_entries) { |
|
2213 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
2214 | - $entries_per_page_dropdown .= ' |
|
2211 | + foreach ($values as $value) { |
|
2212 | + if ($value < $max_entries) { |
|
2213 | + $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
2214 | + $entries_per_page_dropdown .= ' |
|
2215 | 2215 | <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
2216 | - } |
|
2217 | - } |
|
2218 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
2219 | - $entries_per_page_dropdown .= ' |
|
2216 | + } |
|
2217 | + } |
|
2218 | + $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
2219 | + $entries_per_page_dropdown .= ' |
|
2220 | 2220 | <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
2221 | - $entries_per_page_dropdown .= ' |
|
2221 | + $entries_per_page_dropdown .= ' |
|
2222 | 2222 | </select> |
2223 | 2223 | entries |
2224 | 2224 | </label> |
2225 | 2225 | <input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" > |
2226 | 2226 | </div> |
2227 | 2227 | '; |
2228 | - return $entries_per_page_dropdown; |
|
2229 | - } |
|
2230 | - |
|
2231 | - |
|
2232 | - /** |
|
2233 | - * _set_search_attributes |
|
2234 | - * |
|
2235 | - * @return void |
|
2236 | - */ |
|
2237 | - public function _set_search_attributes() |
|
2238 | - { |
|
2239 | - $this->_template_args['search']['btn_label'] = sprintf( |
|
2240 | - esc_html__('Search %s', 'event_espresso'), |
|
2241 | - empty($this->_search_btn_label) ? $this->page_label |
|
2242 | - : $this->_search_btn_label |
|
2243 | - ); |
|
2244 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
2245 | - } |
|
2246 | - |
|
2247 | - |
|
2248 | - |
|
2249 | - /*** END LIST TABLE METHODS **/ |
|
2250 | - |
|
2251 | - |
|
2252 | - /** |
|
2253 | - * _add_registered_metaboxes |
|
2254 | - * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
2255 | - * |
|
2256 | - * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
2257 | - * @return void |
|
2258 | - * @throws EE_Error |
|
2259 | - */ |
|
2260 | - private function _add_registered_meta_boxes() |
|
2261 | - { |
|
2262 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2263 | - // we only add meta boxes if the page_route calls for it |
|
2264 | - if (is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
2265 | - && is_array( |
|
2266 | - $this->_route_config['metaboxes'] |
|
2267 | - ) |
|
2268 | - ) { |
|
2269 | - // this simply loops through the callbacks provided |
|
2270 | - // and checks if there is a corresponding callback registered by the child |
|
2271 | - // if there is then we go ahead and process the metabox loader. |
|
2272 | - foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
2273 | - // first check for Closures |
|
2274 | - if ($metabox_callback instanceof Closure) { |
|
2275 | - $result = $metabox_callback(); |
|
2276 | - } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
2277 | - $result = call_user_func(array($metabox_callback[0], $metabox_callback[1])); |
|
2278 | - } else { |
|
2279 | - $result = call_user_func(array($this, &$metabox_callback)); |
|
2280 | - } |
|
2281 | - if ($result === false) { |
|
2282 | - // user error msg |
|
2283 | - $error_msg = esc_html__( |
|
2284 | - 'An error occurred. The requested metabox could not be found.', |
|
2285 | - 'event_espresso' |
|
2286 | - ); |
|
2287 | - // developer error msg |
|
2288 | - $error_msg .= '||' |
|
2289 | - . sprintf( |
|
2290 | - esc_html__( |
|
2291 | - 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
2292 | - 'event_espresso' |
|
2293 | - ), |
|
2294 | - $metabox_callback |
|
2295 | - ); |
|
2296 | - throw new EE_Error($error_msg); |
|
2297 | - } |
|
2298 | - } |
|
2299 | - } |
|
2300 | - } |
|
2301 | - |
|
2302 | - |
|
2303 | - /** |
|
2304 | - * _add_screen_columns |
|
2305 | - * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
2306 | - * the dynamic column template and we'll setup the column options for the page. |
|
2307 | - * |
|
2308 | - * @return void |
|
2309 | - */ |
|
2310 | - private function _add_screen_columns() |
|
2311 | - { |
|
2312 | - if (is_array($this->_route_config) |
|
2313 | - && isset($this->_route_config['columns']) |
|
2314 | - && is_array($this->_route_config['columns']) |
|
2315 | - && count($this->_route_config['columns']) === 2 |
|
2316 | - ) { |
|
2317 | - add_screen_option( |
|
2318 | - 'layout_columns', |
|
2319 | - array( |
|
2320 | - 'max' => (int) $this->_route_config['columns'][0], |
|
2321 | - 'default' => (int) $this->_route_config['columns'][1], |
|
2322 | - ) |
|
2323 | - ); |
|
2324 | - $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
2325 | - $screen_id = $this->_current_screen->id; |
|
2326 | - $screen_columns = (int) get_user_option("screen_layout_{$screen_id}"); |
|
2327 | - $total_columns = ! empty($screen_columns) |
|
2328 | - ? $screen_columns |
|
2329 | - : $this->_route_config['columns'][1]; |
|
2330 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
2331 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
2332 | - $this->_template_args['screen'] = $this->_current_screen; |
|
2333 | - $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
2334 | - . 'admin_details_metabox_column_wrapper.template.php'; |
|
2335 | - // finally if we don't have has_metaboxes set in the route config |
|
2336 | - // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
2337 | - $this->_route_config['has_metaboxes'] = true; |
|
2338 | - } |
|
2339 | - } |
|
2340 | - |
|
2341 | - |
|
2342 | - |
|
2343 | - /** GLOBALLY AVAILABLE METABOXES **/ |
|
2344 | - |
|
2345 | - |
|
2346 | - /** |
|
2347 | - * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
2348 | - * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
2349 | - * these get loaded on. |
|
2350 | - */ |
|
2351 | - private function _espresso_news_post_box() |
|
2352 | - { |
|
2353 | - $news_box_title = apply_filters( |
|
2354 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
2355 | - esc_html__('New @ Event Espresso', 'event_espresso') |
|
2356 | - ); |
|
2357 | - add_meta_box( |
|
2358 | - 'espresso_news_post_box', |
|
2359 | - $news_box_title, |
|
2360 | - array( |
|
2361 | - $this, |
|
2362 | - 'espresso_news_post_box', |
|
2363 | - ), |
|
2364 | - $this->_wp_page_slug, |
|
2365 | - 'side' |
|
2366 | - ); |
|
2367 | - } |
|
2368 | - |
|
2369 | - |
|
2370 | - /** |
|
2371 | - * Code for setting up espresso ratings request metabox. |
|
2372 | - */ |
|
2373 | - protected function _espresso_ratings_request() |
|
2374 | - { |
|
2375 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
2376 | - return; |
|
2377 | - } |
|
2378 | - $ratings_box_title = apply_filters( |
|
2379 | - 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
2380 | - esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
2381 | - ); |
|
2382 | - add_meta_box( |
|
2383 | - 'espresso_ratings_request', |
|
2384 | - $ratings_box_title, |
|
2385 | - array( |
|
2386 | - $this, |
|
2387 | - 'espresso_ratings_request', |
|
2388 | - ), |
|
2389 | - $this->_wp_page_slug, |
|
2390 | - 'side' |
|
2391 | - ); |
|
2392 | - } |
|
2393 | - |
|
2394 | - |
|
2395 | - /** |
|
2396 | - * Code for setting up espresso ratings request metabox content. |
|
2397 | - * |
|
2398 | - * @throws DomainException |
|
2399 | - */ |
|
2400 | - public function espresso_ratings_request() |
|
2401 | - { |
|
2402 | - EEH_Template::display_template( |
|
2403 | - EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
2404 | - array() |
|
2405 | - ); |
|
2406 | - } |
|
2407 | - |
|
2408 | - |
|
2409 | - public static function cached_rss_display($rss_id, $url) |
|
2410 | - { |
|
2411 | - $loading = '<p class="widget-loading hide-if-no-js">' |
|
2412 | - . __('Loading…', 'event_espresso') |
|
2413 | - . '</p><p class="hide-if-js">' |
|
2414 | - . esc_html__('This widget requires JavaScript.', 'event_espresso') |
|
2415 | - . '</p>'; |
|
2416 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
2417 | - $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
2418 | - $post = '</div>' . "\n"; |
|
2419 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
2420 | - $output = get_transient($cache_key); |
|
2421 | - if ($output !== false) { |
|
2422 | - echo $pre . $output . $post; |
|
2423 | - return true; |
|
2424 | - } |
|
2425 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
2426 | - echo $pre . $loading . $post; |
|
2427 | - return false; |
|
2428 | - } |
|
2429 | - ob_start(); |
|
2430 | - wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5)); |
|
2431 | - set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
2432 | - return true; |
|
2433 | - } |
|
2434 | - |
|
2435 | - |
|
2436 | - public function espresso_news_post_box() |
|
2437 | - { |
|
2438 | - ?> |
|
2228 | + return $entries_per_page_dropdown; |
|
2229 | + } |
|
2230 | + |
|
2231 | + |
|
2232 | + /** |
|
2233 | + * _set_search_attributes |
|
2234 | + * |
|
2235 | + * @return void |
|
2236 | + */ |
|
2237 | + public function _set_search_attributes() |
|
2238 | + { |
|
2239 | + $this->_template_args['search']['btn_label'] = sprintf( |
|
2240 | + esc_html__('Search %s', 'event_espresso'), |
|
2241 | + empty($this->_search_btn_label) ? $this->page_label |
|
2242 | + : $this->_search_btn_label |
|
2243 | + ); |
|
2244 | + $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
2245 | + } |
|
2246 | + |
|
2247 | + |
|
2248 | + |
|
2249 | + /*** END LIST TABLE METHODS **/ |
|
2250 | + |
|
2251 | + |
|
2252 | + /** |
|
2253 | + * _add_registered_metaboxes |
|
2254 | + * this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array. |
|
2255 | + * |
|
2256 | + * @link http://codex.wordpress.org/Function_Reference/add_meta_box |
|
2257 | + * @return void |
|
2258 | + * @throws EE_Error |
|
2259 | + */ |
|
2260 | + private function _add_registered_meta_boxes() |
|
2261 | + { |
|
2262 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2263 | + // we only add meta boxes if the page_route calls for it |
|
2264 | + if (is_array($this->_route_config) && isset($this->_route_config['metaboxes']) |
|
2265 | + && is_array( |
|
2266 | + $this->_route_config['metaboxes'] |
|
2267 | + ) |
|
2268 | + ) { |
|
2269 | + // this simply loops through the callbacks provided |
|
2270 | + // and checks if there is a corresponding callback registered by the child |
|
2271 | + // if there is then we go ahead and process the metabox loader. |
|
2272 | + foreach ($this->_route_config['metaboxes'] as $metabox_callback) { |
|
2273 | + // first check for Closures |
|
2274 | + if ($metabox_callback instanceof Closure) { |
|
2275 | + $result = $metabox_callback(); |
|
2276 | + } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) { |
|
2277 | + $result = call_user_func(array($metabox_callback[0], $metabox_callback[1])); |
|
2278 | + } else { |
|
2279 | + $result = call_user_func(array($this, &$metabox_callback)); |
|
2280 | + } |
|
2281 | + if ($result === false) { |
|
2282 | + // user error msg |
|
2283 | + $error_msg = esc_html__( |
|
2284 | + 'An error occurred. The requested metabox could not be found.', |
|
2285 | + 'event_espresso' |
|
2286 | + ); |
|
2287 | + // developer error msg |
|
2288 | + $error_msg .= '||' |
|
2289 | + . sprintf( |
|
2290 | + esc_html__( |
|
2291 | + 'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.', |
|
2292 | + 'event_espresso' |
|
2293 | + ), |
|
2294 | + $metabox_callback |
|
2295 | + ); |
|
2296 | + throw new EE_Error($error_msg); |
|
2297 | + } |
|
2298 | + } |
|
2299 | + } |
|
2300 | + } |
|
2301 | + |
|
2302 | + |
|
2303 | + /** |
|
2304 | + * _add_screen_columns |
|
2305 | + * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as |
|
2306 | + * the dynamic column template and we'll setup the column options for the page. |
|
2307 | + * |
|
2308 | + * @return void |
|
2309 | + */ |
|
2310 | + private function _add_screen_columns() |
|
2311 | + { |
|
2312 | + if (is_array($this->_route_config) |
|
2313 | + && isset($this->_route_config['columns']) |
|
2314 | + && is_array($this->_route_config['columns']) |
|
2315 | + && count($this->_route_config['columns']) === 2 |
|
2316 | + ) { |
|
2317 | + add_screen_option( |
|
2318 | + 'layout_columns', |
|
2319 | + array( |
|
2320 | + 'max' => (int) $this->_route_config['columns'][0], |
|
2321 | + 'default' => (int) $this->_route_config['columns'][1], |
|
2322 | + ) |
|
2323 | + ); |
|
2324 | + $this->_template_args['num_columns'] = $this->_route_config['columns'][0]; |
|
2325 | + $screen_id = $this->_current_screen->id; |
|
2326 | + $screen_columns = (int) get_user_option("screen_layout_{$screen_id}"); |
|
2327 | + $total_columns = ! empty($screen_columns) |
|
2328 | + ? $screen_columns |
|
2329 | + : $this->_route_config['columns'][1]; |
|
2330 | + $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
2331 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
2332 | + $this->_template_args['screen'] = $this->_current_screen; |
|
2333 | + $this->_column_template_path = EE_ADMIN_TEMPLATE |
|
2334 | + . 'admin_details_metabox_column_wrapper.template.php'; |
|
2335 | + // finally if we don't have has_metaboxes set in the route config |
|
2336 | + // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded. |
|
2337 | + $this->_route_config['has_metaboxes'] = true; |
|
2338 | + } |
|
2339 | + } |
|
2340 | + |
|
2341 | + |
|
2342 | + |
|
2343 | + /** GLOBALLY AVAILABLE METABOXES **/ |
|
2344 | + |
|
2345 | + |
|
2346 | + /** |
|
2347 | + * In this section we put any globally available EE metaboxes for all EE Admin pages. They are called by simply |
|
2348 | + * referencing the callback in the _page_config array property. This way you can be very specific about what pages |
|
2349 | + * these get loaded on. |
|
2350 | + */ |
|
2351 | + private function _espresso_news_post_box() |
|
2352 | + { |
|
2353 | + $news_box_title = apply_filters( |
|
2354 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
2355 | + esc_html__('New @ Event Espresso', 'event_espresso') |
|
2356 | + ); |
|
2357 | + add_meta_box( |
|
2358 | + 'espresso_news_post_box', |
|
2359 | + $news_box_title, |
|
2360 | + array( |
|
2361 | + $this, |
|
2362 | + 'espresso_news_post_box', |
|
2363 | + ), |
|
2364 | + $this->_wp_page_slug, |
|
2365 | + 'side' |
|
2366 | + ); |
|
2367 | + } |
|
2368 | + |
|
2369 | + |
|
2370 | + /** |
|
2371 | + * Code for setting up espresso ratings request metabox. |
|
2372 | + */ |
|
2373 | + protected function _espresso_ratings_request() |
|
2374 | + { |
|
2375 | + if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
2376 | + return; |
|
2377 | + } |
|
2378 | + $ratings_box_title = apply_filters( |
|
2379 | + 'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title', |
|
2380 | + esc_html__('Keep Event Espresso Decaf Free', 'event_espresso') |
|
2381 | + ); |
|
2382 | + add_meta_box( |
|
2383 | + 'espresso_ratings_request', |
|
2384 | + $ratings_box_title, |
|
2385 | + array( |
|
2386 | + $this, |
|
2387 | + 'espresso_ratings_request', |
|
2388 | + ), |
|
2389 | + $this->_wp_page_slug, |
|
2390 | + 'side' |
|
2391 | + ); |
|
2392 | + } |
|
2393 | + |
|
2394 | + |
|
2395 | + /** |
|
2396 | + * Code for setting up espresso ratings request metabox content. |
|
2397 | + * |
|
2398 | + * @throws DomainException |
|
2399 | + */ |
|
2400 | + public function espresso_ratings_request() |
|
2401 | + { |
|
2402 | + EEH_Template::display_template( |
|
2403 | + EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
2404 | + array() |
|
2405 | + ); |
|
2406 | + } |
|
2407 | + |
|
2408 | + |
|
2409 | + public static function cached_rss_display($rss_id, $url) |
|
2410 | + { |
|
2411 | + $loading = '<p class="widget-loading hide-if-no-js">' |
|
2412 | + . __('Loading…', 'event_espresso') |
|
2413 | + . '</p><p class="hide-if-js">' |
|
2414 | + . esc_html__('This widget requires JavaScript.', 'event_espresso') |
|
2415 | + . '</p>'; |
|
2416 | + $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
2417 | + $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
2418 | + $post = '</div>' . "\n"; |
|
2419 | + $cache_key = 'ee_rss_' . md5($rss_id); |
|
2420 | + $output = get_transient($cache_key); |
|
2421 | + if ($output !== false) { |
|
2422 | + echo $pre . $output . $post; |
|
2423 | + return true; |
|
2424 | + } |
|
2425 | + if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
2426 | + echo $pre . $loading . $post; |
|
2427 | + return false; |
|
2428 | + } |
|
2429 | + ob_start(); |
|
2430 | + wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5)); |
|
2431 | + set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS); |
|
2432 | + return true; |
|
2433 | + } |
|
2434 | + |
|
2435 | + |
|
2436 | + public function espresso_news_post_box() |
|
2437 | + { |
|
2438 | + ?> |
|
2439 | 2439 | <div class="padding"> |
2440 | 2440 | <div id="espresso_news_post_box_content" class="infolinks"> |
2441 | 2441 | <?php |
2442 | - // Get RSS Feed(s) |
|
2443 | - self::cached_rss_display( |
|
2444 | - 'espresso_news_post_box_content', |
|
2445 | - urlencode( |
|
2446 | - apply_filters( |
|
2447 | - 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
2448 | - 'http://eventespresso.com/feed/' |
|
2449 | - ) |
|
2450 | - ) |
|
2451 | - ); |
|
2452 | - ?> |
|
2442 | + // Get RSS Feed(s) |
|
2443 | + self::cached_rss_display( |
|
2444 | + 'espresso_news_post_box_content', |
|
2445 | + urlencode( |
|
2446 | + apply_filters( |
|
2447 | + 'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url', |
|
2448 | + 'http://eventespresso.com/feed/' |
|
2449 | + ) |
|
2450 | + ) |
|
2451 | + ); |
|
2452 | + ?> |
|
2453 | 2453 | </div> |
2454 | 2454 | <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?> |
2455 | 2455 | </div> |
2456 | 2456 | <?php |
2457 | - } |
|
2458 | - |
|
2459 | - |
|
2460 | - private function _espresso_links_post_box() |
|
2461 | - { |
|
2462 | - // Hiding until we actually have content to put in here... |
|
2463 | - // add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
2464 | - } |
|
2465 | - |
|
2466 | - |
|
2467 | - public function espresso_links_post_box() |
|
2468 | - { |
|
2469 | - // Hiding until we actually have content to put in here... |
|
2470 | - // EEH_Template::display_template( |
|
2471 | - // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
2472 | - // ); |
|
2473 | - } |
|
2474 | - |
|
2475 | - |
|
2476 | - protected function _espresso_sponsors_post_box() |
|
2477 | - { |
|
2478 | - if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
2479 | - add_meta_box( |
|
2480 | - 'espresso_sponsors_post_box', |
|
2481 | - esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
2482 | - array($this, 'espresso_sponsors_post_box'), |
|
2483 | - $this->_wp_page_slug, |
|
2484 | - 'side' |
|
2485 | - ); |
|
2486 | - } |
|
2487 | - } |
|
2488 | - |
|
2489 | - |
|
2490 | - public function espresso_sponsors_post_box() |
|
2491 | - { |
|
2492 | - EEH_Template::display_template( |
|
2493 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
2494 | - ); |
|
2495 | - } |
|
2496 | - |
|
2497 | - |
|
2498 | - private function _publish_post_box() |
|
2499 | - { |
|
2500 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
2501 | - // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
2502 | - // then we'll use that for the metabox label. |
|
2503 | - // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
2504 | - if (! empty($this->_labels['publishbox'])) { |
|
2505 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
2506 | - : $this->_labels['publishbox']; |
|
2507 | - } else { |
|
2508 | - $box_label = esc_html__('Publish', 'event_espresso'); |
|
2509 | - } |
|
2510 | - $box_label = apply_filters( |
|
2511 | - 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
2512 | - $box_label, |
|
2513 | - $this->_req_action, |
|
2514 | - $this |
|
2515 | - ); |
|
2516 | - add_meta_box( |
|
2517 | - $meta_box_ref, |
|
2518 | - $box_label, |
|
2519 | - array($this, 'editor_overview'), |
|
2520 | - $this->_current_screen->id, |
|
2521 | - 'side', |
|
2522 | - 'high' |
|
2523 | - ); |
|
2524 | - } |
|
2525 | - |
|
2526 | - |
|
2527 | - public function editor_overview() |
|
2528 | - { |
|
2529 | - // if we have extra content set let's add it in if not make sure its empty |
|
2530 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
2531 | - ? $this->_template_args['publish_box_extra_content'] |
|
2532 | - : ''; |
|
2533 | - echo EEH_Template::display_template( |
|
2534 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
2535 | - $this->_template_args, |
|
2536 | - true |
|
2537 | - ); |
|
2538 | - } |
|
2539 | - |
|
2540 | - |
|
2541 | - /** end of globally available metaboxes section **/ |
|
2542 | - |
|
2543 | - |
|
2544 | - /** |
|
2545 | - * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
2546 | - * protected method. |
|
2547 | - * |
|
2548 | - * @see $this->_set_publish_post_box_vars for param details |
|
2549 | - * @since 4.6.0 |
|
2550 | - * @param string $name |
|
2551 | - * @param int $id |
|
2552 | - * @param bool $delete |
|
2553 | - * @param string $save_close_redirect_URL |
|
2554 | - * @param bool $both_btns |
|
2555 | - * @throws EE_Error |
|
2556 | - * @throws InvalidArgumentException |
|
2557 | - * @throws InvalidDataTypeException |
|
2558 | - * @throws InvalidInterfaceException |
|
2559 | - */ |
|
2560 | - public function set_publish_post_box_vars( |
|
2561 | - $name = '', |
|
2562 | - $id = 0, |
|
2563 | - $delete = false, |
|
2564 | - $save_close_redirect_URL = '', |
|
2565 | - $both_btns = true |
|
2566 | - ) { |
|
2567 | - $this->_set_publish_post_box_vars( |
|
2568 | - $name, |
|
2569 | - $id, |
|
2570 | - $delete, |
|
2571 | - $save_close_redirect_URL, |
|
2572 | - $both_btns |
|
2573 | - ); |
|
2574 | - } |
|
2575 | - |
|
2576 | - |
|
2577 | - /** |
|
2578 | - * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
2579 | - * Note: currently there is no validation for this. However if you want the delete button, the |
|
2580 | - * save, and save and close buttons to work properly, then you will want to include a |
|
2581 | - * values for the name and id arguments. |
|
2582 | - * |
|
2583 | - * @todo Add in validation for name/id arguments. |
|
2584 | - * @param string $name key used for the action ID (i.e. event_id) |
|
2585 | - * @param int $id id attached to the item published |
|
2586 | - * @param string $delete page route callback for the delete action |
|
2587 | - * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
2588 | - * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
2589 | - * the Save button |
|
2590 | - * @throws EE_Error |
|
2591 | - * @throws InvalidArgumentException |
|
2592 | - * @throws InvalidDataTypeException |
|
2593 | - * @throws InvalidInterfaceException |
|
2594 | - */ |
|
2595 | - protected function _set_publish_post_box_vars( |
|
2596 | - $name = '', |
|
2597 | - $id = 0, |
|
2598 | - $delete = '', |
|
2599 | - $save_close_redirect_URL = '', |
|
2600 | - $both_btns = true |
|
2601 | - ) { |
|
2602 | - // if Save & Close, use a custom redirect URL or default to the main page? |
|
2603 | - $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
2604 | - ? $save_close_redirect_URL |
|
2605 | - : $this->_admin_base_url; |
|
2606 | - // create the Save & Close and Save buttons |
|
2607 | - $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL); |
|
2608 | - // if we have extra content set let's add it in if not make sure its empty |
|
2609 | - $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
2610 | - ? $this->_template_args['publish_box_extra_content'] |
|
2611 | - : ''; |
|
2612 | - if ($delete && ! empty($id)) { |
|
2613 | - // make sure we have a default if just true is sent. |
|
2614 | - $delete = ! empty($delete) ? $delete : 'delete'; |
|
2615 | - $delete_link_args = array($name => $id); |
|
2616 | - $delete = $this->get_action_link_or_button( |
|
2617 | - $delete, |
|
2618 | - $delete, |
|
2619 | - $delete_link_args, |
|
2620 | - 'submitdelete deletion', |
|
2621 | - '', |
|
2622 | - false |
|
2623 | - ); |
|
2624 | - } |
|
2625 | - $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
2626 | - if (! empty($name) && ! empty($id)) { |
|
2627 | - $hidden_field_arr[ $name ] = array( |
|
2628 | - 'type' => 'hidden', |
|
2629 | - 'value' => $id, |
|
2630 | - ); |
|
2631 | - $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
2632 | - } else { |
|
2633 | - $hf = ''; |
|
2634 | - } |
|
2635 | - // add hidden field |
|
2636 | - $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
2637 | - ? $hf[ $name ]['field'] |
|
2638 | - : $hf; |
|
2639 | - } |
|
2640 | - |
|
2641 | - |
|
2642 | - /** |
|
2643 | - * displays an error message to ppl who have javascript disabled |
|
2644 | - * |
|
2645 | - * @return void |
|
2646 | - */ |
|
2647 | - private function _display_no_javascript_warning() |
|
2648 | - { |
|
2649 | - ?> |
|
2457 | + } |
|
2458 | + |
|
2459 | + |
|
2460 | + private function _espresso_links_post_box() |
|
2461 | + { |
|
2462 | + // Hiding until we actually have content to put in here... |
|
2463 | + // add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side'); |
|
2464 | + } |
|
2465 | + |
|
2466 | + |
|
2467 | + public function espresso_links_post_box() |
|
2468 | + { |
|
2469 | + // Hiding until we actually have content to put in here... |
|
2470 | + // EEH_Template::display_template( |
|
2471 | + // EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php' |
|
2472 | + // ); |
|
2473 | + } |
|
2474 | + |
|
2475 | + |
|
2476 | + protected function _espresso_sponsors_post_box() |
|
2477 | + { |
|
2478 | + if (apply_filters('FHEE_show_sponsors_meta_box', true)) { |
|
2479 | + add_meta_box( |
|
2480 | + 'espresso_sponsors_post_box', |
|
2481 | + esc_html__('Event Espresso Highlights', 'event_espresso'), |
|
2482 | + array($this, 'espresso_sponsors_post_box'), |
|
2483 | + $this->_wp_page_slug, |
|
2484 | + 'side' |
|
2485 | + ); |
|
2486 | + } |
|
2487 | + } |
|
2488 | + |
|
2489 | + |
|
2490 | + public function espresso_sponsors_post_box() |
|
2491 | + { |
|
2492 | + EEH_Template::display_template( |
|
2493 | + EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
2494 | + ); |
|
2495 | + } |
|
2496 | + |
|
2497 | + |
|
2498 | + private function _publish_post_box() |
|
2499 | + { |
|
2500 | + $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
2501 | + // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
|
2502 | + // then we'll use that for the metabox label. |
|
2503 | + // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
|
2504 | + if (! empty($this->_labels['publishbox'])) { |
|
2505 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
2506 | + : $this->_labels['publishbox']; |
|
2507 | + } else { |
|
2508 | + $box_label = esc_html__('Publish', 'event_espresso'); |
|
2509 | + } |
|
2510 | + $box_label = apply_filters( |
|
2511 | + 'FHEE__EE_Admin_Page___publish_post_box__box_label', |
|
2512 | + $box_label, |
|
2513 | + $this->_req_action, |
|
2514 | + $this |
|
2515 | + ); |
|
2516 | + add_meta_box( |
|
2517 | + $meta_box_ref, |
|
2518 | + $box_label, |
|
2519 | + array($this, 'editor_overview'), |
|
2520 | + $this->_current_screen->id, |
|
2521 | + 'side', |
|
2522 | + 'high' |
|
2523 | + ); |
|
2524 | + } |
|
2525 | + |
|
2526 | + |
|
2527 | + public function editor_overview() |
|
2528 | + { |
|
2529 | + // if we have extra content set let's add it in if not make sure its empty |
|
2530 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
2531 | + ? $this->_template_args['publish_box_extra_content'] |
|
2532 | + : ''; |
|
2533 | + echo EEH_Template::display_template( |
|
2534 | + EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
2535 | + $this->_template_args, |
|
2536 | + true |
|
2537 | + ); |
|
2538 | + } |
|
2539 | + |
|
2540 | + |
|
2541 | + /** end of globally available metaboxes section **/ |
|
2542 | + |
|
2543 | + |
|
2544 | + /** |
|
2545 | + * Public wrapper for the protected method. Allows plugins/addons to externally call the |
|
2546 | + * protected method. |
|
2547 | + * |
|
2548 | + * @see $this->_set_publish_post_box_vars for param details |
|
2549 | + * @since 4.6.0 |
|
2550 | + * @param string $name |
|
2551 | + * @param int $id |
|
2552 | + * @param bool $delete |
|
2553 | + * @param string $save_close_redirect_URL |
|
2554 | + * @param bool $both_btns |
|
2555 | + * @throws EE_Error |
|
2556 | + * @throws InvalidArgumentException |
|
2557 | + * @throws InvalidDataTypeException |
|
2558 | + * @throws InvalidInterfaceException |
|
2559 | + */ |
|
2560 | + public function set_publish_post_box_vars( |
|
2561 | + $name = '', |
|
2562 | + $id = 0, |
|
2563 | + $delete = false, |
|
2564 | + $save_close_redirect_URL = '', |
|
2565 | + $both_btns = true |
|
2566 | + ) { |
|
2567 | + $this->_set_publish_post_box_vars( |
|
2568 | + $name, |
|
2569 | + $id, |
|
2570 | + $delete, |
|
2571 | + $save_close_redirect_URL, |
|
2572 | + $both_btns |
|
2573 | + ); |
|
2574 | + } |
|
2575 | + |
|
2576 | + |
|
2577 | + /** |
|
2578 | + * Sets the _template_args arguments used by the _publish_post_box shortcut |
|
2579 | + * Note: currently there is no validation for this. However if you want the delete button, the |
|
2580 | + * save, and save and close buttons to work properly, then you will want to include a |
|
2581 | + * values for the name and id arguments. |
|
2582 | + * |
|
2583 | + * @todo Add in validation for name/id arguments. |
|
2584 | + * @param string $name key used for the action ID (i.e. event_id) |
|
2585 | + * @param int $id id attached to the item published |
|
2586 | + * @param string $delete page route callback for the delete action |
|
2587 | + * @param string $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed |
|
2588 | + * @param boolean $both_btns whether to display BOTH the "Save & Close" and "Save" buttons or just |
|
2589 | + * the Save button |
|
2590 | + * @throws EE_Error |
|
2591 | + * @throws InvalidArgumentException |
|
2592 | + * @throws InvalidDataTypeException |
|
2593 | + * @throws InvalidInterfaceException |
|
2594 | + */ |
|
2595 | + protected function _set_publish_post_box_vars( |
|
2596 | + $name = '', |
|
2597 | + $id = 0, |
|
2598 | + $delete = '', |
|
2599 | + $save_close_redirect_URL = '', |
|
2600 | + $both_btns = true |
|
2601 | + ) { |
|
2602 | + // if Save & Close, use a custom redirect URL or default to the main page? |
|
2603 | + $save_close_redirect_URL = ! empty($save_close_redirect_URL) |
|
2604 | + ? $save_close_redirect_URL |
|
2605 | + : $this->_admin_base_url; |
|
2606 | + // create the Save & Close and Save buttons |
|
2607 | + $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL); |
|
2608 | + // if we have extra content set let's add it in if not make sure its empty |
|
2609 | + $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content']) |
|
2610 | + ? $this->_template_args['publish_box_extra_content'] |
|
2611 | + : ''; |
|
2612 | + if ($delete && ! empty($id)) { |
|
2613 | + // make sure we have a default if just true is sent. |
|
2614 | + $delete = ! empty($delete) ? $delete : 'delete'; |
|
2615 | + $delete_link_args = array($name => $id); |
|
2616 | + $delete = $this->get_action_link_or_button( |
|
2617 | + $delete, |
|
2618 | + $delete, |
|
2619 | + $delete_link_args, |
|
2620 | + 'submitdelete deletion', |
|
2621 | + '', |
|
2622 | + false |
|
2623 | + ); |
|
2624 | + } |
|
2625 | + $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
|
2626 | + if (! empty($name) && ! empty($id)) { |
|
2627 | + $hidden_field_arr[ $name ] = array( |
|
2628 | + 'type' => 'hidden', |
|
2629 | + 'value' => $id, |
|
2630 | + ); |
|
2631 | + $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array'); |
|
2632 | + } else { |
|
2633 | + $hf = ''; |
|
2634 | + } |
|
2635 | + // add hidden field |
|
2636 | + $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
|
2637 | + ? $hf[ $name ]['field'] |
|
2638 | + : $hf; |
|
2639 | + } |
|
2640 | + |
|
2641 | + |
|
2642 | + /** |
|
2643 | + * displays an error message to ppl who have javascript disabled |
|
2644 | + * |
|
2645 | + * @return void |
|
2646 | + */ |
|
2647 | + private function _display_no_javascript_warning() |
|
2648 | + { |
|
2649 | + ?> |
|
2650 | 2650 | <noscript> |
2651 | 2651 | <div id="no-js-message" class="error"> |
2652 | 2652 | <p style="font-size:1.3em;"> |
2653 | 2653 | <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span> |
2654 | 2654 | <?php esc_html_e( |
2655 | - 'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.', |
|
2656 | - 'event_espresso' |
|
2657 | - ); ?> |
|
2655 | + 'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.', |
|
2656 | + 'event_espresso' |
|
2657 | + ); ?> |
|
2658 | 2658 | </p> |
2659 | 2659 | </div> |
2660 | 2660 | </noscript> |
2661 | 2661 | <?php |
2662 | - } |
|
2663 | - |
|
2664 | - |
|
2665 | - /** |
|
2666 | - * displays espresso success and/or error notices |
|
2667 | - * |
|
2668 | - * @return void |
|
2669 | - */ |
|
2670 | - private function _display_espresso_notices() |
|
2671 | - { |
|
2672 | - $notices = $this->_get_transient(true); |
|
2673 | - echo stripslashes($notices); |
|
2674 | - } |
|
2675 | - |
|
2676 | - |
|
2677 | - /** |
|
2678 | - * spinny things pacify the masses |
|
2679 | - * |
|
2680 | - * @return void |
|
2681 | - */ |
|
2682 | - protected function _add_admin_page_ajax_loading_img() |
|
2683 | - { |
|
2684 | - ?> |
|
2662 | + } |
|
2663 | + |
|
2664 | + |
|
2665 | + /** |
|
2666 | + * displays espresso success and/or error notices |
|
2667 | + * |
|
2668 | + * @return void |
|
2669 | + */ |
|
2670 | + private function _display_espresso_notices() |
|
2671 | + { |
|
2672 | + $notices = $this->_get_transient(true); |
|
2673 | + echo stripslashes($notices); |
|
2674 | + } |
|
2675 | + |
|
2676 | + |
|
2677 | + /** |
|
2678 | + * spinny things pacify the masses |
|
2679 | + * |
|
2680 | + * @return void |
|
2681 | + */ |
|
2682 | + protected function _add_admin_page_ajax_loading_img() |
|
2683 | + { |
|
2684 | + ?> |
|
2685 | 2685 | <div id="espresso-ajax-loading" class="ajax-loading-grey"> |
2686 | 2686 | <span class="ee-spinner ee-spin"></span><span class="hidden"><?php |
2687 | - esc_html_e('loading...', 'event_espresso'); ?></span> |
|
2687 | + esc_html_e('loading...', 'event_espresso'); ?></span> |
|
2688 | 2688 | </div> |
2689 | 2689 | <?php |
2690 | - } |
|
2690 | + } |
|
2691 | 2691 | |
2692 | 2692 | |
2693 | - /** |
|
2694 | - * add admin page overlay for modal boxes |
|
2695 | - * |
|
2696 | - * @return void |
|
2697 | - */ |
|
2698 | - protected function _add_admin_page_overlay() |
|
2699 | - { |
|
2700 | - ?> |
|
2693 | + /** |
|
2694 | + * add admin page overlay for modal boxes |
|
2695 | + * |
|
2696 | + * @return void |
|
2697 | + */ |
|
2698 | + protected function _add_admin_page_overlay() |
|
2699 | + { |
|
2700 | + ?> |
|
2701 | 2701 | <div id="espresso-admin-page-overlay-dv" class=""></div> |
2702 | 2702 | <?php |
2703 | - } |
|
2704 | - |
|
2705 | - |
|
2706 | - /** |
|
2707 | - * facade for add_meta_box |
|
2708 | - * |
|
2709 | - * @param string $action where the metabox get's displayed |
|
2710 | - * @param string $title Title of Metabox (output in metabox header) |
|
2711 | - * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
2712 | - * instead of the one created in here. |
|
2713 | - * @param array $callback_args an array of args supplied for the metabox |
|
2714 | - * @param string $column what metabox column |
|
2715 | - * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
2716 | - * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
2717 | - * created but just set our own callback for wp's add_meta_box. |
|
2718 | - * @throws \DomainException |
|
2719 | - */ |
|
2720 | - public function _add_admin_page_meta_box( |
|
2721 | - $action, |
|
2722 | - $title, |
|
2723 | - $callback, |
|
2724 | - $callback_args, |
|
2725 | - $column = 'normal', |
|
2726 | - $priority = 'high', |
|
2727 | - $create_func = true |
|
2728 | - ) { |
|
2729 | - do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
2730 | - // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
2731 | - if (empty($callback_args) && $create_func) { |
|
2732 | - $callback_args = array( |
|
2733 | - 'template_path' => $this->_template_path, |
|
2734 | - 'template_args' => $this->_template_args, |
|
2735 | - ); |
|
2736 | - } |
|
2737 | - // if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
2738 | - $call_back_func = $create_func |
|
2739 | - ? function ($post, $metabox) { |
|
2740 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2741 | - echo EEH_Template::display_template( |
|
2742 | - $metabox['args']['template_path'], |
|
2743 | - $metabox['args']['template_args'], |
|
2744 | - true |
|
2745 | - ); |
|
2746 | - } |
|
2747 | - : $callback; |
|
2748 | - add_meta_box( |
|
2749 | - str_replace('_', '-', $action) . '-mbox', |
|
2750 | - $title, |
|
2751 | - $call_back_func, |
|
2752 | - $this->_wp_page_slug, |
|
2753 | - $column, |
|
2754 | - $priority, |
|
2755 | - $callback_args |
|
2756 | - ); |
|
2757 | - } |
|
2758 | - |
|
2759 | - |
|
2760 | - /** |
|
2761 | - * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
2762 | - * |
|
2763 | - * @throws DomainException |
|
2764 | - * @throws EE_Error |
|
2765 | - */ |
|
2766 | - public function display_admin_page_with_metabox_columns() |
|
2767 | - { |
|
2768 | - $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
2769 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
2770 | - $this->_column_template_path, |
|
2771 | - $this->_template_args, |
|
2772 | - true |
|
2773 | - ); |
|
2774 | - // the final wrapper |
|
2775 | - $this->admin_page_wrapper(); |
|
2776 | - } |
|
2777 | - |
|
2778 | - |
|
2779 | - /** |
|
2780 | - * generates HTML wrapper for an admin details page |
|
2781 | - * |
|
2782 | - * @return void |
|
2783 | - * @throws EE_Error |
|
2784 | - * @throws DomainException |
|
2785 | - */ |
|
2786 | - public function display_admin_page_with_sidebar() |
|
2787 | - { |
|
2788 | - $this->_display_admin_page(true); |
|
2789 | - } |
|
2790 | - |
|
2791 | - |
|
2792 | - /** |
|
2793 | - * generates HTML wrapper for an admin details page (except no sidebar) |
|
2794 | - * |
|
2795 | - * @return void |
|
2796 | - * @throws EE_Error |
|
2797 | - * @throws DomainException |
|
2798 | - */ |
|
2799 | - public function display_admin_page_with_no_sidebar() |
|
2800 | - { |
|
2801 | - $this->_display_admin_page(); |
|
2802 | - } |
|
2803 | - |
|
2804 | - |
|
2805 | - /** |
|
2806 | - * generates HTML wrapper for an EE about admin page (no sidebar) |
|
2807 | - * |
|
2808 | - * @return void |
|
2809 | - * @throws EE_Error |
|
2810 | - * @throws DomainException |
|
2811 | - */ |
|
2812 | - public function display_about_admin_page() |
|
2813 | - { |
|
2814 | - $this->_display_admin_page(false, true); |
|
2815 | - } |
|
2816 | - |
|
2817 | - |
|
2818 | - /** |
|
2819 | - * display_admin_page |
|
2820 | - * contains the code for actually displaying an admin page |
|
2821 | - * |
|
2822 | - * @param boolean $sidebar true with sidebar, false without |
|
2823 | - * @param boolean $about use the about admin wrapper instead of the default. |
|
2824 | - * @return void |
|
2825 | - * @throws DomainException |
|
2826 | - * @throws EE_Error |
|
2827 | - */ |
|
2828 | - private function _display_admin_page($sidebar = false, $about = false) |
|
2829 | - { |
|
2830 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2831 | - // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
2832 | - do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
2833 | - // set current wp page slug - looks like: event-espresso_page_event_categories |
|
2834 | - // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
2835 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
2836 | - $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
2837 | - ? 'poststuff' |
|
2838 | - : 'espresso-default-admin'; |
|
2839 | - $template_path = $sidebar |
|
2840 | - ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
2841 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
2842 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
2843 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
2844 | - } |
|
2845 | - $template_path = ! empty($this->_column_template_path) |
|
2846 | - ? $this->_column_template_path : $template_path; |
|
2847 | - $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) |
|
2848 | - ? $this->_template_args['admin_page_content'] |
|
2849 | - : ''; |
|
2850 | - $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) |
|
2851 | - ? $this->_template_args['before_admin_page_content'] |
|
2852 | - : ''; |
|
2853 | - $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) |
|
2854 | - ? $this->_template_args['after_admin_page_content'] |
|
2855 | - : ''; |
|
2856 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
2857 | - $template_path, |
|
2858 | - $this->_template_args, |
|
2859 | - true |
|
2860 | - ); |
|
2861 | - // the final template wrapper |
|
2862 | - $this->admin_page_wrapper($about); |
|
2863 | - } |
|
2864 | - |
|
2865 | - |
|
2866 | - /** |
|
2867 | - * This is used to display caf preview pages. |
|
2868 | - * |
|
2869 | - * @since 4.3.2 |
|
2870 | - * @param string $utm_campaign_source what is the key used for google analytics link |
|
2871 | - * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
2872 | - * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
2873 | - * @return void |
|
2874 | - * @throws DomainException |
|
2875 | - * @throws EE_Error |
|
2876 | - * @throws InvalidArgumentException |
|
2877 | - * @throws InvalidDataTypeException |
|
2878 | - * @throws InvalidInterfaceException |
|
2879 | - */ |
|
2880 | - public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
2881 | - { |
|
2882 | - // let's generate a default preview action button if there isn't one already present. |
|
2883 | - $this->_labels['buttons']['buy_now'] = esc_html__( |
|
2884 | - 'Upgrade to Event Espresso 4 Right Now', |
|
2885 | - 'event_espresso' |
|
2886 | - ); |
|
2887 | - $buy_now_url = add_query_arg( |
|
2888 | - array( |
|
2889 | - 'ee_ver' => 'ee4', |
|
2890 | - 'utm_source' => 'ee4_plugin_admin', |
|
2891 | - 'utm_medium' => 'link', |
|
2892 | - 'utm_campaign' => $utm_campaign_source, |
|
2893 | - 'utm_content' => 'buy_now_button', |
|
2894 | - ), |
|
2895 | - 'http://eventespresso.com/pricing/' |
|
2896 | - ); |
|
2897 | - $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
2898 | - ? $this->get_action_link_or_button( |
|
2899 | - '', |
|
2900 | - 'buy_now', |
|
2901 | - array(), |
|
2902 | - 'button-primary button-large', |
|
2903 | - $buy_now_url, |
|
2904 | - true |
|
2905 | - ) |
|
2906 | - : $this->_template_args['preview_action_button']; |
|
2907 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
2908 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
2909 | - $this->_template_args, |
|
2910 | - true |
|
2911 | - ); |
|
2912 | - $this->_display_admin_page($display_sidebar); |
|
2913 | - } |
|
2914 | - |
|
2915 | - |
|
2916 | - /** |
|
2917 | - * display_admin_list_table_page_with_sidebar |
|
2918 | - * generates HTML wrapper for an admin_page with list_table |
|
2919 | - * |
|
2920 | - * @return void |
|
2921 | - * @throws EE_Error |
|
2922 | - * @throws DomainException |
|
2923 | - */ |
|
2924 | - public function display_admin_list_table_page_with_sidebar() |
|
2925 | - { |
|
2926 | - $this->_display_admin_list_table_page(true); |
|
2927 | - } |
|
2928 | - |
|
2929 | - |
|
2930 | - /** |
|
2931 | - * display_admin_list_table_page_with_no_sidebar |
|
2932 | - * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
2933 | - * |
|
2934 | - * @return void |
|
2935 | - * @throws EE_Error |
|
2936 | - * @throws DomainException |
|
2937 | - */ |
|
2938 | - public function display_admin_list_table_page_with_no_sidebar() |
|
2939 | - { |
|
2940 | - $this->_display_admin_list_table_page(); |
|
2941 | - } |
|
2942 | - |
|
2943 | - |
|
2944 | - /** |
|
2945 | - * generates html wrapper for an admin_list_table page |
|
2946 | - * |
|
2947 | - * @param boolean $sidebar whether to display with sidebar or not. |
|
2948 | - * @return void |
|
2949 | - * @throws DomainException |
|
2950 | - * @throws EE_Error |
|
2951 | - */ |
|
2952 | - private function _display_admin_list_table_page($sidebar = false) |
|
2953 | - { |
|
2954 | - // setup search attributes |
|
2955 | - $this->_set_search_attributes(); |
|
2956 | - $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
2957 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
2958 | - $this->_template_args['table_url'] = defined('DOING_AJAX') |
|
2959 | - ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
|
2960 | - : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
|
2961 | - $this->_template_args['list_table'] = $this->_list_table_object; |
|
2962 | - $this->_template_args['current_route'] = $this->_req_action; |
|
2963 | - $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
2964 | - $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
2965 | - if (! empty($ajax_sorting_callback)) { |
|
2966 | - $sortable_list_table_form_fields = wp_nonce_field( |
|
2967 | - $ajax_sorting_callback . '_nonce', |
|
2968 | - $ajax_sorting_callback . '_nonce', |
|
2969 | - false, |
|
2970 | - false |
|
2971 | - ); |
|
2972 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
2973 | - . $this->page_slug |
|
2974 | - . '" />'; |
|
2975 | - $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
2976 | - . $ajax_sorting_callback |
|
2977 | - . '" />'; |
|
2978 | - } else { |
|
2979 | - $sortable_list_table_form_fields = ''; |
|
2980 | - } |
|
2981 | - $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
2982 | - $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) |
|
2983 | - ? $this->_template_args['list_table_hidden_fields'] |
|
2984 | - : ''; |
|
2985 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
2986 | - $hidden_form_fields .= '<input type="hidden" name="' |
|
2987 | - . $nonce_ref |
|
2988 | - . '" value="' |
|
2989 | - . wp_create_nonce($nonce_ref) |
|
2990 | - . '">'; |
|
2991 | - $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
2992 | - // display message about search results? |
|
2993 | - $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
|
2994 | - ? '<p class="ee-search-results">' . sprintf( |
|
2995 | - esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
2996 | - trim($this->_req_data['s'], '%') |
|
2997 | - ) . '</p>' |
|
2998 | - : ''; |
|
2999 | - // filter before_list_table template arg |
|
3000 | - $this->_template_args['before_list_table'] = apply_filters( |
|
3001 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
3002 | - $this->_template_args['before_list_table'], |
|
3003 | - $this->page_slug, |
|
3004 | - $this->_req_data, |
|
3005 | - $this->_req_action |
|
3006 | - ); |
|
3007 | - // convert to array and filter again |
|
3008 | - // arrays are easier to inject new items in a specific location, |
|
3009 | - // but would not be backwards compatible, so we have to add a new filter |
|
3010 | - $this->_template_args['before_list_table'] = implode( |
|
3011 | - " \n", |
|
3012 | - (array) apply_filters( |
|
3013 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
3014 | - (array) $this->_template_args['before_list_table'], |
|
3015 | - $this->page_slug, |
|
3016 | - $this->_req_data, |
|
3017 | - $this->_req_action |
|
3018 | - ) |
|
3019 | - ); |
|
3020 | - // filter after_list_table template arg |
|
3021 | - $this->_template_args['after_list_table'] = apply_filters( |
|
3022 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
3023 | - $this->_template_args['after_list_table'], |
|
3024 | - $this->page_slug, |
|
3025 | - $this->_req_data, |
|
3026 | - $this->_req_action |
|
3027 | - ); |
|
3028 | - // convert to array and filter again |
|
3029 | - // arrays are easier to inject new items in a specific location, |
|
3030 | - // but would not be backwards compatible, so we have to add a new filter |
|
3031 | - $this->_template_args['after_list_table'] = implode( |
|
3032 | - " \n", |
|
3033 | - (array) apply_filters( |
|
3034 | - 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
3035 | - (array) $this->_template_args['after_list_table'], |
|
3036 | - $this->page_slug, |
|
3037 | - $this->_req_data, |
|
3038 | - $this->_req_action |
|
3039 | - ) |
|
3040 | - ); |
|
3041 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
3042 | - $template_path, |
|
3043 | - $this->_template_args, |
|
3044 | - true |
|
3045 | - ); |
|
3046 | - // the final template wrapper |
|
3047 | - if ($sidebar) { |
|
3048 | - $this->display_admin_page_with_sidebar(); |
|
3049 | - } else { |
|
3050 | - $this->display_admin_page_with_no_sidebar(); |
|
3051 | - } |
|
3052 | - } |
|
3053 | - |
|
3054 | - |
|
3055 | - /** |
|
3056 | - * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
3057 | - * html string for the legend. |
|
3058 | - * $items are expected in an array in the following format: |
|
3059 | - * $legend_items = array( |
|
3060 | - * 'item_id' => array( |
|
3061 | - * 'icon' => 'http://url_to_icon_being_described.png', |
|
3062 | - * 'desc' => esc_html__('localized description of item'); |
|
3063 | - * ) |
|
3064 | - * ); |
|
3065 | - * |
|
3066 | - * @param array $items see above for format of array |
|
3067 | - * @return string html string of legend |
|
3068 | - * @throws DomainException |
|
3069 | - */ |
|
3070 | - protected function _display_legend($items) |
|
3071 | - { |
|
3072 | - $this->_template_args['items'] = apply_filters( |
|
3073 | - 'FHEE__EE_Admin_Page___display_legend__items', |
|
3074 | - (array) $items, |
|
3075 | - $this |
|
3076 | - ); |
|
3077 | - return EEH_Template::display_template( |
|
3078 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
3079 | - $this->_template_args, |
|
3080 | - true |
|
3081 | - ); |
|
3082 | - } |
|
3083 | - |
|
3084 | - |
|
3085 | - /** |
|
3086 | - * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
3087 | - * The returned json object is created from an array in the following format: |
|
3088 | - * array( |
|
3089 | - * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
3090 | - * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
3091 | - * 'notices' => '', // - contains any EE_Error formatted notices |
|
3092 | - * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
3093 | - * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
3094 | - * We're also going to include the template args with every package (so js can pick out any specific template args |
|
3095 | - * that might be included in here) |
|
3096 | - * ) |
|
3097 | - * The json object is populated by whatever is set in the $_template_args property. |
|
3098 | - * |
|
3099 | - * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
3100 | - * instead of displayed. |
|
3101 | - * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
3102 | - * @return void |
|
3103 | - * @throws EE_Error |
|
3104 | - */ |
|
3105 | - protected function _return_json($sticky_notices = false, $notices_arguments = array()) |
|
3106 | - { |
|
3107 | - // make sure any EE_Error notices have been handled. |
|
3108 | - $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
3109 | - $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array(); |
|
3110 | - unset($this->_template_args['data']); |
|
3111 | - $json = array( |
|
3112 | - 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
3113 | - 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
3114 | - 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
3115 | - 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
3116 | - 'notices' => EE_Error::get_notices(), |
|
3117 | - 'content' => isset($this->_template_args['admin_page_content']) |
|
3118 | - ? $this->_template_args['admin_page_content'] : '', |
|
3119 | - 'data' => array_merge($data, array('template_args' => $this->_template_args)), |
|
3120 | - 'isEEajax' => true |
|
3121 | - // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
3122 | - ); |
|
3123 | - // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
3124 | - if (null === error_get_last() || ! headers_sent()) { |
|
3125 | - header('Content-Type: application/json; charset=UTF-8'); |
|
3126 | - } |
|
3127 | - echo wp_json_encode($json); |
|
3128 | - exit(); |
|
3129 | - } |
|
3130 | - |
|
3131 | - |
|
3132 | - /** |
|
3133 | - * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
3134 | - * |
|
3135 | - * @return void |
|
3136 | - * @throws EE_Error |
|
3137 | - */ |
|
3138 | - public function return_json() |
|
3139 | - { |
|
3140 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
3141 | - $this->_return_json(); |
|
3142 | - } else { |
|
3143 | - throw new EE_Error( |
|
3144 | - sprintf( |
|
3145 | - esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
3146 | - __FUNCTION__ |
|
3147 | - ) |
|
3148 | - ); |
|
3149 | - } |
|
3150 | - } |
|
3151 | - |
|
3152 | - |
|
3153 | - /** |
|
3154 | - * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
3155 | - * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
3156 | - * |
|
3157 | - * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
3158 | - */ |
|
3159 | - public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
3160 | - { |
|
3161 | - $this->_hook_obj = $hook_obj; |
|
3162 | - } |
|
3163 | - |
|
3164 | - |
|
3165 | - /** |
|
3166 | - * generates HTML wrapper with Tabbed nav for an admin page |
|
3167 | - * |
|
3168 | - * @param boolean $about whether to use the special about page wrapper or default. |
|
3169 | - * @return void |
|
3170 | - * @throws DomainException |
|
3171 | - * @throws EE_Error |
|
3172 | - */ |
|
3173 | - public function admin_page_wrapper($about = false) |
|
3174 | - { |
|
3175 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
3176 | - $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
3177 | - $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
3178 | - $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
3179 | - $this->_template_args['before_admin_page_content'] = apply_filters( |
|
3180 | - "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
3181 | - isset($this->_template_args['before_admin_page_content']) |
|
3182 | - ? $this->_template_args['before_admin_page_content'] |
|
3183 | - : '' |
|
3184 | - ); |
|
3185 | - $this->_template_args['after_admin_page_content'] = apply_filters( |
|
3186 | - "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
3187 | - isset($this->_template_args['after_admin_page_content']) |
|
3188 | - ? $this->_template_args['after_admin_page_content'] |
|
3189 | - : '' |
|
3190 | - ); |
|
3191 | - $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
3192 | - // load settings page wrapper template |
|
3193 | - $template_path = ! defined('DOING_AJAX') |
|
3194 | - ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' |
|
3195 | - : EE_ADMIN_TEMPLATE |
|
3196 | - . 'admin_wrapper_ajax.template.php'; |
|
3197 | - // about page? |
|
3198 | - $template_path = $about |
|
3199 | - ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
3200 | - : $template_path; |
|
3201 | - if (defined('DOING_AJAX')) { |
|
3202 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
3203 | - $template_path, |
|
3204 | - $this->_template_args, |
|
3205 | - true |
|
3206 | - ); |
|
3207 | - $this->_return_json(); |
|
3208 | - } else { |
|
3209 | - EEH_Template::display_template($template_path, $this->_template_args); |
|
3210 | - } |
|
3211 | - } |
|
3212 | - |
|
3213 | - |
|
3214 | - /** |
|
3215 | - * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
3216 | - * |
|
3217 | - * @return string html |
|
3218 | - * @throws EE_Error |
|
3219 | - */ |
|
3220 | - protected function _get_main_nav_tabs() |
|
3221 | - { |
|
3222 | - // let's generate the html using the EEH_Tabbed_Content helper. |
|
3223 | - // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
3224 | - // (rather than setting in the page_routes array) |
|
3225 | - return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
3226 | - } |
|
3227 | - |
|
3228 | - |
|
3229 | - /** |
|
3230 | - * sort nav tabs |
|
3231 | - * |
|
3232 | - * @param $a |
|
3233 | - * @param $b |
|
3234 | - * @return int |
|
3235 | - */ |
|
3236 | - private function _sort_nav_tabs($a, $b) |
|
3237 | - { |
|
3238 | - if ($a['order'] === $b['order']) { |
|
3239 | - return 0; |
|
3240 | - } |
|
3241 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
3242 | - } |
|
3243 | - |
|
3244 | - |
|
3245 | - /** |
|
3246 | - * generates HTML for the forms used on admin pages |
|
3247 | - * |
|
3248 | - * @param array $input_vars - array of input field details |
|
3249 | - * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to |
|
3250 | - * use) |
|
3251 | - * @param bool $id |
|
3252 | - * @return string |
|
3253 | - * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
3254 | - * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
3255 | - */ |
|
3256 | - protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false) |
|
3257 | - { |
|
3258 | - $content = $generator === 'string' |
|
3259 | - ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
3260 | - : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
3261 | - return $content; |
|
3262 | - } |
|
3263 | - |
|
3264 | - |
|
3265 | - /** |
|
3266 | - * generates the "Save" and "Save & Close" buttons for edit forms |
|
3267 | - * |
|
3268 | - * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
3269 | - * Close" button. |
|
3270 | - * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
3271 | - * 'Save', [1] => 'save & close') |
|
3272 | - * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
3273 | - * via the "name" value in the button). We can also use this to just dump |
|
3274 | - * default actions by submitting some other value. |
|
3275 | - * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
3276 | - * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
3277 | - * close (normal form handling). |
|
3278 | - */ |
|
3279 | - protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
|
3280 | - { |
|
3281 | - // make sure $text and $actions are in an array |
|
3282 | - $text = (array) $text; |
|
3283 | - $actions = (array) $actions; |
|
3284 | - $referrer_url = empty($referrer) |
|
3285 | - ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
3286 | - . $_SERVER['REQUEST_URI'] |
|
3287 | - . '" />' |
|
3288 | - : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
3289 | - . $referrer |
|
3290 | - . '" />'; |
|
3291 | - $button_text = ! empty($text) |
|
3292 | - ? $text |
|
3293 | - : array( |
|
3294 | - esc_html__('Save', 'event_espresso'), |
|
3295 | - esc_html__('Save and Close', 'event_espresso'), |
|
3296 | - ); |
|
3297 | - $default_names = array('save', 'save_and_close'); |
|
3298 | - // add in a hidden index for the current page (so save and close redirects properly) |
|
3299 | - $this->_template_args['save_buttons'] = $referrer_url; |
|
3300 | - foreach ($button_text as $key => $button) { |
|
3301 | - $ref = $default_names[ $key ]; |
|
3302 | - $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' |
|
3303 | - . $ref |
|
3304 | - . '" value="' |
|
3305 | - . $button |
|
3306 | - . '" name="' |
|
3307 | - . (! empty($actions) ? $actions[ $key ] : $ref) |
|
3308 | - . '" id="' |
|
3309 | - . $this->_current_view . '_' . $ref |
|
3310 | - . '" />'; |
|
3311 | - if (! $both) { |
|
3312 | - break; |
|
3313 | - } |
|
3314 | - } |
|
3315 | - } |
|
3316 | - |
|
3317 | - |
|
3318 | - /** |
|
3319 | - * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
3320 | - * |
|
3321 | - * @see $this->_set_add_edit_form_tags() for details on params |
|
3322 | - * @since 4.6.0 |
|
3323 | - * @param string $route |
|
3324 | - * @param array $additional_hidden_fields |
|
3325 | - */ |
|
3326 | - public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
3327 | - { |
|
3328 | - $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
3329 | - } |
|
3330 | - |
|
3331 | - |
|
3332 | - /** |
|
3333 | - * set form open and close tags on add/edit pages. |
|
3334 | - * |
|
3335 | - * @param string $route the route you want the form to direct to |
|
3336 | - * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
3337 | - * @return void |
|
3338 | - */ |
|
3339 | - protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
3340 | - { |
|
3341 | - if (empty($route)) { |
|
3342 | - $user_msg = esc_html__( |
|
3343 | - 'An error occurred. No action was set for this page\'s form.', |
|
3344 | - 'event_espresso' |
|
3345 | - ); |
|
3346 | - $dev_msg = $user_msg . "\n" |
|
3347 | - . sprintf( |
|
3348 | - esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
3349 | - __FUNCTION__, |
|
3350 | - __CLASS__ |
|
3351 | - ); |
|
3352 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
3353 | - } |
|
3354 | - // open form |
|
3355 | - $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
|
3356 | - . $this->_admin_base_url |
|
3357 | - . '" id="' |
|
3358 | - . $route |
|
3359 | - . '_event_form" >'; |
|
3360 | - // add nonce |
|
3361 | - $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
3362 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
3363 | - // add REQUIRED form action |
|
3364 | - $hidden_fields = array( |
|
3365 | - 'action' => array('type' => 'hidden', 'value' => $route), |
|
3366 | - ); |
|
3367 | - // merge arrays |
|
3368 | - $hidden_fields = is_array($additional_hidden_fields) |
|
3369 | - ? array_merge($hidden_fields, $additional_hidden_fields) |
|
3370 | - : $hidden_fields; |
|
3371 | - // generate form fields |
|
3372 | - $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
3373 | - // add fields to form |
|
3374 | - foreach ((array) $form_fields as $field_name => $form_field) { |
|
3375 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
3376 | - } |
|
3377 | - // close form |
|
3378 | - $this->_template_args['after_admin_page_content'] = '</form>'; |
|
3379 | - } |
|
3380 | - |
|
3381 | - |
|
3382 | - /** |
|
3383 | - * Public Wrapper for _redirect_after_action() method since its |
|
3384 | - * discovered it would be useful for external code to have access. |
|
3385 | - * |
|
3386 | - * @see EE_Admin_Page::_redirect_after_action() for params. |
|
3387 | - * @since 4.5.0 |
|
3388 | - * @param bool $success |
|
3389 | - * @param string $what |
|
3390 | - * @param string $action_desc |
|
3391 | - * @param array $query_args |
|
3392 | - * @param bool $override_overwrite |
|
3393 | - * @throws EE_Error |
|
3394 | - */ |
|
3395 | - public function redirect_after_action( |
|
3396 | - $success = false, |
|
3397 | - $what = 'item', |
|
3398 | - $action_desc = 'processed', |
|
3399 | - $query_args = array(), |
|
3400 | - $override_overwrite = false |
|
3401 | - ) { |
|
3402 | - $this->_redirect_after_action( |
|
3403 | - $success, |
|
3404 | - $what, |
|
3405 | - $action_desc, |
|
3406 | - $query_args, |
|
3407 | - $override_overwrite |
|
3408 | - ); |
|
3409 | - } |
|
3410 | - |
|
3411 | - |
|
3412 | - /** |
|
3413 | - * Helper method for merging existing request data with the returned redirect url. |
|
3414 | - * |
|
3415 | - * This is typically used for redirects after an action so that if the original view was a filtered view those |
|
3416 | - * filters are still applied. |
|
3417 | - * |
|
3418 | - * @param array $new_route_data |
|
3419 | - * @return array |
|
3420 | - */ |
|
3421 | - protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data) |
|
3422 | - { |
|
3423 | - foreach ($this->_req_data as $ref => $value) { |
|
3424 | - // unset nonces |
|
3425 | - if (strpos($ref, 'nonce') !== false) { |
|
3426 | - unset($this->_req_data[ $ref ]); |
|
3427 | - continue; |
|
3428 | - } |
|
3429 | - // urlencode values. |
|
3430 | - $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
3431 | - $this->_req_data[ $ref ] = $value; |
|
3432 | - } |
|
3433 | - return array_merge($this->_req_data, $new_route_data); |
|
3434 | - } |
|
3435 | - |
|
3436 | - |
|
3437 | - /** |
|
3438 | - * _redirect_after_action |
|
3439 | - * |
|
3440 | - * @param int $success - whether success was for two or more records, or just one, or none |
|
3441 | - * @param string $what - what the action was performed on |
|
3442 | - * @param string $action_desc - what was done ie: updated, deleted, etc |
|
3443 | - * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
3444 | - * action is completed |
|
3445 | - * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
3446 | - * override this so that they show. |
|
3447 | - * @return void |
|
3448 | - * @throws EE_Error |
|
3449 | - */ |
|
3450 | - protected function _redirect_after_action( |
|
3451 | - $success = 0, |
|
3452 | - $what = 'item', |
|
3453 | - $action_desc = 'processed', |
|
3454 | - $query_args = array(), |
|
3455 | - $override_overwrite = false |
|
3456 | - ) { |
|
3457 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
3458 | - // class name for actions/filters. |
|
3459 | - $classname = get_class($this); |
|
3460 | - // set redirect url. |
|
3461 | - // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
3462 | - // otherwise we go with whatever is set as the _admin_base_url |
|
3463 | - $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
3464 | - $notices = EE_Error::get_notices(false); |
|
3465 | - // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
3466 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
3467 | - EE_Error::overwrite_success(); |
|
3468 | - } |
|
3469 | - if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
3470 | - // how many records affected ? more than one record ? or just one ? |
|
3471 | - if ($success > 1) { |
|
3472 | - // set plural msg |
|
3473 | - EE_Error::add_success( |
|
3474 | - sprintf( |
|
3475 | - esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
3476 | - $what, |
|
3477 | - $action_desc |
|
3478 | - ), |
|
3479 | - __FILE__, |
|
3480 | - __FUNCTION__, |
|
3481 | - __LINE__ |
|
3482 | - ); |
|
3483 | - } elseif ($success === 1) { |
|
3484 | - // set singular msg |
|
3485 | - EE_Error::add_success( |
|
3486 | - sprintf( |
|
3487 | - esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
3488 | - $what, |
|
3489 | - $action_desc |
|
3490 | - ), |
|
3491 | - __FILE__, |
|
3492 | - __FUNCTION__, |
|
3493 | - __LINE__ |
|
3494 | - ); |
|
3495 | - } |
|
3496 | - } |
|
3497 | - // check that $query_args isn't something crazy |
|
3498 | - if (! is_array($query_args)) { |
|
3499 | - $query_args = array(); |
|
3500 | - } |
|
3501 | - /** |
|
3502 | - * Allow injecting actions before the query_args are modified for possible different |
|
3503 | - * redirections on save and close actions |
|
3504 | - * |
|
3505 | - * @since 4.2.0 |
|
3506 | - * @param array $query_args The original query_args array coming into the |
|
3507 | - * method. |
|
3508 | - */ |
|
3509 | - do_action( |
|
3510 | - "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
3511 | - $query_args |
|
3512 | - ); |
|
3513 | - // calculate where we're going (if we have a "save and close" button pushed) |
|
3514 | - if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) { |
|
3515 | - // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
3516 | - $parsed_url = parse_url($this->_req_data['save_and_close_referrer']); |
|
3517 | - // regenerate query args array from referrer URL |
|
3518 | - parse_str($parsed_url['query'], $query_args); |
|
3519 | - // correct page and action will be in the query args now |
|
3520 | - $redirect_url = admin_url('admin.php'); |
|
3521 | - } |
|
3522 | - // merge any default query_args set in _default_route_query_args property |
|
3523 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
3524 | - $args_to_merge = array(); |
|
3525 | - foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
3526 | - // is there a wp_referer array in our _default_route_query_args property? |
|
3527 | - if ($query_param === 'wp_referer') { |
|
3528 | - $query_value = (array) $query_value; |
|
3529 | - foreach ($query_value as $reference => $value) { |
|
3530 | - if (strpos($reference, 'nonce') !== false) { |
|
3531 | - continue; |
|
3532 | - } |
|
3533 | - // finally we will override any arguments in the referer with |
|
3534 | - // what might be set on the _default_route_query_args array. |
|
3535 | - if (isset($this->_default_route_query_args[ $reference ])) { |
|
3536 | - $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
3537 | - } else { |
|
3538 | - $args_to_merge[ $reference ] = urlencode($value); |
|
3539 | - } |
|
3540 | - } |
|
3541 | - continue; |
|
3542 | - } |
|
3543 | - $args_to_merge[ $query_param ] = $query_value; |
|
3544 | - } |
|
3545 | - // now let's merge these arguments but override with what was specifically sent in to the |
|
3546 | - // redirect. |
|
3547 | - $query_args = array_merge($args_to_merge, $query_args); |
|
3548 | - } |
|
3549 | - $this->_process_notices($query_args); |
|
3550 | - // generate redirect url |
|
3551 | - // if redirecting to anything other than the main page, add a nonce |
|
3552 | - if (isset($query_args['action'])) { |
|
3553 | - // manually generate wp_nonce and merge that with the query vars |
|
3554 | - // becuz the wp_nonce_url function wrecks havoc on some vars |
|
3555 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
3556 | - } |
|
3557 | - // we're adding some hooks and filters in here for processing any things just before redirects |
|
3558 | - // (example: an admin page has done an insert or update and we want to run something after that). |
|
3559 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
3560 | - $redirect_url = apply_filters( |
|
3561 | - 'FHEE_redirect_' . $classname . $this->_req_action, |
|
3562 | - self::add_query_args_and_nonce($query_args, $redirect_url), |
|
3563 | - $query_args |
|
3564 | - ); |
|
3565 | - // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
3566 | - if (defined('DOING_AJAX')) { |
|
3567 | - $default_data = array( |
|
3568 | - 'close' => true, |
|
3569 | - 'redirect_url' => $redirect_url, |
|
3570 | - 'where' => 'main', |
|
3571 | - 'what' => 'append', |
|
3572 | - ); |
|
3573 | - $this->_template_args['success'] = $success; |
|
3574 | - $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
3575 | - $default_data, |
|
3576 | - $this->_template_args['data'] |
|
3577 | - ) : $default_data; |
|
3578 | - $this->_return_json(); |
|
3579 | - } |
|
3580 | - wp_safe_redirect($redirect_url); |
|
3581 | - exit(); |
|
3582 | - } |
|
3583 | - |
|
3584 | - |
|
3585 | - /** |
|
3586 | - * process any notices before redirecting (or returning ajax request) |
|
3587 | - * This method sets the $this->_template_args['notices'] attribute; |
|
3588 | - * |
|
3589 | - * @param array $query_args any query args that need to be used for notice transient ('action') |
|
3590 | - * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
3591 | - * page_routes haven't been defined yet. |
|
3592 | - * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
3593 | - * still save a transient for the notice. |
|
3594 | - * @return void |
|
3595 | - * @throws EE_Error |
|
3596 | - */ |
|
3597 | - protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true) |
|
3598 | - { |
|
3599 | - // first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
3600 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
3601 | - $notices = EE_Error::get_notices(false); |
|
3602 | - if (empty($this->_template_args['success'])) { |
|
3603 | - $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
3604 | - } |
|
3605 | - if (empty($this->_template_args['errors'])) { |
|
3606 | - $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
3607 | - } |
|
3608 | - if (empty($this->_template_args['attention'])) { |
|
3609 | - $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
3610 | - } |
|
3611 | - } |
|
3612 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
3613 | - // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
3614 | - if (! defined('DOING_AJAX') || $sticky_notices) { |
|
3615 | - $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
3616 | - $this->_add_transient( |
|
3617 | - $route, |
|
3618 | - $this->_template_args['notices'], |
|
3619 | - true, |
|
3620 | - $skip_route_verify |
|
3621 | - ); |
|
3622 | - } |
|
3623 | - } |
|
3624 | - |
|
3625 | - |
|
3626 | - /** |
|
3627 | - * get_action_link_or_button |
|
3628 | - * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
3629 | - * |
|
3630 | - * @param string $action use this to indicate which action the url is generated with. |
|
3631 | - * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
3632 | - * property. |
|
3633 | - * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
3634 | - * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
3635 | - * @param string $base_url If this is not provided |
|
3636 | - * the _admin_base_url will be used as the default for the button base_url. |
|
3637 | - * Otherwise this value will be used. |
|
3638 | - * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
3639 | - * @return string |
|
3640 | - * @throws InvalidArgumentException |
|
3641 | - * @throws InvalidInterfaceException |
|
3642 | - * @throws InvalidDataTypeException |
|
3643 | - * @throws EE_Error |
|
3644 | - */ |
|
3645 | - public function get_action_link_or_button( |
|
3646 | - $action, |
|
3647 | - $type = 'add', |
|
3648 | - $extra_request = array(), |
|
3649 | - $class = 'button-primary', |
|
3650 | - $base_url = '', |
|
3651 | - $exclude_nonce = false |
|
3652 | - ) { |
|
3653 | - // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
3654 | - if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
3655 | - throw new EE_Error( |
|
3656 | - sprintf( |
|
3657 | - esc_html__( |
|
3658 | - 'There is no page route for given action for the button. This action was given: %s', |
|
3659 | - 'event_espresso' |
|
3660 | - ), |
|
3661 | - $action |
|
3662 | - ) |
|
3663 | - ); |
|
3664 | - } |
|
3665 | - if (! isset($this->_labels['buttons'][ $type ])) { |
|
3666 | - throw new EE_Error( |
|
3667 | - sprintf( |
|
3668 | - __( |
|
3669 | - 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
3670 | - 'event_espresso' |
|
3671 | - ), |
|
3672 | - $type |
|
3673 | - ) |
|
3674 | - ); |
|
3675 | - } |
|
3676 | - // finally check user access for this button. |
|
3677 | - $has_access = $this->check_user_access($action, true); |
|
3678 | - if (! $has_access) { |
|
3679 | - return ''; |
|
3680 | - } |
|
3681 | - $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
3682 | - $query_args = array( |
|
3683 | - 'action' => $action, |
|
3684 | - ); |
|
3685 | - // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
3686 | - if (! empty($extra_request)) { |
|
3687 | - $query_args = array_merge($extra_request, $query_args); |
|
3688 | - } |
|
3689 | - $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
3690 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
3691 | - } |
|
3692 | - |
|
3693 | - |
|
3694 | - /** |
|
3695 | - * _per_page_screen_option |
|
3696 | - * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
3697 | - * |
|
3698 | - * @return void |
|
3699 | - * @throws InvalidArgumentException |
|
3700 | - * @throws InvalidInterfaceException |
|
3701 | - * @throws InvalidDataTypeException |
|
3702 | - */ |
|
3703 | - protected function _per_page_screen_option() |
|
3704 | - { |
|
3705 | - $option = 'per_page'; |
|
3706 | - $args = array( |
|
3707 | - 'label' => apply_filters( |
|
3708 | - 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
3709 | - $this->_admin_page_title, |
|
3710 | - $this |
|
3711 | - ), |
|
3712 | - 'default' => (int) apply_filters( |
|
3713 | - 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
3714 | - 20 |
|
3715 | - ), |
|
3716 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
3717 | - ); |
|
3718 | - // ONLY add the screen option if the user has access to it. |
|
3719 | - if ($this->check_user_access($this->_current_view, true)) { |
|
3720 | - add_screen_option($option, $args); |
|
3721 | - } |
|
3722 | - } |
|
3723 | - |
|
3724 | - |
|
3725 | - /** |
|
3726 | - * set_per_page_screen_option |
|
3727 | - * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
3728 | - * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
3729 | - * admin_menu. |
|
3730 | - * |
|
3731 | - * @return void |
|
3732 | - */ |
|
3733 | - private function _set_per_page_screen_options() |
|
3734 | - { |
|
3735 | - if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
|
3736 | - check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
3737 | - if (! $user = wp_get_current_user()) { |
|
3738 | - return; |
|
3739 | - } |
|
3740 | - $option = $_POST['wp_screen_options']['option']; |
|
3741 | - $value = $_POST['wp_screen_options']['value']; |
|
3742 | - if ($option != sanitize_key($option)) { |
|
3743 | - return; |
|
3744 | - } |
|
3745 | - $map_option = $option; |
|
3746 | - $option = str_replace('-', '_', $option); |
|
3747 | - switch ($map_option) { |
|
3748 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
3749 | - $value = (int) $value; |
|
3750 | - $max_value = apply_filters( |
|
3751 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
3752 | - 999, |
|
3753 | - $this->_current_page, |
|
3754 | - $this->_current_view |
|
3755 | - ); |
|
3756 | - if ($value < 1) { |
|
3757 | - return; |
|
3758 | - } |
|
3759 | - $value = min($value, $max_value); |
|
3760 | - break; |
|
3761 | - default: |
|
3762 | - $value = apply_filters( |
|
3763 | - 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
3764 | - false, |
|
3765 | - $option, |
|
3766 | - $value |
|
3767 | - ); |
|
3768 | - if (false === $value) { |
|
3769 | - return; |
|
3770 | - } |
|
3771 | - break; |
|
3772 | - } |
|
3773 | - update_user_meta($user->ID, $option, $value); |
|
3774 | - wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer())); |
|
3775 | - exit; |
|
3776 | - } |
|
3777 | - } |
|
3778 | - |
|
3779 | - |
|
3780 | - /** |
|
3781 | - * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
3782 | - * |
|
3783 | - * @param array $data array that will be assigned to template args. |
|
3784 | - */ |
|
3785 | - public function set_template_args($data) |
|
3786 | - { |
|
3787 | - $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
3788 | - } |
|
3789 | - |
|
3790 | - |
|
3791 | - /** |
|
3792 | - * This makes available the WP transient system for temporarily moving data between routes |
|
3793 | - * |
|
3794 | - * @param string $route the route that should receive the transient |
|
3795 | - * @param array $data the data that gets sent |
|
3796 | - * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
3797 | - * normal route transient. |
|
3798 | - * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
3799 | - * when we are adding a transient before page_routes have been defined. |
|
3800 | - * @return void |
|
3801 | - * @throws EE_Error |
|
3802 | - */ |
|
3803 | - protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
3804 | - { |
|
3805 | - $user_id = get_current_user_id(); |
|
3806 | - if (! $skip_route_verify) { |
|
3807 | - $this->_verify_route($route); |
|
3808 | - } |
|
3809 | - // now let's set the string for what kind of transient we're setting |
|
3810 | - $transient = $notices |
|
3811 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
3812 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
3813 | - $data = $notices ? array('notices' => $data) : $data; |
|
3814 | - // is there already a transient for this route? If there is then let's ADD to that transient |
|
3815 | - $existing = is_multisite() && is_network_admin() |
|
3816 | - ? get_site_transient($transient) |
|
3817 | - : get_transient($transient); |
|
3818 | - if ($existing) { |
|
3819 | - $data = array_merge((array) $data, (array) $existing); |
|
3820 | - } |
|
3821 | - if (is_multisite() && is_network_admin()) { |
|
3822 | - set_site_transient($transient, $data, 8); |
|
3823 | - } else { |
|
3824 | - set_transient($transient, $data, 8); |
|
3825 | - } |
|
3826 | - } |
|
3827 | - |
|
3828 | - |
|
3829 | - /** |
|
3830 | - * this retrieves the temporary transient that has been set for moving data between routes. |
|
3831 | - * |
|
3832 | - * @param bool $notices true we get notices transient. False we just return normal route transient |
|
3833 | - * @param string $route |
|
3834 | - * @return mixed data |
|
3835 | - */ |
|
3836 | - protected function _get_transient($notices = false, $route = '') |
|
3837 | - { |
|
3838 | - $user_id = get_current_user_id(); |
|
3839 | - $route = ! $route ? $this->_req_action : $route; |
|
3840 | - $transient = $notices |
|
3841 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
3842 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
3843 | - $data = is_multisite() && is_network_admin() |
|
3844 | - ? get_site_transient($transient) |
|
3845 | - : get_transient($transient); |
|
3846 | - // delete transient after retrieval (just in case it hasn't expired); |
|
3847 | - if (is_multisite() && is_network_admin()) { |
|
3848 | - delete_site_transient($transient); |
|
3849 | - } else { |
|
3850 | - delete_transient($transient); |
|
3851 | - } |
|
3852 | - return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
3853 | - } |
|
3854 | - |
|
3855 | - |
|
3856 | - /** |
|
3857 | - * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
3858 | - * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
3859 | - * default route callback on the EE_Admin page you want it run.) |
|
3860 | - * |
|
3861 | - * @return void |
|
3862 | - */ |
|
3863 | - protected function _transient_garbage_collection() |
|
3864 | - { |
|
3865 | - global $wpdb; |
|
3866 | - // retrieve all existing transients |
|
3867 | - $query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
3868 | - if ($results = $wpdb->get_results($query)) { |
|
3869 | - foreach ($results as $result) { |
|
3870 | - $transient = str_replace('_transient_', '', $result->option_name); |
|
3871 | - get_transient($transient); |
|
3872 | - if (is_multisite() && is_network_admin()) { |
|
3873 | - get_site_transient($transient); |
|
3874 | - } |
|
3875 | - } |
|
3876 | - } |
|
3877 | - } |
|
3878 | - |
|
3879 | - |
|
3880 | - /** |
|
3881 | - * get_view |
|
3882 | - * |
|
3883 | - * @return string content of _view property |
|
3884 | - */ |
|
3885 | - public function get_view() |
|
3886 | - { |
|
3887 | - return $this->_view; |
|
3888 | - } |
|
3889 | - |
|
3890 | - |
|
3891 | - /** |
|
3892 | - * getter for the protected $_views property |
|
3893 | - * |
|
3894 | - * @return array |
|
3895 | - */ |
|
3896 | - public function get_views() |
|
3897 | - { |
|
3898 | - return $this->_views; |
|
3899 | - } |
|
3900 | - |
|
3901 | - |
|
3902 | - /** |
|
3903 | - * get_current_page |
|
3904 | - * |
|
3905 | - * @return string _current_page property value |
|
3906 | - */ |
|
3907 | - public function get_current_page() |
|
3908 | - { |
|
3909 | - return $this->_current_page; |
|
3910 | - } |
|
3911 | - |
|
3912 | - |
|
3913 | - /** |
|
3914 | - * get_current_view |
|
3915 | - * |
|
3916 | - * @return string _current_view property value |
|
3917 | - */ |
|
3918 | - public function get_current_view() |
|
3919 | - { |
|
3920 | - return $this->_current_view; |
|
3921 | - } |
|
3922 | - |
|
3923 | - |
|
3924 | - /** |
|
3925 | - * get_current_screen |
|
3926 | - * |
|
3927 | - * @return object The current WP_Screen object |
|
3928 | - */ |
|
3929 | - public function get_current_screen() |
|
3930 | - { |
|
3931 | - return $this->_current_screen; |
|
3932 | - } |
|
3933 | - |
|
3934 | - |
|
3935 | - /** |
|
3936 | - * get_current_page_view_url |
|
3937 | - * |
|
3938 | - * @return string This returns the url for the current_page_view. |
|
3939 | - */ |
|
3940 | - public function get_current_page_view_url() |
|
3941 | - { |
|
3942 | - return $this->_current_page_view_url; |
|
3943 | - } |
|
3944 | - |
|
3945 | - |
|
3946 | - /** |
|
3947 | - * just returns the _req_data property |
|
3948 | - * |
|
3949 | - * @return array |
|
3950 | - */ |
|
3951 | - public function get_request_data() |
|
3952 | - { |
|
3953 | - return $this->_req_data; |
|
3954 | - } |
|
3955 | - |
|
3956 | - |
|
3957 | - /** |
|
3958 | - * returns the _req_data protected property |
|
3959 | - * |
|
3960 | - * @return string |
|
3961 | - */ |
|
3962 | - public function get_req_action() |
|
3963 | - { |
|
3964 | - return $this->_req_action; |
|
3965 | - } |
|
3966 | - |
|
3967 | - |
|
3968 | - /** |
|
3969 | - * @return bool value of $_is_caf property |
|
3970 | - */ |
|
3971 | - public function is_caf() |
|
3972 | - { |
|
3973 | - return $this->_is_caf; |
|
3974 | - } |
|
3975 | - |
|
3976 | - |
|
3977 | - /** |
|
3978 | - * @return mixed |
|
3979 | - */ |
|
3980 | - public function default_espresso_metaboxes() |
|
3981 | - { |
|
3982 | - return $this->_default_espresso_metaboxes; |
|
3983 | - } |
|
3984 | - |
|
3985 | - |
|
3986 | - /** |
|
3987 | - * @return mixed |
|
3988 | - */ |
|
3989 | - public function admin_base_url() |
|
3990 | - { |
|
3991 | - return $this->_admin_base_url; |
|
3992 | - } |
|
3993 | - |
|
3994 | - |
|
3995 | - /** |
|
3996 | - * @return mixed |
|
3997 | - */ |
|
3998 | - public function wp_page_slug() |
|
3999 | - { |
|
4000 | - return $this->_wp_page_slug; |
|
4001 | - } |
|
4002 | - |
|
4003 | - |
|
4004 | - /** |
|
4005 | - * updates espresso configuration settings |
|
4006 | - * |
|
4007 | - * @param string $tab |
|
4008 | - * @param EE_Config_Base|EE_Config $config |
|
4009 | - * @param string $file file where error occurred |
|
4010 | - * @param string $func function where error occurred |
|
4011 | - * @param string $line line no where error occurred |
|
4012 | - * @return boolean |
|
4013 | - */ |
|
4014 | - protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
4015 | - { |
|
4016 | - // remove any options that are NOT going to be saved with the config settings. |
|
4017 | - if (isset($config->core->ee_ueip_optin)) { |
|
4018 | - // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
4019 | - update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
4020 | - update_option('ee_ueip_has_notified', true); |
|
4021 | - } |
|
4022 | - // and save it (note we're also doing the network save here) |
|
4023 | - $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
4024 | - $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
4025 | - if ($config_saved && $net_saved) { |
|
4026 | - EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
4027 | - return true; |
|
4028 | - } |
|
4029 | - EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
4030 | - return false; |
|
4031 | - } |
|
4032 | - |
|
4033 | - |
|
4034 | - /** |
|
4035 | - * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
4036 | - * |
|
4037 | - * @return array |
|
4038 | - */ |
|
4039 | - public function get_yes_no_values() |
|
4040 | - { |
|
4041 | - return $this->_yes_no_values; |
|
4042 | - } |
|
4043 | - |
|
4044 | - |
|
4045 | - protected function _get_dir() |
|
4046 | - { |
|
4047 | - $reflector = new ReflectionClass(get_class($this)); |
|
4048 | - return dirname($reflector->getFileName()); |
|
4049 | - } |
|
4050 | - |
|
4051 | - |
|
4052 | - /** |
|
4053 | - * A helper for getting a "next link". |
|
4054 | - * |
|
4055 | - * @param string $url The url to link to |
|
4056 | - * @param string $class The class to use. |
|
4057 | - * @return string |
|
4058 | - */ |
|
4059 | - protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
4060 | - { |
|
4061 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
4062 | - } |
|
4063 | - |
|
4064 | - |
|
4065 | - /** |
|
4066 | - * A helper for getting a "previous link". |
|
4067 | - * |
|
4068 | - * @param string $url The url to link to |
|
4069 | - * @param string $class The class to use. |
|
4070 | - * @return string |
|
4071 | - */ |
|
4072 | - protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
4073 | - { |
|
4074 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
4075 | - } |
|
4076 | - |
|
4077 | - |
|
4078 | - |
|
4079 | - |
|
4080 | - |
|
4081 | - |
|
4082 | - |
|
4083 | - // below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
4084 | - |
|
4085 | - |
|
4086 | - /** |
|
4087 | - * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
4088 | - * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the |
|
4089 | - * _req_data array. |
|
4090 | - * |
|
4091 | - * @return bool success/fail |
|
4092 | - * @throws EE_Error |
|
4093 | - * @throws InvalidArgumentException |
|
4094 | - * @throws ReflectionException |
|
4095 | - * @throws InvalidDataTypeException |
|
4096 | - * @throws InvalidInterfaceException |
|
4097 | - */ |
|
4098 | - protected function _process_resend_registration() |
|
4099 | - { |
|
4100 | - $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
4101 | - do_action( |
|
4102 | - 'AHEE__EE_Admin_Page___process_resend_registration', |
|
4103 | - $this->_template_args['success'], |
|
4104 | - $this->_req_data |
|
4105 | - ); |
|
4106 | - return $this->_template_args['success']; |
|
4107 | - } |
|
4108 | - |
|
4109 | - |
|
4110 | - /** |
|
4111 | - * This automatically processes any payment message notifications when manual payment has been applied. |
|
4112 | - * |
|
4113 | - * @param \EE_Payment $payment |
|
4114 | - * @return bool success/fail |
|
4115 | - */ |
|
4116 | - protected function _process_payment_notification(EE_Payment $payment) |
|
4117 | - { |
|
4118 | - add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
4119 | - do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
4120 | - $this->_template_args['success'] = apply_filters( |
|
4121 | - 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
4122 | - false, |
|
4123 | - $payment |
|
4124 | - ); |
|
4125 | - return $this->_template_args['success']; |
|
4126 | - } |
|
2703 | + } |
|
2704 | + |
|
2705 | + |
|
2706 | + /** |
|
2707 | + * facade for add_meta_box |
|
2708 | + * |
|
2709 | + * @param string $action where the metabox get's displayed |
|
2710 | + * @param string $title Title of Metabox (output in metabox header) |
|
2711 | + * @param string $callback If not empty and $create_fun is set to false then we'll use a custom callback |
|
2712 | + * instead of the one created in here. |
|
2713 | + * @param array $callback_args an array of args supplied for the metabox |
|
2714 | + * @param string $column what metabox column |
|
2715 | + * @param string $priority give this metabox a priority (using accepted priorities for wp meta boxes) |
|
2716 | + * @param boolean $create_func default is true. Basically we can say we don't WANT to have the runtime function |
|
2717 | + * created but just set our own callback for wp's add_meta_box. |
|
2718 | + * @throws \DomainException |
|
2719 | + */ |
|
2720 | + public function _add_admin_page_meta_box( |
|
2721 | + $action, |
|
2722 | + $title, |
|
2723 | + $callback, |
|
2724 | + $callback_args, |
|
2725 | + $column = 'normal', |
|
2726 | + $priority = 'high', |
|
2727 | + $create_func = true |
|
2728 | + ) { |
|
2729 | + do_action('AHEE_log', __FILE__, __FUNCTION__, $callback); |
|
2730 | + // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated. |
|
2731 | + if (empty($callback_args) && $create_func) { |
|
2732 | + $callback_args = array( |
|
2733 | + 'template_path' => $this->_template_path, |
|
2734 | + 'template_args' => $this->_template_args, |
|
2735 | + ); |
|
2736 | + } |
|
2737 | + // if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
|
2738 | + $call_back_func = $create_func |
|
2739 | + ? function ($post, $metabox) { |
|
2740 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2741 | + echo EEH_Template::display_template( |
|
2742 | + $metabox['args']['template_path'], |
|
2743 | + $metabox['args']['template_args'], |
|
2744 | + true |
|
2745 | + ); |
|
2746 | + } |
|
2747 | + : $callback; |
|
2748 | + add_meta_box( |
|
2749 | + str_replace('_', '-', $action) . '-mbox', |
|
2750 | + $title, |
|
2751 | + $call_back_func, |
|
2752 | + $this->_wp_page_slug, |
|
2753 | + $column, |
|
2754 | + $priority, |
|
2755 | + $callback_args |
|
2756 | + ); |
|
2757 | + } |
|
2758 | + |
|
2759 | + |
|
2760 | + /** |
|
2761 | + * generates HTML wrapper for and admin details page that contains metaboxes in columns |
|
2762 | + * |
|
2763 | + * @throws DomainException |
|
2764 | + * @throws EE_Error |
|
2765 | + */ |
|
2766 | + public function display_admin_page_with_metabox_columns() |
|
2767 | + { |
|
2768 | + $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content']; |
|
2769 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
2770 | + $this->_column_template_path, |
|
2771 | + $this->_template_args, |
|
2772 | + true |
|
2773 | + ); |
|
2774 | + // the final wrapper |
|
2775 | + $this->admin_page_wrapper(); |
|
2776 | + } |
|
2777 | + |
|
2778 | + |
|
2779 | + /** |
|
2780 | + * generates HTML wrapper for an admin details page |
|
2781 | + * |
|
2782 | + * @return void |
|
2783 | + * @throws EE_Error |
|
2784 | + * @throws DomainException |
|
2785 | + */ |
|
2786 | + public function display_admin_page_with_sidebar() |
|
2787 | + { |
|
2788 | + $this->_display_admin_page(true); |
|
2789 | + } |
|
2790 | + |
|
2791 | + |
|
2792 | + /** |
|
2793 | + * generates HTML wrapper for an admin details page (except no sidebar) |
|
2794 | + * |
|
2795 | + * @return void |
|
2796 | + * @throws EE_Error |
|
2797 | + * @throws DomainException |
|
2798 | + */ |
|
2799 | + public function display_admin_page_with_no_sidebar() |
|
2800 | + { |
|
2801 | + $this->_display_admin_page(); |
|
2802 | + } |
|
2803 | + |
|
2804 | + |
|
2805 | + /** |
|
2806 | + * generates HTML wrapper for an EE about admin page (no sidebar) |
|
2807 | + * |
|
2808 | + * @return void |
|
2809 | + * @throws EE_Error |
|
2810 | + * @throws DomainException |
|
2811 | + */ |
|
2812 | + public function display_about_admin_page() |
|
2813 | + { |
|
2814 | + $this->_display_admin_page(false, true); |
|
2815 | + } |
|
2816 | + |
|
2817 | + |
|
2818 | + /** |
|
2819 | + * display_admin_page |
|
2820 | + * contains the code for actually displaying an admin page |
|
2821 | + * |
|
2822 | + * @param boolean $sidebar true with sidebar, false without |
|
2823 | + * @param boolean $about use the about admin wrapper instead of the default. |
|
2824 | + * @return void |
|
2825 | + * @throws DomainException |
|
2826 | + * @throws EE_Error |
|
2827 | + */ |
|
2828 | + private function _display_admin_page($sidebar = false, $about = false) |
|
2829 | + { |
|
2830 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2831 | + // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages. |
|
2832 | + do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'); |
|
2833 | + // set current wp page slug - looks like: event-espresso_page_event_categories |
|
2834 | + // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated. |
|
2835 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
2836 | + $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route |
|
2837 | + ? 'poststuff' |
|
2838 | + : 'espresso-default-admin'; |
|
2839 | + $template_path = $sidebar |
|
2840 | + ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
|
2841 | + : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
2842 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
2843 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
2844 | + } |
|
2845 | + $template_path = ! empty($this->_column_template_path) |
|
2846 | + ? $this->_column_template_path : $template_path; |
|
2847 | + $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content']) |
|
2848 | + ? $this->_template_args['admin_page_content'] |
|
2849 | + : ''; |
|
2850 | + $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content']) |
|
2851 | + ? $this->_template_args['before_admin_page_content'] |
|
2852 | + : ''; |
|
2853 | + $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content']) |
|
2854 | + ? $this->_template_args['after_admin_page_content'] |
|
2855 | + : ''; |
|
2856 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
2857 | + $template_path, |
|
2858 | + $this->_template_args, |
|
2859 | + true |
|
2860 | + ); |
|
2861 | + // the final template wrapper |
|
2862 | + $this->admin_page_wrapper($about); |
|
2863 | + } |
|
2864 | + |
|
2865 | + |
|
2866 | + /** |
|
2867 | + * This is used to display caf preview pages. |
|
2868 | + * |
|
2869 | + * @since 4.3.2 |
|
2870 | + * @param string $utm_campaign_source what is the key used for google analytics link |
|
2871 | + * @param bool $display_sidebar whether to use the sidebar template or the full template for the page. TRUE |
|
2872 | + * = SHOW sidebar, FALSE = no sidebar. Default no sidebar. |
|
2873 | + * @return void |
|
2874 | + * @throws DomainException |
|
2875 | + * @throws EE_Error |
|
2876 | + * @throws InvalidArgumentException |
|
2877 | + * @throws InvalidDataTypeException |
|
2878 | + * @throws InvalidInterfaceException |
|
2879 | + */ |
|
2880 | + public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true) |
|
2881 | + { |
|
2882 | + // let's generate a default preview action button if there isn't one already present. |
|
2883 | + $this->_labels['buttons']['buy_now'] = esc_html__( |
|
2884 | + 'Upgrade to Event Espresso 4 Right Now', |
|
2885 | + 'event_espresso' |
|
2886 | + ); |
|
2887 | + $buy_now_url = add_query_arg( |
|
2888 | + array( |
|
2889 | + 'ee_ver' => 'ee4', |
|
2890 | + 'utm_source' => 'ee4_plugin_admin', |
|
2891 | + 'utm_medium' => 'link', |
|
2892 | + 'utm_campaign' => $utm_campaign_source, |
|
2893 | + 'utm_content' => 'buy_now_button', |
|
2894 | + ), |
|
2895 | + 'http://eventespresso.com/pricing/' |
|
2896 | + ); |
|
2897 | + $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button']) |
|
2898 | + ? $this->get_action_link_or_button( |
|
2899 | + '', |
|
2900 | + 'buy_now', |
|
2901 | + array(), |
|
2902 | + 'button-primary button-large', |
|
2903 | + $buy_now_url, |
|
2904 | + true |
|
2905 | + ) |
|
2906 | + : $this->_template_args['preview_action_button']; |
|
2907 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
2908 | + EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
2909 | + $this->_template_args, |
|
2910 | + true |
|
2911 | + ); |
|
2912 | + $this->_display_admin_page($display_sidebar); |
|
2913 | + } |
|
2914 | + |
|
2915 | + |
|
2916 | + /** |
|
2917 | + * display_admin_list_table_page_with_sidebar |
|
2918 | + * generates HTML wrapper for an admin_page with list_table |
|
2919 | + * |
|
2920 | + * @return void |
|
2921 | + * @throws EE_Error |
|
2922 | + * @throws DomainException |
|
2923 | + */ |
|
2924 | + public function display_admin_list_table_page_with_sidebar() |
|
2925 | + { |
|
2926 | + $this->_display_admin_list_table_page(true); |
|
2927 | + } |
|
2928 | + |
|
2929 | + |
|
2930 | + /** |
|
2931 | + * display_admin_list_table_page_with_no_sidebar |
|
2932 | + * generates HTML wrapper for an admin_page with list_table (but with no sidebar) |
|
2933 | + * |
|
2934 | + * @return void |
|
2935 | + * @throws EE_Error |
|
2936 | + * @throws DomainException |
|
2937 | + */ |
|
2938 | + public function display_admin_list_table_page_with_no_sidebar() |
|
2939 | + { |
|
2940 | + $this->_display_admin_list_table_page(); |
|
2941 | + } |
|
2942 | + |
|
2943 | + |
|
2944 | + /** |
|
2945 | + * generates html wrapper for an admin_list_table page |
|
2946 | + * |
|
2947 | + * @param boolean $sidebar whether to display with sidebar or not. |
|
2948 | + * @return void |
|
2949 | + * @throws DomainException |
|
2950 | + * @throws EE_Error |
|
2951 | + */ |
|
2952 | + private function _display_admin_list_table_page($sidebar = false) |
|
2953 | + { |
|
2954 | + // setup search attributes |
|
2955 | + $this->_set_search_attributes(); |
|
2956 | + $this->_template_args['current_page'] = $this->_wp_page_slug; |
|
2957 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
2958 | + $this->_template_args['table_url'] = defined('DOING_AJAX') |
|
2959 | + ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
|
2960 | + : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
|
2961 | + $this->_template_args['list_table'] = $this->_list_table_object; |
|
2962 | + $this->_template_args['current_route'] = $this->_req_action; |
|
2963 | + $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
|
2964 | + $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
|
2965 | + if (! empty($ajax_sorting_callback)) { |
|
2966 | + $sortable_list_table_form_fields = wp_nonce_field( |
|
2967 | + $ajax_sorting_callback . '_nonce', |
|
2968 | + $ajax_sorting_callback . '_nonce', |
|
2969 | + false, |
|
2970 | + false |
|
2971 | + ); |
|
2972 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="' |
|
2973 | + . $this->page_slug |
|
2974 | + . '" />'; |
|
2975 | + $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="' |
|
2976 | + . $ajax_sorting_callback |
|
2977 | + . '" />'; |
|
2978 | + } else { |
|
2979 | + $sortable_list_table_form_fields = ''; |
|
2980 | + } |
|
2981 | + $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields; |
|
2982 | + $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) |
|
2983 | + ? $this->_template_args['list_table_hidden_fields'] |
|
2984 | + : ''; |
|
2985 | + $nonce_ref = $this->_req_action . '_nonce'; |
|
2986 | + $hidden_form_fields .= '<input type="hidden" name="' |
|
2987 | + . $nonce_ref |
|
2988 | + . '" value="' |
|
2989 | + . wp_create_nonce($nonce_ref) |
|
2990 | + . '">'; |
|
2991 | + $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
|
2992 | + // display message about search results? |
|
2993 | + $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
|
2994 | + ? '<p class="ee-search-results">' . sprintf( |
|
2995 | + esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
|
2996 | + trim($this->_req_data['s'], '%') |
|
2997 | + ) . '</p>' |
|
2998 | + : ''; |
|
2999 | + // filter before_list_table template arg |
|
3000 | + $this->_template_args['before_list_table'] = apply_filters( |
|
3001 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg', |
|
3002 | + $this->_template_args['before_list_table'], |
|
3003 | + $this->page_slug, |
|
3004 | + $this->_req_data, |
|
3005 | + $this->_req_action |
|
3006 | + ); |
|
3007 | + // convert to array and filter again |
|
3008 | + // arrays are easier to inject new items in a specific location, |
|
3009 | + // but would not be backwards compatible, so we have to add a new filter |
|
3010 | + $this->_template_args['before_list_table'] = implode( |
|
3011 | + " \n", |
|
3012 | + (array) apply_filters( |
|
3013 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array', |
|
3014 | + (array) $this->_template_args['before_list_table'], |
|
3015 | + $this->page_slug, |
|
3016 | + $this->_req_data, |
|
3017 | + $this->_req_action |
|
3018 | + ) |
|
3019 | + ); |
|
3020 | + // filter after_list_table template arg |
|
3021 | + $this->_template_args['after_list_table'] = apply_filters( |
|
3022 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg', |
|
3023 | + $this->_template_args['after_list_table'], |
|
3024 | + $this->page_slug, |
|
3025 | + $this->_req_data, |
|
3026 | + $this->_req_action |
|
3027 | + ); |
|
3028 | + // convert to array and filter again |
|
3029 | + // arrays are easier to inject new items in a specific location, |
|
3030 | + // but would not be backwards compatible, so we have to add a new filter |
|
3031 | + $this->_template_args['after_list_table'] = implode( |
|
3032 | + " \n", |
|
3033 | + (array) apply_filters( |
|
3034 | + 'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array', |
|
3035 | + (array) $this->_template_args['after_list_table'], |
|
3036 | + $this->page_slug, |
|
3037 | + $this->_req_data, |
|
3038 | + $this->_req_action |
|
3039 | + ) |
|
3040 | + ); |
|
3041 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
3042 | + $template_path, |
|
3043 | + $this->_template_args, |
|
3044 | + true |
|
3045 | + ); |
|
3046 | + // the final template wrapper |
|
3047 | + if ($sidebar) { |
|
3048 | + $this->display_admin_page_with_sidebar(); |
|
3049 | + } else { |
|
3050 | + $this->display_admin_page_with_no_sidebar(); |
|
3051 | + } |
|
3052 | + } |
|
3053 | + |
|
3054 | + |
|
3055 | + /** |
|
3056 | + * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the |
|
3057 | + * html string for the legend. |
|
3058 | + * $items are expected in an array in the following format: |
|
3059 | + * $legend_items = array( |
|
3060 | + * 'item_id' => array( |
|
3061 | + * 'icon' => 'http://url_to_icon_being_described.png', |
|
3062 | + * 'desc' => esc_html__('localized description of item'); |
|
3063 | + * ) |
|
3064 | + * ); |
|
3065 | + * |
|
3066 | + * @param array $items see above for format of array |
|
3067 | + * @return string html string of legend |
|
3068 | + * @throws DomainException |
|
3069 | + */ |
|
3070 | + protected function _display_legend($items) |
|
3071 | + { |
|
3072 | + $this->_template_args['items'] = apply_filters( |
|
3073 | + 'FHEE__EE_Admin_Page___display_legend__items', |
|
3074 | + (array) $items, |
|
3075 | + $this |
|
3076 | + ); |
|
3077 | + return EEH_Template::display_template( |
|
3078 | + EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
3079 | + $this->_template_args, |
|
3080 | + true |
|
3081 | + ); |
|
3082 | + } |
|
3083 | + |
|
3084 | + |
|
3085 | + /** |
|
3086 | + * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect |
|
3087 | + * The returned json object is created from an array in the following format: |
|
3088 | + * array( |
|
3089 | + * 'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early), |
|
3090 | + * 'success' => FALSE, //(default FALSE) - contains any special success message. |
|
3091 | + * 'notices' => '', // - contains any EE_Error formatted notices |
|
3092 | + * 'content' => 'string can be html', //this is a string of formatted content (can be html) |
|
3093 | + * 'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js. |
|
3094 | + * We're also going to include the template args with every package (so js can pick out any specific template args |
|
3095 | + * that might be included in here) |
|
3096 | + * ) |
|
3097 | + * The json object is populated by whatever is set in the $_template_args property. |
|
3098 | + * |
|
3099 | + * @param bool $sticky_notices Used to indicate whether you want to ensure notices are added to a transient |
|
3100 | + * instead of displayed. |
|
3101 | + * @param array $notices_arguments Use this to pass any additional args on to the _process_notices. |
|
3102 | + * @return void |
|
3103 | + * @throws EE_Error |
|
3104 | + */ |
|
3105 | + protected function _return_json($sticky_notices = false, $notices_arguments = array()) |
|
3106 | + { |
|
3107 | + // make sure any EE_Error notices have been handled. |
|
3108 | + $this->_process_notices($notices_arguments, true, $sticky_notices); |
|
3109 | + $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array(); |
|
3110 | + unset($this->_template_args['data']); |
|
3111 | + $json = array( |
|
3112 | + 'error' => isset($this->_template_args['error']) ? $this->_template_args['error'] : false, |
|
3113 | + 'success' => isset($this->_template_args['success']) ? $this->_template_args['success'] : false, |
|
3114 | + 'errors' => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false, |
|
3115 | + 'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false, |
|
3116 | + 'notices' => EE_Error::get_notices(), |
|
3117 | + 'content' => isset($this->_template_args['admin_page_content']) |
|
3118 | + ? $this->_template_args['admin_page_content'] : '', |
|
3119 | + 'data' => array_merge($data, array('template_args' => $this->_template_args)), |
|
3120 | + 'isEEajax' => true |
|
3121 | + // special flag so any ajax.Success methods in js can identify this return package as a EEajax package. |
|
3122 | + ); |
|
3123 | + // make sure there are no php errors or headers_sent. Then we can set correct json header. |
|
3124 | + if (null === error_get_last() || ! headers_sent()) { |
|
3125 | + header('Content-Type: application/json; charset=UTF-8'); |
|
3126 | + } |
|
3127 | + echo wp_json_encode($json); |
|
3128 | + exit(); |
|
3129 | + } |
|
3130 | + |
|
3131 | + |
|
3132 | + /** |
|
3133 | + * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax) |
|
3134 | + * |
|
3135 | + * @return void |
|
3136 | + * @throws EE_Error |
|
3137 | + */ |
|
3138 | + public function return_json() |
|
3139 | + { |
|
3140 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
3141 | + $this->_return_json(); |
|
3142 | + } else { |
|
3143 | + throw new EE_Error( |
|
3144 | + sprintf( |
|
3145 | + esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'), |
|
3146 | + __FUNCTION__ |
|
3147 | + ) |
|
3148 | + ); |
|
3149 | + } |
|
3150 | + } |
|
3151 | + |
|
3152 | + |
|
3153 | + /** |
|
3154 | + * This provides a way for child hook classes to send along themselves by reference so methods/properties within |
|
3155 | + * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property. |
|
3156 | + * |
|
3157 | + * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child |
|
3158 | + */ |
|
3159 | + public function set_hook_object(EE_Admin_Hooks $hook_obj) |
|
3160 | + { |
|
3161 | + $this->_hook_obj = $hook_obj; |
|
3162 | + } |
|
3163 | + |
|
3164 | + |
|
3165 | + /** |
|
3166 | + * generates HTML wrapper with Tabbed nav for an admin page |
|
3167 | + * |
|
3168 | + * @param boolean $about whether to use the special about page wrapper or default. |
|
3169 | + * @return void |
|
3170 | + * @throws DomainException |
|
3171 | + * @throws EE_Error |
|
3172 | + */ |
|
3173 | + public function admin_page_wrapper($about = false) |
|
3174 | + { |
|
3175 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
3176 | + $this->_nav_tabs = $this->_get_main_nav_tabs(); |
|
3177 | + $this->_template_args['nav_tabs'] = $this->_nav_tabs; |
|
3178 | + $this->_template_args['admin_page_title'] = $this->_admin_page_title; |
|
3179 | + $this->_template_args['before_admin_page_content'] = apply_filters( |
|
3180 | + "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
3181 | + isset($this->_template_args['before_admin_page_content']) |
|
3182 | + ? $this->_template_args['before_admin_page_content'] |
|
3183 | + : '' |
|
3184 | + ); |
|
3185 | + $this->_template_args['after_admin_page_content'] = apply_filters( |
|
3186 | + "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}", |
|
3187 | + isset($this->_template_args['after_admin_page_content']) |
|
3188 | + ? $this->_template_args['after_admin_page_content'] |
|
3189 | + : '' |
|
3190 | + ); |
|
3191 | + $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content(); |
|
3192 | + // load settings page wrapper template |
|
3193 | + $template_path = ! defined('DOING_AJAX') |
|
3194 | + ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php' |
|
3195 | + : EE_ADMIN_TEMPLATE |
|
3196 | + . 'admin_wrapper_ajax.template.php'; |
|
3197 | + // about page? |
|
3198 | + $template_path = $about |
|
3199 | + ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php' |
|
3200 | + : $template_path; |
|
3201 | + if (defined('DOING_AJAX')) { |
|
3202 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
3203 | + $template_path, |
|
3204 | + $this->_template_args, |
|
3205 | + true |
|
3206 | + ); |
|
3207 | + $this->_return_json(); |
|
3208 | + } else { |
|
3209 | + EEH_Template::display_template($template_path, $this->_template_args); |
|
3210 | + } |
|
3211 | + } |
|
3212 | + |
|
3213 | + |
|
3214 | + /** |
|
3215 | + * This returns the admin_nav tabs html using the configuration in the _nav_tabs property |
|
3216 | + * |
|
3217 | + * @return string html |
|
3218 | + * @throws EE_Error |
|
3219 | + */ |
|
3220 | + protected function _get_main_nav_tabs() |
|
3221 | + { |
|
3222 | + // let's generate the html using the EEH_Tabbed_Content helper. |
|
3223 | + // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute |
|
3224 | + // (rather than setting in the page_routes array) |
|
3225 | + return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs); |
|
3226 | + } |
|
3227 | + |
|
3228 | + |
|
3229 | + /** |
|
3230 | + * sort nav tabs |
|
3231 | + * |
|
3232 | + * @param $a |
|
3233 | + * @param $b |
|
3234 | + * @return int |
|
3235 | + */ |
|
3236 | + private function _sort_nav_tabs($a, $b) |
|
3237 | + { |
|
3238 | + if ($a['order'] === $b['order']) { |
|
3239 | + return 0; |
|
3240 | + } |
|
3241 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
3242 | + } |
|
3243 | + |
|
3244 | + |
|
3245 | + /** |
|
3246 | + * generates HTML for the forms used on admin pages |
|
3247 | + * |
|
3248 | + * @param array $input_vars - array of input field details |
|
3249 | + * @param string $generator (options are 'string' or 'array', basically use this to indicate which generator to |
|
3250 | + * use) |
|
3251 | + * @param bool $id |
|
3252 | + * @return string |
|
3253 | + * @uses EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php) |
|
3254 | + * @uses EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php) |
|
3255 | + */ |
|
3256 | + protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false) |
|
3257 | + { |
|
3258 | + $content = $generator === 'string' |
|
3259 | + ? EEH_Form_Fields::get_form_fields($input_vars, $id) |
|
3260 | + : EEH_Form_Fields::get_form_fields_array($input_vars); |
|
3261 | + return $content; |
|
3262 | + } |
|
3263 | + |
|
3264 | + |
|
3265 | + /** |
|
3266 | + * generates the "Save" and "Save & Close" buttons for edit forms |
|
3267 | + * |
|
3268 | + * @param bool $both if true then both buttons will be generated. If false then just the "Save & |
|
3269 | + * Close" button. |
|
3270 | + * @param array $text if included, generator will use the given text for the buttons ( array([0] => |
|
3271 | + * 'Save', [1] => 'save & close') |
|
3272 | + * @param array $actions if included allows us to set the actions that each button will carry out (i.e. |
|
3273 | + * via the "name" value in the button). We can also use this to just dump |
|
3274 | + * default actions by submitting some other value. |
|
3275 | + * @param bool|string|null $referrer if false then we just do the default action on save and close. Other wise it |
|
3276 | + * will use the $referrer string. IF null, then we don't do ANYTHING on save and |
|
3277 | + * close (normal form handling). |
|
3278 | + */ |
|
3279 | + protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null) |
|
3280 | + { |
|
3281 | + // make sure $text and $actions are in an array |
|
3282 | + $text = (array) $text; |
|
3283 | + $actions = (array) $actions; |
|
3284 | + $referrer_url = empty($referrer) |
|
3285 | + ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
3286 | + . $_SERVER['REQUEST_URI'] |
|
3287 | + . '" />' |
|
3288 | + : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="' |
|
3289 | + . $referrer |
|
3290 | + . '" />'; |
|
3291 | + $button_text = ! empty($text) |
|
3292 | + ? $text |
|
3293 | + : array( |
|
3294 | + esc_html__('Save', 'event_espresso'), |
|
3295 | + esc_html__('Save and Close', 'event_espresso'), |
|
3296 | + ); |
|
3297 | + $default_names = array('save', 'save_and_close'); |
|
3298 | + // add in a hidden index for the current page (so save and close redirects properly) |
|
3299 | + $this->_template_args['save_buttons'] = $referrer_url; |
|
3300 | + foreach ($button_text as $key => $button) { |
|
3301 | + $ref = $default_names[ $key ]; |
|
3302 | + $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' |
|
3303 | + . $ref |
|
3304 | + . '" value="' |
|
3305 | + . $button |
|
3306 | + . '" name="' |
|
3307 | + . (! empty($actions) ? $actions[ $key ] : $ref) |
|
3308 | + . '" id="' |
|
3309 | + . $this->_current_view . '_' . $ref |
|
3310 | + . '" />'; |
|
3311 | + if (! $both) { |
|
3312 | + break; |
|
3313 | + } |
|
3314 | + } |
|
3315 | + } |
|
3316 | + |
|
3317 | + |
|
3318 | + /** |
|
3319 | + * Wrapper for the protected function. Allows plugins/addons to call this to set the form tags. |
|
3320 | + * |
|
3321 | + * @see $this->_set_add_edit_form_tags() for details on params |
|
3322 | + * @since 4.6.0 |
|
3323 | + * @param string $route |
|
3324 | + * @param array $additional_hidden_fields |
|
3325 | + */ |
|
3326 | + public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
3327 | + { |
|
3328 | + $this->_set_add_edit_form_tags($route, $additional_hidden_fields); |
|
3329 | + } |
|
3330 | + |
|
3331 | + |
|
3332 | + /** |
|
3333 | + * set form open and close tags on add/edit pages. |
|
3334 | + * |
|
3335 | + * @param string $route the route you want the form to direct to |
|
3336 | + * @param array $additional_hidden_fields any additional hidden fields required in the form header |
|
3337 | + * @return void |
|
3338 | + */ |
|
3339 | + protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array()) |
|
3340 | + { |
|
3341 | + if (empty($route)) { |
|
3342 | + $user_msg = esc_html__( |
|
3343 | + 'An error occurred. No action was set for this page\'s form.', |
|
3344 | + 'event_espresso' |
|
3345 | + ); |
|
3346 | + $dev_msg = $user_msg . "\n" |
|
3347 | + . sprintf( |
|
3348 | + esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
|
3349 | + __FUNCTION__, |
|
3350 | + __CLASS__ |
|
3351 | + ); |
|
3352 | + EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
3353 | + } |
|
3354 | + // open form |
|
3355 | + $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
|
3356 | + . $this->_admin_base_url |
|
3357 | + . '" id="' |
|
3358 | + . $route |
|
3359 | + . '_event_form" >'; |
|
3360 | + // add nonce |
|
3361 | + $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
3362 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
3363 | + // add REQUIRED form action |
|
3364 | + $hidden_fields = array( |
|
3365 | + 'action' => array('type' => 'hidden', 'value' => $route), |
|
3366 | + ); |
|
3367 | + // merge arrays |
|
3368 | + $hidden_fields = is_array($additional_hidden_fields) |
|
3369 | + ? array_merge($hidden_fields, $additional_hidden_fields) |
|
3370 | + : $hidden_fields; |
|
3371 | + // generate form fields |
|
3372 | + $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
|
3373 | + // add fields to form |
|
3374 | + foreach ((array) $form_fields as $field_name => $form_field) { |
|
3375 | + $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
3376 | + } |
|
3377 | + // close form |
|
3378 | + $this->_template_args['after_admin_page_content'] = '</form>'; |
|
3379 | + } |
|
3380 | + |
|
3381 | + |
|
3382 | + /** |
|
3383 | + * Public Wrapper for _redirect_after_action() method since its |
|
3384 | + * discovered it would be useful for external code to have access. |
|
3385 | + * |
|
3386 | + * @see EE_Admin_Page::_redirect_after_action() for params. |
|
3387 | + * @since 4.5.0 |
|
3388 | + * @param bool $success |
|
3389 | + * @param string $what |
|
3390 | + * @param string $action_desc |
|
3391 | + * @param array $query_args |
|
3392 | + * @param bool $override_overwrite |
|
3393 | + * @throws EE_Error |
|
3394 | + */ |
|
3395 | + public function redirect_after_action( |
|
3396 | + $success = false, |
|
3397 | + $what = 'item', |
|
3398 | + $action_desc = 'processed', |
|
3399 | + $query_args = array(), |
|
3400 | + $override_overwrite = false |
|
3401 | + ) { |
|
3402 | + $this->_redirect_after_action( |
|
3403 | + $success, |
|
3404 | + $what, |
|
3405 | + $action_desc, |
|
3406 | + $query_args, |
|
3407 | + $override_overwrite |
|
3408 | + ); |
|
3409 | + } |
|
3410 | + |
|
3411 | + |
|
3412 | + /** |
|
3413 | + * Helper method for merging existing request data with the returned redirect url. |
|
3414 | + * |
|
3415 | + * This is typically used for redirects after an action so that if the original view was a filtered view those |
|
3416 | + * filters are still applied. |
|
3417 | + * |
|
3418 | + * @param array $new_route_data |
|
3419 | + * @return array |
|
3420 | + */ |
|
3421 | + protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data) |
|
3422 | + { |
|
3423 | + foreach ($this->_req_data as $ref => $value) { |
|
3424 | + // unset nonces |
|
3425 | + if (strpos($ref, 'nonce') !== false) { |
|
3426 | + unset($this->_req_data[ $ref ]); |
|
3427 | + continue; |
|
3428 | + } |
|
3429 | + // urlencode values. |
|
3430 | + $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
3431 | + $this->_req_data[ $ref ] = $value; |
|
3432 | + } |
|
3433 | + return array_merge($this->_req_data, $new_route_data); |
|
3434 | + } |
|
3435 | + |
|
3436 | + |
|
3437 | + /** |
|
3438 | + * _redirect_after_action |
|
3439 | + * |
|
3440 | + * @param int $success - whether success was for two or more records, or just one, or none |
|
3441 | + * @param string $what - what the action was performed on |
|
3442 | + * @param string $action_desc - what was done ie: updated, deleted, etc |
|
3443 | + * @param array $query_args - an array of query_args to be added to the URL to redirect to after the admin |
|
3444 | + * action is completed |
|
3445 | + * @param BOOL $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to |
|
3446 | + * override this so that they show. |
|
3447 | + * @return void |
|
3448 | + * @throws EE_Error |
|
3449 | + */ |
|
3450 | + protected function _redirect_after_action( |
|
3451 | + $success = 0, |
|
3452 | + $what = 'item', |
|
3453 | + $action_desc = 'processed', |
|
3454 | + $query_args = array(), |
|
3455 | + $override_overwrite = false |
|
3456 | + ) { |
|
3457 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
3458 | + // class name for actions/filters. |
|
3459 | + $classname = get_class($this); |
|
3460 | + // set redirect url. |
|
3461 | + // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route, |
|
3462 | + // otherwise we go with whatever is set as the _admin_base_url |
|
3463 | + $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
|
3464 | + $notices = EE_Error::get_notices(false); |
|
3465 | + // overwrite default success messages //BUT ONLY if overwrite not overridden |
|
3466 | + if (! $override_overwrite || ! empty($notices['errors'])) { |
|
3467 | + EE_Error::overwrite_success(); |
|
3468 | + } |
|
3469 | + if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
3470 | + // how many records affected ? more than one record ? or just one ? |
|
3471 | + if ($success > 1) { |
|
3472 | + // set plural msg |
|
3473 | + EE_Error::add_success( |
|
3474 | + sprintf( |
|
3475 | + esc_html__('The "%s" have been successfully %s.', 'event_espresso'), |
|
3476 | + $what, |
|
3477 | + $action_desc |
|
3478 | + ), |
|
3479 | + __FILE__, |
|
3480 | + __FUNCTION__, |
|
3481 | + __LINE__ |
|
3482 | + ); |
|
3483 | + } elseif ($success === 1) { |
|
3484 | + // set singular msg |
|
3485 | + EE_Error::add_success( |
|
3486 | + sprintf( |
|
3487 | + esc_html__('The "%s" has been successfully %s.', 'event_espresso'), |
|
3488 | + $what, |
|
3489 | + $action_desc |
|
3490 | + ), |
|
3491 | + __FILE__, |
|
3492 | + __FUNCTION__, |
|
3493 | + __LINE__ |
|
3494 | + ); |
|
3495 | + } |
|
3496 | + } |
|
3497 | + // check that $query_args isn't something crazy |
|
3498 | + if (! is_array($query_args)) { |
|
3499 | + $query_args = array(); |
|
3500 | + } |
|
3501 | + /** |
|
3502 | + * Allow injecting actions before the query_args are modified for possible different |
|
3503 | + * redirections on save and close actions |
|
3504 | + * |
|
3505 | + * @since 4.2.0 |
|
3506 | + * @param array $query_args The original query_args array coming into the |
|
3507 | + * method. |
|
3508 | + */ |
|
3509 | + do_action( |
|
3510 | + "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}", |
|
3511 | + $query_args |
|
3512 | + ); |
|
3513 | + // calculate where we're going (if we have a "save and close" button pushed) |
|
3514 | + if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) { |
|
3515 | + // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce |
|
3516 | + $parsed_url = parse_url($this->_req_data['save_and_close_referrer']); |
|
3517 | + // regenerate query args array from referrer URL |
|
3518 | + parse_str($parsed_url['query'], $query_args); |
|
3519 | + // correct page and action will be in the query args now |
|
3520 | + $redirect_url = admin_url('admin.php'); |
|
3521 | + } |
|
3522 | + // merge any default query_args set in _default_route_query_args property |
|
3523 | + if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
3524 | + $args_to_merge = array(); |
|
3525 | + foreach ($this->_default_route_query_args as $query_param => $query_value) { |
|
3526 | + // is there a wp_referer array in our _default_route_query_args property? |
|
3527 | + if ($query_param === 'wp_referer') { |
|
3528 | + $query_value = (array) $query_value; |
|
3529 | + foreach ($query_value as $reference => $value) { |
|
3530 | + if (strpos($reference, 'nonce') !== false) { |
|
3531 | + continue; |
|
3532 | + } |
|
3533 | + // finally we will override any arguments in the referer with |
|
3534 | + // what might be set on the _default_route_query_args array. |
|
3535 | + if (isset($this->_default_route_query_args[ $reference ])) { |
|
3536 | + $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
3537 | + } else { |
|
3538 | + $args_to_merge[ $reference ] = urlencode($value); |
|
3539 | + } |
|
3540 | + } |
|
3541 | + continue; |
|
3542 | + } |
|
3543 | + $args_to_merge[ $query_param ] = $query_value; |
|
3544 | + } |
|
3545 | + // now let's merge these arguments but override with what was specifically sent in to the |
|
3546 | + // redirect. |
|
3547 | + $query_args = array_merge($args_to_merge, $query_args); |
|
3548 | + } |
|
3549 | + $this->_process_notices($query_args); |
|
3550 | + // generate redirect url |
|
3551 | + // if redirecting to anything other than the main page, add a nonce |
|
3552 | + if (isset($query_args['action'])) { |
|
3553 | + // manually generate wp_nonce and merge that with the query vars |
|
3554 | + // becuz the wp_nonce_url function wrecks havoc on some vars |
|
3555 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
3556 | + } |
|
3557 | + // we're adding some hooks and filters in here for processing any things just before redirects |
|
3558 | + // (example: an admin page has done an insert or update and we want to run something after that). |
|
3559 | + do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
3560 | + $redirect_url = apply_filters( |
|
3561 | + 'FHEE_redirect_' . $classname . $this->_req_action, |
|
3562 | + self::add_query_args_and_nonce($query_args, $redirect_url), |
|
3563 | + $query_args |
|
3564 | + ); |
|
3565 | + // check if we're doing ajax. If we are then lets just return the results and js can handle how it wants. |
|
3566 | + if (defined('DOING_AJAX')) { |
|
3567 | + $default_data = array( |
|
3568 | + 'close' => true, |
|
3569 | + 'redirect_url' => $redirect_url, |
|
3570 | + 'where' => 'main', |
|
3571 | + 'what' => 'append', |
|
3572 | + ); |
|
3573 | + $this->_template_args['success'] = $success; |
|
3574 | + $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge( |
|
3575 | + $default_data, |
|
3576 | + $this->_template_args['data'] |
|
3577 | + ) : $default_data; |
|
3578 | + $this->_return_json(); |
|
3579 | + } |
|
3580 | + wp_safe_redirect($redirect_url); |
|
3581 | + exit(); |
|
3582 | + } |
|
3583 | + |
|
3584 | + |
|
3585 | + /** |
|
3586 | + * process any notices before redirecting (or returning ajax request) |
|
3587 | + * This method sets the $this->_template_args['notices'] attribute; |
|
3588 | + * |
|
3589 | + * @param array $query_args any query args that need to be used for notice transient ('action') |
|
3590 | + * @param bool $skip_route_verify This is typically used when we are processing notices REALLY early and |
|
3591 | + * page_routes haven't been defined yet. |
|
3592 | + * @param bool $sticky_notices This is used to flag that regardless of whether this is doing_ajax or not, we |
|
3593 | + * still save a transient for the notice. |
|
3594 | + * @return void |
|
3595 | + * @throws EE_Error |
|
3596 | + */ |
|
3597 | + protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true) |
|
3598 | + { |
|
3599 | + // first let's set individual error properties if doing_ajax and the properties aren't already set. |
|
3600 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
3601 | + $notices = EE_Error::get_notices(false); |
|
3602 | + if (empty($this->_template_args['success'])) { |
|
3603 | + $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false; |
|
3604 | + } |
|
3605 | + if (empty($this->_template_args['errors'])) { |
|
3606 | + $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false; |
|
3607 | + } |
|
3608 | + if (empty($this->_template_args['attention'])) { |
|
3609 | + $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false; |
|
3610 | + } |
|
3611 | + } |
|
3612 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
3613 | + // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
|
3614 | + if (! defined('DOING_AJAX') || $sticky_notices) { |
|
3615 | + $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
|
3616 | + $this->_add_transient( |
|
3617 | + $route, |
|
3618 | + $this->_template_args['notices'], |
|
3619 | + true, |
|
3620 | + $skip_route_verify |
|
3621 | + ); |
|
3622 | + } |
|
3623 | + } |
|
3624 | + |
|
3625 | + |
|
3626 | + /** |
|
3627 | + * get_action_link_or_button |
|
3628 | + * returns the button html for adding, editing, or deleting an item (depending on given type) |
|
3629 | + * |
|
3630 | + * @param string $action use this to indicate which action the url is generated with. |
|
3631 | + * @param string $type accepted strings must be defined in the $_labels['button'] array(as the key) |
|
3632 | + * property. |
|
3633 | + * @param array $extra_request if the button requires extra params you can include them in $key=>$value pairs. |
|
3634 | + * @param string $class Use this to give the class for the button. Defaults to 'button-primary' |
|
3635 | + * @param string $base_url If this is not provided |
|
3636 | + * the _admin_base_url will be used as the default for the button base_url. |
|
3637 | + * Otherwise this value will be used. |
|
3638 | + * @param bool $exclude_nonce If true then no nonce will be in the generated button link. |
|
3639 | + * @return string |
|
3640 | + * @throws InvalidArgumentException |
|
3641 | + * @throws InvalidInterfaceException |
|
3642 | + * @throws InvalidDataTypeException |
|
3643 | + * @throws EE_Error |
|
3644 | + */ |
|
3645 | + public function get_action_link_or_button( |
|
3646 | + $action, |
|
3647 | + $type = 'add', |
|
3648 | + $extra_request = array(), |
|
3649 | + $class = 'button-primary', |
|
3650 | + $base_url = '', |
|
3651 | + $exclude_nonce = false |
|
3652 | + ) { |
|
3653 | + // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
|
3654 | + if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
3655 | + throw new EE_Error( |
|
3656 | + sprintf( |
|
3657 | + esc_html__( |
|
3658 | + 'There is no page route for given action for the button. This action was given: %s', |
|
3659 | + 'event_espresso' |
|
3660 | + ), |
|
3661 | + $action |
|
3662 | + ) |
|
3663 | + ); |
|
3664 | + } |
|
3665 | + if (! isset($this->_labels['buttons'][ $type ])) { |
|
3666 | + throw new EE_Error( |
|
3667 | + sprintf( |
|
3668 | + __( |
|
3669 | + 'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.', |
|
3670 | + 'event_espresso' |
|
3671 | + ), |
|
3672 | + $type |
|
3673 | + ) |
|
3674 | + ); |
|
3675 | + } |
|
3676 | + // finally check user access for this button. |
|
3677 | + $has_access = $this->check_user_access($action, true); |
|
3678 | + if (! $has_access) { |
|
3679 | + return ''; |
|
3680 | + } |
|
3681 | + $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
|
3682 | + $query_args = array( |
|
3683 | + 'action' => $action, |
|
3684 | + ); |
|
3685 | + // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
|
3686 | + if (! empty($extra_request)) { |
|
3687 | + $query_args = array_merge($extra_request, $query_args); |
|
3688 | + } |
|
3689 | + $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
|
3690 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
3691 | + } |
|
3692 | + |
|
3693 | + |
|
3694 | + /** |
|
3695 | + * _per_page_screen_option |
|
3696 | + * Utility function for adding in a per_page_option in the screen_options_dropdown. |
|
3697 | + * |
|
3698 | + * @return void |
|
3699 | + * @throws InvalidArgumentException |
|
3700 | + * @throws InvalidInterfaceException |
|
3701 | + * @throws InvalidDataTypeException |
|
3702 | + */ |
|
3703 | + protected function _per_page_screen_option() |
|
3704 | + { |
|
3705 | + $option = 'per_page'; |
|
3706 | + $args = array( |
|
3707 | + 'label' => apply_filters( |
|
3708 | + 'FHEE__EE_Admin_Page___per_page_screen_options___label', |
|
3709 | + $this->_admin_page_title, |
|
3710 | + $this |
|
3711 | + ), |
|
3712 | + 'default' => (int) apply_filters( |
|
3713 | + 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
|
3714 | + 20 |
|
3715 | + ), |
|
3716 | + 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
3717 | + ); |
|
3718 | + // ONLY add the screen option if the user has access to it. |
|
3719 | + if ($this->check_user_access($this->_current_view, true)) { |
|
3720 | + add_screen_option($option, $args); |
|
3721 | + } |
|
3722 | + } |
|
3723 | + |
|
3724 | + |
|
3725 | + /** |
|
3726 | + * set_per_page_screen_option |
|
3727 | + * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page. |
|
3728 | + * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than |
|
3729 | + * admin_menu. |
|
3730 | + * |
|
3731 | + * @return void |
|
3732 | + */ |
|
3733 | + private function _set_per_page_screen_options() |
|
3734 | + { |
|
3735 | + if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
|
3736 | + check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
|
3737 | + if (! $user = wp_get_current_user()) { |
|
3738 | + return; |
|
3739 | + } |
|
3740 | + $option = $_POST['wp_screen_options']['option']; |
|
3741 | + $value = $_POST['wp_screen_options']['value']; |
|
3742 | + if ($option != sanitize_key($option)) { |
|
3743 | + return; |
|
3744 | + } |
|
3745 | + $map_option = $option; |
|
3746 | + $option = str_replace('-', '_', $option); |
|
3747 | + switch ($map_option) { |
|
3748 | + case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
3749 | + $value = (int) $value; |
|
3750 | + $max_value = apply_filters( |
|
3751 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
|
3752 | + 999, |
|
3753 | + $this->_current_page, |
|
3754 | + $this->_current_view |
|
3755 | + ); |
|
3756 | + if ($value < 1) { |
|
3757 | + return; |
|
3758 | + } |
|
3759 | + $value = min($value, $max_value); |
|
3760 | + break; |
|
3761 | + default: |
|
3762 | + $value = apply_filters( |
|
3763 | + 'FHEE__EE_Admin_Page___set_per_page_screen_options__value', |
|
3764 | + false, |
|
3765 | + $option, |
|
3766 | + $value |
|
3767 | + ); |
|
3768 | + if (false === $value) { |
|
3769 | + return; |
|
3770 | + } |
|
3771 | + break; |
|
3772 | + } |
|
3773 | + update_user_meta($user->ID, $option, $value); |
|
3774 | + wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer())); |
|
3775 | + exit; |
|
3776 | + } |
|
3777 | + } |
|
3778 | + |
|
3779 | + |
|
3780 | + /** |
|
3781 | + * This just allows for setting the $_template_args property if it needs to be set outside the object |
|
3782 | + * |
|
3783 | + * @param array $data array that will be assigned to template args. |
|
3784 | + */ |
|
3785 | + public function set_template_args($data) |
|
3786 | + { |
|
3787 | + $this->_template_args = array_merge($this->_template_args, (array) $data); |
|
3788 | + } |
|
3789 | + |
|
3790 | + |
|
3791 | + /** |
|
3792 | + * This makes available the WP transient system for temporarily moving data between routes |
|
3793 | + * |
|
3794 | + * @param string $route the route that should receive the transient |
|
3795 | + * @param array $data the data that gets sent |
|
3796 | + * @param bool $notices If this is for notices then we use this to indicate so, otherwise its just a |
|
3797 | + * normal route transient. |
|
3798 | + * @param bool $skip_route_verify Used to indicate we want to skip route verification. This is usually ONLY used |
|
3799 | + * when we are adding a transient before page_routes have been defined. |
|
3800 | + * @return void |
|
3801 | + * @throws EE_Error |
|
3802 | + */ |
|
3803 | + protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
|
3804 | + { |
|
3805 | + $user_id = get_current_user_id(); |
|
3806 | + if (! $skip_route_verify) { |
|
3807 | + $this->_verify_route($route); |
|
3808 | + } |
|
3809 | + // now let's set the string for what kind of transient we're setting |
|
3810 | + $transient = $notices |
|
3811 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
3812 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
3813 | + $data = $notices ? array('notices' => $data) : $data; |
|
3814 | + // is there already a transient for this route? If there is then let's ADD to that transient |
|
3815 | + $existing = is_multisite() && is_network_admin() |
|
3816 | + ? get_site_transient($transient) |
|
3817 | + : get_transient($transient); |
|
3818 | + if ($existing) { |
|
3819 | + $data = array_merge((array) $data, (array) $existing); |
|
3820 | + } |
|
3821 | + if (is_multisite() && is_network_admin()) { |
|
3822 | + set_site_transient($transient, $data, 8); |
|
3823 | + } else { |
|
3824 | + set_transient($transient, $data, 8); |
|
3825 | + } |
|
3826 | + } |
|
3827 | + |
|
3828 | + |
|
3829 | + /** |
|
3830 | + * this retrieves the temporary transient that has been set for moving data between routes. |
|
3831 | + * |
|
3832 | + * @param bool $notices true we get notices transient. False we just return normal route transient |
|
3833 | + * @param string $route |
|
3834 | + * @return mixed data |
|
3835 | + */ |
|
3836 | + protected function _get_transient($notices = false, $route = '') |
|
3837 | + { |
|
3838 | + $user_id = get_current_user_id(); |
|
3839 | + $route = ! $route ? $this->_req_action : $route; |
|
3840 | + $transient = $notices |
|
3841 | + ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
3842 | + : 'rte_tx_' . $route . '_' . $user_id; |
|
3843 | + $data = is_multisite() && is_network_admin() |
|
3844 | + ? get_site_transient($transient) |
|
3845 | + : get_transient($transient); |
|
3846 | + // delete transient after retrieval (just in case it hasn't expired); |
|
3847 | + if (is_multisite() && is_network_admin()) { |
|
3848 | + delete_site_transient($transient); |
|
3849 | + } else { |
|
3850 | + delete_transient($transient); |
|
3851 | + } |
|
3852 | + return $notices && isset($data['notices']) ? $data['notices'] : $data; |
|
3853 | + } |
|
3854 | + |
|
3855 | + |
|
3856 | + /** |
|
3857 | + * The purpose of this method is just to run garbage collection on any EE transients that might have expired but |
|
3858 | + * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the |
|
3859 | + * default route callback on the EE_Admin page you want it run.) |
|
3860 | + * |
|
3861 | + * @return void |
|
3862 | + */ |
|
3863 | + protected function _transient_garbage_collection() |
|
3864 | + { |
|
3865 | + global $wpdb; |
|
3866 | + // retrieve all existing transients |
|
3867 | + $query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'"; |
|
3868 | + if ($results = $wpdb->get_results($query)) { |
|
3869 | + foreach ($results as $result) { |
|
3870 | + $transient = str_replace('_transient_', '', $result->option_name); |
|
3871 | + get_transient($transient); |
|
3872 | + if (is_multisite() && is_network_admin()) { |
|
3873 | + get_site_transient($transient); |
|
3874 | + } |
|
3875 | + } |
|
3876 | + } |
|
3877 | + } |
|
3878 | + |
|
3879 | + |
|
3880 | + /** |
|
3881 | + * get_view |
|
3882 | + * |
|
3883 | + * @return string content of _view property |
|
3884 | + */ |
|
3885 | + public function get_view() |
|
3886 | + { |
|
3887 | + return $this->_view; |
|
3888 | + } |
|
3889 | + |
|
3890 | + |
|
3891 | + /** |
|
3892 | + * getter for the protected $_views property |
|
3893 | + * |
|
3894 | + * @return array |
|
3895 | + */ |
|
3896 | + public function get_views() |
|
3897 | + { |
|
3898 | + return $this->_views; |
|
3899 | + } |
|
3900 | + |
|
3901 | + |
|
3902 | + /** |
|
3903 | + * get_current_page |
|
3904 | + * |
|
3905 | + * @return string _current_page property value |
|
3906 | + */ |
|
3907 | + public function get_current_page() |
|
3908 | + { |
|
3909 | + return $this->_current_page; |
|
3910 | + } |
|
3911 | + |
|
3912 | + |
|
3913 | + /** |
|
3914 | + * get_current_view |
|
3915 | + * |
|
3916 | + * @return string _current_view property value |
|
3917 | + */ |
|
3918 | + public function get_current_view() |
|
3919 | + { |
|
3920 | + return $this->_current_view; |
|
3921 | + } |
|
3922 | + |
|
3923 | + |
|
3924 | + /** |
|
3925 | + * get_current_screen |
|
3926 | + * |
|
3927 | + * @return object The current WP_Screen object |
|
3928 | + */ |
|
3929 | + public function get_current_screen() |
|
3930 | + { |
|
3931 | + return $this->_current_screen; |
|
3932 | + } |
|
3933 | + |
|
3934 | + |
|
3935 | + /** |
|
3936 | + * get_current_page_view_url |
|
3937 | + * |
|
3938 | + * @return string This returns the url for the current_page_view. |
|
3939 | + */ |
|
3940 | + public function get_current_page_view_url() |
|
3941 | + { |
|
3942 | + return $this->_current_page_view_url; |
|
3943 | + } |
|
3944 | + |
|
3945 | + |
|
3946 | + /** |
|
3947 | + * just returns the _req_data property |
|
3948 | + * |
|
3949 | + * @return array |
|
3950 | + */ |
|
3951 | + public function get_request_data() |
|
3952 | + { |
|
3953 | + return $this->_req_data; |
|
3954 | + } |
|
3955 | + |
|
3956 | + |
|
3957 | + /** |
|
3958 | + * returns the _req_data protected property |
|
3959 | + * |
|
3960 | + * @return string |
|
3961 | + */ |
|
3962 | + public function get_req_action() |
|
3963 | + { |
|
3964 | + return $this->_req_action; |
|
3965 | + } |
|
3966 | + |
|
3967 | + |
|
3968 | + /** |
|
3969 | + * @return bool value of $_is_caf property |
|
3970 | + */ |
|
3971 | + public function is_caf() |
|
3972 | + { |
|
3973 | + return $this->_is_caf; |
|
3974 | + } |
|
3975 | + |
|
3976 | + |
|
3977 | + /** |
|
3978 | + * @return mixed |
|
3979 | + */ |
|
3980 | + public function default_espresso_metaboxes() |
|
3981 | + { |
|
3982 | + return $this->_default_espresso_metaboxes; |
|
3983 | + } |
|
3984 | + |
|
3985 | + |
|
3986 | + /** |
|
3987 | + * @return mixed |
|
3988 | + */ |
|
3989 | + public function admin_base_url() |
|
3990 | + { |
|
3991 | + return $this->_admin_base_url; |
|
3992 | + } |
|
3993 | + |
|
3994 | + |
|
3995 | + /** |
|
3996 | + * @return mixed |
|
3997 | + */ |
|
3998 | + public function wp_page_slug() |
|
3999 | + { |
|
4000 | + return $this->_wp_page_slug; |
|
4001 | + } |
|
4002 | + |
|
4003 | + |
|
4004 | + /** |
|
4005 | + * updates espresso configuration settings |
|
4006 | + * |
|
4007 | + * @param string $tab |
|
4008 | + * @param EE_Config_Base|EE_Config $config |
|
4009 | + * @param string $file file where error occurred |
|
4010 | + * @param string $func function where error occurred |
|
4011 | + * @param string $line line no where error occurred |
|
4012 | + * @return boolean |
|
4013 | + */ |
|
4014 | + protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '') |
|
4015 | + { |
|
4016 | + // remove any options that are NOT going to be saved with the config settings. |
|
4017 | + if (isset($config->core->ee_ueip_optin)) { |
|
4018 | + // TODO: remove the following two lines and make sure values are migrated from 3.1 |
|
4019 | + update_option('ee_ueip_optin', $config->core->ee_ueip_optin); |
|
4020 | + update_option('ee_ueip_has_notified', true); |
|
4021 | + } |
|
4022 | + // and save it (note we're also doing the network save here) |
|
4023 | + $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true; |
|
4024 | + $config_saved = EE_Config::instance()->update_espresso_config(false, false); |
|
4025 | + if ($config_saved && $net_saved) { |
|
4026 | + EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab)); |
|
4027 | + return true; |
|
4028 | + } |
|
4029 | + EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line); |
|
4030 | + return false; |
|
4031 | + } |
|
4032 | + |
|
4033 | + |
|
4034 | + /** |
|
4035 | + * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument. |
|
4036 | + * |
|
4037 | + * @return array |
|
4038 | + */ |
|
4039 | + public function get_yes_no_values() |
|
4040 | + { |
|
4041 | + return $this->_yes_no_values; |
|
4042 | + } |
|
4043 | + |
|
4044 | + |
|
4045 | + protected function _get_dir() |
|
4046 | + { |
|
4047 | + $reflector = new ReflectionClass(get_class($this)); |
|
4048 | + return dirname($reflector->getFileName()); |
|
4049 | + } |
|
4050 | + |
|
4051 | + |
|
4052 | + /** |
|
4053 | + * A helper for getting a "next link". |
|
4054 | + * |
|
4055 | + * @param string $url The url to link to |
|
4056 | + * @param string $class The class to use. |
|
4057 | + * @return string |
|
4058 | + */ |
|
4059 | + protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
|
4060 | + { |
|
4061 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
4062 | + } |
|
4063 | + |
|
4064 | + |
|
4065 | + /** |
|
4066 | + * A helper for getting a "previous link". |
|
4067 | + * |
|
4068 | + * @param string $url The url to link to |
|
4069 | + * @param string $class The class to use. |
|
4070 | + * @return string |
|
4071 | + */ |
|
4072 | + protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
|
4073 | + { |
|
4074 | + return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
4075 | + } |
|
4076 | + |
|
4077 | + |
|
4078 | + |
|
4079 | + |
|
4080 | + |
|
4081 | + |
|
4082 | + |
|
4083 | + // below are some messages related methods that should be available across the EE_Admin system. Note, these methods are NOT page specific |
|
4084 | + |
|
4085 | + |
|
4086 | + /** |
|
4087 | + * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller |
|
4088 | + * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the |
|
4089 | + * _req_data array. |
|
4090 | + * |
|
4091 | + * @return bool success/fail |
|
4092 | + * @throws EE_Error |
|
4093 | + * @throws InvalidArgumentException |
|
4094 | + * @throws ReflectionException |
|
4095 | + * @throws InvalidDataTypeException |
|
4096 | + * @throws InvalidInterfaceException |
|
4097 | + */ |
|
4098 | + protected function _process_resend_registration() |
|
4099 | + { |
|
4100 | + $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data); |
|
4101 | + do_action( |
|
4102 | + 'AHEE__EE_Admin_Page___process_resend_registration', |
|
4103 | + $this->_template_args['success'], |
|
4104 | + $this->_req_data |
|
4105 | + ); |
|
4106 | + return $this->_template_args['success']; |
|
4107 | + } |
|
4108 | + |
|
4109 | + |
|
4110 | + /** |
|
4111 | + * This automatically processes any payment message notifications when manual payment has been applied. |
|
4112 | + * |
|
4113 | + * @param \EE_Payment $payment |
|
4114 | + * @return bool success/fail |
|
4115 | + */ |
|
4116 | + protected function _process_payment_notification(EE_Payment $payment) |
|
4117 | + { |
|
4118 | + add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true'); |
|
4119 | + do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment); |
|
4120 | + $this->_template_args['success'] = apply_filters( |
|
4121 | + 'FHEE__EE_Admin_Page___process_admin_payment_notification__success', |
|
4122 | + false, |
|
4123 | + $payment |
|
4124 | + ); |
|
4125 | + return $this->_template_args['success']; |
|
4126 | + } |
|
4127 | 4127 | } |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | ); |
501 | 501 | global $ee_menu_slugs; |
502 | 502 | $ee_menu_slugs = (array) $ee_menu_slugs; |
503 | - if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) { |
|
503 | + if ( ! defined('DOING_AJAX') && ( ! $this->_current_page || ! isset($ee_menu_slugs[$this->_current_page]))) { |
|
504 | 504 | return; |
505 | 505 | } |
506 | 506 | // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | ? $this->_req_data['route'] |
525 | 525 | : $this->_req_action; |
526 | 526 | $this->_current_view = $this->_req_action; |
527 | - $this->_req_nonce = $this->_req_action . '_nonce'; |
|
527 | + $this->_req_nonce = $this->_req_action.'_nonce'; |
|
528 | 528 | $this->_define_page_props(); |
529 | 529 | $this->_current_page_view_url = add_query_arg( |
530 | 530 | array('page' => $this->_current_page, 'action' => $this->_current_view), |
@@ -558,21 +558,21 @@ discard block |
||
558 | 558 | } |
559 | 559 | // filter routes and page_config so addons can add their stuff. Filtering done per class |
560 | 560 | $this->_page_routes = apply_filters( |
561 | - 'FHEE__' . get_class($this) . '__page_setup__page_routes', |
|
561 | + 'FHEE__'.get_class($this).'__page_setup__page_routes', |
|
562 | 562 | $this->_page_routes, |
563 | 563 | $this |
564 | 564 | ); |
565 | 565 | $this->_page_config = apply_filters( |
566 | - 'FHEE__' . get_class($this) . '__page_setup__page_config', |
|
566 | + 'FHEE__'.get_class($this).'__page_setup__page_config', |
|
567 | 567 | $this->_page_config, |
568 | 568 | $this |
569 | 569 | ); |
570 | 570 | // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present |
571 | 571 | // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action |
572 | - if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) { |
|
572 | + if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view)) { |
|
573 | 573 | add_action( |
574 | 574 | 'AHEE__EE_Admin_Page__route_admin_request', |
575 | - array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view), |
|
575 | + array($this, 'AHEE__EE_Admin_Page__route_admin_request_'.$this->_current_view), |
|
576 | 576 | 10, |
577 | 577 | 2 |
578 | 578 | ); |
@@ -585,8 +585,8 @@ discard block |
||
585 | 585 | if ($this->_is_UI_request) { |
586 | 586 | // admin_init stuff - global, all views for this page class, specific view |
587 | 587 | add_action('admin_init', array($this, 'admin_init'), 10); |
588 | - if (method_exists($this, 'admin_init_' . $this->_current_view)) { |
|
589 | - add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15); |
|
588 | + if (method_exists($this, 'admin_init_'.$this->_current_view)) { |
|
589 | + add_action('admin_init', array($this, 'admin_init_'.$this->_current_view), 15); |
|
590 | 590 | } |
591 | 591 | } else { |
592 | 592 | // hijack regular WP loading and route admin request immediately |
@@ -606,12 +606,12 @@ discard block |
||
606 | 606 | */ |
607 | 607 | private function _do_other_page_hooks() |
608 | 608 | { |
609 | - $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array()); |
|
609 | + $registered_pages = apply_filters('FHEE_do_other_page_hooks_'.$this->page_slug, array()); |
|
610 | 610 | foreach ($registered_pages as $page) { |
611 | 611 | // now let's setup the file name and class that should be present |
612 | 612 | $classname = str_replace('.class.php', '', $page); |
613 | 613 | // autoloaders should take care of loading file |
614 | - if (! class_exists($classname)) { |
|
614 | + if ( ! class_exists($classname)) { |
|
615 | 615 | $error_msg[] = sprintf( |
616 | 616 | esc_html__( |
617 | 617 | 'Something went wrong with loading the %s admin hooks page.', |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | ), |
629 | 629 | $page, |
630 | 630 | '<br />', |
631 | - '<strong>' . $classname . '</strong>' |
|
631 | + '<strong>'.$classname.'</strong>' |
|
632 | 632 | ); |
633 | 633 | throw new EE_Error(implode('||', $error_msg)); |
634 | 634 | } |
@@ -668,13 +668,13 @@ discard block |
||
668 | 668 | // load admin_notices - global, page class, and view specific |
669 | 669 | add_action('admin_notices', array($this, 'admin_notices_global'), 5); |
670 | 670 | add_action('admin_notices', array($this, 'admin_notices'), 10); |
671 | - if (method_exists($this, 'admin_notices_' . $this->_current_view)) { |
|
672 | - add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15); |
|
671 | + if (method_exists($this, 'admin_notices_'.$this->_current_view)) { |
|
672 | + add_action('admin_notices', array($this, 'admin_notices_'.$this->_current_view), 15); |
|
673 | 673 | } |
674 | 674 | // load network admin_notices - global, page class, and view specific |
675 | 675 | add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5); |
676 | - if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) { |
|
677 | - add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view)); |
|
676 | + if (method_exists($this, 'network_admin_notices_'.$this->_current_view)) { |
|
677 | + add_action('network_admin_notices', array($this, 'network_admin_notices_'.$this->_current_view)); |
|
678 | 678 | } |
679 | 679 | // this will save any per_page screen options if they are present |
680 | 680 | $this->_set_per_page_screen_options(); |
@@ -796,7 +796,7 @@ discard block |
||
796 | 796 | protected function _verify_routes() |
797 | 797 | { |
798 | 798 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
799 | - if (! $this->_current_page && ! defined('DOING_AJAX')) { |
|
799 | + if ( ! $this->_current_page && ! defined('DOING_AJAX')) { |
|
800 | 800 | return false; |
801 | 801 | } |
802 | 802 | $this->_route = false; |
@@ -808,7 +808,7 @@ discard block |
||
808 | 808 | $this->_admin_page_title |
809 | 809 | ); |
810 | 810 | // developer error msg |
811 | - $error_msg .= '||' . $error_msg |
|
811 | + $error_msg .= '||'.$error_msg |
|
812 | 812 | . esc_html__( |
813 | 813 | ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.', |
814 | 814 | 'event_espresso' |
@@ -817,9 +817,9 @@ discard block |
||
817 | 817 | } |
818 | 818 | // and that the requested page route exists |
819 | 819 | if (array_key_exists($this->_req_action, $this->_page_routes)) { |
820 | - $this->_route = $this->_page_routes[ $this->_req_action ]; |
|
821 | - $this->_route_config = isset($this->_page_config[ $this->_req_action ]) |
|
822 | - ? $this->_page_config[ $this->_req_action ] : array(); |
|
820 | + $this->_route = $this->_page_routes[$this->_req_action]; |
|
821 | + $this->_route_config = isset($this->_page_config[$this->_req_action]) |
|
822 | + ? $this->_page_config[$this->_req_action] : array(); |
|
823 | 823 | } else { |
824 | 824 | // user error msg |
825 | 825 | $error_msg = sprintf( |
@@ -830,7 +830,7 @@ discard block |
||
830 | 830 | $this->_admin_page_title |
831 | 831 | ); |
832 | 832 | // developer error msg |
833 | - $error_msg .= '||' . $error_msg |
|
833 | + $error_msg .= '||'.$error_msg |
|
834 | 834 | . sprintf( |
835 | 835 | esc_html__( |
836 | 836 | ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.', |
@@ -841,7 +841,7 @@ discard block |
||
841 | 841 | throw new EE_Error($error_msg); |
842 | 842 | } |
843 | 843 | // and that a default route exists |
844 | - if (! array_key_exists('default', $this->_page_routes)) { |
|
844 | + if ( ! array_key_exists('default', $this->_page_routes)) { |
|
845 | 845 | // user error msg |
846 | 846 | $error_msg = sprintf( |
847 | 847 | esc_html__( |
@@ -851,7 +851,7 @@ discard block |
||
851 | 851 | $this->_admin_page_title |
852 | 852 | ); |
853 | 853 | // developer error msg |
854 | - $error_msg .= '||' . $error_msg |
|
854 | + $error_msg .= '||'.$error_msg |
|
855 | 855 | . esc_html__( |
856 | 856 | ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.', |
857 | 857 | 'event_espresso' |
@@ -890,7 +890,7 @@ discard block |
||
890 | 890 | $this->_admin_page_title |
891 | 891 | ); |
892 | 892 | // developer error msg |
893 | - $error_msg .= '||' . $error_msg |
|
893 | + $error_msg .= '||'.$error_msg |
|
894 | 894 | . sprintf( |
895 | 895 | esc_html__( |
896 | 896 | ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property', |
@@ -915,7 +915,7 @@ discard block |
||
915 | 915 | protected function _verify_nonce($nonce, $nonce_ref) |
916 | 916 | { |
917 | 917 | // verify nonce against expected value |
918 | - if (! wp_verify_nonce($nonce, $nonce_ref)) { |
|
918 | + if ( ! wp_verify_nonce($nonce, $nonce_ref)) { |
|
919 | 919 | // these are not the droids you are looking for !!! |
920 | 920 | $msg = sprintf( |
921 | 921 | esc_html__('%sNonce Fail.%s', 'event_espresso'), |
@@ -932,7 +932,7 @@ discard block |
||
932 | 932 | __CLASS__ |
933 | 933 | ); |
934 | 934 | } |
935 | - if (! defined('DOING_AJAX')) { |
|
935 | + if ( ! defined('DOING_AJAX')) { |
|
936 | 936 | wp_die($msg); |
937 | 937 | } else { |
938 | 938 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
@@ -957,7 +957,7 @@ discard block |
||
957 | 957 | */ |
958 | 958 | protected function _route_admin_request() |
959 | 959 | { |
960 | - if (! $this->_is_UI_request) { |
|
960 | + if ( ! $this->_is_UI_request) { |
|
961 | 961 | $this->_verify_routes(); |
962 | 962 | } |
963 | 963 | $nonce_check = isset($this->_route_config['require_nonce']) |
@@ -965,8 +965,8 @@ discard block |
||
965 | 965 | : true; |
966 | 966 | if ($this->_req_action !== 'default' && $nonce_check) { |
967 | 967 | // set nonce from post data |
968 | - $nonce = isset($this->_req_data[ $this->_req_nonce ]) |
|
969 | - ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) |
|
968 | + $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
969 | + ? sanitize_text_field($this->_req_data[$this->_req_nonce]) |
|
970 | 970 | : ''; |
971 | 971 | $this->_verify_nonce($nonce, $this->_req_nonce); |
972 | 972 | } |
@@ -981,7 +981,7 @@ discard block |
||
981 | 981 | $error_msg = ''; |
982 | 982 | // action right before calling route |
983 | 983 | // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request') |
984 | - if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
984 | + if ( ! did_action('AHEE__EE_Admin_Page__route_admin_request')) { |
|
985 | 985 | do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this); |
986 | 986 | } |
987 | 987 | // right before calling the route, let's remove _wp_http_referer from the |
@@ -990,7 +990,7 @@ discard block |
||
990 | 990 | '_wp_http_referer', |
991 | 991 | wp_unslash($_SERVER['REQUEST_URI']) |
992 | 992 | ); |
993 | - if (! empty($func)) { |
|
993 | + if ( ! empty($func)) { |
|
994 | 994 | if (is_array($func)) { |
995 | 995 | list($class, $method) = $func; |
996 | 996 | } elseif (strpos($func, '::') !== false) { |
@@ -999,7 +999,7 @@ discard block |
||
999 | 999 | $class = $this; |
1000 | 1000 | $method = $func; |
1001 | 1001 | } |
1002 | - if (! (is_object($class) && $class === $this)) { |
|
1002 | + if ( ! (is_object($class) && $class === $this)) { |
|
1003 | 1003 | // send along this admin page object for access by addons. |
1004 | 1004 | $args['admin_page_object'] = $this; |
1005 | 1005 | } |
@@ -1039,7 +1039,7 @@ discard block |
||
1039 | 1039 | $method |
1040 | 1040 | ); |
1041 | 1041 | } |
1042 | - if (! empty($error_msg)) { |
|
1042 | + if ( ! empty($error_msg)) { |
|
1043 | 1043 | throw new EE_Error($error_msg); |
1044 | 1044 | } |
1045 | 1045 | } |
@@ -1123,7 +1123,7 @@ discard block |
||
1123 | 1123 | if (strpos($key, 'nonce') !== false) { |
1124 | 1124 | continue; |
1125 | 1125 | } |
1126 | - $args[ 'wp_referer[' . $key . ']' ] = $value; |
|
1126 | + $args['wp_referer['.$key.']'] = $value; |
|
1127 | 1127 | } |
1128 | 1128 | } |
1129 | 1129 | return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce); |
@@ -1163,10 +1163,10 @@ discard block |
||
1163 | 1163 | protected function _add_help_tabs() |
1164 | 1164 | { |
1165 | 1165 | $tour_buttons = ''; |
1166 | - if (isset($this->_page_config[ $this->_req_action ])) { |
|
1167 | - $config = $this->_page_config[ $this->_req_action ]; |
|
1166 | + if (isset($this->_page_config[$this->_req_action])) { |
|
1167 | + $config = $this->_page_config[$this->_req_action]; |
|
1168 | 1168 | // is there a help tour for the current route? if there is let's setup the tour buttons |
1169 | - if (isset($this->_help_tour[ $this->_req_action ])) { |
|
1169 | + if (isset($this->_help_tour[$this->_req_action])) { |
|
1170 | 1170 | $tb = array(); |
1171 | 1171 | $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">'; |
1172 | 1172 | foreach ($this->_help_tour['tours'] as $tour) { |
@@ -1186,7 +1186,7 @@ discard block |
||
1186 | 1186 | // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well. |
1187 | 1187 | if (is_array($config) && isset($config['help_sidebar'])) { |
1188 | 1188 | // check that the callback given is valid |
1189 | - if (! method_exists($this, $config['help_sidebar'])) { |
|
1189 | + if ( ! method_exists($this, $config['help_sidebar'])) { |
|
1190 | 1190 | throw new EE_Error( |
1191 | 1191 | sprintf( |
1192 | 1192 | esc_html__( |
@@ -1199,7 +1199,7 @@ discard block |
||
1199 | 1199 | ); |
1200 | 1200 | } |
1201 | 1201 | $content = apply_filters( |
1202 | - 'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar', |
|
1202 | + 'FHEE__'.get_class($this).'__add_help_tabs__help_sidebar', |
|
1203 | 1203 | $this->{$config['help_sidebar']}() |
1204 | 1204 | ); |
1205 | 1205 | $content .= $tour_buttons; // add help tour buttons. |
@@ -1207,27 +1207,27 @@ discard block |
||
1207 | 1207 | $this->_current_screen->set_help_sidebar($content); |
1208 | 1208 | } |
1209 | 1209 | // if we DON'T have config help sidebar and there ARE tour buttons then we'll just add the tour buttons to the sidebar. |
1210 | - if (! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
1210 | + if ( ! isset($config['help_sidebar']) && ! empty($tour_buttons)) { |
|
1211 | 1211 | $this->_current_screen->set_help_sidebar($tour_buttons); |
1212 | 1212 | } |
1213 | 1213 | // handle if no help_tabs are set so the sidebar will still show for the help tour buttons |
1214 | - if (! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
1214 | + if ( ! isset($config['help_tabs']) && ! empty($tour_buttons)) { |
|
1215 | 1215 | $_ht['id'] = $this->page_slug; |
1216 | 1216 | $_ht['title'] = esc_html__('Help Tours', 'event_espresso'); |
1217 | 1217 | $_ht['content'] = '<p>' |
1218 | 1218 | . esc_html__( |
1219 | 1219 | 'The buttons to the right allow you to start/restart any help tours available for this page', |
1220 | 1220 | 'event_espresso' |
1221 | - ) . '</p>'; |
|
1221 | + ).'</p>'; |
|
1222 | 1222 | $this->_current_screen->add_help_tab($_ht); |
1223 | 1223 | } |
1224 | - if (! isset($config['help_tabs'])) { |
|
1224 | + if ( ! isset($config['help_tabs'])) { |
|
1225 | 1225 | return; |
1226 | 1226 | } //no help tabs for this route |
1227 | 1227 | foreach ((array) $config['help_tabs'] as $tab_id => $cfg) { |
1228 | 1228 | // we're here so there ARE help tabs! |
1229 | 1229 | // make sure we've got what we need |
1230 | - if (! isset($cfg['title'])) { |
|
1230 | + if ( ! isset($cfg['title'])) { |
|
1231 | 1231 | throw new EE_Error( |
1232 | 1232 | esc_html__( |
1233 | 1233 | 'The _page_config array is not set up properly for help tabs. It is missing a title', |
@@ -1235,7 +1235,7 @@ discard block |
||
1235 | 1235 | ) |
1236 | 1236 | ); |
1237 | 1237 | } |
1238 | - if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
1238 | + if ( ! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) { |
|
1239 | 1239 | throw new EE_Error( |
1240 | 1240 | esc_html__( |
1241 | 1241 | 'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab', |
@@ -1244,11 +1244,11 @@ discard block |
||
1244 | 1244 | ); |
1245 | 1245 | } |
1246 | 1246 | // first priority goes to content. |
1247 | - if (! empty($cfg['content'])) { |
|
1247 | + if ( ! empty($cfg['content'])) { |
|
1248 | 1248 | $content = ! empty($cfg['content']) ? $cfg['content'] : null; |
1249 | 1249 | // second priority goes to filename |
1250 | - } elseif (! empty($cfg['filename'])) { |
|
1251 | - $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php'; |
|
1250 | + } elseif ( ! empty($cfg['filename'])) { |
|
1251 | + $file_path = $this->_get_dir().'/help_tabs/'.$cfg['filename'].'.help_tab.php'; |
|
1252 | 1252 | // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too) |
1253 | 1253 | $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES |
1254 | 1254 | . basename($this->_get_dir()) |
@@ -1256,7 +1256,7 @@ discard block |
||
1256 | 1256 | . $cfg['filename'] |
1257 | 1257 | . '.help_tab.php' : $file_path; |
1258 | 1258 | // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
1259 | - if (! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
1259 | + if ( ! isset($cfg['callback']) && ! is_readable($file_path)) { |
|
1260 | 1260 | EE_Error::add_error( |
1261 | 1261 | sprintf( |
1262 | 1262 | esc_html__( |
@@ -1302,7 +1302,7 @@ discard block |
||
1302 | 1302 | return; |
1303 | 1303 | } |
1304 | 1304 | // setup config array for help tab method |
1305 | - $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id; |
|
1305 | + $id = $this->page_slug.'-'.$this->_req_action.'-'.$tab_id; |
|
1306 | 1306 | $_ht = array( |
1307 | 1307 | 'id' => $id, |
1308 | 1308 | 'title' => $cfg['title'], |
@@ -1346,7 +1346,7 @@ discard block |
||
1346 | 1346 | } |
1347 | 1347 | if (isset($config['help_tour'])) { |
1348 | 1348 | foreach ($config['help_tour'] as $tour) { |
1349 | - $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php'; |
|
1349 | + $file_path = $this->_get_dir().'/help_tours/'.$tour.'.class.php'; |
|
1350 | 1350 | // let's see if we can get that file... |
1351 | 1351 | // if not its possible this is a decaf route not set in caffeinated |
1352 | 1352 | // so lets try and get the caffeinated equivalent |
@@ -1356,7 +1356,7 @@ discard block |
||
1356 | 1356 | . $tour |
1357 | 1357 | . '.class.php' : $file_path; |
1358 | 1358 | // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error. |
1359 | - if (! is_readable($file_path)) { |
|
1359 | + if ( ! is_readable($file_path)) { |
|
1360 | 1360 | EE_Error::add_error( |
1361 | 1361 | sprintf( |
1362 | 1362 | esc_html__( |
@@ -1373,12 +1373,12 @@ discard block |
||
1373 | 1373 | return; |
1374 | 1374 | } |
1375 | 1375 | require_once $file_path; |
1376 | - if (! class_exists($tour)) { |
|
1376 | + if ( ! class_exists($tour)) { |
|
1377 | 1377 | $error_msg[] = sprintf( |
1378 | 1378 | esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'), |
1379 | 1379 | $tour |
1380 | 1380 | ); |
1381 | - $error_msg[] = $error_msg[0] . "\r\n" |
|
1381 | + $error_msg[] = $error_msg[0]."\r\n" |
|
1382 | 1382 | . sprintf( |
1383 | 1383 | esc_html__( |
1384 | 1384 | 'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.', |
@@ -1394,15 +1394,15 @@ discard block |
||
1394 | 1394 | } |
1395 | 1395 | $tour_obj = new $tour($this->_is_caf); |
1396 | 1396 | $tours[] = $tour_obj; |
1397 | - $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
1397 | + $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($tour_obj); |
|
1398 | 1398 | } |
1399 | 1399 | // let's inject the end tour stop element common to all pages... this will only get seen once per machine. |
1400 | 1400 | $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf); |
1401 | 1401 | $tours[] = $end_stop_tour; |
1402 | - $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
1402 | + $this->_help_tour[$route][] = EEH_Template::help_tour_stops_generator($end_stop_tour); |
|
1403 | 1403 | } |
1404 | 1404 | } |
1405 | - if (! empty($tours)) { |
|
1405 | + if ( ! empty($tours)) { |
|
1406 | 1406 | $this->_help_tour['tours'] = $tours; |
1407 | 1407 | } |
1408 | 1408 | // that's it! Now that the $_help_tours property is set (or not) |
@@ -1421,8 +1421,8 @@ discard block |
||
1421 | 1421 | $qtips = (array) $this->_route_config['qtips']; |
1422 | 1422 | // load qtip loader |
1423 | 1423 | $path = array( |
1424 | - $this->_get_dir() . '/qtips/', |
|
1425 | - EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/', |
|
1424 | + $this->_get_dir().'/qtips/', |
|
1425 | + EE_ADMIN_PAGES.basename($this->_get_dir()).'/qtips/', |
|
1426 | 1426 | ); |
1427 | 1427 | EEH_Qtip_Loader::instance()->register($qtips, $path); |
1428 | 1428 | } |
@@ -1444,7 +1444,7 @@ discard block |
||
1444 | 1444 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
1445 | 1445 | $i = 0; |
1446 | 1446 | foreach ($this->_page_config as $slug => $config) { |
1447 | - if (! is_array($config) |
|
1447 | + if ( ! is_array($config) |
|
1448 | 1448 | || ( |
1449 | 1449 | is_array($config) |
1450 | 1450 | && ( |
@@ -1461,12 +1461,12 @@ discard block |
||
1461 | 1461 | // nav tab is only to appear when route requested. |
1462 | 1462 | continue; |
1463 | 1463 | } |
1464 | - if (! $this->check_user_access($slug, true)) { |
|
1464 | + if ( ! $this->check_user_access($slug, true)) { |
|
1465 | 1465 | // no nav tab because current user does not have access. |
1466 | 1466 | continue; |
1467 | 1467 | } |
1468 | - $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : ''; |
|
1469 | - $this->_nav_tabs[ $slug ] = array( |
|
1468 | + $css_class = isset($config['css_class']) ? $config['css_class'].' ' : ''; |
|
1469 | + $this->_nav_tabs[$slug] = array( |
|
1470 | 1470 | 'url' => isset($config['nav']['url']) |
1471 | 1471 | ? $config['nav']['url'] |
1472 | 1472 | : self::add_query_args_and_nonce( |
@@ -1478,14 +1478,14 @@ discard block |
||
1478 | 1478 | : ucwords( |
1479 | 1479 | str_replace('_', ' ', $slug) |
1480 | 1480 | ), |
1481 | - 'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class, |
|
1481 | + 'css_class' => $this->_req_action === $slug ? $css_class.'nav-tab-active' : $css_class, |
|
1482 | 1482 | 'order' => isset($config['nav']['order']) ? $config['nav']['order'] : $i, |
1483 | 1483 | ); |
1484 | 1484 | $i++; |
1485 | 1485 | } |
1486 | 1486 | // if $this->_nav_tabs is empty then lets set the default |
1487 | 1487 | if (empty($this->_nav_tabs)) { |
1488 | - $this->_nav_tabs[ $this->_default_nav_tab_name ] = array( |
|
1488 | + $this->_nav_tabs[$this->_default_nav_tab_name] = array( |
|
1489 | 1489 | 'url' => $this->_admin_base_url, |
1490 | 1490 | 'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)), |
1491 | 1491 | 'css_class' => 'nav-tab-active', |
@@ -1510,10 +1510,10 @@ discard block |
||
1510 | 1510 | foreach ($this->_route_config['labels'] as $label => $text) { |
1511 | 1511 | if (is_array($text)) { |
1512 | 1512 | foreach ($text as $sublabel => $subtext) { |
1513 | - $this->_labels[ $label ][ $sublabel ] = $subtext; |
|
1513 | + $this->_labels[$label][$sublabel] = $subtext; |
|
1514 | 1514 | } |
1515 | 1515 | } else { |
1516 | - $this->_labels[ $label ] = $text; |
|
1516 | + $this->_labels[$label] = $text; |
|
1517 | 1517 | } |
1518 | 1518 | } |
1519 | 1519 | } |
@@ -1535,12 +1535,12 @@ discard block |
||
1535 | 1535 | { |
1536 | 1536 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
1537 | 1537 | $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check; |
1538 | - $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ]) |
|
1538 | + $capability = ! empty($route_to_check) && isset($this->_page_routes[$route_to_check]) |
|
1539 | 1539 | && is_array( |
1540 | - $this->_page_routes[ $route_to_check ] |
|
1540 | + $this->_page_routes[$route_to_check] |
|
1541 | 1541 | ) |
1542 | - && ! empty($this->_page_routes[ $route_to_check ]['capability']) |
|
1543 | - ? $this->_page_routes[ $route_to_check ]['capability'] : null; |
|
1542 | + && ! empty($this->_page_routes[$route_to_check]['capability']) |
|
1543 | + ? $this->_page_routes[$route_to_check]['capability'] : null; |
|
1544 | 1544 | if (empty($capability) && empty($route_to_check)) { |
1545 | 1545 | $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options' |
1546 | 1546 | : $this->_route['capability']; |
@@ -1548,7 +1548,7 @@ discard block |
||
1548 | 1548 | $capability = empty($capability) ? 'manage_options' : $capability; |
1549 | 1549 | } |
1550 | 1550 | $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0; |
1551 | - if (! defined('DOING_AJAX') |
|
1551 | + if ( ! defined('DOING_AJAX') |
|
1552 | 1552 | && ( |
1553 | 1553 | ! function_exists('is_admin') |
1554 | 1554 | || ! EE_Registry::instance()->CAP->current_user_can( |
@@ -1651,17 +1651,17 @@ discard block |
||
1651 | 1651 | public function admin_footer_global() |
1652 | 1652 | { |
1653 | 1653 | // dialog container for dialog helper |
1654 | - $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n"; |
|
1654 | + $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">'."\n"; |
|
1655 | 1655 | $d_cont .= '<div class="ee-notices"></div>'; |
1656 | 1656 | $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>'; |
1657 | 1657 | $d_cont .= '</div>'; |
1658 | 1658 | echo $d_cont; |
1659 | 1659 | // help tour stuff? |
1660 | - if (isset($this->_help_tour[ $this->_req_action ])) { |
|
1661 | - echo implode('<br />', $this->_help_tour[ $this->_req_action ]); |
|
1660 | + if (isset($this->_help_tour[$this->_req_action])) { |
|
1661 | + echo implode('<br />', $this->_help_tour[$this->_req_action]); |
|
1662 | 1662 | } |
1663 | 1663 | // current set timezone for timezone js |
1664 | - echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>'; |
|
1664 | + echo '<span id="current_timezone" class="hidden">'.EEH_DTT_Helper::get_timezone().'</span>'; |
|
1665 | 1665 | } |
1666 | 1666 | |
1667 | 1667 | |
@@ -1695,7 +1695,7 @@ discard block |
||
1695 | 1695 | // loop through the array and setup content |
1696 | 1696 | foreach ($help_array as $trigger => $help) { |
1697 | 1697 | // make sure the array is setup properly |
1698 | - if (! isset($help['title']) || ! isset($help['content'])) { |
|
1698 | + if ( ! isset($help['title']) || ! isset($help['content'])) { |
|
1699 | 1699 | throw new EE_Error( |
1700 | 1700 | esc_html__( |
1701 | 1701 | 'Does not look like the popup content array has been setup correctly. Might want to double check that. Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class', |
@@ -1710,7 +1710,7 @@ discard block |
||
1710 | 1710 | 'help_popup_content' => $help['content'], |
1711 | 1711 | ); |
1712 | 1712 | $content .= EEH_Template::display_template( |
1713 | - EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php', |
|
1713 | + EE_ADMIN_TEMPLATE.'admin_help_popup.template.php', |
|
1714 | 1714 | $template_args, |
1715 | 1715 | true |
1716 | 1716 | ); |
@@ -1732,15 +1732,15 @@ discard block |
||
1732 | 1732 | private function _get_help_content() |
1733 | 1733 | { |
1734 | 1734 | // what is the method we're looking for? |
1735 | - $method_name = '_help_popup_content_' . $this->_req_action; |
|
1735 | + $method_name = '_help_popup_content_'.$this->_req_action; |
|
1736 | 1736 | // if method doesn't exist let's get out. |
1737 | - if (! method_exists($this, $method_name)) { |
|
1737 | + if ( ! method_exists($this, $method_name)) { |
|
1738 | 1738 | return array(); |
1739 | 1739 | } |
1740 | 1740 | // k we're good to go let's retrieve the help array |
1741 | 1741 | $help_array = call_user_func(array($this, $method_name)); |
1742 | 1742 | // make sure we've got an array! |
1743 | - if (! is_array($help_array)) { |
|
1743 | + if ( ! is_array($help_array)) { |
|
1744 | 1744 | throw new EE_Error( |
1745 | 1745 | esc_html__( |
1746 | 1746 | 'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.', |
@@ -1772,8 +1772,8 @@ discard block |
||
1772 | 1772 | // let's check and see if there is any content set for this popup. If there isn't then we'll include a default title and content so that developers know something needs to be corrected |
1773 | 1773 | $help_array = $this->_get_help_content(); |
1774 | 1774 | $help_content = ''; |
1775 | - if (empty($help_array) || ! isset($help_array[ $trigger_id ])) { |
|
1776 | - $help_array[ $trigger_id ] = array( |
|
1775 | + if (empty($help_array) || ! isset($help_array[$trigger_id])) { |
|
1776 | + $help_array[$trigger_id] = array( |
|
1777 | 1777 | 'title' => esc_html__('Missing Content', 'event_espresso'), |
1778 | 1778 | 'content' => esc_html__( |
1779 | 1779 | 'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)', |
@@ -1849,15 +1849,15 @@ discard block |
||
1849 | 1849 | // register all styles |
1850 | 1850 | wp_register_style( |
1851 | 1851 | 'espresso-ui-theme', |
1852 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
1852 | + EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
1853 | 1853 | array(), |
1854 | 1854 | EVENT_ESPRESSO_VERSION |
1855 | 1855 | ); |
1856 | - wp_register_style('ee-admin-css', EE_ADMIN_URL . 'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
1856 | + wp_register_style('ee-admin-css', EE_ADMIN_URL.'assets/ee-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
1857 | 1857 | // helpers styles |
1858 | 1858 | wp_register_style( |
1859 | 1859 | 'ee-text-links', |
1860 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.css', |
|
1860 | + EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.css', |
|
1861 | 1861 | array(), |
1862 | 1862 | EVENT_ESPRESSO_VERSION |
1863 | 1863 | ); |
@@ -1865,21 +1865,21 @@ discard block |
||
1865 | 1865 | // register all scripts |
1866 | 1866 | wp_register_script( |
1867 | 1867 | 'ee-dialog', |
1868 | - EE_ADMIN_URL . 'assets/ee-dialog-helper.js', |
|
1868 | + EE_ADMIN_URL.'assets/ee-dialog-helper.js', |
|
1869 | 1869 | array('jquery', 'jquery-ui-draggable'), |
1870 | 1870 | EVENT_ESPRESSO_VERSION, |
1871 | 1871 | true |
1872 | 1872 | ); |
1873 | 1873 | wp_register_script( |
1874 | 1874 | 'ee_admin_js', |
1875 | - EE_ADMIN_URL . 'assets/ee-admin-page.js', |
|
1875 | + EE_ADMIN_URL.'assets/ee-admin-page.js', |
|
1876 | 1876 | array('espresso_core', 'ee-parse-uri', 'ee-dialog'), |
1877 | 1877 | EVENT_ESPRESSO_VERSION, |
1878 | 1878 | true |
1879 | 1879 | ); |
1880 | 1880 | wp_register_script( |
1881 | 1881 | 'jquery-ui-timepicker-addon', |
1882 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery-ui-timepicker-addon.js', |
|
1882 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery-ui-timepicker-addon.js', |
|
1883 | 1883 | array('jquery-ui-datepicker', 'jquery-ui-slider'), |
1884 | 1884 | EVENT_ESPRESSO_VERSION, |
1885 | 1885 | true |
@@ -1888,7 +1888,7 @@ discard block |
||
1888 | 1888 | // script for sorting tables |
1889 | 1889 | wp_register_script( |
1890 | 1890 | 'espresso_ajax_table_sorting', |
1891 | - EE_ADMIN_URL . 'assets/espresso_ajax_table_sorting.js', |
|
1891 | + EE_ADMIN_URL.'assets/espresso_ajax_table_sorting.js', |
|
1892 | 1892 | array('ee_admin_js', 'jquery-ui-sortable'), |
1893 | 1893 | EVENT_ESPRESSO_VERSION, |
1894 | 1894 | true |
@@ -1896,7 +1896,7 @@ discard block |
||
1896 | 1896 | // script for parsing uri's |
1897 | 1897 | wp_register_script( |
1898 | 1898 | 'ee-parse-uri', |
1899 | - EE_GLOBAL_ASSETS_URL . 'scripts/parseuri.js', |
|
1899 | + EE_GLOBAL_ASSETS_URL.'scripts/parseuri.js', |
|
1900 | 1900 | array(), |
1901 | 1901 | EVENT_ESPRESSO_VERSION, |
1902 | 1902 | true |
@@ -1904,7 +1904,7 @@ discard block |
||
1904 | 1904 | // and parsing associative serialized form elements |
1905 | 1905 | wp_register_script( |
1906 | 1906 | 'ee-serialize-full-array', |
1907 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.serializefullarray.js', |
|
1907 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.serializefullarray.js', |
|
1908 | 1908 | array('jquery'), |
1909 | 1909 | EVENT_ESPRESSO_VERSION, |
1910 | 1910 | true |
@@ -1912,28 +1912,28 @@ discard block |
||
1912 | 1912 | // helpers scripts |
1913 | 1913 | wp_register_script( |
1914 | 1914 | 'ee-text-links', |
1915 | - EE_PLUGIN_DIR_URL . 'core/helpers/assets/ee_text_list_helper.js', |
|
1915 | + EE_PLUGIN_DIR_URL.'core/helpers/assets/ee_text_list_helper.js', |
|
1916 | 1916 | array('jquery'), |
1917 | 1917 | EVENT_ESPRESSO_VERSION, |
1918 | 1918 | true |
1919 | 1919 | ); |
1920 | 1920 | wp_register_script( |
1921 | 1921 | 'ee-moment-core', |
1922 | - EE_THIRD_PARTY_URL . 'moment/moment-with-locales.min.js', |
|
1922 | + EE_THIRD_PARTY_URL.'moment/moment-with-locales.min.js', |
|
1923 | 1923 | array(), |
1924 | 1924 | EVENT_ESPRESSO_VERSION, |
1925 | 1925 | true |
1926 | 1926 | ); |
1927 | 1927 | wp_register_script( |
1928 | 1928 | 'ee-moment', |
1929 | - EE_THIRD_PARTY_URL . 'moment/moment-timezone-with-data.min.js', |
|
1929 | + EE_THIRD_PARTY_URL.'moment/moment-timezone-with-data.min.js', |
|
1930 | 1930 | array('ee-moment-core'), |
1931 | 1931 | EVENT_ESPRESSO_VERSION, |
1932 | 1932 | true |
1933 | 1933 | ); |
1934 | 1934 | wp_register_script( |
1935 | 1935 | 'ee-datepicker', |
1936 | - EE_ADMIN_URL . 'assets/ee-datepicker.js', |
|
1936 | + EE_ADMIN_URL.'assets/ee-datepicker.js', |
|
1937 | 1937 | array('jquery-ui-timepicker-addon', 'ee-moment'), |
1938 | 1938 | EVENT_ESPRESSO_VERSION, |
1939 | 1939 | true |
@@ -1967,11 +1967,11 @@ discard block |
||
1967 | 1967 | /** |
1968 | 1968 | * help tour stuff |
1969 | 1969 | */ |
1970 | - if (! empty($this->_help_tour)) { |
|
1970 | + if ( ! empty($this->_help_tour)) { |
|
1971 | 1971 | // register the js for kicking things off |
1972 | 1972 | wp_enqueue_script( |
1973 | 1973 | 'ee-help-tour', |
1974 | - EE_ADMIN_URL . 'assets/ee-help-tour.js', |
|
1974 | + EE_ADMIN_URL.'assets/ee-help-tour.js', |
|
1975 | 1975 | array('jquery-joyride'), |
1976 | 1976 | EVENT_ESPRESSO_VERSION, |
1977 | 1977 | true |
@@ -2068,12 +2068,12 @@ discard block |
||
2068 | 2068 | protected function _set_list_table() |
2069 | 2069 | { |
2070 | 2070 | // first is this a list_table view? |
2071 | - if (! isset($this->_route_config['list_table'])) { |
|
2071 | + if ( ! isset($this->_route_config['list_table'])) { |
|
2072 | 2072 | return; |
2073 | 2073 | } //not a list_table view so get out. |
2074 | 2074 | // list table functions are per view specific (because some admin pages might have more than one list table!) |
2075 | - $list_table_view = '_set_list_table_views_' . $this->_req_action; |
|
2076 | - if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
2075 | + $list_table_view = '_set_list_table_views_'.$this->_req_action; |
|
2076 | + if ( ! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) { |
|
2077 | 2077 | // user error msg |
2078 | 2078 | $error_msg = esc_html__( |
2079 | 2079 | 'An error occurred. The requested list table views could not be found.', |
@@ -2093,10 +2093,10 @@ discard block |
||
2093 | 2093 | } |
2094 | 2094 | // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally |
2095 | 2095 | $this->_views = apply_filters( |
2096 | - 'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action, |
|
2096 | + 'FHEE_list_table_views_'.$this->page_slug.'_'.$this->_req_action, |
|
2097 | 2097 | $this->_views |
2098 | 2098 | ); |
2099 | - $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views); |
|
2099 | + $this->_views = apply_filters('FHEE_list_table_views_'.$this->page_slug, $this->_views); |
|
2100 | 2100 | $this->_views = apply_filters('FHEE_list_table_views', $this->_views); |
2101 | 2101 | $this->_set_list_table_view(); |
2102 | 2102 | $this->_set_list_table_object(); |
@@ -2112,7 +2112,7 @@ discard block |
||
2112 | 2112 | { |
2113 | 2113 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
2114 | 2114 | // looking at active items or dumpster diving ? |
2115 | - if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
2115 | + if ( ! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) { |
|
2116 | 2116 | $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all'; |
2117 | 2117 | } else { |
2118 | 2118 | $this->_view = sanitize_key($this->_req_data['status']); |
@@ -2133,7 +2133,7 @@ discard block |
||
2133 | 2133 | protected function _set_list_table_object() |
2134 | 2134 | { |
2135 | 2135 | if (isset($this->_route_config['list_table'])) { |
2136 | - if (! class_exists($this->_route_config['list_table'])) { |
|
2136 | + if ( ! class_exists($this->_route_config['list_table'])) { |
|
2137 | 2137 | throw new EE_Error( |
2138 | 2138 | sprintf( |
2139 | 2139 | esc_html__( |
@@ -2171,15 +2171,15 @@ discard block |
||
2171 | 2171 | foreach ($this->_views as $key => $view) { |
2172 | 2172 | $query_args = array(); |
2173 | 2173 | // check for current view |
2174 | - $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
2174 | + $this->_views[$key]['class'] = $this->_view === $view['slug'] ? 'current' : ''; |
|
2175 | 2175 | $query_args['action'] = $this->_req_action; |
2176 | - $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
2176 | + $query_args[$this->_req_action.'_nonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
2177 | 2177 | $query_args['status'] = $view['slug']; |
2178 | 2178 | // merge any other arguments sent in. |
2179 | - if (isset($extra_query_args[ $view['slug'] ])) { |
|
2180 | - $query_args = array_merge($query_args, $extra_query_args[ $view['slug'] ]); |
|
2179 | + if (isset($extra_query_args[$view['slug']])) { |
|
2180 | + $query_args = array_merge($query_args, $extra_query_args[$view['slug']]); |
|
2181 | 2181 | } |
2182 | - $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
2182 | + $this->_views[$key]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url); |
|
2183 | 2183 | } |
2184 | 2184 | return $this->_views; |
2185 | 2185 | } |
@@ -2198,7 +2198,7 @@ discard block |
||
2198 | 2198 | { |
2199 | 2199 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
2200 | 2200 | $values = array(10, 25, 50, 100); |
2201 | - $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
2201 | + $per_page = ( ! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10; |
|
2202 | 2202 | if ($max_entries) { |
2203 | 2203 | $values[] = $max_entries; |
2204 | 2204 | sort($values); |
@@ -2210,14 +2210,14 @@ discard block |
||
2210 | 2210 | <select id="entries-per-page-slct" name="entries-per-page-slct">'; |
2211 | 2211 | foreach ($values as $value) { |
2212 | 2212 | if ($value < $max_entries) { |
2213 | - $selected = $value === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
2213 | + $selected = $value === $per_page ? ' selected="'.$per_page.'"' : ''; |
|
2214 | 2214 | $entries_per_page_dropdown .= ' |
2215 | - <option value="' . $value . '"' . $selected . '>' . $value . ' </option>'; |
|
2215 | + <option value="' . $value.'"'.$selected.'>'.$value.' </option>'; |
|
2216 | 2216 | } |
2217 | 2217 | } |
2218 | - $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : ''; |
|
2218 | + $selected = $max_entries === $per_page ? ' selected="'.$per_page.'"' : ''; |
|
2219 | 2219 | $entries_per_page_dropdown .= ' |
2220 | - <option value="' . $max_entries . '"' . $selected . '>All </option>'; |
|
2220 | + <option value="' . $max_entries.'"'.$selected.'>All </option>'; |
|
2221 | 2221 | $entries_per_page_dropdown .= ' |
2222 | 2222 | </select> |
2223 | 2223 | entries |
@@ -2241,7 +2241,7 @@ discard block |
||
2241 | 2241 | empty($this->_search_btn_label) ? $this->page_label |
2242 | 2242 | : $this->_search_btn_label |
2243 | 2243 | ); |
2244 | - $this->_template_args['search']['callback'] = 'search_' . $this->page_slug; |
|
2244 | + $this->_template_args['search']['callback'] = 'search_'.$this->page_slug; |
|
2245 | 2245 | } |
2246 | 2246 | |
2247 | 2247 | |
@@ -2327,7 +2327,7 @@ discard block |
||
2327 | 2327 | $total_columns = ! empty($screen_columns) |
2328 | 2328 | ? $screen_columns |
2329 | 2329 | : $this->_route_config['columns'][1]; |
2330 | - $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns; |
|
2330 | + $this->_template_args['current_screen_widget_class'] = 'columns-'.$total_columns; |
|
2331 | 2331 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
2332 | 2332 | $this->_template_args['screen'] = $this->_current_screen; |
2333 | 2333 | $this->_column_template_path = EE_ADMIN_TEMPLATE |
@@ -2372,7 +2372,7 @@ discard block |
||
2372 | 2372 | */ |
2373 | 2373 | protected function _espresso_ratings_request() |
2374 | 2374 | { |
2375 | - if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
2375 | + if ( ! apply_filters('FHEE_show_ratings_request_meta_box', true)) { |
|
2376 | 2376 | return; |
2377 | 2377 | } |
2378 | 2378 | $ratings_box_title = apply_filters( |
@@ -2400,7 +2400,7 @@ discard block |
||
2400 | 2400 | public function espresso_ratings_request() |
2401 | 2401 | { |
2402 | 2402 | EEH_Template::display_template( |
2403 | - EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php', |
|
2403 | + EE_ADMIN_TEMPLATE.'espresso_ratings_request_content.template.php', |
|
2404 | 2404 | array() |
2405 | 2405 | ); |
2406 | 2406 | } |
@@ -2413,17 +2413,17 @@ discard block |
||
2413 | 2413 | . '</p><p class="hide-if-js">' |
2414 | 2414 | . esc_html__('This widget requires JavaScript.', 'event_espresso') |
2415 | 2415 | . '</p>'; |
2416 | - $pre = '<div class="espresso-rss-display">' . "\n\t"; |
|
2417 | - $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>'; |
|
2418 | - $post = '</div>' . "\n"; |
|
2419 | - $cache_key = 'ee_rss_' . md5($rss_id); |
|
2416 | + $pre = '<div class="espresso-rss-display">'."\n\t"; |
|
2417 | + $pre .= '<span id="'.$rss_id.'_url" class="hidden">'.$url.'</span>'; |
|
2418 | + $post = '</div>'."\n"; |
|
2419 | + $cache_key = 'ee_rss_'.md5($rss_id); |
|
2420 | 2420 | $output = get_transient($cache_key); |
2421 | 2421 | if ($output !== false) { |
2422 | - echo $pre . $output . $post; |
|
2422 | + echo $pre.$output.$post; |
|
2423 | 2423 | return true; |
2424 | 2424 | } |
2425 | - if (! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
2426 | - echo $pre . $loading . $post; |
|
2425 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
2426 | + echo $pre.$loading.$post; |
|
2427 | 2427 | return false; |
2428 | 2428 | } |
2429 | 2429 | ob_start(); |
@@ -2490,19 +2490,19 @@ discard block |
||
2490 | 2490 | public function espresso_sponsors_post_box() |
2491 | 2491 | { |
2492 | 2492 | EEH_Template::display_template( |
2493 | - EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
2493 | + EE_ADMIN_TEMPLATE.'admin_general_metabox_contents_espresso_sponsors.template.php' |
|
2494 | 2494 | ); |
2495 | 2495 | } |
2496 | 2496 | |
2497 | 2497 | |
2498 | 2498 | private function _publish_post_box() |
2499 | 2499 | { |
2500 | - $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview'; |
|
2500 | + $meta_box_ref = 'espresso_'.$this->page_slug.'_editor_overview'; |
|
2501 | 2501 | // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array |
2502 | 2502 | // then we'll use that for the metabox label. |
2503 | 2503 | // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes) |
2504 | - if (! empty($this->_labels['publishbox'])) { |
|
2505 | - $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ] |
|
2504 | + if ( ! empty($this->_labels['publishbox'])) { |
|
2505 | + $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][$this->_req_action] |
|
2506 | 2506 | : $this->_labels['publishbox']; |
2507 | 2507 | } else { |
2508 | 2508 | $box_label = esc_html__('Publish', 'event_espresso'); |
@@ -2531,7 +2531,7 @@ discard block |
||
2531 | 2531 | ? $this->_template_args['publish_box_extra_content'] |
2532 | 2532 | : ''; |
2533 | 2533 | echo EEH_Template::display_template( |
2534 | - EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php', |
|
2534 | + EE_ADMIN_TEMPLATE.'admin_details_publish_metabox.template.php', |
|
2535 | 2535 | $this->_template_args, |
2536 | 2536 | true |
2537 | 2537 | ); |
@@ -2623,8 +2623,8 @@ discard block |
||
2623 | 2623 | ); |
2624 | 2624 | } |
2625 | 2625 | $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : ''; |
2626 | - if (! empty($name) && ! empty($id)) { |
|
2627 | - $hidden_field_arr[ $name ] = array( |
|
2626 | + if ( ! empty($name) && ! empty($id)) { |
|
2627 | + $hidden_field_arr[$name] = array( |
|
2628 | 2628 | 'type' => 'hidden', |
2629 | 2629 | 'value' => $id, |
2630 | 2630 | ); |
@@ -2634,7 +2634,7 @@ discard block |
||
2634 | 2634 | } |
2635 | 2635 | // add hidden field |
2636 | 2636 | $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name) |
2637 | - ? $hf[ $name ]['field'] |
|
2637 | + ? $hf[$name]['field'] |
|
2638 | 2638 | : $hf; |
2639 | 2639 | } |
2640 | 2640 | |
@@ -2736,7 +2736,7 @@ discard block |
||
2736 | 2736 | } |
2737 | 2737 | // if $create_func is true (default) then we automatically create the function for displaying the actual meta box. If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish) |
2738 | 2738 | $call_back_func = $create_func |
2739 | - ? function ($post, $metabox) { |
|
2739 | + ? function($post, $metabox) { |
|
2740 | 2740 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
2741 | 2741 | echo EEH_Template::display_template( |
2742 | 2742 | $metabox['args']['template_path'], |
@@ -2746,7 +2746,7 @@ discard block |
||
2746 | 2746 | } |
2747 | 2747 | : $callback; |
2748 | 2748 | add_meta_box( |
2749 | - str_replace('_', '-', $action) . '-mbox', |
|
2749 | + str_replace('_', '-', $action).'-mbox', |
|
2750 | 2750 | $title, |
2751 | 2751 | $call_back_func, |
2752 | 2752 | $this->_wp_page_slug, |
@@ -2838,9 +2838,9 @@ discard block |
||
2838 | 2838 | : 'espresso-default-admin'; |
2839 | 2839 | $template_path = $sidebar |
2840 | 2840 | ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php' |
2841 | - : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php'; |
|
2841 | + : EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar.template.php'; |
|
2842 | 2842 | if (defined('DOING_AJAX') && DOING_AJAX) { |
2843 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
2843 | + $template_path = EE_ADMIN_TEMPLATE.'admin_details_wrapper_no_sidebar_ajax.template.php'; |
|
2844 | 2844 | } |
2845 | 2845 | $template_path = ! empty($this->_column_template_path) |
2846 | 2846 | ? $this->_column_template_path : $template_path; |
@@ -2905,7 +2905,7 @@ discard block |
||
2905 | 2905 | ) |
2906 | 2906 | : $this->_template_args['preview_action_button']; |
2907 | 2907 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
2908 | - EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php', |
|
2908 | + EE_ADMIN_TEMPLATE.'admin_caf_full_page_preview.template.php', |
|
2909 | 2909 | $this->_template_args, |
2910 | 2910 | true |
2911 | 2911 | ); |
@@ -2954,7 +2954,7 @@ discard block |
||
2954 | 2954 | // setup search attributes |
2955 | 2955 | $this->_set_search_attributes(); |
2956 | 2956 | $this->_template_args['current_page'] = $this->_wp_page_slug; |
2957 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php'; |
|
2957 | + $template_path = EE_ADMIN_TEMPLATE.'admin_list_wrapper.template.php'; |
|
2958 | 2958 | $this->_template_args['table_url'] = defined('DOING_AJAX') |
2959 | 2959 | ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url) |
2960 | 2960 | : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url); |
@@ -2962,10 +2962,10 @@ discard block |
||
2962 | 2962 | $this->_template_args['current_route'] = $this->_req_action; |
2963 | 2963 | $this->_template_args['list_table_class'] = get_class($this->_list_table_object); |
2964 | 2964 | $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback(); |
2965 | - if (! empty($ajax_sorting_callback)) { |
|
2965 | + if ( ! empty($ajax_sorting_callback)) { |
|
2966 | 2966 | $sortable_list_table_form_fields = wp_nonce_field( |
2967 | - $ajax_sorting_callback . '_nonce', |
|
2968 | - $ajax_sorting_callback . '_nonce', |
|
2967 | + $ajax_sorting_callback.'_nonce', |
|
2968 | + $ajax_sorting_callback.'_nonce', |
|
2969 | 2969 | false, |
2970 | 2970 | false |
2971 | 2971 | ); |
@@ -2982,7 +2982,7 @@ discard block |
||
2982 | 2982 | $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields']) |
2983 | 2983 | ? $this->_template_args['list_table_hidden_fields'] |
2984 | 2984 | : ''; |
2985 | - $nonce_ref = $this->_req_action . '_nonce'; |
|
2985 | + $nonce_ref = $this->_req_action.'_nonce'; |
|
2986 | 2986 | $hidden_form_fields .= '<input type="hidden" name="' |
2987 | 2987 | . $nonce_ref |
2988 | 2988 | . '" value="' |
@@ -2991,10 +2991,10 @@ discard block |
||
2991 | 2991 | $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields; |
2992 | 2992 | // display message about search results? |
2993 | 2993 | $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s']) |
2994 | - ? '<p class="ee-search-results">' . sprintf( |
|
2994 | + ? '<p class="ee-search-results">'.sprintf( |
|
2995 | 2995 | esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'), |
2996 | 2996 | trim($this->_req_data['s'], '%') |
2997 | - ) . '</p>' |
|
2997 | + ).'</p>' |
|
2998 | 2998 | : ''; |
2999 | 2999 | // filter before_list_table template arg |
3000 | 3000 | $this->_template_args['before_list_table'] = apply_filters( |
@@ -3075,7 +3075,7 @@ discard block |
||
3075 | 3075 | $this |
3076 | 3076 | ); |
3077 | 3077 | return EEH_Template::display_template( |
3078 | - EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php', |
|
3078 | + EE_ADMIN_TEMPLATE.'admin_details_legend.template.php', |
|
3079 | 3079 | $this->_template_args, |
3080 | 3080 | true |
3081 | 3081 | ); |
@@ -3298,17 +3298,17 @@ discard block |
||
3298 | 3298 | // add in a hidden index for the current page (so save and close redirects properly) |
3299 | 3299 | $this->_template_args['save_buttons'] = $referrer_url; |
3300 | 3300 | foreach ($button_text as $key => $button) { |
3301 | - $ref = $default_names[ $key ]; |
|
3301 | + $ref = $default_names[$key]; |
|
3302 | 3302 | $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary ' |
3303 | 3303 | . $ref |
3304 | 3304 | . '" value="' |
3305 | 3305 | . $button |
3306 | 3306 | . '" name="' |
3307 | - . (! empty($actions) ? $actions[ $key ] : $ref) |
|
3307 | + . ( ! empty($actions) ? $actions[$key] : $ref) |
|
3308 | 3308 | . '" id="' |
3309 | - . $this->_current_view . '_' . $ref |
|
3309 | + . $this->_current_view.'_'.$ref |
|
3310 | 3310 | . '" />'; |
3311 | - if (! $both) { |
|
3311 | + if ( ! $both) { |
|
3312 | 3312 | break; |
3313 | 3313 | } |
3314 | 3314 | } |
@@ -3343,13 +3343,13 @@ discard block |
||
3343 | 3343 | 'An error occurred. No action was set for this page\'s form.', |
3344 | 3344 | 'event_espresso' |
3345 | 3345 | ); |
3346 | - $dev_msg = $user_msg . "\n" |
|
3346 | + $dev_msg = $user_msg."\n" |
|
3347 | 3347 | . sprintf( |
3348 | 3348 | esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'), |
3349 | 3349 | __FUNCTION__, |
3350 | 3350 | __CLASS__ |
3351 | 3351 | ); |
3352 | - EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
3352 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
3353 | 3353 | } |
3354 | 3354 | // open form |
3355 | 3355 | $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="' |
@@ -3358,8 +3358,8 @@ discard block |
||
3358 | 3358 | . $route |
3359 | 3359 | . '_event_form" >'; |
3360 | 3360 | // add nonce |
3361 | - $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false); |
|
3362 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce; |
|
3361 | + $nonce = wp_nonce_field($route.'_nonce', $route.'_nonce', false, false); |
|
3362 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$nonce; |
|
3363 | 3363 | // add REQUIRED form action |
3364 | 3364 | $hidden_fields = array( |
3365 | 3365 | 'action' => array('type' => 'hidden', 'value' => $route), |
@@ -3372,7 +3372,7 @@ discard block |
||
3372 | 3372 | $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array'); |
3373 | 3373 | // add fields to form |
3374 | 3374 | foreach ((array) $form_fields as $field_name => $form_field) { |
3375 | - $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field']; |
|
3375 | + $this->_template_args['before_admin_page_content'] .= "\n\t".$form_field['field']; |
|
3376 | 3376 | } |
3377 | 3377 | // close form |
3378 | 3378 | $this->_template_args['after_admin_page_content'] = '</form>'; |
@@ -3423,12 +3423,12 @@ discard block |
||
3423 | 3423 | foreach ($this->_req_data as $ref => $value) { |
3424 | 3424 | // unset nonces |
3425 | 3425 | if (strpos($ref, 'nonce') !== false) { |
3426 | - unset($this->_req_data[ $ref ]); |
|
3426 | + unset($this->_req_data[$ref]); |
|
3427 | 3427 | continue; |
3428 | 3428 | } |
3429 | 3429 | // urlencode values. |
3430 | 3430 | $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
3431 | - $this->_req_data[ $ref ] = $value; |
|
3431 | + $this->_req_data[$ref] = $value; |
|
3432 | 3432 | } |
3433 | 3433 | return array_merge($this->_req_data, $new_route_data); |
3434 | 3434 | } |
@@ -3463,10 +3463,10 @@ discard block |
||
3463 | 3463 | $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url; |
3464 | 3464 | $notices = EE_Error::get_notices(false); |
3465 | 3465 | // overwrite default success messages //BUT ONLY if overwrite not overridden |
3466 | - if (! $override_overwrite || ! empty($notices['errors'])) { |
|
3466 | + if ( ! $override_overwrite || ! empty($notices['errors'])) { |
|
3467 | 3467 | EE_Error::overwrite_success(); |
3468 | 3468 | } |
3469 | - if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
3469 | + if ( ! empty($what) && ! empty($action_desc) && empty($notices['errors'])) { |
|
3470 | 3470 | // how many records affected ? more than one record ? or just one ? |
3471 | 3471 | if ($success > 1) { |
3472 | 3472 | // set plural msg |
@@ -3495,7 +3495,7 @@ discard block |
||
3495 | 3495 | } |
3496 | 3496 | } |
3497 | 3497 | // check that $query_args isn't something crazy |
3498 | - if (! is_array($query_args)) { |
|
3498 | + if ( ! is_array($query_args)) { |
|
3499 | 3499 | $query_args = array(); |
3500 | 3500 | } |
3501 | 3501 | /** |
@@ -3520,7 +3520,7 @@ discard block |
||
3520 | 3520 | $redirect_url = admin_url('admin.php'); |
3521 | 3521 | } |
3522 | 3522 | // merge any default query_args set in _default_route_query_args property |
3523 | - if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
3523 | + if ( ! empty($this->_default_route_query_args) && ! $this->_is_UI_request) { |
|
3524 | 3524 | $args_to_merge = array(); |
3525 | 3525 | foreach ($this->_default_route_query_args as $query_param => $query_value) { |
3526 | 3526 | // is there a wp_referer array in our _default_route_query_args property? |
@@ -3532,15 +3532,15 @@ discard block |
||
3532 | 3532 | } |
3533 | 3533 | // finally we will override any arguments in the referer with |
3534 | 3534 | // what might be set on the _default_route_query_args array. |
3535 | - if (isset($this->_default_route_query_args[ $reference ])) { |
|
3536 | - $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]); |
|
3535 | + if (isset($this->_default_route_query_args[$reference])) { |
|
3536 | + $args_to_merge[$reference] = urlencode($this->_default_route_query_args[$reference]); |
|
3537 | 3537 | } else { |
3538 | - $args_to_merge[ $reference ] = urlencode($value); |
|
3538 | + $args_to_merge[$reference] = urlencode($value); |
|
3539 | 3539 | } |
3540 | 3540 | } |
3541 | 3541 | continue; |
3542 | 3542 | } |
3543 | - $args_to_merge[ $query_param ] = $query_value; |
|
3543 | + $args_to_merge[$query_param] = $query_value; |
|
3544 | 3544 | } |
3545 | 3545 | // now let's merge these arguments but override with what was specifically sent in to the |
3546 | 3546 | // redirect. |
@@ -3552,13 +3552,13 @@ discard block |
||
3552 | 3552 | if (isset($query_args['action'])) { |
3553 | 3553 | // manually generate wp_nonce and merge that with the query vars |
3554 | 3554 | // becuz the wp_nonce_url function wrecks havoc on some vars |
3555 | - $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce'); |
|
3555 | + $query_args['_wpnonce'] = wp_create_nonce($query_args['action'].'_nonce'); |
|
3556 | 3556 | } |
3557 | 3557 | // we're adding some hooks and filters in here for processing any things just before redirects |
3558 | 3558 | // (example: an admin page has done an insert or update and we want to run something after that). |
3559 | - do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args); |
|
3559 | + do_action('AHEE_redirect_'.$classname.$this->_req_action, $query_args); |
|
3560 | 3560 | $redirect_url = apply_filters( |
3561 | - 'FHEE_redirect_' . $classname . $this->_req_action, |
|
3561 | + 'FHEE_redirect_'.$classname.$this->_req_action, |
|
3562 | 3562 | self::add_query_args_and_nonce($query_args, $redirect_url), |
3563 | 3563 | $query_args |
3564 | 3564 | ); |
@@ -3611,7 +3611,7 @@ discard block |
||
3611 | 3611 | } |
3612 | 3612 | $this->_template_args['notices'] = EE_Error::get_notices(); |
3613 | 3613 | // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true) |
3614 | - if (! defined('DOING_AJAX') || $sticky_notices) { |
|
3614 | + if ( ! defined('DOING_AJAX') || $sticky_notices) { |
|
3615 | 3615 | $route = isset($query_args['action']) ? $query_args['action'] : 'default'; |
3616 | 3616 | $this->_add_transient( |
3617 | 3617 | $route, |
@@ -3651,7 +3651,7 @@ discard block |
||
3651 | 3651 | $exclude_nonce = false |
3652 | 3652 | ) { |
3653 | 3653 | // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along) |
3654 | - if (empty($base_url) && ! isset($this->_page_routes[ $action ])) { |
|
3654 | + if (empty($base_url) && ! isset($this->_page_routes[$action])) { |
|
3655 | 3655 | throw new EE_Error( |
3656 | 3656 | sprintf( |
3657 | 3657 | esc_html__( |
@@ -3662,7 +3662,7 @@ discard block |
||
3662 | 3662 | ) |
3663 | 3663 | ); |
3664 | 3664 | } |
3665 | - if (! isset($this->_labels['buttons'][ $type ])) { |
|
3665 | + if ( ! isset($this->_labels['buttons'][$type])) { |
|
3666 | 3666 | throw new EE_Error( |
3667 | 3667 | sprintf( |
3668 | 3668 | __( |
@@ -3675,7 +3675,7 @@ discard block |
||
3675 | 3675 | } |
3676 | 3676 | // finally check user access for this button. |
3677 | 3677 | $has_access = $this->check_user_access($action, true); |
3678 | - if (! $has_access) { |
|
3678 | + if ( ! $has_access) { |
|
3679 | 3679 | return ''; |
3680 | 3680 | } |
3681 | 3681 | $_base_url = ! $base_url ? $this->_admin_base_url : $base_url; |
@@ -3683,11 +3683,11 @@ discard block |
||
3683 | 3683 | 'action' => $action, |
3684 | 3684 | ); |
3685 | 3685 | // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten. |
3686 | - if (! empty($extra_request)) { |
|
3686 | + if ( ! empty($extra_request)) { |
|
3687 | 3687 | $query_args = array_merge($extra_request, $query_args); |
3688 | 3688 | } |
3689 | 3689 | $url = self::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce); |
3690 | - return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class); |
|
3690 | + return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][$type], $class); |
|
3691 | 3691 | } |
3692 | 3692 | |
3693 | 3693 | |
@@ -3713,7 +3713,7 @@ discard block |
||
3713 | 3713 | 'FHEE__EE_Admin_Page___per_page_screen_options__default', |
3714 | 3714 | 20 |
3715 | 3715 | ), |
3716 | - 'option' => $this->_current_page . '_' . $this->_current_view . '_per_page', |
|
3716 | + 'option' => $this->_current_page.'_'.$this->_current_view.'_per_page', |
|
3717 | 3717 | ); |
3718 | 3718 | // ONLY add the screen option if the user has access to it. |
3719 | 3719 | if ($this->check_user_access($this->_current_view, true)) { |
@@ -3734,7 +3734,7 @@ discard block |
||
3734 | 3734 | { |
3735 | 3735 | if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) { |
3736 | 3736 | check_admin_referer('screen-options-nonce', 'screenoptionnonce'); |
3737 | - if (! $user = wp_get_current_user()) { |
|
3737 | + if ( ! $user = wp_get_current_user()) { |
|
3738 | 3738 | return; |
3739 | 3739 | } |
3740 | 3740 | $option = $_POST['wp_screen_options']['option']; |
@@ -3745,7 +3745,7 @@ discard block |
||
3745 | 3745 | $map_option = $option; |
3746 | 3746 | $option = str_replace('-', '_', $option); |
3747 | 3747 | switch ($map_option) { |
3748 | - case $this->_current_page . '_' . $this->_current_view . '_per_page': |
|
3748 | + case $this->_current_page.'_'.$this->_current_view.'_per_page': |
|
3749 | 3749 | $value = (int) $value; |
3750 | 3750 | $max_value = apply_filters( |
3751 | 3751 | 'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value', |
@@ -3803,13 +3803,13 @@ discard block |
||
3803 | 3803 | protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false) |
3804 | 3804 | { |
3805 | 3805 | $user_id = get_current_user_id(); |
3806 | - if (! $skip_route_verify) { |
|
3806 | + if ( ! $skip_route_verify) { |
|
3807 | 3807 | $this->_verify_route($route); |
3808 | 3808 | } |
3809 | 3809 | // now let's set the string for what kind of transient we're setting |
3810 | 3810 | $transient = $notices |
3811 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
3812 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
3811 | + ? 'ee_rte_n_tx_'.$route.'_'.$user_id |
|
3812 | + : 'rte_tx_'.$route.'_'.$user_id; |
|
3813 | 3813 | $data = $notices ? array('notices' => $data) : $data; |
3814 | 3814 | // is there already a transient for this route? If there is then let's ADD to that transient |
3815 | 3815 | $existing = is_multisite() && is_network_admin() |
@@ -3838,8 +3838,8 @@ discard block |
||
3838 | 3838 | $user_id = get_current_user_id(); |
3839 | 3839 | $route = ! $route ? $this->_req_action : $route; |
3840 | 3840 | $transient = $notices |
3841 | - ? 'ee_rte_n_tx_' . $route . '_' . $user_id |
|
3842 | - : 'rte_tx_' . $route . '_' . $user_id; |
|
3841 | + ? 'ee_rte_n_tx_'.$route.'_'.$user_id |
|
3842 | + : 'rte_tx_'.$route.'_'.$user_id; |
|
3843 | 3843 | $data = is_multisite() && is_network_admin() |
3844 | 3844 | ? get_site_transient($transient) |
3845 | 3845 | : get_transient($transient); |
@@ -4058,7 +4058,7 @@ discard block |
||
4058 | 4058 | */ |
4059 | 4059 | protected function _next_link($url, $class = 'dashicons dashicons-arrow-right') |
4060 | 4060 | { |
4061 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
4061 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
4062 | 4062 | } |
4063 | 4063 | |
4064 | 4064 | |
@@ -4071,7 +4071,7 @@ discard block |
||
4071 | 4071 | */ |
4072 | 4072 | protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left') |
4073 | 4073 | { |
4074 | - return '<a class="' . $class . '" href="' . $url . '"></a>'; |
|
4074 | + return '<a class="'.$class.'" href="'.$url.'"></a>'; |
|
4075 | 4075 | } |
4076 | 4076 | |
4077 | 4077 |
@@ -924,7 +924,7 @@ |
||
924 | 924 | * handles toggling the checkin status for the registration, |
925 | 925 | * |
926 | 926 | * @access protected |
927 | - * @return int|void |
|
927 | + * @return integer |
|
928 | 928 | * @throws EE_Error |
929 | 929 | * @throws InvalidArgumentException |
930 | 930 | * @throws InvalidDataTypeException |
@@ -16,1259 +16,1259 @@ |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * This is used to hold the reports template data which is setup early in the request. |
|
21 | - * |
|
22 | - * @type array |
|
23 | - */ |
|
24 | - protected $_reports_template_data = array(); |
|
19 | + /** |
|
20 | + * This is used to hold the reports template data which is setup early in the request. |
|
21 | + * |
|
22 | + * @type array |
|
23 | + */ |
|
24 | + protected $_reports_template_data = array(); |
|
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * Extend_Registrations_Admin_Page constructor. |
|
29 | - * |
|
30 | - * @param bool $routing |
|
31 | - */ |
|
32 | - public function __construct($routing = true) |
|
33 | - { |
|
34 | - parent::__construct($routing); |
|
35 | - if (! defined('REG_CAF_TEMPLATE_PATH')) { |
|
36 | - define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
37 | - define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
38 | - define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
39 | - } |
|
40 | - } |
|
27 | + /** |
|
28 | + * Extend_Registrations_Admin_Page constructor. |
|
29 | + * |
|
30 | + * @param bool $routing |
|
31 | + */ |
|
32 | + public function __construct($routing = true) |
|
33 | + { |
|
34 | + parent::__construct($routing); |
|
35 | + if (! defined('REG_CAF_TEMPLATE_PATH')) { |
|
36 | + define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
37 | + define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
38 | + define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
39 | + } |
|
40 | + } |
|
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * Extending page configuration. |
|
45 | - */ |
|
46 | - protected function _extend_page_config() |
|
47 | - { |
|
48 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
49 | - $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
50 | - ? $this->_req_data['_REG_ID'] |
|
51 | - : 0; |
|
52 | - $new_page_routes = array( |
|
53 | - 'reports' => array( |
|
54 | - 'func' => '_registration_reports', |
|
55 | - 'capability' => 'ee_read_registrations', |
|
56 | - ), |
|
57 | - 'registration_checkins' => array( |
|
58 | - 'func' => '_registration_checkin_list_table', |
|
59 | - 'capability' => 'ee_read_checkins', |
|
60 | - ), |
|
61 | - 'newsletter_selected_send' => array( |
|
62 | - 'func' => '_newsletter_selected_send', |
|
63 | - 'noheader' => true, |
|
64 | - 'capability' => 'ee_send_message', |
|
65 | - ), |
|
66 | - 'delete_checkin_rows' => array( |
|
67 | - 'func' => '_delete_checkin_rows', |
|
68 | - 'noheader' => true, |
|
69 | - 'capability' => 'ee_delete_checkins', |
|
70 | - ), |
|
71 | - 'delete_checkin_row' => array( |
|
72 | - 'func' => '_delete_checkin_row', |
|
73 | - 'noheader' => true, |
|
74 | - 'capability' => 'ee_delete_checkin', |
|
75 | - 'obj_id' => $reg_id, |
|
76 | - ), |
|
77 | - 'toggle_checkin_status' => array( |
|
78 | - 'func' => '_toggle_checkin_status', |
|
79 | - 'noheader' => true, |
|
80 | - 'capability' => 'ee_edit_checkin', |
|
81 | - 'obj_id' => $reg_id, |
|
82 | - ), |
|
83 | - 'toggle_checkin_status_bulk' => array( |
|
84 | - 'func' => '_toggle_checkin_status', |
|
85 | - 'noheader' => true, |
|
86 | - 'capability' => 'ee_edit_checkins', |
|
87 | - ), |
|
88 | - 'event_registrations' => array( |
|
89 | - 'func' => '_event_registrations_list_table', |
|
90 | - 'capability' => 'ee_read_checkins', |
|
91 | - ), |
|
92 | - 'registrations_checkin_report' => array( |
|
93 | - 'func' => '_registrations_checkin_report', |
|
94 | - 'noheader' => true, |
|
95 | - 'capability' => 'ee_read_registrations', |
|
96 | - ), |
|
97 | - ); |
|
98 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
99 | - $new_page_config = array( |
|
100 | - 'reports' => array( |
|
101 | - 'nav' => array( |
|
102 | - 'label' => esc_html__('Reports', 'event_espresso'), |
|
103 | - 'order' => 30, |
|
104 | - ), |
|
105 | - 'help_tabs' => array( |
|
106 | - 'registrations_reports_help_tab' => array( |
|
107 | - 'title' => esc_html__('Registration Reports', 'event_espresso'), |
|
108 | - 'filename' => 'registrations_reports', |
|
109 | - ), |
|
110 | - ), |
|
111 | - /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/ |
|
112 | - 'require_nonce' => false, |
|
113 | - ), |
|
114 | - 'event_registrations' => array( |
|
115 | - 'nav' => array( |
|
116 | - 'label' => esc_html__('Event Check-In', 'event_espresso'), |
|
117 | - 'order' => 10, |
|
118 | - 'persistent' => true, |
|
119 | - ), |
|
120 | - 'help_tabs' => array( |
|
121 | - 'registrations_event_checkin_help_tab' => array( |
|
122 | - 'title' => esc_html__('Registrations Event Check-In', 'event_espresso'), |
|
123 | - 'filename' => 'registrations_event_checkin', |
|
124 | - ), |
|
125 | - 'registrations_event_checkin_table_column_headings_help_tab' => array( |
|
126 | - 'title' => esc_html__('Event Check-In Table Column Headings', 'event_espresso'), |
|
127 | - 'filename' => 'registrations_event_checkin_table_column_headings', |
|
128 | - ), |
|
129 | - 'registrations_event_checkin_filters_help_tab' => array( |
|
130 | - 'title' => esc_html__('Event Check-In Filters', 'event_espresso'), |
|
131 | - 'filename' => 'registrations_event_checkin_filters', |
|
132 | - ), |
|
133 | - 'registrations_event_checkin_views_help_tab' => array( |
|
134 | - 'title' => esc_html__('Event Check-In Views', 'event_espresso'), |
|
135 | - 'filename' => 'registrations_event_checkin_views', |
|
136 | - ), |
|
137 | - 'registrations_event_checkin_other_help_tab' => array( |
|
138 | - 'title' => esc_html__('Event Check-In Other', 'event_espresso'), |
|
139 | - 'filename' => 'registrations_event_checkin_other', |
|
140 | - ), |
|
141 | - ), |
|
142 | - 'help_tour' => array('Event_Checkin_Help_Tour'), |
|
143 | - 'qtips' => array('Registration_List_Table_Tips'), |
|
144 | - 'list_table' => 'EE_Event_Registrations_List_Table', |
|
145 | - 'metaboxes' => array(), |
|
146 | - 'require_nonce' => false, |
|
147 | - ), |
|
148 | - 'registration_checkins' => array( |
|
149 | - 'nav' => array( |
|
150 | - 'label' => esc_html__('Check-In Records', 'event_espresso'), |
|
151 | - 'order' => 15, |
|
152 | - 'persistent' => false, |
|
153 | - 'url' => '', |
|
154 | - ), |
|
155 | - 'list_table' => 'EE_Registration_CheckIn_List_Table', |
|
156 | - // 'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ), |
|
157 | - 'metaboxes' => array(), |
|
158 | - 'require_nonce' => false, |
|
159 | - ), |
|
160 | - ); |
|
161 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
162 | - $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table'; |
|
163 | - $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table'; |
|
164 | - } |
|
43 | + /** |
|
44 | + * Extending page configuration. |
|
45 | + */ |
|
46 | + protected function _extend_page_config() |
|
47 | + { |
|
48 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
49 | + $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
50 | + ? $this->_req_data['_REG_ID'] |
|
51 | + : 0; |
|
52 | + $new_page_routes = array( |
|
53 | + 'reports' => array( |
|
54 | + 'func' => '_registration_reports', |
|
55 | + 'capability' => 'ee_read_registrations', |
|
56 | + ), |
|
57 | + 'registration_checkins' => array( |
|
58 | + 'func' => '_registration_checkin_list_table', |
|
59 | + 'capability' => 'ee_read_checkins', |
|
60 | + ), |
|
61 | + 'newsletter_selected_send' => array( |
|
62 | + 'func' => '_newsletter_selected_send', |
|
63 | + 'noheader' => true, |
|
64 | + 'capability' => 'ee_send_message', |
|
65 | + ), |
|
66 | + 'delete_checkin_rows' => array( |
|
67 | + 'func' => '_delete_checkin_rows', |
|
68 | + 'noheader' => true, |
|
69 | + 'capability' => 'ee_delete_checkins', |
|
70 | + ), |
|
71 | + 'delete_checkin_row' => array( |
|
72 | + 'func' => '_delete_checkin_row', |
|
73 | + 'noheader' => true, |
|
74 | + 'capability' => 'ee_delete_checkin', |
|
75 | + 'obj_id' => $reg_id, |
|
76 | + ), |
|
77 | + 'toggle_checkin_status' => array( |
|
78 | + 'func' => '_toggle_checkin_status', |
|
79 | + 'noheader' => true, |
|
80 | + 'capability' => 'ee_edit_checkin', |
|
81 | + 'obj_id' => $reg_id, |
|
82 | + ), |
|
83 | + 'toggle_checkin_status_bulk' => array( |
|
84 | + 'func' => '_toggle_checkin_status', |
|
85 | + 'noheader' => true, |
|
86 | + 'capability' => 'ee_edit_checkins', |
|
87 | + ), |
|
88 | + 'event_registrations' => array( |
|
89 | + 'func' => '_event_registrations_list_table', |
|
90 | + 'capability' => 'ee_read_checkins', |
|
91 | + ), |
|
92 | + 'registrations_checkin_report' => array( |
|
93 | + 'func' => '_registrations_checkin_report', |
|
94 | + 'noheader' => true, |
|
95 | + 'capability' => 'ee_read_registrations', |
|
96 | + ), |
|
97 | + ); |
|
98 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
99 | + $new_page_config = array( |
|
100 | + 'reports' => array( |
|
101 | + 'nav' => array( |
|
102 | + 'label' => esc_html__('Reports', 'event_espresso'), |
|
103 | + 'order' => 30, |
|
104 | + ), |
|
105 | + 'help_tabs' => array( |
|
106 | + 'registrations_reports_help_tab' => array( |
|
107 | + 'title' => esc_html__('Registration Reports', 'event_espresso'), |
|
108 | + 'filename' => 'registrations_reports', |
|
109 | + ), |
|
110 | + ), |
|
111 | + /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/ |
|
112 | + 'require_nonce' => false, |
|
113 | + ), |
|
114 | + 'event_registrations' => array( |
|
115 | + 'nav' => array( |
|
116 | + 'label' => esc_html__('Event Check-In', 'event_espresso'), |
|
117 | + 'order' => 10, |
|
118 | + 'persistent' => true, |
|
119 | + ), |
|
120 | + 'help_tabs' => array( |
|
121 | + 'registrations_event_checkin_help_tab' => array( |
|
122 | + 'title' => esc_html__('Registrations Event Check-In', 'event_espresso'), |
|
123 | + 'filename' => 'registrations_event_checkin', |
|
124 | + ), |
|
125 | + 'registrations_event_checkin_table_column_headings_help_tab' => array( |
|
126 | + 'title' => esc_html__('Event Check-In Table Column Headings', 'event_espresso'), |
|
127 | + 'filename' => 'registrations_event_checkin_table_column_headings', |
|
128 | + ), |
|
129 | + 'registrations_event_checkin_filters_help_tab' => array( |
|
130 | + 'title' => esc_html__('Event Check-In Filters', 'event_espresso'), |
|
131 | + 'filename' => 'registrations_event_checkin_filters', |
|
132 | + ), |
|
133 | + 'registrations_event_checkin_views_help_tab' => array( |
|
134 | + 'title' => esc_html__('Event Check-In Views', 'event_espresso'), |
|
135 | + 'filename' => 'registrations_event_checkin_views', |
|
136 | + ), |
|
137 | + 'registrations_event_checkin_other_help_tab' => array( |
|
138 | + 'title' => esc_html__('Event Check-In Other', 'event_espresso'), |
|
139 | + 'filename' => 'registrations_event_checkin_other', |
|
140 | + ), |
|
141 | + ), |
|
142 | + 'help_tour' => array('Event_Checkin_Help_Tour'), |
|
143 | + 'qtips' => array('Registration_List_Table_Tips'), |
|
144 | + 'list_table' => 'EE_Event_Registrations_List_Table', |
|
145 | + 'metaboxes' => array(), |
|
146 | + 'require_nonce' => false, |
|
147 | + ), |
|
148 | + 'registration_checkins' => array( |
|
149 | + 'nav' => array( |
|
150 | + 'label' => esc_html__('Check-In Records', 'event_espresso'), |
|
151 | + 'order' => 15, |
|
152 | + 'persistent' => false, |
|
153 | + 'url' => '', |
|
154 | + ), |
|
155 | + 'list_table' => 'EE_Registration_CheckIn_List_Table', |
|
156 | + // 'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ), |
|
157 | + 'metaboxes' => array(), |
|
158 | + 'require_nonce' => false, |
|
159 | + ), |
|
160 | + ); |
|
161 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
162 | + $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table'; |
|
163 | + $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table'; |
|
164 | + } |
|
165 | 165 | |
166 | 166 | |
167 | - /** |
|
168 | - * Ajax hooks for all routes in this page. |
|
169 | - */ |
|
170 | - protected function _ajax_hooks() |
|
171 | - { |
|
172 | - parent::_ajax_hooks(); |
|
173 | - add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content')); |
|
174 | - } |
|
167 | + /** |
|
168 | + * Ajax hooks for all routes in this page. |
|
169 | + */ |
|
170 | + protected function _ajax_hooks() |
|
171 | + { |
|
172 | + parent::_ajax_hooks(); |
|
173 | + add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content')); |
|
174 | + } |
|
175 | 175 | |
176 | 176 | |
177 | - /** |
|
178 | - * Global scripts for all routes in this page. |
|
179 | - */ |
|
180 | - public function load_scripts_styles() |
|
181 | - { |
|
182 | - parent::load_scripts_styles(); |
|
183 | - // if newsletter message type is active then let's add filter and load js for it. |
|
184 | - if (EEH_MSG_Template::is_mt_active('newsletter')) { |
|
185 | - // enqueue newsletter js |
|
186 | - wp_enqueue_script( |
|
187 | - 'ee-newsletter-trigger', |
|
188 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
189 | - array('ee-dialog'), |
|
190 | - EVENT_ESPRESSO_VERSION, |
|
191 | - true |
|
192 | - ); |
|
193 | - wp_enqueue_style( |
|
194 | - 'ee-newsletter-trigger-css', |
|
195 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
196 | - array(), |
|
197 | - EVENT_ESPRESSO_VERSION |
|
198 | - ); |
|
199 | - // hook in buttons for newsletter message type trigger. |
|
200 | - add_action( |
|
201 | - 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
202 | - array($this, 'add_newsletter_action_buttons'), |
|
203 | - 10 |
|
204 | - ); |
|
205 | - } |
|
206 | - } |
|
177 | + /** |
|
178 | + * Global scripts for all routes in this page. |
|
179 | + */ |
|
180 | + public function load_scripts_styles() |
|
181 | + { |
|
182 | + parent::load_scripts_styles(); |
|
183 | + // if newsletter message type is active then let's add filter and load js for it. |
|
184 | + if (EEH_MSG_Template::is_mt_active('newsletter')) { |
|
185 | + // enqueue newsletter js |
|
186 | + wp_enqueue_script( |
|
187 | + 'ee-newsletter-trigger', |
|
188 | + REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
189 | + array('ee-dialog'), |
|
190 | + EVENT_ESPRESSO_VERSION, |
|
191 | + true |
|
192 | + ); |
|
193 | + wp_enqueue_style( |
|
194 | + 'ee-newsletter-trigger-css', |
|
195 | + REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
196 | + array(), |
|
197 | + EVENT_ESPRESSO_VERSION |
|
198 | + ); |
|
199 | + // hook in buttons for newsletter message type trigger. |
|
200 | + add_action( |
|
201 | + 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
202 | + array($this, 'add_newsletter_action_buttons'), |
|
203 | + 10 |
|
204 | + ); |
|
205 | + } |
|
206 | + } |
|
207 | 207 | |
208 | 208 | |
209 | - /** |
|
210 | - * Scripts and styles for just the reports route. |
|
211 | - */ |
|
212 | - public function load_scripts_styles_reports() |
|
213 | - { |
|
214 | - wp_register_script( |
|
215 | - 'ee-reg-reports-js', |
|
216 | - REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
217 | - array('google-charts'), |
|
218 | - EVENT_ESPRESSO_VERSION, |
|
219 | - true |
|
220 | - ); |
|
221 | - wp_enqueue_script('ee-reg-reports-js'); |
|
222 | - $this->_registration_reports_js_setup(); |
|
223 | - } |
|
209 | + /** |
|
210 | + * Scripts and styles for just the reports route. |
|
211 | + */ |
|
212 | + public function load_scripts_styles_reports() |
|
213 | + { |
|
214 | + wp_register_script( |
|
215 | + 'ee-reg-reports-js', |
|
216 | + REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
217 | + array('google-charts'), |
|
218 | + EVENT_ESPRESSO_VERSION, |
|
219 | + true |
|
220 | + ); |
|
221 | + wp_enqueue_script('ee-reg-reports-js'); |
|
222 | + $this->_registration_reports_js_setup(); |
|
223 | + } |
|
224 | 224 | |
225 | 225 | |
226 | - /** |
|
227 | - * Register screen options for event_registrations route. |
|
228 | - */ |
|
229 | - protected function _add_screen_options_event_registrations() |
|
230 | - { |
|
231 | - $this->_per_page_screen_option(); |
|
232 | - } |
|
226 | + /** |
|
227 | + * Register screen options for event_registrations route. |
|
228 | + */ |
|
229 | + protected function _add_screen_options_event_registrations() |
|
230 | + { |
|
231 | + $this->_per_page_screen_option(); |
|
232 | + } |
|
233 | 233 | |
234 | 234 | |
235 | - /** |
|
236 | - * Register screen options for registration_checkins route |
|
237 | - */ |
|
238 | - protected function _add_screen_options_registration_checkins() |
|
239 | - { |
|
240 | - $page_title = $this->_admin_page_title; |
|
241 | - $this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso'); |
|
242 | - $this->_per_page_screen_option(); |
|
243 | - $this->_admin_page_title = $page_title; |
|
244 | - } |
|
235 | + /** |
|
236 | + * Register screen options for registration_checkins route |
|
237 | + */ |
|
238 | + protected function _add_screen_options_registration_checkins() |
|
239 | + { |
|
240 | + $page_title = $this->_admin_page_title; |
|
241 | + $this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso'); |
|
242 | + $this->_per_page_screen_option(); |
|
243 | + $this->_admin_page_title = $page_title; |
|
244 | + } |
|
245 | 245 | |
246 | 246 | |
247 | - /** |
|
248 | - * Set views property for event_registrations route. |
|
249 | - */ |
|
250 | - protected function _set_list_table_views_event_registrations() |
|
251 | - { |
|
252 | - $this->_views = array( |
|
253 | - 'all' => array( |
|
254 | - 'slug' => 'all', |
|
255 | - 'label' => esc_html__('All', 'event_espresso'), |
|
256 | - 'count' => 0, |
|
257 | - 'bulk_action' => ! isset($this->_req_data['event_id']) |
|
258 | - ? array() |
|
259 | - : array( |
|
260 | - 'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'), |
|
261 | - ), |
|
262 | - ), |
|
263 | - ); |
|
264 | - } |
|
247 | + /** |
|
248 | + * Set views property for event_registrations route. |
|
249 | + */ |
|
250 | + protected function _set_list_table_views_event_registrations() |
|
251 | + { |
|
252 | + $this->_views = array( |
|
253 | + 'all' => array( |
|
254 | + 'slug' => 'all', |
|
255 | + 'label' => esc_html__('All', 'event_espresso'), |
|
256 | + 'count' => 0, |
|
257 | + 'bulk_action' => ! isset($this->_req_data['event_id']) |
|
258 | + ? array() |
|
259 | + : array( |
|
260 | + 'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'), |
|
261 | + ), |
|
262 | + ), |
|
263 | + ); |
|
264 | + } |
|
265 | 265 | |
266 | 266 | |
267 | - /** |
|
268 | - * Set views property for registration_checkins route. |
|
269 | - */ |
|
270 | - protected function _set_list_table_views_registration_checkins() |
|
271 | - { |
|
272 | - $this->_views = array( |
|
273 | - 'all' => array( |
|
274 | - 'slug' => 'all', |
|
275 | - 'label' => esc_html__('All', 'event_espresso'), |
|
276 | - 'count' => 0, |
|
277 | - 'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')), |
|
278 | - ), |
|
279 | - ); |
|
280 | - } |
|
267 | + /** |
|
268 | + * Set views property for registration_checkins route. |
|
269 | + */ |
|
270 | + protected function _set_list_table_views_registration_checkins() |
|
271 | + { |
|
272 | + $this->_views = array( |
|
273 | + 'all' => array( |
|
274 | + 'slug' => 'all', |
|
275 | + 'label' => esc_html__('All', 'event_espresso'), |
|
276 | + 'count' => 0, |
|
277 | + 'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')), |
|
278 | + ), |
|
279 | + ); |
|
280 | + } |
|
281 | 281 | |
282 | 282 | |
283 | - /** |
|
284 | - * callback for ajax action. |
|
285 | - * |
|
286 | - * @since 4.3.0 |
|
287 | - * @return void (JSON) |
|
288 | - * @throws EE_Error |
|
289 | - * @throws InvalidArgumentException |
|
290 | - * @throws InvalidDataTypeException |
|
291 | - * @throws InvalidInterfaceException |
|
292 | - */ |
|
293 | - public function get_newsletter_form_content() |
|
294 | - { |
|
295 | - // do a nonce check cause we're not coming in from an normal route here. |
|
296 | - $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field( |
|
297 | - $this->_req_data['get_newsletter_form_content_nonce'] |
|
298 | - ) : ''; |
|
299 | - $nonce_ref = 'get_newsletter_form_content_nonce'; |
|
300 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
301 | - // let's get the mtp for the incoming MTP_ ID |
|
302 | - if (! isset($this->_req_data['GRP_ID'])) { |
|
303 | - EE_Error::add_error( |
|
304 | - esc_html__( |
|
305 | - 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
|
306 | - 'event_espresso' |
|
307 | - ), |
|
308 | - __FILE__, |
|
309 | - __FUNCTION__, |
|
310 | - __LINE__ |
|
311 | - ); |
|
312 | - $this->_template_args['success'] = false; |
|
313 | - $this->_template_args['error'] = true; |
|
314 | - $this->_return_json(); |
|
315 | - } |
|
316 | - $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
|
317 | - if (! $MTPG instanceof EE_Message_Template_Group) { |
|
318 | - EE_Error::add_error( |
|
319 | - sprintf( |
|
320 | - esc_html__( |
|
321 | - 'The GRP_ID given (%d) does not appear to have a corresponding row in the database.', |
|
322 | - 'event_espresso' |
|
323 | - ), |
|
324 | - $this->_req_data['GRP_ID'] |
|
325 | - ), |
|
326 | - __FILE__, |
|
327 | - __FUNCTION__, |
|
328 | - __LINE__ |
|
329 | - ); |
|
330 | - $this->_template_args['success'] = false; |
|
331 | - $this->_template_args['error'] = true; |
|
332 | - $this->_return_json(); |
|
333 | - } |
|
334 | - $MTPs = $MTPG->context_templates(); |
|
335 | - $MTPs = $MTPs['attendee']; |
|
336 | - $template_fields = array(); |
|
337 | - /** @var EE_Message_Template $MTP */ |
|
338 | - foreach ($MTPs as $MTP) { |
|
339 | - $field = $MTP->get('MTP_template_field'); |
|
340 | - if ($field === 'content') { |
|
341 | - $content = $MTP->get('MTP_content'); |
|
342 | - if (! empty($content['newsletter_content'])) { |
|
343 | - $template_fields['newsletter_content'] = $content['newsletter_content']; |
|
344 | - } |
|
345 | - continue; |
|
346 | - } |
|
347 | - $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content'); |
|
348 | - } |
|
349 | - $this->_template_args['success'] = true; |
|
350 | - $this->_template_args['error'] = false; |
|
351 | - $this->_template_args['data'] = array( |
|
352 | - 'batch_message_from' => isset($template_fields['from']) |
|
353 | - ? $template_fields['from'] |
|
354 | - : '', |
|
355 | - 'batch_message_subject' => isset($template_fields['subject']) |
|
356 | - ? $template_fields['subject'] |
|
357 | - : '', |
|
358 | - 'batch_message_content' => isset($template_fields['newsletter_content']) |
|
359 | - ? $template_fields['newsletter_content'] |
|
360 | - : '', |
|
361 | - ); |
|
362 | - $this->_return_json(); |
|
363 | - } |
|
283 | + /** |
|
284 | + * callback for ajax action. |
|
285 | + * |
|
286 | + * @since 4.3.0 |
|
287 | + * @return void (JSON) |
|
288 | + * @throws EE_Error |
|
289 | + * @throws InvalidArgumentException |
|
290 | + * @throws InvalidDataTypeException |
|
291 | + * @throws InvalidInterfaceException |
|
292 | + */ |
|
293 | + public function get_newsletter_form_content() |
|
294 | + { |
|
295 | + // do a nonce check cause we're not coming in from an normal route here. |
|
296 | + $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field( |
|
297 | + $this->_req_data['get_newsletter_form_content_nonce'] |
|
298 | + ) : ''; |
|
299 | + $nonce_ref = 'get_newsletter_form_content_nonce'; |
|
300 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
301 | + // let's get the mtp for the incoming MTP_ ID |
|
302 | + if (! isset($this->_req_data['GRP_ID'])) { |
|
303 | + EE_Error::add_error( |
|
304 | + esc_html__( |
|
305 | + 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
|
306 | + 'event_espresso' |
|
307 | + ), |
|
308 | + __FILE__, |
|
309 | + __FUNCTION__, |
|
310 | + __LINE__ |
|
311 | + ); |
|
312 | + $this->_template_args['success'] = false; |
|
313 | + $this->_template_args['error'] = true; |
|
314 | + $this->_return_json(); |
|
315 | + } |
|
316 | + $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
|
317 | + if (! $MTPG instanceof EE_Message_Template_Group) { |
|
318 | + EE_Error::add_error( |
|
319 | + sprintf( |
|
320 | + esc_html__( |
|
321 | + 'The GRP_ID given (%d) does not appear to have a corresponding row in the database.', |
|
322 | + 'event_espresso' |
|
323 | + ), |
|
324 | + $this->_req_data['GRP_ID'] |
|
325 | + ), |
|
326 | + __FILE__, |
|
327 | + __FUNCTION__, |
|
328 | + __LINE__ |
|
329 | + ); |
|
330 | + $this->_template_args['success'] = false; |
|
331 | + $this->_template_args['error'] = true; |
|
332 | + $this->_return_json(); |
|
333 | + } |
|
334 | + $MTPs = $MTPG->context_templates(); |
|
335 | + $MTPs = $MTPs['attendee']; |
|
336 | + $template_fields = array(); |
|
337 | + /** @var EE_Message_Template $MTP */ |
|
338 | + foreach ($MTPs as $MTP) { |
|
339 | + $field = $MTP->get('MTP_template_field'); |
|
340 | + if ($field === 'content') { |
|
341 | + $content = $MTP->get('MTP_content'); |
|
342 | + if (! empty($content['newsletter_content'])) { |
|
343 | + $template_fields['newsletter_content'] = $content['newsletter_content']; |
|
344 | + } |
|
345 | + continue; |
|
346 | + } |
|
347 | + $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content'); |
|
348 | + } |
|
349 | + $this->_template_args['success'] = true; |
|
350 | + $this->_template_args['error'] = false; |
|
351 | + $this->_template_args['data'] = array( |
|
352 | + 'batch_message_from' => isset($template_fields['from']) |
|
353 | + ? $template_fields['from'] |
|
354 | + : '', |
|
355 | + 'batch_message_subject' => isset($template_fields['subject']) |
|
356 | + ? $template_fields['subject'] |
|
357 | + : '', |
|
358 | + 'batch_message_content' => isset($template_fields['newsletter_content']) |
|
359 | + ? $template_fields['newsletter_content'] |
|
360 | + : '', |
|
361 | + ); |
|
362 | + $this->_return_json(); |
|
363 | + } |
|
364 | 364 | |
365 | 365 | |
366 | - /** |
|
367 | - * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action |
|
368 | - * |
|
369 | - * @since 4.3.0 |
|
370 | - * @param EE_Admin_List_Table $list_table |
|
371 | - * @return void |
|
372 | - * @throws InvalidArgumentException |
|
373 | - * @throws InvalidDataTypeException |
|
374 | - * @throws InvalidInterfaceException |
|
375 | - */ |
|
376 | - public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
|
377 | - { |
|
378 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
379 | - 'ee_send_message', |
|
380 | - 'espresso_registrations_newsletter_selected_send' |
|
381 | - ) |
|
382 | - ) { |
|
383 | - return; |
|
384 | - } |
|
385 | - $routes_to_add_to = array( |
|
386 | - 'contact_list', |
|
387 | - 'event_registrations', |
|
388 | - 'default', |
|
389 | - ); |
|
390 | - if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) { |
|
391 | - if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id'])) |
|
392 | - || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash') |
|
393 | - ) { |
|
394 | - echo ''; |
|
395 | - } else { |
|
396 | - $button_text = sprintf( |
|
397 | - esc_html__('Send Batch Message (%s selected)', 'event_espresso'), |
|
398 | - '<span class="send-selected-newsletter-count">0</span>' |
|
399 | - ); |
|
400 | - echo '<button id="selected-batch-send-trigger" class="button secondary-button">' |
|
401 | - . '<span class="dashicons dashicons-email "></span>' |
|
402 | - . $button_text |
|
403 | - . '</button>'; |
|
404 | - add_action('admin_footer', array($this, 'newsletter_send_form_skeleton')); |
|
405 | - } |
|
406 | - } |
|
407 | - } |
|
366 | + /** |
|
367 | + * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action |
|
368 | + * |
|
369 | + * @since 4.3.0 |
|
370 | + * @param EE_Admin_List_Table $list_table |
|
371 | + * @return void |
|
372 | + * @throws InvalidArgumentException |
|
373 | + * @throws InvalidDataTypeException |
|
374 | + * @throws InvalidInterfaceException |
|
375 | + */ |
|
376 | + public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
|
377 | + { |
|
378 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
379 | + 'ee_send_message', |
|
380 | + 'espresso_registrations_newsletter_selected_send' |
|
381 | + ) |
|
382 | + ) { |
|
383 | + return; |
|
384 | + } |
|
385 | + $routes_to_add_to = array( |
|
386 | + 'contact_list', |
|
387 | + 'event_registrations', |
|
388 | + 'default', |
|
389 | + ); |
|
390 | + if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) { |
|
391 | + if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id'])) |
|
392 | + || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash') |
|
393 | + ) { |
|
394 | + echo ''; |
|
395 | + } else { |
|
396 | + $button_text = sprintf( |
|
397 | + esc_html__('Send Batch Message (%s selected)', 'event_espresso'), |
|
398 | + '<span class="send-selected-newsletter-count">0</span>' |
|
399 | + ); |
|
400 | + echo '<button id="selected-batch-send-trigger" class="button secondary-button">' |
|
401 | + . '<span class="dashicons dashicons-email "></span>' |
|
402 | + . $button_text |
|
403 | + . '</button>'; |
|
404 | + add_action('admin_footer', array($this, 'newsletter_send_form_skeleton')); |
|
405 | + } |
|
406 | + } |
|
407 | + } |
|
408 | 408 | |
409 | 409 | |
410 | - /** |
|
411 | - * @throws DomainException |
|
412 | - * @throws EE_Error |
|
413 | - * @throws InvalidArgumentException |
|
414 | - * @throws InvalidDataTypeException |
|
415 | - * @throws InvalidInterfaceException |
|
416 | - */ |
|
417 | - public function newsletter_send_form_skeleton() |
|
418 | - { |
|
419 | - $list_table = $this->_list_table_object; |
|
420 | - $codes = array(); |
|
421 | - // need to templates for the newsletter message type for the template selector. |
|
422 | - $values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0); |
|
423 | - $mtps = EEM_Message_Template_Group::instance()->get_all( |
|
424 | - array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')) |
|
425 | - ); |
|
426 | - foreach ($mtps as $mtp) { |
|
427 | - $name = $mtp->name(); |
|
428 | - $values[] = array( |
|
429 | - 'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name, |
|
430 | - 'id' => $mtp->ID(), |
|
431 | - ); |
|
432 | - } |
|
433 | - // need to get a list of shortcodes that are available for the newsletter message type. |
|
434 | - $shortcodes = EEH_MSG_Template::get_shortcodes( |
|
435 | - 'newsletter', |
|
436 | - 'email', |
|
437 | - array(), |
|
438 | - 'attendee', |
|
439 | - false |
|
440 | - ); |
|
441 | - foreach ($shortcodes as $field => $shortcode_array) { |
|
442 | - $available_shortcodes = array(); |
|
443 | - foreach ($shortcode_array as $shortcode => $shortcode_details) { |
|
444 | - $field_id = $field === '[NEWSLETTER_CONTENT]' |
|
445 | - ? 'content' |
|
446 | - : $field; |
|
447 | - $field_id = 'batch-message-' . strtolower($field_id); |
|
448 | - $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="' |
|
449 | - . $shortcode |
|
450 | - . '" data-linked-input-id="' . $field_id . '">' |
|
451 | - . $shortcode |
|
452 | - . '</span>'; |
|
453 | - } |
|
454 | - $codes[ $field ] = implode(', ', $available_shortcodes); |
|
455 | - } |
|
456 | - $shortcodes = $codes; |
|
457 | - $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
458 | - $form_template_args = array( |
|
459 | - 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
|
460 | - 'form_route' => 'newsletter_selected_send', |
|
461 | - 'form_nonce_name' => 'newsletter_selected_send_nonce', |
|
462 | - 'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'), |
|
463 | - 'redirect_back_to' => $this->_req_action, |
|
464 | - 'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'), |
|
465 | - 'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values), |
|
466 | - 'shortcodes' => $shortcodes, |
|
467 | - 'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration', |
|
468 | - ); |
|
469 | - EEH_Template::display_template($form_template, $form_template_args); |
|
470 | - } |
|
410 | + /** |
|
411 | + * @throws DomainException |
|
412 | + * @throws EE_Error |
|
413 | + * @throws InvalidArgumentException |
|
414 | + * @throws InvalidDataTypeException |
|
415 | + * @throws InvalidInterfaceException |
|
416 | + */ |
|
417 | + public function newsletter_send_form_skeleton() |
|
418 | + { |
|
419 | + $list_table = $this->_list_table_object; |
|
420 | + $codes = array(); |
|
421 | + // need to templates for the newsletter message type for the template selector. |
|
422 | + $values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0); |
|
423 | + $mtps = EEM_Message_Template_Group::instance()->get_all( |
|
424 | + array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')) |
|
425 | + ); |
|
426 | + foreach ($mtps as $mtp) { |
|
427 | + $name = $mtp->name(); |
|
428 | + $values[] = array( |
|
429 | + 'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name, |
|
430 | + 'id' => $mtp->ID(), |
|
431 | + ); |
|
432 | + } |
|
433 | + // need to get a list of shortcodes that are available for the newsletter message type. |
|
434 | + $shortcodes = EEH_MSG_Template::get_shortcodes( |
|
435 | + 'newsletter', |
|
436 | + 'email', |
|
437 | + array(), |
|
438 | + 'attendee', |
|
439 | + false |
|
440 | + ); |
|
441 | + foreach ($shortcodes as $field => $shortcode_array) { |
|
442 | + $available_shortcodes = array(); |
|
443 | + foreach ($shortcode_array as $shortcode => $shortcode_details) { |
|
444 | + $field_id = $field === '[NEWSLETTER_CONTENT]' |
|
445 | + ? 'content' |
|
446 | + : $field; |
|
447 | + $field_id = 'batch-message-' . strtolower($field_id); |
|
448 | + $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="' |
|
449 | + . $shortcode |
|
450 | + . '" data-linked-input-id="' . $field_id . '">' |
|
451 | + . $shortcode |
|
452 | + . '</span>'; |
|
453 | + } |
|
454 | + $codes[ $field ] = implode(', ', $available_shortcodes); |
|
455 | + } |
|
456 | + $shortcodes = $codes; |
|
457 | + $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
458 | + $form_template_args = array( |
|
459 | + 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
|
460 | + 'form_route' => 'newsletter_selected_send', |
|
461 | + 'form_nonce_name' => 'newsletter_selected_send_nonce', |
|
462 | + 'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'), |
|
463 | + 'redirect_back_to' => $this->_req_action, |
|
464 | + 'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'), |
|
465 | + 'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values), |
|
466 | + 'shortcodes' => $shortcodes, |
|
467 | + 'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration', |
|
468 | + ); |
|
469 | + EEH_Template::display_template($form_template, $form_template_args); |
|
470 | + } |
|
471 | 471 | |
472 | 472 | |
473 | - /** |
|
474 | - * Handles sending selected registrations/contacts a newsletter. |
|
475 | - * |
|
476 | - * @since 4.3.0 |
|
477 | - * @return void |
|
478 | - * @throws EE_Error |
|
479 | - * @throws InvalidArgumentException |
|
480 | - * @throws InvalidDataTypeException |
|
481 | - * @throws InvalidInterfaceException |
|
482 | - */ |
|
483 | - protected function _newsletter_selected_send() |
|
484 | - { |
|
485 | - $success = true; |
|
486 | - // first we need to make sure we have a GRP_ID so we know what template we're sending and updating! |
|
487 | - if (empty($this->_req_data['newsletter_mtp_selected'])) { |
|
488 | - EE_Error::add_error( |
|
489 | - esc_html__( |
|
490 | - 'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', |
|
491 | - 'event_espresso' |
|
492 | - ), |
|
493 | - __FILE__, |
|
494 | - __FUNCTION__, |
|
495 | - __LINE__ |
|
496 | - ); |
|
497 | - $success = false; |
|
498 | - } |
|
499 | - if ($success) { |
|
500 | - // update Message template in case there are any changes |
|
501 | - $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
502 | - $this->_req_data['newsletter_mtp_selected'] |
|
503 | - ); |
|
504 | - $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group |
|
505 | - ? $Message_Template_Group->context_templates() |
|
506 | - : array(); |
|
507 | - if (empty($Message_Templates)) { |
|
508 | - EE_Error::add_error( |
|
509 | - esc_html__( |
|
510 | - 'Unable to retrieve message template fields from the db. Messages not sent.', |
|
511 | - 'event_espresso' |
|
512 | - ), |
|
513 | - __FILE__, |
|
514 | - __FUNCTION__, |
|
515 | - __LINE__ |
|
516 | - ); |
|
517 | - } |
|
518 | - // let's just update the specific fields |
|
519 | - foreach ($Message_Templates['attendee'] as $Message_Template) { |
|
520 | - if ($Message_Template instanceof EE_Message_Template) { |
|
521 | - $field = $Message_Template->get('MTP_template_field'); |
|
522 | - $content = $Message_Template->get('MTP_content'); |
|
523 | - $new_content = $content; |
|
524 | - switch ($field) { |
|
525 | - case 'from': |
|
526 | - $new_content = ! empty($this->_req_data['batch_message']['from']) |
|
527 | - ? $this->_req_data['batch_message']['from'] |
|
528 | - : $content; |
|
529 | - break; |
|
530 | - case 'subject': |
|
531 | - $new_content = ! empty($this->_req_data['batch_message']['subject']) |
|
532 | - ? $this->_req_data['batch_message']['subject'] |
|
533 | - : $content; |
|
534 | - break; |
|
535 | - case 'content': |
|
536 | - $new_content = $content; |
|
537 | - $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content']) |
|
538 | - ? $this->_req_data['batch_message']['content'] |
|
539 | - : $content['newsletter_content']; |
|
540 | - break; |
|
541 | - default: |
|
542 | - // continue the foreach loop, we don't want to set $new_content nor save. |
|
543 | - continue 2; |
|
544 | - } |
|
545 | - $Message_Template->set('MTP_content', $new_content); |
|
546 | - $Message_Template->save(); |
|
547 | - } |
|
548 | - } |
|
549 | - // great fields are updated! now let's make sure we just have contact objects (EE_Attendee). |
|
550 | - $id_type = ! empty($this->_req_data['batch_message']['id_type']) |
|
551 | - ? $this->_req_data['batch_message']['id_type'] |
|
552 | - : 'registration'; |
|
553 | - // id_type will affect how we assemble the ids. |
|
554 | - $ids = ! empty($this->_req_data['batch_message']['ids']) |
|
555 | - ? json_decode(stripslashes($this->_req_data['batch_message']['ids'])) |
|
556 | - : array(); |
|
557 | - $registrations_used_for_contact_data = array(); |
|
558 | - // using switch because eventually we'll have other contexts that will be used for generating messages. |
|
559 | - switch ($id_type) { |
|
560 | - case 'registration': |
|
561 | - $registrations_used_for_contact_data = EEM_Registration::instance()->get_all( |
|
562 | - array( |
|
563 | - array( |
|
564 | - 'REG_ID' => array('IN', $ids), |
|
565 | - ), |
|
566 | - ) |
|
567 | - ); |
|
568 | - break; |
|
569 | - case 'contact': |
|
570 | - $registrations_used_for_contact_data = EEM_Registration::instance() |
|
571 | - ->get_latest_registration_for_each_of_given_contacts( |
|
572 | - $ids |
|
573 | - ); |
|
574 | - break; |
|
575 | - } |
|
576 | - do_action_ref_array( |
|
577 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
578 | - array( |
|
579 | - $registrations_used_for_contact_data, |
|
580 | - $Message_Template_Group->ID(), |
|
581 | - ) |
|
582 | - ); |
|
583 | - // kept for backward compat, internally we no longer use this action. |
|
584 | - // @deprecated 4.8.36.rc.002 |
|
585 | - $contacts = $id_type === 'registration' |
|
586 | - ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids) |
|
587 | - : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids)))); |
|
588 | - do_action_ref_array( |
|
589 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', |
|
590 | - array( |
|
591 | - $contacts, |
|
592 | - $Message_Template_Group->ID(), |
|
593 | - ) |
|
594 | - ); |
|
595 | - } |
|
596 | - $query_args = array( |
|
597 | - 'action' => ! empty($this->_req_data['redirect_back_to']) |
|
598 | - ? $this->_req_data['redirect_back_to'] |
|
599 | - : 'default', |
|
600 | - ); |
|
601 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
602 | - } |
|
473 | + /** |
|
474 | + * Handles sending selected registrations/contacts a newsletter. |
|
475 | + * |
|
476 | + * @since 4.3.0 |
|
477 | + * @return void |
|
478 | + * @throws EE_Error |
|
479 | + * @throws InvalidArgumentException |
|
480 | + * @throws InvalidDataTypeException |
|
481 | + * @throws InvalidInterfaceException |
|
482 | + */ |
|
483 | + protected function _newsletter_selected_send() |
|
484 | + { |
|
485 | + $success = true; |
|
486 | + // first we need to make sure we have a GRP_ID so we know what template we're sending and updating! |
|
487 | + if (empty($this->_req_data['newsletter_mtp_selected'])) { |
|
488 | + EE_Error::add_error( |
|
489 | + esc_html__( |
|
490 | + 'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', |
|
491 | + 'event_espresso' |
|
492 | + ), |
|
493 | + __FILE__, |
|
494 | + __FUNCTION__, |
|
495 | + __LINE__ |
|
496 | + ); |
|
497 | + $success = false; |
|
498 | + } |
|
499 | + if ($success) { |
|
500 | + // update Message template in case there are any changes |
|
501 | + $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
502 | + $this->_req_data['newsletter_mtp_selected'] |
|
503 | + ); |
|
504 | + $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group |
|
505 | + ? $Message_Template_Group->context_templates() |
|
506 | + : array(); |
|
507 | + if (empty($Message_Templates)) { |
|
508 | + EE_Error::add_error( |
|
509 | + esc_html__( |
|
510 | + 'Unable to retrieve message template fields from the db. Messages not sent.', |
|
511 | + 'event_espresso' |
|
512 | + ), |
|
513 | + __FILE__, |
|
514 | + __FUNCTION__, |
|
515 | + __LINE__ |
|
516 | + ); |
|
517 | + } |
|
518 | + // let's just update the specific fields |
|
519 | + foreach ($Message_Templates['attendee'] as $Message_Template) { |
|
520 | + if ($Message_Template instanceof EE_Message_Template) { |
|
521 | + $field = $Message_Template->get('MTP_template_field'); |
|
522 | + $content = $Message_Template->get('MTP_content'); |
|
523 | + $new_content = $content; |
|
524 | + switch ($field) { |
|
525 | + case 'from': |
|
526 | + $new_content = ! empty($this->_req_data['batch_message']['from']) |
|
527 | + ? $this->_req_data['batch_message']['from'] |
|
528 | + : $content; |
|
529 | + break; |
|
530 | + case 'subject': |
|
531 | + $new_content = ! empty($this->_req_data['batch_message']['subject']) |
|
532 | + ? $this->_req_data['batch_message']['subject'] |
|
533 | + : $content; |
|
534 | + break; |
|
535 | + case 'content': |
|
536 | + $new_content = $content; |
|
537 | + $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content']) |
|
538 | + ? $this->_req_data['batch_message']['content'] |
|
539 | + : $content['newsletter_content']; |
|
540 | + break; |
|
541 | + default: |
|
542 | + // continue the foreach loop, we don't want to set $new_content nor save. |
|
543 | + continue 2; |
|
544 | + } |
|
545 | + $Message_Template->set('MTP_content', $new_content); |
|
546 | + $Message_Template->save(); |
|
547 | + } |
|
548 | + } |
|
549 | + // great fields are updated! now let's make sure we just have contact objects (EE_Attendee). |
|
550 | + $id_type = ! empty($this->_req_data['batch_message']['id_type']) |
|
551 | + ? $this->_req_data['batch_message']['id_type'] |
|
552 | + : 'registration'; |
|
553 | + // id_type will affect how we assemble the ids. |
|
554 | + $ids = ! empty($this->_req_data['batch_message']['ids']) |
|
555 | + ? json_decode(stripslashes($this->_req_data['batch_message']['ids'])) |
|
556 | + : array(); |
|
557 | + $registrations_used_for_contact_data = array(); |
|
558 | + // using switch because eventually we'll have other contexts that will be used for generating messages. |
|
559 | + switch ($id_type) { |
|
560 | + case 'registration': |
|
561 | + $registrations_used_for_contact_data = EEM_Registration::instance()->get_all( |
|
562 | + array( |
|
563 | + array( |
|
564 | + 'REG_ID' => array('IN', $ids), |
|
565 | + ), |
|
566 | + ) |
|
567 | + ); |
|
568 | + break; |
|
569 | + case 'contact': |
|
570 | + $registrations_used_for_contact_data = EEM_Registration::instance() |
|
571 | + ->get_latest_registration_for_each_of_given_contacts( |
|
572 | + $ids |
|
573 | + ); |
|
574 | + break; |
|
575 | + } |
|
576 | + do_action_ref_array( |
|
577 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
578 | + array( |
|
579 | + $registrations_used_for_contact_data, |
|
580 | + $Message_Template_Group->ID(), |
|
581 | + ) |
|
582 | + ); |
|
583 | + // kept for backward compat, internally we no longer use this action. |
|
584 | + // @deprecated 4.8.36.rc.002 |
|
585 | + $contacts = $id_type === 'registration' |
|
586 | + ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids) |
|
587 | + : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids)))); |
|
588 | + do_action_ref_array( |
|
589 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', |
|
590 | + array( |
|
591 | + $contacts, |
|
592 | + $Message_Template_Group->ID(), |
|
593 | + ) |
|
594 | + ); |
|
595 | + } |
|
596 | + $query_args = array( |
|
597 | + 'action' => ! empty($this->_req_data['redirect_back_to']) |
|
598 | + ? $this->_req_data['redirect_back_to'] |
|
599 | + : 'default', |
|
600 | + ); |
|
601 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
602 | + } |
|
603 | 603 | |
604 | 604 | |
605 | - /** |
|
606 | - * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
607 | - * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method. |
|
608 | - */ |
|
609 | - protected function _registration_reports_js_setup() |
|
610 | - { |
|
611 | - $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report(); |
|
612 | - $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report(); |
|
613 | - } |
|
605 | + /** |
|
606 | + * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
607 | + * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method. |
|
608 | + */ |
|
609 | + protected function _registration_reports_js_setup() |
|
610 | + { |
|
611 | + $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report(); |
|
612 | + $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report(); |
|
613 | + } |
|
614 | 614 | |
615 | 615 | |
616 | - /** |
|
617 | - * generates Business Reports regarding Registrations |
|
618 | - * |
|
619 | - * @access protected |
|
620 | - * @return void |
|
621 | - * @throws DomainException |
|
622 | - */ |
|
623 | - protected function _registration_reports() |
|
624 | - { |
|
625 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
626 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
627 | - $template_path, |
|
628 | - $this->_reports_template_data, |
|
629 | - true |
|
630 | - ); |
|
631 | - // the final template wrapper |
|
632 | - $this->display_admin_page_with_no_sidebar(); |
|
633 | - } |
|
616 | + /** |
|
617 | + * generates Business Reports regarding Registrations |
|
618 | + * |
|
619 | + * @access protected |
|
620 | + * @return void |
|
621 | + * @throws DomainException |
|
622 | + */ |
|
623 | + protected function _registration_reports() |
|
624 | + { |
|
625 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
626 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
627 | + $template_path, |
|
628 | + $this->_reports_template_data, |
|
629 | + true |
|
630 | + ); |
|
631 | + // the final template wrapper |
|
632 | + $this->display_admin_page_with_no_sidebar(); |
|
633 | + } |
|
634 | 634 | |
635 | 635 | |
636 | - /** |
|
637 | - * Generates Business Report showing total registrations per day. |
|
638 | - * |
|
639 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
640 | - * @return string |
|
641 | - * @throws EE_Error |
|
642 | - * @throws InvalidArgumentException |
|
643 | - * @throws InvalidDataTypeException |
|
644 | - * @throws InvalidInterfaceException |
|
645 | - */ |
|
646 | - private function _registrations_per_day_report($period = '-1 month') |
|
647 | - { |
|
648 | - $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
|
649 | - $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
|
650 | - $results = (array) $results; |
|
651 | - $regs = array(); |
|
652 | - $subtitle = ''; |
|
653 | - if ($results) { |
|
654 | - $column_titles = array(); |
|
655 | - $tracker = 0; |
|
656 | - foreach ($results as $result) { |
|
657 | - $report_column_values = array(); |
|
658 | - foreach ($result as $property_name => $property_value) { |
|
659 | - $property_value = $property_name === 'Registration_REG_date' ? $property_value |
|
660 | - : (int) $property_value; |
|
661 | - $report_column_values[] = $property_value; |
|
662 | - if ($tracker === 0) { |
|
663 | - if ($property_name === 'Registration_REG_date') { |
|
664 | - $column_titles[] = esc_html__( |
|
665 | - 'Date (only days with registrations are shown)', |
|
666 | - 'event_espresso' |
|
667 | - ); |
|
668 | - } else { |
|
669 | - $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
670 | - } |
|
671 | - } |
|
672 | - } |
|
673 | - $tracker++; |
|
674 | - $regs[] = $report_column_values; |
|
675 | - } |
|
676 | - // make sure the column_titles is pushed to the beginning of the array |
|
677 | - array_unshift($regs, $column_titles); |
|
678 | - // setup the date range. |
|
679 | - $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
680 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
681 | - $ending_date = new DateTime("now", $DateTimeZone); |
|
682 | - $subtitle = sprintf( |
|
683 | - _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
684 | - $beginning_date->format('Y-m-d'), |
|
685 | - $ending_date->format('Y-m-d') |
|
686 | - ); |
|
687 | - } |
|
688 | - $report_title = esc_html__('Total Registrations per Day', 'event_espresso'); |
|
689 | - $report_params = array( |
|
690 | - 'title' => $report_title, |
|
691 | - 'subtitle' => $subtitle, |
|
692 | - 'id' => $report_ID, |
|
693 | - 'regs' => $regs, |
|
694 | - 'noResults' => empty($regs), |
|
695 | - 'noRegsMsg' => sprintf( |
|
696 | - esc_html__( |
|
697 | - '%sThere are currently no registration records in the last month for this report.%s', |
|
698 | - 'event_espresso' |
|
699 | - ), |
|
700 | - '<h2>' . $report_title . '</h2><p>', |
|
701 | - '</p>' |
|
702 | - ), |
|
703 | - ); |
|
704 | - wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params); |
|
705 | - return $report_ID; |
|
706 | - } |
|
636 | + /** |
|
637 | + * Generates Business Report showing total registrations per day. |
|
638 | + * |
|
639 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
640 | + * @return string |
|
641 | + * @throws EE_Error |
|
642 | + * @throws InvalidArgumentException |
|
643 | + * @throws InvalidDataTypeException |
|
644 | + * @throws InvalidInterfaceException |
|
645 | + */ |
|
646 | + private function _registrations_per_day_report($period = '-1 month') |
|
647 | + { |
|
648 | + $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
|
649 | + $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
|
650 | + $results = (array) $results; |
|
651 | + $regs = array(); |
|
652 | + $subtitle = ''; |
|
653 | + if ($results) { |
|
654 | + $column_titles = array(); |
|
655 | + $tracker = 0; |
|
656 | + foreach ($results as $result) { |
|
657 | + $report_column_values = array(); |
|
658 | + foreach ($result as $property_name => $property_value) { |
|
659 | + $property_value = $property_name === 'Registration_REG_date' ? $property_value |
|
660 | + : (int) $property_value; |
|
661 | + $report_column_values[] = $property_value; |
|
662 | + if ($tracker === 0) { |
|
663 | + if ($property_name === 'Registration_REG_date') { |
|
664 | + $column_titles[] = esc_html__( |
|
665 | + 'Date (only days with registrations are shown)', |
|
666 | + 'event_espresso' |
|
667 | + ); |
|
668 | + } else { |
|
669 | + $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
670 | + } |
|
671 | + } |
|
672 | + } |
|
673 | + $tracker++; |
|
674 | + $regs[] = $report_column_values; |
|
675 | + } |
|
676 | + // make sure the column_titles is pushed to the beginning of the array |
|
677 | + array_unshift($regs, $column_titles); |
|
678 | + // setup the date range. |
|
679 | + $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
680 | + $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
681 | + $ending_date = new DateTime("now", $DateTimeZone); |
|
682 | + $subtitle = sprintf( |
|
683 | + _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
684 | + $beginning_date->format('Y-m-d'), |
|
685 | + $ending_date->format('Y-m-d') |
|
686 | + ); |
|
687 | + } |
|
688 | + $report_title = esc_html__('Total Registrations per Day', 'event_espresso'); |
|
689 | + $report_params = array( |
|
690 | + 'title' => $report_title, |
|
691 | + 'subtitle' => $subtitle, |
|
692 | + 'id' => $report_ID, |
|
693 | + 'regs' => $regs, |
|
694 | + 'noResults' => empty($regs), |
|
695 | + 'noRegsMsg' => sprintf( |
|
696 | + esc_html__( |
|
697 | + '%sThere are currently no registration records in the last month for this report.%s', |
|
698 | + 'event_espresso' |
|
699 | + ), |
|
700 | + '<h2>' . $report_title . '</h2><p>', |
|
701 | + '</p>' |
|
702 | + ), |
|
703 | + ); |
|
704 | + wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params); |
|
705 | + return $report_ID; |
|
706 | + } |
|
707 | 707 | |
708 | 708 | |
709 | - /** |
|
710 | - * Generates Business Report showing total registrations per event. |
|
711 | - * |
|
712 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
713 | - * @return string |
|
714 | - * @throws EE_Error |
|
715 | - * @throws InvalidArgumentException |
|
716 | - * @throws InvalidDataTypeException |
|
717 | - * @throws InvalidInterfaceException |
|
718 | - */ |
|
719 | - private function _registrations_per_event_report($period = '-1 month') |
|
720 | - { |
|
721 | - $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
|
722 | - $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
|
723 | - $results = (array) $results; |
|
724 | - $regs = array(); |
|
725 | - $subtitle = ''; |
|
726 | - if ($results) { |
|
727 | - $column_titles = array(); |
|
728 | - $tracker = 0; |
|
729 | - foreach ($results as $result) { |
|
730 | - $report_column_values = array(); |
|
731 | - foreach ($result as $property_name => $property_value) { |
|
732 | - $property_value = $property_name === 'Registration_Event' ? wp_trim_words( |
|
733 | - $property_value, |
|
734 | - 4, |
|
735 | - '...' |
|
736 | - ) : (int) $property_value; |
|
737 | - $report_column_values[] = $property_value; |
|
738 | - if ($tracker === 0) { |
|
739 | - if ($property_name === 'Registration_Event') { |
|
740 | - $column_titles[] = esc_html__('Event', 'event_espresso'); |
|
741 | - } else { |
|
742 | - $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
743 | - } |
|
744 | - } |
|
745 | - } |
|
746 | - $tracker++; |
|
747 | - $regs[] = $report_column_values; |
|
748 | - } |
|
749 | - // make sure the column_titles is pushed to the beginning of the array |
|
750 | - array_unshift($regs, $column_titles); |
|
751 | - // setup the date range. |
|
752 | - $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
753 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
754 | - $ending_date = new DateTime("now", $DateTimeZone); |
|
755 | - $subtitle = sprintf( |
|
756 | - _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
757 | - $beginning_date->format('Y-m-d'), |
|
758 | - $ending_date->format('Y-m-d') |
|
759 | - ); |
|
760 | - } |
|
761 | - $report_title = esc_html__('Total Registrations per Event', 'event_espresso'); |
|
762 | - $report_params = array( |
|
763 | - 'title' => $report_title, |
|
764 | - 'subtitle' => $subtitle, |
|
765 | - 'id' => $report_ID, |
|
766 | - 'regs' => $regs, |
|
767 | - 'noResults' => empty($regs), |
|
768 | - 'noRegsMsg' => sprintf( |
|
769 | - esc_html__( |
|
770 | - '%sThere are currently no registration records in the last month for this report.%s', |
|
771 | - 'event_espresso' |
|
772 | - ), |
|
773 | - '<h2>' . $report_title . '</h2><p>', |
|
774 | - '</p>' |
|
775 | - ), |
|
776 | - ); |
|
777 | - wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params); |
|
778 | - return $report_ID; |
|
779 | - } |
|
709 | + /** |
|
710 | + * Generates Business Report showing total registrations per event. |
|
711 | + * |
|
712 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
713 | + * @return string |
|
714 | + * @throws EE_Error |
|
715 | + * @throws InvalidArgumentException |
|
716 | + * @throws InvalidDataTypeException |
|
717 | + * @throws InvalidInterfaceException |
|
718 | + */ |
|
719 | + private function _registrations_per_event_report($period = '-1 month') |
|
720 | + { |
|
721 | + $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
|
722 | + $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
|
723 | + $results = (array) $results; |
|
724 | + $regs = array(); |
|
725 | + $subtitle = ''; |
|
726 | + if ($results) { |
|
727 | + $column_titles = array(); |
|
728 | + $tracker = 0; |
|
729 | + foreach ($results as $result) { |
|
730 | + $report_column_values = array(); |
|
731 | + foreach ($result as $property_name => $property_value) { |
|
732 | + $property_value = $property_name === 'Registration_Event' ? wp_trim_words( |
|
733 | + $property_value, |
|
734 | + 4, |
|
735 | + '...' |
|
736 | + ) : (int) $property_value; |
|
737 | + $report_column_values[] = $property_value; |
|
738 | + if ($tracker === 0) { |
|
739 | + if ($property_name === 'Registration_Event') { |
|
740 | + $column_titles[] = esc_html__('Event', 'event_espresso'); |
|
741 | + } else { |
|
742 | + $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
743 | + } |
|
744 | + } |
|
745 | + } |
|
746 | + $tracker++; |
|
747 | + $regs[] = $report_column_values; |
|
748 | + } |
|
749 | + // make sure the column_titles is pushed to the beginning of the array |
|
750 | + array_unshift($regs, $column_titles); |
|
751 | + // setup the date range. |
|
752 | + $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
753 | + $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
754 | + $ending_date = new DateTime("now", $DateTimeZone); |
|
755 | + $subtitle = sprintf( |
|
756 | + _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
757 | + $beginning_date->format('Y-m-d'), |
|
758 | + $ending_date->format('Y-m-d') |
|
759 | + ); |
|
760 | + } |
|
761 | + $report_title = esc_html__('Total Registrations per Event', 'event_espresso'); |
|
762 | + $report_params = array( |
|
763 | + 'title' => $report_title, |
|
764 | + 'subtitle' => $subtitle, |
|
765 | + 'id' => $report_ID, |
|
766 | + 'regs' => $regs, |
|
767 | + 'noResults' => empty($regs), |
|
768 | + 'noRegsMsg' => sprintf( |
|
769 | + esc_html__( |
|
770 | + '%sThere are currently no registration records in the last month for this report.%s', |
|
771 | + 'event_espresso' |
|
772 | + ), |
|
773 | + '<h2>' . $report_title . '</h2><p>', |
|
774 | + '</p>' |
|
775 | + ), |
|
776 | + ); |
|
777 | + wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params); |
|
778 | + return $report_ID; |
|
779 | + } |
|
780 | 780 | |
781 | 781 | |
782 | - /** |
|
783 | - * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration) |
|
784 | - * |
|
785 | - * @access protected |
|
786 | - * @return void |
|
787 | - * @throws EE_Error |
|
788 | - * @throws InvalidArgumentException |
|
789 | - * @throws InvalidDataTypeException |
|
790 | - * @throws InvalidInterfaceException |
|
791 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
792 | - */ |
|
793 | - protected function _registration_checkin_list_table() |
|
794 | - { |
|
795 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
796 | - $reg_id = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : null; |
|
797 | - /** @var EE_Registration $registration */ |
|
798 | - $registration = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
799 | - $attendee = $registration->attendee(); |
|
800 | - $this->_admin_page_title .= $this->get_action_link_or_button( |
|
801 | - 'new_registration', |
|
802 | - 'add-registrant', |
|
803 | - array('event_id' => $registration->event_ID()), |
|
804 | - 'add-new-h2' |
|
805 | - ); |
|
806 | - $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
807 | - $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
808 | - $legend_items = array( |
|
809 | - 'checkin' => array( |
|
810 | - 'class' => $checked_in->cssClasses(), |
|
811 | - 'desc' => $checked_in->legendLabel(), |
|
812 | - ), |
|
813 | - 'checkout' => array( |
|
814 | - 'class' => $checked_out->cssClasses(), |
|
815 | - 'desc' => $checked_out->legendLabel(), |
|
816 | - ), |
|
817 | - ); |
|
818 | - $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
819 | - $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
820 | - /** @var EE_Datetime $datetime */ |
|
821 | - $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id); |
|
822 | - $datetime_label = ''; |
|
823 | - if ($datetime instanceof EE_Datetime) { |
|
824 | - $datetime_label = $datetime->get_dtt_display_name(true); |
|
825 | - $datetime_label .= ! empty($datetime_label) |
|
826 | - ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
827 | - : $datetime->get_dtt_display_name(); |
|
828 | - } |
|
829 | - $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
|
830 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
831 | - array( |
|
832 | - 'action' => 'event_registrations', |
|
833 | - 'event_id' => $registration->event_ID(), |
|
834 | - 'DTT_ID' => $dtt_id, |
|
835 | - ), |
|
836 | - $this->_admin_base_url |
|
837 | - ) |
|
838 | - : ''; |
|
839 | - $datetime_link = ! empty($datetime_link) |
|
840 | - ? '<a href="' . $datetime_link . '">' |
|
841 | - . '<span id="checkin-dtt">' |
|
842 | - . $datetime_label |
|
843 | - . '</span></a>' |
|
844 | - : $datetime_label; |
|
845 | - $attendee_name = $attendee instanceof EE_Attendee |
|
846 | - ? $attendee->full_name() |
|
847 | - : ''; |
|
848 | - $attendee_link = $attendee instanceof EE_Attendee |
|
849 | - ? $attendee->get_admin_details_link() |
|
850 | - : ''; |
|
851 | - $attendee_link = ! empty($attendee_link) |
|
852 | - ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
853 | - . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
854 | - . '<span id="checkin-attendee-name">' |
|
855 | - . $attendee_name |
|
856 | - . '</span></a>' |
|
857 | - : ''; |
|
858 | - $event_link = $registration->event() instanceof EE_Event |
|
859 | - ? $registration->event()->get_admin_details_link() |
|
860 | - : ''; |
|
861 | - $event_link = ! empty($event_link) |
|
862 | - ? '<a href="' . $event_link . '"' |
|
863 | - . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
864 | - . '<span id="checkin-event-name">' |
|
865 | - . $registration->event_name() |
|
866 | - . '</span>' |
|
867 | - . '</a>' |
|
868 | - : ''; |
|
869 | - $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
|
870 | - ? '<h2>' . sprintf( |
|
871 | - esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
|
872 | - $attendee_link, |
|
873 | - $datetime_link, |
|
874 | - $event_link |
|
875 | - ) . '</h2>' |
|
876 | - : ''; |
|
877 | - $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
|
878 | - ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : ''; |
|
879 | - $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
|
880 | - ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
881 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
882 | - } |
|
782 | + /** |
|
783 | + * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration) |
|
784 | + * |
|
785 | + * @access protected |
|
786 | + * @return void |
|
787 | + * @throws EE_Error |
|
788 | + * @throws InvalidArgumentException |
|
789 | + * @throws InvalidDataTypeException |
|
790 | + * @throws InvalidInterfaceException |
|
791 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
792 | + */ |
|
793 | + protected function _registration_checkin_list_table() |
|
794 | + { |
|
795 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
796 | + $reg_id = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : null; |
|
797 | + /** @var EE_Registration $registration */ |
|
798 | + $registration = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
799 | + $attendee = $registration->attendee(); |
|
800 | + $this->_admin_page_title .= $this->get_action_link_or_button( |
|
801 | + 'new_registration', |
|
802 | + 'add-registrant', |
|
803 | + array('event_id' => $registration->event_ID()), |
|
804 | + 'add-new-h2' |
|
805 | + ); |
|
806 | + $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
807 | + $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
808 | + $legend_items = array( |
|
809 | + 'checkin' => array( |
|
810 | + 'class' => $checked_in->cssClasses(), |
|
811 | + 'desc' => $checked_in->legendLabel(), |
|
812 | + ), |
|
813 | + 'checkout' => array( |
|
814 | + 'class' => $checked_out->cssClasses(), |
|
815 | + 'desc' => $checked_out->legendLabel(), |
|
816 | + ), |
|
817 | + ); |
|
818 | + $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
819 | + $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
820 | + /** @var EE_Datetime $datetime */ |
|
821 | + $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id); |
|
822 | + $datetime_label = ''; |
|
823 | + if ($datetime instanceof EE_Datetime) { |
|
824 | + $datetime_label = $datetime->get_dtt_display_name(true); |
|
825 | + $datetime_label .= ! empty($datetime_label) |
|
826 | + ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
827 | + : $datetime->get_dtt_display_name(); |
|
828 | + } |
|
829 | + $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
|
830 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
831 | + array( |
|
832 | + 'action' => 'event_registrations', |
|
833 | + 'event_id' => $registration->event_ID(), |
|
834 | + 'DTT_ID' => $dtt_id, |
|
835 | + ), |
|
836 | + $this->_admin_base_url |
|
837 | + ) |
|
838 | + : ''; |
|
839 | + $datetime_link = ! empty($datetime_link) |
|
840 | + ? '<a href="' . $datetime_link . '">' |
|
841 | + . '<span id="checkin-dtt">' |
|
842 | + . $datetime_label |
|
843 | + . '</span></a>' |
|
844 | + : $datetime_label; |
|
845 | + $attendee_name = $attendee instanceof EE_Attendee |
|
846 | + ? $attendee->full_name() |
|
847 | + : ''; |
|
848 | + $attendee_link = $attendee instanceof EE_Attendee |
|
849 | + ? $attendee->get_admin_details_link() |
|
850 | + : ''; |
|
851 | + $attendee_link = ! empty($attendee_link) |
|
852 | + ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
853 | + . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
854 | + . '<span id="checkin-attendee-name">' |
|
855 | + . $attendee_name |
|
856 | + . '</span></a>' |
|
857 | + : ''; |
|
858 | + $event_link = $registration->event() instanceof EE_Event |
|
859 | + ? $registration->event()->get_admin_details_link() |
|
860 | + : ''; |
|
861 | + $event_link = ! empty($event_link) |
|
862 | + ? '<a href="' . $event_link . '"' |
|
863 | + . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
864 | + . '<span id="checkin-event-name">' |
|
865 | + . $registration->event_name() |
|
866 | + . '</span>' |
|
867 | + . '</a>' |
|
868 | + : ''; |
|
869 | + $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
|
870 | + ? '<h2>' . sprintf( |
|
871 | + esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
|
872 | + $attendee_link, |
|
873 | + $datetime_link, |
|
874 | + $event_link |
|
875 | + ) . '</h2>' |
|
876 | + : ''; |
|
877 | + $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
|
878 | + ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : ''; |
|
879 | + $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
|
880 | + ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
881 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
882 | + } |
|
883 | 883 | |
884 | 884 | |
885 | - /** |
|
886 | - * toggle the Check-in status for the given registration (coming from ajax) |
|
887 | - * |
|
888 | - * @return void (JSON) |
|
889 | - * @throws EE_Error |
|
890 | - * @throws InvalidArgumentException |
|
891 | - * @throws InvalidDataTypeException |
|
892 | - * @throws InvalidInterfaceException |
|
893 | - */ |
|
894 | - public function toggle_checkin_status() |
|
895 | - { |
|
896 | - // first make sure we have the necessary data |
|
897 | - if (! isset($this->_req_data['_regid'])) { |
|
898 | - EE_Error::add_error( |
|
899 | - esc_html__( |
|
900 | - 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
|
901 | - 'event_espresso' |
|
902 | - ), |
|
903 | - __FILE__, |
|
904 | - __FUNCTION__, |
|
905 | - __LINE__ |
|
906 | - ); |
|
907 | - $this->_template_args['success'] = false; |
|
908 | - $this->_template_args['error'] = true; |
|
909 | - $this->_return_json(); |
|
910 | - }; |
|
911 | - // do a nonce check cause we're not coming in from an normal route here. |
|
912 | - $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce']) |
|
913 | - : ''; |
|
914 | - $nonce_ref = 'checkin_nonce'; |
|
915 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
916 | - // beautiful! Made it this far so let's get the status. |
|
917 | - $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status()); |
|
918 | - // setup new class to return via ajax |
|
919 | - $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses(); |
|
920 | - $this->_template_args['success'] = true; |
|
921 | - $this->_return_json(); |
|
922 | - } |
|
885 | + /** |
|
886 | + * toggle the Check-in status for the given registration (coming from ajax) |
|
887 | + * |
|
888 | + * @return void (JSON) |
|
889 | + * @throws EE_Error |
|
890 | + * @throws InvalidArgumentException |
|
891 | + * @throws InvalidDataTypeException |
|
892 | + * @throws InvalidInterfaceException |
|
893 | + */ |
|
894 | + public function toggle_checkin_status() |
|
895 | + { |
|
896 | + // first make sure we have the necessary data |
|
897 | + if (! isset($this->_req_data['_regid'])) { |
|
898 | + EE_Error::add_error( |
|
899 | + esc_html__( |
|
900 | + 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
|
901 | + 'event_espresso' |
|
902 | + ), |
|
903 | + __FILE__, |
|
904 | + __FUNCTION__, |
|
905 | + __LINE__ |
|
906 | + ); |
|
907 | + $this->_template_args['success'] = false; |
|
908 | + $this->_template_args['error'] = true; |
|
909 | + $this->_return_json(); |
|
910 | + }; |
|
911 | + // do a nonce check cause we're not coming in from an normal route here. |
|
912 | + $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce']) |
|
913 | + : ''; |
|
914 | + $nonce_ref = 'checkin_nonce'; |
|
915 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
916 | + // beautiful! Made it this far so let's get the status. |
|
917 | + $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status()); |
|
918 | + // setup new class to return via ajax |
|
919 | + $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses(); |
|
920 | + $this->_template_args['success'] = true; |
|
921 | + $this->_return_json(); |
|
922 | + } |
|
923 | 923 | |
924 | 924 | |
925 | - /** |
|
926 | - * handles toggling the checkin status for the registration, |
|
927 | - * |
|
928 | - * @access protected |
|
929 | - * @return int|void |
|
930 | - * @throws EE_Error |
|
931 | - * @throws InvalidArgumentException |
|
932 | - * @throws InvalidDataTypeException |
|
933 | - * @throws InvalidInterfaceException |
|
934 | - */ |
|
935 | - protected function _toggle_checkin_status() |
|
936 | - { |
|
937 | - // first let's get the query args out of the way for the redirect |
|
938 | - $query_args = array( |
|
939 | - 'action' => 'event_registrations', |
|
940 | - 'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
941 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null, |
|
942 | - ); |
|
943 | - $new_status = false; |
|
944 | - // bulk action check in toggle |
|
945 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
946 | - // cycle thru checkboxes |
|
947 | - while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
|
948 | - $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
949 | - $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID); |
|
950 | - } |
|
951 | - } elseif (isset($this->_req_data['_regid'])) { |
|
952 | - // coming from ajax request |
|
953 | - $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null; |
|
954 | - $query_args['DTT_ID'] = $DTT_ID; |
|
955 | - $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID); |
|
956 | - } else { |
|
957 | - EE_Error::add_error( |
|
958 | - esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'), |
|
959 | - __FILE__, |
|
960 | - __FUNCTION__, |
|
961 | - __LINE__ |
|
962 | - ); |
|
963 | - } |
|
964 | - if (defined('DOING_AJAX')) { |
|
965 | - return $new_status; |
|
966 | - } |
|
967 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
968 | - } |
|
925 | + /** |
|
926 | + * handles toggling the checkin status for the registration, |
|
927 | + * |
|
928 | + * @access protected |
|
929 | + * @return int|void |
|
930 | + * @throws EE_Error |
|
931 | + * @throws InvalidArgumentException |
|
932 | + * @throws InvalidDataTypeException |
|
933 | + * @throws InvalidInterfaceException |
|
934 | + */ |
|
935 | + protected function _toggle_checkin_status() |
|
936 | + { |
|
937 | + // first let's get the query args out of the way for the redirect |
|
938 | + $query_args = array( |
|
939 | + 'action' => 'event_registrations', |
|
940 | + 'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
941 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null, |
|
942 | + ); |
|
943 | + $new_status = false; |
|
944 | + // bulk action check in toggle |
|
945 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
946 | + // cycle thru checkboxes |
|
947 | + while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
|
948 | + $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
949 | + $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID); |
|
950 | + } |
|
951 | + } elseif (isset($this->_req_data['_regid'])) { |
|
952 | + // coming from ajax request |
|
953 | + $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null; |
|
954 | + $query_args['DTT_ID'] = $DTT_ID; |
|
955 | + $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID); |
|
956 | + } else { |
|
957 | + EE_Error::add_error( |
|
958 | + esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'), |
|
959 | + __FILE__, |
|
960 | + __FUNCTION__, |
|
961 | + __LINE__ |
|
962 | + ); |
|
963 | + } |
|
964 | + if (defined('DOING_AJAX')) { |
|
965 | + return $new_status; |
|
966 | + } |
|
967 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
968 | + } |
|
969 | 969 | |
970 | 970 | |
971 | - /** |
|
972 | - * This is toggles a single Check-in for the given registration and datetime. |
|
973 | - * |
|
974 | - * @param int $REG_ID The registration we're toggling |
|
975 | - * @param int $DTT_ID The datetime we're toggling |
|
976 | - * @return int The new status toggled to. |
|
977 | - * @throws EE_Error |
|
978 | - * @throws InvalidArgumentException |
|
979 | - * @throws InvalidDataTypeException |
|
980 | - * @throws InvalidInterfaceException |
|
981 | - */ |
|
982 | - private function _toggle_checkin($REG_ID, $DTT_ID) |
|
983 | - { |
|
984 | - /** @var EE_Registration $REG */ |
|
985 | - $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
986 | - $new_status = $REG->toggle_checkin_status($DTT_ID); |
|
987 | - if ($new_status !== false) { |
|
988 | - EE_Error::add_success($REG->get_checkin_msg($DTT_ID)); |
|
989 | - } else { |
|
990 | - EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__); |
|
991 | - $new_status = false; |
|
992 | - } |
|
993 | - return $new_status; |
|
994 | - } |
|
971 | + /** |
|
972 | + * This is toggles a single Check-in for the given registration and datetime. |
|
973 | + * |
|
974 | + * @param int $REG_ID The registration we're toggling |
|
975 | + * @param int $DTT_ID The datetime we're toggling |
|
976 | + * @return int The new status toggled to. |
|
977 | + * @throws EE_Error |
|
978 | + * @throws InvalidArgumentException |
|
979 | + * @throws InvalidDataTypeException |
|
980 | + * @throws InvalidInterfaceException |
|
981 | + */ |
|
982 | + private function _toggle_checkin($REG_ID, $DTT_ID) |
|
983 | + { |
|
984 | + /** @var EE_Registration $REG */ |
|
985 | + $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
986 | + $new_status = $REG->toggle_checkin_status($DTT_ID); |
|
987 | + if ($new_status !== false) { |
|
988 | + EE_Error::add_success($REG->get_checkin_msg($DTT_ID)); |
|
989 | + } else { |
|
990 | + EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__); |
|
991 | + $new_status = false; |
|
992 | + } |
|
993 | + return $new_status; |
|
994 | + } |
|
995 | 995 | |
996 | 996 | |
997 | - /** |
|
998 | - * Takes care of deleting multiple EE_Checkin table rows |
|
999 | - * |
|
1000 | - * @access protected |
|
1001 | - * @return void |
|
1002 | - * @throws EE_Error |
|
1003 | - * @throws InvalidArgumentException |
|
1004 | - * @throws InvalidDataTypeException |
|
1005 | - * @throws InvalidInterfaceException |
|
1006 | - */ |
|
1007 | - protected function _delete_checkin_rows() |
|
1008 | - { |
|
1009 | - $query_args = array( |
|
1010 | - 'action' => 'registration_checkins', |
|
1011 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
1012 | - '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
1013 | - ); |
|
1014 | - $errors = 0; |
|
1015 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1016 | - while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1017 | - if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
1018 | - $errors++; |
|
1019 | - } |
|
1020 | - } |
|
1021 | - } else { |
|
1022 | - EE_Error::add_error( |
|
1023 | - esc_html__( |
|
1024 | - 'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', |
|
1025 | - 'event_espresso' |
|
1026 | - ), |
|
1027 | - __FILE__, |
|
1028 | - __FUNCTION__, |
|
1029 | - __LINE__ |
|
1030 | - ); |
|
1031 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1032 | - } |
|
1033 | - if ($errors > 0) { |
|
1034 | - EE_Error::add_error( |
|
1035 | - sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors), |
|
1036 | - __FILE__, |
|
1037 | - __FUNCTION__, |
|
1038 | - __LINE__ |
|
1039 | - ); |
|
1040 | - } else { |
|
1041 | - EE_Error::add_success(__('Records were successfully deleted', 'event_espresso')); |
|
1042 | - } |
|
1043 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1044 | - } |
|
997 | + /** |
|
998 | + * Takes care of deleting multiple EE_Checkin table rows |
|
999 | + * |
|
1000 | + * @access protected |
|
1001 | + * @return void |
|
1002 | + * @throws EE_Error |
|
1003 | + * @throws InvalidArgumentException |
|
1004 | + * @throws InvalidDataTypeException |
|
1005 | + * @throws InvalidInterfaceException |
|
1006 | + */ |
|
1007 | + protected function _delete_checkin_rows() |
|
1008 | + { |
|
1009 | + $query_args = array( |
|
1010 | + 'action' => 'registration_checkins', |
|
1011 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
1012 | + '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
1013 | + ); |
|
1014 | + $errors = 0; |
|
1015 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1016 | + while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
|
1017 | + if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
1018 | + $errors++; |
|
1019 | + } |
|
1020 | + } |
|
1021 | + } else { |
|
1022 | + EE_Error::add_error( |
|
1023 | + esc_html__( |
|
1024 | + 'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', |
|
1025 | + 'event_espresso' |
|
1026 | + ), |
|
1027 | + __FILE__, |
|
1028 | + __FUNCTION__, |
|
1029 | + __LINE__ |
|
1030 | + ); |
|
1031 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1032 | + } |
|
1033 | + if ($errors > 0) { |
|
1034 | + EE_Error::add_error( |
|
1035 | + sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors), |
|
1036 | + __FILE__, |
|
1037 | + __FUNCTION__, |
|
1038 | + __LINE__ |
|
1039 | + ); |
|
1040 | + } else { |
|
1041 | + EE_Error::add_success(__('Records were successfully deleted', 'event_espresso')); |
|
1042 | + } |
|
1043 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1044 | + } |
|
1045 | 1045 | |
1046 | 1046 | |
1047 | - /** |
|
1048 | - * Deletes a single EE_Checkin row |
|
1049 | - * |
|
1050 | - * @return void |
|
1051 | - * @throws EE_Error |
|
1052 | - * @throws InvalidArgumentException |
|
1053 | - * @throws InvalidDataTypeException |
|
1054 | - * @throws InvalidInterfaceException |
|
1055 | - */ |
|
1056 | - protected function _delete_checkin_row() |
|
1057 | - { |
|
1058 | - $query_args = array( |
|
1059 | - 'action' => 'registration_checkins', |
|
1060 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
1061 | - '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
1062 | - ); |
|
1063 | - if (! empty($this->_req_data['CHK_ID'])) { |
|
1064 | - if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
1065 | - EE_Error::add_error( |
|
1066 | - esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
|
1067 | - __FILE__, |
|
1068 | - __FUNCTION__, |
|
1069 | - __LINE__ |
|
1070 | - ); |
|
1071 | - } else { |
|
1072 | - EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso')); |
|
1073 | - } |
|
1074 | - } else { |
|
1075 | - EE_Error::add_error( |
|
1076 | - esc_html__( |
|
1077 | - 'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', |
|
1078 | - 'event_espresso' |
|
1079 | - ), |
|
1080 | - __FILE__, |
|
1081 | - __FUNCTION__, |
|
1082 | - __LINE__ |
|
1083 | - ); |
|
1084 | - } |
|
1085 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1086 | - } |
|
1047 | + /** |
|
1048 | + * Deletes a single EE_Checkin row |
|
1049 | + * |
|
1050 | + * @return void |
|
1051 | + * @throws EE_Error |
|
1052 | + * @throws InvalidArgumentException |
|
1053 | + * @throws InvalidDataTypeException |
|
1054 | + * @throws InvalidInterfaceException |
|
1055 | + */ |
|
1056 | + protected function _delete_checkin_row() |
|
1057 | + { |
|
1058 | + $query_args = array( |
|
1059 | + 'action' => 'registration_checkins', |
|
1060 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
1061 | + '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
1062 | + ); |
|
1063 | + if (! empty($this->_req_data['CHK_ID'])) { |
|
1064 | + if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
1065 | + EE_Error::add_error( |
|
1066 | + esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
|
1067 | + __FILE__, |
|
1068 | + __FUNCTION__, |
|
1069 | + __LINE__ |
|
1070 | + ); |
|
1071 | + } else { |
|
1072 | + EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso')); |
|
1073 | + } |
|
1074 | + } else { |
|
1075 | + EE_Error::add_error( |
|
1076 | + esc_html__( |
|
1077 | + 'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', |
|
1078 | + 'event_espresso' |
|
1079 | + ), |
|
1080 | + __FILE__, |
|
1081 | + __FUNCTION__, |
|
1082 | + __LINE__ |
|
1083 | + ); |
|
1084 | + } |
|
1085 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
1086 | + } |
|
1087 | 1087 | |
1088 | 1088 | |
1089 | - /** |
|
1090 | - * generates HTML for the Event Registrations List Table |
|
1091 | - * |
|
1092 | - * @access protected |
|
1093 | - * @return void |
|
1094 | - * @throws EE_Error |
|
1095 | - * @throws InvalidArgumentException |
|
1096 | - * @throws InvalidDataTypeException |
|
1097 | - * @throws InvalidInterfaceException |
|
1098 | - */ |
|
1099 | - protected function _event_registrations_list_table() |
|
1100 | - { |
|
1101 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1102 | - $this->_admin_page_title .= isset($this->_req_data['event_id']) |
|
1103 | - ? $this->get_action_link_or_button( |
|
1104 | - 'new_registration', |
|
1105 | - 'add-registrant', |
|
1106 | - array('event_id' => $this->_req_data['event_id']), |
|
1107 | - 'add-new-h2', |
|
1108 | - '', |
|
1109 | - false |
|
1110 | - ) |
|
1111 | - : ''; |
|
1112 | - $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
1113 | - $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
1114 | - $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never); |
|
1115 | - $legend_items = array( |
|
1116 | - 'star-icon' => array( |
|
1117 | - 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
1118 | - 'desc' => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'), |
|
1119 | - ), |
|
1120 | - 'checkin' => array( |
|
1121 | - 'class' => $checked_in->cssClasses(), |
|
1122 | - 'desc' => $checked_in->legendLabel(), |
|
1123 | - ), |
|
1124 | - 'checkout' => array( |
|
1125 | - 'class' => $checked_out->cssClasses(), |
|
1126 | - 'desc' => $checked_out->legendLabel(), |
|
1127 | - ), |
|
1128 | - 'nocheckinrecord' => array( |
|
1129 | - 'class' => $checked_never->cssClasses(), |
|
1130 | - 'desc' => $checked_never->legendLabel(), |
|
1131 | - ), |
|
1132 | - 'approved_status' => array( |
|
1133 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
1134 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
1135 | - ), |
|
1136 | - 'cancelled_status' => array( |
|
1137 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
1138 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
1139 | - ), |
|
1140 | - 'declined_status' => array( |
|
1141 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
1142 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
1143 | - ), |
|
1144 | - 'not_approved' => array( |
|
1145 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
1146 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
1147 | - ), |
|
1148 | - 'pending_status' => array( |
|
1149 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
1150 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
1151 | - ), |
|
1152 | - 'wait_list' => array( |
|
1153 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
1154 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
1155 | - ), |
|
1156 | - ); |
|
1157 | - $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
1158 | - $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
1159 | - /** @var EE_Event $event */ |
|
1160 | - $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
1161 | - $this->_template_args['before_list_table'] = $event instanceof EE_Event |
|
1162 | - ? '<h2>' . sprintf( |
|
1163 | - esc_html__('Viewing Registrations for Event: %s', 'event_espresso'), |
|
1164 | - EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
|
1165 | - ) . '</h2>' |
|
1166 | - : ''; |
|
1167 | - // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on |
|
1168 | - // the event. |
|
1169 | - $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0; |
|
1170 | - $datetime = null; |
|
1171 | - if ($event instanceof EE_Event) { |
|
1172 | - $datetimes_on_event = $event->datetimes(); |
|
1173 | - if (count($datetimes_on_event) === 1) { |
|
1174 | - $datetime = reset($datetimes_on_event); |
|
1175 | - } |
|
1176 | - } |
|
1177 | - $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
1178 | - if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') { |
|
1179 | - $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5); |
|
1180 | - $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
|
1181 | - $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
1182 | - $this->_template_args['before_list_table'] .= $datetime->name(); |
|
1183 | - $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
1184 | - $this->_template_args['before_list_table'] .= '</span></h2>'; |
|
1185 | - } |
|
1186 | - // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status |
|
1187 | - // column represents |
|
1188 | - if (! $datetime instanceof EE_Datetime) { |
|
1189 | - $this->_template_args['before_list_table'] .= '<br><p class="description">' |
|
1190 | - . esc_html__( |
|
1191 | - 'In this view, the check-in status represents the latest check-in record for the registration in that row.', |
|
1192 | - 'event_espresso' |
|
1193 | - ) |
|
1194 | - . '</p>'; |
|
1195 | - } |
|
1196 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
1197 | - } |
|
1089 | + /** |
|
1090 | + * generates HTML for the Event Registrations List Table |
|
1091 | + * |
|
1092 | + * @access protected |
|
1093 | + * @return void |
|
1094 | + * @throws EE_Error |
|
1095 | + * @throws InvalidArgumentException |
|
1096 | + * @throws InvalidDataTypeException |
|
1097 | + * @throws InvalidInterfaceException |
|
1098 | + */ |
|
1099 | + protected function _event_registrations_list_table() |
|
1100 | + { |
|
1101 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1102 | + $this->_admin_page_title .= isset($this->_req_data['event_id']) |
|
1103 | + ? $this->get_action_link_or_button( |
|
1104 | + 'new_registration', |
|
1105 | + 'add-registrant', |
|
1106 | + array('event_id' => $this->_req_data['event_id']), |
|
1107 | + 'add-new-h2', |
|
1108 | + '', |
|
1109 | + false |
|
1110 | + ) |
|
1111 | + : ''; |
|
1112 | + $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
1113 | + $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
1114 | + $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never); |
|
1115 | + $legend_items = array( |
|
1116 | + 'star-icon' => array( |
|
1117 | + 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
1118 | + 'desc' => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'), |
|
1119 | + ), |
|
1120 | + 'checkin' => array( |
|
1121 | + 'class' => $checked_in->cssClasses(), |
|
1122 | + 'desc' => $checked_in->legendLabel(), |
|
1123 | + ), |
|
1124 | + 'checkout' => array( |
|
1125 | + 'class' => $checked_out->cssClasses(), |
|
1126 | + 'desc' => $checked_out->legendLabel(), |
|
1127 | + ), |
|
1128 | + 'nocheckinrecord' => array( |
|
1129 | + 'class' => $checked_never->cssClasses(), |
|
1130 | + 'desc' => $checked_never->legendLabel(), |
|
1131 | + ), |
|
1132 | + 'approved_status' => array( |
|
1133 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
1134 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
1135 | + ), |
|
1136 | + 'cancelled_status' => array( |
|
1137 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
1138 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
1139 | + ), |
|
1140 | + 'declined_status' => array( |
|
1141 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
1142 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
1143 | + ), |
|
1144 | + 'not_approved' => array( |
|
1145 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
1146 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
1147 | + ), |
|
1148 | + 'pending_status' => array( |
|
1149 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
1150 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
1151 | + ), |
|
1152 | + 'wait_list' => array( |
|
1153 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
1154 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
1155 | + ), |
|
1156 | + ); |
|
1157 | + $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
1158 | + $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
1159 | + /** @var EE_Event $event */ |
|
1160 | + $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
1161 | + $this->_template_args['before_list_table'] = $event instanceof EE_Event |
|
1162 | + ? '<h2>' . sprintf( |
|
1163 | + esc_html__('Viewing Registrations for Event: %s', 'event_espresso'), |
|
1164 | + EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
|
1165 | + ) . '</h2>' |
|
1166 | + : ''; |
|
1167 | + // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on |
|
1168 | + // the event. |
|
1169 | + $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0; |
|
1170 | + $datetime = null; |
|
1171 | + if ($event instanceof EE_Event) { |
|
1172 | + $datetimes_on_event = $event->datetimes(); |
|
1173 | + if (count($datetimes_on_event) === 1) { |
|
1174 | + $datetime = reset($datetimes_on_event); |
|
1175 | + } |
|
1176 | + } |
|
1177 | + $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
1178 | + if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') { |
|
1179 | + $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5); |
|
1180 | + $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
|
1181 | + $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
1182 | + $this->_template_args['before_list_table'] .= $datetime->name(); |
|
1183 | + $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
1184 | + $this->_template_args['before_list_table'] .= '</span></h2>'; |
|
1185 | + } |
|
1186 | + // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status |
|
1187 | + // column represents |
|
1188 | + if (! $datetime instanceof EE_Datetime) { |
|
1189 | + $this->_template_args['before_list_table'] .= '<br><p class="description">' |
|
1190 | + . esc_html__( |
|
1191 | + 'In this view, the check-in status represents the latest check-in record for the registration in that row.', |
|
1192 | + 'event_espresso' |
|
1193 | + ) |
|
1194 | + . '</p>'; |
|
1195 | + } |
|
1196 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
1197 | + } |
|
1198 | 1198 | |
1199 | - /** |
|
1200 | - * Download the registrations check-in report (same as the normal registration report, but with different where |
|
1201 | - * conditions) |
|
1202 | - * |
|
1203 | - * @return void ends the request by a redirect or download |
|
1204 | - */ |
|
1205 | - public function _registrations_checkin_report() |
|
1206 | - { |
|
1207 | - $this->_registrations_report_base('_get_checkin_query_params_from_request'); |
|
1208 | - } |
|
1199 | + /** |
|
1200 | + * Download the registrations check-in report (same as the normal registration report, but with different where |
|
1201 | + * conditions) |
|
1202 | + * |
|
1203 | + * @return void ends the request by a redirect or download |
|
1204 | + */ |
|
1205 | + public function _registrations_checkin_report() |
|
1206 | + { |
|
1207 | + $this->_registrations_report_base('_get_checkin_query_params_from_request'); |
|
1208 | + } |
|
1209 | 1209 | |
1210 | - /** |
|
1211 | - * Gets the query params from the request, plus adds a where condition for the registration status, |
|
1212 | - * because on the checkin page we only ever want to see approved and pending-approval registrations |
|
1213 | - * |
|
1214 | - * @param array $request |
|
1215 | - * @param int $per_page |
|
1216 | - * @param bool $count |
|
1217 | - * @return array |
|
1218 | - * @throws EE_Error |
|
1219 | - */ |
|
1220 | - protected function _get_checkin_query_params_from_request( |
|
1221 | - $request, |
|
1222 | - $per_page = 10, |
|
1223 | - $count = false |
|
1224 | - ) { |
|
1225 | - $query_params = $this->_get_registration_query_parameters($request, $per_page, $count); |
|
1226 | - // unlike the regular registrations list table, |
|
1227 | - $status_ids_array = apply_filters( |
|
1228 | - 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
1229 | - array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
1230 | - ); |
|
1231 | - $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
1232 | - return $query_params; |
|
1233 | - } |
|
1210 | + /** |
|
1211 | + * Gets the query params from the request, plus adds a where condition for the registration status, |
|
1212 | + * because on the checkin page we only ever want to see approved and pending-approval registrations |
|
1213 | + * |
|
1214 | + * @param array $request |
|
1215 | + * @param int $per_page |
|
1216 | + * @param bool $count |
|
1217 | + * @return array |
|
1218 | + * @throws EE_Error |
|
1219 | + */ |
|
1220 | + protected function _get_checkin_query_params_from_request( |
|
1221 | + $request, |
|
1222 | + $per_page = 10, |
|
1223 | + $count = false |
|
1224 | + ) { |
|
1225 | + $query_params = $this->_get_registration_query_parameters($request, $per_page, $count); |
|
1226 | + // unlike the regular registrations list table, |
|
1227 | + $status_ids_array = apply_filters( |
|
1228 | + 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
1229 | + array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
1230 | + ); |
|
1231 | + $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
1232 | + return $query_params; |
|
1233 | + } |
|
1234 | 1234 | |
1235 | 1235 | |
1236 | - /** |
|
1237 | - * Gets registrations for an event |
|
1238 | - * |
|
1239 | - * @param int $per_page |
|
1240 | - * @param bool $count whether to return count or data. |
|
1241 | - * @param bool $trash |
|
1242 | - * @param string $orderby |
|
1243 | - * @return EE_Registration[]|int |
|
1244 | - * @throws EE_Error |
|
1245 | - * @throws InvalidArgumentException |
|
1246 | - * @throws InvalidDataTypeException |
|
1247 | - * @throws InvalidInterfaceException |
|
1248 | - */ |
|
1249 | - public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname') |
|
1250 | - { |
|
1251 | - // normalize some request params that get setup by the parent `get_registrations` method. |
|
1252 | - $request = $this->_req_data; |
|
1253 | - $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
|
1254 | - $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
1255 | - if ($trash) { |
|
1256 | - $request['status'] = 'trash'; |
|
1257 | - } |
|
1258 | - $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count); |
|
1259 | - /** |
|
1260 | - * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
1261 | - * |
|
1262 | - * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
1263 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1264 | - * or if you have the development copy of EE you can view this at the path: |
|
1265 | - * /docs/G--Model-System/model-query-params.md |
|
1266 | - */ |
|
1267 | - $query_params['group_by'] = ''; |
|
1236 | + /** |
|
1237 | + * Gets registrations for an event |
|
1238 | + * |
|
1239 | + * @param int $per_page |
|
1240 | + * @param bool $count whether to return count or data. |
|
1241 | + * @param bool $trash |
|
1242 | + * @param string $orderby |
|
1243 | + * @return EE_Registration[]|int |
|
1244 | + * @throws EE_Error |
|
1245 | + * @throws InvalidArgumentException |
|
1246 | + * @throws InvalidDataTypeException |
|
1247 | + * @throws InvalidInterfaceException |
|
1248 | + */ |
|
1249 | + public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname') |
|
1250 | + { |
|
1251 | + // normalize some request params that get setup by the parent `get_registrations` method. |
|
1252 | + $request = $this->_req_data; |
|
1253 | + $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
|
1254 | + $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
1255 | + if ($trash) { |
|
1256 | + $request['status'] = 'trash'; |
|
1257 | + } |
|
1258 | + $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count); |
|
1259 | + /** |
|
1260 | + * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
1261 | + * |
|
1262 | + * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
1263 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1264 | + * or if you have the development copy of EE you can view this at the path: |
|
1265 | + * /docs/G--Model-System/model-query-params.md |
|
1266 | + */ |
|
1267 | + $query_params['group_by'] = ''; |
|
1268 | 1268 | |
1269 | - return $count |
|
1270 | - ? EEM_Registration::instance()->count($query_params) |
|
1271 | - /** @type EE_Registration[] */ |
|
1272 | - : EEM_Registration::instance()->get_all($query_params); |
|
1273 | - } |
|
1269 | + return $count |
|
1270 | + ? EEM_Registration::instance()->count($query_params) |
|
1271 | + /** @type EE_Registration[] */ |
|
1272 | + : EEM_Registration::instance()->get_all($query_params); |
|
1273 | + } |
|
1274 | 1274 | } |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | public function __construct($routing = true) |
33 | 33 | { |
34 | 34 | parent::__construct($routing); |
35 | - if (! defined('REG_CAF_TEMPLATE_PATH')) { |
|
36 | - define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
37 | - define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
38 | - define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
35 | + if ( ! defined('REG_CAF_TEMPLATE_PATH')) { |
|
36 | + define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'registrations/templates/'); |
|
37 | + define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'registrations/assets/'); |
|
38 | + define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registrations/assets/'); |
|
39 | 39 | } |
40 | 40 | } |
41 | 41 | |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | protected function _extend_page_config() |
47 | 47 | { |
48 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
48 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'registrations'; |
|
49 | 49 | $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
50 | 50 | ? $this->_req_data['_REG_ID'] |
51 | 51 | : 0; |
@@ -185,14 +185,14 @@ discard block |
||
185 | 185 | // enqueue newsletter js |
186 | 186 | wp_enqueue_script( |
187 | 187 | 'ee-newsletter-trigger', |
188 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
188 | + REG_CAF_ASSETS_URL.'ee-newsletter-trigger.js', |
|
189 | 189 | array('ee-dialog'), |
190 | 190 | EVENT_ESPRESSO_VERSION, |
191 | 191 | true |
192 | 192 | ); |
193 | 193 | wp_enqueue_style( |
194 | 194 | 'ee-newsletter-trigger-css', |
195 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
195 | + REG_CAF_ASSETS_URL.'ee-newsletter-trigger.css', |
|
196 | 196 | array(), |
197 | 197 | EVENT_ESPRESSO_VERSION |
198 | 198 | ); |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | { |
214 | 214 | wp_register_script( |
215 | 215 | 'ee-reg-reports-js', |
216 | - REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
216 | + REG_CAF_ASSETS_URL.'ee-registration-admin-reports.js', |
|
217 | 217 | array('google-charts'), |
218 | 218 | EVENT_ESPRESSO_VERSION, |
219 | 219 | true |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | $nonce_ref = 'get_newsletter_form_content_nonce'; |
300 | 300 | $this->_verify_nonce($nonce, $nonce_ref); |
301 | 301 | // let's get the mtp for the incoming MTP_ ID |
302 | - if (! isset($this->_req_data['GRP_ID'])) { |
|
302 | + if ( ! isset($this->_req_data['GRP_ID'])) { |
|
303 | 303 | EE_Error::add_error( |
304 | 304 | esc_html__( |
305 | 305 | 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | $this->_return_json(); |
315 | 315 | } |
316 | 316 | $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
317 | - if (! $MTPG instanceof EE_Message_Template_Group) { |
|
317 | + if ( ! $MTPG instanceof EE_Message_Template_Group) { |
|
318 | 318 | EE_Error::add_error( |
319 | 319 | sprintf( |
320 | 320 | esc_html__( |
@@ -339,12 +339,12 @@ discard block |
||
339 | 339 | $field = $MTP->get('MTP_template_field'); |
340 | 340 | if ($field === 'content') { |
341 | 341 | $content = $MTP->get('MTP_content'); |
342 | - if (! empty($content['newsletter_content'])) { |
|
342 | + if ( ! empty($content['newsletter_content'])) { |
|
343 | 343 | $template_fields['newsletter_content'] = $content['newsletter_content']; |
344 | 344 | } |
345 | 345 | continue; |
346 | 346 | } |
347 | - $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content'); |
|
347 | + $template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content'); |
|
348 | 348 | } |
349 | 349 | $this->_template_args['success'] = true; |
350 | 350 | $this->_template_args['error'] = false; |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | */ |
376 | 376 | public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
377 | 377 | { |
378 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
378 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
379 | 379 | 'ee_send_message', |
380 | 380 | 'espresso_registrations_newsletter_selected_send' |
381 | 381 | ) |
@@ -444,17 +444,17 @@ discard block |
||
444 | 444 | $field_id = $field === '[NEWSLETTER_CONTENT]' |
445 | 445 | ? 'content' |
446 | 446 | : $field; |
447 | - $field_id = 'batch-message-' . strtolower($field_id); |
|
447 | + $field_id = 'batch-message-'.strtolower($field_id); |
|
448 | 448 | $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="' |
449 | 449 | . $shortcode |
450 | - . '" data-linked-input-id="' . $field_id . '">' |
|
450 | + . '" data-linked-input-id="'.$field_id.'">' |
|
451 | 451 | . $shortcode |
452 | 452 | . '</span>'; |
453 | 453 | } |
454 | - $codes[ $field ] = implode(', ', $available_shortcodes); |
|
454 | + $codes[$field] = implode(', ', $available_shortcodes); |
|
455 | 455 | } |
456 | 456 | $shortcodes = $codes; |
457 | - $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
457 | + $form_template = REG_CAF_TEMPLATE_PATH.'newsletter-send-form.template.php'; |
|
458 | 458 | $form_template_args = array( |
459 | 459 | 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
460 | 460 | 'form_route' => 'newsletter_selected_send', |
@@ -622,7 +622,7 @@ discard block |
||
622 | 622 | */ |
623 | 623 | protected function _registration_reports() |
624 | 624 | { |
625 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
625 | + $template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php'; |
|
626 | 626 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
627 | 627 | $template_path, |
628 | 628 | $this->_reports_template_data, |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | array_unshift($regs, $column_titles); |
678 | 678 | // setup the date range. |
679 | 679 | $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
680 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
680 | + $beginning_date = new DateTime("now ".$period, $DateTimeZone); |
|
681 | 681 | $ending_date = new DateTime("now", $DateTimeZone); |
682 | 682 | $subtitle = sprintf( |
683 | 683 | _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
@@ -697,7 +697,7 @@ discard block |
||
697 | 697 | '%sThere are currently no registration records in the last month for this report.%s', |
698 | 698 | 'event_espresso' |
699 | 699 | ), |
700 | - '<h2>' . $report_title . '</h2><p>', |
|
700 | + '<h2>'.$report_title.'</h2><p>', |
|
701 | 701 | '</p>' |
702 | 702 | ), |
703 | 703 | ); |
@@ -750,7 +750,7 @@ discard block |
||
750 | 750 | array_unshift($regs, $column_titles); |
751 | 751 | // setup the date range. |
752 | 752 | $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
753 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
753 | + $beginning_date = new DateTime("now ".$period, $DateTimeZone); |
|
754 | 754 | $ending_date = new DateTime("now", $DateTimeZone); |
755 | 755 | $subtitle = sprintf( |
756 | 756 | _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
@@ -770,7 +770,7 @@ discard block |
||
770 | 770 | '%sThere are currently no registration records in the last month for this report.%s', |
771 | 771 | 'event_espresso' |
772 | 772 | ), |
773 | - '<h2>' . $report_title . '</h2><p>', |
|
773 | + '<h2>'.$report_title.'</h2><p>', |
|
774 | 774 | '</p>' |
775 | 775 | ), |
776 | 776 | ); |
@@ -823,7 +823,7 @@ discard block |
||
823 | 823 | if ($datetime instanceof EE_Datetime) { |
824 | 824 | $datetime_label = $datetime->get_dtt_display_name(true); |
825 | 825 | $datetime_label .= ! empty($datetime_label) |
826 | - ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
826 | + ? ' ('.$datetime->get_dtt_display_name().')' |
|
827 | 827 | : $datetime->get_dtt_display_name(); |
828 | 828 | } |
829 | 829 | $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
@@ -837,7 +837,7 @@ discard block |
||
837 | 837 | ) |
838 | 838 | : ''; |
839 | 839 | $datetime_link = ! empty($datetime_link) |
840 | - ? '<a href="' . $datetime_link . '">' |
|
840 | + ? '<a href="'.$datetime_link.'">' |
|
841 | 841 | . '<span id="checkin-dtt">' |
842 | 842 | . $datetime_label |
843 | 843 | . '</span></a>' |
@@ -849,8 +849,8 @@ discard block |
||
849 | 849 | ? $attendee->get_admin_details_link() |
850 | 850 | : ''; |
851 | 851 | $attendee_link = ! empty($attendee_link) |
852 | - ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
853 | - . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
852 | + ? '<a href="'.$attendee->get_admin_details_link().'"' |
|
853 | + . ' title="'.esc_html__('Click for attendee details', 'event_espresso').'">' |
|
854 | 854 | . '<span id="checkin-attendee-name">' |
855 | 855 | . $attendee_name |
856 | 856 | . '</span></a>' |
@@ -859,25 +859,25 @@ discard block |
||
859 | 859 | ? $registration->event()->get_admin_details_link() |
860 | 860 | : ''; |
861 | 861 | $event_link = ! empty($event_link) |
862 | - ? '<a href="' . $event_link . '"' |
|
863 | - . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
862 | + ? '<a href="'.$event_link.'"' |
|
863 | + . ' title="'.esc_html__('Click here to edit event.', 'event_espresso').'">' |
|
864 | 864 | . '<span id="checkin-event-name">' |
865 | 865 | . $registration->event_name() |
866 | 866 | . '</span>' |
867 | 867 | . '</a>' |
868 | 868 | : ''; |
869 | 869 | $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
870 | - ? '<h2>' . sprintf( |
|
870 | + ? '<h2>'.sprintf( |
|
871 | 871 | esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
872 | 872 | $attendee_link, |
873 | 873 | $datetime_link, |
874 | 874 | $event_link |
875 | - ) . '</h2>' |
|
875 | + ).'</h2>' |
|
876 | 876 | : ''; |
877 | 877 | $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
878 | - ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : ''; |
|
878 | + ? '<input type="hidden" name="_REG_ID" value="'.$reg_id.'">' : ''; |
|
879 | 879 | $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
880 | - ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
880 | + ? '<input type="hidden" name="DTT_ID" value="'.$dtt_id.'">' : ''; |
|
881 | 881 | $this->display_admin_list_table_page_with_no_sidebar(); |
882 | 882 | } |
883 | 883 | |
@@ -894,7 +894,7 @@ discard block |
||
894 | 894 | public function toggle_checkin_status() |
895 | 895 | { |
896 | 896 | // first make sure we have the necessary data |
897 | - if (! isset($this->_req_data['_regid'])) { |
|
897 | + if ( ! isset($this->_req_data['_regid'])) { |
|
898 | 898 | EE_Error::add_error( |
899 | 899 | esc_html__( |
900 | 900 | 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
@@ -916,7 +916,7 @@ discard block |
||
916 | 916 | // beautiful! Made it this far so let's get the status. |
917 | 917 | $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status()); |
918 | 918 | // setup new class to return via ajax |
919 | - $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses(); |
|
919 | + $this->_template_args['admin_page_content'] = 'clickable trigger-checkin '.$new_status->cssClasses(); |
|
920 | 920 | $this->_template_args['success'] = true; |
921 | 921 | $this->_return_json(); |
922 | 922 | } |
@@ -942,7 +942,7 @@ discard block |
||
942 | 942 | ); |
943 | 943 | $new_status = false; |
944 | 944 | // bulk action check in toggle |
945 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
945 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
946 | 946 | // cycle thru checkboxes |
947 | 947 | while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
948 | 948 | $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
@@ -1012,9 +1012,9 @@ discard block |
||
1012 | 1012 | '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
1013 | 1013 | ); |
1014 | 1014 | $errors = 0; |
1015 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1015 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
1016 | 1016 | while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
1017 | - if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
1017 | + if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
1018 | 1018 | $errors++; |
1019 | 1019 | } |
1020 | 1020 | } |
@@ -1060,8 +1060,8 @@ discard block |
||
1060 | 1060 | 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
1061 | 1061 | '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
1062 | 1062 | ); |
1063 | - if (! empty($this->_req_data['CHK_ID'])) { |
|
1064 | - if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
1063 | + if ( ! empty($this->_req_data['CHK_ID'])) { |
|
1064 | + if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
1065 | 1065 | EE_Error::add_error( |
1066 | 1066 | esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
1067 | 1067 | __FILE__, |
@@ -1130,27 +1130,27 @@ discard block |
||
1130 | 1130 | 'desc' => $checked_never->legendLabel(), |
1131 | 1131 | ), |
1132 | 1132 | 'approved_status' => array( |
1133 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
1133 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved, |
|
1134 | 1134 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
1135 | 1135 | ), |
1136 | 1136 | 'cancelled_status' => array( |
1137 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
1137 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled, |
|
1138 | 1138 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
1139 | 1139 | ), |
1140 | 1140 | 'declined_status' => array( |
1141 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
1141 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined, |
|
1142 | 1142 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
1143 | 1143 | ), |
1144 | 1144 | 'not_approved' => array( |
1145 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
1145 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved, |
|
1146 | 1146 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
1147 | 1147 | ), |
1148 | 1148 | 'pending_status' => array( |
1149 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
1149 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment, |
|
1150 | 1150 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
1151 | 1151 | ), |
1152 | 1152 | 'wait_list' => array( |
1153 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
1153 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list, |
|
1154 | 1154 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
1155 | 1155 | ), |
1156 | 1156 | ); |
@@ -1159,10 +1159,10 @@ discard block |
||
1159 | 1159 | /** @var EE_Event $event */ |
1160 | 1160 | $event = EEM_Event::instance()->get_one_by_ID($event_id); |
1161 | 1161 | $this->_template_args['before_list_table'] = $event instanceof EE_Event |
1162 | - ? '<h2>' . sprintf( |
|
1162 | + ? '<h2>'.sprintf( |
|
1163 | 1163 | esc_html__('Viewing Registrations for Event: %s', 'event_espresso'), |
1164 | 1164 | EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
1165 | - ) . '</h2>' |
|
1165 | + ).'</h2>' |
|
1166 | 1166 | : ''; |
1167 | 1167 | // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on |
1168 | 1168 | // the event. |
@@ -1180,12 +1180,12 @@ discard block |
||
1180 | 1180 | $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
1181 | 1181 | $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
1182 | 1182 | $this->_template_args['before_list_table'] .= $datetime->name(); |
1183 | - $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
1183 | + $this->_template_args['before_list_table'] .= ' ( '.$datetime->date_and_time_range().' )'; |
|
1184 | 1184 | $this->_template_args['before_list_table'] .= '</span></h2>'; |
1185 | 1185 | } |
1186 | 1186 | // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status |
1187 | 1187 | // column represents |
1188 | - if (! $datetime instanceof EE_Datetime) { |
|
1188 | + if ( ! $datetime instanceof EE_Datetime) { |
|
1189 | 1189 | $this->_template_args['before_list_table'] .= '<br><p class="description">' |
1190 | 1190 | . esc_html__( |
1191 | 1191 | 'In this view, the check-in status represents the latest check-in record for the registration in that row.', |
@@ -12,32 +12,32 @@ |
||
12 | 12 | class EE_Button_Display_Strategy extends EE_Display_Strategy_Base |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * @return string of html to display the input |
|
17 | - */ |
|
18 | - public function display() |
|
19 | - { |
|
20 | - $default_value = $this->_input->get_default(); |
|
21 | - if ($this->_input->get_normalization_strategy() instanceof EE_Normalization_Strategy_Base) { |
|
22 | - $default_value = $this->_input->get_normalization_strategy()->unnormalize($default_value); |
|
23 | - } |
|
24 | - $html = $this->_opening_tag('button'); |
|
25 | - $html .= $this->_attributes_string( |
|
26 | - array_merge( |
|
27 | - $this->_standard_attributes_array(), |
|
28 | - array( |
|
29 | - 'value' => $default_value, |
|
30 | - ) |
|
31 | - ) |
|
32 | - ); |
|
33 | - if ($this->_input instanceof EE_Button_Input) { |
|
34 | - $button_content = $this->_input->button_content(); |
|
35 | - } else { |
|
36 | - $button_content = $this->_input->get_default(); |
|
37 | - } |
|
38 | - $html .= '>'; |
|
39 | - $html .= $button_content; |
|
40 | - $html .= $this->_closing_tag(); |
|
41 | - return $html; |
|
42 | - } |
|
15 | + /** |
|
16 | + * @return string of html to display the input |
|
17 | + */ |
|
18 | + public function display() |
|
19 | + { |
|
20 | + $default_value = $this->_input->get_default(); |
|
21 | + if ($this->_input->get_normalization_strategy() instanceof EE_Normalization_Strategy_Base) { |
|
22 | + $default_value = $this->_input->get_normalization_strategy()->unnormalize($default_value); |
|
23 | + } |
|
24 | + $html = $this->_opening_tag('button'); |
|
25 | + $html .= $this->_attributes_string( |
|
26 | + array_merge( |
|
27 | + $this->_standard_attributes_array(), |
|
28 | + array( |
|
29 | + 'value' => $default_value, |
|
30 | + ) |
|
31 | + ) |
|
32 | + ); |
|
33 | + if ($this->_input instanceof EE_Button_Input) { |
|
34 | + $button_content = $this->_input->button_content(); |
|
35 | + } else { |
|
36 | + $button_content = $this->_input->get_default(); |
|
37 | + } |
|
38 | + $html .= '>'; |
|
39 | + $html .= $button_content; |
|
40 | + $html .= $this->_closing_tag(); |
|
41 | + return $html; |
|
42 | + } |
|
43 | 43 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public static function getShared(FullyQualifiedName $domain_fqcn, array $arguments) |
42 | 42 | { |
43 | - if (! isset($arguments[0], $arguments[1])) { |
|
43 | + if ( ! isset($arguments[0], $arguments[1])) { |
|
44 | 44 | throw new InvalidArgumentException( |
45 | 45 | esc_html__( |
46 | 46 | 'You need to pass at least two arguments, representing the addon plugin file and version, in order to generate a Domain class', |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | ); |
50 | 50 | } |
51 | 51 | $domain = LoaderFactory::getLoader()->getShared($domain_fqcn, $arguments); |
52 | - if (! $domain instanceof $domain_fqcn && ! $domain instanceof DomainBase) { |
|
52 | + if ( ! $domain instanceof $domain_fqcn && ! $domain instanceof DomainBase) { |
|
53 | 53 | throw new DomainException( |
54 | 54 | sprintf( |
55 | 55 | esc_html__( |
@@ -28,63 +28,63 @@ |
||
28 | 28 | class DomainFactory |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * @param FullyQualifiedName $domain_fqcn [required] Fully Qualified Class Name for the Domain class |
|
33 | - * @param array $arguments [required] array of arguments to be passed to the Domain class |
|
34 | - * constructor. Must at least include the following two value objects: |
|
35 | - * array( |
|
36 | - * EventEspresso\core\domain\values\FilePath $plugin_file |
|
37 | - * EventEspresso\core\domain\values\Version $version |
|
38 | - * ) |
|
39 | - * @return mixed |
|
40 | - * @throws DomainException |
|
41 | - * @throws InvalidArgumentException |
|
42 | - * @throws InvalidDataTypeException |
|
43 | - * @throws InvalidInterfaceException |
|
44 | - */ |
|
45 | - public static function getShared(FullyQualifiedName $domain_fqcn, array $arguments) |
|
46 | - { |
|
47 | - if (! isset($arguments[0], $arguments[1])) { |
|
48 | - throw new InvalidArgumentException( |
|
49 | - esc_html__( |
|
50 | - 'You need to pass at least two arguments, representing the addon plugin file and version, in order to generate a Domain class', |
|
51 | - 'event_espresso' |
|
52 | - ) |
|
53 | - ); |
|
54 | - } |
|
55 | - $domain = LoaderFactory::getLoader()->getShared($domain_fqcn, $arguments); |
|
56 | - if (! $domain instanceof $domain_fqcn && ! $domain instanceof DomainBase) { |
|
57 | - throw new DomainException( |
|
58 | - sprintf( |
|
59 | - esc_html__( |
|
60 | - 'The requested Domain class "%1$s" could not be loaded.', |
|
61 | - 'event_espresso' |
|
62 | - ), |
|
63 | - $domain_fqcn |
|
64 | - ) |
|
65 | - ); |
|
66 | - } |
|
67 | - return $domain; |
|
68 | - } |
|
31 | + /** |
|
32 | + * @param FullyQualifiedName $domain_fqcn [required] Fully Qualified Class Name for the Domain class |
|
33 | + * @param array $arguments [required] array of arguments to be passed to the Domain class |
|
34 | + * constructor. Must at least include the following two value objects: |
|
35 | + * array( |
|
36 | + * EventEspresso\core\domain\values\FilePath $plugin_file |
|
37 | + * EventEspresso\core\domain\values\Version $version |
|
38 | + * ) |
|
39 | + * @return mixed |
|
40 | + * @throws DomainException |
|
41 | + * @throws InvalidArgumentException |
|
42 | + * @throws InvalidDataTypeException |
|
43 | + * @throws InvalidInterfaceException |
|
44 | + */ |
|
45 | + public static function getShared(FullyQualifiedName $domain_fqcn, array $arguments) |
|
46 | + { |
|
47 | + if (! isset($arguments[0], $arguments[1])) { |
|
48 | + throw new InvalidArgumentException( |
|
49 | + esc_html__( |
|
50 | + 'You need to pass at least two arguments, representing the addon plugin file and version, in order to generate a Domain class', |
|
51 | + 'event_espresso' |
|
52 | + ) |
|
53 | + ); |
|
54 | + } |
|
55 | + $domain = LoaderFactory::getLoader()->getShared($domain_fqcn, $arguments); |
|
56 | + if (! $domain instanceof $domain_fqcn && ! $domain instanceof DomainBase) { |
|
57 | + throw new DomainException( |
|
58 | + sprintf( |
|
59 | + esc_html__( |
|
60 | + 'The requested Domain class "%1$s" could not be loaded.', |
|
61 | + 'event_espresso' |
|
62 | + ), |
|
63 | + $domain_fqcn |
|
64 | + ) |
|
65 | + ); |
|
66 | + } |
|
67 | + return $domain; |
|
68 | + } |
|
69 | 69 | |
70 | 70 | |
71 | - /** |
|
72 | - * @return Domain |
|
73 | - * @throws DomainException |
|
74 | - * @throws InvalidArgumentException |
|
75 | - * @throws InvalidDataTypeException |
|
76 | - * @throws InvalidFilePathException |
|
77 | - * @throws InvalidInterfaceException |
|
78 | - */ |
|
79 | - public static function getEventEspressoCoreDomain() |
|
80 | - { |
|
81 | - $domain = new Domain( |
|
82 | - new FilePath(EVENT_ESPRESSO_MAIN_FILE), |
|
83 | - Version::fromString(espresso_version()) |
|
84 | - ); |
|
85 | - LoaderFactory::getLoader()->share('EventEspresso\core\domain\Domain', $domain); |
|
86 | - return $domain; |
|
87 | - } |
|
71 | + /** |
|
72 | + * @return Domain |
|
73 | + * @throws DomainException |
|
74 | + * @throws InvalidArgumentException |
|
75 | + * @throws InvalidDataTypeException |
|
76 | + * @throws InvalidFilePathException |
|
77 | + * @throws InvalidInterfaceException |
|
78 | + */ |
|
79 | + public static function getEventEspressoCoreDomain() |
|
80 | + { |
|
81 | + $domain = new Domain( |
|
82 | + new FilePath(EVENT_ESPRESSO_MAIN_FILE), |
|
83 | + Version::fromString(espresso_version()) |
|
84 | + ); |
|
85 | + LoaderFactory::getLoader()->share('EventEspresso\core\domain\Domain', $domain); |
|
86 | + return $domain; |
|
87 | + } |
|
88 | 88 | } |
89 | 89 | |
90 | 90 |
@@ -20,42 +20,42 @@ |
||
20 | 20 | class FilePath |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var string file_path |
|
25 | - */ |
|
26 | - private $file_path; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * FilePath constructor. |
|
31 | - * |
|
32 | - * @param string $file_path |
|
33 | - * @throws InvalidDataTypeException |
|
34 | - * @throws InvalidFilePathException |
|
35 | - */ |
|
36 | - public function __construct($file_path) |
|
37 | - { |
|
38 | - if (! is_string($file_path)) { |
|
39 | - throw new InvalidDataTypeException( |
|
40 | - '$file_path', |
|
41 | - $file_path, |
|
42 | - 'string' |
|
43 | - ); |
|
44 | - } |
|
45 | - if (! is_readable($file_path)) { |
|
46 | - throw new InvalidFilePathException($file_path); |
|
47 | - } |
|
48 | - $this->file_path = $file_path; |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @return string |
|
54 | - */ |
|
55 | - public function __toString() |
|
56 | - { |
|
57 | - return $this->file_path; |
|
58 | - } |
|
23 | + /** |
|
24 | + * @var string file_path |
|
25 | + */ |
|
26 | + private $file_path; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * FilePath constructor. |
|
31 | + * |
|
32 | + * @param string $file_path |
|
33 | + * @throws InvalidDataTypeException |
|
34 | + * @throws InvalidFilePathException |
|
35 | + */ |
|
36 | + public function __construct($file_path) |
|
37 | + { |
|
38 | + if (! is_string($file_path)) { |
|
39 | + throw new InvalidDataTypeException( |
|
40 | + '$file_path', |
|
41 | + $file_path, |
|
42 | + 'string' |
|
43 | + ); |
|
44 | + } |
|
45 | + if (! is_readable($file_path)) { |
|
46 | + throw new InvalidFilePathException($file_path); |
|
47 | + } |
|
48 | + $this->file_path = $file_path; |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @return string |
|
54 | + */ |
|
55 | + public function __toString() |
|
56 | + { |
|
57 | + return $this->file_path; |
|
58 | + } |
|
59 | 59 | |
60 | 60 | |
61 | 61 | } |
@@ -35,14 +35,14 @@ |
||
35 | 35 | */ |
36 | 36 | public function __construct($file_path) |
37 | 37 | { |
38 | - if (! is_string($file_path)) { |
|
38 | + if ( ! is_string($file_path)) { |
|
39 | 39 | throw new InvalidDataTypeException( |
40 | 40 | '$file_path', |
41 | 41 | $file_path, |
42 | 42 | 'string' |
43 | 43 | ); |
44 | 44 | } |
45 | - if (! is_readable($file_path)) { |
|
45 | + if ( ! is_readable($file_path)) { |
|
46 | 46 | throw new InvalidFilePathException($file_path); |
47 | 47 | } |
48 | 48 | $this->file_path = $file_path; |
@@ -37,14 +37,14 @@ |
||
37 | 37 | */ |
38 | 38 | public function __construct($fully_qualified_name) |
39 | 39 | { |
40 | - if (! is_string($fully_qualified_name)) { |
|
40 | + if ( ! is_string($fully_qualified_name)) { |
|
41 | 41 | throw new InvalidDataTypeException( |
42 | 42 | '$fully_qualified_name', |
43 | 43 | $fully_qualified_name, |
44 | 44 | 'string' |
45 | 45 | ); |
46 | 46 | } |
47 | - if (! class_exists($fully_qualified_name) && ! interface_exists($fully_qualified_name)) { |
|
47 | + if ( ! class_exists($fully_qualified_name) && ! interface_exists($fully_qualified_name)) { |
|
48 | 48 | if (strpos($fully_qualified_name, 'Interface') !== false) { |
49 | 49 | throw new InvalidInterfaceException($fully_qualified_name); |
50 | 50 | } |
@@ -21,54 +21,54 @@ |
||
21 | 21 | class FullyQualifiedName |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @var string $fully_qualified_name |
|
26 | - */ |
|
27 | - private $fully_qualified_name; |
|
24 | + /** |
|
25 | + * @var string $fully_qualified_name |
|
26 | + */ |
|
27 | + private $fully_qualified_name; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * FullyQualifiedName constructor. |
|
32 | - * |
|
33 | - * @param string $fully_qualified_name |
|
34 | - * @throws InvalidClassException |
|
35 | - * @throws InvalidInterfaceException |
|
36 | - * @throws InvalidDataTypeException |
|
37 | - */ |
|
38 | - public function __construct($fully_qualified_name) |
|
39 | - { |
|
40 | - if (! is_string($fully_qualified_name)) { |
|
41 | - throw new InvalidDataTypeException( |
|
42 | - '$fully_qualified_name', |
|
43 | - $fully_qualified_name, |
|
44 | - 'string' |
|
45 | - ); |
|
46 | - } |
|
47 | - if (! class_exists($fully_qualified_name) && ! interface_exists($fully_qualified_name)) { |
|
48 | - if (strpos($fully_qualified_name, 'Interface') !== false) { |
|
49 | - throw new InvalidInterfaceException($fully_qualified_name); |
|
50 | - } |
|
51 | - throw new InvalidClassException($fully_qualified_name); |
|
52 | - } |
|
53 | - $this->fully_qualified_name = $fully_qualified_name; |
|
54 | - } |
|
30 | + /** |
|
31 | + * FullyQualifiedName constructor. |
|
32 | + * |
|
33 | + * @param string $fully_qualified_name |
|
34 | + * @throws InvalidClassException |
|
35 | + * @throws InvalidInterfaceException |
|
36 | + * @throws InvalidDataTypeException |
|
37 | + */ |
|
38 | + public function __construct($fully_qualified_name) |
|
39 | + { |
|
40 | + if (! is_string($fully_qualified_name)) { |
|
41 | + throw new InvalidDataTypeException( |
|
42 | + '$fully_qualified_name', |
|
43 | + $fully_qualified_name, |
|
44 | + 'string' |
|
45 | + ); |
|
46 | + } |
|
47 | + if (! class_exists($fully_qualified_name) && ! interface_exists($fully_qualified_name)) { |
|
48 | + if (strpos($fully_qualified_name, 'Interface') !== false) { |
|
49 | + throw new InvalidInterfaceException($fully_qualified_name); |
|
50 | + } |
|
51 | + throw new InvalidClassException($fully_qualified_name); |
|
52 | + } |
|
53 | + $this->fully_qualified_name = $fully_qualified_name; |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * @return string |
|
59 | - */ |
|
60 | - public function string() |
|
61 | - { |
|
62 | - return $this->fully_qualified_name; |
|
63 | - } |
|
57 | + /** |
|
58 | + * @return string |
|
59 | + */ |
|
60 | + public function string() |
|
61 | + { |
|
62 | + return $this->fully_qualified_name; |
|
63 | + } |
|
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public function __toString() |
|
70 | - { |
|
71 | - return $this->fully_qualified_name; |
|
72 | - } |
|
66 | + /** |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public function __toString() |
|
70 | + { |
|
71 | + return $this->fully_qualified_name; |
|
72 | + } |
|
73 | 73 | |
74 | 74 | } |
@@ -121,7 +121,7 @@ |
||
121 | 121 | |
122 | 122 | |
123 | 123 | /** |
124 | - * @return Version |
|
124 | + * @return string |
|
125 | 125 | */ |
126 | 126 | public function versionValueObject() |
127 | 127 | { |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | */ |
137 | 137 | public function distributionAssetsPath() |
138 | 138 | { |
139 | - return $this->pluginPath() . 'assets/dist/'; |
|
139 | + return $this->pluginPath().'assets/dist/'; |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | */ |
146 | 146 | public function distributionAssetsUrl() |
147 | 147 | { |
148 | - return $this->pluginUrl() . 'assets/dist/'; |
|
148 | + return $this->pluginUrl().'assets/dist/'; |
|
149 | 149 | } |
150 | 150 | |
151 | 151 |
@@ -4,7 +4,6 @@ |
||
4 | 4 | |
5 | 5 | use EventEspresso\core\domain\values\FilePath; |
6 | 6 | use EventEspresso\core\domain\values\Version; |
7 | -use EventEspresso\core\services\assets\Registry; |
|
8 | 7 | |
9 | 8 | /** |
10 | 9 | * DomainBase Class |
@@ -16,153 +16,153 @@ |
||
16 | 16 | abstract class DomainBase implements DomainInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * Equivalent to `__FILE__` for main plugin file. |
|
21 | - * |
|
22 | - * @var FilePath |
|
23 | - */ |
|
24 | - private $plugin_file; |
|
25 | - |
|
26 | - /** |
|
27 | - * String indicating version for plugin |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - private $version; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var string $plugin_basename |
|
35 | - */ |
|
36 | - private $plugin_basename; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var string $plugin_path |
|
40 | - */ |
|
41 | - private $plugin_path; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var string $plugin_url |
|
45 | - */ |
|
46 | - private $plugin_url; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var string $asset_namespace |
|
50 | - */ |
|
51 | - private $asset_namespace; |
|
52 | - |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * Initializes internal properties. |
|
57 | - * |
|
58 | - * @param FilePath $plugin_file |
|
59 | - * @param Version $version |
|
60 | - */ |
|
61 | - public function __construct(FilePath $plugin_file, Version $version) |
|
62 | - { |
|
63 | - $this->plugin_file = $plugin_file; |
|
64 | - $this->version = $version; |
|
65 | - $this->plugin_basename = plugin_basename($this->pluginFile()); |
|
66 | - $this->plugin_path = plugin_dir_path($this->pluginFile()); |
|
67 | - $this->plugin_url = plugin_dir_url($this->pluginFile()); |
|
68 | - $this->setAssetNamespace(); |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - public function pluginFile() |
|
76 | - { |
|
77 | - return (string) $this->plugin_file; |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public function pluginBasename() |
|
86 | - { |
|
87 | - return $this->plugin_basename; |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - public function pluginPath() |
|
96 | - { |
|
97 | - return $this->plugin_path; |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - public function pluginUrl() |
|
106 | - { |
|
107 | - return $this->plugin_url; |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * @return string |
|
114 | - */ |
|
115 | - public function version() |
|
116 | - { |
|
117 | - return (string) $this->version; |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @return Version |
|
124 | - */ |
|
125 | - public function versionValueObject() |
|
126 | - { |
|
127 | - return $this->version; |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public function distributionAssetsPath() |
|
135 | - { |
|
136 | - return $this->pluginPath() . 'assets/dist/'; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - public function distributionAssetsUrl() |
|
144 | - { |
|
145 | - return $this->pluginUrl() . 'assets/dist/'; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * @return string |
|
151 | - */ |
|
152 | - public function assetNamespace() |
|
153 | - { |
|
154 | - return $this->asset_namespace; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * @return void |
|
160 | - */ |
|
161 | - private function setAssetNamespace() |
|
162 | - { |
|
163 | - $this->asset_namespace = sanitize_key( |
|
164 | - // convert directory separators to dashes and remove file extension |
|
165 | - str_replace(array('/', '.php'), array('-', ''), $this->plugin_basename) |
|
166 | - ); |
|
167 | - } |
|
19 | + /** |
|
20 | + * Equivalent to `__FILE__` for main plugin file. |
|
21 | + * |
|
22 | + * @var FilePath |
|
23 | + */ |
|
24 | + private $plugin_file; |
|
25 | + |
|
26 | + /** |
|
27 | + * String indicating version for plugin |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + private $version; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var string $plugin_basename |
|
35 | + */ |
|
36 | + private $plugin_basename; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var string $plugin_path |
|
40 | + */ |
|
41 | + private $plugin_path; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var string $plugin_url |
|
45 | + */ |
|
46 | + private $plugin_url; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var string $asset_namespace |
|
50 | + */ |
|
51 | + private $asset_namespace; |
|
52 | + |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * Initializes internal properties. |
|
57 | + * |
|
58 | + * @param FilePath $plugin_file |
|
59 | + * @param Version $version |
|
60 | + */ |
|
61 | + public function __construct(FilePath $plugin_file, Version $version) |
|
62 | + { |
|
63 | + $this->plugin_file = $plugin_file; |
|
64 | + $this->version = $version; |
|
65 | + $this->plugin_basename = plugin_basename($this->pluginFile()); |
|
66 | + $this->plugin_path = plugin_dir_path($this->pluginFile()); |
|
67 | + $this->plugin_url = plugin_dir_url($this->pluginFile()); |
|
68 | + $this->setAssetNamespace(); |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + public function pluginFile() |
|
76 | + { |
|
77 | + return (string) $this->plugin_file; |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public function pluginBasename() |
|
86 | + { |
|
87 | + return $this->plugin_basename; |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + public function pluginPath() |
|
96 | + { |
|
97 | + return $this->plugin_path; |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + public function pluginUrl() |
|
106 | + { |
|
107 | + return $this->plugin_url; |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * @return string |
|
114 | + */ |
|
115 | + public function version() |
|
116 | + { |
|
117 | + return (string) $this->version; |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @return Version |
|
124 | + */ |
|
125 | + public function versionValueObject() |
|
126 | + { |
|
127 | + return $this->version; |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public function distributionAssetsPath() |
|
135 | + { |
|
136 | + return $this->pluginPath() . 'assets/dist/'; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + public function distributionAssetsUrl() |
|
144 | + { |
|
145 | + return $this->pluginUrl() . 'assets/dist/'; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * @return string |
|
151 | + */ |
|
152 | + public function assetNamespace() |
|
153 | + { |
|
154 | + return $this->asset_namespace; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * @return void |
|
160 | + */ |
|
161 | + private function setAssetNamespace() |
|
162 | + { |
|
163 | + $this->asset_namespace = sanitize_key( |
|
164 | + // convert directory separators to dashes and remove file extension |
|
165 | + str_replace(array('/', '.php'), array('-', ''), $this->plugin_basename) |
|
166 | + ); |
|
167 | + } |
|
168 | 168 | } |
@@ -91,7 +91,7 @@ |
||
91 | 91 | public function __construct($slug, $description) |
92 | 92 | { |
93 | 93 | parent::__construct($slug, $description); |
94 | - if (! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
94 | + if ( ! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
95 | 95 | throw new InvalidArgumentException( |
96 | 96 | sprintf( |
97 | 97 | esc_html__( |
@@ -16,155 +16,155 @@ |
||
16 | 16 | class RequestTypeContext extends Context |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * indicates that the current request involves some form of activation |
|
21 | - */ |
|
22 | - const ACTIVATION = 'activation-request'; |
|
23 | - |
|
24 | - /** |
|
25 | - * indicates that the current request is for the admin but is not being made via AJAX |
|
26 | - */ |
|
27 | - const ADMIN = 'non-ajax-admin-request'; |
|
28 | - |
|
29 | - /** |
|
30 | - * indicates that the current request is for the admin AND is being made via AJAX |
|
31 | - */ |
|
32 | - const AJAX_ADMIN = 'admin-ajax-request'; |
|
33 | - |
|
34 | - /** |
|
35 | - * indicates that the current request is for the frontend AND is being made via AJAX |
|
36 | - */ |
|
37 | - const AJAX_FRONT = 'frontend-ajax-request'; |
|
38 | - |
|
39 | - /** |
|
40 | - * indicates that the current request is for the WP Heartbeat |
|
41 | - */ |
|
42 | - const AJAX_HEARTBEAT = 'admin-ajax-heartbeat'; |
|
43 | - |
|
44 | - /** |
|
45 | - * indicates that the current request is being made via AJAX, but is NOT for EE |
|
46 | - */ |
|
47 | - const AJAX_OTHER = 'other-ajax-request'; |
|
48 | - |
|
49 | - /** |
|
50 | - * indicates that the current request is for the EE REST API |
|
51 | - */ |
|
52 | - const API = 'rest-api'; |
|
53 | - |
|
54 | - /** |
|
55 | - * indicates that the current request is from the command line |
|
56 | - */ |
|
57 | - const CLI = 'command-line'; |
|
58 | - |
|
59 | - /** |
|
60 | - * indicates that the current request is for a WP_Cron |
|
61 | - */ |
|
62 | - const CRON = 'wp-cron'; |
|
63 | - |
|
64 | - /** |
|
65 | - * indicates that the current request is for a feed (ie: RSS) |
|
66 | - */ |
|
67 | - const FEED = 'feed-request'; |
|
68 | - |
|
69 | - /** |
|
70 | - * indicates that the current request is for the frontend but is not being made via AJAX |
|
71 | - */ |
|
72 | - const FRONTEND = 'non-ajax-frontend-request'; |
|
73 | - |
|
74 | - /** |
|
75 | - * indicates that the current request is for content that is to be displayed within an iframe |
|
76 | - */ |
|
77 | - const IFRAME = 'iframe-request'; |
|
78 | - |
|
79 | - /** |
|
80 | - * indicates that the current request is for the WP REST API |
|
81 | - */ |
|
82 | - const WP_API = 'wp-rest-api'; |
|
83 | - |
|
84 | - /** |
|
85 | - * indicates that the current request is a loopback sent from WP core to test for errors |
|
86 | - */ |
|
87 | - const WP_SCRAPE = 'wordpress-scrape'; |
|
88 | - |
|
89 | - /** |
|
90 | - * @var boolean $is_activation |
|
91 | - */ |
|
92 | - private $is_activation = false; |
|
93 | - |
|
94 | - /** |
|
95 | - * @var array $valid_request_types |
|
96 | - */ |
|
97 | - private $valid_request_types = array(); |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * RequestTypeContext constructor. |
|
102 | - * |
|
103 | - * @param string $slug |
|
104 | - * @param string $description |
|
105 | - * @throws InvalidArgumentException |
|
106 | - */ |
|
107 | - public function __construct($slug, $description) |
|
108 | - { |
|
109 | - parent::__construct($slug, $description); |
|
110 | - if (! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
111 | - throw new InvalidArgumentException( |
|
112 | - sprintf( |
|
113 | - esc_html__( |
|
114 | - 'The RequestTypeContext slug must be one of the following values: %1$s %2$s', |
|
115 | - 'event_espresso' |
|
116 | - ), |
|
117 | - var_export($this->validRequestTypes(), true) |
|
118 | - ) |
|
119 | - ); |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * @return array |
|
126 | - */ |
|
127 | - public function validRequestTypes() |
|
128 | - { |
|
129 | - if (empty($this->valid_request_types)) { |
|
130 | - $this->valid_request_types = apply_filters( |
|
131 | - 'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes', |
|
132 | - array( |
|
133 | - RequestTypeContext::ACTIVATION, |
|
134 | - RequestTypeContext::ADMIN, |
|
135 | - RequestTypeContext::AJAX_ADMIN, |
|
136 | - RequestTypeContext::AJAX_FRONT, |
|
137 | - RequestTypeContext::AJAX_HEARTBEAT, |
|
138 | - RequestTypeContext::AJAX_OTHER, |
|
139 | - RequestTypeContext::API, |
|
140 | - RequestTypeContext::CLI, |
|
141 | - RequestTypeContext::CRON, |
|
142 | - RequestTypeContext::FEED, |
|
143 | - RequestTypeContext::FRONTEND, |
|
144 | - RequestTypeContext::IFRAME, |
|
145 | - RequestTypeContext::WP_API, |
|
146 | - RequestTypeContext::WP_SCRAPE, |
|
147 | - ) |
|
148 | - ); |
|
149 | - } |
|
150 | - return $this->valid_request_types; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @return bool |
|
156 | - */ |
|
157 | - public function isActivation() |
|
158 | - { |
|
159 | - return $this->is_activation; |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * @param bool $is_activation |
|
165 | - */ |
|
166 | - public function setIsActivation($is_activation) |
|
167 | - { |
|
168 | - $this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN); |
|
169 | - } |
|
19 | + /** |
|
20 | + * indicates that the current request involves some form of activation |
|
21 | + */ |
|
22 | + const ACTIVATION = 'activation-request'; |
|
23 | + |
|
24 | + /** |
|
25 | + * indicates that the current request is for the admin but is not being made via AJAX |
|
26 | + */ |
|
27 | + const ADMIN = 'non-ajax-admin-request'; |
|
28 | + |
|
29 | + /** |
|
30 | + * indicates that the current request is for the admin AND is being made via AJAX |
|
31 | + */ |
|
32 | + const AJAX_ADMIN = 'admin-ajax-request'; |
|
33 | + |
|
34 | + /** |
|
35 | + * indicates that the current request is for the frontend AND is being made via AJAX |
|
36 | + */ |
|
37 | + const AJAX_FRONT = 'frontend-ajax-request'; |
|
38 | + |
|
39 | + /** |
|
40 | + * indicates that the current request is for the WP Heartbeat |
|
41 | + */ |
|
42 | + const AJAX_HEARTBEAT = 'admin-ajax-heartbeat'; |
|
43 | + |
|
44 | + /** |
|
45 | + * indicates that the current request is being made via AJAX, but is NOT for EE |
|
46 | + */ |
|
47 | + const AJAX_OTHER = 'other-ajax-request'; |
|
48 | + |
|
49 | + /** |
|
50 | + * indicates that the current request is for the EE REST API |
|
51 | + */ |
|
52 | + const API = 'rest-api'; |
|
53 | + |
|
54 | + /** |
|
55 | + * indicates that the current request is from the command line |
|
56 | + */ |
|
57 | + const CLI = 'command-line'; |
|
58 | + |
|
59 | + /** |
|
60 | + * indicates that the current request is for a WP_Cron |
|
61 | + */ |
|
62 | + const CRON = 'wp-cron'; |
|
63 | + |
|
64 | + /** |
|
65 | + * indicates that the current request is for a feed (ie: RSS) |
|
66 | + */ |
|
67 | + const FEED = 'feed-request'; |
|
68 | + |
|
69 | + /** |
|
70 | + * indicates that the current request is for the frontend but is not being made via AJAX |
|
71 | + */ |
|
72 | + const FRONTEND = 'non-ajax-frontend-request'; |
|
73 | + |
|
74 | + /** |
|
75 | + * indicates that the current request is for content that is to be displayed within an iframe |
|
76 | + */ |
|
77 | + const IFRAME = 'iframe-request'; |
|
78 | + |
|
79 | + /** |
|
80 | + * indicates that the current request is for the WP REST API |
|
81 | + */ |
|
82 | + const WP_API = 'wp-rest-api'; |
|
83 | + |
|
84 | + /** |
|
85 | + * indicates that the current request is a loopback sent from WP core to test for errors |
|
86 | + */ |
|
87 | + const WP_SCRAPE = 'wordpress-scrape'; |
|
88 | + |
|
89 | + /** |
|
90 | + * @var boolean $is_activation |
|
91 | + */ |
|
92 | + private $is_activation = false; |
|
93 | + |
|
94 | + /** |
|
95 | + * @var array $valid_request_types |
|
96 | + */ |
|
97 | + private $valid_request_types = array(); |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * RequestTypeContext constructor. |
|
102 | + * |
|
103 | + * @param string $slug |
|
104 | + * @param string $description |
|
105 | + * @throws InvalidArgumentException |
|
106 | + */ |
|
107 | + public function __construct($slug, $description) |
|
108 | + { |
|
109 | + parent::__construct($slug, $description); |
|
110 | + if (! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
111 | + throw new InvalidArgumentException( |
|
112 | + sprintf( |
|
113 | + esc_html__( |
|
114 | + 'The RequestTypeContext slug must be one of the following values: %1$s %2$s', |
|
115 | + 'event_espresso' |
|
116 | + ), |
|
117 | + var_export($this->validRequestTypes(), true) |
|
118 | + ) |
|
119 | + ); |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * @return array |
|
126 | + */ |
|
127 | + public function validRequestTypes() |
|
128 | + { |
|
129 | + if (empty($this->valid_request_types)) { |
|
130 | + $this->valid_request_types = apply_filters( |
|
131 | + 'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes', |
|
132 | + array( |
|
133 | + RequestTypeContext::ACTIVATION, |
|
134 | + RequestTypeContext::ADMIN, |
|
135 | + RequestTypeContext::AJAX_ADMIN, |
|
136 | + RequestTypeContext::AJAX_FRONT, |
|
137 | + RequestTypeContext::AJAX_HEARTBEAT, |
|
138 | + RequestTypeContext::AJAX_OTHER, |
|
139 | + RequestTypeContext::API, |
|
140 | + RequestTypeContext::CLI, |
|
141 | + RequestTypeContext::CRON, |
|
142 | + RequestTypeContext::FEED, |
|
143 | + RequestTypeContext::FRONTEND, |
|
144 | + RequestTypeContext::IFRAME, |
|
145 | + RequestTypeContext::WP_API, |
|
146 | + RequestTypeContext::WP_SCRAPE, |
|
147 | + ) |
|
148 | + ); |
|
149 | + } |
|
150 | + return $this->valid_request_types; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @return bool |
|
156 | + */ |
|
157 | + public function isActivation() |
|
158 | + { |
|
159 | + return $this->is_activation; |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * @param bool $is_activation |
|
165 | + */ |
|
166 | + public function setIsActivation($is_activation) |
|
167 | + { |
|
168 | + $this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN); |
|
169 | + } |
|
170 | 170 | } |