@@ -57,7 +57,7 @@ |
||
57 | 57 | public function getCapCheck() |
58 | 58 | { |
59 | 59 | // need cap for non-AJAX admin requests |
60 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
60 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
61 | 61 | // there's no specific caps for editing/creating transactions, |
62 | 62 | // so that's why we are using ee_edit_registrations |
63 | 63 | return new CapCheck('ee_edit_registrations', 'create_new_transaction'); |
@@ -20,60 +20,60 @@ |
||
20 | 20 | class CreateTransactionCommand extends Command implements CommandRequiresCapCheckInterface |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var EE_Checkout $checkout |
|
25 | - */ |
|
26 | - protected $checkout; |
|
23 | + /** |
|
24 | + * @var EE_Checkout $checkout |
|
25 | + */ |
|
26 | + protected $checkout; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @var array $transaction_details |
|
30 | - */ |
|
31 | - protected $transaction_details; |
|
28 | + /** |
|
29 | + * @var array $transaction_details |
|
30 | + */ |
|
31 | + protected $transaction_details; |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * CreateTransactionCommand constructor. |
|
36 | - * |
|
37 | - * @param EE_Checkout $checkout |
|
38 | - * @param array $transaction_details |
|
39 | - */ |
|
40 | - public function __construct(EE_Checkout $checkout = null, array $transaction_details = array()) |
|
41 | - { |
|
42 | - $this->checkout = $checkout; |
|
43 | - $this->transaction_details = $transaction_details; |
|
44 | - } |
|
34 | + /** |
|
35 | + * CreateTransactionCommand constructor. |
|
36 | + * |
|
37 | + * @param EE_Checkout $checkout |
|
38 | + * @param array $transaction_details |
|
39 | + */ |
|
40 | + public function __construct(EE_Checkout $checkout = null, array $transaction_details = array()) |
|
41 | + { |
|
42 | + $this->checkout = $checkout; |
|
43 | + $this->transaction_details = $transaction_details; |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * @return CapCheckInterface |
|
49 | - * @throws InvalidDataTypeException |
|
50 | - */ |
|
51 | - public function getCapCheck() |
|
52 | - { |
|
53 | - // need cap for non-AJAX admin requests |
|
54 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
55 | - // there's no specific caps for editing/creating transactions, |
|
56 | - // so that's why we are using ee_edit_registrations |
|
57 | - return new CapCheck('ee_edit_registrations', 'create_new_transaction'); |
|
58 | - } |
|
59 | - return new PublicCapabilities('', 'create_new_transaction'); |
|
60 | - } |
|
47 | + /** |
|
48 | + * @return CapCheckInterface |
|
49 | + * @throws InvalidDataTypeException |
|
50 | + */ |
|
51 | + public function getCapCheck() |
|
52 | + { |
|
53 | + // need cap for non-AJAX admin requests |
|
54 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
55 | + // there's no specific caps for editing/creating transactions, |
|
56 | + // so that's why we are using ee_edit_registrations |
|
57 | + return new CapCheck('ee_edit_registrations', 'create_new_transaction'); |
|
58 | + } |
|
59 | + return new PublicCapabilities('', 'create_new_transaction'); |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | - /** |
|
64 | - * @return EE_Checkout |
|
65 | - */ |
|
66 | - public function checkout() |
|
67 | - { |
|
68 | - return $this->checkout; |
|
69 | - } |
|
63 | + /** |
|
64 | + * @return EE_Checkout |
|
65 | + */ |
|
66 | + public function checkout() |
|
67 | + { |
|
68 | + return $this->checkout; |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * @return array |
|
74 | - */ |
|
75 | - public function transactionDetails() |
|
76 | - { |
|
77 | - return $this->transaction_details; |
|
78 | - } |
|
72 | + /** |
|
73 | + * @return array |
|
74 | + */ |
|
75 | + public function transactionDetails() |
|
76 | + { |
|
77 | + return $this->transaction_details; |
|
78 | + } |
|
79 | 79 | } |
@@ -26,44 +26,44 @@ |
||
26 | 26 | { |
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * @param CommandInterface $command |
|
31 | - * @return mixed |
|
32 | - * @throws EE_Error |
|
33 | - * @throws InvalidEntityException |
|
34 | - */ |
|
35 | - public function handle(CommandInterface $command) |
|
36 | - { |
|
37 | - /** @var CreateTransactionCommand $command */ |
|
38 | - if (! $command instanceof CreateTransactionCommand) { |
|
39 | - throw new InvalidEntityException(get_class($command), 'CreateTransactionCommand'); |
|
40 | - } |
|
41 | - $transaction_details = $command->transactionDetails(); |
|
42 | - $cart_total = null; |
|
43 | - if ($command->checkout() instanceof EE_Checkout) { |
|
44 | - // ensure cart totals have been calculated |
|
45 | - $command->checkout()->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
46 | - // grab the cart grand total |
|
47 | - $cart_total = $command->checkout()->cart->get_cart_grand_total(); |
|
48 | - $transaction_details['TXN_reg_steps'] = $command->checkout()->initialize_txn_reg_steps_array(); |
|
49 | - $transaction_details['TXN_total'] = $cart_total > 0 ? $cart_total : 0; |
|
50 | - } |
|
51 | - // create new TXN and save it so it has an ID |
|
52 | - $transaction = EE_Transaction::new_instance($transaction_details); |
|
53 | - if (! $transaction instanceof EE_Transaction) { |
|
54 | - throw new InvalidEntityException(get_class($transaction), 'EE_Transaction'); |
|
55 | - } |
|
56 | - $transaction->save(); |
|
57 | - // ensure grand total line item created |
|
58 | - $cart_total = $cart_total instanceof EE_Line_Item |
|
59 | - ? $cart_total |
|
60 | - : EEH_Line_Item::create_total_line_item($transaction); |
|
61 | - if (! $cart_total instanceof EE_Line_Item) { |
|
62 | - throw new InvalidEntityException(get_class($cart_total), 'EE_Line_Item'); |
|
63 | - } |
|
64 | - $cart_total->save_this_and_descendants_to_txn($transaction->ID()); |
|
65 | - return $transaction; |
|
66 | - } |
|
29 | + /** |
|
30 | + * @param CommandInterface $command |
|
31 | + * @return mixed |
|
32 | + * @throws EE_Error |
|
33 | + * @throws InvalidEntityException |
|
34 | + */ |
|
35 | + public function handle(CommandInterface $command) |
|
36 | + { |
|
37 | + /** @var CreateTransactionCommand $command */ |
|
38 | + if (! $command instanceof CreateTransactionCommand) { |
|
39 | + throw new InvalidEntityException(get_class($command), 'CreateTransactionCommand'); |
|
40 | + } |
|
41 | + $transaction_details = $command->transactionDetails(); |
|
42 | + $cart_total = null; |
|
43 | + if ($command->checkout() instanceof EE_Checkout) { |
|
44 | + // ensure cart totals have been calculated |
|
45 | + $command->checkout()->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
46 | + // grab the cart grand total |
|
47 | + $cart_total = $command->checkout()->cart->get_cart_grand_total(); |
|
48 | + $transaction_details['TXN_reg_steps'] = $command->checkout()->initialize_txn_reg_steps_array(); |
|
49 | + $transaction_details['TXN_total'] = $cart_total > 0 ? $cart_total : 0; |
|
50 | + } |
|
51 | + // create new TXN and save it so it has an ID |
|
52 | + $transaction = EE_Transaction::new_instance($transaction_details); |
|
53 | + if (! $transaction instanceof EE_Transaction) { |
|
54 | + throw new InvalidEntityException(get_class($transaction), 'EE_Transaction'); |
|
55 | + } |
|
56 | + $transaction->save(); |
|
57 | + // ensure grand total line item created |
|
58 | + $cart_total = $cart_total instanceof EE_Line_Item |
|
59 | + ? $cart_total |
|
60 | + : EEH_Line_Item::create_total_line_item($transaction); |
|
61 | + if (! $cart_total instanceof EE_Line_Item) { |
|
62 | + throw new InvalidEntityException(get_class($cart_total), 'EE_Line_Item'); |
|
63 | + } |
|
64 | + $cart_total->save_this_and_descendants_to_txn($transaction->ID()); |
|
65 | + return $transaction; |
|
66 | + } |
|
67 | 67 | |
68 | 68 | |
69 | 69 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | public function handle(CommandInterface $command) |
36 | 36 | { |
37 | 37 | /** @var CreateTransactionCommand $command */ |
38 | - if (! $command instanceof CreateTransactionCommand) { |
|
38 | + if ( ! $command instanceof CreateTransactionCommand) { |
|
39 | 39 | throw new InvalidEntityException(get_class($command), 'CreateTransactionCommand'); |
40 | 40 | } |
41 | 41 | $transaction_details = $command->transactionDetails(); |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | } |
51 | 51 | // create new TXN and save it so it has an ID |
52 | 52 | $transaction = EE_Transaction::new_instance($transaction_details); |
53 | - if (! $transaction instanceof EE_Transaction) { |
|
53 | + if ( ! $transaction instanceof EE_Transaction) { |
|
54 | 54 | throw new InvalidEntityException(get_class($transaction), 'EE_Transaction'); |
55 | 55 | } |
56 | 56 | $transaction->save(); |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | $cart_total = $cart_total instanceof EE_Line_Item |
59 | 59 | ? $cart_total |
60 | 60 | : EEH_Line_Item::create_total_line_item($transaction); |
61 | - if (! $cart_total instanceof EE_Line_Item) { |
|
61 | + if ( ! $cart_total instanceof EE_Line_Item) { |
|
62 | 62 | throw new InvalidEntityException(get_class($cart_total), 'EE_Line_Item'); |
63 | 63 | } |
64 | 64 | $cart_total->save_this_and_descendants_to_txn($transaction->ID()); |
@@ -81,7 +81,7 @@ |
||
81 | 81 | public function getCapCheck() |
82 | 82 | { |
83 | 83 | // need cap for non-AJAX admin requests |
84 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
84 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
85 | 85 | return new CapCheck('ee_edit_contacts', 'create_new_contact'); |
86 | 86 | } |
87 | 87 | return new PublicCapabilities('', 'create_new_contact'); |
@@ -20,62 +20,62 @@ |
||
20 | 20 | class CreateAttendeeCommand extends Command implements CommandRequiresCapCheckInterface |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * array of details where keys are names of EEM_Attendee model fields |
|
25 | - * |
|
26 | - * @var array $attendee_details |
|
27 | - */ |
|
28 | - protected $attendee_details; |
|
23 | + /** |
|
24 | + * array of details where keys are names of EEM_Attendee model fields |
|
25 | + * |
|
26 | + * @var array $attendee_details |
|
27 | + */ |
|
28 | + protected $attendee_details; |
|
29 | 29 | |
30 | - /** |
|
31 | - * an existing registration to associate this attendee with |
|
32 | - * |
|
33 | - * @var EE_Registration $registration |
|
34 | - */ |
|
35 | - protected $registration; |
|
30 | + /** |
|
31 | + * an existing registration to associate this attendee with |
|
32 | + * |
|
33 | + * @var EE_Registration $registration |
|
34 | + */ |
|
35 | + protected $registration; |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * CreateAttendeeCommand constructor. |
|
40 | - * |
|
41 | - * @param array $attendee_details |
|
42 | - * @param EE_Registration $registration |
|
43 | - */ |
|
44 | - public function __construct(array $attendee_details, EE_Registration $registration) |
|
45 | - { |
|
46 | - $this->attendee_details = $attendee_details; |
|
47 | - $this->registration = $registration; |
|
48 | - } |
|
38 | + /** |
|
39 | + * CreateAttendeeCommand constructor. |
|
40 | + * |
|
41 | + * @param array $attendee_details |
|
42 | + * @param EE_Registration $registration |
|
43 | + */ |
|
44 | + public function __construct(array $attendee_details, EE_Registration $registration) |
|
45 | + { |
|
46 | + $this->attendee_details = $attendee_details; |
|
47 | + $this->registration = $registration; |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * @return array |
|
53 | - */ |
|
54 | - public function attendeeDetails() |
|
55 | - { |
|
56 | - return $this->attendee_details; |
|
57 | - } |
|
51 | + /** |
|
52 | + * @return array |
|
53 | + */ |
|
54 | + public function attendeeDetails() |
|
55 | + { |
|
56 | + return $this->attendee_details; |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * @return EE_Registration |
|
62 | - */ |
|
63 | - public function registration() |
|
64 | - { |
|
65 | - return $this->registration; |
|
66 | - } |
|
60 | + /** |
|
61 | + * @return EE_Registration |
|
62 | + */ |
|
63 | + public function registration() |
|
64 | + { |
|
65 | + return $this->registration; |
|
66 | + } |
|
67 | 67 | |
68 | 68 | |
69 | - /** |
|
70 | - * @return CapCheckInterface |
|
71 | - * @throws InvalidDataTypeException |
|
72 | - */ |
|
73 | - public function getCapCheck() |
|
74 | - { |
|
75 | - // need cap for non-AJAX admin requests |
|
76 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
77 | - return new CapCheck('ee_edit_contacts', 'create_new_contact'); |
|
78 | - } |
|
79 | - return new PublicCapabilities('', 'create_new_contact'); |
|
80 | - } |
|
69 | + /** |
|
70 | + * @return CapCheckInterface |
|
71 | + * @throws InvalidDataTypeException |
|
72 | + */ |
|
73 | + public function getCapCheck() |
|
74 | + { |
|
75 | + // need cap for non-AJAX admin requests |
|
76 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
77 | + return new CapCheck('ee_edit_contacts', 'create_new_contact'); |
|
78 | + } |
|
79 | + return new PublicCapabilities('', 'create_new_contact'); |
|
80 | + } |
|
81 | 81 | } |
@@ -5,7 +5,6 @@ |
||
5 | 5 | use WP_Error; |
6 | 6 | use WP_REST_Response; |
7 | 7 | use EventEspresso\core\libraries\rest_api\RestException; |
8 | - |
|
9 | 8 | use EE_Error; |
10 | 9 | use EED_Core_Rest_Api; |
11 | 10 | use EEH_Inflector; |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | */ |
97 | 97 | protected function setDebugInfo($key, $info) |
98 | 98 | { |
99 | - $this->debug_info[ $key ] = $info; |
|
99 | + $this->debug_info[$key] = $info; |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | |
@@ -113,11 +113,11 @@ discard block |
||
113 | 113 | { |
114 | 114 | if (is_array($value)) { |
115 | 115 | foreach ($value as $value_key => $value_value) { |
116 | - $this->setResponseHeader($header_key . '[' . $value_key . ']', $value_value); |
|
116 | + $this->setResponseHeader($header_key.'['.$value_key.']', $value_value); |
|
117 | 117 | } |
118 | 118 | } else { |
119 | 119 | $prefix = $use_ee_prefix ? Base::HEADER_PREFIX_FOR_EE : Base::HEADER_PREFIX_FOR_WP; |
120 | - $this->response_headers[ $prefix . $header_key ] = $value; |
|
120 | + $this->response_headers[$prefix.$header_key] = $value; |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | protected function addEeErrorsToResponse(WP_Error $wp_error_response) |
148 | 148 | { |
149 | 149 | $notices_during_checkin = EE_Error::get_raw_notices(); |
150 | - if (! empty($notices_during_checkin['errors'])) { |
|
150 | + if ( ! empty($notices_during_checkin['errors'])) { |
|
151 | 151 | foreach ($notices_during_checkin['errors'] as $error_code => $error_message) { |
152 | 152 | $wp_error_response->add( |
153 | 153 | sanitize_key($error_code), |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | if (is_array($debug_info)) { |
191 | 191 | $debug_info = wp_json_encode($debug_info); |
192 | 192 | } |
193 | - $headers[ 'X-EE4-Debug-' . ucwords($debug_key) ] = $debug_info; |
|
193 | + $headers['X-EE4-Debug-'.ucwords($debug_key)] = $debug_info; |
|
194 | 194 | } |
195 | 195 | } |
196 | 196 | $headers = array_merge( |
@@ -249,15 +249,15 @@ discard block |
||
249 | 249 | $headers = array(); |
250 | 250 | $notices = EE_Error::get_raw_notices(); |
251 | 251 | foreach ($notices as $notice_type => $sub_notices) { |
252 | - if (! is_array($sub_notices)) { |
|
252 | + if ( ! is_array($sub_notices)) { |
|
253 | 253 | continue; |
254 | 254 | } |
255 | 255 | foreach ($sub_notices as $notice_code => $sub_notice) { |
256 | - $headers[ 'X-EE4-Notices-' |
|
256 | + $headers['X-EE4-Notices-' |
|
257 | 257 | . EEH_Inflector::humanize($notice_type) |
258 | 258 | . '[' |
259 | 259 | . $notice_code |
260 | - . ']' ] = strip_tags($sub_notice); |
|
260 | + . ']'] = strip_tags($sub_notice); |
|
261 | 261 | } |
262 | 262 | } |
263 | 263 | return apply_filters( |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | } |
287 | 287 | $matches = $this->parseRoute( |
288 | 288 | $route, |
289 | - '~' . EED_Core_Rest_Api::ee_api_namespace_for_regex . '~', |
|
289 | + '~'.EED_Core_Rest_Api::ee_api_namespace_for_regex.'~', |
|
290 | 290 | array('version') |
291 | 291 | ); |
292 | 292 | if (isset($matches['version'])) { |
@@ -320,14 +320,14 @@ discard block |
||
320 | 320 | if (is_array($matches)) { |
321 | 321 | // skip the overall regex match. Who cares |
322 | 322 | for ($i = 1; $i <= count($match_keys); $i++) { |
323 | - if (! isset($matches[ $i ])) { |
|
323 | + if ( ! isset($matches[$i])) { |
|
324 | 324 | $success = false; |
325 | 325 | } else { |
326 | - $indexed_matches[ $match_keys[ $i - 1 ] ] = $matches[ $i ]; |
|
326 | + $indexed_matches[$match_keys[$i - 1]] = $matches[$i]; |
|
327 | 327 | } |
328 | 328 | } |
329 | 329 | } |
330 | - if (! $success) { |
|
330 | + if ( ! $success) { |
|
331 | 331 | throw new EE_Error( |
332 | 332 | __('We could not parse the URL. Please contact Event Espresso Support', 'event_espresso'), |
333 | 333 | 'endpoint_parsing_error' |
@@ -22,338 +22,338 @@ |
||
22 | 22 | class Base |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @deprecated use all-caps version |
|
27 | - */ |
|
28 | - // @codingStandardsIgnoreStart |
|
29 | - const header_prefix_for_ee = 'X-EE-'; |
|
30 | - // @codingStandardsIgnoreEnd |
|
31 | - |
|
32 | - const HEADER_PREFIX_FOR_EE = 'X-EE-'; |
|
33 | - |
|
34 | - /** |
|
35 | - * @deprecated use all-caps version instead |
|
36 | - */ |
|
37 | - // @codingStandardsIgnoreStart |
|
38 | - const header_prefix_for_wp = 'X-WP-'; |
|
39 | - // @codingStandardsIgnoreEnd |
|
40 | - |
|
41 | - const HEADER_PREFIX_FOR_WP = 'X-WP-'; |
|
42 | - |
|
43 | - /** |
|
44 | - * Contains debug info we'll send back in the response headers |
|
45 | - * |
|
46 | - * @var array |
|
47 | - */ |
|
48 | - protected $debug_info = array(); |
|
49 | - |
|
50 | - /** |
|
51 | - * Indicates whether or not the API is in debug mode |
|
52 | - * |
|
53 | - * @var boolean |
|
54 | - */ |
|
55 | - protected $debug_mode = false; |
|
56 | - |
|
57 | - /** |
|
58 | - * Indicates the version that was requested |
|
59 | - * |
|
60 | - * @var string |
|
61 | - */ |
|
62 | - protected $requested_version; |
|
63 | - |
|
64 | - /** |
|
65 | - * flat array of headers to send in the response |
|
66 | - * |
|
67 | - * @var array |
|
68 | - */ |
|
69 | - protected $response_headers = array(); |
|
70 | - |
|
71 | - |
|
72 | - public function __construct() |
|
73 | - { |
|
74 | - $this->debug_mode = EED_Core_Rest_Api::debugMode(); |
|
75 | - // we are handling a REST request. Don't show a fancy HTML error message is any error comes up |
|
76 | - add_filter('FHEE__EE_Error__get_error__show_normal_exceptions', '__return_true'); |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * Sets the version the user requested |
|
82 | - * |
|
83 | - * @param string $version eg '4.8' |
|
84 | - */ |
|
85 | - public function setRequestedVersion($version) |
|
86 | - { |
|
87 | - $this->requested_version = $version; |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * Sets some debug info that we'll send back in headers |
|
93 | - * |
|
94 | - * @param string $key |
|
95 | - * @param string|array $info |
|
96 | - */ |
|
97 | - protected function setDebugInfo($key, $info) |
|
98 | - { |
|
99 | - $this->debug_info[ $key ] = $info; |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * Sets headers for the response |
|
105 | - * |
|
106 | - * @param string $header_key , excluding the "X-EE-" part |
|
107 | - * @param array|string $value if an array, multiple headers will be added, one |
|
108 | - * for each key in the array |
|
109 | - * @param boolean $use_ee_prefix whether to use the EE prefix on the header, or fallback to |
|
110 | - * the standard WP one |
|
111 | - */ |
|
112 | - protected function setResponseHeader($header_key, $value, $use_ee_prefix = true) |
|
113 | - { |
|
114 | - if (is_array($value)) { |
|
115 | - foreach ($value as $value_key => $value_value) { |
|
116 | - $this->setResponseHeader($header_key . '[' . $value_key . ']', $value_value); |
|
117 | - } |
|
118 | - } else { |
|
119 | - $prefix = $use_ee_prefix ? Base::HEADER_PREFIX_FOR_EE : Base::HEADER_PREFIX_FOR_WP; |
|
120 | - $this->response_headers[ $prefix . $header_key ] = $value; |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * Returns a flat array of headers to be added to the response |
|
127 | - * |
|
128 | - * @return array |
|
129 | - */ |
|
130 | - protected function getResponseHeaders() |
|
131 | - { |
|
132 | - return apply_filters( |
|
133 | - 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers', |
|
134 | - $this->response_headers, |
|
135 | - $this, |
|
136 | - $this->requested_version |
|
137 | - ); |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * Adds error notices from EE_Error onto the provided \WP_Error |
|
143 | - * |
|
144 | - * @param WP_Error $wp_error_response |
|
145 | - * @return WP_Error |
|
146 | - */ |
|
147 | - protected function addEeErrorsToResponse(WP_Error $wp_error_response) |
|
148 | - { |
|
149 | - $notices_during_checkin = EE_Error::get_raw_notices(); |
|
150 | - if (! empty($notices_during_checkin['errors'])) { |
|
151 | - foreach ($notices_during_checkin['errors'] as $error_code => $error_message) { |
|
152 | - $wp_error_response->add( |
|
153 | - sanitize_key($error_code), |
|
154 | - strip_tags($error_message) |
|
155 | - ); |
|
156 | - } |
|
157 | - } |
|
158 | - return $wp_error_response; |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * Sends a response, but also makes sure to attach headers that |
|
164 | - * are handy for debugging. |
|
165 | - * Specifically, we assume folks will want to know what exactly was the DB query that got run, |
|
166 | - * what exactly was the Models query that got run, what capabilities came into play, what fields were omitted from |
|
167 | - * the response, others? |
|
168 | - * |
|
169 | - * @param array|WP_Error|Exception|RestException $response |
|
170 | - * @return WP_REST_Response |
|
171 | - */ |
|
172 | - public function sendResponse($response) |
|
173 | - { |
|
174 | - if ($response instanceof RestException) { |
|
175 | - $response = new WP_Error($response->getStringCode(), $response->getMessage(), $response->getData()); |
|
176 | - } |
|
177 | - if ($response instanceof Exception) { |
|
178 | - $code = $response->getCode() ? $response->getCode() : 'error_occurred'; |
|
179 | - $response = new WP_Error($code, $response->getMessage()); |
|
180 | - } |
|
181 | - if ($response instanceof WP_Error) { |
|
182 | - $response = $this->addEeErrorsToResponse($response); |
|
183 | - $rest_response = $this->createRestResponseFromWpError($response); |
|
184 | - } else { |
|
185 | - $rest_response = new WP_REST_Response($response, 200); |
|
186 | - } |
|
187 | - $headers = array(); |
|
188 | - if ($this->debug_mode && is_array($this->debug_info)) { |
|
189 | - foreach ($this->debug_info as $debug_key => $debug_info) { |
|
190 | - if (is_array($debug_info)) { |
|
191 | - $debug_info = wp_json_encode($debug_info); |
|
192 | - } |
|
193 | - $headers[ 'X-EE4-Debug-' . ucwords($debug_key) ] = $debug_info; |
|
194 | - } |
|
195 | - } |
|
196 | - $headers = array_merge( |
|
197 | - $headers, |
|
198 | - $this->getResponseHeaders(), |
|
199 | - $this->getHeadersFromEeNotices() |
|
200 | - ); |
|
201 | - $rest_response->set_headers($headers); |
|
202 | - return $rest_response; |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * Converts the \WP_Error into `WP_REST_Response. |
|
208 | - * Mostly this is just a copy-and-paste from \WP_REST_Server::error_to_response |
|
209 | - * (which is protected) |
|
210 | - * |
|
211 | - * @param WP_Error $wp_error |
|
212 | - * @return WP_REST_Response |
|
213 | - */ |
|
214 | - protected function createRestResponseFromWpError(WP_Error $wp_error) |
|
215 | - { |
|
216 | - $error_data = $wp_error->get_error_data(); |
|
217 | - if (is_array($error_data) && isset($error_data['status'])) { |
|
218 | - $status = $error_data['status']; |
|
219 | - } else { |
|
220 | - $status = 500; |
|
221 | - } |
|
222 | - $errors = array(); |
|
223 | - foreach ((array) $wp_error->errors as $code => $messages) { |
|
224 | - foreach ((array) $messages as $message) { |
|
225 | - $errors[] = array( |
|
226 | - 'code' => $code, |
|
227 | - 'message' => $message, |
|
228 | - 'data' => $wp_error->get_error_data($code), |
|
229 | - ); |
|
230 | - } |
|
231 | - } |
|
232 | - $data = isset($errors[0]) ? $errors[0] : array(); |
|
233 | - if (count($errors) > 1) { |
|
234 | - // Remove the primary error. |
|
235 | - array_shift($errors); |
|
236 | - $data['additional_errors'] = $errors; |
|
237 | - } |
|
238 | - return new WP_REST_Response($data, $status); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * Array of headers derived from EE success, attention, and error messages |
|
244 | - * |
|
245 | - * @return array |
|
246 | - */ |
|
247 | - protected function getHeadersFromEeNotices() |
|
248 | - { |
|
249 | - $headers = array(); |
|
250 | - $notices = EE_Error::get_raw_notices(); |
|
251 | - foreach ($notices as $notice_type => $sub_notices) { |
|
252 | - if (! is_array($sub_notices)) { |
|
253 | - continue; |
|
254 | - } |
|
255 | - foreach ($sub_notices as $notice_code => $sub_notice) { |
|
256 | - $headers[ 'X-EE4-Notices-' |
|
257 | - . EEH_Inflector::humanize($notice_type) |
|
258 | - . '[' |
|
259 | - . $notice_code |
|
260 | - . ']' ] = strip_tags($sub_notice); |
|
261 | - } |
|
262 | - } |
|
263 | - return apply_filters( |
|
264 | - 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_headers_from_ee_notices__return', |
|
265 | - $headers, |
|
266 | - $this->requested_version, |
|
267 | - $notices |
|
268 | - ); |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * Finds which version of the API was requested given the route, and returns it. |
|
274 | - * eg in a request to "mysite.com/wp-json/ee/v4.8.29/events/123" this would return |
|
275 | - * "4.8.29". |
|
276 | - * We should know hte requested version in this model though, so if no route is |
|
277 | - * provided just use what we set earlier |
|
278 | - * |
|
279 | - * @param string $route |
|
280 | - * @return string |
|
281 | - */ |
|
282 | - public function getRequestedVersion($route = null) |
|
283 | - { |
|
284 | - if ($route === null) { |
|
285 | - return $this->requested_version; |
|
286 | - } |
|
287 | - $matches = $this->parseRoute( |
|
288 | - $route, |
|
289 | - '~' . EED_Core_Rest_Api::ee_api_namespace_for_regex . '~', |
|
290 | - array('version') |
|
291 | - ); |
|
292 | - if (isset($matches['version'])) { |
|
293 | - return $matches['version']; |
|
294 | - } else { |
|
295 | - return EED_Core_Rest_Api::latest_rest_api_version(); |
|
296 | - } |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - /** |
|
301 | - * Applies the regex to the route, then creates an array using the values of |
|
302 | - * $match_keys as keys (but ignores the full pattern match). Returns the array of matches. |
|
303 | - * For example, if you call |
|
304 | - * parse_route( '/ee/v4.8/events', '~\/ee\/v([^/]*)\/(.*)~', array( 'version', 'model' ) ) |
|
305 | - * it will return array( 'version' => '4.8', 'model' => 'events' ) |
|
306 | - * |
|
307 | - * @param string $route |
|
308 | - * @param string $regex |
|
309 | - * @param array $match_keys EXCLUDING matching the entire regex |
|
310 | - * @return array where $match_keys are the keys (the first value of $match_keys |
|
311 | - * becomes the first key of the return value, etc. Eg passing in $match_keys of |
|
312 | - * array( 'model', 'id' ), will, if the regex is successful, will return |
|
313 | - * array( 'model' => 'foo', 'id' => 'bar' ) |
|
314 | - * @throws EE_Error if it couldn't be parsed |
|
315 | - */ |
|
316 | - public function parseRoute($route, $regex, $match_keys) |
|
317 | - { |
|
318 | - $indexed_matches = array(); |
|
319 | - $success = preg_match($regex, $route, $matches); |
|
320 | - if (is_array($matches)) { |
|
321 | - // skip the overall regex match. Who cares |
|
322 | - for ($i = 1; $i <= count($match_keys); $i++) { |
|
323 | - if (! isset($matches[ $i ])) { |
|
324 | - $success = false; |
|
325 | - } else { |
|
326 | - $indexed_matches[ $match_keys[ $i - 1 ] ] = $matches[ $i ]; |
|
327 | - } |
|
328 | - } |
|
329 | - } |
|
330 | - if (! $success) { |
|
331 | - throw new EE_Error( |
|
332 | - __('We could not parse the URL. Please contact Event Espresso Support', 'event_espresso'), |
|
333 | - 'endpoint_parsing_error' |
|
334 | - ); |
|
335 | - } |
|
336 | - return $indexed_matches; |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * Gets the body's params (either from JSON or parsed body), which EXCLUDES the GET params and URL params |
|
342 | - * |
|
343 | - * @param \WP_REST_Request $request |
|
344 | - * @return array |
|
345 | - */ |
|
346 | - protected function getBodyParams(\WP_REST_Request $request) |
|
347 | - { |
|
348 | - // $request->get_params(); |
|
349 | - return array_merge( |
|
350 | - (array) $request->get_body_params(), |
|
351 | - (array) $request->get_json_params() |
|
352 | - ); |
|
353 | - // return array_diff_key( |
|
354 | - // $request->get_params(), |
|
355 | - // $request->get_url_params(), |
|
356 | - // $request->get_query_params() |
|
357 | - // ); |
|
358 | - } |
|
25 | + /** |
|
26 | + * @deprecated use all-caps version |
|
27 | + */ |
|
28 | + // @codingStandardsIgnoreStart |
|
29 | + const header_prefix_for_ee = 'X-EE-'; |
|
30 | + // @codingStandardsIgnoreEnd |
|
31 | + |
|
32 | + const HEADER_PREFIX_FOR_EE = 'X-EE-'; |
|
33 | + |
|
34 | + /** |
|
35 | + * @deprecated use all-caps version instead |
|
36 | + */ |
|
37 | + // @codingStandardsIgnoreStart |
|
38 | + const header_prefix_for_wp = 'X-WP-'; |
|
39 | + // @codingStandardsIgnoreEnd |
|
40 | + |
|
41 | + const HEADER_PREFIX_FOR_WP = 'X-WP-'; |
|
42 | + |
|
43 | + /** |
|
44 | + * Contains debug info we'll send back in the response headers |
|
45 | + * |
|
46 | + * @var array |
|
47 | + */ |
|
48 | + protected $debug_info = array(); |
|
49 | + |
|
50 | + /** |
|
51 | + * Indicates whether or not the API is in debug mode |
|
52 | + * |
|
53 | + * @var boolean |
|
54 | + */ |
|
55 | + protected $debug_mode = false; |
|
56 | + |
|
57 | + /** |
|
58 | + * Indicates the version that was requested |
|
59 | + * |
|
60 | + * @var string |
|
61 | + */ |
|
62 | + protected $requested_version; |
|
63 | + |
|
64 | + /** |
|
65 | + * flat array of headers to send in the response |
|
66 | + * |
|
67 | + * @var array |
|
68 | + */ |
|
69 | + protected $response_headers = array(); |
|
70 | + |
|
71 | + |
|
72 | + public function __construct() |
|
73 | + { |
|
74 | + $this->debug_mode = EED_Core_Rest_Api::debugMode(); |
|
75 | + // we are handling a REST request. Don't show a fancy HTML error message is any error comes up |
|
76 | + add_filter('FHEE__EE_Error__get_error__show_normal_exceptions', '__return_true'); |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * Sets the version the user requested |
|
82 | + * |
|
83 | + * @param string $version eg '4.8' |
|
84 | + */ |
|
85 | + public function setRequestedVersion($version) |
|
86 | + { |
|
87 | + $this->requested_version = $version; |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * Sets some debug info that we'll send back in headers |
|
93 | + * |
|
94 | + * @param string $key |
|
95 | + * @param string|array $info |
|
96 | + */ |
|
97 | + protected function setDebugInfo($key, $info) |
|
98 | + { |
|
99 | + $this->debug_info[ $key ] = $info; |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * Sets headers for the response |
|
105 | + * |
|
106 | + * @param string $header_key , excluding the "X-EE-" part |
|
107 | + * @param array|string $value if an array, multiple headers will be added, one |
|
108 | + * for each key in the array |
|
109 | + * @param boolean $use_ee_prefix whether to use the EE prefix on the header, or fallback to |
|
110 | + * the standard WP one |
|
111 | + */ |
|
112 | + protected function setResponseHeader($header_key, $value, $use_ee_prefix = true) |
|
113 | + { |
|
114 | + if (is_array($value)) { |
|
115 | + foreach ($value as $value_key => $value_value) { |
|
116 | + $this->setResponseHeader($header_key . '[' . $value_key . ']', $value_value); |
|
117 | + } |
|
118 | + } else { |
|
119 | + $prefix = $use_ee_prefix ? Base::HEADER_PREFIX_FOR_EE : Base::HEADER_PREFIX_FOR_WP; |
|
120 | + $this->response_headers[ $prefix . $header_key ] = $value; |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * Returns a flat array of headers to be added to the response |
|
127 | + * |
|
128 | + * @return array |
|
129 | + */ |
|
130 | + protected function getResponseHeaders() |
|
131 | + { |
|
132 | + return apply_filters( |
|
133 | + 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers', |
|
134 | + $this->response_headers, |
|
135 | + $this, |
|
136 | + $this->requested_version |
|
137 | + ); |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * Adds error notices from EE_Error onto the provided \WP_Error |
|
143 | + * |
|
144 | + * @param WP_Error $wp_error_response |
|
145 | + * @return WP_Error |
|
146 | + */ |
|
147 | + protected function addEeErrorsToResponse(WP_Error $wp_error_response) |
|
148 | + { |
|
149 | + $notices_during_checkin = EE_Error::get_raw_notices(); |
|
150 | + if (! empty($notices_during_checkin['errors'])) { |
|
151 | + foreach ($notices_during_checkin['errors'] as $error_code => $error_message) { |
|
152 | + $wp_error_response->add( |
|
153 | + sanitize_key($error_code), |
|
154 | + strip_tags($error_message) |
|
155 | + ); |
|
156 | + } |
|
157 | + } |
|
158 | + return $wp_error_response; |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * Sends a response, but also makes sure to attach headers that |
|
164 | + * are handy for debugging. |
|
165 | + * Specifically, we assume folks will want to know what exactly was the DB query that got run, |
|
166 | + * what exactly was the Models query that got run, what capabilities came into play, what fields were omitted from |
|
167 | + * the response, others? |
|
168 | + * |
|
169 | + * @param array|WP_Error|Exception|RestException $response |
|
170 | + * @return WP_REST_Response |
|
171 | + */ |
|
172 | + public function sendResponse($response) |
|
173 | + { |
|
174 | + if ($response instanceof RestException) { |
|
175 | + $response = new WP_Error($response->getStringCode(), $response->getMessage(), $response->getData()); |
|
176 | + } |
|
177 | + if ($response instanceof Exception) { |
|
178 | + $code = $response->getCode() ? $response->getCode() : 'error_occurred'; |
|
179 | + $response = new WP_Error($code, $response->getMessage()); |
|
180 | + } |
|
181 | + if ($response instanceof WP_Error) { |
|
182 | + $response = $this->addEeErrorsToResponse($response); |
|
183 | + $rest_response = $this->createRestResponseFromWpError($response); |
|
184 | + } else { |
|
185 | + $rest_response = new WP_REST_Response($response, 200); |
|
186 | + } |
|
187 | + $headers = array(); |
|
188 | + if ($this->debug_mode && is_array($this->debug_info)) { |
|
189 | + foreach ($this->debug_info as $debug_key => $debug_info) { |
|
190 | + if (is_array($debug_info)) { |
|
191 | + $debug_info = wp_json_encode($debug_info); |
|
192 | + } |
|
193 | + $headers[ 'X-EE4-Debug-' . ucwords($debug_key) ] = $debug_info; |
|
194 | + } |
|
195 | + } |
|
196 | + $headers = array_merge( |
|
197 | + $headers, |
|
198 | + $this->getResponseHeaders(), |
|
199 | + $this->getHeadersFromEeNotices() |
|
200 | + ); |
|
201 | + $rest_response->set_headers($headers); |
|
202 | + return $rest_response; |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * Converts the \WP_Error into `WP_REST_Response. |
|
208 | + * Mostly this is just a copy-and-paste from \WP_REST_Server::error_to_response |
|
209 | + * (which is protected) |
|
210 | + * |
|
211 | + * @param WP_Error $wp_error |
|
212 | + * @return WP_REST_Response |
|
213 | + */ |
|
214 | + protected function createRestResponseFromWpError(WP_Error $wp_error) |
|
215 | + { |
|
216 | + $error_data = $wp_error->get_error_data(); |
|
217 | + if (is_array($error_data) && isset($error_data['status'])) { |
|
218 | + $status = $error_data['status']; |
|
219 | + } else { |
|
220 | + $status = 500; |
|
221 | + } |
|
222 | + $errors = array(); |
|
223 | + foreach ((array) $wp_error->errors as $code => $messages) { |
|
224 | + foreach ((array) $messages as $message) { |
|
225 | + $errors[] = array( |
|
226 | + 'code' => $code, |
|
227 | + 'message' => $message, |
|
228 | + 'data' => $wp_error->get_error_data($code), |
|
229 | + ); |
|
230 | + } |
|
231 | + } |
|
232 | + $data = isset($errors[0]) ? $errors[0] : array(); |
|
233 | + if (count($errors) > 1) { |
|
234 | + // Remove the primary error. |
|
235 | + array_shift($errors); |
|
236 | + $data['additional_errors'] = $errors; |
|
237 | + } |
|
238 | + return new WP_REST_Response($data, $status); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * Array of headers derived from EE success, attention, and error messages |
|
244 | + * |
|
245 | + * @return array |
|
246 | + */ |
|
247 | + protected function getHeadersFromEeNotices() |
|
248 | + { |
|
249 | + $headers = array(); |
|
250 | + $notices = EE_Error::get_raw_notices(); |
|
251 | + foreach ($notices as $notice_type => $sub_notices) { |
|
252 | + if (! is_array($sub_notices)) { |
|
253 | + continue; |
|
254 | + } |
|
255 | + foreach ($sub_notices as $notice_code => $sub_notice) { |
|
256 | + $headers[ 'X-EE4-Notices-' |
|
257 | + . EEH_Inflector::humanize($notice_type) |
|
258 | + . '[' |
|
259 | + . $notice_code |
|
260 | + . ']' ] = strip_tags($sub_notice); |
|
261 | + } |
|
262 | + } |
|
263 | + return apply_filters( |
|
264 | + 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_headers_from_ee_notices__return', |
|
265 | + $headers, |
|
266 | + $this->requested_version, |
|
267 | + $notices |
|
268 | + ); |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * Finds which version of the API was requested given the route, and returns it. |
|
274 | + * eg in a request to "mysite.com/wp-json/ee/v4.8.29/events/123" this would return |
|
275 | + * "4.8.29". |
|
276 | + * We should know hte requested version in this model though, so if no route is |
|
277 | + * provided just use what we set earlier |
|
278 | + * |
|
279 | + * @param string $route |
|
280 | + * @return string |
|
281 | + */ |
|
282 | + public function getRequestedVersion($route = null) |
|
283 | + { |
|
284 | + if ($route === null) { |
|
285 | + return $this->requested_version; |
|
286 | + } |
|
287 | + $matches = $this->parseRoute( |
|
288 | + $route, |
|
289 | + '~' . EED_Core_Rest_Api::ee_api_namespace_for_regex . '~', |
|
290 | + array('version') |
|
291 | + ); |
|
292 | + if (isset($matches['version'])) { |
|
293 | + return $matches['version']; |
|
294 | + } else { |
|
295 | + return EED_Core_Rest_Api::latest_rest_api_version(); |
|
296 | + } |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + /** |
|
301 | + * Applies the regex to the route, then creates an array using the values of |
|
302 | + * $match_keys as keys (but ignores the full pattern match). Returns the array of matches. |
|
303 | + * For example, if you call |
|
304 | + * parse_route( '/ee/v4.8/events', '~\/ee\/v([^/]*)\/(.*)~', array( 'version', 'model' ) ) |
|
305 | + * it will return array( 'version' => '4.8', 'model' => 'events' ) |
|
306 | + * |
|
307 | + * @param string $route |
|
308 | + * @param string $regex |
|
309 | + * @param array $match_keys EXCLUDING matching the entire regex |
|
310 | + * @return array where $match_keys are the keys (the first value of $match_keys |
|
311 | + * becomes the first key of the return value, etc. Eg passing in $match_keys of |
|
312 | + * array( 'model', 'id' ), will, if the regex is successful, will return |
|
313 | + * array( 'model' => 'foo', 'id' => 'bar' ) |
|
314 | + * @throws EE_Error if it couldn't be parsed |
|
315 | + */ |
|
316 | + public function parseRoute($route, $regex, $match_keys) |
|
317 | + { |
|
318 | + $indexed_matches = array(); |
|
319 | + $success = preg_match($regex, $route, $matches); |
|
320 | + if (is_array($matches)) { |
|
321 | + // skip the overall regex match. Who cares |
|
322 | + for ($i = 1; $i <= count($match_keys); $i++) { |
|
323 | + if (! isset($matches[ $i ])) { |
|
324 | + $success = false; |
|
325 | + } else { |
|
326 | + $indexed_matches[ $match_keys[ $i - 1 ] ] = $matches[ $i ]; |
|
327 | + } |
|
328 | + } |
|
329 | + } |
|
330 | + if (! $success) { |
|
331 | + throw new EE_Error( |
|
332 | + __('We could not parse the URL. Please contact Event Espresso Support', 'event_espresso'), |
|
333 | + 'endpoint_parsing_error' |
|
334 | + ); |
|
335 | + } |
|
336 | + return $indexed_matches; |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * Gets the body's params (either from JSON or parsed body), which EXCLUDES the GET params and URL params |
|
342 | + * |
|
343 | + * @param \WP_REST_Request $request |
|
344 | + * @return array |
|
345 | + */ |
|
346 | + protected function getBodyParams(\WP_REST_Request $request) |
|
347 | + { |
|
348 | + // $request->get_params(); |
|
349 | + return array_merge( |
|
350 | + (array) $request->get_body_params(), |
|
351 | + (array) $request->get_json_params() |
|
352 | + ); |
|
353 | + // return array_diff_key( |
|
354 | + // $request->get_params(), |
|
355 | + // $request->get_url_params(), |
|
356 | + // $request->get_query_params() |
|
357 | + // ); |
|
358 | + } |
|
359 | 359 | } |
@@ -9,12 +9,12 @@ |
||
9 | 9 | interface EEI_Line_Item_Display |
10 | 10 | { |
11 | 11 | |
12 | - /** |
|
13 | - * @param EE_Line_Item $line_item |
|
14 | - * @param array $options |
|
15 | - * @return mixed |
|
16 | - */ |
|
17 | - public function display_line_item(EE_Line_Item $line_item, $options = array()); |
|
12 | + /** |
|
13 | + * @param EE_Line_Item $line_item |
|
14 | + * @param array $options |
|
15 | + * @return mixed |
|
16 | + */ |
|
17 | + public function display_line_item(EE_Line_Item $line_item, $options = array()); |
|
18 | 18 | |
19 | 19 | } |
20 | 20 |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <p> |
2 | 2 | <?php esc_html_e( |
3 | - 'Use this to control what the default will be for maximum tickets on an order when creating a new event.', |
|
4 | - 'event_espresso' |
|
5 | - ); ?> |
|
3 | + 'Use this to control what the default will be for maximum tickets on an order when creating a new event.', |
|
4 | + 'event_espresso' |
|
5 | + ); ?> |
|
6 | 6 | </p> |
7 | 7 | \ No newline at end of file |
@@ -43,7 +43,7 @@ |
||
43 | 43 | $error_string = esc_html__('The following errors occurred:', 'event_espresso'); |
44 | 44 | foreach ($notices->getError() as $notice) { |
45 | 45 | if ($this->getThrowExceptions()) { |
46 | - $error_string .= '<br />' . $notice->message(); |
|
46 | + $error_string .= '<br />'.$notice->message(); |
|
47 | 47 | } else { |
48 | 48 | EE_Error::add_error( |
49 | 49 | $notice->message(), |
@@ -19,56 +19,56 @@ |
||
19 | 19 | class ConvertNoticesToEeErrors extends NoticeConverter |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * Converts Notice objects into EE_Error notifications |
|
24 | - * |
|
25 | - * @param NoticesContainerInterface $notices |
|
26 | - * @throws EE_Error |
|
27 | - */ |
|
28 | - public function process(NoticesContainerInterface $notices) |
|
29 | - { |
|
30 | - $this->setNotices($notices); |
|
31 | - $notices = $this->getNotices(); |
|
32 | - if ($notices->hasAttention()) { |
|
33 | - foreach ($notices->getAttention() as $notice) { |
|
34 | - EE_Error::add_attention( |
|
35 | - $notice->message(), |
|
36 | - $notice->file(), |
|
37 | - $notice->func(), |
|
38 | - $notice->line() |
|
39 | - ); |
|
40 | - } |
|
41 | - } |
|
42 | - if ($notices->hasError()) { |
|
43 | - $error_string = esc_html__('The following errors occurred:', 'event_espresso'); |
|
44 | - foreach ($notices->getError() as $notice) { |
|
45 | - if ($this->getThrowExceptions()) { |
|
46 | - $error_string .= '<br />' . $notice->message(); |
|
47 | - } else { |
|
48 | - EE_Error::add_error( |
|
49 | - $notice->message(), |
|
50 | - $notice->file(), |
|
51 | - $notice->func(), |
|
52 | - $notice->line() |
|
53 | - ); |
|
54 | - } |
|
55 | - } |
|
56 | - if ($this->getThrowExceptions()) { |
|
57 | - throw new EE_Error($error_string); |
|
58 | - } |
|
59 | - } |
|
60 | - if ($notices->hasSuccess()) { |
|
61 | - foreach ($notices->getSuccess() as $notice) { |
|
62 | - EE_Error::add_success( |
|
63 | - $notice->message(), |
|
64 | - $notice->file(), |
|
65 | - $notice->func(), |
|
66 | - $notice->line() |
|
67 | - ); |
|
68 | - } |
|
69 | - } |
|
70 | - $this->clearNotices(); |
|
71 | - } |
|
22 | + /** |
|
23 | + * Converts Notice objects into EE_Error notifications |
|
24 | + * |
|
25 | + * @param NoticesContainerInterface $notices |
|
26 | + * @throws EE_Error |
|
27 | + */ |
|
28 | + public function process(NoticesContainerInterface $notices) |
|
29 | + { |
|
30 | + $this->setNotices($notices); |
|
31 | + $notices = $this->getNotices(); |
|
32 | + if ($notices->hasAttention()) { |
|
33 | + foreach ($notices->getAttention() as $notice) { |
|
34 | + EE_Error::add_attention( |
|
35 | + $notice->message(), |
|
36 | + $notice->file(), |
|
37 | + $notice->func(), |
|
38 | + $notice->line() |
|
39 | + ); |
|
40 | + } |
|
41 | + } |
|
42 | + if ($notices->hasError()) { |
|
43 | + $error_string = esc_html__('The following errors occurred:', 'event_espresso'); |
|
44 | + foreach ($notices->getError() as $notice) { |
|
45 | + if ($this->getThrowExceptions()) { |
|
46 | + $error_string .= '<br />' . $notice->message(); |
|
47 | + } else { |
|
48 | + EE_Error::add_error( |
|
49 | + $notice->message(), |
|
50 | + $notice->file(), |
|
51 | + $notice->func(), |
|
52 | + $notice->line() |
|
53 | + ); |
|
54 | + } |
|
55 | + } |
|
56 | + if ($this->getThrowExceptions()) { |
|
57 | + throw new EE_Error($error_string); |
|
58 | + } |
|
59 | + } |
|
60 | + if ($notices->hasSuccess()) { |
|
61 | + foreach ($notices->getSuccess() as $notice) { |
|
62 | + EE_Error::add_success( |
|
63 | + $notice->message(), |
|
64 | + $notice->file(), |
|
65 | + $notice->func(), |
|
66 | + $notice->line() |
|
67 | + ); |
|
68 | + } |
|
69 | + } |
|
70 | + $this->clearNotices(); |
|
71 | + } |
|
72 | 72 | |
73 | 73 | |
74 | 74 | } |
@@ -11,48 +11,48 @@ |
||
11 | 11 | * @version 4+ |
12 | 12 | */ |
13 | 13 | if (have_posts()) : |
14 | - if (apply_filters('FHEE__archive_espresso_events_template__show_header', true)) : ?> |
|
14 | + if (apply_filters('FHEE__archive_espresso_events_template__show_header', true)) : ?> |
|
15 | 15 | <header class="page-header"> |
16 | 16 | <h1 class="page-title"> |
17 | 17 | <?php |
18 | - if (is_day()) : |
|
19 | - printf(__('Today\'s Events: %s', 'event_espresso'), get_the_date()); |
|
20 | - elseif (is_month()) : |
|
21 | - printf( |
|
22 | - __('Events This Month: %s', 'event_espresso'), |
|
23 | - get_the_date(_x('F Y', 'monthly archives date format', 'event_espresso')) |
|
24 | - ); |
|
25 | - elseif (is_year()) : |
|
26 | - printf( |
|
27 | - __('Events This Year: %s', 'event_espresso'), |
|
28 | - get_the_date(_x('Y', 'yearly archives date format', 'event_espresso')) |
|
29 | - ); |
|
30 | - else : |
|
31 | - echo apply_filters( |
|
32 | - 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
|
33 | - __('Upcoming Events', 'event_espresso') |
|
34 | - ); |
|
35 | - endif; |
|
36 | - ?> |
|
18 | + if (is_day()) : |
|
19 | + printf(__('Today\'s Events: %s', 'event_espresso'), get_the_date()); |
|
20 | + elseif (is_month()) : |
|
21 | + printf( |
|
22 | + __('Events This Month: %s', 'event_espresso'), |
|
23 | + get_the_date(_x('F Y', 'monthly archives date format', 'event_espresso')) |
|
24 | + ); |
|
25 | + elseif (is_year()) : |
|
26 | + printf( |
|
27 | + __('Events This Year: %s', 'event_espresso'), |
|
28 | + get_the_date(_x('Y', 'yearly archives date format', 'event_espresso')) |
|
29 | + ); |
|
30 | + else : |
|
31 | + echo apply_filters( |
|
32 | + 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
|
33 | + __('Upcoming Events', 'event_espresso') |
|
34 | + ); |
|
35 | + endif; |
|
36 | + ?> |
|
37 | 37 | </h1> |
38 | 38 | |
39 | 39 | </header><!-- .page-header --> |
40 | 40 | |
41 | 41 | <?php |
42 | - endif; |
|
43 | - // allow other stuff |
|
44 | - do_action('AHEE__archive_espresso_events_template__before_loop'); |
|
45 | - // Start the Loop. |
|
46 | - while (have_posts()) : the_post(); |
|
47 | - // Include the post TYPE-specific template for the content. |
|
48 | - espresso_get_template_part('content', 'espresso_events-shortcode'); |
|
49 | - endwhile; |
|
50 | - // Previous/next page navigation. |
|
51 | - espresso_pagination(); |
|
52 | - // allow moar other stuff |
|
53 | - do_action('AHEE__archive_espresso_events_template__after_loop'); |
|
42 | + endif; |
|
43 | + // allow other stuff |
|
44 | + do_action('AHEE__archive_espresso_events_template__before_loop'); |
|
45 | + // Start the Loop. |
|
46 | + while (have_posts()) : the_post(); |
|
47 | + // Include the post TYPE-specific template for the content. |
|
48 | + espresso_get_template_part('content', 'espresso_events-shortcode'); |
|
49 | + endwhile; |
|
50 | + // Previous/next page navigation. |
|
51 | + espresso_pagination(); |
|
52 | + // allow moar other stuff |
|
53 | + do_action('AHEE__archive_espresso_events_template__after_loop'); |
|
54 | 54 | else : |
55 | - // If no content, include the "No posts found" template. |
|
56 | - espresso_get_template_part('content', 'none'); |
|
55 | + // If no content, include the "No posts found" template. |
|
56 | + espresso_get_template_part('content', 'none'); |
|
57 | 57 | endif; |
58 | 58 |
@@ -27,11 +27,13 @@ discard block |
||
27 | 27 | __('Events This Year: %s', 'event_espresso'), |
28 | 28 | get_the_date(_x('Y', 'yearly archives date format', 'event_espresso')) |
29 | 29 | ); |
30 | - else : |
|
30 | + else { |
|
31 | + : |
|
31 | 32 | echo apply_filters( |
32 | 33 | 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
33 | 34 | __('Upcoming Events', 'event_espresso') |
34 | 35 | ); |
36 | + } |
|
35 | 37 | endif; |
36 | 38 | ?> |
37 | 39 | </h1> |
@@ -51,8 +53,10 @@ discard block |
||
51 | 53 | espresso_pagination(); |
52 | 54 | // allow moar other stuff |
53 | 55 | do_action('AHEE__archive_espresso_events_template__after_loop'); |
54 | -else : |
|
56 | +else { |
|
57 | + : |
|
55 | 58 | // If no content, include the "No posts found" template. |
56 | 59 | espresso_get_template_part('content', 'none'); |
60 | +} |
|
57 | 61 | endif; |
58 | 62 |
@@ -12,23 +12,23 @@ |
||
12 | 12 | trait TicketSelector |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Use to select a quantity from the first ticket for the given event (so this can be used on a event archive page). |
|
17 | - * @param int|string $event_id |
|
18 | - * @param int|string $quantity |
|
19 | - */ |
|
20 | - public function selectQuantityOfFirstTicketForEventId($event_id, $quantity = 1) |
|
21 | - { |
|
22 | - $this->actor()->selectOption(TicketSelectorElements::ticketOptionByEventIdSelector($event_id), $quantity); |
|
23 | - } |
|
15 | + /** |
|
16 | + * Use to select a quantity from the first ticket for the given event (so this can be used on a event archive page). |
|
17 | + * @param int|string $event_id |
|
18 | + * @param int|string $quantity |
|
19 | + */ |
|
20 | + public function selectQuantityOfFirstTicketForEventId($event_id, $quantity = 1) |
|
21 | + { |
|
22 | + $this->actor()->selectOption(TicketSelectorElements::ticketOptionByEventIdSelector($event_id), $quantity); |
|
23 | + } |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * Used to submit the ticket selection for the given event id (so this can be used on an event archive page). |
|
28 | - * @param int|string $event_id |
|
29 | - */ |
|
30 | - public function submitTicketSelectionsForEventId($event_id) |
|
31 | - { |
|
32 | - $this->actor()->click(TicketSelectorElements::ticketSelectionSubmitSelectorByEventId($event_id)); |
|
33 | - } |
|
26 | + /** |
|
27 | + * Used to submit the ticket selection for the given event id (so this can be used on an event archive page). |
|
28 | + * @param int|string $event_id |
|
29 | + */ |
|
30 | + public function submitTicketSelectionsForEventId($event_id) |
|
31 | + { |
|
32 | + $this->actor()->click(TicketSelectorElements::ticketSelectionSubmitSelectorByEventId($event_id)); |
|
33 | + } |
|
34 | 34 | } |
35 | 35 | \ No newline at end of file |