@@ -2,58 +2,57 @@ |
||
2 | 2 | |
3 | 3 | /** |
4 | 4 | * Goes through all the posts and pages, and converts old shortcodes to new ones |
5 | - |
|
6 | -*/ |
|
5 | + */ |
|
7 | 6 | |
8 | 7 | class EE_DMS_4_1_0_shortcodes extends EE_Data_Migration_Script_Stage |
9 | 8 | { |
10 | - public function __construct() |
|
11 | - { |
|
12 | - global $wpdb; |
|
13 | - $this->_pretty_name = __("Shortcodes", "event_espresso"); |
|
14 | - $this->_old_table = $wpdb->posts; |
|
15 | - parent::__construct(); |
|
16 | - } |
|
17 | - protected function _migrate_old_row($old_row) |
|
18 | - { |
|
19 | - $new_post_content = $this->_change_event_list_shortcode($old_row['post_content']); |
|
20 | - global $wpdb; |
|
21 | - $wpdb->query($wpdb->prepare("UPDATE ".$this->_old_table." SET post_content=%s WHERE ID=%d", $new_post_content, $old_row['ID'])); |
|
22 | - } |
|
9 | + public function __construct() |
|
10 | + { |
|
11 | + global $wpdb; |
|
12 | + $this->_pretty_name = __("Shortcodes", "event_espresso"); |
|
13 | + $this->_old_table = $wpdb->posts; |
|
14 | + parent::__construct(); |
|
15 | + } |
|
16 | + protected function _migrate_old_row($old_row) |
|
17 | + { |
|
18 | + $new_post_content = $this->_change_event_list_shortcode($old_row['post_content']); |
|
19 | + global $wpdb; |
|
20 | + $wpdb->query($wpdb->prepare("UPDATE ".$this->_old_table." SET post_content=%s WHERE ID=%d", $new_post_content, $old_row['ID'])); |
|
21 | + } |
|
23 | 22 | |
24 | - /** |
|
25 | - * replaces [EVENT_LIST... with [ESPRESSO_EVENTS...] |
|
26 | - * @param string $old_content |
|
27 | - */ |
|
28 | - private function _change_event_list_shortcode($old_content) |
|
29 | - { |
|
30 | - return str_replace("[EVENT_LIST", "[ESPRESSO_EVENTS", $old_content); |
|
31 | - } |
|
23 | + /** |
|
24 | + * replaces [EVENT_LIST... with [ESPRESSO_EVENTS...] |
|
25 | + * @param string $old_content |
|
26 | + */ |
|
27 | + private function _change_event_list_shortcode($old_content) |
|
28 | + { |
|
29 | + return str_replace("[EVENT_LIST", "[ESPRESSO_EVENTS", $old_content); |
|
30 | + } |
|
32 | 31 | |
33 | - public function _migration_step($num_items = 50) |
|
34 | - { |
|
35 | - global $wpdb; |
|
36 | - $start_at_record = $this->count_records_migrated(); |
|
37 | - $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table {$this->_sql_to_only_select_non_drafts()} LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A); |
|
38 | - $items_actually_migrated = 0; |
|
39 | - foreach ($rows as $old_row) { |
|
40 | - $this->_migrate_old_row($old_row); |
|
41 | - $items_actually_migrated++; |
|
42 | - } |
|
43 | - if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
44 | - $this->set_completed(); |
|
45 | - } |
|
46 | - return $items_actually_migrated; |
|
47 | - } |
|
48 | - public function _count_records_to_migrate() |
|
49 | - { |
|
50 | - global $wpdb; |
|
51 | - $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table.$this->_sql_to_only_select_non_drafts()); |
|
52 | - return $count; |
|
53 | - } |
|
32 | + public function _migration_step($num_items = 50) |
|
33 | + { |
|
34 | + global $wpdb; |
|
35 | + $start_at_record = $this->count_records_migrated(); |
|
36 | + $rows = $wpdb->get_results($wpdb->prepare("SELECT * FROM $this->_old_table {$this->_sql_to_only_select_non_drafts()} LIMIT %d,%d", $start_at_record, $num_items), ARRAY_A); |
|
37 | + $items_actually_migrated = 0; |
|
38 | + foreach ($rows as $old_row) { |
|
39 | + $this->_migrate_old_row($old_row); |
|
40 | + $items_actually_migrated++; |
|
41 | + } |
|
42 | + if ($this->count_records_migrated() + $items_actually_migrated >= $this->count_records_to_migrate()) { |
|
43 | + $this->set_completed(); |
|
44 | + } |
|
45 | + return $items_actually_migrated; |
|
46 | + } |
|
47 | + public function _count_records_to_migrate() |
|
48 | + { |
|
49 | + global $wpdb; |
|
50 | + $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table.$this->_sql_to_only_select_non_drafts()); |
|
51 | + return $count; |
|
52 | + } |
|
54 | 53 | |
55 | - private function _sql_to_only_select_non_drafts() |
|
56 | - { |
|
57 | - return " WHERE post_type NOT IN ('revision','auto-draft','attachment','nav_menu_item') "; |
|
58 | - } |
|
54 | + private function _sql_to_only_select_non_drafts() |
|
55 | + { |
|
56 | + return " WHERE post_type NOT IN ('revision','auto-draft','attachment','nav_menu_item') "; |
|
57 | + } |
|
59 | 58 | } |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | /** |
334 | 334 | * @param EE_Ticket $ticket |
335 | 335 | * @param int $quantity |
336 | - * @return bool |
|
336 | + * @return integer |
|
337 | 337 | * @throws EE_Error |
338 | 338 | */ |
339 | 339 | protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
@@ -984,6 +984,7 @@ discard block |
||
984 | 984 | * reservations are now invalid. We don't use the list of invalid ticket line items because |
985 | 985 | * we don't know which of those have already been taken into account when reducing ticket |
986 | 986 | * reservation counts, and which haven't. |
987 | + * @param string $source |
|
987 | 988 | * @return int |
988 | 989 | * @throws UnexpectedEntityException |
989 | 990 | * @throws DomainException |
@@ -20,1056 +20,1056 @@ |
||
20 | 20 | class EED_Ticket_Sales_Monitor extends EED_Module |
21 | 21 | { |
22 | 22 | |
23 | - const debug = false; |
|
24 | - |
|
25 | - private static $nl = ''; |
|
26 | - |
|
27 | - /** |
|
28 | - * an array of raw ticket data from EED_Ticket_Selector |
|
29 | - * |
|
30 | - * @var array $ticket_selections |
|
31 | - */ |
|
32 | - protected $ticket_selections = array(); |
|
33 | - |
|
34 | - /** |
|
35 | - * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
36 | - * according to how they are displayed in the actual Ticket_Selector |
|
37 | - * this tracks the current row being processed |
|
38 | - * |
|
39 | - * @var int $current_row |
|
40 | - */ |
|
41 | - protected $current_row = 0; |
|
42 | - |
|
43 | - /** |
|
44 | - * an array for tracking names of tickets that have sold out |
|
45 | - * |
|
46 | - * @var array $sold_out_tickets |
|
47 | - */ |
|
48 | - protected $sold_out_tickets = array(); |
|
49 | - |
|
50 | - /** |
|
51 | - * an array for tracking names of tickets that have had their quantities reduced |
|
52 | - * |
|
53 | - * @var array $decremented_tickets |
|
54 | - */ |
|
55 | - protected $decremented_tickets = array(); |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
60 | - * |
|
61 | - * @return void |
|
62 | - */ |
|
63 | - public static function set_hooks() |
|
64 | - { |
|
65 | - self::$nl = defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
66 | - // release tickets for expired carts |
|
67 | - add_action( |
|
68 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
69 | - array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
70 | - 1 |
|
71 | - ); |
|
72 | - // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
73 | - add_filter( |
|
74 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
75 | - array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
76 | - 20, |
|
77 | - 3 |
|
78 | - ); |
|
79 | - // add notices for sold out tickets |
|
80 | - add_action( |
|
81 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
82 | - array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
83 | - 10 |
|
84 | - ); |
|
85 | - |
|
86 | - // handle tickets deleted from cart |
|
87 | - add_action( |
|
88 | - 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
89 | - array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
90 | - 10, |
|
91 | - 2 |
|
92 | - ); |
|
93 | - // handle emptied carts |
|
94 | - add_action( |
|
95 | - 'AHEE__EE_Session__reset_cart__before_reset', |
|
96 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
97 | - 10, |
|
98 | - 1 |
|
99 | - ); |
|
100 | - add_action( |
|
101 | - 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
102 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
103 | - 10, |
|
104 | - 1 |
|
105 | - ); |
|
106 | - // handle cancelled registrations |
|
107 | - add_action( |
|
108 | - 'AHEE__EE_Session__reset_checkout__before_reset', |
|
109 | - array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
110 | - 10, |
|
111 | - 1 |
|
112 | - ); |
|
113 | - // cron tasks |
|
114 | - add_action( |
|
115 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
116 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
117 | - 10, |
|
118 | - 1 |
|
119 | - ); |
|
120 | - add_action( |
|
121 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
122 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
123 | - 10, |
|
124 | - 1 |
|
125 | - ); |
|
126 | - add_action( |
|
127 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
128 | - array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
129 | - 10, |
|
130 | - 1 |
|
131 | - ); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
137 | - * |
|
138 | - * @return void |
|
139 | - */ |
|
140 | - public static function set_hooks_admin() |
|
141 | - { |
|
142 | - EED_Ticket_Sales_Monitor::set_hooks(); |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * @return EED_Ticket_Sales_Monitor|EED_Module |
|
148 | - */ |
|
149 | - public static function instance() |
|
150 | - { |
|
151 | - return parent::get_instance(__CLASS__); |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * @param WP_Query $WP_Query |
|
157 | - * @return void |
|
158 | - */ |
|
159 | - public function run($WP_Query) |
|
160 | - { |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - |
|
165 | - /********************************** PRE_TICKET_SALES **********************************/ |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * Retrieves grand totals from the line items that have no TXN ID |
|
170 | - * and timestamps less than the current time minus the session lifespan. |
|
171 | - * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
172 | - * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
173 | - * |
|
174 | - * @return void |
|
175 | - * @throws DomainException |
|
176 | - * @throws EE_Error |
|
177 | - * @throws InvalidArgumentException |
|
178 | - * @throws InvalidDataTypeException |
|
179 | - * @throws InvalidInterfaceException |
|
180 | - * @throws UnexpectedEntityException |
|
181 | - */ |
|
182 | - public static function release_tickets_for_expired_carts() |
|
183 | - { |
|
184 | - if (self::debug) { |
|
185 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
186 | - } |
|
187 | - do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
188 | - $expired_ticket_IDs = array(); |
|
189 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
190 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
191 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
192 | - ); |
|
193 | - $timestamp = $session_lifespan->expiration(); |
|
194 | - $expired_ticket_line_items = EEM_Line_Item::instance()->getTicketLineItemsForExpiredCarts($timestamp); |
|
195 | - if (self::debug) { |
|
196 | - echo self::$nl . ' . time(): ' . time(); |
|
197 | - echo self::$nl . ' . time() as date: ' . date('Y-m-d H:i a'); |
|
198 | - echo self::$nl . ' . session expiration: ' . $session_lifespan->expiration(); |
|
199 | - echo self::$nl . ' . session expiration as date: ' . date('Y-m-d H:i a', $session_lifespan->expiration()); |
|
200 | - echo self::$nl . ' . timestamp: ' . $timestamp; |
|
201 | - echo self::$nl . ' . $expired_ticket_line_items: ' . count($expired_ticket_line_items); |
|
202 | - } |
|
203 | - if (! empty($expired_ticket_line_items)) { |
|
204 | - foreach ($expired_ticket_line_items as $expired_ticket_line_item) { |
|
205 | - if (! $expired_ticket_line_item instanceof EE_Line_Item) { |
|
206 | - continue; |
|
207 | - } |
|
208 | - $expired_ticket_IDs[ $expired_ticket_line_item->OBJ_ID() ] = $expired_ticket_line_item->OBJ_ID(); |
|
209 | - if (self::debug) { |
|
210 | - echo self::$nl . ' . $expired_ticket_line_item->OBJ_ID(): ' . $expired_ticket_line_item->OBJ_ID(); |
|
211 | - echo self::$nl . ' . $expired_ticket_line_item->timestamp(): ' |
|
212 | - . date( |
|
213 | - 'Y-m-d h:i a', |
|
214 | - $expired_ticket_line_item->timestamp(true) |
|
215 | - ); |
|
216 | - } |
|
217 | - } |
|
218 | - if (! empty($expired_ticket_IDs)) { |
|
219 | - EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
220 | - \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
221 | - array(), |
|
222 | - __FUNCTION__ |
|
223 | - ); |
|
224 | - // now let's get rid of expired line items so that they can't interfere with tracking |
|
225 | - EED_Ticket_Sales_Monitor::clear_expired_line_items_with_no_transaction($timestamp); |
|
226 | - } |
|
227 | - } |
|
228 | - do_action( |
|
229 | - 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
230 | - $expired_ticket_IDs, |
|
231 | - $expired_ticket_line_items |
|
232 | - ); |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - |
|
237 | - /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
242 | - * |
|
243 | - * @param int $qty |
|
244 | - * @param EE_Ticket $ticket |
|
245 | - * @return bool |
|
246 | - * @throws UnexpectedEntityException |
|
247 | - * @throws EE_Error |
|
248 | - */ |
|
249 | - public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
250 | - { |
|
251 | - $qty = absint($qty); |
|
252 | - if ($qty > 0) { |
|
253 | - $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
254 | - } |
|
255 | - if (self::debug) { |
|
256 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
257 | - echo self::$nl . self::$nl . '<b> RETURNED QTY: ' . $qty . '</b>'; |
|
258 | - } |
|
259 | - return $qty; |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
265 | - * |
|
266 | - * @param EE_Ticket $ticket |
|
267 | - * @param int $qty |
|
268 | - * @return int |
|
269 | - * @throws UnexpectedEntityException |
|
270 | - * @throws EE_Error |
|
271 | - */ |
|
272 | - protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
273 | - { |
|
274 | - if (self::debug) { |
|
275 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
276 | - } |
|
277 | - if (! $ticket instanceof EE_Ticket) { |
|
278 | - return 0; |
|
279 | - } |
|
280 | - if (self::debug) { |
|
281 | - echo self::$nl . '<b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
282 | - echo self::$nl . ' . original ticket->reserved: ' . $ticket->reserved(); |
|
283 | - } |
|
284 | - $ticket->refresh_from_db(); |
|
285 | - // first let's determine the ticket availability based on sales |
|
286 | - $available = $ticket->qty('saleable'); |
|
287 | - if (self::debug) { |
|
288 | - echo self::$nl . ' . . . ticket->qty: ' . $ticket->qty(); |
|
289 | - echo self::$nl . ' . . . ticket->sold: ' . $ticket->sold(); |
|
290 | - echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
291 | - echo self::$nl . ' . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
292 | - echo self::$nl . ' . . . available: ' . $available; |
|
293 | - } |
|
294 | - if ($available < 1) { |
|
295 | - $this->_ticket_sold_out($ticket); |
|
296 | - return 0; |
|
297 | - } |
|
298 | - if (self::debug) { |
|
299 | - echo self::$nl . ' . . . qty: ' . $qty; |
|
300 | - } |
|
301 | - if ($available < $qty) { |
|
302 | - $qty = $available; |
|
303 | - if (self::debug) { |
|
304 | - echo self::$nl . ' . . . QTY ADJUSTED: ' . $qty; |
|
305 | - } |
|
306 | - $this->_ticket_quantity_decremented($ticket); |
|
307 | - } |
|
308 | - if ($this->_reserve_ticket($ticket, $qty)) { |
|
309 | - return $qty; |
|
310 | - } else { |
|
311 | - return 0; |
|
312 | - } |
|
313 | - } |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * increments ticket reserved based on quantity passed |
|
318 | - * |
|
319 | - * @param EE_Ticket $ticket |
|
320 | - * @param int $quantity |
|
321 | - * @return bool indicating success or failure |
|
322 | - * @throws EE_Error |
|
323 | - */ |
|
324 | - protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
325 | - { |
|
326 | - if (self::debug) { |
|
327 | - echo self::$nl . self::$nl . ' . . . INCREASE RESERVED: ' . $quantity; |
|
328 | - } |
|
329 | - return $ticket->increaseReserved($quantity, 'TicketSalesMonitor:' . __LINE__); |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - /** |
|
334 | - * @param EE_Ticket $ticket |
|
335 | - * @param int $quantity |
|
336 | - * @return bool |
|
337 | - * @throws EE_Error |
|
338 | - */ |
|
339 | - protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
340 | - { |
|
341 | - if (self::debug) { |
|
342 | - echo self::$nl . ' . . . ticket->ID: ' . $ticket->ID(); |
|
343 | - echo self::$nl . ' . . . ticket->reserved before: ' . $ticket->reserved(); |
|
344 | - } |
|
345 | - $ticket->decreaseReserved($quantity, true, 'TicketSalesMonitor:' . __LINE__); |
|
346 | - if (self::debug) { |
|
347 | - echo self::$nl . ' . . . ticket->reserved after: ' . $ticket->reserved(); |
|
348 | - } |
|
349 | - return $ticket->save() ? 1 : 0; |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * removes quantities within the ticket selector based on zero ticket availability |
|
355 | - * |
|
356 | - * @param EE_Ticket $ticket |
|
357 | - * @return void |
|
358 | - * @throws UnexpectedEntityException |
|
359 | - * @throws EE_Error |
|
360 | - */ |
|
361 | - protected function _ticket_sold_out(EE_Ticket $ticket) |
|
362 | - { |
|
363 | - if (self::debug) { |
|
364 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
365 | - echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
366 | - } |
|
367 | - $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
368 | - } |
|
369 | - |
|
370 | - |
|
371 | - /** |
|
372 | - * adjusts quantities within the ticket selector based on decreased ticket availability |
|
373 | - * |
|
374 | - * @param EE_Ticket $ticket |
|
375 | - * @return void |
|
376 | - * @throws UnexpectedEntityException |
|
377 | - * @throws EE_Error |
|
378 | - */ |
|
379 | - protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
380 | - { |
|
381 | - if (self::debug) { |
|
382 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
383 | - echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
384 | - } |
|
385 | - $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * builds string out of ticket and event name |
|
391 | - * |
|
392 | - * @param EE_Ticket $ticket |
|
393 | - * @return string |
|
394 | - * @throws UnexpectedEntityException |
|
395 | - * @throws EE_Error |
|
396 | - */ |
|
397 | - protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
398 | - { |
|
399 | - $event = $ticket->get_related_event(); |
|
400 | - if ($event instanceof EE_Event) { |
|
401 | - $ticket_name = sprintf( |
|
402 | - _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
403 | - $ticket->name(), |
|
404 | - $event->name() |
|
405 | - ); |
|
406 | - } else { |
|
407 | - $ticket_name = $ticket->name(); |
|
408 | - } |
|
409 | - return $ticket_name; |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - |
|
414 | - /********************************** EVENT CART **********************************/ |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * releases or reserves ticket(s) based on quantity passed |
|
419 | - * |
|
420 | - * @param EE_Line_Item $line_item |
|
421 | - * @param int $quantity |
|
422 | - * @return void |
|
423 | - * @throws EE_Error |
|
424 | - * @throws InvalidArgumentException |
|
425 | - * @throws InvalidDataTypeException |
|
426 | - * @throws InvalidInterfaceException |
|
427 | - */ |
|
428 | - public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
429 | - { |
|
430 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
431 | - if ($ticket instanceof EE_Ticket) { |
|
432 | - $ticket->add_extra_meta( |
|
433 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
434 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
435 | - ); |
|
436 | - if ($quantity > 0) { |
|
437 | - EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
438 | - } else { |
|
439 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
440 | - } |
|
441 | - } |
|
442 | - } |
|
443 | - |
|
444 | - |
|
445 | - /** |
|
446 | - * releases reserved ticket(s) based on quantity passed |
|
447 | - * |
|
448 | - * @param EE_Ticket $ticket |
|
449 | - * @param int $quantity |
|
450 | - * @return void |
|
451 | - * @throws EE_Error |
|
452 | - */ |
|
453 | - public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
454 | - { |
|
455 | - $ticket->add_extra_meta( |
|
456 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
457 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
458 | - ); |
|
459 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - |
|
464 | - /********************************** POST_NOTICES **********************************/ |
|
465 | - |
|
466 | - |
|
467 | - /** |
|
468 | - * @return void |
|
469 | - * @throws EE_Error |
|
470 | - * @throws InvalidArgumentException |
|
471 | - * @throws ReflectionException |
|
472 | - * @throws InvalidDataTypeException |
|
473 | - * @throws InvalidInterfaceException |
|
474 | - */ |
|
475 | - public static function post_notices() |
|
476 | - { |
|
477 | - EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
478 | - } |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * @return void |
|
483 | - * @throws EE_Error |
|
484 | - * @throws InvalidArgumentException |
|
485 | - * @throws ReflectionException |
|
486 | - * @throws InvalidDataTypeException |
|
487 | - * @throws InvalidInterfaceException |
|
488 | - */ |
|
489 | - protected function _post_notices() |
|
490 | - { |
|
491 | - if (self::debug) { |
|
492 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
493 | - } |
|
494 | - $refresh_msg = ''; |
|
495 | - $none_added_msg = ''; |
|
496 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
497 | - $refresh_msg = __( |
|
498 | - 'Please refresh the page to view updated ticket quantities.', |
|
499 | - 'event_espresso' |
|
500 | - ); |
|
501 | - $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
502 | - } |
|
503 | - if (! empty($this->sold_out_tickets)) { |
|
504 | - EE_Error::add_attention( |
|
505 | - sprintf( |
|
506 | - apply_filters( |
|
507 | - 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
508 | - __( |
|
509 | - 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
510 | - 'event_espresso' |
|
511 | - ) |
|
512 | - ), |
|
513 | - '<br />', |
|
514 | - implode('<br />', $this->sold_out_tickets), |
|
515 | - $none_added_msg, |
|
516 | - $refresh_msg |
|
517 | - ) |
|
518 | - ); |
|
519 | - // alter code flow in the Ticket Selector for better UX |
|
520 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
521 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
522 | - $this->sold_out_tickets = array(); |
|
523 | - // and reset the cart |
|
524 | - EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
525 | - } |
|
526 | - if (! empty($this->decremented_tickets)) { |
|
527 | - EE_Error::add_attention( |
|
528 | - sprintf( |
|
529 | - apply_filters( |
|
530 | - 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
531 | - __( |
|
532 | - 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
533 | - 'event_espresso' |
|
534 | - ) |
|
535 | - ), |
|
536 | - '<br />', |
|
537 | - implode('<br />', $this->decremented_tickets), |
|
538 | - $none_added_msg, |
|
539 | - $refresh_msg |
|
540 | - ) |
|
541 | - ); |
|
542 | - $this->decremented_tickets = array(); |
|
543 | - } |
|
544 | - } |
|
545 | - |
|
546 | - |
|
547 | - |
|
548 | - /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
549 | - |
|
550 | - |
|
551 | - /** |
|
552 | - * releases reserved tickets for all registrations of an EE_Transaction |
|
553 | - * by default, will NOT release tickets for finalized transactions |
|
554 | - * |
|
555 | - * @param EE_Transaction $transaction |
|
556 | - * @return int |
|
557 | - * @throws EE_Error |
|
558 | - * @throws InvalidSessionDataException |
|
559 | - */ |
|
560 | - protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
561 | - { |
|
562 | - if (self::debug) { |
|
563 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
564 | - echo self::$nl . ' . transaction->ID: ' . $transaction->ID(); |
|
565 | - echo self::$nl . ' . TXN status_ID: ' . $transaction->status_ID(); |
|
566 | - } |
|
567 | - // check if 'finalize_registration' step has been completed... |
|
568 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
569 | - if (self::debug) { |
|
570 | - // DEBUG LOG |
|
571 | - EEH_Debug_Tools::log( |
|
572 | - __CLASS__, |
|
573 | - __FUNCTION__, |
|
574 | - __LINE__, |
|
575 | - array('finalized' => $finalized), |
|
576 | - false, |
|
577 | - 'EE_Transaction: ' . $transaction->ID() |
|
578 | - ); |
|
579 | - } |
|
580 | - // how many tickets were released |
|
581 | - $count = 0; |
|
582 | - if (self::debug) { |
|
583 | - echo self::$nl . ' . . . TXN finalized: ' . $finalized; |
|
584 | - } |
|
585 | - $release_tickets_with_TXN_status = array( |
|
586 | - EEM_Transaction::failed_status_code, |
|
587 | - EEM_Transaction::abandoned_status_code, |
|
588 | - EEM_Transaction::incomplete_status_code, |
|
589 | - ); |
|
590 | - $events = array(); |
|
591 | - // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed |
|
592 | - if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
593 | - // cancel any reserved tickets for registrations that were not approved |
|
594 | - $registrations = $transaction->registrations(); |
|
595 | - if (self::debug) { |
|
596 | - echo self::$nl . ' . . . # registrations: ' . count($registrations); |
|
597 | - $reg = reset($registrations); |
|
598 | - $ticket = $reg->ticket(); |
|
599 | - if ($ticket instanceof EE_Ticket) { |
|
600 | - $ticket->add_extra_meta( |
|
601 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
602 | - __LINE__ . ') Release All Tickets TXN:' . $transaction->ID() |
|
603 | - ); |
|
604 | - } |
|
605 | - } |
|
606 | - if (! empty($registrations)) { |
|
607 | - foreach ($registrations as $registration) { |
|
608 | - if ($registration instanceof EE_Registration |
|
609 | - && $this->_release_reserved_ticket_for_registration($registration, $transaction) |
|
610 | - ) { |
|
611 | - $count++; |
|
612 | - $events[ $registration->event_ID() ] = $registration->event(); |
|
613 | - } |
|
614 | - } |
|
615 | - } |
|
616 | - } |
|
617 | - if ($events !== array()) { |
|
618 | - foreach ($events as $event) { |
|
619 | - /** @var EE_Event $event */ |
|
620 | - $event->perform_sold_out_status_check(); |
|
621 | - } |
|
622 | - } |
|
623 | - return $count; |
|
624 | - } |
|
625 | - |
|
626 | - |
|
627 | - /** |
|
628 | - * releases reserved tickets for an EE_Registration |
|
629 | - * by default, will NOT release tickets for APPROVED registrations |
|
630 | - * |
|
631 | - * @param EE_Registration $registration |
|
632 | - * @param EE_Transaction $transaction |
|
633 | - * @return int |
|
634 | - * @throws EE_Error |
|
635 | - */ |
|
636 | - protected function _release_reserved_ticket_for_registration( |
|
637 | - EE_Registration $registration, |
|
638 | - EE_Transaction $transaction |
|
639 | - ) { |
|
640 | - $STS_ID = $transaction->status_ID(); |
|
641 | - if (self::debug) { |
|
642 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
643 | - echo self::$nl . ' . . registration->ID: ' . $registration->ID(); |
|
644 | - echo self::$nl . ' . . registration->status_ID: ' . $registration->status_ID(); |
|
645 | - echo self::$nl . ' . . transaction->status_ID(): ' . $STS_ID; |
|
646 | - } |
|
647 | - if (// release Tickets for Failed Transactions and Abandoned Transactions |
|
648 | - $STS_ID === EEM_Transaction::failed_status_code |
|
649 | - || $STS_ID === EEM_Transaction::abandoned_status_code |
|
650 | - || ( |
|
651 | - // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
652 | - $STS_ID === EEM_Transaction::incomplete_status_code |
|
653 | - && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
654 | - ) |
|
655 | - ) { |
|
656 | - if (self::debug) { |
|
657 | - echo self::$nl . self::$nl . ' . . RELEASE RESERVED TICKET'; |
|
658 | - $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true); |
|
659 | - echo self::$nl . ' . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
660 | - var_dump($rsrvd); |
|
661 | - } |
|
662 | - $registration->release_reserved_ticket(true, 'TicketSalesMonitor:' . __LINE__); |
|
663 | - return 1; |
|
664 | - } |
|
665 | - return 0; |
|
666 | - } |
|
667 | - |
|
668 | - |
|
669 | - |
|
670 | - /********************************** SESSION_CART_RESET **********************************/ |
|
671 | - |
|
672 | - |
|
673 | - /** |
|
674 | - * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
675 | - * |
|
676 | - * @param EE_Session $session |
|
677 | - * @return void |
|
678 | - * @throws EE_Error |
|
679 | - * @throws InvalidArgumentException |
|
680 | - * @throws ReflectionException |
|
681 | - * @throws InvalidDataTypeException |
|
682 | - * @throws InvalidInterfaceException |
|
683 | - */ |
|
684 | - public static function session_cart_reset(EE_Session $session) |
|
685 | - { |
|
686 | - // don't release tickets if checkout was already reset |
|
687 | - if (did_action('AHEE__EE_Session__reset_checkout__before_reset')) { |
|
688 | - return; |
|
689 | - } |
|
690 | - if (self::debug) { |
|
691 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
692 | - } |
|
693 | - // first check of the session has a valid Checkout object |
|
694 | - $checkout = $session->checkout(); |
|
695 | - if ($checkout instanceof EE_Checkout) { |
|
696 | - // and use that to clear ticket reservations because it will update the associated registration meta data |
|
697 | - EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
698 | - return; |
|
699 | - } |
|
700 | - $cart = $session->cart(); |
|
701 | - if ($cart instanceof EE_Cart) { |
|
702 | - if (self::debug) { |
|
703 | - echo self::$nl . self::$nl . ' cart instance of EE_Cart: '; |
|
704 | - } |
|
705 | - EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session); |
|
706 | - } else { |
|
707 | - if (self::debug) { |
|
708 | - echo self::$nl . self::$nl . ' invalid EE_Cart: '; |
|
709 | - var_export($cart, true); |
|
710 | - } |
|
711 | - } |
|
712 | - } |
|
713 | - |
|
714 | - |
|
715 | - /** |
|
716 | - * releases reserved tickets in the EE_Cart |
|
717 | - * |
|
718 | - * @param EE_Cart $cart |
|
719 | - * @return void |
|
720 | - * @throws EE_Error |
|
721 | - * @throws InvalidArgumentException |
|
722 | - * @throws ReflectionException |
|
723 | - * @throws InvalidDataTypeException |
|
724 | - * @throws InvalidInterfaceException |
|
725 | - */ |
|
726 | - protected function _session_cart_reset(EE_Cart $cart, EE_Session $session) |
|
727 | - { |
|
728 | - if (self::debug) { |
|
729 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
730 | - } |
|
731 | - $ticket_line_items = $cart->get_tickets(); |
|
732 | - if (empty($ticket_line_items)) { |
|
733 | - return; |
|
734 | - } |
|
735 | - if (self::debug) { |
|
736 | - echo '<br /> . ticket_line_item count: ' . count($ticket_line_items); |
|
737 | - } |
|
738 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
739 | - if (self::debug) { |
|
740 | - echo self::$nl . ' . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
741 | - } |
|
742 | - if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
743 | - if (self::debug) { |
|
744 | - echo self::$nl . ' . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
745 | - } |
|
746 | - $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
747 | - if ($ticket instanceof EE_Ticket) { |
|
748 | - if (self::debug) { |
|
749 | - echo self::$nl . ' . . ticket->ID(): ' . $ticket->ID(); |
|
750 | - echo self::$nl . ' . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
751 | - } |
|
752 | - $ticket->add_extra_meta( |
|
753 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
754 | - __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id() |
|
755 | - ); |
|
756 | - $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
757 | - } |
|
758 | - } |
|
759 | - } |
|
760 | - if (self::debug) { |
|
761 | - echo self::$nl . self::$nl . ' RESET COMPLETED '; |
|
762 | - } |
|
763 | - } |
|
764 | - |
|
765 | - |
|
766 | - |
|
767 | - /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
768 | - |
|
769 | - |
|
770 | - /** |
|
771 | - * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
772 | - * |
|
773 | - * @param EE_Session $session |
|
774 | - * @return void |
|
775 | - * @throws EE_Error |
|
776 | - * @throws InvalidSessionDataException |
|
777 | - */ |
|
778 | - public static function session_checkout_reset(EE_Session $session) |
|
779 | - { |
|
780 | - // don't release tickets if cart was already reset |
|
781 | - if (did_action('AHEE__EE_Session__reset_cart__before_reset')) { |
|
782 | - return; |
|
783 | - } |
|
784 | - $checkout = $session->checkout(); |
|
785 | - if ($checkout instanceof EE_Checkout) { |
|
786 | - EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
787 | - } |
|
788 | - } |
|
789 | - |
|
790 | - |
|
791 | - /** |
|
792 | - * releases reserved tickets for the EE_Checkout->transaction |
|
793 | - * |
|
794 | - * @param EE_Checkout $checkout |
|
795 | - * @return void |
|
796 | - * @throws EE_Error |
|
797 | - * @throws InvalidSessionDataException |
|
798 | - */ |
|
799 | - protected function _session_checkout_reset(EE_Checkout $checkout) |
|
800 | - { |
|
801 | - if (self::debug) { |
|
802 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
803 | - } |
|
804 | - // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
805 | - if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
806 | - return; |
|
807 | - } |
|
808 | - $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
809 | - } |
|
810 | - |
|
811 | - |
|
812 | - |
|
813 | - /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
814 | - |
|
815 | - |
|
816 | - /** |
|
817 | - * @param EE_Session $session |
|
818 | - * @return void |
|
819 | - */ |
|
820 | - public static function session_expired_reset(EE_Session $session) |
|
821 | - { |
|
822 | - } |
|
823 | - |
|
824 | - |
|
825 | - |
|
826 | - /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
827 | - |
|
828 | - |
|
829 | - /** |
|
830 | - * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
831 | - * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
832 | - * |
|
833 | - * @param EE_Transaction $transaction |
|
834 | - * @return void |
|
835 | - * @throws EE_Error |
|
836 | - * @throws InvalidSessionDataException |
|
837 | - */ |
|
838 | - public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
839 | - { |
|
840 | - // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
841 | - if ($transaction->is_free() || $transaction->paid() > 0) { |
|
842 | - if (self::debug) { |
|
843 | - // DEBUG LOG |
|
844 | - EEH_Debug_Tools::log( |
|
845 | - __CLASS__, |
|
846 | - __FUNCTION__, |
|
847 | - __LINE__, |
|
848 | - array($transaction), |
|
849 | - false, |
|
850 | - 'EE_Transaction: ' . $transaction->ID() |
|
851 | - ); |
|
852 | - } |
|
853 | - return; |
|
854 | - } |
|
855 | - // have their been any successful payments made ? |
|
856 | - $payments = $transaction->payments(); |
|
857 | - foreach ($payments as $payment) { |
|
858 | - if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
859 | - if (self::debug) { |
|
860 | - // DEBUG LOG |
|
861 | - EEH_Debug_Tools::log( |
|
862 | - __CLASS__, |
|
863 | - __FUNCTION__, |
|
864 | - __LINE__, |
|
865 | - array($payment), |
|
866 | - false, |
|
867 | - 'EE_Transaction: ' . $transaction->ID() |
|
868 | - ); |
|
869 | - } |
|
870 | - return; |
|
871 | - } |
|
872 | - } |
|
873 | - // since you haven't even attempted to pay for your ticket... |
|
874 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
875 | - } |
|
876 | - |
|
877 | - |
|
878 | - |
|
879 | - /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
880 | - |
|
881 | - |
|
882 | - /** |
|
883 | - * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
884 | - * |
|
885 | - * @param EE_Transaction $transaction |
|
886 | - * @return void |
|
887 | - * @throws EE_Error |
|
888 | - * @throws InvalidSessionDataException |
|
889 | - */ |
|
890 | - public static function process_failed_transactions(EE_Transaction $transaction) |
|
891 | - { |
|
892 | - // since you haven't even attempted to pay for your ticket... |
|
893 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
894 | - } |
|
895 | - |
|
896 | - |
|
897 | - |
|
898 | - /********************************** RESET RESERVATION COUNTS *********************************/ |
|
899 | - |
|
900 | - |
|
901 | - /** |
|
902 | - * Resets the ticket and datetime reserved counts. |
|
903 | - * |
|
904 | - * For all the tickets with reservations, recalculates what their actual reserved counts should be based |
|
905 | - * on the valid transactions. |
|
906 | - * |
|
907 | - * @return int number of tickets whose reservations were released. |
|
908 | - * @throws EE_Error |
|
909 | - * @throws DomainException |
|
910 | - * @throws InvalidDataTypeException |
|
911 | - * @throws InvalidInterfaceException |
|
912 | - * @throws InvalidArgumentException |
|
913 | - * @throws UnexpectedEntityException |
|
914 | - * @throws ReflectionException |
|
915 | - */ |
|
916 | - public static function reset_reservation_counts() |
|
917 | - { |
|
918 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
919 | - $valid_reserved_tickets = array(); |
|
920 | - /** @var EE_Transaction[] $transactions_in_progress */ |
|
921 | - $transactions_in_progress = EEM_Transaction::instance()->get_transactions_in_progress(); |
|
922 | - foreach ($transactions_in_progress as $transaction) { |
|
923 | - // if this TXN has been fully completed, then skip it |
|
924 | - if ($transaction->reg_step_completed('finalize_registration')) { |
|
925 | - continue; |
|
926 | - } |
|
927 | - $total_line_item = $transaction->total_line_item(); |
|
928 | - // $transaction_in_progress->line |
|
929 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
930 | - throw new DomainException( |
|
931 | - esc_html__( |
|
932 | - 'Transaction does not have a valid Total Line Item associated with it.', |
|
933 | - 'event_espresso' |
|
934 | - ) |
|
935 | - ); |
|
936 | - } |
|
937 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
938 | - $total_line_item |
|
939 | - ); |
|
940 | - } |
|
941 | - $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
942 | - foreach ($total_line_items as $total_line_item) { |
|
943 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
944 | - $total_line_item |
|
945 | - ); |
|
946 | - } |
|
947 | - $tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations(); |
|
948 | - return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
949 | - $tickets_with_reservations, |
|
950 | - $valid_reserved_tickets, |
|
951 | - __FUNCTION__ |
|
952 | - ); |
|
953 | - } |
|
954 | - |
|
955 | - |
|
956 | - /** |
|
957 | - * @param EE_Line_Item $total_line_item |
|
958 | - * @return EE_Line_Item[] |
|
959 | - */ |
|
960 | - private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
961 | - { |
|
962 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
963 | - $valid_reserved_tickets = array(); |
|
964 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
965 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
966 | - if ($ticket_line_item instanceof EE_Line_Item) { |
|
967 | - $valid_reserved_tickets[ $ticket_line_item->ID() ] = $ticket_line_item; |
|
968 | - } |
|
969 | - } |
|
970 | - return $valid_reserved_tickets; |
|
971 | - } |
|
972 | - |
|
973 | - |
|
974 | - /** |
|
975 | - * Releases ticket and datetime reservations (ie, reduces the number of reserved spots on them). |
|
976 | - * |
|
977 | - * Given the list of tickets which have reserved spots on them, uses the complete list of line items for tickets |
|
978 | - * whose transactions aren't complete and also aren't yet expired (ie, they're incomplete and younger than the |
|
979 | - * session's expiry time) to update the ticket (and their datetimes') reserved counts. |
|
980 | - * |
|
981 | - * @param EE_Ticket[] $tickets_with_reservations all tickets with TKT_reserved > 0 |
|
982 | - * @param EE_Line_Item[] $valid_reserved_ticket_line_items all line items for tickets and incomplete transactions |
|
983 | - * whose session has NOT expired. We will use these to determine the number of ticket |
|
984 | - * reservations are now invalid. We don't use the list of invalid ticket line items because |
|
985 | - * we don't know which of those have already been taken into account when reducing ticket |
|
986 | - * reservation counts, and which haven't. |
|
987 | - * @return int |
|
988 | - * @throws UnexpectedEntityException |
|
989 | - * @throws DomainException |
|
990 | - * @throws EE_Error |
|
991 | - */ |
|
992 | - protected static function release_reservations_for_tickets( |
|
993 | - array $tickets_with_reservations, |
|
994 | - array $valid_reserved_ticket_line_items = array(), |
|
995 | - $source |
|
996 | - ) { |
|
997 | - $total_tickets_released = 0; |
|
998 | - $sold_out_events = array(); |
|
999 | - foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
1000 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
1001 | - continue; |
|
1002 | - } |
|
1003 | - // The $valid_reserved_ticket_line_items tells us what the reserved count on their tickets (and datetimes) |
|
1004 | - // SHOULD be. Instead of just directly updating the list, we're going to use EE_Ticket::decreaseReserved() |
|
1005 | - // to try to avoid race conditions, so instead of just finding the number to update TO, we're going to find |
|
1006 | - // the number to RELEASE. It's the same end result, just different path. |
|
1007 | - // Begin by assuming we're going to release all the reservations on this ticket. |
|
1008 | - $expired_reservations_count = $ticket_with_reservations->reserved(); |
|
1009 | - // Now reduce that number using the list of current valid reservations. |
|
1010 | - foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
1011 | - if ($valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
1012 | - && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
1013 | - ) { |
|
1014 | - $expired_reservations_count -= $valid_reserved_ticket_line_item->quantity(); |
|
1015 | - } |
|
1016 | - } |
|
1017 | - // Only bother saving the tickets and datetimes if we're actually going to release some spots. |
|
1018 | - if ($expired_reservations_count > 0) { |
|
1019 | - $ticket_with_reservations->add_extra_meta( |
|
1020 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
1021 | - __LINE__ . ') ' . $source . '()' |
|
1022 | - ); |
|
1023 | - $ticket_with_reservations->decreaseReserved($expired_reservations_count, true, 'TicketSalesMonitor:' . __LINE__); |
|
1024 | - $total_tickets_released += $expired_reservations_count; |
|
1025 | - $event = $ticket_with_reservations->get_related_event(); |
|
1026 | - // track sold out events |
|
1027 | - if ($event instanceof EE_Event && $event->is_sold_out()) { |
|
1028 | - $sold_out_events[] = $event; |
|
1029 | - } |
|
1030 | - } |
|
1031 | - } |
|
1032 | - // Double check whether sold out events should remain sold out after releasing tickets |
|
1033 | - if ($sold_out_events !== array()) { |
|
1034 | - foreach ($sold_out_events as $sold_out_event) { |
|
1035 | - /** @var EE_Event $sold_out_event */ |
|
1036 | - $sold_out_event->perform_sold_out_status_check(); |
|
1037 | - } |
|
1038 | - } |
|
1039 | - return $total_tickets_released; |
|
1040 | - } |
|
1041 | - |
|
1042 | - |
|
1043 | - |
|
1044 | - /********************************** SHUTDOWN **********************************/ |
|
1045 | - |
|
1046 | - |
|
1047 | - /** |
|
1048 | - * @param int $timestamp |
|
1049 | - * @return false|int |
|
1050 | - * @throws EE_Error |
|
1051 | - * @throws InvalidArgumentException |
|
1052 | - * @throws InvalidDataTypeException |
|
1053 | - * @throws InvalidInterfaceException |
|
1054 | - */ |
|
1055 | - public static function clear_expired_line_items_with_no_transaction($timestamp = 0) |
|
1056 | - { |
|
1057 | - /** @type WPDB $wpdb */ |
|
1058 | - global $wpdb; |
|
1059 | - if (! absint($timestamp)) { |
|
1060 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
1061 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
1062 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
1063 | - ); |
|
1064 | - $timestamp = $session_lifespan->expiration(); |
|
1065 | - } |
|
1066 | - return $wpdb->query( |
|
1067 | - $wpdb->prepare( |
|
1068 | - 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
23 | + const debug = false; |
|
24 | + |
|
25 | + private static $nl = ''; |
|
26 | + |
|
27 | + /** |
|
28 | + * an array of raw ticket data from EED_Ticket_Selector |
|
29 | + * |
|
30 | + * @var array $ticket_selections |
|
31 | + */ |
|
32 | + protected $ticket_selections = array(); |
|
33 | + |
|
34 | + /** |
|
35 | + * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
36 | + * according to how they are displayed in the actual Ticket_Selector |
|
37 | + * this tracks the current row being processed |
|
38 | + * |
|
39 | + * @var int $current_row |
|
40 | + */ |
|
41 | + protected $current_row = 0; |
|
42 | + |
|
43 | + /** |
|
44 | + * an array for tracking names of tickets that have sold out |
|
45 | + * |
|
46 | + * @var array $sold_out_tickets |
|
47 | + */ |
|
48 | + protected $sold_out_tickets = array(); |
|
49 | + |
|
50 | + /** |
|
51 | + * an array for tracking names of tickets that have had their quantities reduced |
|
52 | + * |
|
53 | + * @var array $decremented_tickets |
|
54 | + */ |
|
55 | + protected $decremented_tickets = array(); |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
60 | + * |
|
61 | + * @return void |
|
62 | + */ |
|
63 | + public static function set_hooks() |
|
64 | + { |
|
65 | + self::$nl = defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
66 | + // release tickets for expired carts |
|
67 | + add_action( |
|
68 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
69 | + array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
70 | + 1 |
|
71 | + ); |
|
72 | + // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
73 | + add_filter( |
|
74 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
75 | + array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
76 | + 20, |
|
77 | + 3 |
|
78 | + ); |
|
79 | + // add notices for sold out tickets |
|
80 | + add_action( |
|
81 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
82 | + array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
83 | + 10 |
|
84 | + ); |
|
85 | + |
|
86 | + // handle tickets deleted from cart |
|
87 | + add_action( |
|
88 | + 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
89 | + array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
90 | + 10, |
|
91 | + 2 |
|
92 | + ); |
|
93 | + // handle emptied carts |
|
94 | + add_action( |
|
95 | + 'AHEE__EE_Session__reset_cart__before_reset', |
|
96 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
97 | + 10, |
|
98 | + 1 |
|
99 | + ); |
|
100 | + add_action( |
|
101 | + 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
102 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
103 | + 10, |
|
104 | + 1 |
|
105 | + ); |
|
106 | + // handle cancelled registrations |
|
107 | + add_action( |
|
108 | + 'AHEE__EE_Session__reset_checkout__before_reset', |
|
109 | + array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
110 | + 10, |
|
111 | + 1 |
|
112 | + ); |
|
113 | + // cron tasks |
|
114 | + add_action( |
|
115 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
116 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
117 | + 10, |
|
118 | + 1 |
|
119 | + ); |
|
120 | + add_action( |
|
121 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
122 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
123 | + 10, |
|
124 | + 1 |
|
125 | + ); |
|
126 | + add_action( |
|
127 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
128 | + array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
129 | + 10, |
|
130 | + 1 |
|
131 | + ); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
137 | + * |
|
138 | + * @return void |
|
139 | + */ |
|
140 | + public static function set_hooks_admin() |
|
141 | + { |
|
142 | + EED_Ticket_Sales_Monitor::set_hooks(); |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * @return EED_Ticket_Sales_Monitor|EED_Module |
|
148 | + */ |
|
149 | + public static function instance() |
|
150 | + { |
|
151 | + return parent::get_instance(__CLASS__); |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * @param WP_Query $WP_Query |
|
157 | + * @return void |
|
158 | + */ |
|
159 | + public function run($WP_Query) |
|
160 | + { |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + |
|
165 | + /********************************** PRE_TICKET_SALES **********************************/ |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * Retrieves grand totals from the line items that have no TXN ID |
|
170 | + * and timestamps less than the current time minus the session lifespan. |
|
171 | + * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
172 | + * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
173 | + * |
|
174 | + * @return void |
|
175 | + * @throws DomainException |
|
176 | + * @throws EE_Error |
|
177 | + * @throws InvalidArgumentException |
|
178 | + * @throws InvalidDataTypeException |
|
179 | + * @throws InvalidInterfaceException |
|
180 | + * @throws UnexpectedEntityException |
|
181 | + */ |
|
182 | + public static function release_tickets_for_expired_carts() |
|
183 | + { |
|
184 | + if (self::debug) { |
|
185 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
186 | + } |
|
187 | + do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
188 | + $expired_ticket_IDs = array(); |
|
189 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
190 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
191 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
192 | + ); |
|
193 | + $timestamp = $session_lifespan->expiration(); |
|
194 | + $expired_ticket_line_items = EEM_Line_Item::instance()->getTicketLineItemsForExpiredCarts($timestamp); |
|
195 | + if (self::debug) { |
|
196 | + echo self::$nl . ' . time(): ' . time(); |
|
197 | + echo self::$nl . ' . time() as date: ' . date('Y-m-d H:i a'); |
|
198 | + echo self::$nl . ' . session expiration: ' . $session_lifespan->expiration(); |
|
199 | + echo self::$nl . ' . session expiration as date: ' . date('Y-m-d H:i a', $session_lifespan->expiration()); |
|
200 | + echo self::$nl . ' . timestamp: ' . $timestamp; |
|
201 | + echo self::$nl . ' . $expired_ticket_line_items: ' . count($expired_ticket_line_items); |
|
202 | + } |
|
203 | + if (! empty($expired_ticket_line_items)) { |
|
204 | + foreach ($expired_ticket_line_items as $expired_ticket_line_item) { |
|
205 | + if (! $expired_ticket_line_item instanceof EE_Line_Item) { |
|
206 | + continue; |
|
207 | + } |
|
208 | + $expired_ticket_IDs[ $expired_ticket_line_item->OBJ_ID() ] = $expired_ticket_line_item->OBJ_ID(); |
|
209 | + if (self::debug) { |
|
210 | + echo self::$nl . ' . $expired_ticket_line_item->OBJ_ID(): ' . $expired_ticket_line_item->OBJ_ID(); |
|
211 | + echo self::$nl . ' . $expired_ticket_line_item->timestamp(): ' |
|
212 | + . date( |
|
213 | + 'Y-m-d h:i a', |
|
214 | + $expired_ticket_line_item->timestamp(true) |
|
215 | + ); |
|
216 | + } |
|
217 | + } |
|
218 | + if (! empty($expired_ticket_IDs)) { |
|
219 | + EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
220 | + \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
221 | + array(), |
|
222 | + __FUNCTION__ |
|
223 | + ); |
|
224 | + // now let's get rid of expired line items so that they can't interfere with tracking |
|
225 | + EED_Ticket_Sales_Monitor::clear_expired_line_items_with_no_transaction($timestamp); |
|
226 | + } |
|
227 | + } |
|
228 | + do_action( |
|
229 | + 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
230 | + $expired_ticket_IDs, |
|
231 | + $expired_ticket_line_items |
|
232 | + ); |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + |
|
237 | + /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
242 | + * |
|
243 | + * @param int $qty |
|
244 | + * @param EE_Ticket $ticket |
|
245 | + * @return bool |
|
246 | + * @throws UnexpectedEntityException |
|
247 | + * @throws EE_Error |
|
248 | + */ |
|
249 | + public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
250 | + { |
|
251 | + $qty = absint($qty); |
|
252 | + if ($qty > 0) { |
|
253 | + $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
254 | + } |
|
255 | + if (self::debug) { |
|
256 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
257 | + echo self::$nl . self::$nl . '<b> RETURNED QTY: ' . $qty . '</b>'; |
|
258 | + } |
|
259 | + return $qty; |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
265 | + * |
|
266 | + * @param EE_Ticket $ticket |
|
267 | + * @param int $qty |
|
268 | + * @return int |
|
269 | + * @throws UnexpectedEntityException |
|
270 | + * @throws EE_Error |
|
271 | + */ |
|
272 | + protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
273 | + { |
|
274 | + if (self::debug) { |
|
275 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
276 | + } |
|
277 | + if (! $ticket instanceof EE_Ticket) { |
|
278 | + return 0; |
|
279 | + } |
|
280 | + if (self::debug) { |
|
281 | + echo self::$nl . '<b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
282 | + echo self::$nl . ' . original ticket->reserved: ' . $ticket->reserved(); |
|
283 | + } |
|
284 | + $ticket->refresh_from_db(); |
|
285 | + // first let's determine the ticket availability based on sales |
|
286 | + $available = $ticket->qty('saleable'); |
|
287 | + if (self::debug) { |
|
288 | + echo self::$nl . ' . . . ticket->qty: ' . $ticket->qty(); |
|
289 | + echo self::$nl . ' . . . ticket->sold: ' . $ticket->sold(); |
|
290 | + echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
291 | + echo self::$nl . ' . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
292 | + echo self::$nl . ' . . . available: ' . $available; |
|
293 | + } |
|
294 | + if ($available < 1) { |
|
295 | + $this->_ticket_sold_out($ticket); |
|
296 | + return 0; |
|
297 | + } |
|
298 | + if (self::debug) { |
|
299 | + echo self::$nl . ' . . . qty: ' . $qty; |
|
300 | + } |
|
301 | + if ($available < $qty) { |
|
302 | + $qty = $available; |
|
303 | + if (self::debug) { |
|
304 | + echo self::$nl . ' . . . QTY ADJUSTED: ' . $qty; |
|
305 | + } |
|
306 | + $this->_ticket_quantity_decremented($ticket); |
|
307 | + } |
|
308 | + if ($this->_reserve_ticket($ticket, $qty)) { |
|
309 | + return $qty; |
|
310 | + } else { |
|
311 | + return 0; |
|
312 | + } |
|
313 | + } |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * increments ticket reserved based on quantity passed |
|
318 | + * |
|
319 | + * @param EE_Ticket $ticket |
|
320 | + * @param int $quantity |
|
321 | + * @return bool indicating success or failure |
|
322 | + * @throws EE_Error |
|
323 | + */ |
|
324 | + protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
325 | + { |
|
326 | + if (self::debug) { |
|
327 | + echo self::$nl . self::$nl . ' . . . INCREASE RESERVED: ' . $quantity; |
|
328 | + } |
|
329 | + return $ticket->increaseReserved($quantity, 'TicketSalesMonitor:' . __LINE__); |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + /** |
|
334 | + * @param EE_Ticket $ticket |
|
335 | + * @param int $quantity |
|
336 | + * @return bool |
|
337 | + * @throws EE_Error |
|
338 | + */ |
|
339 | + protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
340 | + { |
|
341 | + if (self::debug) { |
|
342 | + echo self::$nl . ' . . . ticket->ID: ' . $ticket->ID(); |
|
343 | + echo self::$nl . ' . . . ticket->reserved before: ' . $ticket->reserved(); |
|
344 | + } |
|
345 | + $ticket->decreaseReserved($quantity, true, 'TicketSalesMonitor:' . __LINE__); |
|
346 | + if (self::debug) { |
|
347 | + echo self::$nl . ' . . . ticket->reserved after: ' . $ticket->reserved(); |
|
348 | + } |
|
349 | + return $ticket->save() ? 1 : 0; |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * removes quantities within the ticket selector based on zero ticket availability |
|
355 | + * |
|
356 | + * @param EE_Ticket $ticket |
|
357 | + * @return void |
|
358 | + * @throws UnexpectedEntityException |
|
359 | + * @throws EE_Error |
|
360 | + */ |
|
361 | + protected function _ticket_sold_out(EE_Ticket $ticket) |
|
362 | + { |
|
363 | + if (self::debug) { |
|
364 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
365 | + echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
366 | + } |
|
367 | + $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
368 | + } |
|
369 | + |
|
370 | + |
|
371 | + /** |
|
372 | + * adjusts quantities within the ticket selector based on decreased ticket availability |
|
373 | + * |
|
374 | + * @param EE_Ticket $ticket |
|
375 | + * @return void |
|
376 | + * @throws UnexpectedEntityException |
|
377 | + * @throws EE_Error |
|
378 | + */ |
|
379 | + protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
380 | + { |
|
381 | + if (self::debug) { |
|
382 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
383 | + echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
384 | + } |
|
385 | + $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * builds string out of ticket and event name |
|
391 | + * |
|
392 | + * @param EE_Ticket $ticket |
|
393 | + * @return string |
|
394 | + * @throws UnexpectedEntityException |
|
395 | + * @throws EE_Error |
|
396 | + */ |
|
397 | + protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
398 | + { |
|
399 | + $event = $ticket->get_related_event(); |
|
400 | + if ($event instanceof EE_Event) { |
|
401 | + $ticket_name = sprintf( |
|
402 | + _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
403 | + $ticket->name(), |
|
404 | + $event->name() |
|
405 | + ); |
|
406 | + } else { |
|
407 | + $ticket_name = $ticket->name(); |
|
408 | + } |
|
409 | + return $ticket_name; |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + |
|
414 | + /********************************** EVENT CART **********************************/ |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * releases or reserves ticket(s) based on quantity passed |
|
419 | + * |
|
420 | + * @param EE_Line_Item $line_item |
|
421 | + * @param int $quantity |
|
422 | + * @return void |
|
423 | + * @throws EE_Error |
|
424 | + * @throws InvalidArgumentException |
|
425 | + * @throws InvalidDataTypeException |
|
426 | + * @throws InvalidInterfaceException |
|
427 | + */ |
|
428 | + public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
429 | + { |
|
430 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
431 | + if ($ticket instanceof EE_Ticket) { |
|
432 | + $ticket->add_extra_meta( |
|
433 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
434 | + __LINE__ . ') ' . __METHOD__ . '()' |
|
435 | + ); |
|
436 | + if ($quantity > 0) { |
|
437 | + EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
438 | + } else { |
|
439 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
440 | + } |
|
441 | + } |
|
442 | + } |
|
443 | + |
|
444 | + |
|
445 | + /** |
|
446 | + * releases reserved ticket(s) based on quantity passed |
|
447 | + * |
|
448 | + * @param EE_Ticket $ticket |
|
449 | + * @param int $quantity |
|
450 | + * @return void |
|
451 | + * @throws EE_Error |
|
452 | + */ |
|
453 | + public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
454 | + { |
|
455 | + $ticket->add_extra_meta( |
|
456 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
457 | + __LINE__ . ') ' . __METHOD__ . '()' |
|
458 | + ); |
|
459 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + |
|
464 | + /********************************** POST_NOTICES **********************************/ |
|
465 | + |
|
466 | + |
|
467 | + /** |
|
468 | + * @return void |
|
469 | + * @throws EE_Error |
|
470 | + * @throws InvalidArgumentException |
|
471 | + * @throws ReflectionException |
|
472 | + * @throws InvalidDataTypeException |
|
473 | + * @throws InvalidInterfaceException |
|
474 | + */ |
|
475 | + public static function post_notices() |
|
476 | + { |
|
477 | + EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
478 | + } |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * @return void |
|
483 | + * @throws EE_Error |
|
484 | + * @throws InvalidArgumentException |
|
485 | + * @throws ReflectionException |
|
486 | + * @throws InvalidDataTypeException |
|
487 | + * @throws InvalidInterfaceException |
|
488 | + */ |
|
489 | + protected function _post_notices() |
|
490 | + { |
|
491 | + if (self::debug) { |
|
492 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
493 | + } |
|
494 | + $refresh_msg = ''; |
|
495 | + $none_added_msg = ''; |
|
496 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
497 | + $refresh_msg = __( |
|
498 | + 'Please refresh the page to view updated ticket quantities.', |
|
499 | + 'event_espresso' |
|
500 | + ); |
|
501 | + $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
502 | + } |
|
503 | + if (! empty($this->sold_out_tickets)) { |
|
504 | + EE_Error::add_attention( |
|
505 | + sprintf( |
|
506 | + apply_filters( |
|
507 | + 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
508 | + __( |
|
509 | + 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
510 | + 'event_espresso' |
|
511 | + ) |
|
512 | + ), |
|
513 | + '<br />', |
|
514 | + implode('<br />', $this->sold_out_tickets), |
|
515 | + $none_added_msg, |
|
516 | + $refresh_msg |
|
517 | + ) |
|
518 | + ); |
|
519 | + // alter code flow in the Ticket Selector for better UX |
|
520 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
521 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
522 | + $this->sold_out_tickets = array(); |
|
523 | + // and reset the cart |
|
524 | + EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
525 | + } |
|
526 | + if (! empty($this->decremented_tickets)) { |
|
527 | + EE_Error::add_attention( |
|
528 | + sprintf( |
|
529 | + apply_filters( |
|
530 | + 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
531 | + __( |
|
532 | + 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
533 | + 'event_espresso' |
|
534 | + ) |
|
535 | + ), |
|
536 | + '<br />', |
|
537 | + implode('<br />', $this->decremented_tickets), |
|
538 | + $none_added_msg, |
|
539 | + $refresh_msg |
|
540 | + ) |
|
541 | + ); |
|
542 | + $this->decremented_tickets = array(); |
|
543 | + } |
|
544 | + } |
|
545 | + |
|
546 | + |
|
547 | + |
|
548 | + /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
549 | + |
|
550 | + |
|
551 | + /** |
|
552 | + * releases reserved tickets for all registrations of an EE_Transaction |
|
553 | + * by default, will NOT release tickets for finalized transactions |
|
554 | + * |
|
555 | + * @param EE_Transaction $transaction |
|
556 | + * @return int |
|
557 | + * @throws EE_Error |
|
558 | + * @throws InvalidSessionDataException |
|
559 | + */ |
|
560 | + protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
561 | + { |
|
562 | + if (self::debug) { |
|
563 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
564 | + echo self::$nl . ' . transaction->ID: ' . $transaction->ID(); |
|
565 | + echo self::$nl . ' . TXN status_ID: ' . $transaction->status_ID(); |
|
566 | + } |
|
567 | + // check if 'finalize_registration' step has been completed... |
|
568 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
569 | + if (self::debug) { |
|
570 | + // DEBUG LOG |
|
571 | + EEH_Debug_Tools::log( |
|
572 | + __CLASS__, |
|
573 | + __FUNCTION__, |
|
574 | + __LINE__, |
|
575 | + array('finalized' => $finalized), |
|
576 | + false, |
|
577 | + 'EE_Transaction: ' . $transaction->ID() |
|
578 | + ); |
|
579 | + } |
|
580 | + // how many tickets were released |
|
581 | + $count = 0; |
|
582 | + if (self::debug) { |
|
583 | + echo self::$nl . ' . . . TXN finalized: ' . $finalized; |
|
584 | + } |
|
585 | + $release_tickets_with_TXN_status = array( |
|
586 | + EEM_Transaction::failed_status_code, |
|
587 | + EEM_Transaction::abandoned_status_code, |
|
588 | + EEM_Transaction::incomplete_status_code, |
|
589 | + ); |
|
590 | + $events = array(); |
|
591 | + // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed |
|
592 | + if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
593 | + // cancel any reserved tickets for registrations that were not approved |
|
594 | + $registrations = $transaction->registrations(); |
|
595 | + if (self::debug) { |
|
596 | + echo self::$nl . ' . . . # registrations: ' . count($registrations); |
|
597 | + $reg = reset($registrations); |
|
598 | + $ticket = $reg->ticket(); |
|
599 | + if ($ticket instanceof EE_Ticket) { |
|
600 | + $ticket->add_extra_meta( |
|
601 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
602 | + __LINE__ . ') Release All Tickets TXN:' . $transaction->ID() |
|
603 | + ); |
|
604 | + } |
|
605 | + } |
|
606 | + if (! empty($registrations)) { |
|
607 | + foreach ($registrations as $registration) { |
|
608 | + if ($registration instanceof EE_Registration |
|
609 | + && $this->_release_reserved_ticket_for_registration($registration, $transaction) |
|
610 | + ) { |
|
611 | + $count++; |
|
612 | + $events[ $registration->event_ID() ] = $registration->event(); |
|
613 | + } |
|
614 | + } |
|
615 | + } |
|
616 | + } |
|
617 | + if ($events !== array()) { |
|
618 | + foreach ($events as $event) { |
|
619 | + /** @var EE_Event $event */ |
|
620 | + $event->perform_sold_out_status_check(); |
|
621 | + } |
|
622 | + } |
|
623 | + return $count; |
|
624 | + } |
|
625 | + |
|
626 | + |
|
627 | + /** |
|
628 | + * releases reserved tickets for an EE_Registration |
|
629 | + * by default, will NOT release tickets for APPROVED registrations |
|
630 | + * |
|
631 | + * @param EE_Registration $registration |
|
632 | + * @param EE_Transaction $transaction |
|
633 | + * @return int |
|
634 | + * @throws EE_Error |
|
635 | + */ |
|
636 | + protected function _release_reserved_ticket_for_registration( |
|
637 | + EE_Registration $registration, |
|
638 | + EE_Transaction $transaction |
|
639 | + ) { |
|
640 | + $STS_ID = $transaction->status_ID(); |
|
641 | + if (self::debug) { |
|
642 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
643 | + echo self::$nl . ' . . registration->ID: ' . $registration->ID(); |
|
644 | + echo self::$nl . ' . . registration->status_ID: ' . $registration->status_ID(); |
|
645 | + echo self::$nl . ' . . transaction->status_ID(): ' . $STS_ID; |
|
646 | + } |
|
647 | + if (// release Tickets for Failed Transactions and Abandoned Transactions |
|
648 | + $STS_ID === EEM_Transaction::failed_status_code |
|
649 | + || $STS_ID === EEM_Transaction::abandoned_status_code |
|
650 | + || ( |
|
651 | + // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
652 | + $STS_ID === EEM_Transaction::incomplete_status_code |
|
653 | + && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
654 | + ) |
|
655 | + ) { |
|
656 | + if (self::debug) { |
|
657 | + echo self::$nl . self::$nl . ' . . RELEASE RESERVED TICKET'; |
|
658 | + $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true); |
|
659 | + echo self::$nl . ' . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
660 | + var_dump($rsrvd); |
|
661 | + } |
|
662 | + $registration->release_reserved_ticket(true, 'TicketSalesMonitor:' . __LINE__); |
|
663 | + return 1; |
|
664 | + } |
|
665 | + return 0; |
|
666 | + } |
|
667 | + |
|
668 | + |
|
669 | + |
|
670 | + /********************************** SESSION_CART_RESET **********************************/ |
|
671 | + |
|
672 | + |
|
673 | + /** |
|
674 | + * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
675 | + * |
|
676 | + * @param EE_Session $session |
|
677 | + * @return void |
|
678 | + * @throws EE_Error |
|
679 | + * @throws InvalidArgumentException |
|
680 | + * @throws ReflectionException |
|
681 | + * @throws InvalidDataTypeException |
|
682 | + * @throws InvalidInterfaceException |
|
683 | + */ |
|
684 | + public static function session_cart_reset(EE_Session $session) |
|
685 | + { |
|
686 | + // don't release tickets if checkout was already reset |
|
687 | + if (did_action('AHEE__EE_Session__reset_checkout__before_reset')) { |
|
688 | + return; |
|
689 | + } |
|
690 | + if (self::debug) { |
|
691 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
692 | + } |
|
693 | + // first check of the session has a valid Checkout object |
|
694 | + $checkout = $session->checkout(); |
|
695 | + if ($checkout instanceof EE_Checkout) { |
|
696 | + // and use that to clear ticket reservations because it will update the associated registration meta data |
|
697 | + EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
698 | + return; |
|
699 | + } |
|
700 | + $cart = $session->cart(); |
|
701 | + if ($cart instanceof EE_Cart) { |
|
702 | + if (self::debug) { |
|
703 | + echo self::$nl . self::$nl . ' cart instance of EE_Cart: '; |
|
704 | + } |
|
705 | + EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session); |
|
706 | + } else { |
|
707 | + if (self::debug) { |
|
708 | + echo self::$nl . self::$nl . ' invalid EE_Cart: '; |
|
709 | + var_export($cart, true); |
|
710 | + } |
|
711 | + } |
|
712 | + } |
|
713 | + |
|
714 | + |
|
715 | + /** |
|
716 | + * releases reserved tickets in the EE_Cart |
|
717 | + * |
|
718 | + * @param EE_Cart $cart |
|
719 | + * @return void |
|
720 | + * @throws EE_Error |
|
721 | + * @throws InvalidArgumentException |
|
722 | + * @throws ReflectionException |
|
723 | + * @throws InvalidDataTypeException |
|
724 | + * @throws InvalidInterfaceException |
|
725 | + */ |
|
726 | + protected function _session_cart_reset(EE_Cart $cart, EE_Session $session) |
|
727 | + { |
|
728 | + if (self::debug) { |
|
729 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
730 | + } |
|
731 | + $ticket_line_items = $cart->get_tickets(); |
|
732 | + if (empty($ticket_line_items)) { |
|
733 | + return; |
|
734 | + } |
|
735 | + if (self::debug) { |
|
736 | + echo '<br /> . ticket_line_item count: ' . count($ticket_line_items); |
|
737 | + } |
|
738 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
739 | + if (self::debug) { |
|
740 | + echo self::$nl . ' . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
741 | + } |
|
742 | + if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
743 | + if (self::debug) { |
|
744 | + echo self::$nl . ' . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
745 | + } |
|
746 | + $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
747 | + if ($ticket instanceof EE_Ticket) { |
|
748 | + if (self::debug) { |
|
749 | + echo self::$nl . ' . . ticket->ID(): ' . $ticket->ID(); |
|
750 | + echo self::$nl . ' . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
751 | + } |
|
752 | + $ticket->add_extra_meta( |
|
753 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
754 | + __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id() |
|
755 | + ); |
|
756 | + $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
757 | + } |
|
758 | + } |
|
759 | + } |
|
760 | + if (self::debug) { |
|
761 | + echo self::$nl . self::$nl . ' RESET COMPLETED '; |
|
762 | + } |
|
763 | + } |
|
764 | + |
|
765 | + |
|
766 | + |
|
767 | + /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
768 | + |
|
769 | + |
|
770 | + /** |
|
771 | + * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
772 | + * |
|
773 | + * @param EE_Session $session |
|
774 | + * @return void |
|
775 | + * @throws EE_Error |
|
776 | + * @throws InvalidSessionDataException |
|
777 | + */ |
|
778 | + public static function session_checkout_reset(EE_Session $session) |
|
779 | + { |
|
780 | + // don't release tickets if cart was already reset |
|
781 | + if (did_action('AHEE__EE_Session__reset_cart__before_reset')) { |
|
782 | + return; |
|
783 | + } |
|
784 | + $checkout = $session->checkout(); |
|
785 | + if ($checkout instanceof EE_Checkout) { |
|
786 | + EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
787 | + } |
|
788 | + } |
|
789 | + |
|
790 | + |
|
791 | + /** |
|
792 | + * releases reserved tickets for the EE_Checkout->transaction |
|
793 | + * |
|
794 | + * @param EE_Checkout $checkout |
|
795 | + * @return void |
|
796 | + * @throws EE_Error |
|
797 | + * @throws InvalidSessionDataException |
|
798 | + */ |
|
799 | + protected function _session_checkout_reset(EE_Checkout $checkout) |
|
800 | + { |
|
801 | + if (self::debug) { |
|
802 | + echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
803 | + } |
|
804 | + // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
805 | + if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
806 | + return; |
|
807 | + } |
|
808 | + $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
809 | + } |
|
810 | + |
|
811 | + |
|
812 | + |
|
813 | + /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
814 | + |
|
815 | + |
|
816 | + /** |
|
817 | + * @param EE_Session $session |
|
818 | + * @return void |
|
819 | + */ |
|
820 | + public static function session_expired_reset(EE_Session $session) |
|
821 | + { |
|
822 | + } |
|
823 | + |
|
824 | + |
|
825 | + |
|
826 | + /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
827 | + |
|
828 | + |
|
829 | + /** |
|
830 | + * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
831 | + * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
832 | + * |
|
833 | + * @param EE_Transaction $transaction |
|
834 | + * @return void |
|
835 | + * @throws EE_Error |
|
836 | + * @throws InvalidSessionDataException |
|
837 | + */ |
|
838 | + public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
839 | + { |
|
840 | + // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
841 | + if ($transaction->is_free() || $transaction->paid() > 0) { |
|
842 | + if (self::debug) { |
|
843 | + // DEBUG LOG |
|
844 | + EEH_Debug_Tools::log( |
|
845 | + __CLASS__, |
|
846 | + __FUNCTION__, |
|
847 | + __LINE__, |
|
848 | + array($transaction), |
|
849 | + false, |
|
850 | + 'EE_Transaction: ' . $transaction->ID() |
|
851 | + ); |
|
852 | + } |
|
853 | + return; |
|
854 | + } |
|
855 | + // have their been any successful payments made ? |
|
856 | + $payments = $transaction->payments(); |
|
857 | + foreach ($payments as $payment) { |
|
858 | + if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
859 | + if (self::debug) { |
|
860 | + // DEBUG LOG |
|
861 | + EEH_Debug_Tools::log( |
|
862 | + __CLASS__, |
|
863 | + __FUNCTION__, |
|
864 | + __LINE__, |
|
865 | + array($payment), |
|
866 | + false, |
|
867 | + 'EE_Transaction: ' . $transaction->ID() |
|
868 | + ); |
|
869 | + } |
|
870 | + return; |
|
871 | + } |
|
872 | + } |
|
873 | + // since you haven't even attempted to pay for your ticket... |
|
874 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
875 | + } |
|
876 | + |
|
877 | + |
|
878 | + |
|
879 | + /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
880 | + |
|
881 | + |
|
882 | + /** |
|
883 | + * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
884 | + * |
|
885 | + * @param EE_Transaction $transaction |
|
886 | + * @return void |
|
887 | + * @throws EE_Error |
|
888 | + * @throws InvalidSessionDataException |
|
889 | + */ |
|
890 | + public static function process_failed_transactions(EE_Transaction $transaction) |
|
891 | + { |
|
892 | + // since you haven't even attempted to pay for your ticket... |
|
893 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
894 | + } |
|
895 | + |
|
896 | + |
|
897 | + |
|
898 | + /********************************** RESET RESERVATION COUNTS *********************************/ |
|
899 | + |
|
900 | + |
|
901 | + /** |
|
902 | + * Resets the ticket and datetime reserved counts. |
|
903 | + * |
|
904 | + * For all the tickets with reservations, recalculates what their actual reserved counts should be based |
|
905 | + * on the valid transactions. |
|
906 | + * |
|
907 | + * @return int number of tickets whose reservations were released. |
|
908 | + * @throws EE_Error |
|
909 | + * @throws DomainException |
|
910 | + * @throws InvalidDataTypeException |
|
911 | + * @throws InvalidInterfaceException |
|
912 | + * @throws InvalidArgumentException |
|
913 | + * @throws UnexpectedEntityException |
|
914 | + * @throws ReflectionException |
|
915 | + */ |
|
916 | + public static function reset_reservation_counts() |
|
917 | + { |
|
918 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
919 | + $valid_reserved_tickets = array(); |
|
920 | + /** @var EE_Transaction[] $transactions_in_progress */ |
|
921 | + $transactions_in_progress = EEM_Transaction::instance()->get_transactions_in_progress(); |
|
922 | + foreach ($transactions_in_progress as $transaction) { |
|
923 | + // if this TXN has been fully completed, then skip it |
|
924 | + if ($transaction->reg_step_completed('finalize_registration')) { |
|
925 | + continue; |
|
926 | + } |
|
927 | + $total_line_item = $transaction->total_line_item(); |
|
928 | + // $transaction_in_progress->line |
|
929 | + if (! $total_line_item instanceof EE_Line_Item) { |
|
930 | + throw new DomainException( |
|
931 | + esc_html__( |
|
932 | + 'Transaction does not have a valid Total Line Item associated with it.', |
|
933 | + 'event_espresso' |
|
934 | + ) |
|
935 | + ); |
|
936 | + } |
|
937 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
938 | + $total_line_item |
|
939 | + ); |
|
940 | + } |
|
941 | + $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
942 | + foreach ($total_line_items as $total_line_item) { |
|
943 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
944 | + $total_line_item |
|
945 | + ); |
|
946 | + } |
|
947 | + $tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations(); |
|
948 | + return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
949 | + $tickets_with_reservations, |
|
950 | + $valid_reserved_tickets, |
|
951 | + __FUNCTION__ |
|
952 | + ); |
|
953 | + } |
|
954 | + |
|
955 | + |
|
956 | + /** |
|
957 | + * @param EE_Line_Item $total_line_item |
|
958 | + * @return EE_Line_Item[] |
|
959 | + */ |
|
960 | + private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
961 | + { |
|
962 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
963 | + $valid_reserved_tickets = array(); |
|
964 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
965 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
966 | + if ($ticket_line_item instanceof EE_Line_Item) { |
|
967 | + $valid_reserved_tickets[ $ticket_line_item->ID() ] = $ticket_line_item; |
|
968 | + } |
|
969 | + } |
|
970 | + return $valid_reserved_tickets; |
|
971 | + } |
|
972 | + |
|
973 | + |
|
974 | + /** |
|
975 | + * Releases ticket and datetime reservations (ie, reduces the number of reserved spots on them). |
|
976 | + * |
|
977 | + * Given the list of tickets which have reserved spots on them, uses the complete list of line items for tickets |
|
978 | + * whose transactions aren't complete and also aren't yet expired (ie, they're incomplete and younger than the |
|
979 | + * session's expiry time) to update the ticket (and their datetimes') reserved counts. |
|
980 | + * |
|
981 | + * @param EE_Ticket[] $tickets_with_reservations all tickets with TKT_reserved > 0 |
|
982 | + * @param EE_Line_Item[] $valid_reserved_ticket_line_items all line items for tickets and incomplete transactions |
|
983 | + * whose session has NOT expired. We will use these to determine the number of ticket |
|
984 | + * reservations are now invalid. We don't use the list of invalid ticket line items because |
|
985 | + * we don't know which of those have already been taken into account when reducing ticket |
|
986 | + * reservation counts, and which haven't. |
|
987 | + * @return int |
|
988 | + * @throws UnexpectedEntityException |
|
989 | + * @throws DomainException |
|
990 | + * @throws EE_Error |
|
991 | + */ |
|
992 | + protected static function release_reservations_for_tickets( |
|
993 | + array $tickets_with_reservations, |
|
994 | + array $valid_reserved_ticket_line_items = array(), |
|
995 | + $source |
|
996 | + ) { |
|
997 | + $total_tickets_released = 0; |
|
998 | + $sold_out_events = array(); |
|
999 | + foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
1000 | + if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
1001 | + continue; |
|
1002 | + } |
|
1003 | + // The $valid_reserved_ticket_line_items tells us what the reserved count on their tickets (and datetimes) |
|
1004 | + // SHOULD be. Instead of just directly updating the list, we're going to use EE_Ticket::decreaseReserved() |
|
1005 | + // to try to avoid race conditions, so instead of just finding the number to update TO, we're going to find |
|
1006 | + // the number to RELEASE. It's the same end result, just different path. |
|
1007 | + // Begin by assuming we're going to release all the reservations on this ticket. |
|
1008 | + $expired_reservations_count = $ticket_with_reservations->reserved(); |
|
1009 | + // Now reduce that number using the list of current valid reservations. |
|
1010 | + foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
1011 | + if ($valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
1012 | + && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
1013 | + ) { |
|
1014 | + $expired_reservations_count -= $valid_reserved_ticket_line_item->quantity(); |
|
1015 | + } |
|
1016 | + } |
|
1017 | + // Only bother saving the tickets and datetimes if we're actually going to release some spots. |
|
1018 | + if ($expired_reservations_count > 0) { |
|
1019 | + $ticket_with_reservations->add_extra_meta( |
|
1020 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
1021 | + __LINE__ . ') ' . $source . '()' |
|
1022 | + ); |
|
1023 | + $ticket_with_reservations->decreaseReserved($expired_reservations_count, true, 'TicketSalesMonitor:' . __LINE__); |
|
1024 | + $total_tickets_released += $expired_reservations_count; |
|
1025 | + $event = $ticket_with_reservations->get_related_event(); |
|
1026 | + // track sold out events |
|
1027 | + if ($event instanceof EE_Event && $event->is_sold_out()) { |
|
1028 | + $sold_out_events[] = $event; |
|
1029 | + } |
|
1030 | + } |
|
1031 | + } |
|
1032 | + // Double check whether sold out events should remain sold out after releasing tickets |
|
1033 | + if ($sold_out_events !== array()) { |
|
1034 | + foreach ($sold_out_events as $sold_out_event) { |
|
1035 | + /** @var EE_Event $sold_out_event */ |
|
1036 | + $sold_out_event->perform_sold_out_status_check(); |
|
1037 | + } |
|
1038 | + } |
|
1039 | + return $total_tickets_released; |
|
1040 | + } |
|
1041 | + |
|
1042 | + |
|
1043 | + |
|
1044 | + /********************************** SHUTDOWN **********************************/ |
|
1045 | + |
|
1046 | + |
|
1047 | + /** |
|
1048 | + * @param int $timestamp |
|
1049 | + * @return false|int |
|
1050 | + * @throws EE_Error |
|
1051 | + * @throws InvalidArgumentException |
|
1052 | + * @throws InvalidDataTypeException |
|
1053 | + * @throws InvalidInterfaceException |
|
1054 | + */ |
|
1055 | + public static function clear_expired_line_items_with_no_transaction($timestamp = 0) |
|
1056 | + { |
|
1057 | + /** @type WPDB $wpdb */ |
|
1058 | + global $wpdb; |
|
1059 | + if (! absint($timestamp)) { |
|
1060 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
1061 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
1062 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
1063 | + ); |
|
1064 | + $timestamp = $session_lifespan->expiration(); |
|
1065 | + } |
|
1066 | + return $wpdb->query( |
|
1067 | + $wpdb->prepare( |
|
1068 | + 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
1069 | 1069 | WHERE TXN_ID = 0 AND LIN_timestamp <= %s', |
1070 | - // use GMT time because that's what LIN_timestamps are in |
|
1071 | - date('Y-m-d H:i:s', $timestamp) |
|
1072 | - ) |
|
1073 | - ); |
|
1074 | - } |
|
1070 | + // use GMT time because that's what LIN_timestamps are in |
|
1071 | + date('Y-m-d H:i:s', $timestamp) |
|
1072 | + ) |
|
1073 | + ); |
|
1074 | + } |
|
1075 | 1075 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | public static function release_tickets_for_expired_carts() |
183 | 183 | { |
184 | 184 | if (self::debug) { |
185 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
185 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'()'; |
|
186 | 186 | } |
187 | 187 | do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
188 | 188 | $expired_ticket_IDs = array(); |
@@ -193,29 +193,29 @@ discard block |
||
193 | 193 | $timestamp = $session_lifespan->expiration(); |
194 | 194 | $expired_ticket_line_items = EEM_Line_Item::instance()->getTicketLineItemsForExpiredCarts($timestamp); |
195 | 195 | if (self::debug) { |
196 | - echo self::$nl . ' . time(): ' . time(); |
|
197 | - echo self::$nl . ' . time() as date: ' . date('Y-m-d H:i a'); |
|
198 | - echo self::$nl . ' . session expiration: ' . $session_lifespan->expiration(); |
|
199 | - echo self::$nl . ' . session expiration as date: ' . date('Y-m-d H:i a', $session_lifespan->expiration()); |
|
200 | - echo self::$nl . ' . timestamp: ' . $timestamp; |
|
201 | - echo self::$nl . ' . $expired_ticket_line_items: ' . count($expired_ticket_line_items); |
|
196 | + echo self::$nl.' . time(): '.time(); |
|
197 | + echo self::$nl.' . time() as date: '.date('Y-m-d H:i a'); |
|
198 | + echo self::$nl.' . session expiration: '.$session_lifespan->expiration(); |
|
199 | + echo self::$nl.' . session expiration as date: '.date('Y-m-d H:i a', $session_lifespan->expiration()); |
|
200 | + echo self::$nl.' . timestamp: '.$timestamp; |
|
201 | + echo self::$nl.' . $expired_ticket_line_items: '.count($expired_ticket_line_items); |
|
202 | 202 | } |
203 | - if (! empty($expired_ticket_line_items)) { |
|
203 | + if ( ! empty($expired_ticket_line_items)) { |
|
204 | 204 | foreach ($expired_ticket_line_items as $expired_ticket_line_item) { |
205 | - if (! $expired_ticket_line_item instanceof EE_Line_Item) { |
|
205 | + if ( ! $expired_ticket_line_item instanceof EE_Line_Item) { |
|
206 | 206 | continue; |
207 | 207 | } |
208 | - $expired_ticket_IDs[ $expired_ticket_line_item->OBJ_ID() ] = $expired_ticket_line_item->OBJ_ID(); |
|
208 | + $expired_ticket_IDs[$expired_ticket_line_item->OBJ_ID()] = $expired_ticket_line_item->OBJ_ID(); |
|
209 | 209 | if (self::debug) { |
210 | - echo self::$nl . ' . $expired_ticket_line_item->OBJ_ID(): ' . $expired_ticket_line_item->OBJ_ID(); |
|
211 | - echo self::$nl . ' . $expired_ticket_line_item->timestamp(): ' |
|
210 | + echo self::$nl.' . $expired_ticket_line_item->OBJ_ID(): '.$expired_ticket_line_item->OBJ_ID(); |
|
211 | + echo self::$nl.' . $expired_ticket_line_item->timestamp(): ' |
|
212 | 212 | . date( |
213 | 213 | 'Y-m-d h:i a', |
214 | 214 | $expired_ticket_line_item->timestamp(true) |
215 | 215 | ); |
216 | 216 | } |
217 | 217 | } |
218 | - if (! empty($expired_ticket_IDs)) { |
|
218 | + if ( ! empty($expired_ticket_IDs)) { |
|
219 | 219 | EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
220 | 220 | \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
221 | 221 | array(), |
@@ -253,8 +253,8 @@ discard block |
||
253 | 253 | $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
254 | 254 | } |
255 | 255 | if (self::debug) { |
256 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '()'; |
|
257 | - echo self::$nl . self::$nl . '<b> RETURNED QTY: ' . $qty . '</b>'; |
|
256 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'()'; |
|
257 | + echo self::$nl.self::$nl.'<b> RETURNED QTY: '.$qty.'</b>'; |
|
258 | 258 | } |
259 | 259 | return $qty; |
260 | 260 | } |
@@ -272,36 +272,36 @@ discard block |
||
272 | 272 | protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
273 | 273 | { |
274 | 274 | if (self::debug) { |
275 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
275 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
276 | 276 | } |
277 | - if (! $ticket instanceof EE_Ticket) { |
|
277 | + if ( ! $ticket instanceof EE_Ticket) { |
|
278 | 278 | return 0; |
279 | 279 | } |
280 | 280 | if (self::debug) { |
281 | - echo self::$nl . '<b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
282 | - echo self::$nl . ' . original ticket->reserved: ' . $ticket->reserved(); |
|
281 | + echo self::$nl.'<b> . ticket->ID: '.$ticket->ID().'</b>'; |
|
282 | + echo self::$nl.' . original ticket->reserved: '.$ticket->reserved(); |
|
283 | 283 | } |
284 | 284 | $ticket->refresh_from_db(); |
285 | 285 | // first let's determine the ticket availability based on sales |
286 | 286 | $available = $ticket->qty('saleable'); |
287 | 287 | if (self::debug) { |
288 | - echo self::$nl . ' . . . ticket->qty: ' . $ticket->qty(); |
|
289 | - echo self::$nl . ' . . . ticket->sold: ' . $ticket->sold(); |
|
290 | - echo self::$nl . ' . . . ticket->reserved: ' . $ticket->reserved(); |
|
291 | - echo self::$nl . ' . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
292 | - echo self::$nl . ' . . . available: ' . $available; |
|
288 | + echo self::$nl.' . . . ticket->qty: '.$ticket->qty(); |
|
289 | + echo self::$nl.' . . . ticket->sold: '.$ticket->sold(); |
|
290 | + echo self::$nl.' . . . ticket->reserved: '.$ticket->reserved(); |
|
291 | + echo self::$nl.' . . . ticket->qty(saleable): '.$ticket->qty('saleable'); |
|
292 | + echo self::$nl.' . . . available: '.$available; |
|
293 | 293 | } |
294 | 294 | if ($available < 1) { |
295 | 295 | $this->_ticket_sold_out($ticket); |
296 | 296 | return 0; |
297 | 297 | } |
298 | 298 | if (self::debug) { |
299 | - echo self::$nl . ' . . . qty: ' . $qty; |
|
299 | + echo self::$nl.' . . . qty: '.$qty; |
|
300 | 300 | } |
301 | 301 | if ($available < $qty) { |
302 | 302 | $qty = $available; |
303 | 303 | if (self::debug) { |
304 | - echo self::$nl . ' . . . QTY ADJUSTED: ' . $qty; |
|
304 | + echo self::$nl.' . . . QTY ADJUSTED: '.$qty; |
|
305 | 305 | } |
306 | 306 | $this->_ticket_quantity_decremented($ticket); |
307 | 307 | } |
@@ -324,9 +324,9 @@ discard block |
||
324 | 324 | protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
325 | 325 | { |
326 | 326 | if (self::debug) { |
327 | - echo self::$nl . self::$nl . ' . . . INCREASE RESERVED: ' . $quantity; |
|
327 | + echo self::$nl.self::$nl.' . . . INCREASE RESERVED: '.$quantity; |
|
328 | 328 | } |
329 | - return $ticket->increaseReserved($quantity, 'TicketSalesMonitor:' . __LINE__); |
|
329 | + return $ticket->increaseReserved($quantity, 'TicketSalesMonitor:'.__LINE__); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | |
@@ -339,12 +339,12 @@ discard block |
||
339 | 339 | protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
340 | 340 | { |
341 | 341 | if (self::debug) { |
342 | - echo self::$nl . ' . . . ticket->ID: ' . $ticket->ID(); |
|
343 | - echo self::$nl . ' . . . ticket->reserved before: ' . $ticket->reserved(); |
|
342 | + echo self::$nl.' . . . ticket->ID: '.$ticket->ID(); |
|
343 | + echo self::$nl.' . . . ticket->reserved before: '.$ticket->reserved(); |
|
344 | 344 | } |
345 | - $ticket->decreaseReserved($quantity, true, 'TicketSalesMonitor:' . __LINE__); |
|
345 | + $ticket->decreaseReserved($quantity, true, 'TicketSalesMonitor:'.__LINE__); |
|
346 | 346 | if (self::debug) { |
347 | - echo self::$nl . ' . . . ticket->reserved after: ' . $ticket->reserved(); |
|
347 | + echo self::$nl.' . . . ticket->reserved after: '.$ticket->reserved(); |
|
348 | 348 | } |
349 | 349 | return $ticket->save() ? 1 : 0; |
350 | 350 | } |
@@ -361,8 +361,8 @@ discard block |
||
361 | 361 | protected function _ticket_sold_out(EE_Ticket $ticket) |
362 | 362 | { |
363 | 363 | if (self::debug) { |
364 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
365 | - echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
364 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
365 | + echo self::$nl.' . . ticket->name: '.$this->_get_ticket_and_event_name($ticket); |
|
366 | 366 | } |
367 | 367 | $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
368 | 368 | } |
@@ -379,8 +379,8 @@ discard block |
||
379 | 379 | protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
380 | 380 | { |
381 | 381 | if (self::debug) { |
382 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
383 | - echo self::$nl . ' . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
382 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
383 | + echo self::$nl.' . . ticket->name: '.$this->_get_ticket_and_event_name($ticket); |
|
384 | 384 | } |
385 | 385 | $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
386 | 386 | } |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | if ($ticket instanceof EE_Ticket) { |
432 | 432 | $ticket->add_extra_meta( |
433 | 433 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
434 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
434 | + __LINE__.') '.__METHOD__.'()' |
|
435 | 435 | ); |
436 | 436 | if ($quantity > 0) { |
437 | 437 | EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | { |
455 | 455 | $ticket->add_extra_meta( |
456 | 456 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
457 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
457 | + __LINE__.') '.__METHOD__.'()' |
|
458 | 458 | ); |
459 | 459 | EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
460 | 460 | } |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | protected function _post_notices() |
490 | 490 | { |
491 | 491 | if (self::debug) { |
492 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
492 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
493 | 493 | } |
494 | 494 | $refresh_msg = ''; |
495 | 495 | $none_added_msg = ''; |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | ); |
501 | 501 | $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
502 | 502 | } |
503 | - if (! empty($this->sold_out_tickets)) { |
|
503 | + if ( ! empty($this->sold_out_tickets)) { |
|
504 | 504 | EE_Error::add_attention( |
505 | 505 | sprintf( |
506 | 506 | apply_filters( |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | // and reset the cart |
524 | 524 | EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
525 | 525 | } |
526 | - if (! empty($this->decremented_tickets)) { |
|
526 | + if ( ! empty($this->decremented_tickets)) { |
|
527 | 527 | EE_Error::add_attention( |
528 | 528 | sprintf( |
529 | 529 | apply_filters( |
@@ -560,9 +560,9 @@ discard block |
||
560 | 560 | protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
561 | 561 | { |
562 | 562 | if (self::debug) { |
563 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
564 | - echo self::$nl . ' . transaction->ID: ' . $transaction->ID(); |
|
565 | - echo self::$nl . ' . TXN status_ID: ' . $transaction->status_ID(); |
|
563 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
564 | + echo self::$nl.' . transaction->ID: '.$transaction->ID(); |
|
565 | + echo self::$nl.' . TXN status_ID: '.$transaction->status_ID(); |
|
566 | 566 | } |
567 | 567 | // check if 'finalize_registration' step has been completed... |
568 | 568 | $finalized = $transaction->reg_step_completed('finalize_registration'); |
@@ -574,13 +574,13 @@ discard block |
||
574 | 574 | __LINE__, |
575 | 575 | array('finalized' => $finalized), |
576 | 576 | false, |
577 | - 'EE_Transaction: ' . $transaction->ID() |
|
577 | + 'EE_Transaction: '.$transaction->ID() |
|
578 | 578 | ); |
579 | 579 | } |
580 | 580 | // how many tickets were released |
581 | 581 | $count = 0; |
582 | 582 | if (self::debug) { |
583 | - echo self::$nl . ' . . . TXN finalized: ' . $finalized; |
|
583 | + echo self::$nl.' . . . TXN finalized: '.$finalized; |
|
584 | 584 | } |
585 | 585 | $release_tickets_with_TXN_status = array( |
586 | 586 | EEM_Transaction::failed_status_code, |
@@ -589,27 +589,27 @@ discard block |
||
589 | 589 | ); |
590 | 590 | $events = array(); |
591 | 591 | // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed |
592 | - if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
592 | + if ( ! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
593 | 593 | // cancel any reserved tickets for registrations that were not approved |
594 | 594 | $registrations = $transaction->registrations(); |
595 | 595 | if (self::debug) { |
596 | - echo self::$nl . ' . . . # registrations: ' . count($registrations); |
|
596 | + echo self::$nl.' . . . # registrations: '.count($registrations); |
|
597 | 597 | $reg = reset($registrations); |
598 | 598 | $ticket = $reg->ticket(); |
599 | 599 | if ($ticket instanceof EE_Ticket) { |
600 | 600 | $ticket->add_extra_meta( |
601 | 601 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
602 | - __LINE__ . ') Release All Tickets TXN:' . $transaction->ID() |
|
602 | + __LINE__.') Release All Tickets TXN:'.$transaction->ID() |
|
603 | 603 | ); |
604 | 604 | } |
605 | 605 | } |
606 | - if (! empty($registrations)) { |
|
606 | + if ( ! empty($registrations)) { |
|
607 | 607 | foreach ($registrations as $registration) { |
608 | 608 | if ($registration instanceof EE_Registration |
609 | 609 | && $this->_release_reserved_ticket_for_registration($registration, $transaction) |
610 | 610 | ) { |
611 | 611 | $count++; |
612 | - $events[ $registration->event_ID() ] = $registration->event(); |
|
612 | + $events[$registration->event_ID()] = $registration->event(); |
|
613 | 613 | } |
614 | 614 | } |
615 | 615 | } |
@@ -639,10 +639,10 @@ discard block |
||
639 | 639 | ) { |
640 | 640 | $STS_ID = $transaction->status_ID(); |
641 | 641 | if (self::debug) { |
642 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
643 | - echo self::$nl . ' . . registration->ID: ' . $registration->ID(); |
|
644 | - echo self::$nl . ' . . registration->status_ID: ' . $registration->status_ID(); |
|
645 | - echo self::$nl . ' . . transaction->status_ID(): ' . $STS_ID; |
|
642 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
643 | + echo self::$nl.' . . registration->ID: '.$registration->ID(); |
|
644 | + echo self::$nl.' . . registration->status_ID: '.$registration->status_ID(); |
|
645 | + echo self::$nl.' . . transaction->status_ID(): '.$STS_ID; |
|
646 | 646 | } |
647 | 647 | if (// release Tickets for Failed Transactions and Abandoned Transactions |
648 | 648 | $STS_ID === EEM_Transaction::failed_status_code |
@@ -654,12 +654,12 @@ discard block |
||
654 | 654 | ) |
655 | 655 | ) { |
656 | 656 | if (self::debug) { |
657 | - echo self::$nl . self::$nl . ' . . RELEASE RESERVED TICKET'; |
|
657 | + echo self::$nl.self::$nl.' . . RELEASE RESERVED TICKET'; |
|
658 | 658 | $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true); |
659 | - echo self::$nl . ' . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
659 | + echo self::$nl.' . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
660 | 660 | var_dump($rsrvd); |
661 | 661 | } |
662 | - $registration->release_reserved_ticket(true, 'TicketSalesMonitor:' . __LINE__); |
|
662 | + $registration->release_reserved_ticket(true, 'TicketSalesMonitor:'.__LINE__); |
|
663 | 663 | return 1; |
664 | 664 | } |
665 | 665 | return 0; |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | return; |
689 | 689 | } |
690 | 690 | if (self::debug) { |
691 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
691 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
692 | 692 | } |
693 | 693 | // first check of the session has a valid Checkout object |
694 | 694 | $checkout = $session->checkout(); |
@@ -700,12 +700,12 @@ discard block |
||
700 | 700 | $cart = $session->cart(); |
701 | 701 | if ($cart instanceof EE_Cart) { |
702 | 702 | if (self::debug) { |
703 | - echo self::$nl . self::$nl . ' cart instance of EE_Cart: '; |
|
703 | + echo self::$nl.self::$nl.' cart instance of EE_Cart: '; |
|
704 | 704 | } |
705 | 705 | EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session); |
706 | 706 | } else { |
707 | 707 | if (self::debug) { |
708 | - echo self::$nl . self::$nl . ' invalid EE_Cart: '; |
|
708 | + echo self::$nl.self::$nl.' invalid EE_Cart: '; |
|
709 | 709 | var_export($cart, true); |
710 | 710 | } |
711 | 711 | } |
@@ -726,39 +726,39 @@ discard block |
||
726 | 726 | protected function _session_cart_reset(EE_Cart $cart, EE_Session $session) |
727 | 727 | { |
728 | 728 | if (self::debug) { |
729 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
729 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
730 | 730 | } |
731 | 731 | $ticket_line_items = $cart->get_tickets(); |
732 | 732 | if (empty($ticket_line_items)) { |
733 | 733 | return; |
734 | 734 | } |
735 | 735 | if (self::debug) { |
736 | - echo '<br /> . ticket_line_item count: ' . count($ticket_line_items); |
|
736 | + echo '<br /> . ticket_line_item count: '.count($ticket_line_items); |
|
737 | 737 | } |
738 | 738 | foreach ($ticket_line_items as $ticket_line_item) { |
739 | 739 | if (self::debug) { |
740 | - echo self::$nl . ' . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
740 | + echo self::$nl.' . ticket_line_item->ID(): '.$ticket_line_item->ID(); |
|
741 | 741 | } |
742 | 742 | if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
743 | 743 | if (self::debug) { |
744 | - echo self::$nl . ' . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
744 | + echo self::$nl.' . . ticket_line_item->OBJ_ID(): '.$ticket_line_item->OBJ_ID(); |
|
745 | 745 | } |
746 | 746 | $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
747 | 747 | if ($ticket instanceof EE_Ticket) { |
748 | 748 | if (self::debug) { |
749 | - echo self::$nl . ' . . ticket->ID(): ' . $ticket->ID(); |
|
750 | - echo self::$nl . ' . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
749 | + echo self::$nl.' . . ticket->ID(): '.$ticket->ID(); |
|
750 | + echo self::$nl.' . . ticket_line_item->quantity(): '.$ticket_line_item->quantity(); |
|
751 | 751 | } |
752 | 752 | $ticket->add_extra_meta( |
753 | 753 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
754 | - __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id() |
|
754 | + __LINE__.') '.__METHOD__.'() SID = '.$session->id() |
|
755 | 755 | ); |
756 | 756 | $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
757 | 757 | } |
758 | 758 | } |
759 | 759 | } |
760 | 760 | if (self::debug) { |
761 | - echo self::$nl . self::$nl . ' RESET COMPLETED '; |
|
761 | + echo self::$nl.self::$nl.' RESET COMPLETED '; |
|
762 | 762 | } |
763 | 763 | } |
764 | 764 | |
@@ -799,7 +799,7 @@ discard block |
||
799 | 799 | protected function _session_checkout_reset(EE_Checkout $checkout) |
800 | 800 | { |
801 | 801 | if (self::debug) { |
802 | - echo self::$nl . self::$nl . __LINE__ . ') ' . __METHOD__ . '() '; |
|
802 | + echo self::$nl.self::$nl.__LINE__.') '.__METHOD__.'() '; |
|
803 | 803 | } |
804 | 804 | // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
805 | 805 | if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
@@ -847,7 +847,7 @@ discard block |
||
847 | 847 | __LINE__, |
848 | 848 | array($transaction), |
849 | 849 | false, |
850 | - 'EE_Transaction: ' . $transaction->ID() |
|
850 | + 'EE_Transaction: '.$transaction->ID() |
|
851 | 851 | ); |
852 | 852 | } |
853 | 853 | return; |
@@ -864,7 +864,7 @@ discard block |
||
864 | 864 | __LINE__, |
865 | 865 | array($payment), |
866 | 866 | false, |
867 | - 'EE_Transaction: ' . $transaction->ID() |
|
867 | + 'EE_Transaction: '.$transaction->ID() |
|
868 | 868 | ); |
869 | 869 | } |
870 | 870 | return; |
@@ -926,7 +926,7 @@ discard block |
||
926 | 926 | } |
927 | 927 | $total_line_item = $transaction->total_line_item(); |
928 | 928 | // $transaction_in_progress->line |
929 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
929 | + if ( ! $total_line_item instanceof EE_Line_Item) { |
|
930 | 930 | throw new DomainException( |
931 | 931 | esc_html__( |
932 | 932 | 'Transaction does not have a valid Total Line Item associated with it.', |
@@ -964,7 +964,7 @@ discard block |
||
964 | 964 | $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
965 | 965 | foreach ($ticket_line_items as $ticket_line_item) { |
966 | 966 | if ($ticket_line_item instanceof EE_Line_Item) { |
967 | - $valid_reserved_tickets[ $ticket_line_item->ID() ] = $ticket_line_item; |
|
967 | + $valid_reserved_tickets[$ticket_line_item->ID()] = $ticket_line_item; |
|
968 | 968 | } |
969 | 969 | } |
970 | 970 | return $valid_reserved_tickets; |
@@ -997,7 +997,7 @@ discard block |
||
997 | 997 | $total_tickets_released = 0; |
998 | 998 | $sold_out_events = array(); |
999 | 999 | foreach ($tickets_with_reservations as $ticket_with_reservations) { |
1000 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
1000 | + if ( ! $ticket_with_reservations instanceof EE_Ticket) { |
|
1001 | 1001 | continue; |
1002 | 1002 | } |
1003 | 1003 | // The $valid_reserved_ticket_line_items tells us what the reserved count on their tickets (and datetimes) |
@@ -1018,9 +1018,9 @@ discard block |
||
1018 | 1018 | if ($expired_reservations_count > 0) { |
1019 | 1019 | $ticket_with_reservations->add_extra_meta( |
1020 | 1020 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
1021 | - __LINE__ . ') ' . $source . '()' |
|
1021 | + __LINE__.') '.$source.'()' |
|
1022 | 1022 | ); |
1023 | - $ticket_with_reservations->decreaseReserved($expired_reservations_count, true, 'TicketSalesMonitor:' . __LINE__); |
|
1023 | + $ticket_with_reservations->decreaseReserved($expired_reservations_count, true, 'TicketSalesMonitor:'.__LINE__); |
|
1024 | 1024 | $total_tickets_released += $expired_reservations_count; |
1025 | 1025 | $event = $ticket_with_reservations->get_related_event(); |
1026 | 1026 | // track sold out events |
@@ -1056,7 +1056,7 @@ discard block |
||
1056 | 1056 | { |
1057 | 1057 | /** @type WPDB $wpdb */ |
1058 | 1058 | global $wpdb; |
1059 | - if (! absint($timestamp)) { |
|
1059 | + if ( ! absint($timestamp)) { |
|
1060 | 1060 | /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
1061 | 1061 | $session_lifespan = LoaderFactory::getLoader()->getShared( |
1062 | 1062 | 'EventEspresso\core\domain\values\session\SessionLifespan' |
@@ -1065,7 +1065,7 @@ discard block |
||
1065 | 1065 | } |
1066 | 1066 | return $wpdb->query( |
1067 | 1067 | $wpdb->prepare( |
1068 | - 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
1068 | + 'DELETE FROM '.EEM_Line_Item::instance()->table().' |
|
1069 | 1069 | WHERE TXN_ID = 0 AND LIN_timestamp <= %s', |
1070 | 1070 | // use GMT time because that's what LIN_timestamps are in |
1071 | 1071 | date('Y-m-d H:i:s', $timestamp) |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | |
135 | 135 | |
136 | 136 | // If there is no event objecdt by now then get out. |
137 | - if (! $this->_event instanceof EE_Event) { |
|
137 | + if ( ! $this->_event instanceof EE_Event) { |
|
138 | 138 | return ''; |
139 | 139 | } |
140 | 140 | |
@@ -187,11 +187,11 @@ discard block |
||
187 | 187 | $image = $this->_event->feature_image_url(array(600, 300)); |
188 | 188 | // @todo: eventually we should make this an attribute shortcode so that em can send along what size they want returned. |
189 | 189 | return ! empty($image) |
190 | - ? '<img src="' . $image . '" alt="' |
|
190 | + ? '<img src="'.$image.'" alt="' |
|
191 | 191 | . sprintf( |
192 | 192 | esc_attr__('%s Feature Image', 'event_espresso'), |
193 | 193 | $this->_event->get('EVT_name') |
194 | - ) . '" />' |
|
194 | + ).'" />' |
|
195 | 195 | : ''; |
196 | 196 | break; |
197 | 197 | |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | // Add a filter to allow all instances of EVENT_META_* to run through do_shortcode, default to false. |
252 | 252 | // Check if a do_shortcode attribute was set to true and if so run $event_meta through that function. |
253 | 253 | if (apply_filters('FHEE__EventEspresso_core_libraries_shortcodes_EE_Event_Shortcodes___parser__event_meta_do_shortcode', false) |
254 | - || !empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN) |
|
254 | + || ! empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN) |
|
255 | 255 | ) { |
256 | 256 | return do_shortcode($event_meta); |
257 | 257 | } |
@@ -269,11 +269,11 @@ discard block |
||
269 | 269 | |
270 | 270 | if (strpos($shortcode, '[EVENT_IMAGE_*') !== false) { |
271 | 271 | $attrs = $this->_get_shortcode_attrs($shortcode); |
272 | - $width = empty($attrs['width']) ? '' : ' width="' . $attrs['width'] . '"'; |
|
273 | - $height = empty($attrs['height']) ? '' : ' height="' . $attrs['height'] . '"'; |
|
272 | + $width = empty($attrs['width']) ? '' : ' width="'.$attrs['width'].'"'; |
|
273 | + $height = empty($attrs['height']) ? '' : ' height="'.$attrs['height'].'"'; |
|
274 | 274 | |
275 | 275 | // Size may be set to a string such as 'tumbnail' or "width, height" eg - '200,200' |
276 | - if (! empty($attrs['size'])) { |
|
276 | + if ( ! empty($attrs['size'])) { |
|
277 | 277 | $size = explode(',', $attrs['size']); |
278 | 278 | if (count($size) === 1) { |
279 | 279 | $size = $size[0]; |
@@ -285,11 +285,11 @@ discard block |
||
285 | 285 | $image = $this->_event->feature_image_url($size); |
286 | 286 | |
287 | 287 | return ! empty($image) |
288 | - ? '<img src="' . $image . '" alt="' |
|
288 | + ? '<img src="'.$image.'" alt="' |
|
289 | 289 | . sprintf( |
290 | 290 | esc_attr__('%s Feature Image', 'event_espresso'), |
291 | 291 | $this->_event->get('EVT_name') |
292 | - ) . '"' . $width . $height . '/>' |
|
292 | + ).'"'.$width.$height.'/>' |
|
293 | 293 | : ''; |
294 | 294 | } |
295 | 295 | |
@@ -308,6 +308,6 @@ discard block |
||
308 | 308 | { |
309 | 309 | $url = get_permalink($event->ID()); |
310 | 310 | |
311 | - return $full_link ? '<a href="' . $url . '">' . $event->get('EVT_name') . '</a>' : $url; |
|
311 | + return $full_link ? '<a href="'.$url.'">'.$event->get('EVT_name').'</a>' : $url; |
|
312 | 312 | } |
313 | 313 | } |
@@ -19,296 +19,296 @@ |
||
19 | 19 | { |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * Will hold the EE_Event if available |
|
24 | - * |
|
25 | - * @var EE_Event |
|
26 | - */ |
|
27 | - protected $_event; |
|
28 | - |
|
29 | - |
|
30 | - public function __construct() |
|
31 | - { |
|
32 | - parent::__construct(); |
|
33 | - } |
|
34 | - |
|
35 | - |
|
36 | - protected function _init_props() |
|
37 | - { |
|
38 | - $this->label = __('Event Shortcodes', 'event_espresso'); |
|
39 | - $this->description = __('All shortcodes specific to event related data', 'event_espresso'); |
|
40 | - $this->_shortcodes = array( |
|
41 | - '[EVENT_ID]' => __( |
|
42 | - 'Will be replaced by the event ID of an event', |
|
43 | - 'event_espresso' |
|
44 | - ), |
|
45 | - '[EVENT]' => __('The name of the event', 'event_espresso'), |
|
46 | - '[EVENT_NAME]' => __( |
|
47 | - "This also can be used for the name of the event", |
|
48 | - 'event_espresso' |
|
49 | - ), |
|
50 | - '[EVENT_PHONE]' => __( |
|
51 | - 'The phone number for the event (usually an info number)', |
|
52 | - 'event_espresso' |
|
53 | - ), |
|
54 | - '[EVENT_DESCRIPTION]' => __('The description of the event', 'event_espresso'), |
|
55 | - '[EVENT_EXCERPT]' => __( |
|
56 | - 'This gets parsed to the value for the excerpt field in the event or blank if there is no excerpt.', |
|
57 | - 'event_espresso' |
|
58 | - ), |
|
59 | - '[EVENT_LINK]' => __('A link associated with the event', 'event_espresso'), |
|
60 | - '[EVENT_URL]' => __( |
|
61 | - 'A link to the event set up on the host site.', |
|
62 | - 'event_espresso' |
|
63 | - ), |
|
64 | - '[VIRTUAL_URL]' => __( |
|
65 | - 'What was used for the "URL of Event" field in the Venue settings', |
|
66 | - 'event_espresso' |
|
67 | - ), |
|
68 | - '[VIRTUAL_PHONE]' => __( |
|
69 | - 'An alternate phone number for the event. Typically used as a "call-in" number', |
|
70 | - 'event_espresso' |
|
71 | - ), |
|
72 | - '[EVENT_IMAGE]' => __( |
|
73 | - 'This will parse to the Feature image for the event.', |
|
74 | - 'event_espresso' |
|
75 | - ), |
|
76 | - '[EVENT_IMAGE_*]' => sprintf( |
|
77 | - __( |
|
78 | - 'This will parse to the Feature image for the event, %1$ssize%2$s can be set to determine the size of the image loaded by the shortcode. The %1$swidth%2$s and/or %1$sheight%2$s can also be set to determine the width and height of the image when output. By default the shortcode will load the %1$sthumbnail%2$s image size.', |
|
79 | - 'event_espresso' |
|
80 | - ), |
|
81 | - '<code>', |
|
82 | - '</code>' |
|
83 | - ), |
|
84 | - '[EVENT_TOTAL_AVAILABLE_SPACES_*]' => sprintf( |
|
85 | - __( |
|
86 | - 'This will parse to the total available spaces for an event. Calculating total spaces is approximate because it is dependent on the complexity of limits on your event. There are two methods of calculation (which can be indicated by the %1$smethod%2$s param on the shortcode). %1$scurrent%2$s which will do a more accurate calculation of total available spaces based on current sales, and %1$sfull%2$s which will be the maximum total available spaces that is on the event in optimal conditions. The shortcode will default to current.', |
|
87 | - 'event_espresso' |
|
88 | - ), |
|
89 | - '<code>', |
|
90 | - '</code>' |
|
91 | - ), |
|
92 | - '[EVENT_TOTAL_SPOTS_TAKEN]' => __( |
|
93 | - 'This shortcode will parse to the output the total approved registrations for this event', |
|
94 | - 'event_espresso' |
|
95 | - ), |
|
96 | - '[EVENT_FACEBOOK_URL]' => __( |
|
97 | - 'This will return the Facebook URL for the event if you have it set via custom field in your event, otherwise it will use the Facebook URL set in "Your Organization Settings". To set the facebook url in your event, add a custom field with the key as <code>event_facebook</code> and the value as your facebook url.', |
|
98 | - 'event_espresso' |
|
99 | - ), |
|
100 | - '[EVENT_TWITTER_URL]' => __( |
|
101 | - 'This will return the Twitter URL for the event if you have it set via custom field in your event, otherwise it will use the Twitter URL set in "Your Organization Settings". To set the facebook url in your event, add a custom field with the key as <code>event_twitter</code> and the value as your facebook url', |
|
102 | - 'event_espresso' |
|
103 | - ), |
|
104 | - '[EVENT_META_*]' => sprintf( |
|
105 | - __( |
|
106 | - 'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the event then it will be output in place of this shortcode. If you use shortcodes within your custom fields set %1$sdo_shortcode=true%2$s at the end of the shortcode to run the value through the do_shortcode function. ', |
|
107 | - 'event_espresso' |
|
108 | - ), |
|
109 | - '<code>', |
|
110 | - '</code>' |
|
111 | - ), |
|
112 | - '[REGISTRATION_LIST_TABLE_FOR_EVENT_URL]' => __( |
|
113 | - 'This parses to the url for the registration list table filtered by registrations for this event.', |
|
114 | - 'event_espresso' |
|
115 | - ), |
|
116 | - ); |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - protected function _parser($shortcode) |
|
121 | - { |
|
122 | - |
|
123 | - |
|
124 | - $this->_event = $this->_data instanceof EE_Event ? $this->_data : null; |
|
125 | - |
|
126 | - // if no event, then let's see if there is a reg_obj. If there IS, then we'll try and grab the event from the reg_obj instead. |
|
127 | - if (empty($this->_event)) { |
|
128 | - $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
129 | - $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee; |
|
130 | - |
|
131 | - $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration |
|
132 | - ? $aee->reg_obj->event() : null; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - // If there is no event objecdt by now then get out. |
|
137 | - if (! $this->_event instanceof EE_Event) { |
|
138 | - return ''; |
|
139 | - } |
|
140 | - |
|
141 | - switch ($shortcode) { |
|
142 | - case '[EVENT_ID]': |
|
143 | - return $this->_event->ID(); |
|
144 | - break; |
|
145 | - |
|
146 | - case '[EVENT]': |
|
147 | - case '[EVENT_NAME]': |
|
148 | - return $this->_event->get('EVT_name'); |
|
149 | - break; |
|
150 | - |
|
151 | - case '[EVENT_PHONE]': |
|
152 | - return $this->_event->get('EVT_phone'); |
|
153 | - break; |
|
154 | - |
|
155 | - case '[EVENT_DESCRIPTION]': |
|
156 | - return $this->_event->get('EVT_desc'); |
|
157 | - break; |
|
158 | - |
|
159 | - case '[EVENT_EXCERPT]': |
|
160 | - return $this->_event->get('EVT_short_desc'); |
|
161 | - break; |
|
162 | - |
|
163 | - case '[EVENT_LINK]': |
|
164 | - return $this->_get_event_link($this->_event); |
|
165 | - break; |
|
166 | - |
|
167 | - case '[EVENT_URL]': |
|
168 | - return $this->_get_event_link($this->_event, false); |
|
169 | - break; |
|
170 | - |
|
171 | - case '[VIRTUAL_URL]': |
|
172 | - $venue = $this->_event->get_first_related('Venue'); |
|
173 | - if (empty($venue)) { |
|
174 | - return ''; |
|
175 | - } |
|
176 | - return $venue->get('VNU_virtual_url'); |
|
177 | - |
|
178 | - case '[VIRTUAL_PHONE]': |
|
179 | - $venue = $this->_event->get_first_related('Venue'); |
|
180 | - if (empty($venue)) { |
|
181 | - return ''; |
|
182 | - } |
|
183 | - return $venue->get('VNU_virtual_phone'); |
|
184 | - break; |
|
185 | - |
|
186 | - case '[EVENT_IMAGE]': |
|
187 | - $image = $this->_event->feature_image_url(array(600, 300)); |
|
188 | - // @todo: eventually we should make this an attribute shortcode so that em can send along what size they want returned. |
|
189 | - return ! empty($image) |
|
190 | - ? '<img src="' . $image . '" alt="' |
|
191 | - . sprintf( |
|
192 | - esc_attr__('%s Feature Image', 'event_espresso'), |
|
193 | - $this->_event->get('EVT_name') |
|
194 | - ) . '" />' |
|
195 | - : ''; |
|
196 | - break; |
|
197 | - |
|
198 | - case '[EVENT_FACEBOOK_URL]': |
|
199 | - $facebook_url = $this->_event->get_post_meta('event_facebook', true); |
|
200 | - return empty($facebook_url) ? EE_Registry::instance()->CFG->organization->get_pretty('facebook') |
|
201 | - : $facebook_url; |
|
202 | - break; |
|
203 | - |
|
204 | - case '[EVENT_TWITTER_URL]': |
|
205 | - $twitter_url = $this->_event->get_post_meta('event_twitter', true); |
|
206 | - return empty($twitter_url) ? EE_Registry::instance()->CFG->organization->get_pretty('twitter') |
|
207 | - : $twitter_url; |
|
208 | - break; |
|
209 | - |
|
210 | - case '[EVENT_AUTHOR_EMAIL]': |
|
211 | - $author_id = $this->_event->get('EVT_wp_user'); |
|
212 | - $user_data = get_userdata((int) $author_id); |
|
213 | - return $user_data->user_email; |
|
214 | - break; |
|
215 | - |
|
216 | - case '[EVENT_TOTAL_SPOTS_TAKEN]': |
|
217 | - return EEM_Registration::instance()->count( |
|
218 | - array(array('EVT_ID' => $this->_event->ID(), 'STS_ID' => EEM_Registration::status_id_approved)), |
|
219 | - 'REG_ID', |
|
220 | - true |
|
221 | - ); |
|
222 | - break; |
|
223 | - |
|
224 | - case '[REGISTRATION_LIST_TABLE_FOR_EVENT_URL]': |
|
225 | - return EEH_URL::add_query_args_and_nonce( |
|
226 | - array( |
|
227 | - 'event_id' => $this->_event->ID(), |
|
228 | - 'page' => 'espresso_registrations', |
|
229 | - 'action' => 'default', |
|
230 | - ), |
|
231 | - admin_url('admin.php'), |
|
232 | - true |
|
233 | - ); |
|
234 | - break; |
|
235 | - } |
|
236 | - |
|
237 | - if (strpos($shortcode, '[EVENT_META_*') !== false) { |
|
238 | - // Strip the shortcode itself from $shortcode leaving any attributes set. |
|
239 | - // Removing the * is correct here as _* is used to indiciate a dynamic shortcode. |
|
240 | - $shortcode = str_replace('[EVENT_META_*', '', $shortcode); |
|
241 | - $shortcode = trim(str_replace(']', '', $shortcode)); |
|
242 | - // Get any attributes set on this shortcode. |
|
243 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
244 | - // The meta_key set on the shortcode should always be the first value in the array. |
|
245 | - $meta_key = $attrs[0]; |
|
246 | - // Pull the meta value from the event post. |
|
247 | - $event_meta = $this->_event->get_post_meta($meta_key, true); |
|
248 | - // If we have no event_meta, just return an empty string. |
|
249 | - if (empty($event_meta)) { |
|
250 | - return ''; |
|
251 | - } |
|
252 | - // Add a filter to allow all instances of EVENT_META_* to run through do_shortcode, default to false. |
|
253 | - // Check if a do_shortcode attribute was set to true and if so run $event_meta through that function. |
|
254 | - if (apply_filters('FHEE__EventEspresso_core_libraries_shortcodes_EE_Event_Shortcodes___parser__event_meta_do_shortcode', false) |
|
255 | - || !empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN) |
|
256 | - ) { |
|
257 | - return do_shortcode($event_meta); |
|
258 | - } |
|
259 | - // Still here? We just need to return the event_meta value as is. |
|
260 | - return $event_meta; |
|
261 | - } |
|
262 | - |
|
263 | - if (strpos($shortcode, '[EVENT_TOTAL_AVAILABLE_SPACES_*') !== false) { |
|
264 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
265 | - $method = empty($attrs['method']) ? 'current' : $attrs['method']; |
|
266 | - $method = $method === 'current'; |
|
267 | - $available = $this->_event->total_available_spaces($method); |
|
268 | - return $available === EE_INF ? '∞' : $available; |
|
269 | - } |
|
270 | - |
|
271 | - if (strpos($shortcode, '[EVENT_IMAGE_*') !== false) { |
|
272 | - $attrs = $this->_get_shortcode_attrs($shortcode); |
|
273 | - $width = empty($attrs['width']) ? '' : ' width="' . $attrs['width'] . '"'; |
|
274 | - $height = empty($attrs['height']) ? '' : ' height="' . $attrs['height'] . '"'; |
|
275 | - |
|
276 | - // Size may be set to a string such as 'tumbnail' or "width, height" eg - '200,200' |
|
277 | - if (! empty($attrs['size'])) { |
|
278 | - $size = explode(',', $attrs['size']); |
|
279 | - if (count($size) === 1) { |
|
280 | - $size = $size[0]; |
|
281 | - } |
|
282 | - } else { |
|
283 | - $size = 'thumbnail'; |
|
284 | - } |
|
285 | - |
|
286 | - $image = $this->_event->feature_image_url($size); |
|
287 | - |
|
288 | - return ! empty($image) |
|
289 | - ? '<img src="' . $image . '" alt="' |
|
290 | - . sprintf( |
|
291 | - esc_attr__('%s Feature Image', 'event_espresso'), |
|
292 | - $this->_event->get('EVT_name') |
|
293 | - ) . '"' . $width . $height . '/>' |
|
294 | - : ''; |
|
295 | - } |
|
296 | - |
|
297 | - return ''; |
|
298 | - } |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * returns the link to the event |
|
303 | - * |
|
304 | - * @param boolean $full_link if TRUE (default) we return the html for the name of the event linked to the event. |
|
305 | - * Otherwise we just return the url of the event. |
|
306 | - * @return string |
|
307 | - */ |
|
308 | - private function _get_event_link($event, $full_link = true) |
|
309 | - { |
|
310 | - $url = get_permalink($event->ID()); |
|
311 | - |
|
312 | - return $full_link ? '<a href="' . $url . '">' . $event->get('EVT_name') . '</a>' : $url; |
|
313 | - } |
|
22 | + /** |
|
23 | + * Will hold the EE_Event if available |
|
24 | + * |
|
25 | + * @var EE_Event |
|
26 | + */ |
|
27 | + protected $_event; |
|
28 | + |
|
29 | + |
|
30 | + public function __construct() |
|
31 | + { |
|
32 | + parent::__construct(); |
|
33 | + } |
|
34 | + |
|
35 | + |
|
36 | + protected function _init_props() |
|
37 | + { |
|
38 | + $this->label = __('Event Shortcodes', 'event_espresso'); |
|
39 | + $this->description = __('All shortcodes specific to event related data', 'event_espresso'); |
|
40 | + $this->_shortcodes = array( |
|
41 | + '[EVENT_ID]' => __( |
|
42 | + 'Will be replaced by the event ID of an event', |
|
43 | + 'event_espresso' |
|
44 | + ), |
|
45 | + '[EVENT]' => __('The name of the event', 'event_espresso'), |
|
46 | + '[EVENT_NAME]' => __( |
|
47 | + "This also can be used for the name of the event", |
|
48 | + 'event_espresso' |
|
49 | + ), |
|
50 | + '[EVENT_PHONE]' => __( |
|
51 | + 'The phone number for the event (usually an info number)', |
|
52 | + 'event_espresso' |
|
53 | + ), |
|
54 | + '[EVENT_DESCRIPTION]' => __('The description of the event', 'event_espresso'), |
|
55 | + '[EVENT_EXCERPT]' => __( |
|
56 | + 'This gets parsed to the value for the excerpt field in the event or blank if there is no excerpt.', |
|
57 | + 'event_espresso' |
|
58 | + ), |
|
59 | + '[EVENT_LINK]' => __('A link associated with the event', 'event_espresso'), |
|
60 | + '[EVENT_URL]' => __( |
|
61 | + 'A link to the event set up on the host site.', |
|
62 | + 'event_espresso' |
|
63 | + ), |
|
64 | + '[VIRTUAL_URL]' => __( |
|
65 | + 'What was used for the "URL of Event" field in the Venue settings', |
|
66 | + 'event_espresso' |
|
67 | + ), |
|
68 | + '[VIRTUAL_PHONE]' => __( |
|
69 | + 'An alternate phone number for the event. Typically used as a "call-in" number', |
|
70 | + 'event_espresso' |
|
71 | + ), |
|
72 | + '[EVENT_IMAGE]' => __( |
|
73 | + 'This will parse to the Feature image for the event.', |
|
74 | + 'event_espresso' |
|
75 | + ), |
|
76 | + '[EVENT_IMAGE_*]' => sprintf( |
|
77 | + __( |
|
78 | + 'This will parse to the Feature image for the event, %1$ssize%2$s can be set to determine the size of the image loaded by the shortcode. The %1$swidth%2$s and/or %1$sheight%2$s can also be set to determine the width and height of the image when output. By default the shortcode will load the %1$sthumbnail%2$s image size.', |
|
79 | + 'event_espresso' |
|
80 | + ), |
|
81 | + '<code>', |
|
82 | + '</code>' |
|
83 | + ), |
|
84 | + '[EVENT_TOTAL_AVAILABLE_SPACES_*]' => sprintf( |
|
85 | + __( |
|
86 | + 'This will parse to the total available spaces for an event. Calculating total spaces is approximate because it is dependent on the complexity of limits on your event. There are two methods of calculation (which can be indicated by the %1$smethod%2$s param on the shortcode). %1$scurrent%2$s which will do a more accurate calculation of total available spaces based on current sales, and %1$sfull%2$s which will be the maximum total available spaces that is on the event in optimal conditions. The shortcode will default to current.', |
|
87 | + 'event_espresso' |
|
88 | + ), |
|
89 | + '<code>', |
|
90 | + '</code>' |
|
91 | + ), |
|
92 | + '[EVENT_TOTAL_SPOTS_TAKEN]' => __( |
|
93 | + 'This shortcode will parse to the output the total approved registrations for this event', |
|
94 | + 'event_espresso' |
|
95 | + ), |
|
96 | + '[EVENT_FACEBOOK_URL]' => __( |
|
97 | + 'This will return the Facebook URL for the event if you have it set via custom field in your event, otherwise it will use the Facebook URL set in "Your Organization Settings". To set the facebook url in your event, add a custom field with the key as <code>event_facebook</code> and the value as your facebook url.', |
|
98 | + 'event_espresso' |
|
99 | + ), |
|
100 | + '[EVENT_TWITTER_URL]' => __( |
|
101 | + 'This will return the Twitter URL for the event if you have it set via custom field in your event, otherwise it will use the Twitter URL set in "Your Organization Settings". To set the facebook url in your event, add a custom field with the key as <code>event_twitter</code> and the value as your facebook url', |
|
102 | + 'event_espresso' |
|
103 | + ), |
|
104 | + '[EVENT_META_*]' => sprintf( |
|
105 | + __( |
|
106 | + 'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the event then it will be output in place of this shortcode. If you use shortcodes within your custom fields set %1$sdo_shortcode=true%2$s at the end of the shortcode to run the value through the do_shortcode function. ', |
|
107 | + 'event_espresso' |
|
108 | + ), |
|
109 | + '<code>', |
|
110 | + '</code>' |
|
111 | + ), |
|
112 | + '[REGISTRATION_LIST_TABLE_FOR_EVENT_URL]' => __( |
|
113 | + 'This parses to the url for the registration list table filtered by registrations for this event.', |
|
114 | + 'event_espresso' |
|
115 | + ), |
|
116 | + ); |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + protected function _parser($shortcode) |
|
121 | + { |
|
122 | + |
|
123 | + |
|
124 | + $this->_event = $this->_data instanceof EE_Event ? $this->_data : null; |
|
125 | + |
|
126 | + // if no event, then let's see if there is a reg_obj. If there IS, then we'll try and grab the event from the reg_obj instead. |
|
127 | + if (empty($this->_event)) { |
|
128 | + $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
129 | + $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee; |
|
130 | + |
|
131 | + $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration |
|
132 | + ? $aee->reg_obj->event() : null; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + // If there is no event objecdt by now then get out. |
|
137 | + if (! $this->_event instanceof EE_Event) { |
|
138 | + return ''; |
|
139 | + } |
|
140 | + |
|
141 | + switch ($shortcode) { |
|
142 | + case '[EVENT_ID]': |
|
143 | + return $this->_event->ID(); |
|
144 | + break; |
|
145 | + |
|
146 | + case '[EVENT]': |
|
147 | + case '[EVENT_NAME]': |
|
148 | + return $this->_event->get('EVT_name'); |
|
149 | + break; |
|
150 | + |
|
151 | + case '[EVENT_PHONE]': |
|
152 | + return $this->_event->get('EVT_phone'); |
|
153 | + break; |
|
154 | + |
|
155 | + case '[EVENT_DESCRIPTION]': |
|
156 | + return $this->_event->get('EVT_desc'); |
|
157 | + break; |
|
158 | + |
|
159 | + case '[EVENT_EXCERPT]': |
|
160 | + return $this->_event->get('EVT_short_desc'); |
|
161 | + break; |
|
162 | + |
|
163 | + case '[EVENT_LINK]': |
|
164 | + return $this->_get_event_link($this->_event); |
|
165 | + break; |
|
166 | + |
|
167 | + case '[EVENT_URL]': |
|
168 | + return $this->_get_event_link($this->_event, false); |
|
169 | + break; |
|
170 | + |
|
171 | + case '[VIRTUAL_URL]': |
|
172 | + $venue = $this->_event->get_first_related('Venue'); |
|
173 | + if (empty($venue)) { |
|
174 | + return ''; |
|
175 | + } |
|
176 | + return $venue->get('VNU_virtual_url'); |
|
177 | + |
|
178 | + case '[VIRTUAL_PHONE]': |
|
179 | + $venue = $this->_event->get_first_related('Venue'); |
|
180 | + if (empty($venue)) { |
|
181 | + return ''; |
|
182 | + } |
|
183 | + return $venue->get('VNU_virtual_phone'); |
|
184 | + break; |
|
185 | + |
|
186 | + case '[EVENT_IMAGE]': |
|
187 | + $image = $this->_event->feature_image_url(array(600, 300)); |
|
188 | + // @todo: eventually we should make this an attribute shortcode so that em can send along what size they want returned. |
|
189 | + return ! empty($image) |
|
190 | + ? '<img src="' . $image . '" alt="' |
|
191 | + . sprintf( |
|
192 | + esc_attr__('%s Feature Image', 'event_espresso'), |
|
193 | + $this->_event->get('EVT_name') |
|
194 | + ) . '" />' |
|
195 | + : ''; |
|
196 | + break; |
|
197 | + |
|
198 | + case '[EVENT_FACEBOOK_URL]': |
|
199 | + $facebook_url = $this->_event->get_post_meta('event_facebook', true); |
|
200 | + return empty($facebook_url) ? EE_Registry::instance()->CFG->organization->get_pretty('facebook') |
|
201 | + : $facebook_url; |
|
202 | + break; |
|
203 | + |
|
204 | + case '[EVENT_TWITTER_URL]': |
|
205 | + $twitter_url = $this->_event->get_post_meta('event_twitter', true); |
|
206 | + return empty($twitter_url) ? EE_Registry::instance()->CFG->organization->get_pretty('twitter') |
|
207 | + : $twitter_url; |
|
208 | + break; |
|
209 | + |
|
210 | + case '[EVENT_AUTHOR_EMAIL]': |
|
211 | + $author_id = $this->_event->get('EVT_wp_user'); |
|
212 | + $user_data = get_userdata((int) $author_id); |
|
213 | + return $user_data->user_email; |
|
214 | + break; |
|
215 | + |
|
216 | + case '[EVENT_TOTAL_SPOTS_TAKEN]': |
|
217 | + return EEM_Registration::instance()->count( |
|
218 | + array(array('EVT_ID' => $this->_event->ID(), 'STS_ID' => EEM_Registration::status_id_approved)), |
|
219 | + 'REG_ID', |
|
220 | + true |
|
221 | + ); |
|
222 | + break; |
|
223 | + |
|
224 | + case '[REGISTRATION_LIST_TABLE_FOR_EVENT_URL]': |
|
225 | + return EEH_URL::add_query_args_and_nonce( |
|
226 | + array( |
|
227 | + 'event_id' => $this->_event->ID(), |
|
228 | + 'page' => 'espresso_registrations', |
|
229 | + 'action' => 'default', |
|
230 | + ), |
|
231 | + admin_url('admin.php'), |
|
232 | + true |
|
233 | + ); |
|
234 | + break; |
|
235 | + } |
|
236 | + |
|
237 | + if (strpos($shortcode, '[EVENT_META_*') !== false) { |
|
238 | + // Strip the shortcode itself from $shortcode leaving any attributes set. |
|
239 | + // Removing the * is correct here as _* is used to indiciate a dynamic shortcode. |
|
240 | + $shortcode = str_replace('[EVENT_META_*', '', $shortcode); |
|
241 | + $shortcode = trim(str_replace(']', '', $shortcode)); |
|
242 | + // Get any attributes set on this shortcode. |
|
243 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
244 | + // The meta_key set on the shortcode should always be the first value in the array. |
|
245 | + $meta_key = $attrs[0]; |
|
246 | + // Pull the meta value from the event post. |
|
247 | + $event_meta = $this->_event->get_post_meta($meta_key, true); |
|
248 | + // If we have no event_meta, just return an empty string. |
|
249 | + if (empty($event_meta)) { |
|
250 | + return ''; |
|
251 | + } |
|
252 | + // Add a filter to allow all instances of EVENT_META_* to run through do_shortcode, default to false. |
|
253 | + // Check if a do_shortcode attribute was set to true and if so run $event_meta through that function. |
|
254 | + if (apply_filters('FHEE__EventEspresso_core_libraries_shortcodes_EE_Event_Shortcodes___parser__event_meta_do_shortcode', false) |
|
255 | + || !empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN) |
|
256 | + ) { |
|
257 | + return do_shortcode($event_meta); |
|
258 | + } |
|
259 | + // Still here? We just need to return the event_meta value as is. |
|
260 | + return $event_meta; |
|
261 | + } |
|
262 | + |
|
263 | + if (strpos($shortcode, '[EVENT_TOTAL_AVAILABLE_SPACES_*') !== false) { |
|
264 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
265 | + $method = empty($attrs['method']) ? 'current' : $attrs['method']; |
|
266 | + $method = $method === 'current'; |
|
267 | + $available = $this->_event->total_available_spaces($method); |
|
268 | + return $available === EE_INF ? '∞' : $available; |
|
269 | + } |
|
270 | + |
|
271 | + if (strpos($shortcode, '[EVENT_IMAGE_*') !== false) { |
|
272 | + $attrs = $this->_get_shortcode_attrs($shortcode); |
|
273 | + $width = empty($attrs['width']) ? '' : ' width="' . $attrs['width'] . '"'; |
|
274 | + $height = empty($attrs['height']) ? '' : ' height="' . $attrs['height'] . '"'; |
|
275 | + |
|
276 | + // Size may be set to a string such as 'tumbnail' or "width, height" eg - '200,200' |
|
277 | + if (! empty($attrs['size'])) { |
|
278 | + $size = explode(',', $attrs['size']); |
|
279 | + if (count($size) === 1) { |
|
280 | + $size = $size[0]; |
|
281 | + } |
|
282 | + } else { |
|
283 | + $size = 'thumbnail'; |
|
284 | + } |
|
285 | + |
|
286 | + $image = $this->_event->feature_image_url($size); |
|
287 | + |
|
288 | + return ! empty($image) |
|
289 | + ? '<img src="' . $image . '" alt="' |
|
290 | + . sprintf( |
|
291 | + esc_attr__('%s Feature Image', 'event_espresso'), |
|
292 | + $this->_event->get('EVT_name') |
|
293 | + ) . '"' . $width . $height . '/>' |
|
294 | + : ''; |
|
295 | + } |
|
296 | + |
|
297 | + return ''; |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * returns the link to the event |
|
303 | + * |
|
304 | + * @param boolean $full_link if TRUE (default) we return the html for the name of the event linked to the event. |
|
305 | + * Otherwise we just return the url of the event. |
|
306 | + * @return string |
|
307 | + */ |
|
308 | + private function _get_event_link($event, $full_link = true) |
|
309 | + { |
|
310 | + $url = get_permalink($event->ID()); |
|
311 | + |
|
312 | + return $full_link ? '<a href="' . $url . '">' . $event->get('EVT_name') . '</a>' : $url; |
|
313 | + } |
|
314 | 314 | } |
@@ -19,797 +19,797 @@ discard block |
||
19 | 19 | { |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * prefix to be added onto an addon's plugin slug to make a wp option name |
|
24 | - * which will be used to store the plugin's activation history |
|
25 | - */ |
|
26 | - const ee_addon_version_history_option_prefix = 'ee_version_history_'; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var $_version |
|
30 | - * @type string |
|
31 | - */ |
|
32 | - protected $_version = ''; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var $_min_core_version |
|
36 | - * @type string |
|
37 | - */ |
|
38 | - protected $_min_core_version = ''; |
|
39 | - |
|
40 | - /** |
|
41 | - * derived from plugin 'main_file_path using plugin_basename() |
|
42 | - * |
|
43 | - * @type string $_plugin_basename |
|
44 | - */ |
|
45 | - protected $_plugin_basename = ''; |
|
46 | - |
|
47 | - /** |
|
48 | - * A non-internationalized name to identify this addon for use in URLs, etc |
|
49 | - * |
|
50 | - * @type string $_plugin_slug |
|
51 | - */ |
|
52 | - protected $_plugin_slug = ''; |
|
53 | - |
|
54 | - /** |
|
55 | - * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/ |
|
56 | - * |
|
57 | - * @type string _addon_name |
|
58 | - */ |
|
59 | - protected $_addon_name = ''; |
|
60 | - |
|
61 | - /** |
|
62 | - * one of the EE_System::req_type_* constants |
|
63 | - * |
|
64 | - * @type int $_req_type |
|
65 | - */ |
|
66 | - protected $_req_type; |
|
67 | - |
|
68 | - /** |
|
69 | - * page slug to be used when generating the "Settings" link on the WP plugin page |
|
70 | - * |
|
71 | - * @type string $_plugin_action_slug |
|
72 | - */ |
|
73 | - protected $_plugin_action_slug = ''; |
|
74 | - |
|
75 | - /** |
|
76 | - * if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
77 | - * that can be used for adding upgrading/marketing info |
|
78 | - * |
|
79 | - * @type array $_plugins_page_row |
|
80 | - */ |
|
81 | - protected $_plugins_page_row = array(); |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc. |
|
86 | - * |
|
87 | - * @type string |
|
88 | - */ |
|
89 | - protected $_main_plugin_file; |
|
90 | - |
|
91 | - /** |
|
92 | - * This is the slug used to identify this add-on within the plugin update engine. |
|
93 | - * |
|
94 | - * @type string |
|
95 | - */ |
|
96 | - protected $pue_slug; |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * @var EE_Dependency_Map $dependency_map |
|
101 | - */ |
|
102 | - private $dependency_map; |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @var DomainInterface $domain |
|
107 | - */ |
|
108 | - private $domain; |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * @param EE_Dependency_Map $dependency_map [optional] |
|
113 | - * @param DomainInterface $domain [optional] |
|
114 | - */ |
|
115 | - public function __construct(EE_Dependency_Map $dependency_map = null, DomainInterface $domain = null) |
|
116 | - { |
|
117 | - if ($dependency_map instanceof EE_Dependency_Map) { |
|
118 | - $this->setDependencyMap($dependency_map); |
|
119 | - } |
|
120 | - if ($domain instanceof DomainInterface) { |
|
121 | - $this->setDomain($domain); |
|
122 | - } |
|
123 | - add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init')); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @param EE_Dependency_Map $dependency_map |
|
129 | - */ |
|
130 | - public function setDependencyMap($dependency_map) |
|
131 | - { |
|
132 | - $this->dependency_map = $dependency_map; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @return EE_Dependency_Map |
|
138 | - */ |
|
139 | - public function dependencyMap() |
|
140 | - { |
|
141 | - return $this->dependency_map; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @param DomainInterface $domain |
|
147 | - */ |
|
148 | - public function setDomain(DomainInterface $domain) |
|
149 | - { |
|
150 | - $this->domain = $domain; |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * @return DomainInterface |
|
155 | - */ |
|
156 | - public function domain() |
|
157 | - { |
|
158 | - return $this->domain; |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * @param mixed $version |
|
164 | - */ |
|
165 | - public function set_version($version = null) |
|
166 | - { |
|
167 | - $this->_version = $version; |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * get__version |
|
173 | - * |
|
174 | - * @return string |
|
175 | - */ |
|
176 | - public function version() |
|
177 | - { |
|
178 | - return $this->_version; |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * @param mixed $min_core_version |
|
184 | - */ |
|
185 | - public function set_min_core_version($min_core_version = null) |
|
186 | - { |
|
187 | - $this->_min_core_version = $min_core_version; |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * get__min_core_version |
|
193 | - * |
|
194 | - * @return string |
|
195 | - */ |
|
196 | - public function min_core_version() |
|
197 | - { |
|
198 | - return $this->_min_core_version; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * Sets addon_name |
|
204 | - * |
|
205 | - * @param string $addon_name |
|
206 | - * @return boolean |
|
207 | - */ |
|
208 | - public function set_name($addon_name) |
|
209 | - { |
|
210 | - return $this->_addon_name = $addon_name; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * Gets addon_name |
|
216 | - * |
|
217 | - * @return string |
|
218 | - */ |
|
219 | - public function name() |
|
220 | - { |
|
221 | - return $this->_addon_name; |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * @return string |
|
227 | - */ |
|
228 | - public function plugin_basename() |
|
229 | - { |
|
230 | - |
|
231 | - return $this->_plugin_basename; |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * @param string $plugin_basename |
|
237 | - */ |
|
238 | - public function set_plugin_basename($plugin_basename) |
|
239 | - { |
|
240 | - |
|
241 | - $this->_plugin_basename = $plugin_basename; |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * @return string |
|
247 | - */ |
|
248 | - public function plugin_slug() |
|
249 | - { |
|
250 | - |
|
251 | - return $this->_plugin_slug; |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * @param string $plugin_slug |
|
257 | - */ |
|
258 | - public function set_plugin_slug($plugin_slug) |
|
259 | - { |
|
260 | - |
|
261 | - $this->_plugin_slug = $plugin_slug; |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @return string |
|
267 | - */ |
|
268 | - public function plugin_action_slug() |
|
269 | - { |
|
270 | - |
|
271 | - return $this->_plugin_action_slug; |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * @param string $plugin_action_slug |
|
277 | - */ |
|
278 | - public function set_plugin_action_slug($plugin_action_slug) |
|
279 | - { |
|
280 | - |
|
281 | - $this->_plugin_action_slug = $plugin_action_slug; |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * @return array |
|
287 | - */ |
|
288 | - public function get_plugins_page_row() |
|
289 | - { |
|
290 | - |
|
291 | - return $this->_plugins_page_row; |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * @param array $plugins_page_row |
|
297 | - */ |
|
298 | - public function set_plugins_page_row($plugins_page_row = array()) |
|
299 | - { |
|
300 | - // sigh.... check for example content that I stupidly merged to master and remove it if found |
|
301 | - if (! is_array($plugins_page_row) |
|
302 | - && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false |
|
303 | - ) { |
|
304 | - $plugins_page_row = array(); |
|
305 | - } |
|
306 | - $this->_plugins_page_row = (array) $plugins_page_row; |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * Called when EE core detects this addon has been activated for the first time. |
|
312 | - * If the site isn't in maintenance mode, should setup the addon's database |
|
313 | - * |
|
314 | - * @return void |
|
315 | - */ |
|
316 | - public function new_install() |
|
317 | - { |
|
318 | - $classname = get_class($this); |
|
319 | - do_action("AHEE__{$classname}__new_install"); |
|
320 | - do_action('AHEE__EE_Addon__new_install', $this); |
|
321 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
322 | - add_action( |
|
323 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
324 | - array($this, 'initialize_db_if_no_migrations_required') |
|
325 | - ); |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * Called when EE core detects this addon has been reactivated. When this happens, |
|
331 | - * it's good to just check that your data is still intact |
|
332 | - * |
|
333 | - * @return void |
|
334 | - */ |
|
335 | - public function reactivation() |
|
336 | - { |
|
337 | - $classname = get_class($this); |
|
338 | - do_action("AHEE__{$classname}__reactivation"); |
|
339 | - do_action('AHEE__EE_Addon__reactivation', $this); |
|
340 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
341 | - add_action( |
|
342 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
343 | - array($this, 'initialize_db_if_no_migrations_required') |
|
344 | - ); |
|
345 | - } |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * Called when the registered deactivation hook for this addon fires. |
|
350 | - * |
|
351 | - * @throws EE_Error |
|
352 | - */ |
|
353 | - public function deactivation() |
|
354 | - { |
|
355 | - $classname = get_class($this); |
|
356 | - do_action("AHEE__{$classname}__deactivation"); |
|
357 | - do_action('AHEE__EE_Addon__deactivation', $this); |
|
358 | - // check if the site no longer needs to be in maintenance mode |
|
359 | - EE_Register_Addon::deregister($this->name()); |
|
360 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * Takes care of double-checking that we're not in maintenance mode, and then |
|
366 | - * initializing this addon's necessary initial data. This is called by default on new activations |
|
367 | - * and reactivations. |
|
368 | - * |
|
369 | - * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data. |
|
370 | - * This is a resource-intensive job so we prefer to only do it when necessary |
|
371 | - * @return void |
|
372 | - * @throws \EE_Error |
|
373 | - * @throws InvalidInterfaceException |
|
374 | - * @throws InvalidDataTypeException |
|
375 | - * @throws InvalidArgumentException |
|
376 | - */ |
|
377 | - public function initialize_db_if_no_migrations_required($verify_schema = true) |
|
378 | - { |
|
379 | - if ($verify_schema === '') { |
|
380 | - // wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name |
|
381 | - // (ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it |
|
382 | - // calls them with an argument of an empty string (ie ""), which evaluates to false |
|
383 | - // so we need to treat the empty string as if nothing had been passed, and should instead use the default |
|
384 | - $verify_schema = true; |
|
385 | - } |
|
386 | - if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
387 | - if ($verify_schema) { |
|
388 | - $this->initialize_db(); |
|
389 | - } |
|
390 | - $this->initialize_default_data(); |
|
391 | - // @todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe |
|
392 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
393 | - array( |
|
394 | - 'slug' => $this->name(), |
|
395 | - 'version' => $this->version(), |
|
396 | - ) |
|
397 | - ); |
|
398 | - /* make sure core's data is a-ok |
|
22 | + /** |
|
23 | + * prefix to be added onto an addon's plugin slug to make a wp option name |
|
24 | + * which will be used to store the plugin's activation history |
|
25 | + */ |
|
26 | + const ee_addon_version_history_option_prefix = 'ee_version_history_'; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var $_version |
|
30 | + * @type string |
|
31 | + */ |
|
32 | + protected $_version = ''; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var $_min_core_version |
|
36 | + * @type string |
|
37 | + */ |
|
38 | + protected $_min_core_version = ''; |
|
39 | + |
|
40 | + /** |
|
41 | + * derived from plugin 'main_file_path using plugin_basename() |
|
42 | + * |
|
43 | + * @type string $_plugin_basename |
|
44 | + */ |
|
45 | + protected $_plugin_basename = ''; |
|
46 | + |
|
47 | + /** |
|
48 | + * A non-internationalized name to identify this addon for use in URLs, etc |
|
49 | + * |
|
50 | + * @type string $_plugin_slug |
|
51 | + */ |
|
52 | + protected $_plugin_slug = ''; |
|
53 | + |
|
54 | + /** |
|
55 | + * A non-internationalized name to identify this addon. Eg 'Calendar','MailChimp',etc/ |
|
56 | + * |
|
57 | + * @type string _addon_name |
|
58 | + */ |
|
59 | + protected $_addon_name = ''; |
|
60 | + |
|
61 | + /** |
|
62 | + * one of the EE_System::req_type_* constants |
|
63 | + * |
|
64 | + * @type int $_req_type |
|
65 | + */ |
|
66 | + protected $_req_type; |
|
67 | + |
|
68 | + /** |
|
69 | + * page slug to be used when generating the "Settings" link on the WP plugin page |
|
70 | + * |
|
71 | + * @type string $_plugin_action_slug |
|
72 | + */ |
|
73 | + protected $_plugin_action_slug = ''; |
|
74 | + |
|
75 | + /** |
|
76 | + * if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
77 | + * that can be used for adding upgrading/marketing info |
|
78 | + * |
|
79 | + * @type array $_plugins_page_row |
|
80 | + */ |
|
81 | + protected $_plugins_page_row = array(); |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * filepath to the main file, which can be used for register_activation_hook, register_deactivation_hook, etc. |
|
86 | + * |
|
87 | + * @type string |
|
88 | + */ |
|
89 | + protected $_main_plugin_file; |
|
90 | + |
|
91 | + /** |
|
92 | + * This is the slug used to identify this add-on within the plugin update engine. |
|
93 | + * |
|
94 | + * @type string |
|
95 | + */ |
|
96 | + protected $pue_slug; |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * @var EE_Dependency_Map $dependency_map |
|
101 | + */ |
|
102 | + private $dependency_map; |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @var DomainInterface $domain |
|
107 | + */ |
|
108 | + private $domain; |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * @param EE_Dependency_Map $dependency_map [optional] |
|
113 | + * @param DomainInterface $domain [optional] |
|
114 | + */ |
|
115 | + public function __construct(EE_Dependency_Map $dependency_map = null, DomainInterface $domain = null) |
|
116 | + { |
|
117 | + if ($dependency_map instanceof EE_Dependency_Map) { |
|
118 | + $this->setDependencyMap($dependency_map); |
|
119 | + } |
|
120 | + if ($domain instanceof DomainInterface) { |
|
121 | + $this->setDomain($domain); |
|
122 | + } |
|
123 | + add_action('AHEE__EE_System__load_controllers__load_admin_controllers', array($this, 'admin_init')); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @param EE_Dependency_Map $dependency_map |
|
129 | + */ |
|
130 | + public function setDependencyMap($dependency_map) |
|
131 | + { |
|
132 | + $this->dependency_map = $dependency_map; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @return EE_Dependency_Map |
|
138 | + */ |
|
139 | + public function dependencyMap() |
|
140 | + { |
|
141 | + return $this->dependency_map; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @param DomainInterface $domain |
|
147 | + */ |
|
148 | + public function setDomain(DomainInterface $domain) |
|
149 | + { |
|
150 | + $this->domain = $domain; |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * @return DomainInterface |
|
155 | + */ |
|
156 | + public function domain() |
|
157 | + { |
|
158 | + return $this->domain; |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * @param mixed $version |
|
164 | + */ |
|
165 | + public function set_version($version = null) |
|
166 | + { |
|
167 | + $this->_version = $version; |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * get__version |
|
173 | + * |
|
174 | + * @return string |
|
175 | + */ |
|
176 | + public function version() |
|
177 | + { |
|
178 | + return $this->_version; |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * @param mixed $min_core_version |
|
184 | + */ |
|
185 | + public function set_min_core_version($min_core_version = null) |
|
186 | + { |
|
187 | + $this->_min_core_version = $min_core_version; |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * get__min_core_version |
|
193 | + * |
|
194 | + * @return string |
|
195 | + */ |
|
196 | + public function min_core_version() |
|
197 | + { |
|
198 | + return $this->_min_core_version; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * Sets addon_name |
|
204 | + * |
|
205 | + * @param string $addon_name |
|
206 | + * @return boolean |
|
207 | + */ |
|
208 | + public function set_name($addon_name) |
|
209 | + { |
|
210 | + return $this->_addon_name = $addon_name; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * Gets addon_name |
|
216 | + * |
|
217 | + * @return string |
|
218 | + */ |
|
219 | + public function name() |
|
220 | + { |
|
221 | + return $this->_addon_name; |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * @return string |
|
227 | + */ |
|
228 | + public function plugin_basename() |
|
229 | + { |
|
230 | + |
|
231 | + return $this->_plugin_basename; |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * @param string $plugin_basename |
|
237 | + */ |
|
238 | + public function set_plugin_basename($plugin_basename) |
|
239 | + { |
|
240 | + |
|
241 | + $this->_plugin_basename = $plugin_basename; |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * @return string |
|
247 | + */ |
|
248 | + public function plugin_slug() |
|
249 | + { |
|
250 | + |
|
251 | + return $this->_plugin_slug; |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * @param string $plugin_slug |
|
257 | + */ |
|
258 | + public function set_plugin_slug($plugin_slug) |
|
259 | + { |
|
260 | + |
|
261 | + $this->_plugin_slug = $plugin_slug; |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @return string |
|
267 | + */ |
|
268 | + public function plugin_action_slug() |
|
269 | + { |
|
270 | + |
|
271 | + return $this->_plugin_action_slug; |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * @param string $plugin_action_slug |
|
277 | + */ |
|
278 | + public function set_plugin_action_slug($plugin_action_slug) |
|
279 | + { |
|
280 | + |
|
281 | + $this->_plugin_action_slug = $plugin_action_slug; |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * @return array |
|
287 | + */ |
|
288 | + public function get_plugins_page_row() |
|
289 | + { |
|
290 | + |
|
291 | + return $this->_plugins_page_row; |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * @param array $plugins_page_row |
|
297 | + */ |
|
298 | + public function set_plugins_page_row($plugins_page_row = array()) |
|
299 | + { |
|
300 | + // sigh.... check for example content that I stupidly merged to master and remove it if found |
|
301 | + if (! is_array($plugins_page_row) |
|
302 | + && strpos($plugins_page_row, '<h3>Promotions Addon Upsell Info</h3>') !== false |
|
303 | + ) { |
|
304 | + $plugins_page_row = array(); |
|
305 | + } |
|
306 | + $this->_plugins_page_row = (array) $plugins_page_row; |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * Called when EE core detects this addon has been activated for the first time. |
|
312 | + * If the site isn't in maintenance mode, should setup the addon's database |
|
313 | + * |
|
314 | + * @return void |
|
315 | + */ |
|
316 | + public function new_install() |
|
317 | + { |
|
318 | + $classname = get_class($this); |
|
319 | + do_action("AHEE__{$classname}__new_install"); |
|
320 | + do_action('AHEE__EE_Addon__new_install', $this); |
|
321 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
322 | + add_action( |
|
323 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
324 | + array($this, 'initialize_db_if_no_migrations_required') |
|
325 | + ); |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * Called when EE core detects this addon has been reactivated. When this happens, |
|
331 | + * it's good to just check that your data is still intact |
|
332 | + * |
|
333 | + * @return void |
|
334 | + */ |
|
335 | + public function reactivation() |
|
336 | + { |
|
337 | + $classname = get_class($this); |
|
338 | + do_action("AHEE__{$classname}__reactivation"); |
|
339 | + do_action('AHEE__EE_Addon__reactivation', $this); |
|
340 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
341 | + add_action( |
|
342 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
343 | + array($this, 'initialize_db_if_no_migrations_required') |
|
344 | + ); |
|
345 | + } |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * Called when the registered deactivation hook for this addon fires. |
|
350 | + * |
|
351 | + * @throws EE_Error |
|
352 | + */ |
|
353 | + public function deactivation() |
|
354 | + { |
|
355 | + $classname = get_class($this); |
|
356 | + do_action("AHEE__{$classname}__deactivation"); |
|
357 | + do_action('AHEE__EE_Addon__deactivation', $this); |
|
358 | + // check if the site no longer needs to be in maintenance mode |
|
359 | + EE_Register_Addon::deregister($this->name()); |
|
360 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * Takes care of double-checking that we're not in maintenance mode, and then |
|
366 | + * initializing this addon's necessary initial data. This is called by default on new activations |
|
367 | + * and reactivations. |
|
368 | + * |
|
369 | + * @param boolean $verify_schema whether to verify the database's schema for this addon, or just its data. |
|
370 | + * This is a resource-intensive job so we prefer to only do it when necessary |
|
371 | + * @return void |
|
372 | + * @throws \EE_Error |
|
373 | + * @throws InvalidInterfaceException |
|
374 | + * @throws InvalidDataTypeException |
|
375 | + * @throws InvalidArgumentException |
|
376 | + */ |
|
377 | + public function initialize_db_if_no_migrations_required($verify_schema = true) |
|
378 | + { |
|
379 | + if ($verify_schema === '') { |
|
380 | + // wp core bug imo: if no args are passed to `do_action('some_hook_name')` besides the hook's name |
|
381 | + // (ie, no 2nd or 3rd arguments), instead of calling the registered callbacks with no arguments, it |
|
382 | + // calls them with an argument of an empty string (ie ""), which evaluates to false |
|
383 | + // so we need to treat the empty string as if nothing had been passed, and should instead use the default |
|
384 | + $verify_schema = true; |
|
385 | + } |
|
386 | + if (EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
387 | + if ($verify_schema) { |
|
388 | + $this->initialize_db(); |
|
389 | + } |
|
390 | + $this->initialize_default_data(); |
|
391 | + // @todo: this will probably need to be adjusted in 4.4 as the array changed formats I believe |
|
392 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
393 | + array( |
|
394 | + 'slug' => $this->name(), |
|
395 | + 'version' => $this->version(), |
|
396 | + ) |
|
397 | + ); |
|
398 | + /* make sure core's data is a-ok |
|
399 | 399 | * (at the time of writing, we especially want to verify all the caps are present |
400 | 400 | * because payment method type capabilities are added dynamically, and it's |
401 | 401 | * possible this addon added a payment method. But it's also possible |
402 | 402 | * other data needs to be verified) |
403 | 403 | */ |
404 | - EEH_Activation::initialize_db_content(); |
|
405 | - /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
406 | - $rewrite_rules = LoaderFactory::getLoader()->getShared( |
|
407 | - 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
408 | - ); |
|
409 | - $rewrite_rules->flushRewriteRules(); |
|
410 | - // in case there are lots of addons being activated at once, let's force garbage collection |
|
411 | - // to help avoid memory limit errors |
|
412 | - // EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true ); |
|
413 | - gc_collect_cycles(); |
|
414 | - } else { |
|
415 | - // ask the data migration manager to init this addon's data |
|
416 | - // when migrations are finished because we can't do it now |
|
417 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name()); |
|
418 | - } |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * Used to setup this addon's database tables, but not necessarily any default |
|
424 | - * data in them. The default is to actually use the most up-to-date data migration script |
|
425 | - * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration() |
|
426 | - * methods to setup the db. |
|
427 | - */ |
|
428 | - public function initialize_db() |
|
429 | - { |
|
430 | - // find the migration script that sets the database to be compatible with the code |
|
431 | - $current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name()); |
|
432 | - if ($current_dms_name) { |
|
433 | - $current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name); |
|
434 | - $current_data_migration_script->set_migrating(false); |
|
435 | - $current_data_migration_script->schema_changes_before_migration(); |
|
436 | - $current_data_migration_script->schema_changes_after_migration(); |
|
437 | - if ($current_data_migration_script->get_errors()) { |
|
438 | - foreach ($current_data_migration_script->get_errors() as $error) { |
|
439 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
440 | - } |
|
441 | - } |
|
442 | - } |
|
443 | - // if not DMS was found that should be ok. This addon just doesn't require any database changes |
|
444 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
445 | - array( |
|
446 | - 'slug' => $this->name(), |
|
447 | - 'version' => $this->version(), |
|
448 | - ) |
|
449 | - ); |
|
450 | - } |
|
451 | - |
|
452 | - |
|
453 | - /** |
|
454 | - * If you want to setup default data for the addon, override this method, and call |
|
455 | - * parent::initialize_default_data() from within it. This is normally called |
|
456 | - * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db() |
|
457 | - * and should verify default data is present (but this is also called |
|
458 | - * on reactivations and just after migrations, so please verify you actually want |
|
459 | - * to ADD default data, because it may already be present). |
|
460 | - * However, please call this parent (currently it just fires a hook which other |
|
461 | - * addons may be depending on) |
|
462 | - */ |
|
463 | - public function initialize_default_data() |
|
464 | - { |
|
465 | - /** |
|
466 | - * Called when an addon is ensuring its default data is set (possibly called |
|
467 | - * on a reactivation, so first check for the absence of other data before setting |
|
468 | - * default data) |
|
469 | - * |
|
470 | - * @param EE_Addon $addon the addon that called this |
|
471 | - */ |
|
472 | - do_action('AHEE__EE_Addon__initialize_default_data__begin', $this); |
|
473 | - // override to insert default data. It is safe to use the models here |
|
474 | - // because the site should not be in maintenance mode |
|
475 | - } |
|
476 | - |
|
477 | - |
|
478 | - /** |
|
479 | - * EE Core detected that this addon has been upgraded. We should check if there |
|
480 | - * are any new migration scripts, and if so put the site into maintenance mode until |
|
481 | - * they're ran |
|
482 | - * |
|
483 | - * @return void |
|
484 | - */ |
|
485 | - public function upgrade() |
|
486 | - { |
|
487 | - $classname = get_class($this); |
|
488 | - do_action("AHEE__{$classname}__upgrade"); |
|
489 | - do_action('AHEE__EE_Addon__upgrade', $this); |
|
490 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
491 | - // also it's possible there is new default data that needs to be added |
|
492 | - add_action( |
|
493 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
494 | - array($this, 'initialize_db_if_no_migrations_required') |
|
495 | - ); |
|
496 | - } |
|
497 | - |
|
498 | - |
|
499 | - /** |
|
500 | - * If Core detects this addon has been downgraded, you may want to invoke some special logic here. |
|
501 | - */ |
|
502 | - public function downgrade() |
|
503 | - { |
|
504 | - $classname = get_class($this); |
|
505 | - do_action("AHEE__{$classname}__downgrade"); |
|
506 | - do_action('AHEE__EE_Addon__downgrade', $this); |
|
507 | - // it's possible there's old default data that needs to be double-checked |
|
508 | - add_action( |
|
509 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
510 | - array($this, 'initialize_db_if_no_migrations_required') |
|
511 | - ); |
|
512 | - } |
|
513 | - |
|
514 | - |
|
515 | - /** |
|
516 | - * set_db_update_option_name |
|
517 | - * Until we do something better, we'll just check for migration scripts upon |
|
518 | - * plugin activation only. In the future, we'll want to do it on plugin updates too |
|
519 | - * |
|
520 | - * @return bool |
|
521 | - */ |
|
522 | - public function set_db_update_option_name() |
|
523 | - { |
|
524 | - EE_Error::doing_it_wrong( |
|
525 | - __FUNCTION__, |
|
526 | - esc_html__( |
|
527 | - 'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option', |
|
528 | - 'event_espresso' |
|
529 | - ), |
|
530 | - '4.3.0.alpha.016' |
|
531 | - ); |
|
532 | - // let's just handle this on the next request, ok? right now we're just not really ready |
|
533 | - return $this->set_activation_indicator_option(); |
|
534 | - } |
|
535 | - |
|
536 | - |
|
537 | - /** |
|
538 | - * Returns the name of the activation indicator option |
|
539 | - * (an option which is set temporarily to indicate that this addon was just activated) |
|
540 | - * |
|
541 | - * @deprecated since version 4.3.0.alpha.016 |
|
542 | - * @return string |
|
543 | - */ |
|
544 | - public function get_db_update_option_name() |
|
545 | - { |
|
546 | - EE_Error::doing_it_wrong( |
|
547 | - __FUNCTION__, |
|
548 | - esc_html__( |
|
549 | - 'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name', |
|
550 | - 'event_espresso' |
|
551 | - ), |
|
552 | - '4.3.0.alpha.016' |
|
553 | - ); |
|
554 | - return $this->get_activation_indicator_option_name(); |
|
555 | - } |
|
556 | - |
|
557 | - |
|
558 | - /** |
|
559 | - * When the addon is activated, this should be called to set a wordpress option that |
|
560 | - * indicates it was activated. This is especially useful for detecting reactivations. |
|
561 | - * |
|
562 | - * @return bool |
|
563 | - */ |
|
564 | - public function set_activation_indicator_option() |
|
565 | - { |
|
566 | - // let's just handle this on the next request, ok? right now we're just not really ready |
|
567 | - return update_option($this->get_activation_indicator_option_name(), true); |
|
568 | - } |
|
569 | - |
|
570 | - |
|
571 | - /** |
|
572 | - * Gets the name of the wp option which is used to temporarily indicate that this addon was activated |
|
573 | - * |
|
574 | - * @return string |
|
575 | - */ |
|
576 | - public function get_activation_indicator_option_name() |
|
577 | - { |
|
578 | - return 'ee_activation_' . $this->name(); |
|
579 | - } |
|
580 | - |
|
581 | - |
|
582 | - /** |
|
583 | - * Used by EE_System to set the request type of this addon. Should not be used by addon developers |
|
584 | - * |
|
585 | - * @param int $req_type |
|
586 | - */ |
|
587 | - public function set_req_type($req_type) |
|
588 | - { |
|
589 | - $this->_req_type = $req_type; |
|
590 | - } |
|
591 | - |
|
592 | - |
|
593 | - /** |
|
594 | - * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation, |
|
595 | - * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by |
|
596 | - * EE_System when it is checking for new install or upgrades of addons |
|
597 | - */ |
|
598 | - public function detect_req_type() |
|
599 | - { |
|
600 | - if (! $this->_req_type) { |
|
601 | - $this->detect_activation_or_upgrade(); |
|
602 | - } |
|
603 | - return $this->_req_type; |
|
604 | - } |
|
605 | - |
|
606 | - |
|
607 | - /** |
|
608 | - * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.) |
|
609 | - * Should only be called once per request |
|
610 | - * |
|
611 | - * @return void |
|
612 | - */ |
|
613 | - public function detect_activation_or_upgrade() |
|
614 | - { |
|
615 | - $activation_history_for_addon = $this->get_activation_history(); |
|
616 | - $request_type = EE_System::detect_req_type_given_activation_history( |
|
617 | - $activation_history_for_addon, |
|
618 | - $this->get_activation_indicator_option_name(), |
|
619 | - $this->version() |
|
620 | - ); |
|
621 | - $this->set_req_type($request_type); |
|
622 | - $classname = get_class($this); |
|
623 | - switch ($request_type) { |
|
624 | - case EE_System::req_type_new_activation: |
|
625 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation"); |
|
626 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this); |
|
627 | - $this->new_install(); |
|
628 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
629 | - break; |
|
630 | - case EE_System::req_type_reactivation: |
|
631 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation"); |
|
632 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this); |
|
633 | - $this->reactivation(); |
|
634 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
635 | - break; |
|
636 | - case EE_System::req_type_upgrade: |
|
637 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade"); |
|
638 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this); |
|
639 | - $this->upgrade(); |
|
640 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
641 | - break; |
|
642 | - case EE_System::req_type_downgrade: |
|
643 | - do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade"); |
|
644 | - do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this); |
|
645 | - $this->downgrade(); |
|
646 | - $this->update_list_of_installed_versions($activation_history_for_addon); |
|
647 | - break; |
|
648 | - case EE_System::req_type_normal: |
|
649 | - default: |
|
650 | - break; |
|
651 | - } |
|
652 | - |
|
653 | - do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete"); |
|
654 | - } |
|
655 | - |
|
656 | - /** |
|
657 | - * Updates the version history for this addon |
|
658 | - * |
|
659 | - * @param array $version_history |
|
660 | - * @param string $current_version_to_add |
|
661 | - * @return boolean success |
|
662 | - */ |
|
663 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
664 | - { |
|
665 | - if (! $version_history) { |
|
666 | - $version_history = $this->get_activation_history(); |
|
667 | - } |
|
668 | - if ($current_version_to_add === null) { |
|
669 | - $current_version_to_add = $this->version(); |
|
670 | - } |
|
671 | - $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
672 | - // resave |
|
673 | - return update_option($this->get_activation_history_option_name(), $version_history); |
|
674 | - } |
|
675 | - |
|
676 | - /** |
|
677 | - * Gets the name of the wp option that stores the activation history |
|
678 | - * of this addon |
|
679 | - * |
|
680 | - * @return string |
|
681 | - */ |
|
682 | - public function get_activation_history_option_name() |
|
683 | - { |
|
684 | - return self::ee_addon_version_history_option_prefix . $this->name(); |
|
685 | - } |
|
686 | - |
|
687 | - |
|
688 | - /** |
|
689 | - * Gets the wp option which stores the activation history for this addon |
|
690 | - * |
|
691 | - * @return array |
|
692 | - */ |
|
693 | - public function get_activation_history() |
|
694 | - { |
|
695 | - return get_option($this->get_activation_history_option_name(), null); |
|
696 | - } |
|
697 | - |
|
698 | - |
|
699 | - /** |
|
700 | - * @param string $config_section |
|
701 | - */ |
|
702 | - public function set_config_section($config_section = '') |
|
703 | - { |
|
704 | - $this->_config_section = ! empty($config_section) ? $config_section : 'addons'; |
|
705 | - } |
|
706 | - |
|
707 | - /** |
|
708 | - * Sets the filepath to the main plugin file |
|
709 | - * |
|
710 | - * @param string $filepath |
|
711 | - */ |
|
712 | - public function set_main_plugin_file($filepath) |
|
713 | - { |
|
714 | - $this->_main_plugin_file = $filepath; |
|
715 | - } |
|
716 | - |
|
717 | - /** |
|
718 | - * gets the filepath to teh main file |
|
719 | - * |
|
720 | - * @return string |
|
721 | - */ |
|
722 | - public function get_main_plugin_file() |
|
723 | - { |
|
724 | - return $this->_main_plugin_file; |
|
725 | - } |
|
726 | - |
|
727 | - /** |
|
728 | - * Gets the filename (no path) of the main file (the main file loaded |
|
729 | - * by WP) |
|
730 | - * |
|
731 | - * @return string |
|
732 | - */ |
|
733 | - public function get_main_plugin_file_basename() |
|
734 | - { |
|
735 | - return plugin_basename($this->get_main_plugin_file()); |
|
736 | - } |
|
737 | - |
|
738 | - /** |
|
739 | - * Gets the folder name which contains the main plugin file |
|
740 | - * |
|
741 | - * @return string |
|
742 | - */ |
|
743 | - public function get_main_plugin_file_dirname() |
|
744 | - { |
|
745 | - return dirname($this->get_main_plugin_file()); |
|
746 | - } |
|
747 | - |
|
748 | - |
|
749 | - /** |
|
750 | - * sets hooks used in the admin |
|
751 | - * |
|
752 | - * @return void |
|
753 | - */ |
|
754 | - public function admin_init() |
|
755 | - { |
|
756 | - // is admin and not in M-Mode ? |
|
757 | - if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
758 | - add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2); |
|
759 | - add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3); |
|
760 | - } |
|
761 | - } |
|
762 | - |
|
763 | - |
|
764 | - /** |
|
765 | - * plugin_actions |
|
766 | - * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page. |
|
767 | - * |
|
768 | - * @param $links |
|
769 | - * @param $file |
|
770 | - * @return array |
|
771 | - */ |
|
772 | - public function plugin_action_links($links, $file) |
|
773 | - { |
|
774 | - if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') { |
|
775 | - // before other links |
|
776 | - array_unshift( |
|
777 | - $links, |
|
778 | - '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' |
|
779 | - . esc_html__('Settings', 'event_espresso') |
|
780 | - . '</a>' |
|
781 | - ); |
|
782 | - } |
|
783 | - return $links; |
|
784 | - } |
|
785 | - |
|
786 | - |
|
787 | - /** |
|
788 | - * after_plugin_row |
|
789 | - * Add additional content to the plugins page plugin row |
|
790 | - * Inserts another row |
|
791 | - * |
|
792 | - * @param $plugin_file |
|
793 | - * @param $plugin_data |
|
794 | - * @param $status |
|
795 | - * @return void |
|
796 | - */ |
|
797 | - public function after_plugin_row($plugin_file, $plugin_data, $status) |
|
798 | - { |
|
799 | - $after_plugin_row = ''; |
|
800 | - $plugins_page_row = $this->get_plugins_page_row(); |
|
801 | - if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) { |
|
802 | - $class = $status ? 'active' : 'inactive'; |
|
803 | - $link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : ''; |
|
804 | - $link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : ''; |
|
805 | - $description = isset($plugins_page_row['description']) |
|
806 | - ? $plugins_page_row['description'] |
|
807 | - : ''; |
|
808 | - if (! empty($link_text) && ! empty($link_url) && ! empty($description)) { |
|
809 | - $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">'; |
|
810 | - $after_plugin_row .= '<th class="check-column" scope="row"></th>'; |
|
811 | - $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">'; |
|
812 | - $after_plugin_row .= '<style> |
|
404 | + EEH_Activation::initialize_db_content(); |
|
405 | + /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
406 | + $rewrite_rules = LoaderFactory::getLoader()->getShared( |
|
407 | + 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
408 | + ); |
|
409 | + $rewrite_rules->flushRewriteRules(); |
|
410 | + // in case there are lots of addons being activated at once, let's force garbage collection |
|
411 | + // to help avoid memory limit errors |
|
412 | + // EEH_Debug_Tools::instance()->measure_memory( 'db content initialized for ' . get_class( $this), true ); |
|
413 | + gc_collect_cycles(); |
|
414 | + } else { |
|
415 | + // ask the data migration manager to init this addon's data |
|
416 | + // when migrations are finished because we can't do it now |
|
417 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for($this->name()); |
|
418 | + } |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * Used to setup this addon's database tables, but not necessarily any default |
|
424 | + * data in them. The default is to actually use the most up-to-date data migration script |
|
425 | + * for this addon, and just use its schema_changes_before_migration() and schema_changes_after_migration() |
|
426 | + * methods to setup the db. |
|
427 | + */ |
|
428 | + public function initialize_db() |
|
429 | + { |
|
430 | + // find the migration script that sets the database to be compatible with the code |
|
431 | + $current_dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms($this->name()); |
|
432 | + if ($current_dms_name) { |
|
433 | + $current_data_migration_script = EE_Registry::instance()->load_dms($current_dms_name); |
|
434 | + $current_data_migration_script->set_migrating(false); |
|
435 | + $current_data_migration_script->schema_changes_before_migration(); |
|
436 | + $current_data_migration_script->schema_changes_after_migration(); |
|
437 | + if ($current_data_migration_script->get_errors()) { |
|
438 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
439 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
440 | + } |
|
441 | + } |
|
442 | + } |
|
443 | + // if not DMS was found that should be ok. This addon just doesn't require any database changes |
|
444 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to( |
|
445 | + array( |
|
446 | + 'slug' => $this->name(), |
|
447 | + 'version' => $this->version(), |
|
448 | + ) |
|
449 | + ); |
|
450 | + } |
|
451 | + |
|
452 | + |
|
453 | + /** |
|
454 | + * If you want to setup default data for the addon, override this method, and call |
|
455 | + * parent::initialize_default_data() from within it. This is normally called |
|
456 | + * from EE_Addon::initialize_db_if_no_migrations_required(), just after EE_Addon::initialize_db() |
|
457 | + * and should verify default data is present (but this is also called |
|
458 | + * on reactivations and just after migrations, so please verify you actually want |
|
459 | + * to ADD default data, because it may already be present). |
|
460 | + * However, please call this parent (currently it just fires a hook which other |
|
461 | + * addons may be depending on) |
|
462 | + */ |
|
463 | + public function initialize_default_data() |
|
464 | + { |
|
465 | + /** |
|
466 | + * Called when an addon is ensuring its default data is set (possibly called |
|
467 | + * on a reactivation, so first check for the absence of other data before setting |
|
468 | + * default data) |
|
469 | + * |
|
470 | + * @param EE_Addon $addon the addon that called this |
|
471 | + */ |
|
472 | + do_action('AHEE__EE_Addon__initialize_default_data__begin', $this); |
|
473 | + // override to insert default data. It is safe to use the models here |
|
474 | + // because the site should not be in maintenance mode |
|
475 | + } |
|
476 | + |
|
477 | + |
|
478 | + /** |
|
479 | + * EE Core detected that this addon has been upgraded. We should check if there |
|
480 | + * are any new migration scripts, and if so put the site into maintenance mode until |
|
481 | + * they're ran |
|
482 | + * |
|
483 | + * @return void |
|
484 | + */ |
|
485 | + public function upgrade() |
|
486 | + { |
|
487 | + $classname = get_class($this); |
|
488 | + do_action("AHEE__{$classname}__upgrade"); |
|
489 | + do_action('AHEE__EE_Addon__upgrade', $this); |
|
490 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
491 | + // also it's possible there is new default data that needs to be added |
|
492 | + add_action( |
|
493 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
494 | + array($this, 'initialize_db_if_no_migrations_required') |
|
495 | + ); |
|
496 | + } |
|
497 | + |
|
498 | + |
|
499 | + /** |
|
500 | + * If Core detects this addon has been downgraded, you may want to invoke some special logic here. |
|
501 | + */ |
|
502 | + public function downgrade() |
|
503 | + { |
|
504 | + $classname = get_class($this); |
|
505 | + do_action("AHEE__{$classname}__downgrade"); |
|
506 | + do_action('AHEE__EE_Addon__downgrade', $this); |
|
507 | + // it's possible there's old default data that needs to be double-checked |
|
508 | + add_action( |
|
509 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
510 | + array($this, 'initialize_db_if_no_migrations_required') |
|
511 | + ); |
|
512 | + } |
|
513 | + |
|
514 | + |
|
515 | + /** |
|
516 | + * set_db_update_option_name |
|
517 | + * Until we do something better, we'll just check for migration scripts upon |
|
518 | + * plugin activation only. In the future, we'll want to do it on plugin updates too |
|
519 | + * |
|
520 | + * @return bool |
|
521 | + */ |
|
522 | + public function set_db_update_option_name() |
|
523 | + { |
|
524 | + EE_Error::doing_it_wrong( |
|
525 | + __FUNCTION__, |
|
526 | + esc_html__( |
|
527 | + 'EE_Addon::set_db_update_option_name was renamed to EE_Addon::set_activation_indicator_option', |
|
528 | + 'event_espresso' |
|
529 | + ), |
|
530 | + '4.3.0.alpha.016' |
|
531 | + ); |
|
532 | + // let's just handle this on the next request, ok? right now we're just not really ready |
|
533 | + return $this->set_activation_indicator_option(); |
|
534 | + } |
|
535 | + |
|
536 | + |
|
537 | + /** |
|
538 | + * Returns the name of the activation indicator option |
|
539 | + * (an option which is set temporarily to indicate that this addon was just activated) |
|
540 | + * |
|
541 | + * @deprecated since version 4.3.0.alpha.016 |
|
542 | + * @return string |
|
543 | + */ |
|
544 | + public function get_db_update_option_name() |
|
545 | + { |
|
546 | + EE_Error::doing_it_wrong( |
|
547 | + __FUNCTION__, |
|
548 | + esc_html__( |
|
549 | + 'EE_Addon::get_db_update_option was renamed to EE_Addon::get_activation_indicator_option_name', |
|
550 | + 'event_espresso' |
|
551 | + ), |
|
552 | + '4.3.0.alpha.016' |
|
553 | + ); |
|
554 | + return $this->get_activation_indicator_option_name(); |
|
555 | + } |
|
556 | + |
|
557 | + |
|
558 | + /** |
|
559 | + * When the addon is activated, this should be called to set a wordpress option that |
|
560 | + * indicates it was activated. This is especially useful for detecting reactivations. |
|
561 | + * |
|
562 | + * @return bool |
|
563 | + */ |
|
564 | + public function set_activation_indicator_option() |
|
565 | + { |
|
566 | + // let's just handle this on the next request, ok? right now we're just not really ready |
|
567 | + return update_option($this->get_activation_indicator_option_name(), true); |
|
568 | + } |
|
569 | + |
|
570 | + |
|
571 | + /** |
|
572 | + * Gets the name of the wp option which is used to temporarily indicate that this addon was activated |
|
573 | + * |
|
574 | + * @return string |
|
575 | + */ |
|
576 | + public function get_activation_indicator_option_name() |
|
577 | + { |
|
578 | + return 'ee_activation_' . $this->name(); |
|
579 | + } |
|
580 | + |
|
581 | + |
|
582 | + /** |
|
583 | + * Used by EE_System to set the request type of this addon. Should not be used by addon developers |
|
584 | + * |
|
585 | + * @param int $req_type |
|
586 | + */ |
|
587 | + public function set_req_type($req_type) |
|
588 | + { |
|
589 | + $this->_req_type = $req_type; |
|
590 | + } |
|
591 | + |
|
592 | + |
|
593 | + /** |
|
594 | + * Returns the request type of this addon (ie, EE_System::req_type_normal, EE_System::req_type_new_activation, |
|
595 | + * EE_System::req_type_reactivation, EE_System::req_type_upgrade, or EE_System::req_type_downgrade). This is set by |
|
596 | + * EE_System when it is checking for new install or upgrades of addons |
|
597 | + */ |
|
598 | + public function detect_req_type() |
|
599 | + { |
|
600 | + if (! $this->_req_type) { |
|
601 | + $this->detect_activation_or_upgrade(); |
|
602 | + } |
|
603 | + return $this->_req_type; |
|
604 | + } |
|
605 | + |
|
606 | + |
|
607 | + /** |
|
608 | + * Detects the request type for this addon (whether it was just activated, upgrades, a normal request, etc.) |
|
609 | + * Should only be called once per request |
|
610 | + * |
|
611 | + * @return void |
|
612 | + */ |
|
613 | + public function detect_activation_or_upgrade() |
|
614 | + { |
|
615 | + $activation_history_for_addon = $this->get_activation_history(); |
|
616 | + $request_type = EE_System::detect_req_type_given_activation_history( |
|
617 | + $activation_history_for_addon, |
|
618 | + $this->get_activation_indicator_option_name(), |
|
619 | + $this->version() |
|
620 | + ); |
|
621 | + $this->set_req_type($request_type); |
|
622 | + $classname = get_class($this); |
|
623 | + switch ($request_type) { |
|
624 | + case EE_System::req_type_new_activation: |
|
625 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__new_activation"); |
|
626 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__new_activation', $this); |
|
627 | + $this->new_install(); |
|
628 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
629 | + break; |
|
630 | + case EE_System::req_type_reactivation: |
|
631 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__reactivation"); |
|
632 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__reactivation', $this); |
|
633 | + $this->reactivation(); |
|
634 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
635 | + break; |
|
636 | + case EE_System::req_type_upgrade: |
|
637 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__upgrade"); |
|
638 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__upgrade', $this); |
|
639 | + $this->upgrade(); |
|
640 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
641 | + break; |
|
642 | + case EE_System::req_type_downgrade: |
|
643 | + do_action("AHEE__{$classname}__detect_activations_or_upgrades__downgrade"); |
|
644 | + do_action('AHEE__EE_Addon__detect_activations_or_upgrades__downgrade', $this); |
|
645 | + $this->downgrade(); |
|
646 | + $this->update_list_of_installed_versions($activation_history_for_addon); |
|
647 | + break; |
|
648 | + case EE_System::req_type_normal: |
|
649 | + default: |
|
650 | + break; |
|
651 | + } |
|
652 | + |
|
653 | + do_action("AHEE__{$classname}__detect_if_activation_or_upgrade__complete"); |
|
654 | + } |
|
655 | + |
|
656 | + /** |
|
657 | + * Updates the version history for this addon |
|
658 | + * |
|
659 | + * @param array $version_history |
|
660 | + * @param string $current_version_to_add |
|
661 | + * @return boolean success |
|
662 | + */ |
|
663 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
664 | + { |
|
665 | + if (! $version_history) { |
|
666 | + $version_history = $this->get_activation_history(); |
|
667 | + } |
|
668 | + if ($current_version_to_add === null) { |
|
669 | + $current_version_to_add = $this->version(); |
|
670 | + } |
|
671 | + $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
672 | + // resave |
|
673 | + return update_option($this->get_activation_history_option_name(), $version_history); |
|
674 | + } |
|
675 | + |
|
676 | + /** |
|
677 | + * Gets the name of the wp option that stores the activation history |
|
678 | + * of this addon |
|
679 | + * |
|
680 | + * @return string |
|
681 | + */ |
|
682 | + public function get_activation_history_option_name() |
|
683 | + { |
|
684 | + return self::ee_addon_version_history_option_prefix . $this->name(); |
|
685 | + } |
|
686 | + |
|
687 | + |
|
688 | + /** |
|
689 | + * Gets the wp option which stores the activation history for this addon |
|
690 | + * |
|
691 | + * @return array |
|
692 | + */ |
|
693 | + public function get_activation_history() |
|
694 | + { |
|
695 | + return get_option($this->get_activation_history_option_name(), null); |
|
696 | + } |
|
697 | + |
|
698 | + |
|
699 | + /** |
|
700 | + * @param string $config_section |
|
701 | + */ |
|
702 | + public function set_config_section($config_section = '') |
|
703 | + { |
|
704 | + $this->_config_section = ! empty($config_section) ? $config_section : 'addons'; |
|
705 | + } |
|
706 | + |
|
707 | + /** |
|
708 | + * Sets the filepath to the main plugin file |
|
709 | + * |
|
710 | + * @param string $filepath |
|
711 | + */ |
|
712 | + public function set_main_plugin_file($filepath) |
|
713 | + { |
|
714 | + $this->_main_plugin_file = $filepath; |
|
715 | + } |
|
716 | + |
|
717 | + /** |
|
718 | + * gets the filepath to teh main file |
|
719 | + * |
|
720 | + * @return string |
|
721 | + */ |
|
722 | + public function get_main_plugin_file() |
|
723 | + { |
|
724 | + return $this->_main_plugin_file; |
|
725 | + } |
|
726 | + |
|
727 | + /** |
|
728 | + * Gets the filename (no path) of the main file (the main file loaded |
|
729 | + * by WP) |
|
730 | + * |
|
731 | + * @return string |
|
732 | + */ |
|
733 | + public function get_main_plugin_file_basename() |
|
734 | + { |
|
735 | + return plugin_basename($this->get_main_plugin_file()); |
|
736 | + } |
|
737 | + |
|
738 | + /** |
|
739 | + * Gets the folder name which contains the main plugin file |
|
740 | + * |
|
741 | + * @return string |
|
742 | + */ |
|
743 | + public function get_main_plugin_file_dirname() |
|
744 | + { |
|
745 | + return dirname($this->get_main_plugin_file()); |
|
746 | + } |
|
747 | + |
|
748 | + |
|
749 | + /** |
|
750 | + * sets hooks used in the admin |
|
751 | + * |
|
752 | + * @return void |
|
753 | + */ |
|
754 | + public function admin_init() |
|
755 | + { |
|
756 | + // is admin and not in M-Mode ? |
|
757 | + if (is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
758 | + add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2); |
|
759 | + add_filter('after_plugin_row_' . $this->_plugin_basename, array($this, 'after_plugin_row'), 10, 3); |
|
760 | + } |
|
761 | + } |
|
762 | + |
|
763 | + |
|
764 | + /** |
|
765 | + * plugin_actions |
|
766 | + * Add a settings link to the Plugins page, so people can go straight from the plugin page to the settings page. |
|
767 | + * |
|
768 | + * @param $links |
|
769 | + * @param $file |
|
770 | + * @return array |
|
771 | + */ |
|
772 | + public function plugin_action_links($links, $file) |
|
773 | + { |
|
774 | + if ($file === $this->plugin_basename() && $this->plugin_action_slug() !== '') { |
|
775 | + // before other links |
|
776 | + array_unshift( |
|
777 | + $links, |
|
778 | + '<a href="admin.php?page=' . $this->plugin_action_slug() . '">' |
|
779 | + . esc_html__('Settings', 'event_espresso') |
|
780 | + . '</a>' |
|
781 | + ); |
|
782 | + } |
|
783 | + return $links; |
|
784 | + } |
|
785 | + |
|
786 | + |
|
787 | + /** |
|
788 | + * after_plugin_row |
|
789 | + * Add additional content to the plugins page plugin row |
|
790 | + * Inserts another row |
|
791 | + * |
|
792 | + * @param $plugin_file |
|
793 | + * @param $plugin_data |
|
794 | + * @param $status |
|
795 | + * @return void |
|
796 | + */ |
|
797 | + public function after_plugin_row($plugin_file, $plugin_data, $status) |
|
798 | + { |
|
799 | + $after_plugin_row = ''; |
|
800 | + $plugins_page_row = $this->get_plugins_page_row(); |
|
801 | + if (! empty($plugins_page_row) && $plugin_file === $this->plugin_basename()) { |
|
802 | + $class = $status ? 'active' : 'inactive'; |
|
803 | + $link_text = isset($plugins_page_row['link_text']) ? $plugins_page_row['link_text'] : ''; |
|
804 | + $link_url = isset($plugins_page_row['link_url']) ? $plugins_page_row['link_url'] : ''; |
|
805 | + $description = isset($plugins_page_row['description']) |
|
806 | + ? $plugins_page_row['description'] |
|
807 | + : ''; |
|
808 | + if (! empty($link_text) && ! empty($link_url) && ! empty($description)) { |
|
809 | + $after_plugin_row .= '<tr id="' . sanitize_title($plugin_file) . '-ee-addon" class="' . $class . '">'; |
|
810 | + $after_plugin_row .= '<th class="check-column" scope="row"></th>'; |
|
811 | + $after_plugin_row .= '<td class="ee-addon-upsell-info-title-td plugin-title column-primary">'; |
|
812 | + $after_plugin_row .= '<style> |
|
813 | 813 | .ee-button, |
814 | 814 | .ee-button:active, |
815 | 815 | .ee-button:visited { |
@@ -846,64 +846,64 @@ discard block |
||
846 | 846 | } |
847 | 847 | .ee-button:active { top:0; } |
848 | 848 | </style>'; |
849 | - $after_plugin_row .= ' |
|
849 | + $after_plugin_row .= ' |
|
850 | 850 | <p class="ee-addon-upsell-info-dv"> |
851 | 851 | <a class="ee-button" href="' . $link_url . '">' |
852 | - . $link_text |
|
853 | - . ' <span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>' |
|
854 | - . '</a> |
|
852 | + . $link_text |
|
853 | + . ' <span class="dashicons dashicons-arrow-right-alt2" style="margin:0;"></span>' |
|
854 | + . '</a> |
|
855 | 855 | </p>'; |
856 | - $after_plugin_row .= '</td>'; |
|
857 | - $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">'; |
|
858 | - $after_plugin_row .= $description; |
|
859 | - $after_plugin_row .= '</td>'; |
|
860 | - $after_plugin_row .= '</tr>'; |
|
861 | - } else { |
|
862 | - $after_plugin_row .= $description; |
|
863 | - } |
|
864 | - } |
|
865 | - |
|
866 | - echo $after_plugin_row; |
|
867 | - } |
|
868 | - |
|
869 | - |
|
870 | - /** |
|
871 | - * A safe space for addons to add additional logic like setting hooks that need to be set early in the request. |
|
872 | - * Child classes that have logic like that to run can override this method declaration. This was not made abstract |
|
873 | - * for back compat reasons. |
|
874 | - * |
|
875 | - * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999. |
|
876 | - * |
|
877 | - * It is recommended, if client code is `de-registering` an add-on, then do it on the |
|
878 | - * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this |
|
879 | - * callback does not get run/set in that request. |
|
880 | - * |
|
881 | - * Also, keep in mind that if a registered add-on happens to be deactivated via |
|
882 | - * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method |
|
883 | - * (including setting hooks etc) will have executed before the plugin was deactivated. If you use |
|
884 | - * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's |
|
885 | - * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there. Just remember |
|
886 | - * to call `parent::deactivation`. |
|
887 | - * |
|
888 | - * @since 4.9.26 |
|
889 | - */ |
|
890 | - public function after_registration() |
|
891 | - { |
|
892 | - // cricket chirp... cricket chirp... |
|
893 | - } |
|
894 | - |
|
895 | - /** |
|
896 | - * @return string |
|
897 | - */ |
|
898 | - public function getPueSlug() |
|
899 | - { |
|
900 | - return $this->pue_slug; |
|
901 | - } |
|
902 | - /** |
|
903 | - * @param string $pue_slug |
|
904 | - */ |
|
905 | - public function setPueSlug($pue_slug) |
|
906 | - { |
|
907 | - $this->pue_slug = $pue_slug; |
|
908 | - } |
|
856 | + $after_plugin_row .= '</td>'; |
|
857 | + $after_plugin_row .= '<td class="ee-addon-upsell-info-desc-td column-description desc">'; |
|
858 | + $after_plugin_row .= $description; |
|
859 | + $after_plugin_row .= '</td>'; |
|
860 | + $after_plugin_row .= '</tr>'; |
|
861 | + } else { |
|
862 | + $after_plugin_row .= $description; |
|
863 | + } |
|
864 | + } |
|
865 | + |
|
866 | + echo $after_plugin_row; |
|
867 | + } |
|
868 | + |
|
869 | + |
|
870 | + /** |
|
871 | + * A safe space for addons to add additional logic like setting hooks that need to be set early in the request. |
|
872 | + * Child classes that have logic like that to run can override this method declaration. This was not made abstract |
|
873 | + * for back compat reasons. |
|
874 | + * |
|
875 | + * This will fire on the `AHEE__EE_System__load_espresso_addons__complete` hook at priority 999. |
|
876 | + * |
|
877 | + * It is recommended, if client code is `de-registering` an add-on, then do it on the |
|
878 | + * `AHEE__EE_System__load_espresso_addons__complete` hook before priority 999 so as to ensure any code logic in this |
|
879 | + * callback does not get run/set in that request. |
|
880 | + * |
|
881 | + * Also, keep in mind that if a registered add-on happens to be deactivated via |
|
882 | + * EE_System::_deactivate_incompatible_addons() because its incompatible, any code executed in this method |
|
883 | + * (including setting hooks etc) will have executed before the plugin was deactivated. If you use |
|
884 | + * `after_registration` to set any filter and/or action hooks and want to ensure they are removed on this add-on's |
|
885 | + * deactivation, you can override `EE_Addon::deactivation` and unset your hooks and filters there. Just remember |
|
886 | + * to call `parent::deactivation`. |
|
887 | + * |
|
888 | + * @since 4.9.26 |
|
889 | + */ |
|
890 | + public function after_registration() |
|
891 | + { |
|
892 | + // cricket chirp... cricket chirp... |
|
893 | + } |
|
894 | + |
|
895 | + /** |
|
896 | + * @return string |
|
897 | + */ |
|
898 | + public function getPueSlug() |
|
899 | + { |
|
900 | + return $this->pue_slug; |
|
901 | + } |
|
902 | + /** |
|
903 | + * @param string $pue_slug |
|
904 | + */ |
|
905 | + public function setPueSlug($pue_slug) |
|
906 | + { |
|
907 | + $this->pue_slug = $pue_slug; |
|
908 | + } |
|
909 | 909 | } |
@@ -31,536 +31,536 @@ |
||
31 | 31 | */ |
32 | 32 | class RegistrationsReport extends JobHandlerFile |
33 | 33 | { |
34 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
35 | - // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
36 | - /** |
|
37 | - * Performs any necessary setup for starting the job. This is also a good |
|
38 | - * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
39 | - * when continue_job will be called |
|
40 | - * |
|
41 | - * @param JobParameters $job_parameters |
|
42 | - * @throws BatchRequestException |
|
43 | - * @return JobStepResponse |
|
44 | - */ |
|
45 | - public function create_job(JobParameters $job_parameters) |
|
46 | - { |
|
47 | - $event_id = intval($job_parameters->request_datum('EVT_ID', '0')); |
|
48 | - if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
49 | - throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso')); |
|
50 | - } |
|
51 | - $filepath = $this->create_file_from_job_with_name( |
|
52 | - $job_parameters->job_id(), |
|
53 | - $this->get_filename($event_id) |
|
54 | - ); |
|
55 | - $job_parameters->add_extra_data('filepath', $filepath); |
|
56 | - if ($job_parameters->request_datum('use_filters', false)) { |
|
57 | - $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array()))); |
|
58 | - } else { |
|
59 | - $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array( |
|
60 | - array( |
|
61 | - 'OR' => array( |
|
62 | - // don't include registrations from failed or abandoned transactions... |
|
63 | - 'Transaction.STS_ID' => array( |
|
64 | - 'NOT IN', |
|
65 | - array( |
|
66 | - EEM_Transaction::failed_status_code, |
|
67 | - EEM_Transaction::abandoned_status_code, |
|
68 | - ), |
|
69 | - ), |
|
70 | - // unless the registration is approved, in which case include it regardless of transaction status |
|
71 | - 'STS_ID' => \EEM_Registration::status_id_approved, |
|
72 | - ), |
|
73 | - 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
74 | - ), |
|
75 | - 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
76 | - 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
77 | - 'caps' => \EEM_Base::caps_read_admin, |
|
78 | - ), $event_id); |
|
79 | - if ($event_id) { |
|
80 | - $query_params[0]['EVT_ID'] = $event_id; |
|
81 | - } else { |
|
82 | - $query_params['force_join'][] = 'Event'; |
|
83 | - } |
|
84 | - } |
|
85 | - if (! isset($query_params['force_join'])) { |
|
86 | - $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee'); |
|
87 | - } |
|
88 | - $job_parameters->add_extra_data('query_params', $query_params); |
|
89 | - $question_labels = $this->_get_question_labels($query_params); |
|
90 | - $job_parameters->add_extra_data('question_labels', $question_labels); |
|
91 | - $job_parameters->set_job_size( |
|
92 | - \EEM_Registration::instance()->count( |
|
93 | - array_diff_key( |
|
94 | - $query_params, |
|
95 | - array_flip( |
|
96 | - array('limit') |
|
97 | - ) |
|
98 | - ) |
|
99 | - ) |
|
100 | - ); |
|
101 | - // we should also set the header columns |
|
102 | - $csv_data_for_row = $this->get_csv_data_for( |
|
103 | - $event_id, |
|
104 | - 0, |
|
105 | - 1, |
|
106 | - $job_parameters->extra_datum('question_labels'), |
|
107 | - $job_parameters->extra_datum('query_params') |
|
108 | - ); |
|
109 | - EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); |
|
110 | - // if we actually processed a row there, record it |
|
111 | - if ($job_parameters->job_size()) { |
|
112 | - $job_parameters->mark_processed(1); |
|
113 | - } |
|
114 | - return new JobStepResponse( |
|
115 | - $job_parameters, |
|
116 | - __('Registrations report started successfully...', 'event_espresso') |
|
117 | - ); |
|
118 | - } |
|
34 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
35 | + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
36 | + /** |
|
37 | + * Performs any necessary setup for starting the job. This is also a good |
|
38 | + * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
39 | + * when continue_job will be called |
|
40 | + * |
|
41 | + * @param JobParameters $job_parameters |
|
42 | + * @throws BatchRequestException |
|
43 | + * @return JobStepResponse |
|
44 | + */ |
|
45 | + public function create_job(JobParameters $job_parameters) |
|
46 | + { |
|
47 | + $event_id = intval($job_parameters->request_datum('EVT_ID', '0')); |
|
48 | + if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
49 | + throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso')); |
|
50 | + } |
|
51 | + $filepath = $this->create_file_from_job_with_name( |
|
52 | + $job_parameters->job_id(), |
|
53 | + $this->get_filename($event_id) |
|
54 | + ); |
|
55 | + $job_parameters->add_extra_data('filepath', $filepath); |
|
56 | + if ($job_parameters->request_datum('use_filters', false)) { |
|
57 | + $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array()))); |
|
58 | + } else { |
|
59 | + $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array( |
|
60 | + array( |
|
61 | + 'OR' => array( |
|
62 | + // don't include registrations from failed or abandoned transactions... |
|
63 | + 'Transaction.STS_ID' => array( |
|
64 | + 'NOT IN', |
|
65 | + array( |
|
66 | + EEM_Transaction::failed_status_code, |
|
67 | + EEM_Transaction::abandoned_status_code, |
|
68 | + ), |
|
69 | + ), |
|
70 | + // unless the registration is approved, in which case include it regardless of transaction status |
|
71 | + 'STS_ID' => \EEM_Registration::status_id_approved, |
|
72 | + ), |
|
73 | + 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
74 | + ), |
|
75 | + 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
76 | + 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
77 | + 'caps' => \EEM_Base::caps_read_admin, |
|
78 | + ), $event_id); |
|
79 | + if ($event_id) { |
|
80 | + $query_params[0]['EVT_ID'] = $event_id; |
|
81 | + } else { |
|
82 | + $query_params['force_join'][] = 'Event'; |
|
83 | + } |
|
84 | + } |
|
85 | + if (! isset($query_params['force_join'])) { |
|
86 | + $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee'); |
|
87 | + } |
|
88 | + $job_parameters->add_extra_data('query_params', $query_params); |
|
89 | + $question_labels = $this->_get_question_labels($query_params); |
|
90 | + $job_parameters->add_extra_data('question_labels', $question_labels); |
|
91 | + $job_parameters->set_job_size( |
|
92 | + \EEM_Registration::instance()->count( |
|
93 | + array_diff_key( |
|
94 | + $query_params, |
|
95 | + array_flip( |
|
96 | + array('limit') |
|
97 | + ) |
|
98 | + ) |
|
99 | + ) |
|
100 | + ); |
|
101 | + // we should also set the header columns |
|
102 | + $csv_data_for_row = $this->get_csv_data_for( |
|
103 | + $event_id, |
|
104 | + 0, |
|
105 | + 1, |
|
106 | + $job_parameters->extra_datum('question_labels'), |
|
107 | + $job_parameters->extra_datum('query_params') |
|
108 | + ); |
|
109 | + EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); |
|
110 | + // if we actually processed a row there, record it |
|
111 | + if ($job_parameters->job_size()) { |
|
112 | + $job_parameters->mark_processed(1); |
|
113 | + } |
|
114 | + return new JobStepResponse( |
|
115 | + $job_parameters, |
|
116 | + __('Registrations report started successfully...', 'event_espresso') |
|
117 | + ); |
|
118 | + } |
|
119 | 119 | |
120 | 120 | |
121 | - /** |
|
122 | - * Gets the filename |
|
123 | - * |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - protected function get_filename() |
|
127 | - { |
|
128 | - return apply_filters( |
|
129 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__get_filename', |
|
130 | - sprintf( |
|
131 | - "event-espresso-registrations-%s.csv", |
|
132 | - str_replace(array(':', ' '), '-', current_time('mysql')) |
|
133 | - ) |
|
134 | - ); |
|
135 | - } |
|
121 | + /** |
|
122 | + * Gets the filename |
|
123 | + * |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + protected function get_filename() |
|
127 | + { |
|
128 | + return apply_filters( |
|
129 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__get_filename', |
|
130 | + sprintf( |
|
131 | + "event-espresso-registrations-%s.csv", |
|
132 | + str_replace(array(':', ' '), '-', current_time('mysql')) |
|
133 | + ) |
|
134 | + ); |
|
135 | + } |
|
136 | 136 | |
137 | 137 | |
138 | - /** |
|
139 | - * Gets the questions which are to be used for this report, so they |
|
140 | - * can be remembered for later |
|
141 | - * |
|
142 | - * @param array $registration_query_params |
|
143 | - * @return array question admin labels to be used for this report |
|
144 | - */ |
|
145 | - protected function _get_question_labels($registration_query_params) |
|
146 | - { |
|
147 | - $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null; |
|
148 | - $question_query_params = array(); |
|
149 | - if ($where !== null) { |
|
150 | - $question_query_params = array( |
|
151 | - $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]), |
|
152 | - ); |
|
153 | - } |
|
154 | - // Make sure it's not a system question |
|
155 | - $question_query_params[0]['OR*not-system-questions'] = [ |
|
156 | - 'QST_system' => '', |
|
157 | - 'QST_system*null' => ['IS_NULL'] |
|
158 | - ]; |
|
159 | - if (apply_filters( |
|
160 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', |
|
161 | - false, |
|
162 | - $registration_query_params |
|
163 | - )) { |
|
164 | - $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL'); |
|
165 | - } |
|
166 | - $question_query_params['group_by'] = array('QST_ID'); |
|
167 | - return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label')); |
|
168 | - } |
|
138 | + /** |
|
139 | + * Gets the questions which are to be used for this report, so they |
|
140 | + * can be remembered for later |
|
141 | + * |
|
142 | + * @param array $registration_query_params |
|
143 | + * @return array question admin labels to be used for this report |
|
144 | + */ |
|
145 | + protected function _get_question_labels($registration_query_params) |
|
146 | + { |
|
147 | + $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null; |
|
148 | + $question_query_params = array(); |
|
149 | + if ($where !== null) { |
|
150 | + $question_query_params = array( |
|
151 | + $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]), |
|
152 | + ); |
|
153 | + } |
|
154 | + // Make sure it's not a system question |
|
155 | + $question_query_params[0]['OR*not-system-questions'] = [ |
|
156 | + 'QST_system' => '', |
|
157 | + 'QST_system*null' => ['IS_NULL'] |
|
158 | + ]; |
|
159 | + if (apply_filters( |
|
160 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', |
|
161 | + false, |
|
162 | + $registration_query_params |
|
163 | + )) { |
|
164 | + $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL'); |
|
165 | + } |
|
166 | + $question_query_params['group_by'] = array('QST_ID'); |
|
167 | + return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label')); |
|
168 | + } |
|
169 | 169 | |
170 | 170 | |
171 | - /** |
|
172 | - * Takes where params meant for registrations and changes them to work for questions |
|
173 | - * |
|
174 | - * @param array $reg_where_params |
|
175 | - * @return array |
|
176 | - */ |
|
177 | - protected function _change_registration_where_params_to_question_where_params($reg_where_params) |
|
178 | - { |
|
179 | - $question_where_params = array(); |
|
180 | - foreach ($reg_where_params as $key => $val) { |
|
181 | - if (\EEM_Registration::instance()->is_logic_query_param_key($key)) { |
|
182 | - $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val); |
|
183 | - } else { |
|
184 | - // it's a normal where condition |
|
185 | - $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val; |
|
186 | - } |
|
187 | - } |
|
188 | - return $question_where_params; |
|
189 | - } |
|
171 | + /** |
|
172 | + * Takes where params meant for registrations and changes them to work for questions |
|
173 | + * |
|
174 | + * @param array $reg_where_params |
|
175 | + * @return array |
|
176 | + */ |
|
177 | + protected function _change_registration_where_params_to_question_where_params($reg_where_params) |
|
178 | + { |
|
179 | + $question_where_params = array(); |
|
180 | + foreach ($reg_where_params as $key => $val) { |
|
181 | + if (\EEM_Registration::instance()->is_logic_query_param_key($key)) { |
|
182 | + $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val); |
|
183 | + } else { |
|
184 | + // it's a normal where condition |
|
185 | + $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val; |
|
186 | + } |
|
187 | + } |
|
188 | + return $question_where_params; |
|
189 | + } |
|
190 | 190 | |
191 | 191 | |
192 | - /** |
|
193 | - * Performs another step of the job |
|
194 | - * |
|
195 | - * @param JobParameters $job_parameters |
|
196 | - * @param int $batch_size |
|
197 | - * @return JobStepResponse |
|
198 | - * @throws \EE_Error |
|
199 | - */ |
|
200 | - public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
201 | - { |
|
202 | - if ($job_parameters->units_processed() < $job_parameters->job_size()) { |
|
203 | - $csv_data = $this->get_csv_data_for( |
|
204 | - $job_parameters->request_datum('EVT_ID', '0'), |
|
205 | - $job_parameters->units_processed(), |
|
206 | - $batch_size, |
|
207 | - $job_parameters->extra_datum('question_labels'), |
|
208 | - $job_parameters->extra_datum('query_params') |
|
209 | - ); |
|
210 | - EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false); |
|
211 | - $units_processed = count($csv_data); |
|
212 | - } else { |
|
213 | - $csv_data = array(); |
|
214 | - $units_processed = 0; |
|
215 | - } |
|
216 | - $job_parameters->mark_processed($units_processed); |
|
217 | - $extra_response_data = array( |
|
218 | - 'file_url' => '', |
|
219 | - ); |
|
220 | - if ($units_processed < $batch_size) { |
|
221 | - $job_parameters->set_status(JobParameters::status_complete); |
|
222 | - $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
223 | - } |
|
192 | + /** |
|
193 | + * Performs another step of the job |
|
194 | + * |
|
195 | + * @param JobParameters $job_parameters |
|
196 | + * @param int $batch_size |
|
197 | + * @return JobStepResponse |
|
198 | + * @throws \EE_Error |
|
199 | + */ |
|
200 | + public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
201 | + { |
|
202 | + if ($job_parameters->units_processed() < $job_parameters->job_size()) { |
|
203 | + $csv_data = $this->get_csv_data_for( |
|
204 | + $job_parameters->request_datum('EVT_ID', '0'), |
|
205 | + $job_parameters->units_processed(), |
|
206 | + $batch_size, |
|
207 | + $job_parameters->extra_datum('question_labels'), |
|
208 | + $job_parameters->extra_datum('query_params') |
|
209 | + ); |
|
210 | + EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false); |
|
211 | + $units_processed = count($csv_data); |
|
212 | + } else { |
|
213 | + $csv_data = array(); |
|
214 | + $units_processed = 0; |
|
215 | + } |
|
216 | + $job_parameters->mark_processed($units_processed); |
|
217 | + $extra_response_data = array( |
|
218 | + 'file_url' => '', |
|
219 | + ); |
|
220 | + if ($units_processed < $batch_size) { |
|
221 | + $job_parameters->set_status(JobParameters::status_complete); |
|
222 | + $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
223 | + } |
|
224 | 224 | |
225 | - return new JobStepResponse( |
|
226 | - $job_parameters, |
|
227 | - sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)), |
|
228 | - $extra_response_data |
|
229 | - ); |
|
230 | - } |
|
225 | + return new JobStepResponse( |
|
226 | + $job_parameters, |
|
227 | + sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)), |
|
228 | + $extra_response_data |
|
229 | + ); |
|
230 | + } |
|
231 | 231 | |
232 | 232 | |
233 | - /** |
|
234 | - * Gets the csv data for a batch of registrations |
|
235 | - * |
|
236 | - * @param int|null $event_id |
|
237 | - * @param int $offset |
|
238 | - * @param int $limit |
|
239 | - * @param array $question_labels the IDs for all the questions which were answered by someone in this selection |
|
240 | - * @param array $query_params for using where querying the model |
|
241 | - * @return array top-level keys are numeric, next-level keys are column headers |
|
242 | - * @throws \EE_Error |
|
243 | - */ |
|
244 | - public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params) |
|
245 | - { |
|
246 | - $reg_fields_to_include = array( |
|
247 | - 'TXN_ID', |
|
248 | - 'ATT_ID', |
|
249 | - 'REG_ID', |
|
250 | - 'REG_date', |
|
251 | - 'REG_code', |
|
252 | - 'REG_count', |
|
253 | - 'REG_final_price', |
|
254 | - ); |
|
255 | - $att_fields_to_include = array( |
|
256 | - 'ATT_fname', |
|
257 | - 'ATT_lname', |
|
258 | - 'ATT_email', |
|
259 | - 'ATT_address', |
|
260 | - 'ATT_address2', |
|
261 | - 'ATT_city', |
|
262 | - 'STA_ID', |
|
263 | - 'CNT_ISO', |
|
264 | - 'ATT_zip', |
|
265 | - 'ATT_phone', |
|
266 | - ); |
|
267 | - $registrations_csv_ready_array = array(); |
|
268 | - $reg_model = EE_Registry::instance()->load_model('Registration'); |
|
269 | - $query_params['limit'] = array($offset, $limit); |
|
270 | - $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
271 | - $registration_ids = array(); |
|
272 | - foreach ($registration_rows as $reg_row) { |
|
273 | - $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
274 | - } |
|
275 | - foreach ($registration_rows as $reg_row) { |
|
276 | - if (is_array($reg_row)) { |
|
277 | - $reg_csv_array = array(); |
|
278 | - if (! $event_id) { |
|
279 | - // get the event's name and Id |
|
280 | - $reg_csv_array[ (string) __('Event', 'event_espresso') ] = sprintf( |
|
281 | - /* translators: 1: event name, 2: event ID */ |
|
282 | - __('%1$s (%2$s)', 'event_espresso'), |
|
283 | - EEH_Export::prepare_value_from_db_for_display( |
|
284 | - EEM_Event::instance(), |
|
285 | - 'EVT_name', |
|
286 | - $reg_row['Event_CPT.post_title'] |
|
287 | - ), |
|
288 | - $reg_row['Event_CPT.ID'] |
|
289 | - ); |
|
290 | - } |
|
291 | - $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
292 | - /*@var $reg_row EE_Registration */ |
|
293 | - foreach ($reg_fields_to_include as $field_name) { |
|
294 | - $field = $reg_model->field_settings_for($field_name); |
|
295 | - if ($field_name == 'REG_final_price') { |
|
296 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
297 | - $reg_model, |
|
298 | - $field_name, |
|
299 | - $reg_row['Registration.REG_final_price'], |
|
300 | - 'localized_float' |
|
301 | - ); |
|
302 | - } elseif ($field_name == 'REG_count') { |
|
303 | - $value = sprintf( |
|
304 | - /* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */ |
|
305 | - __('%1$s of %2$s', 'event_espresso'), |
|
306 | - EEH_Export::prepare_value_from_db_for_display( |
|
307 | - $reg_model, |
|
308 | - 'REG_count', |
|
309 | - $reg_row['Registration.REG_count'] |
|
310 | - ), |
|
311 | - EEH_Export::prepare_value_from_db_for_display( |
|
312 | - $reg_model, |
|
313 | - 'REG_group_size', |
|
314 | - $reg_row['Registration.REG_group_size'] |
|
315 | - ) |
|
316 | - ); |
|
317 | - } elseif ($field_name == 'REG_date') { |
|
318 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
319 | - $reg_model, |
|
320 | - $field_name, |
|
321 | - $reg_row['Registration.REG_date'], |
|
322 | - 'no_html' |
|
323 | - ); |
|
324 | - } else { |
|
325 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
326 | - $reg_model, |
|
327 | - $field_name, |
|
328 | - $reg_row[ $field->get_qualified_column() ] |
|
329 | - ); |
|
330 | - } |
|
331 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value; |
|
332 | - if ($field_name == 'REG_final_price') { |
|
333 | - // add a column named Currency after the final price |
|
334 | - $reg_csv_array[ (string) __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code; |
|
335 | - } |
|
336 | - } |
|
337 | - // get pretty status |
|
338 | - $stati = EEM_Status::instance()->localized_status( |
|
339 | - array( |
|
340 | - $reg_row['Registration.STS_ID'] => __('unknown', 'event_espresso'), |
|
341 | - $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'), |
|
342 | - ), |
|
343 | - false, |
|
344 | - 'sentence' |
|
345 | - ); |
|
346 | - $reg_csv_array[ (string) __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
347 | - // get pretty transaction status |
|
348 | - $reg_csv_array[ (string) __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
349 | - $reg_csv_array[ (string) __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
350 | - ? EEH_Export::prepare_value_from_db_for_display( |
|
351 | - EEM_Transaction::instance(), |
|
352 | - 'TXN_total', |
|
353 | - $reg_row['TransactionTable.TXN_total'], |
|
354 | - 'localized_float' |
|
355 | - ) : '0.00'; |
|
356 | - $reg_csv_array[ (string) __('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
357 | - ? EEH_Export::prepare_value_from_db_for_display( |
|
358 | - EEM_Transaction::instance(), |
|
359 | - 'TXN_paid', |
|
360 | - $reg_row['TransactionTable.TXN_paid'], |
|
361 | - 'localized_float' |
|
362 | - ) : '0.00'; |
|
363 | - $payment_methods = array(); |
|
364 | - $gateway_txn_ids_etc = array(); |
|
365 | - $payment_times = array(); |
|
366 | - if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
367 | - $payments_info = EEM_Payment::instance()->get_all_wpdb_results( |
|
368 | - array( |
|
369 | - array( |
|
370 | - 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
371 | - 'STS_ID' => EEM_Payment::status_id_approved, |
|
372 | - ), |
|
373 | - 'force_join' => array('Payment_Method'), |
|
374 | - ), |
|
375 | - ARRAY_A, |
|
376 | - 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
377 | - ); |
|
378 | - foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
379 | - $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) |
|
380 | - ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso'); |
|
381 | - $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) |
|
382 | - ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
383 | - $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) |
|
384 | - ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
385 | - } |
|
386 | - } |
|
387 | - $reg_csv_array[ (string) __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
388 | - $reg_csv_array[ (string) __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
389 | - $reg_csv_array[ (string) __('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
390 | - ',', |
|
391 | - $gateway_txn_ids_etc |
|
392 | - ); |
|
393 | - // get whether or not the user has checked in |
|
394 | - $reg_csv_array[ (string) __("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
395 | - $reg_row['Registration.REG_ID'], |
|
396 | - 'Checkin' |
|
397 | - ); |
|
398 | - // get ticket of registration and its price |
|
399 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
400 | - if ($reg_row['Ticket.TKT_ID']) { |
|
401 | - $ticket_name = EEH_Export::prepare_value_from_db_for_display( |
|
402 | - $ticket_model, |
|
403 | - 'TKT_name', |
|
404 | - $reg_row['Ticket.TKT_name'] |
|
405 | - ); |
|
406 | - $datetimes_strings = array(); |
|
407 | - foreach (EEM_Datetime::instance()->get_all_wpdb_results( |
|
408 | - array( |
|
409 | - array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), |
|
410 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
411 | - 'default_where_conditions' => 'none', |
|
412 | - ) |
|
413 | - ) as $datetime) { |
|
414 | - $datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display( |
|
415 | - EEM_Datetime::instance(), |
|
416 | - 'DTT_EVT_start', |
|
417 | - $datetime['Datetime.DTT_EVT_start'] |
|
418 | - ); |
|
419 | - } |
|
420 | - } else { |
|
421 | - $ticket_name = __('Unknown', 'event_espresso'); |
|
422 | - $datetimes_strings = array(__('Unknown', 'event_espresso')); |
|
423 | - } |
|
424 | - $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
425 | - $reg_csv_array[ (string) __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
426 | - // get datetime(s) of registration |
|
427 | - // add attendee columns |
|
428 | - foreach ($att_fields_to_include as $att_field_name) { |
|
429 | - $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name); |
|
430 | - if ($reg_row['Attendee_CPT.ID']) { |
|
431 | - if ($att_field_name == 'STA_ID') { |
|
432 | - $value = EEM_State::instance()->get_var( |
|
433 | - array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), |
|
434 | - 'STA_name' |
|
435 | - ); |
|
436 | - } elseif ($att_field_name == 'CNT_ISO') { |
|
437 | - $value = EEM_Country::instance()->get_var( |
|
438 | - array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), |
|
439 | - 'CNT_name' |
|
440 | - ); |
|
441 | - } else { |
|
442 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
443 | - EEM_Attendee::instance(), |
|
444 | - $att_field_name, |
|
445 | - $reg_row[ $field_obj->get_qualified_column() ] |
|
446 | - ); |
|
447 | - } |
|
448 | - } else { |
|
449 | - $value = ''; |
|
450 | - } |
|
451 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value; |
|
452 | - } |
|
453 | - // make sure each registration has the same questions in the same order |
|
454 | - foreach ($question_labels as $question_label) { |
|
455 | - if (! isset($reg_csv_array[ $question_label ])) { |
|
456 | - $reg_csv_array[ $question_label ] = null; |
|
457 | - } |
|
458 | - } |
|
459 | - $answers = EEM_Answer::instance()->get_all_wpdb_results(array( |
|
460 | - array('REG_ID' => $reg_row['Registration.REG_ID']), |
|
461 | - 'force_join' => array('Question'), |
|
462 | - )); |
|
463 | - // now fill out the questions THEY answered |
|
464 | - foreach ($answers as $answer_row) { |
|
465 | - if ($answer_row['Question.QST_system']) { |
|
466 | - // it's an answer to a system question. That was already displayed as part of the attendee |
|
467 | - // fields, so don't write it out again thanks. |
|
468 | - continue; |
|
469 | - } |
|
470 | - if ($answer_row['Question.QST_ID']) { |
|
471 | - $question_label = EEH_Export::prepare_value_from_db_for_display( |
|
472 | - EEM_Question::instance(), |
|
473 | - 'QST_admin_label', |
|
474 | - $answer_row['Question.QST_admin_label'] |
|
475 | - ); |
|
476 | - } else { |
|
477 | - $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
478 | - } |
|
479 | - if (isset($answer_row['Question.QST_type']) |
|
480 | - && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state |
|
481 | - ) { |
|
482 | - $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
483 | - $answer_row['Answer.ANS_value'] |
|
484 | - ); |
|
485 | - } else { |
|
486 | - // this isn't for html, so don't show html entities |
|
487 | - $reg_csv_array[ $question_label ] = html_entity_decode( |
|
488 | - EEH_Export::prepare_value_from_db_for_display( |
|
489 | - EEM_Answer::instance(), |
|
490 | - 'ANS_value', |
|
491 | - $answer_row['Answer.ANS_value'] |
|
492 | - ) |
|
493 | - ); |
|
494 | - } |
|
495 | - } |
|
233 | + /** |
|
234 | + * Gets the csv data for a batch of registrations |
|
235 | + * |
|
236 | + * @param int|null $event_id |
|
237 | + * @param int $offset |
|
238 | + * @param int $limit |
|
239 | + * @param array $question_labels the IDs for all the questions which were answered by someone in this selection |
|
240 | + * @param array $query_params for using where querying the model |
|
241 | + * @return array top-level keys are numeric, next-level keys are column headers |
|
242 | + * @throws \EE_Error |
|
243 | + */ |
|
244 | + public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params) |
|
245 | + { |
|
246 | + $reg_fields_to_include = array( |
|
247 | + 'TXN_ID', |
|
248 | + 'ATT_ID', |
|
249 | + 'REG_ID', |
|
250 | + 'REG_date', |
|
251 | + 'REG_code', |
|
252 | + 'REG_count', |
|
253 | + 'REG_final_price', |
|
254 | + ); |
|
255 | + $att_fields_to_include = array( |
|
256 | + 'ATT_fname', |
|
257 | + 'ATT_lname', |
|
258 | + 'ATT_email', |
|
259 | + 'ATT_address', |
|
260 | + 'ATT_address2', |
|
261 | + 'ATT_city', |
|
262 | + 'STA_ID', |
|
263 | + 'CNT_ISO', |
|
264 | + 'ATT_zip', |
|
265 | + 'ATT_phone', |
|
266 | + ); |
|
267 | + $registrations_csv_ready_array = array(); |
|
268 | + $reg_model = EE_Registry::instance()->load_model('Registration'); |
|
269 | + $query_params['limit'] = array($offset, $limit); |
|
270 | + $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
271 | + $registration_ids = array(); |
|
272 | + foreach ($registration_rows as $reg_row) { |
|
273 | + $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
274 | + } |
|
275 | + foreach ($registration_rows as $reg_row) { |
|
276 | + if (is_array($reg_row)) { |
|
277 | + $reg_csv_array = array(); |
|
278 | + if (! $event_id) { |
|
279 | + // get the event's name and Id |
|
280 | + $reg_csv_array[ (string) __('Event', 'event_espresso') ] = sprintf( |
|
281 | + /* translators: 1: event name, 2: event ID */ |
|
282 | + __('%1$s (%2$s)', 'event_espresso'), |
|
283 | + EEH_Export::prepare_value_from_db_for_display( |
|
284 | + EEM_Event::instance(), |
|
285 | + 'EVT_name', |
|
286 | + $reg_row['Event_CPT.post_title'] |
|
287 | + ), |
|
288 | + $reg_row['Event_CPT.ID'] |
|
289 | + ); |
|
290 | + } |
|
291 | + $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
292 | + /*@var $reg_row EE_Registration */ |
|
293 | + foreach ($reg_fields_to_include as $field_name) { |
|
294 | + $field = $reg_model->field_settings_for($field_name); |
|
295 | + if ($field_name == 'REG_final_price') { |
|
296 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
297 | + $reg_model, |
|
298 | + $field_name, |
|
299 | + $reg_row['Registration.REG_final_price'], |
|
300 | + 'localized_float' |
|
301 | + ); |
|
302 | + } elseif ($field_name == 'REG_count') { |
|
303 | + $value = sprintf( |
|
304 | + /* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */ |
|
305 | + __('%1$s of %2$s', 'event_espresso'), |
|
306 | + EEH_Export::prepare_value_from_db_for_display( |
|
307 | + $reg_model, |
|
308 | + 'REG_count', |
|
309 | + $reg_row['Registration.REG_count'] |
|
310 | + ), |
|
311 | + EEH_Export::prepare_value_from_db_for_display( |
|
312 | + $reg_model, |
|
313 | + 'REG_group_size', |
|
314 | + $reg_row['Registration.REG_group_size'] |
|
315 | + ) |
|
316 | + ); |
|
317 | + } elseif ($field_name == 'REG_date') { |
|
318 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
319 | + $reg_model, |
|
320 | + $field_name, |
|
321 | + $reg_row['Registration.REG_date'], |
|
322 | + 'no_html' |
|
323 | + ); |
|
324 | + } else { |
|
325 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
326 | + $reg_model, |
|
327 | + $field_name, |
|
328 | + $reg_row[ $field->get_qualified_column() ] |
|
329 | + ); |
|
330 | + } |
|
331 | + $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = $value; |
|
332 | + if ($field_name == 'REG_final_price') { |
|
333 | + // add a column named Currency after the final price |
|
334 | + $reg_csv_array[ (string) __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code; |
|
335 | + } |
|
336 | + } |
|
337 | + // get pretty status |
|
338 | + $stati = EEM_Status::instance()->localized_status( |
|
339 | + array( |
|
340 | + $reg_row['Registration.STS_ID'] => __('unknown', 'event_espresso'), |
|
341 | + $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'), |
|
342 | + ), |
|
343 | + false, |
|
344 | + 'sentence' |
|
345 | + ); |
|
346 | + $reg_csv_array[ (string) __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
347 | + // get pretty transaction status |
|
348 | + $reg_csv_array[ (string) __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
349 | + $reg_csv_array[ (string) __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
350 | + ? EEH_Export::prepare_value_from_db_for_display( |
|
351 | + EEM_Transaction::instance(), |
|
352 | + 'TXN_total', |
|
353 | + $reg_row['TransactionTable.TXN_total'], |
|
354 | + 'localized_float' |
|
355 | + ) : '0.00'; |
|
356 | + $reg_csv_array[ (string) __('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
357 | + ? EEH_Export::prepare_value_from_db_for_display( |
|
358 | + EEM_Transaction::instance(), |
|
359 | + 'TXN_paid', |
|
360 | + $reg_row['TransactionTable.TXN_paid'], |
|
361 | + 'localized_float' |
|
362 | + ) : '0.00'; |
|
363 | + $payment_methods = array(); |
|
364 | + $gateway_txn_ids_etc = array(); |
|
365 | + $payment_times = array(); |
|
366 | + if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
367 | + $payments_info = EEM_Payment::instance()->get_all_wpdb_results( |
|
368 | + array( |
|
369 | + array( |
|
370 | + 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
371 | + 'STS_ID' => EEM_Payment::status_id_approved, |
|
372 | + ), |
|
373 | + 'force_join' => array('Payment_Method'), |
|
374 | + ), |
|
375 | + ARRAY_A, |
|
376 | + 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
377 | + ); |
|
378 | + foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
379 | + $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) |
|
380 | + ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso'); |
|
381 | + $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) |
|
382 | + ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
383 | + $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) |
|
384 | + ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
385 | + } |
|
386 | + } |
|
387 | + $reg_csv_array[ (string) __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
388 | + $reg_csv_array[ (string) __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
389 | + $reg_csv_array[ (string) __('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
390 | + ',', |
|
391 | + $gateway_txn_ids_etc |
|
392 | + ); |
|
393 | + // get whether or not the user has checked in |
|
394 | + $reg_csv_array[ (string) __("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
395 | + $reg_row['Registration.REG_ID'], |
|
396 | + 'Checkin' |
|
397 | + ); |
|
398 | + // get ticket of registration and its price |
|
399 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
400 | + if ($reg_row['Ticket.TKT_ID']) { |
|
401 | + $ticket_name = EEH_Export::prepare_value_from_db_for_display( |
|
402 | + $ticket_model, |
|
403 | + 'TKT_name', |
|
404 | + $reg_row['Ticket.TKT_name'] |
|
405 | + ); |
|
406 | + $datetimes_strings = array(); |
|
407 | + foreach (EEM_Datetime::instance()->get_all_wpdb_results( |
|
408 | + array( |
|
409 | + array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), |
|
410 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
411 | + 'default_where_conditions' => 'none', |
|
412 | + ) |
|
413 | + ) as $datetime) { |
|
414 | + $datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display( |
|
415 | + EEM_Datetime::instance(), |
|
416 | + 'DTT_EVT_start', |
|
417 | + $datetime['Datetime.DTT_EVT_start'] |
|
418 | + ); |
|
419 | + } |
|
420 | + } else { |
|
421 | + $ticket_name = __('Unknown', 'event_espresso'); |
|
422 | + $datetimes_strings = array(__('Unknown', 'event_espresso')); |
|
423 | + } |
|
424 | + $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
425 | + $reg_csv_array[ (string) __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
426 | + // get datetime(s) of registration |
|
427 | + // add attendee columns |
|
428 | + foreach ($att_fields_to_include as $att_field_name) { |
|
429 | + $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name); |
|
430 | + if ($reg_row['Attendee_CPT.ID']) { |
|
431 | + if ($att_field_name == 'STA_ID') { |
|
432 | + $value = EEM_State::instance()->get_var( |
|
433 | + array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), |
|
434 | + 'STA_name' |
|
435 | + ); |
|
436 | + } elseif ($att_field_name == 'CNT_ISO') { |
|
437 | + $value = EEM_Country::instance()->get_var( |
|
438 | + array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), |
|
439 | + 'CNT_name' |
|
440 | + ); |
|
441 | + } else { |
|
442 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
443 | + EEM_Attendee::instance(), |
|
444 | + $att_field_name, |
|
445 | + $reg_row[ $field_obj->get_qualified_column() ] |
|
446 | + ); |
|
447 | + } |
|
448 | + } else { |
|
449 | + $value = ''; |
|
450 | + } |
|
451 | + $reg_csv_array[ EEH_Export::get_column_name_for_field($field_obj) ] = $value; |
|
452 | + } |
|
453 | + // make sure each registration has the same questions in the same order |
|
454 | + foreach ($question_labels as $question_label) { |
|
455 | + if (! isset($reg_csv_array[ $question_label ])) { |
|
456 | + $reg_csv_array[ $question_label ] = null; |
|
457 | + } |
|
458 | + } |
|
459 | + $answers = EEM_Answer::instance()->get_all_wpdb_results(array( |
|
460 | + array('REG_ID' => $reg_row['Registration.REG_ID']), |
|
461 | + 'force_join' => array('Question'), |
|
462 | + )); |
|
463 | + // now fill out the questions THEY answered |
|
464 | + foreach ($answers as $answer_row) { |
|
465 | + if ($answer_row['Question.QST_system']) { |
|
466 | + // it's an answer to a system question. That was already displayed as part of the attendee |
|
467 | + // fields, so don't write it out again thanks. |
|
468 | + continue; |
|
469 | + } |
|
470 | + if ($answer_row['Question.QST_ID']) { |
|
471 | + $question_label = EEH_Export::prepare_value_from_db_for_display( |
|
472 | + EEM_Question::instance(), |
|
473 | + 'QST_admin_label', |
|
474 | + $answer_row['Question.QST_admin_label'] |
|
475 | + ); |
|
476 | + } else { |
|
477 | + $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
478 | + } |
|
479 | + if (isset($answer_row['Question.QST_type']) |
|
480 | + && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state |
|
481 | + ) { |
|
482 | + $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
483 | + $answer_row['Answer.ANS_value'] |
|
484 | + ); |
|
485 | + } else { |
|
486 | + // this isn't for html, so don't show html entities |
|
487 | + $reg_csv_array[ $question_label ] = html_entity_decode( |
|
488 | + EEH_Export::prepare_value_from_db_for_display( |
|
489 | + EEM_Answer::instance(), |
|
490 | + 'ANS_value', |
|
491 | + $answer_row['Answer.ANS_value'] |
|
492 | + ) |
|
493 | + ); |
|
494 | + } |
|
495 | + } |
|
496 | 496 | |
497 | - /** |
|
498 | - * Filter to change the contents of each row of the registrations report CSV file. |
|
499 | - * This can be used to add or remote columns from the CSV file, or change their values. |
|
500 | - * Note when using: all rows in the CSV should have the same columns. |
|
501 | - * @param array $reg_csv_array keys are the column names, values are their cell values |
|
502 | - * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results() |
|
503 | - */ |
|
504 | - $registrations_csv_ready_array[] = apply_filters( |
|
505 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', |
|
506 | - $reg_csv_array, |
|
507 | - $reg_row |
|
508 | - ); |
|
509 | - } |
|
510 | - } |
|
511 | - // if we couldn't export anything, we want to at least show the column headers |
|
512 | - if (empty($registrations_csv_ready_array)) { |
|
513 | - $reg_csv_array = array(); |
|
514 | - $model_and_fields_to_include = array( |
|
515 | - 'Registration' => $reg_fields_to_include, |
|
516 | - 'Attendee' => $att_fields_to_include, |
|
517 | - ); |
|
518 | - foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
519 | - $model = EE_Registry::instance()->load_model($model_name); |
|
520 | - foreach ($field_list as $field_name) { |
|
521 | - $field = $model->field_settings_for($field_name); |
|
522 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null; |
|
523 | - } |
|
524 | - } |
|
525 | - $registrations_csv_ready_array[] = $reg_csv_array; |
|
526 | - } |
|
527 | - return $registrations_csv_ready_array; |
|
528 | - } |
|
497 | + /** |
|
498 | + * Filter to change the contents of each row of the registrations report CSV file. |
|
499 | + * This can be used to add or remote columns from the CSV file, or change their values. |
|
500 | + * Note when using: all rows in the CSV should have the same columns. |
|
501 | + * @param array $reg_csv_array keys are the column names, values are their cell values |
|
502 | + * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results() |
|
503 | + */ |
|
504 | + $registrations_csv_ready_array[] = apply_filters( |
|
505 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', |
|
506 | + $reg_csv_array, |
|
507 | + $reg_row |
|
508 | + ); |
|
509 | + } |
|
510 | + } |
|
511 | + // if we couldn't export anything, we want to at least show the column headers |
|
512 | + if (empty($registrations_csv_ready_array)) { |
|
513 | + $reg_csv_array = array(); |
|
514 | + $model_and_fields_to_include = array( |
|
515 | + 'Registration' => $reg_fields_to_include, |
|
516 | + 'Attendee' => $att_fields_to_include, |
|
517 | + ); |
|
518 | + foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
519 | + $model = EE_Registry::instance()->load_model($model_name); |
|
520 | + foreach ($field_list as $field_name) { |
|
521 | + $field = $model->field_settings_for($field_name); |
|
522 | + $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null; |
|
523 | + } |
|
524 | + } |
|
525 | + $registrations_csv_ready_array[] = $reg_csv_array; |
|
526 | + } |
|
527 | + return $registrations_csv_ready_array; |
|
528 | + } |
|
529 | 529 | |
530 | 530 | |
531 | - /** |
|
532 | - * Counts total unit to process |
|
533 | - * |
|
534 | - * @deprecated since 4.9.19 |
|
535 | - * @param int|array $event_id |
|
536 | - * @return int |
|
537 | - */ |
|
538 | - public function count_units_to_process($event_id) |
|
539 | - { |
|
540 | - // use the legacy filter |
|
541 | - if ($event_id) { |
|
542 | - $query_params[0]['EVT_ID'] = $event_id; |
|
543 | - } else { |
|
544 | - $query_params['force_join'][] = 'Event'; |
|
545 | - } |
|
546 | - return \EEM_Registration::instance()->count($query_params); |
|
547 | - } |
|
531 | + /** |
|
532 | + * Counts total unit to process |
|
533 | + * |
|
534 | + * @deprecated since 4.9.19 |
|
535 | + * @param int|array $event_id |
|
536 | + * @return int |
|
537 | + */ |
|
538 | + public function count_units_to_process($event_id) |
|
539 | + { |
|
540 | + // use the legacy filter |
|
541 | + if ($event_id) { |
|
542 | + $query_params[0]['EVT_ID'] = $event_id; |
|
543 | + } else { |
|
544 | + $query_params['force_join'][] = 'Event'; |
|
545 | + } |
|
546 | + return \EEM_Registration::instance()->count($query_params); |
|
547 | + } |
|
548 | 548 | |
549 | 549 | |
550 | - /** |
|
551 | - * Performs any clean-up logic when we know the job is completed. |
|
552 | - * In this case, we delete the temporary file |
|
553 | - * |
|
554 | - * @param JobParameters $job_parameters |
|
555 | - * @return boolean |
|
556 | - */ |
|
557 | - public function cleanup_job(JobParameters $job_parameters) |
|
558 | - { |
|
559 | - $this->_file_helper->delete( |
|
560 | - \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
561 | - true, |
|
562 | - 'd' |
|
563 | - ); |
|
564 | - return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso')); |
|
565 | - } |
|
550 | + /** |
|
551 | + * Performs any clean-up logic when we know the job is completed. |
|
552 | + * In this case, we delete the temporary file |
|
553 | + * |
|
554 | + * @param JobParameters $job_parameters |
|
555 | + * @return boolean |
|
556 | + */ |
|
557 | + public function cleanup_job(JobParameters $job_parameters) |
|
558 | + { |
|
559 | + $this->_file_helper->delete( |
|
560 | + \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
561 | + true, |
|
562 | + 'd' |
|
563 | + ); |
|
564 | + return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso')); |
|
565 | + } |
|
566 | 566 | } |
@@ -6,16 +6,16 @@ discard block |
||
6 | 6 | <?php if (!is_admin()) : ?> |
7 | 7 | <p id="spco-attendee_information-pg" class="spco-steps-pg small-text drk-grey-text"> |
8 | 8 | <?php echo apply_filters( |
9 | - 'FHEE__registration_page_attendee_information__attendee_information_pg', |
|
10 | - sprintf( |
|
11 | - esc_html__( |
|
12 | - 'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.', |
|
13 | - 'event_espresso' |
|
14 | - ), |
|
15 | - '<br />', |
|
16 | - '<span class="asterisk">*</span>' |
|
17 | - ) |
|
18 | - ); ?> |
|
9 | + 'FHEE__registration_page_attendee_information__attendee_information_pg', |
|
10 | + sprintf( |
|
11 | + esc_html__( |
|
12 | + 'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.', |
|
13 | + 'event_espresso' |
|
14 | + ), |
|
15 | + '<br />', |
|
16 | + '<span class="asterisk">*</span>' |
|
17 | + ) |
|
18 | + ); ?> |
|
19 | 19 | </p> |
20 | 20 | <?php endif; ?> |
21 | 21 | |
@@ -25,8 +25,8 @@ discard block |
||
25 | 25 | $prev_ticket = 0; |
26 | 26 | |
27 | 27 | if (count($registrations) > 0) { |
28 | - $ticketID = key($template_args['ticket_count']); |
|
29 | - ?> |
|
28 | + $ticketID = key($template_args['ticket_count']); |
|
29 | + ?> |
|
30 | 30 | |
31 | 31 | <div id="spco-attendee-panel-dv-<?php echo $ticketID; ?>" |
32 | 32 | class="spco-attendee-panel-dv spco-attendee-ticket-<?php echo $ticketID; ?>"> |
@@ -41,54 +41,54 @@ discard block |
||
41 | 41 | <th scope="col" width="" class="jst-left"><?php esc_html_e('Name and Description', 'event_espresso'); ?></th> |
42 | 42 | <th scope="col" width="7.5%" class="jst-rght"> |
43 | 43 | <?php esc_html_e( |
44 | - 'Qty', |
|
45 | - 'event_espresso' |
|
46 | - ); ?></th> |
|
44 | + 'Qty', |
|
45 | + 'event_espresso' |
|
46 | + ); ?></th> |
|
47 | 47 | <th scope="col" width="17.5%" class="jst-rght"> |
48 | 48 | <?php esc_html_e( |
49 | - 'Price', |
|
50 | - 'event_espresso' |
|
51 | - ); ?></th> |
|
49 | + 'Price', |
|
50 | + 'event_espresso' |
|
51 | + ); ?></th> |
|
52 | 52 | <th scope="col" width="17.5%" class="jst-rght"> |
53 | 53 | <?php esc_html_e( |
54 | - 'Total', |
|
55 | - 'event_espresso' |
|
56 | - ); ?></th> |
|
54 | + 'Total', |
|
55 | + 'event_espresso' |
|
56 | + ); ?></th> |
|
57 | 57 | </tr> |
58 | 58 | </thead> |
59 | 59 | <tbody> |
60 | 60 | <?php |
61 | - // Store previous values to avoid duplicated rows. |
|
62 | - $prev_ticket = 0; |
|
63 | - // Display all tickets inside. |
|
64 | - foreach ($registrations as $registration) { |
|
65 | - if ($registration instanceof EE_Registration) { |
|
66 | - if ($registration->ticket()->ID() !== $prev_ticket) { |
|
67 | - echo $ticket_line_item[ $registration->ticket()->ID() ]; |
|
68 | - } |
|
61 | + // Store previous values to avoid duplicated rows. |
|
62 | + $prev_ticket = 0; |
|
63 | + // Display all tickets inside. |
|
64 | + foreach ($registrations as $registration) { |
|
65 | + if ($registration instanceof EE_Registration) { |
|
66 | + if ($registration->ticket()->ID() !== $prev_ticket) { |
|
67 | + echo $ticket_line_item[ $registration->ticket()->ID() ]; |
|
68 | + } |
|
69 | 69 | |
70 | - $prev_ticket = $registration->ticket()->ID(); |
|
71 | - } |
|
72 | - } |
|
73 | - ?> |
|
70 | + $prev_ticket = $registration->ticket()->ID(); |
|
71 | + } |
|
72 | + } |
|
73 | + ?> |
|
74 | 74 | </tbody> |
75 | 75 | </table> |
76 | 76 | </div><!-- close spco-ticket-info-dv --> |
77 | 77 | |
78 | 78 | <?php |
79 | - // Display the forms below the table. |
|
80 | - foreach ($registrations as $registration) { |
|
81 | - if ($registration instanceof EE_Registration) { |
|
82 | - // Attendee Questions. |
|
83 | - $reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link()); |
|
84 | - echo ${$reg_form}; |
|
85 | - } // if ( $registration instanceof EE_Registration ) |
|
86 | - } // end foreach ( $registrations as $registration ) |
|
79 | + // Display the forms below the table. |
|
80 | + foreach ($registrations as $registration) { |
|
81 | + if ($registration instanceof EE_Registration) { |
|
82 | + // Attendee Questions. |
|
83 | + $reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link()); |
|
84 | + echo ${$reg_form}; |
|
85 | + } // if ( $registration instanceof EE_Registration ) |
|
86 | + } // end foreach ( $registrations as $registration ) |
|
87 | 87 | |
88 | - ?> |
|
88 | + ?> |
|
89 | 89 | </div><!-- close spco-attendee-panel-dv --> |
90 | 90 | <?php |
91 | - echo $default_hidden_inputs; |
|
91 | + echo $default_hidden_inputs; |
|
92 | 92 | } // end if ( count( $registrations ) > 0 ) |
93 | 93 | |
94 | 94 | ?> |
@@ -22,1229 +22,1229 @@ |
||
22 | 22 | class EE_Register_Addon implements EEI_Plugin_API |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * possibly truncated version of the EE core version string |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected static $_core_version = ''; |
|
25 | + /** |
|
26 | + * possibly truncated version of the EE core version string |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected static $_core_version = ''; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Holds values for registered addons |
|
34 | - * |
|
35 | - * @var array |
|
36 | - */ |
|
37 | - protected static $_settings = array(); |
|
32 | + /** |
|
33 | + * Holds values for registered addons |
|
34 | + * |
|
35 | + * @var array |
|
36 | + */ |
|
37 | + protected static $_settings = array(); |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var array $_incompatible_addons keys are addon SLUGS |
|
41 | - * (first argument passed to EE_Register_Addon::register()), keys are |
|
42 | - * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
43 | - * Generally this should be used sparingly, as we don't want to muddle up |
|
44 | - * EE core with knowledge of ALL the addons out there. |
|
45 | - * If you want NO versions of an addon to run with a certain version of core, |
|
46 | - * it's usually best to define the addon's "min_core_version" as part of its call |
|
47 | - * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
48 | - * minimum plugin version. |
|
49 | - * @access protected |
|
50 | - */ |
|
51 | - protected static $_incompatible_addons = array( |
|
52 | - 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
53 | - 'Promotions' => '1.0.0.rc.084', |
|
54 | - ); |
|
39 | + /** |
|
40 | + * @var array $_incompatible_addons keys are addon SLUGS |
|
41 | + * (first argument passed to EE_Register_Addon::register()), keys are |
|
42 | + * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
43 | + * Generally this should be used sparingly, as we don't want to muddle up |
|
44 | + * EE core with knowledge of ALL the addons out there. |
|
45 | + * If you want NO versions of an addon to run with a certain version of core, |
|
46 | + * it's usually best to define the addon's "min_core_version" as part of its call |
|
47 | + * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
48 | + * minimum plugin version. |
|
49 | + * @access protected |
|
50 | + */ |
|
51 | + protected static $_incompatible_addons = array( |
|
52 | + 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
53 | + 'Promotions' => '1.0.0.rc.084', |
|
54 | + ); |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * We should always be comparing core to a version like '4.3.0.rc.000', |
|
59 | - * not just '4.3.0'. |
|
60 | - * So if the addon developer doesn't provide that full version string, |
|
61 | - * fill in the blanks for them |
|
62 | - * |
|
63 | - * @param string $min_core_version |
|
64 | - * @return string always like '4.3.0.rc.000' |
|
65 | - */ |
|
66 | - protected static function _effective_version($min_core_version) |
|
67 | - { |
|
68 | - // versions: 4 . 3 . 1 . p . 123 |
|
69 | - // offsets: 0 . 1 . 2 . 3 . 4 |
|
70 | - $version_parts = explode('.', $min_core_version); |
|
71 | - // check they specified the micro version (after 2nd period) |
|
72 | - if (! isset($version_parts[2])) { |
|
73 | - $version_parts[2] = '0'; |
|
74 | - } |
|
75 | - // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
76 | - // soon we can assume that's 'rc', but this current version is 'alpha' |
|
77 | - if (! isset($version_parts[3])) { |
|
78 | - $version_parts[3] = 'dev'; |
|
79 | - } |
|
80 | - if (! isset($version_parts[4])) { |
|
81 | - $version_parts[4] = '000'; |
|
82 | - } |
|
83 | - return implode('.', $version_parts); |
|
84 | - } |
|
57 | + /** |
|
58 | + * We should always be comparing core to a version like '4.3.0.rc.000', |
|
59 | + * not just '4.3.0'. |
|
60 | + * So if the addon developer doesn't provide that full version string, |
|
61 | + * fill in the blanks for them |
|
62 | + * |
|
63 | + * @param string $min_core_version |
|
64 | + * @return string always like '4.3.0.rc.000' |
|
65 | + */ |
|
66 | + protected static function _effective_version($min_core_version) |
|
67 | + { |
|
68 | + // versions: 4 . 3 . 1 . p . 123 |
|
69 | + // offsets: 0 . 1 . 2 . 3 . 4 |
|
70 | + $version_parts = explode('.', $min_core_version); |
|
71 | + // check they specified the micro version (after 2nd period) |
|
72 | + if (! isset($version_parts[2])) { |
|
73 | + $version_parts[2] = '0'; |
|
74 | + } |
|
75 | + // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
76 | + // soon we can assume that's 'rc', but this current version is 'alpha' |
|
77 | + if (! isset($version_parts[3])) { |
|
78 | + $version_parts[3] = 'dev'; |
|
79 | + } |
|
80 | + if (! isset($version_parts[4])) { |
|
81 | + $version_parts[4] = '000'; |
|
82 | + } |
|
83 | + return implode('.', $version_parts); |
|
84 | + } |
|
85 | 85 | |
86 | 86 | |
87 | - /** |
|
88 | - * Returns whether or not the min core version requirement of the addon is met |
|
89 | - * |
|
90 | - * @param string $min_core_version the minimum core version required by the addon |
|
91 | - * @param string $actual_core_version the actual core version, optional |
|
92 | - * @return boolean |
|
93 | - */ |
|
94 | - public static function _meets_min_core_version_requirement( |
|
95 | - $min_core_version, |
|
96 | - $actual_core_version = EVENT_ESPRESSO_VERSION |
|
97 | - ) { |
|
98 | - return version_compare( |
|
99 | - self::_effective_version($actual_core_version), |
|
100 | - self::_effective_version($min_core_version), |
|
101 | - '>=' |
|
102 | - ); |
|
103 | - } |
|
87 | + /** |
|
88 | + * Returns whether or not the min core version requirement of the addon is met |
|
89 | + * |
|
90 | + * @param string $min_core_version the minimum core version required by the addon |
|
91 | + * @param string $actual_core_version the actual core version, optional |
|
92 | + * @return boolean |
|
93 | + */ |
|
94 | + public static function _meets_min_core_version_requirement( |
|
95 | + $min_core_version, |
|
96 | + $actual_core_version = EVENT_ESPRESSO_VERSION |
|
97 | + ) { |
|
98 | + return version_compare( |
|
99 | + self::_effective_version($actual_core_version), |
|
100 | + self::_effective_version($min_core_version), |
|
101 | + '>=' |
|
102 | + ); |
|
103 | + } |
|
104 | 104 | |
105 | 105 | |
106 | - /** |
|
107 | - * Method for registering new EE_Addons. |
|
108 | - * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
109 | - * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
110 | - * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
111 | - * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
112 | - * 'activate_plugin', it registers the addon still, but its components are not registered |
|
113 | - * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
114 | - * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
115 | - * (so that we can detect that the addon has activated on the subsequent request) |
|
116 | - * |
|
117 | - * @since 4.3.0 |
|
118 | - * @param string $addon_name [Required] the EE_Addon's name. |
|
119 | - * @param array $setup_args { |
|
120 | - * An array of arguments provided for registering |
|
121 | - * the message type. |
|
122 | - * @type string $class_name the addon's main file name. |
|
123 | - * If left blank, generated from the addon name, |
|
124 | - * changes something like "calendar" to |
|
125 | - * "EE_Calendar" |
|
126 | - * @type string $min_core_version the minimum version of EE Core that the |
|
127 | - * addon will work with. eg "4.8.1.rc.084" |
|
128 | - * @type string $version the "software" version for the addon. eg |
|
129 | - * "1.0.0.p" for a first stable release, or |
|
130 | - * "1.0.0.rc.043" for a version in progress |
|
131 | - * @type string $main_file_path the full server path to the main file |
|
132 | - * loaded directly by WP |
|
133 | - * @type DomainInterface $domain child class of |
|
134 | - * EventEspresso\core\domain\DomainBase |
|
135 | - * @type string $domain_fqcn Fully Qualified Class Name |
|
136 | - * for the addon's Domain class |
|
137 | - * (see EventEspresso\core\domain\Domain) |
|
138 | - * @type string $admin_path full server path to the folder where the |
|
139 | - * addon\'s admin files reside |
|
140 | - * @type string $admin_callback a method to be called when the EE Admin is |
|
141 | - * first invoked, can be used for hooking into |
|
142 | - * any admin page |
|
143 | - * @type string $config_section the section name for this addon's |
|
144 | - * configuration settings section |
|
145 | - * (defaults to "addons") |
|
146 | - * @type string $config_class the class name for this addon's |
|
147 | - * configuration settings object |
|
148 | - * @type string $config_name the class name for this addon's |
|
149 | - * configuration settings object |
|
150 | - * @type string $autoloader_paths [Required] an array of class names and the full |
|
151 | - * server paths to those files. |
|
152 | - * @type string $autoloader_folders an array of "full server paths" for any |
|
153 | - * folders containing classes that might be |
|
154 | - * invoked by the addon |
|
155 | - * @type string $dms_paths [Required] an array of full server paths to |
|
156 | - * folders that contain data migration scripts. |
|
157 | - * The key should be the EE_Addon class name that |
|
158 | - * this set of data migration scripts belongs to. |
|
159 | - * If the EE_Addon class is namespaced, then this |
|
160 | - * needs to be the Fully Qualified Class Name |
|
161 | - * @type string $module_paths an array of full server paths to any |
|
162 | - * EED_Modules used by the addon |
|
163 | - * @type string $shortcode_paths an array of full server paths to folders |
|
164 | - * that contain EES_Shortcodes |
|
165 | - * @type string $widget_paths an array of full server paths to folders |
|
166 | - * that contain WP_Widgets |
|
167 | - * @type string $pue_options |
|
168 | - * @type array $capabilities an array indexed by role name |
|
169 | - * (i.e administrator,author ) and the values |
|
170 | - * are an array of caps to add to the role. |
|
171 | - * 'administrator' => array( |
|
172 | - * 'read_addon', |
|
173 | - * 'edit_addon', |
|
174 | - * etc. |
|
175 | - * ). |
|
176 | - * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
177 | - * for any addons that need to register any |
|
178 | - * special meta mapped capabilities. Should |
|
179 | - * be indexed where the key is the |
|
180 | - * EE_Meta_Capability_Map class name and the |
|
181 | - * values are the arguments sent to the class. |
|
182 | - * @type array $model_paths array of folders containing DB models |
|
183 | - * @see EE_Register_Model |
|
184 | - * @type array $class_paths array of folders containing DB classes |
|
185 | - * @see EE_Register_Model |
|
186 | - * @type array $model_extension_paths array of folders containing DB model |
|
187 | - * extensions |
|
188 | - * @see EE_Register_Model_Extension |
|
189 | - * @type array $class_extension_paths array of folders containing DB class |
|
190 | - * extensions |
|
191 | - * @see EE_Register_Model_Extension |
|
192 | - * @type array message_types { |
|
193 | - * An array of message types with the key as |
|
194 | - * the message type name and the values as |
|
195 | - * below: |
|
196 | - * @type string $mtfilename [Required] The filename of the message type |
|
197 | - * being registered. This will be the main |
|
198 | - * EE_{Message Type Name}_message_type class. |
|
199 | - * for example: |
|
200 | - * EE_Declined_Registration_message_type.class.php |
|
201 | - * @type array $autoloadpaths [Required] An array of paths to add to the |
|
202 | - * messages autoloader for the new message type. |
|
203 | - * @type array $messengers_to_activate_with An array of messengers that this message |
|
204 | - * type should activate with. Each value in |
|
205 | - * the |
|
206 | - * array |
|
207 | - * should match the name property of a |
|
208 | - * EE_messenger. Optional. |
|
209 | - * @type array $messengers_to_validate_with An array of messengers that this message |
|
210 | - * type should validate with. Each value in |
|
211 | - * the |
|
212 | - * array |
|
213 | - * should match the name property of an |
|
214 | - * EE_messenger. |
|
215 | - * Optional. |
|
216 | - * } |
|
217 | - * @type array $custom_post_types |
|
218 | - * @type array $custom_taxonomies |
|
219 | - * @type array $payment_method_paths each element is the folder containing the |
|
220 | - * EE_PMT_Base child class |
|
221 | - * (eg, |
|
222 | - * '/wp-content/plugins/my_plugin/Payomatic/' |
|
223 | - * which contains the files |
|
224 | - * EE_PMT_Payomatic.pm.php) |
|
225 | - * @type array $default_terms |
|
226 | - * @type array $namespace { |
|
227 | - * An array with two items for registering the |
|
228 | - * addon's namespace. (If, for some reason, you |
|
229 | - * require additional namespaces, |
|
230 | - * use |
|
231 | - * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
232 | - * directly) |
|
233 | - * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
234 | - * @type string $FQNS the namespace prefix |
|
235 | - * @type string $DIR a base directory for class files in the |
|
236 | - * namespace. |
|
237 | - * } |
|
238 | - * } |
|
239 | - * @type string $privacy_policies FQNSs (namespaces, each of which contains only |
|
240 | - * privacy policy classes) or FQCNs (specific |
|
241 | - * classnames of privacy policy classes) |
|
242 | - * @type string $personal_data_exporters FQNSs (namespaces, each of which contains only |
|
243 | - * privacy policy classes) or FQCNs (specific |
|
244 | - * classnames of privacy policy classes) |
|
245 | - * @type string $personal_data_erasers FQNSs (namespaces, each of which contains only |
|
246 | - * privacy policy classes) or FQCNs (specific |
|
247 | - * classnames of privacy policy classes) |
|
248 | - * @return void |
|
249 | - * @throws DomainException |
|
250 | - * @throws EE_Error |
|
251 | - * @throws InvalidArgumentException |
|
252 | - * @throws ReflectionException |
|
253 | - * @throws InvalidDataTypeException |
|
254 | - * @throws InvalidInterfaceException |
|
255 | - */ |
|
256 | - public static function register($addon_name = '', $setup_args = array()) |
|
257 | - { |
|
258 | - // required fields MUST be present, so let's make sure they are. |
|
259 | - EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
260 | - // get class name for addon |
|
261 | - $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
262 | - // setup $_settings array from incoming values. |
|
263 | - $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
264 | - // setup PUE |
|
265 | - EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
266 | - // does this addon work with this version of core or WordPress ? |
|
267 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
268 | - return; |
|
269 | - } |
|
270 | - // register namespaces |
|
271 | - EE_Register_Addon::_setup_namespaces($addon_settings); |
|
272 | - // check if this is an activation request |
|
273 | - if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
274 | - // dont bother setting up the rest of the addon atm |
|
275 | - return; |
|
276 | - } |
|
277 | - // we need cars |
|
278 | - EE_Register_Addon::_setup_autoloaders($addon_name); |
|
279 | - // register new models and extensions |
|
280 | - EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
281 | - // setup DMS |
|
282 | - EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
283 | - // if config_class is present let's register config. |
|
284 | - EE_Register_Addon::_register_config($addon_name); |
|
285 | - // register admin pages |
|
286 | - EE_Register_Addon::_register_admin_pages($addon_name); |
|
287 | - // add to list of modules to be registered |
|
288 | - EE_Register_Addon::_register_modules($addon_name); |
|
289 | - // add to list of shortcodes to be registered |
|
290 | - EE_Register_Addon::_register_shortcodes($addon_name); |
|
291 | - // add to list of widgets to be registered |
|
292 | - EE_Register_Addon::_register_widgets($addon_name); |
|
293 | - // register capability related stuff. |
|
294 | - EE_Register_Addon::_register_capabilities($addon_name); |
|
295 | - // any message type to register? |
|
296 | - EE_Register_Addon::_register_message_types($addon_name); |
|
297 | - // any custom post type/ custom capabilities or default terms to register |
|
298 | - EE_Register_Addon::_register_custom_post_types($addon_name); |
|
299 | - // and any payment methods |
|
300 | - EE_Register_Addon::_register_payment_methods($addon_name); |
|
301 | - // and privacy policy generators |
|
302 | - EE_Register_Addon::registerPrivacyPolicies($addon_name); |
|
303 | - // and privacy policy generators |
|
304 | - EE_Register_Addon::registerPersonalDataExporters($addon_name); |
|
305 | - // and privacy policy generators |
|
306 | - EE_Register_Addon::registerPersonalDataErasers($addon_name); |
|
307 | - // load and instantiate main addon class |
|
308 | - $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
309 | - // delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
310 | - add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
311 | - } |
|
106 | + /** |
|
107 | + * Method for registering new EE_Addons. |
|
108 | + * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
109 | + * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
110 | + * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
111 | + * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
112 | + * 'activate_plugin', it registers the addon still, but its components are not registered |
|
113 | + * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
114 | + * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
115 | + * (so that we can detect that the addon has activated on the subsequent request) |
|
116 | + * |
|
117 | + * @since 4.3.0 |
|
118 | + * @param string $addon_name [Required] the EE_Addon's name. |
|
119 | + * @param array $setup_args { |
|
120 | + * An array of arguments provided for registering |
|
121 | + * the message type. |
|
122 | + * @type string $class_name the addon's main file name. |
|
123 | + * If left blank, generated from the addon name, |
|
124 | + * changes something like "calendar" to |
|
125 | + * "EE_Calendar" |
|
126 | + * @type string $min_core_version the minimum version of EE Core that the |
|
127 | + * addon will work with. eg "4.8.1.rc.084" |
|
128 | + * @type string $version the "software" version for the addon. eg |
|
129 | + * "1.0.0.p" for a first stable release, or |
|
130 | + * "1.0.0.rc.043" for a version in progress |
|
131 | + * @type string $main_file_path the full server path to the main file |
|
132 | + * loaded directly by WP |
|
133 | + * @type DomainInterface $domain child class of |
|
134 | + * EventEspresso\core\domain\DomainBase |
|
135 | + * @type string $domain_fqcn Fully Qualified Class Name |
|
136 | + * for the addon's Domain class |
|
137 | + * (see EventEspresso\core\domain\Domain) |
|
138 | + * @type string $admin_path full server path to the folder where the |
|
139 | + * addon\'s admin files reside |
|
140 | + * @type string $admin_callback a method to be called when the EE Admin is |
|
141 | + * first invoked, can be used for hooking into |
|
142 | + * any admin page |
|
143 | + * @type string $config_section the section name for this addon's |
|
144 | + * configuration settings section |
|
145 | + * (defaults to "addons") |
|
146 | + * @type string $config_class the class name for this addon's |
|
147 | + * configuration settings object |
|
148 | + * @type string $config_name the class name for this addon's |
|
149 | + * configuration settings object |
|
150 | + * @type string $autoloader_paths [Required] an array of class names and the full |
|
151 | + * server paths to those files. |
|
152 | + * @type string $autoloader_folders an array of "full server paths" for any |
|
153 | + * folders containing classes that might be |
|
154 | + * invoked by the addon |
|
155 | + * @type string $dms_paths [Required] an array of full server paths to |
|
156 | + * folders that contain data migration scripts. |
|
157 | + * The key should be the EE_Addon class name that |
|
158 | + * this set of data migration scripts belongs to. |
|
159 | + * If the EE_Addon class is namespaced, then this |
|
160 | + * needs to be the Fully Qualified Class Name |
|
161 | + * @type string $module_paths an array of full server paths to any |
|
162 | + * EED_Modules used by the addon |
|
163 | + * @type string $shortcode_paths an array of full server paths to folders |
|
164 | + * that contain EES_Shortcodes |
|
165 | + * @type string $widget_paths an array of full server paths to folders |
|
166 | + * that contain WP_Widgets |
|
167 | + * @type string $pue_options |
|
168 | + * @type array $capabilities an array indexed by role name |
|
169 | + * (i.e administrator,author ) and the values |
|
170 | + * are an array of caps to add to the role. |
|
171 | + * 'administrator' => array( |
|
172 | + * 'read_addon', |
|
173 | + * 'edit_addon', |
|
174 | + * etc. |
|
175 | + * ). |
|
176 | + * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
177 | + * for any addons that need to register any |
|
178 | + * special meta mapped capabilities. Should |
|
179 | + * be indexed where the key is the |
|
180 | + * EE_Meta_Capability_Map class name and the |
|
181 | + * values are the arguments sent to the class. |
|
182 | + * @type array $model_paths array of folders containing DB models |
|
183 | + * @see EE_Register_Model |
|
184 | + * @type array $class_paths array of folders containing DB classes |
|
185 | + * @see EE_Register_Model |
|
186 | + * @type array $model_extension_paths array of folders containing DB model |
|
187 | + * extensions |
|
188 | + * @see EE_Register_Model_Extension |
|
189 | + * @type array $class_extension_paths array of folders containing DB class |
|
190 | + * extensions |
|
191 | + * @see EE_Register_Model_Extension |
|
192 | + * @type array message_types { |
|
193 | + * An array of message types with the key as |
|
194 | + * the message type name and the values as |
|
195 | + * below: |
|
196 | + * @type string $mtfilename [Required] The filename of the message type |
|
197 | + * being registered. This will be the main |
|
198 | + * EE_{Message Type Name}_message_type class. |
|
199 | + * for example: |
|
200 | + * EE_Declined_Registration_message_type.class.php |
|
201 | + * @type array $autoloadpaths [Required] An array of paths to add to the |
|
202 | + * messages autoloader for the new message type. |
|
203 | + * @type array $messengers_to_activate_with An array of messengers that this message |
|
204 | + * type should activate with. Each value in |
|
205 | + * the |
|
206 | + * array |
|
207 | + * should match the name property of a |
|
208 | + * EE_messenger. Optional. |
|
209 | + * @type array $messengers_to_validate_with An array of messengers that this message |
|
210 | + * type should validate with. Each value in |
|
211 | + * the |
|
212 | + * array |
|
213 | + * should match the name property of an |
|
214 | + * EE_messenger. |
|
215 | + * Optional. |
|
216 | + * } |
|
217 | + * @type array $custom_post_types |
|
218 | + * @type array $custom_taxonomies |
|
219 | + * @type array $payment_method_paths each element is the folder containing the |
|
220 | + * EE_PMT_Base child class |
|
221 | + * (eg, |
|
222 | + * '/wp-content/plugins/my_plugin/Payomatic/' |
|
223 | + * which contains the files |
|
224 | + * EE_PMT_Payomatic.pm.php) |
|
225 | + * @type array $default_terms |
|
226 | + * @type array $namespace { |
|
227 | + * An array with two items for registering the |
|
228 | + * addon's namespace. (If, for some reason, you |
|
229 | + * require additional namespaces, |
|
230 | + * use |
|
231 | + * EventEspresso\core\Psr4Autoloader::addNamespace() |
|
232 | + * directly) |
|
233 | + * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
234 | + * @type string $FQNS the namespace prefix |
|
235 | + * @type string $DIR a base directory for class files in the |
|
236 | + * namespace. |
|
237 | + * } |
|
238 | + * } |
|
239 | + * @type string $privacy_policies FQNSs (namespaces, each of which contains only |
|
240 | + * privacy policy classes) or FQCNs (specific |
|
241 | + * classnames of privacy policy classes) |
|
242 | + * @type string $personal_data_exporters FQNSs (namespaces, each of which contains only |
|
243 | + * privacy policy classes) or FQCNs (specific |
|
244 | + * classnames of privacy policy classes) |
|
245 | + * @type string $personal_data_erasers FQNSs (namespaces, each of which contains only |
|
246 | + * privacy policy classes) or FQCNs (specific |
|
247 | + * classnames of privacy policy classes) |
|
248 | + * @return void |
|
249 | + * @throws DomainException |
|
250 | + * @throws EE_Error |
|
251 | + * @throws InvalidArgumentException |
|
252 | + * @throws ReflectionException |
|
253 | + * @throws InvalidDataTypeException |
|
254 | + * @throws InvalidInterfaceException |
|
255 | + */ |
|
256 | + public static function register($addon_name = '', $setup_args = array()) |
|
257 | + { |
|
258 | + // required fields MUST be present, so let's make sure they are. |
|
259 | + EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
260 | + // get class name for addon |
|
261 | + $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
262 | + // setup $_settings array from incoming values. |
|
263 | + $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
264 | + // setup PUE |
|
265 | + EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
266 | + // does this addon work with this version of core or WordPress ? |
|
267 | + if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
268 | + return; |
|
269 | + } |
|
270 | + // register namespaces |
|
271 | + EE_Register_Addon::_setup_namespaces($addon_settings); |
|
272 | + // check if this is an activation request |
|
273 | + if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
274 | + // dont bother setting up the rest of the addon atm |
|
275 | + return; |
|
276 | + } |
|
277 | + // we need cars |
|
278 | + EE_Register_Addon::_setup_autoloaders($addon_name); |
|
279 | + // register new models and extensions |
|
280 | + EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
281 | + // setup DMS |
|
282 | + EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
283 | + // if config_class is present let's register config. |
|
284 | + EE_Register_Addon::_register_config($addon_name); |
|
285 | + // register admin pages |
|
286 | + EE_Register_Addon::_register_admin_pages($addon_name); |
|
287 | + // add to list of modules to be registered |
|
288 | + EE_Register_Addon::_register_modules($addon_name); |
|
289 | + // add to list of shortcodes to be registered |
|
290 | + EE_Register_Addon::_register_shortcodes($addon_name); |
|
291 | + // add to list of widgets to be registered |
|
292 | + EE_Register_Addon::_register_widgets($addon_name); |
|
293 | + // register capability related stuff. |
|
294 | + EE_Register_Addon::_register_capabilities($addon_name); |
|
295 | + // any message type to register? |
|
296 | + EE_Register_Addon::_register_message_types($addon_name); |
|
297 | + // any custom post type/ custom capabilities or default terms to register |
|
298 | + EE_Register_Addon::_register_custom_post_types($addon_name); |
|
299 | + // and any payment methods |
|
300 | + EE_Register_Addon::_register_payment_methods($addon_name); |
|
301 | + // and privacy policy generators |
|
302 | + EE_Register_Addon::registerPrivacyPolicies($addon_name); |
|
303 | + // and privacy policy generators |
|
304 | + EE_Register_Addon::registerPersonalDataExporters($addon_name); |
|
305 | + // and privacy policy generators |
|
306 | + EE_Register_Addon::registerPersonalDataErasers($addon_name); |
|
307 | + // load and instantiate main addon class |
|
308 | + $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
309 | + // delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
310 | + add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
311 | + } |
|
312 | 312 | |
313 | 313 | |
314 | - /** |
|
315 | - * @param string $addon_name |
|
316 | - * @param array $setup_args |
|
317 | - * @return void |
|
318 | - * @throws EE_Error |
|
319 | - */ |
|
320 | - private static function _verify_parameters($addon_name, array $setup_args) |
|
321 | - { |
|
322 | - // required fields MUST be present, so let's make sure they are. |
|
323 | - if (empty($addon_name) || ! is_array($setup_args)) { |
|
324 | - throw new EE_Error( |
|
325 | - __( |
|
326 | - 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
327 | - 'event_espresso' |
|
328 | - ) |
|
329 | - ); |
|
330 | - } |
|
331 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
332 | - throw new EE_Error( |
|
333 | - sprintf( |
|
334 | - __( |
|
335 | - 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
336 | - 'event_espresso' |
|
337 | - ), |
|
338 | - implode(',', array_keys($setup_args)) |
|
339 | - ) |
|
340 | - ); |
|
341 | - } |
|
342 | - // check that addon has not already been registered with that name |
|
343 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
344 | - throw new EE_Error( |
|
345 | - sprintf( |
|
346 | - __( |
|
347 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
348 | - 'event_espresso' |
|
349 | - ), |
|
350 | - $addon_name |
|
351 | - ) |
|
352 | - ); |
|
353 | - } |
|
354 | - } |
|
314 | + /** |
|
315 | + * @param string $addon_name |
|
316 | + * @param array $setup_args |
|
317 | + * @return void |
|
318 | + * @throws EE_Error |
|
319 | + */ |
|
320 | + private static function _verify_parameters($addon_name, array $setup_args) |
|
321 | + { |
|
322 | + // required fields MUST be present, so let's make sure they are. |
|
323 | + if (empty($addon_name) || ! is_array($setup_args)) { |
|
324 | + throw new EE_Error( |
|
325 | + __( |
|
326 | + 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
327 | + 'event_espresso' |
|
328 | + ) |
|
329 | + ); |
|
330 | + } |
|
331 | + if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
332 | + throw new EE_Error( |
|
333 | + sprintf( |
|
334 | + __( |
|
335 | + 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
336 | + 'event_espresso' |
|
337 | + ), |
|
338 | + implode(',', array_keys($setup_args)) |
|
339 | + ) |
|
340 | + ); |
|
341 | + } |
|
342 | + // check that addon has not already been registered with that name |
|
343 | + if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
344 | + throw new EE_Error( |
|
345 | + sprintf( |
|
346 | + __( |
|
347 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
348 | + 'event_espresso' |
|
349 | + ), |
|
350 | + $addon_name |
|
351 | + ) |
|
352 | + ); |
|
353 | + } |
|
354 | + } |
|
355 | 355 | |
356 | 356 | |
357 | - /** |
|
358 | - * @param string $addon_name |
|
359 | - * @param array $setup_args |
|
360 | - * @return string |
|
361 | - */ |
|
362 | - private static function _parse_class_name($addon_name, array $setup_args) |
|
363 | - { |
|
364 | - if (empty($setup_args['class_name'])) { |
|
365 | - // generate one by first separating name with spaces |
|
366 | - $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
367 | - // capitalize, then replace spaces with underscores |
|
368 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
369 | - } else { |
|
370 | - $class_name = $setup_args['class_name']; |
|
371 | - } |
|
372 | - // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
373 | - return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
374 | - ? $class_name |
|
375 | - : 'EE_' . $class_name; |
|
376 | - } |
|
357 | + /** |
|
358 | + * @param string $addon_name |
|
359 | + * @param array $setup_args |
|
360 | + * @return string |
|
361 | + */ |
|
362 | + private static function _parse_class_name($addon_name, array $setup_args) |
|
363 | + { |
|
364 | + if (empty($setup_args['class_name'])) { |
|
365 | + // generate one by first separating name with spaces |
|
366 | + $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
367 | + // capitalize, then replace spaces with underscores |
|
368 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
369 | + } else { |
|
370 | + $class_name = $setup_args['class_name']; |
|
371 | + } |
|
372 | + // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
373 | + return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
374 | + ? $class_name |
|
375 | + : 'EE_' . $class_name; |
|
376 | + } |
|
377 | 377 | |
378 | 378 | |
379 | - /** |
|
380 | - * @param string $class_name |
|
381 | - * @param array $setup_args |
|
382 | - * @return array |
|
383 | - */ |
|
384 | - private static function _get_addon_settings($class_name, array $setup_args) |
|
385 | - { |
|
386 | - // setup $_settings array from incoming values. |
|
387 | - $addon_settings = array( |
|
388 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
389 | - 'class_name' => $class_name, |
|
390 | - // the addon slug for use in URLs, etc |
|
391 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
392 | - ? (string) $setup_args['plugin_slug'] |
|
393 | - : '', |
|
394 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
395 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
396 | - ? (string) $setup_args['plugin_action_slug'] |
|
397 | - : '', |
|
398 | - // the "software" version for the addon |
|
399 | - 'version' => isset($setup_args['version']) |
|
400 | - ? (string) $setup_args['version'] |
|
401 | - : '', |
|
402 | - // the minimum version of EE Core that the addon will work with |
|
403 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
404 | - ? (string) $setup_args['min_core_version'] |
|
405 | - : '', |
|
406 | - // the minimum version of WordPress that the addon will work with |
|
407 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
408 | - ? (string) $setup_args['min_wp_version'] |
|
409 | - : EE_MIN_WP_VER_REQUIRED, |
|
410 | - // full server path to main file (file loaded directly by WP) |
|
411 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
412 | - ? (string) $setup_args['main_file_path'] |
|
413 | - : '', |
|
414 | - // instance of \EventEspresso\core\domain\DomainInterface |
|
415 | - 'domain' => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface |
|
416 | - ? $setup_args['domain'] |
|
417 | - : null, |
|
418 | - // Fully Qualified Class Name for the addon's Domain class |
|
419 | - 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
420 | - ? (string) $setup_args['domain_fqcn'] |
|
421 | - : '', |
|
422 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
423 | - 'admin_path' => isset($setup_args['admin_path']) |
|
424 | - ? (string) $setup_args['admin_path'] : '', |
|
425 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
426 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
427 | - ? (string) $setup_args['admin_callback'] |
|
428 | - : '', |
|
429 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
430 | - 'config_section' => isset($setup_args['config_section']) |
|
431 | - ? (string) $setup_args['config_section'] |
|
432 | - : 'addons', |
|
433 | - // the class name for this addon's configuration settings object |
|
434 | - 'config_class' => isset($setup_args['config_class']) |
|
435 | - ? (string) $setup_args['config_class'] : '', |
|
436 | - // the name given to the config for this addons' configuration settings object (optional) |
|
437 | - 'config_name' => isset($setup_args['config_name']) |
|
438 | - ? (string) $setup_args['config_name'] : '', |
|
439 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
440 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
441 | - ? (array) $setup_args['autoloader_paths'] |
|
442 | - : array(), |
|
443 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
444 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
445 | - ? (array) $setup_args['autoloader_folders'] |
|
446 | - : array(), |
|
447 | - // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
448 | - // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
449 | - // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
450 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
451 | - ? (array) $setup_args['dms_paths'] |
|
452 | - : array(), |
|
453 | - // array of full server paths to any EED_Modules used by the addon |
|
454 | - 'module_paths' => isset($setup_args['module_paths']) |
|
455 | - ? (array) $setup_args['module_paths'] |
|
456 | - : array(), |
|
457 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
458 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
459 | - ? (array) $setup_args['shortcode_paths'] |
|
460 | - : array(), |
|
461 | - 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
462 | - ? (array) $setup_args['shortcode_fqcns'] |
|
463 | - : array(), |
|
464 | - // array of full server paths to any WP_Widgets used by the addon |
|
465 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
466 | - ? (array) $setup_args['widget_paths'] |
|
467 | - : array(), |
|
468 | - // array of PUE options used by the addon |
|
469 | - 'pue_options' => isset($setup_args['pue_options']) |
|
470 | - ? (array) $setup_args['pue_options'] |
|
471 | - : array(), |
|
472 | - 'message_types' => isset($setup_args['message_types']) |
|
473 | - ? (array) $setup_args['message_types'] |
|
474 | - : array(), |
|
475 | - 'capabilities' => isset($setup_args['capabilities']) |
|
476 | - ? (array) $setup_args['capabilities'] |
|
477 | - : array(), |
|
478 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
479 | - ? (array) $setup_args['capability_maps'] |
|
480 | - : array(), |
|
481 | - 'model_paths' => isset($setup_args['model_paths']) |
|
482 | - ? (array) $setup_args['model_paths'] |
|
483 | - : array(), |
|
484 | - 'class_paths' => isset($setup_args['class_paths']) |
|
485 | - ? (array) $setup_args['class_paths'] |
|
486 | - : array(), |
|
487 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
488 | - ? (array) $setup_args['model_extension_paths'] |
|
489 | - : array(), |
|
490 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
491 | - ? (array) $setup_args['class_extension_paths'] |
|
492 | - : array(), |
|
493 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
494 | - ? (array) $setup_args['custom_post_types'] |
|
495 | - : array(), |
|
496 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
497 | - ? (array) $setup_args['custom_taxonomies'] |
|
498 | - : array(), |
|
499 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
500 | - ? (array) $setup_args['payment_method_paths'] |
|
501 | - : array(), |
|
502 | - 'default_terms' => isset($setup_args['default_terms']) |
|
503 | - ? (array) $setup_args['default_terms'] |
|
504 | - : array(), |
|
505 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
506 | - // that can be used for adding upgrading/marketing info |
|
507 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
508 | - ? $setup_args['plugins_page_row'] |
|
509 | - : '', |
|
510 | - 'namespace' => isset( |
|
511 | - $setup_args['namespace']['FQNS'], |
|
512 | - $setup_args['namespace']['DIR'] |
|
513 | - ) |
|
514 | - ? (array) $setup_args['namespace'] |
|
515 | - : array(), |
|
516 | - 'privacy_policies' => isset($setup_args['privacy_policies']) |
|
517 | - ? (array) $setup_args['privacy_policies'] |
|
518 | - : '', |
|
519 | - ); |
|
520 | - // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
521 | - // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
522 | - $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
523 | - && ! empty($addon_settings['admin_path']) |
|
524 | - ? $addon_settings['plugin_slug'] |
|
525 | - : $addon_settings['plugin_action_slug']; |
|
526 | - // full server path to main file (file loaded directly by WP) |
|
527 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
528 | - return $addon_settings; |
|
529 | - } |
|
379 | + /** |
|
380 | + * @param string $class_name |
|
381 | + * @param array $setup_args |
|
382 | + * @return array |
|
383 | + */ |
|
384 | + private static function _get_addon_settings($class_name, array $setup_args) |
|
385 | + { |
|
386 | + // setup $_settings array from incoming values. |
|
387 | + $addon_settings = array( |
|
388 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
389 | + 'class_name' => $class_name, |
|
390 | + // the addon slug for use in URLs, etc |
|
391 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
392 | + ? (string) $setup_args['plugin_slug'] |
|
393 | + : '', |
|
394 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
395 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
396 | + ? (string) $setup_args['plugin_action_slug'] |
|
397 | + : '', |
|
398 | + // the "software" version for the addon |
|
399 | + 'version' => isset($setup_args['version']) |
|
400 | + ? (string) $setup_args['version'] |
|
401 | + : '', |
|
402 | + // the minimum version of EE Core that the addon will work with |
|
403 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
404 | + ? (string) $setup_args['min_core_version'] |
|
405 | + : '', |
|
406 | + // the minimum version of WordPress that the addon will work with |
|
407 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
408 | + ? (string) $setup_args['min_wp_version'] |
|
409 | + : EE_MIN_WP_VER_REQUIRED, |
|
410 | + // full server path to main file (file loaded directly by WP) |
|
411 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
412 | + ? (string) $setup_args['main_file_path'] |
|
413 | + : '', |
|
414 | + // instance of \EventEspresso\core\domain\DomainInterface |
|
415 | + 'domain' => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface |
|
416 | + ? $setup_args['domain'] |
|
417 | + : null, |
|
418 | + // Fully Qualified Class Name for the addon's Domain class |
|
419 | + 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
420 | + ? (string) $setup_args['domain_fqcn'] |
|
421 | + : '', |
|
422 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
423 | + 'admin_path' => isset($setup_args['admin_path']) |
|
424 | + ? (string) $setup_args['admin_path'] : '', |
|
425 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
426 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
427 | + ? (string) $setup_args['admin_callback'] |
|
428 | + : '', |
|
429 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
430 | + 'config_section' => isset($setup_args['config_section']) |
|
431 | + ? (string) $setup_args['config_section'] |
|
432 | + : 'addons', |
|
433 | + // the class name for this addon's configuration settings object |
|
434 | + 'config_class' => isset($setup_args['config_class']) |
|
435 | + ? (string) $setup_args['config_class'] : '', |
|
436 | + // the name given to the config for this addons' configuration settings object (optional) |
|
437 | + 'config_name' => isset($setup_args['config_name']) |
|
438 | + ? (string) $setup_args['config_name'] : '', |
|
439 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
440 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
441 | + ? (array) $setup_args['autoloader_paths'] |
|
442 | + : array(), |
|
443 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
444 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
445 | + ? (array) $setup_args['autoloader_folders'] |
|
446 | + : array(), |
|
447 | + // array of full server paths to any EE_DMS data migration scripts used by the addon. |
|
448 | + // The key should be the EE_Addon class name that this set of data migration scripts belongs to. |
|
449 | + // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name |
|
450 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
451 | + ? (array) $setup_args['dms_paths'] |
|
452 | + : array(), |
|
453 | + // array of full server paths to any EED_Modules used by the addon |
|
454 | + 'module_paths' => isset($setup_args['module_paths']) |
|
455 | + ? (array) $setup_args['module_paths'] |
|
456 | + : array(), |
|
457 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
458 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
459 | + ? (array) $setup_args['shortcode_paths'] |
|
460 | + : array(), |
|
461 | + 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
462 | + ? (array) $setup_args['shortcode_fqcns'] |
|
463 | + : array(), |
|
464 | + // array of full server paths to any WP_Widgets used by the addon |
|
465 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
466 | + ? (array) $setup_args['widget_paths'] |
|
467 | + : array(), |
|
468 | + // array of PUE options used by the addon |
|
469 | + 'pue_options' => isset($setup_args['pue_options']) |
|
470 | + ? (array) $setup_args['pue_options'] |
|
471 | + : array(), |
|
472 | + 'message_types' => isset($setup_args['message_types']) |
|
473 | + ? (array) $setup_args['message_types'] |
|
474 | + : array(), |
|
475 | + 'capabilities' => isset($setup_args['capabilities']) |
|
476 | + ? (array) $setup_args['capabilities'] |
|
477 | + : array(), |
|
478 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
479 | + ? (array) $setup_args['capability_maps'] |
|
480 | + : array(), |
|
481 | + 'model_paths' => isset($setup_args['model_paths']) |
|
482 | + ? (array) $setup_args['model_paths'] |
|
483 | + : array(), |
|
484 | + 'class_paths' => isset($setup_args['class_paths']) |
|
485 | + ? (array) $setup_args['class_paths'] |
|
486 | + : array(), |
|
487 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
488 | + ? (array) $setup_args['model_extension_paths'] |
|
489 | + : array(), |
|
490 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
491 | + ? (array) $setup_args['class_extension_paths'] |
|
492 | + : array(), |
|
493 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
494 | + ? (array) $setup_args['custom_post_types'] |
|
495 | + : array(), |
|
496 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
497 | + ? (array) $setup_args['custom_taxonomies'] |
|
498 | + : array(), |
|
499 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
500 | + ? (array) $setup_args['payment_method_paths'] |
|
501 | + : array(), |
|
502 | + 'default_terms' => isset($setup_args['default_terms']) |
|
503 | + ? (array) $setup_args['default_terms'] |
|
504 | + : array(), |
|
505 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
506 | + // that can be used for adding upgrading/marketing info |
|
507 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
508 | + ? $setup_args['plugins_page_row'] |
|
509 | + : '', |
|
510 | + 'namespace' => isset( |
|
511 | + $setup_args['namespace']['FQNS'], |
|
512 | + $setup_args['namespace']['DIR'] |
|
513 | + ) |
|
514 | + ? (array) $setup_args['namespace'] |
|
515 | + : array(), |
|
516 | + 'privacy_policies' => isset($setup_args['privacy_policies']) |
|
517 | + ? (array) $setup_args['privacy_policies'] |
|
518 | + : '', |
|
519 | + ); |
|
520 | + // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
521 | + // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
522 | + $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
523 | + && ! empty($addon_settings['admin_path']) |
|
524 | + ? $addon_settings['plugin_slug'] |
|
525 | + : $addon_settings['plugin_action_slug']; |
|
526 | + // full server path to main file (file loaded directly by WP) |
|
527 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
528 | + return $addon_settings; |
|
529 | + } |
|
530 | 530 | |
531 | 531 | |
532 | - /** |
|
533 | - * @param string $addon_name |
|
534 | - * @param array $addon_settings |
|
535 | - * @return boolean |
|
536 | - */ |
|
537 | - private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
538 | - { |
|
539 | - global $wp_version; |
|
540 | - $incompatibility_message = ''; |
|
541 | - // check whether this addon version is compatible with EE core |
|
542 | - if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
543 | - && ! self::_meets_min_core_version_requirement( |
|
544 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
545 | - $addon_settings['version'] |
|
546 | - ) |
|
547 | - ) { |
|
548 | - $incompatibility_message = sprintf( |
|
549 | - __( |
|
550 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.', |
|
551 | - 'event_espresso' |
|
552 | - ), |
|
553 | - $addon_name, |
|
554 | - '<br />', |
|
555 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
556 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
557 | - '</span><br />' |
|
558 | - ); |
|
559 | - } elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
560 | - ) { |
|
561 | - $incompatibility_message = sprintf( |
|
562 | - __( |
|
563 | - '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
564 | - 'event_espresso' |
|
565 | - ), |
|
566 | - $addon_name, |
|
567 | - self::_effective_version($addon_settings['min_core_version']), |
|
568 | - self::_effective_version(espresso_version()), |
|
569 | - '<br />', |
|
570 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
571 | - '</span><br />' |
|
572 | - ); |
|
573 | - } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
574 | - $incompatibility_message = sprintf( |
|
575 | - __( |
|
576 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
577 | - 'event_espresso' |
|
578 | - ), |
|
579 | - $addon_name, |
|
580 | - $addon_settings['min_wp_version'], |
|
581 | - '<br />', |
|
582 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
583 | - '</span><br />' |
|
584 | - ); |
|
585 | - } |
|
586 | - if (! empty($incompatibility_message)) { |
|
587 | - // remove 'activate' from the REQUEST |
|
588 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
589 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
590 | - if (current_user_can('activate_plugins')) { |
|
591 | - // show an error message indicating the plugin didn't activate properly |
|
592 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
593 | - } |
|
594 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
595 | - return false; |
|
596 | - } |
|
597 | - // addon IS compatible |
|
598 | - return true; |
|
599 | - } |
|
532 | + /** |
|
533 | + * @param string $addon_name |
|
534 | + * @param array $addon_settings |
|
535 | + * @return boolean |
|
536 | + */ |
|
537 | + private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
538 | + { |
|
539 | + global $wp_version; |
|
540 | + $incompatibility_message = ''; |
|
541 | + // check whether this addon version is compatible with EE core |
|
542 | + if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
543 | + && ! self::_meets_min_core_version_requirement( |
|
544 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
545 | + $addon_settings['version'] |
|
546 | + ) |
|
547 | + ) { |
|
548 | + $incompatibility_message = sprintf( |
|
549 | + __( |
|
550 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.', |
|
551 | + 'event_espresso' |
|
552 | + ), |
|
553 | + $addon_name, |
|
554 | + '<br />', |
|
555 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
556 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
557 | + '</span><br />' |
|
558 | + ); |
|
559 | + } elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
560 | + ) { |
|
561 | + $incompatibility_message = sprintf( |
|
562 | + __( |
|
563 | + '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
564 | + 'event_espresso' |
|
565 | + ), |
|
566 | + $addon_name, |
|
567 | + self::_effective_version($addon_settings['min_core_version']), |
|
568 | + self::_effective_version(espresso_version()), |
|
569 | + '<br />', |
|
570 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
571 | + '</span><br />' |
|
572 | + ); |
|
573 | + } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
574 | + $incompatibility_message = sprintf( |
|
575 | + __( |
|
576 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
577 | + 'event_espresso' |
|
578 | + ), |
|
579 | + $addon_name, |
|
580 | + $addon_settings['min_wp_version'], |
|
581 | + '<br />', |
|
582 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
583 | + '</span><br />' |
|
584 | + ); |
|
585 | + } |
|
586 | + if (! empty($incompatibility_message)) { |
|
587 | + // remove 'activate' from the REQUEST |
|
588 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
589 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
590 | + if (current_user_can('activate_plugins')) { |
|
591 | + // show an error message indicating the plugin didn't activate properly |
|
592 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
593 | + } |
|
594 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
595 | + return false; |
|
596 | + } |
|
597 | + // addon IS compatible |
|
598 | + return true; |
|
599 | + } |
|
600 | 600 | |
601 | 601 | |
602 | - /** |
|
603 | - * if plugin update engine is being used for auto-updates, |
|
604 | - * then let's set that up now before going any further so that ALL addons can be updated |
|
605 | - * (not needed if PUE is not being used) |
|
606 | - * |
|
607 | - * @param string $addon_name |
|
608 | - * @param string $class_name |
|
609 | - * @param array $setup_args |
|
610 | - * @return void |
|
611 | - */ |
|
612 | - private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
613 | - { |
|
614 | - if (! empty($setup_args['pue_options'])) { |
|
615 | - self::$_settings[ $addon_name ]['pue_options'] = array( |
|
616 | - 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
617 | - ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
618 | - : 'espresso_' . strtolower($class_name), |
|
619 | - 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
620 | - ? (string) $setup_args['pue_options']['plugin_basename'] |
|
621 | - : plugin_basename($setup_args['main_file_path']), |
|
622 | - 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
623 | - ? (string) $setup_args['pue_options']['checkPeriod'] |
|
624 | - : '24', |
|
625 | - 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
626 | - ? (string) $setup_args['pue_options']['use_wp_update'] |
|
627 | - : false, |
|
628 | - ); |
|
629 | - add_action( |
|
630 | - 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
631 | - array('EE_Register_Addon', 'load_pue_update') |
|
632 | - ); |
|
633 | - } |
|
634 | - } |
|
602 | + /** |
|
603 | + * if plugin update engine is being used for auto-updates, |
|
604 | + * then let's set that up now before going any further so that ALL addons can be updated |
|
605 | + * (not needed if PUE is not being used) |
|
606 | + * |
|
607 | + * @param string $addon_name |
|
608 | + * @param string $class_name |
|
609 | + * @param array $setup_args |
|
610 | + * @return void |
|
611 | + */ |
|
612 | + private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
613 | + { |
|
614 | + if (! empty($setup_args['pue_options'])) { |
|
615 | + self::$_settings[ $addon_name ]['pue_options'] = array( |
|
616 | + 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
617 | + ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
618 | + : 'espresso_' . strtolower($class_name), |
|
619 | + 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
620 | + ? (string) $setup_args['pue_options']['plugin_basename'] |
|
621 | + : plugin_basename($setup_args['main_file_path']), |
|
622 | + 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
623 | + ? (string) $setup_args['pue_options']['checkPeriod'] |
|
624 | + : '24', |
|
625 | + 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
626 | + ? (string) $setup_args['pue_options']['use_wp_update'] |
|
627 | + : false, |
|
628 | + ); |
|
629 | + add_action( |
|
630 | + 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
631 | + array('EE_Register_Addon', 'load_pue_update') |
|
632 | + ); |
|
633 | + } |
|
634 | + } |
|
635 | 635 | |
636 | 636 | |
637 | - /** |
|
638 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
639 | - * |
|
640 | - * @param array $addon_settings |
|
641 | - * @return void |
|
642 | - */ |
|
643 | - private static function _setup_namespaces(array $addon_settings) |
|
644 | - { |
|
645 | - // |
|
646 | - if (isset( |
|
647 | - $addon_settings['namespace']['FQNS'], |
|
648 | - $addon_settings['namespace']['DIR'] |
|
649 | - )) { |
|
650 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
651 | - $addon_settings['namespace']['FQNS'], |
|
652 | - $addon_settings['namespace']['DIR'] |
|
653 | - ); |
|
654 | - } |
|
655 | - } |
|
637 | + /** |
|
638 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
639 | + * |
|
640 | + * @param array $addon_settings |
|
641 | + * @return void |
|
642 | + */ |
|
643 | + private static function _setup_namespaces(array $addon_settings) |
|
644 | + { |
|
645 | + // |
|
646 | + if (isset( |
|
647 | + $addon_settings['namespace']['FQNS'], |
|
648 | + $addon_settings['namespace']['DIR'] |
|
649 | + )) { |
|
650 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
651 | + $addon_settings['namespace']['FQNS'], |
|
652 | + $addon_settings['namespace']['DIR'] |
|
653 | + ); |
|
654 | + } |
|
655 | + } |
|
656 | 656 | |
657 | 657 | |
658 | - /** |
|
659 | - * @param string $addon_name |
|
660 | - * @param array $addon_settings |
|
661 | - * @return bool |
|
662 | - * @throws EE_Error |
|
663 | - * @throws InvalidArgumentException |
|
664 | - * @throws ReflectionException |
|
665 | - * @throws InvalidDataTypeException |
|
666 | - * @throws InvalidInterfaceException |
|
667 | - */ |
|
668 | - private static function _addon_activation($addon_name, array $addon_settings) |
|
669 | - { |
|
670 | - // this is an activation request |
|
671 | - if (did_action( |
|
672 | - 'activate_plugin' |
|
673 | - )) {// to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
674 | - // (as the newly-activated addon wasn't around the first time addons were registered). |
|
675 | - // Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
676 | - // property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
677 | - if (! isset(self::$_settings[ $addon_name ]) |
|
678 | - || (isset(self::$_settings[ $addon_name ]) |
|
679 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
680 | - ) |
|
681 | - ) { |
|
682 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
683 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
684 | - $addon->set_activation_indicator_option(); |
|
685 | - // dont bother setting up the rest of the addon. |
|
686 | - // we know it was just activated and the request will end soon |
|
687 | - } |
|
688 | - return true; |
|
689 | - } |
|
690 | - // make sure this was called in the right place! |
|
691 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
692 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
693 | - ) { |
|
694 | - EE_Error::doing_it_wrong( |
|
695 | - __METHOD__, |
|
696 | - sprintf( |
|
697 | - __( |
|
698 | - 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
699 | - 'event_espresso' |
|
700 | - ), |
|
701 | - $addon_name |
|
702 | - ), |
|
703 | - '4.3.0' |
|
704 | - ); |
|
705 | - } |
|
706 | - // make sure addon settings are set correctly without overwriting anything existing |
|
707 | - if (isset(self::$_settings[ $addon_name ])) { |
|
708 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
709 | - } else { |
|
710 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
711 | - } |
|
712 | - return false; |
|
713 | - } |
|
658 | + /** |
|
659 | + * @param string $addon_name |
|
660 | + * @param array $addon_settings |
|
661 | + * @return bool |
|
662 | + * @throws EE_Error |
|
663 | + * @throws InvalidArgumentException |
|
664 | + * @throws ReflectionException |
|
665 | + * @throws InvalidDataTypeException |
|
666 | + * @throws InvalidInterfaceException |
|
667 | + */ |
|
668 | + private static function _addon_activation($addon_name, array $addon_settings) |
|
669 | + { |
|
670 | + // this is an activation request |
|
671 | + if (did_action( |
|
672 | + 'activate_plugin' |
|
673 | + )) {// to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
674 | + // (as the newly-activated addon wasn't around the first time addons were registered). |
|
675 | + // Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
676 | + // property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
677 | + if (! isset(self::$_settings[ $addon_name ]) |
|
678 | + || (isset(self::$_settings[ $addon_name ]) |
|
679 | + && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
680 | + ) |
|
681 | + ) { |
|
682 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
683 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
684 | + $addon->set_activation_indicator_option(); |
|
685 | + // dont bother setting up the rest of the addon. |
|
686 | + // we know it was just activated and the request will end soon |
|
687 | + } |
|
688 | + return true; |
|
689 | + } |
|
690 | + // make sure this was called in the right place! |
|
691 | + if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
692 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
693 | + ) { |
|
694 | + EE_Error::doing_it_wrong( |
|
695 | + __METHOD__, |
|
696 | + sprintf( |
|
697 | + __( |
|
698 | + 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
699 | + 'event_espresso' |
|
700 | + ), |
|
701 | + $addon_name |
|
702 | + ), |
|
703 | + '4.3.0' |
|
704 | + ); |
|
705 | + } |
|
706 | + // make sure addon settings are set correctly without overwriting anything existing |
|
707 | + if (isset(self::$_settings[ $addon_name ])) { |
|
708 | + self::$_settings[ $addon_name ] += $addon_settings; |
|
709 | + } else { |
|
710 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
711 | + } |
|
712 | + return false; |
|
713 | + } |
|
714 | 714 | |
715 | 715 | |
716 | - /** |
|
717 | - * @param string $addon_name |
|
718 | - * @return void |
|
719 | - * @throws EE_Error |
|
720 | - */ |
|
721 | - private static function _setup_autoloaders($addon_name) |
|
722 | - { |
|
723 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
724 | - // setup autoloader for single file |
|
725 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
726 | - } |
|
727 | - // setup autoloaders for folders |
|
728 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
729 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
730 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
731 | - } |
|
732 | - } |
|
733 | - } |
|
716 | + /** |
|
717 | + * @param string $addon_name |
|
718 | + * @return void |
|
719 | + * @throws EE_Error |
|
720 | + */ |
|
721 | + private static function _setup_autoloaders($addon_name) |
|
722 | + { |
|
723 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
724 | + // setup autoloader for single file |
|
725 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
726 | + } |
|
727 | + // setup autoloaders for folders |
|
728 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
729 | + foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
730 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
731 | + } |
|
732 | + } |
|
733 | + } |
|
734 | 734 | |
735 | 735 | |
736 | - /** |
|
737 | - * register new models and extensions |
|
738 | - * |
|
739 | - * @param string $addon_name |
|
740 | - * @return void |
|
741 | - * @throws EE_Error |
|
742 | - */ |
|
743 | - private static function _register_models_and_extensions($addon_name) |
|
744 | - { |
|
745 | - // register new models |
|
746 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
747 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
748 | - ) { |
|
749 | - EE_Register_Model::register( |
|
750 | - $addon_name, |
|
751 | - array( |
|
752 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
753 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
754 | - ) |
|
755 | - ); |
|
756 | - } |
|
757 | - // register model extensions |
|
758 | - if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
759 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
760 | - ) { |
|
761 | - EE_Register_Model_Extensions::register( |
|
762 | - $addon_name, |
|
763 | - array( |
|
764 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
765 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
766 | - ) |
|
767 | - ); |
|
768 | - } |
|
769 | - } |
|
736 | + /** |
|
737 | + * register new models and extensions |
|
738 | + * |
|
739 | + * @param string $addon_name |
|
740 | + * @return void |
|
741 | + * @throws EE_Error |
|
742 | + */ |
|
743 | + private static function _register_models_and_extensions($addon_name) |
|
744 | + { |
|
745 | + // register new models |
|
746 | + if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
747 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
748 | + ) { |
|
749 | + EE_Register_Model::register( |
|
750 | + $addon_name, |
|
751 | + array( |
|
752 | + 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
753 | + 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
754 | + ) |
|
755 | + ); |
|
756 | + } |
|
757 | + // register model extensions |
|
758 | + if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
759 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
760 | + ) { |
|
761 | + EE_Register_Model_Extensions::register( |
|
762 | + $addon_name, |
|
763 | + array( |
|
764 | + 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
765 | + 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
766 | + ) |
|
767 | + ); |
|
768 | + } |
|
769 | + } |
|
770 | 770 | |
771 | 771 | |
772 | - /** |
|
773 | - * @param string $addon_name |
|
774 | - * @return void |
|
775 | - * @throws EE_Error |
|
776 | - */ |
|
777 | - private static function _register_data_migration_scripts($addon_name) |
|
778 | - { |
|
779 | - // setup DMS |
|
780 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
781 | - EE_Register_Data_Migration_Scripts::register( |
|
782 | - $addon_name, |
|
783 | - array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
784 | - ); |
|
785 | - } |
|
786 | - } |
|
772 | + /** |
|
773 | + * @param string $addon_name |
|
774 | + * @return void |
|
775 | + * @throws EE_Error |
|
776 | + */ |
|
777 | + private static function _register_data_migration_scripts($addon_name) |
|
778 | + { |
|
779 | + // setup DMS |
|
780 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
781 | + EE_Register_Data_Migration_Scripts::register( |
|
782 | + $addon_name, |
|
783 | + array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
784 | + ); |
|
785 | + } |
|
786 | + } |
|
787 | 787 | |
788 | 788 | |
789 | - /** |
|
790 | - * @param string $addon_name |
|
791 | - * @return void |
|
792 | - * @throws EE_Error |
|
793 | - */ |
|
794 | - private static function _register_config($addon_name) |
|
795 | - { |
|
796 | - // if config_class is present let's register config. |
|
797 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
798 | - EE_Register_Config::register( |
|
799 | - self::$_settings[ $addon_name ]['config_class'], |
|
800 | - array( |
|
801 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
802 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
803 | - ) |
|
804 | - ); |
|
805 | - } |
|
806 | - } |
|
789 | + /** |
|
790 | + * @param string $addon_name |
|
791 | + * @return void |
|
792 | + * @throws EE_Error |
|
793 | + */ |
|
794 | + private static function _register_config($addon_name) |
|
795 | + { |
|
796 | + // if config_class is present let's register config. |
|
797 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
798 | + EE_Register_Config::register( |
|
799 | + self::$_settings[ $addon_name ]['config_class'], |
|
800 | + array( |
|
801 | + 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
802 | + 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
803 | + ) |
|
804 | + ); |
|
805 | + } |
|
806 | + } |
|
807 | 807 | |
808 | 808 | |
809 | - /** |
|
810 | - * @param string $addon_name |
|
811 | - * @return void |
|
812 | - * @throws EE_Error |
|
813 | - */ |
|
814 | - private static function _register_admin_pages($addon_name) |
|
815 | - { |
|
816 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
817 | - EE_Register_Admin_Page::register( |
|
818 | - $addon_name, |
|
819 | - array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
820 | - ); |
|
821 | - } |
|
822 | - } |
|
809 | + /** |
|
810 | + * @param string $addon_name |
|
811 | + * @return void |
|
812 | + * @throws EE_Error |
|
813 | + */ |
|
814 | + private static function _register_admin_pages($addon_name) |
|
815 | + { |
|
816 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
817 | + EE_Register_Admin_Page::register( |
|
818 | + $addon_name, |
|
819 | + array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
820 | + ); |
|
821 | + } |
|
822 | + } |
|
823 | 823 | |
824 | 824 | |
825 | - /** |
|
826 | - * @param string $addon_name |
|
827 | - * @return void |
|
828 | - * @throws EE_Error |
|
829 | - */ |
|
830 | - private static function _register_modules($addon_name) |
|
831 | - { |
|
832 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
833 | - EE_Register_Module::register( |
|
834 | - $addon_name, |
|
835 | - array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
836 | - ); |
|
837 | - } |
|
838 | - } |
|
825 | + /** |
|
826 | + * @param string $addon_name |
|
827 | + * @return void |
|
828 | + * @throws EE_Error |
|
829 | + */ |
|
830 | + private static function _register_modules($addon_name) |
|
831 | + { |
|
832 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
833 | + EE_Register_Module::register( |
|
834 | + $addon_name, |
|
835 | + array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
836 | + ); |
|
837 | + } |
|
838 | + } |
|
839 | 839 | |
840 | 840 | |
841 | - /** |
|
842 | - * @param string $addon_name |
|
843 | - * @return void |
|
844 | - * @throws EE_Error |
|
845 | - */ |
|
846 | - private static function _register_shortcodes($addon_name) |
|
847 | - { |
|
848 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
849 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
850 | - ) { |
|
851 | - EE_Register_Shortcode::register( |
|
852 | - $addon_name, |
|
853 | - array( |
|
854 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
855 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
856 | - : array(), |
|
857 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
858 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
859 | - : array(), |
|
860 | - ) |
|
861 | - ); |
|
862 | - } |
|
863 | - } |
|
841 | + /** |
|
842 | + * @param string $addon_name |
|
843 | + * @return void |
|
844 | + * @throws EE_Error |
|
845 | + */ |
|
846 | + private static function _register_shortcodes($addon_name) |
|
847 | + { |
|
848 | + if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
849 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
850 | + ) { |
|
851 | + EE_Register_Shortcode::register( |
|
852 | + $addon_name, |
|
853 | + array( |
|
854 | + 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
855 | + ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
856 | + : array(), |
|
857 | + 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
858 | + ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
859 | + : array(), |
|
860 | + ) |
|
861 | + ); |
|
862 | + } |
|
863 | + } |
|
864 | 864 | |
865 | 865 | |
866 | - /** |
|
867 | - * @param string $addon_name |
|
868 | - * @return void |
|
869 | - * @throws EE_Error |
|
870 | - */ |
|
871 | - private static function _register_widgets($addon_name) |
|
872 | - { |
|
873 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
874 | - EE_Register_Widget::register( |
|
875 | - $addon_name, |
|
876 | - array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
877 | - ); |
|
878 | - } |
|
879 | - } |
|
866 | + /** |
|
867 | + * @param string $addon_name |
|
868 | + * @return void |
|
869 | + * @throws EE_Error |
|
870 | + */ |
|
871 | + private static function _register_widgets($addon_name) |
|
872 | + { |
|
873 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
874 | + EE_Register_Widget::register( |
|
875 | + $addon_name, |
|
876 | + array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
877 | + ); |
|
878 | + } |
|
879 | + } |
|
880 | 880 | |
881 | 881 | |
882 | - /** |
|
883 | - * @param string $addon_name |
|
884 | - * @return void |
|
885 | - * @throws EE_Error |
|
886 | - */ |
|
887 | - private static function _register_capabilities($addon_name) |
|
888 | - { |
|
889 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
890 | - EE_Register_Capabilities::register( |
|
891 | - $addon_name, |
|
892 | - array( |
|
893 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
894 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
895 | - ) |
|
896 | - ); |
|
897 | - } |
|
898 | - } |
|
882 | + /** |
|
883 | + * @param string $addon_name |
|
884 | + * @return void |
|
885 | + * @throws EE_Error |
|
886 | + */ |
|
887 | + private static function _register_capabilities($addon_name) |
|
888 | + { |
|
889 | + if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
890 | + EE_Register_Capabilities::register( |
|
891 | + $addon_name, |
|
892 | + array( |
|
893 | + 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
894 | + 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
895 | + ) |
|
896 | + ); |
|
897 | + } |
|
898 | + } |
|
899 | 899 | |
900 | 900 | |
901 | - /** |
|
902 | - * @param string $addon_name |
|
903 | - * @return void |
|
904 | - * @throws EE_Error |
|
905 | - */ |
|
906 | - private static function _register_message_types($addon_name) |
|
907 | - { |
|
908 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
909 | - add_action( |
|
910 | - 'EE_Brewing_Regular___messages_caf', |
|
911 | - array('EE_Register_Addon', 'register_message_types') |
|
912 | - ); |
|
913 | - } |
|
914 | - } |
|
901 | + /** |
|
902 | + * @param string $addon_name |
|
903 | + * @return void |
|
904 | + * @throws EE_Error |
|
905 | + */ |
|
906 | + private static function _register_message_types($addon_name) |
|
907 | + { |
|
908 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
909 | + add_action( |
|
910 | + 'EE_Brewing_Regular___messages_caf', |
|
911 | + array('EE_Register_Addon', 'register_message_types') |
|
912 | + ); |
|
913 | + } |
|
914 | + } |
|
915 | 915 | |
916 | 916 | |
917 | - /** |
|
918 | - * @param string $addon_name |
|
919 | - * @return void |
|
920 | - * @throws EE_Error |
|
921 | - */ |
|
922 | - private static function _register_custom_post_types($addon_name) |
|
923 | - { |
|
924 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
925 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
926 | - ) { |
|
927 | - EE_Register_CPT::register( |
|
928 | - $addon_name, |
|
929 | - array( |
|
930 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
931 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
932 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
933 | - ) |
|
934 | - ); |
|
935 | - } |
|
936 | - } |
|
917 | + /** |
|
918 | + * @param string $addon_name |
|
919 | + * @return void |
|
920 | + * @throws EE_Error |
|
921 | + */ |
|
922 | + private static function _register_custom_post_types($addon_name) |
|
923 | + { |
|
924 | + if (! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
925 | + || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
926 | + ) { |
|
927 | + EE_Register_CPT::register( |
|
928 | + $addon_name, |
|
929 | + array( |
|
930 | + 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
931 | + 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
932 | + 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
933 | + ) |
|
934 | + ); |
|
935 | + } |
|
936 | + } |
|
937 | 937 | |
938 | 938 | |
939 | - /** |
|
940 | - * @param string $addon_name |
|
941 | - * @return void |
|
942 | - * @throws InvalidArgumentException |
|
943 | - * @throws InvalidInterfaceException |
|
944 | - * @throws InvalidDataTypeException |
|
945 | - * @throws DomainException |
|
946 | - * @throws EE_Error |
|
947 | - */ |
|
948 | - private static function _register_payment_methods($addon_name) |
|
949 | - { |
|
950 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
951 | - EE_Register_Payment_Method::register( |
|
952 | - $addon_name, |
|
953 | - array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
954 | - ); |
|
955 | - } |
|
956 | - } |
|
939 | + /** |
|
940 | + * @param string $addon_name |
|
941 | + * @return void |
|
942 | + * @throws InvalidArgumentException |
|
943 | + * @throws InvalidInterfaceException |
|
944 | + * @throws InvalidDataTypeException |
|
945 | + * @throws DomainException |
|
946 | + * @throws EE_Error |
|
947 | + */ |
|
948 | + private static function _register_payment_methods($addon_name) |
|
949 | + { |
|
950 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
951 | + EE_Register_Payment_Method::register( |
|
952 | + $addon_name, |
|
953 | + array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
954 | + ); |
|
955 | + } |
|
956 | + } |
|
957 | 957 | |
958 | 958 | |
959 | - /** |
|
960 | - * @param string $addon_name |
|
961 | - * @return void |
|
962 | - * @throws InvalidArgumentException |
|
963 | - * @throws InvalidInterfaceException |
|
964 | - * @throws InvalidDataTypeException |
|
965 | - * @throws DomainException |
|
966 | - * @throws EE_Error |
|
967 | - */ |
|
968 | - private static function registerPrivacyPolicies($addon_name) |
|
969 | - { |
|
970 | - if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
971 | - EE_Register_Privacy_Policy::register( |
|
972 | - $addon_name, |
|
973 | - self::$_settings[ $addon_name ]['privacy_policies'] |
|
974 | - ); |
|
975 | - } |
|
976 | - } |
|
959 | + /** |
|
960 | + * @param string $addon_name |
|
961 | + * @return void |
|
962 | + * @throws InvalidArgumentException |
|
963 | + * @throws InvalidInterfaceException |
|
964 | + * @throws InvalidDataTypeException |
|
965 | + * @throws DomainException |
|
966 | + * @throws EE_Error |
|
967 | + */ |
|
968 | + private static function registerPrivacyPolicies($addon_name) |
|
969 | + { |
|
970 | + if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
971 | + EE_Register_Privacy_Policy::register( |
|
972 | + $addon_name, |
|
973 | + self::$_settings[ $addon_name ]['privacy_policies'] |
|
974 | + ); |
|
975 | + } |
|
976 | + } |
|
977 | 977 | |
978 | 978 | |
979 | - /** |
|
980 | - * @param string $addon_name |
|
981 | - * @return void |
|
982 | - */ |
|
983 | - private static function registerPersonalDataExporters($addon_name) |
|
984 | - { |
|
985 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
986 | - EE_Register_Personal_Data_Eraser::register( |
|
987 | - $addon_name, |
|
988 | - self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
989 | - ); |
|
990 | - } |
|
991 | - } |
|
979 | + /** |
|
980 | + * @param string $addon_name |
|
981 | + * @return void |
|
982 | + */ |
|
983 | + private static function registerPersonalDataExporters($addon_name) |
|
984 | + { |
|
985 | + if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
986 | + EE_Register_Personal_Data_Eraser::register( |
|
987 | + $addon_name, |
|
988 | + self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
989 | + ); |
|
990 | + } |
|
991 | + } |
|
992 | 992 | |
993 | 993 | |
994 | - /** |
|
995 | - * @param string $addon_name |
|
996 | - * @return void |
|
997 | - */ |
|
998 | - private static function registerPersonalDataErasers($addon_name) |
|
999 | - { |
|
1000 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
1001 | - EE_Register_Personal_Data_Eraser::register( |
|
1002 | - $addon_name, |
|
1003 | - self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
1004 | - ); |
|
1005 | - } |
|
1006 | - } |
|
994 | + /** |
|
995 | + * @param string $addon_name |
|
996 | + * @return void |
|
997 | + */ |
|
998 | + private static function registerPersonalDataErasers($addon_name) |
|
999 | + { |
|
1000 | + if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
1001 | + EE_Register_Personal_Data_Eraser::register( |
|
1002 | + $addon_name, |
|
1003 | + self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
1004 | + ); |
|
1005 | + } |
|
1006 | + } |
|
1007 | 1007 | |
1008 | 1008 | |
1009 | - /** |
|
1010 | - * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
1011 | - * |
|
1012 | - * @param string $addon_name |
|
1013 | - * @return EE_Addon |
|
1014 | - * @throws InvalidArgumentException |
|
1015 | - * @throws InvalidInterfaceException |
|
1016 | - * @throws InvalidDataTypeException |
|
1017 | - * @throws ReflectionException |
|
1018 | - * @throws EE_Error |
|
1019 | - */ |
|
1020 | - private static function _load_and_init_addon_class($addon_name) |
|
1021 | - { |
|
1022 | - $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
|
1023 | - $addon = $loader->getShared( |
|
1024 | - self::$_settings[ $addon_name ]['class_name'], |
|
1025 | - array('EE_Registry::create(addon)' => true) |
|
1026 | - ); |
|
1027 | - // setter inject dep map if required |
|
1028 | - if ($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null) { |
|
1029 | - $addon->setDependencyMap($loader->getShared('EE_Dependency_Map')); |
|
1030 | - } |
|
1031 | - // setter inject domain if required |
|
1032 | - if ($addon instanceof RequiresDomainInterface |
|
1033 | - && $addon->domain() === null |
|
1034 | - ) { |
|
1035 | - // using supplied Domain object |
|
1036 | - $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
1037 | - ? self::$_settings[ $addon_name ]['domain'] |
|
1038 | - : null; |
|
1039 | - // or construct one using Domain FQCN |
|
1040 | - if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
1041 | - $domain = $loader->getShared( |
|
1042 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
1043 | - array( |
|
1044 | - new EventEspresso\core\domain\values\FilePath( |
|
1045 | - self::$_settings[ $addon_name ]['main_file_path'] |
|
1046 | - ), |
|
1047 | - EventEspresso\core\domain\values\Version::fromString( |
|
1048 | - self::$_settings[ $addon_name ]['version'] |
|
1049 | - ), |
|
1050 | - ) |
|
1051 | - ); |
|
1052 | - } |
|
1053 | - if ($domain instanceof DomainInterface) { |
|
1054 | - $addon->setDomain($domain); |
|
1055 | - } |
|
1056 | - } |
|
1057 | - $addon->set_name($addon_name); |
|
1058 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
1059 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
1060 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
1061 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
1062 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
1063 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
1064 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
1065 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
1066 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
1067 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
1068 | - // setup the add-on's pue_slug if we have one. |
|
1069 | - if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) { |
|
1070 | - $addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']); |
|
1071 | - } |
|
1072 | - // unfortunately this can't be hooked in upon construction, because we don't have |
|
1073 | - // the plugin mainfile's path upon construction. |
|
1074 | - register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
1075 | - // call any additional admin_callback functions during load_admin_controller hook |
|
1076 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
1077 | - add_action( |
|
1078 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
1079 | - array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
1080 | - ); |
|
1081 | - } |
|
1082 | - return $addon; |
|
1083 | - } |
|
1009 | + /** |
|
1010 | + * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
1011 | + * |
|
1012 | + * @param string $addon_name |
|
1013 | + * @return EE_Addon |
|
1014 | + * @throws InvalidArgumentException |
|
1015 | + * @throws InvalidInterfaceException |
|
1016 | + * @throws InvalidDataTypeException |
|
1017 | + * @throws ReflectionException |
|
1018 | + * @throws EE_Error |
|
1019 | + */ |
|
1020 | + private static function _load_and_init_addon_class($addon_name) |
|
1021 | + { |
|
1022 | + $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
|
1023 | + $addon = $loader->getShared( |
|
1024 | + self::$_settings[ $addon_name ]['class_name'], |
|
1025 | + array('EE_Registry::create(addon)' => true) |
|
1026 | + ); |
|
1027 | + // setter inject dep map if required |
|
1028 | + if ($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null) { |
|
1029 | + $addon->setDependencyMap($loader->getShared('EE_Dependency_Map')); |
|
1030 | + } |
|
1031 | + // setter inject domain if required |
|
1032 | + if ($addon instanceof RequiresDomainInterface |
|
1033 | + && $addon->domain() === null |
|
1034 | + ) { |
|
1035 | + // using supplied Domain object |
|
1036 | + $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
1037 | + ? self::$_settings[ $addon_name ]['domain'] |
|
1038 | + : null; |
|
1039 | + // or construct one using Domain FQCN |
|
1040 | + if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
1041 | + $domain = $loader->getShared( |
|
1042 | + self::$_settings[ $addon_name ]['domain_fqcn'], |
|
1043 | + array( |
|
1044 | + new EventEspresso\core\domain\values\FilePath( |
|
1045 | + self::$_settings[ $addon_name ]['main_file_path'] |
|
1046 | + ), |
|
1047 | + EventEspresso\core\domain\values\Version::fromString( |
|
1048 | + self::$_settings[ $addon_name ]['version'] |
|
1049 | + ), |
|
1050 | + ) |
|
1051 | + ); |
|
1052 | + } |
|
1053 | + if ($domain instanceof DomainInterface) { |
|
1054 | + $addon->setDomain($domain); |
|
1055 | + } |
|
1056 | + } |
|
1057 | + $addon->set_name($addon_name); |
|
1058 | + $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
1059 | + $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
1060 | + $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
1061 | + $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
1062 | + $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
1063 | + $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
1064 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
1065 | + $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
1066 | + $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
1067 | + $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
1068 | + // setup the add-on's pue_slug if we have one. |
|
1069 | + if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) { |
|
1070 | + $addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']); |
|
1071 | + } |
|
1072 | + // unfortunately this can't be hooked in upon construction, because we don't have |
|
1073 | + // the plugin mainfile's path upon construction. |
|
1074 | + register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
1075 | + // call any additional admin_callback functions during load_admin_controller hook |
|
1076 | + if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
1077 | + add_action( |
|
1078 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
1079 | + array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
1080 | + ); |
|
1081 | + } |
|
1082 | + return $addon; |
|
1083 | + } |
|
1084 | 1084 | |
1085 | 1085 | |
1086 | - /** |
|
1087 | - * load_pue_update - Update notifications |
|
1088 | - * |
|
1089 | - * @return void |
|
1090 | - * @throws InvalidArgumentException |
|
1091 | - * @throws InvalidDataTypeException |
|
1092 | - * @throws InvalidInterfaceException |
|
1093 | - */ |
|
1094 | - public static function load_pue_update() |
|
1095 | - { |
|
1096 | - // load PUE client |
|
1097 | - require_once EE_THIRD_PARTY . 'pue/pue-client.php'; |
|
1098 | - $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com'; |
|
1099 | - // cycle thru settings |
|
1100 | - foreach (self::$_settings as $settings) { |
|
1101 | - if (! empty($settings['pue_options'])) { |
|
1102 | - // initiate the class and start the plugin update engine! |
|
1103 | - new PluginUpdateEngineChecker( |
|
1104 | - // host file URL |
|
1105 | - $license_server, |
|
1106 | - // plugin slug(s) |
|
1107 | - array( |
|
1108 | - 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
1109 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
1110 | - ), |
|
1111 | - // options |
|
1112 | - array( |
|
1113 | - 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
1114 | - 'lang_domain' => 'event_espresso', |
|
1115 | - 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
1116 | - 'option_key' => 'ee_site_license_key', |
|
1117 | - 'options_page_slug' => 'event_espresso', |
|
1118 | - 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
1119 | - // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
1120 | - 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
1121 | - ) |
|
1122 | - ); |
|
1123 | - } |
|
1124 | - } |
|
1125 | - } |
|
1086 | + /** |
|
1087 | + * load_pue_update - Update notifications |
|
1088 | + * |
|
1089 | + * @return void |
|
1090 | + * @throws InvalidArgumentException |
|
1091 | + * @throws InvalidDataTypeException |
|
1092 | + * @throws InvalidInterfaceException |
|
1093 | + */ |
|
1094 | + public static function load_pue_update() |
|
1095 | + { |
|
1096 | + // load PUE client |
|
1097 | + require_once EE_THIRD_PARTY . 'pue/pue-client.php'; |
|
1098 | + $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com'; |
|
1099 | + // cycle thru settings |
|
1100 | + foreach (self::$_settings as $settings) { |
|
1101 | + if (! empty($settings['pue_options'])) { |
|
1102 | + // initiate the class and start the plugin update engine! |
|
1103 | + new PluginUpdateEngineChecker( |
|
1104 | + // host file URL |
|
1105 | + $license_server, |
|
1106 | + // plugin slug(s) |
|
1107 | + array( |
|
1108 | + 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
1109 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
1110 | + ), |
|
1111 | + // options |
|
1112 | + array( |
|
1113 | + 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
1114 | + 'lang_domain' => 'event_espresso', |
|
1115 | + 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
1116 | + 'option_key' => 'ee_site_license_key', |
|
1117 | + 'options_page_slug' => 'event_espresso', |
|
1118 | + 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
1119 | + // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
1120 | + 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
1121 | + ) |
|
1122 | + ); |
|
1123 | + } |
|
1124 | + } |
|
1125 | + } |
|
1126 | 1126 | |
1127 | 1127 | |
1128 | - /** |
|
1129 | - * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
1130 | - * |
|
1131 | - * @since 4.4.0 |
|
1132 | - * @return void |
|
1133 | - * @throws EE_Error |
|
1134 | - */ |
|
1135 | - public static function register_message_types() |
|
1136 | - { |
|
1137 | - foreach (self::$_settings as $addon_name => $settings) { |
|
1138 | - if (! empty($settings['message_types'])) { |
|
1139 | - foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
1140 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
1141 | - } |
|
1142 | - } |
|
1143 | - } |
|
1144 | - } |
|
1128 | + /** |
|
1129 | + * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
1130 | + * |
|
1131 | + * @since 4.4.0 |
|
1132 | + * @return void |
|
1133 | + * @throws EE_Error |
|
1134 | + */ |
|
1135 | + public static function register_message_types() |
|
1136 | + { |
|
1137 | + foreach (self::$_settings as $addon_name => $settings) { |
|
1138 | + if (! empty($settings['message_types'])) { |
|
1139 | + foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
1140 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
1141 | + } |
|
1142 | + } |
|
1143 | + } |
|
1144 | + } |
|
1145 | 1145 | |
1146 | 1146 | |
1147 | - /** |
|
1148 | - * This deregisters an addon that was previously registered with a specific addon_name. |
|
1149 | - * |
|
1150 | - * @since 4.3.0 |
|
1151 | - * @param string $addon_name the name for the addon that was previously registered |
|
1152 | - * @throws DomainException |
|
1153 | - * @throws EE_Error |
|
1154 | - * @throws InvalidArgumentException |
|
1155 | - * @throws InvalidDataTypeException |
|
1156 | - * @throws InvalidInterfaceException |
|
1157 | - */ |
|
1158 | - public static function deregister($addon_name = null) |
|
1159 | - { |
|
1160 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1161 | - try { |
|
1162 | - do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
1163 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
1164 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
1165 | - // setup DMS |
|
1166 | - EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
1167 | - } |
|
1168 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
1169 | - // register admin page |
|
1170 | - EE_Register_Admin_Page::deregister($addon_name); |
|
1171 | - } |
|
1172 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
1173 | - // add to list of modules to be registered |
|
1174 | - EE_Register_Module::deregister($addon_name); |
|
1175 | - } |
|
1176 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
1177 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
1178 | - ) { |
|
1179 | - // add to list of shortcodes to be registered |
|
1180 | - EE_Register_Shortcode::deregister($addon_name); |
|
1181 | - } |
|
1182 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
1183 | - // if config_class present let's register config. |
|
1184 | - EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
1185 | - } |
|
1186 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
1187 | - // add to list of widgets to be registered |
|
1188 | - EE_Register_Widget::deregister($addon_name); |
|
1189 | - } |
|
1190 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
1191 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
1192 | - ) { |
|
1193 | - // add to list of shortcodes to be registered |
|
1194 | - EE_Register_Model::deregister($addon_name); |
|
1195 | - } |
|
1196 | - if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
1197 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
1198 | - ) { |
|
1199 | - // add to list of shortcodes to be registered |
|
1200 | - EE_Register_Model_Extensions::deregister($addon_name); |
|
1201 | - } |
|
1202 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
1203 | - foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
1204 | - EE_Register_Message_Type::deregister($message_type); |
|
1205 | - } |
|
1206 | - } |
|
1207 | - // deregister capabilities for addon |
|
1208 | - if (! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
1209 | - || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
1210 | - ) { |
|
1211 | - EE_Register_Capabilities::deregister($addon_name); |
|
1212 | - } |
|
1213 | - // deregister custom_post_types for addon |
|
1214 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
1215 | - EE_Register_CPT::deregister($addon_name); |
|
1216 | - } |
|
1217 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
1218 | - EE_Register_Payment_Method::deregister($addon_name); |
|
1219 | - } |
|
1220 | - $addon = EE_Registry::instance()->getAddon($class_name); |
|
1221 | - if ($addon instanceof EE_Addon) { |
|
1222 | - remove_action( |
|
1223 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1224 | - array($addon, 'deactivation') |
|
1225 | - ); |
|
1226 | - remove_action( |
|
1227 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
1228 | - array($addon, 'initialize_db_if_no_migrations_required') |
|
1229 | - ); |
|
1230 | - // remove `after_registration` call |
|
1231 | - remove_action( |
|
1232 | - 'AHEE__EE_System__load_espresso_addons__complete', |
|
1233 | - array($addon, 'after_registration'), |
|
1234 | - 999 |
|
1235 | - ); |
|
1236 | - } |
|
1237 | - EE_Registry::instance()->removeAddon($class_name); |
|
1238 | - } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
1239 | - // the add-on was not yet registered in the registry, |
|
1240 | - // so RegistryContainer::__get() throws this exception. |
|
1241 | - // also no need to worry about this or log it, |
|
1242 | - // it's ok to deregister an add-on before its registered in the registry |
|
1243 | - } catch (Exception $e) { |
|
1244 | - new ExceptionLogger($e); |
|
1245 | - } |
|
1246 | - unset(self::$_settings[ $addon_name ]); |
|
1247 | - do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1248 | - } |
|
1249 | - } |
|
1147 | + /** |
|
1148 | + * This deregisters an addon that was previously registered with a specific addon_name. |
|
1149 | + * |
|
1150 | + * @since 4.3.0 |
|
1151 | + * @param string $addon_name the name for the addon that was previously registered |
|
1152 | + * @throws DomainException |
|
1153 | + * @throws EE_Error |
|
1154 | + * @throws InvalidArgumentException |
|
1155 | + * @throws InvalidDataTypeException |
|
1156 | + * @throws InvalidInterfaceException |
|
1157 | + */ |
|
1158 | + public static function deregister($addon_name = null) |
|
1159 | + { |
|
1160 | + if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1161 | + try { |
|
1162 | + do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
1163 | + $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
1164 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
1165 | + // setup DMS |
|
1166 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
1167 | + } |
|
1168 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
1169 | + // register admin page |
|
1170 | + EE_Register_Admin_Page::deregister($addon_name); |
|
1171 | + } |
|
1172 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
1173 | + // add to list of modules to be registered |
|
1174 | + EE_Register_Module::deregister($addon_name); |
|
1175 | + } |
|
1176 | + if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
1177 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
1178 | + ) { |
|
1179 | + // add to list of shortcodes to be registered |
|
1180 | + EE_Register_Shortcode::deregister($addon_name); |
|
1181 | + } |
|
1182 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
1183 | + // if config_class present let's register config. |
|
1184 | + EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
1185 | + } |
|
1186 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
1187 | + // add to list of widgets to be registered |
|
1188 | + EE_Register_Widget::deregister($addon_name); |
|
1189 | + } |
|
1190 | + if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
1191 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
1192 | + ) { |
|
1193 | + // add to list of shortcodes to be registered |
|
1194 | + EE_Register_Model::deregister($addon_name); |
|
1195 | + } |
|
1196 | + if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
1197 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
1198 | + ) { |
|
1199 | + // add to list of shortcodes to be registered |
|
1200 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
1201 | + } |
|
1202 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
1203 | + foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
1204 | + EE_Register_Message_Type::deregister($message_type); |
|
1205 | + } |
|
1206 | + } |
|
1207 | + // deregister capabilities for addon |
|
1208 | + if (! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
1209 | + || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
1210 | + ) { |
|
1211 | + EE_Register_Capabilities::deregister($addon_name); |
|
1212 | + } |
|
1213 | + // deregister custom_post_types for addon |
|
1214 | + if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
1215 | + EE_Register_CPT::deregister($addon_name); |
|
1216 | + } |
|
1217 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
1218 | + EE_Register_Payment_Method::deregister($addon_name); |
|
1219 | + } |
|
1220 | + $addon = EE_Registry::instance()->getAddon($class_name); |
|
1221 | + if ($addon instanceof EE_Addon) { |
|
1222 | + remove_action( |
|
1223 | + 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1224 | + array($addon, 'deactivation') |
|
1225 | + ); |
|
1226 | + remove_action( |
|
1227 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
1228 | + array($addon, 'initialize_db_if_no_migrations_required') |
|
1229 | + ); |
|
1230 | + // remove `after_registration` call |
|
1231 | + remove_action( |
|
1232 | + 'AHEE__EE_System__load_espresso_addons__complete', |
|
1233 | + array($addon, 'after_registration'), |
|
1234 | + 999 |
|
1235 | + ); |
|
1236 | + } |
|
1237 | + EE_Registry::instance()->removeAddon($class_name); |
|
1238 | + } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
1239 | + // the add-on was not yet registered in the registry, |
|
1240 | + // so RegistryContainer::__get() throws this exception. |
|
1241 | + // also no need to worry about this or log it, |
|
1242 | + // it's ok to deregister an add-on before its registered in the registry |
|
1243 | + } catch (Exception $e) { |
|
1244 | + new ExceptionLogger($e); |
|
1245 | + } |
|
1246 | + unset(self::$_settings[ $addon_name ]); |
|
1247 | + do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1248 | + } |
|
1249 | + } |
|
1250 | 1250 | } |
@@ -69,15 +69,15 @@ discard block |
||
69 | 69 | // offsets: 0 . 1 . 2 . 3 . 4 |
70 | 70 | $version_parts = explode('.', $min_core_version); |
71 | 71 | // check they specified the micro version (after 2nd period) |
72 | - if (! isset($version_parts[2])) { |
|
72 | + if ( ! isset($version_parts[2])) { |
|
73 | 73 | $version_parts[2] = '0'; |
74 | 74 | } |
75 | 75 | // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
76 | 76 | // soon we can assume that's 'rc', but this current version is 'alpha' |
77 | - if (! isset($version_parts[3])) { |
|
77 | + if ( ! isset($version_parts[3])) { |
|
78 | 78 | $version_parts[3] = 'dev'; |
79 | 79 | } |
80 | - if (! isset($version_parts[4])) { |
|
80 | + if ( ! isset($version_parts[4])) { |
|
81 | 81 | $version_parts[4] = '000'; |
82 | 82 | } |
83 | 83 | return implode('.', $version_parts); |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | // setup PUE |
265 | 265 | EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
266 | 266 | // does this addon work with this version of core or WordPress ? |
267 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
267 | + if ( ! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
268 | 268 | return; |
269 | 269 | } |
270 | 270 | // register namespaces |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | ) |
329 | 329 | ); |
330 | 330 | } |
331 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
331 | + if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
332 | 332 | throw new EE_Error( |
333 | 333 | sprintf( |
334 | 334 | __( |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | ); |
341 | 341 | } |
342 | 342 | // check that addon has not already been registered with that name |
343 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
343 | + if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
344 | 344 | throw new EE_Error( |
345 | 345 | sprintf( |
346 | 346 | __( |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
373 | 373 | return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
374 | 374 | ? $class_name |
375 | - : 'EE_' . $class_name; |
|
375 | + : 'EE_'.$class_name; |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | |
@@ -539,9 +539,9 @@ discard block |
||
539 | 539 | global $wp_version; |
540 | 540 | $incompatibility_message = ''; |
541 | 541 | // check whether this addon version is compatible with EE core |
542 | - if (isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
542 | + if (isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
543 | 543 | && ! self::_meets_min_core_version_requirement( |
544 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
544 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
545 | 545 | $addon_settings['version'] |
546 | 546 | ) |
547 | 547 | ) { |
@@ -552,11 +552,11 @@ discard block |
||
552 | 552 | ), |
553 | 553 | $addon_name, |
554 | 554 | '<br />', |
555 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
555 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
556 | 556 | '<span style="font-weight: bold; color: #D54E21;">', |
557 | 557 | '</span><br />' |
558 | 558 | ); |
559 | - } elseif (! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
559 | + } elseif ( ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
560 | 560 | ) { |
561 | 561 | $incompatibility_message = sprintf( |
562 | 562 | __( |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | '</span><br />' |
584 | 584 | ); |
585 | 585 | } |
586 | - if (! empty($incompatibility_message)) { |
|
586 | + if ( ! empty($incompatibility_message)) { |
|
587 | 587 | // remove 'activate' from the REQUEST |
588 | 588 | // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
589 | 589 | unset($_GET['activate'], $_REQUEST['activate']); |
@@ -611,11 +611,11 @@ discard block |
||
611 | 611 | */ |
612 | 612 | private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
613 | 613 | { |
614 | - if (! empty($setup_args['pue_options'])) { |
|
615 | - self::$_settings[ $addon_name ]['pue_options'] = array( |
|
614 | + if ( ! empty($setup_args['pue_options'])) { |
|
615 | + self::$_settings[$addon_name]['pue_options'] = array( |
|
616 | 616 | 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
617 | 617 | ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
618 | - : 'espresso_' . strtolower($class_name), |
|
618 | + : 'espresso_'.strtolower($class_name), |
|
619 | 619 | 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
620 | 620 | ? (string) $setup_args['pue_options']['plugin_basename'] |
621 | 621 | : plugin_basename($setup_args['main_file_path']), |
@@ -674,12 +674,12 @@ discard block |
||
674 | 674 | // (as the newly-activated addon wasn't around the first time addons were registered). |
675 | 675 | // Note: the presence of pue_options in the addon registration options will initialize the $_settings |
676 | 676 | // property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
677 | - if (! isset(self::$_settings[ $addon_name ]) |
|
678 | - || (isset(self::$_settings[ $addon_name ]) |
|
679 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
677 | + if ( ! isset(self::$_settings[$addon_name]) |
|
678 | + || (isset(self::$_settings[$addon_name]) |
|
679 | + && ! isset(self::$_settings[$addon_name]['class_name']) |
|
680 | 680 | ) |
681 | 681 | ) { |
682 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
682 | + self::$_settings[$addon_name] = $addon_settings; |
|
683 | 683 | $addon = self::_load_and_init_addon_class($addon_name); |
684 | 684 | $addon->set_activation_indicator_option(); |
685 | 685 | // dont bother setting up the rest of the addon. |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | return true; |
689 | 689 | } |
690 | 690 | // make sure this was called in the right place! |
691 | - if (! did_action('AHEE__EE_System__load_espresso_addons') |
|
691 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons') |
|
692 | 692 | || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
693 | 693 | ) { |
694 | 694 | EE_Error::doing_it_wrong( |
@@ -704,10 +704,10 @@ discard block |
||
704 | 704 | ); |
705 | 705 | } |
706 | 706 | // make sure addon settings are set correctly without overwriting anything existing |
707 | - if (isset(self::$_settings[ $addon_name ])) { |
|
708 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
707 | + if (isset(self::$_settings[$addon_name])) { |
|
708 | + self::$_settings[$addon_name] += $addon_settings; |
|
709 | 709 | } else { |
710 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
710 | + self::$_settings[$addon_name] = $addon_settings; |
|
711 | 711 | } |
712 | 712 | return false; |
713 | 713 | } |
@@ -720,13 +720,13 @@ discard block |
||
720 | 720 | */ |
721 | 721 | private static function _setup_autoloaders($addon_name) |
722 | 722 | { |
723 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
723 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
724 | 724 | // setup autoloader for single file |
725 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
725 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
726 | 726 | } |
727 | 727 | // setup autoloaders for folders |
728 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
729 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
728 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
729 | + foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
730 | 730 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
731 | 731 | } |
732 | 732 | } |
@@ -743,26 +743,26 @@ discard block |
||
743 | 743 | private static function _register_models_and_extensions($addon_name) |
744 | 744 | { |
745 | 745 | // register new models |
746 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
747 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
746 | + if ( ! empty(self::$_settings[$addon_name]['model_paths']) |
|
747 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
748 | 748 | ) { |
749 | 749 | EE_Register_Model::register( |
750 | 750 | $addon_name, |
751 | 751 | array( |
752 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
753 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
752 | + 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
753 | + 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
754 | 754 | ) |
755 | 755 | ); |
756 | 756 | } |
757 | 757 | // register model extensions |
758 | - if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
759 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
758 | + if ( ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
759 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
760 | 760 | ) { |
761 | 761 | EE_Register_Model_Extensions::register( |
762 | 762 | $addon_name, |
763 | 763 | array( |
764 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
765 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
764 | + 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
765 | + 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
766 | 766 | ) |
767 | 767 | ); |
768 | 768 | } |
@@ -777,10 +777,10 @@ discard block |
||
777 | 777 | private static function _register_data_migration_scripts($addon_name) |
778 | 778 | { |
779 | 779 | // setup DMS |
780 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
780 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
781 | 781 | EE_Register_Data_Migration_Scripts::register( |
782 | 782 | $addon_name, |
783 | - array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
783 | + array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
784 | 784 | ); |
785 | 785 | } |
786 | 786 | } |
@@ -794,12 +794,12 @@ discard block |
||
794 | 794 | private static function _register_config($addon_name) |
795 | 795 | { |
796 | 796 | // if config_class is present let's register config. |
797 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
797 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
798 | 798 | EE_Register_Config::register( |
799 | - self::$_settings[ $addon_name ]['config_class'], |
|
799 | + self::$_settings[$addon_name]['config_class'], |
|
800 | 800 | array( |
801 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
802 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
801 | + 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
802 | + 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
803 | 803 | ) |
804 | 804 | ); |
805 | 805 | } |
@@ -813,10 +813,10 @@ discard block |
||
813 | 813 | */ |
814 | 814 | private static function _register_admin_pages($addon_name) |
815 | 815 | { |
816 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
816 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
817 | 817 | EE_Register_Admin_Page::register( |
818 | 818 | $addon_name, |
819 | - array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
819 | + array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
820 | 820 | ); |
821 | 821 | } |
822 | 822 | } |
@@ -829,10 +829,10 @@ discard block |
||
829 | 829 | */ |
830 | 830 | private static function _register_modules($addon_name) |
831 | 831 | { |
832 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
832 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
833 | 833 | EE_Register_Module::register( |
834 | 834 | $addon_name, |
835 | - array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
835 | + array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
836 | 836 | ); |
837 | 837 | } |
838 | 838 | } |
@@ -845,17 +845,17 @@ discard block |
||
845 | 845 | */ |
846 | 846 | private static function _register_shortcodes($addon_name) |
847 | 847 | { |
848 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
849 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
848 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
849 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
850 | 850 | ) { |
851 | 851 | EE_Register_Shortcode::register( |
852 | 852 | $addon_name, |
853 | 853 | array( |
854 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
855 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
854 | + 'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths']) |
|
855 | + ? self::$_settings[$addon_name]['shortcode_paths'] |
|
856 | 856 | : array(), |
857 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
858 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
857 | + 'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
858 | + ? self::$_settings[$addon_name]['shortcode_fqcns'] |
|
859 | 859 | : array(), |
860 | 860 | ) |
861 | 861 | ); |
@@ -870,10 +870,10 @@ discard block |
||
870 | 870 | */ |
871 | 871 | private static function _register_widgets($addon_name) |
872 | 872 | { |
873 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
873 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
874 | 874 | EE_Register_Widget::register( |
875 | 875 | $addon_name, |
876 | - array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
876 | + array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
877 | 877 | ); |
878 | 878 | } |
879 | 879 | } |
@@ -886,12 +886,12 @@ discard block |
||
886 | 886 | */ |
887 | 887 | private static function _register_capabilities($addon_name) |
888 | 888 | { |
889 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
889 | + if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
890 | 890 | EE_Register_Capabilities::register( |
891 | 891 | $addon_name, |
892 | 892 | array( |
893 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
894 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
893 | + 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
894 | + 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
895 | 895 | ) |
896 | 896 | ); |
897 | 897 | } |
@@ -905,7 +905,7 @@ discard block |
||
905 | 905 | */ |
906 | 906 | private static function _register_message_types($addon_name) |
907 | 907 | { |
908 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
908 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
909 | 909 | add_action( |
910 | 910 | 'EE_Brewing_Regular___messages_caf', |
911 | 911 | array('EE_Register_Addon', 'register_message_types') |
@@ -921,15 +921,15 @@ discard block |
||
921 | 921 | */ |
922 | 922 | private static function _register_custom_post_types($addon_name) |
923 | 923 | { |
924 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
925 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
924 | + if ( ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
925 | + || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
926 | 926 | ) { |
927 | 927 | EE_Register_CPT::register( |
928 | 928 | $addon_name, |
929 | 929 | array( |
930 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
931 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
932 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
930 | + 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
931 | + 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
932 | + 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
933 | 933 | ) |
934 | 934 | ); |
935 | 935 | } |
@@ -947,10 +947,10 @@ discard block |
||
947 | 947 | */ |
948 | 948 | private static function _register_payment_methods($addon_name) |
949 | 949 | { |
950 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
950 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
951 | 951 | EE_Register_Payment_Method::register( |
952 | 952 | $addon_name, |
953 | - array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
953 | + array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
954 | 954 | ); |
955 | 955 | } |
956 | 956 | } |
@@ -967,10 +967,10 @@ discard block |
||
967 | 967 | */ |
968 | 968 | private static function registerPrivacyPolicies($addon_name) |
969 | 969 | { |
970 | - if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) { |
|
970 | + if ( ! empty(self::$_settings[$addon_name]['privacy_policies'])) { |
|
971 | 971 | EE_Register_Privacy_Policy::register( |
972 | 972 | $addon_name, |
973 | - self::$_settings[ $addon_name ]['privacy_policies'] |
|
973 | + self::$_settings[$addon_name]['privacy_policies'] |
|
974 | 974 | ); |
975 | 975 | } |
976 | 976 | } |
@@ -982,10 +982,10 @@ discard block |
||
982 | 982 | */ |
983 | 983 | private static function registerPersonalDataExporters($addon_name) |
984 | 984 | { |
985 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) { |
|
985 | + if ( ! empty(self::$_settings[$addon_name]['personal_data_exporters'])) { |
|
986 | 986 | EE_Register_Personal_Data_Eraser::register( |
987 | 987 | $addon_name, |
988 | - self::$_settings[ $addon_name ]['personal_data_exporters'] |
|
988 | + self::$_settings[$addon_name]['personal_data_exporters'] |
|
989 | 989 | ); |
990 | 990 | } |
991 | 991 | } |
@@ -997,10 +997,10 @@ discard block |
||
997 | 997 | */ |
998 | 998 | private static function registerPersonalDataErasers($addon_name) |
999 | 999 | { |
1000 | - if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) { |
|
1000 | + if ( ! empty(self::$_settings[$addon_name]['personal_data_erasers'])) { |
|
1001 | 1001 | EE_Register_Personal_Data_Eraser::register( |
1002 | 1002 | $addon_name, |
1003 | - self::$_settings[ $addon_name ]['personal_data_erasers'] |
|
1003 | + self::$_settings[$addon_name]['personal_data_erasers'] |
|
1004 | 1004 | ); |
1005 | 1005 | } |
1006 | 1006 | } |
@@ -1021,7 +1021,7 @@ discard block |
||
1021 | 1021 | { |
1022 | 1022 | $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
1023 | 1023 | $addon = $loader->getShared( |
1024 | - self::$_settings[ $addon_name ]['class_name'], |
|
1024 | + self::$_settings[$addon_name]['class_name'], |
|
1025 | 1025 | array('EE_Registry::create(addon)' => true) |
1026 | 1026 | ); |
1027 | 1027 | // setter inject dep map if required |
@@ -1033,19 +1033,19 @@ discard block |
||
1033 | 1033 | && $addon->domain() === null |
1034 | 1034 | ) { |
1035 | 1035 | // using supplied Domain object |
1036 | - $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface |
|
1037 | - ? self::$_settings[ $addon_name ]['domain'] |
|
1036 | + $domain = self::$_settings[$addon_name]['domain'] instanceof DomainInterface |
|
1037 | + ? self::$_settings[$addon_name]['domain'] |
|
1038 | 1038 | : null; |
1039 | 1039 | // or construct one using Domain FQCN |
1040 | - if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') { |
|
1040 | + if ($domain === null && self::$_settings[$addon_name]['domain_fqcn'] !== '') { |
|
1041 | 1041 | $domain = $loader->getShared( |
1042 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
1042 | + self::$_settings[$addon_name]['domain_fqcn'], |
|
1043 | 1043 | array( |
1044 | 1044 | new EventEspresso\core\domain\values\FilePath( |
1045 | - self::$_settings[ $addon_name ]['main_file_path'] |
|
1045 | + self::$_settings[$addon_name]['main_file_path'] |
|
1046 | 1046 | ), |
1047 | 1047 | EventEspresso\core\domain\values\Version::fromString( |
1048 | - self::$_settings[ $addon_name ]['version'] |
|
1048 | + self::$_settings[$addon_name]['version'] |
|
1049 | 1049 | ), |
1050 | 1050 | ) |
1051 | 1051 | ); |
@@ -1055,28 +1055,28 @@ discard block |
||
1055 | 1055 | } |
1056 | 1056 | } |
1057 | 1057 | $addon->set_name($addon_name); |
1058 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
1059 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
1060 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
1061 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
1062 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
1063 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
1064 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
1065 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
1066 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
1067 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
1058 | + $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
1059 | + $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
1060 | + $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
1061 | + $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
1062 | + $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
1063 | + $addon->set_version(self::$_settings[$addon_name]['version']); |
|
1064 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
1065 | + $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
1066 | + $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
1067 | + $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
1068 | 1068 | // setup the add-on's pue_slug if we have one. |
1069 | - if (! empty(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) { |
|
1070 | - $addon->setPueSlug(self::$_settings[ $addon_name ]['pue_options']['pue_plugin_slug']); |
|
1069 | + if ( ! empty(self::$_settings[$addon_name]['pue_options']['pue_plugin_slug'])) { |
|
1070 | + $addon->setPueSlug(self::$_settings[$addon_name]['pue_options']['pue_plugin_slug']); |
|
1071 | 1071 | } |
1072 | 1072 | // unfortunately this can't be hooked in upon construction, because we don't have |
1073 | 1073 | // the plugin mainfile's path upon construction. |
1074 | 1074 | register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
1075 | 1075 | // call any additional admin_callback functions during load_admin_controller hook |
1076 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
1076 | + if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
1077 | 1077 | add_action( |
1078 | 1078 | 'AHEE__EE_System__load_controllers__load_admin_controllers', |
1079 | - array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
1079 | + array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
1080 | 1080 | ); |
1081 | 1081 | } |
1082 | 1082 | return $addon; |
@@ -1094,11 +1094,11 @@ discard block |
||
1094 | 1094 | public static function load_pue_update() |
1095 | 1095 | { |
1096 | 1096 | // load PUE client |
1097 | - require_once EE_THIRD_PARTY . 'pue/pue-client.php'; |
|
1097 | + require_once EE_THIRD_PARTY.'pue/pue-client.php'; |
|
1098 | 1098 | $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com'; |
1099 | 1099 | // cycle thru settings |
1100 | 1100 | foreach (self::$_settings as $settings) { |
1101 | - if (! empty($settings['pue_options'])) { |
|
1101 | + if ( ! empty($settings['pue_options'])) { |
|
1102 | 1102 | // initiate the class and start the plugin update engine! |
1103 | 1103 | new PluginUpdateEngineChecker( |
1104 | 1104 | // host file URL |
@@ -1106,7 +1106,7 @@ discard block |
||
1106 | 1106 | // plugin slug(s) |
1107 | 1107 | array( |
1108 | 1108 | 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
1109 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
1109 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'), |
|
1110 | 1110 | ), |
1111 | 1111 | // options |
1112 | 1112 | array( |
@@ -1135,7 +1135,7 @@ discard block |
||
1135 | 1135 | public static function register_message_types() |
1136 | 1136 | { |
1137 | 1137 | foreach (self::$_settings as $addon_name => $settings) { |
1138 | - if (! empty($settings['message_types'])) { |
|
1138 | + if ( ! empty($settings['message_types'])) { |
|
1139 | 1139 | foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
1140 | 1140 | EE_Register_Message_Type::register($message_type, $message_type_settings); |
1141 | 1141 | } |
@@ -1157,70 +1157,70 @@ discard block |
||
1157 | 1157 | */ |
1158 | 1158 | public static function deregister($addon_name = null) |
1159 | 1159 | { |
1160 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1160 | + if (isset(self::$_settings[$addon_name]['class_name'])) { |
|
1161 | 1161 | try { |
1162 | 1162 | do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
1163 | - $class_name = self::$_settings[ $addon_name ]['class_name']; |
|
1164 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
1163 | + $class_name = self::$_settings[$addon_name]['class_name']; |
|
1164 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
1165 | 1165 | // setup DMS |
1166 | 1166 | EE_Register_Data_Migration_Scripts::deregister($addon_name); |
1167 | 1167 | } |
1168 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
1168 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
1169 | 1169 | // register admin page |
1170 | 1170 | EE_Register_Admin_Page::deregister($addon_name); |
1171 | 1171 | } |
1172 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
1172 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
1173 | 1173 | // add to list of modules to be registered |
1174 | 1174 | EE_Register_Module::deregister($addon_name); |
1175 | 1175 | } |
1176 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
1177 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
1176 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
1177 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
1178 | 1178 | ) { |
1179 | 1179 | // add to list of shortcodes to be registered |
1180 | 1180 | EE_Register_Shortcode::deregister($addon_name); |
1181 | 1181 | } |
1182 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
1182 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
1183 | 1183 | // if config_class present let's register config. |
1184 | - EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']); |
|
1184 | + EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
1185 | 1185 | } |
1186 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
1186 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
1187 | 1187 | // add to list of widgets to be registered |
1188 | 1188 | EE_Register_Widget::deregister($addon_name); |
1189 | 1189 | } |
1190 | - if (! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
1191 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
1190 | + if ( ! empty(self::$_settings[$addon_name]['model_paths']) |
|
1191 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
1192 | 1192 | ) { |
1193 | 1193 | // add to list of shortcodes to be registered |
1194 | 1194 | EE_Register_Model::deregister($addon_name); |
1195 | 1195 | } |
1196 | - if (! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
1197 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
1196 | + if ( ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
1197 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
1198 | 1198 | ) { |
1199 | 1199 | // add to list of shortcodes to be registered |
1200 | 1200 | EE_Register_Model_Extensions::deregister($addon_name); |
1201 | 1201 | } |
1202 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
1203 | - foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) { |
|
1202 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
1203 | + foreach ((array) self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) { |
|
1204 | 1204 | EE_Register_Message_Type::deregister($message_type); |
1205 | 1205 | } |
1206 | 1206 | } |
1207 | 1207 | // deregister capabilities for addon |
1208 | - if (! empty(self::$_settings[ $addon_name ]['capabilities']) |
|
1209 | - || ! empty(self::$_settings[ $addon_name ]['capability_maps']) |
|
1208 | + if ( ! empty(self::$_settings[$addon_name]['capabilities']) |
|
1209 | + || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
1210 | 1210 | ) { |
1211 | 1211 | EE_Register_Capabilities::deregister($addon_name); |
1212 | 1212 | } |
1213 | 1213 | // deregister custom_post_types for addon |
1214 | - if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) { |
|
1214 | + if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
1215 | 1215 | EE_Register_CPT::deregister($addon_name); |
1216 | 1216 | } |
1217 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
1217 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
1218 | 1218 | EE_Register_Payment_Method::deregister($addon_name); |
1219 | 1219 | } |
1220 | 1220 | $addon = EE_Registry::instance()->getAddon($class_name); |
1221 | 1221 | if ($addon instanceof EE_Addon) { |
1222 | 1222 | remove_action( |
1223 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1223 | + 'deactivate_'.$addon->get_main_plugin_file_basename(), |
|
1224 | 1224 | array($addon, 'deactivation') |
1225 | 1225 | ); |
1226 | 1226 | remove_action( |
@@ -1243,7 +1243,7 @@ discard block |
||
1243 | 1243 | } catch (Exception $e) { |
1244 | 1244 | new ExceptionLogger($e); |
1245 | 1245 | } |
1246 | - unset(self::$_settings[ $addon_name ]); |
|
1246 | + unset(self::$_settings[$addon_name]); |
|
1247 | 1247 | do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
1248 | 1248 | } |
1249 | 1249 | } |
@@ -15,9 +15,9 @@ discard block |
||
15 | 15 | $stages = glob(EE_CORE . 'data_migration_scripts/4_10_0_stages/*'); |
16 | 16 | $class_to_filepath = []; |
17 | 17 | foreach ($stages as $filepath) { |
18 | - $matches = []; |
|
19 | - preg_match('~4_10_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
20 | - $class_to_filepath[ $matches[1] ] = $filepath; |
|
18 | + $matches = []; |
|
19 | + preg_match('~4_10_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
20 | + $class_to_filepath[ $matches[1] ] = $filepath; |
|
21 | 21 | } |
22 | 22 | // give addons a chance to autoload their stages too |
23 | 23 | $class_to_filepath = apply_filters('FHEE__EE_DMS_4_10_0__autoloaded_stages', $class_to_filepath); |
@@ -35,66 +35,66 @@ discard block |
||
35 | 35 | */ |
36 | 36 | class EE_DMS_Core_4_10_0 extends EE_Data_Migration_Script_Base |
37 | 37 | { |
38 | - /** |
|
39 | - * |
|
40 | - * @param TableManager $table_manager |
|
41 | - * @param TableAnalysis $table_analysis |
|
42 | - */ |
|
43 | - public function __construct( |
|
44 | - TableManager $table_manager = null, |
|
45 | - TableAnalysis $table_analysis = null, |
|
46 | - EE_DMS_Core_4_9_0 $dms_4_9 |
|
47 | - ) { |
|
48 | - $this->previous_dms = $dms_4_9; |
|
49 | - $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.10.0", "event_espresso"); |
|
50 | - $this->_priority = 10; |
|
51 | - $this->_migration_stages = array( |
|
52 | - new EE_DMS_4_10_0_Event_Question_Group(), |
|
53 | - ); |
|
54 | - parent::__construct($table_manager, $table_analysis); |
|
55 | - } |
|
38 | + /** |
|
39 | + * |
|
40 | + * @param TableManager $table_manager |
|
41 | + * @param TableAnalysis $table_analysis |
|
42 | + */ |
|
43 | + public function __construct( |
|
44 | + TableManager $table_manager = null, |
|
45 | + TableAnalysis $table_analysis = null, |
|
46 | + EE_DMS_Core_4_9_0 $dms_4_9 |
|
47 | + ) { |
|
48 | + $this->previous_dms = $dms_4_9; |
|
49 | + $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.10.0", "event_espresso"); |
|
50 | + $this->_priority = 10; |
|
51 | + $this->_migration_stages = array( |
|
52 | + new EE_DMS_4_10_0_Event_Question_Group(), |
|
53 | + ); |
|
54 | + parent::__construct($table_manager, $table_analysis); |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * Whether to migrate or not. |
|
61 | - * |
|
62 | - * @param array $version_array |
|
63 | - * @return bool |
|
64 | - */ |
|
65 | - public function can_migrate_from_version($version_array) |
|
66 | - { |
|
67 | - $version_string = $version_array['Core']; |
|
68 | - if (version_compare($version_string, '4.10.0.decaf', '<') && version_compare($version_string, '4.9.0.decaf', '>=')) { |
|
69 | - return true; |
|
70 | - } elseif (! $version_string) { |
|
71 | - // echo "no version string provided: $version_string"; |
|
72 | - // no version string provided... this must be pre 4.3 |
|
73 | - return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
74 | - } |
|
75 | - return false; |
|
76 | - } |
|
59 | + /** |
|
60 | + * Whether to migrate or not. |
|
61 | + * |
|
62 | + * @param array $version_array |
|
63 | + * @return bool |
|
64 | + */ |
|
65 | + public function can_migrate_from_version($version_array) |
|
66 | + { |
|
67 | + $version_string = $version_array['Core']; |
|
68 | + if (version_compare($version_string, '4.10.0.decaf', '<') && version_compare($version_string, '4.9.0.decaf', '>=')) { |
|
69 | + return true; |
|
70 | + } elseif (! $version_string) { |
|
71 | + // echo "no version string provided: $version_string"; |
|
72 | + // no version string provided... this must be pre 4.3 |
|
73 | + return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
74 | + } |
|
75 | + return false; |
|
76 | + } |
|
77 | 77 | |
78 | 78 | |
79 | 79 | |
80 | - /** |
|
81 | - * @return bool |
|
82 | - */ |
|
83 | - public function schema_changes_before_migration() |
|
84 | - { |
|
85 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
86 | - $now_in_mysql = current_time('mysql', true); |
|
87 | - $table_name = 'esp_answer'; |
|
88 | - $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
80 | + /** |
|
81 | + * @return bool |
|
82 | + */ |
|
83 | + public function schema_changes_before_migration() |
|
84 | + { |
|
85 | + require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
86 | + $now_in_mysql = current_time('mysql', true); |
|
87 | + $table_name = 'esp_answer'; |
|
88 | + $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
89 | 89 | REG_ID int(10) unsigned NOT NULL, |
90 | 90 | QST_ID int(10) unsigned NOT NULL, |
91 | 91 | ANS_value text NOT NULL, |
92 | 92 | PRIMARY KEY (ANS_ID), |
93 | 93 | KEY REG_ID (REG_ID), |
94 | 94 | KEY QST_ID (QST_ID)"; |
95 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
96 | - $table_name = 'esp_attendee_meta'; |
|
97 | - $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
95 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
96 | + $table_name = 'esp_attendee_meta'; |
|
97 | + $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
98 | 98 | ATT_ID bigint(20) unsigned NOT NULL, |
99 | 99 | ATT_fname varchar(45) NOT NULL, |
100 | 100 | ATT_lname varchar(45) NOT NULL, |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | KEY ATT_email (ATT_email(191)), |
112 | 112 | KEY ATT_lname (ATT_lname), |
113 | 113 | KEY ATT_fname (ATT_fname)"; |
114 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
115 | - $table_name = 'esp_checkin'; |
|
116 | - $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
114 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
115 | + $table_name = 'esp_checkin'; |
|
116 | + $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
117 | 117 | REG_ID int(10) unsigned NOT NULL, |
118 | 118 | DTT_ID int(10) unsigned NOT NULL, |
119 | 119 | CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | PRIMARY KEY (CHK_ID), |
122 | 122 | KEY REG_ID (REG_ID), |
123 | 123 | KEY DTT_ID (DTT_ID)"; |
124 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
125 | - $table_name = 'esp_country'; |
|
126 | - $sql = "CNT_ISO varchar(2) NOT NULL, |
|
124 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
125 | + $table_name = 'esp_country'; |
|
126 | + $sql = "CNT_ISO varchar(2) NOT NULL, |
|
127 | 127 | CNT_ISO3 varchar(3) NOT NULL, |
128 | 128 | RGN_ID tinyint(3) unsigned DEFAULT NULL, |
129 | 129 | CNT_name varchar(45) NOT NULL, |
@@ -139,29 +139,29 @@ discard block |
||
139 | 139 | CNT_is_EU tinyint(1) DEFAULT '0', |
140 | 140 | CNT_active tinyint(1) DEFAULT '0', |
141 | 141 | PRIMARY KEY (CNT_ISO)"; |
142 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
143 | - $table_name = 'esp_currency'; |
|
144 | - $sql = "CUR_code varchar(6) NOT NULL, |
|
142 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
143 | + $table_name = 'esp_currency'; |
|
144 | + $sql = "CUR_code varchar(6) NOT NULL, |
|
145 | 145 | CUR_single varchar(45) DEFAULT 'dollar', |
146 | 146 | CUR_plural varchar(45) DEFAULT 'dollars', |
147 | 147 | CUR_sign varchar(45) DEFAULT '$', |
148 | 148 | CUR_dec_plc varchar(1) NOT NULL DEFAULT '2', |
149 | 149 | CUR_active tinyint(1) DEFAULT '0', |
150 | 150 | PRIMARY KEY (CUR_code)"; |
151 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
152 | - // note: although this table is no longer in use, |
|
153 | - // it hasn't been removed because then queries to the model will have errors. |
|
154 | - // but you should expect this table and its corresponding model to be removed in |
|
155 | - // the next few months |
|
156 | - $table_name = 'esp_currency_payment_method'; |
|
157 | - $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
151 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
152 | + // note: although this table is no longer in use, |
|
153 | + // it hasn't been removed because then queries to the model will have errors. |
|
154 | + // but you should expect this table and its corresponding model to be removed in |
|
155 | + // the next few months |
|
156 | + $table_name = 'esp_currency_payment_method'; |
|
157 | + $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
158 | 158 | CUR_code varchar(6) NOT NULL, |
159 | 159 | PMD_ID int(11) NOT NULL, |
160 | 160 | PRIMARY KEY (CPM_ID), |
161 | 161 | KEY PMD_ID (PMD_ID)"; |
162 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
163 | - $table_name = 'esp_datetime'; |
|
164 | - $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
162 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
163 | + $table_name = 'esp_datetime'; |
|
164 | + $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
165 | 165 | EVT_ID bigint(20) unsigned NOT NULL, |
166 | 166 | DTT_name varchar(255) NOT NULL DEFAULT '', |
167 | 167 | DTT_description text NOT NULL, |
@@ -178,25 +178,25 @@ discard block |
||
178 | 178 | KEY DTT_EVT_start (DTT_EVT_start), |
179 | 179 | KEY EVT_ID (EVT_ID), |
180 | 180 | KEY DTT_is_primary (DTT_is_primary)"; |
181 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
182 | - $table_name = "esp_datetime_ticket"; |
|
183 | - $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
181 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
182 | + $table_name = "esp_datetime_ticket"; |
|
183 | + $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
184 | 184 | DTT_ID int(10) unsigned NOT NULL, |
185 | 185 | TKT_ID int(10) unsigned NOT NULL, |
186 | 186 | PRIMARY KEY (DTK_ID), |
187 | 187 | KEY DTT_ID (DTT_ID), |
188 | 188 | KEY TKT_ID (TKT_ID)"; |
189 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
190 | - $table_name = 'esp_event_message_template'; |
|
191 | - $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
189 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
190 | + $table_name = 'esp_event_message_template'; |
|
191 | + $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
192 | 192 | EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
193 | 193 | GRP_ID int(10) unsigned NOT NULL DEFAULT 0, |
194 | 194 | PRIMARY KEY (EMT_ID), |
195 | 195 | KEY EVT_ID (EVT_ID), |
196 | 196 | KEY GRP_ID (GRP_ID)"; |
197 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
198 | - $table_name = 'esp_event_meta'; |
|
199 | - $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
197 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
198 | + $table_name = 'esp_event_meta'; |
|
199 | + $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
200 | 200 | EVT_ID bigint(20) unsigned NOT NULL, |
201 | 201 | EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1, |
202 | 202 | EVT_display_ticket_selector tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -211,9 +211,9 @@ discard block |
||
211 | 211 | EVT_donations tinyint(1) NULL, |
212 | 212 | PRIMARY KEY (EVTM_ID), |
213 | 213 | KEY EVT_ID (EVT_ID)"; |
214 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
215 | - $table_name = 'esp_event_question_group'; |
|
216 | - $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
214 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
215 | + $table_name = 'esp_event_question_group'; |
|
216 | + $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
217 | 217 | EVT_ID bigint(20) unsigned NOT NULL, |
218 | 218 | QSG_ID int(10) unsigned NOT NULL, |
219 | 219 | EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
@@ -221,25 +221,25 @@ discard block |
||
221 | 221 | PRIMARY KEY (EQG_ID), |
222 | 222 | KEY EVT_ID (EVT_ID), |
223 | 223 | KEY QSG_ID (QSG_ID)"; |
224 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
225 | - $table_name = 'esp_event_venue'; |
|
226 | - $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
224 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
225 | + $table_name = 'esp_event_venue'; |
|
226 | + $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
227 | 227 | EVT_ID bigint(20) unsigned NOT NULL, |
228 | 228 | VNU_ID bigint(20) unsigned NOT NULL, |
229 | 229 | EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
230 | 230 | PRIMARY KEY (EVV_ID)"; |
231 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
232 | - $table_name = 'esp_extra_meta'; |
|
233 | - $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
231 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
232 | + $table_name = 'esp_extra_meta'; |
|
233 | + $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
234 | 234 | OBJ_ID int(11) DEFAULT NULL, |
235 | 235 | EXM_type varchar(45) DEFAULT NULL, |
236 | 236 | EXM_key varchar(45) DEFAULT NULL, |
237 | 237 | EXM_value text, |
238 | 238 | PRIMARY KEY (EXM_ID), |
239 | 239 | KEY EXM_type (EXM_type,OBJ_ID,EXM_key)"; |
240 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
241 | - $table_name = 'esp_extra_join'; |
|
242 | - $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
240 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
241 | + $table_name = 'esp_extra_join'; |
|
242 | + $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
243 | 243 | EXJ_first_model_id varchar(6) NOT NULL, |
244 | 244 | EXJ_first_model_name varchar(20) NOT NULL, |
245 | 245 | EXJ_second_model_id varchar(6) NOT NULL, |
@@ -247,9 +247,9 @@ discard block |
||
247 | 247 | PRIMARY KEY (EXJ_ID), |
248 | 248 | KEY first_model (EXJ_first_model_name,EXJ_first_model_id), |
249 | 249 | KEY second_model (EXJ_second_model_name,EXJ_second_model_id)"; |
250 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
251 | - $table_name = 'esp_line_item'; |
|
252 | - $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
250 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
251 | + $table_name = 'esp_line_item'; |
|
252 | + $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
253 | 253 | LIN_code varchar(245) NOT NULL DEFAULT '', |
254 | 254 | TXN_ID int(11) DEFAULT NULL, |
255 | 255 | LIN_name varchar(245) NOT NULL DEFAULT '', |
@@ -270,9 +270,9 @@ discard block |
||
270 | 270 | KEY txn_type_timestamp (TXN_ID,LIN_type,LIN_timestamp), |
271 | 271 | KEY txn_obj_id_obj_type (TXN_ID,OBJ_ID,OBJ_type), |
272 | 272 | KEY obj_id_obj_type (OBJ_ID,OBJ_type)"; |
273 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
274 | - $table_name = 'esp_log'; |
|
275 | - $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
273 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
274 | + $table_name = 'esp_log'; |
|
275 | + $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
276 | 276 | LOG_time datetime DEFAULT NULL, |
277 | 277 | OBJ_ID varchar(45) DEFAULT NULL, |
278 | 278 | OBJ_type varchar(45) DEFAULT NULL, |
@@ -283,9 +283,9 @@ discard block |
||
283 | 283 | KEY LOG_time (LOG_time), |
284 | 284 | KEY OBJ (OBJ_type,OBJ_ID), |
285 | 285 | KEY LOG_type (LOG_type)"; |
286 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
287 | - $table_name = 'esp_message'; |
|
288 | - $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
286 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
287 | + $table_name = 'esp_message'; |
|
288 | + $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
289 | 289 | GRP_ID int(10) unsigned NULL, |
290 | 290 | MSG_token varchar(255) NULL, |
291 | 291 | TXN_ID int(10) unsigned NULL, |
@@ -317,18 +317,18 @@ discard block |
||
317 | 317 | KEY STS_ID (STS_ID), |
318 | 318 | KEY MSG_created (MSG_created), |
319 | 319 | KEY MSG_modified (MSG_modified)"; |
320 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
321 | - $table_name = 'esp_message_template'; |
|
322 | - $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
320 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
321 | + $table_name = 'esp_message_template'; |
|
322 | + $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
323 | 323 | GRP_ID int(10) unsigned NOT NULL, |
324 | 324 | MTP_context varchar(50) NOT NULL, |
325 | 325 | MTP_template_field varchar(30) NOT NULL, |
326 | 326 | MTP_content text NOT NULL, |
327 | 327 | PRIMARY KEY (MTP_ID), |
328 | 328 | KEY GRP_ID (GRP_ID)"; |
329 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
330 | - $table_name = 'esp_message_template_group'; |
|
331 | - $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
329 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
330 | + $table_name = 'esp_message_template_group'; |
|
331 | + $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
332 | 332 | MTP_user_id int(10) NOT NULL DEFAULT '1', |
333 | 333 | MTP_name varchar(245) NOT NULL DEFAULT '', |
334 | 334 | MTP_description varchar(245) NOT NULL DEFAULT '', |
@@ -340,9 +340,9 @@ discard block |
||
340 | 340 | MTP_is_active tinyint(1) NOT NULL DEFAULT '1', |
341 | 341 | PRIMARY KEY (GRP_ID), |
342 | 342 | KEY MTP_user_id (MTP_user_id)"; |
343 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
344 | - $table_name = 'esp_payment'; |
|
345 | - $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
343 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
344 | + $table_name = 'esp_payment'; |
|
345 | + $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
346 | 346 | TXN_ID int(10) unsigned DEFAULT NULL, |
347 | 347 | STS_ID varchar(3) DEFAULT NULL, |
348 | 348 | PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -359,9 +359,9 @@ discard block |
||
359 | 359 | PRIMARY KEY (PAY_ID), |
360 | 360 | KEY PAY_timestamp (PAY_timestamp), |
361 | 361 | KEY TXN_ID (TXN_ID)"; |
362 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
363 | - $table_name = 'esp_payment_method'; |
|
364 | - $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
362 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
363 | + $table_name = 'esp_payment_method'; |
|
364 | + $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
365 | 365 | PMD_type varchar(124) DEFAULT NULL, |
366 | 366 | PMD_name varchar(255) DEFAULT NULL, |
367 | 367 | PMD_desc text, |
@@ -377,24 +377,24 @@ discard block |
||
377 | 377 | PRIMARY KEY (PMD_ID), |
378 | 378 | UNIQUE KEY PMD_slug_UNIQUE (PMD_slug), |
379 | 379 | KEY PMD_type (PMD_type)"; |
380 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
381 | - $table_name = "esp_ticket_price"; |
|
382 | - $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
380 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
381 | + $table_name = "esp_ticket_price"; |
|
382 | + $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
383 | 383 | TKT_ID int(10) unsigned NOT NULL, |
384 | 384 | PRC_ID int(10) unsigned NOT NULL, |
385 | 385 | PRIMARY KEY (TKP_ID), |
386 | 386 | KEY TKT_ID (TKT_ID), |
387 | 387 | KEY PRC_ID (PRC_ID)"; |
388 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
389 | - $table_name = "esp_ticket_template"; |
|
390 | - $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
388 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
389 | + $table_name = "esp_ticket_template"; |
|
390 | + $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
391 | 391 | TTM_name varchar(45) NOT NULL, |
392 | 392 | TTM_description text, |
393 | 393 | TTM_file varchar(45), |
394 | 394 | PRIMARY KEY (TTM_ID)"; |
395 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
396 | - $table_name = 'esp_question'; |
|
397 | - $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
395 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
396 | + $table_name = 'esp_question'; |
|
397 | + $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
398 | 398 | QST_display_text text NOT NULL, |
399 | 399 | QST_admin_label varchar(255) NOT NULL, |
400 | 400 | QST_system varchar(25) DEFAULT NULL, |
@@ -408,18 +408,18 @@ discard block |
||
408 | 408 | QST_deleted tinyint(2) unsigned NOT NULL DEFAULT 0, |
409 | 409 | PRIMARY KEY (QST_ID), |
410 | 410 | KEY QST_order (QST_order)'; |
411 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
412 | - $table_name = 'esp_question_group_question'; |
|
413 | - $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
411 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
412 | + $table_name = 'esp_question_group_question'; |
|
413 | + $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
414 | 414 | QSG_ID int(10) unsigned NOT NULL, |
415 | 415 | QST_ID int(10) unsigned NOT NULL, |
416 | 416 | QGQ_order int(10) unsigned NOT NULL DEFAULT 0, |
417 | 417 | PRIMARY KEY (QGQ_ID), |
418 | 418 | KEY QST_ID (QST_ID), |
419 | 419 | KEY QSG_ID_order (QSG_ID,QGQ_order)"; |
420 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
421 | - $table_name = 'esp_question_option'; |
|
422 | - $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
420 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
421 | + $table_name = 'esp_question_option'; |
|
422 | + $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
423 | 423 | QSO_value varchar(255) NOT NULL, |
424 | 424 | QSO_desc text NOT NULL, |
425 | 425 | QST_ID int(10) unsigned NOT NULL, |
@@ -429,9 +429,9 @@ discard block |
||
429 | 429 | PRIMARY KEY (QSO_ID), |
430 | 430 | KEY QST_ID (QST_ID), |
431 | 431 | KEY QSO_order (QSO_order)"; |
432 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
433 | - $table_name = 'esp_registration'; |
|
434 | - $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
432 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
433 | + $table_name = 'esp_registration'; |
|
434 | + $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
435 | 435 | EVT_ID bigint(20) unsigned NOT NULL, |
436 | 436 | ATT_ID bigint(20) unsigned NOT NULL, |
437 | 437 | TXN_ID int(10) unsigned NOT NULL, |
@@ -455,18 +455,18 @@ discard block |
||
455 | 455 | KEY TKT_ID (TKT_ID), |
456 | 456 | KEY EVT_ID (EVT_ID), |
457 | 457 | KEY STS_ID (STS_ID)"; |
458 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
459 | - $table_name = 'esp_registration_payment'; |
|
460 | - $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
458 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
459 | + $table_name = 'esp_registration_payment'; |
|
460 | + $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
461 | 461 | REG_ID int(10) unsigned NOT NULL, |
462 | 462 | PAY_ID int(10) unsigned NULL, |
463 | 463 | RPY_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
464 | 464 | PRIMARY KEY (RPY_ID), |
465 | 465 | KEY REG_ID (REG_ID), |
466 | 466 | KEY PAY_ID (PAY_ID)"; |
467 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
468 | - $table_name = 'esp_state'; |
|
469 | - $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
467 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
468 | + $table_name = 'esp_state'; |
|
469 | + $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
470 | 470 | CNT_ISO varchar(2) NOT NULL, |
471 | 471 | STA_abbrev varchar(24) NOT NULL, |
472 | 472 | STA_name varchar(100) NOT NULL, |
@@ -474,9 +474,9 @@ discard block |
||
474 | 474 | PRIMARY KEY (STA_ID), |
475 | 475 | KEY STA_abbrev (STA_abbrev), |
476 | 476 | KEY CNT_ISO (CNT_ISO)"; |
477 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
478 | - $table_name = 'esp_status'; |
|
479 | - $sql = "STS_ID varchar(3) NOT NULL, |
|
477 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
478 | + $table_name = 'esp_status'; |
|
479 | + $sql = "STS_ID varchar(3) NOT NULL, |
|
480 | 480 | STS_code varchar(45) NOT NULL, |
481 | 481 | STS_type varchar(45) NOT NULL, |
482 | 482 | STS_can_edit tinyint(1) NOT NULL DEFAULT 0, |
@@ -484,9 +484,9 @@ discard block |
||
484 | 484 | STS_open tinyint(1) NOT NULL DEFAULT 1, |
485 | 485 | UNIQUE KEY STS_ID_UNIQUE (STS_ID), |
486 | 486 | KEY STS_type (STS_type)"; |
487 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
488 | - $table_name = 'esp_transaction'; |
|
489 | - $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
487 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
488 | + $table_name = 'esp_transaction'; |
|
489 | + $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
490 | 490 | TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
491 | 491 | TXN_total decimal(12,3) DEFAULT '0.00', |
492 | 492 | TXN_paid decimal(12,3) NOT NULL DEFAULT '0.00', |
@@ -498,9 +498,9 @@ discard block |
||
498 | 498 | PRIMARY KEY (TXN_ID), |
499 | 499 | KEY TXN_timestamp (TXN_timestamp), |
500 | 500 | KEY STS_ID (STS_ID)"; |
501 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
502 | - $table_name = 'esp_venue_meta'; |
|
503 | - $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
501 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
502 | + $table_name = 'esp_venue_meta'; |
|
503 | + $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
504 | 504 | VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
505 | 505 | VNU_address varchar(255) DEFAULT NULL, |
506 | 506 | VNU_address2 varchar(255) DEFAULT NULL, |
@@ -519,10 +519,10 @@ discard block |
||
519 | 519 | KEY VNU_ID (VNU_ID), |
520 | 520 | KEY STA_ID (STA_ID), |
521 | 521 | KEY CNT_ISO (CNT_ISO)"; |
522 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
523 | - // modified tables |
|
524 | - $table_name = "esp_price"; |
|
525 | - $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
522 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
523 | + // modified tables |
|
524 | + $table_name = "esp_price"; |
|
525 | + $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
526 | 526 | PRT_ID tinyint(3) unsigned NOT NULL, |
527 | 527 | PRC_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
528 | 528 | PRC_name varchar(245) NOT NULL, |
@@ -535,9 +535,9 @@ discard block |
||
535 | 535 | PRC_parent int(10) unsigned DEFAULT 0, |
536 | 536 | PRIMARY KEY (PRC_ID), |
537 | 537 | KEY PRT_ID (PRT_ID)"; |
538 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
539 | - $table_name = "esp_price_type"; |
|
540 | - $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
538 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
539 | + $table_name = "esp_price_type"; |
|
540 | + $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
541 | 541 | PRT_name varchar(45) NOT NULL, |
542 | 542 | PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1', |
543 | 543 | PRT_is_percent tinyint(1) NOT NULL DEFAULT '0', |
@@ -546,9 +546,9 @@ discard block |
||
546 | 546 | PRT_deleted tinyint(1) NOT NULL DEFAULT '0', |
547 | 547 | UNIQUE KEY PRT_name_UNIQUE (PRT_name), |
548 | 548 | PRIMARY KEY (PRT_ID)"; |
549 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
550 | - $table_name = "esp_ticket"; |
|
551 | - $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
549 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
550 | + $table_name = "esp_ticket"; |
|
551 | + $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
552 | 552 | TTM_ID int(10) unsigned NOT NULL, |
553 | 553 | TKT_name varchar(245) NOT NULL DEFAULT '', |
554 | 554 | TKT_description text NOT NULL, |
@@ -571,9 +571,9 @@ discard block |
||
571 | 571 | TKT_deleted tinyint(1) NOT NULL DEFAULT '0', |
572 | 572 | PRIMARY KEY (TKT_ID), |
573 | 573 | KEY TKT_start_date (TKT_start_date)"; |
574 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
575 | - $table_name = 'esp_question_group'; |
|
576 | - $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
574 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
575 | + $table_name = 'esp_question_group'; |
|
576 | + $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
577 | 577 | QSG_name varchar(255) NOT NULL, |
578 | 578 | QSG_identifier varchar(100) NOT NULL, |
579 | 579 | QSG_desc text NULL, |
@@ -586,70 +586,70 @@ discard block |
||
586 | 586 | PRIMARY KEY (QSG_ID), |
587 | 587 | UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier), |
588 | 588 | KEY QSG_order (QSG_order)'; |
589 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
590 | - $this->insert_default_data(); |
|
591 | - return true; |
|
592 | - } |
|
589 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
590 | + $this->insert_default_data(); |
|
591 | + return true; |
|
592 | + } |
|
593 | 593 | |
594 | - /** |
|
595 | - * Inserts default data on new installs |
|
596 | - * @since 4.10.0.p |
|
597 | - * @throws EE_Error |
|
598 | - * @throws InvalidArgumentException |
|
599 | - * @throws ReflectionException |
|
600 | - * @throws InvalidDataTypeException |
|
601 | - * @throws InvalidInterfaceException |
|
602 | - */ |
|
603 | - public function insert_default_data() |
|
604 | - { |
|
605 | - $this->previous_dms->insert_default_data(); |
|
606 | - $this->removeMijirehPM(); |
|
607 | - } |
|
594 | + /** |
|
595 | + * Inserts default data on new installs |
|
596 | + * @since 4.10.0.p |
|
597 | + * @throws EE_Error |
|
598 | + * @throws InvalidArgumentException |
|
599 | + * @throws ReflectionException |
|
600 | + * @throws InvalidDataTypeException |
|
601 | + * @throws InvalidInterfaceException |
|
602 | + */ |
|
603 | + public function insert_default_data() |
|
604 | + { |
|
605 | + $this->previous_dms->insert_default_data(); |
|
606 | + $this->removeMijirehPM(); |
|
607 | + } |
|
608 | 608 | |
609 | 609 | |
610 | 610 | |
611 | - /** |
|
612 | - * @return boolean |
|
613 | - */ |
|
614 | - public function schema_changes_after_migration() |
|
615 | - { |
|
616 | - return true; |
|
617 | - } |
|
611 | + /** |
|
612 | + * @return boolean |
|
613 | + */ |
|
614 | + public function schema_changes_after_migration() |
|
615 | + { |
|
616 | + return true; |
|
617 | + } |
|
618 | 618 | |
619 | 619 | |
620 | 620 | |
621 | - public function migration_page_hooks() |
|
622 | - { |
|
623 | - } |
|
621 | + public function migration_page_hooks() |
|
622 | + { |
|
623 | + } |
|
624 | 624 | |
625 | - /** |
|
626 | - * Mijireh was removed in 4.10.3.p, but let's avoid having an error message because its files were removed, and don't |
|
627 | - * show old payments made with it as being by "Unknown". The fix is to make it an "Admin_Only" payment method |
|
628 | - * (like Invoice or Check) but don't allow it to be used in the admin either... so it's usable nowhere from now on, |
|
629 | - * but it still exists so there's no problems. |
|
630 | - * @since 4.10.3.p |
|
631 | - */ |
|
632 | - protected function removeMijirehPM() |
|
633 | - { |
|
634 | - global $wpdb; |
|
635 | - $wpdb->update( |
|
636 | - $wpdb->prefix . 'esp_payment_method', |
|
637 | - [ |
|
638 | - 'PMD_type' => 'Admin_Only', |
|
639 | - 'PMD_scope' => serialize(array()) |
|
640 | - ], |
|
641 | - [ |
|
642 | - 'PMD_type' => 'Mijireh' |
|
643 | - ], |
|
644 | - [ |
|
645 | - // update formats |
|
646 | - '%s', // PMD_type |
|
647 | - '%s', // PMD_scope |
|
648 | - ], |
|
649 | - [ |
|
650 | - // where formats |
|
651 | - '%s' |
|
652 | - ] |
|
653 | - ); |
|
654 | - } |
|
625 | + /** |
|
626 | + * Mijireh was removed in 4.10.3.p, but let's avoid having an error message because its files were removed, and don't |
|
627 | + * show old payments made with it as being by "Unknown". The fix is to make it an "Admin_Only" payment method |
|
628 | + * (like Invoice or Check) but don't allow it to be used in the admin either... so it's usable nowhere from now on, |
|
629 | + * but it still exists so there's no problems. |
|
630 | + * @since 4.10.3.p |
|
631 | + */ |
|
632 | + protected function removeMijirehPM() |
|
633 | + { |
|
634 | + global $wpdb; |
|
635 | + $wpdb->update( |
|
636 | + $wpdb->prefix . 'esp_payment_method', |
|
637 | + [ |
|
638 | + 'PMD_type' => 'Admin_Only', |
|
639 | + 'PMD_scope' => serialize(array()) |
|
640 | + ], |
|
641 | + [ |
|
642 | + 'PMD_type' => 'Mijireh' |
|
643 | + ], |
|
644 | + [ |
|
645 | + // update formats |
|
646 | + '%s', // PMD_type |
|
647 | + '%s', // PMD_scope |
|
648 | + ], |
|
649 | + [ |
|
650 | + // where formats |
|
651 | + '%s' |
|
652 | + ] |
|
653 | + ); |
|
654 | + } |
|
655 | 655 | } |
@@ -26,417 +26,417 @@ discard block |
||
26 | 26 | class EEG_Aim extends EE_Onsite_Gateway |
27 | 27 | { |
28 | 28 | |
29 | - const LIVE_URL = 'https://secure2.authorize.net/gateway/transact.dll'; // Authnet URL |
|
30 | - |
|
31 | - const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll'; |
|
32 | - |
|
33 | - protected $_login_id; |
|
34 | - |
|
35 | - protected $_transaction_key; |
|
36 | - |
|
37 | - protected $_currencies_supported = array( |
|
38 | - 'AUD', |
|
39 | - 'USD', |
|
40 | - 'CAD', |
|
41 | - 'EUR', |
|
42 | - 'GBP', |
|
43 | - 'NZD', |
|
44 | - ); |
|
45 | - |
|
46 | - /** |
|
47 | - * Whether to send test transactions (even to live site) |
|
48 | - * |
|
49 | - * @var boolean |
|
50 | - */ |
|
51 | - protected $_test_transactions; |
|
52 | - |
|
53 | - private $VERIFY_PEER = false; |
|
54 | - |
|
55 | - private $_x_post_fields = array( |
|
56 | - "version" => "3.1", |
|
57 | - "delim_char" => ",", |
|
58 | - "delim_data" => "TRUE", |
|
59 | - "relay_response" => "FALSE", |
|
60 | - "encap_char" => "|", |
|
61 | - ); |
|
62 | - |
|
63 | - private $_additional_line_items = array(); |
|
64 | - |
|
65 | - /** |
|
66 | - * A list of all fields in the AIM API. |
|
67 | - * Used to warn user if they try to set a field not offered in the API. |
|
68 | - */ |
|
69 | - private $_all_aim_fields = array( |
|
70 | - "address", |
|
71 | - "allow_partial_auth", |
|
72 | - "amount", |
|
73 | - "auth_code", |
|
74 | - "authentication_indicator", |
|
75 | - "bank_aba_code", |
|
76 | - "bank_acct_name", |
|
77 | - "bank_acct_num", |
|
78 | - "bank_acct_type", |
|
79 | - "bank_check_number", |
|
80 | - "bank_name", |
|
81 | - "card_code", |
|
82 | - "card_num", |
|
83 | - "cardholder_authentication_value", |
|
84 | - "city", |
|
85 | - "company", |
|
86 | - "country", |
|
87 | - "cust_id", |
|
88 | - "customer_ip", |
|
89 | - "delim_char", |
|
90 | - "delim_data", |
|
91 | - "description", |
|
92 | - "duplicate_window", |
|
93 | - "duty", |
|
94 | - "echeck_type", |
|
95 | - "email", |
|
96 | - "email_customer", |
|
97 | - "encap_char", |
|
98 | - "exp_date", |
|
99 | - "fax", |
|
100 | - "first_name", |
|
101 | - "footer_email_receipt", |
|
102 | - "freight", |
|
103 | - "header_email_receipt", |
|
104 | - "invoice_num", |
|
105 | - "last_name", |
|
106 | - "line_item", |
|
107 | - "login", |
|
108 | - "method", |
|
109 | - "phone", |
|
110 | - "po_num", |
|
111 | - "recurring_billing", |
|
112 | - "relay_response", |
|
113 | - "ship_to_address", |
|
114 | - "ship_to_city", |
|
115 | - "ship_to_company", |
|
116 | - "ship_to_country", |
|
117 | - "ship_to_first_name", |
|
118 | - "ship_to_last_name", |
|
119 | - "ship_to_state", |
|
120 | - "ship_to_zip", |
|
121 | - "split_tender_id", |
|
122 | - "state", |
|
123 | - "tax", |
|
124 | - "tax_exempt", |
|
125 | - "test_request", |
|
126 | - "tran_key", |
|
127 | - "trans_id", |
|
128 | - "type", |
|
129 | - "version", |
|
130 | - "zip", |
|
131 | - "solution_id", |
|
132 | - "currency_code" |
|
133 | - ); |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * Gets the URL where the request should go. This is filterable |
|
138 | - * |
|
139 | - * @return string |
|
140 | - */ |
|
141 | - protected function _get_server_url() |
|
142 | - { |
|
143 | - return apply_filters( |
|
144 | - 'FHEE__EEG_Aim___get_server_url', |
|
145 | - $this->_debug_mode ? self::SANDBOX_URL : self::LIVE_URL, |
|
146 | - $this |
|
147 | - ); |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * Asks the gateway to do whatever it does to process the payment. Onsite gateways will |
|
153 | - * usually send a request directly to the payment provider and update the payment's status based on that; |
|
154 | - * whereas offsite gateways will usually just update the payment with the URL and query parameters to use |
|
155 | - * for sending the request via http_remote_request() |
|
156 | - * |
|
157 | - * @param EEI_Payment $payment |
|
158 | - * @param array $billing_info { |
|
159 | - * @type $credit_card string |
|
160 | - * @type $cvv string |
|
161 | - * @type $exp_month string |
|
162 | - * @type $exp_year string |
|
163 | - * @see parent::do_direct_payment |
|
164 | - * } |
|
165 | - * @return EEI_Payment updated |
|
166 | - */ |
|
167 | - public function do_direct_payment($payment, $billing_info = null) |
|
168 | - { |
|
169 | - // Enable test mode if needed |
|
170 | - // 4007000000027 <-- test successful visa |
|
171 | - // 4222222222222 <-- test failure card number |
|
172 | - |
|
173 | - $item_num = 1; |
|
174 | - $transaction = $payment->transaction(); |
|
175 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
176 | - $order_description = $this->prepareStringForAuthnet($gateway_formatter->formatOrderDescription($payment)); |
|
177 | - $primary_registrant = $transaction->primary_registration(); |
|
178 | - // if we're are charging for the full amount, show the normal line items |
|
179 | - // and the itemized total adds up properly |
|
180 | - if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
181 | - $total_line_item = $transaction->total_line_item(); |
|
182 | - foreach ($total_line_item->get_items() as $line_item) { |
|
183 | - if ($line_item->quantity() == 0) { |
|
184 | - continue; |
|
185 | - } |
|
186 | - $this->addLineItem( |
|
187 | - $item_num++, |
|
188 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
189 | - $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
190 | - $line_item->quantity(), |
|
191 | - $line_item->unit_price(), |
|
192 | - 'N' |
|
193 | - ); |
|
194 | - $order_description .= $this->prepareStringForAuthnet($line_item->desc()) . ', '; |
|
195 | - } |
|
196 | - foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
197 | - $this->addLineItem( |
|
198 | - $item_num++, |
|
199 | - $tax_line_item->name(), |
|
200 | - $tax_line_item->desc(), |
|
201 | - 1, |
|
202 | - $tax_line_item->total(), |
|
203 | - 'N' |
|
204 | - ); |
|
205 | - } |
|
206 | - } |
|
207 | - |
|
208 | - // start transaction |
|
209 | - // if in debug mode, use authorize.net's sandbox id; otherwise use the Event Espresso partner id |
|
210 | - $partner_id = $this->_debug_mode ? 'AAA100302' : 'AAA105363'; |
|
211 | - $this->setField('solution_id', $partner_id); |
|
212 | - $this->setField('amount', $gateway_formatter->formatCurrency($payment->amount())); |
|
213 | - $this->setField('description', substr(rtrim($order_description, ', '), 0, 255)); |
|
214 | - $this->_set_sensitive_billing_data($billing_info); |
|
215 | - $this->setField('first_name', $billing_info['first_name']); |
|
216 | - $this->setField('last_name', $billing_info['last_name']); |
|
217 | - $this->setField('email', $billing_info['email']); |
|
218 | - $this->setField('company', $billing_info['company']); |
|
219 | - $this->setField('address', $billing_info['address'].' '.$billing_info['address2']); |
|
220 | - $this->setField('city', $billing_info['city']); |
|
221 | - $this->setField('state', $billing_info['state']); |
|
222 | - $this->setField('country', $billing_info['country']); |
|
223 | - $this->setField('zip', $billing_info['zip']); |
|
224 | - $this->setField('fax', $billing_info['fax']); |
|
225 | - $this->setField('cust_id', $primary_registrant->ID()); |
|
226 | - $this->setField('phone', $billing_info['phone']); |
|
227 | - $currency_config = LoaderFactory::getLoader()->load('EE_Currency_Config'); |
|
228 | - $this->setField('currency_code', $currency_config->code); |
|
229 | - // invoice_num would be nice to have it be unique per SPCO page-load, that way if users |
|
230 | - // press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page |
|
231 | - // in which case, we need to generate teh invoice num per request right here... |
|
232 | - $this->setField('invoice_num', wp_generate_password(12, false));// $billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
233 | - // tell AIM that any duplicates sent in the next 5 minutes are to be ignored |
|
234 | - $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS); |
|
235 | - |
|
236 | - if ($this->_test_transactions) { |
|
237 | - $this->test_request = "true"; |
|
238 | - } |
|
239 | - |
|
240 | - // Capture response |
|
241 | - $this->type = "AUTH_CAPTURE"; |
|
242 | - $response = $this->_sendRequest($payment); |
|
243 | - if (! empty($response)) { |
|
244 | - if ($response->error_message) { |
|
245 | - $payment->set_status($this->_pay_model->failed_status()); |
|
246 | - $payment->set_gateway_response($response->error_message); |
|
247 | - } else { |
|
248 | - $payment_status = $response->approved |
|
249 | - ? $this->_pay_model->approved_status() |
|
250 | - : $this->_pay_model->declined_status(); |
|
251 | - $payment->set_status($payment_status); |
|
252 | - // make sure we interpret the AMT as a float, not an international string (where periods are thousand separators) |
|
253 | - $payment->set_amount((float) $response->amount); |
|
254 | - $payment->set_gateway_response( |
|
255 | - sprintf( |
|
256 | - esc_html__('%1$s (Reason Code: %2$s)', 'event_espresso'), |
|
257 | - $response->response_reason_text, |
|
258 | - $response->response_reason_code |
|
259 | - ) |
|
260 | - ); |
|
261 | - if ($this->_debug_mode) { |
|
262 | - $txn_id = $response->invoice_number; |
|
263 | - } else { |
|
264 | - $txn_id = $response->transaction_id; |
|
265 | - } |
|
266 | - $payment->set_txn_id_chq_nmbr($txn_id); |
|
267 | - } |
|
268 | - $payment->set_extra_accntng($primary_registrant->reg_code()); |
|
269 | - $payment->set_details(print_r($response, true)); |
|
270 | - } else { |
|
271 | - $payment->set_status($this->_pay_model->failed_status()); |
|
272 | - $payment->set_gateway_response(__("There was no response from Authorize.net", 'event_espresso')); |
|
273 | - $payment->set_details(print_r($response, true)); |
|
274 | - } |
|
275 | - return $payment; |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * Sets billing data for the upcoming request to AIM that is considered sensitive; |
|
281 | - * also this method can be overridden by children classes to easily change |
|
282 | - * what billing data gets sent |
|
283 | - * |
|
284 | - * @param array $billing_info |
|
285 | - */ |
|
286 | - protected function _set_sensitive_billing_data($billing_info) |
|
287 | - { |
|
288 | - $this->setField('card_num', $billing_info['credit_card']); |
|
289 | - $this->setField('exp_date', $billing_info['exp_month'] . $billing_info['exp_year']); |
|
290 | - $this->setField('card_code', $billing_info['cvv']); |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * Add a line item. |
|
296 | - * |
|
297 | - * @param string $item_id |
|
298 | - * @param string $item_name |
|
299 | - * @param string $item_description |
|
300 | - * @param string $item_quantity |
|
301 | - * @param string $item_unit_price |
|
302 | - * @param string $item_taxable |
|
303 | - */ |
|
304 | - public function addLineItem($item_id, $item_name, $item_description, $item_quantity, $item_unit_price, $item_taxable) |
|
305 | - { |
|
306 | - $args = array( |
|
307 | - substr($item_id, 0, 31), |
|
308 | - substr($this->prepareStringForAuthnet($item_name), 0, 31), |
|
309 | - substr($this->prepareStringForAuthnet($item_description), 0, 255), |
|
310 | - number_format(abs($item_quantity), 2, '.', ''), |
|
311 | - number_format(abs($item_unit_price), 2, '.', ''), |
|
312 | - $item_taxable === 'N' ? 'N' : 'Y' |
|
313 | - ); |
|
314 | - $this->_additional_line_items[] = implode('<|>', $args); |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * Set an individual name/value pair. This will append x_ to the name |
|
320 | - * before posting. |
|
321 | - * |
|
322 | - * @param string $name |
|
323 | - * @param string $value |
|
324 | - * @throws AuthorizeNetException |
|
325 | - */ |
|
326 | - protected function setField($name, $value) |
|
327 | - { |
|
328 | - if (in_array($name, $this->_all_aim_fields)) { |
|
329 | - $this->_x_post_fields[ $name ] = $value; |
|
330 | - } else { |
|
331 | - throw new AuthorizeNetException("Error: no field $name exists in the AIM API. |
|
29 | + const LIVE_URL = 'https://secure2.authorize.net/gateway/transact.dll'; // Authnet URL |
|
30 | + |
|
31 | + const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll'; |
|
32 | + |
|
33 | + protected $_login_id; |
|
34 | + |
|
35 | + protected $_transaction_key; |
|
36 | + |
|
37 | + protected $_currencies_supported = array( |
|
38 | + 'AUD', |
|
39 | + 'USD', |
|
40 | + 'CAD', |
|
41 | + 'EUR', |
|
42 | + 'GBP', |
|
43 | + 'NZD', |
|
44 | + ); |
|
45 | + |
|
46 | + /** |
|
47 | + * Whether to send test transactions (even to live site) |
|
48 | + * |
|
49 | + * @var boolean |
|
50 | + */ |
|
51 | + protected $_test_transactions; |
|
52 | + |
|
53 | + private $VERIFY_PEER = false; |
|
54 | + |
|
55 | + private $_x_post_fields = array( |
|
56 | + "version" => "3.1", |
|
57 | + "delim_char" => ",", |
|
58 | + "delim_data" => "TRUE", |
|
59 | + "relay_response" => "FALSE", |
|
60 | + "encap_char" => "|", |
|
61 | + ); |
|
62 | + |
|
63 | + private $_additional_line_items = array(); |
|
64 | + |
|
65 | + /** |
|
66 | + * A list of all fields in the AIM API. |
|
67 | + * Used to warn user if they try to set a field not offered in the API. |
|
68 | + */ |
|
69 | + private $_all_aim_fields = array( |
|
70 | + "address", |
|
71 | + "allow_partial_auth", |
|
72 | + "amount", |
|
73 | + "auth_code", |
|
74 | + "authentication_indicator", |
|
75 | + "bank_aba_code", |
|
76 | + "bank_acct_name", |
|
77 | + "bank_acct_num", |
|
78 | + "bank_acct_type", |
|
79 | + "bank_check_number", |
|
80 | + "bank_name", |
|
81 | + "card_code", |
|
82 | + "card_num", |
|
83 | + "cardholder_authentication_value", |
|
84 | + "city", |
|
85 | + "company", |
|
86 | + "country", |
|
87 | + "cust_id", |
|
88 | + "customer_ip", |
|
89 | + "delim_char", |
|
90 | + "delim_data", |
|
91 | + "description", |
|
92 | + "duplicate_window", |
|
93 | + "duty", |
|
94 | + "echeck_type", |
|
95 | + "email", |
|
96 | + "email_customer", |
|
97 | + "encap_char", |
|
98 | + "exp_date", |
|
99 | + "fax", |
|
100 | + "first_name", |
|
101 | + "footer_email_receipt", |
|
102 | + "freight", |
|
103 | + "header_email_receipt", |
|
104 | + "invoice_num", |
|
105 | + "last_name", |
|
106 | + "line_item", |
|
107 | + "login", |
|
108 | + "method", |
|
109 | + "phone", |
|
110 | + "po_num", |
|
111 | + "recurring_billing", |
|
112 | + "relay_response", |
|
113 | + "ship_to_address", |
|
114 | + "ship_to_city", |
|
115 | + "ship_to_company", |
|
116 | + "ship_to_country", |
|
117 | + "ship_to_first_name", |
|
118 | + "ship_to_last_name", |
|
119 | + "ship_to_state", |
|
120 | + "ship_to_zip", |
|
121 | + "split_tender_id", |
|
122 | + "state", |
|
123 | + "tax", |
|
124 | + "tax_exempt", |
|
125 | + "test_request", |
|
126 | + "tran_key", |
|
127 | + "trans_id", |
|
128 | + "type", |
|
129 | + "version", |
|
130 | + "zip", |
|
131 | + "solution_id", |
|
132 | + "currency_code" |
|
133 | + ); |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * Gets the URL where the request should go. This is filterable |
|
138 | + * |
|
139 | + * @return string |
|
140 | + */ |
|
141 | + protected function _get_server_url() |
|
142 | + { |
|
143 | + return apply_filters( |
|
144 | + 'FHEE__EEG_Aim___get_server_url', |
|
145 | + $this->_debug_mode ? self::SANDBOX_URL : self::LIVE_URL, |
|
146 | + $this |
|
147 | + ); |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * Asks the gateway to do whatever it does to process the payment. Onsite gateways will |
|
153 | + * usually send a request directly to the payment provider and update the payment's status based on that; |
|
154 | + * whereas offsite gateways will usually just update the payment with the URL and query parameters to use |
|
155 | + * for sending the request via http_remote_request() |
|
156 | + * |
|
157 | + * @param EEI_Payment $payment |
|
158 | + * @param array $billing_info { |
|
159 | + * @type $credit_card string |
|
160 | + * @type $cvv string |
|
161 | + * @type $exp_month string |
|
162 | + * @type $exp_year string |
|
163 | + * @see parent::do_direct_payment |
|
164 | + * } |
|
165 | + * @return EEI_Payment updated |
|
166 | + */ |
|
167 | + public function do_direct_payment($payment, $billing_info = null) |
|
168 | + { |
|
169 | + // Enable test mode if needed |
|
170 | + // 4007000000027 <-- test successful visa |
|
171 | + // 4222222222222 <-- test failure card number |
|
172 | + |
|
173 | + $item_num = 1; |
|
174 | + $transaction = $payment->transaction(); |
|
175 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
176 | + $order_description = $this->prepareStringForAuthnet($gateway_formatter->formatOrderDescription($payment)); |
|
177 | + $primary_registrant = $transaction->primary_registration(); |
|
178 | + // if we're are charging for the full amount, show the normal line items |
|
179 | + // and the itemized total adds up properly |
|
180 | + if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
181 | + $total_line_item = $transaction->total_line_item(); |
|
182 | + foreach ($total_line_item->get_items() as $line_item) { |
|
183 | + if ($line_item->quantity() == 0) { |
|
184 | + continue; |
|
185 | + } |
|
186 | + $this->addLineItem( |
|
187 | + $item_num++, |
|
188 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
189 | + $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
190 | + $line_item->quantity(), |
|
191 | + $line_item->unit_price(), |
|
192 | + 'N' |
|
193 | + ); |
|
194 | + $order_description .= $this->prepareStringForAuthnet($line_item->desc()) . ', '; |
|
195 | + } |
|
196 | + foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
197 | + $this->addLineItem( |
|
198 | + $item_num++, |
|
199 | + $tax_line_item->name(), |
|
200 | + $tax_line_item->desc(), |
|
201 | + 1, |
|
202 | + $tax_line_item->total(), |
|
203 | + 'N' |
|
204 | + ); |
|
205 | + } |
|
206 | + } |
|
207 | + |
|
208 | + // start transaction |
|
209 | + // if in debug mode, use authorize.net's sandbox id; otherwise use the Event Espresso partner id |
|
210 | + $partner_id = $this->_debug_mode ? 'AAA100302' : 'AAA105363'; |
|
211 | + $this->setField('solution_id', $partner_id); |
|
212 | + $this->setField('amount', $gateway_formatter->formatCurrency($payment->amount())); |
|
213 | + $this->setField('description', substr(rtrim($order_description, ', '), 0, 255)); |
|
214 | + $this->_set_sensitive_billing_data($billing_info); |
|
215 | + $this->setField('first_name', $billing_info['first_name']); |
|
216 | + $this->setField('last_name', $billing_info['last_name']); |
|
217 | + $this->setField('email', $billing_info['email']); |
|
218 | + $this->setField('company', $billing_info['company']); |
|
219 | + $this->setField('address', $billing_info['address'].' '.$billing_info['address2']); |
|
220 | + $this->setField('city', $billing_info['city']); |
|
221 | + $this->setField('state', $billing_info['state']); |
|
222 | + $this->setField('country', $billing_info['country']); |
|
223 | + $this->setField('zip', $billing_info['zip']); |
|
224 | + $this->setField('fax', $billing_info['fax']); |
|
225 | + $this->setField('cust_id', $primary_registrant->ID()); |
|
226 | + $this->setField('phone', $billing_info['phone']); |
|
227 | + $currency_config = LoaderFactory::getLoader()->load('EE_Currency_Config'); |
|
228 | + $this->setField('currency_code', $currency_config->code); |
|
229 | + // invoice_num would be nice to have it be unique per SPCO page-load, that way if users |
|
230 | + // press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page |
|
231 | + // in which case, we need to generate teh invoice num per request right here... |
|
232 | + $this->setField('invoice_num', wp_generate_password(12, false));// $billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
233 | + // tell AIM that any duplicates sent in the next 5 minutes are to be ignored |
|
234 | + $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS); |
|
235 | + |
|
236 | + if ($this->_test_transactions) { |
|
237 | + $this->test_request = "true"; |
|
238 | + } |
|
239 | + |
|
240 | + // Capture response |
|
241 | + $this->type = "AUTH_CAPTURE"; |
|
242 | + $response = $this->_sendRequest($payment); |
|
243 | + if (! empty($response)) { |
|
244 | + if ($response->error_message) { |
|
245 | + $payment->set_status($this->_pay_model->failed_status()); |
|
246 | + $payment->set_gateway_response($response->error_message); |
|
247 | + } else { |
|
248 | + $payment_status = $response->approved |
|
249 | + ? $this->_pay_model->approved_status() |
|
250 | + : $this->_pay_model->declined_status(); |
|
251 | + $payment->set_status($payment_status); |
|
252 | + // make sure we interpret the AMT as a float, not an international string (where periods are thousand separators) |
|
253 | + $payment->set_amount((float) $response->amount); |
|
254 | + $payment->set_gateway_response( |
|
255 | + sprintf( |
|
256 | + esc_html__('%1$s (Reason Code: %2$s)', 'event_espresso'), |
|
257 | + $response->response_reason_text, |
|
258 | + $response->response_reason_code |
|
259 | + ) |
|
260 | + ); |
|
261 | + if ($this->_debug_mode) { |
|
262 | + $txn_id = $response->invoice_number; |
|
263 | + } else { |
|
264 | + $txn_id = $response->transaction_id; |
|
265 | + } |
|
266 | + $payment->set_txn_id_chq_nmbr($txn_id); |
|
267 | + } |
|
268 | + $payment->set_extra_accntng($primary_registrant->reg_code()); |
|
269 | + $payment->set_details(print_r($response, true)); |
|
270 | + } else { |
|
271 | + $payment->set_status($this->_pay_model->failed_status()); |
|
272 | + $payment->set_gateway_response(__("There was no response from Authorize.net", 'event_espresso')); |
|
273 | + $payment->set_details(print_r($response, true)); |
|
274 | + } |
|
275 | + return $payment; |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * Sets billing data for the upcoming request to AIM that is considered sensitive; |
|
281 | + * also this method can be overridden by children classes to easily change |
|
282 | + * what billing data gets sent |
|
283 | + * |
|
284 | + * @param array $billing_info |
|
285 | + */ |
|
286 | + protected function _set_sensitive_billing_data($billing_info) |
|
287 | + { |
|
288 | + $this->setField('card_num', $billing_info['credit_card']); |
|
289 | + $this->setField('exp_date', $billing_info['exp_month'] . $billing_info['exp_year']); |
|
290 | + $this->setField('card_code', $billing_info['cvv']); |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * Add a line item. |
|
296 | + * |
|
297 | + * @param string $item_id |
|
298 | + * @param string $item_name |
|
299 | + * @param string $item_description |
|
300 | + * @param string $item_quantity |
|
301 | + * @param string $item_unit_price |
|
302 | + * @param string $item_taxable |
|
303 | + */ |
|
304 | + public function addLineItem($item_id, $item_name, $item_description, $item_quantity, $item_unit_price, $item_taxable) |
|
305 | + { |
|
306 | + $args = array( |
|
307 | + substr($item_id, 0, 31), |
|
308 | + substr($this->prepareStringForAuthnet($item_name), 0, 31), |
|
309 | + substr($this->prepareStringForAuthnet($item_description), 0, 255), |
|
310 | + number_format(abs($item_quantity), 2, '.', ''), |
|
311 | + number_format(abs($item_unit_price), 2, '.', ''), |
|
312 | + $item_taxable === 'N' ? 'N' : 'Y' |
|
313 | + ); |
|
314 | + $this->_additional_line_items[] = implode('<|>', $args); |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * Set an individual name/value pair. This will append x_ to the name |
|
320 | + * before posting. |
|
321 | + * |
|
322 | + * @param string $name |
|
323 | + * @param string $value |
|
324 | + * @throws AuthorizeNetException |
|
325 | + */ |
|
326 | + protected function setField($name, $value) |
|
327 | + { |
|
328 | + if (in_array($name, $this->_all_aim_fields)) { |
|
329 | + $this->_x_post_fields[ $name ] = $value; |
|
330 | + } else { |
|
331 | + throw new AuthorizeNetException("Error: no field $name exists in the AIM API. |
|
332 | 332 | To set a custom field use setCustomField('field','value') instead."); |
333 | - } |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * Posts the request to AuthorizeNet & returns response. |
|
339 | - * |
|
340 | - * @param $payment |
|
341 | - * @return \EE_AuthorizeNetAIM_Response |
|
342 | - */ |
|
343 | - private function _sendRequest($payment) |
|
344 | - { |
|
345 | - $this->_x_post_fields['login'] = $this->_login_id; |
|
346 | - $this->_x_post_fields['tran_key'] = $this->_transaction_key; |
|
347 | - $x_keys = array(); |
|
348 | - foreach ($this->_x_post_fields as $key => $value) { |
|
349 | - $x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
350 | - } |
|
351 | - // Add line items |
|
352 | - foreach ($this->_additional_line_items as $key => $value) { |
|
353 | - $x_keys[] = "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
354 | - } |
|
355 | - $this->_log_clean_request($x_keys, $payment); |
|
356 | - $post_url = $this->_get_server_url(); |
|
357 | - $curl_request = curl_init($post_url); |
|
358 | - $post_body = implode("&", $x_keys); |
|
359 | - curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_body); |
|
360 | - curl_setopt($curl_request, CURLOPT_HEADER, 0); |
|
361 | - curl_setopt($curl_request, CURLOPT_TIMEOUT, 45); |
|
362 | - curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); |
|
363 | - curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2); |
|
364 | - if ($this->VERIFY_PEER) { |
|
365 | - curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__) . '/ssl/cert.pem'); |
|
366 | - } else { |
|
367 | - curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); |
|
368 | - } |
|
369 | - |
|
370 | - if (preg_match('/xml/', $post_url)) { |
|
371 | - curl_setopt($curl_request, CURLOPT_HTTPHEADER, array("Content-Type: text/xml")); |
|
372 | - } |
|
373 | - |
|
374 | - $response = curl_exec($curl_request); |
|
375 | - |
|
376 | - curl_close($curl_request); |
|
377 | - $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
378 | - |
|
379 | - return $this->_log_and_clean_response($response_obj, $payment); |
|
380 | - } |
|
381 | - |
|
382 | - |
|
383 | - /** |
|
384 | - * Logs the clean data only |
|
385 | - * |
|
386 | - * @param array $request_array |
|
387 | - * @param EEI_Payment $payment |
|
388 | - */ |
|
389 | - protected function _log_clean_request($request_array, $payment) |
|
390 | - { |
|
391 | - $keys_to_filter_out = array('x_card_num', 'x_card_code', 'x_exp_date'); |
|
392 | - foreach ($request_array as $index => $keyvaltogether) { |
|
393 | - foreach ($keys_to_filter_out as $key) { |
|
394 | - if (strpos($keyvaltogether, $key) === 0) { |
|
395 | - // found it at the first character |
|
396 | - // so its one of them |
|
397 | - unset($request_array[ $index ]); |
|
398 | - } |
|
399 | - } |
|
400 | - } |
|
401 | - $this->log( |
|
402 | - array( |
|
403 | - 'AIM Request sent:' => $request_array, |
|
404 | - 'Server URL' => $this->_get_server_url() |
|
405 | - ), |
|
406 | - $payment |
|
407 | - ); |
|
408 | - } |
|
409 | - |
|
410 | - |
|
411 | - |
|
412 | - /** |
|
413 | - * Logs the response and cleans it |
|
414 | - * |
|
415 | - * @param EE_AuthorizeNetAIM_Response $response_obj |
|
416 | - * @param EE_Payment $payment |
|
417 | - * @return \EE_AuthorizeNetAIM_Response |
|
418 | - */ |
|
419 | - private function _log_and_clean_response($response_obj, $payment) |
|
420 | - { |
|
421 | - $response_obj->account_number = ''; |
|
422 | - $this->log(array('AIM Response received:' => (array) $response_obj), $payment); |
|
423 | - return $response_obj; |
|
424 | - } |
|
425 | - |
|
426 | - /** |
|
427 | - * Removes characters Authorize.net doesn't handle well. |
|
428 | - * @since 4.9.82.p |
|
429 | - * @param $text |
|
430 | - * @return string |
|
431 | - */ |
|
432 | - private function prepareStringForAuthnet($text) |
|
433 | - { |
|
434 | - return str_replace( |
|
435 | - '\'', |
|
436 | - '', |
|
437 | - $text |
|
438 | - ); |
|
439 | - } |
|
333 | + } |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * Posts the request to AuthorizeNet & returns response. |
|
339 | + * |
|
340 | + * @param $payment |
|
341 | + * @return \EE_AuthorizeNetAIM_Response |
|
342 | + */ |
|
343 | + private function _sendRequest($payment) |
|
344 | + { |
|
345 | + $this->_x_post_fields['login'] = $this->_login_id; |
|
346 | + $this->_x_post_fields['tran_key'] = $this->_transaction_key; |
|
347 | + $x_keys = array(); |
|
348 | + foreach ($this->_x_post_fields as $key => $value) { |
|
349 | + $x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
350 | + } |
|
351 | + // Add line items |
|
352 | + foreach ($this->_additional_line_items as $key => $value) { |
|
353 | + $x_keys[] = "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
354 | + } |
|
355 | + $this->_log_clean_request($x_keys, $payment); |
|
356 | + $post_url = $this->_get_server_url(); |
|
357 | + $curl_request = curl_init($post_url); |
|
358 | + $post_body = implode("&", $x_keys); |
|
359 | + curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_body); |
|
360 | + curl_setopt($curl_request, CURLOPT_HEADER, 0); |
|
361 | + curl_setopt($curl_request, CURLOPT_TIMEOUT, 45); |
|
362 | + curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); |
|
363 | + curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2); |
|
364 | + if ($this->VERIFY_PEER) { |
|
365 | + curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__) . '/ssl/cert.pem'); |
|
366 | + } else { |
|
367 | + curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); |
|
368 | + } |
|
369 | + |
|
370 | + if (preg_match('/xml/', $post_url)) { |
|
371 | + curl_setopt($curl_request, CURLOPT_HTTPHEADER, array("Content-Type: text/xml")); |
|
372 | + } |
|
373 | + |
|
374 | + $response = curl_exec($curl_request); |
|
375 | + |
|
376 | + curl_close($curl_request); |
|
377 | + $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
378 | + |
|
379 | + return $this->_log_and_clean_response($response_obj, $payment); |
|
380 | + } |
|
381 | + |
|
382 | + |
|
383 | + /** |
|
384 | + * Logs the clean data only |
|
385 | + * |
|
386 | + * @param array $request_array |
|
387 | + * @param EEI_Payment $payment |
|
388 | + */ |
|
389 | + protected function _log_clean_request($request_array, $payment) |
|
390 | + { |
|
391 | + $keys_to_filter_out = array('x_card_num', 'x_card_code', 'x_exp_date'); |
|
392 | + foreach ($request_array as $index => $keyvaltogether) { |
|
393 | + foreach ($keys_to_filter_out as $key) { |
|
394 | + if (strpos($keyvaltogether, $key) === 0) { |
|
395 | + // found it at the first character |
|
396 | + // so its one of them |
|
397 | + unset($request_array[ $index ]); |
|
398 | + } |
|
399 | + } |
|
400 | + } |
|
401 | + $this->log( |
|
402 | + array( |
|
403 | + 'AIM Request sent:' => $request_array, |
|
404 | + 'Server URL' => $this->_get_server_url() |
|
405 | + ), |
|
406 | + $payment |
|
407 | + ); |
|
408 | + } |
|
409 | + |
|
410 | + |
|
411 | + |
|
412 | + /** |
|
413 | + * Logs the response and cleans it |
|
414 | + * |
|
415 | + * @param EE_AuthorizeNetAIM_Response $response_obj |
|
416 | + * @param EE_Payment $payment |
|
417 | + * @return \EE_AuthorizeNetAIM_Response |
|
418 | + */ |
|
419 | + private function _log_and_clean_response($response_obj, $payment) |
|
420 | + { |
|
421 | + $response_obj->account_number = ''; |
|
422 | + $this->log(array('AIM Response received:' => (array) $response_obj), $payment); |
|
423 | + return $response_obj; |
|
424 | + } |
|
425 | + |
|
426 | + /** |
|
427 | + * Removes characters Authorize.net doesn't handle well. |
|
428 | + * @since 4.9.82.p |
|
429 | + * @param $text |
|
430 | + * @return string |
|
431 | + */ |
|
432 | + private function prepareStringForAuthnet($text) |
|
433 | + { |
|
434 | + return str_replace( |
|
435 | + '\'', |
|
436 | + '', |
|
437 | + $text |
|
438 | + ); |
|
439 | + } |
|
440 | 440 | } |
441 | 441 | |
442 | 442 | |
@@ -452,192 +452,192 @@ discard block |
||
452 | 452 | class EE_AuthorizeNetAIM_Response |
453 | 453 | { |
454 | 454 | |
455 | - const APPROVED = '1'; |
|
456 | - const DECLINED = '2'; |
|
457 | - const ERROR = '3'; |
|
458 | - const HELD = '4'; |
|
459 | - |
|
460 | - protected $_x_post_fields = array( |
|
461 | - "version" => "3.1", |
|
462 | - "delim_char" => ",", |
|
463 | - "delim_data" => "TRUE", |
|
464 | - "relay_response" => "FALSE", |
|
465 | - "encap_char" => "|", |
|
466 | - ); |
|
467 | - public $approved; |
|
468 | - public $declined; |
|
469 | - public $error; |
|
470 | - public $held; |
|
471 | - public $response_code; |
|
472 | - public $response_subcode; |
|
473 | - public $response_reason_code; |
|
474 | - public $response_reason_text; |
|
475 | - public $authorization_code; |
|
476 | - public $avs_response; |
|
477 | - public $transaction_id; |
|
478 | - public $invoice_number; |
|
479 | - public $description; |
|
480 | - public $amount; |
|
481 | - public $method; |
|
482 | - public $transaction_type; |
|
483 | - public $customer_id; |
|
484 | - public $first_name; |
|
485 | - public $last_name; |
|
486 | - public $company; |
|
487 | - public $address; |
|
488 | - public $city; |
|
489 | - public $state; |
|
490 | - public $zip_code; |
|
491 | - public $country; |
|
492 | - public $phone; |
|
493 | - public $fax; |
|
494 | - public $email_address; |
|
495 | - public $ship_to_first_name; |
|
496 | - public $ship_to_last_name; |
|
497 | - public $ship_to_company; |
|
498 | - public $ship_to_address; |
|
499 | - public $ship_to_city; |
|
500 | - public $ship_to_state; |
|
501 | - public $ship_to_zip_code; |
|
502 | - public $ship_to_country; |
|
503 | - public $tax; |
|
504 | - public $duty; |
|
505 | - public $freight; |
|
506 | - public $tax_exempt; |
|
507 | - public $purchase_order_number; |
|
508 | - public $md5_hash; |
|
509 | - public $card_code_response; |
|
510 | - public $cavv_response; // cardholder_authentication_verification_response |
|
511 | - public $account_number; |
|
512 | - public $card_type; |
|
513 | - public $split_tender_id; |
|
514 | - public $requested_amount; |
|
515 | - public $balance_on_card; |
|
516 | - public $response; // The response string from AuthorizeNet. |
|
517 | - public $error_message; |
|
518 | - private $_response_array = array(); // An array with the split response. |
|
519 | - |
|
520 | - |
|
521 | - /** |
|
522 | - * Constructor. Parses the AuthorizeNet response string |
|
523 | - * |
|
524 | - * @param string $response The response from the AuthNet server. |
|
525 | - * @var string $delimiter The delimiter used (default is ",") |
|
526 | - * @var string $encap_char The encap_char used (default is "|") |
|
527 | - * @var array $custom_fields Any custom fields set in the request. |
|
528 | - */ |
|
529 | - |
|
530 | - public function __construct($response) |
|
531 | - { |
|
532 | - $encap_char = $this->_x_post_fields['encap_char']; |
|
533 | - $delimiter = $this->_x_post_fields['delim_char']; |
|
534 | - if ($response) { |
|
535 | - // Split Array |
|
536 | - $this->response = $response; |
|
537 | - if ($encap_char) { |
|
538 | - $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
539 | - } else { |
|
540 | - $this->_response_array = explode($delimiter, $response); |
|
541 | - } |
|
542 | - |
|
543 | - /** |
|
544 | - * If AuthorizeNet doesn't return a delimited response. |
|
545 | - */ |
|
546 | - if (count($this->_response_array) < 10) { |
|
547 | - $this->approved = false; |
|
548 | - $this->error = true; |
|
549 | - $this->error_message = sprintf( |
|
550 | - esc_html__('Unrecognized response from Authorize.net: %1$s', 'event_espresso'), |
|
551 | - esc_html($response) |
|
552 | - ); |
|
553 | - return; |
|
554 | - } |
|
555 | - |
|
556 | - |
|
557 | - |
|
558 | - // Set all fields |
|
559 | - $this->response_code = $this->_response_array[0]; |
|
560 | - $this->response_subcode = $this->_response_array[1]; |
|
561 | - $this->response_reason_code = $this->_response_array[2]; |
|
562 | - $this->response_reason_text = $this->_response_array[3]; |
|
563 | - $this->authorization_code = $this->_response_array[4]; |
|
564 | - $this->avs_response = $this->_response_array[5]; |
|
565 | - $this->transaction_id = $this->_response_array[6]; |
|
566 | - $this->invoice_number = $this->_response_array[7]; |
|
567 | - $this->description = $this->_response_array[8]; |
|
568 | - $this->amount = $this->_response_array[9]; |
|
569 | - $this->method = $this->_response_array[10]; |
|
570 | - $this->transaction_type = $this->_response_array[11]; |
|
571 | - $this->customer_id = $this->_response_array[12]; |
|
572 | - $this->first_name = $this->_response_array[13]; |
|
573 | - $this->last_name = $this->_response_array[14]; |
|
574 | - $this->company = $this->_response_array[15]; |
|
575 | - $this->address = $this->_response_array[16]; |
|
576 | - $this->city = $this->_response_array[17]; |
|
577 | - $this->state = $this->_response_array[18]; |
|
578 | - $this->zip_code = $this->_response_array[19]; |
|
579 | - $this->country = $this->_response_array[20]; |
|
580 | - $this->phone = $this->_response_array[21]; |
|
581 | - $this->fax = $this->_response_array[22]; |
|
582 | - $this->email_address = $this->_response_array[23]; |
|
583 | - $this->ship_to_first_name = $this->_response_array[24]; |
|
584 | - $this->ship_to_last_name = $this->_response_array[25]; |
|
585 | - $this->ship_to_company = $this->_response_array[26]; |
|
586 | - $this->ship_to_address = $this->_response_array[27]; |
|
587 | - $this->ship_to_city = $this->_response_array[28]; |
|
588 | - $this->ship_to_state = $this->_response_array[29]; |
|
589 | - $this->ship_to_zip_code = $this->_response_array[30]; |
|
590 | - $this->ship_to_country = $this->_response_array[31]; |
|
591 | - $this->tax = $this->_response_array[32]; |
|
592 | - $this->duty = $this->_response_array[33]; |
|
593 | - $this->freight = $this->_response_array[34]; |
|
594 | - $this->tax_exempt = $this->_response_array[35]; |
|
595 | - $this->purchase_order_number = $this->_response_array[36]; |
|
596 | - $this->md5_hash = $this->_response_array[37]; |
|
597 | - $this->card_code_response = $this->_response_array[38]; |
|
598 | - $this->cavv_response = $this->_response_array[39]; |
|
599 | - $this->account_number = $this->_response_array[50]; |
|
600 | - $this->card_type = $this->_response_array[51]; |
|
601 | - $this->split_tender_id = $this->_response_array[52]; |
|
602 | - $this->requested_amount = $this->_response_array[53]; |
|
603 | - $this->balance_on_card = $this->_response_array[54]; |
|
604 | - |
|
605 | - $this->approved = ($this->response_code === self::APPROVED); |
|
606 | - $this->declined = ($this->response_code === self::DECLINED); |
|
607 | - $this->error = ($this->response_code === self::ERROR); |
|
608 | - $this->held = ($this->response_code === self::HELD); |
|
609 | - } else { |
|
610 | - $this->approved = false; |
|
611 | - $this->error = true; |
|
612 | - $this->error_message = esc_html__( |
|
613 | - 'Error connecting to Authorize.net', |
|
614 | - 'event_espresso' |
|
615 | - ); |
|
616 | - } |
|
617 | - } |
|
455 | + const APPROVED = '1'; |
|
456 | + const DECLINED = '2'; |
|
457 | + const ERROR = '3'; |
|
458 | + const HELD = '4'; |
|
459 | + |
|
460 | + protected $_x_post_fields = array( |
|
461 | + "version" => "3.1", |
|
462 | + "delim_char" => ",", |
|
463 | + "delim_data" => "TRUE", |
|
464 | + "relay_response" => "FALSE", |
|
465 | + "encap_char" => "|", |
|
466 | + ); |
|
467 | + public $approved; |
|
468 | + public $declined; |
|
469 | + public $error; |
|
470 | + public $held; |
|
471 | + public $response_code; |
|
472 | + public $response_subcode; |
|
473 | + public $response_reason_code; |
|
474 | + public $response_reason_text; |
|
475 | + public $authorization_code; |
|
476 | + public $avs_response; |
|
477 | + public $transaction_id; |
|
478 | + public $invoice_number; |
|
479 | + public $description; |
|
480 | + public $amount; |
|
481 | + public $method; |
|
482 | + public $transaction_type; |
|
483 | + public $customer_id; |
|
484 | + public $first_name; |
|
485 | + public $last_name; |
|
486 | + public $company; |
|
487 | + public $address; |
|
488 | + public $city; |
|
489 | + public $state; |
|
490 | + public $zip_code; |
|
491 | + public $country; |
|
492 | + public $phone; |
|
493 | + public $fax; |
|
494 | + public $email_address; |
|
495 | + public $ship_to_first_name; |
|
496 | + public $ship_to_last_name; |
|
497 | + public $ship_to_company; |
|
498 | + public $ship_to_address; |
|
499 | + public $ship_to_city; |
|
500 | + public $ship_to_state; |
|
501 | + public $ship_to_zip_code; |
|
502 | + public $ship_to_country; |
|
503 | + public $tax; |
|
504 | + public $duty; |
|
505 | + public $freight; |
|
506 | + public $tax_exempt; |
|
507 | + public $purchase_order_number; |
|
508 | + public $md5_hash; |
|
509 | + public $card_code_response; |
|
510 | + public $cavv_response; // cardholder_authentication_verification_response |
|
511 | + public $account_number; |
|
512 | + public $card_type; |
|
513 | + public $split_tender_id; |
|
514 | + public $requested_amount; |
|
515 | + public $balance_on_card; |
|
516 | + public $response; // The response string from AuthorizeNet. |
|
517 | + public $error_message; |
|
518 | + private $_response_array = array(); // An array with the split response. |
|
519 | + |
|
520 | + |
|
521 | + /** |
|
522 | + * Constructor. Parses the AuthorizeNet response string |
|
523 | + * |
|
524 | + * @param string $response The response from the AuthNet server. |
|
525 | + * @var string $delimiter The delimiter used (default is ",") |
|
526 | + * @var string $encap_char The encap_char used (default is "|") |
|
527 | + * @var array $custom_fields Any custom fields set in the request. |
|
528 | + */ |
|
529 | + |
|
530 | + public function __construct($response) |
|
531 | + { |
|
532 | + $encap_char = $this->_x_post_fields['encap_char']; |
|
533 | + $delimiter = $this->_x_post_fields['delim_char']; |
|
534 | + if ($response) { |
|
535 | + // Split Array |
|
536 | + $this->response = $response; |
|
537 | + if ($encap_char) { |
|
538 | + $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
539 | + } else { |
|
540 | + $this->_response_array = explode($delimiter, $response); |
|
541 | + } |
|
542 | + |
|
543 | + /** |
|
544 | + * If AuthorizeNet doesn't return a delimited response. |
|
545 | + */ |
|
546 | + if (count($this->_response_array) < 10) { |
|
547 | + $this->approved = false; |
|
548 | + $this->error = true; |
|
549 | + $this->error_message = sprintf( |
|
550 | + esc_html__('Unrecognized response from Authorize.net: %1$s', 'event_espresso'), |
|
551 | + esc_html($response) |
|
552 | + ); |
|
553 | + return; |
|
554 | + } |
|
555 | + |
|
556 | + |
|
557 | + |
|
558 | + // Set all fields |
|
559 | + $this->response_code = $this->_response_array[0]; |
|
560 | + $this->response_subcode = $this->_response_array[1]; |
|
561 | + $this->response_reason_code = $this->_response_array[2]; |
|
562 | + $this->response_reason_text = $this->_response_array[3]; |
|
563 | + $this->authorization_code = $this->_response_array[4]; |
|
564 | + $this->avs_response = $this->_response_array[5]; |
|
565 | + $this->transaction_id = $this->_response_array[6]; |
|
566 | + $this->invoice_number = $this->_response_array[7]; |
|
567 | + $this->description = $this->_response_array[8]; |
|
568 | + $this->amount = $this->_response_array[9]; |
|
569 | + $this->method = $this->_response_array[10]; |
|
570 | + $this->transaction_type = $this->_response_array[11]; |
|
571 | + $this->customer_id = $this->_response_array[12]; |
|
572 | + $this->first_name = $this->_response_array[13]; |
|
573 | + $this->last_name = $this->_response_array[14]; |
|
574 | + $this->company = $this->_response_array[15]; |
|
575 | + $this->address = $this->_response_array[16]; |
|
576 | + $this->city = $this->_response_array[17]; |
|
577 | + $this->state = $this->_response_array[18]; |
|
578 | + $this->zip_code = $this->_response_array[19]; |
|
579 | + $this->country = $this->_response_array[20]; |
|
580 | + $this->phone = $this->_response_array[21]; |
|
581 | + $this->fax = $this->_response_array[22]; |
|
582 | + $this->email_address = $this->_response_array[23]; |
|
583 | + $this->ship_to_first_name = $this->_response_array[24]; |
|
584 | + $this->ship_to_last_name = $this->_response_array[25]; |
|
585 | + $this->ship_to_company = $this->_response_array[26]; |
|
586 | + $this->ship_to_address = $this->_response_array[27]; |
|
587 | + $this->ship_to_city = $this->_response_array[28]; |
|
588 | + $this->ship_to_state = $this->_response_array[29]; |
|
589 | + $this->ship_to_zip_code = $this->_response_array[30]; |
|
590 | + $this->ship_to_country = $this->_response_array[31]; |
|
591 | + $this->tax = $this->_response_array[32]; |
|
592 | + $this->duty = $this->_response_array[33]; |
|
593 | + $this->freight = $this->_response_array[34]; |
|
594 | + $this->tax_exempt = $this->_response_array[35]; |
|
595 | + $this->purchase_order_number = $this->_response_array[36]; |
|
596 | + $this->md5_hash = $this->_response_array[37]; |
|
597 | + $this->card_code_response = $this->_response_array[38]; |
|
598 | + $this->cavv_response = $this->_response_array[39]; |
|
599 | + $this->account_number = $this->_response_array[50]; |
|
600 | + $this->card_type = $this->_response_array[51]; |
|
601 | + $this->split_tender_id = $this->_response_array[52]; |
|
602 | + $this->requested_amount = $this->_response_array[53]; |
|
603 | + $this->balance_on_card = $this->_response_array[54]; |
|
604 | + |
|
605 | + $this->approved = ($this->response_code === self::APPROVED); |
|
606 | + $this->declined = ($this->response_code === self::DECLINED); |
|
607 | + $this->error = ($this->response_code === self::ERROR); |
|
608 | + $this->held = ($this->response_code === self::HELD); |
|
609 | + } else { |
|
610 | + $this->approved = false; |
|
611 | + $this->error = true; |
|
612 | + $this->error_message = esc_html__( |
|
613 | + 'Error connecting to Authorize.net', |
|
614 | + 'event_espresso' |
|
615 | + ); |
|
616 | + } |
|
617 | + } |
|
618 | 618 | } |
619 | 619 | |
620 | 620 | if (! class_exists('AuthorizeNetException')) { |
621 | - /** |
|
622 | - * Class AuthorizeNetException |
|
623 | - * |
|
624 | - * @package AuthorizeNet |
|
625 | - */ |
|
626 | - class AuthorizeNetException extends Exception |
|
627 | - { |
|
628 | - |
|
629 | - /** |
|
630 | - * Construct the exception. Note: The message is NOT binary safe. |
|
631 | - * |
|
632 | - * @link http://php.net/manual/en/exception.construct.php |
|
633 | - * @param string $message [optional] The Exception message to throw. |
|
634 | - * @param int $code [optional] The Exception code. |
|
635 | - * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0 |
|
636 | - * @since 5.1.0 |
|
637 | - */ |
|
638 | - public function __construct($message = "", $code = 0, Exception $previous = null) |
|
639 | - { |
|
640 | - parent::__construct($message, $code, $previous); |
|
641 | - } |
|
642 | - } |
|
621 | + /** |
|
622 | + * Class AuthorizeNetException |
|
623 | + * |
|
624 | + * @package AuthorizeNet |
|
625 | + */ |
|
626 | + class AuthorizeNetException extends Exception |
|
627 | + { |
|
628 | + |
|
629 | + /** |
|
630 | + * Construct the exception. Note: The message is NOT binary safe. |
|
631 | + * |
|
632 | + * @link http://php.net/manual/en/exception.construct.php |
|
633 | + * @param string $message [optional] The Exception message to throw. |
|
634 | + * @param int $code [optional] The Exception code. |
|
635 | + * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0 |
|
636 | + * @since 5.1.0 |
|
637 | + */ |
|
638 | + public function __construct($message = "", $code = 0, Exception $previous = null) |
|
639 | + { |
|
640 | + parent::__construct($message, $code, $previous); |
|
641 | + } |
|
642 | + } |
|
643 | 643 | } |