Completed
Branch master (16095c)
by
unknown
09:17 queued 04:49
created
core/db_models/EEM_Message.model.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
             self::priority_low    => esc_html__('low', 'event_espresso'),
127 127
         );
128 128
 
129
-        $this->_fields          = array(
129
+        $this->_fields = array(
130 130
             'Message' => array(
131 131
                 'MSG_ID'             => new EE_Primary_Key_Int_Field('MSG_ID', esc_html__('Message ID', 'event_espresso')),
132 132
                 'MSG_token'          => new EE_Plain_Text_Field(
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
                         );
437 437
                         break;
438 438
                     default:
439
-                        $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value;
439
+                        $query_params[0]['AND**filter_by']['OR**filter_by_'.$request_key][$model_name.'.'.$request_key] = $request_value;
440 440
                         break;
441 441
                 }
442 442
             }
@@ -499,8 +499,8 @@  discard block
 block discarded – undo
499 499
         if ($label_parts) {
500 500
             // prepend to the last element of $label_parts an "and".
501 501
             if (count($label_parts) > 1) {
502
-                $label_parts_index_to_prepend               = count($label_parts) - 1;
503
-                $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ];
502
+                $label_parts_index_to_prepend = count($label_parts) - 1;
503
+                $label_parts[$label_parts_index_to_prepend] = 'and'.$label_parts[$label_parts_index_to_prepend];
504 504
             }
505 505
 
506 506
             $pretty_label .= sprintf(
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
             $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES;
561 561
         }
562 562
 
563
-        if (! is_null($set_debug)) {
563
+        if ( ! is_null($set_debug)) {
564 564
             $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN);
565 565
         }
566 566
 
@@ -627,13 +627,13 @@  discard block
 block discarded – undo
627 627
             )
628 628
         );
629 629
 
630
-        if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
630
+        if ( ! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
631 631
             global $wpdb;
632 632
             $number_deleted = $wpdb->query('
633 633
                 DELETE
634
-                FROM ' . $this->table() . '
634
+                FROM ' . $this->table().'
635 635
                 WHERE
636
-                    MSG_ID IN (' . implode(",", $message_ids_to_delete) . ')
636
+                    MSG_ID IN (' . implode(",", $message_ids_to_delete).')
637 637
             ');
638 638
         }
639 639
 
Please login to merge, or discard this patch.
Indentation   +640 added lines, -640 removed lines patch added patch discarded remove patch
@@ -12,649 +12,649 @@
 block discarded – undo
12 12
  */
13 13
 class EEM_Message extends EEM_Base implements EEI_Query_Filter
14 14
 {
15
-    // private instance of the Message object
16
-    protected static $_instance = null;
17
-
18
-
19
-    /**
20
-     * This priority indicates a message should be generated and sent ASAP
21
-     *
22
-     * @type int
23
-     */
24
-    const priority_high = 10;
25
-
26
-
27
-    /**
28
-     * This priority indicates a message should be generated ASAP and queued for sending.
29
-     *
30
-     * @type
31
-     */
32
-    const priority_medium = 20;
33
-
34
-
35
-    /**
36
-     * This priority indicates a message should be queued for generating.
37
-     *
38
-     * @type int
39
-     */
40
-    const priority_low = 30;
41
-
42
-
43
-    /**
44
-     * indicates this message was sent at the time modified
45
-     */
46
-    const status_sent = 'MSN';
47
-
48
-
49
-    /**
50
-     * indicates this message is waiting to be sent
51
-     */
52
-    const status_idle = 'MID';
53
-
54
-
55
-    /**
56
-     * indicates an attempt was a made to send this message
57
-     * at the scheduled time, but it failed at the time modified.  This differs from MDO status in that it will ALWAYS
58
-     * appear to the end user.
59
-     */
60
-    const status_failed = 'MFL';
61
-
62
-
63
-    /**
64
-     * indicates the message has been flagged for resending (at the time modified).
65
-     */
66
-    const status_resend = 'MRS';
67
-
68
-
69
-    /**
70
-     * indicates the message has been flagged for generation but has not been generated yet.  Messages always start as
71
-     * this status when added to the queue.
72
-     */
73
-    const status_incomplete = 'MIC';
74
-
75
-
76
-    /**
77
-     * Indicates everything was generated fine for the message, however, the messenger was unable to send.
78
-     * This status means that its possible to retry sending the message.
79
-     */
80
-    const status_retry = 'MRT';
81
-
82
-
83
-    /**
84
-     * This is used for more informational messages that may not indicate anything is broken but still cannot be
85
-     * generated or sent correctly. An example of a message that would get flagged this way would be when a not
86
-     * approved message was queued for generation, but at time of generation, the attached registration(s) are
87
-     * approved. So the message queued for generation is no longer valid.  Messages for this status will only persist
88
-     * in the db and be viewable in the message activity list table when the messages system is in debug mode.
89
-     *
90
-     * @see EEM_Message::debug()
91
-     */
92
-    const status_debug_only = 'MDO';
93
-
94
-
95
-    /**
96
-     * This status is given to messages it is processed by the messenger send method.
97
-     * Messages with this status should rarely be seen in the Message List table, but if they are, that's usually
98
-     * indicative of a PHP timeout or memory limit issue.
99
-     */
100
-    const status_messenger_executing = 'MEX';
101
-
102
-
103
-    /**
104
-     *    Private constructor to prevent direct creation.
105
-     *
106
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and
107
-     *                         any incoming timezone data that gets saved).  Note this just sends the timezone info to
108
-     *                         the date time model field objects.  Default is null (and will be assumed using the set
109
-     *                         timezone in the 'timezone_string' wp option)
110
-     * @throws EE_Error
111
-     * @throws EE_Error
112
-     * @throws EE_Error
113
-     */
114
-    protected function __construct($timezone = null)
115
-    {
116
-        $this->singular_item = esc_html__('Message', 'event_espresso');
117
-        $this->plural_item   = esc_html__('Messages', 'event_espresso');
118
-
119
-        $this->_tables = array(
120
-            'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'),
121
-        );
122
-
123
-        $allowed_priority = array(
124
-            self::priority_high   => esc_html__('high', 'event_espresso'),
125
-            self::priority_medium => esc_html__('medium', 'event_espresso'),
126
-            self::priority_low    => esc_html__('low', 'event_espresso'),
127
-        );
128
-
129
-        $this->_fields          = array(
130
-            'Message' => array(
131
-                'MSG_ID'             => new EE_Primary_Key_Int_Field('MSG_ID', esc_html__('Message ID', 'event_espresso')),
132
-                'MSG_token'          => new EE_Plain_Text_Field(
133
-                    'MSG_token',
134
-                    esc_html__(
135
-                        'Unique Token used to represent this row in publicly viewable contexts (eg. a url).',
136
-                        'event_espresso'
137
-                    ),
138
-                    false,
139
-                    EEH_URL::generate_unique_token()
140
-                ),
141
-                'GRP_ID'             => new EE_Foreign_Key_Int_Field(
142
-                    'GRP_ID',
143
-                    esc_html__('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'),
144
-                    true,
145
-                    0,
146
-                    'Message_Template_Group'
147
-                ),
148
-                'TXN_ID'             => new EE_Foreign_Key_Int_Field(
149
-                    'TXN_ID',
150
-                    esc_html__(
151
-                        'Foreign key to the related EE_Transaction.  This is required to give context for regenerating the specific message',
152
-                        'event_espresso'
153
-                    ),
154
-                    true,
155
-                    0,
156
-                    'Transaction'
157
-                ),
158
-                'MSG_messenger'      => new EE_Plain_Text_Field(
159
-                    'MSG_messenger',
160
-                    esc_html__(
161
-                        'Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.',
162
-                        'event_espresso'
163
-                    ),
164
-                    false,
165
-                    'email'
166
-                ),
167
-                'MSG_message_type'   => new EE_Plain_Text_Field(
168
-                    'MSG_message_type',
169
-                    esc_html__('Corresponds to the EE_message_type::name used to generate this message.', 'event_espresso'),
170
-                    false,
171
-                    'receipt'
172
-                ),
173
-                'MSG_context'        => new EE_Plain_Text_Field('MSG_context', esc_html__('Context', 'event_espresso'), false),
174
-                'MSG_recipient_ID'   => new EE_Foreign_Key_Int_Field(
175
-                    'MSG_recipient_ID',
176
-                    esc_html__('Recipient ID', 'event_espresso'),
177
-                    true,
178
-                    null,
179
-                    array('Registration', 'Attendee', 'WP_User')
180
-                ),
181
-                'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field(
182
-                    'MSG_recipient_type',
183
-                    esc_html__('Recipient Type', 'event_espresso'),
184
-                    true,
185
-                    null,
186
-                    array('Registration', 'Attendee', 'WP_User')
187
-                ),
188
-                'MSG_content'        => new EE_Maybe_Serialized_Text_Field(
189
-                    'MSG_content',
190
-                    esc_html__('Content', 'event_espresso'),
191
-                    true,
192
-                    ''
193
-                ),
194
-                'MSG_to'             => new EE_Maybe_Serialized_Text_Field(
195
-                    'MSG_to',
196
-                    esc_html__('Address To', 'event_espresso'),
197
-                    true
198
-                ),
199
-                'MSG_from'           => new EE_Maybe_Serialized_Text_Field(
200
-                    'MSG_from',
201
-                    esc_html__('Address From', 'event_espresso'),
202
-                    true
203
-                ),
204
-                'MSG_subject'        => new EE_Maybe_Serialized_Text_Field(
205
-                    'MSG_subject',
206
-                    esc_html__('Subject', 'event_espresso'),
207
-                    true,
208
-                    ''
209
-                ),
210
-                'MSG_priority'       => new EE_Enum_Integer_Field(
211
-                    'MSG_priority',
212
-                    esc_html__('Priority', 'event_espresso'),
213
-                    false,
214
-                    self::priority_low,
215
-                    $allowed_priority
216
-                ),
217
-                'STS_ID'             => new EE_Foreign_Key_String_Field(
218
-                    'STS_ID',
219
-                    esc_html__('Status', 'event_espresso'),
220
-                    false,
221
-                    self::status_incomplete,
222
-                    'Status'
223
-                ),
224
-                'MSG_created'        => new EE_Datetime_Field(
225
-                    'MSG_created',
226
-                    esc_html__('Created', 'event_espresso'),
227
-                    false,
228
-                    EE_Datetime_Field::now
229
-                ),
230
-                'MSG_modified'       => new EE_Datetime_Field(
231
-                    'MSG_modified',
232
-                    esc_html__('Modified', 'event_espresso'),
233
-                    true,
234
-                    EE_Datetime_Field::now
235
-                ),
236
-            ),
237
-        );
238
-        $this->_model_relations = array(
239
-            'Attendee'               => new EE_Belongs_To_Any_Relation(),
240
-            'Registration'           => new EE_Belongs_To_Any_Relation(),
241
-            'WP_User'                => new EE_Belongs_To_Any_Relation(),
242
-            'Message_Template_Group' => new EE_Belongs_To_Relation(),
243
-            'Transaction'            => new EE_Belongs_To_Relation(),
244
-        );
245
-        parent::__construct($timezone);
246
-    }
247
-
248
-
249
-    /**
250
-     * @return EE_Message
251
-     * @throws EE_Error
252
-     */
253
-    public function create_default_object()
254
-    {
255
-        /** @type EE_Message $message */
256
-        $message = parent::create_default_object();
257
-        if ($message instanceof EE_Message) {
258
-            return EE_Message_Factory::set_messenger_and_message_type($message);
259
-        }
260
-        return null;
261
-    }
262
-
263
-
264
-    /**
265
-     * @param mixed $cols_n_values
266
-     * @return EE_Message
267
-     * @throws EE_Error
268
-     * @throws EE_Error
269
-     */
270
-    public function instantiate_class_from_array_or_object($cols_n_values)
271
-    {
272
-        /** @type EE_Message $message */
273
-        $message = parent::instantiate_class_from_array_or_object($cols_n_values);
274
-        if ($message instanceof EE_Message) {
275
-            return EE_Message_Factory::set_messenger_and_message_type($message);
276
-        }
277
-        return null;
278
-    }
279
-
280
-
281
-    /**
282
-     * Returns whether or not a message of that type was sent for a given attendee.
283
-     *
284
-     * @param EE_Attendee|int $attendee
285
-     * @param string          $message_type the message type slug
286
-     * @return boolean
287
-     * @throws EE_Error
288
-     * @throws EE_Error
289
-     * @throws EE_Error
290
-     */
291
-    public function message_sent_for_attendee($attendee, $message_type)
292
-    {
293
-        $attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee);
294
-        return $this->exists(array(
295
-            array(
296
-                'Attendee.ATT_ID'  => $attendee_ID,
297
-                'MSG_message_type' => $message_type,
298
-                'STS_ID'           => array('IN', $this->stati_indicating_sent()),
299
-            ),
300
-        ));
301
-    }
302
-
303
-
304
-    /**
305
-     * Returns whether or not a message of that type was sent for a given registration
306
-     *
307
-     * @param EE_Registration|int $registration
308
-     * @param string              $message_type the message type slug
309
-     * @return boolean
310
-     * @throws EE_Error
311
-     * @throws EE_Error
312
-     * @throws EE_Error
313
-     */
314
-    public function message_sent_for_registration($registration, $message_type)
315
-    {
316
-        $registrationID = EEM_Registration::instance()->ensure_is_ID($registration);
317
-        return $this->exists(array(
318
-            array(
319
-                'Registration.REG_ID' => $registrationID,
320
-                'MSG_message_type'    => $message_type,
321
-                'STS_ID'              => array('IN', $this->stati_indicating_sent()),
322
-            ),
323
-        ));
324
-    }
325
-
326
-
327
-    /**
328
-     * This retrieves an EE_Message object from the db matching the given token string.
329
-     *
330
-     * @param string $token
331
-     * @return EE_Message
332
-     * @throws EE_Error
333
-     */
334
-    public function get_one_by_token($token)
335
-    {
336
-        return $this->get_one(array(
337
-            array(
338
-                'MSG_token' => $token,
339
-            ),
340
-        ));
341
-    }
342
-
343
-
344
-    /**
345
-     * Returns stati that indicate the message HAS been sent
346
-     *
347
-     * @return array of strings for possible stati
348
-     */
349
-    public function stati_indicating_sent()
350
-    {
351
-        return apply_filters('FHEE__EEM_Message__stati_indicating_sent', array(self::status_sent));
352
-    }
353
-
354
-
355
-    /**
356
-     * Returns stati that indicate the message is waiting to be sent.
357
-     *
358
-     * @return array of strings for possible stati.
359
-     */
360
-    public function stati_indicating_to_send()
361
-    {
362
-        return apply_filters(
363
-            'FHEE__EEM_Message__stati_indicating_to_send',
364
-            array(self::status_idle, self::status_resend)
365
-        );
366
-    }
367
-
368
-
369
-    /**
370
-     * Returns stati that indicate the message has failed sending
371
-     *
372
-     * @return array  array of strings for possible stati.
373
-     */
374
-    public function stati_indicating_failed_sending()
375
-    {
376
-        $failed_stati = array(
377
-            self::status_failed,
378
-            self::status_retry,
379
-            self::status_messenger_executing,
380
-        );
381
-        // if WP_DEBUG is set, then let's include debug_only fails
382
-        if (WP_DEBUG) {
383
-            $failed_stati[] = self::status_debug_only;
384
-        }
385
-        return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati);
386
-    }
387
-
388
-
389
-    /**
390
-     * Returns filterable array of all EEM_Message statuses.
391
-     *
392
-     * @return array
393
-     */
394
-    public function all_statuses()
395
-    {
396
-        return apply_filters(
397
-            'FHEE__EEM_Message__all_statuses',
398
-            array(
399
-                EEM_Message::status_sent,
400
-                EEM_Message::status_incomplete,
401
-                EEM_Message::status_idle,
402
-                EEM_Message::status_resend,
403
-                EEM_Message::status_retry,
404
-                EEM_Message::status_failed,
405
-                EEM_Message::status_messenger_executing,
406
-                EEM_Message::status_debug_only,
407
-            )
408
-        );
409
-    }
410
-
411
-    /**
412
-     * Detects any specific query variables in the request and uses those to setup appropriate
413
-     * filter for any queries.
414
-     *
415
-     * @return array
416
-     */
417
-    public function filter_by_query_params()
418
-    {
419
-        /** @var RequestInterface $request */
420
-        $request = EEM_Base::$loader->getShared(RequestInterface::class);
421
-        // expected possible query_vars, the key in this array matches an expected key in the request,
422
-        // the value, matches the corresponding EEM_Base child reference.
423
-        $expected_vars   = $this->_expected_vars_for_query_inject();
424
-        $query_params[0] = array();
425
-        foreach ($expected_vars as $request_key => $model_name) {
426
-            $request_value = $request->getRequestParam($request_key);
427
-            if ($request_value) {
428
-                // special case
429
-                switch ($request_key) {
430
-                    case '_REG_ID':
431
-                        $query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = array(
432
-                            'Transaction.Registration.REG_ID' => $request_value,
433
-                        );
434
-                        break;
435
-                    case 'EVT_ID':
436
-                        $query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = array(
437
-                            'Transaction.Registration.EVT_ID' => $request_value,
438
-                        );
439
-                        break;
440
-                    default:
441
-                        $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value;
442
-                        break;
443
-                }
444
-            }
445
-        }
446
-        return $query_params;
447
-    }
448
-
449
-
450
-    /**
451
-     * @return string
452
-     * @throws EE_Error
453
-     * @throws ReflectionException
454
-     */
455
-    public function get_pretty_label_for_results()
456
-    {
457
-        /** @var RequestInterface $request */
458
-        $request = EEM_Base::$loader->getShared(RequestInterface::class);
459
-        $expected_vars = $this->_expected_vars_for_query_inject();
460
-        $pretty_label  = '';
461
-        $label_parts   = array();
462
-        foreach ($expected_vars as $request_key => $model_name) {
463
-            $model_name = strpos($model_name, 'EEM_', true) === 0 ? $model_name : "EEM_{$model_name}";
464
-            $model = EEM_Base::$loader->getShared($model_name);
465
-            $model_field_value = $request->getRequestParam($request_key);
466
-            if ($model instanceof EEM_Base && $model_field_value !== '') {
467
-                switch ($request_key) {
468
-                    case '_REG_ID':
469
-                        $label_parts[] = sprintf(
470
-                            esc_html__('Registration with the ID: %s', 'event_espresso'),
471
-                            $model_field_value
472
-                        );
473
-                        break;
474
-                    case 'ATT_ID':
475
-                        /** @var EE_Attendee $attendee */
476
-                        $attendee      = $model->get_one_by_ID($model_field_value);
477
-                        $label_parts[] = $attendee instanceof EE_Attendee
478
-                            ? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name())
479
-                            : sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value);
480
-                        break;
481
-                    case 'ID':
482
-                        /** @var EE_WP_User $wpUser */
483
-                        $wpUser        = $model->get_one_by_ID($model_field_value);
484
-                        $label_parts[] = $wpUser instanceof EE_WP_User
485
-                            ? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name())
486
-                            : sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value);
487
-                        break;
488
-                    case 'TXN_ID':
489
-                        $label_parts[] = sprintf(
490
-                            esc_html__('Transaction with the ID: %s', 'event_espresso'),
491
-                            $model_field_value
492
-                        );
493
-                        break;
494
-                    case 'EVT_ID':
495
-                        /** @var EE_Event $Event */
496
-                        $Event         = $model->get_one_by_ID($model_field_value);
497
-                        $label_parts[] = $Event instanceof EE_Event
498
-                            ? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name())
499
-                            : sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value);
500
-                        break;
501
-                }
502
-            }
503
-        }
504
-
505
-        if ($label_parts) {
506
-            // prepend to the last element of $label_parts an "and".
507
-            if (count($label_parts) > 1) {
508
-                $label_parts_index_to_prepend               = count($label_parts) - 1;
509
-                $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ];
510
-            }
511
-
512
-            $pretty_label .= sprintf(
513
-                esc_html_x(
514
-                    'Showing messages for %s',
515
-                    'A label for the messages returned in a query that are filtered by items in the query. This could be Transaction, Event, Attendee, Registration, or WP_User.',
516
-                    'event_espresso'
517
-                ),
518
-                implode(', ', $label_parts)
519
-            );
520
-        }
521
-        return $pretty_label;
522
-    }
523
-
524
-
525
-    /**
526
-     * This returns the array of expected variables for the EEI_Query_Filter methods being implemented
527
-     * The array is in the format:
528
-     * array(
529
-     *  {$field_name} => {$model_name}
530
-     * );
531
-     *
532
-     * @since 4.9.0
533
-     * @return array
534
-     */
535
-    protected function _expected_vars_for_query_inject()
536
-    {
537
-        return array(
538
-            '_REG_ID' => 'Registration',
539
-            'ATT_ID'  => 'Attendee',
540
-            'ID'      => 'WP_User',
541
-            'TXN_ID'  => 'Transaction',
542
-            'EVT_ID'  => 'Event',
543
-        );
544
-    }
545
-
546
-
547
-    /**
548
-     * This returns whether EEM_Message is in debug mode or not.
549
-     * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when
550
-     * generating/sending messages. Debug mode can be set by either:
551
-     * 1. Sending in a value for the $set_debug argument
552
-     * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php
553
-     * 3. Overriding the above via the provided filter.
554
-     *
555
-     * @param bool|null $set_debug      If provided, then the debug mode will be set internally until reset via the
556
-     *                                  provided boolean. When no argument is provided (default null) then the debug
557
-     *                                  mode will be returned.
558
-     * @return bool         true means Messages is in debug mode.  false means messages system is not in debug mode.
559
-     */
560
-    public static function debug($set_debug = null)
561
-    {
562
-        static $is_debugging = null;
563
-
564
-        // initialize (use constant if set).
565
-        if (is_null($set_debug) && is_null($is_debugging)) {
566
-            $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES;
567
-        }
568
-
569
-        if (! is_null($set_debug)) {
570
-            $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN);
571
-        }
572
-
573
-        // return filtered value
574
-        return apply_filters('FHEE__EEM_Message__debug', $is_debugging);
575
-    }
576
-
577
-
578
-    /**
579
-     * Deletes old messages meeting certain criteria for removal from the database.
580
-     * By default, this will delete messages that:
581
-     * - are older than the value of the delete_threshold in months.
582
-     * - have a STS_ID other than EEM_Message::status_idle
583
-     *
584
-     * @param int $delete_threshold This integer will be used to set the boundary for what messages are deleted in
585
-     *                              months.
586
-     * @return bool|false|int Either the number of records affected or false if there was an error (you can call
587
-     *                              $wpdb->last_error to find out what the error was.
588
-     * @throws EE_Error
589
-     * @throws EE_Error
590
-     * @throws EE_Error
591
-     */
592
-    public function delete_old_messages($delete_threshold = 6)
593
-    {
594
-        $number_deleted = 0;
595
-        /**
596
-         * Allows code to change the boundary for what messages are kept.
597
-         * Uses the value of the `delete_threshold` variable by default.
598
-         *
599
-         * @param int $seconds seconds that will be subtracted from the timestamp for now.
600
-         * @return int
601
-         */
602
-        $time_to_leave_alone = absint(
603
-            apply_filters(
604
-                'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone',
605
-                ((int) $delete_threshold) * MONTH_IN_SECONDS
606
-            )
607
-        );
608
-
609
-
610
-        /**
611
-         * Allows code to change what message stati are ignored when deleting.
612
-         * Defaults to only ignore EEM_Message::status_idle messages.
613
-         *
614
-         * @param string $message_stati_to_keep  An array of message statuses that will be ignored when deleting.
615
-         */
616
-        $message_stati_to_keep = (array) apply_filters(
617
-            'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep',
618
-            array(
619
-                EEM_Message::status_idle
620
-            )
621
-        );
622
-
623
-        // first get all the ids of messages being deleted
624
-        $message_ids_to_delete = EEM_Message::instance()->get_col(
625
-            array(
626
-                0 => array(
627
-                    'STS_ID' => array('NOT_IN', $message_stati_to_keep),
628
-                    'MSG_modified' => array('<', time() - $time_to_leave_alone)
629
-                ),
630
-                'limit' => apply_filters(
631
-                    'EEM_Message__delete_old_messages__limit',
632
-                    2000,
633
-                    $delete_threshold
634
-                )
635
-            )
636
-        );
637
-
638
-        if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
639
-            global $wpdb;
640
-            $number_deleted = $wpdb->query('
15
+	// private instance of the Message object
16
+	protected static $_instance = null;
17
+
18
+
19
+	/**
20
+	 * This priority indicates a message should be generated and sent ASAP
21
+	 *
22
+	 * @type int
23
+	 */
24
+	const priority_high = 10;
25
+
26
+
27
+	/**
28
+	 * This priority indicates a message should be generated ASAP and queued for sending.
29
+	 *
30
+	 * @type
31
+	 */
32
+	const priority_medium = 20;
33
+
34
+
35
+	/**
36
+	 * This priority indicates a message should be queued for generating.
37
+	 *
38
+	 * @type int
39
+	 */
40
+	const priority_low = 30;
41
+
42
+
43
+	/**
44
+	 * indicates this message was sent at the time modified
45
+	 */
46
+	const status_sent = 'MSN';
47
+
48
+
49
+	/**
50
+	 * indicates this message is waiting to be sent
51
+	 */
52
+	const status_idle = 'MID';
53
+
54
+
55
+	/**
56
+	 * indicates an attempt was a made to send this message
57
+	 * at the scheduled time, but it failed at the time modified.  This differs from MDO status in that it will ALWAYS
58
+	 * appear to the end user.
59
+	 */
60
+	const status_failed = 'MFL';
61
+
62
+
63
+	/**
64
+	 * indicates the message has been flagged for resending (at the time modified).
65
+	 */
66
+	const status_resend = 'MRS';
67
+
68
+
69
+	/**
70
+	 * indicates the message has been flagged for generation but has not been generated yet.  Messages always start as
71
+	 * this status when added to the queue.
72
+	 */
73
+	const status_incomplete = 'MIC';
74
+
75
+
76
+	/**
77
+	 * Indicates everything was generated fine for the message, however, the messenger was unable to send.
78
+	 * This status means that its possible to retry sending the message.
79
+	 */
80
+	const status_retry = 'MRT';
81
+
82
+
83
+	/**
84
+	 * This is used for more informational messages that may not indicate anything is broken but still cannot be
85
+	 * generated or sent correctly. An example of a message that would get flagged this way would be when a not
86
+	 * approved message was queued for generation, but at time of generation, the attached registration(s) are
87
+	 * approved. So the message queued for generation is no longer valid.  Messages for this status will only persist
88
+	 * in the db and be viewable in the message activity list table when the messages system is in debug mode.
89
+	 *
90
+	 * @see EEM_Message::debug()
91
+	 */
92
+	const status_debug_only = 'MDO';
93
+
94
+
95
+	/**
96
+	 * This status is given to messages it is processed by the messenger send method.
97
+	 * Messages with this status should rarely be seen in the Message List table, but if they are, that's usually
98
+	 * indicative of a PHP timeout or memory limit issue.
99
+	 */
100
+	const status_messenger_executing = 'MEX';
101
+
102
+
103
+	/**
104
+	 *    Private constructor to prevent direct creation.
105
+	 *
106
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and
107
+	 *                         any incoming timezone data that gets saved).  Note this just sends the timezone info to
108
+	 *                         the date time model field objects.  Default is null (and will be assumed using the set
109
+	 *                         timezone in the 'timezone_string' wp option)
110
+	 * @throws EE_Error
111
+	 * @throws EE_Error
112
+	 * @throws EE_Error
113
+	 */
114
+	protected function __construct($timezone = null)
115
+	{
116
+		$this->singular_item = esc_html__('Message', 'event_espresso');
117
+		$this->plural_item   = esc_html__('Messages', 'event_espresso');
118
+
119
+		$this->_tables = array(
120
+			'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'),
121
+		);
122
+
123
+		$allowed_priority = array(
124
+			self::priority_high   => esc_html__('high', 'event_espresso'),
125
+			self::priority_medium => esc_html__('medium', 'event_espresso'),
126
+			self::priority_low    => esc_html__('low', 'event_espresso'),
127
+		);
128
+
129
+		$this->_fields          = array(
130
+			'Message' => array(
131
+				'MSG_ID'             => new EE_Primary_Key_Int_Field('MSG_ID', esc_html__('Message ID', 'event_espresso')),
132
+				'MSG_token'          => new EE_Plain_Text_Field(
133
+					'MSG_token',
134
+					esc_html__(
135
+						'Unique Token used to represent this row in publicly viewable contexts (eg. a url).',
136
+						'event_espresso'
137
+					),
138
+					false,
139
+					EEH_URL::generate_unique_token()
140
+				),
141
+				'GRP_ID'             => new EE_Foreign_Key_Int_Field(
142
+					'GRP_ID',
143
+					esc_html__('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'),
144
+					true,
145
+					0,
146
+					'Message_Template_Group'
147
+				),
148
+				'TXN_ID'             => new EE_Foreign_Key_Int_Field(
149
+					'TXN_ID',
150
+					esc_html__(
151
+						'Foreign key to the related EE_Transaction.  This is required to give context for regenerating the specific message',
152
+						'event_espresso'
153
+					),
154
+					true,
155
+					0,
156
+					'Transaction'
157
+				),
158
+				'MSG_messenger'      => new EE_Plain_Text_Field(
159
+					'MSG_messenger',
160
+					esc_html__(
161
+						'Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.',
162
+						'event_espresso'
163
+					),
164
+					false,
165
+					'email'
166
+				),
167
+				'MSG_message_type'   => new EE_Plain_Text_Field(
168
+					'MSG_message_type',
169
+					esc_html__('Corresponds to the EE_message_type::name used to generate this message.', 'event_espresso'),
170
+					false,
171
+					'receipt'
172
+				),
173
+				'MSG_context'        => new EE_Plain_Text_Field('MSG_context', esc_html__('Context', 'event_espresso'), false),
174
+				'MSG_recipient_ID'   => new EE_Foreign_Key_Int_Field(
175
+					'MSG_recipient_ID',
176
+					esc_html__('Recipient ID', 'event_espresso'),
177
+					true,
178
+					null,
179
+					array('Registration', 'Attendee', 'WP_User')
180
+				),
181
+				'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field(
182
+					'MSG_recipient_type',
183
+					esc_html__('Recipient Type', 'event_espresso'),
184
+					true,
185
+					null,
186
+					array('Registration', 'Attendee', 'WP_User')
187
+				),
188
+				'MSG_content'        => new EE_Maybe_Serialized_Text_Field(
189
+					'MSG_content',
190
+					esc_html__('Content', 'event_espresso'),
191
+					true,
192
+					''
193
+				),
194
+				'MSG_to'             => new EE_Maybe_Serialized_Text_Field(
195
+					'MSG_to',
196
+					esc_html__('Address To', 'event_espresso'),
197
+					true
198
+				),
199
+				'MSG_from'           => new EE_Maybe_Serialized_Text_Field(
200
+					'MSG_from',
201
+					esc_html__('Address From', 'event_espresso'),
202
+					true
203
+				),
204
+				'MSG_subject'        => new EE_Maybe_Serialized_Text_Field(
205
+					'MSG_subject',
206
+					esc_html__('Subject', 'event_espresso'),
207
+					true,
208
+					''
209
+				),
210
+				'MSG_priority'       => new EE_Enum_Integer_Field(
211
+					'MSG_priority',
212
+					esc_html__('Priority', 'event_espresso'),
213
+					false,
214
+					self::priority_low,
215
+					$allowed_priority
216
+				),
217
+				'STS_ID'             => new EE_Foreign_Key_String_Field(
218
+					'STS_ID',
219
+					esc_html__('Status', 'event_espresso'),
220
+					false,
221
+					self::status_incomplete,
222
+					'Status'
223
+				),
224
+				'MSG_created'        => new EE_Datetime_Field(
225
+					'MSG_created',
226
+					esc_html__('Created', 'event_espresso'),
227
+					false,
228
+					EE_Datetime_Field::now
229
+				),
230
+				'MSG_modified'       => new EE_Datetime_Field(
231
+					'MSG_modified',
232
+					esc_html__('Modified', 'event_espresso'),
233
+					true,
234
+					EE_Datetime_Field::now
235
+				),
236
+			),
237
+		);
238
+		$this->_model_relations = array(
239
+			'Attendee'               => new EE_Belongs_To_Any_Relation(),
240
+			'Registration'           => new EE_Belongs_To_Any_Relation(),
241
+			'WP_User'                => new EE_Belongs_To_Any_Relation(),
242
+			'Message_Template_Group' => new EE_Belongs_To_Relation(),
243
+			'Transaction'            => new EE_Belongs_To_Relation(),
244
+		);
245
+		parent::__construct($timezone);
246
+	}
247
+
248
+
249
+	/**
250
+	 * @return EE_Message
251
+	 * @throws EE_Error
252
+	 */
253
+	public function create_default_object()
254
+	{
255
+		/** @type EE_Message $message */
256
+		$message = parent::create_default_object();
257
+		if ($message instanceof EE_Message) {
258
+			return EE_Message_Factory::set_messenger_and_message_type($message);
259
+		}
260
+		return null;
261
+	}
262
+
263
+
264
+	/**
265
+	 * @param mixed $cols_n_values
266
+	 * @return EE_Message
267
+	 * @throws EE_Error
268
+	 * @throws EE_Error
269
+	 */
270
+	public function instantiate_class_from_array_or_object($cols_n_values)
271
+	{
272
+		/** @type EE_Message $message */
273
+		$message = parent::instantiate_class_from_array_or_object($cols_n_values);
274
+		if ($message instanceof EE_Message) {
275
+			return EE_Message_Factory::set_messenger_and_message_type($message);
276
+		}
277
+		return null;
278
+	}
279
+
280
+
281
+	/**
282
+	 * Returns whether or not a message of that type was sent for a given attendee.
283
+	 *
284
+	 * @param EE_Attendee|int $attendee
285
+	 * @param string          $message_type the message type slug
286
+	 * @return boolean
287
+	 * @throws EE_Error
288
+	 * @throws EE_Error
289
+	 * @throws EE_Error
290
+	 */
291
+	public function message_sent_for_attendee($attendee, $message_type)
292
+	{
293
+		$attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee);
294
+		return $this->exists(array(
295
+			array(
296
+				'Attendee.ATT_ID'  => $attendee_ID,
297
+				'MSG_message_type' => $message_type,
298
+				'STS_ID'           => array('IN', $this->stati_indicating_sent()),
299
+			),
300
+		));
301
+	}
302
+
303
+
304
+	/**
305
+	 * Returns whether or not a message of that type was sent for a given registration
306
+	 *
307
+	 * @param EE_Registration|int $registration
308
+	 * @param string              $message_type the message type slug
309
+	 * @return boolean
310
+	 * @throws EE_Error
311
+	 * @throws EE_Error
312
+	 * @throws EE_Error
313
+	 */
314
+	public function message_sent_for_registration($registration, $message_type)
315
+	{
316
+		$registrationID = EEM_Registration::instance()->ensure_is_ID($registration);
317
+		return $this->exists(array(
318
+			array(
319
+				'Registration.REG_ID' => $registrationID,
320
+				'MSG_message_type'    => $message_type,
321
+				'STS_ID'              => array('IN', $this->stati_indicating_sent()),
322
+			),
323
+		));
324
+	}
325
+
326
+
327
+	/**
328
+	 * This retrieves an EE_Message object from the db matching the given token string.
329
+	 *
330
+	 * @param string $token
331
+	 * @return EE_Message
332
+	 * @throws EE_Error
333
+	 */
334
+	public function get_one_by_token($token)
335
+	{
336
+		return $this->get_one(array(
337
+			array(
338
+				'MSG_token' => $token,
339
+			),
340
+		));
341
+	}
342
+
343
+
344
+	/**
345
+	 * Returns stati that indicate the message HAS been sent
346
+	 *
347
+	 * @return array of strings for possible stati
348
+	 */
349
+	public function stati_indicating_sent()
350
+	{
351
+		return apply_filters('FHEE__EEM_Message__stati_indicating_sent', array(self::status_sent));
352
+	}
353
+
354
+
355
+	/**
356
+	 * Returns stati that indicate the message is waiting to be sent.
357
+	 *
358
+	 * @return array of strings for possible stati.
359
+	 */
360
+	public function stati_indicating_to_send()
361
+	{
362
+		return apply_filters(
363
+			'FHEE__EEM_Message__stati_indicating_to_send',
364
+			array(self::status_idle, self::status_resend)
365
+		);
366
+	}
367
+
368
+
369
+	/**
370
+	 * Returns stati that indicate the message has failed sending
371
+	 *
372
+	 * @return array  array of strings for possible stati.
373
+	 */
374
+	public function stati_indicating_failed_sending()
375
+	{
376
+		$failed_stati = array(
377
+			self::status_failed,
378
+			self::status_retry,
379
+			self::status_messenger_executing,
380
+		);
381
+		// if WP_DEBUG is set, then let's include debug_only fails
382
+		if (WP_DEBUG) {
383
+			$failed_stati[] = self::status_debug_only;
384
+		}
385
+		return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati);
386
+	}
387
+
388
+
389
+	/**
390
+	 * Returns filterable array of all EEM_Message statuses.
391
+	 *
392
+	 * @return array
393
+	 */
394
+	public function all_statuses()
395
+	{
396
+		return apply_filters(
397
+			'FHEE__EEM_Message__all_statuses',
398
+			array(
399
+				EEM_Message::status_sent,
400
+				EEM_Message::status_incomplete,
401
+				EEM_Message::status_idle,
402
+				EEM_Message::status_resend,
403
+				EEM_Message::status_retry,
404
+				EEM_Message::status_failed,
405
+				EEM_Message::status_messenger_executing,
406
+				EEM_Message::status_debug_only,
407
+			)
408
+		);
409
+	}
410
+
411
+	/**
412
+	 * Detects any specific query variables in the request and uses those to setup appropriate
413
+	 * filter for any queries.
414
+	 *
415
+	 * @return array
416
+	 */
417
+	public function filter_by_query_params()
418
+	{
419
+		/** @var RequestInterface $request */
420
+		$request = EEM_Base::$loader->getShared(RequestInterface::class);
421
+		// expected possible query_vars, the key in this array matches an expected key in the request,
422
+		// the value, matches the corresponding EEM_Base child reference.
423
+		$expected_vars   = $this->_expected_vars_for_query_inject();
424
+		$query_params[0] = array();
425
+		foreach ($expected_vars as $request_key => $model_name) {
426
+			$request_value = $request->getRequestParam($request_key);
427
+			if ($request_value) {
428
+				// special case
429
+				switch ($request_key) {
430
+					case '_REG_ID':
431
+						$query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = array(
432
+							'Transaction.Registration.REG_ID' => $request_value,
433
+						);
434
+						break;
435
+					case 'EVT_ID':
436
+						$query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = array(
437
+							'Transaction.Registration.EVT_ID' => $request_value,
438
+						);
439
+						break;
440
+					default:
441
+						$query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value;
442
+						break;
443
+				}
444
+			}
445
+		}
446
+		return $query_params;
447
+	}
448
+
449
+
450
+	/**
451
+	 * @return string
452
+	 * @throws EE_Error
453
+	 * @throws ReflectionException
454
+	 */
455
+	public function get_pretty_label_for_results()
456
+	{
457
+		/** @var RequestInterface $request */
458
+		$request = EEM_Base::$loader->getShared(RequestInterface::class);
459
+		$expected_vars = $this->_expected_vars_for_query_inject();
460
+		$pretty_label  = '';
461
+		$label_parts   = array();
462
+		foreach ($expected_vars as $request_key => $model_name) {
463
+			$model_name = strpos($model_name, 'EEM_', true) === 0 ? $model_name : "EEM_{$model_name}";
464
+			$model = EEM_Base::$loader->getShared($model_name);
465
+			$model_field_value = $request->getRequestParam($request_key);
466
+			if ($model instanceof EEM_Base && $model_field_value !== '') {
467
+				switch ($request_key) {
468
+					case '_REG_ID':
469
+						$label_parts[] = sprintf(
470
+							esc_html__('Registration with the ID: %s', 'event_espresso'),
471
+							$model_field_value
472
+						);
473
+						break;
474
+					case 'ATT_ID':
475
+						/** @var EE_Attendee $attendee */
476
+						$attendee      = $model->get_one_by_ID($model_field_value);
477
+						$label_parts[] = $attendee instanceof EE_Attendee
478
+							? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name())
479
+							: sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value);
480
+						break;
481
+					case 'ID':
482
+						/** @var EE_WP_User $wpUser */
483
+						$wpUser        = $model->get_one_by_ID($model_field_value);
484
+						$label_parts[] = $wpUser instanceof EE_WP_User
485
+							? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name())
486
+							: sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value);
487
+						break;
488
+					case 'TXN_ID':
489
+						$label_parts[] = sprintf(
490
+							esc_html__('Transaction with the ID: %s', 'event_espresso'),
491
+							$model_field_value
492
+						);
493
+						break;
494
+					case 'EVT_ID':
495
+						/** @var EE_Event $Event */
496
+						$Event         = $model->get_one_by_ID($model_field_value);
497
+						$label_parts[] = $Event instanceof EE_Event
498
+							? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name())
499
+							: sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value);
500
+						break;
501
+				}
502
+			}
503
+		}
504
+
505
+		if ($label_parts) {
506
+			// prepend to the last element of $label_parts an "and".
507
+			if (count($label_parts) > 1) {
508
+				$label_parts_index_to_prepend               = count($label_parts) - 1;
509
+				$label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ];
510
+			}
511
+
512
+			$pretty_label .= sprintf(
513
+				esc_html_x(
514
+					'Showing messages for %s',
515
+					'A label for the messages returned in a query that are filtered by items in the query. This could be Transaction, Event, Attendee, Registration, or WP_User.',
516
+					'event_espresso'
517
+				),
518
+				implode(', ', $label_parts)
519
+			);
520
+		}
521
+		return $pretty_label;
522
+	}
523
+
524
+
525
+	/**
526
+	 * This returns the array of expected variables for the EEI_Query_Filter methods being implemented
527
+	 * The array is in the format:
528
+	 * array(
529
+	 *  {$field_name} => {$model_name}
530
+	 * );
531
+	 *
532
+	 * @since 4.9.0
533
+	 * @return array
534
+	 */
535
+	protected function _expected_vars_for_query_inject()
536
+	{
537
+		return array(
538
+			'_REG_ID' => 'Registration',
539
+			'ATT_ID'  => 'Attendee',
540
+			'ID'      => 'WP_User',
541
+			'TXN_ID'  => 'Transaction',
542
+			'EVT_ID'  => 'Event',
543
+		);
544
+	}
545
+
546
+
547
+	/**
548
+	 * This returns whether EEM_Message is in debug mode or not.
549
+	 * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when
550
+	 * generating/sending messages. Debug mode can be set by either:
551
+	 * 1. Sending in a value for the $set_debug argument
552
+	 * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php
553
+	 * 3. Overriding the above via the provided filter.
554
+	 *
555
+	 * @param bool|null $set_debug      If provided, then the debug mode will be set internally until reset via the
556
+	 *                                  provided boolean. When no argument is provided (default null) then the debug
557
+	 *                                  mode will be returned.
558
+	 * @return bool         true means Messages is in debug mode.  false means messages system is not in debug mode.
559
+	 */
560
+	public static function debug($set_debug = null)
561
+	{
562
+		static $is_debugging = null;
563
+
564
+		// initialize (use constant if set).
565
+		if (is_null($set_debug) && is_null($is_debugging)) {
566
+			$is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES;
567
+		}
568
+
569
+		if (! is_null($set_debug)) {
570
+			$is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN);
571
+		}
572
+
573
+		// return filtered value
574
+		return apply_filters('FHEE__EEM_Message__debug', $is_debugging);
575
+	}
576
+
577
+
578
+	/**
579
+	 * Deletes old messages meeting certain criteria for removal from the database.
580
+	 * By default, this will delete messages that:
581
+	 * - are older than the value of the delete_threshold in months.
582
+	 * - have a STS_ID other than EEM_Message::status_idle
583
+	 *
584
+	 * @param int $delete_threshold This integer will be used to set the boundary for what messages are deleted in
585
+	 *                              months.
586
+	 * @return bool|false|int Either the number of records affected or false if there was an error (you can call
587
+	 *                              $wpdb->last_error to find out what the error was.
588
+	 * @throws EE_Error
589
+	 * @throws EE_Error
590
+	 * @throws EE_Error
591
+	 */
592
+	public function delete_old_messages($delete_threshold = 6)
593
+	{
594
+		$number_deleted = 0;
595
+		/**
596
+		 * Allows code to change the boundary for what messages are kept.
597
+		 * Uses the value of the `delete_threshold` variable by default.
598
+		 *
599
+		 * @param int $seconds seconds that will be subtracted from the timestamp for now.
600
+		 * @return int
601
+		 */
602
+		$time_to_leave_alone = absint(
603
+			apply_filters(
604
+				'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone',
605
+				((int) $delete_threshold) * MONTH_IN_SECONDS
606
+			)
607
+		);
608
+
609
+
610
+		/**
611
+		 * Allows code to change what message stati are ignored when deleting.
612
+		 * Defaults to only ignore EEM_Message::status_idle messages.
613
+		 *
614
+		 * @param string $message_stati_to_keep  An array of message statuses that will be ignored when deleting.
615
+		 */
616
+		$message_stati_to_keep = (array) apply_filters(
617
+			'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep',
618
+			array(
619
+				EEM_Message::status_idle
620
+			)
621
+		);
622
+
623
+		// first get all the ids of messages being deleted
624
+		$message_ids_to_delete = EEM_Message::instance()->get_col(
625
+			array(
626
+				0 => array(
627
+					'STS_ID' => array('NOT_IN', $message_stati_to_keep),
628
+					'MSG_modified' => array('<', time() - $time_to_leave_alone)
629
+				),
630
+				'limit' => apply_filters(
631
+					'EEM_Message__delete_old_messages__limit',
632
+					2000,
633
+					$delete_threshold
634
+				)
635
+			)
636
+		);
637
+
638
+		if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
639
+			global $wpdb;
640
+			$number_deleted = $wpdb->query('
641 641
                 DELETE
642 642
                 FROM ' . $this->table() . '
643 643
                 WHERE
644 644
                     MSG_ID IN (' . implode(",", $message_ids_to_delete) . ')
645 645
             ');
646
-        }
647
-
648
-        /**
649
-         * This will get called if the number of records deleted 0 or greater.  So a successful deletion is one where
650
-         * there were no errors.  An unsuccessful deletion is where there were errors.  Keep that in mind for the actions
651
-         * below.
652
-         */
653
-        if ($number_deleted !== false) {
654
-            do_action('AHEE__EEM_Message__delete_old_messages__after_successful_deletion', $message_ids_to_delete, $number_deleted);
655
-        } else {
656
-            do_action('AHEE__EEM_Message__delete_old_messages__after_deletion_fail', $message_ids_to_delete, $number_deleted);
657
-        }
658
-        return $number_deleted;
659
-    }
646
+		}
647
+
648
+		/**
649
+		 * This will get called if the number of records deleted 0 or greater.  So a successful deletion is one where
650
+		 * there were no errors.  An unsuccessful deletion is where there were errors.  Keep that in mind for the actions
651
+		 * below.
652
+		 */
653
+		if ($number_deleted !== false) {
654
+			do_action('AHEE__EEM_Message__delete_old_messages__after_successful_deletion', $message_ids_to_delete, $number_deleted);
655
+		} else {
656
+			do_action('AHEE__EEM_Message__delete_old_messages__after_deletion_fail', $message_ids_to_delete, $number_deleted);
657
+		}
658
+		return $number_deleted;
659
+	}
660 660
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_Field_With_Model_Name.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -79,10 +79,10 @@
 block discarded – undo
79 79
         $model_names = [];
80 80
         if (is_array($this->_model_name_pointed_to)) {
81 81
             foreach ($this->_model_name_pointed_to as $model_name) {
82
-                $model_names[] = "EE_" . $model_name;
82
+                $model_names[] = "EE_".$model_name;
83 83
             }
84 84
         } else {
85
-            $model_names = ["EE_" . $this->_model_name_pointed_to];
85
+            $model_names = ["EE_".$this->_model_name_pointed_to];
86 86
         }
87 87
         return $model_names;
88 88
     }
Please login to merge, or discard this patch.
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -8,94 +8,94 @@
 block discarded – undo
8 8
  */
9 9
 abstract class EE_Field_With_Model_Name extends EE_Model_Field_Base
10 10
 {
11
-    /**
12
-     * Usually the name of a single model. However, as in the case for custom post types,
13
-     * it can actually be an array of models
14
-     *
15
-     * @var string[]
16
-     */
17
-    protected $_model_name_pointed_to;
11
+	/**
12
+	 * Usually the name of a single model. However, as in the case for custom post types,
13
+	 * it can actually be an array of models
14
+	 *
15
+	 * @var string[]
16
+	 */
17
+	protected $_model_name_pointed_to;
18 18
 
19 19
 
20
-    /**
21
-     * @param string          $table_column  name of column for field
22
-     * @param string          $nicename      should be internationalized with __('blah','event_espresso')
23
-     * @param boolean         $nullable
24
-     * @param int|string      $default_value data type should match field type
25
-     * @param string|string[] $model_name    eg 'Event','Answer','Term', etc.
26
-     *                                       Basically its the model class's name without the "EEM_"
27
-     */
28
-    public function __construct($table_column, $nicename, $nullable, $default_value, $model_name)
29
-    {
30
-        $this->_model_name_pointed_to = (array) $model_name;
31
-        parent::__construct($table_column, $nicename, $nullable, $default_value);
32
-    }
20
+	/**
21
+	 * @param string          $table_column  name of column for field
22
+	 * @param string          $nicename      should be internationalized with __('blah','event_espresso')
23
+	 * @param boolean         $nullable
24
+	 * @param int|string      $default_value data type should match field type
25
+	 * @param string|string[] $model_name    eg 'Event','Answer','Term', etc.
26
+	 *                                       Basically its the model class's name without the "EEM_"
27
+	 */
28
+	public function __construct($table_column, $nicename, $nullable, $default_value, $model_name)
29
+	{
30
+		$this->_model_name_pointed_to = (array) $model_name;
31
+		parent::__construct($table_column, $nicename, $nullable, $default_value);
32
+	}
33 33
 
34 34
 
35
-    /**
36
-     * Returns the name of the model(s) pointed to
37
-     *
38
-     * @return string[] string or array of strings
39
-     * @deprecated since version 4.6.7
40
-     */
41
-    public function get_model_name_pointed_to(): array
42
-    {
43
-        EE_Error::doing_it_wrong(
44
-            'get_model_name_pointed_to',
45
-            esc_html__(
46
-                'This method has been deprecated in favour of instead using get_model_names_pointed_to, which consistently returns an array',
47
-                'event_espresso'
48
-            ),
49
-            '4.6.7'
50
-        );
51
-        return $this->_model_name_pointed_to;
52
-    }
35
+	/**
36
+	 * Returns the name of the model(s) pointed to
37
+	 *
38
+	 * @return string[] string or array of strings
39
+	 * @deprecated since version 4.6.7
40
+	 */
41
+	public function get_model_name_pointed_to(): array
42
+	{
43
+		EE_Error::doing_it_wrong(
44
+			'get_model_name_pointed_to',
45
+			esc_html__(
46
+				'This method has been deprecated in favour of instead using get_model_names_pointed_to, which consistently returns an array',
47
+				'event_espresso'
48
+			),
49
+			'4.6.7'
50
+		);
51
+		return $this->_model_name_pointed_to;
52
+	}
53 53
 
54 54
 
55
-    /**
56
-     * Gets the model names pointed to by this field, always as an array
57
-     * (even if there's only one)
58
-     *
59
-     * @return string[] of model names pointed to by this field
60
-     */
61
-    public function get_model_names_pointed_to(): array
62
-    {
63
-        return is_array($this->_model_name_pointed_to)
64
-            ? $this->_model_name_pointed_to
65
-            : [$this->_model_name_pointed_to];
66
-    }
55
+	/**
56
+	 * Gets the model names pointed to by this field, always as an array
57
+	 * (even if there's only one)
58
+	 *
59
+	 * @return string[] of model names pointed to by this field
60
+	 */
61
+	public function get_model_names_pointed_to(): array
62
+	{
63
+		return is_array($this->_model_name_pointed_to)
64
+			? $this->_model_name_pointed_to
65
+			: [$this->_model_name_pointed_to];
66
+	}
67 67
 
68 68
 
69
-    /**
70
-     * Returns the model's classname (eg EE_Event instead of just Event)
71
-     *
72
-     * @return string[]
73
-     */
74
-    public function get_model_class_names_pointed_to(): array
75
-    {
76
-        $model_names = [];
77
-        if (is_array($this->_model_name_pointed_to)) {
78
-            foreach ($this->_model_name_pointed_to as $model_name) {
79
-                $model_names[] = "EE_" . $model_name;
80
-            }
81
-        } else {
82
-            $model_names = ["EE_" . $this->_model_name_pointed_to];
83
-        }
84
-        return $model_names;
85
-    }
69
+	/**
70
+	 * Returns the model's classname (eg EE_Event instead of just Event)
71
+	 *
72
+	 * @return string[]
73
+	 */
74
+	public function get_model_class_names_pointed_to(): array
75
+	{
76
+		$model_names = [];
77
+		if (is_array($this->_model_name_pointed_to)) {
78
+			foreach ($this->_model_name_pointed_to as $model_name) {
79
+				$model_names[] = "EE_" . $model_name;
80
+			}
81
+		} else {
82
+			$model_names = ["EE_" . $this->_model_name_pointed_to];
83
+		}
84
+		return $model_names;
85
+	}
86 86
 
87 87
 
88
-    /**
89
-     * @param int|EE_Base_Class $model_obj
90
-     * @return bool
91
-     */
92
-    public function is_model_obj_of_type_pointed_to($model_obj): bool
93
-    {
94
-        foreach ($this->get_model_class_names_pointed_to() as $model_obj_classname) {
95
-            if ($model_obj instanceof $model_obj_classname) {
96
-                return true;
97
-            }
98
-        }
99
-        return false;
100
-    }
88
+	/**
89
+	 * @param int|EE_Base_Class $model_obj
90
+	 * @return bool
91
+	 */
92
+	public function is_model_obj_of_type_pointed_to($model_obj): bool
93
+	{
94
+		foreach ($this->get_model_class_names_pointed_to() as $model_obj_classname) {
95
+			if ($model_obj instanceof $model_obj_classname) {
96
+				return true;
97
+			}
98
+		}
99
+		return false;
100
+	}
101 101
 }
Please login to merge, or discard this patch.
core/db_models/fields/EE_WP_Post_Type_Field.php.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -5,12 +5,12 @@
 block discarded – undo
5 5
  */
6 6
 class EE_WP_Post_Type_Field extends EE_DB_Only_Text_Field
7 7
 {
8
-    /**
9
-     * @param string $post_type the exact string to be used for the post type
10
-     *                          of all these post type model objects/rows
11
-     */
12
-    public function __construct($post_type)
13
-    {
14
-        parent::__construct('post_type', esc_html__("Post Type", 'event_espresso'), false, $post_type);
15
-    }
8
+	/**
9
+	 * @param string $post_type the exact string to be used for the post type
10
+	 *                          of all these post type model objects/rows
11
+	 */
12
+	public function __construct($post_type)
13
+	{
14
+		parent::__construct('post_type', esc_html__("Post Type", 'event_espresso'), false, $post_type);
15
+	}
16 16
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Currency_Payment_Method.model.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@
 block discarded – undo
55 55
             'Payment_Method' => new EE_Belongs_To_Relation(),
56 56
         ];
57 57
         // this model is generally available for reading
58
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
58
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
59 59
         $this->_caps_slug                                         = 'payment_methods';
60 60
         parent::__construct($timezone);
61 61
     }
Please login to merge, or discard this patch.
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -9,44 +9,44 @@
 block discarded – undo
9 9
  */
10 10
 class EEM_Currency_Payment_Method extends EEM_Base
11 11
 {
12
-    protected static ?EEM_Currency_Payment_Method $_instance = null;
12
+	protected static ?EEM_Currency_Payment_Method $_instance = null;
13 13
 
14
-    protected function __construct($timezone = null)
15
-    {
16
-        $this->singular_item    = esc_html__('Currency Usable by Payment Method', 'event_espresso');
17
-        $this->plural_item      = esc_html__('Currencies Usable by Payment Methods', 'event_espresso');
18
-        $this->_tables          = [
19
-            'Currency_Payment_Method' => new EE_Primary_Table('esp_currency_payment_method', 'CPM_ID'),
20
-        ];
21
-        $this->_fields          = [
22
-            'Currency_Payment_Method' => [
23
-                'CPM_ID'   => new EE_Primary_Key_Int_Field(
24
-                    'CPM_ID',
25
-                    esc_html__('Currency to Payment Method LInk ID', 'event_espresso')
26
-                ),
27
-                'CUR_code' => new EE_Foreign_Key_String_Field(
28
-                    'CUR_code',
29
-                    esc_html__('Currency Code', 'event_espresso'),
30
-                    false,
31
-                    '',
32
-                    'Currency'
33
-                ),
34
-                'PMD_ID'   => new EE_Foreign_Key_Int_Field(
35
-                    'PMD_ID',
36
-                    esc_html__('Paymetn Method ID', 'event_espresso'),
37
-                    false,
38
-                    0,
39
-                    'Payment_Method'
40
-                ),
41
-            ],
42
-        ];
43
-        $this->_model_relations = [
44
-            'Currency'       => new EE_Belongs_To_Relation(),
45
-            'Payment_Method' => new EE_Belongs_To_Relation(),
46
-        ];
47
-        // this model is generally available for reading
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
49
-        $this->_caps_slug                                         = 'payment_methods';
50
-        parent::__construct($timezone);
51
-    }
14
+	protected function __construct($timezone = null)
15
+	{
16
+		$this->singular_item    = esc_html__('Currency Usable by Payment Method', 'event_espresso');
17
+		$this->plural_item      = esc_html__('Currencies Usable by Payment Methods', 'event_espresso');
18
+		$this->_tables          = [
19
+			'Currency_Payment_Method' => new EE_Primary_Table('esp_currency_payment_method', 'CPM_ID'),
20
+		];
21
+		$this->_fields          = [
22
+			'Currency_Payment_Method' => [
23
+				'CPM_ID'   => new EE_Primary_Key_Int_Field(
24
+					'CPM_ID',
25
+					esc_html__('Currency to Payment Method LInk ID', 'event_espresso')
26
+				),
27
+				'CUR_code' => new EE_Foreign_Key_String_Field(
28
+					'CUR_code',
29
+					esc_html__('Currency Code', 'event_espresso'),
30
+					false,
31
+					'',
32
+					'Currency'
33
+				),
34
+				'PMD_ID'   => new EE_Foreign_Key_Int_Field(
35
+					'PMD_ID',
36
+					esc_html__('Paymetn Method ID', 'event_espresso'),
37
+					false,
38
+					0,
39
+					'Payment_Method'
40
+				),
41
+			],
42
+		];
43
+		$this->_model_relations = [
44
+			'Currency'       => new EE_Belongs_To_Relation(),
45
+			'Payment_Method' => new EE_Belongs_To_Relation(),
46
+		];
47
+		// this model is generally available for reading
48
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
49
+		$this->_caps_slug                                         = 'payment_methods';
50
+		parent::__construct($timezone);
51
+	}
52 52
 }
Please login to merge, or discard this patch.
core/services/form/meta/inputs/Button.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -4,49 +4,49 @@
 block discarded – undo
4 4
 
5 5
 class Button
6 6
 {
7
-    /**
8
-     * indicates that the HTML input type is 'button'
9
-     */
10
-    public const TYPE_BUTTON = 'button';
11
-
12
-    /**
13
-     * indicates that the HTML input type is 'reset'
14
-     */
15
-    public const TYPE_BUTTON_RESET = 'reset';
16
-
17
-    /**
18
-     * indicates that the HTML input type is 'submit'
19
-     */
20
-    public const TYPE_BUTTON_SUBMIT = 'submit';
21
-
22
-
23
-    /**
24
-     * @var array
25
-     */
26
-    private $valid_type_options;
27
-
28
-
29
-    public function __construct()
30
-    {
31
-        $this->valid_type_options = apply_filters(
32
-            'FHEE__EventEspresso_core_services_form_meta_inputs_Button__valid_type_options',
33
-            [
34
-                Button::TYPE_BUTTON        => esc_html__('Button', 'event_espresso'),
35
-                Button::TYPE_BUTTON_RESET  => esc_html__('Reset Button', 'event_espresso'),
36
-                Button::TYPE_BUTTON_SUBMIT => esc_html__('Submit Button', 'event_espresso'),
37
-            ]
38
-        );
39
-    }
40
-
41
-
42
-    /**
43
-     * @param bool $constants_only
44
-     * @return array
45
-     */
46
-    public function validTypeOptions(bool $constants_only = false): array
47
-    {
48
-        return $constants_only
49
-            ? array_keys($this->valid_type_options)
50
-            : $this->valid_type_options;
51
-    }
7
+	/**
8
+	 * indicates that the HTML input type is 'button'
9
+	 */
10
+	public const TYPE_BUTTON = 'button';
11
+
12
+	/**
13
+	 * indicates that the HTML input type is 'reset'
14
+	 */
15
+	public const TYPE_BUTTON_RESET = 'reset';
16
+
17
+	/**
18
+	 * indicates that the HTML input type is 'submit'
19
+	 */
20
+	public const TYPE_BUTTON_SUBMIT = 'submit';
21
+
22
+
23
+	/**
24
+	 * @var array
25
+	 */
26
+	private $valid_type_options;
27
+
28
+
29
+	public function __construct()
30
+	{
31
+		$this->valid_type_options = apply_filters(
32
+			'FHEE__EventEspresso_core_services_form_meta_inputs_Button__valid_type_options',
33
+			[
34
+				Button::TYPE_BUTTON        => esc_html__('Button', 'event_espresso'),
35
+				Button::TYPE_BUTTON_RESET  => esc_html__('Reset Button', 'event_espresso'),
36
+				Button::TYPE_BUTTON_SUBMIT => esc_html__('Submit Button', 'event_espresso'),
37
+			]
38
+		);
39
+	}
40
+
41
+
42
+	/**
43
+	 * @param bool $constants_only
44
+	 * @return array
45
+	 */
46
+	public function validTypeOptions(bool $constants_only = false): array
47
+	{
48
+		return $constants_only
49
+			? array_keys($this->valid_type_options)
50
+			: $this->valid_type_options;
51
+	}
52 52
 }
Please login to merge, or discard this patch.
core/services/form/meta/inputs/DateTime.php 1 patch
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -5,81 +5,81 @@
 block discarded – undo
5 5
 class DateTime
6 6
 {
7 7
 
8
-    /**
9
-     * indicates that the HTML input type is 'date'
10
-     */
11
-    public const TYPE_DATE = 'date';
12
-
13
-    /**
14
-     * indicates that the HTML input type is 'datetime-local'
15
-     */
16
-    public const TYPE_DATETIME_LOCAL = 'datetime-local';
17
-
18
-    /**
19
-     * indicates that the HTML input type is 'month'
20
-     */
21
-    public const TYPE_MONTH = 'month';
22
-
23
-    /**
24
-     * indicates that the HTML input type is 'time'
25
-     */
26
-    public const TYPE_TIME = 'time';
27
-
28
-    /**
29
-     * indicates that the HTML input type is 'week'
30
-     */
31
-    public const TYPE_WEEK = 'week';
32
-
33
-    // CUSTOM EE DATE TYPES
34
-
35
-    /**
36
-     * indicates that the input is an HTML dropdown used for selecting the day for a date
37
-     */
38
-    public const TYPE_SELECT_DAY = 'day-select';
39
-
40
-    /**
41
-     * indicates that the input is an HTML dropdown used for selecting the month for a date
42
-     */
43
-    public const TYPE_SELECT_MONTH = 'month-select';
44
-
45
-    /**
46
-     * indicates that the input is an HTML dropdown used for selecting the year for a date
47
-     */
48
-    public const TYPE_SELECT_YEAR = 'year-select';
49
-
50
-
51
-    /**
52
-     * @var array
53
-     */
54
-    private $valid_type_options;
55
-
56
-
57
-    public function __construct()
58
-    {
59
-        $this->valid_type_options = apply_filters(
60
-            'FHEE__EventEspresso_core_services_form_meta_inputs_DateTime__valid_type_options',
61
-            [
62
-                DateTime::TYPE_DATE           => esc_html__('Date Picker', 'event_espresso'),
63
-                DateTime::TYPE_DATETIME_LOCAL => esc_html__('Local Date Picker', 'event_espresso'),
64
-                DateTime::TYPE_MONTH          => esc_html__('Month Picker', 'event_espresso'),
65
-                DateTime::TYPE_TIME           => esc_html__('Time Picker', 'event_espresso'),
66
-                DateTime::TYPE_WEEK           => esc_html__('Week Picker', 'event_espresso'),
67
-                DateTime::TYPE_SELECT_DAY     => esc_html__('Day Selector', 'event_espresso'),
68
-                DateTime::TYPE_SELECT_MONTH   => esc_html__('Month Selector', 'event_espresso'),
69
-                DateTime::TYPE_SELECT_YEAR    => esc_html__('Year Selector', 'event_espresso'),
70
-            ]
71
-        );
72
-    }
73
-
74
-
75
-    /**
76
-     * @param bool $constants_only
77
-     * @return array
78
-     */
79
-    public function validTypeOptions(bool $constants_only = false): array
80
-    {
81
-        return $constants_only
82
-            ? array_keys($this->valid_type_options)
83
-            : $this->valid_type_options;
84
-    }
8
+	/**
9
+	 * indicates that the HTML input type is 'date'
10
+	 */
11
+	public const TYPE_DATE = 'date';
12
+
13
+	/**
14
+	 * indicates that the HTML input type is 'datetime-local'
15
+	 */
16
+	public const TYPE_DATETIME_LOCAL = 'datetime-local';
17
+
18
+	/**
19
+	 * indicates that the HTML input type is 'month'
20
+	 */
21
+	public const TYPE_MONTH = 'month';
22
+
23
+	/**
24
+	 * indicates that the HTML input type is 'time'
25
+	 */
26
+	public const TYPE_TIME = 'time';
27
+
28
+	/**
29
+	 * indicates that the HTML input type is 'week'
30
+	 */
31
+	public const TYPE_WEEK = 'week';
32
+
33
+	// CUSTOM EE DATE TYPES
34
+
35
+	/**
36
+	 * indicates that the input is an HTML dropdown used for selecting the day for a date
37
+	 */
38
+	public const TYPE_SELECT_DAY = 'day-select';
39
+
40
+	/**
41
+	 * indicates that the input is an HTML dropdown used for selecting the month for a date
42
+	 */
43
+	public const TYPE_SELECT_MONTH = 'month-select';
44
+
45
+	/**
46
+	 * indicates that the input is an HTML dropdown used for selecting the year for a date
47
+	 */
48
+	public const TYPE_SELECT_YEAR = 'year-select';
49
+
50
+
51
+	/**
52
+	 * @var array
53
+	 */
54
+	private $valid_type_options;
55
+
56
+
57
+	public function __construct()
58
+	{
59
+		$this->valid_type_options = apply_filters(
60
+			'FHEE__EventEspresso_core_services_form_meta_inputs_DateTime__valid_type_options',
61
+			[
62
+				DateTime::TYPE_DATE           => esc_html__('Date Picker', 'event_espresso'),
63
+				DateTime::TYPE_DATETIME_LOCAL => esc_html__('Local Date Picker', 'event_espresso'),
64
+				DateTime::TYPE_MONTH          => esc_html__('Month Picker', 'event_espresso'),
65
+				DateTime::TYPE_TIME           => esc_html__('Time Picker', 'event_espresso'),
66
+				DateTime::TYPE_WEEK           => esc_html__('Week Picker', 'event_espresso'),
67
+				DateTime::TYPE_SELECT_DAY     => esc_html__('Day Selector', 'event_espresso'),
68
+				DateTime::TYPE_SELECT_MONTH   => esc_html__('Month Selector', 'event_espresso'),
69
+				DateTime::TYPE_SELECT_YEAR    => esc_html__('Year Selector', 'event_espresso'),
70
+			]
71
+		);
72
+	}
73
+
74
+
75
+	/**
76
+	 * @param bool $constants_only
77
+	 * @return array
78
+	 */
79
+	public function validTypeOptions(bool $constants_only = false): array
80
+	{
81
+		return $constants_only
82
+			? array_keys($this->valid_type_options)
83
+			: $this->valid_type_options;
84
+	}
85 85
 }
Please login to merge, or discard this patch.
core/services/form/meta/inputs/Number.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -5,49 +5,49 @@
 block discarded – undo
5 5
 class Number
6 6
 {
7 7
 
8
-    /**
9
-     * indicates that the HTML input type is 'number' whose value is a decimal (float)
10
-     */
11
-    public const TYPE_FLOAT = 'decimal';
12
-
13
-    /**
14
-     * indicates that the HTML input type is 'number' whose value is an integer (whole number)
15
-     */
16
-    public const TYPE_INT = 'integer';
17
-
18
-    /**
19
-     * indicates that the HTML input type is 'range'
20
-     */
21
-    public const TYPE_RANGE = 'range';
22
-
23
-
24
-    /**
25
-     * @var array
26
-     */
27
-    private $valid_type_options;
28
-
29
-
30
-    public function __construct()
31
-    {
32
-        $this->valid_type_options = apply_filters(
33
-            'FHEE__EventEspresso_core_services_form_meta_inputs_Number__valid_type_options',
34
-            [
35
-                Number::TYPE_FLOAT => esc_html__('Decimal Number', 'event_espresso'),
36
-                Number::TYPE_INT   => esc_html__('Integer (Whole) Number', 'event_espresso'),
37
-                Number::TYPE_RANGE => esc_html__('Number Range', 'event_espresso'),
38
-            ]
39
-        );
40
-    }
41
-
42
-
43
-    /**
44
-     * @param bool $constants_only
45
-     * @return array
46
-     */
47
-    public function validTypeOptions(bool $constants_only = false): array
48
-    {
49
-        return $constants_only
50
-            ? array_keys($this->valid_type_options)
51
-            : $this->valid_type_options;
52
-    }
8
+	/**
9
+	 * indicates that the HTML input type is 'number' whose value is a decimal (float)
10
+	 */
11
+	public const TYPE_FLOAT = 'decimal';
12
+
13
+	/**
14
+	 * indicates that the HTML input type is 'number' whose value is an integer (whole number)
15
+	 */
16
+	public const TYPE_INT = 'integer';
17
+
18
+	/**
19
+	 * indicates that the HTML input type is 'range'
20
+	 */
21
+	public const TYPE_RANGE = 'range';
22
+
23
+
24
+	/**
25
+	 * @var array
26
+	 */
27
+	private $valid_type_options;
28
+
29
+
30
+	public function __construct()
31
+	{
32
+		$this->valid_type_options = apply_filters(
33
+			'FHEE__EventEspresso_core_services_form_meta_inputs_Number__valid_type_options',
34
+			[
35
+				Number::TYPE_FLOAT => esc_html__('Decimal Number', 'event_espresso'),
36
+				Number::TYPE_INT   => esc_html__('Integer (Whole) Number', 'event_espresso'),
37
+				Number::TYPE_RANGE => esc_html__('Number Range', 'event_espresso'),
38
+			]
39
+		);
40
+	}
41
+
42
+
43
+	/**
44
+	 * @param bool $constants_only
45
+	 * @return array
46
+	 */
47
+	public function validTypeOptions(bool $constants_only = false): array
48
+	{
49
+		return $constants_only
50
+			? array_keys($this->valid_type_options)
51
+			: $this->valid_type_options;
52
+	}
53 53
 }
Please login to merge, or discard this patch.
core/services/form/meta/inputs/Select.php 1 patch
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -5,59 +5,59 @@
 block discarded – undo
5 5
 class Select
6 6
 {
7 7
 
8
-    /**
9
-     * indicates that the input is an HTML dropdown (select input) that accepts only one value
10
-     */
11
-    public const TYPE_SELECT = 'select';
12
-
13
-    /**
14
-     * indicates that the input is an HTML dropdown (select input) that accepts multiple values
15
-     */
16
-    public const TYPE_SELECT_MULTI = 'select-multi';
17
-
18
-    // CUSTOM EE SELECT TYPES
19
-
20
-    /**
21
-     * indicates that input is an HTML dropdown (select input)
22
-     * populated with names of countries that are enabled for the site
23
-     */
24
-    public const TYPE_SELECT_COUNTRY = 'select-country';
25
-
26
-    /**
27
-     * indicates that the input is an HTML dropdown (select input)
28
-     * populated with names of states for the countries that are enabled for the site
29
-     */
30
-    public const TYPE_SELECT_STATE = 'select-state';
31
-
32
-
33
-    /**
34
-     * @var array
35
-     */
36
-    private $valid_type_options;
37
-
38
-
39
-    public function __construct()
40
-    {
41
-        $this->valid_type_options = apply_filters(
42
-            'FHEE__EventEspresso_core_services_form_meta_inputs_Select__valid_type_options',
43
-            [
44
-                Select::TYPE_SELECT         => esc_html__('Dropdown', 'event_espresso'),
45
-                Select::TYPE_SELECT_MULTI   => esc_html__('Multi-Select Dropdown', 'event_espresso'),
46
-                Select::TYPE_SELECT_COUNTRY => esc_html__('Country Selector', 'event_espresso'),
47
-                Select::TYPE_SELECT_STATE   => esc_html__('State Selector', 'event_espresso'),
48
-            ]
49
-        );
50
-    }
51
-
52
-
53
-    /**
54
-     * @param bool $constants_only
55
-     * @return array
56
-     */
57
-    public function validTypeOptions(bool $constants_only = false): array
58
-    {
59
-        return $constants_only
60
-            ? array_keys($this->valid_type_options)
61
-            : $this->valid_type_options;
62
-    }
8
+	/**
9
+	 * indicates that the input is an HTML dropdown (select input) that accepts only one value
10
+	 */
11
+	public const TYPE_SELECT = 'select';
12
+
13
+	/**
14
+	 * indicates that the input is an HTML dropdown (select input) that accepts multiple values
15
+	 */
16
+	public const TYPE_SELECT_MULTI = 'select-multi';
17
+
18
+	// CUSTOM EE SELECT TYPES
19
+
20
+	/**
21
+	 * indicates that input is an HTML dropdown (select input)
22
+	 * populated with names of countries that are enabled for the site
23
+	 */
24
+	public const TYPE_SELECT_COUNTRY = 'select-country';
25
+
26
+	/**
27
+	 * indicates that the input is an HTML dropdown (select input)
28
+	 * populated with names of states for the countries that are enabled for the site
29
+	 */
30
+	public const TYPE_SELECT_STATE = 'select-state';
31
+
32
+
33
+	/**
34
+	 * @var array
35
+	 */
36
+	private $valid_type_options;
37
+
38
+
39
+	public function __construct()
40
+	{
41
+		$this->valid_type_options = apply_filters(
42
+			'FHEE__EventEspresso_core_services_form_meta_inputs_Select__valid_type_options',
43
+			[
44
+				Select::TYPE_SELECT         => esc_html__('Dropdown', 'event_espresso'),
45
+				Select::TYPE_SELECT_MULTI   => esc_html__('Multi-Select Dropdown', 'event_espresso'),
46
+				Select::TYPE_SELECT_COUNTRY => esc_html__('Country Selector', 'event_espresso'),
47
+				Select::TYPE_SELECT_STATE   => esc_html__('State Selector', 'event_espresso'),
48
+			]
49
+		);
50
+	}
51
+
52
+
53
+	/**
54
+	 * @param bool $constants_only
55
+	 * @return array
56
+	 */
57
+	public function validTypeOptions(bool $constants_only = false): array
58
+	{
59
+		return $constants_only
60
+			? array_keys($this->valid_type_options)
61
+			: $this->valid_type_options;
62
+	}
63 63
 }
Please login to merge, or discard this patch.
core/services/form/meta/inputs/Phone.php 2 patches
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -5,109 +5,109 @@
 block discarded – undo
5 5
 class Phone
6 6
 {
7 7
 
8
-    /**
9
-     * indicates that the HTML input type is 'tel'
10
-     */
11
-    public const INPUT_TYPE = 'tel';
8
+	/**
9
+	 * indicates that the HTML input type is 'tel'
10
+	 */
11
+	public const INPUT_TYPE = 'tel';
12 12
 
13
-    /**
14
-     * indicates that the 'tel' input regex pattern is for a US formatted phone number, examples:
15
-     *      ##########
16
-     *      ###-###-####
17
-     *      ### ### ####
18
-     *      (###)-###-####
19
-     *      (###) ###-####
20
-     *
21
-     * captures the intl code to the first group (+1) and the rest of the number to group 2
22
-     *      +1 (###) ###-####
23
-     */
24
-    public const PATTERN_US = '(\+?\d{1,3})?[\ \-]?(\(?\d{3}\)?[\ \-]?\d{3}[\ \-]?\d{4})';
13
+	/**
14
+	 * indicates that the 'tel' input regex pattern is for a US formatted phone number, examples:
15
+	 *      ##########
16
+	 *      ###-###-####
17
+	 *      ### ### ####
18
+	 *      (###)-###-####
19
+	 *      (###) ###-####
20
+	 *
21
+	 * captures the intl code to the first group (+1) and the rest of the number to group 2
22
+	 *      +1 (###) ###-####
23
+	 */
24
+	public const PATTERN_US = '(\+?\d{1,3})?[\ \-]?(\(?\d{3}\)?[\ \-]?\d{3}[\ \-]?\d{4})';
25 25
 
26
-    /**
27
-     * indicates that the 'tel' input regex pattern is for a UK formatted phone number, examples:
28
-     *      (###) #### ####
29
-     *      (####) ### ####
30
-     *      (#####) ## ####
31
-     *
32
-     * captures the intl code to the first group (+44) and the rest of the number to group 2
33
-     *      +44 (###) #### ####
34
-     */
35
-    public const PATTERN_UK = '(\+?44)?[\ ]?(\(?(?:(?:\d{3,5})|(?:\d{4} \d{2}))\)?[\-\ ]?\d{2,4}[\-\ ]?\d{2,4})';
26
+	/**
27
+	 * indicates that the 'tel' input regex pattern is for a UK formatted phone number, examples:
28
+	 *      (###) #### ####
29
+	 *      (####) ### ####
30
+	 *      (#####) ## ####
31
+	 *
32
+	 * captures the intl code to the first group (+44) and the rest of the number to group 2
33
+	 *      +44 (###) #### ####
34
+	 */
35
+	public const PATTERN_UK = '(\+?44)?[\ ]?(\(?(?:(?:\d{3,5})|(?:\d{4} \d{2}))\)?[\-\ ]?\d{2,4}[\-\ ]?\d{2,4})';
36 36
 
37
-    /**
38
-     * indicates that the 'tel' input regex pattern is for a France formatted phone number, examples:
39
-     *      0# ## ## ## ##
40
-     *      0### ## ## ##
41
-     *
42
-     * captures the intl code to the first group (+33) and the rest of the number to group 2
43
-     *      +33 # ## ## ## ##
44
-     *      0033 # ## ## ## ##
45
-     */
46
-    public const PATTERN_FR = '((?:\+|00)33)?[\ \.\-]*((?:(?:\(0\)[\ \.\-]{0,3})?|0)[1-9](?:(?:[\ \.\-]?\d{2}){4}|\d{2}(?:[\ \.\-]?\d{3}){2}))';
37
+	/**
38
+	 * indicates that the 'tel' input regex pattern is for a France formatted phone number, examples:
39
+	 *      0# ## ## ## ##
40
+	 *      0### ## ## ##
41
+	 *
42
+	 * captures the intl code to the first group (+33) and the rest of the number to group 2
43
+	 *      +33 # ## ## ## ##
44
+	 *      0033 # ## ## ## ##
45
+	 */
46
+	public const PATTERN_FR = '((?:\+|00)33)?[\ \.\-]*((?:(?:\(0\)[\ \.\-]{0,3})?|0)[1-9](?:(?:[\ \.\-]?\d{2}){4}|\d{2}(?:[\ \.\-]?\d{3}){2}))';
47 47
 
48
-    /**
49
-     * indicates that the 'tel' input regex pattern is for a German formatted phone number, examples:
50
-     *      (0##) ####-####
51
-     *      (0###) ####-####
52
-     *      (0####) ###-####
53
-     *      (03####) ##-####
54
-     *
55
-     * captures the intl code to the first group (+49) and the rest of the number to group 2
56
-     *      +49 (0##) ####-####
57
-     */
58
-    public const PATTERN_DE = '(\+?49)?[\ \.\-]?(\(?(?:[\d \-\)\–\/\(]+){6,}\)?(?:[\ \.\-–\/]?)(?:[\d]+))';
48
+	/**
49
+	 * indicates that the 'tel' input regex pattern is for a German formatted phone number, examples:
50
+	 *      (0##) ####-####
51
+	 *      (0###) ####-####
52
+	 *      (0####) ###-####
53
+	 *      (03####) ##-####
54
+	 *
55
+	 * captures the intl code to the first group (+49) and the rest of the number to group 2
56
+	 *      +49 (0##) ####-####
57
+	 */
58
+	public const PATTERN_DE = '(\+?49)?[\ \.\-]?(\(?(?:[\d \-\)\–\/\(]+){6,}\)?(?:[\ \.\-–\/]?)(?:[\d]+))';
59 59
 
60
-    /**
61
-     * @var array
62
-     */
63
-    private $regex_patterns;
60
+	/**
61
+	 * @var array
62
+	 */
63
+	private $regex_patterns;
64 64
 
65
-    /**
66
-     * @var array
67
-     */
68
-    private $valid_type_options;
65
+	/**
66
+	 * @var array
67
+	 */
68
+	private $valid_type_options;
69 69
 
70 70
 
71
-    /**
72
-     * Phone constructor.
73
-     */
74
-    public function __construct()
75
-    {
76
-        $this->regex_patterns     = (array) apply_filters(
77
-            'FHEE__EventEspresso_core_services_form_meta_inputs_Phone__regex_patterns',
78
-            [
79
-                'de_DE' => Phone::PATTERN_DE,
80
-                'fr_FR' => Phone::PATTERN_FR,
81
-                'en_UK' => Phone::PATTERN_UK,
82
-                'en_US' => Phone::PATTERN_US,
83
-            ]
84
-        );
85
-        $this->valid_type_options = apply_filters(
86
-            'FHEE__EventEspresso_core_services_form_meta_inputs_Phone__valid_type_options',
87
-            [
88
-                Phone::INPUT_TYPE => esc_html__('Phone Number', 'event_espresso'),
89
-            ]
90
-        );
91
-    }
71
+	/**
72
+	 * Phone constructor.
73
+	 */
74
+	public function __construct()
75
+	{
76
+		$this->regex_patterns     = (array) apply_filters(
77
+			'FHEE__EventEspresso_core_services_form_meta_inputs_Phone__regex_patterns',
78
+			[
79
+				'de_DE' => Phone::PATTERN_DE,
80
+				'fr_FR' => Phone::PATTERN_FR,
81
+				'en_UK' => Phone::PATTERN_UK,
82
+				'en_US' => Phone::PATTERN_US,
83
+			]
84
+		);
85
+		$this->valid_type_options = apply_filters(
86
+			'FHEE__EventEspresso_core_services_form_meta_inputs_Phone__valid_type_options',
87
+			[
88
+				Phone::INPUT_TYPE => esc_html__('Phone Number', 'event_espresso'),
89
+			]
90
+		);
91
+	}
92 92
 
93 93
 
94
-    /**
95
-     * @return array
96
-     */
97
-    public function regexPatterns(): array
98
-    {
99
-        return $this->regex_patterns;
100
-    }
94
+	/**
95
+	 * @return array
96
+	 */
97
+	public function regexPatterns(): array
98
+	{
99
+		return $this->regex_patterns;
100
+	}
101 101
 
102 102
 
103
-    /**
104
-     * @param bool $constants_only
105
-     * @return array
106
-     */
107
-    public function validTypeOptions(bool $constants_only = false): array
108
-    {
109
-        return $constants_only
110
-            ? array_keys($this->valid_type_options)
111
-            : $this->valid_type_options;
112
-    }
103
+	/**
104
+	 * @param bool $constants_only
105
+	 * @return array
106
+	 */
107
+	public function validTypeOptions(bool $constants_only = false): array
108
+	{
109
+		return $constants_only
110
+			? array_keys($this->valid_type_options)
111
+			: $this->valid_type_options;
112
+	}
113 113
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@
 block discarded – undo
73 73
      */
74 74
     public function __construct()
75 75
     {
76
-        $this->regex_patterns     = (array) apply_filters(
76
+        $this->regex_patterns = (array) apply_filters(
77 77
             'FHEE__EventEspresso_core_services_form_meta_inputs_Phone__regex_patterns',
78 78
             [
79 79
                 'de_DE' => Phone::PATTERN_DE,
Please login to merge, or discard this patch.