Completed
Branch 973/fix-visible-recaptcha (0580c7)
by
unknown
03:03 queued 30s
created
core/libraries/payment_methods/EE_Payment_Method_Manager.lib.php 2 patches
Indentation   +557 added lines, -557 removed lines patch added patch discarded remove patch
@@ -17,561 +17,561 @@
 block discarded – undo
17 17
 class EE_Payment_Method_Manager implements ResettableInterface
18 18
 {
19 19
 
20
-    /**
21
-     * prefix added to all payment method capabilities names
22
-     */
23
-    const   CAPABILITIES_PREFIX = 'ee_payment_method_';
24
-
25
-    /**
26
-     * @var EE_Payment_Method_Manager $_instance
27
-     */
28
-    private static $_instance;
29
-
30
-    /**
31
-     * @var boolean
32
-     */
33
-    protected $payment_method_caps_initialized = false;
34
-
35
-    /**
36
-     * @var array keys are class names without 'EE_PMT_', values are their filepaths
37
-     */
38
-    protected $_payment_method_types = array();
39
-
40
-    /**
41
-     * @var EE_PMT_Base[]
42
-     */
43
-    protected $payment_method_objects = array();
44
-
45
-
46
-    /**
47
-     * EE_Payment_Method_Manager constructor.
48
-     *
49
-     * @throws EE_Error
50
-     * @throws DomainException
51
-     */
52
-    public function __construct()
53
-    {
54
-        // if in admin lets ensure caps are set.
55
-        if (is_admin()) {
56
-            $this->_register_payment_methods();
57
-            // set them immediately
58
-            $this->initializePaymentMethodCaps();
59
-            // plus any time they get reset
60
-            add_filter(
61
-                'FHEE__EE_Capabilities__addCaps__capabilities_to_add',
62
-                array($this, 'addPaymentMethodCapsDuringReset')
63
-            );
64
-        }
65
-    }
66
-
67
-
68
-    /**
69
-     * @singleton method used to instantiate class object
70
-     * @return EE_Payment_Method_Manager instance
71
-     * @throws DomainException
72
-     * @throws EE_Error
73
-     */
74
-    public static function instance()
75
-    {
76
-        // check if class object is instantiated, and instantiated properly
77
-        if (! self::$_instance instanceof EE_Payment_Method_Manager) {
78
-            EE_Registry::instance()->load_lib('PMT_Base');
79
-            self::$_instance = new self();
80
-        }
81
-        return self::$_instance;
82
-    }
83
-
84
-
85
-    /**
86
-     * Resets the instance and returns a new one
87
-     *
88
-     * @return EE_Payment_Method_Manager
89
-     * @throws DomainException
90
-     * @throws EE_Error
91
-     */
92
-    public static function reset()
93
-    {
94
-        self::$_instance = null;
95
-        return self::instance();
96
-    }
97
-
98
-
99
-    /**
100
-     * If necessary, re-register payment methods
101
-     *
102
-     * @param boolean $force_recheck whether to recheck for payment method types,
103
-     *                               or just re-use the PMTs we found last time we checked during this request (if
104
-     *                               we have not yet checked during this request, then we need to check anyways)
105
-     */
106
-    public function maybe_register_payment_methods($force_recheck = false)
107
-    {
108
-        if (! $this->_payment_method_types || $force_recheck) {
109
-            $this->_register_payment_methods();
110
-        }
111
-    }
112
-
113
-
114
-    /**
115
-     * register_payment_methods
116
-     *
117
-     * @return array
118
-     */
119
-    protected function _register_payment_methods()
120
-    {
121
-        // grab list of installed modules
122
-        $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
123
-        // filter list of modules to register
124
-        $pm_to_register = apply_filters(
125
-            'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
126
-            $pm_to_register
127
-        );
128
-        // remove any duplicates if that should happen for some reason
129
-        $pm_to_register = array_unique($pm_to_register);
130
-        // loop through folders
131
-        foreach ($pm_to_register as $pm_path) {
132
-            $this->register_payment_method($pm_path);
133
-        }
134
-        do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods');
135
-        // filter list of installed modules
136
-        // keep them organized alphabetically by the payment method type's name
137
-        ksort($this->_payment_method_types);
138
-        return apply_filters(
139
-            'FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods',
140
-            $this->_payment_method_types
141
-        );
142
-    }
143
-
144
-
145
-    /**
146
-     * register_payment_method- makes core aware of this payment method
147
-     *
148
-     * @param string $payment_method_path - full path up to and including payment method folder
149
-     * @return boolean
150
-     */
151
-    public function register_payment_method($payment_method_path = '')
152
-    {
153
-        do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path);
154
-        $module_ext = '.pm.php';
155
-        // make all separators match
156
-        $payment_method_path = rtrim(str_replace('/\\', '/', $payment_method_path), '/');
157
-        // grab and sanitize module name
158
-        $module_dir = basename($payment_method_path);
159
-        // create class name from module directory name
160
-        $module = str_replace(array('_', ' '), array(' ', '_'), $module_dir);
161
-        // add class prefix
162
-        $module_class = 'EE_PMT_' . $module;
163
-        // does the module exist ?
164
-        if (! is_readable($payment_method_path . '/' . $module_class . $module_ext)) {
165
-            $msg = sprintf(
166
-                esc_html__(
167
-                    'The requested %s payment method file could not be found or is not readable due to file permissions.',
168
-                    'event_espresso'
169
-                ),
170
-                $module
171
-            );
172
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
173
-            return false;
174
-        }
175
-        // load the module class file
176
-        require_once($payment_method_path . '/' . $module_class . $module_ext);
177
-        // verify that class exists
178
-        if (! class_exists($module_class)) {
179
-            $msg = sprintf(
180
-                esc_html__('The requested %s module class does not exist.', 'event_espresso'),
181
-                $module_class
182
-            );
183
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
184
-            return false;
185
-        }
186
-        // add to array of registered modules
187
-        $this->_payment_method_types[ $module ] = $payment_method_path . '/' . $module_class . $module_ext;
188
-        ksort($this->_payment_method_types);
189
-        return true;
190
-    }
191
-
192
-
193
-    /**
194
-     * Checks if a payment method has been registered, and if so includes it
195
-     *
196
-     * @param string  $payment_method_name like 'PayPal_Pro', (ie class name without the prefix 'EEPM_')
197
-     * @param boolean $force_recheck       whether to force re-checking for new payment method types
198
-     * @return boolean
199
-     */
200
-    public function payment_method_type_exists($payment_method_name, $force_recheck = false)
201
-    {
202
-        if (
203
-            $force_recheck
204
-            || ! is_array($this->_payment_method_types)
205
-            || ! isset($this->_payment_method_types[ $payment_method_name ])
206
-        ) {
207
-            $this->maybe_register_payment_methods($force_recheck);
208
-        }
209
-        if (isset($this->_payment_method_types[ $payment_method_name ])) {
210
-            require_once($this->_payment_method_types[ $payment_method_name ]);
211
-            return true;
212
-        }
213
-        return false;
214
-    }
215
-
216
-
217
-    /**
218
-     * Returns all the class names of the various payment method types
219
-     *
220
-     * @param boolean $with_prefixes TRUE: get payment method type class names; false just their 'names'
221
-     *                               (what you'd find in wp_esp_payment_method.PMD_type)
222
-     * @param boolean $force_recheck whether to force re-checking for new payment method types
223
-     * @return array
224
-     */
225
-    public function payment_method_type_names($with_prefixes = false, $force_recheck = false)
226
-    {
227
-        $this->maybe_register_payment_methods($force_recheck);
228
-        if ($with_prefixes) {
229
-            $classnames = array_keys($this->_payment_method_types);
230
-            $payment_methods = array();
231
-            foreach ($classnames as $classname) {
232
-                $payment_methods[] = $this->payment_method_class_from_type($classname);
233
-            }
234
-            return $payment_methods;
235
-        }
236
-        return array_keys($this->_payment_method_types);
237
-    }
238
-
239
-
240
-    /**
241
-     * Gets an object of each payment method type, none of which are bound to a
242
-     * payment method instance
243
-     *
244
-     * @param boolean $force_recheck whether to force re-checking for new payment method types
245
-     * @return EE_PMT_Base[]
246
-     */
247
-    public function payment_method_types($force_recheck = false)
248
-    {
249
-        if ($force_recheck || empty($this->payment_method_objects)) {
250
-            $this->maybe_register_payment_methods($force_recheck);
251
-            foreach ($this->payment_method_type_names(true) as $classname) {
252
-                if (! isset($this->payment_method_objects[ $classname ])) {
253
-                    $this->payment_method_objects[ $classname ] = new $classname();
254
-                }
255
-            }
256
-        }
257
-        return $this->payment_method_objects;
258
-    }
259
-
260
-
261
-    /**
262
-     * Changes the payment method's class name into the payment method type's name
263
-     * (as used on the payment method's table's PMD_type field)
264
-     *
265
-     * @param string $classname
266
-     * @return string
267
-     */
268
-    public function payment_method_type_sans_class_prefix($classname)
269
-    {
270
-        return str_replace('EE_PMT_', '', $classname);
271
-    }
272
-
273
-
274
-    /**
275
-     * Does the opposite of payment-method_type_sans_prefix
276
-     *
277
-     * @param string $type
278
-     * @return string
279
-     */
280
-    public function payment_method_class_from_type($type)
281
-    {
282
-        return 'EE_PMT_' . $type;
283
-    }
284
-
285
-
286
-    /**
287
-     * Activates a payment method of the given type.
288
-     *
289
-     * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice'
290
-     * @return EE_Payment_Method
291
-     * @throws InvalidDataTypeException
292
-     * @throws EE_Error
293
-     */
294
-    public function activate_a_payment_method_of_type($payment_method_type)
295
-    {
296
-        $this->maybe_register_payment_methods();
297
-        $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
298
-        if (! $payment_method instanceof EE_Payment_Method) {
299
-            $pm_type_class = $this->payment_method_class_from_type($payment_method_type);
300
-            if (class_exists($pm_type_class)) {
301
-                /** @var $pm_type_obj EE_PMT_Base */
302
-                $pm_type_obj = new $pm_type_class();
303
-                $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
304
-                if (! $payment_method) {
305
-                    $payment_method = $this->create_payment_method_of_type($pm_type_obj);
306
-                }
307
-                $payment_method->set_type($payment_method_type);
308
-                $this->initialize_payment_method($payment_method);
309
-            } else {
310
-                throw new EE_Error(
311
-                    sprintf(
312
-                        esc_html__(
313
-                            'There is no payment method of type %1$s, so it could not be activated',
314
-                            'event_espresso'
315
-                        ),
316
-                        $pm_type_class
317
-                    )
318
-                );
319
-            }
320
-        }
321
-        $payment_method->set_active();
322
-        $payment_method->save();
323
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
324
-        // if this was the invoice message type, make sure users can view their invoices
325
-        if (
326
-            $payment_method->type() === 'Invoice'
327
-            && (
328
-            ! EEH_MSG_Template::is_mt_active('invoice')
329
-            )
330
-        ) {
331
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
332
-            /** @type EE_Message_Resource_Manager $message_resource_manager */
333
-            $message_resource_manager->ensure_message_type_is_active('invoice', 'html');
334
-            new PersistentAdminNotice(
335
-                'invoice_pm_requirements_notice',
336
-                sprintf(
337
-                    esc_html__(
338
-                        'The Invoice payment method has been activated. It requires the %1$sinvoice message%2$s type to be active, so it was automatically activated for you.',
339
-                        'event_espresso'
340
-                    ),
341
-                    '<a href="' . admin_url('admin.php?page=espresso_messages&action=settings') . '">',
342
-                    '</a>'
343
-                ),
344
-                true
345
-            );
346
-        }
347
-        return $payment_method;
348
-    }
349
-
350
-
351
-    /**
352
-     * Creates a payment method of the specified type. Does not save it.
353
-     *
354
-     * @global WP_User    $current_user
355
-     * @param EE_PMT_Base $pm_type_obj
356
-     * @return EE_Payment_Method
357
-     * @throws EE_Error
358
-     */
359
-    public function create_payment_method_of_type($pm_type_obj)
360
-    {
361
-        global $current_user;
362
-        $payment_method = EE_Payment_Method::new_instance(
363
-            array(
364
-                'PMD_type'       => $pm_type_obj->system_name(),
365
-                'PMD_name'       => $pm_type_obj->defaultFrontendName(),
366
-                'PMD_admin_name' => $pm_type_obj->pretty_name(),
367
-                'PMD_slug'       => $pm_type_obj->system_name(),// automatically converted to slug
368
-                'PMD_wp_user'    => $current_user->ID,
369
-                'PMD_order'      => EEM_Payment_Method::instance()->count(
370
-                    array(array('PMD_type' => array('!=', 'Admin_Only')))
371
-                ) * 10,
372
-            )
373
-        );
374
-        return $payment_method;
375
-    }
376
-
377
-
378
-    /**
379
-     * Sets the initial payment method properties (including extra meta)
380
-     *
381
-     * @param EE_Payment_Method $payment_method
382
-     * @return EE_Payment_Method
383
-     * @throws EE_Error
384
-     */
385
-    public function initialize_payment_method($payment_method)
386
-    {
387
-        $pm_type_obj = $payment_method->type_obj();
388
-        $payment_method->set_description($pm_type_obj->default_description());
389
-        if (! $payment_method->button_url()) {
390
-            $payment_method->set_button_url($pm_type_obj->default_button_url());
391
-        }
392
-        // now add setup its default extra meta properties
393
-        $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
394
-        if (! empty($extra_metas)) {
395
-            // verify the payment method has an ID before adding extra meta
396
-            if (! $payment_method->ID()) {
397
-                $payment_method->save();
398
-            }
399
-            foreach ($extra_metas as $meta_name => $input) {
400
-                $payment_method->update_extra_meta($meta_name, $input->raw_value());
401
-            }
402
-        }
403
-        return $payment_method;
404
-    }
405
-
406
-
407
-    /**
408
-     * Makes sure the payment method is related to the specified payment method
409
-     *
410
-     * @deprecated in 4.9.40 because the currency payment method table is being deprecated
411
-     * @param EE_Payment_Method $payment_method
412
-     * @return EE_Payment_Method
413
-     * @throws EE_Error
414
-     */
415
-    public function set_usable_currencies_on_payment_method($payment_method)
416
-    {
417
-        EE_Error::doing_it_wrong(
418
-            'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method',
419
-            esc_html__(
420
-                'We no longer define what currencies are usable by payment methods. Its not used nor efficient.',
421
-                'event_espresso'
422
-            ),
423
-            '4.9.40'
424
-        );
425
-        return $payment_method;
426
-    }
427
-
428
-
429
-    /**
430
-     * Deactivates a payment method of the given payment method slug.
431
-     *
432
-     * @param string $payment_method_slug The slug for the payment method to deactivate.
433
-     * @return int count of rows updated.
434
-     * @throws EE_Error
435
-     */
436
-    public function deactivate_payment_method($payment_method_slug)
437
-    {
438
-        EE_Log::instance()->log(
439
-            __FILE__,
440
-            __FUNCTION__,
441
-            sprintf(
442
-                esc_html__(
443
-                    'Payment method with slug %1$s is being deactivated by site admin',
444
-                    'event_espresso'
445
-                ),
446
-                $payment_method_slug
447
-            ),
448
-            'payment_method_change'
449
-        );
450
-        $count_updated = EEM_Payment_Method::instance()->update(
451
-            array('PMD_scope' => array()),
452
-            array(array('PMD_slug' => $payment_method_slug))
453
-        );
454
-        do_action(
455
-            'AHEE__EE_Payment_Method_Manager__deactivate_payment_method__after_deactivating_payment_method',
456
-            $payment_method_slug,
457
-            $count_updated
458
-        );
459
-        return $count_updated;
460
-    }
461
-
462
-
463
-    /**
464
-     * initializes payment method access caps via EE_Capabilities::init_role_caps()
465
-     * upon EE_Payment_Method_Manager construction
466
-     *
467
-     * @throws EE_Error
468
-     * @throws DomainException
469
-     */
470
-    protected function initializePaymentMethodCaps()
471
-    {
472
-        // don't do this twice
473
-        if ($this->payment_method_caps_initialized) {
474
-            return;
475
-        }
476
-        EE_Capabilities::instance()->addCaps(
477
-            $this->getPaymentMethodCaps()
478
-        );
479
-        $this->payment_method_caps_initialized = true;
480
-    }
481
-
482
-
483
-    /**
484
-     * array  of dynamic payment method access caps.
485
-     * at the time of writing, october 20 2014, these are the caps added:
486
-     *  ee_payment_method_admin_only
487
-     *  ee_payment_method_aim
488
-     *  ee_payment_method_bank
489
-     *  ee_payment_method_check
490
-     *  ee_payment_method_invoice
491
-     *  ee_payment_method_mijireh
492
-     *  ee_payment_method_paypal_pro
493
-     *  ee_payment_method_paypal_standard
494
-     * Any other payment methods added to core or via addons will also get
495
-     * their related capability automatically added too, so long as they are
496
-     * registered properly using EE_Register_Payment_Method::register()
497
-     *
498
-     * @return array
499
-     * @throws DomainException
500
-     */
501
-    protected function getPaymentMethodCaps()
502
-    {
503
-        $caps = array();
504
-        foreach ($this->payment_method_type_names() as $payment_method_name) {
505
-            $caps = $this->addPaymentMethodCap($payment_method_name, $caps);
506
-        }
507
-        return $caps;
508
-    }
509
-
510
-
511
-    /**
512
-     * @param string $payment_method_name
513
-     * @param array  $payment_method_caps
514
-     * @param string $role
515
-     * @return array
516
-     * @throws DomainException
517
-     */
518
-    public function addPaymentMethodCap($payment_method_name, array $payment_method_caps, $role = 'administrator')
519
-    {
520
-        if (empty($payment_method_name)) {
521
-            throw new DomainException(
522
-                esc_html__(
523
-                    'The name of a payment method must be specified to add capabilities.',
524
-                    'event_espresso'
525
-                )
526
-            );
527
-        }
528
-        if (empty($role)) {
529
-            throw new DomainException(
530
-                sprintf(
531
-                    esc_html__(
532
-                        'No role was supplied while trying to add capabilities for the %1$s payment method.',
533
-                        'event_espresso'
534
-                    ),
535
-                    $payment_method_name
536
-                )
537
-            );
538
-        }
539
-        if (! isset($payment_method_caps[ $role ])) {
540
-            $payment_method_caps[ $role ] = array();
541
-        }
542
-        $payment_method_caps[ $role ][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX
543
-                                          . strtolower($payment_method_name);
544
-        return $payment_method_caps;
545
-    }
546
-
547
-
548
-    /**
549
-     * callback for FHEE__EE_Capabilities__init_role_caps__caps_map filter
550
-     * to add dynamic payment method access caps when capabilities are reset
551
-     * (or if that filter is called and PM caps are not already set)
552
-     *
553
-     * @param array $caps capabilities being filtered
554
-     * @param bool  $reset
555
-     * @return array
556
-     * @throws DomainException
557
-     */
558
-    public function addPaymentMethodCapsDuringReset(array $caps, $reset = false)
559
-    {
560
-        if ($reset || ! $this->payment_method_caps_initialized) {
561
-            $this->payment_method_caps_initialized = true;
562
-            $caps = array_merge_recursive($caps, $this->getPaymentMethodCaps());
563
-        }
564
-        return $caps;
565
-    }
566
-
567
-
568
-    /**
569
-     * @deprecated 4.9.42
570
-     * @param $caps
571
-     * @return mixed
572
-     */
573
-    public function add_payment_method_caps($caps)
574
-    {
575
-        return $caps;
576
-    }
20
+	/**
21
+	 * prefix added to all payment method capabilities names
22
+	 */
23
+	const   CAPABILITIES_PREFIX = 'ee_payment_method_';
24
+
25
+	/**
26
+	 * @var EE_Payment_Method_Manager $_instance
27
+	 */
28
+	private static $_instance;
29
+
30
+	/**
31
+	 * @var boolean
32
+	 */
33
+	protected $payment_method_caps_initialized = false;
34
+
35
+	/**
36
+	 * @var array keys are class names without 'EE_PMT_', values are their filepaths
37
+	 */
38
+	protected $_payment_method_types = array();
39
+
40
+	/**
41
+	 * @var EE_PMT_Base[]
42
+	 */
43
+	protected $payment_method_objects = array();
44
+
45
+
46
+	/**
47
+	 * EE_Payment_Method_Manager constructor.
48
+	 *
49
+	 * @throws EE_Error
50
+	 * @throws DomainException
51
+	 */
52
+	public function __construct()
53
+	{
54
+		// if in admin lets ensure caps are set.
55
+		if (is_admin()) {
56
+			$this->_register_payment_methods();
57
+			// set them immediately
58
+			$this->initializePaymentMethodCaps();
59
+			// plus any time they get reset
60
+			add_filter(
61
+				'FHEE__EE_Capabilities__addCaps__capabilities_to_add',
62
+				array($this, 'addPaymentMethodCapsDuringReset')
63
+			);
64
+		}
65
+	}
66
+
67
+
68
+	/**
69
+	 * @singleton method used to instantiate class object
70
+	 * @return EE_Payment_Method_Manager instance
71
+	 * @throws DomainException
72
+	 * @throws EE_Error
73
+	 */
74
+	public static function instance()
75
+	{
76
+		// check if class object is instantiated, and instantiated properly
77
+		if (! self::$_instance instanceof EE_Payment_Method_Manager) {
78
+			EE_Registry::instance()->load_lib('PMT_Base');
79
+			self::$_instance = new self();
80
+		}
81
+		return self::$_instance;
82
+	}
83
+
84
+
85
+	/**
86
+	 * Resets the instance and returns a new one
87
+	 *
88
+	 * @return EE_Payment_Method_Manager
89
+	 * @throws DomainException
90
+	 * @throws EE_Error
91
+	 */
92
+	public static function reset()
93
+	{
94
+		self::$_instance = null;
95
+		return self::instance();
96
+	}
97
+
98
+
99
+	/**
100
+	 * If necessary, re-register payment methods
101
+	 *
102
+	 * @param boolean $force_recheck whether to recheck for payment method types,
103
+	 *                               or just re-use the PMTs we found last time we checked during this request (if
104
+	 *                               we have not yet checked during this request, then we need to check anyways)
105
+	 */
106
+	public function maybe_register_payment_methods($force_recheck = false)
107
+	{
108
+		if (! $this->_payment_method_types || $force_recheck) {
109
+			$this->_register_payment_methods();
110
+		}
111
+	}
112
+
113
+
114
+	/**
115
+	 * register_payment_methods
116
+	 *
117
+	 * @return array
118
+	 */
119
+	protected function _register_payment_methods()
120
+	{
121
+		// grab list of installed modules
122
+		$pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
123
+		// filter list of modules to register
124
+		$pm_to_register = apply_filters(
125
+			'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
126
+			$pm_to_register
127
+		);
128
+		// remove any duplicates if that should happen for some reason
129
+		$pm_to_register = array_unique($pm_to_register);
130
+		// loop through folders
131
+		foreach ($pm_to_register as $pm_path) {
132
+			$this->register_payment_method($pm_path);
133
+		}
134
+		do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods');
135
+		// filter list of installed modules
136
+		// keep them organized alphabetically by the payment method type's name
137
+		ksort($this->_payment_method_types);
138
+		return apply_filters(
139
+			'FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods',
140
+			$this->_payment_method_types
141
+		);
142
+	}
143
+
144
+
145
+	/**
146
+	 * register_payment_method- makes core aware of this payment method
147
+	 *
148
+	 * @param string $payment_method_path - full path up to and including payment method folder
149
+	 * @return boolean
150
+	 */
151
+	public function register_payment_method($payment_method_path = '')
152
+	{
153
+		do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path);
154
+		$module_ext = '.pm.php';
155
+		// make all separators match
156
+		$payment_method_path = rtrim(str_replace('/\\', '/', $payment_method_path), '/');
157
+		// grab and sanitize module name
158
+		$module_dir = basename($payment_method_path);
159
+		// create class name from module directory name
160
+		$module = str_replace(array('_', ' '), array(' ', '_'), $module_dir);
161
+		// add class prefix
162
+		$module_class = 'EE_PMT_' . $module;
163
+		// does the module exist ?
164
+		if (! is_readable($payment_method_path . '/' . $module_class . $module_ext)) {
165
+			$msg = sprintf(
166
+				esc_html__(
167
+					'The requested %s payment method file could not be found or is not readable due to file permissions.',
168
+					'event_espresso'
169
+				),
170
+				$module
171
+			);
172
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
173
+			return false;
174
+		}
175
+		// load the module class file
176
+		require_once($payment_method_path . '/' . $module_class . $module_ext);
177
+		// verify that class exists
178
+		if (! class_exists($module_class)) {
179
+			$msg = sprintf(
180
+				esc_html__('The requested %s module class does not exist.', 'event_espresso'),
181
+				$module_class
182
+			);
183
+			EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
184
+			return false;
185
+		}
186
+		// add to array of registered modules
187
+		$this->_payment_method_types[ $module ] = $payment_method_path . '/' . $module_class . $module_ext;
188
+		ksort($this->_payment_method_types);
189
+		return true;
190
+	}
191
+
192
+
193
+	/**
194
+	 * Checks if a payment method has been registered, and if so includes it
195
+	 *
196
+	 * @param string  $payment_method_name like 'PayPal_Pro', (ie class name without the prefix 'EEPM_')
197
+	 * @param boolean $force_recheck       whether to force re-checking for new payment method types
198
+	 * @return boolean
199
+	 */
200
+	public function payment_method_type_exists($payment_method_name, $force_recheck = false)
201
+	{
202
+		if (
203
+			$force_recheck
204
+			|| ! is_array($this->_payment_method_types)
205
+			|| ! isset($this->_payment_method_types[ $payment_method_name ])
206
+		) {
207
+			$this->maybe_register_payment_methods($force_recheck);
208
+		}
209
+		if (isset($this->_payment_method_types[ $payment_method_name ])) {
210
+			require_once($this->_payment_method_types[ $payment_method_name ]);
211
+			return true;
212
+		}
213
+		return false;
214
+	}
215
+
216
+
217
+	/**
218
+	 * Returns all the class names of the various payment method types
219
+	 *
220
+	 * @param boolean $with_prefixes TRUE: get payment method type class names; false just their 'names'
221
+	 *                               (what you'd find in wp_esp_payment_method.PMD_type)
222
+	 * @param boolean $force_recheck whether to force re-checking for new payment method types
223
+	 * @return array
224
+	 */
225
+	public function payment_method_type_names($with_prefixes = false, $force_recheck = false)
226
+	{
227
+		$this->maybe_register_payment_methods($force_recheck);
228
+		if ($with_prefixes) {
229
+			$classnames = array_keys($this->_payment_method_types);
230
+			$payment_methods = array();
231
+			foreach ($classnames as $classname) {
232
+				$payment_methods[] = $this->payment_method_class_from_type($classname);
233
+			}
234
+			return $payment_methods;
235
+		}
236
+		return array_keys($this->_payment_method_types);
237
+	}
238
+
239
+
240
+	/**
241
+	 * Gets an object of each payment method type, none of which are bound to a
242
+	 * payment method instance
243
+	 *
244
+	 * @param boolean $force_recheck whether to force re-checking for new payment method types
245
+	 * @return EE_PMT_Base[]
246
+	 */
247
+	public function payment_method_types($force_recheck = false)
248
+	{
249
+		if ($force_recheck || empty($this->payment_method_objects)) {
250
+			$this->maybe_register_payment_methods($force_recheck);
251
+			foreach ($this->payment_method_type_names(true) as $classname) {
252
+				if (! isset($this->payment_method_objects[ $classname ])) {
253
+					$this->payment_method_objects[ $classname ] = new $classname();
254
+				}
255
+			}
256
+		}
257
+		return $this->payment_method_objects;
258
+	}
259
+
260
+
261
+	/**
262
+	 * Changes the payment method's class name into the payment method type's name
263
+	 * (as used on the payment method's table's PMD_type field)
264
+	 *
265
+	 * @param string $classname
266
+	 * @return string
267
+	 */
268
+	public function payment_method_type_sans_class_prefix($classname)
269
+	{
270
+		return str_replace('EE_PMT_', '', $classname);
271
+	}
272
+
273
+
274
+	/**
275
+	 * Does the opposite of payment-method_type_sans_prefix
276
+	 *
277
+	 * @param string $type
278
+	 * @return string
279
+	 */
280
+	public function payment_method_class_from_type($type)
281
+	{
282
+		return 'EE_PMT_' . $type;
283
+	}
284
+
285
+
286
+	/**
287
+	 * Activates a payment method of the given type.
288
+	 *
289
+	 * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice'
290
+	 * @return EE_Payment_Method
291
+	 * @throws InvalidDataTypeException
292
+	 * @throws EE_Error
293
+	 */
294
+	public function activate_a_payment_method_of_type($payment_method_type)
295
+	{
296
+		$this->maybe_register_payment_methods();
297
+		$payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
298
+		if (! $payment_method instanceof EE_Payment_Method) {
299
+			$pm_type_class = $this->payment_method_class_from_type($payment_method_type);
300
+			if (class_exists($pm_type_class)) {
301
+				/** @var $pm_type_obj EE_PMT_Base */
302
+				$pm_type_obj = new $pm_type_class();
303
+				$payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
304
+				if (! $payment_method) {
305
+					$payment_method = $this->create_payment_method_of_type($pm_type_obj);
306
+				}
307
+				$payment_method->set_type($payment_method_type);
308
+				$this->initialize_payment_method($payment_method);
309
+			} else {
310
+				throw new EE_Error(
311
+					sprintf(
312
+						esc_html__(
313
+							'There is no payment method of type %1$s, so it could not be activated',
314
+							'event_espresso'
315
+						),
316
+						$pm_type_class
317
+					)
318
+				);
319
+			}
320
+		}
321
+		$payment_method->set_active();
322
+		$payment_method->save();
323
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
324
+		// if this was the invoice message type, make sure users can view their invoices
325
+		if (
326
+			$payment_method->type() === 'Invoice'
327
+			&& (
328
+			! EEH_MSG_Template::is_mt_active('invoice')
329
+			)
330
+		) {
331
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
332
+			/** @type EE_Message_Resource_Manager $message_resource_manager */
333
+			$message_resource_manager->ensure_message_type_is_active('invoice', 'html');
334
+			new PersistentAdminNotice(
335
+				'invoice_pm_requirements_notice',
336
+				sprintf(
337
+					esc_html__(
338
+						'The Invoice payment method has been activated. It requires the %1$sinvoice message%2$s type to be active, so it was automatically activated for you.',
339
+						'event_espresso'
340
+					),
341
+					'<a href="' . admin_url('admin.php?page=espresso_messages&action=settings') . '">',
342
+					'</a>'
343
+				),
344
+				true
345
+			);
346
+		}
347
+		return $payment_method;
348
+	}
349
+
350
+
351
+	/**
352
+	 * Creates a payment method of the specified type. Does not save it.
353
+	 *
354
+	 * @global WP_User    $current_user
355
+	 * @param EE_PMT_Base $pm_type_obj
356
+	 * @return EE_Payment_Method
357
+	 * @throws EE_Error
358
+	 */
359
+	public function create_payment_method_of_type($pm_type_obj)
360
+	{
361
+		global $current_user;
362
+		$payment_method = EE_Payment_Method::new_instance(
363
+			array(
364
+				'PMD_type'       => $pm_type_obj->system_name(),
365
+				'PMD_name'       => $pm_type_obj->defaultFrontendName(),
366
+				'PMD_admin_name' => $pm_type_obj->pretty_name(),
367
+				'PMD_slug'       => $pm_type_obj->system_name(),// automatically converted to slug
368
+				'PMD_wp_user'    => $current_user->ID,
369
+				'PMD_order'      => EEM_Payment_Method::instance()->count(
370
+					array(array('PMD_type' => array('!=', 'Admin_Only')))
371
+				) * 10,
372
+			)
373
+		);
374
+		return $payment_method;
375
+	}
376
+
377
+
378
+	/**
379
+	 * Sets the initial payment method properties (including extra meta)
380
+	 *
381
+	 * @param EE_Payment_Method $payment_method
382
+	 * @return EE_Payment_Method
383
+	 * @throws EE_Error
384
+	 */
385
+	public function initialize_payment_method($payment_method)
386
+	{
387
+		$pm_type_obj = $payment_method->type_obj();
388
+		$payment_method->set_description($pm_type_obj->default_description());
389
+		if (! $payment_method->button_url()) {
390
+			$payment_method->set_button_url($pm_type_obj->default_button_url());
391
+		}
392
+		// now add setup its default extra meta properties
393
+		$extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
394
+		if (! empty($extra_metas)) {
395
+			// verify the payment method has an ID before adding extra meta
396
+			if (! $payment_method->ID()) {
397
+				$payment_method->save();
398
+			}
399
+			foreach ($extra_metas as $meta_name => $input) {
400
+				$payment_method->update_extra_meta($meta_name, $input->raw_value());
401
+			}
402
+		}
403
+		return $payment_method;
404
+	}
405
+
406
+
407
+	/**
408
+	 * Makes sure the payment method is related to the specified payment method
409
+	 *
410
+	 * @deprecated in 4.9.40 because the currency payment method table is being deprecated
411
+	 * @param EE_Payment_Method $payment_method
412
+	 * @return EE_Payment_Method
413
+	 * @throws EE_Error
414
+	 */
415
+	public function set_usable_currencies_on_payment_method($payment_method)
416
+	{
417
+		EE_Error::doing_it_wrong(
418
+			'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method',
419
+			esc_html__(
420
+				'We no longer define what currencies are usable by payment methods. Its not used nor efficient.',
421
+				'event_espresso'
422
+			),
423
+			'4.9.40'
424
+		);
425
+		return $payment_method;
426
+	}
427
+
428
+
429
+	/**
430
+	 * Deactivates a payment method of the given payment method slug.
431
+	 *
432
+	 * @param string $payment_method_slug The slug for the payment method to deactivate.
433
+	 * @return int count of rows updated.
434
+	 * @throws EE_Error
435
+	 */
436
+	public function deactivate_payment_method($payment_method_slug)
437
+	{
438
+		EE_Log::instance()->log(
439
+			__FILE__,
440
+			__FUNCTION__,
441
+			sprintf(
442
+				esc_html__(
443
+					'Payment method with slug %1$s is being deactivated by site admin',
444
+					'event_espresso'
445
+				),
446
+				$payment_method_slug
447
+			),
448
+			'payment_method_change'
449
+		);
450
+		$count_updated = EEM_Payment_Method::instance()->update(
451
+			array('PMD_scope' => array()),
452
+			array(array('PMD_slug' => $payment_method_slug))
453
+		);
454
+		do_action(
455
+			'AHEE__EE_Payment_Method_Manager__deactivate_payment_method__after_deactivating_payment_method',
456
+			$payment_method_slug,
457
+			$count_updated
458
+		);
459
+		return $count_updated;
460
+	}
461
+
462
+
463
+	/**
464
+	 * initializes payment method access caps via EE_Capabilities::init_role_caps()
465
+	 * upon EE_Payment_Method_Manager construction
466
+	 *
467
+	 * @throws EE_Error
468
+	 * @throws DomainException
469
+	 */
470
+	protected function initializePaymentMethodCaps()
471
+	{
472
+		// don't do this twice
473
+		if ($this->payment_method_caps_initialized) {
474
+			return;
475
+		}
476
+		EE_Capabilities::instance()->addCaps(
477
+			$this->getPaymentMethodCaps()
478
+		);
479
+		$this->payment_method_caps_initialized = true;
480
+	}
481
+
482
+
483
+	/**
484
+	 * array  of dynamic payment method access caps.
485
+	 * at the time of writing, october 20 2014, these are the caps added:
486
+	 *  ee_payment_method_admin_only
487
+	 *  ee_payment_method_aim
488
+	 *  ee_payment_method_bank
489
+	 *  ee_payment_method_check
490
+	 *  ee_payment_method_invoice
491
+	 *  ee_payment_method_mijireh
492
+	 *  ee_payment_method_paypal_pro
493
+	 *  ee_payment_method_paypal_standard
494
+	 * Any other payment methods added to core or via addons will also get
495
+	 * their related capability automatically added too, so long as they are
496
+	 * registered properly using EE_Register_Payment_Method::register()
497
+	 *
498
+	 * @return array
499
+	 * @throws DomainException
500
+	 */
501
+	protected function getPaymentMethodCaps()
502
+	{
503
+		$caps = array();
504
+		foreach ($this->payment_method_type_names() as $payment_method_name) {
505
+			$caps = $this->addPaymentMethodCap($payment_method_name, $caps);
506
+		}
507
+		return $caps;
508
+	}
509
+
510
+
511
+	/**
512
+	 * @param string $payment_method_name
513
+	 * @param array  $payment_method_caps
514
+	 * @param string $role
515
+	 * @return array
516
+	 * @throws DomainException
517
+	 */
518
+	public function addPaymentMethodCap($payment_method_name, array $payment_method_caps, $role = 'administrator')
519
+	{
520
+		if (empty($payment_method_name)) {
521
+			throw new DomainException(
522
+				esc_html__(
523
+					'The name of a payment method must be specified to add capabilities.',
524
+					'event_espresso'
525
+				)
526
+			);
527
+		}
528
+		if (empty($role)) {
529
+			throw new DomainException(
530
+				sprintf(
531
+					esc_html__(
532
+						'No role was supplied while trying to add capabilities for the %1$s payment method.',
533
+						'event_espresso'
534
+					),
535
+					$payment_method_name
536
+				)
537
+			);
538
+		}
539
+		if (! isset($payment_method_caps[ $role ])) {
540
+			$payment_method_caps[ $role ] = array();
541
+		}
542
+		$payment_method_caps[ $role ][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX
543
+										  . strtolower($payment_method_name);
544
+		return $payment_method_caps;
545
+	}
546
+
547
+
548
+	/**
549
+	 * callback for FHEE__EE_Capabilities__init_role_caps__caps_map filter
550
+	 * to add dynamic payment method access caps when capabilities are reset
551
+	 * (or if that filter is called and PM caps are not already set)
552
+	 *
553
+	 * @param array $caps capabilities being filtered
554
+	 * @param bool  $reset
555
+	 * @return array
556
+	 * @throws DomainException
557
+	 */
558
+	public function addPaymentMethodCapsDuringReset(array $caps, $reset = false)
559
+	{
560
+		if ($reset || ! $this->payment_method_caps_initialized) {
561
+			$this->payment_method_caps_initialized = true;
562
+			$caps = array_merge_recursive($caps, $this->getPaymentMethodCaps());
563
+		}
564
+		return $caps;
565
+	}
566
+
567
+
568
+	/**
569
+	 * @deprecated 4.9.42
570
+	 * @param $caps
571
+	 * @return mixed
572
+	 */
573
+	public function add_payment_method_caps($caps)
574
+	{
575
+		return $caps;
576
+	}
577 577
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
     public static function instance()
75 75
     {
76 76
         // check if class object is instantiated, and instantiated properly
77
-        if (! self::$_instance instanceof EE_Payment_Method_Manager) {
77
+        if ( ! self::$_instance instanceof EE_Payment_Method_Manager) {
78 78
             EE_Registry::instance()->load_lib('PMT_Base');
79 79
             self::$_instance = new self();
80 80
         }
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
      */
106 106
     public function maybe_register_payment_methods($force_recheck = false)
107 107
     {
108
-        if (! $this->_payment_method_types || $force_recheck) {
108
+        if ( ! $this->_payment_method_types || $force_recheck) {
109 109
             $this->_register_payment_methods();
110 110
         }
111 111
     }
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
     protected function _register_payment_methods()
120 120
     {
121 121
         // grab list of installed modules
122
-        $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR);
122
+        $pm_to_register = glob(EE_PAYMENT_METHODS.'*', GLOB_ONLYDIR);
123 123
         // filter list of modules to register
124 124
         $pm_to_register = apply_filters(
125 125
             'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register',
@@ -159,9 +159,9 @@  discard block
 block discarded – undo
159 159
         // create class name from module directory name
160 160
         $module = str_replace(array('_', ' '), array(' ', '_'), $module_dir);
161 161
         // add class prefix
162
-        $module_class = 'EE_PMT_' . $module;
162
+        $module_class = 'EE_PMT_'.$module;
163 163
         // does the module exist ?
164
-        if (! is_readable($payment_method_path . '/' . $module_class . $module_ext)) {
164
+        if ( ! is_readable($payment_method_path.'/'.$module_class.$module_ext)) {
165 165
             $msg = sprintf(
166 166
                 esc_html__(
167 167
                     'The requested %s payment method file could not be found or is not readable due to file permissions.',
@@ -169,22 +169,22 @@  discard block
 block discarded – undo
169 169
                 ),
170 170
                 $module
171 171
             );
172
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
172
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
173 173
             return false;
174 174
         }
175 175
         // load the module class file
176
-        require_once($payment_method_path . '/' . $module_class . $module_ext);
176
+        require_once($payment_method_path.'/'.$module_class.$module_ext);
177 177
         // verify that class exists
178
-        if (! class_exists($module_class)) {
178
+        if ( ! class_exists($module_class)) {
179 179
             $msg = sprintf(
180 180
                 esc_html__('The requested %s module class does not exist.', 'event_espresso'),
181 181
                 $module_class
182 182
             );
183
-            EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__);
183
+            EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__);
184 184
             return false;
185 185
         }
186 186
         // add to array of registered modules
187
-        $this->_payment_method_types[ $module ] = $payment_method_path . '/' . $module_class . $module_ext;
187
+        $this->_payment_method_types[$module] = $payment_method_path.'/'.$module_class.$module_ext;
188 188
         ksort($this->_payment_method_types);
189 189
         return true;
190 190
     }
@@ -202,12 +202,12 @@  discard block
 block discarded – undo
202 202
         if (
203 203
             $force_recheck
204 204
             || ! is_array($this->_payment_method_types)
205
-            || ! isset($this->_payment_method_types[ $payment_method_name ])
205
+            || ! isset($this->_payment_method_types[$payment_method_name])
206 206
         ) {
207 207
             $this->maybe_register_payment_methods($force_recheck);
208 208
         }
209
-        if (isset($this->_payment_method_types[ $payment_method_name ])) {
210
-            require_once($this->_payment_method_types[ $payment_method_name ]);
209
+        if (isset($this->_payment_method_types[$payment_method_name])) {
210
+            require_once($this->_payment_method_types[$payment_method_name]);
211 211
             return true;
212 212
         }
213 213
         return false;
@@ -249,8 +249,8 @@  discard block
 block discarded – undo
249 249
         if ($force_recheck || empty($this->payment_method_objects)) {
250 250
             $this->maybe_register_payment_methods($force_recheck);
251 251
             foreach ($this->payment_method_type_names(true) as $classname) {
252
-                if (! isset($this->payment_method_objects[ $classname ])) {
253
-                    $this->payment_method_objects[ $classname ] = new $classname();
252
+                if ( ! isset($this->payment_method_objects[$classname])) {
253
+                    $this->payment_method_objects[$classname] = new $classname();
254 254
                 }
255 255
             }
256 256
         }
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
      */
280 280
     public function payment_method_class_from_type($type)
281 281
     {
282
-        return 'EE_PMT_' . $type;
282
+        return 'EE_PMT_'.$type;
283 283
     }
284 284
 
285 285
 
@@ -295,13 +295,13 @@  discard block
 block discarded – undo
295 295
     {
296 296
         $this->maybe_register_payment_methods();
297 297
         $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type);
298
-        if (! $payment_method instanceof EE_Payment_Method) {
298
+        if ( ! $payment_method instanceof EE_Payment_Method) {
299 299
             $pm_type_class = $this->payment_method_class_from_type($payment_method_type);
300 300
             if (class_exists($pm_type_class)) {
301 301
                 /** @var $pm_type_obj EE_PMT_Base */
302 302
                 $pm_type_obj = new $pm_type_class();
303 303
                 $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name());
304
-                if (! $payment_method) {
304
+                if ( ! $payment_method) {
305 305
                     $payment_method = $this->create_payment_method_of_type($pm_type_obj);
306 306
                 }
307 307
                 $payment_method->set_type($payment_method_type);
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
                         'The Invoice payment method has been activated. It requires the %1$sinvoice message%2$s type to be active, so it was automatically activated for you.',
339 339
                         'event_espresso'
340 340
                     ),
341
-                    '<a href="' . admin_url('admin.php?page=espresso_messages&action=settings') . '">',
341
+                    '<a href="'.admin_url('admin.php?page=espresso_messages&action=settings').'">',
342 342
                     '</a>'
343 343
                 ),
344 344
                 true
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
                 'PMD_type'       => $pm_type_obj->system_name(),
365 365
                 'PMD_name'       => $pm_type_obj->defaultFrontendName(),
366 366
                 'PMD_admin_name' => $pm_type_obj->pretty_name(),
367
-                'PMD_slug'       => $pm_type_obj->system_name(),// automatically converted to slug
367
+                'PMD_slug'       => $pm_type_obj->system_name(), // automatically converted to slug
368 368
                 'PMD_wp_user'    => $current_user->ID,
369 369
                 'PMD_order'      => EEM_Payment_Method::instance()->count(
370 370
                     array(array('PMD_type' => array('!=', 'Admin_Only')))
@@ -386,14 +386,14 @@  discard block
 block discarded – undo
386 386
     {
387 387
         $pm_type_obj = $payment_method->type_obj();
388 388
         $payment_method->set_description($pm_type_obj->default_description());
389
-        if (! $payment_method->button_url()) {
389
+        if ( ! $payment_method->button_url()) {
390 390
             $payment_method->set_button_url($pm_type_obj->default_button_url());
391 391
         }
392 392
         // now add setup its default extra meta properties
393 393
         $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs();
394
-        if (! empty($extra_metas)) {
394
+        if ( ! empty($extra_metas)) {
395 395
             // verify the payment method has an ID before adding extra meta
396
-            if (! $payment_method->ID()) {
396
+            if ( ! $payment_method->ID()) {
397 397
                 $payment_method->save();
398 398
             }
399 399
             foreach ($extra_metas as $meta_name => $input) {
@@ -536,10 +536,10 @@  discard block
 block discarded – undo
536 536
                 )
537 537
             );
538 538
         }
539
-        if (! isset($payment_method_caps[ $role ])) {
540
-            $payment_method_caps[ $role ] = array();
539
+        if ( ! isset($payment_method_caps[$role])) {
540
+            $payment_method_caps[$role] = array();
541 541
         }
542
-        $payment_method_caps[ $role ][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX
542
+        $payment_method_caps[$role][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX
543 543
                                           . strtolower($payment_method_name);
544 544
         return $payment_method_caps;
545 545
     }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Recipient_Details_Shortcodes.lib.php 2 patches
Indentation   +351 added lines, -351 removed lines patch added patch discarded remove patch
@@ -19,355 +19,355 @@
 block discarded – undo
19 19
 class EE_Recipient_Details_Shortcodes extends EE_Shortcodes
20 20
 {
21 21
 
22
-    protected $_recipient;
23
-
24
-    protected $_registrations_for_recipient;
25
-
26
-
27
-    protected function _init_props()
28
-    {
29
-        $this->label = esc_html__('Recipient Details Shortcodes', 'event_espresso');
30
-        $this->description = esc_html__('All shortcodes specific to recipient registration data', 'event_espresso');
31
-        $this->_shortcodes = array(
32
-            '[RECIPIENT_FNAME]'                  => esc_html__(
33
-                'Parses to the first name of the recipient for the message.',
34
-                'event_espresso'
35
-            ),
36
-            '[RECIPIENT_LNAME]'                  => esc_html__(
37
-                'Parses to the last name of the recipient for the message.',
38
-                'event_espresso'
39
-            ),
40
-            '[RECIPIENT_EMAIL]'                  => esc_html__(
41
-                'Parses to the email address of the recipient for the message.',
42
-                'event_espresso'
43
-            ),
44
-            '[RECIPIENT_REGISTRATION_ID]'        => esc_html__(
45
-                'Parses to the registration ID of the recipient for the message.',
46
-                'event_espresso'
47
-            ),
48
-            '[RECIPIENT_REGISTRATION_CODE]'      => esc_html__(
49
-                'Parses to the registration code of the recipient for the message.',
50
-                'event_espresso'
51
-            ),
52
-            '[RECIPIENT_EDIT_REGISTRATION_LINK]' => esc_html__(
53
-                'Parses to a link for frontend editing of the registration for the recipient.',
54
-                'event_espresso'
55
-            ),
56
-            '[RECIPIENT_PHONE_NUMBER]'           => esc_html__(
57
-                'The Phone Number for the recipient of the message.',
58
-                'event_espresso'
59
-            ),
60
-            '[RECIPIENT_ADDRESS]'                => esc_html__(
61
-                'The Address for the recipient of the message.',
62
-                'event_espresso'
63
-            ),
64
-            '[RECIPIENT_ADDRESS2]'               => esc_html__(
65
-                'Whatever was in the address 2 field for the recipient of the message.',
66
-                'event_espresso'
67
-            ),
68
-            '[RECIPIENT_CITY]'                   => esc_html__(
69
-                'The city for the recipient of the message.',
70
-                'event_espresso'
71
-            ),
72
-            '[RECIPIENT_ZIP_PC]'                 => esc_html__(
73
-                'The ZIP (or Postal) Code for the recipient of the message.',
74
-                'event_espresso'
75
-            ),
76
-            '[RECIPIENT_ADDRESS_STATE]'          => esc_html__(
77
-                'The state/province for the recipient of the message.',
78
-                'event_espresso'
79
-            ),
80
-            '[RECIPIENT_COUNTRY]'                => esc_html__(
81
-                'The country for the recipient of the message.',
82
-                'event_espresso'
83
-            ),
84
-            '[RECIPIENT_ANSWER_*]'               => esc_html__(
85
-                'This is a special dynamic shortcode.  After the "*", add the exact text of an existing question, and if there is an answer for that question for this recipient, then it will be output in place of this shortcode.',
86
-                'event_espresso'
87
-            ),
88
-            '[RECIPIENT_TOTAL_AMOUNT_PAID]'      => esc_html__(
89
-                'If a single registration related to the recipient is available, that is used to retrieve the total amount that has been paid for this recipient.  Otherwise the value of 0 is printed.',
90
-                'event_espresso'
91
-            ),
92
-        );
93
-    }
94
-
95
-
96
-    /**
97
-     * @access protected
98
-     * @param  string $shortcode the shortcode to be parsed.
99
-     * @return string parsed shortcode
100
-     */
101
-    protected function _parser($shortcode)
102
-    {
103
-
104
-        // make sure we end up with a copy of the EE_Messages_Addressee object
105
-        $this->_recipient = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
106
-        $this->_recipient = ! $this->_recipient instanceof EE_Messages_Addressee
107
-                            && is_array($this->_data)
108
-                            && isset($this->_data['data'])
109
-                            && $this->_data['data'] instanceof EE_Messages_Addressee
110
-            ? $this->_data['data']
111
-            :
112
-            $this->_recipient;
113
-        $this->_recipient = ! $this->_recipient instanceof EE_Messages_Addressee
114
-                            && ! empty($this->_extra_data['data'])
115
-                            && $this->_extra_data['data'] instanceof EE_Messages_Addressee
116
-            ? $this->_extra_data['data']
117
-            : $this->_recipient;
118
-
119
-        if (! $this->_recipient instanceof EE_Messages_Addressee) {
120
-            return '';
121
-        }
122
-
123
-        $attendee = $this->_recipient->att_obj;
124
-        if (! $attendee instanceof EE_Attendee) {
125
-            return '';
126
-        }
127
-
128
-        $this->_registrations_for_recipient = isset($this->_recipient->attendees[ $attendee->ID() ]['reg_objs'])
129
-            ? $this->_recipient->attendees[ $attendee->ID() ]['reg_objs']
130
-            : array();
131
-
132
-        switch ($shortcode) {
133
-            case '[RECIPIENT_FNAME]':
134
-                return $attendee->fname();
135
-                break;
136
-
137
-            case '[RECIPIENT_LNAME]':
138
-                return $attendee->lname();
139
-                break;
140
-
141
-            case '[RECIPIENT_EMAIL]':
142
-                return $attendee->email();
143
-                break;
144
-
145
-            case '[RECIPIENT_REGISTRATION_ID]':
146
-                if (! $this->_recipient->reg_obj instanceof EE_Registration) {
147
-                    return '';
148
-                }
149
-                return $this->_get_reg_id();
150
-                break;
151
-
152
-            case '[RECIPIENT_REGISTRATION_CODE]':
153
-                if (! $this->_recipient->reg_obj instanceof EE_Registration) {
154
-                    return '';
155
-                }
156
-                return $this->_get_reg_code();
157
-                break;
158
-
159
-            case '[RECIPIENT_EDIT_REGISTRATION_LINK]':
160
-                if (! $this->_recipient->reg_obj instanceof EE_Registration) {
161
-                    return '';
162
-                }
163
-                return $this->_recipient->reg_obj->edit_attendee_information_url();
164
-                break;
165
-
166
-            case '[RECIPIENT_PHONE_NUMBER]':
167
-                return $attendee->phone();
168
-                break;
169
-
170
-            case '[RECIPIENT_ADDRESS]':
171
-                return $attendee->address();
172
-                break;
173
-
174
-            case '[RECIPIENT_ADDRESS2]':
175
-                return $attendee->address2();
176
-                break;
177
-
178
-            case '[RECIPIENT_CITY]':
179
-                return $attendee->city();
180
-                break;
181
-
182
-            case '[RECIPIENT_ZIP_PC]':
183
-                return $attendee->zip();
184
-                break;
185
-
186
-            case '[RECIPIENT_ADDRESS_STATE]':
187
-                $state_obj = $attendee->state_obj();
188
-                return $state_obj instanceof EE_State ? $state_obj->name() : '';
189
-                break;
190
-
191
-            case '[RECIPIENT_COUNTRY]':
192
-                $country_obj = $attendee->country_obj();
193
-                return $country_obj instanceof EE_Country ? $country_obj->name() : '';
194
-                break;
195
-            case '[RECIPIENT_TOTAL_AMOUNT_PAID]':
196
-                return $this->_recipient->reg_obj instanceof EE_Registration
197
-                    ? $this->_recipient->reg_obj->pretty_paid()
198
-                    : 0;
199
-                break;
200
-        }
201
-
202
-        if (strpos($shortcode, '[RECIPIENT_ANSWER_*') !== false) {
203
-            $shortcode = str_replace('[RECIPIENT_ANSWER_*', '', $shortcode);
204
-            $shortcode = trim(str_replace(']', '', $shortcode));
205
-
206
-
207
-            // now let's figure out what question has this text
208
-            if (empty($this->_recipient->questions) || ! $this->_recipient->reg_obj instanceof EE_Registration) {
209
-                return '';
210
-            }
211
-
212
-            foreach ($this->_recipient->questions as $ansid => $question) {
213
-                if (
214
-                    $question instanceof EE_Question
215
-                    && trim($question->display_text()) === trim($shortcode)
216
-                    && isset($this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ])
217
-                ) {
218
-                    $recipient_ansid = $this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ];
219
-
220
-                    // what we show for the answer depends on the question type!
221
-                    switch ($question->get('QST_type')) {
222
-                        case EEM_Question::QST_type_state:
223
-                            $state = EEM_State::instance()->get_one_by_ID($recipient_ansid->get('ANS_value'));
224
-                            $answer = $state instanceof EE_State ? $state->name() : '';
225
-                            break;
226
-
227
-                        case EEM_Question::QST_type_country:
228
-                            $country = EEM_Country::instance()->get_one_by_ID($recipient_ansid->get('ANS_value'));
229
-                            $answer = $country instanceof EE_Country ? $country->name() : '';
230
-                            break;
231
-
232
-                        default:
233
-                            $answer = $recipient_ansid->get_pretty('ANS_value', 'no_wpautop');
234
-                            break;
235
-                    }
236
-
237
-                    return $answer;
238
-                    break;
239
-                }
240
-            }
241
-        }
242
-
243
-        return '';
244
-    }
245
-
246
-
247
-    /**
248
-     * Returns the EE_Messages_Addressee object for the recipient.
249
-     *
250
-     * @since 4.5.0
251
-     *
252
-     * @return EE_Messages_Addressee
253
-     */
254
-    public function get_recipient()
255
-    {
256
-        return $this->_recipient;
257
-    }
258
-
259
-
260
-    /**
261
-     * returns the reg code for the recipient depending on the context and whether the recipient has multiple
262
-     * registrations or not.
263
-     *
264
-     * @return string
265
-     */
266
-    protected function _get_reg_code()
267
-    {
268
-
269
-        // if only one related registration for the recipient then just return that reg code.
270
-        if (count($this->_registrations_for_recipient) <= 1) {
271
-            return $this->_recipient->reg_obj->reg_code();
272
-        }
273
-
274
-        // k more than one registration so let's see if we can get specific to context
275
-        // are we parsing event_list?
276
-        if ($this->_data instanceof EE_Event) {
277
-            $reg_code = array();
278
-            // loop through registrations for recipient and see if there is a match for this event
279
-            foreach ($this->_registrations_for_recipient as $reg) {
280
-                if ($reg instanceof EE_Registration && $reg->event_ID() == $this->_data->ID()) {
281
-                    $reg_code[] = $reg->reg_code();
282
-                }
283
-            }
284
-            return implode(', ', $reg_code);
285
-        }
286
-
287
-        // are we parsing ticket list?
288
-        if ($this->_data instanceof EE_Ticket) {
289
-            $reg_code = array();
290
-            // loop through each registration for recipient and see if there is a match for this ticket
291
-            foreach ($this->_registrations_for_recipient as $reg) {
292
-                if ($reg instanceof EE_Registration && $reg->ticket_ID() == $this->_data->ID()) {
293
-                    $reg_code = $reg->reg_code();
294
-                }
295
-            }
296
-            return implode(', ', $reg_code);
297
-        }
298
-
299
-        // do we have a specific reg_obj?  Let's use it
300
-        if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) {
301
-            return $this->_data->reg_obj->reg_code();
302
-        }
303
-
304
-        // do we have a specific reg_obj?  Let's use it
305
-        if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) {
306
-            return $this->_data->reg_obj->reg_code();
307
-        }
308
-
309
-        // not able to determine the single reg code so let's return a comma delimited list of reg codes.
310
-        $reg_code = array();
311
-        foreach ($this->_registrations_for_recipient as $reg) {
312
-            if ($reg instanceof EE_Registration) {
313
-                $reg_code[] = $reg->reg_code();
314
-            }
315
-        }
316
-        return implode(', ', $reg_code);
317
-    }
318
-
319
-
320
-    /**
321
-     * returns the reg ID for the recipient depending on the context and whether the recipient has multiple
322
-     * registrations or not.
323
-     *
324
-     * @return int|string
325
-     */
326
-    protected function _get_reg_id()
327
-    {
328
-
329
-        // if only one related registration for the recipient then just return that reg code.
330
-        if (count($this->_registrations_for_recipient) <= 1) {
331
-            return $this->_recipient->reg_obj->ID();
332
-        }
333
-
334
-        // k more than one registration so let's see if we can get specific to context
335
-        // are we parsing event_list?
336
-        if ($this->_data instanceof EE_Event) {
337
-            $registration_ids = array();
338
-            // loop through registrations for recipient and see if there is a match for this event
339
-            foreach ($this->_registrations_for_recipient as $reg) {
340
-                if ($reg instanceof EE_Registration && $reg->event_ID() == $this->_data->ID()) {
341
-                    $registration_ids[] = $reg->ID();
342
-                }
343
-            }
344
-            return implode(', ', $registration_ids);
345
-        }
346
-
347
-        // are we parsing ticket list?
348
-        if ($this->_data instanceof EE_Ticket) {
349
-            $registration_ids = array();
350
-            // loop through each registration for recipient and see if there is a match for this ticket
351
-            foreach ($this->_registrations_for_recipient as $reg) {
352
-                if ($reg instanceof EE_Registration && $reg->ticket_ID() == $this->_data->ID()) {
353
-                    $registration_ids = $reg->ID();
354
-                }
355
-            }
356
-            return implode(', ', $registration_ids);
357
-        }
358
-
359
-        // do we have a specific reg_obj?  Let's use it
360
-        if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) {
361
-            return $this->_data->reg_obj->ID();
362
-        }
363
-
364
-        // not able to determine the single reg code so let's return a comma delimited list of reg codes.
365
-        $registration_ids = array();
366
-        foreach ($this->_registrations_for_recipient as $reg) {
367
-            if ($reg instanceof EE_Registration) {
368
-                $registration_ids[] = $reg->ID();
369
-            }
370
-        }
371
-        return implode(', ', $registration_ids);
372
-    }
22
+	protected $_recipient;
23
+
24
+	protected $_registrations_for_recipient;
25
+
26
+
27
+	protected function _init_props()
28
+	{
29
+		$this->label = esc_html__('Recipient Details Shortcodes', 'event_espresso');
30
+		$this->description = esc_html__('All shortcodes specific to recipient registration data', 'event_espresso');
31
+		$this->_shortcodes = array(
32
+			'[RECIPIENT_FNAME]'                  => esc_html__(
33
+				'Parses to the first name of the recipient for the message.',
34
+				'event_espresso'
35
+			),
36
+			'[RECIPIENT_LNAME]'                  => esc_html__(
37
+				'Parses to the last name of the recipient for the message.',
38
+				'event_espresso'
39
+			),
40
+			'[RECIPIENT_EMAIL]'                  => esc_html__(
41
+				'Parses to the email address of the recipient for the message.',
42
+				'event_espresso'
43
+			),
44
+			'[RECIPIENT_REGISTRATION_ID]'        => esc_html__(
45
+				'Parses to the registration ID of the recipient for the message.',
46
+				'event_espresso'
47
+			),
48
+			'[RECIPIENT_REGISTRATION_CODE]'      => esc_html__(
49
+				'Parses to the registration code of the recipient for the message.',
50
+				'event_espresso'
51
+			),
52
+			'[RECIPIENT_EDIT_REGISTRATION_LINK]' => esc_html__(
53
+				'Parses to a link for frontend editing of the registration for the recipient.',
54
+				'event_espresso'
55
+			),
56
+			'[RECIPIENT_PHONE_NUMBER]'           => esc_html__(
57
+				'The Phone Number for the recipient of the message.',
58
+				'event_espresso'
59
+			),
60
+			'[RECIPIENT_ADDRESS]'                => esc_html__(
61
+				'The Address for the recipient of the message.',
62
+				'event_espresso'
63
+			),
64
+			'[RECIPIENT_ADDRESS2]'               => esc_html__(
65
+				'Whatever was in the address 2 field for the recipient of the message.',
66
+				'event_espresso'
67
+			),
68
+			'[RECIPIENT_CITY]'                   => esc_html__(
69
+				'The city for the recipient of the message.',
70
+				'event_espresso'
71
+			),
72
+			'[RECIPIENT_ZIP_PC]'                 => esc_html__(
73
+				'The ZIP (or Postal) Code for the recipient of the message.',
74
+				'event_espresso'
75
+			),
76
+			'[RECIPIENT_ADDRESS_STATE]'          => esc_html__(
77
+				'The state/province for the recipient of the message.',
78
+				'event_espresso'
79
+			),
80
+			'[RECIPIENT_COUNTRY]'                => esc_html__(
81
+				'The country for the recipient of the message.',
82
+				'event_espresso'
83
+			),
84
+			'[RECIPIENT_ANSWER_*]'               => esc_html__(
85
+				'This is a special dynamic shortcode.  After the "*", add the exact text of an existing question, and if there is an answer for that question for this recipient, then it will be output in place of this shortcode.',
86
+				'event_espresso'
87
+			),
88
+			'[RECIPIENT_TOTAL_AMOUNT_PAID]'      => esc_html__(
89
+				'If a single registration related to the recipient is available, that is used to retrieve the total amount that has been paid for this recipient.  Otherwise the value of 0 is printed.',
90
+				'event_espresso'
91
+			),
92
+		);
93
+	}
94
+
95
+
96
+	/**
97
+	 * @access protected
98
+	 * @param  string $shortcode the shortcode to be parsed.
99
+	 * @return string parsed shortcode
100
+	 */
101
+	protected function _parser($shortcode)
102
+	{
103
+
104
+		// make sure we end up with a copy of the EE_Messages_Addressee object
105
+		$this->_recipient = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
106
+		$this->_recipient = ! $this->_recipient instanceof EE_Messages_Addressee
107
+							&& is_array($this->_data)
108
+							&& isset($this->_data['data'])
109
+							&& $this->_data['data'] instanceof EE_Messages_Addressee
110
+			? $this->_data['data']
111
+			:
112
+			$this->_recipient;
113
+		$this->_recipient = ! $this->_recipient instanceof EE_Messages_Addressee
114
+							&& ! empty($this->_extra_data['data'])
115
+							&& $this->_extra_data['data'] instanceof EE_Messages_Addressee
116
+			? $this->_extra_data['data']
117
+			: $this->_recipient;
118
+
119
+		if (! $this->_recipient instanceof EE_Messages_Addressee) {
120
+			return '';
121
+		}
122
+
123
+		$attendee = $this->_recipient->att_obj;
124
+		if (! $attendee instanceof EE_Attendee) {
125
+			return '';
126
+		}
127
+
128
+		$this->_registrations_for_recipient = isset($this->_recipient->attendees[ $attendee->ID() ]['reg_objs'])
129
+			? $this->_recipient->attendees[ $attendee->ID() ]['reg_objs']
130
+			: array();
131
+
132
+		switch ($shortcode) {
133
+			case '[RECIPIENT_FNAME]':
134
+				return $attendee->fname();
135
+				break;
136
+
137
+			case '[RECIPIENT_LNAME]':
138
+				return $attendee->lname();
139
+				break;
140
+
141
+			case '[RECIPIENT_EMAIL]':
142
+				return $attendee->email();
143
+				break;
144
+
145
+			case '[RECIPIENT_REGISTRATION_ID]':
146
+				if (! $this->_recipient->reg_obj instanceof EE_Registration) {
147
+					return '';
148
+				}
149
+				return $this->_get_reg_id();
150
+				break;
151
+
152
+			case '[RECIPIENT_REGISTRATION_CODE]':
153
+				if (! $this->_recipient->reg_obj instanceof EE_Registration) {
154
+					return '';
155
+				}
156
+				return $this->_get_reg_code();
157
+				break;
158
+
159
+			case '[RECIPIENT_EDIT_REGISTRATION_LINK]':
160
+				if (! $this->_recipient->reg_obj instanceof EE_Registration) {
161
+					return '';
162
+				}
163
+				return $this->_recipient->reg_obj->edit_attendee_information_url();
164
+				break;
165
+
166
+			case '[RECIPIENT_PHONE_NUMBER]':
167
+				return $attendee->phone();
168
+				break;
169
+
170
+			case '[RECIPIENT_ADDRESS]':
171
+				return $attendee->address();
172
+				break;
173
+
174
+			case '[RECIPIENT_ADDRESS2]':
175
+				return $attendee->address2();
176
+				break;
177
+
178
+			case '[RECIPIENT_CITY]':
179
+				return $attendee->city();
180
+				break;
181
+
182
+			case '[RECIPIENT_ZIP_PC]':
183
+				return $attendee->zip();
184
+				break;
185
+
186
+			case '[RECIPIENT_ADDRESS_STATE]':
187
+				$state_obj = $attendee->state_obj();
188
+				return $state_obj instanceof EE_State ? $state_obj->name() : '';
189
+				break;
190
+
191
+			case '[RECIPIENT_COUNTRY]':
192
+				$country_obj = $attendee->country_obj();
193
+				return $country_obj instanceof EE_Country ? $country_obj->name() : '';
194
+				break;
195
+			case '[RECIPIENT_TOTAL_AMOUNT_PAID]':
196
+				return $this->_recipient->reg_obj instanceof EE_Registration
197
+					? $this->_recipient->reg_obj->pretty_paid()
198
+					: 0;
199
+				break;
200
+		}
201
+
202
+		if (strpos($shortcode, '[RECIPIENT_ANSWER_*') !== false) {
203
+			$shortcode = str_replace('[RECIPIENT_ANSWER_*', '', $shortcode);
204
+			$shortcode = trim(str_replace(']', '', $shortcode));
205
+
206
+
207
+			// now let's figure out what question has this text
208
+			if (empty($this->_recipient->questions) || ! $this->_recipient->reg_obj instanceof EE_Registration) {
209
+				return '';
210
+			}
211
+
212
+			foreach ($this->_recipient->questions as $ansid => $question) {
213
+				if (
214
+					$question instanceof EE_Question
215
+					&& trim($question->display_text()) === trim($shortcode)
216
+					&& isset($this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ])
217
+				) {
218
+					$recipient_ansid = $this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ];
219
+
220
+					// what we show for the answer depends on the question type!
221
+					switch ($question->get('QST_type')) {
222
+						case EEM_Question::QST_type_state:
223
+							$state = EEM_State::instance()->get_one_by_ID($recipient_ansid->get('ANS_value'));
224
+							$answer = $state instanceof EE_State ? $state->name() : '';
225
+							break;
226
+
227
+						case EEM_Question::QST_type_country:
228
+							$country = EEM_Country::instance()->get_one_by_ID($recipient_ansid->get('ANS_value'));
229
+							$answer = $country instanceof EE_Country ? $country->name() : '';
230
+							break;
231
+
232
+						default:
233
+							$answer = $recipient_ansid->get_pretty('ANS_value', 'no_wpautop');
234
+							break;
235
+					}
236
+
237
+					return $answer;
238
+					break;
239
+				}
240
+			}
241
+		}
242
+
243
+		return '';
244
+	}
245
+
246
+
247
+	/**
248
+	 * Returns the EE_Messages_Addressee object for the recipient.
249
+	 *
250
+	 * @since 4.5.0
251
+	 *
252
+	 * @return EE_Messages_Addressee
253
+	 */
254
+	public function get_recipient()
255
+	{
256
+		return $this->_recipient;
257
+	}
258
+
259
+
260
+	/**
261
+	 * returns the reg code for the recipient depending on the context and whether the recipient has multiple
262
+	 * registrations or not.
263
+	 *
264
+	 * @return string
265
+	 */
266
+	protected function _get_reg_code()
267
+	{
268
+
269
+		// if only one related registration for the recipient then just return that reg code.
270
+		if (count($this->_registrations_for_recipient) <= 1) {
271
+			return $this->_recipient->reg_obj->reg_code();
272
+		}
273
+
274
+		// k more than one registration so let's see if we can get specific to context
275
+		// are we parsing event_list?
276
+		if ($this->_data instanceof EE_Event) {
277
+			$reg_code = array();
278
+			// loop through registrations for recipient and see if there is a match for this event
279
+			foreach ($this->_registrations_for_recipient as $reg) {
280
+				if ($reg instanceof EE_Registration && $reg->event_ID() == $this->_data->ID()) {
281
+					$reg_code[] = $reg->reg_code();
282
+				}
283
+			}
284
+			return implode(', ', $reg_code);
285
+		}
286
+
287
+		// are we parsing ticket list?
288
+		if ($this->_data instanceof EE_Ticket) {
289
+			$reg_code = array();
290
+			// loop through each registration for recipient and see if there is a match for this ticket
291
+			foreach ($this->_registrations_for_recipient as $reg) {
292
+				if ($reg instanceof EE_Registration && $reg->ticket_ID() == $this->_data->ID()) {
293
+					$reg_code = $reg->reg_code();
294
+				}
295
+			}
296
+			return implode(', ', $reg_code);
297
+		}
298
+
299
+		// do we have a specific reg_obj?  Let's use it
300
+		if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) {
301
+			return $this->_data->reg_obj->reg_code();
302
+		}
303
+
304
+		// do we have a specific reg_obj?  Let's use it
305
+		if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) {
306
+			return $this->_data->reg_obj->reg_code();
307
+		}
308
+
309
+		// not able to determine the single reg code so let's return a comma delimited list of reg codes.
310
+		$reg_code = array();
311
+		foreach ($this->_registrations_for_recipient as $reg) {
312
+			if ($reg instanceof EE_Registration) {
313
+				$reg_code[] = $reg->reg_code();
314
+			}
315
+		}
316
+		return implode(', ', $reg_code);
317
+	}
318
+
319
+
320
+	/**
321
+	 * returns the reg ID for the recipient depending on the context and whether the recipient has multiple
322
+	 * registrations or not.
323
+	 *
324
+	 * @return int|string
325
+	 */
326
+	protected function _get_reg_id()
327
+	{
328
+
329
+		// if only one related registration for the recipient then just return that reg code.
330
+		if (count($this->_registrations_for_recipient) <= 1) {
331
+			return $this->_recipient->reg_obj->ID();
332
+		}
333
+
334
+		// k more than one registration so let's see if we can get specific to context
335
+		// are we parsing event_list?
336
+		if ($this->_data instanceof EE_Event) {
337
+			$registration_ids = array();
338
+			// loop through registrations for recipient and see if there is a match for this event
339
+			foreach ($this->_registrations_for_recipient as $reg) {
340
+				if ($reg instanceof EE_Registration && $reg->event_ID() == $this->_data->ID()) {
341
+					$registration_ids[] = $reg->ID();
342
+				}
343
+			}
344
+			return implode(', ', $registration_ids);
345
+		}
346
+
347
+		// are we parsing ticket list?
348
+		if ($this->_data instanceof EE_Ticket) {
349
+			$registration_ids = array();
350
+			// loop through each registration for recipient and see if there is a match for this ticket
351
+			foreach ($this->_registrations_for_recipient as $reg) {
352
+				if ($reg instanceof EE_Registration && $reg->ticket_ID() == $this->_data->ID()) {
353
+					$registration_ids = $reg->ID();
354
+				}
355
+			}
356
+			return implode(', ', $registration_ids);
357
+		}
358
+
359
+		// do we have a specific reg_obj?  Let's use it
360
+		if ($this->_data instanceof EE_Messages_Addressee && $this->_data->reg_obj instanceof EE_Registration) {
361
+			return $this->_data->reg_obj->ID();
362
+		}
363
+
364
+		// not able to determine the single reg code so let's return a comma delimited list of reg codes.
365
+		$registration_ids = array();
366
+		foreach ($this->_registrations_for_recipient as $reg) {
367
+			if ($reg instanceof EE_Registration) {
368
+				$registration_ids[] = $reg->ID();
369
+			}
370
+		}
371
+		return implode(', ', $registration_ids);
372
+	}
373 373
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -116,17 +116,17 @@  discard block
 block discarded – undo
116 116
             ? $this->_extra_data['data']
117 117
             : $this->_recipient;
118 118
 
119
-        if (! $this->_recipient instanceof EE_Messages_Addressee) {
119
+        if ( ! $this->_recipient instanceof EE_Messages_Addressee) {
120 120
             return '';
121 121
         }
122 122
 
123 123
         $attendee = $this->_recipient->att_obj;
124
-        if (! $attendee instanceof EE_Attendee) {
124
+        if ( ! $attendee instanceof EE_Attendee) {
125 125
             return '';
126 126
         }
127 127
 
128
-        $this->_registrations_for_recipient = isset($this->_recipient->attendees[ $attendee->ID() ]['reg_objs'])
129
-            ? $this->_recipient->attendees[ $attendee->ID() ]['reg_objs']
128
+        $this->_registrations_for_recipient = isset($this->_recipient->attendees[$attendee->ID()]['reg_objs'])
129
+            ? $this->_recipient->attendees[$attendee->ID()]['reg_objs']
130 130
             : array();
131 131
 
132 132
         switch ($shortcode) {
@@ -143,21 +143,21 @@  discard block
 block discarded – undo
143 143
                 break;
144 144
 
145 145
             case '[RECIPIENT_REGISTRATION_ID]':
146
-                if (! $this->_recipient->reg_obj instanceof EE_Registration) {
146
+                if ( ! $this->_recipient->reg_obj instanceof EE_Registration) {
147 147
                     return '';
148 148
                 }
149 149
                 return $this->_get_reg_id();
150 150
                 break;
151 151
 
152 152
             case '[RECIPIENT_REGISTRATION_CODE]':
153
-                if (! $this->_recipient->reg_obj instanceof EE_Registration) {
153
+                if ( ! $this->_recipient->reg_obj instanceof EE_Registration) {
154 154
                     return '';
155 155
                 }
156 156
                 return $this->_get_reg_code();
157 157
                 break;
158 158
 
159 159
             case '[RECIPIENT_EDIT_REGISTRATION_LINK]':
160
-                if (! $this->_recipient->reg_obj instanceof EE_Registration) {
160
+                if ( ! $this->_recipient->reg_obj instanceof EE_Registration) {
161 161
                     return '';
162 162
                 }
163 163
                 return $this->_recipient->reg_obj->edit_attendee_information_url();
@@ -213,9 +213,9 @@  discard block
 block discarded – undo
213 213
                 if (
214 214
                     $question instanceof EE_Question
215 215
                     && trim($question->display_text()) === trim($shortcode)
216
-                    && isset($this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ])
216
+                    && isset($this->_recipient->registrations[$this->_recipient->reg_obj->ID()]['ans_objs'][$ansid])
217 217
                 ) {
218
-                    $recipient_ansid = $this->_recipient->registrations[ $this->_recipient->reg_obj->ID() ]['ans_objs'][ $ansid ];
218
+                    $recipient_ansid = $this->_recipient->registrations[$this->_recipient->reg_obj->ID()]['ans_objs'][$ansid];
219 219
 
220 220
                     // what we show for the answer depends on the question type!
221 221
                     switch ($question->get('QST_type')) {
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Event_Shortcodes.lib.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 
135 135
 
136 136
         // If there is no event objecdt by now then get out.
137
-        if (! $this->_event instanceof EE_Event) {
137
+        if ( ! $this->_event instanceof EE_Event) {
138 138
             return '';
139 139
         }
140 140
 
@@ -187,11 +187,11 @@  discard block
 block discarded – undo
187 187
                 $image = $this->_event->feature_image_url(array(600, 300));
188 188
                 // @todo: eventually we should make this an attribute shortcode so that em can send along what size they want returned.
189 189
                 return ! empty($image)
190
-                    ? '<img src="' . $image . '" alt="'
190
+                    ? '<img src="'.$image.'" alt="'
191 191
                       . sprintf(
192 192
                           esc_attr__('%s Feature Image', 'event_espresso'),
193 193
                           $this->_event->get('EVT_name')
194
-                      ) . '" />'
194
+                      ).'" />'
195 195
                     : '';
196 196
                 break;
197 197
 
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
             // Check if a do_shortcode attribute was set to true and if so run $event_meta through that function.
254 254
             if (
255 255
                 apply_filters('FHEE__EventEspresso_core_libraries_shortcodes_EE_Event_Shortcodes___parser__event_meta_do_shortcode', false)
256
-                || !empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN)
256
+                || ! empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN)
257 257
             ) {
258 258
                 return do_shortcode($event_meta);
259 259
             }
@@ -271,11 +271,11 @@  discard block
 block discarded – undo
271 271
 
272 272
         if (strpos($shortcode, '[EVENT_IMAGE_*') !== false) {
273 273
             $attrs = $this->_get_shortcode_attrs($shortcode);
274
-            $width = empty($attrs['width']) ? '' : ' width="' . $attrs['width'] . '"';
275
-            $height = empty($attrs['height']) ? '' : ' height="' . $attrs['height'] . '"';
274
+            $width = empty($attrs['width']) ? '' : ' width="'.$attrs['width'].'"';
275
+            $height = empty($attrs['height']) ? '' : ' height="'.$attrs['height'].'"';
276 276
 
277 277
             // Size may be set to a string such as 'tumbnail' or "width, height" eg - '200,200'
278
-            if (! empty($attrs['size'])) {
278
+            if ( ! empty($attrs['size'])) {
279 279
                 $size = explode(',', $attrs['size']);
280 280
                 if (count($size) === 1) {
281 281
                     $size = $size[0];
@@ -287,11 +287,11 @@  discard block
 block discarded – undo
287 287
             $image = $this->_event->feature_image_url($size);
288 288
 
289 289
             return ! empty($image)
290
-                ? '<img src="' . $image . '" alt="'
290
+                ? '<img src="'.$image.'" alt="'
291 291
                   . sprintf(
292 292
                       esc_attr__('%s Feature Image', 'event_espresso'),
293 293
                       $this->_event->get('EVT_name')
294
-                  ) . '"' . $width . $height . '/>'
294
+                  ).'"'.$width.$height.'/>'
295 295
                 : '';
296 296
         }
297 297
 
@@ -310,6 +310,6 @@  discard block
 block discarded – undo
310 310
     {
311 311
         $url = get_permalink($event->ID());
312 312
 
313
-        return $full_link ? '<a href="' . $url . '">' . $event->get('EVT_name') . '</a>' : $url;
313
+        return $full_link ? '<a href="'.$url.'">'.$event->get('EVT_name').'</a>' : $url;
314 314
     }
315 315
 }
Please login to merge, or discard this patch.
Indentation   +293 added lines, -293 removed lines patch added patch discarded remove patch
@@ -19,297 +19,297 @@
 block discarded – undo
19 19
 {
20 20
 
21 21
 
22
-    /**
23
-     * Will hold the EE_Event if available
24
-     *
25
-     * @var EE_Event
26
-     */
27
-    protected $_event;
28
-
29
-
30
-    public function __construct()
31
-    {
32
-        parent::__construct();
33
-    }
34
-
35
-
36
-    protected function _init_props()
37
-    {
38
-        $this->label = esc_html__('Event Shortcodes', 'event_espresso');
39
-        $this->description = esc_html__('All shortcodes specific to event related data', 'event_espresso');
40
-        $this->_shortcodes = array(
41
-            '[EVENT_ID]'                              => esc_html__(
42
-                'Will be replaced by the event ID of an event',
43
-                'event_espresso'
44
-            ),
45
-            '[EVENT]'                                 => esc_html__('The name of the event', 'event_espresso'),
46
-            '[EVENT_NAME]'                            => esc_html__(
47
-                "This also can be used for the name of the event",
48
-                'event_espresso'
49
-            ),
50
-            '[EVENT_PHONE]'                           => esc_html__(
51
-                'The phone number for the event (usually an info number)',
52
-                'event_espresso'
53
-            ),
54
-            '[EVENT_DESCRIPTION]'                     => esc_html__('The description of the event', 'event_espresso'),
55
-            '[EVENT_EXCERPT]'                         => esc_html__(
56
-                'This gets parsed to the value for the excerpt field in the event or blank if there is no excerpt.',
57
-                'event_espresso'
58
-            ),
59
-            '[EVENT_LINK]'                            => esc_html__('A link associated with the event', 'event_espresso'),
60
-            '[EVENT_URL]'                             => esc_html__(
61
-                'A link to the event set up on the host site.',
62
-                'event_espresso'
63
-            ),
64
-            '[VIRTUAL_URL]'                           => esc_html__(
65
-                'What was used for the "URL of Event" field in the Venue settings',
66
-                'event_espresso'
67
-            ),
68
-            '[VIRTUAL_PHONE]'                         => esc_html__(
69
-                'An alternate phone number for the event. Typically used as a "call-in" number',
70
-                'event_espresso'
71
-            ),
72
-            '[EVENT_IMAGE]'                           => esc_html__(
73
-                'This will parse to the Feature image for the event.',
74
-                'event_espresso'
75
-            ),
76
-            '[EVENT_IMAGE_*]'                         => sprintf(
77
-                esc_html__(
78
-                    'This will parse to the Feature image for the event, %1$ssize%2$s can be set to determine the size of the image loaded by the shortcode. The %1$swidth%2$s and/or %1$sheight%2$s can also be set to determine the width and height of the image when output. By default the shortcode will load the %1$sthumbnail%2$s image size.',
79
-                    'event_espresso'
80
-                ),
81
-                '<code>',
82
-                '</code>'
83
-            ),
84
-            '[EVENT_TOTAL_AVAILABLE_SPACES_*]'        => sprintf(
85
-                esc_html__(
86
-                    'This will parse to the total available spaces for an event. Calculating total spaces is approximate because it is dependent on the complexity of limits on your event.  There are two methods of calculation (which can be indicated by the %1$smethod%2$s param on the shortcode).  %1$scurrent%2$s which will do a more accurate calculation of total available spaces based on current sales, and %1$sfull%2$s which will be the maximum total available spaces that is on the event in optimal conditions. The shortcode will default to current.',
87
-                    'event_espresso'
88
-                ),
89
-                '<code>',
90
-                '</code>'
91
-            ),
92
-            '[EVENT_TOTAL_SPOTS_TAKEN]'               => esc_html__(
93
-                'This shortcode will parse to the output the total approved registrations for this event',
94
-                'event_espresso'
95
-            ),
96
-            '[EVENT_FACEBOOK_URL]'                    => esc_html__(
97
-                'This will return the Facebook URL for the event if you have it set via custom field in your event, otherwise it will use the Facebook URL set in "Your Organization Settings". To set the facebook url in your event, add a custom field with the key as <code>event_facebook</code> and the value as your facebook url.',
98
-                'event_espresso'
99
-            ),
100
-            '[EVENT_TWITTER_URL]'                     => esc_html__(
101
-                'This will return the Twitter URL for the event if you have it set via custom field in your event, otherwise it will use the Twitter URL set in "Your Organization Settings". To set the facebook url in your event, add a custom field with the key as <code>event_twitter</code> and the value as your facebook url',
102
-                'event_espresso'
103
-            ),
104
-            '[EVENT_META_*]'                          => sprintf(
105
-                esc_html__(
106
-                    'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the event then it will be output in place of this shortcode. If you use shortcodes within your custom fields set %1$sdo_shortcode=true%2$s at the end of the shortcode to run the value through the do_shortcode function. ',
107
-                    'event_espresso'
108
-                ),
109
-                '<code>',
110
-                '</code>'
111
-            ),
112
-            '[REGISTRATION_LIST_TABLE_FOR_EVENT_URL]' => esc_html__(
113
-                'This parses to the url for the registration list table filtered by registrations for this event.',
114
-                'event_espresso'
115
-            ),
116
-        );
117
-    }
118
-
119
-
120
-    protected function _parser($shortcode)
121
-    {
122
-
123
-
124
-        $this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
125
-
126
-        // if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the reg_obj instead.
127
-        if (empty($this->_event)) {
128
-            $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
129
-            $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
130
-
131
-            $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration
132
-                ? $aee->reg_obj->event() : null;
133
-        }
134
-
135
-
136
-        // If there is no event objecdt by now then get out.
137
-        if (! $this->_event instanceof EE_Event) {
138
-            return '';
139
-        }
140
-
141
-        switch ($shortcode) {
142
-            case '[EVENT_ID]':
143
-                return $this->_event->ID();
144
-                break;
145
-
146
-            case '[EVENT]':
147
-            case '[EVENT_NAME]':
148
-                return $this->_event->get('EVT_name');
149
-                break;
150
-
151
-            case '[EVENT_PHONE]':
152
-                return $this->_event->get('EVT_phone');
153
-                break;
154
-
155
-            case '[EVENT_DESCRIPTION]':
156
-                return $this->_event->get('EVT_desc');
157
-                break;
158
-
159
-            case '[EVENT_EXCERPT]':
160
-                return $this->_event->get('EVT_short_desc');
161
-                break;
162
-
163
-            case '[EVENT_LINK]':
164
-                return $this->_get_event_link($this->_event);
165
-                break;
166
-
167
-            case '[EVENT_URL]':
168
-                return $this->_get_event_link($this->_event, false);
169
-                break;
170
-
171
-            case '[VIRTUAL_URL]':
172
-                $venue = $this->_event->get_first_related('Venue');
173
-                if (empty($venue)) {
174
-                    return '';
175
-                }
176
-                return $venue->get('VNU_virtual_url');
177
-
178
-            case '[VIRTUAL_PHONE]':
179
-                $venue = $this->_event->get_first_related('Venue');
180
-                if (empty($venue)) {
181
-                    return '';
182
-                }
183
-                return $venue->get('VNU_virtual_phone');
184
-                break;
185
-
186
-            case '[EVENT_IMAGE]':
187
-                $image = $this->_event->feature_image_url(array(600, 300));
188
-                // @todo: eventually we should make this an attribute shortcode so that em can send along what size they want returned.
189
-                return ! empty($image)
190
-                    ? '<img src="' . $image . '" alt="'
191
-                      . sprintf(
192
-                          esc_attr__('%s Feature Image', 'event_espresso'),
193
-                          $this->_event->get('EVT_name')
194
-                      ) . '" />'
195
-                    : '';
196
-                break;
197
-
198
-            case '[EVENT_FACEBOOK_URL]':
199
-                $facebook_url = $this->_event->get_post_meta('event_facebook', true);
200
-                return empty($facebook_url) ? EE_Registry::instance()->CFG->organization->get_pretty('facebook')
201
-                    : $facebook_url;
202
-                break;
203
-
204
-            case '[EVENT_TWITTER_URL]':
205
-                $twitter_url = $this->_event->get_post_meta('event_twitter', true);
206
-                return empty($twitter_url) ? EE_Registry::instance()->CFG->organization->get_pretty('twitter')
207
-                    : $twitter_url;
208
-                break;
209
-
210
-            case '[EVENT_AUTHOR_EMAIL]':
211
-                $author_id = $this->_event->get('EVT_wp_user');
212
-                $user_data = get_userdata((int) $author_id);
213
-                return $user_data->user_email;
214
-                break;
215
-
216
-            case '[EVENT_TOTAL_SPOTS_TAKEN]':
217
-                return EEM_Registration::instance()->count(
218
-                    array(array('EVT_ID' => $this->_event->ID(), 'STS_ID' => EEM_Registration::status_id_approved)),
219
-                    'REG_ID',
220
-                    true
221
-                );
222
-                break;
223
-
224
-            case '[REGISTRATION_LIST_TABLE_FOR_EVENT_URL]':
225
-                return EEH_URL::add_query_args_and_nonce(
226
-                    array(
227
-                        'event_id' => $this->_event->ID(),
228
-                        'page'     => 'espresso_registrations',
229
-                        'action'   => 'default',
230
-                    ),
231
-                    admin_url('admin.php'),
232
-                    true
233
-                );
234
-                break;
235
-        }
236
-
237
-        if (strpos($shortcode, '[EVENT_META_*') !== false) {
238
-            // Strip the shortcode itself from $shortcode leaving any attributes set.
239
-            // Removing the * is correct here as _* is used to indiciate a dynamic shortcode.
240
-            $shortcode = str_replace('[EVENT_META_*', '', $shortcode);
241
-            $shortcode = trim(str_replace(']', '', $shortcode));
242
-            // Get any attributes set on this shortcode.
243
-            $attrs = $this->_get_shortcode_attrs($shortcode);
244
-            // The meta_key set on the shortcode should always be the first value in the array.
245
-            $meta_key = $attrs[0];
246
-            // Pull the meta value from the event post.
247
-            $event_meta = $this->_event->get_post_meta($meta_key, true);
248
-            // If we have no event_meta, just return an empty string.
249
-            if (empty($event_meta)) {
250
-                return '';
251
-            }
252
-            // Add a filter to allow all instances of EVENT_META_* to run through do_shortcode, default to false.
253
-            // Check if a do_shortcode attribute was set to true and if so run $event_meta through that function.
254
-            if (
255
-                apply_filters('FHEE__EventEspresso_core_libraries_shortcodes_EE_Event_Shortcodes___parser__event_meta_do_shortcode', false)
256
-                || !empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN)
257
-            ) {
258
-                return do_shortcode($event_meta);
259
-            }
260
-            // Still here? We just need to return the event_meta value as is.
261
-            return $event_meta;
262
-        }
263
-
264
-        if (strpos($shortcode, '[EVENT_TOTAL_AVAILABLE_SPACES_*') !== false) {
265
-            $attrs = $this->_get_shortcode_attrs($shortcode);
266
-            $method = empty($attrs['method']) ? 'current' : $attrs['method'];
267
-            $method = $method === 'current';
268
-            $available = $this->_event->total_available_spaces($method);
269
-            return $available === EE_INF ? '&infin;' : $available;
270
-        }
271
-
272
-        if (strpos($shortcode, '[EVENT_IMAGE_*') !== false) {
273
-            $attrs = $this->_get_shortcode_attrs($shortcode);
274
-            $width = empty($attrs['width']) ? '' : ' width="' . $attrs['width'] . '"';
275
-            $height = empty($attrs['height']) ? '' : ' height="' . $attrs['height'] . '"';
276
-
277
-            // Size may be set to a string such as 'tumbnail' or "width, height" eg - '200,200'
278
-            if (! empty($attrs['size'])) {
279
-                $size = explode(',', $attrs['size']);
280
-                if (count($size) === 1) {
281
-                    $size = $size[0];
282
-                }
283
-            } else {
284
-                $size = 'thumbnail';
285
-            }
286
-
287
-            $image = $this->_event->feature_image_url($size);
288
-
289
-            return ! empty($image)
290
-                ? '<img src="' . $image . '" alt="'
291
-                  . sprintf(
292
-                      esc_attr__('%s Feature Image', 'event_espresso'),
293
-                      $this->_event->get('EVT_name')
294
-                  ) . '"' . $width . $height . '/>'
295
-                : '';
296
-        }
297
-
298
-        return '';
299
-    }
300
-
301
-
302
-    /**
303
-     * returns the link to the event
304
-     *
305
-     * @param  boolean $full_link if TRUE (default) we return the html for the name of the event linked to the event.
306
-     *                            Otherwise we just return the url of the event.
307
-     * @return string
308
-     */
309
-    private function _get_event_link($event, $full_link = true)
310
-    {
311
-        $url = get_permalink($event->ID());
312
-
313
-        return $full_link ? '<a href="' . $url . '">' . $event->get('EVT_name') . '</a>' : $url;
314
-    }
22
+	/**
23
+	 * Will hold the EE_Event if available
24
+	 *
25
+	 * @var EE_Event
26
+	 */
27
+	protected $_event;
28
+
29
+
30
+	public function __construct()
31
+	{
32
+		parent::__construct();
33
+	}
34
+
35
+
36
+	protected function _init_props()
37
+	{
38
+		$this->label = esc_html__('Event Shortcodes', 'event_espresso');
39
+		$this->description = esc_html__('All shortcodes specific to event related data', 'event_espresso');
40
+		$this->_shortcodes = array(
41
+			'[EVENT_ID]'                              => esc_html__(
42
+				'Will be replaced by the event ID of an event',
43
+				'event_espresso'
44
+			),
45
+			'[EVENT]'                                 => esc_html__('The name of the event', 'event_espresso'),
46
+			'[EVENT_NAME]'                            => esc_html__(
47
+				"This also can be used for the name of the event",
48
+				'event_espresso'
49
+			),
50
+			'[EVENT_PHONE]'                           => esc_html__(
51
+				'The phone number for the event (usually an info number)',
52
+				'event_espresso'
53
+			),
54
+			'[EVENT_DESCRIPTION]'                     => esc_html__('The description of the event', 'event_espresso'),
55
+			'[EVENT_EXCERPT]'                         => esc_html__(
56
+				'This gets parsed to the value for the excerpt field in the event or blank if there is no excerpt.',
57
+				'event_espresso'
58
+			),
59
+			'[EVENT_LINK]'                            => esc_html__('A link associated with the event', 'event_espresso'),
60
+			'[EVENT_URL]'                             => esc_html__(
61
+				'A link to the event set up on the host site.',
62
+				'event_espresso'
63
+			),
64
+			'[VIRTUAL_URL]'                           => esc_html__(
65
+				'What was used for the "URL of Event" field in the Venue settings',
66
+				'event_espresso'
67
+			),
68
+			'[VIRTUAL_PHONE]'                         => esc_html__(
69
+				'An alternate phone number for the event. Typically used as a "call-in" number',
70
+				'event_espresso'
71
+			),
72
+			'[EVENT_IMAGE]'                           => esc_html__(
73
+				'This will parse to the Feature image for the event.',
74
+				'event_espresso'
75
+			),
76
+			'[EVENT_IMAGE_*]'                         => sprintf(
77
+				esc_html__(
78
+					'This will parse to the Feature image for the event, %1$ssize%2$s can be set to determine the size of the image loaded by the shortcode. The %1$swidth%2$s and/or %1$sheight%2$s can also be set to determine the width and height of the image when output. By default the shortcode will load the %1$sthumbnail%2$s image size.',
79
+					'event_espresso'
80
+				),
81
+				'<code>',
82
+				'</code>'
83
+			),
84
+			'[EVENT_TOTAL_AVAILABLE_SPACES_*]'        => sprintf(
85
+				esc_html__(
86
+					'This will parse to the total available spaces for an event. Calculating total spaces is approximate because it is dependent on the complexity of limits on your event.  There are two methods of calculation (which can be indicated by the %1$smethod%2$s param on the shortcode).  %1$scurrent%2$s which will do a more accurate calculation of total available spaces based on current sales, and %1$sfull%2$s which will be the maximum total available spaces that is on the event in optimal conditions. The shortcode will default to current.',
87
+					'event_espresso'
88
+				),
89
+				'<code>',
90
+				'</code>'
91
+			),
92
+			'[EVENT_TOTAL_SPOTS_TAKEN]'               => esc_html__(
93
+				'This shortcode will parse to the output the total approved registrations for this event',
94
+				'event_espresso'
95
+			),
96
+			'[EVENT_FACEBOOK_URL]'                    => esc_html__(
97
+				'This will return the Facebook URL for the event if you have it set via custom field in your event, otherwise it will use the Facebook URL set in "Your Organization Settings". To set the facebook url in your event, add a custom field with the key as <code>event_facebook</code> and the value as your facebook url.',
98
+				'event_espresso'
99
+			),
100
+			'[EVENT_TWITTER_URL]'                     => esc_html__(
101
+				'This will return the Twitter URL for the event if you have it set via custom field in your event, otherwise it will use the Twitter URL set in "Your Organization Settings". To set the facebook url in your event, add a custom field with the key as <code>event_twitter</code> and the value as your facebook url',
102
+				'event_espresso'
103
+			),
104
+			'[EVENT_META_*]'                          => sprintf(
105
+				esc_html__(
106
+					'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the event then it will be output in place of this shortcode. If you use shortcodes within your custom fields set %1$sdo_shortcode=true%2$s at the end of the shortcode to run the value through the do_shortcode function. ',
107
+					'event_espresso'
108
+				),
109
+				'<code>',
110
+				'</code>'
111
+			),
112
+			'[REGISTRATION_LIST_TABLE_FOR_EVENT_URL]' => esc_html__(
113
+				'This parses to the url for the registration list table filtered by registrations for this event.',
114
+				'event_espresso'
115
+			),
116
+		);
117
+	}
118
+
119
+
120
+	protected function _parser($shortcode)
121
+	{
122
+
123
+
124
+		$this->_event = $this->_data instanceof EE_Event ? $this->_data : null;
125
+
126
+		// if no event, then let's see if there is a reg_obj.  If there IS, then we'll try and grab the event from the reg_obj instead.
127
+		if (empty($this->_event)) {
128
+			$aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
129
+			$aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee;
130
+
131
+			$this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration
132
+				? $aee->reg_obj->event() : null;
133
+		}
134
+
135
+
136
+		// If there is no event objecdt by now then get out.
137
+		if (! $this->_event instanceof EE_Event) {
138
+			return '';
139
+		}
140
+
141
+		switch ($shortcode) {
142
+			case '[EVENT_ID]':
143
+				return $this->_event->ID();
144
+				break;
145
+
146
+			case '[EVENT]':
147
+			case '[EVENT_NAME]':
148
+				return $this->_event->get('EVT_name');
149
+				break;
150
+
151
+			case '[EVENT_PHONE]':
152
+				return $this->_event->get('EVT_phone');
153
+				break;
154
+
155
+			case '[EVENT_DESCRIPTION]':
156
+				return $this->_event->get('EVT_desc');
157
+				break;
158
+
159
+			case '[EVENT_EXCERPT]':
160
+				return $this->_event->get('EVT_short_desc');
161
+				break;
162
+
163
+			case '[EVENT_LINK]':
164
+				return $this->_get_event_link($this->_event);
165
+				break;
166
+
167
+			case '[EVENT_URL]':
168
+				return $this->_get_event_link($this->_event, false);
169
+				break;
170
+
171
+			case '[VIRTUAL_URL]':
172
+				$venue = $this->_event->get_first_related('Venue');
173
+				if (empty($venue)) {
174
+					return '';
175
+				}
176
+				return $venue->get('VNU_virtual_url');
177
+
178
+			case '[VIRTUAL_PHONE]':
179
+				$venue = $this->_event->get_first_related('Venue');
180
+				if (empty($venue)) {
181
+					return '';
182
+				}
183
+				return $venue->get('VNU_virtual_phone');
184
+				break;
185
+
186
+			case '[EVENT_IMAGE]':
187
+				$image = $this->_event->feature_image_url(array(600, 300));
188
+				// @todo: eventually we should make this an attribute shortcode so that em can send along what size they want returned.
189
+				return ! empty($image)
190
+					? '<img src="' . $image . '" alt="'
191
+					  . sprintf(
192
+						  esc_attr__('%s Feature Image', 'event_espresso'),
193
+						  $this->_event->get('EVT_name')
194
+					  ) . '" />'
195
+					: '';
196
+				break;
197
+
198
+			case '[EVENT_FACEBOOK_URL]':
199
+				$facebook_url = $this->_event->get_post_meta('event_facebook', true);
200
+				return empty($facebook_url) ? EE_Registry::instance()->CFG->organization->get_pretty('facebook')
201
+					: $facebook_url;
202
+				break;
203
+
204
+			case '[EVENT_TWITTER_URL]':
205
+				$twitter_url = $this->_event->get_post_meta('event_twitter', true);
206
+				return empty($twitter_url) ? EE_Registry::instance()->CFG->organization->get_pretty('twitter')
207
+					: $twitter_url;
208
+				break;
209
+
210
+			case '[EVENT_AUTHOR_EMAIL]':
211
+				$author_id = $this->_event->get('EVT_wp_user');
212
+				$user_data = get_userdata((int) $author_id);
213
+				return $user_data->user_email;
214
+				break;
215
+
216
+			case '[EVENT_TOTAL_SPOTS_TAKEN]':
217
+				return EEM_Registration::instance()->count(
218
+					array(array('EVT_ID' => $this->_event->ID(), 'STS_ID' => EEM_Registration::status_id_approved)),
219
+					'REG_ID',
220
+					true
221
+				);
222
+				break;
223
+
224
+			case '[REGISTRATION_LIST_TABLE_FOR_EVENT_URL]':
225
+				return EEH_URL::add_query_args_and_nonce(
226
+					array(
227
+						'event_id' => $this->_event->ID(),
228
+						'page'     => 'espresso_registrations',
229
+						'action'   => 'default',
230
+					),
231
+					admin_url('admin.php'),
232
+					true
233
+				);
234
+				break;
235
+		}
236
+
237
+		if (strpos($shortcode, '[EVENT_META_*') !== false) {
238
+			// Strip the shortcode itself from $shortcode leaving any attributes set.
239
+			// Removing the * is correct here as _* is used to indiciate a dynamic shortcode.
240
+			$shortcode = str_replace('[EVENT_META_*', '', $shortcode);
241
+			$shortcode = trim(str_replace(']', '', $shortcode));
242
+			// Get any attributes set on this shortcode.
243
+			$attrs = $this->_get_shortcode_attrs($shortcode);
244
+			// The meta_key set on the shortcode should always be the first value in the array.
245
+			$meta_key = $attrs[0];
246
+			// Pull the meta value from the event post.
247
+			$event_meta = $this->_event->get_post_meta($meta_key, true);
248
+			// If we have no event_meta, just return an empty string.
249
+			if (empty($event_meta)) {
250
+				return '';
251
+			}
252
+			// Add a filter to allow all instances of EVENT_META_* to run through do_shortcode, default to false.
253
+			// Check if a do_shortcode attribute was set to true and if so run $event_meta through that function.
254
+			if (
255
+				apply_filters('FHEE__EventEspresso_core_libraries_shortcodes_EE_Event_Shortcodes___parser__event_meta_do_shortcode', false)
256
+				|| !empty($attrs['do_shortcode']) && filter_var($attrs['do_shortcode'], FILTER_VALIDATE_BOOLEAN)
257
+			) {
258
+				return do_shortcode($event_meta);
259
+			}
260
+			// Still here? We just need to return the event_meta value as is.
261
+			return $event_meta;
262
+		}
263
+
264
+		if (strpos($shortcode, '[EVENT_TOTAL_AVAILABLE_SPACES_*') !== false) {
265
+			$attrs = $this->_get_shortcode_attrs($shortcode);
266
+			$method = empty($attrs['method']) ? 'current' : $attrs['method'];
267
+			$method = $method === 'current';
268
+			$available = $this->_event->total_available_spaces($method);
269
+			return $available === EE_INF ? '&infin;' : $available;
270
+		}
271
+
272
+		if (strpos($shortcode, '[EVENT_IMAGE_*') !== false) {
273
+			$attrs = $this->_get_shortcode_attrs($shortcode);
274
+			$width = empty($attrs['width']) ? '' : ' width="' . $attrs['width'] . '"';
275
+			$height = empty($attrs['height']) ? '' : ' height="' . $attrs['height'] . '"';
276
+
277
+			// Size may be set to a string such as 'tumbnail' or "width, height" eg - '200,200'
278
+			if (! empty($attrs['size'])) {
279
+				$size = explode(',', $attrs['size']);
280
+				if (count($size) === 1) {
281
+					$size = $size[0];
282
+				}
283
+			} else {
284
+				$size = 'thumbnail';
285
+			}
286
+
287
+			$image = $this->_event->feature_image_url($size);
288
+
289
+			return ! empty($image)
290
+				? '<img src="' . $image . '" alt="'
291
+				  . sprintf(
292
+					  esc_attr__('%s Feature Image', 'event_espresso'),
293
+					  $this->_event->get('EVT_name')
294
+				  ) . '"' . $width . $height . '/>'
295
+				: '';
296
+		}
297
+
298
+		return '';
299
+	}
300
+
301
+
302
+	/**
303
+	 * returns the link to the event
304
+	 *
305
+	 * @param  boolean $full_link if TRUE (default) we return the html for the name of the event linked to the event.
306
+	 *                            Otherwise we just return the url of the event.
307
+	 * @return string
308
+	 */
309
+	private function _get_event_link($event, $full_link = true)
310
+	{
311
+		$url = get_permalink($event->ID());
312
+
313
+		return $full_link ? '<a href="' . $url . '">' . $event->get('EVT_name') . '</a>' : $url;
314
+	}
315 315
 }
Please login to merge, or discard this patch.
core/libraries/shortcodes/EE_Primary_Registration_List_Shortcodes.lib.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
     private function _get_recipient_ticket_list_parsed(EE_Messages_Addressee $data, $primary = false)
84 84
     {
85 85
         $registration = $primary ? $data->primary_reg_obj : $data->reg_obj;
86
-        if (! $registration instanceof EE_Registration) {
86
+        if ( ! $registration instanceof EE_Registration) {
87 87
             return '';
88 88
         }
89 89
         // setup valid shortcodes depending on what the status of the $this->_data property is
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
                 'attendee',
98 98
             );
99 99
             $template = $this->_data['template'];
100
-            $tkts = array($data->registrations[ $registration->ID() ]['tkt_obj']);
100
+            $tkts = array($data->registrations[$registration->ID()]['tkt_obj']);
101 101
             $data = $this->_data;
102 102
         } elseif ($this->_data['data'] instanceof EE_Event) {
103 103
             $valid_shortcodes = array('ticket', 'attendee_list', 'datetime_list', 'attendee');
@@ -127,16 +127,16 @@  discard block
 block discarded – undo
127 127
 
128 128
     private function _get_tickets_from_event(EE_Event $event, $reg = null)
129 129
     {
130
-        $evt_tkts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID(
131
-        ) ]['tkt_objs'] : array();
130
+        $evt_tkts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[$event->ID(
131
+        )]['tkt_objs'] : array();
132 132
 
133 133
         if ($reg instanceof EE_Registration && $this->_extra_data['data'] instanceof EE_Messages_Addressee) {
134 134
             $adj_tkts = array();
135 135
             // return only tickets for the given attendee
136 136
             foreach ($evt_tkts as $tkt) {
137 137
                 if (
138
-                    isset($this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj'])
139
-                    && $this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj']->ID() == $tkt->ID()
138
+                    isset($this->_extra_data['data']->registrations[$reg->ID()]['tkt_obj'])
139
+                    && $this->_extra_data['data']->registrations[$reg->ID()]['tkt_obj']->ID() == $tkt->ID()
140 140
                 ) {
141 141
                     $adj_tkts[] = $tkt;
142 142
                 }
@@ -172,14 +172,14 @@  discard block
 block discarded – undo
172 172
     private function _get_recipient_datetime_list_parsed(EE_Messages_Addressee $data, $primary = false)
173 173
     {
174 174
         $registration = $primary ? $data->primary_reg_obj : $data->reg_obj;
175
-        if (! $registration instanceof EE_Registration) {
175
+        if ( ! $registration instanceof EE_Registration) {
176 176
             return '';
177 177
         }
178 178
         // setup valid shortcodes depending on what the status of the $this->_data property is
179 179
         if ($this->_data['data'] instanceof EE_Messages_Addressee) {
180 180
             $valid_shortcodes = array('datetime', 'attendee');
181 181
             $template = $this->_data['template'];
182
-            $dtts = $data->registrations[ $registration->ID() ]['dtt_objs'];
182
+            $dtts = $data->registrations[$registration->ID()]['dtt_objs'];
183 183
             $data = $this->_data;
184 184
         } elseif ($this->_data['data'] instanceof EE_Event) {
185 185
             $valid_shortcodes = array('datetime', 'attendee');
@@ -206,14 +206,14 @@  discard block
 block discarded – undo
206 206
 
207 207
     private function _get_datetimes_from_event(EE_Event $event, $reg = null)
208 208
     {
209
-        $evt_dtts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID(
210
-        ) ]['dtt_objs'] : array();
209
+        $evt_dtts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[$event->ID(
210
+        )]['dtt_objs'] : array();
211 211
 
212 212
         if ($reg instanceof EE_Registration && $this->_extra_data['data'] instanceof EE_Messages_Addressee) {
213 213
             $adj_dtts = array();
214 214
             // return only dtts for the given attendee
215 215
             foreach ($evt_dtts as $dtt) {
216
-                if (isset($this->_extra_data['data']->registrations[ $reg->ID() ]['dtt_objs'][ $dtt->ID() ])) {
216
+                if (isset($this->_extra_data['data']->registrations[$reg->ID()]['dtt_objs'][$dtt->ID()])) {
217 217
                     $adj_dtts[] = $dtt;
218 218
                 }
219 219
             }
Please login to merge, or discard this patch.
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -19,206 +19,206 @@
 block discarded – undo
19 19
 class EE_Primary_Registration_List_Shortcodes extends EE_Shortcodes
20 20
 {
21 21
 
22
-    public function __construct()
23
-    {
24
-        parent::__construct();
25
-    }
26
-
27
-
28
-    protected function _init_props()
29
-    {
30
-        $this->label = esc_html__('Primary Registrant List Shortcodes', 'event_espresso');
31
-        $this->description = esc_html__(
32
-            'All shortcodes specific primary registrant recipients list type data.',
33
-            'event_espresso'
34
-        );
35
-        $this->_shortcodes = array(
36
-            '[PRIMARY_REGISTRANT_TICKET_LIST]' => esc_html__(
37
-                'Will output a list of tickets that the primary registration received.',
38
-                'event_espresso'
39
-            ),
40
-            '[PRIMARY_REGISTRANT_DATETIME_LIST]' => esc_html__(
41
-                'Will output a list of datetimes that the primary registrant for the transaction has been registered for.',
42
-                'event_espresso'
43
-            ),
44
-        );
45
-    }
46
-
47
-
48
-    protected function _parser($shortcode)
49
-    {
50
-        switch ($shortcode) {
51
-            case '[PRIMARY_REGISTRANT_TICKET_LIST]':
52
-                return $this->_get_recipient_ticket_list(true);
53
-                break;
54
-
55
-            case '[PRIMARY_REGISTRANT_DATETIME_LIST]':
56
-                return $this->_get_recipient_datetime_list(true);
57
-                break;
58
-        }
59
-        return '';
60
-    }
61
-
62
-
63
-    /**
64
-     * figure out what the incoming data is and then return the appropriate parsed value
65
-     *
66
-     * @param  boolean $primary whether we're getting the primary registrant ticket_list.
67
-     * @return string
68
-     */
69
-    private function _get_recipient_ticket_list($primary = false)
70
-    {
71
-        $this->_validate_list_requirements();
72
-
73
-        if ($this->_data['data'] instanceof EE_Messages_Addressee) {
74
-            return $this->_get_recipient_ticket_list_parsed($this->_data['data'], $primary);
75
-        } elseif ($this->_extra_data['data'] instanceof EE_Messages_Addressee) {
76
-            return $this->_get_recipient_ticket_list_parsed($this->_extra_data['data'], $primary);
77
-        } else {
78
-            return '';
79
-        }
80
-    }
81
-
82
-
83
-    private function _get_recipient_ticket_list_parsed(EE_Messages_Addressee $data, $primary = false)
84
-    {
85
-        $registration = $primary ? $data->primary_reg_obj : $data->reg_obj;
86
-        if (! $registration instanceof EE_Registration) {
87
-            return '';
88
-        }
89
-        // setup valid shortcodes depending on what the status of the $this->_data property is
90
-        if ($this->_data['data'] instanceof EE_Messages_Addressee) {
91
-            $valid_shortcodes = array(
92
-                'ticket',
93
-                'event_list',
94
-                'attendee_list',
95
-                'datetime_list',
96
-                'registration_details',
97
-                'attendee',
98
-            );
99
-            $template = $this->_data['template'];
100
-            $tkts = array($data->registrations[ $registration->ID() ]['tkt_obj']);
101
-            $data = $this->_data;
102
-        } elseif ($this->_data['data'] instanceof EE_Event) {
103
-            $valid_shortcodes = array('ticket', 'attendee_list', 'datetime_list', 'attendee');
104
-            $template = is_array($this->_data['template']) && isset($this->_data['template']['ticket_list'])
105
-                ? $this->_data['template']['ticket_list'] : $this->_extra_data['template']['ticket_list'];
106
-            // let's remove any existing [EVENT_LIST] shortcode from the ticket list template so that we don't get recursion.
107
-            $template = str_replace('[EVENT_LIST]', '', $template);
108
-            // data will be tickets for this event for this recipient.
109
-            $tkts = $this->_get_tickets_from_event($this->_data['data'], $registration);
110
-            $data = $this->_extra_data;
111
-        } else {
112
-            return '';
113
-        }
114
-
115
-        $tktparsed = '';
116
-        foreach ($tkts as $ticket) {
117
-            $tktparsed .= $this->_shortcode_helper->parse_ticket_list_template(
118
-                $template,
119
-                $ticket,
120
-                $valid_shortcodes,
121
-                $data
122
-            );
123
-        }
124
-        return $tktparsed;
125
-    }
126
-
127
-
128
-    private function _get_tickets_from_event(EE_Event $event, $reg = null)
129
-    {
130
-        $evt_tkts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID(
131
-        ) ]['tkt_objs'] : array();
132
-
133
-        if ($reg instanceof EE_Registration && $this->_extra_data['data'] instanceof EE_Messages_Addressee) {
134
-            $adj_tkts = array();
135
-            // return only tickets for the given attendee
136
-            foreach ($evt_tkts as $tkt) {
137
-                if (
138
-                    isset($this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj'])
139
-                    && $this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj']->ID() == $tkt->ID()
140
-                ) {
141
-                    $adj_tkts[] = $tkt;
142
-                }
143
-            }
144
-            $evt_tkts = $adj_tkts;
145
-        }
146
-        return $evt_tkts;
147
-    }
148
-
149
-
150
-    /**
151
-     * figure out what the incoming data is and then return the appropriate parsed value
152
-     *
153
-     * @param  boolean $primary whether we're getting the primary registrant ticket_list.
154
-     * @return string
155
-     */
156
-    private function _get_recipient_datetime_list($primary = false)
157
-    {
158
-        $this->_validate_list_requirements();
159
-
160
-        if ($this->_data['data'] instanceof EE_Messages_Addressee) {
161
-            return $this->_get_recipient_datetime_list_parsed($this->_data['data'], $primary);
162
-        } elseif ($this->_extra_data['data'] instanceof EE_Messages_Addressee) {
163
-            return $this->_get_recipient_datetime_list_parsed($this->_extra_data['data'], $primary);
164
-        } else {
165
-            return '';
166
-        }
167
-
168
-        return $this->_get_recipient_datetime_list_parsed($this->_data['data'], $primary);
169
-    }
170
-
171
-
172
-    private function _get_recipient_datetime_list_parsed(EE_Messages_Addressee $data, $primary = false)
173
-    {
174
-        $registration = $primary ? $data->primary_reg_obj : $data->reg_obj;
175
-        if (! $registration instanceof EE_Registration) {
176
-            return '';
177
-        }
178
-        // setup valid shortcodes depending on what the status of the $this->_data property is
179
-        if ($this->_data['data'] instanceof EE_Messages_Addressee) {
180
-            $valid_shortcodes = array('datetime', 'attendee');
181
-            $template = $this->_data['template'];
182
-            $dtts = $data->registrations[ $registration->ID() ]['dtt_objs'];
183
-            $data = $this->_data;
184
-        } elseif ($this->_data['data'] instanceof EE_Event) {
185
-            $valid_shortcodes = array('datetime', 'attendee');
186
-            $template = is_array($this->_data['template']) && isset($this->_data['template']['datetime_list'])
187
-                ? $this->_data['template']['datetime_list'] : $this->_extra_data['template']['datetime_list'];
188
-            $dtts = $this->_get_datetimes_from_event($this->_data['data'], $registration);
189
-            $data = $this->_extra_data;
190
-        } else {
191
-            return '';
192
-        }
193
-
194
-        $dtt_parsed = '';
195
-        foreach ($dtts as $datetime) {
196
-            $dtt_parsed .= $this->_shortcode_helper->parse_datetime_list_template(
197
-                $template,
198
-                $datetime,
199
-                $valid_shortcodes,
200
-                $this->_extra_data
201
-            );
202
-        }
203
-        return $dtt_parsed;
204
-    }
205
-
206
-
207
-    private function _get_datetimes_from_event(EE_Event $event, $reg = null)
208
-    {
209
-        $evt_dtts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID(
210
-        ) ]['dtt_objs'] : array();
211
-
212
-        if ($reg instanceof EE_Registration && $this->_extra_data['data'] instanceof EE_Messages_Addressee) {
213
-            $adj_dtts = array();
214
-            // return only dtts for the given attendee
215
-            foreach ($evt_dtts as $dtt) {
216
-                if (isset($this->_extra_data['data']->registrations[ $reg->ID() ]['dtt_objs'][ $dtt->ID() ])) {
217
-                    $adj_dtts[] = $dtt;
218
-                }
219
-            }
220
-            $evt_dtts = $adj_dtts;
221
-        }
222
-        return $evt_dtts;
223
-    }
22
+	public function __construct()
23
+	{
24
+		parent::__construct();
25
+	}
26
+
27
+
28
+	protected function _init_props()
29
+	{
30
+		$this->label = esc_html__('Primary Registrant List Shortcodes', 'event_espresso');
31
+		$this->description = esc_html__(
32
+			'All shortcodes specific primary registrant recipients list type data.',
33
+			'event_espresso'
34
+		);
35
+		$this->_shortcodes = array(
36
+			'[PRIMARY_REGISTRANT_TICKET_LIST]' => esc_html__(
37
+				'Will output a list of tickets that the primary registration received.',
38
+				'event_espresso'
39
+			),
40
+			'[PRIMARY_REGISTRANT_DATETIME_LIST]' => esc_html__(
41
+				'Will output a list of datetimes that the primary registrant for the transaction has been registered for.',
42
+				'event_espresso'
43
+			),
44
+		);
45
+	}
46
+
47
+
48
+	protected function _parser($shortcode)
49
+	{
50
+		switch ($shortcode) {
51
+			case '[PRIMARY_REGISTRANT_TICKET_LIST]':
52
+				return $this->_get_recipient_ticket_list(true);
53
+				break;
54
+
55
+			case '[PRIMARY_REGISTRANT_DATETIME_LIST]':
56
+				return $this->_get_recipient_datetime_list(true);
57
+				break;
58
+		}
59
+		return '';
60
+	}
61
+
62
+
63
+	/**
64
+	 * figure out what the incoming data is and then return the appropriate parsed value
65
+	 *
66
+	 * @param  boolean $primary whether we're getting the primary registrant ticket_list.
67
+	 * @return string
68
+	 */
69
+	private function _get_recipient_ticket_list($primary = false)
70
+	{
71
+		$this->_validate_list_requirements();
72
+
73
+		if ($this->_data['data'] instanceof EE_Messages_Addressee) {
74
+			return $this->_get_recipient_ticket_list_parsed($this->_data['data'], $primary);
75
+		} elseif ($this->_extra_data['data'] instanceof EE_Messages_Addressee) {
76
+			return $this->_get_recipient_ticket_list_parsed($this->_extra_data['data'], $primary);
77
+		} else {
78
+			return '';
79
+		}
80
+	}
81
+
82
+
83
+	private function _get_recipient_ticket_list_parsed(EE_Messages_Addressee $data, $primary = false)
84
+	{
85
+		$registration = $primary ? $data->primary_reg_obj : $data->reg_obj;
86
+		if (! $registration instanceof EE_Registration) {
87
+			return '';
88
+		}
89
+		// setup valid shortcodes depending on what the status of the $this->_data property is
90
+		if ($this->_data['data'] instanceof EE_Messages_Addressee) {
91
+			$valid_shortcodes = array(
92
+				'ticket',
93
+				'event_list',
94
+				'attendee_list',
95
+				'datetime_list',
96
+				'registration_details',
97
+				'attendee',
98
+			);
99
+			$template = $this->_data['template'];
100
+			$tkts = array($data->registrations[ $registration->ID() ]['tkt_obj']);
101
+			$data = $this->_data;
102
+		} elseif ($this->_data['data'] instanceof EE_Event) {
103
+			$valid_shortcodes = array('ticket', 'attendee_list', 'datetime_list', 'attendee');
104
+			$template = is_array($this->_data['template']) && isset($this->_data['template']['ticket_list'])
105
+				? $this->_data['template']['ticket_list'] : $this->_extra_data['template']['ticket_list'];
106
+			// let's remove any existing [EVENT_LIST] shortcode from the ticket list template so that we don't get recursion.
107
+			$template = str_replace('[EVENT_LIST]', '', $template);
108
+			// data will be tickets for this event for this recipient.
109
+			$tkts = $this->_get_tickets_from_event($this->_data['data'], $registration);
110
+			$data = $this->_extra_data;
111
+		} else {
112
+			return '';
113
+		}
114
+
115
+		$tktparsed = '';
116
+		foreach ($tkts as $ticket) {
117
+			$tktparsed .= $this->_shortcode_helper->parse_ticket_list_template(
118
+				$template,
119
+				$ticket,
120
+				$valid_shortcodes,
121
+				$data
122
+			);
123
+		}
124
+		return $tktparsed;
125
+	}
126
+
127
+
128
+	private function _get_tickets_from_event(EE_Event $event, $reg = null)
129
+	{
130
+		$evt_tkts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID(
131
+		) ]['tkt_objs'] : array();
132
+
133
+		if ($reg instanceof EE_Registration && $this->_extra_data['data'] instanceof EE_Messages_Addressee) {
134
+			$adj_tkts = array();
135
+			// return only tickets for the given attendee
136
+			foreach ($evt_tkts as $tkt) {
137
+				if (
138
+					isset($this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj'])
139
+					&& $this->_extra_data['data']->registrations[ $reg->ID() ]['tkt_obj']->ID() == $tkt->ID()
140
+				) {
141
+					$adj_tkts[] = $tkt;
142
+				}
143
+			}
144
+			$evt_tkts = $adj_tkts;
145
+		}
146
+		return $evt_tkts;
147
+	}
148
+
149
+
150
+	/**
151
+	 * figure out what the incoming data is and then return the appropriate parsed value
152
+	 *
153
+	 * @param  boolean $primary whether we're getting the primary registrant ticket_list.
154
+	 * @return string
155
+	 */
156
+	private function _get_recipient_datetime_list($primary = false)
157
+	{
158
+		$this->_validate_list_requirements();
159
+
160
+		if ($this->_data['data'] instanceof EE_Messages_Addressee) {
161
+			return $this->_get_recipient_datetime_list_parsed($this->_data['data'], $primary);
162
+		} elseif ($this->_extra_data['data'] instanceof EE_Messages_Addressee) {
163
+			return $this->_get_recipient_datetime_list_parsed($this->_extra_data['data'], $primary);
164
+		} else {
165
+			return '';
166
+		}
167
+
168
+		return $this->_get_recipient_datetime_list_parsed($this->_data['data'], $primary);
169
+	}
170
+
171
+
172
+	private function _get_recipient_datetime_list_parsed(EE_Messages_Addressee $data, $primary = false)
173
+	{
174
+		$registration = $primary ? $data->primary_reg_obj : $data->reg_obj;
175
+		if (! $registration instanceof EE_Registration) {
176
+			return '';
177
+		}
178
+		// setup valid shortcodes depending on what the status of the $this->_data property is
179
+		if ($this->_data['data'] instanceof EE_Messages_Addressee) {
180
+			$valid_shortcodes = array('datetime', 'attendee');
181
+			$template = $this->_data['template'];
182
+			$dtts = $data->registrations[ $registration->ID() ]['dtt_objs'];
183
+			$data = $this->_data;
184
+		} elseif ($this->_data['data'] instanceof EE_Event) {
185
+			$valid_shortcodes = array('datetime', 'attendee');
186
+			$template = is_array($this->_data['template']) && isset($this->_data['template']['datetime_list'])
187
+				? $this->_data['template']['datetime_list'] : $this->_extra_data['template']['datetime_list'];
188
+			$dtts = $this->_get_datetimes_from_event($this->_data['data'], $registration);
189
+			$data = $this->_extra_data;
190
+		} else {
191
+			return '';
192
+		}
193
+
194
+		$dtt_parsed = '';
195
+		foreach ($dtts as $datetime) {
196
+			$dtt_parsed .= $this->_shortcode_helper->parse_datetime_list_template(
197
+				$template,
198
+				$datetime,
199
+				$valid_shortcodes,
200
+				$this->_extra_data
201
+			);
202
+		}
203
+		return $dtt_parsed;
204
+	}
205
+
206
+
207
+	private function _get_datetimes_from_event(EE_Event $event, $reg = null)
208
+	{
209
+		$evt_dtts = isset($this->_extra_data['data']->events) ? $this->_extra_data['data']->events[ $event->ID(
210
+		) ]['dtt_objs'] : array();
211
+
212
+		if ($reg instanceof EE_Registration && $this->_extra_data['data'] instanceof EE_Messages_Addressee) {
213
+			$adj_dtts = array();
214
+			// return only dtts for the given attendee
215
+			foreach ($evt_dtts as $dtt) {
216
+				if (isset($this->_extra_data['data']->registrations[ $reg->ID() ]['dtt_objs'][ $dtt->ID() ])) {
217
+					$adj_dtts[] = $dtt;
218
+				}
219
+			}
220
+			$evt_dtts = $adj_dtts;
221
+		}
222
+		return $evt_dtts;
223
+	}
224 224
 }
Please login to merge, or discard this patch.
libraries/shortcodes/EE_Primary_Registration_Details_Shortcodes.lib.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -99,14 +99,14 @@  discard block
 block discarded – undo
99 99
         $primary_registration = ! $primary_registration instanceof EE_Messages_Addressee && ! empty($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee
100 100
             ? $this->_extra_data['data'] : $primary_registration;
101 101
 
102
-        if (! $primary_registration instanceof EE_Messages_Addressee) {
102
+        if ( ! $primary_registration instanceof EE_Messages_Addressee) {
103 103
             return '';
104 104
         }
105 105
 
106 106
         $attendee = $primary_registration->primary_att_obj;
107 107
         $primary_reg = $primary_registration->primary_reg_obj;
108 108
 
109
-        if (! $attendee instanceof EE_Attendee || ! $primary_reg instanceof EE_Registration) {
109
+        if ( ! $attendee instanceof EE_Attendee || ! $primary_reg instanceof EE_Registration) {
110 110
             return '';
111 111
         }
112 112
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
                 break;
163 163
 
164 164
             case '[PRIMARY_REGISTRANT_REGISTRATION_DATE]':
165
-                if (! $primary_registration->primary_reg_obj instanceof EE_Registration) {
165
+                if ( ! $primary_registration->primary_reg_obj instanceof EE_Registration) {
166 166
                     return '';
167 167
                 }
168 168
                 return $primary_registration->primary_reg_obj->get_i18n_datetime('REG_date', get_option('date_format'));
@@ -187,9 +187,9 @@  discard block
 block discarded – undo
187 187
                 if (
188 188
                     $question instanceof EE_Question
189 189
                     && trim($question->get('QST_display_text')) === trim($shortcode)
190
-                    && isset($primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ])
190
+                    && isset($primary_registration->registrations[$primary_reg->ID()]['ans_objs'][$ansid])
191 191
                 ) {
192
-                    $primary_reg_ansid = $primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ];
192
+                    $primary_reg_ansid = $primary_registration->registrations[$primary_reg->ID()]['ans_objs'][$ansid];
193 193
 
194 194
                     // what we show for the answer depends on the question type!
195 195
                     switch ($question->get('QST_type')) {
Please login to merge, or discard this patch.
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -19,201 +19,201 @@
 block discarded – undo
19 19
 {
20 20
 
21 21
 
22
-    protected function _init_props()
23
-    {
24
-        $this->label = esc_html__('Primary_Registration Details Shortcodes', 'event_espresso');
25
-        $this->description = esc_html__('All shortcodes specific primary registrant data', 'event_espresso');
26
-        $this->_shortcodes = array(
27
-            '[PRIMARY_REGISTRANT_FNAME]'                  => esc_html__(
28
-                'Parses to the first name of the primary registration for the transaction.',
29
-                'event_espresso'
30
-            ),
31
-            '[PRIMARY_REGISTRANT_LNAME]'                  => esc_html__(
32
-                'Parses to the last name of the primary registration for the transaction.',
33
-                'event_espresso'
34
-            ),
35
-            '[PRIMARY_REGISTRANT_EMAIL]'                  => esc_html__(
36
-                'Parses to the email address of the primary registration for the transaction.',
37
-                'event_espresso'
38
-            ),
39
-            '[PRIMARY_REGISTRANT_REGISTRATION_ID]'        => esc_html__(
40
-                'Parses to the registration ID of the primary registrant for the transaction.',
41
-                'event_espresso'
42
-            ),
43
-            '[PRIMARY_REGISTRANT_REGISTRATION_CODE]'      => esc_html__(
44
-                'Parses to the registration code of the primary registrant for the transaction.',
45
-                'event_espresso'
46
-            ),
47
-            '[PRIMARY_REGISTRANT_PHONE_NUMBER]'           => esc_html__(
48
-                'The Phone Number for the primary registrant for the transaction.',
49
-                'event_espresso'
50
-            ),
51
-            '[PRIMARY_REGISTRANT_ADDRESS]'                => esc_html__(
52
-                'The Address for the primary registrant for the transaction.',
53
-                'event_espresso'
54
-            ),
55
-            '[PRIMARY_REGISTRANT_ADDRESS2]'               => esc_html__(
56
-                'Whatever was in the address 2 field for the primary registrant for the transaction.',
57
-                'event_espresso'
58
-            ),
59
-            '[PRIMARY_REGISTRANT_CITY]'                   => esc_html__(
60
-                'The city for the primary registrant for the transaction.',
61
-                'event_espresso'
62
-            ),
63
-            '[PRIMARY_REGISTRANT_ZIP_PC]'                 => esc_html__(
64
-                'The ZIP (or Postal) Code for the primary registrant for the transaction.',
65
-                'event_espresso'
66
-            ),
67
-            '[PRIMARY_REGISTRANT_ADDRESS_STATE]'          => esc_html__(
68
-                'The state/province for the primary registrant for the transaction.',
69
-                'event_espresso'
70
-            ),
71
-            '[PRIMARY_REGISTRANT_COUNTRY]'                => esc_html__(
72
-                'The country for the primary registrant for the transaction.',
73
-                'event_espresso'
74
-            ),
75
-            '[PRIMARY_REGISTRANT_REGISTRATION_DATE]'      => esc_html__(
76
-                'The date the registration occured for the primary registration.',
77
-                'event_espresso'
78
-            ),
79
-            '[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]' => esc_html__(
80
-                'Generates a link for the given registration to edit this registration details on the frontend.',
81
-                'event_espresso'
82
-            ),
83
-            '[PRIMARY_REGISTRANT_ANSWER_*]'               => esc_html__(
84
-                'This is a special dynamic shortcode.  After the "*", add the exact text of an existing question, and if there is an answer for that question for this primary registrant, then it will be output in place of this shortcode.',
85
-                'event_espresso'
86
-            ),
87
-        );
88
-    }
89
-
90
-
91
-    protected function _parser($shortcode)
92
-    {
93
-        // make sure we end up with a copy of the EE_Messages_Addressee object
94
-        $primary_registration = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
95
-        $primary_registration = ! $primary_registration instanceof EE_Messages_Addressee && is_array(
96
-            $this->_data
97
-        ) && isset($this->_data['data']) && $this->_data['data'] instanceof EE_Messages_Addressee ? $this->_data['data']
98
-            : $primary_registration;
99
-        $primary_registration = ! $primary_registration instanceof EE_Messages_Addressee && ! empty($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee
100
-            ? $this->_extra_data['data'] : $primary_registration;
101
-
102
-        if (! $primary_registration instanceof EE_Messages_Addressee) {
103
-            return '';
104
-        }
105
-
106
-        $attendee = $primary_registration->primary_att_obj;
107
-        $primary_reg = $primary_registration->primary_reg_obj;
108
-
109
-        if (! $attendee instanceof EE_Attendee || ! $primary_reg instanceof EE_Registration) {
110
-            return '';
111
-        }
112
-
113
-        switch ($shortcode) {
114
-            case '[PRIMARY_REGISTRANT_FNAME]':
115
-                return $attendee->fname();
116
-                break;
117
-
118
-            case '[PRIMARY_REGISTRANT_LNAME]':
119
-                return $attendee->lname();
120
-                break;
121
-
122
-            case '[PRIMARY_REGISTRANT_EMAIL]':
123
-                return $attendee->email();
124
-                break;
125
-
126
-            case '[PRIMARY_REGISTRANT_REGISTRATION_ID]':
127
-                return $primary_reg->ID();
128
-                break;
129
-
130
-            case '[PRIMARY_REGISTRANT_REGISTRATION_CODE]':
131
-                return $primary_reg->reg_code();
132
-                break;
133
-
134
-            case '[PRIMARY_REGISTRANT_PHONE_NUMBER]':
135
-                return $attendee->phone();
136
-                break;
137
-
138
-            case '[PRIMARY_REGISTRANT_ADDRESS]':
139
-                return $attendee->address();
140
-                break;
141
-
142
-            case '[PRIMARY_REGISTRANT_ADDRESS2]':
143
-                return $attendee->address2();
144
-                break;
145
-
146
-            case '[PRIMARY_REGISTRANT_CITY]':
147
-                return $attendee->city();
148
-                break;
149
-
150
-            case '[PRIMARY_REGISTRANT_ZIP_PC]':
151
-                return $attendee->zip();
152
-                break;
153
-
154
-            case '[PRIMARY_REGISTRANT_ADDRESS_STATE]':
155
-                $state_obj = $attendee->state_obj();
156
-                return $state_obj instanceof EE_State ? $state_obj->name() : '';
157
-                break;
158
-
159
-            case '[PRIMARY_REGISTRANT_COUNTRY]':
160
-                $country_obj = $attendee->country_obj();
161
-                return $country_obj instanceof EE_Country ? $country_obj->name() : '';
162
-                break;
163
-
164
-            case '[PRIMARY_REGISTRANT_REGISTRATION_DATE]':
165
-                if (! $primary_registration->primary_reg_obj instanceof EE_Registration) {
166
-                    return '';
167
-                }
168
-                return $primary_registration->primary_reg_obj->get_i18n_datetime('REG_date', get_option('date_format'));
169
-                break;
170
-
171
-            case '[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]':
172
-                return $primary_reg->edit_attendee_information_url();
173
-                break;
174
-        }
175
-
176
-        if (strpos($shortcode, '[PRIMARY_REGISTRANT_ANSWER_*') !== false) {
177
-            $shortcode = str_replace('[PRIMARY_REGISTRANT_ANSWER_*', '', $shortcode);
178
-            $shortcode = trim(str_replace(']', '', $shortcode));
179
-
180
-
181
-            // now let's figure out what question has this text
182
-            if (empty($primary_registration->questions)) {
183
-                return '';
184
-            }
185
-
186
-            foreach ($primary_registration->questions as $ansid => $question) {
187
-                if (
188
-                    $question instanceof EE_Question
189
-                    && trim($question->get('QST_display_text')) === trim($shortcode)
190
-                    && isset($primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ])
191
-                ) {
192
-                    $primary_reg_ansid = $primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ];
193
-
194
-                    // what we show for the answer depends on the question type!
195
-                    switch ($question->get('QST_type')) {
196
-                        case EEM_Question::QST_type_state:
197
-                            $state = EEM_State::instance()->get_one_by_ID($primary_reg_ansid->get('ANS_value'));
198
-                            $answer = $state instanceof EE_State ? $state->name() : '';
199
-                            break;
200
-
201
-                        case EEM_Question::QST_type_country:
202
-                            $country = EEM_Country::instance()->get_one_by_ID($primary_reg_ansid->get('ANS_value'));
203
-                            $answer = $country instanceof EE_Country ? $country->name() : '';
204
-                            break;
205
-
206
-                        default:
207
-                            $answer = $primary_reg_ansid->get_pretty('ANS_value', 'no_wpautop');
208
-                            break;
209
-                    }
210
-
211
-                    return $answer;
212
-                    break;
213
-                }
214
-            }
215
-        }
216
-
217
-        return '';
218
-    }
22
+	protected function _init_props()
23
+	{
24
+		$this->label = esc_html__('Primary_Registration Details Shortcodes', 'event_espresso');
25
+		$this->description = esc_html__('All shortcodes specific primary registrant data', 'event_espresso');
26
+		$this->_shortcodes = array(
27
+			'[PRIMARY_REGISTRANT_FNAME]'                  => esc_html__(
28
+				'Parses to the first name of the primary registration for the transaction.',
29
+				'event_espresso'
30
+			),
31
+			'[PRIMARY_REGISTRANT_LNAME]'                  => esc_html__(
32
+				'Parses to the last name of the primary registration for the transaction.',
33
+				'event_espresso'
34
+			),
35
+			'[PRIMARY_REGISTRANT_EMAIL]'                  => esc_html__(
36
+				'Parses to the email address of the primary registration for the transaction.',
37
+				'event_espresso'
38
+			),
39
+			'[PRIMARY_REGISTRANT_REGISTRATION_ID]'        => esc_html__(
40
+				'Parses to the registration ID of the primary registrant for the transaction.',
41
+				'event_espresso'
42
+			),
43
+			'[PRIMARY_REGISTRANT_REGISTRATION_CODE]'      => esc_html__(
44
+				'Parses to the registration code of the primary registrant for the transaction.',
45
+				'event_espresso'
46
+			),
47
+			'[PRIMARY_REGISTRANT_PHONE_NUMBER]'           => esc_html__(
48
+				'The Phone Number for the primary registrant for the transaction.',
49
+				'event_espresso'
50
+			),
51
+			'[PRIMARY_REGISTRANT_ADDRESS]'                => esc_html__(
52
+				'The Address for the primary registrant for the transaction.',
53
+				'event_espresso'
54
+			),
55
+			'[PRIMARY_REGISTRANT_ADDRESS2]'               => esc_html__(
56
+				'Whatever was in the address 2 field for the primary registrant for the transaction.',
57
+				'event_espresso'
58
+			),
59
+			'[PRIMARY_REGISTRANT_CITY]'                   => esc_html__(
60
+				'The city for the primary registrant for the transaction.',
61
+				'event_espresso'
62
+			),
63
+			'[PRIMARY_REGISTRANT_ZIP_PC]'                 => esc_html__(
64
+				'The ZIP (or Postal) Code for the primary registrant for the transaction.',
65
+				'event_espresso'
66
+			),
67
+			'[PRIMARY_REGISTRANT_ADDRESS_STATE]'          => esc_html__(
68
+				'The state/province for the primary registrant for the transaction.',
69
+				'event_espresso'
70
+			),
71
+			'[PRIMARY_REGISTRANT_COUNTRY]'                => esc_html__(
72
+				'The country for the primary registrant for the transaction.',
73
+				'event_espresso'
74
+			),
75
+			'[PRIMARY_REGISTRANT_REGISTRATION_DATE]'      => esc_html__(
76
+				'The date the registration occured for the primary registration.',
77
+				'event_espresso'
78
+			),
79
+			'[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]' => esc_html__(
80
+				'Generates a link for the given registration to edit this registration details on the frontend.',
81
+				'event_espresso'
82
+			),
83
+			'[PRIMARY_REGISTRANT_ANSWER_*]'               => esc_html__(
84
+				'This is a special dynamic shortcode.  After the "*", add the exact text of an existing question, and if there is an answer for that question for this primary registrant, then it will be output in place of this shortcode.',
85
+				'event_espresso'
86
+			),
87
+		);
88
+	}
89
+
90
+
91
+	protected function _parser($shortcode)
92
+	{
93
+		// make sure we end up with a copy of the EE_Messages_Addressee object
94
+		$primary_registration = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null;
95
+		$primary_registration = ! $primary_registration instanceof EE_Messages_Addressee && is_array(
96
+			$this->_data
97
+		) && isset($this->_data['data']) && $this->_data['data'] instanceof EE_Messages_Addressee ? $this->_data['data']
98
+			: $primary_registration;
99
+		$primary_registration = ! $primary_registration instanceof EE_Messages_Addressee && ! empty($this->_extra_data['data']) && $this->_extra_data['data'] instanceof EE_Messages_Addressee
100
+			? $this->_extra_data['data'] : $primary_registration;
101
+
102
+		if (! $primary_registration instanceof EE_Messages_Addressee) {
103
+			return '';
104
+		}
105
+
106
+		$attendee = $primary_registration->primary_att_obj;
107
+		$primary_reg = $primary_registration->primary_reg_obj;
108
+
109
+		if (! $attendee instanceof EE_Attendee || ! $primary_reg instanceof EE_Registration) {
110
+			return '';
111
+		}
112
+
113
+		switch ($shortcode) {
114
+			case '[PRIMARY_REGISTRANT_FNAME]':
115
+				return $attendee->fname();
116
+				break;
117
+
118
+			case '[PRIMARY_REGISTRANT_LNAME]':
119
+				return $attendee->lname();
120
+				break;
121
+
122
+			case '[PRIMARY_REGISTRANT_EMAIL]':
123
+				return $attendee->email();
124
+				break;
125
+
126
+			case '[PRIMARY_REGISTRANT_REGISTRATION_ID]':
127
+				return $primary_reg->ID();
128
+				break;
129
+
130
+			case '[PRIMARY_REGISTRANT_REGISTRATION_CODE]':
131
+				return $primary_reg->reg_code();
132
+				break;
133
+
134
+			case '[PRIMARY_REGISTRANT_PHONE_NUMBER]':
135
+				return $attendee->phone();
136
+				break;
137
+
138
+			case '[PRIMARY_REGISTRANT_ADDRESS]':
139
+				return $attendee->address();
140
+				break;
141
+
142
+			case '[PRIMARY_REGISTRANT_ADDRESS2]':
143
+				return $attendee->address2();
144
+				break;
145
+
146
+			case '[PRIMARY_REGISTRANT_CITY]':
147
+				return $attendee->city();
148
+				break;
149
+
150
+			case '[PRIMARY_REGISTRANT_ZIP_PC]':
151
+				return $attendee->zip();
152
+				break;
153
+
154
+			case '[PRIMARY_REGISTRANT_ADDRESS_STATE]':
155
+				$state_obj = $attendee->state_obj();
156
+				return $state_obj instanceof EE_State ? $state_obj->name() : '';
157
+				break;
158
+
159
+			case '[PRIMARY_REGISTRANT_COUNTRY]':
160
+				$country_obj = $attendee->country_obj();
161
+				return $country_obj instanceof EE_Country ? $country_obj->name() : '';
162
+				break;
163
+
164
+			case '[PRIMARY_REGISTRANT_REGISTRATION_DATE]':
165
+				if (! $primary_registration->primary_reg_obj instanceof EE_Registration) {
166
+					return '';
167
+				}
168
+				return $primary_registration->primary_reg_obj->get_i18n_datetime('REG_date', get_option('date_format'));
169
+				break;
170
+
171
+			case '[PRIMARY_REGISTRANT_FRONTEND_EDIT_REG_LINK]':
172
+				return $primary_reg->edit_attendee_information_url();
173
+				break;
174
+		}
175
+
176
+		if (strpos($shortcode, '[PRIMARY_REGISTRANT_ANSWER_*') !== false) {
177
+			$shortcode = str_replace('[PRIMARY_REGISTRANT_ANSWER_*', '', $shortcode);
178
+			$shortcode = trim(str_replace(']', '', $shortcode));
179
+
180
+
181
+			// now let's figure out what question has this text
182
+			if (empty($primary_registration->questions)) {
183
+				return '';
184
+			}
185
+
186
+			foreach ($primary_registration->questions as $ansid => $question) {
187
+				if (
188
+					$question instanceof EE_Question
189
+					&& trim($question->get('QST_display_text')) === trim($shortcode)
190
+					&& isset($primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ])
191
+				) {
192
+					$primary_reg_ansid = $primary_registration->registrations[ $primary_reg->ID() ]['ans_objs'][ $ansid ];
193
+
194
+					// what we show for the answer depends on the question type!
195
+					switch ($question->get('QST_type')) {
196
+						case EEM_Question::QST_type_state:
197
+							$state = EEM_State::instance()->get_one_by_ID($primary_reg_ansid->get('ANS_value'));
198
+							$answer = $state instanceof EE_State ? $state->name() : '';
199
+							break;
200
+
201
+						case EEM_Question::QST_type_country:
202
+							$country = EEM_Country::instance()->get_one_by_ID($primary_reg_ansid->get('ANS_value'));
203
+							$answer = $country instanceof EE_Country ? $country->name() : '';
204
+							break;
205
+
206
+						default:
207
+							$answer = $primary_reg_ansid->get_pretty('ANS_value', 'no_wpautop');
208
+							break;
209
+					}
210
+
211
+					return $answer;
212
+					break;
213
+				}
214
+			}
215
+		}
216
+
217
+		return '';
218
+	}
219 219
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Currency_Input.input.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -12,23 +12,23 @@
 block discarded – undo
12 12
 class EE_Currency_Input extends EE_Select_Input
13 13
 {
14 14
 
15
-    /**
16
-     *
17
-     * @param array $only_specific_currency_codes numerically-indexed array of allowed currency codes. By default, all are allowed
18
-     * @param array $input_settings
19
-     */
20
-    public function __construct($only_specific_currency_codes = array(), $input_settings = array())
21
-    {
22
-        $query_params = array('order_by' => array('CNT_name' => 'asc'));
23
-        if ($only_specific_currency_codes) {
24
-            $query_params[0]['CNT_cur_code'] = array('IN',$only_specific_currency_codes);
25
-        }
26
-        $all_countries = EEM_Country::instance()->get_all($query_params);
27
-        $country_options = array();
28
-        foreach ($all_countries as $country) {
29
-            /* @var $country EE_Country */
30
-            $country_options[ $country->currency_code() ] = $country->name() . ": " . $country->currency_name_single() . " (" . $country->currency_sign() . ")";
31
-        }
32
-        parent::__construct($country_options, 'int', $input_settings);
33
-    }
15
+	/**
16
+	 *
17
+	 * @param array $only_specific_currency_codes numerically-indexed array of allowed currency codes. By default, all are allowed
18
+	 * @param array $input_settings
19
+	 */
20
+	public function __construct($only_specific_currency_codes = array(), $input_settings = array())
21
+	{
22
+		$query_params = array('order_by' => array('CNT_name' => 'asc'));
23
+		if ($only_specific_currency_codes) {
24
+			$query_params[0]['CNT_cur_code'] = array('IN',$only_specific_currency_codes);
25
+		}
26
+		$all_countries = EEM_Country::instance()->get_all($query_params);
27
+		$country_options = array();
28
+		foreach ($all_countries as $country) {
29
+			/* @var $country EE_Country */
30
+			$country_options[ $country->currency_code() ] = $country->name() . ": " . $country->currency_name_single() . " (" . $country->currency_sign() . ")";
31
+		}
32
+		parent::__construct($country_options, 'int', $input_settings);
33
+	}
34 34
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -21,13 +21,13 @@
 block discarded – undo
21 21
     {
22 22
         $query_params = array('order_by' => array('CNT_name' => 'asc'));
23 23
         if ($only_specific_currency_codes) {
24
-            $query_params[0]['CNT_cur_code'] = array('IN',$only_specific_currency_codes);
24
+            $query_params[0]['CNT_cur_code'] = array('IN', $only_specific_currency_codes);
25 25
         }
26 26
         $all_countries = EEM_Country::instance()->get_all($query_params);
27 27
         $country_options = array();
28 28
         foreach ($all_countries as $country) {
29 29
             /* @var $country EE_Country */
30
-            $country_options[ $country->currency_code() ] = $country->name() . ": " . $country->currency_name_single() . " (" . $country->currency_sign() . ")";
30
+            $country_options[$country->currency_code()] = $country->name().": ".$country->currency_name_single()." (".$country->currency_sign().")";
31 31
         }
32 32
         parent::__construct($country_options, 'int', $input_settings);
33 33
     }
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Select_Reveal_Input.input.php 2 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -15,65 +15,65 @@
 block discarded – undo
15 15
 class EE_Select_Reveal_Input extends EE_Select_Input
16 16
 {
17 17
 
18
-    /**
19
-     * @param array $answer_options Array keys which match a sibling section's name
20
-     *              will show/unhide that sibling subsection. Otherwise, siblings whose names
21
-     *              match array keys of $answer_options are hidden.
22
-     *              Note: internally each array key is considered a relative form input path
23
-     *              (see EE_Form_Section_Base::find_section_from_path) but relative
24
-     *              to THIS INPUT's PARENT section, not this input itself. ie,
25
-     *              a '../' is automatically added onto each each array key, to produce
26
-     *              the relative form input path.
27
-     *              Note however: array keys which are an EMPTY STRING are left as-is
28
-     *
29
-     * @param array $input_settings
30
-     */
31
-    public function __construct($answer_options, $input_settings = array())
32
-    {
33
-        parent::__construct($answer_options, $input_settings);
34
-    }
18
+	/**
19
+	 * @param array $answer_options Array keys which match a sibling section's name
20
+	 *              will show/unhide that sibling subsection. Otherwise, siblings whose names
21
+	 *              match array keys of $answer_options are hidden.
22
+	 *              Note: internally each array key is considered a relative form input path
23
+	 *              (see EE_Form_Section_Base::find_section_from_path) but relative
24
+	 *              to THIS INPUT's PARENT section, not this input itself. ie,
25
+	 *              a '../' is automatically added onto each each array key, to produce
26
+	 *              the relative form input path.
27
+	 *              Note however: array keys which are an EMPTY STRING are left as-is
28
+	 *
29
+	 * @param array $input_settings
30
+	 */
31
+	public function __construct($answer_options, $input_settings = array())
32
+	{
33
+		parent::__construct($answer_options, $input_settings);
34
+	}
35 35
 
36
-    /**
37
-     * Gets all the sibling sections controlled by this reveal select input
38
-     * @return \EE_Form_Section_Base[] keys are their form section paths
39
-     */
40
-    public function sibling_sections_controlled()
41
-    {
42
-        $sibling_sections = array();
43
-        foreach ($this->options() as $sibling_section_name => $sibling_section) {
44
-            // if it's an empty string just leave it alone
45
-            if (empty($sibling_section_name)) {
46
-                continue;
47
-            }
48
-            $sibling_section = $this->find_section_from_path('../' . $sibling_section_name);
49
-            if (
50
-                $sibling_section instanceof EE_Form_Section_Base
51
-                && ! empty($sibling_section_name)
52
-            ) {
53
-                $sibling_sections[ $sibling_section_name ] = $sibling_section;
54
-            }
55
-        }
56
-        return $sibling_sections;
57
-    }
36
+	/**
37
+	 * Gets all the sibling sections controlled by this reveal select input
38
+	 * @return \EE_Form_Section_Base[] keys are their form section paths
39
+	 */
40
+	public function sibling_sections_controlled()
41
+	{
42
+		$sibling_sections = array();
43
+		foreach ($this->options() as $sibling_section_name => $sibling_section) {
44
+			// if it's an empty string just leave it alone
45
+			if (empty($sibling_section_name)) {
46
+				continue;
47
+			}
48
+			$sibling_section = $this->find_section_from_path('../' . $sibling_section_name);
49
+			if (
50
+				$sibling_section instanceof EE_Form_Section_Base
51
+				&& ! empty($sibling_section_name)
52
+			) {
53
+				$sibling_sections[ $sibling_section_name ] = $sibling_section;
54
+			}
55
+		}
56
+		return $sibling_sections;
57
+	}
58 58
 
59
-    /**
60
-     * Adds an entry of 'select_reveal_inputs' to the js data, which is an array
61
-     * whose top-level keys are select reveal input html ids; values are arrays
62
-     * whose keys are select option values and values are the sections they reveal
63
-     * @param array $form_other_js_data
64
-     * @return array
65
-     */
66
-    public function get_other_js_data($form_other_js_data = array())
67
-    {
68
-        $form_other_js_data = parent::get_other_js_data($form_other_js_data);
69
-        if (! isset($form_other_js_data['select_reveal_inputs'])) {
70
-            $form_other_js_data['select_reveal_inputs'] = array();
71
-        }
72
-        $sibling_input_to_html_id_map = array();
73
-        foreach ($this->sibling_sections_controlled() as $sibling_section_path => $sibling_section) {
74
-            $sibling_input_to_html_id_map[ $sibling_section_path ] = $sibling_section->html_id();
75
-        }
76
-        $form_other_js_data['select_reveal_inputs'][ $this->html_id() ] = $sibling_input_to_html_id_map;
77
-        return $form_other_js_data;
78
-    }
59
+	/**
60
+	 * Adds an entry of 'select_reveal_inputs' to the js data, which is an array
61
+	 * whose top-level keys are select reveal input html ids; values are arrays
62
+	 * whose keys are select option values and values are the sections they reveal
63
+	 * @param array $form_other_js_data
64
+	 * @return array
65
+	 */
66
+	public function get_other_js_data($form_other_js_data = array())
67
+	{
68
+		$form_other_js_data = parent::get_other_js_data($form_other_js_data);
69
+		if (! isset($form_other_js_data['select_reveal_inputs'])) {
70
+			$form_other_js_data['select_reveal_inputs'] = array();
71
+		}
72
+		$sibling_input_to_html_id_map = array();
73
+		foreach ($this->sibling_sections_controlled() as $sibling_section_path => $sibling_section) {
74
+			$sibling_input_to_html_id_map[ $sibling_section_path ] = $sibling_section->html_id();
75
+		}
76
+		$form_other_js_data['select_reveal_inputs'][ $this->html_id() ] = $sibling_input_to_html_id_map;
77
+		return $form_other_js_data;
78
+	}
79 79
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -45,12 +45,12 @@  discard block
 block discarded – undo
45 45
             if (empty($sibling_section_name)) {
46 46
                 continue;
47 47
             }
48
-            $sibling_section = $this->find_section_from_path('../' . $sibling_section_name);
48
+            $sibling_section = $this->find_section_from_path('../'.$sibling_section_name);
49 49
             if (
50 50
                 $sibling_section instanceof EE_Form_Section_Base
51 51
                 && ! empty($sibling_section_name)
52 52
             ) {
53
-                $sibling_sections[ $sibling_section_name ] = $sibling_section;
53
+                $sibling_sections[$sibling_section_name] = $sibling_section;
54 54
             }
55 55
         }
56 56
         return $sibling_sections;
@@ -66,14 +66,14 @@  discard block
 block discarded – undo
66 66
     public function get_other_js_data($form_other_js_data = array())
67 67
     {
68 68
         $form_other_js_data = parent::get_other_js_data($form_other_js_data);
69
-        if (! isset($form_other_js_data['select_reveal_inputs'])) {
69
+        if ( ! isset($form_other_js_data['select_reveal_inputs'])) {
70 70
             $form_other_js_data['select_reveal_inputs'] = array();
71 71
         }
72 72
         $sibling_input_to_html_id_map = array();
73 73
         foreach ($this->sibling_sections_controlled() as $sibling_section_path => $sibling_section) {
74
-            $sibling_input_to_html_id_map[ $sibling_section_path ] = $sibling_section->html_id();
74
+            $sibling_input_to_html_id_map[$sibling_section_path] = $sibling_section->html_id();
75 75
         }
76
-        $form_other_js_data['select_reveal_inputs'][ $this->html_id() ] = $sibling_input_to_html_id_map;
76
+        $form_other_js_data['select_reveal_inputs'][$this->html_id()] = $sibling_input_to_html_id_map;
77 77
         return $form_other_js_data;
78 78
     }
79 79
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Text_Area_Input.input.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -13,68 +13,68 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    protected $_rows = 2;
17
-    protected $_cols = 20;
16
+	protected $_rows = 2;
17
+	protected $_cols = 20;
18 18
 
19
-    /**
20
-     * sets the rows property on this input
21
-     * @param int $rows
22
-     */
23
-    public function set_rows($rows)
24
-    {
25
-        $this->_rows = $rows;
26
-    }
27
-    /**
28
-     * sets the cols html property on this input
29
-     * @param int $cols
30
-     */
31
-    public function set_cols($cols)
32
-    {
33
-        $this->_cols = $cols;
34
-    }
35
-    /**
36
-     *
37
-     * @return int
38
-     */
39
-    public function get_rows()
40
-    {
41
-        return $this->_rows;
42
-    }
43
-    /**
44
-     *
45
-     * @return int
46
-     */
47
-    public function get_cols()
48
-    {
49
-        return $this->_cols;
50
-    }
19
+	/**
20
+	 * sets the rows property on this input
21
+	 * @param int $rows
22
+	 */
23
+	public function set_rows($rows)
24
+	{
25
+		$this->_rows = $rows;
26
+	}
27
+	/**
28
+	 * sets the cols html property on this input
29
+	 * @param int $cols
30
+	 */
31
+	public function set_cols($cols)
32
+	{
33
+		$this->_cols = $cols;
34
+	}
35
+	/**
36
+	 *
37
+	 * @return int
38
+	 */
39
+	public function get_rows()
40
+	{
41
+		return $this->_rows;
42
+	}
43
+	/**
44
+	 *
45
+	 * @return int
46
+	 */
47
+	public function get_cols()
48
+	{
49
+		return $this->_cols;
50
+	}
51 51
 
52 52
 
53 53
 
54
-    /**
55
-     * @param array $options_array
56
-     */
57
-    public function __construct($options_array = array())
58
-    {
59
-        $this->_set_display_strategy(new EE_Text_Area_Display_Strategy());
60
-        $this->_set_normalization_strategy(new EE_Text_Normalization());
54
+	/**
55
+	 * @param array $options_array
56
+	 */
57
+	public function __construct($options_array = array())
58
+	{
59
+		$this->_set_display_strategy(new EE_Text_Area_Display_Strategy());
60
+		$this->_set_normalization_strategy(new EE_Text_Normalization());
61 61
 
62 62
 
63
-        parent::__construct($options_array);
63
+		parent::__construct($options_array);
64 64
 
65
-        // if the input hasn't specifically mentioned a more lenient validation strategy,
66
-        // apply plaintext validation strategy
67
-        if (
68
-            ! $this->has_validation_strategy(
69
-                array(
70
-                    'EE_Full_HTML_Validation_Strategy',
71
-                    'EE_Simple_HTML_Validation_Strategy'
72
-                )
73
-            )
74
-        ) {
75
-            // by default we use the plaintext validation. If you want something else,
76
-            // just remove it after the input is constructed :P using EE_Form_Input_Base::remove_validation_strategy()
77
-            $this->_add_validation_strategy(new EE_Plaintext_Validation_Strategy());
78
-        }
79
-    }
65
+		// if the input hasn't specifically mentioned a more lenient validation strategy,
66
+		// apply plaintext validation strategy
67
+		if (
68
+			! $this->has_validation_strategy(
69
+				array(
70
+					'EE_Full_HTML_Validation_Strategy',
71
+					'EE_Simple_HTML_Validation_Strategy'
72
+				)
73
+			)
74
+		) {
75
+			// by default we use the plaintext validation. If you want something else,
76
+			// just remove it after the input is constructed :P using EE_Form_Input_Base::remove_validation_strategy()
77
+			$this->_add_validation_strategy(new EE_Plaintext_Validation_Strategy());
78
+		}
79
+	}
80 80
 }
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_CVV_Input.input.php 2 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -12,43 +12,43 @@
 block discarded – undo
12 12
 class EE_CVV_Input extends EE_Text_Input
13 13
 {
14 14
 
15
-    /**
16
-     * @param array $input_settings {
17
-     *  @type boolean $include_whats_this_link defaults to true
18
-     * }
19
-     */
20
-    public function __construct($input_settings = array())
21
-    {
22
-        $this->set_sensitive_data_removal_strategy(new EE_CCV_Sensitive_Data_Removal());
23
-        $this->_add_validation_strategy(
24
-            new EE_Text_Validation_Strategy(
25
-                isset($input_settings['validation_error_message'])
26
-                    ?  $input_settings['validation_error_message']
27
-                    : esc_html__(
28
-                        'The CVV is either a 3 digit number on the back of your card, or 4 digit number on the front',
29
-                        'event_espresso'
30
-                    ),
31
-                '~^\d{3,4}$~'
32
-            )
33
-        );
34
-        parent::__construct($input_settings);
35
-        if (
36
-            ! isset($input_settings['include_whats_this_link'])
37
-            || (
38
-                isset($input_settings['include_whats_this_link'])
39
-                 && $input_settings['include_whats_this_link'] === true
40
-            )
41
-        ) {
42
-            $this->_html_label_text = sprintf(
43
-                esc_html_x(
44
-                    '%1$s %2$s(What\'s this?)%3$s',
45
-                    'CVV (What\'s this?)',
46
-                    'event_espresso'
47
-                ),
48
-                $this->_html_label_text,
49
-                '<a href="https://www.cvvnumber.com/" target="_blank" rel="noopener noreferrer">',
50
-                '</a>'
51
-            );
52
-        }
53
-    }
15
+	/**
16
+	 * @param array $input_settings {
17
+	 *  @type boolean $include_whats_this_link defaults to true
18
+	 * }
19
+	 */
20
+	public function __construct($input_settings = array())
21
+	{
22
+		$this->set_sensitive_data_removal_strategy(new EE_CCV_Sensitive_Data_Removal());
23
+		$this->_add_validation_strategy(
24
+			new EE_Text_Validation_Strategy(
25
+				isset($input_settings['validation_error_message'])
26
+					?  $input_settings['validation_error_message']
27
+					: esc_html__(
28
+						'The CVV is either a 3 digit number on the back of your card, or 4 digit number on the front',
29
+						'event_espresso'
30
+					),
31
+				'~^\d{3,4}$~'
32
+			)
33
+		);
34
+		parent::__construct($input_settings);
35
+		if (
36
+			! isset($input_settings['include_whats_this_link'])
37
+			|| (
38
+				isset($input_settings['include_whats_this_link'])
39
+				 && $input_settings['include_whats_this_link'] === true
40
+			)
41
+		) {
42
+			$this->_html_label_text = sprintf(
43
+				esc_html_x(
44
+					'%1$s %2$s(What\'s this?)%3$s',
45
+					'CVV (What\'s this?)',
46
+					'event_espresso'
47
+				),
48
+				$this->_html_label_text,
49
+				'<a href="https://www.cvvnumber.com/" target="_blank" rel="noopener noreferrer">',
50
+				'</a>'
51
+			);
52
+		}
53
+	}
54 54
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
         $this->_add_validation_strategy(
24 24
             new EE_Text_Validation_Strategy(
25 25
                 isset($input_settings['validation_error_message'])
26
-                    ?  $input_settings['validation_error_message']
26
+                    ? $input_settings['validation_error_message']
27 27
                     : esc_html__(
28 28
                         'The CVV is either a 3 digit number on the back of your card, or 4 digit number on the front',
29 29
                         'event_espresso'
Please login to merge, or discard this patch.