Completed
Branch BUG-10202-persistent-admin-not... (4d71ca)
by
unknown
23:37 queued 11:57
created
core/helpers/EEH_Event_Query.helper.php 2 patches
Indentation   +670 added lines, -670 removed lines patch added patch discarded remove patch
@@ -18,676 +18,676 @@
 block discarded – undo
18 18
 class EEH_Event_Query
19 19
 {
20 20
 
21
-    /**
22
-     * Start Date
23
-     *
24
-     * @var $_event_query_month
25
-     */
26
-    protected static $_event_query_month;
27
-
28
-    /**
29
-     * Category
30
-     *
31
-     * @var $_event_query_category
32
-     */
33
-    protected static $_event_query_category;
34
-
35
-    /**
36
-     * whether to display expired events in the event list
37
-     *
38
-     * @var bool $_show_expired
39
-     */
40
-    protected static $_event_query_show_expired = false;
41
-
42
-    /**
43
-     * list of params for controlling how the query results are ordered
44
-     *
45
-     * @var array $_event_query_orderby
46
-     */
47
-    protected static $_event_query_orderby = array();
48
-
49
-    /**
50
-     * direction list is sorted
51
-     *
52
-     * @var string $_event_query_sort
53
-     */
54
-    protected static $_event_query_sort;
55
-
56
-    /**
57
-     * list of params used to build the query's various clauses
58
-     *
59
-     * @var $_query_params
60
-     */
61
-    protected static $_query_params = array();
62
-
63
-
64
-
65
-    /**
66
-     * @return void
67
-     */
68
-    public static function add_query_filters()
69
-    {
70
-        //add query filters
71
-        add_action('pre_get_posts', array('EEH_Event_Query', 'filter_query_parts'), 10, 1);
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     * @param WP_Query $WP_Query
78
-     * @return bool
79
-     */
80
-    public static function apply_query_filters(WP_Query $WP_Query)
81
-    {
82
-        return (
83
-                   isset($WP_Query->query['post_type'])
84
-                   && $WP_Query->query['post_type'] === 'espresso_events'
85
-               )
86
-               || apply_filters('FHEE__EEH_Event_Query__apply_query_filters', false);
87
-    }
88
-
89
-
90
-    /**
91
-     * @param WP_Query $WP_Query
92
-     */
93
-    public static function filter_query_parts(WP_Query $WP_Query)
94
-    {
95
-        // ONLY add our filters if this isn't the main wp_query,
96
-        // because if this is the main wp_query we already have
97
-        // our cpt strategies take care of adding things in.
98
-        if ($WP_Query instanceof WP_Query && ! $WP_Query->is_main_query()) {
99
-            // build event list query
100
-            add_filter('posts_fields', array('EEH_Event_Query', 'posts_fields'), 10, 2);
101
-            add_filter('posts_join', array('EEH_Event_Query', 'posts_join'), 10, 2);
102
-            add_filter('posts_where', array('EEH_Event_Query', 'posts_where'), 10, 2);
103
-            add_filter('posts_orderby', array('EEH_Event_Query', 'posts_orderby'), 10, 2);
104
-            add_filter('posts_clauses_request', array('EEH_Event_Query', 'posts_clauses'), 10, 2);
105
-        }
106
-    }
107
-
108
-
109
-
110
-    /**
111
-     * @param string $month
112
-     * @param string $category
113
-     * @param bool   $show_expired
114
-     * @param string $orderby
115
-     * @param string $sort
116
-     * @throws InvalidArgumentException
117
-     * @throws InvalidDataTypeException
118
-     * @throws InvalidInterfaceException
119
-     */
120
-    public static function set_query_params(
121
-        $month = '',
122
-        $category = '',
123
-        $show_expired = false,
124
-        $orderby = 'start_date',
125
-        $sort = 'ASC'
126
-    ) {
127
-        self::$_query_params                        = array();
128
-        EEH_Event_Query::$_event_query_month        = EEH_Event_Query::_display_month($month);
129
-        EEH_Event_Query::$_event_query_category     = EEH_Event_Query::_event_category_slug($category);
130
-        EEH_Event_Query::$_event_query_show_expired = EEH_Event_Query::_show_expired($show_expired);
131
-        EEH_Event_Query::$_event_query_orderby      = EEH_Event_Query::_orderby($orderby);
132
-        EEH_Event_Query::$_event_query_sort         = EEH_Event_Query::_sort($sort);
133
-    }
134
-
135
-
136
-
137
-    /**
138
-     * what month should the event list display events for?
139
-     *
140
-     * @param string $month
141
-     * @return string
142
-     * @throws InvalidArgumentException
143
-     * @throws InvalidDataTypeException
144
-     * @throws InvalidInterfaceException
145
-     */
146
-    private static function _display_month($month = '')
147
-    {
148
-        return sanitize_text_field(EE_Registry::instance()->REQ->get('event_query_month', $month));
149
-    }
150
-
151
-
152
-
153
-    /**
154
-     * @param string $category
155
-     * @return string
156
-     * @throws InvalidArgumentException
157
-     * @throws InvalidDataTypeException
158
-     * @throws InvalidInterfaceException
159
-     */
160
-    private static function _event_category_slug($category = '')
161
-    {
162
-        return sanitize_title_with_dashes(EE_Registry::instance()->REQ->get('event_query_category', $category));
163
-    }
164
-
165
-
166
-
167
-    /**
168
-     * @param bool $show_expired
169
-     * @return bool
170
-     * @throws InvalidArgumentException
171
-     * @throws InvalidDataTypeException
172
-     * @throws InvalidInterfaceException
173
-     */
174
-    private static function _show_expired($show_expired = false)
175
-    {
176
-        // override default expired option if set via filter
177
-        return filter_var(
178
-            EE_Registry::instance()->REQ->get('event_query_show_expired', $show_expired),
179
-            FILTER_VALIDATE_BOOLEAN
180
-        );
181
-    }
182
-
183
-
184
-
185
-    /**
186
-     * @param    string $orderby
187
-     * @return array
188
-     * @throws InvalidArgumentException
189
-     * @throws InvalidDataTypeException
190
-     * @throws InvalidInterfaceException
191
-     */
192
-    private static function _orderby($orderby = 'start_date')
193
-    {
194
-        $event_query_orderby = EE_Registry::instance()->REQ->get('event_query_orderby', $orderby);
195
-        $event_query_orderby = is_array($event_query_orderby)
196
-            ? $event_query_orderby
197
-            : explode(',', $event_query_orderby);
198
-        $event_query_orderby = array_map('trim', $event_query_orderby);
199
-        $event_query_orderby = array_map('sanitize_text_field', $event_query_orderby);
200
-        return $event_query_orderby;
201
-    }
202
-
203
-
204
-
205
-    /**
206
-     * @param string $sort
207
-     * @return string
208
-     * @throws InvalidArgumentException
209
-     * @throws InvalidDataTypeException
210
-     * @throws InvalidInterfaceException
211
-     */
212
-    private static function _sort($sort = 'ASC')
213
-    {
214
-        $sort = EE_Registry::instance()->REQ->get('event_query_sort', $sort);
215
-        return in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true)
216
-            ? strtoupper($sort)
217
-            : 'ASC';
218
-    }
219
-
220
-
221
-
222
-    /**
223
-     * Filters the clauses for the WP_Query object
224
-     *
225
-     * @param array    $clauses array of clauses
226
-     * @param WP_Query $wp_query
227
-     * @return array   array of clauses
228
-     */
229
-    public static function posts_clauses($clauses, WP_Query $wp_query)
230
-    {
231
-        if (EEH_Event_Query::apply_query_filters($wp_query)) {
232
-            global $wpdb;
233
-            $clauses['groupby'] = $wpdb->posts . '.ID ';
234
-        }
235
-        return $clauses;
236
-    }
237
-
238
-
239
-
240
-    /**
241
-     * @param string   $SQL
242
-     * @param WP_Query $wp_query
243
-     * @return string
244
-     * @throws EE_Error
245
-     * @throws InvalidArgumentException
246
-     * @throws InvalidDataTypeException
247
-     * @throws InvalidInterfaceException
248
-     */
249
-    public static function posts_fields($SQL, WP_Query $wp_query)
250
-    {
251
-        if (EEH_Event_Query::apply_query_filters($wp_query)) {
252
-            // adds something like ", wp_esp_datetime.* " to WP Query SELECT statement
253
-            $SQL .= EEH_Event_Query::posts_fields_sql_for_orderby(EEH_Event_Query::$_event_query_orderby);
254
-        }
255
-        return $SQL;
256
-    }
257
-
258
-
259
-
260
-    /**
261
-     * @param array $orderby_params
262
-     * @return string
263
-     * @throws EE_Error
264
-     * @throws InvalidArgumentException
265
-     * @throws InvalidDataTypeException
266
-     * @throws InvalidInterfaceException
267
-     */
268
-    public static function posts_fields_sql_for_orderby(array $orderby_params = array())
269
-    {
270
-        $SQL = ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ';
271
-        foreach ($orderby_params as $orderby) {
272
-            switch ($orderby) {
273
-
274
-                case 'ticket_start' :
275
-                    $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_start_date';
276
-                    break;
277
-                case 'ticket_end' :
278
-                    $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_end_date';
279
-                    break;
280
-                case 'venue_title' :
281
-                    $SQL .= ', Venue.post_title AS venue_title';
282
-                    break;
283
-                case 'city' :
284
-                    $SQL .= ', ' . EEM_Venue::instance()->second_table() . '.VNU_city';
285
-                    break;
286
-                case 'state' :
287
-                    $SQL .= ', ' . EEM_State::instance()->table() . '.STA_name';
288
-                    break;
289
-            }
290
-        }
291
-        return $SQL;
292
-    }
293
-
294
-
295
-
296
-    /**
297
-     * @param string   $SQL
298
-     * @param WP_Query $wp_query
299
-     * @return string
300
-     * @throws EE_Error
301
-     * @throws InvalidArgumentException
302
-     * @throws InvalidDataTypeException
303
-     * @throws InvalidInterfaceException
304
-     */
305
-    public static function posts_join($SQL = '', WP_Query $wp_query)
306
-    {
307
-        if (EEH_Event_Query::apply_query_filters($wp_query)) {
308
-            // Category
309
-            $SQL = EEH_Event_Query::posts_join_sql_for_show_expired($SQL, EEH_Event_Query::$_event_query_show_expired);
310
-            $SQL = EEH_Event_Query::posts_join_sql_for_terms($SQL, EEH_Event_Query::$_event_query_category);
311
-            $SQL = EEH_Event_Query::posts_join_for_orderby($SQL, EEH_Event_Query::$_event_query_orderby);
312
-        }
313
-        return $SQL;
314
-    }
315
-
316
-
317
-
318
-    /**
319
-     * @param string  $SQL
320
-     * @param boolean $show_expired if TRUE, then displayed past events
321
-     * @return string
322
-     * @throws EE_Error
323
-     * @throws InvalidArgumentException
324
-     * @throws InvalidDataTypeException
325
-     * @throws InvalidInterfaceException
326
-     */
327
-    public static function posts_join_sql_for_show_expired($SQL = '', $show_expired = false)
328
-    {
329
-        if (! $show_expired) {
330
-            $join = EEM_Event::instance()->table() . '.ID = ';
331
-            $join .= EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name();
332
-            // don't add if this is already in the SQL
333
-            if (strpos($SQL, $join) === false) {
334
-                $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' ) ';
335
-            }
336
-        }
337
-        return $SQL;
338
-    }
339
-
340
-
341
-
342
-    /**
343
-     * @param string $SQL
344
-     * @param string $join_terms    pass TRUE or term string, doesn't really matter since this value doesn't really get
345
-     *                              used for anything yet
346
-     * @return string
347
-     */
348
-    public static function posts_join_sql_for_terms($SQL = '', $join_terms = '')
349
-    {
350
-        if (! empty($join_terms)) {
351
-            global $wpdb;
352
-            $SQL .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)";
353
-            $SQL .= " LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)";
354
-            $SQL .= " LEFT JOIN $wpdb->terms ON ($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id) ";
355
-        }
356
-        return $SQL;
357
-    }
358
-
359
-
360
-
361
-    /**
362
-     * usage:  $SQL .= EEH_Event_Query::posts_join_for_orderby( $orderby_params );
363
-     *
364
-     * @param    string $SQL
365
-     * @param    array  $orderby_params
366
-     * @return string
367
-     * @throws EE_Error
368
-     * @throws InvalidArgumentException
369
-     * @throws InvalidDataTypeException
370
-     * @throws InvalidInterfaceException
371
-     */
372
-    public static function posts_join_for_orderby($SQL = '', array $orderby_params = array())
373
-    {
374
-        foreach ($orderby_params as $orderby) {
375
-            switch ($orderby) {
376
-                case 'ticket_start' :
377
-                case 'ticket_end' :
378
-                    $SQL .= EEH_Event_Query::_posts_join_for_datetime(
379
-                        $SQL,
380
-                        EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name()
381
-                    );
382
-                    $SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table();
383
-                    $SQL .= ' ON (';
384
-                    $SQL .= EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name();
385
-                    $SQL .= ' = ';
386
-                    $SQL .= EEM_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name();
387
-                    $SQL .= ' )';
388
-                    break;
389
-                case 'venue_title' :
390
-                case 'city' :
391
-                    $SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL);
392
-                    break;
393
-                case 'state' :
394
-                    $SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL);
395
-                    $SQL .= EEH_Event_Query::_posts_join_for_venue_state($SQL);
396
-                    break;
397
-                case 'start_date' :
398
-                default :
399
-                    $SQL .= EEH_Event_Query::_posts_join_for_datetime($SQL, EEM_Event::instance()->table() . '.ID');
400
-                    break;
401
-            }
402
-        }
403
-        return $SQL;
404
-    }
405
-
406
-
407
-
408
-    /**
409
-     * @param string $SQL
410
-     * @param string $join
411
-     * @return string
412
-     * @throws EE_Error
413
-     * @throws InvalidArgumentException
414
-     * @throws InvalidDataTypeException
415
-     * @throws InvalidInterfaceException
416
-     */
417
-    protected static function _posts_join_for_datetime($SQL = '', $join = '')
418
-    {
419
-        if (! empty($join)) {
420
-            $join .= ' = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name();
421
-            if (strpos($SQL, $join) === false) {
422
-                return ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' )';
423
-            }
424
-        }
425
-        return '';
426
-    }
427
-
428
-
429
-
430
-    /**
431
-     * @param string $SQL
432
-     * @return string
433
-     * @throws EE_Error
434
-     * @throws InvalidArgumentException
435
-     * @throws InvalidDataTypeException
436
-     * @throws InvalidInterfaceException
437
-     */
438
-    protected static function _posts_join_for_event_venue($SQL = '')
439
-    {
440
-        // Event Venue table name
441
-        $event_venue_table = EEM_Event_Venue::instance()->table();
442
-        // generate conditions for:  Event <=> Event Venue  JOIN clause
443
-        $event_to_event_venue_join = EEM_Event::instance()->table() . '.ID = ';
444
-        $event_to_event_venue_join .= $event_venue_table . '.' . EEM_Event::instance()->primary_key_name();
445
-        // don't add joins if they have already been added
446
-        if (strpos($SQL, $event_to_event_venue_join) === false) {
447
-            // Venue table name
448
-            $venue_table = EEM_Venue::instance()->table();
449
-            // Venue table pk
450
-            $venue_table_pk = EEM_Venue::instance()->primary_key_name();
451
-            // Venue Meta table name
452
-            $venue_meta_table = EEM_Venue::instance()->second_table();
453
-            // generate JOIN clause for: Event <=> Event Venue
454
-            $venue_SQL = " LEFT JOIN $event_venue_table ON ( $event_to_event_venue_join )";
455
-            // generate JOIN clause for: Event Venue <=> Venue
456
-            $venue_SQL .= " LEFT JOIN $venue_table as Venue ON ( $event_venue_table.$venue_table_pk = Venue.ID )";
457
-            // generate JOIN clause for: Venue <=> Venue Meta
458
-            $venue_SQL .= " LEFT JOIN $venue_meta_table ON ( Venue.ID = $venue_meta_table.$venue_table_pk )";
459
-            unset($event_venue_table, $event_to_event_venue_join, $venue_table, $venue_table_pk, $venue_meta_table);
460
-            return $venue_SQL;
461
-        }
462
-        unset($event_venue_table, $event_to_event_venue_join);
463
-        return '';
464
-    }
465
-
466
-
467
-
468
-    /**
469
-     * @param string $SQL
470
-     * @return string
471
-     * @throws EE_Error
472
-     * @throws InvalidArgumentException
473
-     * @throws InvalidDataTypeException
474
-     * @throws InvalidInterfaceException
475
-     */
476
-    protected static function _posts_join_for_venue_state($SQL = '')
477
-    {
478
-        // Venue Meta table name
479
-        $venue_meta_table = EEM_Venue::instance()->second_table();
480
-        // State table name
481
-        $state_table = EEM_State::instance()->table();
482
-        // State table pk
483
-        $state_table_pk = EEM_State::instance()->primary_key_name();
484
-        // verify vars
485
-        if ($venue_meta_table && $state_table && $state_table_pk) {
486
-            // like: wp_esp_venue_meta.STA_ID = wp_esp_state.STA_ID
487
-            $join = "$venue_meta_table.$state_table_pk = $state_table.$state_table_pk";
488
-            // don't add join if it has already been added
489
-            if (strpos($SQL, $join) === false) {
490
-                unset($state_table_pk, $venue_meta_table, $venue_table_pk);
491
-                return " LEFT JOIN $state_table ON ( $join )";
492
-            }
493
-        }
494
-        unset($join, $state_table, $state_table_pk, $venue_meta_table, $venue_table_pk);
495
-        return '';
496
-    }
497
-
498
-
499
-
500
-    /**
501
-     * @param string   $SQL
502
-     * @param WP_Query $wp_query
503
-     * @return string
504
-     * @throws EE_Error
505
-     * @throws InvalidArgumentException
506
-     * @throws InvalidDataTypeException
507
-     * @throws InvalidInterfaceException
508
-     */
509
-    public static function posts_where($SQL = '', WP_Query $wp_query)
510
-    {
511
-        if (EEH_Event_Query::apply_query_filters($wp_query)) {
512
-            // Show Expired ?
513
-            $SQL .= EEH_Event_Query::posts_where_sql_for_show_expired(EEH_Event_Query::$_event_query_show_expired);
514
-            // Category
515
-            $SQL .= EEH_Event_Query::posts_where_sql_for_event_category_slug(EEH_Event_Query::$_event_query_category);
516
-            // Start Date
517
-            $SQL .= EEH_Event_Query::posts_where_sql_for_event_list_month(EEH_Event_Query::$_event_query_month);
518
-        }
519
-        return $SQL;
520
-    }
521
-
522
-
523
-
524
-    /**
525
-     * @param    boolean $show_expired if TRUE, then displayed past events
526
-     * @return string
527
-     * @throws EE_Error
528
-     * @throws InvalidArgumentException
529
-     * @throws InvalidDataTypeException
530
-     * @throws InvalidInterfaceException
531
-     */
532
-    public static function posts_where_sql_for_show_expired($show_expired = false)
533
-    {
534
-        return ! $show_expired
535
-            ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time('mysql', true) . '\' '
536
-            : '';
537
-    }
538
-
539
-
540
-
541
-    /**
542
-     * @param boolean $event_category_slug
543
-     * @return string
544
-     */
545
-    public static function posts_where_sql_for_event_category_slug($event_category_slug = null)
546
-    {
547
-        global $wpdb;
548
-        return ! empty($event_category_slug)
549
-            ? $wpdb->prepare(" AND {$wpdb->terms}.slug = %s ", $event_category_slug)
550
-            : '';
551
-    }
552
-
553
-
554
-
555
-    /**
556
-     * @param boolean $month
557
-     * @return string
558
-     * @throws EE_Error
559
-     * @throws InvalidArgumentException
560
-     * @throws InvalidDataTypeException
561
-     * @throws InvalidInterfaceException
562
-     */
563
-    public static function posts_where_sql_for_event_list_month($month = null)
564
-    {
565
-        $SQL = '';
566
-        if (! empty($month)) {
567
-            $datetime_table = EEM_Datetime::instance()->table();
568
-            // event start date is LESS than the end of the month ( so nothing that doesn't start until next month )
569
-            $SQL = " AND {$datetime_table}.DTT_EVT_start <= '";
570
-            $SQL .= date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "'";
571
-            // event end date is GREATER than the start of the month ( so nothing that ended before this month )
572
-            $SQL .= " AND {$datetime_table}.DTT_EVT_end >= '";
573
-            $SQL .= date('Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "' ";
574
-        }
575
-        return $SQL;
576
-    }
577
-
578
-
579
-
580
-    /**
581
-     * @param string $SQL
582
-     * @param WP_Query $wp_query
583
-     * @return string
584
-     * @throws EE_Error
585
-     * @throws InvalidArgumentException
586
-     * @throws InvalidDataTypeException
587
-     * @throws InvalidInterfaceException
588
-     */
589
-    public static function posts_orderby($SQL = '', WP_Query $wp_query)
590
-    {
591
-        if (EEH_Event_Query::apply_query_filters($wp_query)) {
592
-            $SQL = EEH_Event_Query::posts_orderby_sql(
593
-                EEH_Event_Query::$_event_query_orderby,
594
-                EEH_Event_Query::$_event_query_sort
595
-            );
596
-        }
597
-        return $SQL;
598
-    }
599
-
600
-
601
-
602
-    /**
603
-     *    posts_orderby_sql
604
-     *    possible parameters:
605
-     *    ID
606
-     *    start_date
607
-     *    end_date
608
-     *    event_name
609
-     *    category_slug
610
-     *    ticket_start
611
-     *    ticket_end
612
-     *    venue_title
613
-     *    city
614
-     *    state
615
-     *    **IMPORTANT**
616
-     *    make sure to also send the $orderby_params array to the posts_join_for_orderby() method
617
-     *    or else some of the table references below will result in MySQL errors
618
-     *
619
-     * @param array  $orderby_params
620
-     * @param string $sort
621
-     * @return string
622
-     * @throws EE_Error
623
-     * @throws InvalidArgumentException
624
-     * @throws InvalidDataTypeException
625
-     * @throws InvalidInterfaceException
626
-     */
627
-    public static function posts_orderby_sql(array $orderby_params = array(), $sort = 'ASC')
628
-    {
629
-        global $wpdb;
630
-        $SQL     = '';
631
-        $counter = 0;
632
-        $sort    = in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true)
633
-            ? strtoupper($sort)
634
-            : 'ASC';
635
-        //make sure 'orderby' is set in query params
636
-        if (! isset(self::$_query_params['orderby'])) {
637
-            self::$_query_params['orderby'] = array();
638
-        }
639
-        // loop thru $orderby_params (type cast as array)
640
-        foreach ($orderby_params as $orderby) {
641
-            // check if we have already added this param
642
-            if (isset(self::$_query_params['orderby'][ $orderby ])) {
643
-                // if so then remove from the $orderby_params so that the count() method below is accurate
644
-                unset($orderby_params[ $orderby ]);
645
-                // then bump ahead to the next param
646
-                continue;
647
-            }
648
-            // this will ad a comma depending on whether this is the first or last param
649
-            $glue = $counter === 0 || $counter === count($orderby_params) ? ' ' : ', ';
650
-            // ok what's we dealing with?
651
-            switch ($orderby) {
652
-                case 'id' :
653
-                case 'ID' :
654
-                    $SQL .= $glue . $wpdb->posts . '.ID ' . $sort;
655
-                    break;
656
-                case 'end_date' :
657
-                    $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort;
658
-                    break;
659
-                case 'event_name' :
660
-                    $SQL .= $glue . $wpdb->posts . '.post_title ' . $sort;
661
-                    break;
662
-                case 'category_slug' :
663
-                    $SQL .= $glue . $wpdb->terms . '.slug ' . $sort;
664
-                    break;
665
-                case 'ticket_start' :
666
-                    $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort;
667
-                    break;
668
-                case 'ticket_end' :
669
-                    $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort;
670
-                    break;
671
-                case 'venue_title' :
672
-                    $SQL .= $glue . 'venue_title ' . $sort;
673
-                    break;
674
-                case 'city' :
675
-                    $SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort;
676
-                    break;
677
-                case 'state' :
678
-                    $SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort;
679
-                    break;
680
-                case 'start_date' :
681
-                default :
682
-                    $SQL .= $glue . ' event_start_date ' . $sort;
683
-                    break;
684
-            }
685
-            // add to array of orderby params that have been added
686
-            self::$_query_params['orderby'][ $orderby ] = true;
687
-            $counter++;
688
-        }
689
-        return $SQL;
690
-    }
21
+	/**
22
+	 * Start Date
23
+	 *
24
+	 * @var $_event_query_month
25
+	 */
26
+	protected static $_event_query_month;
27
+
28
+	/**
29
+	 * Category
30
+	 *
31
+	 * @var $_event_query_category
32
+	 */
33
+	protected static $_event_query_category;
34
+
35
+	/**
36
+	 * whether to display expired events in the event list
37
+	 *
38
+	 * @var bool $_show_expired
39
+	 */
40
+	protected static $_event_query_show_expired = false;
41
+
42
+	/**
43
+	 * list of params for controlling how the query results are ordered
44
+	 *
45
+	 * @var array $_event_query_orderby
46
+	 */
47
+	protected static $_event_query_orderby = array();
48
+
49
+	/**
50
+	 * direction list is sorted
51
+	 *
52
+	 * @var string $_event_query_sort
53
+	 */
54
+	protected static $_event_query_sort;
55
+
56
+	/**
57
+	 * list of params used to build the query's various clauses
58
+	 *
59
+	 * @var $_query_params
60
+	 */
61
+	protected static $_query_params = array();
62
+
63
+
64
+
65
+	/**
66
+	 * @return void
67
+	 */
68
+	public static function add_query_filters()
69
+	{
70
+		//add query filters
71
+		add_action('pre_get_posts', array('EEH_Event_Query', 'filter_query_parts'), 10, 1);
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 * @param WP_Query $WP_Query
78
+	 * @return bool
79
+	 */
80
+	public static function apply_query_filters(WP_Query $WP_Query)
81
+	{
82
+		return (
83
+				   isset($WP_Query->query['post_type'])
84
+				   && $WP_Query->query['post_type'] === 'espresso_events'
85
+			   )
86
+			   || apply_filters('FHEE__EEH_Event_Query__apply_query_filters', false);
87
+	}
88
+
89
+
90
+	/**
91
+	 * @param WP_Query $WP_Query
92
+	 */
93
+	public static function filter_query_parts(WP_Query $WP_Query)
94
+	{
95
+		// ONLY add our filters if this isn't the main wp_query,
96
+		// because if this is the main wp_query we already have
97
+		// our cpt strategies take care of adding things in.
98
+		if ($WP_Query instanceof WP_Query && ! $WP_Query->is_main_query()) {
99
+			// build event list query
100
+			add_filter('posts_fields', array('EEH_Event_Query', 'posts_fields'), 10, 2);
101
+			add_filter('posts_join', array('EEH_Event_Query', 'posts_join'), 10, 2);
102
+			add_filter('posts_where', array('EEH_Event_Query', 'posts_where'), 10, 2);
103
+			add_filter('posts_orderby', array('EEH_Event_Query', 'posts_orderby'), 10, 2);
104
+			add_filter('posts_clauses_request', array('EEH_Event_Query', 'posts_clauses'), 10, 2);
105
+		}
106
+	}
107
+
108
+
109
+
110
+	/**
111
+	 * @param string $month
112
+	 * @param string $category
113
+	 * @param bool   $show_expired
114
+	 * @param string $orderby
115
+	 * @param string $sort
116
+	 * @throws InvalidArgumentException
117
+	 * @throws InvalidDataTypeException
118
+	 * @throws InvalidInterfaceException
119
+	 */
120
+	public static function set_query_params(
121
+		$month = '',
122
+		$category = '',
123
+		$show_expired = false,
124
+		$orderby = 'start_date',
125
+		$sort = 'ASC'
126
+	) {
127
+		self::$_query_params                        = array();
128
+		EEH_Event_Query::$_event_query_month        = EEH_Event_Query::_display_month($month);
129
+		EEH_Event_Query::$_event_query_category     = EEH_Event_Query::_event_category_slug($category);
130
+		EEH_Event_Query::$_event_query_show_expired = EEH_Event_Query::_show_expired($show_expired);
131
+		EEH_Event_Query::$_event_query_orderby      = EEH_Event_Query::_orderby($orderby);
132
+		EEH_Event_Query::$_event_query_sort         = EEH_Event_Query::_sort($sort);
133
+	}
134
+
135
+
136
+
137
+	/**
138
+	 * what month should the event list display events for?
139
+	 *
140
+	 * @param string $month
141
+	 * @return string
142
+	 * @throws InvalidArgumentException
143
+	 * @throws InvalidDataTypeException
144
+	 * @throws InvalidInterfaceException
145
+	 */
146
+	private static function _display_month($month = '')
147
+	{
148
+		return sanitize_text_field(EE_Registry::instance()->REQ->get('event_query_month', $month));
149
+	}
150
+
151
+
152
+
153
+	/**
154
+	 * @param string $category
155
+	 * @return string
156
+	 * @throws InvalidArgumentException
157
+	 * @throws InvalidDataTypeException
158
+	 * @throws InvalidInterfaceException
159
+	 */
160
+	private static function _event_category_slug($category = '')
161
+	{
162
+		return sanitize_title_with_dashes(EE_Registry::instance()->REQ->get('event_query_category', $category));
163
+	}
164
+
165
+
166
+
167
+	/**
168
+	 * @param bool $show_expired
169
+	 * @return bool
170
+	 * @throws InvalidArgumentException
171
+	 * @throws InvalidDataTypeException
172
+	 * @throws InvalidInterfaceException
173
+	 */
174
+	private static function _show_expired($show_expired = false)
175
+	{
176
+		// override default expired option if set via filter
177
+		return filter_var(
178
+			EE_Registry::instance()->REQ->get('event_query_show_expired', $show_expired),
179
+			FILTER_VALIDATE_BOOLEAN
180
+		);
181
+	}
182
+
183
+
184
+
185
+	/**
186
+	 * @param    string $orderby
187
+	 * @return array
188
+	 * @throws InvalidArgumentException
189
+	 * @throws InvalidDataTypeException
190
+	 * @throws InvalidInterfaceException
191
+	 */
192
+	private static function _orderby($orderby = 'start_date')
193
+	{
194
+		$event_query_orderby = EE_Registry::instance()->REQ->get('event_query_orderby', $orderby);
195
+		$event_query_orderby = is_array($event_query_orderby)
196
+			? $event_query_orderby
197
+			: explode(',', $event_query_orderby);
198
+		$event_query_orderby = array_map('trim', $event_query_orderby);
199
+		$event_query_orderby = array_map('sanitize_text_field', $event_query_orderby);
200
+		return $event_query_orderby;
201
+	}
202
+
203
+
204
+
205
+	/**
206
+	 * @param string $sort
207
+	 * @return string
208
+	 * @throws InvalidArgumentException
209
+	 * @throws InvalidDataTypeException
210
+	 * @throws InvalidInterfaceException
211
+	 */
212
+	private static function _sort($sort = 'ASC')
213
+	{
214
+		$sort = EE_Registry::instance()->REQ->get('event_query_sort', $sort);
215
+		return in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true)
216
+			? strtoupper($sort)
217
+			: 'ASC';
218
+	}
219
+
220
+
221
+
222
+	/**
223
+	 * Filters the clauses for the WP_Query object
224
+	 *
225
+	 * @param array    $clauses array of clauses
226
+	 * @param WP_Query $wp_query
227
+	 * @return array   array of clauses
228
+	 */
229
+	public static function posts_clauses($clauses, WP_Query $wp_query)
230
+	{
231
+		if (EEH_Event_Query::apply_query_filters($wp_query)) {
232
+			global $wpdb;
233
+			$clauses['groupby'] = $wpdb->posts . '.ID ';
234
+		}
235
+		return $clauses;
236
+	}
237
+
238
+
239
+
240
+	/**
241
+	 * @param string   $SQL
242
+	 * @param WP_Query $wp_query
243
+	 * @return string
244
+	 * @throws EE_Error
245
+	 * @throws InvalidArgumentException
246
+	 * @throws InvalidDataTypeException
247
+	 * @throws InvalidInterfaceException
248
+	 */
249
+	public static function posts_fields($SQL, WP_Query $wp_query)
250
+	{
251
+		if (EEH_Event_Query::apply_query_filters($wp_query)) {
252
+			// adds something like ", wp_esp_datetime.* " to WP Query SELECT statement
253
+			$SQL .= EEH_Event_Query::posts_fields_sql_for_orderby(EEH_Event_Query::$_event_query_orderby);
254
+		}
255
+		return $SQL;
256
+	}
257
+
258
+
259
+
260
+	/**
261
+	 * @param array $orderby_params
262
+	 * @return string
263
+	 * @throws EE_Error
264
+	 * @throws InvalidArgumentException
265
+	 * @throws InvalidDataTypeException
266
+	 * @throws InvalidInterfaceException
267
+	 */
268
+	public static function posts_fields_sql_for_orderby(array $orderby_params = array())
269
+	{
270
+		$SQL = ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ';
271
+		foreach ($orderby_params as $orderby) {
272
+			switch ($orderby) {
273
+
274
+				case 'ticket_start' :
275
+					$SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_start_date';
276
+					break;
277
+				case 'ticket_end' :
278
+					$SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_end_date';
279
+					break;
280
+				case 'venue_title' :
281
+					$SQL .= ', Venue.post_title AS venue_title';
282
+					break;
283
+				case 'city' :
284
+					$SQL .= ', ' . EEM_Venue::instance()->second_table() . '.VNU_city';
285
+					break;
286
+				case 'state' :
287
+					$SQL .= ', ' . EEM_State::instance()->table() . '.STA_name';
288
+					break;
289
+			}
290
+		}
291
+		return $SQL;
292
+	}
293
+
294
+
295
+
296
+	/**
297
+	 * @param string   $SQL
298
+	 * @param WP_Query $wp_query
299
+	 * @return string
300
+	 * @throws EE_Error
301
+	 * @throws InvalidArgumentException
302
+	 * @throws InvalidDataTypeException
303
+	 * @throws InvalidInterfaceException
304
+	 */
305
+	public static function posts_join($SQL = '', WP_Query $wp_query)
306
+	{
307
+		if (EEH_Event_Query::apply_query_filters($wp_query)) {
308
+			// Category
309
+			$SQL = EEH_Event_Query::posts_join_sql_for_show_expired($SQL, EEH_Event_Query::$_event_query_show_expired);
310
+			$SQL = EEH_Event_Query::posts_join_sql_for_terms($SQL, EEH_Event_Query::$_event_query_category);
311
+			$SQL = EEH_Event_Query::posts_join_for_orderby($SQL, EEH_Event_Query::$_event_query_orderby);
312
+		}
313
+		return $SQL;
314
+	}
315
+
316
+
317
+
318
+	/**
319
+	 * @param string  $SQL
320
+	 * @param boolean $show_expired if TRUE, then displayed past events
321
+	 * @return string
322
+	 * @throws EE_Error
323
+	 * @throws InvalidArgumentException
324
+	 * @throws InvalidDataTypeException
325
+	 * @throws InvalidInterfaceException
326
+	 */
327
+	public static function posts_join_sql_for_show_expired($SQL = '', $show_expired = false)
328
+	{
329
+		if (! $show_expired) {
330
+			$join = EEM_Event::instance()->table() . '.ID = ';
331
+			$join .= EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name();
332
+			// don't add if this is already in the SQL
333
+			if (strpos($SQL, $join) === false) {
334
+				$SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' ) ';
335
+			}
336
+		}
337
+		return $SQL;
338
+	}
339
+
340
+
341
+
342
+	/**
343
+	 * @param string $SQL
344
+	 * @param string $join_terms    pass TRUE or term string, doesn't really matter since this value doesn't really get
345
+	 *                              used for anything yet
346
+	 * @return string
347
+	 */
348
+	public static function posts_join_sql_for_terms($SQL = '', $join_terms = '')
349
+	{
350
+		if (! empty($join_terms)) {
351
+			global $wpdb;
352
+			$SQL .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)";
353
+			$SQL .= " LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)";
354
+			$SQL .= " LEFT JOIN $wpdb->terms ON ($wpdb->terms.term_id = $wpdb->term_taxonomy.term_id) ";
355
+		}
356
+		return $SQL;
357
+	}
358
+
359
+
360
+
361
+	/**
362
+	 * usage:  $SQL .= EEH_Event_Query::posts_join_for_orderby( $orderby_params );
363
+	 *
364
+	 * @param    string $SQL
365
+	 * @param    array  $orderby_params
366
+	 * @return string
367
+	 * @throws EE_Error
368
+	 * @throws InvalidArgumentException
369
+	 * @throws InvalidDataTypeException
370
+	 * @throws InvalidInterfaceException
371
+	 */
372
+	public static function posts_join_for_orderby($SQL = '', array $orderby_params = array())
373
+	{
374
+		foreach ($orderby_params as $orderby) {
375
+			switch ($orderby) {
376
+				case 'ticket_start' :
377
+				case 'ticket_end' :
378
+					$SQL .= EEH_Event_Query::_posts_join_for_datetime(
379
+						$SQL,
380
+						EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name()
381
+					);
382
+					$SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table();
383
+					$SQL .= ' ON (';
384
+					$SQL .= EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name();
385
+					$SQL .= ' = ';
386
+					$SQL .= EEM_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name();
387
+					$SQL .= ' )';
388
+					break;
389
+				case 'venue_title' :
390
+				case 'city' :
391
+					$SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL);
392
+					break;
393
+				case 'state' :
394
+					$SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL);
395
+					$SQL .= EEH_Event_Query::_posts_join_for_venue_state($SQL);
396
+					break;
397
+				case 'start_date' :
398
+				default :
399
+					$SQL .= EEH_Event_Query::_posts_join_for_datetime($SQL, EEM_Event::instance()->table() . '.ID');
400
+					break;
401
+			}
402
+		}
403
+		return $SQL;
404
+	}
405
+
406
+
407
+
408
+	/**
409
+	 * @param string $SQL
410
+	 * @param string $join
411
+	 * @return string
412
+	 * @throws EE_Error
413
+	 * @throws InvalidArgumentException
414
+	 * @throws InvalidDataTypeException
415
+	 * @throws InvalidInterfaceException
416
+	 */
417
+	protected static function _posts_join_for_datetime($SQL = '', $join = '')
418
+	{
419
+		if (! empty($join)) {
420
+			$join .= ' = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name();
421
+			if (strpos($SQL, $join) === false) {
422
+				return ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' )';
423
+			}
424
+		}
425
+		return '';
426
+	}
427
+
428
+
429
+
430
+	/**
431
+	 * @param string $SQL
432
+	 * @return string
433
+	 * @throws EE_Error
434
+	 * @throws InvalidArgumentException
435
+	 * @throws InvalidDataTypeException
436
+	 * @throws InvalidInterfaceException
437
+	 */
438
+	protected static function _posts_join_for_event_venue($SQL = '')
439
+	{
440
+		// Event Venue table name
441
+		$event_venue_table = EEM_Event_Venue::instance()->table();
442
+		// generate conditions for:  Event <=> Event Venue  JOIN clause
443
+		$event_to_event_venue_join = EEM_Event::instance()->table() . '.ID = ';
444
+		$event_to_event_venue_join .= $event_venue_table . '.' . EEM_Event::instance()->primary_key_name();
445
+		// don't add joins if they have already been added
446
+		if (strpos($SQL, $event_to_event_venue_join) === false) {
447
+			// Venue table name
448
+			$venue_table = EEM_Venue::instance()->table();
449
+			// Venue table pk
450
+			$venue_table_pk = EEM_Venue::instance()->primary_key_name();
451
+			// Venue Meta table name
452
+			$venue_meta_table = EEM_Venue::instance()->second_table();
453
+			// generate JOIN clause for: Event <=> Event Venue
454
+			$venue_SQL = " LEFT JOIN $event_venue_table ON ( $event_to_event_venue_join )";
455
+			// generate JOIN clause for: Event Venue <=> Venue
456
+			$venue_SQL .= " LEFT JOIN $venue_table as Venue ON ( $event_venue_table.$venue_table_pk = Venue.ID )";
457
+			// generate JOIN clause for: Venue <=> Venue Meta
458
+			$venue_SQL .= " LEFT JOIN $venue_meta_table ON ( Venue.ID = $venue_meta_table.$venue_table_pk )";
459
+			unset($event_venue_table, $event_to_event_venue_join, $venue_table, $venue_table_pk, $venue_meta_table);
460
+			return $venue_SQL;
461
+		}
462
+		unset($event_venue_table, $event_to_event_venue_join);
463
+		return '';
464
+	}
465
+
466
+
467
+
468
+	/**
469
+	 * @param string $SQL
470
+	 * @return string
471
+	 * @throws EE_Error
472
+	 * @throws InvalidArgumentException
473
+	 * @throws InvalidDataTypeException
474
+	 * @throws InvalidInterfaceException
475
+	 */
476
+	protected static function _posts_join_for_venue_state($SQL = '')
477
+	{
478
+		// Venue Meta table name
479
+		$venue_meta_table = EEM_Venue::instance()->second_table();
480
+		// State table name
481
+		$state_table = EEM_State::instance()->table();
482
+		// State table pk
483
+		$state_table_pk = EEM_State::instance()->primary_key_name();
484
+		// verify vars
485
+		if ($venue_meta_table && $state_table && $state_table_pk) {
486
+			// like: wp_esp_venue_meta.STA_ID = wp_esp_state.STA_ID
487
+			$join = "$venue_meta_table.$state_table_pk = $state_table.$state_table_pk";
488
+			// don't add join if it has already been added
489
+			if (strpos($SQL, $join) === false) {
490
+				unset($state_table_pk, $venue_meta_table, $venue_table_pk);
491
+				return " LEFT JOIN $state_table ON ( $join )";
492
+			}
493
+		}
494
+		unset($join, $state_table, $state_table_pk, $venue_meta_table, $venue_table_pk);
495
+		return '';
496
+	}
497
+
498
+
499
+
500
+	/**
501
+	 * @param string   $SQL
502
+	 * @param WP_Query $wp_query
503
+	 * @return string
504
+	 * @throws EE_Error
505
+	 * @throws InvalidArgumentException
506
+	 * @throws InvalidDataTypeException
507
+	 * @throws InvalidInterfaceException
508
+	 */
509
+	public static function posts_where($SQL = '', WP_Query $wp_query)
510
+	{
511
+		if (EEH_Event_Query::apply_query_filters($wp_query)) {
512
+			// Show Expired ?
513
+			$SQL .= EEH_Event_Query::posts_where_sql_for_show_expired(EEH_Event_Query::$_event_query_show_expired);
514
+			// Category
515
+			$SQL .= EEH_Event_Query::posts_where_sql_for_event_category_slug(EEH_Event_Query::$_event_query_category);
516
+			// Start Date
517
+			$SQL .= EEH_Event_Query::posts_where_sql_for_event_list_month(EEH_Event_Query::$_event_query_month);
518
+		}
519
+		return $SQL;
520
+	}
521
+
522
+
523
+
524
+	/**
525
+	 * @param    boolean $show_expired if TRUE, then displayed past events
526
+	 * @return string
527
+	 * @throws EE_Error
528
+	 * @throws InvalidArgumentException
529
+	 * @throws InvalidDataTypeException
530
+	 * @throws InvalidInterfaceException
531
+	 */
532
+	public static function posts_where_sql_for_show_expired($show_expired = false)
533
+	{
534
+		return ! $show_expired
535
+			? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time('mysql', true) . '\' '
536
+			: '';
537
+	}
538
+
539
+
540
+
541
+	/**
542
+	 * @param boolean $event_category_slug
543
+	 * @return string
544
+	 */
545
+	public static function posts_where_sql_for_event_category_slug($event_category_slug = null)
546
+	{
547
+		global $wpdb;
548
+		return ! empty($event_category_slug)
549
+			? $wpdb->prepare(" AND {$wpdb->terms}.slug = %s ", $event_category_slug)
550
+			: '';
551
+	}
552
+
553
+
554
+
555
+	/**
556
+	 * @param boolean $month
557
+	 * @return string
558
+	 * @throws EE_Error
559
+	 * @throws InvalidArgumentException
560
+	 * @throws InvalidDataTypeException
561
+	 * @throws InvalidInterfaceException
562
+	 */
563
+	public static function posts_where_sql_for_event_list_month($month = null)
564
+	{
565
+		$SQL = '';
566
+		if (! empty($month)) {
567
+			$datetime_table = EEM_Datetime::instance()->table();
568
+			// event start date is LESS than the end of the month ( so nothing that doesn't start until next month )
569
+			$SQL = " AND {$datetime_table}.DTT_EVT_start <= '";
570
+			$SQL .= date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "'";
571
+			// event end date is GREATER than the start of the month ( so nothing that ended before this month )
572
+			$SQL .= " AND {$datetime_table}.DTT_EVT_end >= '";
573
+			$SQL .= date('Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "' ";
574
+		}
575
+		return $SQL;
576
+	}
577
+
578
+
579
+
580
+	/**
581
+	 * @param string $SQL
582
+	 * @param WP_Query $wp_query
583
+	 * @return string
584
+	 * @throws EE_Error
585
+	 * @throws InvalidArgumentException
586
+	 * @throws InvalidDataTypeException
587
+	 * @throws InvalidInterfaceException
588
+	 */
589
+	public static function posts_orderby($SQL = '', WP_Query $wp_query)
590
+	{
591
+		if (EEH_Event_Query::apply_query_filters($wp_query)) {
592
+			$SQL = EEH_Event_Query::posts_orderby_sql(
593
+				EEH_Event_Query::$_event_query_orderby,
594
+				EEH_Event_Query::$_event_query_sort
595
+			);
596
+		}
597
+		return $SQL;
598
+	}
599
+
600
+
601
+
602
+	/**
603
+	 *    posts_orderby_sql
604
+	 *    possible parameters:
605
+	 *    ID
606
+	 *    start_date
607
+	 *    end_date
608
+	 *    event_name
609
+	 *    category_slug
610
+	 *    ticket_start
611
+	 *    ticket_end
612
+	 *    venue_title
613
+	 *    city
614
+	 *    state
615
+	 *    **IMPORTANT**
616
+	 *    make sure to also send the $orderby_params array to the posts_join_for_orderby() method
617
+	 *    or else some of the table references below will result in MySQL errors
618
+	 *
619
+	 * @param array  $orderby_params
620
+	 * @param string $sort
621
+	 * @return string
622
+	 * @throws EE_Error
623
+	 * @throws InvalidArgumentException
624
+	 * @throws InvalidDataTypeException
625
+	 * @throws InvalidInterfaceException
626
+	 */
627
+	public static function posts_orderby_sql(array $orderby_params = array(), $sort = 'ASC')
628
+	{
629
+		global $wpdb;
630
+		$SQL     = '';
631
+		$counter = 0;
632
+		$sort    = in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true)
633
+			? strtoupper($sort)
634
+			: 'ASC';
635
+		//make sure 'orderby' is set in query params
636
+		if (! isset(self::$_query_params['orderby'])) {
637
+			self::$_query_params['orderby'] = array();
638
+		}
639
+		// loop thru $orderby_params (type cast as array)
640
+		foreach ($orderby_params as $orderby) {
641
+			// check if we have already added this param
642
+			if (isset(self::$_query_params['orderby'][ $orderby ])) {
643
+				// if so then remove from the $orderby_params so that the count() method below is accurate
644
+				unset($orderby_params[ $orderby ]);
645
+				// then bump ahead to the next param
646
+				continue;
647
+			}
648
+			// this will ad a comma depending on whether this is the first or last param
649
+			$glue = $counter === 0 || $counter === count($orderby_params) ? ' ' : ', ';
650
+			// ok what's we dealing with?
651
+			switch ($orderby) {
652
+				case 'id' :
653
+				case 'ID' :
654
+					$SQL .= $glue . $wpdb->posts . '.ID ' . $sort;
655
+					break;
656
+				case 'end_date' :
657
+					$SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort;
658
+					break;
659
+				case 'event_name' :
660
+					$SQL .= $glue . $wpdb->posts . '.post_title ' . $sort;
661
+					break;
662
+				case 'category_slug' :
663
+					$SQL .= $glue . $wpdb->terms . '.slug ' . $sort;
664
+					break;
665
+				case 'ticket_start' :
666
+					$SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort;
667
+					break;
668
+				case 'ticket_end' :
669
+					$SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort;
670
+					break;
671
+				case 'venue_title' :
672
+					$SQL .= $glue . 'venue_title ' . $sort;
673
+					break;
674
+				case 'city' :
675
+					$SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort;
676
+					break;
677
+				case 'state' :
678
+					$SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort;
679
+					break;
680
+				case 'start_date' :
681
+				default :
682
+					$SQL .= $glue . ' event_start_date ' . $sort;
683
+					break;
684
+			}
685
+			// add to array of orderby params that have been added
686
+			self::$_query_params['orderby'][ $orderby ] = true;
687
+			$counter++;
688
+		}
689
+		return $SQL;
690
+	}
691 691
 
692 692
 
693 693
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
     {
231 231
         if (EEH_Event_Query::apply_query_filters($wp_query)) {
232 232
             global $wpdb;
233
-            $clauses['groupby'] = $wpdb->posts . '.ID ';
233
+            $clauses['groupby'] = $wpdb->posts.'.ID ';
234 234
         }
235 235
         return $clauses;
236 236
     }
@@ -267,24 +267,24 @@  discard block
 block discarded – undo
267 267
      */
268 268
     public static function posts_fields_sql_for_orderby(array $orderby_params = array())
269 269
     {
270
-        $SQL = ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ';
270
+        $SQL = ', MIN( '.EEM_Datetime::instance()->table().'.DTT_EVT_start ) as event_start_date ';
271 271
         foreach ($orderby_params as $orderby) {
272 272
             switch ($orderby) {
273 273
 
274 274
                 case 'ticket_start' :
275
-                    $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_start_date';
275
+                    $SQL .= ', '.EEM_Ticket::instance()->table().'.TKT_start_date';
276 276
                     break;
277 277
                 case 'ticket_end' :
278
-                    $SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_end_date';
278
+                    $SQL .= ', '.EEM_Ticket::instance()->table().'.TKT_end_date';
279 279
                     break;
280 280
                 case 'venue_title' :
281 281
                     $SQL .= ', Venue.post_title AS venue_title';
282 282
                     break;
283 283
                 case 'city' :
284
-                    $SQL .= ', ' . EEM_Venue::instance()->second_table() . '.VNU_city';
284
+                    $SQL .= ', '.EEM_Venue::instance()->second_table().'.VNU_city';
285 285
                     break;
286 286
                 case 'state' :
287
-                    $SQL .= ', ' . EEM_State::instance()->table() . '.STA_name';
287
+                    $SQL .= ', '.EEM_State::instance()->table().'.STA_name';
288 288
                     break;
289 289
             }
290 290
         }
@@ -326,12 +326,12 @@  discard block
 block discarded – undo
326 326
      */
327 327
     public static function posts_join_sql_for_show_expired($SQL = '', $show_expired = false)
328 328
     {
329
-        if (! $show_expired) {
330
-            $join = EEM_Event::instance()->table() . '.ID = ';
331
-            $join .= EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name();
329
+        if ( ! $show_expired) {
330
+            $join = EEM_Event::instance()->table().'.ID = ';
331
+            $join .= EEM_Datetime::instance()->table().'.'.EEM_Event::instance()->primary_key_name();
332 332
             // don't add if this is already in the SQL
333 333
             if (strpos($SQL, $join) === false) {
334
-                $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' ) ';
334
+                $SQL .= ' INNER JOIN '.EEM_Datetime::instance()->table().' ON ( '.$join.' ) ';
335 335
             }
336 336
         }
337 337
         return $SQL;
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
      */
348 348
     public static function posts_join_sql_for_terms($SQL = '', $join_terms = '')
349 349
     {
350
-        if (! empty($join_terms)) {
350
+        if ( ! empty($join_terms)) {
351 351
             global $wpdb;
352 352
             $SQL .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)";
353 353
             $SQL .= " LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)";
@@ -377,13 +377,13 @@  discard block
 block discarded – undo
377 377
                 case 'ticket_end' :
378 378
                     $SQL .= EEH_Event_Query::_posts_join_for_datetime(
379 379
                         $SQL,
380
-                        EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name()
380
+                        EEM_Datetime_Ticket::instance()->table().'.'.EEM_Datetime::instance()->primary_key_name()
381 381
                     );
382
-                    $SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table();
382
+                    $SQL .= ' LEFT JOIN '.EEM_Ticket::instance()->table();
383 383
                     $SQL .= ' ON (';
384
-                    $SQL .= EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name();
384
+                    $SQL .= EEM_Datetime_Ticket::instance()->table().'.'.EEM_Ticket::instance()->primary_key_name();
385 385
                     $SQL .= ' = ';
386
-                    $SQL .= EEM_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name();
386
+                    $SQL .= EEM_Ticket::instance()->table().'.'.EEM_Ticket::instance()->primary_key_name();
387 387
                     $SQL .= ' )';
388 388
                     break;
389 389
                 case 'venue_title' :
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
                     break;
397 397
                 case 'start_date' :
398 398
                 default :
399
-                    $SQL .= EEH_Event_Query::_posts_join_for_datetime($SQL, EEM_Event::instance()->table() . '.ID');
399
+                    $SQL .= EEH_Event_Query::_posts_join_for_datetime($SQL, EEM_Event::instance()->table().'.ID');
400 400
                     break;
401 401
             }
402 402
         }
@@ -416,10 +416,10 @@  discard block
 block discarded – undo
416 416
      */
417 417
     protected static function _posts_join_for_datetime($SQL = '', $join = '')
418 418
     {
419
-        if (! empty($join)) {
420
-            $join .= ' = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name();
419
+        if ( ! empty($join)) {
420
+            $join .= ' = '.EEM_Datetime::instance()->table().'.'.EEM_Event::instance()->primary_key_name();
421 421
             if (strpos($SQL, $join) === false) {
422
-                return ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' )';
422
+                return ' INNER JOIN '.EEM_Datetime::instance()->table().' ON ( '.$join.' )';
423 423
             }
424 424
         }
425 425
         return '';
@@ -440,8 +440,8 @@  discard block
 block discarded – undo
440 440
         // Event Venue table name
441 441
         $event_venue_table = EEM_Event_Venue::instance()->table();
442 442
         // generate conditions for:  Event <=> Event Venue  JOIN clause
443
-        $event_to_event_venue_join = EEM_Event::instance()->table() . '.ID = ';
444
-        $event_to_event_venue_join .= $event_venue_table . '.' . EEM_Event::instance()->primary_key_name();
443
+        $event_to_event_venue_join = EEM_Event::instance()->table().'.ID = ';
444
+        $event_to_event_venue_join .= $event_venue_table.'.'.EEM_Event::instance()->primary_key_name();
445 445
         // don't add joins if they have already been added
446 446
         if (strpos($SQL, $event_to_event_venue_join) === false) {
447 447
             // Venue table name
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
     public static function posts_where_sql_for_show_expired($show_expired = false)
533 533
     {
534 534
         return ! $show_expired
535
-            ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time('mysql', true) . '\' '
535
+            ? ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_end > \''.current_time('mysql', true).'\' '
536 536
             : '';
537 537
     }
538 538
 
@@ -563,14 +563,14 @@  discard block
 block discarded – undo
563 563
     public static function posts_where_sql_for_event_list_month($month = null)
564 564
     {
565 565
         $SQL = '';
566
-        if (! empty($month)) {
566
+        if ( ! empty($month)) {
567 567
             $datetime_table = EEM_Datetime::instance()->table();
568 568
             // event start date is LESS than the end of the month ( so nothing that doesn't start until next month )
569 569
             $SQL = " AND {$datetime_table}.DTT_EVT_start <= '";
570
-            $SQL .= date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "'";
570
+            $SQL .= date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month))."'";
571 571
             // event end date is GREATER than the start of the month ( so nothing that ended before this month )
572 572
             $SQL .= " AND {$datetime_table}.DTT_EVT_end >= '";
573
-            $SQL .= date('Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "' ";
573
+            $SQL .= date('Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month))."' ";
574 574
         }
575 575
         return $SQL;
576 576
     }
@@ -633,15 +633,15 @@  discard block
 block discarded – undo
633 633
             ? strtoupper($sort)
634 634
             : 'ASC';
635 635
         //make sure 'orderby' is set in query params
636
-        if (! isset(self::$_query_params['orderby'])) {
636
+        if ( ! isset(self::$_query_params['orderby'])) {
637 637
             self::$_query_params['orderby'] = array();
638 638
         }
639 639
         // loop thru $orderby_params (type cast as array)
640 640
         foreach ($orderby_params as $orderby) {
641 641
             // check if we have already added this param
642
-            if (isset(self::$_query_params['orderby'][ $orderby ])) {
642
+            if (isset(self::$_query_params['orderby'][$orderby])) {
643 643
                 // if so then remove from the $orderby_params so that the count() method below is accurate
644
-                unset($orderby_params[ $orderby ]);
644
+                unset($orderby_params[$orderby]);
645 645
                 // then bump ahead to the next param
646 646
                 continue;
647 647
             }
@@ -651,39 +651,39 @@  discard block
 block discarded – undo
651 651
             switch ($orderby) {
652 652
                 case 'id' :
653 653
                 case 'ID' :
654
-                    $SQL .= $glue . $wpdb->posts . '.ID ' . $sort;
654
+                    $SQL .= $glue.$wpdb->posts.'.ID '.$sort;
655 655
                     break;
656 656
                 case 'end_date' :
657
-                    $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort;
657
+                    $SQL .= $glue.EEM_Datetime::instance()->table().'.DTT_EVT_end '.$sort;
658 658
                     break;
659 659
                 case 'event_name' :
660
-                    $SQL .= $glue . $wpdb->posts . '.post_title ' . $sort;
660
+                    $SQL .= $glue.$wpdb->posts.'.post_title '.$sort;
661 661
                     break;
662 662
                 case 'category_slug' :
663
-                    $SQL .= $glue . $wpdb->terms . '.slug ' . $sort;
663
+                    $SQL .= $glue.$wpdb->terms.'.slug '.$sort;
664 664
                     break;
665 665
                 case 'ticket_start' :
666
-                    $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort;
666
+                    $SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_start_date '.$sort;
667 667
                     break;
668 668
                 case 'ticket_end' :
669
-                    $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort;
669
+                    $SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_end_date '.$sort;
670 670
                     break;
671 671
                 case 'venue_title' :
672
-                    $SQL .= $glue . 'venue_title ' . $sort;
672
+                    $SQL .= $glue.'venue_title '.$sort;
673 673
                     break;
674 674
                 case 'city' :
675
-                    $SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort;
675
+                    $SQL .= $glue.EEM_Venue::instance()->second_table().'.VNU_city '.$sort;
676 676
                     break;
677 677
                 case 'state' :
678
-                    $SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort;
678
+                    $SQL .= $glue.EEM_State::instance()->table().'.STA_name '.$sort;
679 679
                     break;
680 680
                 case 'start_date' :
681 681
                 default :
682
-                    $SQL .= $glue . ' event_start_date ' . $sort;
682
+                    $SQL .= $glue.' event_start_date '.$sort;
683 683
                     break;
684 684
             }
685 685
             // add to array of orderby params that have been added
686
-            self::$_query_params['orderby'][ $orderby ] = true;
686
+            self::$_query_params['orderby'][$orderby] = true;
687 687
             $counter++;
688 688
         }
689 689
         return $SQL;
Please login to merge, or discard this patch.
core/domain/entities/notifications/PersistentAdminNotice.php 2 patches
Indentation   +323 added lines, -323 removed lines patch added patch discarded remove patch
@@ -28,332 +28,332 @@
 block discarded – undo
28 28
 class PersistentAdminNotice implements RequiresCapCheckInterface
29 29
 {
30 30
 
31
-    /**
32
-     * @var string $name
33
-     */
34
-    protected $name = '';
35
-
36
-    /**
37
-     * @var string $message
38
-     */
39
-    protected $message = '';
40
-
41
-    /**
42
-     * @var boolean $force_update
43
-     */
44
-    protected $force_update = false;
45
-
46
-    /**
47
-     * @var string $capability
48
-     */
49
-    protected $capability = 'manage_options';
50
-
51
-    /**
52
-     * @var string $cap_context
53
-     */
54
-    protected $cap_context = 'view persistent admin notice';
55
-
56
-    /**
57
-     * @var boolean $dismissed
58
-     */
59
-    protected $dismissed = false;
60
-
61
-    /**
62
-     * @var CapCheckInterface $cap_check
63
-     */
64
-    protected $cap_check;
65
-
66
-    /**
67
-     * if true, then this notice will be deleted from the database
68
-     *
69
-     * @var boolean $purge
70
-     */
71
-    protected $purge = false;
72
-
73
-    /**
74
-     * gets set to true if notice is successfully registered with the PersistentAdminNoticeManager
75
-     * if false, and WP_DEBUG is on, then an exception will be thrown in the admin footer
76
-     *
77
-     * @var boolean $registered
78
-     */
79
-    private $registered = false;
80
-
81
-
82
-
83
-    /**
84
-     * PersistentAdminNotice constructor
85
-     *
86
-     * @param string $name         [required] the name, or key of the Persistent Admin Notice to be stored
87
-     * @param string $message      [required] the message to be stored persistently until dismissed
88
-     * @param bool   $force_update enforce the reappearance of a persistent message
89
-     * @param string $capability   user capability required to view this notice
90
-     * @param string $cap_context  description for why the cap check is being performed
91
-     * @param bool   $dismissed    whether or not the user has already dismissed/viewed this notice
92
-     * @throws InvalidDataTypeException
93
-     */
94
-    public function __construct(
95
-        $name,
96
-        $message,
97
-        $force_update = false,
98
-        $capability = 'manage_options',
99
-        $cap_context = 'view persistent admin notice',
100
-        $dismissed = false
101
-    ) {
102
-        $this->setName($name);
103
-        $this->setMessage($message);
104
-        $this->setForceUpdate($force_update);
105
-        $this->setCapability($capability);
106
-        $this->setCapContext($cap_context);
107
-        $this->setDismissed($dismissed);
108
-        add_action(
109
-            'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices',
110
-            array($this, 'registerPersistentAdminNotice')
111
-        );
112
-        add_action('shutdown', array($this, 'confirmRegistered'), 999);
113
-    }
114
-
115
-
116
-
117
-    /**
118
-     * @return string
119
-     */
120
-    public function getName()
121
-    {
122
-        return $this->name;
123
-    }
124
-
125
-
126
-
127
-    /**
128
-     * @param string $name
129
-     * @throws InvalidDataTypeException
130
-     */
131
-    private function setName($name)
132
-    {
133
-        if (! is_string($name)) {
134
-            throw new InvalidDataTypeException('$name', $name, 'string');
135
-        }
136
-        $this->name = sanitize_key($name);
137
-    }
138
-
139
-
140
-
141
-    /**
142
-     * @return string
143
-     */
144
-    public function getMessage()
145
-    {
146
-        return $this->message;
147
-    }
148
-
149
-
150
-
151
-    /**
152
-     * @param string $message
153
-     * @throws InvalidDataTypeException
154
-     */
155
-    private function setMessage($message)
156
-    {
157
-        if (! is_string($message)) {
158
-            throw new InvalidDataTypeException('$message', $message, 'string');
159
-        }
160
-        global $allowedtags;
161
-        $allowedtags['br'] = array();
162
-        $this->message     = wp_kses($message, $allowedtags);
163
-    }
164
-
165
-
166
-
167
-    /**
168
-     * @return bool
169
-     */
170
-    public function getForceUpdate()
171
-    {
172
-        return $this->force_update;
173
-    }
174
-
175
-
176
-
177
-    /**
178
-     * @param bool $force_update
179
-     */
180
-    private function setForceUpdate($force_update)
181
-    {
182
-        $this->force_update = filter_var($force_update, FILTER_VALIDATE_BOOLEAN);
183
-    }
184
-
185
-
186
-
187
-    /**
188
-     * @return string
189
-     */
190
-    public function getCapability()
191
-    {
192
-        return $this->capability;
193
-    }
194
-
195
-
196
-
197
-    /**
198
-     * @param string $capability
199
-     * @throws InvalidDataTypeException
200
-     */
201
-    private function setCapability($capability)
202
-    {
203
-        if (! is_string($capability)) {
204
-            throw new InvalidDataTypeException('$capability', $capability, 'string');
205
-        }
206
-        $this->capability = ! empty($capability) ? $capability : 'manage_options';
207
-    }
31
+	/**
32
+	 * @var string $name
33
+	 */
34
+	protected $name = '';
35
+
36
+	/**
37
+	 * @var string $message
38
+	 */
39
+	protected $message = '';
40
+
41
+	/**
42
+	 * @var boolean $force_update
43
+	 */
44
+	protected $force_update = false;
45
+
46
+	/**
47
+	 * @var string $capability
48
+	 */
49
+	protected $capability = 'manage_options';
50
+
51
+	/**
52
+	 * @var string $cap_context
53
+	 */
54
+	protected $cap_context = 'view persistent admin notice';
55
+
56
+	/**
57
+	 * @var boolean $dismissed
58
+	 */
59
+	protected $dismissed = false;
60
+
61
+	/**
62
+	 * @var CapCheckInterface $cap_check
63
+	 */
64
+	protected $cap_check;
65
+
66
+	/**
67
+	 * if true, then this notice will be deleted from the database
68
+	 *
69
+	 * @var boolean $purge
70
+	 */
71
+	protected $purge = false;
72
+
73
+	/**
74
+	 * gets set to true if notice is successfully registered with the PersistentAdminNoticeManager
75
+	 * if false, and WP_DEBUG is on, then an exception will be thrown in the admin footer
76
+	 *
77
+	 * @var boolean $registered
78
+	 */
79
+	private $registered = false;
80
+
81
+
82
+
83
+	/**
84
+	 * PersistentAdminNotice constructor
85
+	 *
86
+	 * @param string $name         [required] the name, or key of the Persistent Admin Notice to be stored
87
+	 * @param string $message      [required] the message to be stored persistently until dismissed
88
+	 * @param bool   $force_update enforce the reappearance of a persistent message
89
+	 * @param string $capability   user capability required to view this notice
90
+	 * @param string $cap_context  description for why the cap check is being performed
91
+	 * @param bool   $dismissed    whether or not the user has already dismissed/viewed this notice
92
+	 * @throws InvalidDataTypeException
93
+	 */
94
+	public function __construct(
95
+		$name,
96
+		$message,
97
+		$force_update = false,
98
+		$capability = 'manage_options',
99
+		$cap_context = 'view persistent admin notice',
100
+		$dismissed = false
101
+	) {
102
+		$this->setName($name);
103
+		$this->setMessage($message);
104
+		$this->setForceUpdate($force_update);
105
+		$this->setCapability($capability);
106
+		$this->setCapContext($cap_context);
107
+		$this->setDismissed($dismissed);
108
+		add_action(
109
+			'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices',
110
+			array($this, 'registerPersistentAdminNotice')
111
+		);
112
+		add_action('shutdown', array($this, 'confirmRegistered'), 999);
113
+	}
114
+
115
+
116
+
117
+	/**
118
+	 * @return string
119
+	 */
120
+	public function getName()
121
+	{
122
+		return $this->name;
123
+	}
124
+
125
+
126
+
127
+	/**
128
+	 * @param string $name
129
+	 * @throws InvalidDataTypeException
130
+	 */
131
+	private function setName($name)
132
+	{
133
+		if (! is_string($name)) {
134
+			throw new InvalidDataTypeException('$name', $name, 'string');
135
+		}
136
+		$this->name = sanitize_key($name);
137
+	}
138
+
139
+
140
+
141
+	/**
142
+	 * @return string
143
+	 */
144
+	public function getMessage()
145
+	{
146
+		return $this->message;
147
+	}
148
+
149
+
150
+
151
+	/**
152
+	 * @param string $message
153
+	 * @throws InvalidDataTypeException
154
+	 */
155
+	private function setMessage($message)
156
+	{
157
+		if (! is_string($message)) {
158
+			throw new InvalidDataTypeException('$message', $message, 'string');
159
+		}
160
+		global $allowedtags;
161
+		$allowedtags['br'] = array();
162
+		$this->message     = wp_kses($message, $allowedtags);
163
+	}
164
+
165
+
166
+
167
+	/**
168
+	 * @return bool
169
+	 */
170
+	public function getForceUpdate()
171
+	{
172
+		return $this->force_update;
173
+	}
174
+
175
+
176
+
177
+	/**
178
+	 * @param bool $force_update
179
+	 */
180
+	private function setForceUpdate($force_update)
181
+	{
182
+		$this->force_update = filter_var($force_update, FILTER_VALIDATE_BOOLEAN);
183
+	}
184
+
185
+
186
+
187
+	/**
188
+	 * @return string
189
+	 */
190
+	public function getCapability()
191
+	{
192
+		return $this->capability;
193
+	}
194
+
195
+
196
+
197
+	/**
198
+	 * @param string $capability
199
+	 * @throws InvalidDataTypeException
200
+	 */
201
+	private function setCapability($capability)
202
+	{
203
+		if (! is_string($capability)) {
204
+			throw new InvalidDataTypeException('$capability', $capability, 'string');
205
+		}
206
+		$this->capability = ! empty($capability) ? $capability : 'manage_options';
207
+	}
208 208
 
209 209
 
210 210
 
211
-    /**
212
-     * @return string
213
-     */
214
-    public function getCapContext()
215
-    {
216
-        return $this->cap_context;
217
-    }
218
-
219
-
220
-
221
-    /**
222
-     * @param string $cap_context
223
-     * @throws InvalidDataTypeException
224
-     */
225
-    private function setCapContext($cap_context)
226
-    {
227
-        if (! is_string($cap_context)) {
228
-            throw new InvalidDataTypeException('$cap_context', $cap_context, 'string');
229
-        }
230
-        $this->cap_context = ! empty($cap_context) ? $cap_context : 'view persistent admin notice';
231
-    }
232
-
233
-
234
-
235
-    /**
236
-     * @return bool
237
-     */
238
-    public function getDismissed()
239
-    {
240
-        return $this->dismissed;
241
-    }
242
-
243
-
244
-
245
-    /**
246
-     * @param bool $dismissed
247
-     */
248
-    public function setDismissed($dismissed)
249
-    {
250
-        $this->dismissed = filter_var($dismissed, FILTER_VALIDATE_BOOLEAN);
251
-    }
252
-
253
-
254
-
255
-    /**
256
-     * @return CapCheckInterface
257
-     * @throws InvalidDataTypeException
258
-     */
259
-    public function getCapCheck()
260
-    {
261
-        if (! $this->cap_check instanceof CapCheckInterface) {
262
-            $this->setCapCheck(
263
-                new CapCheck(
264
-                    $this->capability,
265
-                    $this->cap_context
266
-                )
267
-            );
268
-        }
269
-        return $this->cap_check;
270
-    }
271
-
272
-
273
-
274
-    /**
275
-     * @param CapCheckInterface $cap_check
276
-     */
277
-    private function setCapCheck(CapCheckInterface $cap_check)
278
-    {
279
-        $this->cap_check = $cap_check;
280
-    }
281
-
282
-
283
-
284
-    /**
285
-     * @return bool
286
-     */
287
-    public function getPurge()
288
-    {
289
-        return $this->purge;
290
-    }
291
-
292
-
293
-
294
-    /**
295
-     * @param bool $purge
296
-     */
297
-    public function setPurge($purge)
298
-    {
299
-        $this->purge = filter_var($purge, FILTER_VALIDATE_BOOLEAN);
300
-    }
301
-
302
-
303
-
304
-    /**
305
-     * given a valid PersistentAdminNotice Collection,
306
-     * this notice will be added if it is not already found in the collection (using its name as the identifier)
307
-     * if an existing notice is found that has already been dismissed,
308
-     * but we are overriding with a forced update, then we will toggle its dismissed state,
309
-     * so that the notice is displayed again
310
-     *
311
-     * @param Collection $persistent_admin_notice_collection
312
-     * @throws InvalidEntityException
313
-     */
314
-    public function registerPersistentAdminNotice(Collection $persistent_admin_notice_collection)
315
-    {
316
-        if ($this->registered) {
317
-            return;
318
-        }
319
-        // first check if this notice has already been added to the collection
320
-        if ($persistent_admin_notice_collection->has($this->name)) {
321
-            /** @var PersistentAdminNotice $existing */
322
-            $existing = $persistent_admin_notice_collection->get($this->name);
323
-            // we don't need to add it again (we can't actually)
324
-            // but if it has already been dismissed, and we are overriding with a forced update
325
-            if ($existing->getDismissed() && $this->getForceUpdate()) {
326
-                // then toggle the notice's dismissed state to true
327
-                // so that it gets displayed again
328
-                $existing->setDismissed(false);
329
-            }
330
-        } else {
331
-            $persistent_admin_notice_collection->add($this, $this->name);
332
-        }
333
-        $this->registered = true;
334
-    }
335
-
336
-
337
-
338
-    /**
339
-     * @throws Exception
340
-     */
341
-    public function confirmRegistered()
342
-    {
343
-        if (! $this->registered && WP_DEBUG) {
344
-            new ExceptionStackTraceDisplay(
345
-                new DomainException(
346
-                    sprintf(
347
-                        esc_html__(
348
-                            'The "%1$s" PersistentAdminNotice was not successfully registered. Please ensure that it is being created prior to either the "admin_notices" or "network_admin_notices" hooks being triggered.',
349
-                            'event_espresso'
350
-                        ),
351
-                        $this->name
352
-                    )
353
-                )
354
-            );
355
-        }
356
-    }
211
+	/**
212
+	 * @return string
213
+	 */
214
+	public function getCapContext()
215
+	{
216
+		return $this->cap_context;
217
+	}
218
+
219
+
220
+
221
+	/**
222
+	 * @param string $cap_context
223
+	 * @throws InvalidDataTypeException
224
+	 */
225
+	private function setCapContext($cap_context)
226
+	{
227
+		if (! is_string($cap_context)) {
228
+			throw new InvalidDataTypeException('$cap_context', $cap_context, 'string');
229
+		}
230
+		$this->cap_context = ! empty($cap_context) ? $cap_context : 'view persistent admin notice';
231
+	}
232
+
233
+
234
+
235
+	/**
236
+	 * @return bool
237
+	 */
238
+	public function getDismissed()
239
+	{
240
+		return $this->dismissed;
241
+	}
242
+
243
+
244
+
245
+	/**
246
+	 * @param bool $dismissed
247
+	 */
248
+	public function setDismissed($dismissed)
249
+	{
250
+		$this->dismissed = filter_var($dismissed, FILTER_VALIDATE_BOOLEAN);
251
+	}
252
+
253
+
254
+
255
+	/**
256
+	 * @return CapCheckInterface
257
+	 * @throws InvalidDataTypeException
258
+	 */
259
+	public function getCapCheck()
260
+	{
261
+		if (! $this->cap_check instanceof CapCheckInterface) {
262
+			$this->setCapCheck(
263
+				new CapCheck(
264
+					$this->capability,
265
+					$this->cap_context
266
+				)
267
+			);
268
+		}
269
+		return $this->cap_check;
270
+	}
271
+
272
+
273
+
274
+	/**
275
+	 * @param CapCheckInterface $cap_check
276
+	 */
277
+	private function setCapCheck(CapCheckInterface $cap_check)
278
+	{
279
+		$this->cap_check = $cap_check;
280
+	}
281
+
282
+
283
+
284
+	/**
285
+	 * @return bool
286
+	 */
287
+	public function getPurge()
288
+	{
289
+		return $this->purge;
290
+	}
291
+
292
+
293
+
294
+	/**
295
+	 * @param bool $purge
296
+	 */
297
+	public function setPurge($purge)
298
+	{
299
+		$this->purge = filter_var($purge, FILTER_VALIDATE_BOOLEAN);
300
+	}
301
+
302
+
303
+
304
+	/**
305
+	 * given a valid PersistentAdminNotice Collection,
306
+	 * this notice will be added if it is not already found in the collection (using its name as the identifier)
307
+	 * if an existing notice is found that has already been dismissed,
308
+	 * but we are overriding with a forced update, then we will toggle its dismissed state,
309
+	 * so that the notice is displayed again
310
+	 *
311
+	 * @param Collection $persistent_admin_notice_collection
312
+	 * @throws InvalidEntityException
313
+	 */
314
+	public function registerPersistentAdminNotice(Collection $persistent_admin_notice_collection)
315
+	{
316
+		if ($this->registered) {
317
+			return;
318
+		}
319
+		// first check if this notice has already been added to the collection
320
+		if ($persistent_admin_notice_collection->has($this->name)) {
321
+			/** @var PersistentAdminNotice $existing */
322
+			$existing = $persistent_admin_notice_collection->get($this->name);
323
+			// we don't need to add it again (we can't actually)
324
+			// but if it has already been dismissed, and we are overriding with a forced update
325
+			if ($existing->getDismissed() && $this->getForceUpdate()) {
326
+				// then toggle the notice's dismissed state to true
327
+				// so that it gets displayed again
328
+				$existing->setDismissed(false);
329
+			}
330
+		} else {
331
+			$persistent_admin_notice_collection->add($this, $this->name);
332
+		}
333
+		$this->registered = true;
334
+	}
335
+
336
+
337
+
338
+	/**
339
+	 * @throws Exception
340
+	 */
341
+	public function confirmRegistered()
342
+	{
343
+		if (! $this->registered && WP_DEBUG) {
344
+			new ExceptionStackTraceDisplay(
345
+				new DomainException(
346
+					sprintf(
347
+						esc_html__(
348
+							'The "%1$s" PersistentAdminNotice was not successfully registered. Please ensure that it is being created prior to either the "admin_notices" or "network_admin_notices" hooks being triggered.',
349
+							'event_espresso'
350
+						),
351
+						$this->name
352
+					)
353
+				)
354
+			);
355
+		}
356
+	}
357 357
 
358 358
 
359 359
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      */
131 131
     private function setName($name)
132 132
     {
133
-        if (! is_string($name)) {
133
+        if ( ! is_string($name)) {
134 134
             throw new InvalidDataTypeException('$name', $name, 'string');
135 135
         }
136 136
         $this->name = sanitize_key($name);
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
      */
155 155
     private function setMessage($message)
156 156
     {
157
-        if (! is_string($message)) {
157
+        if ( ! is_string($message)) {
158 158
             throw new InvalidDataTypeException('$message', $message, 'string');
159 159
         }
160 160
         global $allowedtags;
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
      */
201 201
     private function setCapability($capability)
202 202
     {
203
-        if (! is_string($capability)) {
203
+        if ( ! is_string($capability)) {
204 204
             throw new InvalidDataTypeException('$capability', $capability, 'string');
205 205
         }
206 206
         $this->capability = ! empty($capability) ? $capability : 'manage_options';
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
      */
225 225
     private function setCapContext($cap_context)
226 226
     {
227
-        if (! is_string($cap_context)) {
227
+        if ( ! is_string($cap_context)) {
228 228
             throw new InvalidDataTypeException('$cap_context', $cap_context, 'string');
229 229
         }
230 230
         $this->cap_context = ! empty($cap_context) ? $cap_context : 'view persistent admin notice';
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
      */
259 259
     public function getCapCheck()
260 260
     {
261
-        if (! $this->cap_check instanceof CapCheckInterface) {
261
+        if ( ! $this->cap_check instanceof CapCheckInterface) {
262 262
             $this->setCapCheck(
263 263
                 new CapCheck(
264 264
                     $this->capability,
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
      */
341 341
     public function confirmRegistered()
342 342
     {
343
-        if (! $this->registered && WP_DEBUG) {
343
+        if ( ! $this->registered && WP_DEBUG) {
344 344
             new ExceptionStackTraceDisplay(
345 345
                 new DomainException(
346 346
                     sprintf(
Please login to merge, or discard this patch.
core/db_models/EEM_Payment_Method.model.php 2 patches
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -294,15 +294,15 @@  discard block
 block discarded – undo
294 294
 
295 295
 
296 296
 
297
-    /**
298
-     * Overrides parent to not only turn wpdb results into EE_Payment_Method objects,
299
-     * but also verifies the payment method type of each is a usable object. If not,
300
-     * deactivate it, sets a notification, and deactivates it
301
-     *
302
-     * @param array $rows
303
-     * @return EE_Payment_Method[]
304
-     * @throws InvalidDataTypeException
305
-     */
297
+	/**
298
+	 * Overrides parent to not only turn wpdb results into EE_Payment_Method objects,
299
+	 * but also verifies the payment method type of each is a usable object. If not,
300
+	 * deactivate it, sets a notification, and deactivates it
301
+	 *
302
+	 * @param array $rows
303
+	 * @return EE_Payment_Method[]
304
+	 * @throws InvalidDataTypeException
305
+	 */
306 306
 	protected function _create_objects( $rows = array() ) {
307 307
 		EE_Registry::instance()->load_lib( 'Payment_Method_Manager' );
308 308
 		$payment_methods = parent::_create_objects( $rows );
@@ -319,18 +319,18 @@  discard block
 block discarded – undo
319 319
 				//only deactivate and notify the admin if the payment is active somewhere
320 320
 				$payment_method->deactivate();
321 321
 				$payment_method->save();
322
-                new PersistentAdminNotice(
323
-                    'auto-deactivated-' . $payment_method->type(),
324
-                    sprintf(
325
-                        __('The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.',
326
-                            'event_espresso'),
327
-                        $payment_method->admin_name(),
328
-                        '<br />',
329
-                        '<a href="' . admin_url('plugins.php') . '">',
330
-                        '</a>'
331
-                    ),
332
-                    true
333
-                );
322
+				new PersistentAdminNotice(
323
+					'auto-deactivated-' . $payment_method->type(),
324
+					sprintf(
325
+						__('The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.',
326
+							'event_espresso'),
327
+						$payment_method->admin_name(),
328
+						'<br />',
329
+						'<a href="' . admin_url('plugins.php') . '">',
330
+						'</a>'
331
+					),
332
+					true
333
+				);
334 334
 			}
335 335
 		}
336 336
 		return $usable_payment_methods;
Please login to merge, or discard this patch.
Spacing   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\core\domain\entities\notifications\PersistentAdminNotice;
2 2
 use EventEspresso\core\exceptions\InvalidDataTypeException;
3 3
 
4
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
5
-	exit( 'No direct script access allowed' );
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 /**
8 8
  *
@@ -40,33 +40,33 @@  discard block
 block discarded – undo
40 40
 	 * @access   protected
41 41
 	 * @return EEM_Payment_Method
42 42
 	 */
43
-	protected function __construct( $timezone = NULL ) {
44
-		$this->singlular_item = __( 'Payment Method', 'event_espresso' );
45
-		$this->plural_item = __( 'Payment Methods', 'event_espresso' );
46
-		$this->_tables = array( 'Payment_Method' => new EE_Primary_Table( 'esp_payment_method', 'PMD_ID' ) );
43
+	protected function __construct($timezone = NULL) {
44
+		$this->singlular_item = __('Payment Method', 'event_espresso');
45
+		$this->plural_item = __('Payment Methods', 'event_espresso');
46
+		$this->_tables = array('Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID'));
47 47
 		$this->_fields = array(
48 48
 			'Payment_Method' => array(
49
-				'PMD_ID' => new EE_Primary_Key_Int_Field( 'PMD_ID', __( "ID", 'event_espresso' ) ),
50
-				'PMD_type' => new EE_Plain_Text_Field( 'PMD_type', __( "Payment Method Type", 'event_espresso' ), FALSE, 'Admin_Only' ),
51
-				'PMD_name' => new EE_Plain_Text_Field( 'PMD_name', __( "Name", 'event_espresso' ), FALSE ),
52
-				'PMD_desc' => new EE_Post_Content_Field( 'PMD_desc', __( "Description", 'event_espresso' ), FALSE, '' ),
53
-				'PMD_admin_name' => new EE_Plain_Text_Field( 'PMD_admin_name', __( "Admin-Only Name", 'event_espresso' ), TRUE ),
54
-				'PMD_admin_desc' => new EE_Post_Content_Field( 'PMD_admin_desc', __( "Admin-Only Description", 'event_espresso' ), TRUE ),
55
-				'PMD_slug' => new EE_Slug_Field( 'PMD_slug', __( "Slug", 'event_espresso' ), FALSE ),
56
-				'PMD_order' => new EE_Integer_Field( 'PMD_order', __( "Order", 'event_espresso' ), FALSE, 0 ),
57
-				'PMD_debug_mode' => new EE_Boolean_Field( 'PMD_debug_mode', __( "Debug Mode On?", 'event_espresso' ), FALSE, FALSE ),
58
-				'PMD_wp_user' => new EE_WP_User_Field( 'PMD_wp_user', __( "Payment Method Creator ID", 'event_espresso' ), FALSE ),
59
-				'PMD_open_by_default' => new EE_Boolean_Field( 'PMD_open_by_default', __( "Open by Default?", 'event_espresso' ), FALSE, FALSE ), 'PMD_button_url' => new EE_Plain_Text_Field( 'PMD_button_url', __( "Button URL", 'event_espresso' ), TRUE, '' ),
60
-				'PMD_scope' => new EE_Serialized_Text_Field( 'PMD_scope', __( "Usable From?", 'event_espresso' ), FALSE, array() ), //possible values currently are 'CART','ADMIN','API'
49
+				'PMD_ID' => new EE_Primary_Key_Int_Field('PMD_ID', __("ID", 'event_espresso')),
50
+				'PMD_type' => new EE_Plain_Text_Field('PMD_type', __("Payment Method Type", 'event_espresso'), FALSE, 'Admin_Only'),
51
+				'PMD_name' => new EE_Plain_Text_Field('PMD_name', __("Name", 'event_espresso'), FALSE),
52
+				'PMD_desc' => new EE_Post_Content_Field('PMD_desc', __("Description", 'event_espresso'), FALSE, ''),
53
+				'PMD_admin_name' => new EE_Plain_Text_Field('PMD_admin_name', __("Admin-Only Name", 'event_espresso'), TRUE),
54
+				'PMD_admin_desc' => new EE_Post_Content_Field('PMD_admin_desc', __("Admin-Only Description", 'event_espresso'), TRUE),
55
+				'PMD_slug' => new EE_Slug_Field('PMD_slug', __("Slug", 'event_espresso'), FALSE),
56
+				'PMD_order' => new EE_Integer_Field('PMD_order', __("Order", 'event_espresso'), FALSE, 0),
57
+				'PMD_debug_mode' => new EE_Boolean_Field('PMD_debug_mode', __("Debug Mode On?", 'event_espresso'), FALSE, FALSE),
58
+				'PMD_wp_user' => new EE_WP_User_Field('PMD_wp_user', __("Payment Method Creator ID", 'event_espresso'), FALSE),
59
+				'PMD_open_by_default' => new EE_Boolean_Field('PMD_open_by_default', __("Open by Default?", 'event_espresso'), FALSE, FALSE), 'PMD_button_url' => new EE_Plain_Text_Field('PMD_button_url', __("Button URL", 'event_espresso'), TRUE, ''),
60
+				'PMD_scope' => new EE_Serialized_Text_Field('PMD_scope', __("Usable From?", 'event_espresso'), FALSE, array()), //possible values currently are 'CART','ADMIN','API'
61 61
 		) );
62 62
 		$this->_model_relations = array(
63 63
  //			'Event'=>new EE_HABTM_Relation('Event_Payment_Method'),
64 64
 			'Payment' => new EE_Has_Many_Relation(),
65
-			'Currency' => new EE_HABTM_Relation( 'Currency_Payment_Method' ),
65
+			'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'),
66 66
 			'Transaction' => new EE_Has_Many_Relation(),
67 67
 			'WP_User' => new EE_Belongs_To_Relation(),
68 68
 		);
69
-		parent::__construct( $timezone );
69
+		parent::__construct($timezone);
70 70
 	}
71 71
 
72 72
 
@@ -76,8 +76,8 @@  discard block
 block discarded – undo
76 76
 	 * @param string $slug
77 77
 	 * @return EE_Payment_Method
78 78
 	 */
79
-	public function get_one_by_slug( $slug ) {
80
-		return $this->get_one( array( array( 'PMD_slug' => $slug ) ) );
79
+	public function get_one_by_slug($slug) {
80
+		return $this->get_one(array(array('PMD_slug' => $slug)));
81 81
 	}
82 82
 
83 83
 
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
 		return apply_filters(
92 92
 			'FHEE__EEM_Payment_Method__scopes',
93 93
 			array(
94
-				self::scope_cart 		=> __( "Front-end Registration Page", 'event_espresso' ),
95
-				self::scope_admin 	=> __( "Admin Registration Page (no online processing)", 'event_espresso' )
94
+				self::scope_cart 		=> __("Front-end Registration Page", 'event_espresso'),
95
+				self::scope_admin 	=> __("Admin Registration Page (no online processing)", 'event_espresso')
96 96
 			)
97 97
 		);
98 98
 	}
@@ -104,9 +104,9 @@  discard block
 block discarded – undo
104 104
 	 * @param string $scope like one of EEM_Payment_Method::instance()->scopes()
105 105
 	 * @return boolean
106 106
 	 */
107
-	public function is_valid_scope( $scope ) {
107
+	public function is_valid_scope($scope) {
108 108
 		$scopes = $this->scopes();
109
-		if ( isset( $scopes[ $scope ] ) ) {
109
+		if (isset($scopes[$scope])) {
110 110
 			return TRUE;
111 111
 		} else {
112 112
 			return FALSE;
@@ -122,11 +122,11 @@  discard block
 block discarded – undo
122 122
 	 * @throws EE_Error
123 123
 	 * @return EE_Payment_Method[]
124 124
 	 */
125
-	public function get_all_active( $scope = NULL, $query_params = array() ) {
126
-		if( ! isset( $query_params[ 'order_by' ] ) && ! isset( $query_params[ 'order' ] ) ) {
127
-			$query_params['order_by'] = array( 'PMD_order' => 'ASC', 'PMD_ID' => 'ASC' );
125
+	public function get_all_active($scope = NULL, $query_params = array()) {
126
+		if ( ! isset($query_params['order_by']) && ! isset($query_params['order'])) {
127
+			$query_params['order_by'] = array('PMD_order' => 'ASC', 'PMD_ID' => 'ASC');
128 128
 		}
129
-		return $this->get_all( $this->_get_query_params_for_all_active( $scope, $query_params ) );
129
+		return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params));
130 130
 	}
131 131
 
132 132
 	/**
@@ -135,8 +135,8 @@  discard block
 block discarded – undo
135 135
 	 * @param array $query_params
136 136
 	 * @return int
137 137
 	 */
138
-	public function count_active( $scope = NULL, $query_params = array() ){
139
-		return $this->count( $this->_get_query_params_for_all_active( $scope, $query_params ) );
138
+	public function count_active($scope = NULL, $query_params = array()) {
139
+		return $this->count($this->_get_query_params_for_all_active($scope, $query_params));
140 140
 	}
141 141
 
142 142
 	/**
@@ -147,21 +147,21 @@  discard block
 block discarded – undo
147 147
 	 * @return array like param of EEM_Base::get_all()
148 148
 	 * @throws EE_Error
149 149
 	 */
150
-	protected function _get_query_params_for_all_active( $scope = NULL, $query_params = array() ){
151
-		if ( $scope ) {
152
-			if ( $this->is_valid_scope( $scope ) ) {
153
-				return array_replace_recursive( array( array( 'PMD_scope' => array( 'LIKE', "%$scope%" ) ) ), $query_params );
150
+	protected function _get_query_params_for_all_active($scope = NULL, $query_params = array()) {
151
+		if ($scope) {
152
+			if ($this->is_valid_scope($scope)) {
153
+				return array_replace_recursive(array(array('PMD_scope' => array('LIKE', "%$scope%"))), $query_params);
154 154
 			} else {
155
-				throw new EE_Error( sprintf( __( "'%s' is not a valid scope for a payment method", "event_espresso" ), $scope ) );
155
+				throw new EE_Error(sprintf(__("'%s' is not a valid scope for a payment method", "event_espresso"), $scope));
156 156
 			}
157 157
 		} else {
158 158
 			$acceptable_scopes = array();
159 159
 			$count = 0;
160
-			foreach ( $this->scopes() as $scope_name => $desc ) {
160
+			foreach ($this->scopes() as $scope_name => $desc) {
161 161
 				$count++;
162
-				$acceptable_scopes[ 'PMD_scope*' . $count ] = array( 'LIKE', '%' . $scope_name . '%' );
162
+				$acceptable_scopes['PMD_scope*'.$count] = array('LIKE', '%'.$scope_name.'%');
163 163
 			}
164
-			return array_replace_recursive( array( array( 'OR*active_scope' => $acceptable_scopes ) ), $query_params );
164
+			return array_replace_recursive(array(array('OR*active_scope' => $acceptable_scopes)), $query_params);
165 165
 		}
166 166
 	}
167 167
 
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
 	 * @return array like param of EEM_Base::get_all()
174 174
 	 * @throws EE_Error
175 175
 	 */
176
-	public function get_query_params_for_all_active( $scope = NULL, $query_params = array() ) {
177
-		return $this->_get_query_params_for_all_active( $scope, $query_params );
176
+	public function get_query_params_for_all_active($scope = NULL, $query_params = array()) {
177
+		return $this->_get_query_params_for_all_active($scope, $query_params);
178 178
 	}
179 179
 
180 180
 
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
 	 * @param array  $query_params
185 185
 	 * @return EE_Payment_Method
186 186
 	 */
187
-	public function get_one_active( $scope = NULL, $query_params = array() ) {
188
-		return $this->get_one( $this->_get_query_params_for_all_active( $scope, $query_params ) );
187
+	public function get_one_active($scope = NULL, $query_params = array()) {
188
+		return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params));
189 189
 	}
190 190
 
191 191
 
@@ -195,8 +195,8 @@  discard block
 block discarded – undo
195 195
 	 * @param string $type
196 196
 	 * @return EE_Payment_Method
197 197
 	 */
198
-	public function get_one_of_type( $type ) {
199
-		return $this->get_one( array( array( 'PMD_type' => $type ) ) );
198
+	public function get_one_of_type($type) {
199
+		return $this->get_one(array(array('PMD_type' => $type)));
200 200
 	}
201 201
 
202 202
 
@@ -209,22 +209,22 @@  discard block
 block discarded – undo
209 209
 	 * @return EE_Payment_Method
210 210
 	 * @throws EE_Error
211 211
 	 */
212
-	public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ) {
212
+	public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) {
213 213
 		//first: check if it's a slug
214
-		if( is_string( $base_class_obj_or_id ) ) {
215
-			$obj = $this->get_one_by_slug( $base_class_obj_or_id );
216
-			if( $obj ) {
214
+		if (is_string($base_class_obj_or_id)) {
215
+			$obj = $this->get_one_by_slug($base_class_obj_or_id);
216
+			if ($obj) {
217 217
 				return $obj;
218 218
 			}
219 219
 		}
220 220
 		//ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID)
221 221
 		try {
222
-			return parent::ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db );
222
+			return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db);
223 223
 		}
224
-		catch ( EE_Error $e ) {
224
+		catch (EE_Error $e) {
225 225
 			//handle it outside the catch
226 226
 		}
227
-		throw new EE_Error( sprintf( __( "'%s' is neither a Payment Method ID, slug, nor object.", "event_espresso" ), $base_class_obj_or_id ) );
227
+		throw new EE_Error(sprintf(__("'%s' is neither a Payment Method ID, slug, nor object.", "event_espresso"), $base_class_obj_or_id));
228 228
 	}
229 229
 
230 230
 
@@ -235,12 +235,12 @@  discard block
 block discarded – undo
235 235
 	 * @param mixed $base_obj_or_id_or_slug
236 236
 	 * @return int
237 237
 	 */
238
-	function ensure_is_ID( $base_obj_or_id_or_slug ) {
239
-		if ( is_string( $base_obj_or_id_or_slug ) ) {
238
+	function ensure_is_ID($base_obj_or_id_or_slug) {
239
+		if (is_string($base_obj_or_id_or_slug)) {
240 240
 			//assume it's a slug
241
-			$base_obj_or_id_or_slug = $this->get_one_by_slug( $base_obj_or_id_or_slug );
241
+			$base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug);
242 242
 		}
243
-		return parent::ensure_is_ID( $base_obj_or_id_or_slug );
243
+		return parent::ensure_is_ID($base_obj_or_id_or_slug);
244 244
 	}
245 245
 
246 246
 
@@ -249,36 +249,36 @@  discard block
 block discarded – undo
249 249
 	 * Verifies the button urls on all the passed payment methods have a valid button url. If not, resets them to their default.
250 250
 	 * @param EE_Payment_Method[] $payment_methods. If NULL is provided defaults to all payment methods active in the cart
251 251
 	 */
252
-	function verify_button_urls( $payment_methods = NULL ) {
253
-		$payment_methods = is_array( $payment_methods ) ? $payment_methods : $this->get_all_active(EEM_Payment_Method::scope_cart);
254
-		foreach ( $payment_methods as $payment_method ) {
252
+	function verify_button_urls($payment_methods = NULL) {
253
+		$payment_methods = is_array($payment_methods) ? $payment_methods : $this->get_all_active(EEM_Payment_Method::scope_cart);
254
+		foreach ($payment_methods as $payment_method) {
255 255
 			try {
256 256
 				$current_button_url = $payment_method->button_url();
257
-				$buttons_urls_to_try = apply_filters( 'FHEE__EEM_Payment_Method__verify_button_urls__button_urls_to_try', array(
258
-					'current_ssl' => str_replace( "http://", "https://", $current_button_url ),
259
-					'current' => str_replace( "https://", "http://", $current_button_url ),
260
-					'default_ssl' => str_replace( "http://", "https://", $payment_method->type_obj()->default_button_url() ),
261
-					'default' => str_replace( "https://", "http://", $payment_method->type_obj()->default_button_url() ),
262
-				) );
263
-				foreach( $buttons_urls_to_try as $button_url_to_try ) {
264
-					if(
257
+				$buttons_urls_to_try = apply_filters('FHEE__EEM_Payment_Method__verify_button_urls__button_urls_to_try', array(
258
+					'current_ssl' => str_replace("http://", "https://", $current_button_url),
259
+					'current' => str_replace("https://", "http://", $current_button_url),
260
+					'default_ssl' => str_replace("http://", "https://", $payment_method->type_obj()->default_button_url()),
261
+					'default' => str_replace("https://", "http://", $payment_method->type_obj()->default_button_url()),
262
+				));
263
+				foreach ($buttons_urls_to_try as $button_url_to_try) {
264
+					if (
265 265
 							(//this is the current url and it exists, regardless of SSL issues
266 266
 								$button_url_to_try == $current_button_url &&
267 267
 								EEH_URL::remote_file_exists(
268 268
 										$button_url_to_try,
269 269
 										array(
270 270
 											'sslverify' => false,
271
-											'limit_response_size' => 4095,//we don't really care for a full response, but we do want headers at least. Lets just ask for a one block
271
+											'limit_response_size' => 4095, //we don't really care for a full response, but we do want headers at least. Lets just ask for a one block
272 272
 											) )
273 273
 							)
274 274
 							||
275 275
 							(//this is NOT the current url and it exists with a working SSL cert
276 276
 								$button_url_to_try != $current_button_url &&
277
-								EEH_URL::remote_file_exists( $button_url_to_try )
277
+								EEH_URL::remote_file_exists($button_url_to_try)
278 278
 							) ) {
279
-						if( $current_button_url != $button_url_to_try ){
280
-							$payment_method->save( array( 'PMD_button_url' => $button_url_to_try ) );
281
-							EE_Error::add_attention( sprintf( __( "Payment Method %s's button url was set to %s, because the old image either didnt exist or SSL was recently enabled.", "event_espresso" ), $payment_method->name(), $button_url_to_try ) );
279
+						if ($current_button_url != $button_url_to_try) {
280
+							$payment_method->save(array('PMD_button_url' => $button_url_to_try));
281
+							EE_Error::add_attention(sprintf(__("Payment Method %s's button url was set to %s, because the old image either didnt exist or SSL was recently enabled.", "event_espresso"), $payment_method->name(), $button_url_to_try));
282 282
 						}
283 283
 						//this image exists. So if wasn't set before, now it is;
284 284
 						//or if it was already set, we have nothing to do
@@ -286,8 +286,8 @@  discard block
 block discarded – undo
286 286
 					}
287 287
 				}
288 288
 			}
289
-			catch ( EE_Error $e ) {
290
-				$payment_method->set_active( FALSE );
289
+			catch (EE_Error $e) {
290
+				$payment_method->set_active(FALSE);
291 291
 			}
292 292
 		}
293 293
 	}
@@ -303,30 +303,30 @@  discard block
 block discarded – undo
303 303
      * @return EE_Payment_Method[]
304 304
      * @throws InvalidDataTypeException
305 305
      */
306
-	protected function _create_objects( $rows = array() ) {
307
-		EE_Registry::instance()->load_lib( 'Payment_Method_Manager' );
308
-		$payment_methods = parent::_create_objects( $rows );
306
+	protected function _create_objects($rows = array()) {
307
+		EE_Registry::instance()->load_lib('Payment_Method_Manager');
308
+		$payment_methods = parent::_create_objects($rows);
309 309
 		/* @var $payment_methods EE_Payment_Method[] */
310 310
 		$usable_payment_methods = array();
311
-		foreach ( $payment_methods as $key => $payment_method ) {
312
-			if ( EE_Payment_Method_Manager::instance()->payment_method_type_exists( $payment_method->type() ) ) {
313
-				$usable_payment_methods[ $key ] = $payment_method;
311
+		foreach ($payment_methods as $key => $payment_method) {
312
+			if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) {
313
+				$usable_payment_methods[$key] = $payment_method;
314 314
 				//some payment methods enqueue their scripts in EE_PMT_*::__construct
315 315
 				//which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue
316 316
 				//its scripts). but for backwards-compat we should continue to do that
317 317
 				$payment_method->type_obj();
318
-			} elseif( $payment_method->active() ) {
318
+			} elseif ($payment_method->active()) {
319 319
 				//only deactivate and notify the admin if the payment is active somewhere
320 320
 				$payment_method->deactivate();
321 321
 				$payment_method->save();
322 322
                 new PersistentAdminNotice(
323
-                    'auto-deactivated-' . $payment_method->type(),
323
+                    'auto-deactivated-'.$payment_method->type(),
324 324
                     sprintf(
325 325
                         __('The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.',
326 326
                             'event_espresso'),
327 327
                         $payment_method->admin_name(),
328 328
                         '<br />',
329
-                        '<a href="' . admin_url('plugins.php') . '">',
329
+                        '<a href="'.admin_url('plugins.php').'">',
330 330
                         '</a>'
331 331
                     ),
332 332
                     true
@@ -346,11 +346,11 @@  discard block
 block discarded – undo
346 346
 	 * @param string 	$scope @see EEM_Payment_Method::get_all_for_events
347 347
 	 * @return EE_Payment_Method[]
348 348
 	 */
349
-	public function get_all_for_transaction( $transaction, $scope ) {
349
+	public function get_all_for_transaction($transaction, $scope) {
350 350
 		//give addons a chance to override what payment methods are chosen based on the transaction
351 351
 		return apply_filters(
352 352
 			'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods',
353
-			$this->get_all_active( $scope, array( 'group_by' => 'PMD_type' ) ),
353
+			$this->get_all_active($scope, array('group_by' => 'PMD_type')),
354 354
 			$transaction,
355 355
 			$scope
356 356
 		);
@@ -366,16 +366,16 @@  discard block
 block discarded – undo
366 366
 	 * @param EE_Registration|int $registration_or_reg_id  Either the EE_Registration object or the id for the registration.
367 367
 	 * @return EE_Payment|null
368 368
 	 */
369
-	public function get_last_used_for_registration( $registration_or_reg_id ) {
370
-		$registration_id = EEM_Registration::instance()->ensure_is_ID( $registration_or_reg_id );
369
+	public function get_last_used_for_registration($registration_or_reg_id) {
370
+		$registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id);
371 371
 
372 372
 		$query_params = array(
373 373
 			0 => array(
374 374
 				'Payment.Registration.REG_ID' => $registration_id,
375 375
 			),
376
-			'order_by' => array( 'Payment.PAY_ID' => 'DESC' )
376
+			'order_by' => array('Payment.PAY_ID' => 'DESC')
377 377
 		);
378
-		return $this->get_one( $query_params );
378
+		return $this->get_one($query_params);
379 379
 	}
380 380
 
381 381
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -38,217 +38,217 @@
 block discarded – undo
38 38
  * @since       4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 
64 64
 } else {
65
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
66
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
-        /**
68
-         * espresso_minimum_php_version_error
69
-         *
70
-         * @return void
71
-         */
72
-        function espresso_minimum_php_version_error()
73
-        {
74
-            ?>
65
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
66
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
67
+		/**
68
+		 * espresso_minimum_php_version_error
69
+		 *
70
+		 * @return void
71
+		 */
72
+		function espresso_minimum_php_version_error()
73
+		{
74
+			?>
75 75
             <div class="error">
76 76
                 <p>
77 77
                     <?php
78
-                    printf(
79
-                        esc_html__(
80
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
81
-                            'event_espresso'
82
-                        ),
83
-                        EE_MIN_PHP_VER_REQUIRED,
84
-                        PHP_VERSION,
85
-                        '<br/>',
86
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
87
-                    );
88
-                    ?>
78
+					printf(
79
+						esc_html__(
80
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
81
+							'event_espresso'
82
+						),
83
+						EE_MIN_PHP_VER_REQUIRED,
84
+						PHP_VERSION,
85
+						'<br/>',
86
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
87
+					);
88
+					?>
89 89
                 </p>
90 90
             </div>
91 91
             <?php
92
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
93
-        }
92
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
93
+		}
94 94
 
95
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
96
-    } else {
97
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
98
-        /**
99
-         * espresso_version
100
-         * Returns the plugin version
101
-         *
102
-         * @return string
103
-         */
104
-        function espresso_version()
105
-        {
106
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.50.rc.011');
107
-        }
95
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
96
+	} else {
97
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
98
+		/**
99
+		 * espresso_version
100
+		 * Returns the plugin version
101
+		 *
102
+		 * @return string
103
+		 */
104
+		function espresso_version()
105
+		{
106
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.50.rc.011');
107
+		}
108 108
 
109
-        /**
110
-         * espresso_plugin_activation
111
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
112
-         */
113
-        function espresso_plugin_activation()
114
-        {
115
-            update_option('ee_espresso_activation', true);
116
-        }
109
+		/**
110
+		 * espresso_plugin_activation
111
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
112
+		 */
113
+		function espresso_plugin_activation()
114
+		{
115
+			update_option('ee_espresso_activation', true);
116
+		}
117 117
 
118
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
119
-        /**
120
-         *    espresso_load_error_handling
121
-         *    this function loads EE's class for handling exceptions and errors
122
-         */
123
-        function espresso_load_error_handling()
124
-        {
125
-            static $error_handling_loaded = false;
126
-            if ($error_handling_loaded) {
127
-                return;
128
-            }
129
-            // load debugging tools
130
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
131
-                require_once   EE_HELPERS . 'EEH_Debug_Tools.helper.php';
132
-                \EEH_Debug_Tools::instance();
133
-            }
134
-            // load error handling
135
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
136
-                require_once EE_CORE . 'EE_Error.core.php';
137
-            } else {
138
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
139
-            }
140
-            $error_handling_loaded = true;
141
-        }
118
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
119
+		/**
120
+		 *    espresso_load_error_handling
121
+		 *    this function loads EE's class for handling exceptions and errors
122
+		 */
123
+		function espresso_load_error_handling()
124
+		{
125
+			static $error_handling_loaded = false;
126
+			if ($error_handling_loaded) {
127
+				return;
128
+			}
129
+			// load debugging tools
130
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
131
+				require_once   EE_HELPERS . 'EEH_Debug_Tools.helper.php';
132
+				\EEH_Debug_Tools::instance();
133
+			}
134
+			// load error handling
135
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
136
+				require_once EE_CORE . 'EE_Error.core.php';
137
+			} else {
138
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
139
+			}
140
+			$error_handling_loaded = true;
141
+		}
142 142
 
143
-        /**
144
-         *    espresso_load_required
145
-         *    given a class name and path, this function will load that file or throw an exception
146
-         *
147
-         * @param    string $classname
148
-         * @param    string $full_path_to_file
149
-         * @throws    EE_Error
150
-         */
151
-        function espresso_load_required($classname, $full_path_to_file)
152
-        {
153
-            if (is_readable($full_path_to_file)) {
154
-                require_once $full_path_to_file;
155
-            } else {
156
-                throw new \EE_Error (
157
-                    sprintf(
158
-                        esc_html__(
159
-                            'The %s class file could not be located or is not readable due to file permissions.',
160
-                            'event_espresso'
161
-                        ),
162
-                        $classname
163
-                    )
164
-                );
165
-            }
166
-        }
143
+		/**
144
+		 *    espresso_load_required
145
+		 *    given a class name and path, this function will load that file or throw an exception
146
+		 *
147
+		 * @param    string $classname
148
+		 * @param    string $full_path_to_file
149
+		 * @throws    EE_Error
150
+		 */
151
+		function espresso_load_required($classname, $full_path_to_file)
152
+		{
153
+			if (is_readable($full_path_to_file)) {
154
+				require_once $full_path_to_file;
155
+			} else {
156
+				throw new \EE_Error (
157
+					sprintf(
158
+						esc_html__(
159
+							'The %s class file could not be located or is not readable due to file permissions.',
160
+							'event_espresso'
161
+						),
162
+						$classname
163
+					)
164
+				);
165
+			}
166
+		}
167 167
 
168
-        /**
169
-         * @since 4.9.27
170
-         * @throws \EE_Error
171
-         * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
172
-         * @throws \EventEspresso\core\exceptions\InvalidEntityException
173
-         * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
174
-         * @throws \EventEspresso\core\exceptions\InvalidClassException
175
-         * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
176
-         * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException
177
-         * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException
178
-         * @throws \OutOfBoundsException
179
-         */
180
-        function bootstrap_espresso()
181
-        {
182
-            require_once __DIR__ . '/core/espresso_definitions.php';
183
-            try {
184
-                espresso_load_error_handling();
185
-                espresso_load_required(
186
-                    'EEH_Base',
187
-                    EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
188
-                );
189
-                espresso_load_required(
190
-                    'EEH_File',
191
-                    EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
192
-                );
193
-                espresso_load_required(
194
-                    'EEH_File',
195
-                    EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
196
-                );
197
-                espresso_load_required(
198
-                    'EEH_Array',
199
-                    EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
200
-                );
201
-                // instantiate and configure PSR4 autoloader
202
-                espresso_load_required(
203
-                    'Psr4Autoloader',
204
-                    EE_CORE . 'Psr4Autoloader.php'
205
-                );
206
-                espresso_load_required(
207
-                    'EE_Psr4AutoloaderInit',
208
-                    EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
209
-                );
210
-                $AutoloaderInit = new EE_Psr4AutoloaderInit();
211
-                $AutoloaderInit->initializeAutoloader();
212
-                espresso_load_required(
213
-                    'EE_Request',
214
-                    EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
215
-                );
216
-                espresso_load_required(
217
-                    'EE_Response',
218
-                    EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
219
-                );
220
-                espresso_load_required(
221
-                    'EE_Bootstrap',
222
-                    EE_CORE . 'EE_Bootstrap.core.php'
223
-                );
224
-                // bootstrap EE and the request stack
225
-                new EE_Bootstrap(
226
-                    new EE_Request($_GET, $_POST, $_COOKIE),
227
-                    new EE_Response()
228
-                );
229
-            } catch (Exception $e) {
230
-                require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
231
-                new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
232
-            }
233
-        }
234
-        bootstrap_espresso();
235
-    }
168
+		/**
169
+		 * @since 4.9.27
170
+		 * @throws \EE_Error
171
+		 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
172
+		 * @throws \EventEspresso\core\exceptions\InvalidEntityException
173
+		 * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
174
+		 * @throws \EventEspresso\core\exceptions\InvalidClassException
175
+		 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
176
+		 * @throws \EventEspresso\core\services\container\exceptions\ServiceExistsException
177
+		 * @throws \EventEspresso\core\services\container\exceptions\ServiceNotFoundException
178
+		 * @throws \OutOfBoundsException
179
+		 */
180
+		function bootstrap_espresso()
181
+		{
182
+			require_once __DIR__ . '/core/espresso_definitions.php';
183
+			try {
184
+				espresso_load_error_handling();
185
+				espresso_load_required(
186
+					'EEH_Base',
187
+					EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'
188
+				);
189
+				espresso_load_required(
190
+					'EEH_File',
191
+					EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php'
192
+				);
193
+				espresso_load_required(
194
+					'EEH_File',
195
+					EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'
196
+				);
197
+				espresso_load_required(
198
+					'EEH_Array',
199
+					EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php'
200
+				);
201
+				// instantiate and configure PSR4 autoloader
202
+				espresso_load_required(
203
+					'Psr4Autoloader',
204
+					EE_CORE . 'Psr4Autoloader.php'
205
+				);
206
+				espresso_load_required(
207
+					'EE_Psr4AutoloaderInit',
208
+					EE_CORE . 'EE_Psr4AutoloaderInit.core.php'
209
+				);
210
+				$AutoloaderInit = new EE_Psr4AutoloaderInit();
211
+				$AutoloaderInit->initializeAutoloader();
212
+				espresso_load_required(
213
+					'EE_Request',
214
+					EE_CORE . 'request_stack' . DS . 'EE_Request.core.php'
215
+				);
216
+				espresso_load_required(
217
+					'EE_Response',
218
+					EE_CORE . 'request_stack' . DS . 'EE_Response.core.php'
219
+				);
220
+				espresso_load_required(
221
+					'EE_Bootstrap',
222
+					EE_CORE . 'EE_Bootstrap.core.php'
223
+				);
224
+				// bootstrap EE and the request stack
225
+				new EE_Bootstrap(
226
+					new EE_Request($_GET, $_POST, $_COOKIE),
227
+					new EE_Response()
228
+				);
229
+			} catch (Exception $e) {
230
+				require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php';
231
+				new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e);
232
+			}
233
+		}
234
+		bootstrap_espresso();
235
+	}
236 236
 }
237 237
 if (! function_exists('espresso_deactivate_plugin')) {
238
-    /**
239
-     *    deactivate_plugin
240
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
241
-     *
242
-     * @access public
243
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
244
-     * @return    void
245
-     */
246
-    function espresso_deactivate_plugin($plugin_basename = '')
247
-    {
248
-        if (! function_exists('deactivate_plugins')) {
249
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
250
-        }
251
-        unset($_GET['activate'], $_REQUEST['activate']);
252
-        deactivate_plugins($plugin_basename);
253
-    }
238
+	/**
239
+	 *    deactivate_plugin
240
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
241
+	 *
242
+	 * @access public
243
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
244
+	 * @return    void
245
+	 */
246
+	function espresso_deactivate_plugin($plugin_basename = '')
247
+	{
248
+		if (! function_exists('deactivate_plugins')) {
249
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
250
+		}
251
+		unset($_GET['activate'], $_REQUEST['activate']);
252
+		deactivate_plugins($plugin_basename);
253
+	}
254 254
 }
Please login to merge, or discard this patch.