@@ -814,7 +814,7 @@ discard block |
||
814 | 814 | * |
815 | 815 | * @since 4.5.0 |
816 | 816 | * @param string $meta_cap What meta capability is this mapping. |
817 | - * @param array $map_values array { |
|
817 | + * @param string[] $map_values array { |
|
818 | 818 | * //array of values that MUST match a count of 4. It's okay to send an empty string |
819 | 819 | * for capabilities that don't get mapped to. |
820 | 820 | * @type $map_values [0] string A string representing the model name. Required. String's |
@@ -885,8 +885,8 @@ discard block |
||
885 | 885 | * @see EE_Meta_Capability_Map::_map_meta_caps() for docs on params. |
886 | 886 | * @since 4.6.x |
887 | 887 | * @param $caps |
888 | - * @param $cap |
|
889 | - * @param $user_id |
|
888 | + * @param string $cap |
|
889 | + * @param integer $user_id |
|
890 | 890 | * @param $args |
891 | 891 | * @return array |
892 | 892 | */ |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @subpackage core, capabilities |
9 | 9 | */ |
10 | 10 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
11 | - exit('No direct script access allowed'); |
|
11 | + exit('No direct script access allowed'); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | |
@@ -26,762 +26,762 @@ discard block |
||
26 | 26 | { |
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * instance of EE_Capabilities object |
|
31 | - * |
|
32 | - * @var EE_Capabilities |
|
33 | - */ |
|
34 | - private static $_instance = null; |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * This is a map of caps that correspond to a default WP_Role. |
|
39 | - * Array is indexed by Role and values are ee capabilities. |
|
40 | - * |
|
41 | - * @since 4.5.0 |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - private $_caps_map = array(); |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * This used to hold an array of EE_Meta_Capability_Map objects that define the granular capabilities mapped to for |
|
49 | - * a user depending on context. |
|
50 | - * |
|
51 | - * @var EE_Meta_Capability_Map[] |
|
52 | - */ |
|
53 | - private $_meta_caps = array(); |
|
54 | - |
|
55 | - /** |
|
56 | - * the name of the wp option used to store caps previously initialized |
|
57 | - */ |
|
58 | - const option_name = 'ee_caps_initialized'; |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * singleton method used to instantiate class object |
|
63 | - * |
|
64 | - * @since 4.5.0 |
|
65 | - * @return EE_Capabilities |
|
66 | - */ |
|
67 | - public static function instance() |
|
68 | - { |
|
69 | - //check if instantiated, and if not do so. |
|
70 | - if ( ! self::$_instance instanceof EE_Capabilities) { |
|
71 | - self::$_instance = new self(); |
|
72 | - } |
|
73 | - |
|
74 | - return self::$_instance; |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * private constructor |
|
80 | - * |
|
81 | - * @since 4.5.0 |
|
82 | - * @return \EE_Capabilities |
|
83 | - */ |
|
84 | - private function __construct() |
|
85 | - { |
|
86 | - if (is_admin()) { |
|
87 | - add_filter( |
|
88 | - 'FHEE__EE_Capabilities__init_caps_map__caps', |
|
89 | - array($this, 'register_additional_capabilities'), |
|
90 | - 10 |
|
91 | - ); |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * This delays the initialization of the capabilities class until EE_System core is loaded and ready. |
|
98 | - * |
|
99 | - * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
100 | - * actually REMOVE any capabilities from existing roles, it just resaves defaults roles and |
|
101 | - * ensures that they are up to date. |
|
102 | - * @since 4.5.0 |
|
103 | - * @return void |
|
104 | - */ |
|
105 | - public function init_caps($reset = false) |
|
106 | - { |
|
107 | - /** |
|
108 | - * Note, this means that caps can only initialized on the default roles when: |
|
109 | - * - models are queryable |
|
110 | - * - All addons have been registered (which happens at plugins_loaded priority 1) |
|
111 | - * In practice, currently this method is usually called around `init`. |
|
112 | - */ |
|
113 | - if ( |
|
114 | - did_action('AHEE__EE_System__load_espresso_addons__complete') |
|
115 | - && EE_Maintenance_Mode::instance()->models_can_query() |
|
116 | - ) { |
|
117 | - $this->_caps_map = $this->_init_caps_map(); |
|
118 | - $this->init_role_caps($reset); |
|
119 | - $this->_set_meta_caps(); |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * This sets the meta caps property. |
|
126 | - * |
|
127 | - * @since 4.5.0 |
|
128 | - * @return void |
|
129 | - */ |
|
130 | - private function _set_meta_caps() |
|
131 | - { |
|
132 | - //make sure we're only ever initializing the default _meta_caps array once if it's empty. |
|
133 | - $this->_meta_caps = $this->_get_default_meta_caps_array(); |
|
134 | - |
|
135 | - $this->_meta_caps = apply_filters('FHEE__EE_Capabilities___set_meta_caps__meta_caps', $this->_meta_caps); |
|
136 | - |
|
137 | - //add filter for map_meta_caps but only if models can query. |
|
138 | - if (EE_Maintenance_Mode::instance()->models_can_query() && ! has_filter('map_meta_cap', |
|
139 | - array($this, 'map_meta_caps')) |
|
140 | - ) { |
|
141 | - add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
|
142 | - } |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * This builds and returns the default meta_caps array only once. |
|
148 | - * |
|
149 | - * @since 4.8.28.rc.012 |
|
150 | - * @return array |
|
151 | - */ |
|
152 | - private function _get_default_meta_caps_array() |
|
153 | - { |
|
154 | - static $default_meta_caps = array(); |
|
155 | - if (empty($default_meta_caps)) { |
|
156 | - $default_meta_caps = array( |
|
157 | - //edits |
|
158 | - new EE_Meta_Capability_Map_Edit('ee_edit_event', |
|
159 | - array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events')), |
|
160 | - new EE_Meta_Capability_Map_Edit('ee_edit_venue', |
|
161 | - array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues')), |
|
162 | - new EE_Meta_Capability_Map_Edit('ee_edit_registration', |
|
163 | - array('Registration', '', 'ee_edit_others_registrations', '')), |
|
164 | - new EE_Meta_Capability_Map_Edit('ee_edit_checkin', |
|
165 | - array('Registration', '', 'ee_edit_others_checkins', '')), |
|
166 | - new EE_Meta_Capability_Map_Messages_Cap('ee_edit_message', |
|
167 | - array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages')), |
|
168 | - new EE_Meta_Capability_Map_Edit('ee_edit_default_ticket', |
|
169 | - array('Ticket', '', 'ee_edit_others_default_tickets', '')), |
|
170 | - new EE_Meta_Capability_Map_Registration_Form_Cap('ee_edit_question', |
|
171 | - array('Question', '', '', 'ee_edit_system_questions')), |
|
172 | - new EE_Meta_Capability_Map_Registration_Form_Cap('ee_edit_question_group', |
|
173 | - array('Question_Group', '', '', 'ee_edit_system_question_groups')), |
|
174 | - new EE_Meta_Capability_Map_Edit('ee_edit_payment_method', |
|
175 | - array('Payment_Method', '', 'ee_edit_others_payment_methods', '')), |
|
176 | - //reads |
|
177 | - new EE_Meta_Capability_Map_Read('ee_read_event', |
|
178 | - array('Event', '', 'ee_read_others_events', 'ee_read_private_events')), |
|
179 | - new EE_Meta_Capability_Map_Read('ee_read_venue', |
|
180 | - array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues')), |
|
181 | - new EE_Meta_Capability_Map_Read('ee_read_registration', |
|
182 | - array('Registration', '', '', 'ee_edit_others_registrations')), |
|
183 | - new EE_Meta_Capability_Map_Read('ee_read_checkin', |
|
184 | - array('Registration', '', '', 'ee_read_others_checkins')), |
|
185 | - new EE_Meta_Capability_Map_Messages_Cap('ee_read_message', |
|
186 | - array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages')), |
|
187 | - new EE_Meta_Capability_Map_Read('ee_read_default_ticket', |
|
188 | - array('Ticket', '', '', 'ee_read_others_default_tickets')), |
|
189 | - new EE_Meta_Capability_Map_Read('ee_read_payment_method', |
|
190 | - array('Payment_Method', '', '', 'ee_read_others_payment_methods')), |
|
191 | - |
|
192 | - //deletes |
|
193 | - new EE_Meta_Capability_Map_Delete('ee_delete_event', array( |
|
194 | - 'Event', |
|
195 | - 'ee_delete_published_events', |
|
196 | - 'ee_delete_others_events', |
|
197 | - 'ee_delete_private_events', |
|
198 | - )), |
|
199 | - new EE_Meta_Capability_Map_Delete('ee_delete_venue', array( |
|
200 | - 'Venue', |
|
201 | - 'ee_delete_published_venues', |
|
202 | - 'ee_delete_others_venues', |
|
203 | - 'ee_delete_private_venues', |
|
204 | - )), |
|
205 | - new EE_Meta_Capability_Map_Delete('ee_delete_registration', |
|
206 | - array('Registration', '', 'ee_delete_others_registrations', '')), |
|
207 | - new EE_Meta_Capability_Map_Delete('ee_delete_checkin', |
|
208 | - array('Registration', '', 'ee_delete_others_checkins', '')), |
|
209 | - new EE_Meta_Capability_Map_Messages_Cap('ee_delete_message', |
|
210 | - array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages')), |
|
211 | - new EE_Meta_Capability_Map_Delete('ee_delete_default_ticket', |
|
212 | - array('Ticket', '', 'ee_delete_others_default_tickets', '')), |
|
213 | - new EE_Meta_Capability_Map_Registration_Form_Cap('ee_delete_question', |
|
214 | - array('Question', '', '', 'delete_system_questions')), |
|
215 | - new EE_Meta_Capability_Map_Registration_Form_Cap('ee_delete_question_group', |
|
216 | - array('Question_Group', '', '', 'delete_system_question_groups')), |
|
217 | - new EE_Meta_Capability_Map_Delete('ee_delete_payment_method', |
|
218 | - array('Payment_Method', '', 'ee_delete_others_payment_methods', '')), |
|
219 | - ); |
|
220 | - } |
|
221 | - |
|
222 | - return $default_meta_caps; |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
228 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
229 | - * The actual logic is carried out by implementer classes in their definition of _map_meta_caps. |
|
230 | - * |
|
231 | - * @since 4.5.0 |
|
232 | - * @see wp-includes/capabilities.php |
|
233 | - * @param array $caps actual users capabilities |
|
234 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
235 | - * @param int $user_id The user id |
|
236 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
237 | - * @return array actual users capabilities |
|
238 | - */ |
|
239 | - public function map_meta_caps($caps, $cap, $user_id, $args) |
|
240 | - { |
|
241 | - if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
|
242 | - //loop through our _meta_caps array |
|
243 | - foreach ($this->_meta_caps as $meta_map) { |
|
244 | - if ( ! $meta_map instanceof EE_Meta_Capability_Map) { |
|
245 | - continue; |
|
246 | - } |
|
247 | - $meta_map->ensure_is_model(); |
|
248 | - |
|
249 | - $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
|
250 | - } |
|
251 | - } |
|
252 | - |
|
253 | - return $caps; |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * This sets up and returns the initial capabilities map for Event Espresso |
|
259 | - * |
|
260 | - * @since 4.5.0 |
|
261 | - * @return array |
|
262 | - */ |
|
263 | - private function _init_caps_map() |
|
264 | - { |
|
265 | - $caps = array( |
|
266 | - 'administrator' => array( |
|
267 | - //basic access |
|
268 | - 'ee_read_ee', |
|
269 | - //gateways |
|
270 | - /** |
|
271 | - * note that with payment method capabilities, although we've implemented |
|
272 | - * capability mapping which will be used for accessing payment methods owned by |
|
273 | - * other users. This is not fully implemented yet in the payment method ui. |
|
274 | - * Currently only the "plural" caps are in active use. (Specific payment method caps are in use as well). |
|
275 | - **/ |
|
276 | - 'ee_manage_gateways', |
|
277 | - 'ee_read_payment_method', |
|
278 | - 'ee_read_payment_methods', |
|
279 | - 'ee_read_others_payment_methods', |
|
280 | - 'ee_edit_payment_method', |
|
281 | - 'ee_edit_payment_methods', |
|
282 | - 'ee_edit_others_payment_methods', |
|
283 | - 'ee_delete_payment_method', |
|
284 | - 'ee_delete_payment_methods', |
|
285 | - //events |
|
286 | - 'ee_publish_events', |
|
287 | - 'ee_read_private_events', |
|
288 | - 'ee_read_others_events', |
|
289 | - 'ee_read_event', |
|
290 | - 'ee_read_events', |
|
291 | - 'ee_edit_event', |
|
292 | - 'ee_edit_events', |
|
293 | - 'ee_edit_published_events', |
|
294 | - 'ee_edit_others_events', |
|
295 | - 'ee_edit_private_events', |
|
296 | - 'ee_delete_published_events', |
|
297 | - 'ee_delete_private_events', |
|
298 | - 'ee_delete_event', |
|
299 | - 'ee_delete_events', |
|
300 | - 'ee_delete_others_events', |
|
301 | - //event categories |
|
302 | - 'ee_manage_event_categories', |
|
303 | - 'ee_edit_event_category', |
|
304 | - 'ee_delete_event_category', |
|
305 | - 'ee_assign_event_category', |
|
306 | - //venues |
|
307 | - 'ee_publish_venues', |
|
308 | - 'ee_read_venue', |
|
309 | - 'ee_read_venues', |
|
310 | - 'ee_read_others_venues', |
|
311 | - 'ee_read_private_venues', |
|
312 | - 'ee_edit_venue', |
|
313 | - 'ee_edit_venues', |
|
314 | - 'ee_edit_others_venues', |
|
315 | - 'ee_edit_published_venues', |
|
316 | - 'ee_edit_private_venues', |
|
317 | - 'ee_delete_venue', |
|
318 | - 'ee_delete_venues', |
|
319 | - 'ee_delete_others_venues', |
|
320 | - 'ee_delete_private_venues', |
|
321 | - 'ee_delete_published_venues', |
|
322 | - //venue categories |
|
323 | - 'ee_manage_venue_categories', |
|
324 | - 'ee_edit_venue_category', |
|
325 | - 'ee_delete_venue_category', |
|
326 | - 'ee_assign_venue_category', |
|
327 | - //contacts |
|
328 | - 'ee_read_contact', |
|
329 | - 'ee_read_contacts', |
|
330 | - 'ee_edit_contact', |
|
331 | - 'ee_edit_contacts', |
|
332 | - 'ee_delete_contact', |
|
333 | - 'ee_delete_contacts', |
|
334 | - //registrations |
|
335 | - 'ee_read_registration', |
|
336 | - 'ee_read_registrations', |
|
337 | - 'ee_read_others_registrations', |
|
338 | - 'ee_edit_registration', |
|
339 | - 'ee_edit_registrations', |
|
340 | - 'ee_edit_others_registrations', |
|
341 | - 'ee_delete_registration', |
|
342 | - 'ee_delete_registrations', |
|
343 | - //checkins |
|
344 | - 'ee_read_checkin', |
|
345 | - 'ee_read_others_checkins', |
|
346 | - 'ee_read_checkins', |
|
347 | - 'ee_edit_checkin', |
|
348 | - 'ee_edit_checkins', |
|
349 | - 'ee_edit_others_checkins', |
|
350 | - 'ee_delete_checkin', |
|
351 | - 'ee_delete_checkins', |
|
352 | - 'ee_delete_others_checkins', |
|
353 | - //transactions && payments |
|
354 | - 'ee_read_transaction', |
|
355 | - 'ee_read_transactions', |
|
356 | - 'ee_edit_payments', |
|
357 | - 'ee_delete_payments', |
|
358 | - //messages |
|
359 | - 'ee_read_message', |
|
360 | - 'ee_read_messages', |
|
361 | - 'ee_read_others_messages', |
|
362 | - 'ee_read_global_messages', |
|
363 | - 'ee_edit_global_messages', |
|
364 | - 'ee_edit_message', |
|
365 | - 'ee_edit_messages', |
|
366 | - 'ee_edit_others_messages', |
|
367 | - 'ee_delete_message', |
|
368 | - 'ee_delete_messages', |
|
369 | - 'ee_delete_others_messages', |
|
370 | - 'ee_delete_global_messages', |
|
371 | - 'ee_send_message', |
|
372 | - //tickets |
|
373 | - 'ee_read_default_ticket', |
|
374 | - 'ee_read_default_tickets', |
|
375 | - 'ee_read_others_default_tickets', |
|
376 | - 'ee_edit_default_ticket', |
|
377 | - 'ee_edit_default_tickets', |
|
378 | - 'ee_edit_others_default_tickets', |
|
379 | - 'ee_delete_default_ticket', |
|
380 | - 'ee_delete_default_tickets', |
|
381 | - 'ee_delete_others_default_tickets', |
|
382 | - //prices |
|
383 | - 'ee_edit_default_price', |
|
384 | - 'ee_edit_default_prices', |
|
385 | - 'ee_delete_default_price', |
|
386 | - 'ee_delete_default_prices', |
|
387 | - 'ee_edit_default_price_type', |
|
388 | - 'ee_edit_default_price_types', |
|
389 | - 'ee_delete_default_price_type', |
|
390 | - 'ee_delete_default_price_types', |
|
391 | - 'ee_read_default_prices', |
|
392 | - 'ee_read_default_price_types', |
|
393 | - //registration form |
|
394 | - 'ee_edit_question', |
|
395 | - 'ee_edit_questions', |
|
396 | - 'ee_edit_system_questions', |
|
397 | - 'ee_read_questions', |
|
398 | - 'ee_delete_question', |
|
399 | - 'ee_delete_questions', |
|
400 | - 'ee_edit_question_group', |
|
401 | - 'ee_edit_question_groups', |
|
402 | - 'ee_read_question_groups', |
|
403 | - 'ee_edit_system_question_groups', |
|
404 | - 'ee_delete_question_group', |
|
405 | - 'ee_delete_question_groups', |
|
406 | - //event_type taxonomy |
|
407 | - 'ee_assign_event_type', |
|
408 | - 'ee_manage_event_types', |
|
409 | - 'ee_edit_event_type', |
|
410 | - 'ee_delete_event_type', |
|
411 | - ), |
|
412 | - 'ee_events_administrator' => array( |
|
413 | - //core wp caps |
|
414 | - 'read', |
|
415 | - 'read_private_pages', |
|
416 | - 'read_private_posts', |
|
417 | - 'edit_users', |
|
418 | - 'edit_posts', |
|
419 | - 'edit_pages', |
|
420 | - 'edit_published_posts', |
|
421 | - 'edit_published_pages', |
|
422 | - 'edit_private_pages', |
|
423 | - 'edit_private_posts', |
|
424 | - 'edit_others_posts', |
|
425 | - 'edit_others_pages', |
|
426 | - 'publish_posts', |
|
427 | - 'publish_pages', |
|
428 | - 'delete_posts', |
|
429 | - 'delete_pages', |
|
430 | - 'delete_private_pages', |
|
431 | - 'delete_private_posts', |
|
432 | - 'delete_published_pages', |
|
433 | - 'delete_published_posts', |
|
434 | - 'delete_others_posts', |
|
435 | - 'delete_others_pages', |
|
436 | - 'manage_categories', |
|
437 | - 'manage_links', |
|
438 | - 'moderate_comments', |
|
439 | - 'unfiltered_html', |
|
440 | - 'upload_files', |
|
441 | - 'export', |
|
442 | - 'import', |
|
443 | - 'list_users', |
|
444 | - 'level_1', //required if user with this role shows up in author dropdowns |
|
445 | - //basic ee access |
|
446 | - 'ee_read_ee', |
|
447 | - //events |
|
448 | - 'ee_publish_events', |
|
449 | - 'ee_read_private_events', |
|
450 | - 'ee_read_others_events', |
|
451 | - 'ee_read_event', |
|
452 | - 'ee_read_events', |
|
453 | - 'ee_edit_event', |
|
454 | - 'ee_edit_events', |
|
455 | - 'ee_edit_published_events', |
|
456 | - 'ee_edit_others_events', |
|
457 | - 'ee_edit_private_events', |
|
458 | - 'ee_delete_published_events', |
|
459 | - 'ee_delete_private_events', |
|
460 | - 'ee_delete_event', |
|
461 | - 'ee_delete_events', |
|
462 | - 'ee_delete_others_events', |
|
463 | - //event categories |
|
464 | - 'ee_manage_event_categories', |
|
465 | - 'ee_edit_event_category', |
|
466 | - 'ee_delete_event_category', |
|
467 | - 'ee_assign_event_category', |
|
468 | - //venues |
|
469 | - 'ee_publish_venues', |
|
470 | - 'ee_read_venue', |
|
471 | - 'ee_read_venues', |
|
472 | - 'ee_read_others_venues', |
|
473 | - 'ee_read_private_venues', |
|
474 | - 'ee_edit_venue', |
|
475 | - 'ee_edit_venues', |
|
476 | - 'ee_edit_others_venues', |
|
477 | - 'ee_edit_published_venues', |
|
478 | - 'ee_edit_private_venues', |
|
479 | - 'ee_delete_venue', |
|
480 | - 'ee_delete_venues', |
|
481 | - 'ee_delete_others_venues', |
|
482 | - 'ee_delete_private_venues', |
|
483 | - 'ee_delete_published_venues', |
|
484 | - //venue categories |
|
485 | - 'ee_manage_venue_categories', |
|
486 | - 'ee_edit_venue_category', |
|
487 | - 'ee_delete_venue_category', |
|
488 | - 'ee_assign_venue_category', |
|
489 | - //contacts |
|
490 | - 'ee_read_contact', |
|
491 | - 'ee_read_contacts', |
|
492 | - 'ee_edit_contact', |
|
493 | - 'ee_edit_contacts', |
|
494 | - 'ee_delete_contact', |
|
495 | - 'ee_delete_contacts', |
|
496 | - //registrations |
|
497 | - 'ee_read_registration', |
|
498 | - 'ee_read_registrations', |
|
499 | - 'ee_read_others_registrations', |
|
500 | - 'ee_edit_registration', |
|
501 | - 'ee_edit_registrations', |
|
502 | - 'ee_edit_others_registrations', |
|
503 | - 'ee_delete_registration', |
|
504 | - 'ee_delete_registrations', |
|
505 | - //checkins |
|
506 | - 'ee_read_checkin', |
|
507 | - 'ee_read_others_checkins', |
|
508 | - 'ee_read_checkins', |
|
509 | - 'ee_edit_checkin', |
|
510 | - 'ee_edit_checkins', |
|
511 | - 'ee_edit_others_checkins', |
|
512 | - 'ee_delete_checkin', |
|
513 | - 'ee_delete_checkins', |
|
514 | - 'ee_delete_others_checkins', |
|
515 | - //transactions && payments |
|
516 | - 'ee_read_transaction', |
|
517 | - 'ee_read_transactions', |
|
518 | - 'ee_edit_payments', |
|
519 | - 'ee_delete_payments', |
|
520 | - //messages |
|
521 | - 'ee_read_message', |
|
522 | - 'ee_read_messages', |
|
523 | - 'ee_read_others_messages', |
|
524 | - 'ee_read_global_messages', |
|
525 | - 'ee_edit_global_messages', |
|
526 | - 'ee_edit_message', |
|
527 | - 'ee_edit_messages', |
|
528 | - 'ee_edit_others_messages', |
|
529 | - 'ee_delete_message', |
|
530 | - 'ee_delete_messages', |
|
531 | - 'ee_delete_others_messages', |
|
532 | - 'ee_delete_global_messages', |
|
533 | - 'ee_send_message', |
|
534 | - //tickets |
|
535 | - 'ee_read_default_ticket', |
|
536 | - 'ee_read_default_tickets', |
|
537 | - 'ee_read_others_default_tickets', |
|
538 | - 'ee_edit_default_ticket', |
|
539 | - 'ee_edit_default_tickets', |
|
540 | - 'ee_edit_others_default_tickets', |
|
541 | - 'ee_delete_default_ticket', |
|
542 | - 'ee_delete_default_tickets', |
|
543 | - 'ee_delete_others_default_tickets', |
|
544 | - //prices |
|
545 | - 'ee_edit_default_price', |
|
546 | - 'ee_edit_default_prices', |
|
547 | - 'ee_delete_default_price', |
|
548 | - 'ee_delete_default_prices', |
|
549 | - 'ee_edit_default_price_type', |
|
550 | - 'ee_edit_default_price_types', |
|
551 | - 'ee_delete_default_price_type', |
|
552 | - 'ee_delete_default_price_types', |
|
553 | - 'ee_read_default_prices', |
|
554 | - 'ee_read_default_price_types', |
|
555 | - //registration form |
|
556 | - 'ee_edit_question', |
|
557 | - 'ee_edit_questions', |
|
558 | - 'ee_edit_system_questions', |
|
559 | - 'ee_read_questions', |
|
560 | - 'ee_delete_question', |
|
561 | - 'ee_delete_questions', |
|
562 | - 'ee_edit_question_group', |
|
563 | - 'ee_edit_question_groups', |
|
564 | - 'ee_read_question_groups', |
|
565 | - 'ee_edit_system_question_groups', |
|
566 | - 'ee_delete_question_group', |
|
567 | - 'ee_delete_question_groups', |
|
568 | - //event_type taxonomy |
|
569 | - 'ee_assign_event_type', |
|
570 | - 'ee_manage_event_types', |
|
571 | - 'ee_edit_event_type', |
|
572 | - 'ee_delete_event_type', |
|
573 | - ), |
|
574 | - ); |
|
575 | - |
|
576 | - $caps = apply_filters('FHEE__EE_Capabilities__init_caps_map__caps', $caps); |
|
577 | - |
|
578 | - return $caps; |
|
579 | - } |
|
580 | - |
|
581 | - |
|
582 | - /** |
|
583 | - * Callback for FHEE__EE_Capabilities__init_caps_map__caps that is used for registering additional core |
|
584 | - * capabilities that get added. |
|
585 | - * This is typically done for more dynamic cap additions such as what is registered via the |
|
586 | - * `EE_Payment_Method_Manager` |
|
587 | - * |
|
588 | - * @param array $caps The existing $role=>$capability array. |
|
589 | - * @return array. |
|
590 | - */ |
|
591 | - public function register_additional_capabilities($caps) |
|
592 | - { |
|
593 | - //take care of dynamic capabilities for payment methods |
|
594 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
595 | - $caps = EE_Payment_Method_Manager::instance()->add_payment_method_caps($caps); |
|
596 | - return $caps; |
|
597 | - } |
|
598 | - |
|
599 | - |
|
600 | - /** |
|
601 | - * This adds all the default caps to roles as registered in the _caps_map property. |
|
602 | - * |
|
603 | - * @since 4.5.0 |
|
604 | - * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
605 | - * actually REMOVE any capabilities from existing roles, it just resaves defaults roles |
|
606 | - * and ensures that they are up to date. |
|
607 | - * @param array $custom_map Optional. Can be used to send a custom map of roles and capabilities for setting them |
|
608 | - * up. Note that this should ONLY be called on activation hook or some other one-time |
|
609 | - * task otherwise the caps will be added on every request. |
|
610 | - * @return void |
|
611 | - */ |
|
612 | - public function init_role_caps($reset = false, $custom_map = array()) |
|
613 | - { |
|
614 | - |
|
615 | - $caps_map = empty($custom_map) ? $this->_caps_map : $custom_map; |
|
616 | - |
|
617 | - //first let's determine if these caps have already been set. |
|
618 | - $caps_set_before = get_option(self::option_name, array()); |
|
619 | - //if not reset, see what caps are new for each role. if they're new, add them. |
|
620 | - foreach ($caps_map as $role => $caps_for_role) { |
|
621 | - foreach ($caps_for_role as $cap) { |
|
622 | - //first check we haven't already added this cap before, or it's a reset |
|
623 | - if ($reset || ! isset($caps_set_before[$role]) || ! in_array($cap, $caps_set_before[$role])) { |
|
624 | - if ($this->add_cap_to_role($role, $cap)) { |
|
625 | - $caps_set_before[$role][] = $cap; |
|
626 | - } |
|
627 | - } |
|
628 | - } |
|
629 | - } |
|
630 | - |
|
631 | - //now let's just save the cap that has been set. |
|
632 | - update_option(self::option_name, $caps_set_before); |
|
633 | - do_action('AHEE__EE_Capabilities__init_role_caps__complete', $caps_set_before); |
|
634 | - } |
|
635 | - |
|
636 | - |
|
637 | - /** |
|
638 | - * This method sets a capability on a role. Note this should only be done on activation, or if you have something |
|
639 | - * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note. |
|
640 | - * this is a wrapper for $wp_role->add_cap() |
|
641 | - * |
|
642 | - * @see wp-includes/capabilities.php |
|
643 | - * @since 4.5.0 |
|
644 | - * @param string $role A WordPress role the capability is being added to |
|
645 | - * @param string $cap The capability being added to the role |
|
646 | - * @param bool $grant Whether to grant access to this cap on this role. |
|
647 | - * @return bool |
|
648 | - */ |
|
649 | - public function add_cap_to_role($role, $cap, $grant = true) |
|
650 | - { |
|
651 | - $role_object = get_role($role); |
|
652 | - //if the role isn't available then we create it. |
|
653 | - if ( ! $role_object instanceof WP_Role) { |
|
654 | - //if a plugin wants to create a specific role name then they should create the role before |
|
655 | - //EE_Capabilities does. Otherwise this function will create the role name from the slug: |
|
656 | - // - removes any `ee_` namespacing from the start of the slug. |
|
657 | - // - replaces `_` with ` ` (empty space). |
|
658 | - // - sentence case on the resulting string. |
|
659 | - $role_label = ucwords(str_replace('_', ' ', str_replace('ee_', '', $role))); |
|
660 | - $role_object = add_role($role, $role_label); |
|
661 | - } |
|
662 | - if ($role_object instanceof WP_Role) { |
|
663 | - $role_object->add_cap($cap, $grant); |
|
664 | - |
|
665 | - return true; |
|
666 | - } |
|
667 | - |
|
668 | - return false; |
|
669 | - } |
|
670 | - |
|
671 | - |
|
672 | - /** |
|
673 | - * Functions similarly to add_cap_to_role except removes cap from given role. |
|
674 | - * Wrapper for $wp_role->remove_cap() |
|
675 | - * |
|
676 | - * @see wp-includes/capabilities.php |
|
677 | - * @since 4.5.0 |
|
678 | - * @param string $role A WordPress role the capability is being removed from. |
|
679 | - * @param string $cap The capability being removed |
|
680 | - * @return void |
|
681 | - */ |
|
682 | - public function remove_cap_from_role($role, $cap) |
|
683 | - { |
|
684 | - $role = get_role($role); |
|
685 | - if ($role instanceof WP_Role) { |
|
686 | - $role->remove_cap($cap); |
|
687 | - } |
|
688 | - } |
|
689 | - |
|
690 | - |
|
691 | - /** |
|
692 | - * Wrapper for the native WP current_user_can() method. |
|
693 | - * This is provided as a handy method for a couple things: |
|
694 | - * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
695 | - * write those filters wherever current_user_can is called). |
|
696 | - * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
697 | - * |
|
698 | - * @since 4.5.0 |
|
699 | - * @param string $cap The cap being checked. |
|
700 | - * @param string $context The context where the current_user_can is being called from. |
|
701 | - * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
702 | - * filters. |
|
703 | - * @return bool Whether user can or not. |
|
704 | - */ |
|
705 | - public function current_user_can($cap, $context, $id = 0) |
|
706 | - { |
|
707 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
708 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
709 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap', $filtered_cap, $context, $cap, |
|
710 | - $id); |
|
711 | - |
|
712 | - return ! empty($id) ? current_user_can($filtered_cap, $id) : current_user_can($filtered_cap); |
|
713 | - } |
|
714 | - |
|
715 | - |
|
716 | - /** |
|
717 | - * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class. |
|
718 | - * |
|
719 | - * @param int|WP_User $user Either the user_id or a WP_User object |
|
720 | - * @param string $cap The capability string being checked |
|
721 | - * @param string $context The context where the user_can is being called from (used in filters). |
|
722 | - * @param int $id Optional. Id for item where user_can is being called from ( used in map_meta_cap() |
|
723 | - * filters) |
|
724 | - * @return bool Whether user can or not. |
|
725 | - */ |
|
726 | - public function user_can($user, $cap, $context, $id = 0) |
|
727 | - { |
|
728 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
729 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
730 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap', $filtered_cap, $context, $cap, $user, |
|
731 | - $id); |
|
732 | - |
|
733 | - return ! empty($id) ? user_can($user, $filtered_cap, $id) : user_can($user, $filtered_cap); |
|
734 | - } |
|
735 | - |
|
736 | - |
|
737 | - /** |
|
738 | - * Wrapper for the native WP current_user_can_for_blog() method. |
|
739 | - * This is provided as a handy method for a couple things: |
|
740 | - * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
741 | - * write those filters wherever current_user_can is called). |
|
742 | - * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
743 | - * |
|
744 | - * @since 4.5.0 |
|
745 | - * @param int $blog_id The blog id that is being checked for. |
|
746 | - * @param string $cap The cap being checked. |
|
747 | - * @param string $context The context where the current_user_can is being called from. |
|
748 | - * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
749 | - * filters. |
|
750 | - * @return bool Whether user can or not. |
|
751 | - */ |
|
752 | - public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0) |
|
753 | - { |
|
754 | - $user_can = ! empty($id) ? current_user_can_for_blog($blog_id, $cap, $id) : current_user_can($blog_id, $cap); |
|
755 | - |
|
756 | - //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
757 | - $user_can = apply_filters('FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, $user_can, |
|
758 | - $blog_id, $cap, $id); |
|
759 | - $user_can = apply_filters('FHEE__EE_Capabilities__current_user_can_for_blog__user_can', $user_can, $context, |
|
760 | - $blog_id, $cap, $id); |
|
761 | - |
|
762 | - return $user_can; |
|
763 | - } |
|
764 | - |
|
765 | - |
|
766 | - /** |
|
767 | - * This helper method just returns an array of registered EE capabilities. |
|
768 | - * Note this array is filtered. It is assumed that all available EE capabilities are assigned to the administrator |
|
769 | - * role. |
|
770 | - * |
|
771 | - * @since 4.5.0 |
|
772 | - * @param string $role If empty then the entire role/capability map is returned. Otherwise just the capabilities |
|
773 | - * for the given role are returned. |
|
774 | - * @return array |
|
775 | - */ |
|
776 | - public function get_ee_capabilities($role = 'administrator') |
|
777 | - { |
|
778 | - $capabilities = $this->_init_caps_map(); |
|
779 | - if (empty($role)) { |
|
780 | - return $capabilities; |
|
781 | - } |
|
782 | - |
|
783 | - return isset($capabilities[$role]) ? $capabilities[$role] : array(); |
|
784 | - } |
|
29 | + /** |
|
30 | + * instance of EE_Capabilities object |
|
31 | + * |
|
32 | + * @var EE_Capabilities |
|
33 | + */ |
|
34 | + private static $_instance = null; |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * This is a map of caps that correspond to a default WP_Role. |
|
39 | + * Array is indexed by Role and values are ee capabilities. |
|
40 | + * |
|
41 | + * @since 4.5.0 |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + private $_caps_map = array(); |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * This used to hold an array of EE_Meta_Capability_Map objects that define the granular capabilities mapped to for |
|
49 | + * a user depending on context. |
|
50 | + * |
|
51 | + * @var EE_Meta_Capability_Map[] |
|
52 | + */ |
|
53 | + private $_meta_caps = array(); |
|
54 | + |
|
55 | + /** |
|
56 | + * the name of the wp option used to store caps previously initialized |
|
57 | + */ |
|
58 | + const option_name = 'ee_caps_initialized'; |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * singleton method used to instantiate class object |
|
63 | + * |
|
64 | + * @since 4.5.0 |
|
65 | + * @return EE_Capabilities |
|
66 | + */ |
|
67 | + public static function instance() |
|
68 | + { |
|
69 | + //check if instantiated, and if not do so. |
|
70 | + if ( ! self::$_instance instanceof EE_Capabilities) { |
|
71 | + self::$_instance = new self(); |
|
72 | + } |
|
73 | + |
|
74 | + return self::$_instance; |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * private constructor |
|
80 | + * |
|
81 | + * @since 4.5.0 |
|
82 | + * @return \EE_Capabilities |
|
83 | + */ |
|
84 | + private function __construct() |
|
85 | + { |
|
86 | + if (is_admin()) { |
|
87 | + add_filter( |
|
88 | + 'FHEE__EE_Capabilities__init_caps_map__caps', |
|
89 | + array($this, 'register_additional_capabilities'), |
|
90 | + 10 |
|
91 | + ); |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * This delays the initialization of the capabilities class until EE_System core is loaded and ready. |
|
98 | + * |
|
99 | + * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
100 | + * actually REMOVE any capabilities from existing roles, it just resaves defaults roles and |
|
101 | + * ensures that they are up to date. |
|
102 | + * @since 4.5.0 |
|
103 | + * @return void |
|
104 | + */ |
|
105 | + public function init_caps($reset = false) |
|
106 | + { |
|
107 | + /** |
|
108 | + * Note, this means that caps can only initialized on the default roles when: |
|
109 | + * - models are queryable |
|
110 | + * - All addons have been registered (which happens at plugins_loaded priority 1) |
|
111 | + * In practice, currently this method is usually called around `init`. |
|
112 | + */ |
|
113 | + if ( |
|
114 | + did_action('AHEE__EE_System__load_espresso_addons__complete') |
|
115 | + && EE_Maintenance_Mode::instance()->models_can_query() |
|
116 | + ) { |
|
117 | + $this->_caps_map = $this->_init_caps_map(); |
|
118 | + $this->init_role_caps($reset); |
|
119 | + $this->_set_meta_caps(); |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * This sets the meta caps property. |
|
126 | + * |
|
127 | + * @since 4.5.0 |
|
128 | + * @return void |
|
129 | + */ |
|
130 | + private function _set_meta_caps() |
|
131 | + { |
|
132 | + //make sure we're only ever initializing the default _meta_caps array once if it's empty. |
|
133 | + $this->_meta_caps = $this->_get_default_meta_caps_array(); |
|
134 | + |
|
135 | + $this->_meta_caps = apply_filters('FHEE__EE_Capabilities___set_meta_caps__meta_caps', $this->_meta_caps); |
|
136 | + |
|
137 | + //add filter for map_meta_caps but only if models can query. |
|
138 | + if (EE_Maintenance_Mode::instance()->models_can_query() && ! has_filter('map_meta_cap', |
|
139 | + array($this, 'map_meta_caps')) |
|
140 | + ) { |
|
141 | + add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4); |
|
142 | + } |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * This builds and returns the default meta_caps array only once. |
|
148 | + * |
|
149 | + * @since 4.8.28.rc.012 |
|
150 | + * @return array |
|
151 | + */ |
|
152 | + private function _get_default_meta_caps_array() |
|
153 | + { |
|
154 | + static $default_meta_caps = array(); |
|
155 | + if (empty($default_meta_caps)) { |
|
156 | + $default_meta_caps = array( |
|
157 | + //edits |
|
158 | + new EE_Meta_Capability_Map_Edit('ee_edit_event', |
|
159 | + array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events')), |
|
160 | + new EE_Meta_Capability_Map_Edit('ee_edit_venue', |
|
161 | + array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues')), |
|
162 | + new EE_Meta_Capability_Map_Edit('ee_edit_registration', |
|
163 | + array('Registration', '', 'ee_edit_others_registrations', '')), |
|
164 | + new EE_Meta_Capability_Map_Edit('ee_edit_checkin', |
|
165 | + array('Registration', '', 'ee_edit_others_checkins', '')), |
|
166 | + new EE_Meta_Capability_Map_Messages_Cap('ee_edit_message', |
|
167 | + array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages')), |
|
168 | + new EE_Meta_Capability_Map_Edit('ee_edit_default_ticket', |
|
169 | + array('Ticket', '', 'ee_edit_others_default_tickets', '')), |
|
170 | + new EE_Meta_Capability_Map_Registration_Form_Cap('ee_edit_question', |
|
171 | + array('Question', '', '', 'ee_edit_system_questions')), |
|
172 | + new EE_Meta_Capability_Map_Registration_Form_Cap('ee_edit_question_group', |
|
173 | + array('Question_Group', '', '', 'ee_edit_system_question_groups')), |
|
174 | + new EE_Meta_Capability_Map_Edit('ee_edit_payment_method', |
|
175 | + array('Payment_Method', '', 'ee_edit_others_payment_methods', '')), |
|
176 | + //reads |
|
177 | + new EE_Meta_Capability_Map_Read('ee_read_event', |
|
178 | + array('Event', '', 'ee_read_others_events', 'ee_read_private_events')), |
|
179 | + new EE_Meta_Capability_Map_Read('ee_read_venue', |
|
180 | + array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues')), |
|
181 | + new EE_Meta_Capability_Map_Read('ee_read_registration', |
|
182 | + array('Registration', '', '', 'ee_edit_others_registrations')), |
|
183 | + new EE_Meta_Capability_Map_Read('ee_read_checkin', |
|
184 | + array('Registration', '', '', 'ee_read_others_checkins')), |
|
185 | + new EE_Meta_Capability_Map_Messages_Cap('ee_read_message', |
|
186 | + array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages')), |
|
187 | + new EE_Meta_Capability_Map_Read('ee_read_default_ticket', |
|
188 | + array('Ticket', '', '', 'ee_read_others_default_tickets')), |
|
189 | + new EE_Meta_Capability_Map_Read('ee_read_payment_method', |
|
190 | + array('Payment_Method', '', '', 'ee_read_others_payment_methods')), |
|
191 | + |
|
192 | + //deletes |
|
193 | + new EE_Meta_Capability_Map_Delete('ee_delete_event', array( |
|
194 | + 'Event', |
|
195 | + 'ee_delete_published_events', |
|
196 | + 'ee_delete_others_events', |
|
197 | + 'ee_delete_private_events', |
|
198 | + )), |
|
199 | + new EE_Meta_Capability_Map_Delete('ee_delete_venue', array( |
|
200 | + 'Venue', |
|
201 | + 'ee_delete_published_venues', |
|
202 | + 'ee_delete_others_venues', |
|
203 | + 'ee_delete_private_venues', |
|
204 | + )), |
|
205 | + new EE_Meta_Capability_Map_Delete('ee_delete_registration', |
|
206 | + array('Registration', '', 'ee_delete_others_registrations', '')), |
|
207 | + new EE_Meta_Capability_Map_Delete('ee_delete_checkin', |
|
208 | + array('Registration', '', 'ee_delete_others_checkins', '')), |
|
209 | + new EE_Meta_Capability_Map_Messages_Cap('ee_delete_message', |
|
210 | + array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages')), |
|
211 | + new EE_Meta_Capability_Map_Delete('ee_delete_default_ticket', |
|
212 | + array('Ticket', '', 'ee_delete_others_default_tickets', '')), |
|
213 | + new EE_Meta_Capability_Map_Registration_Form_Cap('ee_delete_question', |
|
214 | + array('Question', '', '', 'delete_system_questions')), |
|
215 | + new EE_Meta_Capability_Map_Registration_Form_Cap('ee_delete_question_group', |
|
216 | + array('Question_Group', '', '', 'delete_system_question_groups')), |
|
217 | + new EE_Meta_Capability_Map_Delete('ee_delete_payment_method', |
|
218 | + array('Payment_Method', '', 'ee_delete_others_payment_methods', '')), |
|
219 | + ); |
|
220 | + } |
|
221 | + |
|
222 | + return $default_meta_caps; |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
228 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
229 | + * The actual logic is carried out by implementer classes in their definition of _map_meta_caps. |
|
230 | + * |
|
231 | + * @since 4.5.0 |
|
232 | + * @see wp-includes/capabilities.php |
|
233 | + * @param array $caps actual users capabilities |
|
234 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
235 | + * @param int $user_id The user id |
|
236 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
237 | + * @return array actual users capabilities |
|
238 | + */ |
|
239 | + public function map_meta_caps($caps, $cap, $user_id, $args) |
|
240 | + { |
|
241 | + if (did_action('AHEE__EE_System__load_espresso_addons__complete')) { |
|
242 | + //loop through our _meta_caps array |
|
243 | + foreach ($this->_meta_caps as $meta_map) { |
|
244 | + if ( ! $meta_map instanceof EE_Meta_Capability_Map) { |
|
245 | + continue; |
|
246 | + } |
|
247 | + $meta_map->ensure_is_model(); |
|
248 | + |
|
249 | + $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args); |
|
250 | + } |
|
251 | + } |
|
252 | + |
|
253 | + return $caps; |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * This sets up and returns the initial capabilities map for Event Espresso |
|
259 | + * |
|
260 | + * @since 4.5.0 |
|
261 | + * @return array |
|
262 | + */ |
|
263 | + private function _init_caps_map() |
|
264 | + { |
|
265 | + $caps = array( |
|
266 | + 'administrator' => array( |
|
267 | + //basic access |
|
268 | + 'ee_read_ee', |
|
269 | + //gateways |
|
270 | + /** |
|
271 | + * note that with payment method capabilities, although we've implemented |
|
272 | + * capability mapping which will be used for accessing payment methods owned by |
|
273 | + * other users. This is not fully implemented yet in the payment method ui. |
|
274 | + * Currently only the "plural" caps are in active use. (Specific payment method caps are in use as well). |
|
275 | + **/ |
|
276 | + 'ee_manage_gateways', |
|
277 | + 'ee_read_payment_method', |
|
278 | + 'ee_read_payment_methods', |
|
279 | + 'ee_read_others_payment_methods', |
|
280 | + 'ee_edit_payment_method', |
|
281 | + 'ee_edit_payment_methods', |
|
282 | + 'ee_edit_others_payment_methods', |
|
283 | + 'ee_delete_payment_method', |
|
284 | + 'ee_delete_payment_methods', |
|
285 | + //events |
|
286 | + 'ee_publish_events', |
|
287 | + 'ee_read_private_events', |
|
288 | + 'ee_read_others_events', |
|
289 | + 'ee_read_event', |
|
290 | + 'ee_read_events', |
|
291 | + 'ee_edit_event', |
|
292 | + 'ee_edit_events', |
|
293 | + 'ee_edit_published_events', |
|
294 | + 'ee_edit_others_events', |
|
295 | + 'ee_edit_private_events', |
|
296 | + 'ee_delete_published_events', |
|
297 | + 'ee_delete_private_events', |
|
298 | + 'ee_delete_event', |
|
299 | + 'ee_delete_events', |
|
300 | + 'ee_delete_others_events', |
|
301 | + //event categories |
|
302 | + 'ee_manage_event_categories', |
|
303 | + 'ee_edit_event_category', |
|
304 | + 'ee_delete_event_category', |
|
305 | + 'ee_assign_event_category', |
|
306 | + //venues |
|
307 | + 'ee_publish_venues', |
|
308 | + 'ee_read_venue', |
|
309 | + 'ee_read_venues', |
|
310 | + 'ee_read_others_venues', |
|
311 | + 'ee_read_private_venues', |
|
312 | + 'ee_edit_venue', |
|
313 | + 'ee_edit_venues', |
|
314 | + 'ee_edit_others_venues', |
|
315 | + 'ee_edit_published_venues', |
|
316 | + 'ee_edit_private_venues', |
|
317 | + 'ee_delete_venue', |
|
318 | + 'ee_delete_venues', |
|
319 | + 'ee_delete_others_venues', |
|
320 | + 'ee_delete_private_venues', |
|
321 | + 'ee_delete_published_venues', |
|
322 | + //venue categories |
|
323 | + 'ee_manage_venue_categories', |
|
324 | + 'ee_edit_venue_category', |
|
325 | + 'ee_delete_venue_category', |
|
326 | + 'ee_assign_venue_category', |
|
327 | + //contacts |
|
328 | + 'ee_read_contact', |
|
329 | + 'ee_read_contacts', |
|
330 | + 'ee_edit_contact', |
|
331 | + 'ee_edit_contacts', |
|
332 | + 'ee_delete_contact', |
|
333 | + 'ee_delete_contacts', |
|
334 | + //registrations |
|
335 | + 'ee_read_registration', |
|
336 | + 'ee_read_registrations', |
|
337 | + 'ee_read_others_registrations', |
|
338 | + 'ee_edit_registration', |
|
339 | + 'ee_edit_registrations', |
|
340 | + 'ee_edit_others_registrations', |
|
341 | + 'ee_delete_registration', |
|
342 | + 'ee_delete_registrations', |
|
343 | + //checkins |
|
344 | + 'ee_read_checkin', |
|
345 | + 'ee_read_others_checkins', |
|
346 | + 'ee_read_checkins', |
|
347 | + 'ee_edit_checkin', |
|
348 | + 'ee_edit_checkins', |
|
349 | + 'ee_edit_others_checkins', |
|
350 | + 'ee_delete_checkin', |
|
351 | + 'ee_delete_checkins', |
|
352 | + 'ee_delete_others_checkins', |
|
353 | + //transactions && payments |
|
354 | + 'ee_read_transaction', |
|
355 | + 'ee_read_transactions', |
|
356 | + 'ee_edit_payments', |
|
357 | + 'ee_delete_payments', |
|
358 | + //messages |
|
359 | + 'ee_read_message', |
|
360 | + 'ee_read_messages', |
|
361 | + 'ee_read_others_messages', |
|
362 | + 'ee_read_global_messages', |
|
363 | + 'ee_edit_global_messages', |
|
364 | + 'ee_edit_message', |
|
365 | + 'ee_edit_messages', |
|
366 | + 'ee_edit_others_messages', |
|
367 | + 'ee_delete_message', |
|
368 | + 'ee_delete_messages', |
|
369 | + 'ee_delete_others_messages', |
|
370 | + 'ee_delete_global_messages', |
|
371 | + 'ee_send_message', |
|
372 | + //tickets |
|
373 | + 'ee_read_default_ticket', |
|
374 | + 'ee_read_default_tickets', |
|
375 | + 'ee_read_others_default_tickets', |
|
376 | + 'ee_edit_default_ticket', |
|
377 | + 'ee_edit_default_tickets', |
|
378 | + 'ee_edit_others_default_tickets', |
|
379 | + 'ee_delete_default_ticket', |
|
380 | + 'ee_delete_default_tickets', |
|
381 | + 'ee_delete_others_default_tickets', |
|
382 | + //prices |
|
383 | + 'ee_edit_default_price', |
|
384 | + 'ee_edit_default_prices', |
|
385 | + 'ee_delete_default_price', |
|
386 | + 'ee_delete_default_prices', |
|
387 | + 'ee_edit_default_price_type', |
|
388 | + 'ee_edit_default_price_types', |
|
389 | + 'ee_delete_default_price_type', |
|
390 | + 'ee_delete_default_price_types', |
|
391 | + 'ee_read_default_prices', |
|
392 | + 'ee_read_default_price_types', |
|
393 | + //registration form |
|
394 | + 'ee_edit_question', |
|
395 | + 'ee_edit_questions', |
|
396 | + 'ee_edit_system_questions', |
|
397 | + 'ee_read_questions', |
|
398 | + 'ee_delete_question', |
|
399 | + 'ee_delete_questions', |
|
400 | + 'ee_edit_question_group', |
|
401 | + 'ee_edit_question_groups', |
|
402 | + 'ee_read_question_groups', |
|
403 | + 'ee_edit_system_question_groups', |
|
404 | + 'ee_delete_question_group', |
|
405 | + 'ee_delete_question_groups', |
|
406 | + //event_type taxonomy |
|
407 | + 'ee_assign_event_type', |
|
408 | + 'ee_manage_event_types', |
|
409 | + 'ee_edit_event_type', |
|
410 | + 'ee_delete_event_type', |
|
411 | + ), |
|
412 | + 'ee_events_administrator' => array( |
|
413 | + //core wp caps |
|
414 | + 'read', |
|
415 | + 'read_private_pages', |
|
416 | + 'read_private_posts', |
|
417 | + 'edit_users', |
|
418 | + 'edit_posts', |
|
419 | + 'edit_pages', |
|
420 | + 'edit_published_posts', |
|
421 | + 'edit_published_pages', |
|
422 | + 'edit_private_pages', |
|
423 | + 'edit_private_posts', |
|
424 | + 'edit_others_posts', |
|
425 | + 'edit_others_pages', |
|
426 | + 'publish_posts', |
|
427 | + 'publish_pages', |
|
428 | + 'delete_posts', |
|
429 | + 'delete_pages', |
|
430 | + 'delete_private_pages', |
|
431 | + 'delete_private_posts', |
|
432 | + 'delete_published_pages', |
|
433 | + 'delete_published_posts', |
|
434 | + 'delete_others_posts', |
|
435 | + 'delete_others_pages', |
|
436 | + 'manage_categories', |
|
437 | + 'manage_links', |
|
438 | + 'moderate_comments', |
|
439 | + 'unfiltered_html', |
|
440 | + 'upload_files', |
|
441 | + 'export', |
|
442 | + 'import', |
|
443 | + 'list_users', |
|
444 | + 'level_1', //required if user with this role shows up in author dropdowns |
|
445 | + //basic ee access |
|
446 | + 'ee_read_ee', |
|
447 | + //events |
|
448 | + 'ee_publish_events', |
|
449 | + 'ee_read_private_events', |
|
450 | + 'ee_read_others_events', |
|
451 | + 'ee_read_event', |
|
452 | + 'ee_read_events', |
|
453 | + 'ee_edit_event', |
|
454 | + 'ee_edit_events', |
|
455 | + 'ee_edit_published_events', |
|
456 | + 'ee_edit_others_events', |
|
457 | + 'ee_edit_private_events', |
|
458 | + 'ee_delete_published_events', |
|
459 | + 'ee_delete_private_events', |
|
460 | + 'ee_delete_event', |
|
461 | + 'ee_delete_events', |
|
462 | + 'ee_delete_others_events', |
|
463 | + //event categories |
|
464 | + 'ee_manage_event_categories', |
|
465 | + 'ee_edit_event_category', |
|
466 | + 'ee_delete_event_category', |
|
467 | + 'ee_assign_event_category', |
|
468 | + //venues |
|
469 | + 'ee_publish_venues', |
|
470 | + 'ee_read_venue', |
|
471 | + 'ee_read_venues', |
|
472 | + 'ee_read_others_venues', |
|
473 | + 'ee_read_private_venues', |
|
474 | + 'ee_edit_venue', |
|
475 | + 'ee_edit_venues', |
|
476 | + 'ee_edit_others_venues', |
|
477 | + 'ee_edit_published_venues', |
|
478 | + 'ee_edit_private_venues', |
|
479 | + 'ee_delete_venue', |
|
480 | + 'ee_delete_venues', |
|
481 | + 'ee_delete_others_venues', |
|
482 | + 'ee_delete_private_venues', |
|
483 | + 'ee_delete_published_venues', |
|
484 | + //venue categories |
|
485 | + 'ee_manage_venue_categories', |
|
486 | + 'ee_edit_venue_category', |
|
487 | + 'ee_delete_venue_category', |
|
488 | + 'ee_assign_venue_category', |
|
489 | + //contacts |
|
490 | + 'ee_read_contact', |
|
491 | + 'ee_read_contacts', |
|
492 | + 'ee_edit_contact', |
|
493 | + 'ee_edit_contacts', |
|
494 | + 'ee_delete_contact', |
|
495 | + 'ee_delete_contacts', |
|
496 | + //registrations |
|
497 | + 'ee_read_registration', |
|
498 | + 'ee_read_registrations', |
|
499 | + 'ee_read_others_registrations', |
|
500 | + 'ee_edit_registration', |
|
501 | + 'ee_edit_registrations', |
|
502 | + 'ee_edit_others_registrations', |
|
503 | + 'ee_delete_registration', |
|
504 | + 'ee_delete_registrations', |
|
505 | + //checkins |
|
506 | + 'ee_read_checkin', |
|
507 | + 'ee_read_others_checkins', |
|
508 | + 'ee_read_checkins', |
|
509 | + 'ee_edit_checkin', |
|
510 | + 'ee_edit_checkins', |
|
511 | + 'ee_edit_others_checkins', |
|
512 | + 'ee_delete_checkin', |
|
513 | + 'ee_delete_checkins', |
|
514 | + 'ee_delete_others_checkins', |
|
515 | + //transactions && payments |
|
516 | + 'ee_read_transaction', |
|
517 | + 'ee_read_transactions', |
|
518 | + 'ee_edit_payments', |
|
519 | + 'ee_delete_payments', |
|
520 | + //messages |
|
521 | + 'ee_read_message', |
|
522 | + 'ee_read_messages', |
|
523 | + 'ee_read_others_messages', |
|
524 | + 'ee_read_global_messages', |
|
525 | + 'ee_edit_global_messages', |
|
526 | + 'ee_edit_message', |
|
527 | + 'ee_edit_messages', |
|
528 | + 'ee_edit_others_messages', |
|
529 | + 'ee_delete_message', |
|
530 | + 'ee_delete_messages', |
|
531 | + 'ee_delete_others_messages', |
|
532 | + 'ee_delete_global_messages', |
|
533 | + 'ee_send_message', |
|
534 | + //tickets |
|
535 | + 'ee_read_default_ticket', |
|
536 | + 'ee_read_default_tickets', |
|
537 | + 'ee_read_others_default_tickets', |
|
538 | + 'ee_edit_default_ticket', |
|
539 | + 'ee_edit_default_tickets', |
|
540 | + 'ee_edit_others_default_tickets', |
|
541 | + 'ee_delete_default_ticket', |
|
542 | + 'ee_delete_default_tickets', |
|
543 | + 'ee_delete_others_default_tickets', |
|
544 | + //prices |
|
545 | + 'ee_edit_default_price', |
|
546 | + 'ee_edit_default_prices', |
|
547 | + 'ee_delete_default_price', |
|
548 | + 'ee_delete_default_prices', |
|
549 | + 'ee_edit_default_price_type', |
|
550 | + 'ee_edit_default_price_types', |
|
551 | + 'ee_delete_default_price_type', |
|
552 | + 'ee_delete_default_price_types', |
|
553 | + 'ee_read_default_prices', |
|
554 | + 'ee_read_default_price_types', |
|
555 | + //registration form |
|
556 | + 'ee_edit_question', |
|
557 | + 'ee_edit_questions', |
|
558 | + 'ee_edit_system_questions', |
|
559 | + 'ee_read_questions', |
|
560 | + 'ee_delete_question', |
|
561 | + 'ee_delete_questions', |
|
562 | + 'ee_edit_question_group', |
|
563 | + 'ee_edit_question_groups', |
|
564 | + 'ee_read_question_groups', |
|
565 | + 'ee_edit_system_question_groups', |
|
566 | + 'ee_delete_question_group', |
|
567 | + 'ee_delete_question_groups', |
|
568 | + //event_type taxonomy |
|
569 | + 'ee_assign_event_type', |
|
570 | + 'ee_manage_event_types', |
|
571 | + 'ee_edit_event_type', |
|
572 | + 'ee_delete_event_type', |
|
573 | + ), |
|
574 | + ); |
|
575 | + |
|
576 | + $caps = apply_filters('FHEE__EE_Capabilities__init_caps_map__caps', $caps); |
|
577 | + |
|
578 | + return $caps; |
|
579 | + } |
|
580 | + |
|
581 | + |
|
582 | + /** |
|
583 | + * Callback for FHEE__EE_Capabilities__init_caps_map__caps that is used for registering additional core |
|
584 | + * capabilities that get added. |
|
585 | + * This is typically done for more dynamic cap additions such as what is registered via the |
|
586 | + * `EE_Payment_Method_Manager` |
|
587 | + * |
|
588 | + * @param array $caps The existing $role=>$capability array. |
|
589 | + * @return array. |
|
590 | + */ |
|
591 | + public function register_additional_capabilities($caps) |
|
592 | + { |
|
593 | + //take care of dynamic capabilities for payment methods |
|
594 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
595 | + $caps = EE_Payment_Method_Manager::instance()->add_payment_method_caps($caps); |
|
596 | + return $caps; |
|
597 | + } |
|
598 | + |
|
599 | + |
|
600 | + /** |
|
601 | + * This adds all the default caps to roles as registered in the _caps_map property. |
|
602 | + * |
|
603 | + * @since 4.5.0 |
|
604 | + * @param bool $reset allows for resetting the default capabilities saved on roles. Note that this doesn't |
|
605 | + * actually REMOVE any capabilities from existing roles, it just resaves defaults roles |
|
606 | + * and ensures that they are up to date. |
|
607 | + * @param array $custom_map Optional. Can be used to send a custom map of roles and capabilities for setting them |
|
608 | + * up. Note that this should ONLY be called on activation hook or some other one-time |
|
609 | + * task otherwise the caps will be added on every request. |
|
610 | + * @return void |
|
611 | + */ |
|
612 | + public function init_role_caps($reset = false, $custom_map = array()) |
|
613 | + { |
|
614 | + |
|
615 | + $caps_map = empty($custom_map) ? $this->_caps_map : $custom_map; |
|
616 | + |
|
617 | + //first let's determine if these caps have already been set. |
|
618 | + $caps_set_before = get_option(self::option_name, array()); |
|
619 | + //if not reset, see what caps are new for each role. if they're new, add them. |
|
620 | + foreach ($caps_map as $role => $caps_for_role) { |
|
621 | + foreach ($caps_for_role as $cap) { |
|
622 | + //first check we haven't already added this cap before, or it's a reset |
|
623 | + if ($reset || ! isset($caps_set_before[$role]) || ! in_array($cap, $caps_set_before[$role])) { |
|
624 | + if ($this->add_cap_to_role($role, $cap)) { |
|
625 | + $caps_set_before[$role][] = $cap; |
|
626 | + } |
|
627 | + } |
|
628 | + } |
|
629 | + } |
|
630 | + |
|
631 | + //now let's just save the cap that has been set. |
|
632 | + update_option(self::option_name, $caps_set_before); |
|
633 | + do_action('AHEE__EE_Capabilities__init_role_caps__complete', $caps_set_before); |
|
634 | + } |
|
635 | + |
|
636 | + |
|
637 | + /** |
|
638 | + * This method sets a capability on a role. Note this should only be done on activation, or if you have something |
|
639 | + * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note. |
|
640 | + * this is a wrapper for $wp_role->add_cap() |
|
641 | + * |
|
642 | + * @see wp-includes/capabilities.php |
|
643 | + * @since 4.5.0 |
|
644 | + * @param string $role A WordPress role the capability is being added to |
|
645 | + * @param string $cap The capability being added to the role |
|
646 | + * @param bool $grant Whether to grant access to this cap on this role. |
|
647 | + * @return bool |
|
648 | + */ |
|
649 | + public function add_cap_to_role($role, $cap, $grant = true) |
|
650 | + { |
|
651 | + $role_object = get_role($role); |
|
652 | + //if the role isn't available then we create it. |
|
653 | + if ( ! $role_object instanceof WP_Role) { |
|
654 | + //if a plugin wants to create a specific role name then they should create the role before |
|
655 | + //EE_Capabilities does. Otherwise this function will create the role name from the slug: |
|
656 | + // - removes any `ee_` namespacing from the start of the slug. |
|
657 | + // - replaces `_` with ` ` (empty space). |
|
658 | + // - sentence case on the resulting string. |
|
659 | + $role_label = ucwords(str_replace('_', ' ', str_replace('ee_', '', $role))); |
|
660 | + $role_object = add_role($role, $role_label); |
|
661 | + } |
|
662 | + if ($role_object instanceof WP_Role) { |
|
663 | + $role_object->add_cap($cap, $grant); |
|
664 | + |
|
665 | + return true; |
|
666 | + } |
|
667 | + |
|
668 | + return false; |
|
669 | + } |
|
670 | + |
|
671 | + |
|
672 | + /** |
|
673 | + * Functions similarly to add_cap_to_role except removes cap from given role. |
|
674 | + * Wrapper for $wp_role->remove_cap() |
|
675 | + * |
|
676 | + * @see wp-includes/capabilities.php |
|
677 | + * @since 4.5.0 |
|
678 | + * @param string $role A WordPress role the capability is being removed from. |
|
679 | + * @param string $cap The capability being removed |
|
680 | + * @return void |
|
681 | + */ |
|
682 | + public function remove_cap_from_role($role, $cap) |
|
683 | + { |
|
684 | + $role = get_role($role); |
|
685 | + if ($role instanceof WP_Role) { |
|
686 | + $role->remove_cap($cap); |
|
687 | + } |
|
688 | + } |
|
689 | + |
|
690 | + |
|
691 | + /** |
|
692 | + * Wrapper for the native WP current_user_can() method. |
|
693 | + * This is provided as a handy method for a couple things: |
|
694 | + * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
695 | + * write those filters wherever current_user_can is called). |
|
696 | + * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
697 | + * |
|
698 | + * @since 4.5.0 |
|
699 | + * @param string $cap The cap being checked. |
|
700 | + * @param string $context The context where the current_user_can is being called from. |
|
701 | + * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
702 | + * filters. |
|
703 | + * @return bool Whether user can or not. |
|
704 | + */ |
|
705 | + public function current_user_can($cap, $context, $id = 0) |
|
706 | + { |
|
707 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
708 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
709 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap', $filtered_cap, $context, $cap, |
|
710 | + $id); |
|
711 | + |
|
712 | + return ! empty($id) ? current_user_can($filtered_cap, $id) : current_user_can($filtered_cap); |
|
713 | + } |
|
714 | + |
|
715 | + |
|
716 | + /** |
|
717 | + * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class. |
|
718 | + * |
|
719 | + * @param int|WP_User $user Either the user_id or a WP_User object |
|
720 | + * @param string $cap The capability string being checked |
|
721 | + * @param string $context The context where the user_can is being called from (used in filters). |
|
722 | + * @param int $id Optional. Id for item where user_can is being called from ( used in map_meta_cap() |
|
723 | + * filters) |
|
724 | + * @return bool Whether user can or not. |
|
725 | + */ |
|
726 | + public function user_can($user, $cap, $context, $id = 0) |
|
727 | + { |
|
728 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
729 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
730 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap', $filtered_cap, $context, $cap, $user, |
|
731 | + $id); |
|
732 | + |
|
733 | + return ! empty($id) ? user_can($user, $filtered_cap, $id) : user_can($user, $filtered_cap); |
|
734 | + } |
|
735 | + |
|
736 | + |
|
737 | + /** |
|
738 | + * Wrapper for the native WP current_user_can_for_blog() method. |
|
739 | + * This is provided as a handy method for a couple things: |
|
740 | + * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to |
|
741 | + * write those filters wherever current_user_can is called). |
|
742 | + * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters ) |
|
743 | + * |
|
744 | + * @since 4.5.0 |
|
745 | + * @param int $blog_id The blog id that is being checked for. |
|
746 | + * @param string $cap The cap being checked. |
|
747 | + * @param string $context The context where the current_user_can is being called from. |
|
748 | + * @param int $id Optional. Id for item where current_user_can is being called from (used in map_meta_cap() |
|
749 | + * filters. |
|
750 | + * @return bool Whether user can or not. |
|
751 | + */ |
|
752 | + public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0) |
|
753 | + { |
|
754 | + $user_can = ! empty($id) ? current_user_can_for_blog($blog_id, $cap, $id) : current_user_can($blog_id, $cap); |
|
755 | + |
|
756 | + //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
|
757 | + $user_can = apply_filters('FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, $user_can, |
|
758 | + $blog_id, $cap, $id); |
|
759 | + $user_can = apply_filters('FHEE__EE_Capabilities__current_user_can_for_blog__user_can', $user_can, $context, |
|
760 | + $blog_id, $cap, $id); |
|
761 | + |
|
762 | + return $user_can; |
|
763 | + } |
|
764 | + |
|
765 | + |
|
766 | + /** |
|
767 | + * This helper method just returns an array of registered EE capabilities. |
|
768 | + * Note this array is filtered. It is assumed that all available EE capabilities are assigned to the administrator |
|
769 | + * role. |
|
770 | + * |
|
771 | + * @since 4.5.0 |
|
772 | + * @param string $role If empty then the entire role/capability map is returned. Otherwise just the capabilities |
|
773 | + * for the given role are returned. |
|
774 | + * @return array |
|
775 | + */ |
|
776 | + public function get_ee_capabilities($role = 'administrator') |
|
777 | + { |
|
778 | + $capabilities = $this->_init_caps_map(); |
|
779 | + if (empty($role)) { |
|
780 | + return $capabilities; |
|
781 | + } |
|
782 | + |
|
783 | + return isset($capabilities[$role]) ? $capabilities[$role] : array(); |
|
784 | + } |
|
785 | 785 | } |
786 | 786 | |
787 | 787 | |
@@ -797,118 +797,118 @@ discard block |
||
797 | 797 | */ |
798 | 798 | abstract class EE_Meta_Capability_Map |
799 | 799 | { |
800 | - public $meta_cap; |
|
801 | - /** |
|
802 | - * @var EEM_Base |
|
803 | - */ |
|
804 | - protected $_model; |
|
805 | - protected $_model_name; |
|
806 | - public $published_cap = ''; |
|
807 | - public $others_cap = ''; |
|
808 | - public $private_cap = ''; |
|
809 | - |
|
810 | - |
|
811 | - /** |
|
812 | - * constructor. |
|
813 | - * Receives the setup arguments for the map. |
|
814 | - * |
|
815 | - * @since 4.5.0 |
|
816 | - * @param string $meta_cap What meta capability is this mapping. |
|
817 | - * @param array $map_values array { |
|
818 | - * //array of values that MUST match a count of 4. It's okay to send an empty string |
|
819 | - * for capabilities that don't get mapped to. |
|
820 | - * @type $map_values [0] string A string representing the model name. Required. String's |
|
821 | - * should always be used when Menu Maps are registered via the |
|
822 | - * plugin API as models are not allowed to be instantiated when |
|
823 | - * in maintenance mode 2 (migrations). |
|
824 | - * @type $map_values [1] string represents the capability used for published. Optional. |
|
825 | - * @type $map_values [2] string represents the capability used for "others". Optional. |
|
826 | - * @type $map_values [3] string represents the capability used for private. Optional. |
|
827 | - * } |
|
828 | - * @throws EE_Error |
|
829 | - */ |
|
830 | - public function __construct($meta_cap, $map_values) |
|
831 | - { |
|
832 | - $this->meta_cap = $meta_cap; |
|
833 | - //verify there are four args in the $map_values array; |
|
834 | - if (count($map_values) !== 4) { |
|
835 | - throw new EE_Error(sprintf(__('Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
|
836 | - 'event_espresso'), '<br>' . print_r($map_values, true))); |
|
837 | - } |
|
838 | - |
|
839 | - //set properties |
|
840 | - $this->_model = null; |
|
841 | - $this->_model_name = $map_values[0]; |
|
842 | - $this->published_cap = (string)$map_values[1]; |
|
843 | - $this->others_cap = (string)$map_values[2]; |
|
844 | - $this->private_cap = (string)$map_values[3]; |
|
845 | - } |
|
846 | - |
|
847 | - /** |
|
848 | - * Makes it so this object stops filtering caps |
|
849 | - */ |
|
850 | - public function remove_filters() |
|
851 | - { |
|
852 | - remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10); |
|
853 | - } |
|
854 | - |
|
855 | - |
|
856 | - /** |
|
857 | - * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class |
|
858 | - * |
|
859 | - * @since 4.5.0 |
|
860 | - * @throws EE_Error |
|
861 | - * @return void |
|
862 | - */ |
|
863 | - public function ensure_is_model() |
|
864 | - { |
|
865 | - //is it already instantiated? |
|
866 | - if ($this->_model instanceof EEM_Base) { |
|
867 | - return; |
|
868 | - } |
|
869 | - |
|
870 | - //ensure model name is string |
|
871 | - $this->_model_name = (string)$this->_model_name; |
|
872 | - //error proof if the name has EEM in it |
|
873 | - $this->_model_name = str_replace('EEM', '', $this->_model_name); |
|
874 | - |
|
875 | - $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
|
876 | - |
|
877 | - if ( ! $this->_model instanceof EEM_Base) { |
|
878 | - throw new EE_Error(sprintf(__('This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class. Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s', |
|
879 | - 'event_espresso'), get_class($this), $this->_model)); |
|
880 | - } |
|
881 | - } |
|
882 | - |
|
883 | - |
|
884 | - /** |
|
885 | - * @see EE_Meta_Capability_Map::_map_meta_caps() for docs on params. |
|
886 | - * @since 4.6.x |
|
887 | - * @param $caps |
|
888 | - * @param $cap |
|
889 | - * @param $user_id |
|
890 | - * @param $args |
|
891 | - * @return array |
|
892 | - */ |
|
893 | - public function map_meta_caps($caps, $cap, $user_id, $args) |
|
894 | - { |
|
895 | - return $this->_map_meta_caps($caps, $cap, $user_id, $args); |
|
896 | - } |
|
897 | - |
|
898 | - |
|
899 | - /** |
|
900 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
901 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
902 | - * |
|
903 | - * @since 4.5.0 |
|
904 | - * @see wp-includes/capabilities.php |
|
905 | - * @param array $caps actual users capabilities |
|
906 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
907 | - * @param int $user_id The user id |
|
908 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
909 | - * @return array actual users capabilities |
|
910 | - */ |
|
911 | - abstract protected function _map_meta_caps($caps, $cap, $user_id, $args); |
|
800 | + public $meta_cap; |
|
801 | + /** |
|
802 | + * @var EEM_Base |
|
803 | + */ |
|
804 | + protected $_model; |
|
805 | + protected $_model_name; |
|
806 | + public $published_cap = ''; |
|
807 | + public $others_cap = ''; |
|
808 | + public $private_cap = ''; |
|
809 | + |
|
810 | + |
|
811 | + /** |
|
812 | + * constructor. |
|
813 | + * Receives the setup arguments for the map. |
|
814 | + * |
|
815 | + * @since 4.5.0 |
|
816 | + * @param string $meta_cap What meta capability is this mapping. |
|
817 | + * @param array $map_values array { |
|
818 | + * //array of values that MUST match a count of 4. It's okay to send an empty string |
|
819 | + * for capabilities that don't get mapped to. |
|
820 | + * @type $map_values [0] string A string representing the model name. Required. String's |
|
821 | + * should always be used when Menu Maps are registered via the |
|
822 | + * plugin API as models are not allowed to be instantiated when |
|
823 | + * in maintenance mode 2 (migrations). |
|
824 | + * @type $map_values [1] string represents the capability used for published. Optional. |
|
825 | + * @type $map_values [2] string represents the capability used for "others". Optional. |
|
826 | + * @type $map_values [3] string represents the capability used for private. Optional. |
|
827 | + * } |
|
828 | + * @throws EE_Error |
|
829 | + */ |
|
830 | + public function __construct($meta_cap, $map_values) |
|
831 | + { |
|
832 | + $this->meta_cap = $meta_cap; |
|
833 | + //verify there are four args in the $map_values array; |
|
834 | + if (count($map_values) !== 4) { |
|
835 | + throw new EE_Error(sprintf(__('Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
|
836 | + 'event_espresso'), '<br>' . print_r($map_values, true))); |
|
837 | + } |
|
838 | + |
|
839 | + //set properties |
|
840 | + $this->_model = null; |
|
841 | + $this->_model_name = $map_values[0]; |
|
842 | + $this->published_cap = (string)$map_values[1]; |
|
843 | + $this->others_cap = (string)$map_values[2]; |
|
844 | + $this->private_cap = (string)$map_values[3]; |
|
845 | + } |
|
846 | + |
|
847 | + /** |
|
848 | + * Makes it so this object stops filtering caps |
|
849 | + */ |
|
850 | + public function remove_filters() |
|
851 | + { |
|
852 | + remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10); |
|
853 | + } |
|
854 | + |
|
855 | + |
|
856 | + /** |
|
857 | + * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class |
|
858 | + * |
|
859 | + * @since 4.5.0 |
|
860 | + * @throws EE_Error |
|
861 | + * @return void |
|
862 | + */ |
|
863 | + public function ensure_is_model() |
|
864 | + { |
|
865 | + //is it already instantiated? |
|
866 | + if ($this->_model instanceof EEM_Base) { |
|
867 | + return; |
|
868 | + } |
|
869 | + |
|
870 | + //ensure model name is string |
|
871 | + $this->_model_name = (string)$this->_model_name; |
|
872 | + //error proof if the name has EEM in it |
|
873 | + $this->_model_name = str_replace('EEM', '', $this->_model_name); |
|
874 | + |
|
875 | + $this->_model = EE_Registry::instance()->load_model($this->_model_name); |
|
876 | + |
|
877 | + if ( ! $this->_model instanceof EEM_Base) { |
|
878 | + throw new EE_Error(sprintf(__('This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class. Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s', |
|
879 | + 'event_espresso'), get_class($this), $this->_model)); |
|
880 | + } |
|
881 | + } |
|
882 | + |
|
883 | + |
|
884 | + /** |
|
885 | + * @see EE_Meta_Capability_Map::_map_meta_caps() for docs on params. |
|
886 | + * @since 4.6.x |
|
887 | + * @param $caps |
|
888 | + * @param $cap |
|
889 | + * @param $user_id |
|
890 | + * @param $args |
|
891 | + * @return array |
|
892 | + */ |
|
893 | + public function map_meta_caps($caps, $cap, $user_id, $args) |
|
894 | + { |
|
895 | + return $this->_map_meta_caps($caps, $cap, $user_id, $args); |
|
896 | + } |
|
897 | + |
|
898 | + |
|
899 | + /** |
|
900 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
901 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
902 | + * |
|
903 | + * @since 4.5.0 |
|
904 | + * @see wp-includes/capabilities.php |
|
905 | + * @param array $caps actual users capabilities |
|
906 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
907 | + * @param int $user_id The user id |
|
908 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
909 | + * @return array actual users capabilities |
|
910 | + */ |
|
911 | + abstract protected function _map_meta_caps($caps, $cap, $user_id, $args); |
|
912 | 912 | } |
913 | 913 | |
914 | 914 | |
@@ -924,79 +924,79 @@ discard block |
||
924 | 924 | class EE_Meta_Capability_Map_Edit extends EE_Meta_Capability_Map |
925 | 925 | { |
926 | 926 | |
927 | - /** |
|
928 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
929 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
930 | - * |
|
931 | - * @since 4.5.0 |
|
932 | - * @see wp-includes/capabilities.php |
|
933 | - * @param array $caps actual users capabilities |
|
934 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
935 | - * @param int $user_id The user id |
|
936 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
937 | - * @return array actual users capabilities |
|
938 | - */ |
|
939 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
940 | - { |
|
941 | - //only process if we're checking our mapped_cap |
|
942 | - if ($cap !== $this->meta_cap) { |
|
943 | - return $caps; |
|
944 | - } |
|
945 | - |
|
946 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
947 | - |
|
948 | - //if no obj then let's just do cap |
|
949 | - if ( ! $obj instanceof EE_Base_Class) { |
|
950 | - $caps[] = $cap; |
|
951 | - |
|
952 | - return $caps; |
|
953 | - } |
|
954 | - |
|
955 | - if ($obj instanceof EE_CPT_Base) { |
|
956 | - //if the item author is set and the user is the author... |
|
957 | - if ($obj->wp_user() && $user_id == $obj->wp_user()) { |
|
958 | - if (empty($this->published_cap)) { |
|
959 | - $caps[] = $cap; |
|
960 | - } else { |
|
961 | - //if obj is published... |
|
962 | - if ($obj->status() == 'publish') { |
|
963 | - $caps[] = $this->published_cap; |
|
964 | - } else { |
|
965 | - $caps[] = $cap; |
|
966 | - } |
|
967 | - } |
|
968 | - } else { |
|
969 | - //the user is trying to edit someone else's obj |
|
970 | - if ( ! empty($this->others_cap)) { |
|
971 | - $caps[] = $this->others_cap; |
|
972 | - } |
|
973 | - if ( ! empty($this->published_cap) && $obj->status() == 'publish') { |
|
974 | - $caps[] = $this->published_cap; |
|
975 | - } elseif ( ! empty($this->private_cap) && $obj->status() == 'private') { |
|
976 | - $caps[] = $this->private_cap; |
|
977 | - } |
|
978 | - } |
|
979 | - } else { |
|
980 | - //not a cpt object so handled differently |
|
981 | - $has_cap = false; |
|
982 | - try { |
|
983 | - $has_cap = method_exists($obj, 'wp_user') && $obj->wp_user() && $user_id == $obj->wp_user(); |
|
984 | - } catch (Exception $e) { |
|
985 | - if (WP_DEBUG) { |
|
986 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
987 | - } |
|
988 | - } |
|
989 | - if ($has_cap) { |
|
990 | - $caps[] = $cap; |
|
991 | - } else { |
|
992 | - if ( ! empty($this->others_cap)) { |
|
993 | - $caps[] = $this->others_cap; |
|
994 | - } |
|
995 | - } |
|
996 | - } |
|
997 | - |
|
998 | - return $caps; |
|
999 | - } |
|
927 | + /** |
|
928 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
929 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
930 | + * |
|
931 | + * @since 4.5.0 |
|
932 | + * @see wp-includes/capabilities.php |
|
933 | + * @param array $caps actual users capabilities |
|
934 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
935 | + * @param int $user_id The user id |
|
936 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
937 | + * @return array actual users capabilities |
|
938 | + */ |
|
939 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
940 | + { |
|
941 | + //only process if we're checking our mapped_cap |
|
942 | + if ($cap !== $this->meta_cap) { |
|
943 | + return $caps; |
|
944 | + } |
|
945 | + |
|
946 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
947 | + |
|
948 | + //if no obj then let's just do cap |
|
949 | + if ( ! $obj instanceof EE_Base_Class) { |
|
950 | + $caps[] = $cap; |
|
951 | + |
|
952 | + return $caps; |
|
953 | + } |
|
954 | + |
|
955 | + if ($obj instanceof EE_CPT_Base) { |
|
956 | + //if the item author is set and the user is the author... |
|
957 | + if ($obj->wp_user() && $user_id == $obj->wp_user()) { |
|
958 | + if (empty($this->published_cap)) { |
|
959 | + $caps[] = $cap; |
|
960 | + } else { |
|
961 | + //if obj is published... |
|
962 | + if ($obj->status() == 'publish') { |
|
963 | + $caps[] = $this->published_cap; |
|
964 | + } else { |
|
965 | + $caps[] = $cap; |
|
966 | + } |
|
967 | + } |
|
968 | + } else { |
|
969 | + //the user is trying to edit someone else's obj |
|
970 | + if ( ! empty($this->others_cap)) { |
|
971 | + $caps[] = $this->others_cap; |
|
972 | + } |
|
973 | + if ( ! empty($this->published_cap) && $obj->status() == 'publish') { |
|
974 | + $caps[] = $this->published_cap; |
|
975 | + } elseif ( ! empty($this->private_cap) && $obj->status() == 'private') { |
|
976 | + $caps[] = $this->private_cap; |
|
977 | + } |
|
978 | + } |
|
979 | + } else { |
|
980 | + //not a cpt object so handled differently |
|
981 | + $has_cap = false; |
|
982 | + try { |
|
983 | + $has_cap = method_exists($obj, 'wp_user') && $obj->wp_user() && $user_id == $obj->wp_user(); |
|
984 | + } catch (Exception $e) { |
|
985 | + if (WP_DEBUG) { |
|
986 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
987 | + } |
|
988 | + } |
|
989 | + if ($has_cap) { |
|
990 | + $caps[] = $cap; |
|
991 | + } else { |
|
992 | + if ( ! empty($this->others_cap)) { |
|
993 | + $caps[] = $this->others_cap; |
|
994 | + } |
|
995 | + } |
|
996 | + } |
|
997 | + |
|
998 | + return $caps; |
|
999 | + } |
|
1000 | 1000 | } |
1001 | 1001 | |
1002 | 1002 | |
@@ -1013,22 +1013,22 @@ discard block |
||
1013 | 1013 | class EE_Meta_Capability_Map_Delete extends EE_Meta_Capability_Map_Edit |
1014 | 1014 | { |
1015 | 1015 | |
1016 | - /** |
|
1017 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1018 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1019 | - * |
|
1020 | - * @since 4.5.0 |
|
1021 | - * @see wp-includes/capabilities.php |
|
1022 | - * @param array $caps actual users capabilities |
|
1023 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
1024 | - * @param int $user_id The user id |
|
1025 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
1026 | - * @return array actual users capabilities |
|
1027 | - */ |
|
1028 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1029 | - { |
|
1030 | - return parent::_map_meta_caps($caps, $cap, $user_id, $args); |
|
1031 | - } |
|
1016 | + /** |
|
1017 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1018 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1019 | + * |
|
1020 | + * @since 4.5.0 |
|
1021 | + * @see wp-includes/capabilities.php |
|
1022 | + * @param array $caps actual users capabilities |
|
1023 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
1024 | + * @param int $user_id The user id |
|
1025 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
1026 | + * @return array actual users capabilities |
|
1027 | + */ |
|
1028 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1029 | + { |
|
1030 | + return parent::_map_meta_caps($caps, $cap, $user_id, $args); |
|
1031 | + } |
|
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | |
@@ -1044,76 +1044,76 @@ discard block |
||
1044 | 1044 | class EE_Meta_Capability_Map_Read extends EE_Meta_Capability_Map |
1045 | 1045 | { |
1046 | 1046 | |
1047 | - /** |
|
1048 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1049 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1050 | - * |
|
1051 | - * @since 4.5.0 |
|
1052 | - * @see wp-includes/capabilities.php |
|
1053 | - * @param array $caps actual users capabilities |
|
1054 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
1055 | - * @param int $user_id The user id |
|
1056 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
1057 | - * @return array actual users capabilities |
|
1058 | - */ |
|
1059 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1060 | - { |
|
1061 | - //only process if we're checking our mapped cap; |
|
1062 | - if ($cap !== $this->meta_cap) { |
|
1063 | - return $caps; |
|
1064 | - } |
|
1065 | - |
|
1066 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1067 | - |
|
1068 | - //if no obj then let's just do cap |
|
1069 | - if ( ! $obj instanceof EE_Base_Class) { |
|
1070 | - $caps[] = $cap; |
|
1071 | - |
|
1072 | - return $caps; |
|
1073 | - } |
|
1074 | - |
|
1075 | - if ($obj instanceof EE_CPT_Base) { |
|
1076 | - $status_obj = get_post_status_object($obj->status()); |
|
1077 | - if ($status_obj->public) { |
|
1078 | - $caps[] = $cap; |
|
1079 | - |
|
1080 | - return $caps; |
|
1081 | - } |
|
1082 | - |
|
1083 | - //if the item author is set and the user is the author... |
|
1084 | - if ($obj->wp_user() && $user_id == $obj->wp_user()) { |
|
1085 | - $caps[] = $cap; |
|
1086 | - } elseif ($status_obj->private && ! empty($this->private_cap)) { |
|
1087 | - //the user is trying to view someone else's obj |
|
1088 | - $caps[] = $this->private_cap; |
|
1089 | - } elseif ( ! empty($this->others_cap)) { |
|
1090 | - $caps[] = $this->others_cap; |
|
1091 | - } else { |
|
1092 | - $caps[] = $cap; |
|
1093 | - } |
|
1094 | - } else { |
|
1095 | - //not a cpt object so handled differently |
|
1096 | - $has_cap = false; |
|
1097 | - try { |
|
1098 | - $has_cap = method_exists($obj, 'wp_user') && $obj->wp_user() && $user_id == $obj->wp_user(); |
|
1099 | - } catch (Exception $e) { |
|
1100 | - if (WP_DEBUG) { |
|
1101 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1102 | - } |
|
1103 | - } |
|
1104 | - if ($has_cap) { |
|
1105 | - $caps[] = $cap; |
|
1106 | - } elseif ( ! empty($this->private_cap)) { |
|
1107 | - $caps[] = $this->private_cap; |
|
1108 | - } elseif ( ! empty($this->others_cap)) { |
|
1109 | - $caps[] = $this->others_cap; |
|
1110 | - } else { |
|
1111 | - $caps[] = $cap; |
|
1112 | - } |
|
1113 | - } |
|
1114 | - |
|
1115 | - return $caps; |
|
1116 | - } |
|
1047 | + /** |
|
1048 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1049 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1050 | + * |
|
1051 | + * @since 4.5.0 |
|
1052 | + * @see wp-includes/capabilities.php |
|
1053 | + * @param array $caps actual users capabilities |
|
1054 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
1055 | + * @param int $user_id The user id |
|
1056 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
1057 | + * @return array actual users capabilities |
|
1058 | + */ |
|
1059 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1060 | + { |
|
1061 | + //only process if we're checking our mapped cap; |
|
1062 | + if ($cap !== $this->meta_cap) { |
|
1063 | + return $caps; |
|
1064 | + } |
|
1065 | + |
|
1066 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1067 | + |
|
1068 | + //if no obj then let's just do cap |
|
1069 | + if ( ! $obj instanceof EE_Base_Class) { |
|
1070 | + $caps[] = $cap; |
|
1071 | + |
|
1072 | + return $caps; |
|
1073 | + } |
|
1074 | + |
|
1075 | + if ($obj instanceof EE_CPT_Base) { |
|
1076 | + $status_obj = get_post_status_object($obj->status()); |
|
1077 | + if ($status_obj->public) { |
|
1078 | + $caps[] = $cap; |
|
1079 | + |
|
1080 | + return $caps; |
|
1081 | + } |
|
1082 | + |
|
1083 | + //if the item author is set and the user is the author... |
|
1084 | + if ($obj->wp_user() && $user_id == $obj->wp_user()) { |
|
1085 | + $caps[] = $cap; |
|
1086 | + } elseif ($status_obj->private && ! empty($this->private_cap)) { |
|
1087 | + //the user is trying to view someone else's obj |
|
1088 | + $caps[] = $this->private_cap; |
|
1089 | + } elseif ( ! empty($this->others_cap)) { |
|
1090 | + $caps[] = $this->others_cap; |
|
1091 | + } else { |
|
1092 | + $caps[] = $cap; |
|
1093 | + } |
|
1094 | + } else { |
|
1095 | + //not a cpt object so handled differently |
|
1096 | + $has_cap = false; |
|
1097 | + try { |
|
1098 | + $has_cap = method_exists($obj, 'wp_user') && $obj->wp_user() && $user_id == $obj->wp_user(); |
|
1099 | + } catch (Exception $e) { |
|
1100 | + if (WP_DEBUG) { |
|
1101 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1102 | + } |
|
1103 | + } |
|
1104 | + if ($has_cap) { |
|
1105 | + $caps[] = $cap; |
|
1106 | + } elseif ( ! empty($this->private_cap)) { |
|
1107 | + $caps[] = $this->private_cap; |
|
1108 | + } elseif ( ! empty($this->others_cap)) { |
|
1109 | + $caps[] = $this->others_cap; |
|
1110 | + } else { |
|
1111 | + $caps[] = $cap; |
|
1112 | + } |
|
1113 | + } |
|
1114 | + |
|
1115 | + return $caps; |
|
1116 | + } |
|
1117 | 1117 | } |
1118 | 1118 | |
1119 | 1119 | |
@@ -1130,52 +1130,52 @@ discard block |
||
1130 | 1130 | class EE_Meta_Capability_Map_Messages_Cap extends EE_Meta_Capability_Map |
1131 | 1131 | { |
1132 | 1132 | |
1133 | - /** |
|
1134 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1135 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1136 | - * |
|
1137 | - * @since 4.5.0 |
|
1138 | - * @see wp-includes/capabilities.php |
|
1139 | - * @param array $caps actual users capabilities |
|
1140 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
1141 | - * @param int $user_id The user id |
|
1142 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
1143 | - * @return array actual users capabilities |
|
1144 | - */ |
|
1145 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1146 | - { |
|
1147 | - //only process if we're checking our mapped_cap |
|
1148 | - if ($cap !== $this->meta_cap) { |
|
1149 | - return $caps; |
|
1150 | - } |
|
1151 | - |
|
1152 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1153 | - |
|
1154 | - //if no obj then let's just do cap |
|
1155 | - if ( ! $obj instanceof EE_Message_Template_Group) { |
|
1156 | - $caps[] = $cap; |
|
1157 | - |
|
1158 | - return $caps; |
|
1159 | - } |
|
1160 | - |
|
1161 | - $is_global = $obj->is_global(); |
|
1162 | - |
|
1163 | - if ($obj->wp_user() && $user_id == $obj->wp_user()) { |
|
1164 | - if ($is_global) { |
|
1165 | - $caps[] = $this->private_cap; |
|
1166 | - } else { |
|
1167 | - $caps[] = $cap; |
|
1168 | - } |
|
1169 | - } else { |
|
1170 | - if ($is_global) { |
|
1171 | - $caps[] = $this->private_cap; |
|
1172 | - } else { |
|
1173 | - $caps[] = $this->others_cap; |
|
1174 | - } |
|
1175 | - } |
|
1176 | - |
|
1177 | - return $caps; |
|
1178 | - } |
|
1133 | + /** |
|
1134 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1135 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1136 | + * |
|
1137 | + * @since 4.5.0 |
|
1138 | + * @see wp-includes/capabilities.php |
|
1139 | + * @param array $caps actual users capabilities |
|
1140 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
1141 | + * @param int $user_id The user id |
|
1142 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
1143 | + * @return array actual users capabilities |
|
1144 | + */ |
|
1145 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1146 | + { |
|
1147 | + //only process if we're checking our mapped_cap |
|
1148 | + if ($cap !== $this->meta_cap) { |
|
1149 | + return $caps; |
|
1150 | + } |
|
1151 | + |
|
1152 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1153 | + |
|
1154 | + //if no obj then let's just do cap |
|
1155 | + if ( ! $obj instanceof EE_Message_Template_Group) { |
|
1156 | + $caps[] = $cap; |
|
1157 | + |
|
1158 | + return $caps; |
|
1159 | + } |
|
1160 | + |
|
1161 | + $is_global = $obj->is_global(); |
|
1162 | + |
|
1163 | + if ($obj->wp_user() && $user_id == $obj->wp_user()) { |
|
1164 | + if ($is_global) { |
|
1165 | + $caps[] = $this->private_cap; |
|
1166 | + } else { |
|
1167 | + $caps[] = $cap; |
|
1168 | + } |
|
1169 | + } else { |
|
1170 | + if ($is_global) { |
|
1171 | + $caps[] = $this->private_cap; |
|
1172 | + } else { |
|
1173 | + $caps[] = $this->others_cap; |
|
1174 | + } |
|
1175 | + } |
|
1176 | + |
|
1177 | + return $caps; |
|
1178 | + } |
|
1179 | 1179 | } |
1180 | 1180 | |
1181 | 1181 | |
@@ -1192,43 +1192,43 @@ discard block |
||
1192 | 1192 | class EE_Meta_Capability_Map_Registration_Form_Cap extends EE_Meta_Capability_Map |
1193 | 1193 | { |
1194 | 1194 | |
1195 | - /** |
|
1196 | - * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1197 | - * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1198 | - * |
|
1199 | - * @since 4.5.0 |
|
1200 | - * @see wp-includes/capabilities.php |
|
1201 | - * @param array $caps actual users capabilities |
|
1202 | - * @param string $cap initial capability name that is being checked (the "map" key) |
|
1203 | - * @param int $user_id The user id |
|
1204 | - * @param array $args Adds context to the cap. Typically the object ID. |
|
1205 | - * @return array actual users capabilities |
|
1206 | - */ |
|
1207 | - protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1208 | - { |
|
1209 | - //only process if we're checking our mapped_cap |
|
1210 | - if ($cap !== $this->meta_cap) { |
|
1211 | - return $caps; |
|
1212 | - } |
|
1213 | - |
|
1214 | - $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1215 | - |
|
1216 | - //if no obj then let's just do cap |
|
1217 | - if ( ! $obj instanceof EE_Base_Class) { |
|
1218 | - $caps[] = $cap; |
|
1219 | - |
|
1220 | - return $caps; |
|
1221 | - } |
|
1222 | - |
|
1223 | - $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
|
1224 | - $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
|
1225 | - |
|
1226 | - if ($is_system) { |
|
1227 | - $caps[] = $this->private_cap; |
|
1228 | - } else { |
|
1229 | - $caps[] = $cap; |
|
1230 | - } |
|
1231 | - |
|
1232 | - return $caps; |
|
1233 | - } |
|
1195 | + /** |
|
1196 | + * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a |
|
1197 | + * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected. |
|
1198 | + * |
|
1199 | + * @since 4.5.0 |
|
1200 | + * @see wp-includes/capabilities.php |
|
1201 | + * @param array $caps actual users capabilities |
|
1202 | + * @param string $cap initial capability name that is being checked (the "map" key) |
|
1203 | + * @param int $user_id The user id |
|
1204 | + * @param array $args Adds context to the cap. Typically the object ID. |
|
1205 | + * @return array actual users capabilities |
|
1206 | + */ |
|
1207 | + protected function _map_meta_caps($caps, $cap, $user_id, $args) |
|
1208 | + { |
|
1209 | + //only process if we're checking our mapped_cap |
|
1210 | + if ($cap !== $this->meta_cap) { |
|
1211 | + return $caps; |
|
1212 | + } |
|
1213 | + |
|
1214 | + $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null; |
|
1215 | + |
|
1216 | + //if no obj then let's just do cap |
|
1217 | + if ( ! $obj instanceof EE_Base_Class) { |
|
1218 | + $caps[] = $cap; |
|
1219 | + |
|
1220 | + return $caps; |
|
1221 | + } |
|
1222 | + |
|
1223 | + $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false; |
|
1224 | + $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system; |
|
1225 | + |
|
1226 | + if ($is_system) { |
|
1227 | + $caps[] = $this->private_cap; |
|
1228 | + } else { |
|
1229 | + $caps[] = $cap; |
|
1230 | + } |
|
1231 | + |
|
1232 | + return $caps; |
|
1233 | + } |
|
1234 | 1234 | } |
@@ -705,7 +705,7 @@ discard block |
||
705 | 705 | public function current_user_can($cap, $context, $id = 0) |
706 | 706 | { |
707 | 707 | //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
708 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id); |
|
708 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__'.$context, $cap, $id); |
|
709 | 709 | $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap', $filtered_cap, $context, $cap, |
710 | 710 | $id); |
711 | 711 | |
@@ -726,7 +726,7 @@ discard block |
||
726 | 726 | public function user_can($user, $cap, $context, $id = 0) |
727 | 727 | { |
728 | 728 | //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
729 | - $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id); |
|
729 | + $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__'.$context, $cap, $user, $id); |
|
730 | 730 | $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap', $filtered_cap, $context, $cap, $user, |
731 | 731 | $id); |
732 | 732 | |
@@ -754,7 +754,7 @@ discard block |
||
754 | 754 | $user_can = ! empty($id) ? current_user_can_for_blog($blog_id, $cap, $id) : current_user_can($blog_id, $cap); |
755 | 755 | |
756 | 756 | //apply filters (both a global on just the cap, and context specific. Global overrides context specific) |
757 | - $user_can = apply_filters('FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context, $user_can, |
|
757 | + $user_can = apply_filters('FHEE__EE_Capabilities__current_user_can_for_blog__user_can__'.$context, $user_can, |
|
758 | 758 | $blog_id, $cap, $id); |
759 | 759 | $user_can = apply_filters('FHEE__EE_Capabilities__current_user_can_for_blog__user_can', $user_can, $context, |
760 | 760 | $blog_id, $cap, $id); |
@@ -833,15 +833,15 @@ discard block |
||
833 | 833 | //verify there are four args in the $map_values array; |
834 | 834 | if (count($map_values) !== 4) { |
835 | 835 | throw new EE_Error(sprintf(__('Incoming $map_values array should have a count of four values in it. This is what was given: %s', |
836 | - 'event_espresso'), '<br>' . print_r($map_values, true))); |
|
836 | + 'event_espresso'), '<br>'.print_r($map_values, true))); |
|
837 | 837 | } |
838 | 838 | |
839 | 839 | //set properties |
840 | 840 | $this->_model = null; |
841 | 841 | $this->_model_name = $map_values[0]; |
842 | - $this->published_cap = (string)$map_values[1]; |
|
843 | - $this->others_cap = (string)$map_values[2]; |
|
844 | - $this->private_cap = (string)$map_values[3]; |
|
842 | + $this->published_cap = (string) $map_values[1]; |
|
843 | + $this->others_cap = (string) $map_values[2]; |
|
844 | + $this->private_cap = (string) $map_values[3]; |
|
845 | 845 | } |
846 | 846 | |
847 | 847 | /** |
@@ -868,7 +868,7 @@ discard block |
||
868 | 868 | } |
869 | 869 | |
870 | 870 | //ensure model name is string |
871 | - $this->_model_name = (string)$this->_model_name; |
|
871 | + $this->_model_name = (string) $this->_model_name; |
|
872 | 872 | //error proof if the name has EEM in it |
873 | 873 | $this->_model_name = str_replace('EEM', '', $this->_model_name); |
874 | 874 |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\services\database\TableAnalysis; |
3 | 3 | |
4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | /** |
8 | 8 | * the purpose of this file is to simply contain any action/filter hook callbacks etc for specific aspects of EE |
@@ -27,277 +27,277 @@ discard block |
||
27 | 27 | class EE_Brewing_Regular extends EE_BASE |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
32 | - */ |
|
33 | - protected $_table_analysis; |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * EE_Brewing_Regular constructor. |
|
39 | - */ |
|
40 | - public function __construct(TableAnalysis $table_analysis) |
|
41 | - { |
|
42 | - $this->_table_analysis = $table_analysis; |
|
43 | - if (defined('EE_CAFF_PATH')) { |
|
44 | - // activation |
|
45 | - add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content')); |
|
46 | - // load caff init |
|
47 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init')); |
|
48 | - // remove the "powered by" credit link from receipts and invoices |
|
49 | - add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false'); |
|
50 | - // add caffeinated modules |
|
51 | - add_filter( |
|
52 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
53 | - array($this, 'caffeinated_modules_to_register') |
|
54 | - ); |
|
55 | - // load caff scripts |
|
56 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10); |
|
57 | - add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10); |
|
58 | - add_filter( |
|
59 | - 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
60 | - array($this, 'caf_payment_methods') |
|
61 | - ); |
|
62 | - // caffeinated constructed |
|
63 | - do_action('AHEE__EE_Brewing_Regular__construct__finished'); |
|
64 | - //seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer |
|
65 | - add_filter('FHEE__ee_show_affiliate_links', '__return_false'); |
|
66 | - } |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths |
|
73 | - * |
|
74 | - * @param array $paths original helper paths array |
|
75 | - * @return array new array of paths |
|
76 | - */ |
|
77 | - public function caf_helper_paths($paths) |
|
78 | - { |
|
79 | - $paths[] = EE_CAF_CORE . 'helpers' . DS; |
|
80 | - return $paths; |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * Upon brand-new activation, if this is a new activation of CAF, we want to add |
|
87 | - * some global prices that will show off EE4's capabilities. However, if they're upgrading |
|
88 | - * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices. |
|
89 | - * This action should only be called when EE 4.x.0.P is initially activated. |
|
90 | - * Right now the only CAF content are these global prices. If there's more in the future, then |
|
91 | - * we should probably create a caf file to contain it all instead just a function like this. |
|
92 | - * Right now, we ASSUME the only price types in the system are default ones |
|
93 | - * |
|
94 | - * @global wpdb $wpdb |
|
95 | - */ |
|
96 | - public function initialize_caf_db_content() |
|
97 | - { |
|
98 | - global $wpdb; |
|
99 | - //use same method of getting creator id as the version introducing the change |
|
100 | - $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
|
101 | - $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
102 | - $price_table = $wpdb->prefix . "esp_price"; |
|
103 | - if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
104 | - $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types |
|
105 | - $tax_price_type_count = $wpdb->get_var($SQL); |
|
106 | - if ($tax_price_type_count <= 1) { |
|
107 | - $wpdb->insert( |
|
108 | - $price_type_table, |
|
109 | - array( |
|
110 | - 'PRT_name' => __("Regional Tax", "event_espresso"), |
|
111 | - 'PBT_ID' => 4, |
|
112 | - 'PRT_is_percent' => true, |
|
113 | - 'PRT_order' => 60, |
|
114 | - 'PRT_deleted' => false, |
|
115 | - 'PRT_wp_user' => $default_creator_id, |
|
116 | - ), |
|
117 | - array( |
|
118 | - '%s',//PRT_name |
|
119 | - '%d',//PBT_id |
|
120 | - '%d',//PRT_is_percent |
|
121 | - '%d',//PRT_order |
|
122 | - '%d',//PRT_deleted |
|
123 | - '%d', //PRT_wp_user |
|
124 | - ) |
|
125 | - ); |
|
126 | - //federal tax |
|
127 | - $result = $wpdb->insert( |
|
128 | - $price_type_table, |
|
129 | - array( |
|
130 | - 'PRT_name' => __("Federal Tax", "event_espresso"), |
|
131 | - 'PBT_ID' => 4, |
|
132 | - 'PRT_is_percent' => true, |
|
133 | - 'PRT_order' => 70, |
|
134 | - 'PRT_deleted' => false, |
|
135 | - 'PRT_wp_user' => $default_creator_id, |
|
136 | - ), |
|
137 | - array( |
|
138 | - '%s',//PRT_name |
|
139 | - '%d',//PBT_id |
|
140 | - '%d',//PRT_is_percent |
|
141 | - '%d',//PRT_order |
|
142 | - '%d',//PRT_deleted |
|
143 | - '%d' //PRT_wp_user |
|
144 | - ) |
|
145 | - ); |
|
146 | - if ($result) { |
|
147 | - $wpdb->insert( |
|
148 | - $price_table, |
|
149 | - array( |
|
150 | - 'PRT_ID' => $wpdb->insert_id, |
|
151 | - 'PRC_amount' => 15.00, |
|
152 | - 'PRC_name' => __("Sales Tax", "event_espresso"), |
|
153 | - 'PRC_desc' => '', |
|
154 | - 'PRC_is_default' => true, |
|
155 | - 'PRC_overrides' => null, |
|
156 | - 'PRC_deleted' => false, |
|
157 | - 'PRC_order' => 50, |
|
158 | - 'PRC_parent' => null, |
|
159 | - 'PRC_wp_user' => $default_creator_id, |
|
160 | - ), |
|
161 | - array( |
|
162 | - '%d',//PRT_id |
|
163 | - '%f',//PRC_amount |
|
164 | - '%s',//PRC_name |
|
165 | - '%s',//PRC_desc |
|
166 | - '%d',//PRC_is_default |
|
167 | - '%d',//PRC_overrides |
|
168 | - '%d',//PRC_deleted |
|
169 | - '%d',//PRC_order |
|
170 | - '%d',//PRC_parent |
|
171 | - '%d' //PRC_wp_user |
|
172 | - ) |
|
173 | - ); |
|
174 | - } |
|
175 | - } |
|
176 | - } |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * caffeinated_modules_to_register |
|
183 | - * |
|
184 | - * @access public |
|
185 | - * @param array $modules_to_register |
|
186 | - * @return array |
|
187 | - */ |
|
188 | - public function caffeinated_modules_to_register($modules_to_register = array()) |
|
189 | - { |
|
190 | - if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
191 | - $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR); |
|
192 | - if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
|
193 | - $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
|
194 | - } |
|
195 | - } |
|
196 | - return $modules_to_register; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - |
|
201 | - public function caffeinated_init() |
|
202 | - { |
|
203 | - // EE_Register_CPTs hooks |
|
204 | - add_filter('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array($this, 'filter_taxonomies'), 10); |
|
205 | - add_filter('FHEE__EE_Register_CPTs__get_CPTs__cpts', array($this, 'filter_cpts'), 10); |
|
206 | - add_filter('FHEE__EE_Admin__get_extra_nav_menu_pages_items', array($this, 'nav_metabox_items'), 10); |
|
207 | - EE_Registry::instance()->load_file(EE_CAFF_PATH, 'EE_Caf_Messages', 'class', array(), false); |
|
208 | - // caffeinated_init__complete hook |
|
209 | - do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete'); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - |
|
214 | - public function enqueue_caffeinated_scripts() |
|
215 | - { |
|
216 | - // sound of crickets... |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * callbacks below here |
|
223 | - * |
|
224 | - * @param array $taxonomy_array |
|
225 | - * @return array |
|
226 | - */ |
|
227 | - public function filter_taxonomies(array $taxonomy_array) |
|
228 | - { |
|
229 | - $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true; |
|
230 | - return $taxonomy_array; |
|
231 | - } |
|
232 | - |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * @param array $cpt_array |
|
237 | - * @return mixed |
|
238 | - */ |
|
239 | - public function filter_cpts(array $cpt_array) |
|
240 | - { |
|
241 | - $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true; |
|
242 | - return $cpt_array; |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * @param array $menuitems |
|
249 | - * @return array |
|
250 | - */ |
|
251 | - public function nav_metabox_items(array $menuitems) |
|
252 | - { |
|
253 | - $menuitems[] = array( |
|
254 | - 'title' => __('Venue List', 'event_espresso'), |
|
255 | - 'url' => get_post_type_archive_link('espresso_venues'), |
|
256 | - 'description' => __('Archive page for all venues.', 'event_espresso'), |
|
257 | - ); |
|
258 | - return $menuitems; |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - |
|
263 | - /** |
|
264 | - * Adds the payment methods in {event-espresso-core}/caffeinated/payment_methods |
|
265 | - * |
|
266 | - * @param array $payment_method_paths |
|
267 | - * @return array values are folder paths to payment method folders |
|
268 | - */ |
|
269 | - public function caf_payment_methods($payment_method_paths) |
|
270 | - { |
|
271 | - $caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
272 | - $payment_method_paths = array_merge($payment_method_paths, $caf_payment_methods_paths); |
|
273 | - return $payment_method_paths; |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * Gets the injected table analyzer, or throws an exception |
|
280 | - * |
|
281 | - * @return TableAnalysis |
|
282 | - * @throws \EE_Error |
|
283 | - */ |
|
284 | - protected function _get_table_analysis() |
|
285 | - { |
|
286 | - if ($this->_table_analysis instanceof TableAnalysis) { |
|
287 | - return $this->_table_analysis; |
|
288 | - } else { |
|
289 | - throw new \EE_Error( |
|
290 | - sprintf( |
|
291 | - __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
292 | - get_class($this) |
|
293 | - ) |
|
294 | - ); |
|
295 | - } |
|
296 | - } |
|
30 | + /** |
|
31 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
32 | + */ |
|
33 | + protected $_table_analysis; |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * EE_Brewing_Regular constructor. |
|
39 | + */ |
|
40 | + public function __construct(TableAnalysis $table_analysis) |
|
41 | + { |
|
42 | + $this->_table_analysis = $table_analysis; |
|
43 | + if (defined('EE_CAFF_PATH')) { |
|
44 | + // activation |
|
45 | + add_action('AHEE__EEH_Activation__initialize_db_content', array($this, 'initialize_caf_db_content')); |
|
46 | + // load caff init |
|
47 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'caffeinated_init')); |
|
48 | + // remove the "powered by" credit link from receipts and invoices |
|
49 | + add_filter('FHEE_EE_Html_messenger__add_powered_by_credit_link_to_receipt_and_invoice', '__return_false'); |
|
50 | + // add caffeinated modules |
|
51 | + add_filter( |
|
52 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
53 | + array($this, 'caffeinated_modules_to_register') |
|
54 | + ); |
|
55 | + // load caff scripts |
|
56 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_caffeinated_scripts'), 10); |
|
57 | + add_filter('FHEE__EE_Registry__load_helper__helper_paths', array($this, 'caf_helper_paths'), 10); |
|
58 | + add_filter( |
|
59 | + 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
60 | + array($this, 'caf_payment_methods') |
|
61 | + ); |
|
62 | + // caffeinated constructed |
|
63 | + do_action('AHEE__EE_Brewing_Regular__construct__finished'); |
|
64 | + //seeing how this is caf, which isn't put on WordPress.org, we can have affiliate links without a disclaimer |
|
65 | + add_filter('FHEE__ee_show_affiliate_links', '__return_false'); |
|
66 | + } |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * callback for the FHEE__EE_Registry__load_helper__helper_paths filter to add the caffeinated paths |
|
73 | + * |
|
74 | + * @param array $paths original helper paths array |
|
75 | + * @return array new array of paths |
|
76 | + */ |
|
77 | + public function caf_helper_paths($paths) |
|
78 | + { |
|
79 | + $paths[] = EE_CAF_CORE . 'helpers' . DS; |
|
80 | + return $paths; |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * Upon brand-new activation, if this is a new activation of CAF, we want to add |
|
87 | + * some global prices that will show off EE4's capabilities. However, if they're upgrading |
|
88 | + * from 3.1, or simply EE4.x decaf, we assume they don't want us to suddenly introduce these extra prices. |
|
89 | + * This action should only be called when EE 4.x.0.P is initially activated. |
|
90 | + * Right now the only CAF content are these global prices. If there's more in the future, then |
|
91 | + * we should probably create a caf file to contain it all instead just a function like this. |
|
92 | + * Right now, we ASSUME the only price types in the system are default ones |
|
93 | + * |
|
94 | + * @global wpdb $wpdb |
|
95 | + */ |
|
96 | + public function initialize_caf_db_content() |
|
97 | + { |
|
98 | + global $wpdb; |
|
99 | + //use same method of getting creator id as the version introducing the change |
|
100 | + $default_creator_id = apply_filters('FHEE__EE_DMS_Core_4_5_0__get_default_creator_id', get_current_user_id()); |
|
101 | + $price_type_table = $wpdb->prefix . "esp_price_type"; |
|
102 | + $price_table = $wpdb->prefix . "esp_price"; |
|
103 | + if ($this->_get_table_analysis()->tableExists($price_type_table)) { |
|
104 | + $SQL = 'SELECT COUNT(PRT_ID) FROM ' . $price_type_table . ' WHERE PBT_ID=4';//include trashed price types |
|
105 | + $tax_price_type_count = $wpdb->get_var($SQL); |
|
106 | + if ($tax_price_type_count <= 1) { |
|
107 | + $wpdb->insert( |
|
108 | + $price_type_table, |
|
109 | + array( |
|
110 | + 'PRT_name' => __("Regional Tax", "event_espresso"), |
|
111 | + 'PBT_ID' => 4, |
|
112 | + 'PRT_is_percent' => true, |
|
113 | + 'PRT_order' => 60, |
|
114 | + 'PRT_deleted' => false, |
|
115 | + 'PRT_wp_user' => $default_creator_id, |
|
116 | + ), |
|
117 | + array( |
|
118 | + '%s',//PRT_name |
|
119 | + '%d',//PBT_id |
|
120 | + '%d',//PRT_is_percent |
|
121 | + '%d',//PRT_order |
|
122 | + '%d',//PRT_deleted |
|
123 | + '%d', //PRT_wp_user |
|
124 | + ) |
|
125 | + ); |
|
126 | + //federal tax |
|
127 | + $result = $wpdb->insert( |
|
128 | + $price_type_table, |
|
129 | + array( |
|
130 | + 'PRT_name' => __("Federal Tax", "event_espresso"), |
|
131 | + 'PBT_ID' => 4, |
|
132 | + 'PRT_is_percent' => true, |
|
133 | + 'PRT_order' => 70, |
|
134 | + 'PRT_deleted' => false, |
|
135 | + 'PRT_wp_user' => $default_creator_id, |
|
136 | + ), |
|
137 | + array( |
|
138 | + '%s',//PRT_name |
|
139 | + '%d',//PBT_id |
|
140 | + '%d',//PRT_is_percent |
|
141 | + '%d',//PRT_order |
|
142 | + '%d',//PRT_deleted |
|
143 | + '%d' //PRT_wp_user |
|
144 | + ) |
|
145 | + ); |
|
146 | + if ($result) { |
|
147 | + $wpdb->insert( |
|
148 | + $price_table, |
|
149 | + array( |
|
150 | + 'PRT_ID' => $wpdb->insert_id, |
|
151 | + 'PRC_amount' => 15.00, |
|
152 | + 'PRC_name' => __("Sales Tax", "event_espresso"), |
|
153 | + 'PRC_desc' => '', |
|
154 | + 'PRC_is_default' => true, |
|
155 | + 'PRC_overrides' => null, |
|
156 | + 'PRC_deleted' => false, |
|
157 | + 'PRC_order' => 50, |
|
158 | + 'PRC_parent' => null, |
|
159 | + 'PRC_wp_user' => $default_creator_id, |
|
160 | + ), |
|
161 | + array( |
|
162 | + '%d',//PRT_id |
|
163 | + '%f',//PRC_amount |
|
164 | + '%s',//PRC_name |
|
165 | + '%s',//PRC_desc |
|
166 | + '%d',//PRC_is_default |
|
167 | + '%d',//PRC_overrides |
|
168 | + '%d',//PRC_deleted |
|
169 | + '%d',//PRC_order |
|
170 | + '%d',//PRC_parent |
|
171 | + '%d' //PRC_wp_user |
|
172 | + ) |
|
173 | + ); |
|
174 | + } |
|
175 | + } |
|
176 | + } |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * caffeinated_modules_to_register |
|
183 | + * |
|
184 | + * @access public |
|
185 | + * @param array $modules_to_register |
|
186 | + * @return array |
|
187 | + */ |
|
188 | + public function caffeinated_modules_to_register($modules_to_register = array()) |
|
189 | + { |
|
190 | + if (is_readable(EE_CAFF_PATH . 'modules')) { |
|
191 | + $caffeinated_modules_to_register = glob(EE_CAFF_PATH . 'modules' . DS . '*', GLOB_ONLYDIR); |
|
192 | + if (is_array($caffeinated_modules_to_register) && ! empty($caffeinated_modules_to_register)) { |
|
193 | + $modules_to_register = array_merge($modules_to_register, $caffeinated_modules_to_register); |
|
194 | + } |
|
195 | + } |
|
196 | + return $modules_to_register; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + |
|
201 | + public function caffeinated_init() |
|
202 | + { |
|
203 | + // EE_Register_CPTs hooks |
|
204 | + add_filter('FHEE__EE_Register_CPTs__get_taxonomies__taxonomies', array($this, 'filter_taxonomies'), 10); |
|
205 | + add_filter('FHEE__EE_Register_CPTs__get_CPTs__cpts', array($this, 'filter_cpts'), 10); |
|
206 | + add_filter('FHEE__EE_Admin__get_extra_nav_menu_pages_items', array($this, 'nav_metabox_items'), 10); |
|
207 | + EE_Registry::instance()->load_file(EE_CAFF_PATH, 'EE_Caf_Messages', 'class', array(), false); |
|
208 | + // caffeinated_init__complete hook |
|
209 | + do_action('AHEE__EE_Brewing_Regular__caffeinated_init__complete'); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + |
|
214 | + public function enqueue_caffeinated_scripts() |
|
215 | + { |
|
216 | + // sound of crickets... |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * callbacks below here |
|
223 | + * |
|
224 | + * @param array $taxonomy_array |
|
225 | + * @return array |
|
226 | + */ |
|
227 | + public function filter_taxonomies(array $taxonomy_array) |
|
228 | + { |
|
229 | + $taxonomy_array['espresso_venue_categories']['args']['show_in_nav_menus'] = true; |
|
230 | + return $taxonomy_array; |
|
231 | + } |
|
232 | + |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * @param array $cpt_array |
|
237 | + * @return mixed |
|
238 | + */ |
|
239 | + public function filter_cpts(array $cpt_array) |
|
240 | + { |
|
241 | + $cpt_array['espresso_venues']['args']['show_in_nav_menus'] = true; |
|
242 | + return $cpt_array; |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * @param array $menuitems |
|
249 | + * @return array |
|
250 | + */ |
|
251 | + public function nav_metabox_items(array $menuitems) |
|
252 | + { |
|
253 | + $menuitems[] = array( |
|
254 | + 'title' => __('Venue List', 'event_espresso'), |
|
255 | + 'url' => get_post_type_archive_link('espresso_venues'), |
|
256 | + 'description' => __('Archive page for all venues.', 'event_espresso'), |
|
257 | + ); |
|
258 | + return $menuitems; |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + |
|
263 | + /** |
|
264 | + * Adds the payment methods in {event-espresso-core}/caffeinated/payment_methods |
|
265 | + * |
|
266 | + * @param array $payment_method_paths |
|
267 | + * @return array values are folder paths to payment method folders |
|
268 | + */ |
|
269 | + public function caf_payment_methods($payment_method_paths) |
|
270 | + { |
|
271 | + $caf_payment_methods_paths = glob(EE_CAF_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
272 | + $payment_method_paths = array_merge($payment_method_paths, $caf_payment_methods_paths); |
|
273 | + return $payment_method_paths; |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * Gets the injected table analyzer, or throws an exception |
|
280 | + * |
|
281 | + * @return TableAnalysis |
|
282 | + * @throws \EE_Error |
|
283 | + */ |
|
284 | + protected function _get_table_analysis() |
|
285 | + { |
|
286 | + if ($this->_table_analysis instanceof TableAnalysis) { |
|
287 | + return $this->_table_analysis; |
|
288 | + } else { |
|
289 | + throw new \EE_Error( |
|
290 | + sprintf( |
|
291 | + __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
292 | + get_class($this) |
|
293 | + ) |
|
294 | + ); |
|
295 | + } |
|
296 | + } |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | |
300 | 300 | |
301 | 301 | $brewing = new EE_Brewing_Regular( |
302 | - EE_Registry::instance()->create('TableAnalysis', array(), true) |
|
302 | + EE_Registry::instance()->create('TableAnalysis', array(), true) |
|
303 | 303 | ); |
@@ -955,17 +955,17 @@ |
||
955 | 955 | |
956 | 956 | |
957 | 957 | function ee_deprecate_AHEE__EE_Brewing_Regular__construct__complete() { |
958 | - if (has_action('AHEE__EE_Brewing_Regular__construct__complete')) { |
|
959 | - EE_Error::doing_it_wrong( |
|
960 | - 'Action Hook: AHEE__EE_Brewing_Regular__construct__complete', |
|
961 | - esc_html__( |
|
962 | - 'This action has been replaced by `AHEE__EE_Brewing_Regular__construct_finished` which executes at plugins_loaded priority 1. Your callback hooking into this action is still being executed at plugins_loaded priority level 5 but no longer immediately at the end of the EE_Brewing_Regular::construct.', |
|
963 | - 'event_espresso' |
|
964 | - ), |
|
965 | - '4.9.22.p' |
|
966 | - ); |
|
967 | - } |
|
968 | - do_action( 'AHEE__EE_Brewing_Regular__construct__complete' ); |
|
958 | + if (has_action('AHEE__EE_Brewing_Regular__construct__complete')) { |
|
959 | + EE_Error::doing_it_wrong( |
|
960 | + 'Action Hook: AHEE__EE_Brewing_Regular__construct__complete', |
|
961 | + esc_html__( |
|
962 | + 'This action has been replaced by `AHEE__EE_Brewing_Regular__construct_finished` which executes at plugins_loaded priority 1. Your callback hooking into this action is still being executed at plugins_loaded priority level 5 but no longer immediately at the end of the EE_Brewing_Regular::construct.', |
|
963 | + 'event_espresso' |
|
964 | + ), |
|
965 | + '4.9.22.p' |
|
966 | + ); |
|
967 | + } |
|
968 | + do_action( 'AHEE__EE_Brewing_Regular__construct__complete' ); |
|
969 | 969 | } |
970 | 970 | add_action( 'AHEE__EE_System__load_core_configuration__complete', 'ee_deprecate_AHEE__EE_Brewing_Regular__construct__complete' ); |
971 | 971 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
3 | - exit( 'No direct script access allowed' ); |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | /** |
6 | 6 | * ************************************************************************ |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | $action_or_filter = 'action' |
44 | 44 | ) { |
45 | 45 | $action_or_filter = $action_or_filter === 'action' |
46 | - ? esc_html__( 'action', 'event_espresso' ) |
|
47 | - : esc_html__( 'filter', 'event_espresso' ); |
|
46 | + ? esc_html__('action', 'event_espresso') |
|
47 | + : esc_html__('filter', 'event_espresso'); |
|
48 | 48 | EE_Error::doing_it_wrong( |
49 | 49 | $deprecated_filter, |
50 | 50 | sprintf( |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @param \EE_Checkout $checkout |
69 | 69 | * @return string |
70 | 70 | */ |
71 | -function ee_deprecated__registration_checkout__button_text( $submit_button_text, EE_Checkout $checkout ) { |
|
71 | +function ee_deprecated__registration_checkout__button_text($submit_button_text, EE_Checkout $checkout) { |
|
72 | 72 | // list of old filters |
73 | 73 | $deprecated_filters = array( |
74 | 74 | 'update_registration_details' => true, |
@@ -78,16 +78,16 @@ discard block |
||
78 | 78 | 'proceed_to' => true, |
79 | 79 | ); |
80 | 80 | // loop thru and call doing_it_wrong() or remove any that aren't being used |
81 | - foreach ( $deprecated_filters as $deprecated_filter => $on ) { |
|
81 | + foreach ($deprecated_filters as $deprecated_filter => $on) { |
|
82 | 82 | // was this filter called ? |
83 | - if ( has_action( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter )) { |
|
83 | + if (has_action('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter)) { |
|
84 | 84 | // only display doing_it_wrong() notice to Event Admins during non-AJAX requests |
85 | - if ( EE_Registry::instance()->CAP->current_user_can( 'ee_read_ee', 'hide_doing_it_wrong_for_deprecated_SPCO_filter' ) && ! defined( 'DOING_AJAX' ) ) { |
|
85 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_ee', 'hide_doing_it_wrong_for_deprecated_SPCO_filter') && ! defined('DOING_AJAX')) { |
|
86 | 86 | EE_Error::doing_it_wrong( |
87 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter, |
|
87 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter, |
|
88 | 88 | sprintf( |
89 | - __( 'The %1$s filter is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"', 'event_espresso' ), |
|
90 | - 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter, |
|
89 | + __('The %1$s filter is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"', 'event_espresso'), |
|
90 | + 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__'.$deprecated_filter, |
|
91 | 91 | '<br />', |
92 | 92 | 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
93 | 93 | '/modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php' |
@@ -96,24 +96,24 @@ discard block |
||
96 | 96 | ); |
97 | 97 | } |
98 | 98 | } else { |
99 | - unset( $deprecated_filters[ $deprecated_filter ] ); |
|
99 | + unset($deprecated_filters[$deprecated_filter]); |
|
100 | 100 | } |
101 | 101 | } |
102 | - if ( ! empty( $deprecated_filters )) { |
|
103 | - |
|
104 | - if ( $checkout->current_step->slug() == 'attendee_information' && $checkout->revisit && isset( $deprecated_filters[ 'update_registration_details' ] )) { |
|
105 | - $submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details', $submit_button_text ); |
|
106 | - } else if ( $checkout->current_step->slug() == 'payment_options' && $checkout->revisit && isset( $deprecated_filters[ 'process_payment' ] ) ) { |
|
107 | - $submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment', $submit_button_text ); |
|
108 | - } else if ( $checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug() == 'finalize_registration' && isset( $deprecated_filters[ 'finalize_registration' ] ) ) { |
|
109 | - $submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration', $submit_button_text ); |
|
102 | + if ( ! empty($deprecated_filters)) { |
|
103 | + |
|
104 | + if ($checkout->current_step->slug() == 'attendee_information' && $checkout->revisit && isset($deprecated_filters['update_registration_details'])) { |
|
105 | + $submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details', $submit_button_text); |
|
106 | + } else if ($checkout->current_step->slug() == 'payment_options' && $checkout->revisit && isset($deprecated_filters['process_payment'])) { |
|
107 | + $submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment', $submit_button_text); |
|
108 | + } else if ($checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug() == 'finalize_registration' && isset($deprecated_filters['finalize_registration'])) { |
|
109 | + $submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration', $submit_button_text); |
|
110 | 110 | } |
111 | - if ( $checkout->next_step instanceof EE_SPCO_Reg_Step ) { |
|
112 | - if ( $checkout->payment_required() && $checkout->next_step->slug() == 'payment_options' && isset( $deprecated_filters[ 'and_proceed_to_payment' ] ) ) { |
|
113 | - $submit_button_text .= apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment', $submit_button_text ); |
|
111 | + if ($checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
112 | + if ($checkout->payment_required() && $checkout->next_step->slug() == 'payment_options' && isset($deprecated_filters['and_proceed_to_payment'])) { |
|
113 | + $submit_button_text .= apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment', $submit_button_text); |
|
114 | 114 | } |
115 | - if ( $checkout->next_step->slug() != 'finalize_registration' && ! $checkout->revisit && isset( $deprecated_filters[ 'proceed_to' ] ) ) { |
|
116 | - $submit_button_text = apply_filters( 'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', $submit_button_text ) . $checkout->next_step->name(); |
|
115 | + if ($checkout->next_step->slug() != 'finalize_registration' && ! $checkout->revisit && isset($deprecated_filters['proceed_to'])) { |
|
116 | + $submit_button_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', $submit_button_text).$checkout->next_step->name(); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | return $submit_button_text; |
122 | 122 | |
123 | 123 | } |
124 | -add_filter( 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', 'ee_deprecated__registration_checkout__button_text', 10, 2 ); |
|
124 | +add_filter('FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', 'ee_deprecated__registration_checkout__button_text', 10, 2); |
|
125 | 125 | |
126 | 126 | |
127 | 127 | |
@@ -132,16 +132,16 @@ discard block |
||
132 | 132 | * @param \EE_Checkout $checkout |
133 | 133 | * @param boolean $status_updates |
134 | 134 | */ |
135 | -function ee_deprecated_finalize_transaction( EE_Checkout $checkout, $status_updates ) { |
|
135 | +function ee_deprecated_finalize_transaction(EE_Checkout $checkout, $status_updates) { |
|
136 | 136 | $action_ref = NULL; |
137 | - $action_ref = has_action( 'AHEE__EE_Transaction__finalize__new_transaction' ) ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref; |
|
138 | - $action_ref = has_action( 'AHEE__EE_Transaction__finalize__all_transaction' ) ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref; |
|
139 | - if ( $action_ref ) { |
|
137 | + $action_ref = has_action('AHEE__EE_Transaction__finalize__new_transaction') ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref; |
|
138 | + $action_ref = has_action('AHEE__EE_Transaction__finalize__all_transaction') ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref; |
|
139 | + if ($action_ref) { |
|
140 | 140 | |
141 | 141 | EE_Error::doing_it_wrong( |
142 | 142 | $action_ref, |
143 | 143 | sprintf( |
144 | - __( 'This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"', 'event_espresso' ), |
|
144 | + __('This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"', 'event_espresso'), |
|
145 | 145 | '<br />', |
146 | 146 | '/core/business/EE_Transaction_Processor.class.php', |
147 | 147 | 'AHEE__EE_Transaction_Processor__finalize', |
@@ -151,39 +151,39 @@ discard block |
||
151 | 151 | ), |
152 | 152 | '4.6.0' |
153 | 153 | ); |
154 | - switch ( $action_ref ) { |
|
154 | + switch ($action_ref) { |
|
155 | 155 | case 'AHEE__EE_Transaction__finalize__new_transaction' : |
156 | - do_action( 'AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, $checkout->admin_request ); |
|
156 | + do_action('AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, $checkout->admin_request); |
|
157 | 157 | break; |
158 | 158 | case 'AHEE__EE_Transaction__finalize__all_transaction' : |
159 | - do_action( 'AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, array( 'new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates ), $checkout->admin_request ); |
|
159 | + do_action('AHEE__EE_Transaction__finalize__new_transaction', $checkout->transaction, array('new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates), $checkout->admin_request); |
|
160 | 160 | break; |
161 | 161 | } |
162 | 162 | } |
163 | 163 | } |
164 | -add_action( 'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', 'ee_deprecated_finalize_transaction', 10, 2 ); |
|
164 | +add_action('AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed', 'ee_deprecated_finalize_transaction', 10, 2); |
|
165 | 165 | /** |
166 | 166 | * ee_deprecated_finalize_registration |
167 | 167 | * |
168 | 168 | * @param EE_Registration $registration |
169 | 169 | */ |
170 | -function ee_deprecated_finalize_registration( EE_Registration $registration ) { |
|
171 | - $action_ref = has_action( 'AHEE__EE_Registration__finalize__update_and_new_reg' ) ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : NULL; |
|
172 | - if ( $action_ref ) { |
|
170 | +function ee_deprecated_finalize_registration(EE_Registration $registration) { |
|
171 | + $action_ref = has_action('AHEE__EE_Registration__finalize__update_and_new_reg') ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : NULL; |
|
172 | + if ($action_ref) { |
|
173 | 173 | EE_Error::doing_it_wrong( |
174 | 174 | $action_ref, |
175 | 175 | sprintf( |
176 | - __( 'This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"', 'event_espresso' ), |
|
176 | + __('This action is deprecated. It *may* work as an attempt to build in backwards compatibility. However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"', 'event_espresso'), |
|
177 | 177 | '<br />', |
178 | 178 | '/core/business/EE_Registration_Processor.class.php', |
179 | 179 | 'AHEE__EE_Registration_Processor__trigger_registration_status_changed_hook' |
180 | 180 | ), |
181 | 181 | '4.6.0' |
182 | 182 | ); |
183 | - do_action( 'AHEE__EE_Registration__finalize__update_and_new_reg', $registration, ( is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ))); |
|
183 | + do_action('AHEE__EE_Registration__finalize__update_and_new_reg', $registration, (is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX))); |
|
184 | 184 | } |
185 | 185 | } |
186 | -add_action( 'AHEE__EE_Registration_Processor__trigger_registration_update_notifications', 'ee_deprecated_finalize_registration', 10, 1 ); |
|
186 | +add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', 'ee_deprecated_finalize_registration', 10, 1); |
|
187 | 187 | |
188 | 188 | |
189 | 189 | |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * Called after EED_Module::set_hooks() and EED_Module::set_admin_hooks() was called. |
192 | 192 | * Checks if any deprecated hooks were hooked-into and provide doing_it_wrong messages appropriately. |
193 | 193 | */ |
194 | -function ee_deprecated_hooks(){ |
|
194 | +function ee_deprecated_hooks() { |
|
195 | 195 | /** |
196 | 196 | * @var $hooks array where keys are hook names, and their values are array{ |
197 | 197 | * @type string $version when deprecated |
@@ -202,25 +202,25 @@ discard block |
||
202 | 202 | $hooks = array( |
203 | 203 | 'AHEE__EE_System___do_setup_validations' => array( |
204 | 204 | 'version' => '4.6.0', |
205 | - 'alternative' => __( 'Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)', 'event_espresso' ), |
|
205 | + 'alternative' => __('Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)', 'event_espresso'), |
|
206 | 206 | 'still_works' => FALSE |
207 | 207 | ) |
208 | 208 | ); |
209 | - foreach( $hooks as $name => $deprecation_info ){ |
|
210 | - if( has_action( $name ) ){ |
|
209 | + foreach ($hooks as $name => $deprecation_info) { |
|
210 | + if (has_action($name)) { |
|
211 | 211 | EE_Error::doing_it_wrong( |
212 | 212 | $name, |
213 | 213 | sprintf( |
214 | - __('This filter is deprecated. %1$s%2$s','event_espresso'), |
|
215 | - $deprecation_info[ 'still_works' ] ? __('It *may* work as an attempt to build in backwards compatibility.', 'event_espresso') : __( 'It has been completely removed.', 'event_espresso' ), |
|
216 | - isset( $deprecation_info[ 'alternative' ] ) ? $deprecation_info[ 'alternative' ] : __( 'Please read the current EE4 documentation further or contact Support.', 'event_espresso' ) |
|
214 | + __('This filter is deprecated. %1$s%2$s', 'event_espresso'), |
|
215 | + $deprecation_info['still_works'] ? __('It *may* work as an attempt to build in backwards compatibility.', 'event_espresso') : __('It has been completely removed.', 'event_espresso'), |
|
216 | + isset($deprecation_info['alternative']) ? $deprecation_info['alternative'] : __('Please read the current EE4 documentation further or contact Support.', 'event_espresso') |
|
217 | 217 | ), |
218 | - isset( $deprecation_info[ 'version' ] ) ? $deprecation_info[ 'version' ] : __( 'recently', 'event_espresso' ) |
|
218 | + isset($deprecation_info['version']) ? $deprecation_info['version'] : __('recently', 'event_espresso') |
|
219 | 219 | ); |
220 | 220 | } |
221 | 221 | } |
222 | 222 | } |
223 | -add_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', 'ee_deprecated_hooks' ); |
|
223 | +add_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', 'ee_deprecated_hooks'); |
|
224 | 224 | |
225 | 225 | |
226 | 226 | |
@@ -231,9 +231,9 @@ discard block |
||
231 | 231 | * @return boolean |
232 | 232 | */ |
233 | 233 | function ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() { |
234 | - $in_use = has_filter( 'FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns' ) |
|
235 | - || has_action( 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save' ); |
|
236 | - if( $in_use ) { |
|
234 | + $in_use = has_filter('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns') |
|
235 | + || has_action('AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save'); |
|
236 | + if ($in_use) { |
|
237 | 237 | $msg = __( |
238 | 238 | 'We detected you are using the filter FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns or AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save.' |
239 | 239 | . 'Both of these have been deprecated and should not be used anymore. You should instead use FHEE__EE_Form_Section_Proper___construct__options_array to customize the contents of the form,' |
@@ -242,18 +242,18 @@ discard block |
||
242 | 242 | 'event_espresso' ) |
243 | 243 | ; |
244 | 244 | EE_Error::doing_it_wrong( |
245 | - __CLASS__ . '::' . __FUNCTION__, |
|
245 | + __CLASS__.'::'.__FUNCTION__, |
|
246 | 246 | $msg, |
247 | 247 | '4.8.32.rc.000' |
248 | 248 | ); |
249 | 249 | //it seems the doing_it_wrong messages get output during some hidden html tags, so add an error to make sure this gets noticed |
250 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { |
|
251 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
250 | + if (is_admin() && ! defined('DOING_AJAX')) { |
|
251 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
252 | 252 | } |
253 | 253 | } |
254 | 254 | return $in_use; |
255 | 255 | } |
256 | -add_action( 'AHEE__Registrations_Admin_Page___registration_details_metabox__start', 'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks' ); |
|
256 | +add_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', 'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks'); |
|
257 | 257 | |
258 | 258 | /** |
259 | 259 | * @deprecated since 4.8.32.rc.000 because it has issues on https://events.codebasehq.com/projects/event-espresso/tickets/9165 |
@@ -262,34 +262,34 @@ discard block |
||
262 | 262 | * @param EE_Admin_Page $admin_page |
263 | 263 | * @return void |
264 | 264 | */ |
265 | -function ee_deprecated_update_attendee_registration_form_old( $admin_page ) { |
|
265 | +function ee_deprecated_update_attendee_registration_form_old($admin_page) { |
|
266 | 266 | //check if the old hooks are in use. If not, do the default |
267 | - if( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
268 | - || ! $admin_page instanceof EE_Admin_Page ) { |
|
267 | + if ( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
268 | + || ! $admin_page instanceof EE_Admin_Page) { |
|
269 | 269 | return; |
270 | 270 | } |
271 | 271 | $req_data = $admin_page->get_request_data(); |
272 | - $qstns = isset( $req_data['qstn'] ) ? $req_data['qstn'] : FALSE; |
|
273 | - $REG_ID = isset( $req_data['_REG_ID'] ) ? absint( $req_data['_REG_ID'] ) : FALSE; |
|
274 | - $qstns = apply_filters( 'FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns ); |
|
275 | - if ( ! $REG_ID || ! $qstns ) { |
|
276 | - EE_Error::add_error( __('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
272 | + $qstns = isset($req_data['qstn']) ? $req_data['qstn'] : FALSE; |
|
273 | + $REG_ID = isset($req_data['_REG_ID']) ? absint($req_data['_REG_ID']) : FALSE; |
|
274 | + $qstns = apply_filters('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns); |
|
275 | + if ( ! $REG_ID || ! $qstns) { |
|
276 | + EE_Error::add_error(__('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
277 | 277 | } |
278 | 278 | $success = TRUE; |
279 | 279 | |
280 | 280 | // allow others to get in on this awesome fun :D |
281 | - do_action( 'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save', $REG_ID, $qstns ); |
|
281 | + do_action('AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save', $REG_ID, $qstns); |
|
282 | 282 | // loop thru questions... FINALLY!!! |
283 | 283 | |
284 | - foreach ( $qstns as $QST_ID => $qstn ) { |
|
284 | + foreach ($qstns as $QST_ID => $qstn) { |
|
285 | 285 | //if $qstn isn't an array then it doesn't already have an answer, so let's create the answer |
286 | - if ( !is_array($qstn) ) { |
|
287 | - $success = $this->_save_new_answer( $REG_ID, $QST_ID, $qstn); |
|
286 | + if ( ! is_array($qstn)) { |
|
287 | + $success = $this->_save_new_answer($REG_ID, $QST_ID, $qstn); |
|
288 | 288 | continue; |
289 | 289 | } |
290 | 290 | |
291 | 291 | |
292 | - foreach ( $qstn as $ANS_ID => $ANS_value ) { |
|
292 | + foreach ($qstn as $ANS_ID => $ANS_value) { |
|
293 | 293 | //get answer |
294 | 294 | $query_params = array( |
295 | 295 | 0 => array( |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | ); |
301 | 301 | $answer = EEM_Answer::instance()->get_one($query_params); |
302 | 302 | //this MAY be an array but NOT have an answer because its multi select. If so then we need to create the answer |
303 | - if ( ! $answer instanceof EE_Answer ) { |
|
303 | + if ( ! $answer instanceof EE_Answer) { |
|
304 | 304 | $set_values = array( |
305 | 305 | 'QST_ID' => $QST_ID, |
306 | 306 | 'REG_ID' => $REG_ID, |
@@ -315,11 +315,11 @@ discard block |
||
315 | 315 | } |
316 | 316 | } |
317 | 317 | $what = __('Registration Form', 'event_espresso'); |
318 | - $route = $REG_ID ? array( 'action' => 'view_registration', '_REG_ID' => $REG_ID ) : array( 'action' => 'default' ); |
|
319 | - $admin_page->redirect_after_action( $success, $what, __('updated', 'event_espresso'), $route ); |
|
318 | + $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) : array('action' => 'default'); |
|
319 | + $admin_page->redirect_after_action($success, $what, __('updated', 'event_espresso'), $route); |
|
320 | 320 | exit; |
321 | 321 | } |
322 | -add_action( 'AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', 'ee_deprecated_update_attendee_registration_form_old', 10, 1 ); |
|
322 | +add_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', 'ee_deprecated_update_attendee_registration_form_old', 10, 1); |
|
323 | 323 | /** |
324 | 324 | * Render the registration admin page's custom questions area in the old fashion |
325 | 325 | * and firing the old hooks. When this method is removed, we can probably also |
@@ -332,31 +332,31 @@ discard block |
||
332 | 332 | * @return bool |
333 | 333 | * @throws \EE_Error |
334 | 334 | */ |
335 | -function ee_deprecated_reg_questions_meta_box_old( $do_default_action, $admin_page, $registration ) { |
|
335 | +function ee_deprecated_reg_questions_meta_box_old($do_default_action, $admin_page, $registration) { |
|
336 | 336 | //check if the old hooks are in use. If not, do the default |
337 | - if( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
338 | - || ! $admin_page instanceof EE_Admin_Page ) { |
|
337 | + if ( ! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks() |
|
338 | + || ! $admin_page instanceof EE_Admin_Page) { |
|
339 | 339 | return $do_default_action; |
340 | 340 | } |
341 | - add_filter( 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', array( $admin_page, 'form_before_question_group' ), 10, 1 ); |
|
342 | - add_filter( 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', array( $admin_page, 'form_after_question_group' ), 10, 1 ); |
|
343 | - add_filter( 'FHEE__EEH_Form_Fields__label_html', array( $admin_page, 'form_form_field_label_wrap' ), 10, 1 ); |
|
344 | - add_filter( 'FHEE__EEH_Form_Fields__input_html', array( $admin_page, 'form_form_field_input__wrap' ), 10, 1 ); |
|
341 | + add_filter('FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', array($admin_page, 'form_before_question_group'), 10, 1); |
|
342 | + add_filter('FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', array($admin_page, 'form_after_question_group'), 10, 1); |
|
343 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($admin_page, 'form_form_field_label_wrap'), 10, 1); |
|
344 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($admin_page, 'form_form_field_input__wrap'), 10, 1); |
|
345 | 345 | |
346 | - $question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options( $registration, $registration->get('EVT_ID') ); |
|
346 | + $question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options($registration, $registration->get('EVT_ID')); |
|
347 | 347 | |
348 | - EE_Registry::instance()->load_helper( 'Form_Fields' ); |
|
348 | + EE_Registry::instance()->load_helper('Form_Fields'); |
|
349 | 349 | $template_args = array( |
350 | - 'att_questions' => EEH_Form_Fields::generate_question_groups_html( $question_groups ), |
|
350 | + 'att_questions' => EEH_Form_Fields::generate_question_groups_html($question_groups), |
|
351 | 351 | 'reg_questions_form_action' => 'edit_registration', |
352 | 352 | 'REG_ID' => $registration->ID() |
353 | 353 | ); |
354 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
355 | - echo EEH_Template::display_template( $template_path, $template_args, TRUE ); |
|
354 | + $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
355 | + echo EEH_Template::display_template($template_path, $template_args, TRUE); |
|
356 | 356 | //indicate that we should not do the default admin page code |
357 | 357 | return false; |
358 | 358 | } |
359 | -add_action( 'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', 'ee_deprecated_reg_questions_meta_box_old', 10, 3 ); |
|
359 | +add_action('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', 'ee_deprecated_reg_questions_meta_box_old', 10, 3); |
|
360 | 360 | |
361 | 361 | |
362 | 362 | |
@@ -397,9 +397,9 @@ discard block |
||
397 | 397 | '4.9.0' |
398 | 398 | ); |
399 | 399 | /** @var EE_Message_Resource_Manager $message_resource_manager */ |
400 | - $message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
401 | - $messenger = $message_resource_manager->get_messenger( $messenger_name ); |
|
402 | - $message_type = $message_resource_manager->get_message_type( $message_type_name ); |
|
400 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
401 | + $messenger = $message_resource_manager->get_messenger($messenger_name); |
|
402 | + $message_type = $message_resource_manager->get_message_type($message_type_name); |
|
403 | 403 | return EE_Registry::instance()->load_lib( |
404 | 404 | 'Messages_Template_Defaults', |
405 | 405 | array( |
@@ -464,15 +464,15 @@ discard block |
||
464 | 464 | /** |
465 | 465 | * @param string $method |
466 | 466 | */ |
467 | - public function _class_is_deprecated( $method ) { |
|
467 | + public function _class_is_deprecated($method) { |
|
468 | 468 | EE_Error::doing_it_wrong( |
469 | - 'EE_messages::' . $method, |
|
470 | - __( 'EE_messages has been deprecated. Please use EE_Message_Resource_Manager instead.' ), |
|
469 | + 'EE_messages::'.$method, |
|
470 | + __('EE_messages has been deprecated. Please use EE_Message_Resource_Manager instead.'), |
|
471 | 471 | '4.9.0', |
472 | 472 | '4.10.0.p' |
473 | 473 | ); |
474 | 474 | // Please use EE_Message_Resource_Manager instead |
475 | - $this->_message_resource_manager = EE_Registry::instance()->load_lib( 'Message_Resource_Manager' ); |
|
475 | + $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | |
@@ -482,10 +482,10 @@ discard block |
||
482 | 482 | * @param string $messenger_name |
483 | 483 | * @return boolean TRUE if it was PREVIOUSLY active, and FALSE if it was previously inactive |
484 | 484 | */ |
485 | - public function ensure_messenger_is_active( $messenger_name ) { |
|
485 | + public function ensure_messenger_is_active($messenger_name) { |
|
486 | 486 | // EE_messages has been deprecated |
487 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
488 | - return $this->_message_resource_manager->ensure_messenger_is_active( $messenger_name ); |
|
487 | + $this->_class_is_deprecated(__FUNCTION__); |
|
488 | + return $this->_message_resource_manager->ensure_messenger_is_active($messenger_name); |
|
489 | 489 | } |
490 | 490 | |
491 | 491 | |
@@ -497,10 +497,10 @@ discard block |
||
497 | 497 | * @return bool true if it got activated (or was active) and false if not. |
498 | 498 | * @throws \EE_Error |
499 | 499 | */ |
500 | - public function ensure_message_type_is_active( $message_type, $messenger ) { |
|
500 | + public function ensure_message_type_is_active($message_type, $messenger) { |
|
501 | 501 | // EE_messages has been deprecated |
502 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
503 | - return $this->_message_resource_manager->ensure_message_type_is_active( $message_type, $messenger ); |
|
502 | + $this->_class_is_deprecated(__FUNCTION__); |
|
503 | + return $this->_message_resource_manager->ensure_message_type_is_active($message_type, $messenger); |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | |
@@ -513,10 +513,10 @@ discard block |
||
513 | 513 | * they are already setup.) |
514 | 514 | * @return boolean an array of generated templates or false if nothing generated/activated. |
515 | 515 | */ |
516 | - public function activate_messenger( $messenger_name, $mts_to_activate = array() ) { |
|
516 | + public function activate_messenger($messenger_name, $mts_to_activate = array()) { |
|
517 | 517 | // EE_messages has been deprecated |
518 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
519 | - return $this->_message_resource_manager->activate_messenger( $messenger_name, $mts_to_activate ); |
|
518 | + $this->_class_is_deprecated(__FUNCTION__); |
|
519 | + return $this->_message_resource_manager->activate_messenger($messenger_name, $mts_to_activate); |
|
520 | 520 | } |
521 | 521 | |
522 | 522 | |
@@ -528,10 +528,10 @@ discard block |
||
528 | 528 | * |
529 | 529 | * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send. |
530 | 530 | */ |
531 | - public function is_generating_messenger_and_active( EE_messenger $messenger, EE_message_type $message_type ) { |
|
531 | + public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type) { |
|
532 | 532 | // EE_messages has been deprecated |
533 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
534 | - return $this->_message_resource_manager->is_generating_messenger_and_active( $messenger, $message_type ); |
|
533 | + $this->_class_is_deprecated(__FUNCTION__); |
|
534 | + return $this->_message_resource_manager->is_generating_messenger_and_active($messenger, $message_type); |
|
535 | 535 | } |
536 | 536 | |
537 | 537 | |
@@ -541,10 +541,10 @@ discard block |
||
541 | 541 | * @param string $messenger |
542 | 542 | * @return EE_messenger | null |
543 | 543 | */ |
544 | - public function get_messenger_if_active( $messenger ) { |
|
544 | + public function get_messenger_if_active($messenger) { |
|
545 | 545 | // EE_messages has been deprecated |
546 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
547 | - return $this->_message_resource_manager->get_active_messenger( $messenger ); |
|
546 | + $this->_class_is_deprecated(__FUNCTION__); |
|
547 | + return $this->_message_resource_manager->get_active_messenger($messenger); |
|
548 | 548 | } |
549 | 549 | |
550 | 550 | |
@@ -565,9 +565,9 @@ discard block |
||
565 | 565 | * 'message_type' => null |
566 | 566 | * ) |
567 | 567 | */ |
568 | - public function validate_for_use( EE_Message $message ) { |
|
568 | + public function validate_for_use(EE_Message $message) { |
|
569 | 569 | // EE_messages has been deprecated |
570 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
570 | + $this->_class_is_deprecated(__FUNCTION__); |
|
571 | 571 | return array( |
572 | 572 | 'messenger' => $message->messenger_object(), |
573 | 573 | 'message_type' => $message->message_type_object(), |
@@ -595,41 +595,41 @@ discard block |
||
595 | 595 | $send = true |
596 | 596 | ) { |
597 | 597 | // EE_messages has been deprecated |
598 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
598 | + $this->_class_is_deprecated(__FUNCTION__); |
|
599 | 599 | /** @type EE_Messages_Processor $processor */ |
600 | - $processor = EE_Registry::instance()->load_lib( 'Messages_Processor' ); |
|
600 | + $processor = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
601 | 601 | $error = false; |
602 | 602 | //try to intelligently determine what method we'll call based on the incoming data. |
603 | 603 | //if generating and sending are different then generate and send immediately. |
604 | - if ( ! empty( $sending_messenger ) && $sending_messenger != $generating_messenger && $send ) { |
|
604 | + if ( ! empty($sending_messenger) && $sending_messenger != $generating_messenger && $send) { |
|
605 | 605 | //in the legacy system, when generating and sending were different, that means all the |
606 | 606 | //vars are already in the request object. So let's just use that. |
607 | 607 | try { |
608 | 608 | /** @type EE_Message_To_Generate_From_Request $mtg */ |
609 | - $mtg = EE_Registry::instance()->load_lib( 'Message_To_Generate_From_Request' ); |
|
610 | - $processor->generate_and_send_now( $mtg ); |
|
611 | - } catch ( EE_Error $e ) { |
|
609 | + $mtg = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
610 | + $processor->generate_and_send_now($mtg); |
|
611 | + } catch (EE_Error $e) { |
|
612 | 612 | $error_msg = __( |
613 | 613 | 'Please note that a system message failed to send due to a technical issue.', |
614 | 614 | 'event_espresso' |
615 | 615 | ); |
616 | 616 | // add specific message for developers if WP_DEBUG in on |
617 | - $error_msg .= '||' . $e->getMessage(); |
|
618 | - EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
617 | + $error_msg .= '||'.$e->getMessage(); |
|
618 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
619 | 619 | $error = true; |
620 | 620 | } |
621 | 621 | } else { |
622 | - $processor->generate_for_all_active_messengers( $type, $vars, $send ); |
|
622 | + $processor->generate_for_all_active_messengers($type, $vars, $send); |
|
623 | 623 | //let's find out if there were any errors and how many successfully were queued. |
624 | 624 | $count_errors = $processor->get_queue()->count_STS_in_queue( |
625 | - array( EEM_Message::status_failed, EEM_Message::status_debug_only ) |
|
625 | + array(EEM_Message::status_failed, EEM_Message::status_debug_only) |
|
626 | 626 | ); |
627 | - $count_queued = $processor->get_queue()->count_STS_in_queue( EEM_Message::status_incomplete ); |
|
628 | - $count_retry = $processor->get_queue()->count_STS_in_queue( EEM_Message::status_retry ); |
|
627 | + $count_queued = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_incomplete); |
|
628 | + $count_retry = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_retry); |
|
629 | 629 | $count_errors = $count_errors + $count_retry; |
630 | - if ( $count_errors > 0 ) { |
|
630 | + if ($count_errors > 0) { |
|
631 | 631 | $error = true; |
632 | - if ( $count_errors > 1 && $count_retry > 1 && $count_queued > 1 ) { |
|
632 | + if ($count_errors > 1 && $count_retry > 1 && $count_queued > 1) { |
|
633 | 633 | $message = sprintf( |
634 | 634 | __( |
635 | 635 | 'There were %d errors and %d messages successfully queued for generation and sending', |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | $count_errors, |
639 | 639 | $count_queued |
640 | 640 | ); |
641 | - } elseif ( $count_errors > 1 && $count_queued === 1 ) { |
|
641 | + } elseif ($count_errors > 1 && $count_queued === 1) { |
|
642 | 642 | $message = sprintf( |
643 | 643 | __( |
644 | 644 | 'There were %d errors and %d message successfully queued for generation.', |
@@ -647,7 +647,7 @@ discard block |
||
647 | 647 | $count_errors, |
648 | 648 | $count_queued |
649 | 649 | ); |
650 | - } elseif ( $count_errors === 1 && $count_queued > 1 ) { |
|
650 | + } elseif ($count_errors === 1 && $count_queued > 1) { |
|
651 | 651 | $message = sprintf( |
652 | 652 | __( |
653 | 653 | 'There was %d error and %d messages successfully queued for generation.', |
@@ -665,9 +665,9 @@ discard block |
||
665 | 665 | $count_errors |
666 | 666 | ); |
667 | 667 | } |
668 | - EE_Error::add_error( $message, __FILE__, __FUNCTION__, __LINE__ ); |
|
668 | + EE_Error::add_error($message, __FILE__, __FUNCTION__, __LINE__); |
|
669 | 669 | } else { |
670 | - if ( $count_queued === 1 ) { |
|
670 | + if ($count_queued === 1) { |
|
671 | 671 | $message = sprintf( |
672 | 672 | __( |
673 | 673 | '%d message successfully queued for generation.', |
@@ -684,18 +684,18 @@ discard block |
||
684 | 684 | $count_queued |
685 | 685 | ); |
686 | 686 | } |
687 | - EE_Error::add_success( $message ); |
|
687 | + EE_Error::add_success($message); |
|
688 | 688 | } |
689 | 689 | } |
690 | 690 | //if no error then return the generated message(s). |
691 | - if ( ! $error && ! $send ) { |
|
692 | - $generated_queue = $processor->generate_queue( false ); |
|
691 | + if ( ! $error && ! $send) { |
|
692 | + $generated_queue = $processor->generate_queue(false); |
|
693 | 693 | //get message and return. |
694 | 694 | $generated_queue->get_message_repository()->rewind(); |
695 | 695 | $messages = array(); |
696 | - while ( $generated_queue->get_message_repository()->valid() ) { |
|
696 | + while ($generated_queue->get_message_repository()->valid()) { |
|
697 | 697 | $message = $generated_queue->get_message_repository()->current(); |
698 | - if ( $message instanceof EE_Message ) { |
|
698 | + if ($message instanceof EE_Message) { |
|
699 | 699 | //set properties that might be expected by add-ons (backward compat) |
700 | 700 | $message->content = $message->content(); |
701 | 701 | $message->template_pack = $message->get_template_pack(); |
@@ -720,10 +720,10 @@ discard block |
||
720 | 720 | * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular preview |
721 | 721 | * @return string The body of the message. |
722 | 722 | */ |
723 | - public function preview_message( $type, $context, $messenger, $send = false ) { |
|
723 | + public function preview_message($type, $context, $messenger, $send = false) { |
|
724 | 724 | // EE_messages has been deprecated |
725 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
726 | - return EED_Messages::preview_message( $type, $context, $messenger, $send ); |
|
725 | + $this->_class_is_deprecated(__FUNCTION__); |
|
726 | + return EED_Messages::preview_message($type, $context, $messenger, $send); |
|
727 | 727 | } |
728 | 728 | |
729 | 729 | |
@@ -737,14 +737,14 @@ discard block |
||
737 | 737 | * |
738 | 738 | * @return bool success or fail. |
739 | 739 | */ |
740 | - public function send_message_with_messenger_only( $messenger, $message_type, $message ) { |
|
740 | + public function send_message_with_messenger_only($messenger, $message_type, $message) { |
|
741 | 741 | // EE_messages has been deprecated |
742 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
742 | + $this->_class_is_deprecated(__FUNCTION__); |
|
743 | 743 | //setup for sending to new method. |
744 | 744 | /** @type EE_Messages_Queue $queue */ |
745 | - $queue = EE_Registry::instance()->load_lib( 'Messages_Queue' ); |
|
745 | + $queue = EE_Registry::instance()->load_lib('Messages_Queue'); |
|
746 | 746 | //make sure we have a proper message object |
747 | - if ( ! $message instanceof EE_Message && is_object( $message ) && isset( $message->content ) ) { |
|
747 | + if ( ! $message instanceof EE_Message && is_object($message) && isset($message->content)) { |
|
748 | 748 | $msg = EE_Message_Factory::create( |
749 | 749 | array( |
750 | 750 | 'MSG_messenger' => $messenger, |
@@ -756,15 +756,15 @@ discard block |
||
756 | 756 | } else { |
757 | 757 | $msg = $message; |
758 | 758 | } |
759 | - if ( ! $msg instanceof EE_Message ) { |
|
759 | + if ( ! $msg instanceof EE_Message) { |
|
760 | 760 | return false; |
761 | 761 | } |
762 | 762 | //make sure any content in a content property (if not empty) is set on the MSG_content. |
763 | - if ( ! empty( $msg->content ) ) { |
|
764 | - $msg->set( 'MSG_content', $msg->content ); |
|
763 | + if ( ! empty($msg->content)) { |
|
764 | + $msg->set('MSG_content', $msg->content); |
|
765 | 765 | } |
766 | - $queue->add( $msg ); |
|
767 | - return EED_Messages::send_message_with_messenger_only( $messenger, $message_type, $queue ); |
|
766 | + $queue->add($msg); |
|
767 | + return EED_Messages::send_message_with_messenger_only($messenger, $message_type, $queue); |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | |
@@ -778,11 +778,11 @@ discard block |
||
778 | 778 | * @return array|object if creation is successful then we return an array of info, otherwise an error_object is returned. |
779 | 779 | * @throws \EE_Error |
780 | 780 | */ |
781 | - public function create_new_templates( $messenger, $message_type, $GRP_ID = 0, $is_global = false ) { |
|
781 | + public function create_new_templates($messenger, $message_type, $GRP_ID = 0, $is_global = false) { |
|
782 | 782 | // EE_messages has been deprecated |
783 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
784 | - EE_Registry::instance()->load_helper( 'MSG_Template' ); |
|
785 | - return EEH_MSG_Template::create_new_templates( $messenger, $message_type, $GRP_ID, $is_global ); |
|
783 | + $this->_class_is_deprecated(__FUNCTION__); |
|
784 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
785 | + return EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $is_global); |
|
786 | 786 | } |
787 | 787 | |
788 | 788 | |
@@ -793,11 +793,11 @@ discard block |
||
793 | 793 | * @param string $message_type_name name of EE_message_type |
794 | 794 | * @return array |
795 | 795 | */ |
796 | - public function get_fields( $messenger_name, $message_type_name ) { |
|
796 | + public function get_fields($messenger_name, $message_type_name) { |
|
797 | 797 | // EE_messages has been deprecated |
798 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
799 | - EE_Registry::instance()->load_helper( 'MSG_Template' ); |
|
800 | - return EEH_MSG_Template::get_fields( $messenger_name, $message_type_name ); |
|
798 | + $this->_class_is_deprecated(__FUNCTION__); |
|
799 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
800 | + return EEH_MSG_Template::get_fields($messenger_name, $message_type_name); |
|
801 | 801 | } |
802 | 802 | |
803 | 803 | |
@@ -811,13 +811,13 @@ discard block |
||
811 | 811 | * @return array multidimensional array of messenger and message_type objects |
812 | 812 | * (messengers index, and message_type index); |
813 | 813 | */ |
814 | - public function get_installed( $type = 'all', $skip_cache = false ) { |
|
814 | + public function get_installed($type = 'all', $skip_cache = false) { |
|
815 | 815 | // EE_messages has been deprecated |
816 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
817 | - if ( $skip_cache ) { |
|
816 | + $this->_class_is_deprecated(__FUNCTION__); |
|
817 | + if ($skip_cache) { |
|
818 | 818 | $this->_message_resource_manager->reset_active_messengers_and_message_types(); |
819 | 819 | } |
820 | - switch ( $type ) { |
|
820 | + switch ($type) { |
|
821 | 821 | case 'messengers' : |
822 | 822 | return array( |
823 | 823 | 'messenger' => $this->_message_resource_manager->installed_messengers(), |
@@ -846,7 +846,7 @@ discard block |
||
846 | 846 | */ |
847 | 847 | public function get_active_messengers() { |
848 | 848 | // EE_messages has been deprecated |
849 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
849 | + $this->_class_is_deprecated(__FUNCTION__); |
|
850 | 850 | return $this->_message_resource_manager->active_messengers(); |
851 | 851 | } |
852 | 852 | |
@@ -858,7 +858,7 @@ discard block |
||
858 | 858 | */ |
859 | 859 | public function get_active_message_types() { |
860 | 860 | // EE_messages has been deprecated |
861 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
861 | + $this->_class_is_deprecated(__FUNCTION__); |
|
862 | 862 | return $this->_message_resource_manager->list_of_active_message_types(); |
863 | 863 | } |
864 | 864 | |
@@ -870,7 +870,7 @@ discard block |
||
870 | 870 | */ |
871 | 871 | public function get_active_message_type_objects() { |
872 | 872 | // EE_messages has been deprecated |
873 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
873 | + $this->_class_is_deprecated(__FUNCTION__); |
|
874 | 874 | return $this->_message_resource_manager->get_active_message_type_objects(); |
875 | 875 | } |
876 | 876 | |
@@ -882,10 +882,10 @@ discard block |
||
882 | 882 | * @param string $messenger The messenger being checked |
883 | 883 | * @return EE_message_type[] (or empty array if none present) |
884 | 884 | */ |
885 | - public function get_active_message_types_per_messenger( $messenger ) { |
|
885 | + public function get_active_message_types_per_messenger($messenger) { |
|
886 | 886 | // EE_messages has been deprecated |
887 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
888 | - return $this->_message_resource_manager->get_active_message_types_for_messenger( $messenger ); |
|
887 | + $this->_class_is_deprecated(__FUNCTION__); |
|
888 | + return $this->_message_resource_manager->get_active_message_types_for_messenger($messenger); |
|
889 | 889 | } |
890 | 890 | |
891 | 891 | |
@@ -896,10 +896,10 @@ discard block |
||
896 | 896 | * @param string $message_type The string should correspond to a message type. |
897 | 897 | * @return EE_message_type|null |
898 | 898 | */ |
899 | - public function get_active_message_type( $messenger, $message_type ) { |
|
899 | + public function get_active_message_type($messenger, $message_type) { |
|
900 | 900 | // EE_messages has been deprecated |
901 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
902 | - return $this->_message_resource_manager->get_active_message_type_for_messenger( $messenger, $message_type ); |
|
901 | + $this->_class_is_deprecated(__FUNCTION__); |
|
902 | + return $this->_message_resource_manager->get_active_message_type_for_messenger($messenger, $message_type); |
|
903 | 903 | } |
904 | 904 | |
905 | 905 | |
@@ -910,7 +910,7 @@ discard block |
||
910 | 910 | */ |
911 | 911 | public function get_installed_message_types() { |
912 | 912 | // EE_messages has been deprecated |
913 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
913 | + $this->_class_is_deprecated(__FUNCTION__); |
|
914 | 914 | return $this->_message_resource_manager->installed_message_types(); |
915 | 915 | } |
916 | 916 | |
@@ -922,7 +922,7 @@ discard block |
||
922 | 922 | */ |
923 | 923 | public function get_installed_messengers() { |
924 | 924 | // EE_messages has been deprecated |
925 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
925 | + $this->_class_is_deprecated(__FUNCTION__); |
|
926 | 926 | return $this->_message_resource_manager->installed_messengers(); |
927 | 927 | } |
928 | 928 | |
@@ -933,10 +933,10 @@ discard block |
||
933 | 933 | * @param bool $slugs_only Whether to return an array of just slugs and labels (true) or all contexts indexed by message type. |
934 | 934 | * @return array |
935 | 935 | */ |
936 | - public function get_all_contexts( $slugs_only = true ) { |
|
936 | + public function get_all_contexts($slugs_only = true) { |
|
937 | 937 | // EE_messages has been deprecated |
938 | - $this->_class_is_deprecated( __FUNCTION__ ); |
|
939 | - return $this->_message_resource_manager->get_all_contexts( $slugs_only ); |
|
938 | + $this->_class_is_deprecated(__FUNCTION__); |
|
939 | + return $this->_message_resource_manager->get_all_contexts($slugs_only); |
|
940 | 940 | } |
941 | 941 | |
942 | 942 | |
@@ -1002,15 +1002,15 @@ discard block |
||
1002 | 1002 | '4.9.22.p' |
1003 | 1003 | ); |
1004 | 1004 | } |
1005 | - do_action( 'AHEE__EE_Brewing_Regular__construct__complete' ); |
|
1005 | + do_action('AHEE__EE_Brewing_Regular__construct__complete'); |
|
1006 | 1006 | } |
1007 | -add_action( 'AHEE__EE_System__load_core_configuration__complete', 'ee_deprecate_AHEE__EE_Brewing_Regular__construct__complete' ); |
|
1007 | +add_action('AHEE__EE_System__load_core_configuration__complete', 'ee_deprecate_AHEE__EE_Brewing_Regular__construct__complete'); |
|
1008 | 1008 | |
1009 | 1009 | |
1010 | 1010 | add_filter( |
1011 | 1011 | 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css', |
1012 | 1012 | function($event_list_iframe_css) { |
1013 | - if ( ! has_filter( 'FHEE__EventsArchiveIframe__event_list_iframe__css' )) { |
|
1013 | + if ( ! has_filter('FHEE__EventsArchiveIframe__event_list_iframe__css')) { |
|
1014 | 1014 | return $event_list_iframe_css; |
1015 | 1015 | } |
1016 | 1016 | deprecated_espresso_action_or_filter_doing_it_wrong( |
@@ -1030,7 +1030,7 @@ discard block |
||
1030 | 1030 | add_filter( |
1031 | 1031 | 'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js', |
1032 | 1032 | function($event_list_iframe_js) { |
1033 | - if ( ! has_filter( 'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js' )) { |
|
1033 | + if ( ! has_filter('FHEE__EED_Ticket_Selector__ticket_selector_iframe__js')) { |
|
1034 | 1034 | return $event_list_iframe_js; |
1035 | 1035 | } |
1036 | 1036 | deprecated_espresso_action_or_filter_doing_it_wrong( |
@@ -47,30 +47,30 @@ discard block |
||
47 | 47 | * @throws EE_Error |
48 | 48 | * @return void |
49 | 49 | */ |
50 | - public static function register( $cap_reference = NULL, $setup_args = array() ) { |
|
50 | + public static function register($cap_reference = NULL, $setup_args = array()) { |
|
51 | 51 | //required fields MUST be present, so let's make sure they are. |
52 | - if ( ! isset( $cap_reference ) || ! is_array( $setup_args ) || empty( $setup_args['capabilities'] ) ) { |
|
52 | + if ( ! isset($cap_reference) || ! is_array($setup_args) || empty($setup_args['capabilities'])) { |
|
53 | 53 | throw new EE_Error( |
54 | - __( 'In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', 'event_espresso' ) |
|
54 | + __('In order to register capabilities with EE_Register_Capabilities::register, you must include a unique name to reference the capabilities being registered, plus an array containing the following keys: "capabilities".', 'event_espresso') |
|
55 | 55 | ); |
56 | 56 | } |
57 | 57 | //make sure we don't register twice |
58 | - if( isset( self::$_registry[ $cap_reference ] ) ){ |
|
58 | + if (isset(self::$_registry[$cap_reference])) { |
|
59 | 59 | return; |
60 | 60 | } |
61 | 61 | //make sure this is not registered too late or too early. |
62 | - if ( ! did_action( 'AHEE__EE_System__load_espresso_addons' ) || did_action( 'AHEE__EE_System___detect_if_activation_or_upgrade__begin' ) ) { |
|
63 | - EE_Error::doing_it_wrong( __METHOD__, sprintf( __('%s has been registered too late. Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', 'event_espresso'), $cap_reference ), '4.5.0' ); |
|
62 | + if ( ! did_action('AHEE__EE_System__load_espresso_addons') || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')) { |
|
63 | + EE_Error::doing_it_wrong(__METHOD__, sprintf(__('%s has been registered too late. Please ensure that EE_Register_Capabilities::register has been called at some point before the "AHEE__EE_System___detect_if_activation_or_upgrade__begin" action hook has been called.', 'event_espresso'), $cap_reference), '4.5.0'); |
|
64 | 64 | } |
65 | 65 | //some preliminary sanitization and setting to the $_registry property |
66 | 66 | self::$_registry[$cap_reference] = array( |
67 | - 'caps' => isset( $setup_args['capabilities'] ) && is_array( $setup_args['capabilities'] ) ? $setup_args['capabilities'] : array(), |
|
68 | - 'cap_maps' => isset( $setup_args['capability_maps'] ) ? $setup_args['capability_maps'] : array() |
|
67 | + 'caps' => isset($setup_args['capabilities']) && is_array($setup_args['capabilities']) ? $setup_args['capabilities'] : array(), |
|
68 | + 'cap_maps' => isset($setup_args['capability_maps']) ? $setup_args['capability_maps'] : array() |
|
69 | 69 | ); |
70 | 70 | //set initial caps (note that EE_Capabilities takes care of making sure that the caps get added only once) |
71 | - add_filter( 'FHEE__EE_Capabilities__init_caps_map__caps', array( 'EE_Register_Capabilities', 'register_capabilities' ), 10 ); |
|
71 | + add_filter('FHEE__EE_Capabilities__init_caps_map__caps', array('EE_Register_Capabilities', 'register_capabilities'), 10); |
|
72 | 72 | //add filter for cap maps |
73 | - add_filter( 'FHEE__EE_Capabilities___set_meta_caps__meta_caps', array( 'EE_Register_Capabilities', 'register_cap_maps' ), 10 ); |
|
73 | + add_filter('FHEE__EE_Capabilities___set_meta_caps__meta_caps', array('EE_Register_Capabilities', 'register_cap_maps'), 10); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | * |
84 | 84 | * @return array merged in new caps. |
85 | 85 | */ |
86 | - public static function register_capabilities( $incoming_caps ) { |
|
87 | - foreach ( self::$_registry as $ref => $caps_and_cap_map ) { |
|
88 | - $incoming_caps = array_merge_recursive( $incoming_caps, $caps_and_cap_map[ 'caps' ] ); |
|
86 | + public static function register_capabilities($incoming_caps) { |
|
87 | + foreach (self::$_registry as $ref => $caps_and_cap_map) { |
|
88 | + $incoming_caps = array_merge_recursive($incoming_caps, $caps_and_cap_map['caps']); |
|
89 | 89 | } |
90 | 90 | return $incoming_caps; |
91 | 91 | } |
@@ -100,13 +100,13 @@ discard block |
||
100 | 100 | * @return EE_Meta_Capability_Map[] |
101 | 101 | * @throws EE_Error |
102 | 102 | */ |
103 | - public static function register_cap_maps( $cap_maps ) { |
|
103 | + public static function register_cap_maps($cap_maps) { |
|
104 | 104 | //loop through and instantiate cap maps. |
105 | - foreach ( self::$_registry as $cap_reference => $setup ) { |
|
106 | - if ( ! isset( $setup['cap_maps'] ) ) { |
|
105 | + foreach (self::$_registry as $cap_reference => $setup) { |
|
106 | + if ( ! isset($setup['cap_maps'])) { |
|
107 | 107 | continue; |
108 | 108 | } |
109 | - foreach ( $setup['cap_maps'] as $cap_class => $args ) { |
|
109 | + foreach ($setup['cap_maps'] as $cap_class => $args) { |
|
110 | 110 | |
111 | 111 | /** |
112 | 112 | * account for cases where capability maps may be indexed |
@@ -133,19 +133,19 @@ discard block |
||
133 | 133 | * ... |
134 | 134 | * ) |
135 | 135 | */ |
136 | - if ( is_numeric( $cap_class ) ) { |
|
137 | - $cap_class = key( $args ); |
|
136 | + if (is_numeric($cap_class)) { |
|
137 | + $cap_class = key($args); |
|
138 | 138 | $args = $args[$cap_class]; |
139 | 139 | } |
140 | 140 | |
141 | - if ( ! class_exists( $cap_class ) ) { |
|
142 | - throw new EE_Error( sprintf( __( 'An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments', 'event_espresso' ), $cap_reference ) ); |
|
141 | + if ( ! class_exists($cap_class)) { |
|
142 | + throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments', 'event_espresso'), $cap_reference)); |
|
143 | 143 | } |
144 | 144 | |
145 | - if ( count( $args ) !== 2 ) { |
|
146 | - throw new EE_Error( sprintf( __('An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments. The array should have two values the first being a string and the second an array.', 'event_espresso' ), $cap_reference ) ); |
|
145 | + if (count($args) !== 2) { |
|
146 | + throw new EE_Error(sprintf(__('An addon (%s) has tried to register a capability map improperly. Capability map arrays must be indexed by capability map classname, and an array for the class arguments. The array should have two values the first being a string and the second an array.', 'event_espresso'), $cap_reference)); |
|
147 | 147 | } |
148 | - $cap_maps[] = new $cap_class( $args[0], $args[1] ); |
|
148 | + $cap_maps[] = new $cap_class($args[0], $args[1]); |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | return $cap_maps; |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | |
155 | 155 | |
156 | 156 | |
157 | - public static function deregister( $cap_reference = NULL ) { |
|
158 | - if ( !empty( self::$_registry[$cap_reference] ) ) { |
|
159 | - unset( self::$_registry[ $cap_reference ] ); |
|
157 | + public static function deregister($cap_reference = NULL) { |
|
158 | + if ( ! empty(self::$_registry[$cap_reference])) { |
|
159 | + unset(self::$_registry[$cap_reference]); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | //re init caps to grab the changes due to removed caps. |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('No direct script access allowed'); |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -25,591 +25,591 @@ discard block |
||
25 | 25 | class EEG_Paypal_Pro extends EE_Onsite_Gateway |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * @var $_paypal_api_username string |
|
30 | - */ |
|
31 | - protected $_username = null; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var $_password string |
|
35 | - */ |
|
36 | - protected $_password = null; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var $_signature string |
|
40 | - */ |
|
41 | - protected $_signature = null; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var $_credit_card_types array with the keys for credit card types accepted on this account |
|
45 | - */ |
|
46 | - protected $_credit_card_types = null; |
|
47 | - |
|
48 | - protected $_currencies_supported = array( |
|
49 | - 'USD', |
|
50 | - 'GBP', |
|
51 | - 'CAD', |
|
52 | - 'AUD', |
|
53 | - 'BRL', |
|
54 | - 'CHF', |
|
55 | - 'CZK', |
|
56 | - 'DKK', |
|
57 | - 'EUR', |
|
58 | - 'HKD', |
|
59 | - 'HUF', |
|
60 | - 'ILS', |
|
61 | - 'JPY', |
|
62 | - 'MXN', |
|
63 | - 'MYR', |
|
64 | - 'NOK', |
|
65 | - 'NZD', |
|
66 | - 'PHP', |
|
67 | - 'PLN', |
|
68 | - 'SEK', |
|
69 | - 'SGD', |
|
70 | - 'THB', |
|
71 | - 'TRY', |
|
72 | - 'TWD', |
|
73 | - 'RUB', |
|
74 | - ); |
|
75 | - |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * @param EEI_Payment $payment |
|
80 | - * @param array $billing_info { |
|
81 | - * @type string $credit_card |
|
82 | - * @type string $credit_card_type |
|
83 | - * @type string $exp_month always 2 characters |
|
84 | - * @type string $exp_year always 4 characters |
|
85 | - * @type string $cvv |
|
86 | - * } |
|
87 | - * @see parent::do_direct_payment for more info |
|
88 | - * @return EE_Payment|EEI_Payment |
|
89 | - * @throws EE_Error |
|
90 | - */ |
|
91 | - public function do_direct_payment($payment, $billing_info = null) |
|
92 | - { |
|
93 | - $transaction = $payment->transaction(); |
|
94 | - if (! $transaction instanceof EEI_Transaction) { |
|
95 | - throw new EE_Error( |
|
96 | - esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso') |
|
97 | - ); |
|
98 | - } |
|
99 | - $primary_registrant = $transaction->primary_registration(); |
|
100 | - if (! $primary_registrant instanceof EEI_Registration) { |
|
101 | - throw new EE_Error( |
|
102 | - esc_html__( |
|
103 | - 'No primary registration on transaction while paying with PayPal Pro.', |
|
104 | - 'event_espresso' |
|
105 | - ) |
|
106 | - ); |
|
107 | - } |
|
108 | - $attendee = $primary_registrant->attendee(); |
|
109 | - if (! $attendee instanceof EEI_Attendee) { |
|
110 | - throw new EE_Error( |
|
111 | - esc_html__( |
|
112 | - 'No attendee on primary registration while paying with PayPal Pro.', |
|
113 | - 'event_espresso' |
|
114 | - ) |
|
115 | - ); |
|
116 | - } |
|
117 | - $order_description = substr($this->_format_order_description($payment), 0, 127); |
|
118 | - //charge for the full amount. Show itemized list |
|
119 | - if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
120 | - $item_num = 1; |
|
121 | - $total_line_item = $transaction->total_line_item(); |
|
122 | - $order_items = array(); |
|
123 | - foreach ($total_line_item->get_items() as $line_item) { |
|
124 | - //ignore line items with a quantity of 0 |
|
125 | - if ($line_item->quantity() == 0) { |
|
126 | - continue; |
|
127 | - } |
|
128 | - $item = array( |
|
129 | - // Item Name. 127 char max. |
|
130 | - 'l_name' => substr( |
|
131 | - $this->_format_line_item_name($line_item, $payment), |
|
132 | - 0, |
|
133 | - 127 |
|
134 | - ), |
|
135 | - // Item description. 127 char max. |
|
136 | - 'l_desc' => substr( |
|
137 | - $this->_format_line_item_desc($line_item, $payment), |
|
138 | - 0, |
|
139 | - 127 |
|
140 | - ), |
|
141 | - // Cost of individual item. |
|
142 | - 'l_amt' => $line_item->unit_price(), |
|
143 | - // Item Number. 127 char max. |
|
144 | - 'l_number' => $item_num++, |
|
145 | - // Item quantity. Must be any positive integer. |
|
146 | - 'l_qty' => $line_item->quantity(), |
|
147 | - // Item's sales tax amount. |
|
148 | - 'l_taxamt' => '', |
|
149 | - // eBay auction number of item. |
|
150 | - 'l_ebayitemnumber' => '', |
|
151 | - // eBay transaction ID of purchased item. |
|
152 | - 'l_ebayitemauctiontxnid' => '', |
|
153 | - // eBay order ID for the item. |
|
154 | - 'l_ebayitemorderid' => '', |
|
155 | - ); |
|
156 | - // add to array of all items |
|
157 | - array_push($order_items, $item); |
|
158 | - } |
|
159 | - $item_amount = $total_line_item->get_items_total(); |
|
160 | - $tax_amount = $total_line_item->get_total_tax(); |
|
161 | - } else { |
|
162 | - $order_items = array(); |
|
163 | - $item_amount = $payment->amount(); |
|
164 | - $tax_amount = 0; |
|
165 | - array_push($order_items, array( |
|
166 | - // Item Name. 127 char max. |
|
167 | - 'l_name' => substr( |
|
168 | - $this->_format_partial_payment_line_item_name($payment), |
|
169 | - 0, |
|
170 | - 127 |
|
171 | - ), |
|
172 | - // Item description. 127 char max. |
|
173 | - 'l_desc' => substr( |
|
174 | - $this->_format_partial_payment_line_item_desc($payment), |
|
175 | - 0, |
|
176 | - 127 |
|
177 | - ), |
|
178 | - // Cost of individual item. |
|
179 | - 'l_amt' => $payment->amount(), |
|
180 | - // Item Number. 127 char max. |
|
181 | - 'l_number' => 1, |
|
182 | - // Item quantity. Must be any positive integer. |
|
183 | - 'l_qty' => 1, |
|
184 | - )); |
|
185 | - } |
|
186 | - // Populate data arrays with order data. |
|
187 | - $DPFields = array( |
|
188 | - // How you want to obtain payment ? |
|
189 | - // Authorization indicates the payment is a basic auth subject to settlement with Auth & Capture. |
|
190 | - // Sale indicates that this is a final sale for which you are requesting payment. Default is Sale. |
|
191 | - 'paymentaction' => 'Sale', |
|
192 | - // Required. IP address of the payer's browser. |
|
193 | - 'ipaddress' => $_SERVER['REMOTE_ADDR'], |
|
194 | - // Flag to determine whether you want the results returned by FMF. 1 or 0. Default is 0. |
|
195 | - 'returnfmfdetails' => '1', |
|
196 | - ); |
|
197 | - $CCDetails = array( |
|
198 | - // Required. Type of credit card. Visa, MasterCard, Discover, Amex, Maestro, Solo. |
|
199 | - // If Maestro or Solo, the currency code must be GBP. |
|
200 | - // In addition, either start date or issue number must be specified. |
|
201 | - 'creditcardtype' => $billing_info['credit_card_type'], |
|
202 | - // Required. Credit card number. No spaces or punctuation. |
|
203 | - 'acct' => $billing_info['credit_card'], |
|
204 | - // Required. Credit card expiration date. Format is MMYYYY |
|
205 | - 'expdate' => $billing_info['exp_month'] . $billing_info['exp_year'], |
|
206 | - // Requirements determined by your PayPal account settings. Security digits for credit card. |
|
207 | - 'cvv2' => $billing_info['cvv'], |
|
208 | - ); |
|
209 | - $PayerInfo = array( |
|
210 | - // Email address of payer. |
|
211 | - 'email' => $billing_info['email'], |
|
212 | - // Unique PayPal customer ID for payer. |
|
213 | - 'payerid' => '', |
|
214 | - // Status of payer. Values are verified or unverified |
|
215 | - 'payerstatus' => '', |
|
216 | - // Payer's business name. |
|
217 | - 'business' => '', |
|
218 | - ); |
|
219 | - $PayerName = array( |
|
220 | - // Payer's salutation. 20 char max. |
|
221 | - 'salutation' => '', |
|
222 | - // Payer's first name. 25 char max. |
|
223 | - 'firstname' => substr($billing_info['first_name'], 0, 25), |
|
224 | - // Payer's middle name. 25 char max. |
|
225 | - 'middlename' => '', |
|
226 | - // Payer's last name. 25 char max. |
|
227 | - 'lastname' => substr($billing_info['last_name'], 0, 25), |
|
228 | - // Payer's suffix. 12 char max. |
|
229 | - 'suffix' => '', |
|
230 | - ); |
|
231 | - $BillingAddress = array( |
|
232 | - // Required. First street address. |
|
233 | - 'street' => $billing_info['address'], |
|
234 | - // Second street address. |
|
235 | - 'street2' => $billing_info['address2'], |
|
236 | - // Required. Name of City. |
|
237 | - 'city' => $billing_info['city'], |
|
238 | - // Required. Name of State or Province. |
|
239 | - 'state' => substr($billing_info['state'], 0, 40), |
|
240 | - // Required. Country code. |
|
241 | - 'countrycode' => $billing_info['country'], |
|
242 | - // Required. Postal code of payer. |
|
243 | - 'zip' => $billing_info['zip'], |
|
244 | - ); |
|
245 | - //check if the registration info contains the needed fields for paypal pro |
|
246 | - //(see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/) |
|
247 | - if ($attendee->address() && $attendee->city() && $attendee->country_ID()) { |
|
248 | - $use_registration_address_info = true; |
|
249 | - } else { |
|
250 | - $use_registration_address_info = false; |
|
251 | - } |
|
252 | - //so if the attendee has enough data to fill out PayPal Pro's shipping info, use it. |
|
253 | - // If not, use the billing info again |
|
254 | - $ShippingAddress = array( |
|
255 | - 'shiptoname' => substr($use_registration_address_info |
|
256 | - ? $attendee->full_name() |
|
257 | - : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32), |
|
258 | - 'shiptostreet' => substr($use_registration_address_info |
|
259 | - ? $attendee->address() |
|
260 | - : $billing_info['address'], 0, 100), |
|
261 | - 'shiptostreet2' => substr($use_registration_address_info |
|
262 | - ? $attendee->address2() : $billing_info['address2'], 0, 100), |
|
263 | - 'shiptocity' => substr($use_registration_address_info |
|
264 | - ? $attendee->city() |
|
265 | - : $billing_info['city'], 0, 40), |
|
266 | - 'state' => substr($use_registration_address_info |
|
267 | - ? $attendee->state_name() |
|
268 | - : $billing_info['state'], 0, 40), |
|
269 | - 'shiptocountry' => $use_registration_address_info |
|
270 | - ? $attendee->country_ID() |
|
271 | - : $billing_info['country'], |
|
272 | - 'shiptozip' => substr($use_registration_address_info |
|
273 | - ? $attendee->zip() |
|
274 | - : $billing_info['zip'], 0, 20), |
|
275 | - 'shiptophonenum' => substr($use_registration_address_info |
|
276 | - ? $attendee->phone() |
|
277 | - : $billing_info['phone'], 0, 20), |
|
278 | - ); |
|
279 | - $PaymentDetails = array( |
|
280 | - // Required. Total amount of order, including shipping, handling, and tax. |
|
281 | - 'amt' => $this->format_currency($payment->amount()), |
|
282 | - // Required. Three-letter currency code. Default is USD. |
|
283 | - 'currencycode' => $payment->currency_code(), |
|
284 | - // Required if you include itemized cart details. (L_AMTn, etc.) |
|
285 | - //Subtotal of items not including S&H, or tax. |
|
286 | - 'itemamt' => $this->format_currency($item_amount),// |
|
287 | - // Total shipping costs for the order. If you specify shippingamt, you must also specify itemamt. |
|
288 | - 'shippingamt' => '', |
|
289 | - // Total handling costs for the order. If you specify handlingamt, you must also specify itemamt. |
|
290 | - 'handlingamt' => '', |
|
291 | - // Required if you specify itemized cart tax details. |
|
292 | - // Sum of tax for all items on the order. Total sales tax. |
|
293 | - 'taxamt' => $this->format_currency($tax_amount), |
|
294 | - // Description of the order the customer is purchasing. 127 char max. |
|
295 | - 'desc' => $order_description, |
|
296 | - // Free-form field for your own use. 256 char max. |
|
297 | - 'custom' => $primary_registrant ? $primary_registrant->ID() : '', |
|
298 | - // Your own invoice or tracking number |
|
299 | - 'invnum' => wp_generate_password(12, false),//$transaction->ID(), |
|
300 | - // URL for receiving Instant Payment Notifications. This overrides what your profile is set to use. |
|
301 | - 'notifyurl' => '', |
|
302 | - 'buttonsource' => 'EventEspresso_SP',//EE will blow up if you change this |
|
303 | - ); |
|
304 | - // Wrap all data arrays into a single, "master" array which will be passed into the class function. |
|
305 | - $PayPalRequestData = array( |
|
306 | - 'DPFields' => $DPFields, |
|
307 | - 'CCDetails' => $CCDetails, |
|
308 | - 'PayerInfo' => $PayerInfo, |
|
309 | - 'PayerName' => $PayerName, |
|
310 | - 'BillingAddress' => $BillingAddress, |
|
311 | - 'ShippingAddress' => $ShippingAddress, |
|
312 | - 'PaymentDetails' => $PaymentDetails, |
|
313 | - 'OrderItems' => $order_items, |
|
314 | - ); |
|
315 | - $this->_log_clean_request($PayPalRequestData, $payment); |
|
316 | - try { |
|
317 | - $PayPalResult = $this->prep_and_curl_request($PayPalRequestData); |
|
318 | - //remove PCI-sensitive data so it doesn't get stored |
|
319 | - $PayPalResult = $this->_log_clean_response($PayPalResult, $payment); |
|
320 | - $message = isset($PayPalResult['L_LONGMESSAGE0']) ? $PayPalResult['L_LONGMESSAGE0'] : $PayPalResult['ACK']; |
|
321 | - if (empty($PayPalResult['RAWRESPONSE'])) { |
|
322 | - $payment->set_status($this->_pay_model->failed_status()); |
|
323 | - $payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso')); |
|
324 | - $payment->set_details($PayPalResult); |
|
325 | - } else { |
|
326 | - if ($this->_APICallSuccessful($PayPalResult)) { |
|
327 | - $payment->set_status($this->_pay_model->approved_status()); |
|
328 | - } else { |
|
329 | - $payment->set_status($this->_pay_model->declined_status()); |
|
330 | - } |
|
331 | - //make sure we interpret the AMT as a float, not an international string |
|
332 | - // (where periods are thousand separators) |
|
333 | - $payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0); |
|
334 | - $payment->set_gateway_response($message); |
|
335 | - $payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID']) |
|
336 | - ? $PayPalResult['TRANSACTIONID'] |
|
337 | - : null); |
|
338 | - $primary_registration_code = $primary_registrant instanceof EE_Registration |
|
339 | - ? $primary_registrant->reg_code() |
|
340 | - : ''; |
|
341 | - $payment->set_extra_accntng($primary_registration_code); |
|
342 | - $payment->set_details($PayPalResult); |
|
343 | - } |
|
344 | - } catch (Exception $e) { |
|
345 | - $payment->set_status($this->_pay_model->failed_status()); |
|
346 | - $payment->set_gateway_response($e->getMessage()); |
|
347 | - } |
|
348 | - //$payment->set_status( $this->_pay_model->declined_status() ); |
|
349 | - //$payment->set_gateway_response( '' ); |
|
350 | - return $payment; |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * CLeans out sensitive CC data and then logs it, and returns the cleaned request |
|
357 | - * |
|
358 | - * @param array $request |
|
359 | - * @param EEI_Payment $payment |
|
360 | - * @return void |
|
361 | - */ |
|
362 | - private function _log_clean_request($request, $payment) |
|
363 | - { |
|
364 | - $cleaned_request_data = $request; |
|
365 | - unset($cleaned_request_data['CCDetails']['acct']); |
|
366 | - unset($cleaned_request_data['CCDetails']['cvv2']); |
|
367 | - unset($cleaned_request_data['CCDetails']['expdate']); |
|
368 | - $this->log(array('Paypal Request' => $cleaned_request_data), $payment); |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * Cleans the response, logs it, and returns it |
|
375 | - * |
|
376 | - * @param array $response |
|
377 | - * @param EEI_Payment $payment |
|
378 | - * @return array cleaned |
|
379 | - */ |
|
380 | - private function _log_clean_response($response, $payment) |
|
381 | - { |
|
382 | - unset($response['REQUESTDATA']['CREDITCARDTYPE']); |
|
383 | - unset($response['REQUESTDATA']['ACCT']); |
|
384 | - unset($response['REQUESTDATA']['EXPDATE']); |
|
385 | - unset($response['REQUESTDATA']['CVV2']); |
|
386 | - unset($response['RAWREQUEST']); |
|
387 | - $this->log(array('Paypal Response' => $response), $payment); |
|
388 | - return $response; |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - |
|
393 | - /** |
|
394 | - * @param $DataArray |
|
395 | - * @return array |
|
396 | - */ |
|
397 | - private function prep_and_curl_request($DataArray) |
|
398 | - { |
|
399 | - // Create empty holders for each portion of the NVP string |
|
400 | - $DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP'; |
|
401 | - $CCDetailsNVP = ''; |
|
402 | - $PayerInfoNVP = ''; |
|
403 | - $PayerNameNVP = ''; |
|
404 | - $BillingAddressNVP = ''; |
|
405 | - $ShippingAddressNVP = ''; |
|
406 | - $PaymentDetailsNVP = ''; |
|
407 | - $OrderItemsNVP = ''; |
|
408 | - $Secure3DNVP = ''; |
|
409 | - // DP Fields |
|
410 | - $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array(); |
|
411 | - foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) { |
|
412 | - $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal); |
|
413 | - } |
|
414 | - // CC Details Fields |
|
415 | - $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); |
|
416 | - foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) { |
|
417 | - $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal); |
|
418 | - } |
|
419 | - // PayerInfo Type Fields |
|
420 | - $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); |
|
421 | - foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) { |
|
422 | - $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal); |
|
423 | - } |
|
424 | - // Payer Name Fields |
|
425 | - $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); |
|
426 | - foreach ($PayerName as $PayerNameVar => $PayerNameVal) { |
|
427 | - $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal); |
|
428 | - } |
|
429 | - // Address Fields (Billing) |
|
430 | - $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); |
|
431 | - foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) { |
|
432 | - $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal); |
|
433 | - } |
|
434 | - // Payment Details Type Fields |
|
435 | - $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array(); |
|
436 | - foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) { |
|
437 | - $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal); |
|
438 | - } |
|
439 | - // Payment Details Item Type Fields |
|
440 | - $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array(); |
|
441 | - $n = 0; |
|
442 | - foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) { |
|
443 | - $CurrentItem = $OrderItems[$OrderItemsVar]; |
|
444 | - foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) { |
|
445 | - $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal); |
|
446 | - } |
|
447 | - $n++; |
|
448 | - } |
|
449 | - // Ship To Address Fields |
|
450 | - $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); |
|
451 | - foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) { |
|
452 | - $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal); |
|
453 | - } |
|
454 | - // 3D Secure Fields |
|
455 | - $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array(); |
|
456 | - foreach ($Secure3D as $Secure3DVar => $Secure3DVal) { |
|
457 | - $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal); |
|
458 | - } |
|
459 | - // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string |
|
460 | - $NVPRequest = 'USER=' |
|
461 | - . $this->_username |
|
462 | - . '&PWD=' |
|
463 | - . $this->_password |
|
464 | - . '&VERSION=64.0' |
|
465 | - . '&SIGNATURE=' |
|
466 | - . $this->_signature |
|
467 | - . $DPFieldsNVP |
|
468 | - . $CCDetailsNVP |
|
469 | - . $PayerInfoNVP |
|
470 | - . $PayerNameNVP |
|
471 | - . $BillingAddressNVP |
|
472 | - . $PaymentDetailsNVP |
|
473 | - . $OrderItemsNVP |
|
474 | - . $ShippingAddressNVP |
|
475 | - . $Secure3DNVP; |
|
476 | - $NVPResponse = $this->_CURLRequest($NVPRequest); |
|
477 | - $NVPRequestArray = $this->_NVPToArray($NVPRequest); |
|
478 | - $NVPResponseArray = $this->_NVPToArray($NVPResponse); |
|
479 | - $Errors = $this->_GetErrors($NVPResponseArray); |
|
480 | - $NVPResponseArray['ERRORS'] = $Errors; |
|
481 | - $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; |
|
482 | - $NVPResponseArray['RAWREQUEST'] = $NVPRequest; |
|
483 | - $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; |
|
484 | - return $NVPResponseArray; |
|
485 | - } |
|
486 | - |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * @param $Request |
|
491 | - * @return mixed |
|
492 | - */ |
|
493 | - private function _CURLRequest($Request) |
|
494 | - { |
|
495 | - $EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp'; |
|
496 | - $curl = curl_init(); |
|
497 | - curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true)); |
|
498 | - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
499 | - curl_setopt($curl, CURLOPT_TIMEOUT, 60); |
|
500 | - curl_setopt($curl, CURLOPT_URL, $EndPointURL); |
|
501 | - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
|
502 | - curl_setopt($curl, CURLOPT_POSTFIELDS, $Request); |
|
503 | - curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
504 | - //execute the curl POST |
|
505 | - $Response = curl_exec($curl); |
|
506 | - curl_close($curl); |
|
507 | - return $Response; |
|
508 | - } |
|
509 | - |
|
510 | - |
|
511 | - |
|
512 | - /** |
|
513 | - * @param $NVPString |
|
514 | - * @return array |
|
515 | - */ |
|
516 | - private function _NVPToArray($NVPString) |
|
517 | - { |
|
518 | - // prepare responses into array |
|
519 | - $proArray = array(); |
|
520 | - while (strlen($NVPString)) { |
|
521 | - // name |
|
522 | - $keypos = strpos($NVPString, '='); |
|
523 | - $keyval = substr($NVPString, 0, $keypos); |
|
524 | - // value |
|
525 | - $valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString); |
|
526 | - $valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1); |
|
527 | - // decoding the response |
|
528 | - $proArray[$keyval] = urldecode($valval); |
|
529 | - $NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString)); |
|
530 | - } |
|
531 | - return $proArray; |
|
532 | - } |
|
533 | - |
|
534 | - |
|
535 | - |
|
536 | - /** |
|
537 | - * @param array $PayPalResult |
|
538 | - * @return bool |
|
539 | - */ |
|
540 | - private function _APICallSuccessful($PayPalResult) |
|
541 | - { |
|
542 | - $approved = false; |
|
543 | - // check main response message from PayPal |
|
544 | - if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) { |
|
545 | - $ack = strtoupper($PayPalResult['ACK']); |
|
546 | - $approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false; |
|
547 | - } |
|
548 | - return $approved; |
|
549 | - } |
|
550 | - |
|
551 | - |
|
552 | - |
|
553 | - /** |
|
554 | - * @param $DataArray |
|
555 | - * @return array |
|
556 | - */ |
|
557 | - private function _GetErrors($DataArray) |
|
558 | - { |
|
559 | - $Errors = array(); |
|
560 | - $n = 0; |
|
561 | - while (isset($DataArray['L_ERRORCODE' . $n . ''])) { |
|
562 | - $LErrorCode = isset($DataArray['L_ERRORCODE' . $n . '']) ? $DataArray['L_ERRORCODE' . $n . ''] : ''; |
|
563 | - $LShortMessage = isset($DataArray['L_SHORTMESSAGE' . $n . '']) |
|
564 | - ? $DataArray['L_SHORTMESSAGE' . $n . ''] |
|
565 | - : ''; |
|
566 | - $LLongMessage = isset($DataArray['L_LONGMESSAGE' . $n . '']) |
|
567 | - ? $DataArray['L_LONGMESSAGE' . $n . ''] |
|
568 | - : ''; |
|
569 | - $LSeverityCode = isset($DataArray['L_SEVERITYCODE' . $n . '']) |
|
570 | - ? $DataArray['L_SEVERITYCODE' . $n . ''] |
|
571 | - : ''; |
|
572 | - $CurrentItem = array( |
|
573 | - 'L_ERRORCODE' => $LErrorCode, |
|
574 | - 'L_SHORTMESSAGE' => $LShortMessage, |
|
575 | - 'L_LONGMESSAGE' => $LLongMessage, |
|
576 | - 'L_SEVERITYCODE' => $LSeverityCode, |
|
577 | - ); |
|
578 | - array_push($Errors, $CurrentItem); |
|
579 | - $n++; |
|
580 | - } |
|
581 | - return $Errors; |
|
582 | - } |
|
583 | - |
|
584 | - |
|
585 | - |
|
586 | - /** |
|
587 | - * nothing to see here... move along.... |
|
588 | - * |
|
589 | - * @access protected |
|
590 | - * @param $Errors |
|
591 | - * @return string |
|
592 | - */ |
|
593 | - private function _DisplayErrors($Errors) |
|
594 | - { |
|
595 | - $error = ''; |
|
596 | - foreach ($Errors as $ErrorVar => $ErrorVal) { |
|
597 | - $CurrentError = $Errors[$ErrorVar]; |
|
598 | - foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) { |
|
599 | - $CurrentVarName = ''; |
|
600 | - if ($CurrentErrorVar == 'L_ERRORCODE') { |
|
601 | - $CurrentVarName = 'Error Code'; |
|
602 | - } elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') { |
|
603 | - $CurrentVarName = 'Short Message'; |
|
604 | - } elseif ($CurrentErrorVar == 'L_LONGMESSAGE') { |
|
605 | - $CurrentVarName = 'Long Message'; |
|
606 | - } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') { |
|
607 | - $CurrentVarName = 'Severity Code'; |
|
608 | - } |
|
609 | - $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal; |
|
610 | - } |
|
611 | - } |
|
612 | - return $error; |
|
613 | - } |
|
28 | + /** |
|
29 | + * @var $_paypal_api_username string |
|
30 | + */ |
|
31 | + protected $_username = null; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var $_password string |
|
35 | + */ |
|
36 | + protected $_password = null; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var $_signature string |
|
40 | + */ |
|
41 | + protected $_signature = null; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var $_credit_card_types array with the keys for credit card types accepted on this account |
|
45 | + */ |
|
46 | + protected $_credit_card_types = null; |
|
47 | + |
|
48 | + protected $_currencies_supported = array( |
|
49 | + 'USD', |
|
50 | + 'GBP', |
|
51 | + 'CAD', |
|
52 | + 'AUD', |
|
53 | + 'BRL', |
|
54 | + 'CHF', |
|
55 | + 'CZK', |
|
56 | + 'DKK', |
|
57 | + 'EUR', |
|
58 | + 'HKD', |
|
59 | + 'HUF', |
|
60 | + 'ILS', |
|
61 | + 'JPY', |
|
62 | + 'MXN', |
|
63 | + 'MYR', |
|
64 | + 'NOK', |
|
65 | + 'NZD', |
|
66 | + 'PHP', |
|
67 | + 'PLN', |
|
68 | + 'SEK', |
|
69 | + 'SGD', |
|
70 | + 'THB', |
|
71 | + 'TRY', |
|
72 | + 'TWD', |
|
73 | + 'RUB', |
|
74 | + ); |
|
75 | + |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * @param EEI_Payment $payment |
|
80 | + * @param array $billing_info { |
|
81 | + * @type string $credit_card |
|
82 | + * @type string $credit_card_type |
|
83 | + * @type string $exp_month always 2 characters |
|
84 | + * @type string $exp_year always 4 characters |
|
85 | + * @type string $cvv |
|
86 | + * } |
|
87 | + * @see parent::do_direct_payment for more info |
|
88 | + * @return EE_Payment|EEI_Payment |
|
89 | + * @throws EE_Error |
|
90 | + */ |
|
91 | + public function do_direct_payment($payment, $billing_info = null) |
|
92 | + { |
|
93 | + $transaction = $payment->transaction(); |
|
94 | + if (! $transaction instanceof EEI_Transaction) { |
|
95 | + throw new EE_Error( |
|
96 | + esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso') |
|
97 | + ); |
|
98 | + } |
|
99 | + $primary_registrant = $transaction->primary_registration(); |
|
100 | + if (! $primary_registrant instanceof EEI_Registration) { |
|
101 | + throw new EE_Error( |
|
102 | + esc_html__( |
|
103 | + 'No primary registration on transaction while paying with PayPal Pro.', |
|
104 | + 'event_espresso' |
|
105 | + ) |
|
106 | + ); |
|
107 | + } |
|
108 | + $attendee = $primary_registrant->attendee(); |
|
109 | + if (! $attendee instanceof EEI_Attendee) { |
|
110 | + throw new EE_Error( |
|
111 | + esc_html__( |
|
112 | + 'No attendee on primary registration while paying with PayPal Pro.', |
|
113 | + 'event_espresso' |
|
114 | + ) |
|
115 | + ); |
|
116 | + } |
|
117 | + $order_description = substr($this->_format_order_description($payment), 0, 127); |
|
118 | + //charge for the full amount. Show itemized list |
|
119 | + if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
120 | + $item_num = 1; |
|
121 | + $total_line_item = $transaction->total_line_item(); |
|
122 | + $order_items = array(); |
|
123 | + foreach ($total_line_item->get_items() as $line_item) { |
|
124 | + //ignore line items with a quantity of 0 |
|
125 | + if ($line_item->quantity() == 0) { |
|
126 | + continue; |
|
127 | + } |
|
128 | + $item = array( |
|
129 | + // Item Name. 127 char max. |
|
130 | + 'l_name' => substr( |
|
131 | + $this->_format_line_item_name($line_item, $payment), |
|
132 | + 0, |
|
133 | + 127 |
|
134 | + ), |
|
135 | + // Item description. 127 char max. |
|
136 | + 'l_desc' => substr( |
|
137 | + $this->_format_line_item_desc($line_item, $payment), |
|
138 | + 0, |
|
139 | + 127 |
|
140 | + ), |
|
141 | + // Cost of individual item. |
|
142 | + 'l_amt' => $line_item->unit_price(), |
|
143 | + // Item Number. 127 char max. |
|
144 | + 'l_number' => $item_num++, |
|
145 | + // Item quantity. Must be any positive integer. |
|
146 | + 'l_qty' => $line_item->quantity(), |
|
147 | + // Item's sales tax amount. |
|
148 | + 'l_taxamt' => '', |
|
149 | + // eBay auction number of item. |
|
150 | + 'l_ebayitemnumber' => '', |
|
151 | + // eBay transaction ID of purchased item. |
|
152 | + 'l_ebayitemauctiontxnid' => '', |
|
153 | + // eBay order ID for the item. |
|
154 | + 'l_ebayitemorderid' => '', |
|
155 | + ); |
|
156 | + // add to array of all items |
|
157 | + array_push($order_items, $item); |
|
158 | + } |
|
159 | + $item_amount = $total_line_item->get_items_total(); |
|
160 | + $tax_amount = $total_line_item->get_total_tax(); |
|
161 | + } else { |
|
162 | + $order_items = array(); |
|
163 | + $item_amount = $payment->amount(); |
|
164 | + $tax_amount = 0; |
|
165 | + array_push($order_items, array( |
|
166 | + // Item Name. 127 char max. |
|
167 | + 'l_name' => substr( |
|
168 | + $this->_format_partial_payment_line_item_name($payment), |
|
169 | + 0, |
|
170 | + 127 |
|
171 | + ), |
|
172 | + // Item description. 127 char max. |
|
173 | + 'l_desc' => substr( |
|
174 | + $this->_format_partial_payment_line_item_desc($payment), |
|
175 | + 0, |
|
176 | + 127 |
|
177 | + ), |
|
178 | + // Cost of individual item. |
|
179 | + 'l_amt' => $payment->amount(), |
|
180 | + // Item Number. 127 char max. |
|
181 | + 'l_number' => 1, |
|
182 | + // Item quantity. Must be any positive integer. |
|
183 | + 'l_qty' => 1, |
|
184 | + )); |
|
185 | + } |
|
186 | + // Populate data arrays with order data. |
|
187 | + $DPFields = array( |
|
188 | + // How you want to obtain payment ? |
|
189 | + // Authorization indicates the payment is a basic auth subject to settlement with Auth & Capture. |
|
190 | + // Sale indicates that this is a final sale for which you are requesting payment. Default is Sale. |
|
191 | + 'paymentaction' => 'Sale', |
|
192 | + // Required. IP address of the payer's browser. |
|
193 | + 'ipaddress' => $_SERVER['REMOTE_ADDR'], |
|
194 | + // Flag to determine whether you want the results returned by FMF. 1 or 0. Default is 0. |
|
195 | + 'returnfmfdetails' => '1', |
|
196 | + ); |
|
197 | + $CCDetails = array( |
|
198 | + // Required. Type of credit card. Visa, MasterCard, Discover, Amex, Maestro, Solo. |
|
199 | + // If Maestro or Solo, the currency code must be GBP. |
|
200 | + // In addition, either start date or issue number must be specified. |
|
201 | + 'creditcardtype' => $billing_info['credit_card_type'], |
|
202 | + // Required. Credit card number. No spaces or punctuation. |
|
203 | + 'acct' => $billing_info['credit_card'], |
|
204 | + // Required. Credit card expiration date. Format is MMYYYY |
|
205 | + 'expdate' => $billing_info['exp_month'] . $billing_info['exp_year'], |
|
206 | + // Requirements determined by your PayPal account settings. Security digits for credit card. |
|
207 | + 'cvv2' => $billing_info['cvv'], |
|
208 | + ); |
|
209 | + $PayerInfo = array( |
|
210 | + // Email address of payer. |
|
211 | + 'email' => $billing_info['email'], |
|
212 | + // Unique PayPal customer ID for payer. |
|
213 | + 'payerid' => '', |
|
214 | + // Status of payer. Values are verified or unverified |
|
215 | + 'payerstatus' => '', |
|
216 | + // Payer's business name. |
|
217 | + 'business' => '', |
|
218 | + ); |
|
219 | + $PayerName = array( |
|
220 | + // Payer's salutation. 20 char max. |
|
221 | + 'salutation' => '', |
|
222 | + // Payer's first name. 25 char max. |
|
223 | + 'firstname' => substr($billing_info['first_name'], 0, 25), |
|
224 | + // Payer's middle name. 25 char max. |
|
225 | + 'middlename' => '', |
|
226 | + // Payer's last name. 25 char max. |
|
227 | + 'lastname' => substr($billing_info['last_name'], 0, 25), |
|
228 | + // Payer's suffix. 12 char max. |
|
229 | + 'suffix' => '', |
|
230 | + ); |
|
231 | + $BillingAddress = array( |
|
232 | + // Required. First street address. |
|
233 | + 'street' => $billing_info['address'], |
|
234 | + // Second street address. |
|
235 | + 'street2' => $billing_info['address2'], |
|
236 | + // Required. Name of City. |
|
237 | + 'city' => $billing_info['city'], |
|
238 | + // Required. Name of State or Province. |
|
239 | + 'state' => substr($billing_info['state'], 0, 40), |
|
240 | + // Required. Country code. |
|
241 | + 'countrycode' => $billing_info['country'], |
|
242 | + // Required. Postal code of payer. |
|
243 | + 'zip' => $billing_info['zip'], |
|
244 | + ); |
|
245 | + //check if the registration info contains the needed fields for paypal pro |
|
246 | + //(see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/) |
|
247 | + if ($attendee->address() && $attendee->city() && $attendee->country_ID()) { |
|
248 | + $use_registration_address_info = true; |
|
249 | + } else { |
|
250 | + $use_registration_address_info = false; |
|
251 | + } |
|
252 | + //so if the attendee has enough data to fill out PayPal Pro's shipping info, use it. |
|
253 | + // If not, use the billing info again |
|
254 | + $ShippingAddress = array( |
|
255 | + 'shiptoname' => substr($use_registration_address_info |
|
256 | + ? $attendee->full_name() |
|
257 | + : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32), |
|
258 | + 'shiptostreet' => substr($use_registration_address_info |
|
259 | + ? $attendee->address() |
|
260 | + : $billing_info['address'], 0, 100), |
|
261 | + 'shiptostreet2' => substr($use_registration_address_info |
|
262 | + ? $attendee->address2() : $billing_info['address2'], 0, 100), |
|
263 | + 'shiptocity' => substr($use_registration_address_info |
|
264 | + ? $attendee->city() |
|
265 | + : $billing_info['city'], 0, 40), |
|
266 | + 'state' => substr($use_registration_address_info |
|
267 | + ? $attendee->state_name() |
|
268 | + : $billing_info['state'], 0, 40), |
|
269 | + 'shiptocountry' => $use_registration_address_info |
|
270 | + ? $attendee->country_ID() |
|
271 | + : $billing_info['country'], |
|
272 | + 'shiptozip' => substr($use_registration_address_info |
|
273 | + ? $attendee->zip() |
|
274 | + : $billing_info['zip'], 0, 20), |
|
275 | + 'shiptophonenum' => substr($use_registration_address_info |
|
276 | + ? $attendee->phone() |
|
277 | + : $billing_info['phone'], 0, 20), |
|
278 | + ); |
|
279 | + $PaymentDetails = array( |
|
280 | + // Required. Total amount of order, including shipping, handling, and tax. |
|
281 | + 'amt' => $this->format_currency($payment->amount()), |
|
282 | + // Required. Three-letter currency code. Default is USD. |
|
283 | + 'currencycode' => $payment->currency_code(), |
|
284 | + // Required if you include itemized cart details. (L_AMTn, etc.) |
|
285 | + //Subtotal of items not including S&H, or tax. |
|
286 | + 'itemamt' => $this->format_currency($item_amount),// |
|
287 | + // Total shipping costs for the order. If you specify shippingamt, you must also specify itemamt. |
|
288 | + 'shippingamt' => '', |
|
289 | + // Total handling costs for the order. If you specify handlingamt, you must also specify itemamt. |
|
290 | + 'handlingamt' => '', |
|
291 | + // Required if you specify itemized cart tax details. |
|
292 | + // Sum of tax for all items on the order. Total sales tax. |
|
293 | + 'taxamt' => $this->format_currency($tax_amount), |
|
294 | + // Description of the order the customer is purchasing. 127 char max. |
|
295 | + 'desc' => $order_description, |
|
296 | + // Free-form field for your own use. 256 char max. |
|
297 | + 'custom' => $primary_registrant ? $primary_registrant->ID() : '', |
|
298 | + // Your own invoice or tracking number |
|
299 | + 'invnum' => wp_generate_password(12, false),//$transaction->ID(), |
|
300 | + // URL for receiving Instant Payment Notifications. This overrides what your profile is set to use. |
|
301 | + 'notifyurl' => '', |
|
302 | + 'buttonsource' => 'EventEspresso_SP',//EE will blow up if you change this |
|
303 | + ); |
|
304 | + // Wrap all data arrays into a single, "master" array which will be passed into the class function. |
|
305 | + $PayPalRequestData = array( |
|
306 | + 'DPFields' => $DPFields, |
|
307 | + 'CCDetails' => $CCDetails, |
|
308 | + 'PayerInfo' => $PayerInfo, |
|
309 | + 'PayerName' => $PayerName, |
|
310 | + 'BillingAddress' => $BillingAddress, |
|
311 | + 'ShippingAddress' => $ShippingAddress, |
|
312 | + 'PaymentDetails' => $PaymentDetails, |
|
313 | + 'OrderItems' => $order_items, |
|
314 | + ); |
|
315 | + $this->_log_clean_request($PayPalRequestData, $payment); |
|
316 | + try { |
|
317 | + $PayPalResult = $this->prep_and_curl_request($PayPalRequestData); |
|
318 | + //remove PCI-sensitive data so it doesn't get stored |
|
319 | + $PayPalResult = $this->_log_clean_response($PayPalResult, $payment); |
|
320 | + $message = isset($PayPalResult['L_LONGMESSAGE0']) ? $PayPalResult['L_LONGMESSAGE0'] : $PayPalResult['ACK']; |
|
321 | + if (empty($PayPalResult['RAWRESPONSE'])) { |
|
322 | + $payment->set_status($this->_pay_model->failed_status()); |
|
323 | + $payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso')); |
|
324 | + $payment->set_details($PayPalResult); |
|
325 | + } else { |
|
326 | + if ($this->_APICallSuccessful($PayPalResult)) { |
|
327 | + $payment->set_status($this->_pay_model->approved_status()); |
|
328 | + } else { |
|
329 | + $payment->set_status($this->_pay_model->declined_status()); |
|
330 | + } |
|
331 | + //make sure we interpret the AMT as a float, not an international string |
|
332 | + // (where periods are thousand separators) |
|
333 | + $payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0); |
|
334 | + $payment->set_gateway_response($message); |
|
335 | + $payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID']) |
|
336 | + ? $PayPalResult['TRANSACTIONID'] |
|
337 | + : null); |
|
338 | + $primary_registration_code = $primary_registrant instanceof EE_Registration |
|
339 | + ? $primary_registrant->reg_code() |
|
340 | + : ''; |
|
341 | + $payment->set_extra_accntng($primary_registration_code); |
|
342 | + $payment->set_details($PayPalResult); |
|
343 | + } |
|
344 | + } catch (Exception $e) { |
|
345 | + $payment->set_status($this->_pay_model->failed_status()); |
|
346 | + $payment->set_gateway_response($e->getMessage()); |
|
347 | + } |
|
348 | + //$payment->set_status( $this->_pay_model->declined_status() ); |
|
349 | + //$payment->set_gateway_response( '' ); |
|
350 | + return $payment; |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * CLeans out sensitive CC data and then logs it, and returns the cleaned request |
|
357 | + * |
|
358 | + * @param array $request |
|
359 | + * @param EEI_Payment $payment |
|
360 | + * @return void |
|
361 | + */ |
|
362 | + private function _log_clean_request($request, $payment) |
|
363 | + { |
|
364 | + $cleaned_request_data = $request; |
|
365 | + unset($cleaned_request_data['CCDetails']['acct']); |
|
366 | + unset($cleaned_request_data['CCDetails']['cvv2']); |
|
367 | + unset($cleaned_request_data['CCDetails']['expdate']); |
|
368 | + $this->log(array('Paypal Request' => $cleaned_request_data), $payment); |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * Cleans the response, logs it, and returns it |
|
375 | + * |
|
376 | + * @param array $response |
|
377 | + * @param EEI_Payment $payment |
|
378 | + * @return array cleaned |
|
379 | + */ |
|
380 | + private function _log_clean_response($response, $payment) |
|
381 | + { |
|
382 | + unset($response['REQUESTDATA']['CREDITCARDTYPE']); |
|
383 | + unset($response['REQUESTDATA']['ACCT']); |
|
384 | + unset($response['REQUESTDATA']['EXPDATE']); |
|
385 | + unset($response['REQUESTDATA']['CVV2']); |
|
386 | + unset($response['RAWREQUEST']); |
|
387 | + $this->log(array('Paypal Response' => $response), $payment); |
|
388 | + return $response; |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + |
|
393 | + /** |
|
394 | + * @param $DataArray |
|
395 | + * @return array |
|
396 | + */ |
|
397 | + private function prep_and_curl_request($DataArray) |
|
398 | + { |
|
399 | + // Create empty holders for each portion of the NVP string |
|
400 | + $DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP'; |
|
401 | + $CCDetailsNVP = ''; |
|
402 | + $PayerInfoNVP = ''; |
|
403 | + $PayerNameNVP = ''; |
|
404 | + $BillingAddressNVP = ''; |
|
405 | + $ShippingAddressNVP = ''; |
|
406 | + $PaymentDetailsNVP = ''; |
|
407 | + $OrderItemsNVP = ''; |
|
408 | + $Secure3DNVP = ''; |
|
409 | + // DP Fields |
|
410 | + $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array(); |
|
411 | + foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) { |
|
412 | + $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal); |
|
413 | + } |
|
414 | + // CC Details Fields |
|
415 | + $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); |
|
416 | + foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) { |
|
417 | + $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal); |
|
418 | + } |
|
419 | + // PayerInfo Type Fields |
|
420 | + $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); |
|
421 | + foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) { |
|
422 | + $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal); |
|
423 | + } |
|
424 | + // Payer Name Fields |
|
425 | + $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); |
|
426 | + foreach ($PayerName as $PayerNameVar => $PayerNameVal) { |
|
427 | + $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal); |
|
428 | + } |
|
429 | + // Address Fields (Billing) |
|
430 | + $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); |
|
431 | + foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) { |
|
432 | + $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal); |
|
433 | + } |
|
434 | + // Payment Details Type Fields |
|
435 | + $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array(); |
|
436 | + foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) { |
|
437 | + $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal); |
|
438 | + } |
|
439 | + // Payment Details Item Type Fields |
|
440 | + $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array(); |
|
441 | + $n = 0; |
|
442 | + foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) { |
|
443 | + $CurrentItem = $OrderItems[$OrderItemsVar]; |
|
444 | + foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) { |
|
445 | + $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal); |
|
446 | + } |
|
447 | + $n++; |
|
448 | + } |
|
449 | + // Ship To Address Fields |
|
450 | + $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); |
|
451 | + foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) { |
|
452 | + $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal); |
|
453 | + } |
|
454 | + // 3D Secure Fields |
|
455 | + $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array(); |
|
456 | + foreach ($Secure3D as $Secure3DVar => $Secure3DVal) { |
|
457 | + $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal); |
|
458 | + } |
|
459 | + // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string |
|
460 | + $NVPRequest = 'USER=' |
|
461 | + . $this->_username |
|
462 | + . '&PWD=' |
|
463 | + . $this->_password |
|
464 | + . '&VERSION=64.0' |
|
465 | + . '&SIGNATURE=' |
|
466 | + . $this->_signature |
|
467 | + . $DPFieldsNVP |
|
468 | + . $CCDetailsNVP |
|
469 | + . $PayerInfoNVP |
|
470 | + . $PayerNameNVP |
|
471 | + . $BillingAddressNVP |
|
472 | + . $PaymentDetailsNVP |
|
473 | + . $OrderItemsNVP |
|
474 | + . $ShippingAddressNVP |
|
475 | + . $Secure3DNVP; |
|
476 | + $NVPResponse = $this->_CURLRequest($NVPRequest); |
|
477 | + $NVPRequestArray = $this->_NVPToArray($NVPRequest); |
|
478 | + $NVPResponseArray = $this->_NVPToArray($NVPResponse); |
|
479 | + $Errors = $this->_GetErrors($NVPResponseArray); |
|
480 | + $NVPResponseArray['ERRORS'] = $Errors; |
|
481 | + $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray; |
|
482 | + $NVPResponseArray['RAWREQUEST'] = $NVPRequest; |
|
483 | + $NVPResponseArray['RAWRESPONSE'] = $NVPResponse; |
|
484 | + return $NVPResponseArray; |
|
485 | + } |
|
486 | + |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * @param $Request |
|
491 | + * @return mixed |
|
492 | + */ |
|
493 | + private function _CURLRequest($Request) |
|
494 | + { |
|
495 | + $EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp'; |
|
496 | + $curl = curl_init(); |
|
497 | + curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true)); |
|
498 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
499 | + curl_setopt($curl, CURLOPT_TIMEOUT, 60); |
|
500 | + curl_setopt($curl, CURLOPT_URL, $EndPointURL); |
|
501 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
|
502 | + curl_setopt($curl, CURLOPT_POSTFIELDS, $Request); |
|
503 | + curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
|
504 | + //execute the curl POST |
|
505 | + $Response = curl_exec($curl); |
|
506 | + curl_close($curl); |
|
507 | + return $Response; |
|
508 | + } |
|
509 | + |
|
510 | + |
|
511 | + |
|
512 | + /** |
|
513 | + * @param $NVPString |
|
514 | + * @return array |
|
515 | + */ |
|
516 | + private function _NVPToArray($NVPString) |
|
517 | + { |
|
518 | + // prepare responses into array |
|
519 | + $proArray = array(); |
|
520 | + while (strlen($NVPString)) { |
|
521 | + // name |
|
522 | + $keypos = strpos($NVPString, '='); |
|
523 | + $keyval = substr($NVPString, 0, $keypos); |
|
524 | + // value |
|
525 | + $valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString); |
|
526 | + $valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1); |
|
527 | + // decoding the response |
|
528 | + $proArray[$keyval] = urldecode($valval); |
|
529 | + $NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString)); |
|
530 | + } |
|
531 | + return $proArray; |
|
532 | + } |
|
533 | + |
|
534 | + |
|
535 | + |
|
536 | + /** |
|
537 | + * @param array $PayPalResult |
|
538 | + * @return bool |
|
539 | + */ |
|
540 | + private function _APICallSuccessful($PayPalResult) |
|
541 | + { |
|
542 | + $approved = false; |
|
543 | + // check main response message from PayPal |
|
544 | + if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) { |
|
545 | + $ack = strtoupper($PayPalResult['ACK']); |
|
546 | + $approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false; |
|
547 | + } |
|
548 | + return $approved; |
|
549 | + } |
|
550 | + |
|
551 | + |
|
552 | + |
|
553 | + /** |
|
554 | + * @param $DataArray |
|
555 | + * @return array |
|
556 | + */ |
|
557 | + private function _GetErrors($DataArray) |
|
558 | + { |
|
559 | + $Errors = array(); |
|
560 | + $n = 0; |
|
561 | + while (isset($DataArray['L_ERRORCODE' . $n . ''])) { |
|
562 | + $LErrorCode = isset($DataArray['L_ERRORCODE' . $n . '']) ? $DataArray['L_ERRORCODE' . $n . ''] : ''; |
|
563 | + $LShortMessage = isset($DataArray['L_SHORTMESSAGE' . $n . '']) |
|
564 | + ? $DataArray['L_SHORTMESSAGE' . $n . ''] |
|
565 | + : ''; |
|
566 | + $LLongMessage = isset($DataArray['L_LONGMESSAGE' . $n . '']) |
|
567 | + ? $DataArray['L_LONGMESSAGE' . $n . ''] |
|
568 | + : ''; |
|
569 | + $LSeverityCode = isset($DataArray['L_SEVERITYCODE' . $n . '']) |
|
570 | + ? $DataArray['L_SEVERITYCODE' . $n . ''] |
|
571 | + : ''; |
|
572 | + $CurrentItem = array( |
|
573 | + 'L_ERRORCODE' => $LErrorCode, |
|
574 | + 'L_SHORTMESSAGE' => $LShortMessage, |
|
575 | + 'L_LONGMESSAGE' => $LLongMessage, |
|
576 | + 'L_SEVERITYCODE' => $LSeverityCode, |
|
577 | + ); |
|
578 | + array_push($Errors, $CurrentItem); |
|
579 | + $n++; |
|
580 | + } |
|
581 | + return $Errors; |
|
582 | + } |
|
583 | + |
|
584 | + |
|
585 | + |
|
586 | + /** |
|
587 | + * nothing to see here... move along.... |
|
588 | + * |
|
589 | + * @access protected |
|
590 | + * @param $Errors |
|
591 | + * @return string |
|
592 | + */ |
|
593 | + private function _DisplayErrors($Errors) |
|
594 | + { |
|
595 | + $error = ''; |
|
596 | + foreach ($Errors as $ErrorVar => $ErrorVal) { |
|
597 | + $CurrentError = $Errors[$ErrorVar]; |
|
598 | + foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) { |
|
599 | + $CurrentVarName = ''; |
|
600 | + if ($CurrentErrorVar == 'L_ERRORCODE') { |
|
601 | + $CurrentVarName = 'Error Code'; |
|
602 | + } elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') { |
|
603 | + $CurrentVarName = 'Short Message'; |
|
604 | + } elseif ($CurrentErrorVar == 'L_LONGMESSAGE') { |
|
605 | + $CurrentVarName = 'Long Message'; |
|
606 | + } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') { |
|
607 | + $CurrentVarName = 'Severity Code'; |
|
608 | + } |
|
609 | + $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal; |
|
610 | + } |
|
611 | + } |
|
612 | + return $error; |
|
613 | + } |
|
614 | 614 | } |
615 | 615 | // End of file EEG_Paypal_Pro.gateway.php |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('No direct script access allowed'); |
4 | 4 | } |
5 | 5 | |
@@ -91,13 +91,13 @@ discard block |
||
91 | 91 | public function do_direct_payment($payment, $billing_info = null) |
92 | 92 | { |
93 | 93 | $transaction = $payment->transaction(); |
94 | - if (! $transaction instanceof EEI_Transaction) { |
|
94 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
95 | 95 | throw new EE_Error( |
96 | 96 | esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso') |
97 | 97 | ); |
98 | 98 | } |
99 | 99 | $primary_registrant = $transaction->primary_registration(); |
100 | - if (! $primary_registrant instanceof EEI_Registration) { |
|
100 | + if ( ! $primary_registrant instanceof EEI_Registration) { |
|
101 | 101 | throw new EE_Error( |
102 | 102 | esc_html__( |
103 | 103 | 'No primary registration on transaction while paying with PayPal Pro.', |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | ); |
107 | 107 | } |
108 | 108 | $attendee = $primary_registrant->attendee(); |
109 | - if (! $attendee instanceof EEI_Attendee) { |
|
109 | + if ( ! $attendee instanceof EEI_Attendee) { |
|
110 | 110 | throw new EE_Error( |
111 | 111 | esc_html__( |
112 | 112 | 'No attendee on primary registration while paying with PayPal Pro.', |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | // Required. Credit card number. No spaces or punctuation. |
203 | 203 | 'acct' => $billing_info['credit_card'], |
204 | 204 | // Required. Credit card expiration date. Format is MMYYYY |
205 | - 'expdate' => $billing_info['exp_month'] . $billing_info['exp_year'], |
|
205 | + 'expdate' => $billing_info['exp_month'].$billing_info['exp_year'], |
|
206 | 206 | // Requirements determined by your PayPal account settings. Security digits for credit card. |
207 | 207 | 'cvv2' => $billing_info['cvv'], |
208 | 208 | ); |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | $ShippingAddress = array( |
255 | 255 | 'shiptoname' => substr($use_registration_address_info |
256 | 256 | ? $attendee->full_name() |
257 | - : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32), |
|
257 | + : $billing_info['first_name'].' '.$billing_info['last_name'], 0, 32), |
|
258 | 258 | 'shiptostreet' => substr($use_registration_address_info |
259 | 259 | ? $attendee->address() |
260 | 260 | : $billing_info['address'], 0, 100), |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | 'currencycode' => $payment->currency_code(), |
284 | 284 | // Required if you include itemized cart details. (L_AMTn, etc.) |
285 | 285 | //Subtotal of items not including S&H, or tax. |
286 | - 'itemamt' => $this->format_currency($item_amount),// |
|
286 | + 'itemamt' => $this->format_currency($item_amount), // |
|
287 | 287 | // Total shipping costs for the order. If you specify shippingamt, you must also specify itemamt. |
288 | 288 | 'shippingamt' => '', |
289 | 289 | // Total handling costs for the order. If you specify handlingamt, you must also specify itemamt. |
@@ -296,10 +296,10 @@ discard block |
||
296 | 296 | // Free-form field for your own use. 256 char max. |
297 | 297 | 'custom' => $primary_registrant ? $primary_registrant->ID() : '', |
298 | 298 | // Your own invoice or tracking number |
299 | - 'invnum' => wp_generate_password(12, false),//$transaction->ID(), |
|
299 | + 'invnum' => wp_generate_password(12, false), //$transaction->ID(), |
|
300 | 300 | // URL for receiving Instant Payment Notifications. This overrides what your profile is set to use. |
301 | 301 | 'notifyurl' => '', |
302 | - 'buttonsource' => 'EventEspresso_SP',//EE will blow up if you change this |
|
302 | + 'buttonsource' => 'EventEspresso_SP', //EE will blow up if you change this |
|
303 | 303 | ); |
304 | 304 | // Wrap all data arrays into a single, "master" array which will be passed into the class function. |
305 | 305 | $PayPalRequestData = array( |
@@ -409,32 +409,32 @@ discard block |
||
409 | 409 | // DP Fields |
410 | 410 | $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array(); |
411 | 411 | foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) { |
412 | - $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal); |
|
412 | + $DPFieldsNVP .= '&'.strtoupper($DPFieldsVar).'='.urlencode($DPFieldsVal); |
|
413 | 413 | } |
414 | 414 | // CC Details Fields |
415 | 415 | $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array(); |
416 | 416 | foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) { |
417 | - $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal); |
|
417 | + $CCDetailsNVP .= '&'.strtoupper($CCDetailsVar).'='.urlencode($CCDetailsVal); |
|
418 | 418 | } |
419 | 419 | // PayerInfo Type Fields |
420 | 420 | $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array(); |
421 | 421 | foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) { |
422 | - $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal); |
|
422 | + $PayerInfoNVP .= '&'.strtoupper($PayerInfoVar).'='.urlencode($PayerInfoVal); |
|
423 | 423 | } |
424 | 424 | // Payer Name Fields |
425 | 425 | $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array(); |
426 | 426 | foreach ($PayerName as $PayerNameVar => $PayerNameVal) { |
427 | - $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal); |
|
427 | + $PayerNameNVP .= '&'.strtoupper($PayerNameVar).'='.urlencode($PayerNameVal); |
|
428 | 428 | } |
429 | 429 | // Address Fields (Billing) |
430 | 430 | $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array(); |
431 | 431 | foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) { |
432 | - $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal); |
|
432 | + $BillingAddressNVP .= '&'.strtoupper($BillingAddressVar).'='.urlencode($BillingAddressVal); |
|
433 | 433 | } |
434 | 434 | // Payment Details Type Fields |
435 | 435 | $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array(); |
436 | 436 | foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) { |
437 | - $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal); |
|
437 | + $PaymentDetailsNVP .= '&'.strtoupper($PaymentDetailsVar).'='.urlencode($PaymentDetailsVal); |
|
438 | 438 | } |
439 | 439 | // Payment Details Item Type Fields |
440 | 440 | $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array(); |
@@ -442,19 +442,19 @@ discard block |
||
442 | 442 | foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) { |
443 | 443 | $CurrentItem = $OrderItems[$OrderItemsVar]; |
444 | 444 | foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) { |
445 | - $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal); |
|
445 | + $OrderItemsNVP .= '&'.strtoupper($CurrentItemVar).$n.'='.urlencode($CurrentItemVal); |
|
446 | 446 | } |
447 | 447 | $n++; |
448 | 448 | } |
449 | 449 | // Ship To Address Fields |
450 | 450 | $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array(); |
451 | 451 | foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) { |
452 | - $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal); |
|
452 | + $ShippingAddressNVP .= '&'.strtoupper($ShippingAddressVar).'='.urlencode($ShippingAddressVal); |
|
453 | 453 | } |
454 | 454 | // 3D Secure Fields |
455 | 455 | $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array(); |
456 | 456 | foreach ($Secure3D as $Secure3DVar => $Secure3DVal) { |
457 | - $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal); |
|
457 | + $Secure3DNVP .= '&'.strtoupper($Secure3DVar).'='.urlencode($Secure3DVal); |
|
458 | 458 | } |
459 | 459 | // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string |
460 | 460 | $NVPRequest = 'USER=' |
@@ -558,16 +558,16 @@ discard block |
||
558 | 558 | { |
559 | 559 | $Errors = array(); |
560 | 560 | $n = 0; |
561 | - while (isset($DataArray['L_ERRORCODE' . $n . ''])) { |
|
562 | - $LErrorCode = isset($DataArray['L_ERRORCODE' . $n . '']) ? $DataArray['L_ERRORCODE' . $n . ''] : ''; |
|
563 | - $LShortMessage = isset($DataArray['L_SHORTMESSAGE' . $n . '']) |
|
564 | - ? $DataArray['L_SHORTMESSAGE' . $n . ''] |
|
561 | + while (isset($DataArray['L_ERRORCODE'.$n.''])) { |
|
562 | + $LErrorCode = isset($DataArray['L_ERRORCODE'.$n.'']) ? $DataArray['L_ERRORCODE'.$n.''] : ''; |
|
563 | + $LShortMessage = isset($DataArray['L_SHORTMESSAGE'.$n.'']) |
|
564 | + ? $DataArray['L_SHORTMESSAGE'.$n.''] |
|
565 | 565 | : ''; |
566 | - $LLongMessage = isset($DataArray['L_LONGMESSAGE' . $n . '']) |
|
567 | - ? $DataArray['L_LONGMESSAGE' . $n . ''] |
|
566 | + $LLongMessage = isset($DataArray['L_LONGMESSAGE'.$n.'']) |
|
567 | + ? $DataArray['L_LONGMESSAGE'.$n.''] |
|
568 | 568 | : ''; |
569 | - $LSeverityCode = isset($DataArray['L_SEVERITYCODE' . $n . '']) |
|
570 | - ? $DataArray['L_SEVERITYCODE' . $n . ''] |
|
569 | + $LSeverityCode = isset($DataArray['L_SEVERITYCODE'.$n.'']) |
|
570 | + ? $DataArray['L_SEVERITYCODE'.$n.''] |
|
571 | 571 | : ''; |
572 | 572 | $CurrentItem = array( |
573 | 573 | 'L_ERRORCODE' => $LErrorCode, |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') { |
607 | 607 | $CurrentVarName = 'Severity Code'; |
608 | 608 | } |
609 | - $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal; |
|
609 | + $error .= '<br />'.$CurrentVarName.': '.$CurrentErrorVal; |
|
610 | 610 | } |
611 | 611 | } |
612 | 612 | return $error; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | |
6 | 6 | /** |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * |
26 | 26 | * ------------------------------------------------------------------------ |
27 | 27 | */ |
28 | -class EE_PMT_Invoice extends EE_PMT_Base{ |
|
28 | +class EE_PMT_Invoice extends EE_PMT_Base { |
|
29 | 29 | |
30 | 30 | |
31 | 31 | |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | public function __construct($pm_instance = NULL) { |
38 | 38 | $this->_pretty_name = esc_html__("Invoice", 'event_espresso'); |
39 | 39 | $this->_default_description = sprintf( |
40 | - esc_html__( 'After clicking "Finalize Registration", you will be given instructions on how to access your invoice and complete your payment.%sPlease note that event spaces will not be reserved until payment is received in full, and any remaining tickets could be sold to others in the meantime.', 'event_espresso' ), |
|
40 | + esc_html__('After clicking "Finalize Registration", you will be given instructions on how to access your invoice and complete your payment.%sPlease note that event spaces will not be reserved until payment is received in full, and any remaining tickets could be sold to others in the meantime.', 'event_espresso'), |
|
41 | 41 | '<br />' |
42 | 42 | ); |
43 | 43 | parent::__construct($pm_instance); |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * @param \EE_Transaction $transaction |
52 | 52 | * @return NULL |
53 | 53 | */ |
54 | - public function generate_new_billing_form( EE_Transaction $transaction = NULL ) { |
|
54 | + public function generate_new_billing_form(EE_Transaction $transaction = NULL) { |
|
55 | 55 | return NULL; |
56 | 56 | } |
57 | 57 | |
@@ -64,53 +64,53 @@ discard block |
||
64 | 64 | public function generate_new_settings_form() { |
65 | 65 | $pdf_payee_input_name = 'pdf_payee_name'; |
66 | 66 | $confirmation_text_input_name = 'page_confirmation_text'; |
67 | - $form = new EE_Payment_Method_Form(array( |
|
67 | + $form = new EE_Payment_Method_Form(array( |
|
68 | 68 | // 'payment_method_type' => $this, |
69 | 69 | 'extra_meta_inputs'=>array( |
70 | 70 | $pdf_payee_input_name => new EE_Text_Input(array( |
71 | - 'html_label_text' => sprintf( esc_html__( 'Payee Name %s', 'event_espresso' ), $this->get_help_tab_link()) |
|
71 | + 'html_label_text' => sprintf(esc_html__('Payee Name %s', 'event_espresso'), $this->get_help_tab_link()) |
|
72 | 72 | )), |
73 | 73 | 'pdf_payee_email' => new EE_Email_Input(array( |
74 | - 'html_label_text' => sprintf( esc_html__( 'Payee Email %s', 'event_espresso' ), $this->get_help_tab_link()), |
|
74 | + 'html_label_text' => sprintf(esc_html__('Payee Email %s', 'event_espresso'), $this->get_help_tab_link()), |
|
75 | 75 | )), |
76 | 76 | 'pdf_payee_tax_number' => new EE_Text_Input(array( |
77 | - 'html_label_text' => sprintf( esc_html__( 'Payee Tax Number %s', 'event_espresso' ), $this->get_help_tab_link()), |
|
77 | + 'html_label_text' => sprintf(esc_html__('Payee Tax Number %s', 'event_espresso'), $this->get_help_tab_link()), |
|
78 | 78 | )), |
79 | - 'pdf_payee_address' => new EE_Text_Area_Input( array( |
|
80 | - 'html_label_text' => sprintf( esc_html__( 'Payee Address %s', 'event_espresso' ), $this->get_help_tab_link() ), |
|
81 | - 'validation_strategies' => array( new EE_Full_HTML_Validation_Strategy() ), |
|
79 | + 'pdf_payee_address' => new EE_Text_Area_Input(array( |
|
80 | + 'html_label_text' => sprintf(esc_html__('Payee Address %s', 'event_espresso'), $this->get_help_tab_link()), |
|
81 | + 'validation_strategies' => array(new EE_Full_HTML_Validation_Strategy()), |
|
82 | 82 | )), |
83 | 83 | 'pdf_instructions'=>new EE_Text_Area_Input(array( |
84 | - 'html_label_text'=> sprintf(esc_html__("Instructions %s", "event_espresso"), $this->get_help_tab_link()), |
|
84 | + 'html_label_text'=> sprintf(esc_html__("Instructions %s", "event_espresso"), $this->get_help_tab_link()), |
|
85 | 85 | 'default'=> esc_html__("Please send this invoice with payment attached to the address above, or use the payment link below. Payment must be received within 48 hours of event date.", 'event_espresso'), |
86 | - 'validation_strategies' => array( new EE_Full_HTML_Validation_Strategy() ), |
|
86 | + 'validation_strategies' => array(new EE_Full_HTML_Validation_Strategy()), |
|
87 | 87 | )), |
88 | 88 | 'pdf_logo_image'=>new EE_Admin_File_Uploader_Input(array( |
89 | - 'html_label_text'=> sprintf(esc_html__("Logo Image %s", "event_espresso"), $this->get_help_tab_link()), |
|
89 | + 'html_label_text'=> sprintf(esc_html__("Logo Image %s", "event_espresso"), $this->get_help_tab_link()), |
|
90 | 90 | 'default'=> EE_Config::instance()->organization->logo_url, |
91 | 91 | 'html_help_text'=> esc_html__("(Logo for the top left of the invoice)", 'event_espresso'), |
92 | 92 | )), |
93 | 93 | $confirmation_text_input_name =>new EE_Text_Area_Input(array( |
94 | - 'html_label_text'=> sprintf(esc_html__("Confirmation Text %s", "event_espresso"), $this->get_help_tab_link()), |
|
94 | + 'html_label_text'=> sprintf(esc_html__("Confirmation Text %s", "event_espresso"), $this->get_help_tab_link()), |
|
95 | 95 | 'default'=> esc_html__("Payment must be received within 48 hours of event date. Details about where to send the payment are included on the invoice.", 'event_espresso'), |
96 | - 'validation_strategies' => array( new EE_Full_HTML_Validation_Strategy() ), |
|
96 | + 'validation_strategies' => array(new EE_Full_HTML_Validation_Strategy()), |
|
97 | 97 | )), |
98 | 98 | 'page_extra_info'=>new EE_Text_Area_Input(array( |
99 | - 'html_label_text'=> sprintf(esc_html__("Extra Info %s", "event_espresso"), $this->get_help_tab_link()), |
|
100 | - 'validation_strategies' => array( new EE_Full_HTML_Validation_Strategy() ), |
|
99 | + 'html_label_text'=> sprintf(esc_html__("Extra Info %s", "event_espresso"), $this->get_help_tab_link()), |
|
100 | + 'validation_strategies' => array(new EE_Full_HTML_Validation_Strategy()), |
|
101 | 101 | )), |
102 | 102 | ), |
103 | 103 | 'include'=>array( |
104 | - 'PMD_ID', 'PMD_name','PMD_desc','PMD_admin_name','PMD_admin_desc', 'PMD_type','PMD_slug', 'PMD_open_by_default','PMD_button_url','PMD_scope','Currency','PMD_order', |
|
105 | - $pdf_payee_input_name, 'pdf_payee_email', 'pdf_payee_tax_number', 'pdf_payee_address', 'pdf_instructions','pdf_logo_image', |
|
104 | + 'PMD_ID', 'PMD_name', 'PMD_desc', 'PMD_admin_name', 'PMD_admin_desc', 'PMD_type', 'PMD_slug', 'PMD_open_by_default', 'PMD_button_url', 'PMD_scope', 'Currency', 'PMD_order', |
|
105 | + $pdf_payee_input_name, 'pdf_payee_email', 'pdf_payee_tax_number', 'pdf_payee_address', 'pdf_instructions', 'pdf_logo_image', |
|
106 | 106 | $confirmation_text_input_name, 'page_extra_info'), |
107 | 107 | )); |
108 | 108 | $form->add_subsections( |
109 | - array( 'header1' => new EE_Form_Section_HTML_From_Template( 'payment_methods/Invoice/templates/invoice_settings_header_display.template.php' )), |
|
109 | + array('header1' => new EE_Form_Section_HTML_From_Template('payment_methods/Invoice/templates/invoice_settings_header_display.template.php')), |
|
110 | 110 | $pdf_payee_input_name |
111 | 111 | ); |
112 | 112 | $form->add_subsections( |
113 | - array( 'header2'=>new EE_Form_Section_HTML_From_Template( 'payment_methods/Invoice/templates/invoice_settings_header_gateway.template.php' )), |
|
113 | + array('header2'=>new EE_Form_Section_HTML_From_Template('payment_methods/Invoice/templates/invoice_settings_header_gateway.template.php')), |
|
114 | 114 | $confirmation_text_input_name |
115 | 115 | ); |
116 | 116 | return $form; |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | * @see EE_PMT_Base::help_tabs_config() |
124 | 124 | * @return array |
125 | 125 | */ |
126 | - public function help_tabs_config(){ |
|
126 | + public function help_tabs_config() { |
|
127 | 127 | return array( |
128 | 128 | $this->get_help_tab_name() => array( |
129 | 129 | 'title' => esc_html__('Invoice Settings', 'event_espresso'), |
@@ -141,16 +141,16 @@ discard block |
||
141 | 141 | * @param \EE_Payment $payment |
142 | 142 | * @return string |
143 | 143 | */ |
144 | - public function payment_overview_content( EE_Payment $payment ){ |
|
144 | + public function payment_overview_content(EE_Payment $payment) { |
|
145 | 145 | return EEH_Template::locate_template( |
146 | - 'payment_methods' . DS . 'Invoice'. DS . 'templates'.DS.'invoice_payment_details_content.template.php', |
|
146 | + 'payment_methods'.DS.'Invoice'.DS.'templates'.DS.'invoice_payment_details_content.template.php', |
|
147 | 147 | array_merge( |
148 | 148 | array( |
149 | 149 | 'payment_method' => $this->_pm_instance, |
150 | 150 | 'payment' => $payment, |
151 | 151 | 'page_confirmation_text' => '', |
152 | 152 | 'page_extra_info' => '', |
153 | - 'invoice_url' => $payment->transaction()->primary_registration()->invoice_url( 'html' ) |
|
153 | + 'invoice_url' => $payment->transaction()->primary_registration()->invoice_url('html') |
|
154 | 154 | ), |
155 | 155 | $this->_pm_instance->all_extra_meta_array() |
156 | 156 | ) |
@@ -13,39 +13,39 @@ |
||
13 | 13 | trait BaseCoreAdmin |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * Core method for going to an Event Espresso Admin page. |
|
18 | - * @param string $page |
|
19 | - * @param string $action |
|
20 | - * @param string $additional_params |
|
21 | - */ |
|
22 | - public function amOnEventEspressoAdminPage($page = '', $action = '', $additional_params = '') |
|
23 | - { |
|
24 | - $this->actor()->amOnAdminPage(CoreAdmin::adminUrl($page, $action, $additional_params)); |
|
25 | - } |
|
16 | + /** |
|
17 | + * Core method for going to an Event Espresso Admin page. |
|
18 | + * @param string $page |
|
19 | + * @param string $action |
|
20 | + * @param string $additional_params |
|
21 | + */ |
|
22 | + public function amOnEventEspressoAdminPage($page = '', $action = '', $additional_params = '') |
|
23 | + { |
|
24 | + $this->actor()->amOnAdminPage(CoreAdmin::adminUrl($page, $action, $additional_params)); |
|
25 | + } |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * Helper method for returning an instance of the Actor. Intended to help with IDE fill out of methods. |
|
30 | - * @return \EventEspressoAcceptanceTester; |
|
31 | - */ |
|
32 | - protected function actor() |
|
33 | - { |
|
34 | - /** @var \EventEspressoAcceptanceTester $this */ |
|
35 | - return $this; |
|
36 | - } |
|
28 | + /** |
|
29 | + * Helper method for returning an instance of the Actor. Intended to help with IDE fill out of methods. |
|
30 | + * @return \EventEspressoAcceptanceTester; |
|
31 | + */ |
|
32 | + protected function actor() |
|
33 | + { |
|
34 | + /** @var \EventEspressoAcceptanceTester $this */ |
|
35 | + return $this; |
|
36 | + } |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * Use this to set the per page option for a list table page. |
|
41 | - * Assumes you are on a page that has this field exposed. |
|
42 | - * @param int|string $per_page_value |
|
43 | - */ |
|
44 | - public function setPerPageOptionForScreen($per_page_value) |
|
45 | - { |
|
46 | - $this->actor()->click(CoreAdmin::WP_SCREEN_SETTINGS_LINK_SELECTOR); |
|
47 | - $this->actor()->fillField(CoreAdmin::WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR, $per_page_value); |
|
48 | - $this->actor()->click(CoreAdmin::WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR); |
|
49 | - $this->actor()->wait(8); |
|
50 | - } |
|
39 | + /** |
|
40 | + * Use this to set the per page option for a list table page. |
|
41 | + * Assumes you are on a page that has this field exposed. |
|
42 | + * @param int|string $per_page_value |
|
43 | + */ |
|
44 | + public function setPerPageOptionForScreen($per_page_value) |
|
45 | + { |
|
46 | + $this->actor()->click(CoreAdmin::WP_SCREEN_SETTINGS_LINK_SELECTOR); |
|
47 | + $this->actor()->fillField(CoreAdmin::WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR, $per_page_value); |
|
48 | + $this->actor()->click(CoreAdmin::WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR); |
|
49 | + $this->actor()->wait(8); |
|
50 | + } |
|
51 | 51 | } |
52 | 52 | \ No newline at end of file |
@@ -13,63 +13,63 @@ |
||
13 | 13 | class CoreAdmin |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - const URL_PREFIX = 'admin.php?page='; |
|
16 | + /** |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + const URL_PREFIX = 'admin.php?page='; |
|
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * This is the selector for the next page button on list tables. |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - const ADMIN_LIST_TABLE_NEXT_PAGE_CLASS = '.next-page'; |
|
22 | + /** |
|
23 | + * This is the selector for the next page button on list tables. |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + const ADMIN_LIST_TABLE_NEXT_PAGE_CLASS = '.next-page'; |
|
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * The selector for the search input submit button on list table pages |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - const LIST_TABLE_SEARCH_SUBMIT_SELECTOR = '#search-submit'; |
|
29 | + /** |
|
30 | + * The selector for the search input submit button on list table pages |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + const LIST_TABLE_SEARCH_SUBMIT_SELECTOR = '#search-submit'; |
|
34 | 34 | |
35 | 35 | |
36 | - /** |
|
37 | - * Selector for the screen options dropdown. |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - const WP_SCREEN_SETTINGS_LINK_SELECTOR = '#show-settings-link'; |
|
36 | + /** |
|
37 | + * Selector for the screen options dropdown. |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + const WP_SCREEN_SETTINGS_LINK_SELECTOR = '#show-settings-link'; |
|
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * Selector for the per page field setting selector (found within screen options dropdown) |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - const WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR = '.screen-per-page'; |
|
43 | + /** |
|
44 | + * Selector for the per page field setting selector (found within screen options dropdown) |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + const WP_SCREEN_SETTINGS_PER_PAGE_FIELD_SELECTOR = '.screen-per-page'; |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * Selector for apply screen options settings. |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - const WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR = '#screen-options-apply'; |
|
50 | + /** |
|
51 | + * Selector for apply screen options settings. |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + const WP_SCREEN_OPTIONS_APPLY_SETTINGS_BUTTON_SELECTOR = '#screen-options-apply'; |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * Get the EE admin url for the given properties. |
|
59 | - * Note, this is JUST the endpoint for the admin route. It is expected that the actor/test would be calling this |
|
60 | - * with `amOnAdminPage` action. |
|
61 | - * |
|
62 | - * @param string $page |
|
63 | - * @param string $action |
|
64 | - * @param string $additional_params |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public static function adminUrl($page = 'espresso_events', $action = 'default', $additional_params = '') |
|
68 | - { |
|
69 | - $url = self::URL_PREFIX . $page; |
|
70 | - $url .= $action ? '&action=' . $action : ''; |
|
71 | - $url .= $additional_params ? '&' . ltrim('&', ltrim('?', $additional_params)) : ''; |
|
72 | - return $url; |
|
73 | - } |
|
57 | + /** |
|
58 | + * Get the EE admin url for the given properties. |
|
59 | + * Note, this is JUST the endpoint for the admin route. It is expected that the actor/test would be calling this |
|
60 | + * with `amOnAdminPage` action. |
|
61 | + * |
|
62 | + * @param string $page |
|
63 | + * @param string $action |
|
64 | + * @param string $additional_params |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public static function adminUrl($page = 'espresso_events', $action = 'default', $additional_params = '') |
|
68 | + { |
|
69 | + $url = self::URL_PREFIX . $page; |
|
70 | + $url .= $action ? '&action=' . $action : ''; |
|
71 | + $url .= $additional_params ? '&' . ltrim('&', ltrim('?', $additional_params)) : ''; |
|
72 | + return $url; |
|
73 | + } |
|
74 | 74 | |
75 | 75 | } |
76 | 76 | \ No newline at end of file |
@@ -14,136 +14,136 @@ |
||
14 | 14 | class EventsAdmin extends CoreAdmin |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Selector for the Add new Event button in the admin. |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - const ADD_NEW_EVENT_BUTTON_SELECTOR = '#add-new-event'; |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * Selector for the Event Title field in the event editor |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - const EVENT_EDITOR_TITLE_FIELD_SELECTOR = "//input[@id='title']"; |
|
29 | - |
|
30 | - /** |
|
31 | - * Selector for the publish submit button in the event editor. |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - const EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR = "#publish"; |
|
35 | - |
|
36 | - /** |
|
37 | - * Selector for the view link after publishing an event. |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - const EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR = "//div[@id='message']/p/a"; |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * Selector for the ID of the event in the event editor |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - const EVENT_EDITOR_EVT_ID_SELECTOR = "//input[@id='post_ID']"; |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * Selector for the search input on the event list table page. |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - const EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR = '#toplevel_page_espresso_events-search-input'; |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * @param string $additional_params |
|
60 | - * @return string |
|
61 | - */ |
|
62 | - public static function defaultEventsListTableUrl($additional_params = '') |
|
63 | - { |
|
64 | - return self::adminUrl('espresso_events', 'default', $additional_params); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * The selector for the DTTname field for the given row in the event editor. |
|
70 | - * @param int $row_number |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public static function eventEditorDatetimeNameFieldSelector($row_number = 1) |
|
74 | - { |
|
75 | - return self::eventEditorDatetimeFieldSelectorForField('DTT_name', $row_number); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * The selector for the DTT_EVT_start field for the given row in the event editor.d |
|
81 | - * @param int $row_number |
|
82 | - * @return string |
|
83 | - */ |
|
84 | - public static function eventEditorDatetimeStartDateFieldSelector($row_number = 1) |
|
85 | - { |
|
86 | - return self::eventEditorDatetimeFieldSelectorForField('DTT_EVT_start', $row_number); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * Wrapper for getting the selector for a given field and given row of a datetime in the event editor. |
|
92 | - * |
|
93 | - * @param string $field_name |
|
94 | - * @param int $row_number |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - public static function eventEditorDatetimeFieldSelectorForField($field_name, $row_number = 1) |
|
98 | - { |
|
99 | - return "//input[@id='event-datetime-$field_name-$row_number']"; |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * The selector for the TKT_name field for the given display row in the event editor. |
|
105 | - * @param int $row_number |
|
106 | - * @return string |
|
107 | - */ |
|
108 | - public static function eventEditorTicketNameFieldSelector($row_number = 1) |
|
109 | - { |
|
110 | - return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_name', $row_number); |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor. |
|
116 | - * @param $field_name |
|
117 | - * @param int $row_number |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - public static function eventEditorTicketFieldSelectorForFieldInDisplayRow($field_name, $row_number = 1) |
|
121 | - { |
|
122 | - return "//tr[@id='display-ticketrow-$row_number']/td[2]/input[@class='edit-ticket-$field_name ee-large-text-inp']"; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * Returns the selector for the event title edit link in the events list table for the given Event Title. |
|
128 | - * @param string $event_title |
|
129 | - * @return string |
|
130 | - */ |
|
131 | - public static function eventListTableEventTitleEditLinkSelectorForTitle($event_title) |
|
132 | - { |
|
133 | - return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - public static function eventListTableEventIdSelectorForTitle($event_title) |
|
138 | - { |
|
139 | - return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
140 | - . "//ancestor::tr/th[contains(@class, 'check-column')]/input"; |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - public static function eventListTableEventTitleViewLinkSelectorForTitle($event_title) |
|
145 | - { |
|
146 | - return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
147 | - . "//ancestor::td//span[@class='view']/a"; |
|
148 | - } |
|
17 | + /** |
|
18 | + * Selector for the Add new Event button in the admin. |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + const ADD_NEW_EVENT_BUTTON_SELECTOR = '#add-new-event'; |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * Selector for the Event Title field in the event editor |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + const EVENT_EDITOR_TITLE_FIELD_SELECTOR = "//input[@id='title']"; |
|
29 | + |
|
30 | + /** |
|
31 | + * Selector for the publish submit button in the event editor. |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + const EVENT_EDITOR_PUBLISH_BUTTON_SELECTOR = "#publish"; |
|
35 | + |
|
36 | + /** |
|
37 | + * Selector for the view link after publishing an event. |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + const EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR = "//div[@id='message']/p/a"; |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * Selector for the ID of the event in the event editor |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + const EVENT_EDITOR_EVT_ID_SELECTOR = "//input[@id='post_ID']"; |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * Selector for the search input on the event list table page. |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + const EVENT_LIST_TABLE_SEARCH_INPUT_SELECTOR = '#toplevel_page_espresso_events-search-input'; |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * @param string $additional_params |
|
60 | + * @return string |
|
61 | + */ |
|
62 | + public static function defaultEventsListTableUrl($additional_params = '') |
|
63 | + { |
|
64 | + return self::adminUrl('espresso_events', 'default', $additional_params); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * The selector for the DTTname field for the given row in the event editor. |
|
70 | + * @param int $row_number |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public static function eventEditorDatetimeNameFieldSelector($row_number = 1) |
|
74 | + { |
|
75 | + return self::eventEditorDatetimeFieldSelectorForField('DTT_name', $row_number); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * The selector for the DTT_EVT_start field for the given row in the event editor.d |
|
81 | + * @param int $row_number |
|
82 | + * @return string |
|
83 | + */ |
|
84 | + public static function eventEditorDatetimeStartDateFieldSelector($row_number = 1) |
|
85 | + { |
|
86 | + return self::eventEditorDatetimeFieldSelectorForField('DTT_EVT_start', $row_number); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * Wrapper for getting the selector for a given field and given row of a datetime in the event editor. |
|
92 | + * |
|
93 | + * @param string $field_name |
|
94 | + * @param int $row_number |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + public static function eventEditorDatetimeFieldSelectorForField($field_name, $row_number = 1) |
|
98 | + { |
|
99 | + return "//input[@id='event-datetime-$field_name-$row_number']"; |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * The selector for the TKT_name field for the given display row in the event editor. |
|
105 | + * @param int $row_number |
|
106 | + * @return string |
|
107 | + */ |
|
108 | + public static function eventEditorTicketNameFieldSelector($row_number = 1) |
|
109 | + { |
|
110 | + return self::eventEditorTicketFieldSelectorForFieldInDisplayRow('TKT_name', $row_number); |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * Wrapper for getting the selector for a given field and given display row of a ticket in the event editor. |
|
116 | + * @param $field_name |
|
117 | + * @param int $row_number |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + public static function eventEditorTicketFieldSelectorForFieldInDisplayRow($field_name, $row_number = 1) |
|
121 | + { |
|
122 | + return "//tr[@id='display-ticketrow-$row_number']/td[2]/input[@class='edit-ticket-$field_name ee-large-text-inp']"; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * Returns the selector for the event title edit link in the events list table for the given Event Title. |
|
128 | + * @param string $event_title |
|
129 | + * @return string |
|
130 | + */ |
|
131 | + public static function eventListTableEventTitleEditLinkSelectorForTitle($event_title) |
|
132 | + { |
|
133 | + return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']"; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + public static function eventListTableEventIdSelectorForTitle($event_title) |
|
138 | + { |
|
139 | + return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
140 | + . "//ancestor::tr/th[contains(@class, 'check-column')]/input"; |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + public static function eventListTableEventTitleViewLinkSelectorForTitle($event_title) |
|
145 | + { |
|
146 | + return "//td[contains(@class, 'column-name')]/strong/a[text()='$event_title']" |
|
147 | + . "//ancestor::td//span[@class='view']/a"; |
|
148 | + } |
|
149 | 149 | } |
150 | 150 | \ No newline at end of file |