@@ -297,8 +297,8 @@ |
||
297 | 297 | */ |
298 | 298 | public static function verify_and_retrieve_class_name_for_data_handler_reference($data_handler_reference) |
299 | 299 | { |
300 | - $class_name = 'EE_Messages_' . $data_handler_reference . '_incoming_data'; |
|
301 | - if (! class_exists($class_name)) { |
|
300 | + $class_name = 'EE_Messages_'.$data_handler_reference.'_incoming_data'; |
|
301 | + if ( ! class_exists($class_name)) { |
|
302 | 302 | EE_Error::add_error( |
303 | 303 | sprintf( |
304 | 304 | esc_html__( |
@@ -11,308 +11,308 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Message_To_Generate |
13 | 13 | { |
14 | - /** |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $_messenger_name; |
|
18 | - |
|
19 | - /** |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $_message_type_name; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var EE_messenger |
|
26 | - */ |
|
27 | - protected $_messenger; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var EE_message_type |
|
31 | - */ |
|
32 | - protected $_message_type; |
|
33 | - |
|
34 | - /** |
|
35 | - * Identifier for the context the message is to be generated for. |
|
36 | - * |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - protected $_context = ''; |
|
40 | - |
|
41 | - /** |
|
42 | - * Data that will be used to generate message. |
|
43 | - * |
|
44 | - * @var array |
|
45 | - */ |
|
46 | - protected $_data = []; |
|
47 | - |
|
48 | - /** |
|
49 | - * Whether this message is for a preview or not. |
|
50 | - * |
|
51 | - * @var bool |
|
52 | - */ |
|
53 | - protected $_preview = false; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var EE_Message |
|
57 | - */ |
|
58 | - protected $_message; |
|
59 | - |
|
60 | - /** |
|
61 | - * This is set by the constructor to indicate whether the incoming messenger |
|
62 | - * and message type are valid. This can then be checked by callers to determine whether |
|
63 | - * to generate this message or not. |
|
64 | - * |
|
65 | - * @var bool |
|
66 | - */ |
|
67 | - protected $_valid = false; |
|
68 | - |
|
69 | - /** |
|
70 | - * If there are any errors (non exception errors) they get added to this array for callers to decide |
|
71 | - * how to handle. |
|
72 | - * |
|
73 | - * @var array |
|
74 | - */ |
|
75 | - protected $_error_msg = []; |
|
76 | - |
|
77 | - /** |
|
78 | - * Can be accessed via the send_now() method, this is set in the validation |
|
79 | - * routine via the EE_messenger::send_now() method. |
|
80 | - * |
|
81 | - * @var bool |
|
82 | - */ |
|
83 | - protected $_send_now = false; |
|
84 | - |
|
85 | - /** |
|
86 | - * Holds the classname for the data handler used by the current message type. |
|
87 | - * This is set on the first call to the public `get_data_handler_class_name()` method. |
|
88 | - * |
|
89 | - * @var string |
|
90 | - */ |
|
91 | - protected $_data_handler_class_name = ''; |
|
92 | - |
|
93 | - /** |
|
94 | - * one of the message status constants on EEM_Message |
|
95 | - * |
|
96 | - * @var string |
|
97 | - * @since 4.10.29.p |
|
98 | - */ |
|
99 | - protected $_status = ''; |
|
100 | - |
|
101 | - /** |
|
102 | - * use $_status var above |
|
103 | - * |
|
104 | - * @var string |
|
105 | - * @deprecated 4.10.29.p |
|
106 | - */ |
|
107 | - protected $_message_status = ''; |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Constructor |
|
112 | - * |
|
113 | - * @param string $messenger_name Slug representing messenger |
|
114 | - * @param string $message_type_name Slug representing message type. |
|
115 | - * @param mixed $data Data used for generating message. |
|
116 | - * @param string $context Optional context to restrict message generated for. |
|
117 | - * @param bool $preview Whether this is being used to generate a preview or not. |
|
118 | - * @param string $status |
|
119 | - */ |
|
120 | - public function __construct( |
|
121 | - $messenger_name, |
|
122 | - $message_type_name, |
|
123 | - $data = [], |
|
124 | - $context = '', |
|
125 | - $preview = false, |
|
126 | - $status = EEM_Message::status_incomplete |
|
127 | - ) { |
|
128 | - $this->_messenger_name = $messenger_name; |
|
129 | - $this->_message_type_name = $message_type_name; |
|
130 | - $this->_data = is_array($data) ? $data : [$data]; |
|
131 | - $this->_context = $context; |
|
132 | - $this->_preview = $preview; |
|
133 | - $this->_status = $status; |
|
134 | - // attempt to generate message immediately |
|
135 | - $this->_message = $this->_generate_message(); |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - public function context() |
|
143 | - { |
|
144 | - return $this->_context; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * @return array |
|
150 | - */ |
|
151 | - public function data() |
|
152 | - { |
|
153 | - return $this->_data; |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * @return EE_messenger |
|
159 | - */ |
|
160 | - public function messenger() |
|
161 | - { |
|
162 | - return $this->_messenger; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * @return EE_message_type |
|
168 | - */ |
|
169 | - public function message_type() |
|
170 | - { |
|
171 | - return $this->_message_type; |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * @return boolean |
|
177 | - */ |
|
178 | - public function preview() |
|
179 | - { |
|
180 | - return $this->_preview; |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * @param boolean $preview |
|
186 | - */ |
|
187 | - public function set_preview($preview) |
|
188 | - { |
|
189 | - $this->_preview = filter_var($preview, FILTER_VALIDATE_BOOLEAN); |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * @return bool |
|
195 | - */ |
|
196 | - public function send_now() |
|
197 | - { |
|
198 | - return $this->_send_now; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * Simply returns the state of the $_valid property. |
|
204 | - * |
|
205 | - * @return bool |
|
206 | - */ |
|
207 | - public function valid() |
|
208 | - { |
|
209 | - return $this->_valid; |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * generates an EE_Message using the supplied arguments and some defaults |
|
215 | - * |
|
216 | - * @param array $properties |
|
217 | - * @return EE_Message |
|
218 | - */ |
|
219 | - protected function _generate_message($properties = []) |
|
220 | - { |
|
221 | - $message = EE_Message_Factory::create( |
|
222 | - array_merge( |
|
223 | - [ |
|
224 | - 'MSG_messenger' => $this->_messenger_name, |
|
225 | - 'MSG_message_type' => $this->_message_type_name, |
|
226 | - 'MSG_context' => $this->_context, |
|
227 | - 'STS_ID' => $this->_status, |
|
228 | - ], |
|
229 | - $properties |
|
230 | - ) |
|
231 | - ); |
|
232 | - // validate the message, and if it's good, set some properties |
|
233 | - try { |
|
234 | - $message->is_valid_for_sending_or_generation(true); |
|
235 | - $this->_valid = true; |
|
236 | - $this->_messenger = $message->messenger_object(); |
|
237 | - $this->_message_type = $message->message_type_object(); |
|
238 | - $this->_send_now = $message->send_now(); |
|
239 | - } catch (Exception $e) { |
|
240 | - $this->_valid = false; |
|
241 | - $this->_error_msg[] = $e->getMessage(); |
|
242 | - } |
|
243 | - return $message; |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Returns an instantiated EE_Message object from the internal data. |
|
249 | - * |
|
250 | - * @return EE_Message |
|
251 | - */ |
|
252 | - public function get_EE_Message() |
|
253 | - { |
|
254 | - // already set ? |
|
255 | - if ($this->_message instanceof EE_Message) { |
|
256 | - return $this->_message; |
|
257 | - } |
|
258 | - // no? then let's create one |
|
259 | - $this->_message = $this->_generate_message(); |
|
260 | - return $this->_message; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * This returns the data_handler class name for the internal message type set. |
|
266 | - * Note: this also verifies that the data handler class exists. If it doesn't then $_valid is set to false |
|
267 | - * and the data_handler_class name is set to an empty string. |
|
268 | - * |
|
269 | - * @param bool $preview Used to indicate that the preview data handler is to be returned. |
|
270 | - * @return string |
|
271 | - */ |
|
272 | - public function get_data_handler_class_name($preview = false) |
|
273 | - { |
|
274 | - if ($this->_data_handler_class_name === '' && $this->valid()) { |
|
275 | - $ref = $preview ? 'Preview' : $this->_message_type->get_data_handler($this->_data); |
|
276 | - // make sure internal data is updated. |
|
277 | - $this->_data = $this->_message_type->get_data(); |
|
278 | - |
|
279 | - // verify |
|
280 | - $this->_data_handler_class_name = |
|
281 | - EE_Message_To_Generate::verify_and_retrieve_class_name_for_data_handler_reference($ref); |
|
282 | - if ($this->_data_handler_class_name === '') { |
|
283 | - $this->_valid = false; |
|
284 | - } |
|
285 | - } |
|
286 | - return $this->_data_handler_class_name; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * Validates the given string as a reference for an existing, accessible data handler and returns the class name |
|
292 | - * For the handler the reference matches. |
|
293 | - * |
|
294 | - * @param string $data_handler_reference |
|
295 | - * @return string |
|
296 | - */ |
|
297 | - public static function verify_and_retrieve_class_name_for_data_handler_reference($data_handler_reference) |
|
298 | - { |
|
299 | - $class_name = 'EE_Messages_' . $data_handler_reference . '_incoming_data'; |
|
300 | - if (! class_exists($class_name)) { |
|
301 | - EE_Error::add_error( |
|
302 | - sprintf( |
|
303 | - esc_html__( |
|
304 | - 'The included data handler reference (%s) does not match any valid, accessible, "EE_Messages_incoming_data" classes. Looking for %s.', |
|
305 | - 'event_espresso' |
|
306 | - ), |
|
307 | - $data_handler_reference, |
|
308 | - $class_name |
|
309 | - ), |
|
310 | - __FILE__, |
|
311 | - __FUNCTION__, |
|
312 | - __LINE__ |
|
313 | - ); |
|
314 | - $class_name = ''; // clear out class_name so caller knows this isn't valid. |
|
315 | - } |
|
316 | - return $class_name; |
|
317 | - } |
|
14 | + /** |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $_messenger_name; |
|
18 | + |
|
19 | + /** |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $_message_type_name; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var EE_messenger |
|
26 | + */ |
|
27 | + protected $_messenger; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var EE_message_type |
|
31 | + */ |
|
32 | + protected $_message_type; |
|
33 | + |
|
34 | + /** |
|
35 | + * Identifier for the context the message is to be generated for. |
|
36 | + * |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + protected $_context = ''; |
|
40 | + |
|
41 | + /** |
|
42 | + * Data that will be used to generate message. |
|
43 | + * |
|
44 | + * @var array |
|
45 | + */ |
|
46 | + protected $_data = []; |
|
47 | + |
|
48 | + /** |
|
49 | + * Whether this message is for a preview or not. |
|
50 | + * |
|
51 | + * @var bool |
|
52 | + */ |
|
53 | + protected $_preview = false; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var EE_Message |
|
57 | + */ |
|
58 | + protected $_message; |
|
59 | + |
|
60 | + /** |
|
61 | + * This is set by the constructor to indicate whether the incoming messenger |
|
62 | + * and message type are valid. This can then be checked by callers to determine whether |
|
63 | + * to generate this message or not. |
|
64 | + * |
|
65 | + * @var bool |
|
66 | + */ |
|
67 | + protected $_valid = false; |
|
68 | + |
|
69 | + /** |
|
70 | + * If there are any errors (non exception errors) they get added to this array for callers to decide |
|
71 | + * how to handle. |
|
72 | + * |
|
73 | + * @var array |
|
74 | + */ |
|
75 | + protected $_error_msg = []; |
|
76 | + |
|
77 | + /** |
|
78 | + * Can be accessed via the send_now() method, this is set in the validation |
|
79 | + * routine via the EE_messenger::send_now() method. |
|
80 | + * |
|
81 | + * @var bool |
|
82 | + */ |
|
83 | + protected $_send_now = false; |
|
84 | + |
|
85 | + /** |
|
86 | + * Holds the classname for the data handler used by the current message type. |
|
87 | + * This is set on the first call to the public `get_data_handler_class_name()` method. |
|
88 | + * |
|
89 | + * @var string |
|
90 | + */ |
|
91 | + protected $_data_handler_class_name = ''; |
|
92 | + |
|
93 | + /** |
|
94 | + * one of the message status constants on EEM_Message |
|
95 | + * |
|
96 | + * @var string |
|
97 | + * @since 4.10.29.p |
|
98 | + */ |
|
99 | + protected $_status = ''; |
|
100 | + |
|
101 | + /** |
|
102 | + * use $_status var above |
|
103 | + * |
|
104 | + * @var string |
|
105 | + * @deprecated 4.10.29.p |
|
106 | + */ |
|
107 | + protected $_message_status = ''; |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Constructor |
|
112 | + * |
|
113 | + * @param string $messenger_name Slug representing messenger |
|
114 | + * @param string $message_type_name Slug representing message type. |
|
115 | + * @param mixed $data Data used for generating message. |
|
116 | + * @param string $context Optional context to restrict message generated for. |
|
117 | + * @param bool $preview Whether this is being used to generate a preview or not. |
|
118 | + * @param string $status |
|
119 | + */ |
|
120 | + public function __construct( |
|
121 | + $messenger_name, |
|
122 | + $message_type_name, |
|
123 | + $data = [], |
|
124 | + $context = '', |
|
125 | + $preview = false, |
|
126 | + $status = EEM_Message::status_incomplete |
|
127 | + ) { |
|
128 | + $this->_messenger_name = $messenger_name; |
|
129 | + $this->_message_type_name = $message_type_name; |
|
130 | + $this->_data = is_array($data) ? $data : [$data]; |
|
131 | + $this->_context = $context; |
|
132 | + $this->_preview = $preview; |
|
133 | + $this->_status = $status; |
|
134 | + // attempt to generate message immediately |
|
135 | + $this->_message = $this->_generate_message(); |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + public function context() |
|
143 | + { |
|
144 | + return $this->_context; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * @return array |
|
150 | + */ |
|
151 | + public function data() |
|
152 | + { |
|
153 | + return $this->_data; |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * @return EE_messenger |
|
159 | + */ |
|
160 | + public function messenger() |
|
161 | + { |
|
162 | + return $this->_messenger; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * @return EE_message_type |
|
168 | + */ |
|
169 | + public function message_type() |
|
170 | + { |
|
171 | + return $this->_message_type; |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * @return boolean |
|
177 | + */ |
|
178 | + public function preview() |
|
179 | + { |
|
180 | + return $this->_preview; |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * @param boolean $preview |
|
186 | + */ |
|
187 | + public function set_preview($preview) |
|
188 | + { |
|
189 | + $this->_preview = filter_var($preview, FILTER_VALIDATE_BOOLEAN); |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * @return bool |
|
195 | + */ |
|
196 | + public function send_now() |
|
197 | + { |
|
198 | + return $this->_send_now; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * Simply returns the state of the $_valid property. |
|
204 | + * |
|
205 | + * @return bool |
|
206 | + */ |
|
207 | + public function valid() |
|
208 | + { |
|
209 | + return $this->_valid; |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * generates an EE_Message using the supplied arguments and some defaults |
|
215 | + * |
|
216 | + * @param array $properties |
|
217 | + * @return EE_Message |
|
218 | + */ |
|
219 | + protected function _generate_message($properties = []) |
|
220 | + { |
|
221 | + $message = EE_Message_Factory::create( |
|
222 | + array_merge( |
|
223 | + [ |
|
224 | + 'MSG_messenger' => $this->_messenger_name, |
|
225 | + 'MSG_message_type' => $this->_message_type_name, |
|
226 | + 'MSG_context' => $this->_context, |
|
227 | + 'STS_ID' => $this->_status, |
|
228 | + ], |
|
229 | + $properties |
|
230 | + ) |
|
231 | + ); |
|
232 | + // validate the message, and if it's good, set some properties |
|
233 | + try { |
|
234 | + $message->is_valid_for_sending_or_generation(true); |
|
235 | + $this->_valid = true; |
|
236 | + $this->_messenger = $message->messenger_object(); |
|
237 | + $this->_message_type = $message->message_type_object(); |
|
238 | + $this->_send_now = $message->send_now(); |
|
239 | + } catch (Exception $e) { |
|
240 | + $this->_valid = false; |
|
241 | + $this->_error_msg[] = $e->getMessage(); |
|
242 | + } |
|
243 | + return $message; |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Returns an instantiated EE_Message object from the internal data. |
|
249 | + * |
|
250 | + * @return EE_Message |
|
251 | + */ |
|
252 | + public function get_EE_Message() |
|
253 | + { |
|
254 | + // already set ? |
|
255 | + if ($this->_message instanceof EE_Message) { |
|
256 | + return $this->_message; |
|
257 | + } |
|
258 | + // no? then let's create one |
|
259 | + $this->_message = $this->_generate_message(); |
|
260 | + return $this->_message; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * This returns the data_handler class name for the internal message type set. |
|
266 | + * Note: this also verifies that the data handler class exists. If it doesn't then $_valid is set to false |
|
267 | + * and the data_handler_class name is set to an empty string. |
|
268 | + * |
|
269 | + * @param bool $preview Used to indicate that the preview data handler is to be returned. |
|
270 | + * @return string |
|
271 | + */ |
|
272 | + public function get_data_handler_class_name($preview = false) |
|
273 | + { |
|
274 | + if ($this->_data_handler_class_name === '' && $this->valid()) { |
|
275 | + $ref = $preview ? 'Preview' : $this->_message_type->get_data_handler($this->_data); |
|
276 | + // make sure internal data is updated. |
|
277 | + $this->_data = $this->_message_type->get_data(); |
|
278 | + |
|
279 | + // verify |
|
280 | + $this->_data_handler_class_name = |
|
281 | + EE_Message_To_Generate::verify_and_retrieve_class_name_for_data_handler_reference($ref); |
|
282 | + if ($this->_data_handler_class_name === '') { |
|
283 | + $this->_valid = false; |
|
284 | + } |
|
285 | + } |
|
286 | + return $this->_data_handler_class_name; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * Validates the given string as a reference for an existing, accessible data handler and returns the class name |
|
292 | + * For the handler the reference matches. |
|
293 | + * |
|
294 | + * @param string $data_handler_reference |
|
295 | + * @return string |
|
296 | + */ |
|
297 | + public static function verify_and_retrieve_class_name_for_data_handler_reference($data_handler_reference) |
|
298 | + { |
|
299 | + $class_name = 'EE_Messages_' . $data_handler_reference . '_incoming_data'; |
|
300 | + if (! class_exists($class_name)) { |
|
301 | + EE_Error::add_error( |
|
302 | + sprintf( |
|
303 | + esc_html__( |
|
304 | + 'The included data handler reference (%s) does not match any valid, accessible, "EE_Messages_incoming_data" classes. Looking for %s.', |
|
305 | + 'event_espresso' |
|
306 | + ), |
|
307 | + $data_handler_reference, |
|
308 | + $class_name |
|
309 | + ), |
|
310 | + __FILE__, |
|
311 | + __FUNCTION__, |
|
312 | + __LINE__ |
|
313 | + ); |
|
314 | + $class_name = ''; // clear out class_name so caller knows this isn't valid. |
|
315 | + } |
|
316 | + return $class_name; |
|
317 | + } |
|
318 | 318 | } |
@@ -83,8 +83,8 @@ discard block |
||
83 | 83 | */ |
84 | 84 | public static function set_definitions() |
85 | 85 | { |
86 | - define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
87 | - define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates/'); |
|
86 | + define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__).'assets/'); |
|
87 | + define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__).'templates/'); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | { |
226 | 226 | global $post; |
227 | 227 | return ((function_exists('wp_is_block_theme') && wp_is_block_theme()) || in_the_loop()) && $post->ID === (int) $id |
228 | - ? espresso_event_status_banner($post->ID) . $title |
|
228 | + ? espresso_event_status_banner($post->ID).$title |
|
229 | 229 | : $title; |
230 | 230 | } |
231 | 231 | |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | */ |
383 | 383 | public static function event_datetimes($content) |
384 | 384 | { |
385 | - return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
385 | + return EEH_Template::locate_template('content-espresso_events-datetimes.php').$content; |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | */ |
395 | 395 | public static function event_tickets($content) |
396 | 396 | { |
397 | - return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
397 | + return EEH_Template::locate_template('content-espresso_events-tickets.php').$content; |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | */ |
419 | 419 | public static function event_venues($content) |
420 | 420 | { |
421 | - return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
421 | + return $content.EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | |
@@ -448,16 +448,16 @@ discard block |
||
448 | 448 | && apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', true) |
449 | 449 | ) { |
450 | 450 | // first check uploads folder |
451 | - if (is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
451 | + if (is_readable(get_stylesheet_directory().$this->theme.'/style.css')) { |
|
452 | 452 | wp_register_style( |
453 | 453 | $this->theme, |
454 | - get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
454 | + get_stylesheet_directory_uri().$this->theme.'/style.css', |
|
455 | 455 | array('dashicons', 'espresso_default') |
456 | 456 | ); |
457 | 457 | } else { |
458 | 458 | wp_register_style( |
459 | 459 | $this->theme, |
460 | - EE_TEMPLATES_URL . $this->theme . '/style.css', |
|
460 | + EE_TEMPLATES_URL.$this->theme.'/style.css', |
|
461 | 461 | array('dashicons', 'espresso_default') |
462 | 462 | ); |
463 | 463 | } |
@@ -14,475 +14,475 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class EED_Event_Single extends EED_Module |
16 | 16 | { |
17 | - const EVENT_DETAILS_PRIORITY = 100; |
|
18 | - const EVENT_DATETIMES_PRIORITY = 110; |
|
19 | - const EVENT_TICKETS_PRIORITY = 120; |
|
20 | - const EVENT_VENUES_PRIORITY = 130; |
|
21 | - |
|
22 | - /** |
|
23 | - * @type bool $using_get_the_excerpt |
|
24 | - */ |
|
25 | - protected static $using_get_the_excerpt = false; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * @type EE_Template_Part_Manager $template_parts |
|
30 | - */ |
|
31 | - protected $template_parts; |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @return EED_Module|EED_Event_Single |
|
36 | - */ |
|
37 | - public static function instance() |
|
38 | - { |
|
39 | - return parent::get_instance(__CLASS__); |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
45 | - * |
|
46 | - * @return void |
|
47 | - * @throws InvalidArgumentException |
|
48 | - * @throws InvalidDataTypeException |
|
49 | - * @throws InvalidInterfaceException |
|
50 | - */ |
|
51 | - public static function set_hooks() |
|
52 | - { |
|
53 | - add_filter('FHEE_run_EE_wp', '__return_true'); |
|
54 | - add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2); |
|
55 | - /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */ |
|
56 | - $custom_post_type_definitions = LoaderFactory::getLoader()->getShared( |
|
57 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
58 | - ); |
|
59 | - $custom_post_types = $custom_post_type_definitions->getDefinitions(); |
|
60 | - EED_Module::registerRoute( |
|
61 | - $custom_post_types[EspressoPostType::EVENTS]['singular_slug'], |
|
62 | - 'Event_Single', |
|
63 | - 'run' |
|
64 | - ); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
69 | - * |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - public static function set_hooks_admin() |
|
73 | - { |
|
74 | - add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2); |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * set_definitions |
|
80 | - * |
|
81 | - * @static |
|
82 | - * @return void |
|
83 | - */ |
|
84 | - public static function set_definitions() |
|
85 | - { |
|
86 | - define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
87 | - define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates/'); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * set_config |
|
93 | - * |
|
94 | - * @void |
|
95 | - */ |
|
96 | - protected function set_config() |
|
97 | - { |
|
98 | - $this->set_config_section('template_settings'); |
|
99 | - $this->set_config_class('EE_Event_Single_Config'); |
|
100 | - $this->set_config_name('EED_Event_Single'); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * initialize_template_parts |
|
106 | - * |
|
107 | - * @param EE_Config_Base|EE_Event_Single_Config $config |
|
108 | - * @return EE_Template_Part_Manager |
|
109 | - * @throws EE_Error |
|
110 | - */ |
|
111 | - public function initialize_template_parts(EE_Event_Single_Config $config = null) |
|
112 | - { |
|
113 | - /** @type EE_Event_Single_Config $config */ |
|
114 | - $config = $config instanceof EE_Event_Single_Config ? $config : $this->config(); |
|
115 | - EEH_Autoloader::register_template_part_autoloaders(); |
|
116 | - $template_parts = new EE_Template_Part_Manager(); |
|
117 | - $template_parts->add_template_part( |
|
118 | - 'tickets', |
|
119 | - esc_html__('Ticket Selector', 'event_espresso'), |
|
120 | - 'content-espresso_events-tickets.php', |
|
121 | - $config->display_order_tickets |
|
122 | - ); |
|
123 | - $template_parts->add_template_part( |
|
124 | - 'datetimes', |
|
125 | - esc_html__('Dates and Times', 'event_espresso'), |
|
126 | - 'content-espresso_events-datetimes.php', |
|
127 | - $config->display_order_datetimes |
|
128 | - ); |
|
129 | - $template_parts->add_template_part( |
|
130 | - 'event', |
|
131 | - esc_html__('Event Description', 'event_espresso'), |
|
132 | - 'content-espresso_events-details.php', |
|
133 | - $config->display_order_event |
|
134 | - ); |
|
135 | - $template_parts->add_template_part( |
|
136 | - 'venue', |
|
137 | - esc_html__('Venue Information', 'event_espresso'), |
|
138 | - 'content-espresso_events-venues.php', |
|
139 | - $config->display_order_venue |
|
140 | - ); |
|
141 | - do_action('AHEE__EED_Event_Single__initialize_template_parts', $template_parts); |
|
142 | - return $template_parts; |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * run - initial module setup |
|
148 | - * |
|
149 | - * @param WP $WP |
|
150 | - * @return void |
|
151 | - */ |
|
152 | - public function run($WP) |
|
153 | - { |
|
154 | - // ensure valid EE_Events_Single_Config() object exists |
|
155 | - $this->set_config(); |
|
156 | - // check what template is loaded |
|
157 | - add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
158 | - add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
159 | - // load css |
|
160 | - add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * template_include |
|
166 | - * |
|
167 | - * @param string $template |
|
168 | - * @return string |
|
169 | - */ |
|
170 | - public function template_include($template) |
|
171 | - { |
|
172 | - global $post; |
|
173 | - /** @type EE_Event_Single_Config $config */ |
|
174 | - $config = $this->config(); |
|
175 | - if ($config->display_status_banner_single) { |
|
176 | - add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2); |
|
177 | - } |
|
178 | - // not a custom template? |
|
179 | - if ( |
|
180 | - ! post_password_required($post) |
|
181 | - && ( |
|
182 | - apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false) |
|
183 | - || EE_Registry::instance() |
|
184 | - ->load_core('Front_Controller') |
|
185 | - ->get_selected_template() !== 'single-espresso_events.php' |
|
186 | - ) |
|
187 | - ) { |
|
188 | - EEH_Template::load_espresso_theme_functions(); |
|
189 | - // then add extra event data via hooks |
|
190 | - add_action('loop_start', array('EED_Event_Single', 'loop_start')); |
|
191 | - add_filter('get_the_excerpt', array('EED_Event_Single', 'get_the_excerpt'), 1, 1); |
|
192 | - add_filter( |
|
193 | - 'the_content', |
|
194 | - array('EED_Event_Single', 'event_details'), |
|
195 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
196 | - ); |
|
197 | - add_action('loop_end', array('EED_Event_Single', 'loop_end')); |
|
198 | - // don't display entry meta because the existing theme will take car of that |
|
199 | - add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false'); |
|
200 | - } |
|
201 | - return $template; |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - /** |
|
206 | - * loop_start |
|
207 | - * |
|
208 | - * @param array $wp_query_array an array containing the WP_Query object |
|
209 | - * @return void |
|
210 | - */ |
|
211 | - public static function loop_start($wp_query_array) |
|
212 | - { |
|
213 | - global $post; |
|
214 | - do_action('AHEE_event_details_before_post', $post, $wp_query_array); |
|
215 | - } |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * the_title |
|
220 | - * |
|
221 | - * @param string $title |
|
222 | - * @param int $id |
|
223 | - * @return string |
|
224 | - */ |
|
225 | - public static function the_title($title = '', $id = 0) |
|
226 | - { |
|
227 | - global $post; |
|
228 | - return ((function_exists('wp_is_block_theme') && wp_is_block_theme()) || in_the_loop()) && $post->ID === (int) $id |
|
229 | - ? espresso_event_status_banner($post->ID) . $title |
|
230 | - : $title; |
|
231 | - } |
|
232 | - |
|
233 | - |
|
234 | - /** |
|
235 | - * get_the_excerpt |
|
236 | - * kinda hacky, but if a theme is using get_the_excerpt(), |
|
237 | - * then we need to remove our filters on the_content() |
|
238 | - * |
|
239 | - * @param string $excerpt |
|
240 | - * @return string |
|
241 | - */ |
|
242 | - public static function get_the_excerpt($excerpt = '') |
|
243 | - { |
|
244 | - EED_Event_Single::$using_get_the_excerpt = true; |
|
245 | - add_filter('wp_trim_excerpt', array('EED_Event_Single', 'end_get_the_excerpt'), 999, 1); |
|
246 | - return $excerpt; |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * end_get_the_excerpt |
|
252 | - * |
|
253 | - * @param string $text |
|
254 | - * @return string |
|
255 | - */ |
|
256 | - public static function end_get_the_excerpt($text = '') |
|
257 | - { |
|
258 | - EED_Event_Single::$using_get_the_excerpt = false; |
|
259 | - return $text; |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * event_details |
|
265 | - * |
|
266 | - * @param string $content |
|
267 | - * @return string |
|
268 | - */ |
|
269 | - public static function event_details($content) |
|
270 | - { |
|
271 | - global $post; |
|
272 | - static $current_post_ID = 0; |
|
273 | - if ( |
|
274 | - $current_post_ID !== $post->ID |
|
275 | - && $post->post_type === EspressoPostType::EVENTS |
|
276 | - && ! EED_Event_Single::$using_get_the_excerpt |
|
277 | - && ! post_password_required() |
|
278 | - ) { |
|
279 | - // Set current post ID to prevent showing content twice, but only if headers have definitely been sent. |
|
280 | - // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early |
|
281 | - // BEFORE headers are sent in order to examine the post content and generate content for the HTML header. |
|
282 | - // We want to allow those plugins to still do their thing and have access to our content, but depending on |
|
283 | - // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice, |
|
284 | - // so the following allows this filter to be applied multiple times, but only once for real |
|
285 | - $current_post_ID = did_action('loop_start') ? $post->ID : 0; |
|
286 | - if (EE_Registry::instance()->CFG->template_settings->EED_Event_Single->use_sortable_display_order) { |
|
287 | - // we need to first remove this callback from being applied to the_content() |
|
288 | - // (otherwise it will recurse and blow up the interweb) |
|
289 | - remove_filter( |
|
290 | - 'the_content', |
|
291 | - array('EED_Event_Single', 'event_details'), |
|
292 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
293 | - ); |
|
294 | - EED_Event_Single::instance()->template_parts = EED_Event_Single::instance()->initialize_template_parts( |
|
295 | - ); |
|
296 | - $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
297 | - $content = EED_Event_Single::instance()->template_parts->apply_template_part_filters($content); |
|
298 | - add_filter( |
|
299 | - 'the_content', |
|
300 | - array('EED_Event_Single', 'event_details'), |
|
301 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
302 | - ); |
|
303 | - } else { |
|
304 | - $content = EED_Event_Single::use_filterable_display_order(); |
|
305 | - } |
|
306 | - } |
|
307 | - return $content; |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * use_filterable_display_order |
|
313 | - * |
|
314 | - * @return string |
|
315 | - */ |
|
316 | - protected static function use_filterable_display_order() |
|
317 | - { |
|
318 | - // since the 'content-espresso_events-details.php' template might be used directly from within a theme, |
|
319 | - // it uses the_content() for displaying the $post->post_content |
|
320 | - // so in order to load a template that uses the_content() |
|
321 | - // from within a callback being used to filter the_content(), |
|
322 | - // we need to first remove this callback from being applied to the_content() |
|
323 | - // (otherwise it will recurse and blow up the interweb) |
|
324 | - remove_filter( |
|
325 | - 'the_content', |
|
326 | - array('EED_Event_Single', 'event_details'), |
|
327 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
328 | - ); |
|
329 | - // now add additional content |
|
330 | - add_filter( |
|
331 | - 'the_content', |
|
332 | - array('EED_Event_Single', 'event_datetimes'), |
|
333 | - EED_Event_Single::EVENT_DATETIMES_PRIORITY, |
|
334 | - 1 |
|
335 | - ); |
|
336 | - add_filter( |
|
337 | - 'the_content', |
|
338 | - array('EED_Event_Single', 'event_tickets'), |
|
339 | - EED_Event_Single::EVENT_TICKETS_PRIORITY, |
|
340 | - 1 |
|
341 | - ); |
|
342 | - add_filter( |
|
343 | - 'the_content', |
|
344 | - array('EED_Event_Single', 'event_venues'), |
|
345 | - EED_Event_Single::EVENT_VENUES_PRIORITY, |
|
346 | - 1 |
|
347 | - ); |
|
348 | - do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_add_filters'); |
|
349 | - // now load our template |
|
350 | - $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
351 | - // now add our filter back in, plus some others |
|
352 | - add_filter( |
|
353 | - 'the_content', |
|
354 | - array('EED_Event_Single', 'event_details'), |
|
355 | - EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
356 | - ); |
|
357 | - remove_filter( |
|
358 | - 'the_content', |
|
359 | - array('EED_Event_Single', 'event_datetimes'), |
|
360 | - EED_Event_Single::EVENT_DATETIMES_PRIORITY |
|
361 | - ); |
|
362 | - remove_filter( |
|
363 | - 'the_content', |
|
364 | - array('EED_Event_Single', 'event_tickets'), |
|
365 | - EED_Event_Single::EVENT_TICKETS_PRIORITY |
|
366 | - ); |
|
367 | - remove_filter( |
|
368 | - 'the_content', |
|
369 | - array('EED_Event_Single', 'event_venues'), |
|
370 | - EED_Event_Single::EVENT_VENUES_PRIORITY |
|
371 | - ); |
|
372 | - do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_remove_filters'); |
|
373 | - // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
374 | - return $content; |
|
375 | - } |
|
376 | - |
|
377 | - |
|
378 | - /** |
|
379 | - * event_datetimes - adds datetimes ABOVE content |
|
380 | - * |
|
381 | - * @param string $content |
|
382 | - * @return string |
|
383 | - */ |
|
384 | - public static function event_datetimes($content) |
|
385 | - { |
|
386 | - return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * event_tickets - adds tickets ABOVE content (which includes datetimes) |
|
392 | - * |
|
393 | - * @param string $content |
|
394 | - * @return string |
|
395 | - */ |
|
396 | - public static function event_tickets($content) |
|
397 | - { |
|
398 | - return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * event_venues |
|
404 | - * |
|
405 | - * @param string $content |
|
406 | - * @return string |
|
407 | - */ |
|
408 | - public static function event_venue($content) |
|
409 | - { |
|
410 | - return EED_Event_Single::event_venues($content); |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * event_venues - adds venues BELOW content |
|
416 | - * |
|
417 | - * @param string $content |
|
418 | - * @return string |
|
419 | - */ |
|
420 | - public static function event_venues($content) |
|
421 | - { |
|
422 | - return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
423 | - } |
|
424 | - |
|
425 | - |
|
426 | - /** |
|
427 | - * loop_end |
|
428 | - * |
|
429 | - * @param array $wp_query_array an array containing the WP_Query object |
|
430 | - * @return void |
|
431 | - */ |
|
432 | - public static function loop_end($wp_query_array) |
|
433 | - { |
|
434 | - global $post; |
|
435 | - do_action('AHEE_event_details_after_post', $post, $wp_query_array); |
|
436 | - } |
|
437 | - |
|
438 | - |
|
439 | - /** |
|
440 | - * wp_enqueue_scripts |
|
441 | - * |
|
442 | - * @return void |
|
443 | - */ |
|
444 | - public function wp_enqueue_scripts() |
|
445 | - { |
|
446 | - // get some style |
|
447 | - if ( |
|
448 | - apply_filters('FHEE_enable_default_espresso_css', true) |
|
449 | - && apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', true) |
|
450 | - ) { |
|
451 | - // first check uploads folder |
|
452 | - if (is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
453 | - wp_register_style( |
|
454 | - $this->theme, |
|
455 | - get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
456 | - array('dashicons', 'espresso_default') |
|
457 | - ); |
|
458 | - } else { |
|
459 | - wp_register_style( |
|
460 | - $this->theme, |
|
461 | - EE_TEMPLATES_URL . $this->theme . '/style.css', |
|
462 | - array('dashicons', 'espresso_default') |
|
463 | - ); |
|
464 | - } |
|
465 | - wp_enqueue_script($this->theme); |
|
466 | - if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
467 | - add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
468 | - } |
|
469 | - } |
|
470 | - } |
|
471 | - |
|
472 | - |
|
473 | - /** |
|
474 | - * display_venue |
|
475 | - * |
|
476 | - * @return bool |
|
477 | - */ |
|
478 | - public static function display_venue() |
|
479 | - { |
|
480 | - /** @type EE_Event_Single_Config $config */ |
|
481 | - $config = EED_Event_Single::instance()->config(); |
|
482 | - $display_venue = $config->display_venue === null ? true : $config->display_venue; |
|
483 | - $venue_name = EEH_Venue_View::venue_name(); |
|
484 | - return $display_venue && ! empty($venue_name); |
|
485 | - } |
|
17 | + const EVENT_DETAILS_PRIORITY = 100; |
|
18 | + const EVENT_DATETIMES_PRIORITY = 110; |
|
19 | + const EVENT_TICKETS_PRIORITY = 120; |
|
20 | + const EVENT_VENUES_PRIORITY = 130; |
|
21 | + |
|
22 | + /** |
|
23 | + * @type bool $using_get_the_excerpt |
|
24 | + */ |
|
25 | + protected static $using_get_the_excerpt = false; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * @type EE_Template_Part_Manager $template_parts |
|
30 | + */ |
|
31 | + protected $template_parts; |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @return EED_Module|EED_Event_Single |
|
36 | + */ |
|
37 | + public static function instance() |
|
38 | + { |
|
39 | + return parent::get_instance(__CLASS__); |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
45 | + * |
|
46 | + * @return void |
|
47 | + * @throws InvalidArgumentException |
|
48 | + * @throws InvalidDataTypeException |
|
49 | + * @throws InvalidInterfaceException |
|
50 | + */ |
|
51 | + public static function set_hooks() |
|
52 | + { |
|
53 | + add_filter('FHEE_run_EE_wp', '__return_true'); |
|
54 | + add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2); |
|
55 | + /** @var EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions $custom_post_type_definitions */ |
|
56 | + $custom_post_type_definitions = LoaderFactory::getLoader()->getShared( |
|
57 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
58 | + ); |
|
59 | + $custom_post_types = $custom_post_type_definitions->getDefinitions(); |
|
60 | + EED_Module::registerRoute( |
|
61 | + $custom_post_types[EspressoPostType::EVENTS]['singular_slug'], |
|
62 | + 'Event_Single', |
|
63 | + 'run' |
|
64 | + ); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
69 | + * |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + public static function set_hooks_admin() |
|
73 | + { |
|
74 | + add_action('wp_loaded', array('EED_Event_Single', 'set_definitions'), 2); |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * set_definitions |
|
80 | + * |
|
81 | + * @static |
|
82 | + * @return void |
|
83 | + */ |
|
84 | + public static function set_definitions() |
|
85 | + { |
|
86 | + define('EVENT_SINGLE_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
87 | + define('EVENT_SINGLE_TEMPLATES_PATH', plugin_dir_path(__FILE__) . 'templates/'); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * set_config |
|
93 | + * |
|
94 | + * @void |
|
95 | + */ |
|
96 | + protected function set_config() |
|
97 | + { |
|
98 | + $this->set_config_section('template_settings'); |
|
99 | + $this->set_config_class('EE_Event_Single_Config'); |
|
100 | + $this->set_config_name('EED_Event_Single'); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * initialize_template_parts |
|
106 | + * |
|
107 | + * @param EE_Config_Base|EE_Event_Single_Config $config |
|
108 | + * @return EE_Template_Part_Manager |
|
109 | + * @throws EE_Error |
|
110 | + */ |
|
111 | + public function initialize_template_parts(EE_Event_Single_Config $config = null) |
|
112 | + { |
|
113 | + /** @type EE_Event_Single_Config $config */ |
|
114 | + $config = $config instanceof EE_Event_Single_Config ? $config : $this->config(); |
|
115 | + EEH_Autoloader::register_template_part_autoloaders(); |
|
116 | + $template_parts = new EE_Template_Part_Manager(); |
|
117 | + $template_parts->add_template_part( |
|
118 | + 'tickets', |
|
119 | + esc_html__('Ticket Selector', 'event_espresso'), |
|
120 | + 'content-espresso_events-tickets.php', |
|
121 | + $config->display_order_tickets |
|
122 | + ); |
|
123 | + $template_parts->add_template_part( |
|
124 | + 'datetimes', |
|
125 | + esc_html__('Dates and Times', 'event_espresso'), |
|
126 | + 'content-espresso_events-datetimes.php', |
|
127 | + $config->display_order_datetimes |
|
128 | + ); |
|
129 | + $template_parts->add_template_part( |
|
130 | + 'event', |
|
131 | + esc_html__('Event Description', 'event_espresso'), |
|
132 | + 'content-espresso_events-details.php', |
|
133 | + $config->display_order_event |
|
134 | + ); |
|
135 | + $template_parts->add_template_part( |
|
136 | + 'venue', |
|
137 | + esc_html__('Venue Information', 'event_espresso'), |
|
138 | + 'content-espresso_events-venues.php', |
|
139 | + $config->display_order_venue |
|
140 | + ); |
|
141 | + do_action('AHEE__EED_Event_Single__initialize_template_parts', $template_parts); |
|
142 | + return $template_parts; |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * run - initial module setup |
|
148 | + * |
|
149 | + * @param WP $WP |
|
150 | + * @return void |
|
151 | + */ |
|
152 | + public function run($WP) |
|
153 | + { |
|
154 | + // ensure valid EE_Events_Single_Config() object exists |
|
155 | + $this->set_config(); |
|
156 | + // check what template is loaded |
|
157 | + add_filter('template_include', array($this, 'template_include'), 999, 1); |
|
158 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
159 | + // load css |
|
160 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * template_include |
|
166 | + * |
|
167 | + * @param string $template |
|
168 | + * @return string |
|
169 | + */ |
|
170 | + public function template_include($template) |
|
171 | + { |
|
172 | + global $post; |
|
173 | + /** @type EE_Event_Single_Config $config */ |
|
174 | + $config = $this->config(); |
|
175 | + if ($config->display_status_banner_single) { |
|
176 | + add_filter('the_title', array('EED_Event_Single', 'the_title'), 100, 2); |
|
177 | + } |
|
178 | + // not a custom template? |
|
179 | + if ( |
|
180 | + ! post_password_required($post) |
|
181 | + && ( |
|
182 | + apply_filters('FHEE__EED_Event_Single__template_include__allow_custom_selected_template', false) |
|
183 | + || EE_Registry::instance() |
|
184 | + ->load_core('Front_Controller') |
|
185 | + ->get_selected_template() !== 'single-espresso_events.php' |
|
186 | + ) |
|
187 | + ) { |
|
188 | + EEH_Template::load_espresso_theme_functions(); |
|
189 | + // then add extra event data via hooks |
|
190 | + add_action('loop_start', array('EED_Event_Single', 'loop_start')); |
|
191 | + add_filter('get_the_excerpt', array('EED_Event_Single', 'get_the_excerpt'), 1, 1); |
|
192 | + add_filter( |
|
193 | + 'the_content', |
|
194 | + array('EED_Event_Single', 'event_details'), |
|
195 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
196 | + ); |
|
197 | + add_action('loop_end', array('EED_Event_Single', 'loop_end')); |
|
198 | + // don't display entry meta because the existing theme will take car of that |
|
199 | + add_filter('FHEE__content_espresso_events_details_template__display_entry_meta', '__return_false'); |
|
200 | + } |
|
201 | + return $template; |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + /** |
|
206 | + * loop_start |
|
207 | + * |
|
208 | + * @param array $wp_query_array an array containing the WP_Query object |
|
209 | + * @return void |
|
210 | + */ |
|
211 | + public static function loop_start($wp_query_array) |
|
212 | + { |
|
213 | + global $post; |
|
214 | + do_action('AHEE_event_details_before_post', $post, $wp_query_array); |
|
215 | + } |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * the_title |
|
220 | + * |
|
221 | + * @param string $title |
|
222 | + * @param int $id |
|
223 | + * @return string |
|
224 | + */ |
|
225 | + public static function the_title($title = '', $id = 0) |
|
226 | + { |
|
227 | + global $post; |
|
228 | + return ((function_exists('wp_is_block_theme') && wp_is_block_theme()) || in_the_loop()) && $post->ID === (int) $id |
|
229 | + ? espresso_event_status_banner($post->ID) . $title |
|
230 | + : $title; |
|
231 | + } |
|
232 | + |
|
233 | + |
|
234 | + /** |
|
235 | + * get_the_excerpt |
|
236 | + * kinda hacky, but if a theme is using get_the_excerpt(), |
|
237 | + * then we need to remove our filters on the_content() |
|
238 | + * |
|
239 | + * @param string $excerpt |
|
240 | + * @return string |
|
241 | + */ |
|
242 | + public static function get_the_excerpt($excerpt = '') |
|
243 | + { |
|
244 | + EED_Event_Single::$using_get_the_excerpt = true; |
|
245 | + add_filter('wp_trim_excerpt', array('EED_Event_Single', 'end_get_the_excerpt'), 999, 1); |
|
246 | + return $excerpt; |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * end_get_the_excerpt |
|
252 | + * |
|
253 | + * @param string $text |
|
254 | + * @return string |
|
255 | + */ |
|
256 | + public static function end_get_the_excerpt($text = '') |
|
257 | + { |
|
258 | + EED_Event_Single::$using_get_the_excerpt = false; |
|
259 | + return $text; |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * event_details |
|
265 | + * |
|
266 | + * @param string $content |
|
267 | + * @return string |
|
268 | + */ |
|
269 | + public static function event_details($content) |
|
270 | + { |
|
271 | + global $post; |
|
272 | + static $current_post_ID = 0; |
|
273 | + if ( |
|
274 | + $current_post_ID !== $post->ID |
|
275 | + && $post->post_type === EspressoPostType::EVENTS |
|
276 | + && ! EED_Event_Single::$using_get_the_excerpt |
|
277 | + && ! post_password_required() |
|
278 | + ) { |
|
279 | + // Set current post ID to prevent showing content twice, but only if headers have definitely been sent. |
|
280 | + // Reason being is that some plugins, like Yoast, need to run through a copy of the loop early |
|
281 | + // BEFORE headers are sent in order to examine the post content and generate content for the HTML header. |
|
282 | + // We want to allow those plugins to still do their thing and have access to our content, but depending on |
|
283 | + // how your event content is being displayed (shortcode, CPT route, etc), this filter can get applied twice, |
|
284 | + // so the following allows this filter to be applied multiple times, but only once for real |
|
285 | + $current_post_ID = did_action('loop_start') ? $post->ID : 0; |
|
286 | + if (EE_Registry::instance()->CFG->template_settings->EED_Event_Single->use_sortable_display_order) { |
|
287 | + // we need to first remove this callback from being applied to the_content() |
|
288 | + // (otherwise it will recurse and blow up the interweb) |
|
289 | + remove_filter( |
|
290 | + 'the_content', |
|
291 | + array('EED_Event_Single', 'event_details'), |
|
292 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
293 | + ); |
|
294 | + EED_Event_Single::instance()->template_parts = EED_Event_Single::instance()->initialize_template_parts( |
|
295 | + ); |
|
296 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
297 | + $content = EED_Event_Single::instance()->template_parts->apply_template_part_filters($content); |
|
298 | + add_filter( |
|
299 | + 'the_content', |
|
300 | + array('EED_Event_Single', 'event_details'), |
|
301 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
302 | + ); |
|
303 | + } else { |
|
304 | + $content = EED_Event_Single::use_filterable_display_order(); |
|
305 | + } |
|
306 | + } |
|
307 | + return $content; |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * use_filterable_display_order |
|
313 | + * |
|
314 | + * @return string |
|
315 | + */ |
|
316 | + protected static function use_filterable_display_order() |
|
317 | + { |
|
318 | + // since the 'content-espresso_events-details.php' template might be used directly from within a theme, |
|
319 | + // it uses the_content() for displaying the $post->post_content |
|
320 | + // so in order to load a template that uses the_content() |
|
321 | + // from within a callback being used to filter the_content(), |
|
322 | + // we need to first remove this callback from being applied to the_content() |
|
323 | + // (otherwise it will recurse and blow up the interweb) |
|
324 | + remove_filter( |
|
325 | + 'the_content', |
|
326 | + array('EED_Event_Single', 'event_details'), |
|
327 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
328 | + ); |
|
329 | + // now add additional content |
|
330 | + add_filter( |
|
331 | + 'the_content', |
|
332 | + array('EED_Event_Single', 'event_datetimes'), |
|
333 | + EED_Event_Single::EVENT_DATETIMES_PRIORITY, |
|
334 | + 1 |
|
335 | + ); |
|
336 | + add_filter( |
|
337 | + 'the_content', |
|
338 | + array('EED_Event_Single', 'event_tickets'), |
|
339 | + EED_Event_Single::EVENT_TICKETS_PRIORITY, |
|
340 | + 1 |
|
341 | + ); |
|
342 | + add_filter( |
|
343 | + 'the_content', |
|
344 | + array('EED_Event_Single', 'event_venues'), |
|
345 | + EED_Event_Single::EVENT_VENUES_PRIORITY, |
|
346 | + 1 |
|
347 | + ); |
|
348 | + do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_add_filters'); |
|
349 | + // now load our template |
|
350 | + $content = EEH_Template::locate_template('content-espresso_events-details.php'); |
|
351 | + // now add our filter back in, plus some others |
|
352 | + add_filter( |
|
353 | + 'the_content', |
|
354 | + array('EED_Event_Single', 'event_details'), |
|
355 | + EED_Event_Single::EVENT_DETAILS_PRIORITY |
|
356 | + ); |
|
357 | + remove_filter( |
|
358 | + 'the_content', |
|
359 | + array('EED_Event_Single', 'event_datetimes'), |
|
360 | + EED_Event_Single::EVENT_DATETIMES_PRIORITY |
|
361 | + ); |
|
362 | + remove_filter( |
|
363 | + 'the_content', |
|
364 | + array('EED_Event_Single', 'event_tickets'), |
|
365 | + EED_Event_Single::EVENT_TICKETS_PRIORITY |
|
366 | + ); |
|
367 | + remove_filter( |
|
368 | + 'the_content', |
|
369 | + array('EED_Event_Single', 'event_venues'), |
|
370 | + EED_Event_Single::EVENT_VENUES_PRIORITY |
|
371 | + ); |
|
372 | + do_action('AHEE__EED_Event_Single__use_filterable_display_order__after_remove_filters'); |
|
373 | + // we're not returning the $content directly because the template we are loading uses the_content (or the_excerpt) |
|
374 | + return $content; |
|
375 | + } |
|
376 | + |
|
377 | + |
|
378 | + /** |
|
379 | + * event_datetimes - adds datetimes ABOVE content |
|
380 | + * |
|
381 | + * @param string $content |
|
382 | + * @return string |
|
383 | + */ |
|
384 | + public static function event_datetimes($content) |
|
385 | + { |
|
386 | + return EEH_Template::locate_template('content-espresso_events-datetimes.php') . $content; |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * event_tickets - adds tickets ABOVE content (which includes datetimes) |
|
392 | + * |
|
393 | + * @param string $content |
|
394 | + * @return string |
|
395 | + */ |
|
396 | + public static function event_tickets($content) |
|
397 | + { |
|
398 | + return EEH_Template::locate_template('content-espresso_events-tickets.php') . $content; |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * event_venues |
|
404 | + * |
|
405 | + * @param string $content |
|
406 | + * @return string |
|
407 | + */ |
|
408 | + public static function event_venue($content) |
|
409 | + { |
|
410 | + return EED_Event_Single::event_venues($content); |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * event_venues - adds venues BELOW content |
|
416 | + * |
|
417 | + * @param string $content |
|
418 | + * @return string |
|
419 | + */ |
|
420 | + public static function event_venues($content) |
|
421 | + { |
|
422 | + return $content . EEH_Template::locate_template('content-espresso_events-venues.php'); |
|
423 | + } |
|
424 | + |
|
425 | + |
|
426 | + /** |
|
427 | + * loop_end |
|
428 | + * |
|
429 | + * @param array $wp_query_array an array containing the WP_Query object |
|
430 | + * @return void |
|
431 | + */ |
|
432 | + public static function loop_end($wp_query_array) |
|
433 | + { |
|
434 | + global $post; |
|
435 | + do_action('AHEE_event_details_after_post', $post, $wp_query_array); |
|
436 | + } |
|
437 | + |
|
438 | + |
|
439 | + /** |
|
440 | + * wp_enqueue_scripts |
|
441 | + * |
|
442 | + * @return void |
|
443 | + */ |
|
444 | + public function wp_enqueue_scripts() |
|
445 | + { |
|
446 | + // get some style |
|
447 | + if ( |
|
448 | + apply_filters('FHEE_enable_default_espresso_css', true) |
|
449 | + && apply_filters('FHEE__EED_Event_Single__wp_enqueue_scripts__enable_css', true) |
|
450 | + ) { |
|
451 | + // first check uploads folder |
|
452 | + if (is_readable(get_stylesheet_directory() . $this->theme . '/style.css')) { |
|
453 | + wp_register_style( |
|
454 | + $this->theme, |
|
455 | + get_stylesheet_directory_uri() . $this->theme . '/style.css', |
|
456 | + array('dashicons', 'espresso_default') |
|
457 | + ); |
|
458 | + } else { |
|
459 | + wp_register_style( |
|
460 | + $this->theme, |
|
461 | + EE_TEMPLATES_URL . $this->theme . '/style.css', |
|
462 | + array('dashicons', 'espresso_default') |
|
463 | + ); |
|
464 | + } |
|
465 | + wp_enqueue_script($this->theme); |
|
466 | + if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
467 | + add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
468 | + } |
|
469 | + } |
|
470 | + } |
|
471 | + |
|
472 | + |
|
473 | + /** |
|
474 | + * display_venue |
|
475 | + * |
|
476 | + * @return bool |
|
477 | + */ |
|
478 | + public static function display_venue() |
|
479 | + { |
|
480 | + /** @type EE_Event_Single_Config $config */ |
|
481 | + $config = EED_Event_Single::instance()->config(); |
|
482 | + $display_venue = $config->display_venue === null ? true : $config->display_venue; |
|
483 | + $venue_name = EEH_Venue_View::venue_name(); |
|
484 | + return $display_venue && ! empty($venue_name); |
|
485 | + } |
|
486 | 486 | } |
487 | 487 | |
488 | 488 | |
@@ -494,5 +494,5 @@ discard block |
||
494 | 494 | */ |
495 | 495 | function espresso_display_venue_in_event_details() |
496 | 496 | { |
497 | - return EED_Event_Single::display_venue(); |
|
497 | + return EED_Event_Single::display_venue(); |
|
498 | 498 | } |
@@ -6,15 +6,15 @@ discard block |
||
6 | 6 | </p> |
7 | 7 | <p> |
8 | 8 | <?php |
9 | - printf( |
|
10 | - esc_html__( |
|
11 | - 'See %1$shere%2$s for list of currencies supported by Authorize.net AIM.', |
|
12 | - 'event_espresso' |
|
13 | - ), |
|
14 | - "<a href='https://support.authorize.net/s/article/Which-Currencies-Does-Authorize-Net-Support/' target='_blank' rel='noopener noreferrer'>", |
|
15 | - "</a>" |
|
16 | - ); |
|
17 | - ?> |
|
9 | + printf( |
|
10 | + esc_html__( |
|
11 | + 'See %1$shere%2$s for list of currencies supported by Authorize.net AIM.', |
|
12 | + 'event_espresso' |
|
13 | + ), |
|
14 | + "<a href='https://support.authorize.net/s/article/Which-Currencies-Does-Authorize-Net-Support/' target='_blank' rel='noopener noreferrer'>", |
|
15 | + "</a>" |
|
16 | + ); |
|
17 | + ?> |
|
18 | 18 | </p> |
19 | 19 | <p> |
20 | 20 | <strong><?php esc_html_e('Authorize.net AIM Settings', 'event_espresso'); ?></strong> |
@@ -24,70 +24,70 @@ discard block |
||
24 | 24 | <strong><?php esc_html_e('Authorize.net API Login ID', 'event_espresso'); ?></strong> |
25 | 25 | <br/> |
26 | 26 | <?php |
27 | - printf( |
|
28 | - esc_html__( |
|
29 | - 'Enter your API Login ID for Authorize.net. Learn how to find your %1$sAPI Login%2$s ID.', |
|
30 | - 'event_espresso' |
|
31 | - ), |
|
32 | - '<a href="https://support.authorize.net/authkb/index?page=content&id=A405" target="_blank" rel="noopener noreferrer">', |
|
33 | - '</a>' |
|
34 | - ); |
|
35 | - ?> |
|
27 | + printf( |
|
28 | + esc_html__( |
|
29 | + 'Enter your API Login ID for Authorize.net. Learn how to find your %1$sAPI Login%2$s ID.', |
|
30 | + 'event_espresso' |
|
31 | + ), |
|
32 | + '<a href="https://support.authorize.net/authkb/index?page=content&id=A405" target="_blank" rel="noopener noreferrer">', |
|
33 | + '</a>' |
|
34 | + ); |
|
35 | + ?> |
|
36 | 36 | </li> |
37 | 37 | <li> |
38 | 38 | <strong><?php esc_html_e('Authorize.net Transaction Key', 'event_espresso'); ?></strong> |
39 | 39 | <br/> |
40 | 40 | <?php |
41 | - printf( |
|
42 | - esc_html__( |
|
43 | - 'Enter your Transaction Key for Authorize.net. Learn how to find your %1$sTransaction Key%2$s.', |
|
44 | - 'event_espresso' |
|
45 | - ), |
|
46 | - '<a href="https://support.authorize.net/authkb/index?page=content&id=A405" target="_blank" rel="noopener noreferrer">', |
|
47 | - '</a>' |
|
48 | - ); |
|
49 | - ?> |
|
41 | + printf( |
|
42 | + esc_html__( |
|
43 | + 'Enter your Transaction Key for Authorize.net. Learn how to find your %1$sTransaction Key%2$s.', |
|
44 | + 'event_espresso' |
|
45 | + ), |
|
46 | + '<a href="https://support.authorize.net/authkb/index?page=content&id=A405" target="_blank" rel="noopener noreferrer">', |
|
47 | + '</a>' |
|
48 | + ); |
|
49 | + ?> |
|
50 | 50 | </li> |
51 | 51 | <li> |
52 | 52 | <strong> |
53 | 53 | <?php esc_html_e( |
54 | - 'Is this an account on the Authorize.net development server?', |
|
55 | - 'event_espresso' |
|
56 | - ); ?> |
|
54 | + 'Is this an account on the Authorize.net development server?', |
|
55 | + 'event_espresso' |
|
56 | + ); ?> |
|
57 | 57 | </strong> |
58 | 58 | <br/> |
59 | 59 | <?php esc_html_e( |
60 | - 'Specify whether this is a live/production account or a test account on the Authorize.net development server.', |
|
61 | - 'event_espresso' |
|
62 | - ); ?> |
|
60 | + 'Specify whether this is a live/production account or a test account on the Authorize.net development server.', |
|
61 | + 'event_espresso' |
|
62 | + ); ?> |
|
63 | 63 | </li> |
64 | 64 | <li> |
65 | 65 | <strong><?php esc_html_e('Do you want to submit a test transaction?', 'event_espresso'); ?></strong> |
66 | 66 | <br/> |
67 | 67 | <?php esc_html_e( |
68 | - 'Specify if you want to test the Authorize.net AIM payment gateway by submitting a test transaction. Be sure to turn this setting off when you are done testing.', |
|
69 | - 'event_espresso' |
|
70 | - ); ?> |
|
68 | + 'Specify if you want to test the Authorize.net AIM payment gateway by submitting a test transaction. Be sure to turn this setting off when you are done testing.', |
|
69 | + 'event_espresso' |
|
70 | + ); ?> |
|
71 | 71 | </li> |
72 | 72 | <li> |
73 | 73 | <strong><?php esc_html_e('Excluded and Required Payment Form Fields', 'event_espresso'); ?></strong> |
74 | 74 | <br/> |
75 | 75 | <?php esc_html_e( |
76 | - 'By logging into Authorize.net, you can change which payment fields are required by Authorize.net when processing payments. These settings affect both the Advanced Integration Method (AIM, this) and the Simple Integration Method (SIM, different). The payment method settings "Excluded Payment Form Fields" and "Required Payment Form Fields" allow you to change the billing form in Event Espresso to reflect your payment form settings in Authorize.net.', |
|
77 | - 'event_espresso' |
|
78 | - ); ?> |
|
76 | + 'By logging into Authorize.net, you can change which payment fields are required by Authorize.net when processing payments. These settings affect both the Advanced Integration Method (AIM, this) and the Simple Integration Method (SIM, different). The payment method settings "Excluded Payment Form Fields" and "Required Payment Form Fields" allow you to change the billing form in Event Espresso to reflect your payment form settings in Authorize.net.', |
|
77 | + 'event_espresso' |
|
78 | + ); ?> |
|
79 | 79 | <br> |
80 | 80 | <?php printf( |
81 | - esc_html__( |
|
82 | - 'To change your payment form settings in Authorize.net, %1$slog in to authorize.net%2$s, go to %3$sAccount then Payment Form%2$s, then %4$sForm Fields%2$s. It will look similar to %5$sthis%2$s. If you make a field required in Authorize.net, you should also make it required in Event Espresso. If it isn\'t required in Authorize.net, and you want to simplify the billing form in Event Espresso, you can exclude it from the Event Espresso Form too.', |
|
83 | - 'event_espresso' |
|
84 | - ), |
|
85 | - '<a href="http://authorize.net" target="_blank" rel="noopener noreferrer">', |
|
86 | - '</a>', |
|
87 | - '<a href="https://monosnap.com/file/nebVteOkEXcdDIos88SojStWOifP23" target="_blank" rel="noopener noreferrer">', |
|
88 | - '<a href="https://monosnap.com/file/WyxGJtev87TcDmdGBEZ2oi1xaBIQAm" target="_blank" rel="noopener noreferrer">', |
|
89 | - '<a href="https://monosnap.com/image/DbCJNfEesWXeSNUs1wLIpGYODFw52m" target="_blank" rel="noopener noreferrer">' |
|
90 | - ); ?> |
|
81 | + esc_html__( |
|
82 | + 'To change your payment form settings in Authorize.net, %1$slog in to authorize.net%2$s, go to %3$sAccount then Payment Form%2$s, then %4$sForm Fields%2$s. It will look similar to %5$sthis%2$s. If you make a field required in Authorize.net, you should also make it required in Event Espresso. If it isn\'t required in Authorize.net, and you want to simplify the billing form in Event Espresso, you can exclude it from the Event Espresso Form too.', |
|
83 | + 'event_espresso' |
|
84 | + ), |
|
85 | + '<a href="http://authorize.net" target="_blank" rel="noopener noreferrer">', |
|
86 | + '</a>', |
|
87 | + '<a href="https://monosnap.com/file/nebVteOkEXcdDIos88SojStWOifP23" target="_blank" rel="noopener noreferrer">', |
|
88 | + '<a href="https://monosnap.com/file/WyxGJtev87TcDmdGBEZ2oi1xaBIQAm" target="_blank" rel="noopener noreferrer">', |
|
89 | + '<a href="https://monosnap.com/image/DbCJNfEesWXeSNUs1wLIpGYODFw52m" target="_blank" rel="noopener noreferrer">' |
|
90 | + ); ?> |
|
91 | 91 | </li> |
92 | 92 | <li> |
93 | 93 | <strong><?php esc_html_e('Button Image URL', 'event_espresso'); ?></strong> |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | <li> |
98 | 98 | <strong><?php esc_html_e('Note About Special Characters', 'event_espresso'); ?></strong> |
99 | 99 | <?php esc_html_e( |
100 | - 'If your event name, ticket name or ticket description contain special characters (eg emojis, foreign language characters, or curly quotes) they will be removed when sent to Authorize.net. This is because Authorize.net doesn\'t support them.', |
|
101 | - 'event_espresso' |
|
102 | - ); ?> |
|
100 | + 'If your event name, ticket name or ticket description contain special characters (eg emojis, foreign language characters, or curly quotes) they will be removed when sent to Authorize.net. This is because Authorize.net doesn\'t support them.', |
|
101 | + 'event_espresso' |
|
102 | + ); ?> |
|
103 | 103 | </li> |
104 | 104 | </ul> |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | protected static function _set_hooks_for_changes() |
132 | 132 | { |
133 | - $folder_contents = EEH_File::get_contents_of_folders([EE_LIBRARIES . 'rest_api/changes'], false); |
|
133 | + $folder_contents = EEH_File::get_contents_of_folders([EE_LIBRARIES.'rest_api/changes'], false); |
|
134 | 134 | foreach ($folder_contents as $classname_in_namespace => $filepath) { |
135 | 135 | // ignore the base parent class |
136 | 136 | // and legacy named classes |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | ) { |
141 | 141 | continue; |
142 | 142 | } |
143 | - $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
143 | + $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\'.$classname_in_namespace; |
|
144 | 144 | if (class_exists($full_classname)) { |
145 | 145 | $instance_of_class = new $full_classname(); |
146 | 146 | if ($instance_of_class instanceof ChangesInBase) { |
@@ -186,10 +186,10 @@ discard block |
||
186 | 186 | * } |
187 | 187 | */ |
188 | 188 | // skip route options |
189 | - if (! is_numeric($endpoint_key)) { |
|
189 | + if ( ! is_numeric($endpoint_key)) { |
|
190 | 190 | continue; |
191 | 191 | } |
192 | - if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
192 | + if ( ! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
193 | 193 | throw new EE_Error( |
194 | 194 | esc_html__( |
195 | 195 | // @codingStandardsIgnoreStart |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | } |
211 | 211 | if (isset($data_for_single_endpoint['callback_args'])) { |
212 | 212 | $callback_args = $data_for_single_endpoint['callback_args']; |
213 | - $single_endpoint_args['callback'] = static function (WP_REST_Request $request) use ( |
|
213 | + $single_endpoint_args['callback'] = static function(WP_REST_Request $request) use ( |
|
214 | 214 | $callback, |
215 | 215 | $callback_args |
216 | 216 | ) { |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | // the REST API will issue a _doing_it_wrong notice. |
228 | 228 | // Since the EE REST API defers capabilities to the db model system, |
229 | 229 | // we will just use the generic WP callback for public endpoints |
230 | - if (! isset($single_endpoint_args['permission_callback'])) { |
|
230 | + if ( ! isset($single_endpoint_args['permission_callback'])) { |
|
231 | 231 | $single_endpoint_args['permission_callback'] = '__return_true'; |
232 | 232 | } |
233 | 233 | $multiple_endpoint_args[] = $single_endpoint_args; |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | $schema_route_data = $data_for_multiple_endpoints['schema']; |
237 | 237 | $schema_callback = $schema_route_data['schema_callback']; |
238 | 238 | $callback_args = $schema_route_data['callback_args']; |
239 | - $multiple_endpoint_args['schema'] = static function () use ($schema_callback, $callback_args) { |
|
239 | + $multiple_endpoint_args['schema'] = static function() use ($schema_callback, $callback_args) { |
|
240 | 240 | return call_user_func_array( |
241 | 241 | $schema_callback, |
242 | 242 | $callback_args |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | { |
279 | 279 | // delete the saved EE REST API routes |
280 | 280 | foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) { |
281 | - delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version); |
|
281 | + delete_option(EED_Core_Rest_Api::saved_routes_option_names.$version); |
|
282 | 282 | } |
283 | 283 | } |
284 | 284 | |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | { |
299 | 299 | $ee_routes = []; |
300 | 300 | foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoints) { |
301 | - $ee_routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = EED_Core_Rest_Api::_get_ee_route_data_for_version( |
|
301 | + $ee_routes[EED_Core_Rest_Api::ee_api_namespace.$version] = EED_Core_Rest_Api::_get_ee_route_data_for_version( |
|
302 | 302 | $version, |
303 | 303 | $hidden_endpoints |
304 | 304 | ); |
@@ -319,8 +319,8 @@ discard block |
||
319 | 319 | */ |
320 | 320 | protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
321 | 321 | { |
322 | - $ee_routes = get_option(EED_Core_Rest_Api::saved_routes_option_names . $version, null); |
|
323 | - if (! $ee_routes || EED_Core_Rest_Api::debugMode()) { |
|
322 | + $ee_routes = get_option(EED_Core_Rest_Api::saved_routes_option_names.$version, null); |
|
323 | + if ( ! $ee_routes || EED_Core_Rest_Api::debugMode()) { |
|
324 | 324 | $ee_routes = EED_Core_Rest_Api::_save_ee_route_data_for_version($version, $hidden_endpoints); |
325 | 325 | } |
326 | 326 | return $ee_routes; |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
349 | 349 | ) |
350 | 350 | ); |
351 | - $option_name = EED_Core_Rest_Api::saved_routes_option_names . $version; |
|
351 | + $option_name = EED_Core_Rest_Api::saved_routes_option_names.$version; |
|
352 | 352 | if (get_option($option_name)) { |
353 | 353 | update_option($option_name, $routes, true); |
354 | 354 | } else { |
@@ -393,8 +393,8 @@ discard block |
||
393 | 393 | { |
394 | 394 | $model_routes = []; |
395 | 395 | foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
396 | - $model_routes[ EED_Core_Rest_Api::ee_api_namespace |
|
397 | - . $version ] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
396 | + $model_routes[EED_Core_Rest_Api::ee_api_namespace |
|
397 | + . $version] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
398 | 398 | } |
399 | 399 | return $model_routes; |
400 | 400 | } |
@@ -463,13 +463,13 @@ discard block |
||
463 | 463 | foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) { |
464 | 464 | $model = EE_Registry::instance()->load_model($model_name); |
465 | 465 | // if this isn't a valid model then let's skip iterate to the next item in the loop. |
466 | - if (! $model instanceof EEM_Base) { |
|
466 | + if ( ! $model instanceof EEM_Base) { |
|
467 | 467 | continue; |
468 | 468 | } |
469 | 469 | // yes we could just register one route for ALL models, but then they wouldn't show up in the index |
470 | 470 | $plural_model_route = EED_Core_Rest_Api::get_collection_route($model); |
471 | 471 | $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)'); |
472 | - $model_routes[ $plural_model_route ] = [ |
|
472 | + $model_routes[$plural_model_route] = [ |
|
473 | 473 | [ |
474 | 474 | 'callback' => [ |
475 | 475 | 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | 'hidden_endpoint' => $hidden_endpoint, |
481 | 481 | 'args' => $this->_get_read_query_params($model, $version), |
482 | 482 | '_links' => [ |
483 | - 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
483 | + 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace.$version.$singular_model_route), |
|
484 | 484 | ], |
485 | 485 | ], |
486 | 486 | 'schema' => [ |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | 'callback_args' => [$version, $model_name], |
492 | 492 | ], |
493 | 493 | ]; |
494 | - $model_routes[ $singular_model_route ] = [ |
|
494 | + $model_routes[$singular_model_route] = [ |
|
495 | 495 | [ |
496 | 496 | 'callback' => [ |
497 | 497 | 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | $model |
511 | 511 | ) |
512 | 512 | ) { |
513 | - $model_routes[ $plural_model_route ][] = [ |
|
513 | + $model_routes[$plural_model_route][] = [ |
|
514 | 514 | 'callback' => [ |
515 | 515 | 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
516 | 516 | 'handleRequestInsert', |
@@ -520,8 +520,8 @@ discard block |
||
520 | 520 | 'hidden_endpoint' => $hidden_endpoint, |
521 | 521 | 'args' => $this->_get_write_params($model_name, $model_version_info, true), |
522 | 522 | ]; |
523 | - $model_routes[ $singular_model_route ] = array_merge( |
|
524 | - $model_routes[ $singular_model_route ], |
|
523 | + $model_routes[$singular_model_route] = array_merge( |
|
524 | + $model_routes[$singular_model_route], |
|
525 | 525 | [ |
526 | 526 | [ |
527 | 527 | 'callback' => [ |
@@ -552,7 +552,7 @@ discard block |
||
552 | 552 | '(?P<id>[^\/]+)', |
553 | 553 | $relation_obj |
554 | 554 | ); |
555 | - $model_routes[ $related_route ] = [ |
|
555 | + $model_routes[$related_route] = [ |
|
556 | 556 | [ |
557 | 557 | 'callback' => [ |
558 | 558 | 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
@@ -565,8 +565,8 @@ discard block |
||
565 | 565 | ], |
566 | 566 | ]; |
567 | 567 | |
568 | - $related_write_route = $related_route . '/' . '(?P<related_id>[^\/]+)'; |
|
569 | - $model_routes[ $related_write_route ] = [ |
|
568 | + $related_write_route = $related_route.'/'.'(?P<related_id>[^\/]+)'; |
|
569 | + $model_routes[$related_write_route] = [ |
|
570 | 570 | [ |
571 | 571 | 'callback' => [ |
572 | 572 | 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
@@ -623,7 +623,7 @@ discard block |
||
623 | 623 | */ |
624 | 624 | public static function get_entity_route($model, $id) |
625 | 625 | { |
626 | - return EED_Core_Rest_Api::get_collection_route($model) . '/' . $id; |
|
626 | + return EED_Core_Rest_Api::get_collection_route($model).'/'.$id; |
|
627 | 627 | } |
628 | 628 | |
629 | 629 | |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | $relation_obj->get_other_model()->get_this_model_name(), |
644 | 644 | $relation_obj |
645 | 645 | ); |
646 | - return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part; |
|
646 | + return EED_Core_Rest_Api::get_entity_route($model, $id).'/'.$related_model_name_endpoint_part; |
|
647 | 647 | } |
648 | 648 | |
649 | 649 | |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | */ |
658 | 658 | public static function get_versioned_route_to($relative_route, $version = '4.8.36') |
659 | 659 | { |
660 | - return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route; |
|
660 | + return '/'.EED_Core_Rest_Api::ee_api_namespace.$version.'/'.$relative_route; |
|
661 | 661 | } |
662 | 662 | |
663 | 663 | |
@@ -671,7 +671,7 @@ discard block |
||
671 | 671 | { |
672 | 672 | $routes = []; |
673 | 673 | foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
674 | - $routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = $this->_get_rpc_route_data_for_version( |
|
674 | + $routes[EED_Core_Rest_Api::ee_api_namespace.$version] = $this->_get_rpc_route_data_for_version( |
|
675 | 675 | $version, |
676 | 676 | $hidden_endpoint |
677 | 677 | ); |
@@ -804,12 +804,12 @@ discard block |
||
804 | 804 | { |
805 | 805 | // if they're related through a HABTM relation, check for any non-FKs |
806 | 806 | $all_relation_settings = $source_model->relation_settings(); |
807 | - $relation_settings = $all_relation_settings[ $related_model->get_this_model_name() ]; |
|
807 | + $relation_settings = $all_relation_settings[$related_model->get_this_model_name()]; |
|
808 | 808 | $params = []; |
809 | 809 | if ($relation_settings instanceof EE_HABTM_Relation && $relation_settings->hasNonKeyFields()) { |
810 | 810 | foreach ($relation_settings->getNonKeyFields() as $field) { |
811 | 811 | /* @var $field EE_Model_Field_Base */ |
812 | - $params[ $field->get_name() ] = [ |
|
812 | + $params[$field->get_name()] = [ |
|
813 | 813 | 'required' => ! $field->is_nullable(), |
814 | 814 | 'default' => ModelDataTranslator::prepareFieldValueForJson( |
815 | 815 | $field, |
@@ -838,7 +838,7 @@ discard block |
||
838 | 838 | { |
839 | 839 | $default_orderby = []; |
840 | 840 | foreach ($model->get_combined_primary_key_fields() as $key_field) { |
841 | - $default_orderby[ $key_field->get_name() ] = 'ASC'; |
|
841 | + $default_orderby[$key_field->get_name()] = 'ASC'; |
|
842 | 842 | } |
843 | 843 | return array_merge( |
844 | 844 | $this->_get_response_selection_query_params($model, $version), |
@@ -872,7 +872,7 @@ discard block |
||
872 | 872 | 'type' => [ |
873 | 873 | 'object', |
874 | 874 | 'string', |
875 | - ],// because we accept a variety of types, WP core validation and sanitization |
|
875 | + ], // because we accept a variety of types, WP core validation and sanitization |
|
876 | 876 | // freaks out. We'll just validate this argument while handling the request |
877 | 877 | 'validate_callback' => null, |
878 | 878 | 'sanitize_callback' => null, |
@@ -969,7 +969,7 @@ discard block |
||
969 | 969 | $model_version_info->requestedVersion() |
970 | 970 | ); |
971 | 971 | $arg_info['sanitize_callback'] = $sanitize_callback; |
972 | - $args_info[ $field_name ] = $arg_info; |
|
972 | + $args_info[$field_name] = $arg_info; |
|
973 | 973 | if ($field_obj instanceof EE_Datetime_Field) { |
974 | 974 | $gmt_arg_info = $arg_info; |
975 | 975 | $gmt_arg_info['description'] = sprintf( |
@@ -980,7 +980,7 @@ discard block |
||
980 | 980 | $field_obj->get_nicename(), |
981 | 981 | $field_name |
982 | 982 | ); |
983 | - $args_info[ $field_name . '_gmt' ] = $gmt_arg_info; |
|
983 | + $args_info[$field_name.'_gmt'] = $gmt_arg_info; |
|
984 | 984 | } |
985 | 985 | } |
986 | 986 | return $args_info; |
@@ -1004,18 +1004,18 @@ discard block |
||
1004 | 1004 | { |
1005 | 1005 | $attributes = $request->get_attributes(); |
1006 | 1006 | if ( |
1007 | - ! isset($attributes['args'][ $param ]) |
|
1008 | - || ! is_array($attributes['args'][ $param ]) |
|
1007 | + ! isset($attributes['args'][$param]) |
|
1008 | + || ! is_array($attributes['args'][$param]) |
|
1009 | 1009 | ) { |
1010 | 1010 | $validation_result = true; |
1011 | 1011 | } else { |
1012 | - $args = $attributes['args'][ $param ]; |
|
1012 | + $args = $attributes['args'][$param]; |
|
1013 | 1013 | if ( |
1014 | 1014 | ( |
1015 | 1015 | $value === '' |
1016 | 1016 | || $value === null |
1017 | 1017 | ) |
1018 | - && (! isset($args['required']) |
|
1018 | + && ( ! isset($args['required']) |
|
1019 | 1019 | || $args['required'] === false |
1020 | 1020 | ) |
1021 | 1021 | ) { |
@@ -1026,7 +1026,7 @@ discard block |
||
1026 | 1026 | && $args['format'] === 'email' |
1027 | 1027 | ) { |
1028 | 1028 | $validation_result = true; |
1029 | - if (! EED_Core_Rest_Api::_validate_email($value)) { |
|
1029 | + if ( ! EED_Core_Rest_Api::_validate_email($value)) { |
|
1030 | 1030 | $validation_result = new WP_Error( |
1031 | 1031 | 'rest_invalid_param', |
1032 | 1032 | esc_html__( |
@@ -1076,7 +1076,7 @@ discard block |
||
1076 | 1076 | { |
1077 | 1077 | $config_routes = []; |
1078 | 1078 | foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
1079 | - $config_routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = $this->_get_config_route_data_for_version( |
|
1079 | + $config_routes[EED_Core_Rest_Api::ee_api_namespace.$version] = $this->_get_config_route_data_for_version( |
|
1080 | 1080 | $version, |
1081 | 1081 | $hidden_endpoint |
1082 | 1082 | ); |
@@ -1131,7 +1131,7 @@ discard block |
||
1131 | 1131 | { |
1132 | 1132 | $meta_routes = []; |
1133 | 1133 | foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
1134 | - $meta_routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = $this->_get_meta_route_data_for_version( |
|
1134 | + $meta_routes[EED_Core_Rest_Api::ee_api_namespace.$version] = $this->_get_meta_route_data_for_version( |
|
1135 | 1135 | $version, |
1136 | 1136 | $hidden_endpoint |
1137 | 1137 | ); |
@@ -1184,7 +1184,7 @@ discard block |
||
1184 | 1184 | foreach ($relative_urls as $resource_name => $endpoints) { |
1185 | 1185 | foreach ($endpoints as $key => $endpoint) { |
1186 | 1186 | // skip schema and other route options |
1187 | - if (! is_numeric($key)) { |
|
1187 | + if ( ! is_numeric($key)) { |
|
1188 | 1188 | continue; |
1189 | 1189 | } |
1190 | 1190 | // by default, hide "hidden_endpoint"s, unless the request indicates |
@@ -1194,9 +1194,9 @@ discard block |
||
1194 | 1194 | ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
1195 | 1195 | || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '') |
1196 | 1196 | ) { |
1197 | - $full_route = '/' . ltrim($namespace, '/'); |
|
1198 | - $full_route .= '/' . ltrim($resource_name, '/'); |
|
1199 | - unset($route_data[ $full_route ]); |
|
1197 | + $full_route = '/'.ltrim($namespace, '/'); |
|
1198 | + $full_route .= '/'.ltrim($resource_name, '/'); |
|
1199 | + unset($route_data[$full_route]); |
|
1200 | 1200 | } |
1201 | 1201 | } |
1202 | 1202 | } |
@@ -1270,13 +1270,13 @@ discard block |
||
1270 | 1270 | |
1271 | 1271 | if ($key_versioned_endpoint === $latest_version) { |
1272 | 1272 | // don't hide the latest version in the index |
1273 | - $versions_served[ $key_versioned_endpoint ] = false; |
|
1273 | + $versions_served[$key_versioned_endpoint] = false; |
|
1274 | 1274 | } elseif ( |
1275 | 1275 | version_compare($key_versioned_endpoint, $lowest_compatible_version, '>=') |
1276 | 1276 | && version_compare($key_versioned_endpoint, EED_Core_Rest_Api::core_version(), '<') |
1277 | 1277 | ) { |
1278 | 1278 | // include, but hide, previous versions which are still supported |
1279 | - $versions_served[ $key_versioned_endpoint ] = true; |
|
1279 | + $versions_served[$key_versioned_endpoint] = true; |
|
1280 | 1280 | } elseif ( |
1281 | 1281 | apply_filters( |
1282 | 1282 | 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions', |
@@ -1285,7 +1285,7 @@ discard block |
||
1285 | 1285 | ) |
1286 | 1286 | ) { |
1287 | 1287 | // if a version is no longer supported, don't include it in index or list of versions served |
1288 | - $versions_served[ $key_versioned_endpoint ] = true; |
|
1288 | + $versions_served[$key_versioned_endpoint] = true; |
|
1289 | 1289 | } |
1290 | 1290 | } |
1291 | 1291 | return $versions_served; |
@@ -1342,7 +1342,7 @@ discard block |
||
1342 | 1342 | $model_names = EED_Core_Rest_Api::model_names_with_plural_routes($version); |
1343 | 1343 | $collection_routes = []; |
1344 | 1344 | foreach ($model_names as $model_name => $model_class_name) { |
1345 | - $collection_routes[ strtolower($model_name) ] = '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' |
|
1345 | + $collection_routes[strtolower($model_name)] = '/'.EED_Core_Rest_Api::ee_api_namespace.$version.'/' |
|
1346 | 1346 | . EEH_Inflector::pluralize_and_lower($model_name); |
1347 | 1347 | } |
1348 | 1348 | return $collection_routes; |
@@ -1364,9 +1364,9 @@ discard block |
||
1364 | 1364 | $primary_keys = $model_class_name::instance()->get_combined_primary_key_fields(); |
1365 | 1365 | foreach ($primary_keys as $primary_key_name => $primary_key_field) { |
1366 | 1366 | if (count($primary_keys) > 1) { |
1367 | - $primary_key_items[ strtolower($model_name) ][] = $primary_key_name; |
|
1367 | + $primary_key_items[strtolower($model_name)][] = $primary_key_name; |
|
1368 | 1368 | } else { |
1369 | - $primary_key_items[ strtolower($model_name) ] = $primary_key_name; |
|
1369 | + $primary_key_items[strtolower($model_name)] = $primary_key_name; |
|
1370 | 1370 | } |
1371 | 1371 | } |
1372 | 1372 | } |
@@ -22,1382 +22,1382 @@ |
||
22 | 22 | */ |
23 | 23 | class EED_Core_Rest_Api extends EED_Module |
24 | 24 | { |
25 | - const ee_api_namespace = Domain::API_NAMESPACE; |
|
26 | - |
|
27 | - const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/'; |
|
28 | - |
|
29 | - const saved_routes_option_names = 'ee_core_routes'; |
|
30 | - |
|
31 | - /** |
|
32 | - * string used in _links response bodies to make them globally unique. |
|
33 | - * |
|
34 | - * @see http://v2.wp-api.org/extending/linking/ |
|
35 | - */ |
|
36 | - const ee_api_link_namespace = 'https://api.eventespresso.com/'; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var CalculatedModelFields |
|
40 | - */ |
|
41 | - protected static $_field_calculator; |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * @return EED_Core_Rest_Api|EED_Module |
|
46 | - */ |
|
47 | - public static function instance() |
|
48 | - { |
|
49 | - return parent::get_instance(EED_Core_Rest_Api::class); |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
55 | - * |
|
56 | - * @access public |
|
57 | - * @return void |
|
58 | - */ |
|
59 | - public static function set_hooks() |
|
60 | - { |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
66 | - * |
|
67 | - * @access public |
|
68 | - * @return void |
|
69 | - */ |
|
70 | - public static function set_hooks_admin() |
|
71 | - { |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - public static function set_hooks_both() |
|
76 | - { |
|
77 | - add_action('rest_api_init', ['EED_Core_Rest_Api', 'set_hooks_rest_api'], 5); |
|
78 | - add_action('rest_api_init', ['EED_Core_Rest_Api', 'register_routes'], 10); |
|
79 | - add_filter('rest_route_data', ['EED_Core_Rest_Api', 'hide_old_endpoints'], 10, 2); |
|
80 | - add_filter( |
|
81 | - 'rest_index', |
|
82 | - ['EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filterEeMetadataIntoIndex'] |
|
83 | - ); |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @since 5.0.0.p |
|
89 | - */ |
|
90 | - public static function loadCalculatedModelFields() |
|
91 | - { |
|
92 | - EED_Core_Rest_Api::$_field_calculator = LoaderFactory::getLoader()->load( |
|
93 | - 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' |
|
94 | - ); |
|
95 | - EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change(); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * sets up hooks which only need to be included as part of REST API requests; |
|
101 | - * other requests like to the frontend or admin etc don't need them |
|
102 | - * |
|
103 | - * @throws EE_Error |
|
104 | - */ |
|
105 | - public static function set_hooks_rest_api() |
|
106 | - { |
|
107 | - // set hooks which account for changes made to the API |
|
108 | - EED_Core_Rest_Api::_set_hooks_for_changes(); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * public wrapper of _set_hooks_for_changes. |
|
114 | - * Loads all the hooks which make requests to old versions of the API |
|
115 | - * appear the same as they always did |
|
116 | - * |
|
117 | - * @throws EE_Error |
|
118 | - */ |
|
119 | - public static function set_hooks_for_changes() |
|
120 | - { |
|
121 | - EED_Core_Rest_Api::_set_hooks_for_changes(); |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * Loads all the hooks which make requests to old versions of the API |
|
127 | - * appear the same as they always did |
|
128 | - * |
|
129 | - * @throws EE_Error |
|
130 | - */ |
|
131 | - protected static function _set_hooks_for_changes() |
|
132 | - { |
|
133 | - $folder_contents = EEH_File::get_contents_of_folders([EE_LIBRARIES . 'rest_api/changes'], false); |
|
134 | - foreach ($folder_contents as $classname_in_namespace => $filepath) { |
|
135 | - // ignore the base parent class |
|
136 | - // and legacy named classes |
|
137 | - if ( |
|
138 | - $classname_in_namespace === 'ChangesInBase' |
|
139 | - || strpos($classname_in_namespace, 'Changes_In_') === 0 |
|
140 | - ) { |
|
141 | - continue; |
|
142 | - } |
|
143 | - $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
144 | - if (class_exists($full_classname)) { |
|
145 | - $instance_of_class = new $full_classname(); |
|
146 | - if ($instance_of_class instanceof ChangesInBase) { |
|
147 | - $instance_of_class->setHooks(); |
|
148 | - } |
|
149 | - } |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * Filters the WP routes to add our EE-related ones. This takes a bit of time |
|
156 | - * so we actually prefer to only do it when an EE plugin is activated or upgraded |
|
157 | - * |
|
158 | - * @throws EE_Error |
|
159 | - * @throws ReflectionException |
|
160 | - */ |
|
161 | - public static function register_routes() |
|
162 | - { |
|
163 | - foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_routes) { |
|
164 | - foreach ($relative_routes as $relative_route => $data_for_multiple_endpoints) { |
|
165 | - /** |
|
166 | - * @var array $data_for_multiple_endpoints numerically indexed array |
|
167 | - * but can also contain route options like { |
|
168 | - * @type array $schema { |
|
169 | - * @type callable $schema_callback |
|
170 | - * @type array $callback_args arguments that will be passed to the callback, after the |
|
171 | - * WP_REST_Request of course |
|
172 | - * } |
|
173 | - * } |
|
174 | - */ |
|
175 | - // when registering routes, register all the endpoints' data at the same time |
|
176 | - $multiple_endpoint_args = []; |
|
177 | - foreach ($data_for_multiple_endpoints as $endpoint_key => $data_for_single_endpoint) { |
|
178 | - /** |
|
179 | - * @var array $data_for_single_endpoint { |
|
180 | - * @type callable $callback |
|
181 | - * @type string methods |
|
182 | - * @type array args |
|
183 | - * @type array _links |
|
184 | - * @type array $callback_args arguments that will be passed to the callback, after the |
|
185 | - * WP_REST_Request of course |
|
186 | - * } |
|
187 | - */ |
|
188 | - // skip route options |
|
189 | - if (! is_numeric($endpoint_key)) { |
|
190 | - continue; |
|
191 | - } |
|
192 | - if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
193 | - throw new EE_Error( |
|
194 | - esc_html__( |
|
195 | - // @codingStandardsIgnoreStart |
|
196 | - 'Endpoint configuration data needs to have entries "callback" (callable) and "methods" (comma-separated list of accepts HTTP methods).', |
|
197 | - // @codingStandardsIgnoreEnd |
|
198 | - 'event_espresso' |
|
199 | - ) |
|
200 | - ); |
|
201 | - } |
|
202 | - $callback = $data_for_single_endpoint['callback']; |
|
203 | - $single_endpoint_args = [ |
|
204 | - 'methods' => $data_for_single_endpoint['methods'], |
|
205 | - 'args' => isset($data_for_single_endpoint['args']) ? $data_for_single_endpoint['args'] |
|
206 | - : [], |
|
207 | - ]; |
|
208 | - if (isset($data_for_single_endpoint['_links'])) { |
|
209 | - $single_endpoint_args['_links'] = $data_for_single_endpoint['_links']; |
|
210 | - } |
|
211 | - if (isset($data_for_single_endpoint['callback_args'])) { |
|
212 | - $callback_args = $data_for_single_endpoint['callback_args']; |
|
213 | - $single_endpoint_args['callback'] = static function (WP_REST_Request $request) use ( |
|
214 | - $callback, |
|
215 | - $callback_args |
|
216 | - ) { |
|
217 | - array_unshift($callback_args, $request); |
|
218 | - return call_user_func_array( |
|
219 | - $callback, |
|
220 | - $callback_args |
|
221 | - ); |
|
222 | - }; |
|
223 | - } else { |
|
224 | - $single_endpoint_args['callback'] = $data_for_single_endpoint['callback']; |
|
225 | - } |
|
226 | - // As of WordPress 5.5, if a permission_callback is not provided, |
|
227 | - // the REST API will issue a _doing_it_wrong notice. |
|
228 | - // Since the EE REST API defers capabilities to the db model system, |
|
229 | - // we will just use the generic WP callback for public endpoints |
|
230 | - if (! isset($single_endpoint_args['permission_callback'])) { |
|
231 | - $single_endpoint_args['permission_callback'] = '__return_true'; |
|
232 | - } |
|
233 | - $multiple_endpoint_args[] = $single_endpoint_args; |
|
234 | - } |
|
235 | - if (isset($data_for_multiple_endpoints['schema'])) { |
|
236 | - $schema_route_data = $data_for_multiple_endpoints['schema']; |
|
237 | - $schema_callback = $schema_route_data['schema_callback']; |
|
238 | - $callback_args = $schema_route_data['callback_args']; |
|
239 | - $multiple_endpoint_args['schema'] = static function () use ($schema_callback, $callback_args) { |
|
240 | - return call_user_func_array( |
|
241 | - $schema_callback, |
|
242 | - $callback_args |
|
243 | - ); |
|
244 | - }; |
|
245 | - } |
|
246 | - register_rest_route( |
|
247 | - $namespace, |
|
248 | - $relative_route, |
|
249 | - $multiple_endpoint_args |
|
250 | - ); |
|
251 | - } |
|
252 | - } |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * Checks if there was a version change or something that merits invalidating the cached |
|
258 | - * route data. If so, invalidates the cached route data so that it gets refreshed |
|
259 | - * next time the WP API is used |
|
260 | - */ |
|
261 | - public static function invalidate_cached_route_data_on_version_change() |
|
262 | - { |
|
263 | - if (EE_System::instance()->detect_req_type() !== EE_System::req_type_normal) { |
|
264 | - EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
265 | - } |
|
266 | - foreach (EE_Registry::instance()->addons as $addon) { |
|
267 | - if ($addon instanceof EE_Addon && $addon->detect_req_type() !== EE_System::req_type_normal) { |
|
268 | - EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
269 | - } |
|
270 | - } |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * Removes the cached route data so it will get refreshed next time the WP API is used |
|
276 | - */ |
|
277 | - public static function invalidate_cached_route_data() |
|
278 | - { |
|
279 | - // delete the saved EE REST API routes |
|
280 | - foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) { |
|
281 | - delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version); |
|
282 | - } |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * Gets the EE route data |
|
288 | - * |
|
289 | - * @return array top-level key is the namespace, next-level key is the route and its value is array{ |
|
290 | - * @throws EE_Error |
|
291 | - * @throws ReflectionException |
|
292 | - * @type string|array $callback |
|
293 | - * @type string $methods |
|
294 | - * @type boolean $hidden_endpoint |
|
295 | - * } |
|
296 | - */ |
|
297 | - public static function get_ee_route_data() |
|
298 | - { |
|
299 | - $ee_routes = []; |
|
300 | - foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoints) { |
|
301 | - $ee_routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = EED_Core_Rest_Api::_get_ee_route_data_for_version( |
|
302 | - $version, |
|
303 | - $hidden_endpoints |
|
304 | - ); |
|
305 | - } |
|
306 | - return $ee_routes; |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * Gets the EE route data from the wp options if it exists already, |
|
312 | - * otherwise re-generates it and saves it to the option |
|
313 | - * |
|
314 | - * @param string $version |
|
315 | - * @param boolean $hidden_endpoints |
|
316 | - * @return array |
|
317 | - * @throws EE_Error |
|
318 | - * @throws ReflectionException |
|
319 | - */ |
|
320 | - protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
321 | - { |
|
322 | - $ee_routes = get_option(EED_Core_Rest_Api::saved_routes_option_names . $version, null); |
|
323 | - if (! $ee_routes || EED_Core_Rest_Api::debugMode()) { |
|
324 | - $ee_routes = EED_Core_Rest_Api::_save_ee_route_data_for_version($version, $hidden_endpoints); |
|
325 | - } |
|
326 | - return $ee_routes; |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * Saves the EE REST API route data to a wp option and returns it |
|
332 | - * |
|
333 | - * @param string $version |
|
334 | - * @param boolean $hidden_endpoints |
|
335 | - * @return mixed|null |
|
336 | - * @throws EE_Error |
|
337 | - * @throws ReflectionException |
|
338 | - */ |
|
339 | - protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
340 | - { |
|
341 | - $instance = EED_Core_Rest_Api::instance(); |
|
342 | - $routes = apply_filters( |
|
343 | - 'EED_Core_Rest_Api__save_ee_route_data_for_version__routes', |
|
344 | - array_replace_recursive( |
|
345 | - $instance->_get_config_route_data_for_version($version, $hidden_endpoints), |
|
346 | - $instance->_get_meta_route_data_for_version($version, $hidden_endpoints), |
|
347 | - $instance->_get_model_route_data_for_version($version, $hidden_endpoints), |
|
348 | - $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
|
349 | - ) |
|
350 | - ); |
|
351 | - $option_name = EED_Core_Rest_Api::saved_routes_option_names . $version; |
|
352 | - if (get_option($option_name)) { |
|
353 | - update_option($option_name, $routes, true); |
|
354 | - } else { |
|
355 | - add_option($option_name, $routes, null, 'no'); |
|
356 | - } |
|
357 | - return $routes; |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * Calculates all the EE routes and saves it to a WordPress option so we don't |
|
363 | - * need to calculate it on every request |
|
364 | - * |
|
365 | - * @return void |
|
366 | - * @deprecated since version 4.9.1 |
|
367 | - */ |
|
368 | - public static function save_ee_routes() |
|
369 | - { |
|
370 | - if (DbStatus::isOnline()) { |
|
371 | - $instance = EED_Core_Rest_Api::instance(); |
|
372 | - $routes = apply_filters( |
|
373 | - 'EED_Core_Rest_Api__save_ee_routes__routes', |
|
374 | - array_replace_recursive( |
|
375 | - $instance->_register_config_routes(), |
|
376 | - $instance->_register_meta_routes(), |
|
377 | - $instance->_register_model_routes(), |
|
378 | - $instance->_register_rpc_routes() |
|
379 | - ) |
|
380 | - ); |
|
381 | - update_option(EED_Core_Rest_Api::saved_routes_option_names, $routes, true); |
|
382 | - } |
|
383 | - } |
|
384 | - |
|
385 | - |
|
386 | - /** |
|
387 | - * Gets all the route information relating to EE models |
|
388 | - * |
|
389 | - * @return array @see get_ee_route_data |
|
390 | - * @deprecated since version 4.9.1 |
|
391 | - */ |
|
392 | - protected function _register_model_routes() |
|
393 | - { |
|
394 | - $model_routes = []; |
|
395 | - foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
|
396 | - $model_routes[ EED_Core_Rest_Api::ee_api_namespace |
|
397 | - . $version ] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
398 | - } |
|
399 | - return $model_routes; |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * Decides whether or not to add write endpoints for this model. |
|
405 | - * Currently, this defaults to exclude all global tables and models |
|
406 | - * which would allow inserting WP core data (we don't want to duplicate |
|
407 | - * what WP API does, as it's unnecessary, extra work, and potentially extra bugs) |
|
408 | - * |
|
409 | - * @param EEM_Base $model |
|
410 | - * @return bool |
|
411 | - */ |
|
412 | - public static function should_have_write_endpoints(EEM_Base $model) |
|
413 | - { |
|
414 | - if ($model->is_wp_core_model()) { |
|
415 | - return false; |
|
416 | - } |
|
417 | - foreach ($model->get_tables() as $table) { |
|
418 | - if ($table->is_global()) { |
|
419 | - return false; |
|
420 | - } |
|
421 | - } |
|
422 | - return true; |
|
423 | - } |
|
424 | - |
|
425 | - |
|
426 | - /** |
|
427 | - * Gets the names of all models which should have plural routes (eg `ee/v4.8.36/events`) |
|
428 | - * in this versioned namespace of EE4 |
|
429 | - * |
|
430 | - * @param $version |
|
431 | - * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event') |
|
432 | - */ |
|
433 | - public static function model_names_with_plural_routes($version) |
|
434 | - { |
|
435 | - $model_version_info = new ModelVersionInfo($version); |
|
436 | - $models_to_register = $model_version_info->modelsForRequestedVersion(); |
|
437 | - // let's not bother having endpoints for extra metas |
|
438 | - unset( |
|
439 | - $models_to_register['Extra_Meta'], |
|
440 | - $models_to_register['Extra_Join'], |
|
441 | - $models_to_register['Post_Meta'] |
|
442 | - ); |
|
443 | - return apply_filters( |
|
444 | - 'FHEE__EED_Core_REST_API___register_model_routes', |
|
445 | - $models_to_register |
|
446 | - ); |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - /** |
|
451 | - * Gets the route data for EE models in the specified version |
|
452 | - * |
|
453 | - * @param string $version |
|
454 | - * @param boolean $hidden_endpoint |
|
455 | - * @return array |
|
456 | - * @throws EE_Error |
|
457 | - * @throws ReflectionException |
|
458 | - */ |
|
459 | - protected function _get_model_route_data_for_version($version, $hidden_endpoint = false) |
|
460 | - { |
|
461 | - $model_routes = []; |
|
462 | - $model_version_info = new ModelVersionInfo($version); |
|
463 | - foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) { |
|
464 | - $model = EE_Registry::instance()->load_model($model_name); |
|
465 | - // if this isn't a valid model then let's skip iterate to the next item in the loop. |
|
466 | - if (! $model instanceof EEM_Base) { |
|
467 | - continue; |
|
468 | - } |
|
469 | - // yes we could just register one route for ALL models, but then they wouldn't show up in the index |
|
470 | - $plural_model_route = EED_Core_Rest_Api::get_collection_route($model); |
|
471 | - $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)'); |
|
472 | - $model_routes[ $plural_model_route ] = [ |
|
473 | - [ |
|
474 | - 'callback' => [ |
|
475 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
476 | - 'handleRequestGetAll', |
|
477 | - ], |
|
478 | - 'callback_args' => [$version, $model_name], |
|
479 | - 'methods' => WP_REST_Server::READABLE, |
|
480 | - 'hidden_endpoint' => $hidden_endpoint, |
|
481 | - 'args' => $this->_get_read_query_params($model, $version), |
|
482 | - '_links' => [ |
|
483 | - 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
484 | - ], |
|
485 | - ], |
|
486 | - 'schema' => [ |
|
487 | - 'schema_callback' => [ |
|
488 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
489 | - 'handleSchemaRequest', |
|
490 | - ], |
|
491 | - 'callback_args' => [$version, $model_name], |
|
492 | - ], |
|
493 | - ]; |
|
494 | - $model_routes[ $singular_model_route ] = [ |
|
495 | - [ |
|
496 | - 'callback' => [ |
|
497 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
498 | - 'handleRequestGetOne', |
|
499 | - ], |
|
500 | - 'callback_args' => [$version, $model_name], |
|
501 | - 'methods' => WP_REST_Server::READABLE, |
|
502 | - 'hidden_endpoint' => $hidden_endpoint, |
|
503 | - 'args' => $this->_get_response_selection_query_params($model, $version, true), |
|
504 | - ], |
|
505 | - ]; |
|
506 | - if ( |
|
507 | - apply_filters( |
|
508 | - 'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints', |
|
509 | - EED_Core_Rest_Api::should_have_write_endpoints($model), |
|
510 | - $model |
|
511 | - ) |
|
512 | - ) { |
|
513 | - $model_routes[ $plural_model_route ][] = [ |
|
514 | - 'callback' => [ |
|
515 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
516 | - 'handleRequestInsert', |
|
517 | - ], |
|
518 | - 'callback_args' => [$version, $model_name], |
|
519 | - 'methods' => WP_REST_Server::CREATABLE, |
|
520 | - 'hidden_endpoint' => $hidden_endpoint, |
|
521 | - 'args' => $this->_get_write_params($model_name, $model_version_info, true), |
|
522 | - ]; |
|
523 | - $model_routes[ $singular_model_route ] = array_merge( |
|
524 | - $model_routes[ $singular_model_route ], |
|
525 | - [ |
|
526 | - [ |
|
527 | - 'callback' => [ |
|
528 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
529 | - 'handleRequestUpdate', |
|
530 | - ], |
|
531 | - 'callback_args' => [$version, $model_name], |
|
532 | - 'methods' => WP_REST_Server::EDITABLE, |
|
533 | - 'hidden_endpoint' => $hidden_endpoint, |
|
534 | - 'args' => $this->_get_write_params($model_name, $model_version_info), |
|
535 | - ], |
|
536 | - [ |
|
537 | - 'callback' => [ |
|
538 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
539 | - 'handleRequestDelete', |
|
540 | - ], |
|
541 | - 'callback_args' => [$version, $model_name], |
|
542 | - 'methods' => WP_REST_Server::DELETABLE, |
|
543 | - 'hidden_endpoint' => $hidden_endpoint, |
|
544 | - 'args' => $this->_get_delete_query_params($model, $version), |
|
545 | - ], |
|
546 | - ] |
|
547 | - ); |
|
548 | - } |
|
549 | - foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
550 | - $related_route = EED_Core_Rest_Api::get_relation_route_via( |
|
551 | - $model, |
|
552 | - '(?P<id>[^\/]+)', |
|
553 | - $relation_obj |
|
554 | - ); |
|
555 | - $model_routes[ $related_route ] = [ |
|
556 | - [ |
|
557 | - 'callback' => [ |
|
558 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
559 | - 'handleRequestGetRelated', |
|
560 | - ], |
|
561 | - 'callback_args' => [$version, $model_name, $relation_name], |
|
562 | - 'methods' => WP_REST_Server::READABLE, |
|
563 | - 'hidden_endpoint' => $hidden_endpoint, |
|
564 | - 'args' => $this->_get_read_query_params($relation_obj->get_other_model(), $version), |
|
565 | - ], |
|
566 | - ]; |
|
567 | - |
|
568 | - $related_write_route = $related_route . '/' . '(?P<related_id>[^\/]+)'; |
|
569 | - $model_routes[ $related_write_route ] = [ |
|
570 | - [ |
|
571 | - 'callback' => [ |
|
572 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
573 | - 'handleRequestAddRelation', |
|
574 | - ], |
|
575 | - 'callback_args' => [$version, $model_name, $relation_name], |
|
576 | - 'methods' => WP_REST_Server::EDITABLE, |
|
577 | - 'hidden_endpoint' => $hidden_endpoint, |
|
578 | - 'args' => $this->_get_add_relation_query_params( |
|
579 | - $model, |
|
580 | - $relation_obj->get_other_model(), |
|
581 | - $version |
|
582 | - ), |
|
583 | - ], |
|
584 | - [ |
|
585 | - 'callback' => [ |
|
586 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
587 | - 'handleRequestRemoveRelation', |
|
588 | - ], |
|
589 | - 'callback_args' => [$version, $model_name, $relation_name], |
|
590 | - 'methods' => WP_REST_Server::DELETABLE, |
|
591 | - 'hidden_endpoint' => $hidden_endpoint, |
|
592 | - 'args' => [], |
|
593 | - ], |
|
594 | - ]; |
|
595 | - } |
|
596 | - } |
|
597 | - return $model_routes; |
|
598 | - } |
|
599 | - |
|
600 | - |
|
601 | - /** |
|
602 | - * Gets the relative URI to a model's REST API plural route, after the EE4 versioned namespace, |
|
603 | - * excluding the preceding slash. |
|
604 | - * Eg you pass get_plural_route_to('Event') = 'events' |
|
605 | - * |
|
606 | - * @param EEM_Base $model |
|
607 | - * @return string |
|
608 | - */ |
|
609 | - public static function get_collection_route(EEM_Base $model) |
|
610 | - { |
|
611 | - return EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
612 | - } |
|
613 | - |
|
614 | - |
|
615 | - /** |
|
616 | - * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
617 | - * excluding the preceding slash. |
|
618 | - * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
619 | - * |
|
620 | - * @param EEM_Base $model eg Event or Venue |
|
621 | - * @param string $id |
|
622 | - * @return string |
|
623 | - */ |
|
624 | - public static function get_entity_route($model, $id) |
|
625 | - { |
|
626 | - return EED_Core_Rest_Api::get_collection_route($model) . '/' . $id; |
|
627 | - } |
|
628 | - |
|
629 | - |
|
630 | - /** |
|
631 | - * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
632 | - * excluding the preceding slash. |
|
633 | - * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
634 | - * |
|
635 | - * @param EEM_Base $model eg Event or Venue |
|
636 | - * @param string $id |
|
637 | - * @param EE_Model_Relation_Base $relation_obj |
|
638 | - * @return string |
|
639 | - */ |
|
640 | - public static function get_relation_route_via(EEM_Base $model, $id, EE_Model_Relation_Base $relation_obj) |
|
641 | - { |
|
642 | - $related_model_name_endpoint_part = ModelRead::getRelatedEntityName( |
|
643 | - $relation_obj->get_other_model()->get_this_model_name(), |
|
644 | - $relation_obj |
|
645 | - ); |
|
646 | - return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part; |
|
647 | - } |
|
648 | - |
|
649 | - |
|
650 | - /** |
|
651 | - * Adds onto the $relative_route the EE4 REST API versioned namespace. |
|
652 | - * Eg if given '4.8.36' and 'events', will return 'ee/v4.8.36/events' |
|
653 | - * |
|
654 | - * @param string $relative_route |
|
655 | - * @param string $version |
|
656 | - * @return string |
|
657 | - */ |
|
658 | - public static function get_versioned_route_to($relative_route, $version = '4.8.36') |
|
659 | - { |
|
660 | - return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route; |
|
661 | - } |
|
662 | - |
|
663 | - |
|
664 | - /** |
|
665 | - * Adds all the RPC-style routes (remote procedure call-like routes, ie |
|
666 | - * routes that don't conform to the traditional REST CRUD-style). |
|
667 | - * |
|
668 | - * @deprecated since 4.9.1 |
|
669 | - */ |
|
670 | - protected function _register_rpc_routes() |
|
671 | - { |
|
672 | - $routes = []; |
|
673 | - foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
|
674 | - $routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = $this->_get_rpc_route_data_for_version( |
|
675 | - $version, |
|
676 | - $hidden_endpoint |
|
677 | - ); |
|
678 | - } |
|
679 | - return $routes; |
|
680 | - } |
|
681 | - |
|
682 | - |
|
683 | - /** |
|
684 | - * @param string $version |
|
685 | - * @param boolean $hidden_endpoint |
|
686 | - * @return array |
|
687 | - */ |
|
688 | - protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false) |
|
689 | - { |
|
690 | - $this_versions_routes = []; |
|
691 | - // checkin endpoint |
|
692 | - $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = [ |
|
693 | - [ |
|
694 | - 'callback' => [ |
|
695 | - 'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin', |
|
696 | - 'handleRequestToggleCheckin', |
|
697 | - ], |
|
698 | - 'methods' => WP_REST_Server::CREATABLE, |
|
699 | - 'hidden_endpoint' => $hidden_endpoint, |
|
700 | - 'args' => [ |
|
701 | - 'force' => [ |
|
702 | - 'required' => false, |
|
703 | - 'default' => false, |
|
704 | - 'description' => esc_html__( |
|
705 | - // @codingStandardsIgnoreStart |
|
706 | - 'Whether to force toggle checkin, or to verify the registration status and allowed ticket uses', |
|
707 | - // @codingStandardsIgnoreEnd |
|
708 | - 'event_espresso' |
|
709 | - ), |
|
710 | - ], |
|
711 | - ], |
|
712 | - 'callback_args' => [$version], |
|
713 | - ], |
|
714 | - ]; |
|
715 | - return apply_filters( |
|
716 | - 'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes', |
|
717 | - $this_versions_routes, |
|
718 | - $version, |
|
719 | - $hidden_endpoint |
|
720 | - ); |
|
721 | - } |
|
722 | - |
|
723 | - |
|
724 | - /** |
|
725 | - * Gets the query params that can be used when request one or many |
|
726 | - * |
|
727 | - * @param EEM_Base $model |
|
728 | - * @param string $version |
|
729 | - * @return array |
|
730 | - */ |
|
731 | - protected function _get_response_selection_query_params(EEM_Base $model, $version, $single_only = false) |
|
732 | - { |
|
733 | - EED_Core_Rest_Api::loadCalculatedModelFields(); |
|
734 | - $query_params = [ |
|
735 | - 'include' => [ |
|
736 | - 'required' => false, |
|
737 | - 'default' => '*', |
|
738 | - 'type' => 'string', |
|
739 | - ], |
|
740 | - 'calculate' => [ |
|
741 | - 'required' => false, |
|
742 | - 'default' => '', |
|
743 | - 'enum' => EED_Core_Rest_Api::$_field_calculator->retrieveCalculatedFieldsForModel($model), |
|
744 | - 'type' => 'string', |
|
745 | - // because we accept a CSV list of the enumerated strings, WP core validation and sanitization |
|
746 | - // freaks out. We'll just validate this argument while handling the request |
|
747 | - 'validate_callback' => null, |
|
748 | - 'sanitize_callback' => null, |
|
749 | - ], |
|
750 | - 'password' => [ |
|
751 | - 'required' => false, |
|
752 | - 'default' => '', |
|
753 | - 'type' => 'string', |
|
754 | - ], |
|
755 | - ]; |
|
756 | - return apply_filters( |
|
757 | - 'FHEE__EED_Core_Rest_Api___get_response_selection_query_params', |
|
758 | - $query_params, |
|
759 | - $model, |
|
760 | - $version |
|
761 | - ); |
|
762 | - } |
|
763 | - |
|
764 | - |
|
765 | - /** |
|
766 | - * Gets the parameters acceptable for delete requests |
|
767 | - * |
|
768 | - * @param EEM_Base $model |
|
769 | - * @param string $version |
|
770 | - * @return array |
|
771 | - */ |
|
772 | - protected function _get_delete_query_params(EEM_Base $model, $version) |
|
773 | - { |
|
774 | - $params_for_delete = [ |
|
775 | - 'allow_blocking' => [ |
|
776 | - 'required' => false, |
|
777 | - 'default' => true, |
|
778 | - 'type' => 'boolean', |
|
779 | - ], |
|
780 | - ]; |
|
781 | - $params_for_delete['force'] = [ |
|
782 | - 'required' => false, |
|
783 | - 'default' => false, |
|
784 | - 'type' => 'boolean', |
|
785 | - ]; |
|
786 | - return apply_filters( |
|
787 | - 'FHEE__EED_Core_Rest_Api___get_delete_query_params', |
|
788 | - $params_for_delete, |
|
789 | - $model, |
|
790 | - $version |
|
791 | - ); |
|
792 | - } |
|
793 | - |
|
794 | - |
|
795 | - /** |
|
796 | - * @param EEM_Base $source_model |
|
797 | - * @param EEM_Base $related_model |
|
798 | - * @param $version |
|
799 | - * @return array |
|
800 | - * @throws EE_Error |
|
801 | - * @since 5.0.0.p |
|
802 | - */ |
|
803 | - protected function _get_add_relation_query_params(EEM_Base $source_model, EEM_Base $related_model, $version) |
|
804 | - { |
|
805 | - // if they're related through a HABTM relation, check for any non-FKs |
|
806 | - $all_relation_settings = $source_model->relation_settings(); |
|
807 | - $relation_settings = $all_relation_settings[ $related_model->get_this_model_name() ]; |
|
808 | - $params = []; |
|
809 | - if ($relation_settings instanceof EE_HABTM_Relation && $relation_settings->hasNonKeyFields()) { |
|
810 | - foreach ($relation_settings->getNonKeyFields() as $field) { |
|
811 | - /* @var $field EE_Model_Field_Base */ |
|
812 | - $params[ $field->get_name() ] = [ |
|
813 | - 'required' => ! $field->is_nullable(), |
|
814 | - 'default' => ModelDataTranslator::prepareFieldValueForJson( |
|
815 | - $field, |
|
816 | - $field->get_default_value(), |
|
817 | - $version |
|
818 | - ), |
|
819 | - 'type' => $field->getSchemaType(), |
|
820 | - 'validate_callback' => null, |
|
821 | - 'sanitize_callback' => null, |
|
822 | - ]; |
|
823 | - } |
|
824 | - } |
|
825 | - return $params; |
|
826 | - } |
|
827 | - |
|
828 | - |
|
829 | - /** |
|
830 | - * Gets info about reading query params that are acceptable |
|
831 | - * |
|
832 | - * @param EEM_Base $model eg 'Event' or 'Venue' |
|
833 | - * @param string $version |
|
834 | - * @return array describing the args acceptable when querying this model |
|
835 | - * @throws EE_Error |
|
836 | - */ |
|
837 | - protected function _get_read_query_params(EEM_Base $model, $version) |
|
838 | - { |
|
839 | - $default_orderby = []; |
|
840 | - foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
841 | - $default_orderby[ $key_field->get_name() ] = 'ASC'; |
|
842 | - } |
|
843 | - return array_merge( |
|
844 | - $this->_get_response_selection_query_params($model, $version), |
|
845 | - [ |
|
846 | - 'where' => [ |
|
847 | - 'required' => false, |
|
848 | - 'default' => [], |
|
849 | - 'type' => 'object', |
|
850 | - // because we accept an almost infinite list of possible where conditions, WP |
|
851 | - // core validation and sanitization freaks out. We'll just validate this argument |
|
852 | - // while handling the request |
|
853 | - 'validate_callback' => null, |
|
854 | - 'sanitize_callback' => null, |
|
855 | - ], |
|
856 | - 'limit' => [ |
|
857 | - 'required' => false, |
|
858 | - 'default' => EED_Core_Rest_Api::get_default_query_limit(), |
|
859 | - 'type' => [ |
|
860 | - 'array', |
|
861 | - 'string', |
|
862 | - 'integer', |
|
863 | - ], |
|
864 | - // because we accept a variety of types, WP core validation and sanitization |
|
865 | - // freaks out. We'll just validate this argument while handling the request |
|
866 | - 'validate_callback' => null, |
|
867 | - 'sanitize_callback' => null, |
|
868 | - ], |
|
869 | - 'order_by' => [ |
|
870 | - 'required' => false, |
|
871 | - 'default' => $default_orderby, |
|
872 | - 'type' => [ |
|
873 | - 'object', |
|
874 | - 'string', |
|
875 | - ],// because we accept a variety of types, WP core validation and sanitization |
|
876 | - // freaks out. We'll just validate this argument while handling the request |
|
877 | - 'validate_callback' => null, |
|
878 | - 'sanitize_callback' => null, |
|
879 | - ], |
|
880 | - 'group_by' => [ |
|
881 | - 'required' => false, |
|
882 | - 'default' => null, |
|
883 | - 'type' => [ |
|
884 | - 'object', |
|
885 | - 'string', |
|
886 | - ], |
|
887 | - // because we accept an almost infinite list of possible groupings, |
|
888 | - // WP core validation and sanitization |
|
889 | - // freaks out. We'll just validate this argument while handling the request |
|
890 | - 'validate_callback' => null, |
|
891 | - 'sanitize_callback' => null, |
|
892 | - ], |
|
893 | - 'having' => [ |
|
894 | - 'required' => false, |
|
895 | - 'default' => null, |
|
896 | - 'type' => 'object', |
|
897 | - // because we accept an almost infinite list of possible where conditions, WP |
|
898 | - // core validation and sanitization freaks out. We'll just validate this argument |
|
899 | - // while handling the request |
|
900 | - 'validate_callback' => null, |
|
901 | - 'sanitize_callback' => null, |
|
902 | - ], |
|
903 | - 'caps' => [ |
|
904 | - 'required' => false, |
|
905 | - 'default' => EEM_Base::caps_read, |
|
906 | - 'type' => 'string', |
|
907 | - 'enum' => [ |
|
908 | - EEM_Base::caps_read, |
|
909 | - EEM_Base::caps_read_admin, |
|
910 | - EEM_Base::caps_edit, |
|
911 | - EEM_Base::caps_delete, |
|
912 | - ], |
|
913 | - ], |
|
914 | - ] |
|
915 | - ); |
|
916 | - } |
|
917 | - |
|
918 | - |
|
919 | - /** |
|
920 | - * Gets parameter information for a model regarding writing data |
|
921 | - * |
|
922 | - * @param string $model_name |
|
923 | - * @param ModelVersionInfo $model_version_info |
|
924 | - * @param boolean $create whether this is for request to create (in |
|
925 | - * which case we need all required params) or |
|
926 | - * just to update (in which case we don't |
|
927 | - * need those on every request) |
|
928 | - * @return array |
|
929 | - * @throws EE_Error |
|
930 | - * @throws ReflectionException |
|
931 | - */ |
|
932 | - protected function _get_write_params( |
|
933 | - $model_name, |
|
934 | - ModelVersionInfo $model_version_info, |
|
935 | - $create = false |
|
936 | - ) { |
|
937 | - $model = EE_Registry::instance()->load_model($model_name); |
|
938 | - $fields = $model_version_info->fieldsOnModelInThisVersion($model); |
|
939 | - |
|
940 | - // we do our own validation and sanitization within the controller |
|
941 | - $sanitize_callback = function_exists('rest_validate_value_from_schema') |
|
942 | - ? ['EED_Core_Rest_Api', 'default_sanitize_callback'] |
|
943 | - : null; |
|
944 | - $args_info = []; |
|
945 | - foreach ($fields as $field_name => $field_obj) { |
|
946 | - if ($field_obj->is_auto_increment()) { |
|
947 | - // totally ignore auto increment IDs |
|
948 | - continue; |
|
949 | - } |
|
950 | - $arg_info = $field_obj->getSchema(); |
|
951 | - $required = $create && ! $field_obj->is_nullable() && $field_obj->get_default_value() === null; |
|
952 | - $arg_info['required'] = $required; |
|
953 | - // remove the read-only flag. If it were read-only we wouldn't list it as an argument while writing, right? |
|
954 | - unset($arg_info['readonly']); |
|
955 | - $schema_properties = $field_obj->getSchemaProperties(); |
|
956 | - if ( |
|
957 | - isset($schema_properties['raw']) |
|
958 | - && $field_obj->getSchemaType() === 'object' |
|
959 | - ) { |
|
960 | - // if there's a "raw" form of this argument, use those properties instead |
|
961 | - $arg_info = array_replace( |
|
962 | - $arg_info, |
|
963 | - $schema_properties['raw'] |
|
964 | - ); |
|
965 | - } |
|
966 | - $arg_info['default'] = ModelDataTranslator::prepareFieldValueForJson( |
|
967 | - $field_obj, |
|
968 | - $field_obj->get_default_value(), |
|
969 | - $model_version_info->requestedVersion() |
|
970 | - ); |
|
971 | - $arg_info['sanitize_callback'] = $sanitize_callback; |
|
972 | - $args_info[ $field_name ] = $arg_info; |
|
973 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
974 | - $gmt_arg_info = $arg_info; |
|
975 | - $gmt_arg_info['description'] = sprintf( |
|
976 | - esc_html__( |
|
977 | - '%1$s - the value for this field in UTC. Ignored if %2$s is provided.', |
|
978 | - 'event_espresso' |
|
979 | - ), |
|
980 | - $field_obj->get_nicename(), |
|
981 | - $field_name |
|
982 | - ); |
|
983 | - $args_info[ $field_name . '_gmt' ] = $gmt_arg_info; |
|
984 | - } |
|
985 | - } |
|
986 | - return $args_info; |
|
987 | - } |
|
988 | - |
|
989 | - |
|
990 | - /** |
|
991 | - * Replacement for WP API's 'rest_parse_request_arg'. |
|
992 | - * If the value is blank but not required, don't bother validating it. |
|
993 | - * Also, it uses our email validation instead of WP API's default. |
|
994 | - * |
|
995 | - * @param $value |
|
996 | - * @param WP_REST_Request $request |
|
997 | - * @param $param |
|
998 | - * @return bool|true|WP_Error |
|
999 | - * @throws InvalidArgumentException |
|
1000 | - * @throws InvalidInterfaceException |
|
1001 | - * @throws InvalidDataTypeException |
|
1002 | - */ |
|
1003 | - public static function default_sanitize_callback($value, WP_REST_Request $request, $param) |
|
1004 | - { |
|
1005 | - $attributes = $request->get_attributes(); |
|
1006 | - if ( |
|
1007 | - ! isset($attributes['args'][ $param ]) |
|
1008 | - || ! is_array($attributes['args'][ $param ]) |
|
1009 | - ) { |
|
1010 | - $validation_result = true; |
|
1011 | - } else { |
|
1012 | - $args = $attributes['args'][ $param ]; |
|
1013 | - if ( |
|
1014 | - ( |
|
1015 | - $value === '' |
|
1016 | - || $value === null |
|
1017 | - ) |
|
1018 | - && (! isset($args['required']) |
|
1019 | - || $args['required'] === false |
|
1020 | - ) |
|
1021 | - ) { |
|
1022 | - // not required and not provided? that's cool |
|
1023 | - $validation_result = true; |
|
1024 | - } elseif ( |
|
1025 | - isset($args['format']) |
|
1026 | - && $args['format'] === 'email' |
|
1027 | - ) { |
|
1028 | - $validation_result = true; |
|
1029 | - if (! EED_Core_Rest_Api::_validate_email($value)) { |
|
1030 | - $validation_result = new WP_Error( |
|
1031 | - 'rest_invalid_param', |
|
1032 | - esc_html__( |
|
1033 | - 'The email address is not valid or does not exist.', |
|
1034 | - 'event_espresso' |
|
1035 | - ) |
|
1036 | - ); |
|
1037 | - } |
|
1038 | - } else { |
|
1039 | - $validation_result = rest_validate_value_from_schema($value, $args, $param); |
|
1040 | - } |
|
1041 | - } |
|
1042 | - if (is_wp_error($validation_result)) { |
|
1043 | - return $validation_result; |
|
1044 | - } |
|
1045 | - return rest_sanitize_request_arg($value, $request, $param); |
|
1046 | - } |
|
1047 | - |
|
1048 | - |
|
1049 | - /** |
|
1050 | - * Returns whether or not this email address is valid. Copied from EE_Email_Validation_Strategy::_validate_email() |
|
1051 | - * |
|
1052 | - * @param $email |
|
1053 | - * @return bool |
|
1054 | - * @throws InvalidArgumentException |
|
1055 | - * @throws InvalidInterfaceException |
|
1056 | - * @throws InvalidDataTypeException |
|
1057 | - */ |
|
1058 | - protected static function _validate_email($email) |
|
1059 | - { |
|
1060 | - try { |
|
1061 | - EmailAddressFactory::create($email); |
|
1062 | - return true; |
|
1063 | - } catch (EmailValidationException $e) { |
|
1064 | - return false; |
|
1065 | - } |
|
1066 | - } |
|
1067 | - |
|
1068 | - |
|
1069 | - /** |
|
1070 | - * Gets routes for the config |
|
1071 | - * |
|
1072 | - * @return array @see _register_model_routes |
|
1073 | - * @deprecated since version 4.9.1 |
|
1074 | - */ |
|
1075 | - protected function _register_config_routes() |
|
1076 | - { |
|
1077 | - $config_routes = []; |
|
1078 | - foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
|
1079 | - $config_routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = $this->_get_config_route_data_for_version( |
|
1080 | - $version, |
|
1081 | - $hidden_endpoint |
|
1082 | - ); |
|
1083 | - } |
|
1084 | - return $config_routes; |
|
1085 | - } |
|
1086 | - |
|
1087 | - |
|
1088 | - /** |
|
1089 | - * Gets routes for the config for the specified version |
|
1090 | - * |
|
1091 | - * @param string $version |
|
1092 | - * @param boolean $hidden_endpoint |
|
1093 | - * @return array |
|
1094 | - */ |
|
1095 | - protected function _get_config_route_data_for_version($version, $hidden_endpoint) |
|
1096 | - { |
|
1097 | - return [ |
|
1098 | - 'config' => [ |
|
1099 | - [ |
|
1100 | - 'callback' => [ |
|
1101 | - 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
1102 | - 'handleRequest', |
|
1103 | - ], |
|
1104 | - 'methods' => WP_REST_Server::READABLE, |
|
1105 | - 'hidden_endpoint' => $hidden_endpoint, |
|
1106 | - 'callback_args' => [$version], |
|
1107 | - ], |
|
1108 | - ], |
|
1109 | - 'site_info' => [ |
|
1110 | - [ |
|
1111 | - 'callback' => [ |
|
1112 | - 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
1113 | - 'handleRequestSiteInfo', |
|
1114 | - ], |
|
1115 | - 'methods' => WP_REST_Server::READABLE, |
|
1116 | - 'hidden_endpoint' => $hidden_endpoint, |
|
1117 | - 'callback_args' => [$version], |
|
1118 | - ], |
|
1119 | - ], |
|
1120 | - ]; |
|
1121 | - } |
|
1122 | - |
|
1123 | - |
|
1124 | - /** |
|
1125 | - * Gets the meta info routes |
|
1126 | - * |
|
1127 | - * @return array @see _register_model_routes |
|
1128 | - * @deprecated since version 4.9.1 |
|
1129 | - */ |
|
1130 | - protected function _register_meta_routes() |
|
1131 | - { |
|
1132 | - $meta_routes = []; |
|
1133 | - foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
|
1134 | - $meta_routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = $this->_get_meta_route_data_for_version( |
|
1135 | - $version, |
|
1136 | - $hidden_endpoint |
|
1137 | - ); |
|
1138 | - } |
|
1139 | - return $meta_routes; |
|
1140 | - } |
|
1141 | - |
|
1142 | - |
|
1143 | - /** |
|
1144 | - * @param string $version |
|
1145 | - * @param boolean $hidden_endpoint |
|
1146 | - * @return array |
|
1147 | - */ |
|
1148 | - protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false) |
|
1149 | - { |
|
1150 | - return [ |
|
1151 | - 'resources' => [ |
|
1152 | - [ |
|
1153 | - 'callback' => [ |
|
1154 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Meta', |
|
1155 | - 'handleRequestModelsMeta', |
|
1156 | - ], |
|
1157 | - 'methods' => WP_REST_Server::READABLE, |
|
1158 | - 'hidden_endpoint' => $hidden_endpoint, |
|
1159 | - 'callback_args' => [$version], |
|
1160 | - ], |
|
1161 | - ], |
|
1162 | - ]; |
|
1163 | - } |
|
1164 | - |
|
1165 | - |
|
1166 | - /** |
|
1167 | - * Tries to hide old 4.6 endpoints from the |
|
1168 | - * |
|
1169 | - * @param array $route_data |
|
1170 | - * @return array |
|
1171 | - * @throws EE_Error |
|
1172 | - * @throws ReflectionException |
|
1173 | - */ |
|
1174 | - public static function hide_old_endpoints($route_data) |
|
1175 | - { |
|
1176 | - // allow API clients to override which endpoints get hidden, in case |
|
1177 | - // they want to discover particular endpoints |
|
1178 | - // also, we don't have access to the request so we have to just grab it from the superglobal |
|
1179 | - $force_show_ee_namespace = ltrim( |
|
1180 | - EED_Core_Rest_Api::getRequest()->getRequestParam('force_show_ee_namespace'), |
|
1181 | - '/' |
|
1182 | - ); |
|
1183 | - foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
1184 | - foreach ($relative_urls as $resource_name => $endpoints) { |
|
1185 | - foreach ($endpoints as $key => $endpoint) { |
|
1186 | - // skip schema and other route options |
|
1187 | - if (! is_numeric($key)) { |
|
1188 | - continue; |
|
1189 | - } |
|
1190 | - // by default, hide "hidden_endpoint"s, unless the request indicates |
|
1191 | - // to $force_show_ee_namespace, in which case only show that one |
|
1192 | - // namespace's endpoints (and hide all others) |
|
1193 | - if ( |
|
1194 | - ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
|
1195 | - || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '') |
|
1196 | - ) { |
|
1197 | - $full_route = '/' . ltrim($namespace, '/'); |
|
1198 | - $full_route .= '/' . ltrim($resource_name, '/'); |
|
1199 | - unset($route_data[ $full_route ]); |
|
1200 | - } |
|
1201 | - } |
|
1202 | - } |
|
1203 | - } |
|
1204 | - return $route_data; |
|
1205 | - } |
|
1206 | - |
|
1207 | - |
|
1208 | - /** |
|
1209 | - * Returns an array describing which versions of core support serving requests for. |
|
1210 | - * Keys are core versions' major and minor version, and values are the |
|
1211 | - * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like |
|
1212 | - * data by just removing a few models and fields from the responses. However, 4.15 might remove |
|
1213 | - * the answers table entirely, in which case it would be very difficult for |
|
1214 | - * it to serve 4.6-style responses. |
|
1215 | - * Versions of core that are missing from this array are unknowns. |
|
1216 | - * previous ver |
|
1217 | - * |
|
1218 | - * @return array |
|
1219 | - */ |
|
1220 | - public static function version_compatibilities() |
|
1221 | - { |
|
1222 | - return apply_filters( |
|
1223 | - 'FHEE__EED_Core_REST_API__version_compatibilities', |
|
1224 | - [ |
|
1225 | - '4.8.29' => '4.8.29', |
|
1226 | - '4.8.33' => '4.8.29', |
|
1227 | - '4.8.34' => '4.8.29', |
|
1228 | - '4.8.36' => '4.8.29', |
|
1229 | - ] |
|
1230 | - ); |
|
1231 | - } |
|
1232 | - |
|
1233 | - |
|
1234 | - /** |
|
1235 | - * Gets the latest API version served. Eg if there |
|
1236 | - * are two versions served of the API, 4.8.29 and 4.8.32, and |
|
1237 | - * we are on core version 4.8.34, it will return the string "4.8.32" |
|
1238 | - * |
|
1239 | - * @return string |
|
1240 | - */ |
|
1241 | - public static function latest_rest_api_version() |
|
1242 | - { |
|
1243 | - $versions_served = EED_Core_Rest_Api::versions_served(); |
|
1244 | - $versions_served_keys = array_keys($versions_served); |
|
1245 | - return end($versions_served_keys); |
|
1246 | - } |
|
1247 | - |
|
1248 | - |
|
1249 | - /** |
|
1250 | - * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of |
|
1251 | - * EE the API can serve requests for. Eg, if we are on 4.15 of core, and |
|
1252 | - * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ). |
|
1253 | - * We also indicate whether or not this version should be put in the index or not |
|
1254 | - * |
|
1255 | - * @return array keys are API version numbers (just major and minor numbers), and values |
|
1256 | - * are whether or not they should be hidden |
|
1257 | - */ |
|
1258 | - public static function versions_served() |
|
1259 | - { |
|
1260 | - $versions_served = []; |
|
1261 | - $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities(); |
|
1262 | - $lowest_compatible_version = end($possibly_served_versions); |
|
1263 | - reset($possibly_served_versions); |
|
1264 | - $versions_served_historically = array_keys($possibly_served_versions); |
|
1265 | - $latest_version = end($versions_served_historically); |
|
1266 | - reset($versions_served_historically); |
|
1267 | - // for each version of core we have ever served: |
|
1268 | - foreach ($versions_served_historically as $key_versioned_endpoint) { |
|
1269 | - // if it's not above the current core version, and it's compatible with the current version of core |
|
1270 | - |
|
1271 | - if ($key_versioned_endpoint === $latest_version) { |
|
1272 | - // don't hide the latest version in the index |
|
1273 | - $versions_served[ $key_versioned_endpoint ] = false; |
|
1274 | - } elseif ( |
|
1275 | - version_compare($key_versioned_endpoint, $lowest_compatible_version, '>=') |
|
1276 | - && version_compare($key_versioned_endpoint, EED_Core_Rest_Api::core_version(), '<') |
|
1277 | - ) { |
|
1278 | - // include, but hide, previous versions which are still supported |
|
1279 | - $versions_served[ $key_versioned_endpoint ] = true; |
|
1280 | - } elseif ( |
|
1281 | - apply_filters( |
|
1282 | - 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions', |
|
1283 | - false, |
|
1284 | - $possibly_served_versions |
|
1285 | - ) |
|
1286 | - ) { |
|
1287 | - // if a version is no longer supported, don't include it in index or list of versions served |
|
1288 | - $versions_served[ $key_versioned_endpoint ] = true; |
|
1289 | - } |
|
1290 | - } |
|
1291 | - return $versions_served; |
|
1292 | - } |
|
1293 | - |
|
1294 | - |
|
1295 | - /** |
|
1296 | - * Gets the major and minor version of EE core's version string |
|
1297 | - * |
|
1298 | - * @return string |
|
1299 | - */ |
|
1300 | - public static function core_version() |
|
1301 | - { |
|
1302 | - return apply_filters( |
|
1303 | - 'FHEE__EED_Core_REST_API__core_version', |
|
1304 | - implode( |
|
1305 | - '.', |
|
1306 | - array_slice( |
|
1307 | - explode( |
|
1308 | - '.', |
|
1309 | - espresso_version() |
|
1310 | - ), |
|
1311 | - 0, |
|
1312 | - 3 |
|
1313 | - ) |
|
1314 | - ) |
|
1315 | - ); |
|
1316 | - } |
|
1317 | - |
|
1318 | - |
|
1319 | - /** |
|
1320 | - * Gets the default limit that should be used when querying for resources |
|
1321 | - * |
|
1322 | - * @return int |
|
1323 | - */ |
|
1324 | - public static function get_default_query_limit() |
|
1325 | - { |
|
1326 | - // we actually don't use a const because we want folks to always use |
|
1327 | - // this method, not the const directly |
|
1328 | - return apply_filters( |
|
1329 | - 'FHEE__EED_Core_Rest_Api__get_default_query_limit', |
|
1330 | - 100 |
|
1331 | - ); |
|
1332 | - } |
|
1333 | - |
|
1334 | - |
|
1335 | - /** |
|
1336 | - * @param string $version api version string (i.e. '4.8.36') |
|
1337 | - * @return array |
|
1338 | - */ |
|
1339 | - public static function getCollectionRoutesIndexedByModelName($version = '') |
|
1340 | - { |
|
1341 | - $version = empty($version) ? EED_Core_Rest_Api::latest_rest_api_version() : $version; |
|
1342 | - $model_names = EED_Core_Rest_Api::model_names_with_plural_routes($version); |
|
1343 | - $collection_routes = []; |
|
1344 | - foreach ($model_names as $model_name => $model_class_name) { |
|
1345 | - $collection_routes[ strtolower($model_name) ] = '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' |
|
1346 | - . EEH_Inflector::pluralize_and_lower($model_name); |
|
1347 | - } |
|
1348 | - return $collection_routes; |
|
1349 | - } |
|
1350 | - |
|
1351 | - |
|
1352 | - /** |
|
1353 | - * Returns an array of primary key names indexed by model names. |
|
1354 | - * |
|
1355 | - * @param string $version |
|
1356 | - * @return array |
|
1357 | - */ |
|
1358 | - public static function getPrimaryKeyNamesIndexedByModelName($version = '') |
|
1359 | - { |
|
1360 | - $version = empty($version) ? EED_Core_Rest_Api::latest_rest_api_version() : $version; |
|
1361 | - $model_names = EED_Core_Rest_Api::model_names_with_plural_routes($version); |
|
1362 | - $primary_key_items = []; |
|
1363 | - foreach ($model_names as $model_name => $model_class_name) { |
|
1364 | - $primary_keys = $model_class_name::instance()->get_combined_primary_key_fields(); |
|
1365 | - foreach ($primary_keys as $primary_key_name => $primary_key_field) { |
|
1366 | - if (count($primary_keys) > 1) { |
|
1367 | - $primary_key_items[ strtolower($model_name) ][] = $primary_key_name; |
|
1368 | - } else { |
|
1369 | - $primary_key_items[ strtolower($model_name) ] = $primary_key_name; |
|
1370 | - } |
|
1371 | - } |
|
1372 | - } |
|
1373 | - return $primary_key_items; |
|
1374 | - } |
|
1375 | - |
|
1376 | - |
|
1377 | - /** |
|
1378 | - * Determines the EE REST API debug mode is activated, or not. |
|
1379 | - * |
|
1380 | - * @return bool |
|
1381 | - * @since 4.9.76.p |
|
1382 | - */ |
|
1383 | - public static function debugMode() |
|
1384 | - { |
|
1385 | - static $debug_mode = null; // could be class prop |
|
1386 | - if ($debug_mode === null) { |
|
1387 | - $debug_mode = defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE; |
|
1388 | - } |
|
1389 | - return $debug_mode; |
|
1390 | - } |
|
1391 | - |
|
1392 | - |
|
1393 | - /** |
|
1394 | - * run - initial module setup |
|
1395 | - * |
|
1396 | - * @access public |
|
1397 | - * @param WP $WP |
|
1398 | - * @return void |
|
1399 | - */ |
|
1400 | - public function run($WP) |
|
1401 | - { |
|
1402 | - } |
|
25 | + const ee_api_namespace = Domain::API_NAMESPACE; |
|
26 | + |
|
27 | + const ee_api_namespace_for_regex = 'ee\/v([^/]*)\/'; |
|
28 | + |
|
29 | + const saved_routes_option_names = 'ee_core_routes'; |
|
30 | + |
|
31 | + /** |
|
32 | + * string used in _links response bodies to make them globally unique. |
|
33 | + * |
|
34 | + * @see http://v2.wp-api.org/extending/linking/ |
|
35 | + */ |
|
36 | + const ee_api_link_namespace = 'https://api.eventespresso.com/'; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var CalculatedModelFields |
|
40 | + */ |
|
41 | + protected static $_field_calculator; |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * @return EED_Core_Rest_Api|EED_Module |
|
46 | + */ |
|
47 | + public static function instance() |
|
48 | + { |
|
49 | + return parent::get_instance(EED_Core_Rest_Api::class); |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
55 | + * |
|
56 | + * @access public |
|
57 | + * @return void |
|
58 | + */ |
|
59 | + public static function set_hooks() |
|
60 | + { |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
66 | + * |
|
67 | + * @access public |
|
68 | + * @return void |
|
69 | + */ |
|
70 | + public static function set_hooks_admin() |
|
71 | + { |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + public static function set_hooks_both() |
|
76 | + { |
|
77 | + add_action('rest_api_init', ['EED_Core_Rest_Api', 'set_hooks_rest_api'], 5); |
|
78 | + add_action('rest_api_init', ['EED_Core_Rest_Api', 'register_routes'], 10); |
|
79 | + add_filter('rest_route_data', ['EED_Core_Rest_Api', 'hide_old_endpoints'], 10, 2); |
|
80 | + add_filter( |
|
81 | + 'rest_index', |
|
82 | + ['EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filterEeMetadataIntoIndex'] |
|
83 | + ); |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @since 5.0.0.p |
|
89 | + */ |
|
90 | + public static function loadCalculatedModelFields() |
|
91 | + { |
|
92 | + EED_Core_Rest_Api::$_field_calculator = LoaderFactory::getLoader()->load( |
|
93 | + 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' |
|
94 | + ); |
|
95 | + EED_Core_Rest_Api::invalidate_cached_route_data_on_version_change(); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * sets up hooks which only need to be included as part of REST API requests; |
|
101 | + * other requests like to the frontend or admin etc don't need them |
|
102 | + * |
|
103 | + * @throws EE_Error |
|
104 | + */ |
|
105 | + public static function set_hooks_rest_api() |
|
106 | + { |
|
107 | + // set hooks which account for changes made to the API |
|
108 | + EED_Core_Rest_Api::_set_hooks_for_changes(); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * public wrapper of _set_hooks_for_changes. |
|
114 | + * Loads all the hooks which make requests to old versions of the API |
|
115 | + * appear the same as they always did |
|
116 | + * |
|
117 | + * @throws EE_Error |
|
118 | + */ |
|
119 | + public static function set_hooks_for_changes() |
|
120 | + { |
|
121 | + EED_Core_Rest_Api::_set_hooks_for_changes(); |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * Loads all the hooks which make requests to old versions of the API |
|
127 | + * appear the same as they always did |
|
128 | + * |
|
129 | + * @throws EE_Error |
|
130 | + */ |
|
131 | + protected static function _set_hooks_for_changes() |
|
132 | + { |
|
133 | + $folder_contents = EEH_File::get_contents_of_folders([EE_LIBRARIES . 'rest_api/changes'], false); |
|
134 | + foreach ($folder_contents as $classname_in_namespace => $filepath) { |
|
135 | + // ignore the base parent class |
|
136 | + // and legacy named classes |
|
137 | + if ( |
|
138 | + $classname_in_namespace === 'ChangesInBase' |
|
139 | + || strpos($classname_in_namespace, 'Changes_In_') === 0 |
|
140 | + ) { |
|
141 | + continue; |
|
142 | + } |
|
143 | + $full_classname = 'EventEspresso\core\libraries\rest_api\changes\\' . $classname_in_namespace; |
|
144 | + if (class_exists($full_classname)) { |
|
145 | + $instance_of_class = new $full_classname(); |
|
146 | + if ($instance_of_class instanceof ChangesInBase) { |
|
147 | + $instance_of_class->setHooks(); |
|
148 | + } |
|
149 | + } |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * Filters the WP routes to add our EE-related ones. This takes a bit of time |
|
156 | + * so we actually prefer to only do it when an EE plugin is activated or upgraded |
|
157 | + * |
|
158 | + * @throws EE_Error |
|
159 | + * @throws ReflectionException |
|
160 | + */ |
|
161 | + public static function register_routes() |
|
162 | + { |
|
163 | + foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_routes) { |
|
164 | + foreach ($relative_routes as $relative_route => $data_for_multiple_endpoints) { |
|
165 | + /** |
|
166 | + * @var array $data_for_multiple_endpoints numerically indexed array |
|
167 | + * but can also contain route options like { |
|
168 | + * @type array $schema { |
|
169 | + * @type callable $schema_callback |
|
170 | + * @type array $callback_args arguments that will be passed to the callback, after the |
|
171 | + * WP_REST_Request of course |
|
172 | + * } |
|
173 | + * } |
|
174 | + */ |
|
175 | + // when registering routes, register all the endpoints' data at the same time |
|
176 | + $multiple_endpoint_args = []; |
|
177 | + foreach ($data_for_multiple_endpoints as $endpoint_key => $data_for_single_endpoint) { |
|
178 | + /** |
|
179 | + * @var array $data_for_single_endpoint { |
|
180 | + * @type callable $callback |
|
181 | + * @type string methods |
|
182 | + * @type array args |
|
183 | + * @type array _links |
|
184 | + * @type array $callback_args arguments that will be passed to the callback, after the |
|
185 | + * WP_REST_Request of course |
|
186 | + * } |
|
187 | + */ |
|
188 | + // skip route options |
|
189 | + if (! is_numeric($endpoint_key)) { |
|
190 | + continue; |
|
191 | + } |
|
192 | + if (! isset($data_for_single_endpoint['callback'], $data_for_single_endpoint['methods'])) { |
|
193 | + throw new EE_Error( |
|
194 | + esc_html__( |
|
195 | + // @codingStandardsIgnoreStart |
|
196 | + 'Endpoint configuration data needs to have entries "callback" (callable) and "methods" (comma-separated list of accepts HTTP methods).', |
|
197 | + // @codingStandardsIgnoreEnd |
|
198 | + 'event_espresso' |
|
199 | + ) |
|
200 | + ); |
|
201 | + } |
|
202 | + $callback = $data_for_single_endpoint['callback']; |
|
203 | + $single_endpoint_args = [ |
|
204 | + 'methods' => $data_for_single_endpoint['methods'], |
|
205 | + 'args' => isset($data_for_single_endpoint['args']) ? $data_for_single_endpoint['args'] |
|
206 | + : [], |
|
207 | + ]; |
|
208 | + if (isset($data_for_single_endpoint['_links'])) { |
|
209 | + $single_endpoint_args['_links'] = $data_for_single_endpoint['_links']; |
|
210 | + } |
|
211 | + if (isset($data_for_single_endpoint['callback_args'])) { |
|
212 | + $callback_args = $data_for_single_endpoint['callback_args']; |
|
213 | + $single_endpoint_args['callback'] = static function (WP_REST_Request $request) use ( |
|
214 | + $callback, |
|
215 | + $callback_args |
|
216 | + ) { |
|
217 | + array_unshift($callback_args, $request); |
|
218 | + return call_user_func_array( |
|
219 | + $callback, |
|
220 | + $callback_args |
|
221 | + ); |
|
222 | + }; |
|
223 | + } else { |
|
224 | + $single_endpoint_args['callback'] = $data_for_single_endpoint['callback']; |
|
225 | + } |
|
226 | + // As of WordPress 5.5, if a permission_callback is not provided, |
|
227 | + // the REST API will issue a _doing_it_wrong notice. |
|
228 | + // Since the EE REST API defers capabilities to the db model system, |
|
229 | + // we will just use the generic WP callback for public endpoints |
|
230 | + if (! isset($single_endpoint_args['permission_callback'])) { |
|
231 | + $single_endpoint_args['permission_callback'] = '__return_true'; |
|
232 | + } |
|
233 | + $multiple_endpoint_args[] = $single_endpoint_args; |
|
234 | + } |
|
235 | + if (isset($data_for_multiple_endpoints['schema'])) { |
|
236 | + $schema_route_data = $data_for_multiple_endpoints['schema']; |
|
237 | + $schema_callback = $schema_route_data['schema_callback']; |
|
238 | + $callback_args = $schema_route_data['callback_args']; |
|
239 | + $multiple_endpoint_args['schema'] = static function () use ($schema_callback, $callback_args) { |
|
240 | + return call_user_func_array( |
|
241 | + $schema_callback, |
|
242 | + $callback_args |
|
243 | + ); |
|
244 | + }; |
|
245 | + } |
|
246 | + register_rest_route( |
|
247 | + $namespace, |
|
248 | + $relative_route, |
|
249 | + $multiple_endpoint_args |
|
250 | + ); |
|
251 | + } |
|
252 | + } |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * Checks if there was a version change or something that merits invalidating the cached |
|
258 | + * route data. If so, invalidates the cached route data so that it gets refreshed |
|
259 | + * next time the WP API is used |
|
260 | + */ |
|
261 | + public static function invalidate_cached_route_data_on_version_change() |
|
262 | + { |
|
263 | + if (EE_System::instance()->detect_req_type() !== EE_System::req_type_normal) { |
|
264 | + EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
265 | + } |
|
266 | + foreach (EE_Registry::instance()->addons as $addon) { |
|
267 | + if ($addon instanceof EE_Addon && $addon->detect_req_type() !== EE_System::req_type_normal) { |
|
268 | + EED_Core_Rest_Api::invalidate_cached_route_data(); |
|
269 | + } |
|
270 | + } |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * Removes the cached route data so it will get refreshed next time the WP API is used |
|
276 | + */ |
|
277 | + public static function invalidate_cached_route_data() |
|
278 | + { |
|
279 | + // delete the saved EE REST API routes |
|
280 | + foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden) { |
|
281 | + delete_option(EED_Core_Rest_Api::saved_routes_option_names . $version); |
|
282 | + } |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * Gets the EE route data |
|
288 | + * |
|
289 | + * @return array top-level key is the namespace, next-level key is the route and its value is array{ |
|
290 | + * @throws EE_Error |
|
291 | + * @throws ReflectionException |
|
292 | + * @type string|array $callback |
|
293 | + * @type string $methods |
|
294 | + * @type boolean $hidden_endpoint |
|
295 | + * } |
|
296 | + */ |
|
297 | + public static function get_ee_route_data() |
|
298 | + { |
|
299 | + $ee_routes = []; |
|
300 | + foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoints) { |
|
301 | + $ee_routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = EED_Core_Rest_Api::_get_ee_route_data_for_version( |
|
302 | + $version, |
|
303 | + $hidden_endpoints |
|
304 | + ); |
|
305 | + } |
|
306 | + return $ee_routes; |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * Gets the EE route data from the wp options if it exists already, |
|
312 | + * otherwise re-generates it and saves it to the option |
|
313 | + * |
|
314 | + * @param string $version |
|
315 | + * @param boolean $hidden_endpoints |
|
316 | + * @return array |
|
317 | + * @throws EE_Error |
|
318 | + * @throws ReflectionException |
|
319 | + */ |
|
320 | + protected static function _get_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
321 | + { |
|
322 | + $ee_routes = get_option(EED_Core_Rest_Api::saved_routes_option_names . $version, null); |
|
323 | + if (! $ee_routes || EED_Core_Rest_Api::debugMode()) { |
|
324 | + $ee_routes = EED_Core_Rest_Api::_save_ee_route_data_for_version($version, $hidden_endpoints); |
|
325 | + } |
|
326 | + return $ee_routes; |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * Saves the EE REST API route data to a wp option and returns it |
|
332 | + * |
|
333 | + * @param string $version |
|
334 | + * @param boolean $hidden_endpoints |
|
335 | + * @return mixed|null |
|
336 | + * @throws EE_Error |
|
337 | + * @throws ReflectionException |
|
338 | + */ |
|
339 | + protected static function _save_ee_route_data_for_version($version, $hidden_endpoints = false) |
|
340 | + { |
|
341 | + $instance = EED_Core_Rest_Api::instance(); |
|
342 | + $routes = apply_filters( |
|
343 | + 'EED_Core_Rest_Api__save_ee_route_data_for_version__routes', |
|
344 | + array_replace_recursive( |
|
345 | + $instance->_get_config_route_data_for_version($version, $hidden_endpoints), |
|
346 | + $instance->_get_meta_route_data_for_version($version, $hidden_endpoints), |
|
347 | + $instance->_get_model_route_data_for_version($version, $hidden_endpoints), |
|
348 | + $instance->_get_rpc_route_data_for_version($version, $hidden_endpoints) |
|
349 | + ) |
|
350 | + ); |
|
351 | + $option_name = EED_Core_Rest_Api::saved_routes_option_names . $version; |
|
352 | + if (get_option($option_name)) { |
|
353 | + update_option($option_name, $routes, true); |
|
354 | + } else { |
|
355 | + add_option($option_name, $routes, null, 'no'); |
|
356 | + } |
|
357 | + return $routes; |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * Calculates all the EE routes and saves it to a WordPress option so we don't |
|
363 | + * need to calculate it on every request |
|
364 | + * |
|
365 | + * @return void |
|
366 | + * @deprecated since version 4.9.1 |
|
367 | + */ |
|
368 | + public static function save_ee_routes() |
|
369 | + { |
|
370 | + if (DbStatus::isOnline()) { |
|
371 | + $instance = EED_Core_Rest_Api::instance(); |
|
372 | + $routes = apply_filters( |
|
373 | + 'EED_Core_Rest_Api__save_ee_routes__routes', |
|
374 | + array_replace_recursive( |
|
375 | + $instance->_register_config_routes(), |
|
376 | + $instance->_register_meta_routes(), |
|
377 | + $instance->_register_model_routes(), |
|
378 | + $instance->_register_rpc_routes() |
|
379 | + ) |
|
380 | + ); |
|
381 | + update_option(EED_Core_Rest_Api::saved_routes_option_names, $routes, true); |
|
382 | + } |
|
383 | + } |
|
384 | + |
|
385 | + |
|
386 | + /** |
|
387 | + * Gets all the route information relating to EE models |
|
388 | + * |
|
389 | + * @return array @see get_ee_route_data |
|
390 | + * @deprecated since version 4.9.1 |
|
391 | + */ |
|
392 | + protected function _register_model_routes() |
|
393 | + { |
|
394 | + $model_routes = []; |
|
395 | + foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
|
396 | + $model_routes[ EED_Core_Rest_Api::ee_api_namespace |
|
397 | + . $version ] = $this->_get_config_route_data_for_version($version, $hidden_endpoint); |
|
398 | + } |
|
399 | + return $model_routes; |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * Decides whether or not to add write endpoints for this model. |
|
405 | + * Currently, this defaults to exclude all global tables and models |
|
406 | + * which would allow inserting WP core data (we don't want to duplicate |
|
407 | + * what WP API does, as it's unnecessary, extra work, and potentially extra bugs) |
|
408 | + * |
|
409 | + * @param EEM_Base $model |
|
410 | + * @return bool |
|
411 | + */ |
|
412 | + public static function should_have_write_endpoints(EEM_Base $model) |
|
413 | + { |
|
414 | + if ($model->is_wp_core_model()) { |
|
415 | + return false; |
|
416 | + } |
|
417 | + foreach ($model->get_tables() as $table) { |
|
418 | + if ($table->is_global()) { |
|
419 | + return false; |
|
420 | + } |
|
421 | + } |
|
422 | + return true; |
|
423 | + } |
|
424 | + |
|
425 | + |
|
426 | + /** |
|
427 | + * Gets the names of all models which should have plural routes (eg `ee/v4.8.36/events`) |
|
428 | + * in this versioned namespace of EE4 |
|
429 | + * |
|
430 | + * @param $version |
|
431 | + * @return array keys are model names (eg 'Event') and values ar either classnames (eg 'EEM_Event') |
|
432 | + */ |
|
433 | + public static function model_names_with_plural_routes($version) |
|
434 | + { |
|
435 | + $model_version_info = new ModelVersionInfo($version); |
|
436 | + $models_to_register = $model_version_info->modelsForRequestedVersion(); |
|
437 | + // let's not bother having endpoints for extra metas |
|
438 | + unset( |
|
439 | + $models_to_register['Extra_Meta'], |
|
440 | + $models_to_register['Extra_Join'], |
|
441 | + $models_to_register['Post_Meta'] |
|
442 | + ); |
|
443 | + return apply_filters( |
|
444 | + 'FHEE__EED_Core_REST_API___register_model_routes', |
|
445 | + $models_to_register |
|
446 | + ); |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + /** |
|
451 | + * Gets the route data for EE models in the specified version |
|
452 | + * |
|
453 | + * @param string $version |
|
454 | + * @param boolean $hidden_endpoint |
|
455 | + * @return array |
|
456 | + * @throws EE_Error |
|
457 | + * @throws ReflectionException |
|
458 | + */ |
|
459 | + protected function _get_model_route_data_for_version($version, $hidden_endpoint = false) |
|
460 | + { |
|
461 | + $model_routes = []; |
|
462 | + $model_version_info = new ModelVersionInfo($version); |
|
463 | + foreach (EED_Core_Rest_Api::model_names_with_plural_routes($version) as $model_name => $model_classname) { |
|
464 | + $model = EE_Registry::instance()->load_model($model_name); |
|
465 | + // if this isn't a valid model then let's skip iterate to the next item in the loop. |
|
466 | + if (! $model instanceof EEM_Base) { |
|
467 | + continue; |
|
468 | + } |
|
469 | + // yes we could just register one route for ALL models, but then they wouldn't show up in the index |
|
470 | + $plural_model_route = EED_Core_Rest_Api::get_collection_route($model); |
|
471 | + $singular_model_route = EED_Core_Rest_Api::get_entity_route($model, '(?P<id>[^\/]+)'); |
|
472 | + $model_routes[ $plural_model_route ] = [ |
|
473 | + [ |
|
474 | + 'callback' => [ |
|
475 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
476 | + 'handleRequestGetAll', |
|
477 | + ], |
|
478 | + 'callback_args' => [$version, $model_name], |
|
479 | + 'methods' => WP_REST_Server::READABLE, |
|
480 | + 'hidden_endpoint' => $hidden_endpoint, |
|
481 | + 'args' => $this->_get_read_query_params($model, $version), |
|
482 | + '_links' => [ |
|
483 | + 'self' => rest_url(EED_Core_Rest_Api::ee_api_namespace . $version . $singular_model_route), |
|
484 | + ], |
|
485 | + ], |
|
486 | + 'schema' => [ |
|
487 | + 'schema_callback' => [ |
|
488 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
489 | + 'handleSchemaRequest', |
|
490 | + ], |
|
491 | + 'callback_args' => [$version, $model_name], |
|
492 | + ], |
|
493 | + ]; |
|
494 | + $model_routes[ $singular_model_route ] = [ |
|
495 | + [ |
|
496 | + 'callback' => [ |
|
497 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
498 | + 'handleRequestGetOne', |
|
499 | + ], |
|
500 | + 'callback_args' => [$version, $model_name], |
|
501 | + 'methods' => WP_REST_Server::READABLE, |
|
502 | + 'hidden_endpoint' => $hidden_endpoint, |
|
503 | + 'args' => $this->_get_response_selection_query_params($model, $version, true), |
|
504 | + ], |
|
505 | + ]; |
|
506 | + if ( |
|
507 | + apply_filters( |
|
508 | + 'FHEE__EED_Core_Rest_Api___get_model_route_data_for_version__add_write_endpoints', |
|
509 | + EED_Core_Rest_Api::should_have_write_endpoints($model), |
|
510 | + $model |
|
511 | + ) |
|
512 | + ) { |
|
513 | + $model_routes[ $plural_model_route ][] = [ |
|
514 | + 'callback' => [ |
|
515 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
516 | + 'handleRequestInsert', |
|
517 | + ], |
|
518 | + 'callback_args' => [$version, $model_name], |
|
519 | + 'methods' => WP_REST_Server::CREATABLE, |
|
520 | + 'hidden_endpoint' => $hidden_endpoint, |
|
521 | + 'args' => $this->_get_write_params($model_name, $model_version_info, true), |
|
522 | + ]; |
|
523 | + $model_routes[ $singular_model_route ] = array_merge( |
|
524 | + $model_routes[ $singular_model_route ], |
|
525 | + [ |
|
526 | + [ |
|
527 | + 'callback' => [ |
|
528 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
529 | + 'handleRequestUpdate', |
|
530 | + ], |
|
531 | + 'callback_args' => [$version, $model_name], |
|
532 | + 'methods' => WP_REST_Server::EDITABLE, |
|
533 | + 'hidden_endpoint' => $hidden_endpoint, |
|
534 | + 'args' => $this->_get_write_params($model_name, $model_version_info), |
|
535 | + ], |
|
536 | + [ |
|
537 | + 'callback' => [ |
|
538 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
539 | + 'handleRequestDelete', |
|
540 | + ], |
|
541 | + 'callback_args' => [$version, $model_name], |
|
542 | + 'methods' => WP_REST_Server::DELETABLE, |
|
543 | + 'hidden_endpoint' => $hidden_endpoint, |
|
544 | + 'args' => $this->_get_delete_query_params($model, $version), |
|
545 | + ], |
|
546 | + ] |
|
547 | + ); |
|
548 | + } |
|
549 | + foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
550 | + $related_route = EED_Core_Rest_Api::get_relation_route_via( |
|
551 | + $model, |
|
552 | + '(?P<id>[^\/]+)', |
|
553 | + $relation_obj |
|
554 | + ); |
|
555 | + $model_routes[ $related_route ] = [ |
|
556 | + [ |
|
557 | + 'callback' => [ |
|
558 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
|
559 | + 'handleRequestGetRelated', |
|
560 | + ], |
|
561 | + 'callback_args' => [$version, $model_name, $relation_name], |
|
562 | + 'methods' => WP_REST_Server::READABLE, |
|
563 | + 'hidden_endpoint' => $hidden_endpoint, |
|
564 | + 'args' => $this->_get_read_query_params($relation_obj->get_other_model(), $version), |
|
565 | + ], |
|
566 | + ]; |
|
567 | + |
|
568 | + $related_write_route = $related_route . '/' . '(?P<related_id>[^\/]+)'; |
|
569 | + $model_routes[ $related_write_route ] = [ |
|
570 | + [ |
|
571 | + 'callback' => [ |
|
572 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
573 | + 'handleRequestAddRelation', |
|
574 | + ], |
|
575 | + 'callback_args' => [$version, $model_name, $relation_name], |
|
576 | + 'methods' => WP_REST_Server::EDITABLE, |
|
577 | + 'hidden_endpoint' => $hidden_endpoint, |
|
578 | + 'args' => $this->_get_add_relation_query_params( |
|
579 | + $model, |
|
580 | + $relation_obj->get_other_model(), |
|
581 | + $version |
|
582 | + ), |
|
583 | + ], |
|
584 | + [ |
|
585 | + 'callback' => [ |
|
586 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Write', |
|
587 | + 'handleRequestRemoveRelation', |
|
588 | + ], |
|
589 | + 'callback_args' => [$version, $model_name, $relation_name], |
|
590 | + 'methods' => WP_REST_Server::DELETABLE, |
|
591 | + 'hidden_endpoint' => $hidden_endpoint, |
|
592 | + 'args' => [], |
|
593 | + ], |
|
594 | + ]; |
|
595 | + } |
|
596 | + } |
|
597 | + return $model_routes; |
|
598 | + } |
|
599 | + |
|
600 | + |
|
601 | + /** |
|
602 | + * Gets the relative URI to a model's REST API plural route, after the EE4 versioned namespace, |
|
603 | + * excluding the preceding slash. |
|
604 | + * Eg you pass get_plural_route_to('Event') = 'events' |
|
605 | + * |
|
606 | + * @param EEM_Base $model |
|
607 | + * @return string |
|
608 | + */ |
|
609 | + public static function get_collection_route(EEM_Base $model) |
|
610 | + { |
|
611 | + return EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
612 | + } |
|
613 | + |
|
614 | + |
|
615 | + /** |
|
616 | + * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
617 | + * excluding the preceding slash. |
|
618 | + * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
619 | + * |
|
620 | + * @param EEM_Base $model eg Event or Venue |
|
621 | + * @param string $id |
|
622 | + * @return string |
|
623 | + */ |
|
624 | + public static function get_entity_route($model, $id) |
|
625 | + { |
|
626 | + return EED_Core_Rest_Api::get_collection_route($model) . '/' . $id; |
|
627 | + } |
|
628 | + |
|
629 | + |
|
630 | + /** |
|
631 | + * Gets the relative URI to a model's REST API singular route, after the EE4 versioned namespace, |
|
632 | + * excluding the preceding slash. |
|
633 | + * Eg you pass get_plural_route_to('Event', 12) = 'events/12' |
|
634 | + * |
|
635 | + * @param EEM_Base $model eg Event or Venue |
|
636 | + * @param string $id |
|
637 | + * @param EE_Model_Relation_Base $relation_obj |
|
638 | + * @return string |
|
639 | + */ |
|
640 | + public static function get_relation_route_via(EEM_Base $model, $id, EE_Model_Relation_Base $relation_obj) |
|
641 | + { |
|
642 | + $related_model_name_endpoint_part = ModelRead::getRelatedEntityName( |
|
643 | + $relation_obj->get_other_model()->get_this_model_name(), |
|
644 | + $relation_obj |
|
645 | + ); |
|
646 | + return EED_Core_Rest_Api::get_entity_route($model, $id) . '/' . $related_model_name_endpoint_part; |
|
647 | + } |
|
648 | + |
|
649 | + |
|
650 | + /** |
|
651 | + * Adds onto the $relative_route the EE4 REST API versioned namespace. |
|
652 | + * Eg if given '4.8.36' and 'events', will return 'ee/v4.8.36/events' |
|
653 | + * |
|
654 | + * @param string $relative_route |
|
655 | + * @param string $version |
|
656 | + * @return string |
|
657 | + */ |
|
658 | + public static function get_versioned_route_to($relative_route, $version = '4.8.36') |
|
659 | + { |
|
660 | + return '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' . $relative_route; |
|
661 | + } |
|
662 | + |
|
663 | + |
|
664 | + /** |
|
665 | + * Adds all the RPC-style routes (remote procedure call-like routes, ie |
|
666 | + * routes that don't conform to the traditional REST CRUD-style). |
|
667 | + * |
|
668 | + * @deprecated since 4.9.1 |
|
669 | + */ |
|
670 | + protected function _register_rpc_routes() |
|
671 | + { |
|
672 | + $routes = []; |
|
673 | + foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
|
674 | + $routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = $this->_get_rpc_route_data_for_version( |
|
675 | + $version, |
|
676 | + $hidden_endpoint |
|
677 | + ); |
|
678 | + } |
|
679 | + return $routes; |
|
680 | + } |
|
681 | + |
|
682 | + |
|
683 | + /** |
|
684 | + * @param string $version |
|
685 | + * @param boolean $hidden_endpoint |
|
686 | + * @return array |
|
687 | + */ |
|
688 | + protected function _get_rpc_route_data_for_version($version, $hidden_endpoint = false) |
|
689 | + { |
|
690 | + $this_versions_routes = []; |
|
691 | + // checkin endpoint |
|
692 | + $this_versions_routes['registrations/(?P<REG_ID>\d+)/toggle_checkin_for_datetime/(?P<DTT_ID>\d+)'] = [ |
|
693 | + [ |
|
694 | + 'callback' => [ |
|
695 | + 'EventEspresso\core\libraries\rest_api\controllers\rpc\Checkin', |
|
696 | + 'handleRequestToggleCheckin', |
|
697 | + ], |
|
698 | + 'methods' => WP_REST_Server::CREATABLE, |
|
699 | + 'hidden_endpoint' => $hidden_endpoint, |
|
700 | + 'args' => [ |
|
701 | + 'force' => [ |
|
702 | + 'required' => false, |
|
703 | + 'default' => false, |
|
704 | + 'description' => esc_html__( |
|
705 | + // @codingStandardsIgnoreStart |
|
706 | + 'Whether to force toggle checkin, or to verify the registration status and allowed ticket uses', |
|
707 | + // @codingStandardsIgnoreEnd |
|
708 | + 'event_espresso' |
|
709 | + ), |
|
710 | + ], |
|
711 | + ], |
|
712 | + 'callback_args' => [$version], |
|
713 | + ], |
|
714 | + ]; |
|
715 | + return apply_filters( |
|
716 | + 'FHEE__EED_Core_Rest_Api___register_rpc_routes__this_versions_routes', |
|
717 | + $this_versions_routes, |
|
718 | + $version, |
|
719 | + $hidden_endpoint |
|
720 | + ); |
|
721 | + } |
|
722 | + |
|
723 | + |
|
724 | + /** |
|
725 | + * Gets the query params that can be used when request one or many |
|
726 | + * |
|
727 | + * @param EEM_Base $model |
|
728 | + * @param string $version |
|
729 | + * @return array |
|
730 | + */ |
|
731 | + protected function _get_response_selection_query_params(EEM_Base $model, $version, $single_only = false) |
|
732 | + { |
|
733 | + EED_Core_Rest_Api::loadCalculatedModelFields(); |
|
734 | + $query_params = [ |
|
735 | + 'include' => [ |
|
736 | + 'required' => false, |
|
737 | + 'default' => '*', |
|
738 | + 'type' => 'string', |
|
739 | + ], |
|
740 | + 'calculate' => [ |
|
741 | + 'required' => false, |
|
742 | + 'default' => '', |
|
743 | + 'enum' => EED_Core_Rest_Api::$_field_calculator->retrieveCalculatedFieldsForModel($model), |
|
744 | + 'type' => 'string', |
|
745 | + // because we accept a CSV list of the enumerated strings, WP core validation and sanitization |
|
746 | + // freaks out. We'll just validate this argument while handling the request |
|
747 | + 'validate_callback' => null, |
|
748 | + 'sanitize_callback' => null, |
|
749 | + ], |
|
750 | + 'password' => [ |
|
751 | + 'required' => false, |
|
752 | + 'default' => '', |
|
753 | + 'type' => 'string', |
|
754 | + ], |
|
755 | + ]; |
|
756 | + return apply_filters( |
|
757 | + 'FHEE__EED_Core_Rest_Api___get_response_selection_query_params', |
|
758 | + $query_params, |
|
759 | + $model, |
|
760 | + $version |
|
761 | + ); |
|
762 | + } |
|
763 | + |
|
764 | + |
|
765 | + /** |
|
766 | + * Gets the parameters acceptable for delete requests |
|
767 | + * |
|
768 | + * @param EEM_Base $model |
|
769 | + * @param string $version |
|
770 | + * @return array |
|
771 | + */ |
|
772 | + protected function _get_delete_query_params(EEM_Base $model, $version) |
|
773 | + { |
|
774 | + $params_for_delete = [ |
|
775 | + 'allow_blocking' => [ |
|
776 | + 'required' => false, |
|
777 | + 'default' => true, |
|
778 | + 'type' => 'boolean', |
|
779 | + ], |
|
780 | + ]; |
|
781 | + $params_for_delete['force'] = [ |
|
782 | + 'required' => false, |
|
783 | + 'default' => false, |
|
784 | + 'type' => 'boolean', |
|
785 | + ]; |
|
786 | + return apply_filters( |
|
787 | + 'FHEE__EED_Core_Rest_Api___get_delete_query_params', |
|
788 | + $params_for_delete, |
|
789 | + $model, |
|
790 | + $version |
|
791 | + ); |
|
792 | + } |
|
793 | + |
|
794 | + |
|
795 | + /** |
|
796 | + * @param EEM_Base $source_model |
|
797 | + * @param EEM_Base $related_model |
|
798 | + * @param $version |
|
799 | + * @return array |
|
800 | + * @throws EE_Error |
|
801 | + * @since 5.0.0.p |
|
802 | + */ |
|
803 | + protected function _get_add_relation_query_params(EEM_Base $source_model, EEM_Base $related_model, $version) |
|
804 | + { |
|
805 | + // if they're related through a HABTM relation, check for any non-FKs |
|
806 | + $all_relation_settings = $source_model->relation_settings(); |
|
807 | + $relation_settings = $all_relation_settings[ $related_model->get_this_model_name() ]; |
|
808 | + $params = []; |
|
809 | + if ($relation_settings instanceof EE_HABTM_Relation && $relation_settings->hasNonKeyFields()) { |
|
810 | + foreach ($relation_settings->getNonKeyFields() as $field) { |
|
811 | + /* @var $field EE_Model_Field_Base */ |
|
812 | + $params[ $field->get_name() ] = [ |
|
813 | + 'required' => ! $field->is_nullable(), |
|
814 | + 'default' => ModelDataTranslator::prepareFieldValueForJson( |
|
815 | + $field, |
|
816 | + $field->get_default_value(), |
|
817 | + $version |
|
818 | + ), |
|
819 | + 'type' => $field->getSchemaType(), |
|
820 | + 'validate_callback' => null, |
|
821 | + 'sanitize_callback' => null, |
|
822 | + ]; |
|
823 | + } |
|
824 | + } |
|
825 | + return $params; |
|
826 | + } |
|
827 | + |
|
828 | + |
|
829 | + /** |
|
830 | + * Gets info about reading query params that are acceptable |
|
831 | + * |
|
832 | + * @param EEM_Base $model eg 'Event' or 'Venue' |
|
833 | + * @param string $version |
|
834 | + * @return array describing the args acceptable when querying this model |
|
835 | + * @throws EE_Error |
|
836 | + */ |
|
837 | + protected function _get_read_query_params(EEM_Base $model, $version) |
|
838 | + { |
|
839 | + $default_orderby = []; |
|
840 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
841 | + $default_orderby[ $key_field->get_name() ] = 'ASC'; |
|
842 | + } |
|
843 | + return array_merge( |
|
844 | + $this->_get_response_selection_query_params($model, $version), |
|
845 | + [ |
|
846 | + 'where' => [ |
|
847 | + 'required' => false, |
|
848 | + 'default' => [], |
|
849 | + 'type' => 'object', |
|
850 | + // because we accept an almost infinite list of possible where conditions, WP |
|
851 | + // core validation and sanitization freaks out. We'll just validate this argument |
|
852 | + // while handling the request |
|
853 | + 'validate_callback' => null, |
|
854 | + 'sanitize_callback' => null, |
|
855 | + ], |
|
856 | + 'limit' => [ |
|
857 | + 'required' => false, |
|
858 | + 'default' => EED_Core_Rest_Api::get_default_query_limit(), |
|
859 | + 'type' => [ |
|
860 | + 'array', |
|
861 | + 'string', |
|
862 | + 'integer', |
|
863 | + ], |
|
864 | + // because we accept a variety of types, WP core validation and sanitization |
|
865 | + // freaks out. We'll just validate this argument while handling the request |
|
866 | + 'validate_callback' => null, |
|
867 | + 'sanitize_callback' => null, |
|
868 | + ], |
|
869 | + 'order_by' => [ |
|
870 | + 'required' => false, |
|
871 | + 'default' => $default_orderby, |
|
872 | + 'type' => [ |
|
873 | + 'object', |
|
874 | + 'string', |
|
875 | + ],// because we accept a variety of types, WP core validation and sanitization |
|
876 | + // freaks out. We'll just validate this argument while handling the request |
|
877 | + 'validate_callback' => null, |
|
878 | + 'sanitize_callback' => null, |
|
879 | + ], |
|
880 | + 'group_by' => [ |
|
881 | + 'required' => false, |
|
882 | + 'default' => null, |
|
883 | + 'type' => [ |
|
884 | + 'object', |
|
885 | + 'string', |
|
886 | + ], |
|
887 | + // because we accept an almost infinite list of possible groupings, |
|
888 | + // WP core validation and sanitization |
|
889 | + // freaks out. We'll just validate this argument while handling the request |
|
890 | + 'validate_callback' => null, |
|
891 | + 'sanitize_callback' => null, |
|
892 | + ], |
|
893 | + 'having' => [ |
|
894 | + 'required' => false, |
|
895 | + 'default' => null, |
|
896 | + 'type' => 'object', |
|
897 | + // because we accept an almost infinite list of possible where conditions, WP |
|
898 | + // core validation and sanitization freaks out. We'll just validate this argument |
|
899 | + // while handling the request |
|
900 | + 'validate_callback' => null, |
|
901 | + 'sanitize_callback' => null, |
|
902 | + ], |
|
903 | + 'caps' => [ |
|
904 | + 'required' => false, |
|
905 | + 'default' => EEM_Base::caps_read, |
|
906 | + 'type' => 'string', |
|
907 | + 'enum' => [ |
|
908 | + EEM_Base::caps_read, |
|
909 | + EEM_Base::caps_read_admin, |
|
910 | + EEM_Base::caps_edit, |
|
911 | + EEM_Base::caps_delete, |
|
912 | + ], |
|
913 | + ], |
|
914 | + ] |
|
915 | + ); |
|
916 | + } |
|
917 | + |
|
918 | + |
|
919 | + /** |
|
920 | + * Gets parameter information for a model regarding writing data |
|
921 | + * |
|
922 | + * @param string $model_name |
|
923 | + * @param ModelVersionInfo $model_version_info |
|
924 | + * @param boolean $create whether this is for request to create (in |
|
925 | + * which case we need all required params) or |
|
926 | + * just to update (in which case we don't |
|
927 | + * need those on every request) |
|
928 | + * @return array |
|
929 | + * @throws EE_Error |
|
930 | + * @throws ReflectionException |
|
931 | + */ |
|
932 | + protected function _get_write_params( |
|
933 | + $model_name, |
|
934 | + ModelVersionInfo $model_version_info, |
|
935 | + $create = false |
|
936 | + ) { |
|
937 | + $model = EE_Registry::instance()->load_model($model_name); |
|
938 | + $fields = $model_version_info->fieldsOnModelInThisVersion($model); |
|
939 | + |
|
940 | + // we do our own validation and sanitization within the controller |
|
941 | + $sanitize_callback = function_exists('rest_validate_value_from_schema') |
|
942 | + ? ['EED_Core_Rest_Api', 'default_sanitize_callback'] |
|
943 | + : null; |
|
944 | + $args_info = []; |
|
945 | + foreach ($fields as $field_name => $field_obj) { |
|
946 | + if ($field_obj->is_auto_increment()) { |
|
947 | + // totally ignore auto increment IDs |
|
948 | + continue; |
|
949 | + } |
|
950 | + $arg_info = $field_obj->getSchema(); |
|
951 | + $required = $create && ! $field_obj->is_nullable() && $field_obj->get_default_value() === null; |
|
952 | + $arg_info['required'] = $required; |
|
953 | + // remove the read-only flag. If it were read-only we wouldn't list it as an argument while writing, right? |
|
954 | + unset($arg_info['readonly']); |
|
955 | + $schema_properties = $field_obj->getSchemaProperties(); |
|
956 | + if ( |
|
957 | + isset($schema_properties['raw']) |
|
958 | + && $field_obj->getSchemaType() === 'object' |
|
959 | + ) { |
|
960 | + // if there's a "raw" form of this argument, use those properties instead |
|
961 | + $arg_info = array_replace( |
|
962 | + $arg_info, |
|
963 | + $schema_properties['raw'] |
|
964 | + ); |
|
965 | + } |
|
966 | + $arg_info['default'] = ModelDataTranslator::prepareFieldValueForJson( |
|
967 | + $field_obj, |
|
968 | + $field_obj->get_default_value(), |
|
969 | + $model_version_info->requestedVersion() |
|
970 | + ); |
|
971 | + $arg_info['sanitize_callback'] = $sanitize_callback; |
|
972 | + $args_info[ $field_name ] = $arg_info; |
|
973 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
974 | + $gmt_arg_info = $arg_info; |
|
975 | + $gmt_arg_info['description'] = sprintf( |
|
976 | + esc_html__( |
|
977 | + '%1$s - the value for this field in UTC. Ignored if %2$s is provided.', |
|
978 | + 'event_espresso' |
|
979 | + ), |
|
980 | + $field_obj->get_nicename(), |
|
981 | + $field_name |
|
982 | + ); |
|
983 | + $args_info[ $field_name . '_gmt' ] = $gmt_arg_info; |
|
984 | + } |
|
985 | + } |
|
986 | + return $args_info; |
|
987 | + } |
|
988 | + |
|
989 | + |
|
990 | + /** |
|
991 | + * Replacement for WP API's 'rest_parse_request_arg'. |
|
992 | + * If the value is blank but not required, don't bother validating it. |
|
993 | + * Also, it uses our email validation instead of WP API's default. |
|
994 | + * |
|
995 | + * @param $value |
|
996 | + * @param WP_REST_Request $request |
|
997 | + * @param $param |
|
998 | + * @return bool|true|WP_Error |
|
999 | + * @throws InvalidArgumentException |
|
1000 | + * @throws InvalidInterfaceException |
|
1001 | + * @throws InvalidDataTypeException |
|
1002 | + */ |
|
1003 | + public static function default_sanitize_callback($value, WP_REST_Request $request, $param) |
|
1004 | + { |
|
1005 | + $attributes = $request->get_attributes(); |
|
1006 | + if ( |
|
1007 | + ! isset($attributes['args'][ $param ]) |
|
1008 | + || ! is_array($attributes['args'][ $param ]) |
|
1009 | + ) { |
|
1010 | + $validation_result = true; |
|
1011 | + } else { |
|
1012 | + $args = $attributes['args'][ $param ]; |
|
1013 | + if ( |
|
1014 | + ( |
|
1015 | + $value === '' |
|
1016 | + || $value === null |
|
1017 | + ) |
|
1018 | + && (! isset($args['required']) |
|
1019 | + || $args['required'] === false |
|
1020 | + ) |
|
1021 | + ) { |
|
1022 | + // not required and not provided? that's cool |
|
1023 | + $validation_result = true; |
|
1024 | + } elseif ( |
|
1025 | + isset($args['format']) |
|
1026 | + && $args['format'] === 'email' |
|
1027 | + ) { |
|
1028 | + $validation_result = true; |
|
1029 | + if (! EED_Core_Rest_Api::_validate_email($value)) { |
|
1030 | + $validation_result = new WP_Error( |
|
1031 | + 'rest_invalid_param', |
|
1032 | + esc_html__( |
|
1033 | + 'The email address is not valid or does not exist.', |
|
1034 | + 'event_espresso' |
|
1035 | + ) |
|
1036 | + ); |
|
1037 | + } |
|
1038 | + } else { |
|
1039 | + $validation_result = rest_validate_value_from_schema($value, $args, $param); |
|
1040 | + } |
|
1041 | + } |
|
1042 | + if (is_wp_error($validation_result)) { |
|
1043 | + return $validation_result; |
|
1044 | + } |
|
1045 | + return rest_sanitize_request_arg($value, $request, $param); |
|
1046 | + } |
|
1047 | + |
|
1048 | + |
|
1049 | + /** |
|
1050 | + * Returns whether or not this email address is valid. Copied from EE_Email_Validation_Strategy::_validate_email() |
|
1051 | + * |
|
1052 | + * @param $email |
|
1053 | + * @return bool |
|
1054 | + * @throws InvalidArgumentException |
|
1055 | + * @throws InvalidInterfaceException |
|
1056 | + * @throws InvalidDataTypeException |
|
1057 | + */ |
|
1058 | + protected static function _validate_email($email) |
|
1059 | + { |
|
1060 | + try { |
|
1061 | + EmailAddressFactory::create($email); |
|
1062 | + return true; |
|
1063 | + } catch (EmailValidationException $e) { |
|
1064 | + return false; |
|
1065 | + } |
|
1066 | + } |
|
1067 | + |
|
1068 | + |
|
1069 | + /** |
|
1070 | + * Gets routes for the config |
|
1071 | + * |
|
1072 | + * @return array @see _register_model_routes |
|
1073 | + * @deprecated since version 4.9.1 |
|
1074 | + */ |
|
1075 | + protected function _register_config_routes() |
|
1076 | + { |
|
1077 | + $config_routes = []; |
|
1078 | + foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
|
1079 | + $config_routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = $this->_get_config_route_data_for_version( |
|
1080 | + $version, |
|
1081 | + $hidden_endpoint |
|
1082 | + ); |
|
1083 | + } |
|
1084 | + return $config_routes; |
|
1085 | + } |
|
1086 | + |
|
1087 | + |
|
1088 | + /** |
|
1089 | + * Gets routes for the config for the specified version |
|
1090 | + * |
|
1091 | + * @param string $version |
|
1092 | + * @param boolean $hidden_endpoint |
|
1093 | + * @return array |
|
1094 | + */ |
|
1095 | + protected function _get_config_route_data_for_version($version, $hidden_endpoint) |
|
1096 | + { |
|
1097 | + return [ |
|
1098 | + 'config' => [ |
|
1099 | + [ |
|
1100 | + 'callback' => [ |
|
1101 | + 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
1102 | + 'handleRequest', |
|
1103 | + ], |
|
1104 | + 'methods' => WP_REST_Server::READABLE, |
|
1105 | + 'hidden_endpoint' => $hidden_endpoint, |
|
1106 | + 'callback_args' => [$version], |
|
1107 | + ], |
|
1108 | + ], |
|
1109 | + 'site_info' => [ |
|
1110 | + [ |
|
1111 | + 'callback' => [ |
|
1112 | + 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
|
1113 | + 'handleRequestSiteInfo', |
|
1114 | + ], |
|
1115 | + 'methods' => WP_REST_Server::READABLE, |
|
1116 | + 'hidden_endpoint' => $hidden_endpoint, |
|
1117 | + 'callback_args' => [$version], |
|
1118 | + ], |
|
1119 | + ], |
|
1120 | + ]; |
|
1121 | + } |
|
1122 | + |
|
1123 | + |
|
1124 | + /** |
|
1125 | + * Gets the meta info routes |
|
1126 | + * |
|
1127 | + * @return array @see _register_model_routes |
|
1128 | + * @deprecated since version 4.9.1 |
|
1129 | + */ |
|
1130 | + protected function _register_meta_routes() |
|
1131 | + { |
|
1132 | + $meta_routes = []; |
|
1133 | + foreach (EED_Core_Rest_Api::versions_served() as $version => $hidden_endpoint) { |
|
1134 | + $meta_routes[ EED_Core_Rest_Api::ee_api_namespace . $version ] = $this->_get_meta_route_data_for_version( |
|
1135 | + $version, |
|
1136 | + $hidden_endpoint |
|
1137 | + ); |
|
1138 | + } |
|
1139 | + return $meta_routes; |
|
1140 | + } |
|
1141 | + |
|
1142 | + |
|
1143 | + /** |
|
1144 | + * @param string $version |
|
1145 | + * @param boolean $hidden_endpoint |
|
1146 | + * @return array |
|
1147 | + */ |
|
1148 | + protected function _get_meta_route_data_for_version($version, $hidden_endpoint = false) |
|
1149 | + { |
|
1150 | + return [ |
|
1151 | + 'resources' => [ |
|
1152 | + [ |
|
1153 | + 'callback' => [ |
|
1154 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Meta', |
|
1155 | + 'handleRequestModelsMeta', |
|
1156 | + ], |
|
1157 | + 'methods' => WP_REST_Server::READABLE, |
|
1158 | + 'hidden_endpoint' => $hidden_endpoint, |
|
1159 | + 'callback_args' => [$version], |
|
1160 | + ], |
|
1161 | + ], |
|
1162 | + ]; |
|
1163 | + } |
|
1164 | + |
|
1165 | + |
|
1166 | + /** |
|
1167 | + * Tries to hide old 4.6 endpoints from the |
|
1168 | + * |
|
1169 | + * @param array $route_data |
|
1170 | + * @return array |
|
1171 | + * @throws EE_Error |
|
1172 | + * @throws ReflectionException |
|
1173 | + */ |
|
1174 | + public static function hide_old_endpoints($route_data) |
|
1175 | + { |
|
1176 | + // allow API clients to override which endpoints get hidden, in case |
|
1177 | + // they want to discover particular endpoints |
|
1178 | + // also, we don't have access to the request so we have to just grab it from the superglobal |
|
1179 | + $force_show_ee_namespace = ltrim( |
|
1180 | + EED_Core_Rest_Api::getRequest()->getRequestParam('force_show_ee_namespace'), |
|
1181 | + '/' |
|
1182 | + ); |
|
1183 | + foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
1184 | + foreach ($relative_urls as $resource_name => $endpoints) { |
|
1185 | + foreach ($endpoints as $key => $endpoint) { |
|
1186 | + // skip schema and other route options |
|
1187 | + if (! is_numeric($key)) { |
|
1188 | + continue; |
|
1189 | + } |
|
1190 | + // by default, hide "hidden_endpoint"s, unless the request indicates |
|
1191 | + // to $force_show_ee_namespace, in which case only show that one |
|
1192 | + // namespace's endpoints (and hide all others) |
|
1193 | + if ( |
|
1194 | + ($force_show_ee_namespace !== '' && $force_show_ee_namespace !== $namespace) |
|
1195 | + || ($endpoint['hidden_endpoint'] && $force_show_ee_namespace === '') |
|
1196 | + ) { |
|
1197 | + $full_route = '/' . ltrim($namespace, '/'); |
|
1198 | + $full_route .= '/' . ltrim($resource_name, '/'); |
|
1199 | + unset($route_data[ $full_route ]); |
|
1200 | + } |
|
1201 | + } |
|
1202 | + } |
|
1203 | + } |
|
1204 | + return $route_data; |
|
1205 | + } |
|
1206 | + |
|
1207 | + |
|
1208 | + /** |
|
1209 | + * Returns an array describing which versions of core support serving requests for. |
|
1210 | + * Keys are core versions' major and minor version, and values are the |
|
1211 | + * LOWEST requested version they can serve. Eg, 4.7 can serve requests for 4.6-like |
|
1212 | + * data by just removing a few models and fields from the responses. However, 4.15 might remove |
|
1213 | + * the answers table entirely, in which case it would be very difficult for |
|
1214 | + * it to serve 4.6-style responses. |
|
1215 | + * Versions of core that are missing from this array are unknowns. |
|
1216 | + * previous ver |
|
1217 | + * |
|
1218 | + * @return array |
|
1219 | + */ |
|
1220 | + public static function version_compatibilities() |
|
1221 | + { |
|
1222 | + return apply_filters( |
|
1223 | + 'FHEE__EED_Core_REST_API__version_compatibilities', |
|
1224 | + [ |
|
1225 | + '4.8.29' => '4.8.29', |
|
1226 | + '4.8.33' => '4.8.29', |
|
1227 | + '4.8.34' => '4.8.29', |
|
1228 | + '4.8.36' => '4.8.29', |
|
1229 | + ] |
|
1230 | + ); |
|
1231 | + } |
|
1232 | + |
|
1233 | + |
|
1234 | + /** |
|
1235 | + * Gets the latest API version served. Eg if there |
|
1236 | + * are two versions served of the API, 4.8.29 and 4.8.32, and |
|
1237 | + * we are on core version 4.8.34, it will return the string "4.8.32" |
|
1238 | + * |
|
1239 | + * @return string |
|
1240 | + */ |
|
1241 | + public static function latest_rest_api_version() |
|
1242 | + { |
|
1243 | + $versions_served = EED_Core_Rest_Api::versions_served(); |
|
1244 | + $versions_served_keys = array_keys($versions_served); |
|
1245 | + return end($versions_served_keys); |
|
1246 | + } |
|
1247 | + |
|
1248 | + |
|
1249 | + /** |
|
1250 | + * Using EED_Core_Rest_Api::version_compatibilities(), determines what version of |
|
1251 | + * EE the API can serve requests for. Eg, if we are on 4.15 of core, and |
|
1252 | + * we can serve requests from 4.12 or later, this will return array( '4.12', '4.13', '4.14', '4.15' ). |
|
1253 | + * We also indicate whether or not this version should be put in the index or not |
|
1254 | + * |
|
1255 | + * @return array keys are API version numbers (just major and minor numbers), and values |
|
1256 | + * are whether or not they should be hidden |
|
1257 | + */ |
|
1258 | + public static function versions_served() |
|
1259 | + { |
|
1260 | + $versions_served = []; |
|
1261 | + $possibly_served_versions = EED_Core_Rest_Api::version_compatibilities(); |
|
1262 | + $lowest_compatible_version = end($possibly_served_versions); |
|
1263 | + reset($possibly_served_versions); |
|
1264 | + $versions_served_historically = array_keys($possibly_served_versions); |
|
1265 | + $latest_version = end($versions_served_historically); |
|
1266 | + reset($versions_served_historically); |
|
1267 | + // for each version of core we have ever served: |
|
1268 | + foreach ($versions_served_historically as $key_versioned_endpoint) { |
|
1269 | + // if it's not above the current core version, and it's compatible with the current version of core |
|
1270 | + |
|
1271 | + if ($key_versioned_endpoint === $latest_version) { |
|
1272 | + // don't hide the latest version in the index |
|
1273 | + $versions_served[ $key_versioned_endpoint ] = false; |
|
1274 | + } elseif ( |
|
1275 | + version_compare($key_versioned_endpoint, $lowest_compatible_version, '>=') |
|
1276 | + && version_compare($key_versioned_endpoint, EED_Core_Rest_Api::core_version(), '<') |
|
1277 | + ) { |
|
1278 | + // include, but hide, previous versions which are still supported |
|
1279 | + $versions_served[ $key_versioned_endpoint ] = true; |
|
1280 | + } elseif ( |
|
1281 | + apply_filters( |
|
1282 | + 'FHEE__EED_Core_Rest_Api__versions_served__include_incompatible_versions', |
|
1283 | + false, |
|
1284 | + $possibly_served_versions |
|
1285 | + ) |
|
1286 | + ) { |
|
1287 | + // if a version is no longer supported, don't include it in index or list of versions served |
|
1288 | + $versions_served[ $key_versioned_endpoint ] = true; |
|
1289 | + } |
|
1290 | + } |
|
1291 | + return $versions_served; |
|
1292 | + } |
|
1293 | + |
|
1294 | + |
|
1295 | + /** |
|
1296 | + * Gets the major and minor version of EE core's version string |
|
1297 | + * |
|
1298 | + * @return string |
|
1299 | + */ |
|
1300 | + public static function core_version() |
|
1301 | + { |
|
1302 | + return apply_filters( |
|
1303 | + 'FHEE__EED_Core_REST_API__core_version', |
|
1304 | + implode( |
|
1305 | + '.', |
|
1306 | + array_slice( |
|
1307 | + explode( |
|
1308 | + '.', |
|
1309 | + espresso_version() |
|
1310 | + ), |
|
1311 | + 0, |
|
1312 | + 3 |
|
1313 | + ) |
|
1314 | + ) |
|
1315 | + ); |
|
1316 | + } |
|
1317 | + |
|
1318 | + |
|
1319 | + /** |
|
1320 | + * Gets the default limit that should be used when querying for resources |
|
1321 | + * |
|
1322 | + * @return int |
|
1323 | + */ |
|
1324 | + public static function get_default_query_limit() |
|
1325 | + { |
|
1326 | + // we actually don't use a const because we want folks to always use |
|
1327 | + // this method, not the const directly |
|
1328 | + return apply_filters( |
|
1329 | + 'FHEE__EED_Core_Rest_Api__get_default_query_limit', |
|
1330 | + 100 |
|
1331 | + ); |
|
1332 | + } |
|
1333 | + |
|
1334 | + |
|
1335 | + /** |
|
1336 | + * @param string $version api version string (i.e. '4.8.36') |
|
1337 | + * @return array |
|
1338 | + */ |
|
1339 | + public static function getCollectionRoutesIndexedByModelName($version = '') |
|
1340 | + { |
|
1341 | + $version = empty($version) ? EED_Core_Rest_Api::latest_rest_api_version() : $version; |
|
1342 | + $model_names = EED_Core_Rest_Api::model_names_with_plural_routes($version); |
|
1343 | + $collection_routes = []; |
|
1344 | + foreach ($model_names as $model_name => $model_class_name) { |
|
1345 | + $collection_routes[ strtolower($model_name) ] = '/' . EED_Core_Rest_Api::ee_api_namespace . $version . '/' |
|
1346 | + . EEH_Inflector::pluralize_and_lower($model_name); |
|
1347 | + } |
|
1348 | + return $collection_routes; |
|
1349 | + } |
|
1350 | + |
|
1351 | + |
|
1352 | + /** |
|
1353 | + * Returns an array of primary key names indexed by model names. |
|
1354 | + * |
|
1355 | + * @param string $version |
|
1356 | + * @return array |
|
1357 | + */ |
|
1358 | + public static function getPrimaryKeyNamesIndexedByModelName($version = '') |
|
1359 | + { |
|
1360 | + $version = empty($version) ? EED_Core_Rest_Api::latest_rest_api_version() : $version; |
|
1361 | + $model_names = EED_Core_Rest_Api::model_names_with_plural_routes($version); |
|
1362 | + $primary_key_items = []; |
|
1363 | + foreach ($model_names as $model_name => $model_class_name) { |
|
1364 | + $primary_keys = $model_class_name::instance()->get_combined_primary_key_fields(); |
|
1365 | + foreach ($primary_keys as $primary_key_name => $primary_key_field) { |
|
1366 | + if (count($primary_keys) > 1) { |
|
1367 | + $primary_key_items[ strtolower($model_name) ][] = $primary_key_name; |
|
1368 | + } else { |
|
1369 | + $primary_key_items[ strtolower($model_name) ] = $primary_key_name; |
|
1370 | + } |
|
1371 | + } |
|
1372 | + } |
|
1373 | + return $primary_key_items; |
|
1374 | + } |
|
1375 | + |
|
1376 | + |
|
1377 | + /** |
|
1378 | + * Determines the EE REST API debug mode is activated, or not. |
|
1379 | + * |
|
1380 | + * @return bool |
|
1381 | + * @since 4.9.76.p |
|
1382 | + */ |
|
1383 | + public static function debugMode() |
|
1384 | + { |
|
1385 | + static $debug_mode = null; // could be class prop |
|
1386 | + if ($debug_mode === null) { |
|
1387 | + $debug_mode = defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE; |
|
1388 | + } |
|
1389 | + return $debug_mode; |
|
1390 | + } |
|
1391 | + |
|
1392 | + |
|
1393 | + /** |
|
1394 | + * run - initial module setup |
|
1395 | + * |
|
1396 | + * @access public |
|
1397 | + * @param WP $WP |
|
1398 | + * @return void |
|
1399 | + */ |
|
1400 | + public function run($WP) |
|
1401 | + { |
|
1402 | + } |
|
1403 | 1403 | } |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | '', |
176 | 176 | 'tckt-slctr-tbl-td-qty cntr', |
177 | 177 | '', |
178 | - 'headers="quantity-' . $this->EVT_ID . '"' |
|
178 | + 'headers="quantity-'.$this->EVT_ID.'"' |
|
179 | 179 | ); |
180 | 180 | $this->setTicketStatusDisplay($remaining); |
181 | 181 | if (empty($this->ticket_status_display)) { |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | '', |
243 | 243 | 'tckt-slctr-tbl-td-name', |
244 | 244 | '', |
245 | - 'headers="details-' . $this->EVT_ID . '"' |
|
245 | + 'headers="details-'.$this->EVT_ID.'"' |
|
246 | 246 | ); |
247 | 247 | $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); |
248 | 248 | $html .= $this->ticket_details->getShowHideLinks(); |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | '', |
277 | 277 | 'tckt-slctr-tbl-td-price jst-rght', |
278 | 278 | '', |
279 | - 'headers="price-' . $this->EVT_ID . '"' |
|
279 | + 'headers="price-'.$this->EVT_ID.'"' |
|
280 | 280 | ); |
281 | 281 | $html .= EEH_HTML::span( |
282 | 282 | EEH_Template::format_currency($this->ticket_price), |
@@ -19,368 +19,368 @@ |
||
19 | 19 | */ |
20 | 20 | class TicketSelectorRowStandard extends TicketSelectorRow |
21 | 21 | { |
22 | - /** |
|
23 | - * @var TicketDetails |
|
24 | - */ |
|
25 | - protected $ticket_details; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var EE_Ticket_Selector_Config |
|
29 | - */ |
|
30 | - protected $template_settings; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var EE_Tax_Config |
|
34 | - */ |
|
35 | - protected $tax_settings; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var boolean |
|
39 | - */ |
|
40 | - protected $prices_displayed_including_taxes; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var int |
|
44 | - */ |
|
45 | - protected $row; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var int |
|
49 | - */ |
|
50 | - protected $cols; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var boolean |
|
54 | - */ |
|
55 | - protected $hidden_input_qty = false; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var string |
|
59 | - */ |
|
60 | - protected $ticket_datetime_classes; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * TicketDetails constructor. |
|
65 | - * |
|
66 | - * @param TicketDetails $ticket_details |
|
67 | - * @param EE_Tax_Config $tax_settings |
|
68 | - * @param int $total_tickets |
|
69 | - * @param int $max_attendees |
|
70 | - * @param int $row |
|
71 | - * @param int $cols |
|
72 | - * @param boolean $required_ticket_sold_out |
|
73 | - * @param string $event_status |
|
74 | - * @param string $ticket_datetime_classes |
|
75 | - * @throws EE_Error |
|
76 | - * @throws UnexpectedEntityException |
|
77 | - */ |
|
78 | - public function __construct( |
|
79 | - TicketDetails $ticket_details, |
|
80 | - EE_Tax_Config $tax_settings, |
|
81 | - $total_tickets, |
|
82 | - $max_attendees, |
|
83 | - $row, |
|
84 | - $cols, |
|
85 | - $required_ticket_sold_out, |
|
86 | - $event_status, |
|
87 | - $ticket_datetime_classes |
|
88 | - ) { |
|
89 | - $this->ticket_details = $ticket_details; |
|
90 | - $this->template_settings = $ticket_details->getTemplateSettings(); |
|
91 | - $this->tax_settings = $tax_settings; |
|
92 | - $this->row = $row; |
|
93 | - $this->cols = $cols; |
|
94 | - $this->ticket_datetime_classes = $ticket_datetime_classes; |
|
95 | - parent::__construct( |
|
96 | - $ticket_details->getTicket(), |
|
97 | - $max_attendees, |
|
98 | - $ticket_details->getDateFormat(), |
|
99 | - $event_status, |
|
100 | - $required_ticket_sold_out, |
|
101 | - $total_tickets |
|
102 | - ); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * other ticket rows will need to know if a required ticket is sold out, |
|
108 | - * so that they are not offered for sale |
|
109 | - * |
|
110 | - * @return boolean |
|
111 | - */ |
|
112 | - public function getRequiredTicketSoldOut() |
|
113 | - { |
|
114 | - return $this->required_ticket_sold_out; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @return int |
|
120 | - */ |
|
121 | - public function getCols() |
|
122 | - { |
|
123 | - return $this->cols; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * getHtml |
|
129 | - * |
|
130 | - * @return string |
|
131 | - * @throws EE_Error |
|
132 | - * @throws ReflectionException |
|
133 | - */ |
|
134 | - public function getHtml() |
|
135 | - { |
|
136 | - $this->min = 0; |
|
137 | - $this->max = $this->ticket->max(); |
|
138 | - $remaining = $this->ticket->remaining(); |
|
139 | - $this->setTicketMinAndMax($remaining); |
|
140 | - // set flag if ticket is required (flag is set to start date so that future tickets are not blocked) |
|
141 | - $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining |
|
142 | - ? $this->ticket->start_date() |
|
143 | - : $this->required_ticket_sold_out; |
|
144 | - $this->setTicketPriceDetails(); |
|
145 | - $this->setTicketStatusClasses($remaining); |
|
146 | - $filtered_row_html = $this->getFilteredRowHtml(); |
|
147 | - if ($filtered_row_html !== false) { |
|
148 | - return $filtered_row_html; |
|
149 | - } |
|
150 | - $ticket_selector_row_html = EEH_HTML::tr( |
|
151 | - '', |
|
152 | - '', |
|
153 | - "tckt-slctr-tbl-tr {$this->status_class}{$this->ticket_datetime_classes} " |
|
154 | - . espresso_get_object_css_class($this->ticket) |
|
155 | - ); |
|
156 | - $filtered_row_content = $this->getFilteredRowContents(); |
|
157 | - if ($filtered_row_content !== false) { |
|
158 | - if ($this->max_attendees === 1) { |
|
159 | - return $ticket_selector_row_html |
|
160 | - . $filtered_row_content |
|
161 | - . $this->ticketQtyAndIdHiddenInputs() |
|
162 | - . EEH_HTML::trx(); |
|
163 | - } |
|
164 | - return $ticket_selector_row_html |
|
165 | - . $filtered_row_content |
|
166 | - . EEH_HTML::trx(); |
|
167 | - } |
|
168 | - $this->hidden_input_qty = $this->max_attendees > 1; |
|
169 | - |
|
170 | - $ticket_selector_row_html .= $this->ticketNameTableCell(); |
|
171 | - $ticket_selector_row_html .= $this->ticketPriceTableCell(); |
|
172 | - $ticket_selector_row_html .= EEH_HTML::td( |
|
173 | - '', |
|
174 | - '', |
|
175 | - 'tckt-slctr-tbl-td-qty cntr', |
|
176 | - '', |
|
177 | - 'headers="quantity-' . $this->EVT_ID . '"' |
|
178 | - ); |
|
179 | - $this->setTicketStatusDisplay($remaining); |
|
180 | - if (empty($this->ticket_status_display)) { |
|
181 | - if ($this->max_attendees === 1) { |
|
182 | - // only ONE attendee is allowed to register at a time |
|
183 | - $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister(); |
|
184 | - } elseif ($this->max > 0) { |
|
185 | - $ticket_selector_row_html .= $this->ticketQuantitySelector(); |
|
186 | - } |
|
187 | - } |
|
188 | - $ticket_selector_row_html .= $this->ticket_status_display; |
|
189 | - $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs(); |
|
190 | - $ticket_selector_row_html .= $this->ticket_details->display( |
|
191 | - $this->ticket_price, |
|
192 | - $remaining, |
|
193 | - $this->cols |
|
194 | - ); |
|
195 | - $ticket_selector_row_html .= EEH_HTML::tdx(); |
|
196 | - $ticket_selector_row_html .= EEH_HTML::trx(); |
|
197 | - |
|
198 | - |
|
199 | - $this->row++; |
|
200 | - return $ticket_selector_row_html; |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * getTicketPriceDetails |
|
206 | - * |
|
207 | - * @return void |
|
208 | - * @throws EE_Error |
|
209 | - */ |
|
210 | - protected function setTicketPriceDetails() |
|
211 | - { |
|
212 | - $this->ticket_price = $this->tax_settings->prices_displayed_including_taxes |
|
213 | - ? $this->ticket->get_ticket_total_with_taxes() |
|
214 | - : $this->ticket->get_ticket_subtotal(); |
|
215 | - $this->ticket_bundle = false; |
|
216 | - $ticket_min = $this->ticket->min(); |
|
217 | - // for ticket bundles, set min and max qty the same |
|
218 | - if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) { |
|
219 | - $this->ticket_price *= $ticket_min; |
|
220 | - $this->ticket_bundle = true; |
|
221 | - } |
|
222 | - $this->ticket_price = apply_filters( |
|
223 | - 'FHEE__ticket_selector_chart_template__ticket_price', |
|
224 | - $this->ticket_price, |
|
225 | - $this->ticket |
|
226 | - ); |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * ticketNameTableCell |
|
232 | - * |
|
233 | - * @return string |
|
234 | - * @throws EE_Error |
|
235 | - * @throws ReflectionException |
|
236 | - */ |
|
237 | - protected function ticketNameTableCell() |
|
238 | - { |
|
239 | - $html = EEH_HTML::td( |
|
240 | - '', |
|
241 | - '', |
|
242 | - 'tckt-slctr-tbl-td-name', |
|
243 | - '', |
|
244 | - 'headers="details-' . $this->EVT_ID . '"' |
|
245 | - ); |
|
246 | - $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); |
|
247 | - $html .= $this->ticket_details->getShowHideLinks(); |
|
248 | - if ($this->ticket->required()) { |
|
249 | - $html .= EEH_HTML::p( |
|
250 | - apply_filters( |
|
251 | - 'FHEE__ticket_selector_chart_template__ticket_required_message', |
|
252 | - esc_html__('This ticket is required and must be purchased.', 'event_espresso') |
|
253 | - ), |
|
254 | - '', |
|
255 | - 'ticket-required-pg' |
|
256 | - ); |
|
257 | - } |
|
258 | - $html .= EEH_HTML::tdx(); |
|
259 | - return $html; |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * ticketPriceTableCell |
|
265 | - * |
|
266 | - * @return string |
|
267 | - * @throws EE_Error |
|
268 | - */ |
|
269 | - protected function ticketPriceTableCell() |
|
270 | - { |
|
271 | - $html = ''; |
|
272 | - if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) { |
|
273 | - $html .= EEH_HTML::td( |
|
274 | - '', |
|
275 | - '', |
|
276 | - 'tckt-slctr-tbl-td-price jst-rght', |
|
277 | - '', |
|
278 | - 'headers="price-' . $this->EVT_ID . '"' |
|
279 | - ); |
|
280 | - $html .= EEH_HTML::span( |
|
281 | - EEH_Template::format_currency($this->ticket_price), |
|
282 | - '', |
|
283 | - 'tckt-price--nowrap' |
|
284 | - ); |
|
285 | - $html .= $this->ticket->taxable() |
|
286 | - ? EEH_HTML::span('*', '', 'taxable-tickets-asterisk grey-text') |
|
287 | - : ''; |
|
288 | - $html .= ' '; |
|
289 | - // phpcs:disable WordPress.WP.I18n.NoEmptyStrings |
|
290 | - $html .= EEH_HTML::span( |
|
291 | - $this->ticket_bundle |
|
292 | - ? apply_filters( |
|
293 | - 'FHEE__ticket_selector_chart_template__per_ticket_bundle_text', |
|
294 | - esc_html__(' / bundle', 'event_espresso') |
|
295 | - ) |
|
296 | - : apply_filters( |
|
297 | - 'FHEE__ticket_selector_chart_template__per_ticket_text', |
|
298 | - esc_html__('', 'event_espresso') |
|
299 | - ), |
|
300 | - '', |
|
301 | - 'smaller-text no-bold' |
|
302 | - ); |
|
303 | - $html .= ' '; |
|
304 | - $html .= EEH_HTML::tdx(); |
|
305 | - $this->cols++; |
|
306 | - } |
|
307 | - return $html; |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * onlyOneAttendeeCanRegister |
|
313 | - * |
|
314 | - * @return string |
|
315 | - * @throws EE_Error |
|
316 | - */ |
|
317 | - protected function onlyOneAttendeeCanRegister() |
|
318 | - { |
|
319 | - $this->hidden_input_qty = false; |
|
320 | - // display submit button since we have tickets available |
|
321 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
322 | - |
|
323 | - $TKT = $this->ticket->ID(); |
|
324 | - $label = esc_html__('Select this ticket', 'event_espresso'); |
|
325 | - $name = "tkt-slctr-qty-{$this->EVT_ID}"; |
|
326 | - $class = "ticket-selector-tbl-qty-slct"; |
|
327 | - $id = "{$class}-{$this->EVT_ID}-{$this->row}"; |
|
328 | - $checked = $this->total_tickets === 1 ? ' checked' : ''; |
|
329 | - |
|
330 | - $html = "<label class='ee-a11y-screen-reader-text' for='{$id}' >{$label}</label>"; |
|
331 | - $html .= "<input type='radio'{$checked} name='{$name}' id='{$id}' class='{$class}' value='{$TKT}-1' title='' />"; |
|
332 | - return $html; |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * ticketQuantitySelector |
|
338 | - * |
|
339 | - * @return string |
|
340 | - * @throws EE_Error |
|
341 | - */ |
|
342 | - protected function ticketQuantitySelector() |
|
343 | - { |
|
344 | - $this->hidden_input_qty = false; |
|
345 | - // display submit button since we have tickets available |
|
346 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
347 | - |
|
348 | - $TKT = $this->ticket->ID(); |
|
349 | - $label = esc_html__('Quantity', 'event_espresso'); |
|
350 | - $class = 'ticket-selector-tbl-qty-slct'; |
|
351 | - $id = "{$class}-{$this->EVT_ID}-{$this->row}"; |
|
352 | - |
|
353 | - $html = "<label class='ee-a11y-screen-reader-text' for='{$id}' >{$label}</label>"; |
|
354 | - $html .= "<select name='tkt-slctr-qty-{$this->EVT_ID}[{$TKT}]' id='{$id}' class='{$class}'>"; |
|
355 | - // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased |
|
356 | - if ($this->min !== 0 && ! $this->ticket->required()) { |
|
357 | - $html .= "<option value='0'> 0 </option>"; |
|
358 | - } |
|
359 | - // offer ticket quantities from the min to the max |
|
360 | - for ($i = $this->min; $i <= $this->max; $i++) { |
|
361 | - $html .= "<option value='{$i}'> {$i} </option>"; |
|
362 | - } |
|
363 | - $html .= "</select>"; |
|
364 | - return $html; |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * getHiddenInputs |
|
370 | - * |
|
371 | - * @return string |
|
372 | - * @throws EE_Error |
|
373 | - */ |
|
374 | - protected function ticketQtyAndIdHiddenInputs() |
|
375 | - { |
|
376 | - $html = ''; |
|
377 | - $EVT = $this->EVT_ID; |
|
378 | - $TKT = $this->ticket->ID(); |
|
379 | - // depending on group reg we need to change the format for qty |
|
380 | - if ($this->hidden_input_qty) { |
|
381 | - $html .= "<input type='hidden' name='tkt-slctr-qty-{$EVT}[]' value='0' />"; |
|
382 | - } |
|
383 | - $html .= "<input type='hidden' name='tkt-slctr-ticket-id-{$EVT}[]' value='{$TKT}' />"; |
|
384 | - return $html; |
|
385 | - } |
|
22 | + /** |
|
23 | + * @var TicketDetails |
|
24 | + */ |
|
25 | + protected $ticket_details; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var EE_Ticket_Selector_Config |
|
29 | + */ |
|
30 | + protected $template_settings; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var EE_Tax_Config |
|
34 | + */ |
|
35 | + protected $tax_settings; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var boolean |
|
39 | + */ |
|
40 | + protected $prices_displayed_including_taxes; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var int |
|
44 | + */ |
|
45 | + protected $row; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var int |
|
49 | + */ |
|
50 | + protected $cols; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var boolean |
|
54 | + */ |
|
55 | + protected $hidden_input_qty = false; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var string |
|
59 | + */ |
|
60 | + protected $ticket_datetime_classes; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * TicketDetails constructor. |
|
65 | + * |
|
66 | + * @param TicketDetails $ticket_details |
|
67 | + * @param EE_Tax_Config $tax_settings |
|
68 | + * @param int $total_tickets |
|
69 | + * @param int $max_attendees |
|
70 | + * @param int $row |
|
71 | + * @param int $cols |
|
72 | + * @param boolean $required_ticket_sold_out |
|
73 | + * @param string $event_status |
|
74 | + * @param string $ticket_datetime_classes |
|
75 | + * @throws EE_Error |
|
76 | + * @throws UnexpectedEntityException |
|
77 | + */ |
|
78 | + public function __construct( |
|
79 | + TicketDetails $ticket_details, |
|
80 | + EE_Tax_Config $tax_settings, |
|
81 | + $total_tickets, |
|
82 | + $max_attendees, |
|
83 | + $row, |
|
84 | + $cols, |
|
85 | + $required_ticket_sold_out, |
|
86 | + $event_status, |
|
87 | + $ticket_datetime_classes |
|
88 | + ) { |
|
89 | + $this->ticket_details = $ticket_details; |
|
90 | + $this->template_settings = $ticket_details->getTemplateSettings(); |
|
91 | + $this->tax_settings = $tax_settings; |
|
92 | + $this->row = $row; |
|
93 | + $this->cols = $cols; |
|
94 | + $this->ticket_datetime_classes = $ticket_datetime_classes; |
|
95 | + parent::__construct( |
|
96 | + $ticket_details->getTicket(), |
|
97 | + $max_attendees, |
|
98 | + $ticket_details->getDateFormat(), |
|
99 | + $event_status, |
|
100 | + $required_ticket_sold_out, |
|
101 | + $total_tickets |
|
102 | + ); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * other ticket rows will need to know if a required ticket is sold out, |
|
108 | + * so that they are not offered for sale |
|
109 | + * |
|
110 | + * @return boolean |
|
111 | + */ |
|
112 | + public function getRequiredTicketSoldOut() |
|
113 | + { |
|
114 | + return $this->required_ticket_sold_out; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @return int |
|
120 | + */ |
|
121 | + public function getCols() |
|
122 | + { |
|
123 | + return $this->cols; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * getHtml |
|
129 | + * |
|
130 | + * @return string |
|
131 | + * @throws EE_Error |
|
132 | + * @throws ReflectionException |
|
133 | + */ |
|
134 | + public function getHtml() |
|
135 | + { |
|
136 | + $this->min = 0; |
|
137 | + $this->max = $this->ticket->max(); |
|
138 | + $remaining = $this->ticket->remaining(); |
|
139 | + $this->setTicketMinAndMax($remaining); |
|
140 | + // set flag if ticket is required (flag is set to start date so that future tickets are not blocked) |
|
141 | + $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining |
|
142 | + ? $this->ticket->start_date() |
|
143 | + : $this->required_ticket_sold_out; |
|
144 | + $this->setTicketPriceDetails(); |
|
145 | + $this->setTicketStatusClasses($remaining); |
|
146 | + $filtered_row_html = $this->getFilteredRowHtml(); |
|
147 | + if ($filtered_row_html !== false) { |
|
148 | + return $filtered_row_html; |
|
149 | + } |
|
150 | + $ticket_selector_row_html = EEH_HTML::tr( |
|
151 | + '', |
|
152 | + '', |
|
153 | + "tckt-slctr-tbl-tr {$this->status_class}{$this->ticket_datetime_classes} " |
|
154 | + . espresso_get_object_css_class($this->ticket) |
|
155 | + ); |
|
156 | + $filtered_row_content = $this->getFilteredRowContents(); |
|
157 | + if ($filtered_row_content !== false) { |
|
158 | + if ($this->max_attendees === 1) { |
|
159 | + return $ticket_selector_row_html |
|
160 | + . $filtered_row_content |
|
161 | + . $this->ticketQtyAndIdHiddenInputs() |
|
162 | + . EEH_HTML::trx(); |
|
163 | + } |
|
164 | + return $ticket_selector_row_html |
|
165 | + . $filtered_row_content |
|
166 | + . EEH_HTML::trx(); |
|
167 | + } |
|
168 | + $this->hidden_input_qty = $this->max_attendees > 1; |
|
169 | + |
|
170 | + $ticket_selector_row_html .= $this->ticketNameTableCell(); |
|
171 | + $ticket_selector_row_html .= $this->ticketPriceTableCell(); |
|
172 | + $ticket_selector_row_html .= EEH_HTML::td( |
|
173 | + '', |
|
174 | + '', |
|
175 | + 'tckt-slctr-tbl-td-qty cntr', |
|
176 | + '', |
|
177 | + 'headers="quantity-' . $this->EVT_ID . '"' |
|
178 | + ); |
|
179 | + $this->setTicketStatusDisplay($remaining); |
|
180 | + if (empty($this->ticket_status_display)) { |
|
181 | + if ($this->max_attendees === 1) { |
|
182 | + // only ONE attendee is allowed to register at a time |
|
183 | + $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister(); |
|
184 | + } elseif ($this->max > 0) { |
|
185 | + $ticket_selector_row_html .= $this->ticketQuantitySelector(); |
|
186 | + } |
|
187 | + } |
|
188 | + $ticket_selector_row_html .= $this->ticket_status_display; |
|
189 | + $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs(); |
|
190 | + $ticket_selector_row_html .= $this->ticket_details->display( |
|
191 | + $this->ticket_price, |
|
192 | + $remaining, |
|
193 | + $this->cols |
|
194 | + ); |
|
195 | + $ticket_selector_row_html .= EEH_HTML::tdx(); |
|
196 | + $ticket_selector_row_html .= EEH_HTML::trx(); |
|
197 | + |
|
198 | + |
|
199 | + $this->row++; |
|
200 | + return $ticket_selector_row_html; |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * getTicketPriceDetails |
|
206 | + * |
|
207 | + * @return void |
|
208 | + * @throws EE_Error |
|
209 | + */ |
|
210 | + protected function setTicketPriceDetails() |
|
211 | + { |
|
212 | + $this->ticket_price = $this->tax_settings->prices_displayed_including_taxes |
|
213 | + ? $this->ticket->get_ticket_total_with_taxes() |
|
214 | + : $this->ticket->get_ticket_subtotal(); |
|
215 | + $this->ticket_bundle = false; |
|
216 | + $ticket_min = $this->ticket->min(); |
|
217 | + // for ticket bundles, set min and max qty the same |
|
218 | + if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) { |
|
219 | + $this->ticket_price *= $ticket_min; |
|
220 | + $this->ticket_bundle = true; |
|
221 | + } |
|
222 | + $this->ticket_price = apply_filters( |
|
223 | + 'FHEE__ticket_selector_chart_template__ticket_price', |
|
224 | + $this->ticket_price, |
|
225 | + $this->ticket |
|
226 | + ); |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * ticketNameTableCell |
|
232 | + * |
|
233 | + * @return string |
|
234 | + * @throws EE_Error |
|
235 | + * @throws ReflectionException |
|
236 | + */ |
|
237 | + protected function ticketNameTableCell() |
|
238 | + { |
|
239 | + $html = EEH_HTML::td( |
|
240 | + '', |
|
241 | + '', |
|
242 | + 'tckt-slctr-tbl-td-name', |
|
243 | + '', |
|
244 | + 'headers="details-' . $this->EVT_ID . '"' |
|
245 | + ); |
|
246 | + $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); |
|
247 | + $html .= $this->ticket_details->getShowHideLinks(); |
|
248 | + if ($this->ticket->required()) { |
|
249 | + $html .= EEH_HTML::p( |
|
250 | + apply_filters( |
|
251 | + 'FHEE__ticket_selector_chart_template__ticket_required_message', |
|
252 | + esc_html__('This ticket is required and must be purchased.', 'event_espresso') |
|
253 | + ), |
|
254 | + '', |
|
255 | + 'ticket-required-pg' |
|
256 | + ); |
|
257 | + } |
|
258 | + $html .= EEH_HTML::tdx(); |
|
259 | + return $html; |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * ticketPriceTableCell |
|
265 | + * |
|
266 | + * @return string |
|
267 | + * @throws EE_Error |
|
268 | + */ |
|
269 | + protected function ticketPriceTableCell() |
|
270 | + { |
|
271 | + $html = ''; |
|
272 | + if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) { |
|
273 | + $html .= EEH_HTML::td( |
|
274 | + '', |
|
275 | + '', |
|
276 | + 'tckt-slctr-tbl-td-price jst-rght', |
|
277 | + '', |
|
278 | + 'headers="price-' . $this->EVT_ID . '"' |
|
279 | + ); |
|
280 | + $html .= EEH_HTML::span( |
|
281 | + EEH_Template::format_currency($this->ticket_price), |
|
282 | + '', |
|
283 | + 'tckt-price--nowrap' |
|
284 | + ); |
|
285 | + $html .= $this->ticket->taxable() |
|
286 | + ? EEH_HTML::span('*', '', 'taxable-tickets-asterisk grey-text') |
|
287 | + : ''; |
|
288 | + $html .= ' '; |
|
289 | + // phpcs:disable WordPress.WP.I18n.NoEmptyStrings |
|
290 | + $html .= EEH_HTML::span( |
|
291 | + $this->ticket_bundle |
|
292 | + ? apply_filters( |
|
293 | + 'FHEE__ticket_selector_chart_template__per_ticket_bundle_text', |
|
294 | + esc_html__(' / bundle', 'event_espresso') |
|
295 | + ) |
|
296 | + : apply_filters( |
|
297 | + 'FHEE__ticket_selector_chart_template__per_ticket_text', |
|
298 | + esc_html__('', 'event_espresso') |
|
299 | + ), |
|
300 | + '', |
|
301 | + 'smaller-text no-bold' |
|
302 | + ); |
|
303 | + $html .= ' '; |
|
304 | + $html .= EEH_HTML::tdx(); |
|
305 | + $this->cols++; |
|
306 | + } |
|
307 | + return $html; |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * onlyOneAttendeeCanRegister |
|
313 | + * |
|
314 | + * @return string |
|
315 | + * @throws EE_Error |
|
316 | + */ |
|
317 | + protected function onlyOneAttendeeCanRegister() |
|
318 | + { |
|
319 | + $this->hidden_input_qty = false; |
|
320 | + // display submit button since we have tickets available |
|
321 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
322 | + |
|
323 | + $TKT = $this->ticket->ID(); |
|
324 | + $label = esc_html__('Select this ticket', 'event_espresso'); |
|
325 | + $name = "tkt-slctr-qty-{$this->EVT_ID}"; |
|
326 | + $class = "ticket-selector-tbl-qty-slct"; |
|
327 | + $id = "{$class}-{$this->EVT_ID}-{$this->row}"; |
|
328 | + $checked = $this->total_tickets === 1 ? ' checked' : ''; |
|
329 | + |
|
330 | + $html = "<label class='ee-a11y-screen-reader-text' for='{$id}' >{$label}</label>"; |
|
331 | + $html .= "<input type='radio'{$checked} name='{$name}' id='{$id}' class='{$class}' value='{$TKT}-1' title='' />"; |
|
332 | + return $html; |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * ticketQuantitySelector |
|
338 | + * |
|
339 | + * @return string |
|
340 | + * @throws EE_Error |
|
341 | + */ |
|
342 | + protected function ticketQuantitySelector() |
|
343 | + { |
|
344 | + $this->hidden_input_qty = false; |
|
345 | + // display submit button since we have tickets available |
|
346 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
347 | + |
|
348 | + $TKT = $this->ticket->ID(); |
|
349 | + $label = esc_html__('Quantity', 'event_espresso'); |
|
350 | + $class = 'ticket-selector-tbl-qty-slct'; |
|
351 | + $id = "{$class}-{$this->EVT_ID}-{$this->row}"; |
|
352 | + |
|
353 | + $html = "<label class='ee-a11y-screen-reader-text' for='{$id}' >{$label}</label>"; |
|
354 | + $html .= "<select name='tkt-slctr-qty-{$this->EVT_ID}[{$TKT}]' id='{$id}' class='{$class}'>"; |
|
355 | + // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased |
|
356 | + if ($this->min !== 0 && ! $this->ticket->required()) { |
|
357 | + $html .= "<option value='0'> 0 </option>"; |
|
358 | + } |
|
359 | + // offer ticket quantities from the min to the max |
|
360 | + for ($i = $this->min; $i <= $this->max; $i++) { |
|
361 | + $html .= "<option value='{$i}'> {$i} </option>"; |
|
362 | + } |
|
363 | + $html .= "</select>"; |
|
364 | + return $html; |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * getHiddenInputs |
|
370 | + * |
|
371 | + * @return string |
|
372 | + * @throws EE_Error |
|
373 | + */ |
|
374 | + protected function ticketQtyAndIdHiddenInputs() |
|
375 | + { |
|
376 | + $html = ''; |
|
377 | + $EVT = $this->EVT_ID; |
|
378 | + $TKT = $this->ticket->ID(); |
|
379 | + // depending on group reg we need to change the format for qty |
|
380 | + if ($this->hidden_input_qty) { |
|
381 | + $html .= "<input type='hidden' name='tkt-slctr-qty-{$EVT}[]' value='0' />"; |
|
382 | + } |
|
383 | + $html .= "<input type='hidden' name='tkt-slctr-ticket-id-{$EVT}[]' value='{$TKT}' />"; |
|
384 | + return $html; |
|
385 | + } |
|
386 | 386 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | $this->ticket_selector_config->getShowDatetimeSelector() |
93 | 93 | !== EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
94 | 94 | ) { |
95 | - $datetime_selector = new DatetimeSelector( |
|
95 | + $datetime_selector = new DatetimeSelector( |
|
96 | 96 | $this->event, |
97 | 97 | $this->tickets, |
98 | 98 | $this->ticket_selector_config, |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | ? $datetime_selector->getTicketDatetimeClasses($ticket) |
122 | 122 | : '' |
123 | 123 | ); |
124 | - $ticket_row_html = $ticket_selector_row->getHtml(); |
|
124 | + $ticket_row_html = $ticket_selector_row->getHtml(); |
|
125 | 125 | // check if something was actually returned |
126 | - if (! empty($ticket_row_html)) { |
|
126 | + if ( ! empty($ticket_row_html)) { |
|
127 | 127 | // add any output to the cumulative HTML |
128 | 128 | $all_ticket_rows_html .= $ticket_row_html; |
129 | 129 | } |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | esc_html__('Qty', 'event_espresso'), |
169 | 169 | $this->event->ID() |
170 | 170 | ); |
171 | - $this->template_args['template_path'] = TICKET_SELECTOR_TEMPLATES_PATH . 'standard_ticket_selector.template.php'; |
|
171 | + $this->template_args['template_path'] = TICKET_SELECTOR_TEMPLATES_PATH.'standard_ticket_selector.template.php'; |
|
172 | 172 | remove_all_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector'); |
173 | 173 | } |
174 | 174 | } |
@@ -20,154 +20,154 @@ |
||
20 | 20 | */ |
21 | 21 | class TicketSelectorStandard extends TicketSelector |
22 | 22 | { |
23 | - /** |
|
24 | - * @var string $date_format |
|
25 | - */ |
|
26 | - protected $date_format; |
|
23 | + /** |
|
24 | + * @var string $date_format |
|
25 | + */ |
|
26 | + protected $date_format; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @var string $time_format |
|
30 | - */ |
|
31 | - protected $time_format; |
|
28 | + /** |
|
29 | + * @var string $time_format |
|
30 | + */ |
|
31 | + protected $time_format; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @var EE_Ticket_Selector_Config $ticket_selector_config |
|
35 | - */ |
|
36 | - protected $ticket_selector_config; |
|
33 | + /** |
|
34 | + * @var EE_Ticket_Selector_Config $ticket_selector_config |
|
35 | + */ |
|
36 | + protected $ticket_selector_config; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @var EE_Tax_Config $tax_config |
|
40 | - */ |
|
41 | - protected $tax_config; |
|
38 | + /** |
|
39 | + * @var EE_Tax_Config $tax_config |
|
40 | + */ |
|
41 | + protected $tax_config; |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * TicketSelectorSimple constructor. |
|
46 | - * |
|
47 | - * @param EE_Ticket_Selector_Config $ticket_selector_config |
|
48 | - * @param EE_Tax_Config $tax_config |
|
49 | - * @param EE_Event $event |
|
50 | - * @param EE_Ticket[] $tickets |
|
51 | - * @param int $max_attendees |
|
52 | - * @param array $template_args |
|
53 | - * @param string $date_format |
|
54 | - * @param string $time_format |
|
55 | - */ |
|
56 | - public function __construct( |
|
57 | - EE_Ticket_Selector_Config $ticket_selector_config, |
|
58 | - EE_Tax_Config $tax_config, |
|
59 | - EE_Event $event, |
|
60 | - array $tickets, |
|
61 | - int $max_attendees, |
|
62 | - array $template_args, |
|
63 | - $date_format = 'Y-m-d', |
|
64 | - $time_format = 'g:i a' |
|
65 | - ) { |
|
66 | - $this->ticket_selector_config = $ticket_selector_config; |
|
67 | - $this->tax_config = $tax_config; |
|
68 | - $this->date_format = $date_format; |
|
69 | - $this->time_format = $time_format; |
|
70 | - parent::__construct($event, $tickets, $max_attendees, $template_args); |
|
71 | - } |
|
44 | + /** |
|
45 | + * TicketSelectorSimple constructor. |
|
46 | + * |
|
47 | + * @param EE_Ticket_Selector_Config $ticket_selector_config |
|
48 | + * @param EE_Tax_Config $tax_config |
|
49 | + * @param EE_Event $event |
|
50 | + * @param EE_Ticket[] $tickets |
|
51 | + * @param int $max_attendees |
|
52 | + * @param array $template_args |
|
53 | + * @param string $date_format |
|
54 | + * @param string $time_format |
|
55 | + */ |
|
56 | + public function __construct( |
|
57 | + EE_Ticket_Selector_Config $ticket_selector_config, |
|
58 | + EE_Tax_Config $tax_config, |
|
59 | + EE_Event $event, |
|
60 | + array $tickets, |
|
61 | + int $max_attendees, |
|
62 | + array $template_args, |
|
63 | + $date_format = 'Y-m-d', |
|
64 | + $time_format = 'g:i a' |
|
65 | + ) { |
|
66 | + $this->ticket_selector_config = $ticket_selector_config; |
|
67 | + $this->tax_config = $tax_config; |
|
68 | + $this->date_format = $date_format; |
|
69 | + $this->time_format = $time_format; |
|
70 | + parent::__construct($event, $tickets, $max_attendees, $template_args); |
|
71 | + } |
|
72 | 72 | |
73 | 73 | |
74 | - /** |
|
75 | - * sets any and all template args that are required for this Ticket Selector |
|
76 | - * |
|
77 | - * @return void |
|
78 | - * @throws EE_Error |
|
79 | - * @throws ReflectionException |
|
80 | - */ |
|
81 | - protected function addTemplateArgs() |
|
82 | - { |
|
83 | - $this->ticket_rows = 0; |
|
84 | - $all_ticket_rows_html = ''; |
|
85 | - $required_ticket_sold_out = false; |
|
86 | - // flag to indicate that at least one taxable ticket has been encountered |
|
87 | - $taxable_tickets = false; |
|
88 | - $datetime_selector = null; |
|
89 | - $this->template_args['datetime_selector'] = ''; |
|
90 | - if ( |
|
91 | - $this->ticket_selector_config->getShowDatetimeSelector() |
|
92 | - !== EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
93 | - ) { |
|
94 | - $datetime_selector = new DatetimeSelector( |
|
95 | - $this->event, |
|
96 | - $this->tickets, |
|
97 | - $this->ticket_selector_config, |
|
98 | - $this->date_format, |
|
99 | - $this->time_format |
|
100 | - ); |
|
101 | - $this->template_args['datetime_selector'] = $datetime_selector->getDatetimeSelector(); |
|
102 | - } |
|
103 | - $total_tickets = count($this->tickets); |
|
104 | - // loop through tickets |
|
105 | - foreach ($this->tickets as $ticket) { |
|
106 | - if ($ticket instanceof EE_Ticket) { |
|
107 | - $this->ticket_rows++; |
|
108 | - $cols = 2; |
|
109 | - $taxable_tickets = $ticket->taxable() ? true : $taxable_tickets; |
|
110 | - $ticket_selector_row = new TicketSelectorRowStandard( |
|
111 | - new TicketDetails($ticket, $this->ticket_selector_config, $this->template_args), |
|
112 | - $this->tax_config, |
|
113 | - $total_tickets, |
|
114 | - $this->max_attendees, |
|
115 | - $this->ticket_rows, |
|
116 | - $cols, |
|
117 | - $required_ticket_sold_out, |
|
118 | - $this->template_args['event_status'], |
|
119 | - $datetime_selector instanceof DatetimeSelector |
|
120 | - ? $datetime_selector->getTicketDatetimeClasses($ticket) |
|
121 | - : '' |
|
122 | - ); |
|
123 | - $ticket_row_html = $ticket_selector_row->getHtml(); |
|
124 | - // check if something was actually returned |
|
125 | - if (! empty($ticket_row_html)) { |
|
126 | - // add any output to the cumulative HTML |
|
127 | - $all_ticket_rows_html .= $ticket_row_html; |
|
128 | - } |
|
129 | - if (empty($ticket_row_html) || ! $ticket_selector_row->isOnSale()) { |
|
130 | - // decrement the ticket row count since it looks like one has been removed |
|
131 | - $this->ticket_rows--; |
|
132 | - } |
|
74 | + /** |
|
75 | + * sets any and all template args that are required for this Ticket Selector |
|
76 | + * |
|
77 | + * @return void |
|
78 | + * @throws EE_Error |
|
79 | + * @throws ReflectionException |
|
80 | + */ |
|
81 | + protected function addTemplateArgs() |
|
82 | + { |
|
83 | + $this->ticket_rows = 0; |
|
84 | + $all_ticket_rows_html = ''; |
|
85 | + $required_ticket_sold_out = false; |
|
86 | + // flag to indicate that at least one taxable ticket has been encountered |
|
87 | + $taxable_tickets = false; |
|
88 | + $datetime_selector = null; |
|
89 | + $this->template_args['datetime_selector'] = ''; |
|
90 | + if ( |
|
91 | + $this->ticket_selector_config->getShowDatetimeSelector() |
|
92 | + !== EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
93 | + ) { |
|
94 | + $datetime_selector = new DatetimeSelector( |
|
95 | + $this->event, |
|
96 | + $this->tickets, |
|
97 | + $this->ticket_selector_config, |
|
98 | + $this->date_format, |
|
99 | + $this->time_format |
|
100 | + ); |
|
101 | + $this->template_args['datetime_selector'] = $datetime_selector->getDatetimeSelector(); |
|
102 | + } |
|
103 | + $total_tickets = count($this->tickets); |
|
104 | + // loop through tickets |
|
105 | + foreach ($this->tickets as $ticket) { |
|
106 | + if ($ticket instanceof EE_Ticket) { |
|
107 | + $this->ticket_rows++; |
|
108 | + $cols = 2; |
|
109 | + $taxable_tickets = $ticket->taxable() ? true : $taxable_tickets; |
|
110 | + $ticket_selector_row = new TicketSelectorRowStandard( |
|
111 | + new TicketDetails($ticket, $this->ticket_selector_config, $this->template_args), |
|
112 | + $this->tax_config, |
|
113 | + $total_tickets, |
|
114 | + $this->max_attendees, |
|
115 | + $this->ticket_rows, |
|
116 | + $cols, |
|
117 | + $required_ticket_sold_out, |
|
118 | + $this->template_args['event_status'], |
|
119 | + $datetime_selector instanceof DatetimeSelector |
|
120 | + ? $datetime_selector->getTicketDatetimeClasses($ticket) |
|
121 | + : '' |
|
122 | + ); |
|
123 | + $ticket_row_html = $ticket_selector_row->getHtml(); |
|
124 | + // check if something was actually returned |
|
125 | + if (! empty($ticket_row_html)) { |
|
126 | + // add any output to the cumulative HTML |
|
127 | + $all_ticket_rows_html .= $ticket_row_html; |
|
128 | + } |
|
129 | + if (empty($ticket_row_html) || ! $ticket_selector_row->isOnSale()) { |
|
130 | + // decrement the ticket row count since it looks like one has been removed |
|
131 | + $this->ticket_rows--; |
|
132 | + } |
|
133 | 133 | |
134 | - $required_ticket_sold_out = $ticket_selector_row->getRequiredTicketSoldOut(); |
|
135 | - } |
|
136 | - } |
|
137 | - $this->template_args['row'] = $this->ticket_rows; |
|
138 | - $this->template_args['ticket_row_html'] = $all_ticket_rows_html; |
|
139 | - $this->template_args['taxable_tickets'] = $taxable_tickets; |
|
140 | - $this->template_args['prices_displayed_including_taxes'] = $this->tax_config->prices_displayed_including_taxes; |
|
134 | + $required_ticket_sold_out = $ticket_selector_row->getRequiredTicketSoldOut(); |
|
135 | + } |
|
136 | + } |
|
137 | + $this->template_args['row'] = $this->ticket_rows; |
|
138 | + $this->template_args['ticket_row_html'] = $all_ticket_rows_html; |
|
139 | + $this->template_args['taxable_tickets'] = $taxable_tickets; |
|
140 | + $this->template_args['prices_displayed_including_taxes'] = $this->tax_config->prices_displayed_including_taxes; |
|
141 | 141 | |
142 | 142 | |
143 | - /** |
|
144 | - * Filters the text printed for the header of the price column in the ticket selector table |
|
145 | - * |
|
146 | - * @param string 'Price' The translatable text to display in the table header for price |
|
147 | - * @param int $EVT_ID The Event ID |
|
148 | - * @since 4.7.2 |
|
149 | - * |
|
150 | - */ |
|
151 | - $this->template_args['table_header_price'] = apply_filters( |
|
152 | - 'FHEE__ticket_selector_chart_template__table_header_price', |
|
153 | - esc_html__('Price', 'event_espresso'), |
|
154 | - $this->event->ID() |
|
155 | - ); |
|
143 | + /** |
|
144 | + * Filters the text printed for the header of the price column in the ticket selector table |
|
145 | + * |
|
146 | + * @param string 'Price' The translatable text to display in the table header for price |
|
147 | + * @param int $EVT_ID The Event ID |
|
148 | + * @since 4.7.2 |
|
149 | + * |
|
150 | + */ |
|
151 | + $this->template_args['table_header_price'] = apply_filters( |
|
152 | + 'FHEE__ticket_selector_chart_template__table_header_price', |
|
153 | + esc_html__('Price', 'event_espresso'), |
|
154 | + $this->event->ID() |
|
155 | + ); |
|
156 | 156 | |
157 | - /** |
|
158 | - * Filters the text printed for the header of the quantity column in the ticket selector table |
|
159 | - * |
|
160 | - * @param string 'Qty' The translatable text to display in the table header for the Quantity of tickets |
|
161 | - * @param int $EVT_ID The Event ID |
|
162 | - * @since 4.7.2 |
|
163 | - * |
|
164 | - */ |
|
165 | - $this->template_args['table_header_qty'] = apply_filters( |
|
166 | - 'FHEE__ticket_selector_chart_template__table_header_qty', |
|
167 | - esc_html__('Qty', 'event_espresso'), |
|
168 | - $this->event->ID() |
|
169 | - ); |
|
170 | - $this->template_args['template_path'] = TICKET_SELECTOR_TEMPLATES_PATH . 'standard_ticket_selector.template.php'; |
|
171 | - remove_all_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector'); |
|
172 | - } |
|
157 | + /** |
|
158 | + * Filters the text printed for the header of the quantity column in the ticket selector table |
|
159 | + * |
|
160 | + * @param string 'Qty' The translatable text to display in the table header for the Quantity of tickets |
|
161 | + * @param int $EVT_ID The Event ID |
|
162 | + * @since 4.7.2 |
|
163 | + * |
|
164 | + */ |
|
165 | + $this->template_args['table_header_qty'] = apply_filters( |
|
166 | + 'FHEE__ticket_selector_chart_template__table_header_qty', |
|
167 | + esc_html__('Qty', 'event_espresso'), |
|
168 | + $this->event->ID() |
|
169 | + ); |
|
170 | + $this->template_args['template_path'] = TICKET_SELECTOR_TEMPLATES_PATH . 'standard_ticket_selector.template.php'; |
|
171 | + remove_all_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector'); |
|
172 | + } |
|
173 | 173 | } |
@@ -138,10 +138,10 @@ discard block |
||
138 | 138 | if (defined('TICKET_SELECTOR_ASSETS_URL')) { |
139 | 139 | return; |
140 | 140 | } |
141 | - define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
141 | + define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__).'assets/'); |
|
142 | 142 | define( |
143 | 143 | 'TICKET_SELECTOR_TEMPLATES_PATH', |
144 | - str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/' |
|
144 | + str_replace('\\', '/', plugin_dir_path(__FILE__)).'templates/' |
|
145 | 145 | ); |
146 | 146 | // initialize config |
147 | 147 | EED_Ticket_Selector::instance()->set_config(); |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | */ |
164 | 164 | public static function ticketSelector(): DisplayTicketSelector |
165 | 165 | { |
166 | - if (! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) { |
|
166 | + if ( ! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) { |
|
167 | 167 | EED_Ticket_Selector::$ticket_selector = LoaderFactory::getLoader()->getShared( |
168 | 168 | DisplayTicketSelector::class, |
169 | 169 | [ |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | */ |
195 | 195 | public static function getIframeEmbedButton() |
196 | 196 | { |
197 | - if (! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) { |
|
197 | + if ( ! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) { |
|
198 | 198 | self::$iframe_embed_button = new TicketSelectorIframeEmbedButton(); |
199 | 199 | } |
200 | 200 | return self::$iframe_embed_button; |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | // add some style |
303 | 303 | wp_register_style( |
304 | 304 | 'ticket_selector', |
305 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css', |
|
305 | + TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css', |
|
306 | 306 | [], |
307 | 307 | EVENT_ESPRESSO_VERSION |
308 | 308 | ); |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | // make it dance |
311 | 311 | wp_register_script( |
312 | 312 | 'ticket_selector', |
313 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', |
|
313 | + TICKET_SELECTOR_ASSETS_URL.'ticket_selector.js', |
|
314 | 314 | ['espresso_core'], |
315 | 315 | EVENT_ESPRESSO_VERSION, |
316 | 316 | true |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | */ |
358 | 358 | public static function iframeCss(array $iframe_css) |
359 | 359 | { |
360 | - $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css'; |
|
360 | + $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css'; |
|
361 | 361 | return $iframe_css; |
362 | 362 | } |
363 | 363 | |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | */ |
371 | 371 | public static function iframeJs(array $iframe_js) |
372 | 372 | { |
373 | - $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js'; |
|
373 | + $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL.'ticket_selector.js'; |
|
374 | 374 | return $iframe_js; |
375 | 375 | } |
376 | 376 |
@@ -18,491 +18,491 @@ |
||
18 | 18 | */ |
19 | 19 | class EED_Ticket_Selector extends EED_Module |
20 | 20 | { |
21 | - /** |
|
22 | - * @var DisplayTicketSelector $ticket_selector |
|
23 | - */ |
|
24 | - private static $ticket_selector; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var TicketSelectorIframeEmbedButton $iframe_embed_button |
|
28 | - */ |
|
29 | - private static $iframe_embed_button; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @return EED_Module|EED_Ticket_Selector |
|
34 | - * @throws EE_Error |
|
35 | - * @throws ReflectionException |
|
36 | - */ |
|
37 | - public static function instance() |
|
38 | - { |
|
39 | - return parent::get_instance(__CLASS__); |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * @return EE_Ticket_Selector_Config |
|
45 | - * @throws EE_Error |
|
46 | - * @throws ReflectionException |
|
47 | - */ |
|
48 | - public static function ticketConfig() |
|
49 | - { |
|
50 | - EED_Ticket_Selector::instance()->set_config(); |
|
51 | - return EED_Ticket_Selector::instance()->config(); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @return void |
|
57 | - */ |
|
58 | - protected function set_config() |
|
59 | - { |
|
60 | - if ($this->_config instanceof EE_Ticket_Selector_Config) { |
|
61 | - return; |
|
62 | - } |
|
63 | - $this->set_config_section('template_settings'); |
|
64 | - $this->set_config_class('EE_Ticket_Selector_Config'); |
|
65 | - $this->set_config_name('EED_Ticket_Selector'); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
71 | - * |
|
72 | - * @return void |
|
73 | - */ |
|
74 | - public static function set_hooks() |
|
75 | - { |
|
76 | - // routing |
|
77 | - EED_Module::registerRoute( |
|
78 | - 'iframe', |
|
79 | - 'EED_Ticket_Selector', |
|
80 | - 'ticket_selector_iframe', |
|
81 | - 'ticket_selector' |
|
82 | - ); |
|
83 | - EED_Module::registerRoute( |
|
84 | - 'process_ticket_selections', |
|
85 | - 'EED_Ticket_Selector', |
|
86 | - 'process_ticket_selections' |
|
87 | - ); |
|
88 | - EED_Module::registerRoute( |
|
89 | - 'cancel_ticket_selections', |
|
90 | - 'EED_Ticket_Selector', |
|
91 | - 'cancel_ticket_selections' |
|
92 | - ); |
|
93 | - add_action('wp_loaded', ['EED_Ticket_Selector', 'set_definitions'], 2); |
|
94 | - add_action('AHEE_event_details_header_bottom', ['EED_Ticket_Selector', 'display_ticket_selector'], 10, 1); |
|
95 | - add_action('wp_enqueue_scripts', ['EED_Ticket_Selector', 'translate_js_strings'], 0); |
|
96 | - add_action('wp_enqueue_scripts', ['EED_Ticket_Selector', 'load_tckt_slctr_assets'], 10); |
|
97 | - EED_Ticket_Selector::loadIframeAssets(); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
103 | - * |
|
104 | - * @return void |
|
105 | - */ |
|
106 | - public static function set_hooks_admin() |
|
107 | - { |
|
108 | - // hook into the end of the \EE_Admin_Page::_load_page_dependencies() |
|
109 | - // to load assets for "espresso_events" page on the "edit" route (action) |
|
110 | - add_action( |
|
111 | - 'admin_init', |
|
112 | - ['EED_Ticket_Selector', 'ticket_selector_iframe_embed_button'], |
|
113 | - 10 |
|
114 | - ); |
|
115 | - /** |
|
116 | - * Make sure assets for the ticket selector are loaded on the espresso registrations route so admin side |
|
117 | - * registrations work. |
|
118 | - */ |
|
119 | - add_action( |
|
120 | - 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_registrations__new_registration', |
|
121 | - ['EED_Ticket_Selector', 'set_definitions'], |
|
122 | - 10 |
|
123 | - ); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * set_definitions |
|
129 | - * |
|
130 | - * @return void |
|
131 | - * @throws EE_Error |
|
132 | - * @throws ReflectionException |
|
133 | - */ |
|
134 | - public static function set_definitions() |
|
135 | - { |
|
136 | - // don't do this twice |
|
137 | - if (defined('TICKET_SELECTOR_ASSETS_URL')) { |
|
138 | - return; |
|
139 | - } |
|
140 | - define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
141 | - define( |
|
142 | - 'TICKET_SELECTOR_TEMPLATES_PATH', |
|
143 | - str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/' |
|
144 | - ); |
|
145 | - // initialize config |
|
146 | - EED_Ticket_Selector::instance()->set_config(); |
|
147 | - // if config is not set, initialize |
|
148 | - if ( |
|
149 | - ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config |
|
150 | - ) { |
|
151 | - EED_Ticket_Selector::instance()->set_config(); |
|
152 | - EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = |
|
153 | - EED_Ticket_Selector::instance()->config(); |
|
154 | - } |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * @return DisplayTicketSelector |
|
160 | - * @throws EE_Error |
|
161 | - * @throws ReflectionException |
|
162 | - */ |
|
163 | - public static function ticketSelector(): DisplayTicketSelector |
|
164 | - { |
|
165 | - if (! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) { |
|
166 | - EED_Ticket_Selector::$ticket_selector = LoaderFactory::getLoader()->getShared( |
|
167 | - DisplayTicketSelector::class, |
|
168 | - [ |
|
169 | - null, |
|
170 | - EED_Ticket_Selector::getRequest(), |
|
171 | - EED_Ticket_Selector::ticketConfig(), |
|
172 | - EED_Events_Archive::is_iframe(), |
|
173 | - ] |
|
174 | - ); |
|
175 | - } |
|
176 | - return EED_Ticket_Selector::$ticket_selector; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * gets the ball rolling |
|
182 | - * |
|
183 | - * @param WP $WP |
|
184 | - * @return void |
|
185 | - */ |
|
186 | - public function run($WP) |
|
187 | - { |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * @return TicketSelectorIframeEmbedButton |
|
193 | - */ |
|
194 | - public static function getIframeEmbedButton() |
|
195 | - { |
|
196 | - if (! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) { |
|
197 | - self::$iframe_embed_button = new TicketSelectorIframeEmbedButton(); |
|
198 | - } |
|
199 | - return self::$iframe_embed_button; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * ticket_selector_iframe_embed_button |
|
205 | - * |
|
206 | - * @return void |
|
207 | - */ |
|
208 | - public static function ticket_selector_iframe_embed_button() |
|
209 | - { |
|
210 | - $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
211 | - $iframe_embed_button->addEventEditorIframeEmbedButton(); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * ticket_selector_iframe |
|
217 | - * |
|
218 | - * @return void |
|
219 | - * @throws DomainException |
|
220 | - */ |
|
221 | - public function ticket_selector_iframe() |
|
222 | - { |
|
223 | - EE_Dependency_Map::register_dependencies( |
|
224 | - TicketSelectorIframe::class, |
|
225 | - [ |
|
226 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
227 | - 'EventEspresso\core\services\request\CurrentPage' => EE_Dependency_Map::load_from_cache, |
|
228 | - 'EventEspresso\core\services\request\RequestInterface' => EE_Dependency_Map::load_from_cache, |
|
229 | - ] |
|
230 | - ); |
|
231 | - $ticket_selector_iframe = LoaderFactory::getLoader()->getNew(TicketSelectorIframe::class); |
|
232 | - $ticket_selector_iframe->display(); |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * creates buttons for selecting number of attendees for an event |
|
238 | - * |
|
239 | - * @param WP_Post|int $event |
|
240 | - * @param bool $view_details |
|
241 | - * @return string |
|
242 | - * @throws EE_Error |
|
243 | - * @throws ReflectionException |
|
244 | - */ |
|
245 | - public static function display_ticket_selector($event = null, $view_details = false) |
|
246 | - { |
|
247 | - return EED_Ticket_Selector::ticketSelector()->display($event, $view_details); |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * @return bool or FALSE |
|
253 | - * @throws EE_Error |
|
254 | - * @throws InvalidArgumentException |
|
255 | - * @throws InvalidInterfaceException |
|
256 | - * @throws InvalidDataTypeException |
|
257 | - * @throws ReflectionException |
|
258 | - */ |
|
259 | - public function process_ticket_selections() |
|
260 | - { |
|
261 | - /** @var EventEspresso\modules\ticket_selector\ProcessTicketSelector $form */ |
|
262 | - $form = LoaderFactory::getLoader()->getShared('EventEspresso\modules\ticket_selector\ProcessTicketSelector'); |
|
263 | - return $form->processTicketSelections(); |
|
264 | - } |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * @return bool |
|
269 | - * @throws InvalidArgumentException |
|
270 | - * @throws InvalidInterfaceException |
|
271 | - * @throws InvalidDataTypeException |
|
272 | - * @throws EE_Error |
|
273 | - * @throws ReflectionException |
|
274 | - */ |
|
275 | - public static function cancel_ticket_selections() |
|
276 | - { |
|
277 | - /** @var EventEspresso\modules\ticket_selector\ProcessTicketSelector $form */ |
|
278 | - $form = LoaderFactory::getLoader()->getShared('EventEspresso\modules\ticket_selector\ProcessTicketSelector'); |
|
279 | - return $form->cancelTicketSelections(); |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * @return void |
|
285 | - */ |
|
286 | - public static function translate_js_strings() |
|
287 | - { |
|
288 | - EE_Registry::$i18n_js_strings['please_select_date_filter_notice'] = esc_html__( |
|
289 | - 'please select a datetime', |
|
290 | - 'event_espresso' |
|
291 | - ); |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * @return void |
|
297 | - */ |
|
298 | - public static function load_tckt_slctr_assets() |
|
299 | - { |
|
300 | - if (apply_filters('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', false)) { |
|
301 | - // add some style |
|
302 | - wp_register_style( |
|
303 | - 'ticket_selector', |
|
304 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css', |
|
305 | - [], |
|
306 | - EVENT_ESPRESSO_VERSION |
|
307 | - ); |
|
308 | - wp_enqueue_style('ticket_selector'); |
|
309 | - // make it dance |
|
310 | - wp_register_script( |
|
311 | - 'ticket_selector', |
|
312 | - TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', |
|
313 | - ['espresso_core'], |
|
314 | - EVENT_ESPRESSO_VERSION, |
|
315 | - true |
|
316 | - ); |
|
317 | - wp_enqueue_script('ticket_selector'); |
|
318 | - require_once EE_LIBRARIES |
|
319 | - . 'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php'; |
|
320 | - EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts(); |
|
321 | - } |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - /** |
|
326 | - * @return void |
|
327 | - */ |
|
328 | - public static function loadIframeAssets() |
|
329 | - { |
|
330 | - // for event lists |
|
331 | - add_filter( |
|
332 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
333 | - ['EED_Ticket_Selector', 'iframeCss'] |
|
334 | - ); |
|
335 | - add_filter( |
|
336 | - 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
337 | - ['EED_Ticket_Selector', 'iframeJs'] |
|
338 | - ); |
|
339 | - // for ticket selectors |
|
340 | - add_filter( |
|
341 | - 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css', |
|
342 | - ['EED_Ticket_Selector', 'iframeCss'] |
|
343 | - ); |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
349 | - * |
|
350 | - * @param array $iframe_css |
|
351 | - * @return array |
|
352 | - */ |
|
353 | - public static function iframeCss(array $iframe_css) |
|
354 | - { |
|
355 | - $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css'; |
|
356 | - return $iframe_css; |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
362 | - * |
|
363 | - * @param array $iframe_js |
|
364 | - * @return array |
|
365 | - */ |
|
366 | - public static function iframeJs(array $iframe_js) |
|
367 | - { |
|
368 | - $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js'; |
|
369 | - return $iframe_js; |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - /****************************** DEPRECATED ******************************/ |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * @return string |
|
378 | - * @throws EE_Error |
|
379 | - * @throws ReflectionException |
|
380 | - * @deprecated |
|
381 | - */ |
|
382 | - public static function display_view_details_btn() |
|
383 | - { |
|
384 | - // todo add doing_it_wrong() notice during next major version |
|
385 | - return EED_Ticket_Selector::ticketSelector()->displayViewDetailsButton(); |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * @return string |
|
391 | - * @throws EE_Error |
|
392 | - * @throws ReflectionException |
|
393 | - * @deprecated |
|
394 | - */ |
|
395 | - public static function display_ticket_selector_submit() |
|
396 | - { |
|
397 | - // todo add doing_it_wrong() notice during next major version |
|
398 | - return EED_Ticket_Selector::ticketSelector()->displaySubmitButton(); |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * @param string $permalink_string |
|
404 | - * @param int $id |
|
405 | - * @param string $new_title |
|
406 | - * @param string $new_slug |
|
407 | - * @return string |
|
408 | - * @throws InvalidArgumentException |
|
409 | - * @throws InvalidDataTypeException |
|
410 | - * @throws InvalidInterfaceException |
|
411 | - * @deprecated |
|
412 | - */ |
|
413 | - public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '') |
|
414 | - { |
|
415 | - $request = self::getRequest(); |
|
416 | - // todo add doing_it_wrong() notice during next major version |
|
417 | - if ( |
|
418 | - $request->getRequestParam('page') === 'espresso_events' |
|
419 | - && $request->getRequestParam('action') === 'edit' |
|
420 | - ) { |
|
421 | - $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
422 | - $iframe_embed_button->addEventEditorIframeEmbedButton(); |
|
423 | - } |
|
424 | - return ''; |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * @param int $ID |
|
430 | - * @param string $external_url |
|
431 | - * @return string |
|
432 | - * @throws EE_Error |
|
433 | - * @throws ReflectionException |
|
434 | - * @deprecated |
|
435 | - */ |
|
436 | - public static function ticket_selector_form_open($ID = 0, $external_url = '') |
|
437 | - { |
|
438 | - // todo add doing_it_wrong() notice during next major version |
|
439 | - return EED_Ticket_Selector::ticketSelector()->formOpen($ID, $external_url); |
|
440 | - } |
|
441 | - |
|
442 | - |
|
443 | - /** |
|
444 | - * @return string |
|
445 | - * @throws EE_Error |
|
446 | - * @throws ReflectionException |
|
447 | - * @deprecated |
|
448 | - */ |
|
449 | - public static function ticket_selector_form_close() |
|
450 | - { |
|
451 | - // todo add doing_it_wrong() notice during next major version |
|
452 | - return EED_Ticket_Selector::ticketSelector()->formClose(); |
|
453 | - } |
|
454 | - |
|
455 | - |
|
456 | - /** |
|
457 | - * @return string |
|
458 | - * @throws EE_Error |
|
459 | - * @throws ReflectionException |
|
460 | - * @deprecated |
|
461 | - */ |
|
462 | - public static function no_tkt_slctr_end_dv() |
|
463 | - { |
|
464 | - // todo add doing_it_wrong() notice during next major version |
|
465 | - return EED_Ticket_Selector::ticketSelector()->ticketSelectorEndDiv(); |
|
466 | - } |
|
467 | - |
|
468 | - |
|
469 | - /** |
|
470 | - * @return string |
|
471 | - * @throws EE_Error |
|
472 | - * @throws ReflectionException |
|
473 | - * @deprecated 4.9.13 |
|
474 | - */ |
|
475 | - public static function tkt_slctr_end_dv() |
|
476 | - { |
|
477 | - return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
478 | - } |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * @return string |
|
483 | - * @throws EE_Error |
|
484 | - * @throws ReflectionException |
|
485 | - * @deprecated |
|
486 | - */ |
|
487 | - public static function clear_tkt_slctr() |
|
488 | - { |
|
489 | - return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
490 | - } |
|
491 | - |
|
492 | - |
|
493 | - /** |
|
494 | - * @deprecated |
|
495 | - */ |
|
496 | - public static function load_tckt_slctr_assets_admin() |
|
497 | - { |
|
498 | - $request = self::getRequest(); |
|
499 | - // todo add doing_it_wrong() notice during next major version |
|
500 | - if ( |
|
501 | - $request->getRequestParam('page') === 'espresso_events' |
|
502 | - && $request->getRequestParam('action') === 'edit' |
|
503 | - ) { |
|
504 | - $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
505 | - $iframe_embed_button->embedButtonAssets(); |
|
506 | - } |
|
507 | - } |
|
21 | + /** |
|
22 | + * @var DisplayTicketSelector $ticket_selector |
|
23 | + */ |
|
24 | + private static $ticket_selector; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var TicketSelectorIframeEmbedButton $iframe_embed_button |
|
28 | + */ |
|
29 | + private static $iframe_embed_button; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @return EED_Module|EED_Ticket_Selector |
|
34 | + * @throws EE_Error |
|
35 | + * @throws ReflectionException |
|
36 | + */ |
|
37 | + public static function instance() |
|
38 | + { |
|
39 | + return parent::get_instance(__CLASS__); |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * @return EE_Ticket_Selector_Config |
|
45 | + * @throws EE_Error |
|
46 | + * @throws ReflectionException |
|
47 | + */ |
|
48 | + public static function ticketConfig() |
|
49 | + { |
|
50 | + EED_Ticket_Selector::instance()->set_config(); |
|
51 | + return EED_Ticket_Selector::instance()->config(); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @return void |
|
57 | + */ |
|
58 | + protected function set_config() |
|
59 | + { |
|
60 | + if ($this->_config instanceof EE_Ticket_Selector_Config) { |
|
61 | + return; |
|
62 | + } |
|
63 | + $this->set_config_section('template_settings'); |
|
64 | + $this->set_config_class('EE_Ticket_Selector_Config'); |
|
65 | + $this->set_config_name('EED_Ticket_Selector'); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
71 | + * |
|
72 | + * @return void |
|
73 | + */ |
|
74 | + public static function set_hooks() |
|
75 | + { |
|
76 | + // routing |
|
77 | + EED_Module::registerRoute( |
|
78 | + 'iframe', |
|
79 | + 'EED_Ticket_Selector', |
|
80 | + 'ticket_selector_iframe', |
|
81 | + 'ticket_selector' |
|
82 | + ); |
|
83 | + EED_Module::registerRoute( |
|
84 | + 'process_ticket_selections', |
|
85 | + 'EED_Ticket_Selector', |
|
86 | + 'process_ticket_selections' |
|
87 | + ); |
|
88 | + EED_Module::registerRoute( |
|
89 | + 'cancel_ticket_selections', |
|
90 | + 'EED_Ticket_Selector', |
|
91 | + 'cancel_ticket_selections' |
|
92 | + ); |
|
93 | + add_action('wp_loaded', ['EED_Ticket_Selector', 'set_definitions'], 2); |
|
94 | + add_action('AHEE_event_details_header_bottom', ['EED_Ticket_Selector', 'display_ticket_selector'], 10, 1); |
|
95 | + add_action('wp_enqueue_scripts', ['EED_Ticket_Selector', 'translate_js_strings'], 0); |
|
96 | + add_action('wp_enqueue_scripts', ['EED_Ticket_Selector', 'load_tckt_slctr_assets'], 10); |
|
97 | + EED_Ticket_Selector::loadIframeAssets(); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
103 | + * |
|
104 | + * @return void |
|
105 | + */ |
|
106 | + public static function set_hooks_admin() |
|
107 | + { |
|
108 | + // hook into the end of the \EE_Admin_Page::_load_page_dependencies() |
|
109 | + // to load assets for "espresso_events" page on the "edit" route (action) |
|
110 | + add_action( |
|
111 | + 'admin_init', |
|
112 | + ['EED_Ticket_Selector', 'ticket_selector_iframe_embed_button'], |
|
113 | + 10 |
|
114 | + ); |
|
115 | + /** |
|
116 | + * Make sure assets for the ticket selector are loaded on the espresso registrations route so admin side |
|
117 | + * registrations work. |
|
118 | + */ |
|
119 | + add_action( |
|
120 | + 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_registrations__new_registration', |
|
121 | + ['EED_Ticket_Selector', 'set_definitions'], |
|
122 | + 10 |
|
123 | + ); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * set_definitions |
|
129 | + * |
|
130 | + * @return void |
|
131 | + * @throws EE_Error |
|
132 | + * @throws ReflectionException |
|
133 | + */ |
|
134 | + public static function set_definitions() |
|
135 | + { |
|
136 | + // don't do this twice |
|
137 | + if (defined('TICKET_SELECTOR_ASSETS_URL')) { |
|
138 | + return; |
|
139 | + } |
|
140 | + define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
141 | + define( |
|
142 | + 'TICKET_SELECTOR_TEMPLATES_PATH', |
|
143 | + str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/' |
|
144 | + ); |
|
145 | + // initialize config |
|
146 | + EED_Ticket_Selector::instance()->set_config(); |
|
147 | + // if config is not set, initialize |
|
148 | + if ( |
|
149 | + ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config |
|
150 | + ) { |
|
151 | + EED_Ticket_Selector::instance()->set_config(); |
|
152 | + EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = |
|
153 | + EED_Ticket_Selector::instance()->config(); |
|
154 | + } |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * @return DisplayTicketSelector |
|
160 | + * @throws EE_Error |
|
161 | + * @throws ReflectionException |
|
162 | + */ |
|
163 | + public static function ticketSelector(): DisplayTicketSelector |
|
164 | + { |
|
165 | + if (! EED_Ticket_Selector::$ticket_selector instanceof DisplayTicketSelector) { |
|
166 | + EED_Ticket_Selector::$ticket_selector = LoaderFactory::getLoader()->getShared( |
|
167 | + DisplayTicketSelector::class, |
|
168 | + [ |
|
169 | + null, |
|
170 | + EED_Ticket_Selector::getRequest(), |
|
171 | + EED_Ticket_Selector::ticketConfig(), |
|
172 | + EED_Events_Archive::is_iframe(), |
|
173 | + ] |
|
174 | + ); |
|
175 | + } |
|
176 | + return EED_Ticket_Selector::$ticket_selector; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * gets the ball rolling |
|
182 | + * |
|
183 | + * @param WP $WP |
|
184 | + * @return void |
|
185 | + */ |
|
186 | + public function run($WP) |
|
187 | + { |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * @return TicketSelectorIframeEmbedButton |
|
193 | + */ |
|
194 | + public static function getIframeEmbedButton() |
|
195 | + { |
|
196 | + if (! self::$iframe_embed_button instanceof TicketSelectorIframeEmbedButton) { |
|
197 | + self::$iframe_embed_button = new TicketSelectorIframeEmbedButton(); |
|
198 | + } |
|
199 | + return self::$iframe_embed_button; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * ticket_selector_iframe_embed_button |
|
205 | + * |
|
206 | + * @return void |
|
207 | + */ |
|
208 | + public static function ticket_selector_iframe_embed_button() |
|
209 | + { |
|
210 | + $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
211 | + $iframe_embed_button->addEventEditorIframeEmbedButton(); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * ticket_selector_iframe |
|
217 | + * |
|
218 | + * @return void |
|
219 | + * @throws DomainException |
|
220 | + */ |
|
221 | + public function ticket_selector_iframe() |
|
222 | + { |
|
223 | + EE_Dependency_Map::register_dependencies( |
|
224 | + TicketSelectorIframe::class, |
|
225 | + [ |
|
226 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
227 | + 'EventEspresso\core\services\request\CurrentPage' => EE_Dependency_Map::load_from_cache, |
|
228 | + 'EventEspresso\core\services\request\RequestInterface' => EE_Dependency_Map::load_from_cache, |
|
229 | + ] |
|
230 | + ); |
|
231 | + $ticket_selector_iframe = LoaderFactory::getLoader()->getNew(TicketSelectorIframe::class); |
|
232 | + $ticket_selector_iframe->display(); |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * creates buttons for selecting number of attendees for an event |
|
238 | + * |
|
239 | + * @param WP_Post|int $event |
|
240 | + * @param bool $view_details |
|
241 | + * @return string |
|
242 | + * @throws EE_Error |
|
243 | + * @throws ReflectionException |
|
244 | + */ |
|
245 | + public static function display_ticket_selector($event = null, $view_details = false) |
|
246 | + { |
|
247 | + return EED_Ticket_Selector::ticketSelector()->display($event, $view_details); |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * @return bool or FALSE |
|
253 | + * @throws EE_Error |
|
254 | + * @throws InvalidArgumentException |
|
255 | + * @throws InvalidInterfaceException |
|
256 | + * @throws InvalidDataTypeException |
|
257 | + * @throws ReflectionException |
|
258 | + */ |
|
259 | + public function process_ticket_selections() |
|
260 | + { |
|
261 | + /** @var EventEspresso\modules\ticket_selector\ProcessTicketSelector $form */ |
|
262 | + $form = LoaderFactory::getLoader()->getShared('EventEspresso\modules\ticket_selector\ProcessTicketSelector'); |
|
263 | + return $form->processTicketSelections(); |
|
264 | + } |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * @return bool |
|
269 | + * @throws InvalidArgumentException |
|
270 | + * @throws InvalidInterfaceException |
|
271 | + * @throws InvalidDataTypeException |
|
272 | + * @throws EE_Error |
|
273 | + * @throws ReflectionException |
|
274 | + */ |
|
275 | + public static function cancel_ticket_selections() |
|
276 | + { |
|
277 | + /** @var EventEspresso\modules\ticket_selector\ProcessTicketSelector $form */ |
|
278 | + $form = LoaderFactory::getLoader()->getShared('EventEspresso\modules\ticket_selector\ProcessTicketSelector'); |
|
279 | + return $form->cancelTicketSelections(); |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * @return void |
|
285 | + */ |
|
286 | + public static function translate_js_strings() |
|
287 | + { |
|
288 | + EE_Registry::$i18n_js_strings['please_select_date_filter_notice'] = esc_html__( |
|
289 | + 'please select a datetime', |
|
290 | + 'event_espresso' |
|
291 | + ); |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * @return void |
|
297 | + */ |
|
298 | + public static function load_tckt_slctr_assets() |
|
299 | + { |
|
300 | + if (apply_filters('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', false)) { |
|
301 | + // add some style |
|
302 | + wp_register_style( |
|
303 | + 'ticket_selector', |
|
304 | + TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css', |
|
305 | + [], |
|
306 | + EVENT_ESPRESSO_VERSION |
|
307 | + ); |
|
308 | + wp_enqueue_style('ticket_selector'); |
|
309 | + // make it dance |
|
310 | + wp_register_script( |
|
311 | + 'ticket_selector', |
|
312 | + TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', |
|
313 | + ['espresso_core'], |
|
314 | + EVENT_ESPRESSO_VERSION, |
|
315 | + true |
|
316 | + ); |
|
317 | + wp_enqueue_script('ticket_selector'); |
|
318 | + require_once EE_LIBRARIES |
|
319 | + . 'form_sections/strategies/display/EE_Checkbox_Dropdown_Selector_Display_Strategy.strategy.php'; |
|
320 | + EE_Checkbox_Dropdown_Selector_Display_Strategy::enqueue_styles_and_scripts(); |
|
321 | + } |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + /** |
|
326 | + * @return void |
|
327 | + */ |
|
328 | + public static function loadIframeAssets() |
|
329 | + { |
|
330 | + // for event lists |
|
331 | + add_filter( |
|
332 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
|
333 | + ['EED_Ticket_Selector', 'iframeCss'] |
|
334 | + ); |
|
335 | + add_filter( |
|
336 | + 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
|
337 | + ['EED_Ticket_Selector', 'iframeJs'] |
|
338 | + ); |
|
339 | + // for ticket selectors |
|
340 | + add_filter( |
|
341 | + 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css', |
|
342 | + ['EED_Ticket_Selector', 'iframeCss'] |
|
343 | + ); |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
349 | + * |
|
350 | + * @param array $iframe_css |
|
351 | + * @return array |
|
352 | + */ |
|
353 | + public static function iframeCss(array $iframe_css) |
|
354 | + { |
|
355 | + $iframe_css['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css'; |
|
356 | + return $iframe_css; |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * Informs the rest of the forms system what CSS and JS is needed to display the input |
|
362 | + * |
|
363 | + * @param array $iframe_js |
|
364 | + * @return array |
|
365 | + */ |
|
366 | + public static function iframeJs(array $iframe_js) |
|
367 | + { |
|
368 | + $iframe_js['ticket_selector'] = TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js'; |
|
369 | + return $iframe_js; |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + /****************************** DEPRECATED ******************************/ |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * @return string |
|
378 | + * @throws EE_Error |
|
379 | + * @throws ReflectionException |
|
380 | + * @deprecated |
|
381 | + */ |
|
382 | + public static function display_view_details_btn() |
|
383 | + { |
|
384 | + // todo add doing_it_wrong() notice during next major version |
|
385 | + return EED_Ticket_Selector::ticketSelector()->displayViewDetailsButton(); |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * @return string |
|
391 | + * @throws EE_Error |
|
392 | + * @throws ReflectionException |
|
393 | + * @deprecated |
|
394 | + */ |
|
395 | + public static function display_ticket_selector_submit() |
|
396 | + { |
|
397 | + // todo add doing_it_wrong() notice during next major version |
|
398 | + return EED_Ticket_Selector::ticketSelector()->displaySubmitButton(); |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * @param string $permalink_string |
|
404 | + * @param int $id |
|
405 | + * @param string $new_title |
|
406 | + * @param string $new_slug |
|
407 | + * @return string |
|
408 | + * @throws InvalidArgumentException |
|
409 | + * @throws InvalidDataTypeException |
|
410 | + * @throws InvalidInterfaceException |
|
411 | + * @deprecated |
|
412 | + */ |
|
413 | + public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '') |
|
414 | + { |
|
415 | + $request = self::getRequest(); |
|
416 | + // todo add doing_it_wrong() notice during next major version |
|
417 | + if ( |
|
418 | + $request->getRequestParam('page') === 'espresso_events' |
|
419 | + && $request->getRequestParam('action') === 'edit' |
|
420 | + ) { |
|
421 | + $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
422 | + $iframe_embed_button->addEventEditorIframeEmbedButton(); |
|
423 | + } |
|
424 | + return ''; |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * @param int $ID |
|
430 | + * @param string $external_url |
|
431 | + * @return string |
|
432 | + * @throws EE_Error |
|
433 | + * @throws ReflectionException |
|
434 | + * @deprecated |
|
435 | + */ |
|
436 | + public static function ticket_selector_form_open($ID = 0, $external_url = '') |
|
437 | + { |
|
438 | + // todo add doing_it_wrong() notice during next major version |
|
439 | + return EED_Ticket_Selector::ticketSelector()->formOpen($ID, $external_url); |
|
440 | + } |
|
441 | + |
|
442 | + |
|
443 | + /** |
|
444 | + * @return string |
|
445 | + * @throws EE_Error |
|
446 | + * @throws ReflectionException |
|
447 | + * @deprecated |
|
448 | + */ |
|
449 | + public static function ticket_selector_form_close() |
|
450 | + { |
|
451 | + // todo add doing_it_wrong() notice during next major version |
|
452 | + return EED_Ticket_Selector::ticketSelector()->formClose(); |
|
453 | + } |
|
454 | + |
|
455 | + |
|
456 | + /** |
|
457 | + * @return string |
|
458 | + * @throws EE_Error |
|
459 | + * @throws ReflectionException |
|
460 | + * @deprecated |
|
461 | + */ |
|
462 | + public static function no_tkt_slctr_end_dv() |
|
463 | + { |
|
464 | + // todo add doing_it_wrong() notice during next major version |
|
465 | + return EED_Ticket_Selector::ticketSelector()->ticketSelectorEndDiv(); |
|
466 | + } |
|
467 | + |
|
468 | + |
|
469 | + /** |
|
470 | + * @return string |
|
471 | + * @throws EE_Error |
|
472 | + * @throws ReflectionException |
|
473 | + * @deprecated 4.9.13 |
|
474 | + */ |
|
475 | + public static function tkt_slctr_end_dv() |
|
476 | + { |
|
477 | + return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
478 | + } |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * @return string |
|
483 | + * @throws EE_Error |
|
484 | + * @throws ReflectionException |
|
485 | + * @deprecated |
|
486 | + */ |
|
487 | + public static function clear_tkt_slctr() |
|
488 | + { |
|
489 | + return EED_Ticket_Selector::ticketSelector()->clearTicketSelector(); |
|
490 | + } |
|
491 | + |
|
492 | + |
|
493 | + /** |
|
494 | + * @deprecated |
|
495 | + */ |
|
496 | + public static function load_tckt_slctr_assets_admin() |
|
497 | + { |
|
498 | + $request = self::getRequest(); |
|
499 | + // todo add doing_it_wrong() notice during next major version |
|
500 | + if ( |
|
501 | + $request->getRequestParam('page') === 'espresso_events' |
|
502 | + && $request->getRequestParam('action') === 'edit' |
|
503 | + ) { |
|
504 | + $iframe_embed_button = EED_Ticket_Selector::getIframeEmbedButton(); |
|
505 | + $iframe_embed_button->embedButtonAssets(); |
|
506 | + } |
|
507 | + } |
|
508 | 508 | } |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | |
452 | 452 | function espressoUpgradeNow() |
453 | 453 | { |
454 | - if (! defined('EE_CAF_URL')) { |
|
454 | + if ( ! defined('EE_CAF_URL')) { |
|
455 | 455 | return ' |
456 | 456 | <div class="ee-card ee-card__buy-now ee-grid-col-span-3 ee-card--blank"> |
457 | 457 | <a href="https://eventespresso.com/pricing/?utm_source=wordpress_org&utm_medium=link&utm_campaign=decaf_about_page&utm_content=reviews+tab" |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | class="button button--primary button-hero" |
460 | 460 | > |
461 | 461 | <span class="dashicons dashicons-cart"></span> |
462 | - ' . esc_html__('Upgrade Now!', 'event_espresso') . ' |
|
462 | + ' . esc_html__('Upgrade Now!', 'event_espresso').' |
|
463 | 463 | </a> |
464 | 464 | </div>'; |
465 | 465 | } |
@@ -1,19 +1,19 @@ discard block |
||
1 | 1 | <h2 style="text-align: left;"><?php esc_html_e('Who uses Event Espresso?', 'event_espresso'); ?></h2> |
2 | 2 | <p> |
3 | 3 | <?php printf( |
4 | - esc_html__( |
|
5 | - 'Event Espresso is used by over 40,000 event organizers across the world. They host %sconferences%s, %sart classes%s, training courses, concerts, fundraisers, workshops, %sfilm festivals%s, %spaint and wine%s, and more.', |
|
6 | - 'event_espresso' |
|
7 | - ), |
|
8 | - '<a href="https://eventespresso.com/use-cases/conferences/?utm_source=wordpress_org&utm_medium=link&utm_campaign=decaf_about_page&utm_content=Decaf+vs+Regular">', |
|
9 | - '</a>', |
|
10 | - '<a href="https://eventespresso.com/use-cases/art-classes/?utm_source=wordpress_org&utm_medium=link&utm_campaign=decaf_about_page&utm_content=Decaf+vs+Regular">', |
|
11 | - '</a>', |
|
12 | - '<a href="https://eventespresso.com/use-cases/film-festival-ticketing-software/?utm_source=wordpress_org&utm_medium=link&utm_campaign=decaf_about_page&utm_content=Decaf+vs+Regular">', |
|
13 | - '</a>', |
|
14 | - '<a href="https://eventespresso.com/use-cases/paint-wine-party-ticketing-software/?utm_source=wordpress_org&utm_medium=link&utm_campaign=decaf_about_page&utm_content=Decaf+vs+Regular">', |
|
15 | - '</a>' |
|
16 | - ); ?> |
|
4 | + esc_html__( |
|
5 | + 'Event Espresso is used by over 40,000 event organizers across the world. They host %sconferences%s, %sart classes%s, training courses, concerts, fundraisers, workshops, %sfilm festivals%s, %spaint and wine%s, and more.', |
|
6 | + 'event_espresso' |
|
7 | + ), |
|
8 | + '<a href="https://eventespresso.com/use-cases/conferences/?utm_source=wordpress_org&utm_medium=link&utm_campaign=decaf_about_page&utm_content=Decaf+vs+Regular">', |
|
9 | + '</a>', |
|
10 | + '<a href="https://eventespresso.com/use-cases/art-classes/?utm_source=wordpress_org&utm_medium=link&utm_campaign=decaf_about_page&utm_content=Decaf+vs+Regular">', |
|
11 | + '</a>', |
|
12 | + '<a href="https://eventespresso.com/use-cases/film-festival-ticketing-software/?utm_source=wordpress_org&utm_medium=link&utm_campaign=decaf_about_page&utm_content=Decaf+vs+Regular">', |
|
13 | + '</a>', |
|
14 | + '<a href="https://eventespresso.com/use-cases/paint-wine-party-ticketing-software/?utm_source=wordpress_org&utm_medium=link&utm_campaign=decaf_about_page&utm_content=Decaf+vs+Regular">', |
|
15 | + '</a>' |
|
16 | + ); ?> |
|
17 | 17 | </p> |
18 | 18 | |
19 | 19 | <h2 class="about-headline-callout"> |
@@ -451,8 +451,8 @@ discard block |
||
451 | 451 | |
452 | 452 | function espressoUpgradeNow() |
453 | 453 | { |
454 | - if (! defined('EE_CAF_URL')) { |
|
455 | - return ' |
|
454 | + if (! defined('EE_CAF_URL')) { |
|
455 | + return ' |
|
456 | 456 | <div class="ee-card ee-card__buy-now ee-grid-col-span-3 ee-card--blank"> |
457 | 457 | <a href="https://eventespresso.com/pricing/?utm_source=wordpress_org&utm_medium=link&utm_campaign=decaf_about_page&utm_content=reviews+tab" |
458 | 458 | target="_blank" |
@@ -462,13 +462,13 @@ discard block |
||
462 | 462 | ' . esc_html__('Upgrade Now!', 'event_espresso') . ' |
463 | 463 | </a> |
464 | 464 | </div>'; |
465 | - } |
|
465 | + } |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | |
469 | 469 | function espressoFiveStars() |
470 | 470 | { |
471 | - return ' |
|
471 | + return ' |
|
472 | 472 | <div class="wporg-ratings" aria-label="5 out of 5 stars"> |
473 | 473 | <span class="dashicons dashicons-star-filled"></span> |
474 | 474 | <span class="dashicons dashicons-star-filled"></span> |
@@ -3,100 +3,100 @@ |
||
3 | 3 | |
4 | 4 | <h4> |
5 | 5 | <?php |
6 | - esc_html_e( |
|
7 | - 'You may be able to find an answer for your question or concern here:', |
|
8 | - 'event_espresso' |
|
9 | - ); |
|
10 | - ?> |
|
6 | + esc_html_e( |
|
7 | + 'You may be able to find an answer for your question or concern here:', |
|
8 | + 'event_espresso' |
|
9 | + ); |
|
10 | + ?> |
|
11 | 11 | </h4> |
12 | 12 | <ol> |
13 | 13 | <li> |
14 | 14 | <strong><em><?php esc_html_e('A known issue.', 'event_espresso'); ?></em></strong> |
15 | 15 | <?php |
16 | - printf( |
|
17 | - esc_html__( |
|
18 | - 'Some themes and plugins have %1$sknown conflicts%2$s with Event Espresso. (You can also browse the %3$sEvent Espresso support pages%2$s or %4$sEvent Espresso support forums%2$s to see if other members have experienced and solved the problem.)', |
|
19 | - 'event_espresso' |
|
20 | - ), |
|
21 | - '<a href="https://eventespresso.com/wiki/known-third-party-plugin-theme-conflicts/" target="_blank">', |
|
22 | - '</a>', |
|
23 | - '<a href="https://eventespresso.com/support/documentation/versioned-docs/?doc_ver=ee4" target="_blank">', |
|
24 | - '<a href="https://eventespresso.com/support/forums/" target="_blank">' |
|
25 | - ); |
|
26 | - ?> |
|
16 | + printf( |
|
17 | + esc_html__( |
|
18 | + 'Some themes and plugins have %1$sknown conflicts%2$s with Event Espresso. (You can also browse the %3$sEvent Espresso support pages%2$s or %4$sEvent Espresso support forums%2$s to see if other members have experienced and solved the problem.)', |
|
19 | + 'event_espresso' |
|
20 | + ), |
|
21 | + '<a href="https://eventespresso.com/wiki/known-third-party-plugin-theme-conflicts/" target="_blank">', |
|
22 | + '</a>', |
|
23 | + '<a href="https://eventespresso.com/support/documentation/versioned-docs/?doc_ver=ee4" target="_blank">', |
|
24 | + '<a href="https://eventespresso.com/support/forums/" target="_blank">' |
|
25 | + ); |
|
26 | + ?> |
|
27 | 27 | </li> |
28 | 28 | <li> |
29 | 29 | <strong><em><?php esc_html_e('A plugin conflict.', 'event_espresso'); ?></em></strong> |
30 | 30 | <?php esc_html_e( |
31 | - 'You can check to see if there is a plugin conflict by temporarily deactivating all plugins except for Event Espresso. If the problem goes away, then reactivate your plugins one by one until the issue returns. This will help you pinpoint the source of the conflict.', |
|
32 | - 'event_espresso' |
|
33 | - ); ?> |
|
31 | + 'You can check to see if there is a plugin conflict by temporarily deactivating all plugins except for Event Espresso. If the problem goes away, then reactivate your plugins one by one until the issue returns. This will help you pinpoint the source of the conflict.', |
|
32 | + 'event_espresso' |
|
33 | + ); ?> |
|
34 | 34 | </li> |
35 | 35 | <li> |
36 | 36 | <strong><em><?php esc_html_e('A theme conflict.', 'event_espresso'); ?></em></strong> |
37 | 37 | <?php |
38 | - $default_theme = wp_get_theme(WP_DEFAULT_THEME); |
|
38 | + $default_theme = wp_get_theme(WP_DEFAULT_THEME); |
|
39 | 39 | |
40 | - if ($default_theme->exists()) { |
|
41 | - printf( |
|
42 | - esc_html__( |
|
43 | - 'If your problem is not a known issue or caused by a plugin, then try activating %s (the default WordPress theme).', |
|
44 | - 'event_espresso' |
|
45 | - ), |
|
46 | - $default_theme->get('Name') |
|
47 | - ); |
|
48 | - } else { |
|
49 | - esc_html_e( |
|
50 | - 'If your problem is not a known issue or caused by a plugin, then try activating the default WordPress theme.', |
|
51 | - 'event_espresso' |
|
52 | - ); |
|
53 | - } |
|
54 | - ?> |
|
40 | + if ($default_theme->exists()) { |
|
41 | + printf( |
|
42 | + esc_html__( |
|
43 | + 'If your problem is not a known issue or caused by a plugin, then try activating %s (the default WordPress theme).', |
|
44 | + 'event_espresso' |
|
45 | + ), |
|
46 | + $default_theme->get('Name') |
|
47 | + ); |
|
48 | + } else { |
|
49 | + esc_html_e( |
|
50 | + 'If your problem is not a known issue or caused by a plugin, then try activating the default WordPress theme.', |
|
51 | + 'event_espresso' |
|
52 | + ); |
|
53 | + } |
|
54 | + ?> |
|
55 | 55 | <?php |
56 | - esc_html_e( |
|
57 | - 'If this solves the problem for you, then something in your theme is causing this issue. Check to see if an update is available for your WordPress theme or reach out to the theme author.', |
|
58 | - 'event_espresso' |
|
59 | - ); |
|
60 | - ?> |
|
56 | + esc_html_e( |
|
57 | + 'If this solves the problem for you, then something in your theme is causing this issue. Check to see if an update is available for your WordPress theme or reach out to the theme author.', |
|
58 | + 'event_espresso' |
|
59 | + ); |
|
60 | + ?> |
|
61 | 61 | </li> |
62 | 62 | </ol> |
63 | 63 | |
64 | 64 | <p> |
65 | 65 | <?php |
66 | - esc_html_e( |
|
67 | - 'If none of the suggestions above help you find a solution, then feel free to reach out to the support team at Event Espresso.', |
|
68 | - 'event_espresso' |
|
69 | - ); |
|
70 | - ?> |
|
66 | + esc_html_e( |
|
67 | + 'If none of the suggestions above help you find a solution, then feel free to reach out to the support team at Event Espresso.', |
|
68 | + 'event_espresso' |
|
69 | + ); |
|
70 | + ?> |
|
71 | 71 | </p> |
72 | 72 | <p> |
73 | 73 | <?php |
74 | - printf( |
|
75 | - esc_html__( |
|
76 | - 'Login to your account on EventEspresso.com and %1$screate a support post in our member support forums%2$s. Use a %3$sclear and descriptive title%4$s in your support post, %3$sdescribe the issue to the best of your knowledge%4$s, and %3$snever post any sensitive information such as login details%4$s. Be sure to also include %5$simportant information in the section below%2$s about your WordPress site.', |
|
77 | - 'event_espresso' |
|
78 | - ), |
|
79 | - '<a href="https://eventespresso.com/support/forums/" target="_blank">', |
|
80 | - '</a>', |
|
81 | - '<strong>', |
|
82 | - '</strong>', |
|
83 | - '<a href="#espresso_important_information_settings">' |
|
84 | - ); |
|
85 | - ?> |
|
74 | + printf( |
|
75 | + esc_html__( |
|
76 | + 'Login to your account on EventEspresso.com and %1$screate a support post in our member support forums%2$s. Use a %3$sclear and descriptive title%4$s in your support post, %3$sdescribe the issue to the best of your knowledge%4$s, and %3$snever post any sensitive information such as login details%4$s. Be sure to also include %5$simportant information in the section below%2$s about your WordPress site.', |
|
77 | + 'event_espresso' |
|
78 | + ), |
|
79 | + '<a href="https://eventespresso.com/support/forums/" target="_blank">', |
|
80 | + '</a>', |
|
81 | + '<strong>', |
|
82 | + '</strong>', |
|
83 | + '<a href="#espresso_important_information_settings">' |
|
84 | + ); |
|
85 | + ?> |
|
86 | 86 | </p> |
87 | 87 | |
88 | 88 | <h4><?php esc_html_e('Have an emergency?', 'event_espresso'); ?></h4> |
89 | 89 | |
90 | 90 | <p> |
91 | 91 | <?php |
92 | - printf( |
|
93 | - esc_html__( |
|
94 | - 'We offer support tokens to members that need help with a time-sensitive issue. A support token will provide you with up to 30 minutes of one-on-one time with a team member at Event Espresso. If you have an emergency and need help quickly, then please %1$spurchase a support token%2$s.', |
|
95 | - 'event_espresso' |
|
96 | - ), |
|
97 | - '<a href="https://eventespresso.com/product/premium-support-token/?utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=help_support_tab&utm_content=support_token" target="_blank">', |
|
98 | - '</a>' |
|
99 | - ); |
|
100 | - ?> |
|
92 | + printf( |
|
93 | + esc_html__( |
|
94 | + 'We offer support tokens to members that need help with a time-sensitive issue. A support token will provide you with up to 30 minutes of one-on-one time with a team member at Event Espresso. If you have an emergency and need help quickly, then please %1$spurchase a support token%2$s.', |
|
95 | + 'event_espresso' |
|
96 | + ), |
|
97 | + '<a href="https://eventespresso.com/product/premium-support-token/?utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=help_support_tab&utm_content=support_token" target="_blank">', |
|
98 | + '</a>' |
|
99 | + ); |
|
100 | + ?> |
|
101 | 101 | </p> |
102 | 102 | </div> |