Completed
Branch BUG-10878-event-spaces-remaini... (49b4f1)
by
unknown
53:16 queued 42:45
created
core/EE_Error.core.php 2 patches
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -98,14 +98,14 @@  discard block
 block discarded – undo
98 98
             default :
99 99
                 $to = get_option('admin_email');
100 100
         }
101
-        $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
101
+        $subject = $type.' '.$message.' in '.EVENT_ESPRESSO_VERSION.' on '.site_url();
102 102
         $msg = EE_Error::_format_error($type, $message, $file, $line);
103 103
         if (function_exists('wp_mail')) {
104 104
             add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
105 105
             wp_mail($to, $subject, $msg);
106 106
         }
107 107
         echo '<div id="message" class="espresso-notices error"><p>';
108
-        echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
108
+        echo $type.': '.$message.'<br />'.$file.' line '.$line;
109 109
         echo '<br /></p></div>';
110 110
     }
111 111
 
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
             ? true
255 255
             : false;
256 256
         if ($check_stored && ! $has_error) {
257
-            $notices = (array)get_option('ee_notices', array());
257
+            $notices = (array) get_option('ee_notices', array());
258 258
             foreach ($notices as $type => $notice) {
259 259
                 if ($type === $type_to_check && $notice) {
260 260
                     return true;
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 	}
332 332
 </style>
333 333
 <div id="ee-error-message" class="error">';
334
-        if (! WP_DEBUG) {
334
+        if ( ! WP_DEBUG) {
335 335
             $output .= '
336 336
 	<p>';
337 337
         }
@@ -383,14 +383,14 @@  discard block
 block discarded – undo
383 383
                     $class_dsply = ! empty($class) ? $class : '&nbsp;';
384 384
                     $type_dsply = ! empty($type) ? $type : '&nbsp;';
385 385
                     $function_dsply = ! empty($function) ? $function : '&nbsp;';
386
-                    $args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
386
+                    $args_dsply = ! empty($args) ? '( '.$args.' )' : '';
387 387
                     $trace_details .= '
388 388
 					<tr>
389
-						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
390
-						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
391
-						<td align="left" class="' . $zebra . '">' . $file_dsply . '</td>
392
-						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
393
-						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
389
+						<td align="right" class="' . $zebra.'">'.$nmbr_dsply.'</td>
390
+						<td align="right" class="' . $zebra.'">'.$line_dsply.'</td>
391
+						<td align="left" class="' . $zebra.'">'.$file_dsply.'</td>
392
+						<td align="left" class="' . $zebra.'">'.$class_dsply.'</td>
393
+						<td align="left" class="' . $zebra.'">'.$type_dsply.$function_dsply.$args_dsply.'</td>
394 394
 					</tr>';
395 395
                 }
396 396
                 $trace_details .= '
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
             }
400 400
             $ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
401 401
             // add generic non-identifying messages for non-privileged users
402
-            if (! WP_DEBUG) {
402
+            if ( ! WP_DEBUG) {
403 403
                 $output .= '<span class="ee-error-user-msg-spn">'
404 404
                            . trim($ex['msg'])
405 405
                            . '</span> &nbsp; <sup>'
@@ -441,14 +441,14 @@  discard block
 block discarded – undo
441 441
                            . '-dv" class="ee-error-trace-dv" style="display: none;">
442 442
 				'
443 443
                            . $trace_details;
444
-                if (! empty($class)) {
444
+                if ( ! empty($class)) {
445 445
                     $output .= '
446 446
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
447 447
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
448 448
 						<h3>Class Details</h3>';
449 449
                     $a = new ReflectionClass($class);
450 450
                     $output .= '
451
-						<pre>' . $a . '</pre>
451
+						<pre>' . $a.'</pre>
452 452
 					</div>
453 453
 				</div>';
454 454
                 }
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
         }
462 462
         // remove last linebreak
463 463
         $output = substr($output, 0, -6);
464
-        if (! WP_DEBUG) {
464
+        if ( ! WP_DEBUG) {
465 465
             $output .= '
466 466
 	</p>';
467 467
         }
@@ -488,20 +488,20 @@  discard block
 block discarded – undo
488 488
     private function _convert_args_to_string($arguments = array(), $array = false)
489 489
     {
490 490
         $arg_string = '';
491
-        if (! empty($arguments)) {
491
+        if ( ! empty($arguments)) {
492 492
             $args = array();
493 493
             foreach ($arguments as $arg) {
494
-                if (! empty($arg)) {
494
+                if ( ! empty($arg)) {
495 495
                     if (is_string($arg)) {
496
-                        $args[] = " '" . $arg . "'";
496
+                        $args[] = " '".$arg."'";
497 497
                     } elseif (is_array($arg)) {
498
-                        $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
498
+                        $args[] = 'ARRAY('.$this->_convert_args_to_string($arg, true);
499 499
                     } elseif ($arg === null) {
500 500
                         $args[] = ' NULL';
501 501
                     } elseif (is_bool($arg)) {
502 502
                         $args[] = ($arg) ? ' TRUE' : ' FALSE';
503 503
                     } elseif (is_object($arg)) {
504
-                        $args[] = ' OBJECT ' . get_class($arg);
504
+                        $args[] = ' OBJECT '.get_class($arg);
505 505
                     } elseif (is_resource($arg)) {
506 506
                         $args[] = get_resource_type($arg);
507 507
                     } else {
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
     {
607 607
         if (empty($msg)) {
608 608
             EE_Error::doing_it_wrong(
609
-                'EE_Error::add_' . $type . '()',
609
+                'EE_Error::add_'.$type.'()',
610 610
                 sprintf(
611 611
                     __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
612 612
                         'event_espresso'),
@@ -642,11 +642,11 @@  discard block
 block discarded – undo
642 642
         do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
643 643
         $msg = WP_DEBUG ? $dev_msg : $user_msg;
644 644
         // add notice if message exists
645
-        if (! empty($msg)) {
645
+        if ( ! empty($msg)) {
646 646
             // get error code
647 647
             $notice_code = EE_Error::generate_error_code($file, $func, $line);
648 648
             if (WP_DEBUG && $type === 'errors') {
649
-                $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
649
+                $msg .= '<br/><span class="tiny-text">'.$notice_code.'</span>';
650 650
             }
651 651
             // add notice. Index by code if it's not blank
652 652
             if ($notice_code) {
@@ -890,14 +890,14 @@  discard block
 block discarded – undo
890 890
      */
891 891
     public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
892 892
     {
893
-        if (! empty($pan_name) && ! empty($pan_message)) {
893
+        if ( ! empty($pan_name) && ! empty($pan_message)) {
894 894
             $persistent_admin_notices = get_option('ee_pers_admin_notices', array());
895 895
             //maybe initialize persistent_admin_notices
896 896
             if (empty($persistent_admin_notices)) {
897 897
                 add_option('ee_pers_admin_notices', array(), '', 'no');
898 898
             }
899 899
             $pan_name = sanitize_key($pan_name);
900
-            if (! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) {
900
+            if ( ! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) {
901 901
                 $persistent_admin_notices[$pan_name] = $pan_message;
902 902
                 update_option('ee_pers_admin_notices', $persistent_admin_notices);
903 903
             }
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
     {
919 919
         $pan_name = EE_Registry::instance()->REQ->is_set('ee_nag_notice')
920 920
             ? EE_Registry::instance()->REQ->get('ee_nag_notice') : $pan_name;
921
-        if (! empty($pan_name)) {
921
+        if ( ! empty($pan_name)) {
922 922
             $persistent_admin_notices = get_option('ee_pers_admin_notices', array());
923 923
             // check if notice we wish to dismiss is actually in the $persistent_admin_notices array
924 924
             if (is_array($persistent_admin_notices) && isset($persistent_admin_notices[$pan_name])) {
@@ -961,7 +961,7 @@  discard block
 block discarded – undo
961 961
      */
962 962
     public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
963 963
     {
964
-        if (! empty($pan_name) && ! empty($pan_message)) {
964
+        if ( ! empty($pan_name) && ! empty($pan_message)) {
965 965
             $args = array(
966 966
                 'nag_notice'    => $pan_name,
967 967
                 'return_url'    => urlencode($return_url),
@@ -1013,14 +1013,14 @@  discard block
 block discarded – undo
1013 1013
             // load scripts
1014 1014
             wp_register_script(
1015 1015
                 'espresso_core',
1016
-                EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1016
+                EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
1017 1017
                 array('jquery'),
1018 1018
                 EVENT_ESPRESSO_VERSION,
1019 1019
                 true
1020 1020
             );
1021 1021
             wp_register_script(
1022 1022
                 'ee_error_js',
1023
-                EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1023
+                EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js',
1024 1024
                 array('espresso_core'),
1025 1025
                 EVENT_ESPRESSO_VERSION,
1026 1026
                 true
@@ -1044,7 +1044,7 @@  discard block
 block discarded – undo
1044 1044
      */
1045 1045
     private static function _print_scripts($force_print = false)
1046 1046
     {
1047
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1047
+        if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1048 1048
             if (wp_script_is('ee_error_js', 'enqueued')) {
1049 1049
                 return '';
1050 1050
             }
@@ -1058,12 +1058,12 @@  discard block
 block discarded – undo
1058 1058
             return '
1059 1059
 <script>
1060 1060
 /* <![CDATA[ */
1061
-var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
1061
+var ee_settings = {"wp_debug":"' . WP_DEBUG.'"};
1062 1062
 /* ]]> */
1063 1063
 </script>
1064
-<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script>
1065
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1066
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1064
+<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script>
1065
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
1066
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
1067 1067
 ';
1068 1068
         }
1069 1069
         return '';
@@ -1096,8 +1096,8 @@  discard block
 block discarded – undo
1096 1096
     {
1097 1097
         $file = explode('.', basename($file));
1098 1098
         $error_code = ! empty($file[0]) ? $file[0] : '';
1099
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
1100
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
1099
+        $error_code .= ! empty($func) ? ' - '.$func : '';
1100
+        $error_code .= ! empty($line) ? ' - '.$line : '';
1101 1101
         return $error_code;
1102 1102
     }
1103 1103
 
@@ -1116,33 +1116,33 @@  discard block
 block discarded – undo
1116 1116
         if (empty($ex)) {
1117 1117
             return;
1118 1118
         }
1119
-        if (! $time) {
1119
+        if ( ! $time) {
1120 1120
             $time = time();
1121 1121
         }
1122 1122
         $exception_log = '----------------------------------------------------------------------------------------'
1123 1123
                          . PHP_EOL;
1124
-        $exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1125
-        $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1126
-        $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1127
-        $exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1128
-        $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1129
-        $exception_log .= 'Stack trace: ' . PHP_EOL;
1130
-        $exception_log .= $ex['string'] . PHP_EOL;
1124
+        $exception_log .= '['.date('Y-m-d H:i:s', $time).']  Exception Details'.PHP_EOL;
1125
+        $exception_log .= 'Message: '.$ex['msg'].PHP_EOL;
1126
+        $exception_log .= 'Code: '.$ex['code'].PHP_EOL;
1127
+        $exception_log .= 'File: '.$ex['file'].PHP_EOL;
1128
+        $exception_log .= 'Line No: '.$ex['line'].PHP_EOL;
1129
+        $exception_log .= 'Stack trace: '.PHP_EOL;
1130
+        $exception_log .= $ex['string'].PHP_EOL;
1131 1131
         $exception_log .= '----------------------------------------------------------------------------------------'
1132 1132
                           . PHP_EOL;
1133 1133
         try {
1134 1134
             EEH_File::ensure_file_exists_and_is_writable(
1135
-                EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1135
+                EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file
1136 1136
             );
1137
-            EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs');
1138
-            if (! $clear) {
1137
+            EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR.'logs');
1138
+            if ( ! $clear) {
1139 1139
                 //get existing log file and append new log info
1140 1140
                 $exception_log = EEH_File::get_file_contents(
1141
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1142
-                ) . $exception_log;
1141
+                    EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file
1142
+                ).$exception_log;
1143 1143
             }
1144 1144
             EEH_File::write_to_file(
1145
-                EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file,
1145
+                EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.self::$_exception_log_file,
1146 1146
                 $exception_log
1147 1147
             );
1148 1148
         } catch (EE_Error $e) {
@@ -1220,14 +1220,14 @@  discard block
 block discarded – undo
1220 1220
     // js for error handling
1221 1221
     wp_register_script(
1222 1222
         'espresso_core',
1223
-        EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1223
+        EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
1224 1224
         array('jquery'),
1225 1225
         EVENT_ESPRESSO_VERSION,
1226 1226
         false
1227 1227
     );
1228 1228
     wp_register_script(
1229 1229
         'ee_error_js',
1230
-        EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1230
+        EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js',
1231 1231
         array('espresso_core'),
1232 1232
         EVENT_ESPRESSO_VERSION,
1233 1233
         false
Please login to merge, or discard this patch.
Indentation   +1095 added lines, -1095 removed lines patch added patch discarded remove patch
@@ -5,8 +5,8 @@  discard block
 block discarded – undo
5 5
 // if you're a dev and want to receive all errors via email
6 6
 // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE );
7 7
 if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) {
8
-    set_error_handler(array('EE_Error', 'error_handler'));
9
-    register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
8
+	set_error_handler(array('EE_Error', 'error_handler'));
9
+	register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
10 10
 }
11 11
 
12 12
 
@@ -23,259 +23,259 @@  discard block
 block discarded – undo
23 23
 {
24 24
 
25 25
 
26
-    /**
27
-     *    name of the file to log exceptions to
28
-     *
29
-     * @var string
30
-     */
31
-    private static $_exception_log_file = 'espresso_error_log.txt';
32
-
33
-    /**
34
-     *    stores details for all exception
35
-     *
36
-     * @var array
37
-     */
38
-    private static $_all_exceptions = array();
39
-
40
-    /**
41
-     *    tracks number of errors
42
-     *
43
-     * @var int
44
-     */
45
-    private static $_error_count = 0;
46
-
47
-    /**
48
-     *    has shutdown action been added ?
49
-     *
50
-     * @var array $_espresso_notices
51
-     */
52
-    private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
53
-
54
-
55
-
56
-    /**
57
-     * @override default exception handling
58
-     * @param string         $message
59
-     * @param int            $code
60
-     * @param Exception|null $previous
61
-     */
62
-    public function __construct($message, $code = 0, Exception $previous = null)
63
-    {
64
-        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
65
-            parent::__construct($message, $code);
66
-        } else {
67
-            parent::__construct($message, $code, $previous);
68
-        }
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     *    error_handler
75
-     *
76
-     * @param $code
77
-     * @param $message
78
-     * @param $file
79
-     * @param $line
80
-     * @return void
81
-     */
82
-    public static function error_handler($code, $message, $file, $line)
83
-    {
84
-        $type = EE_Error::error_type($code);
85
-        $site = site_url();
86
-        switch ($site) {
87
-            case 'http://ee4.eventespresso.com/' :
88
-            case 'http://ee4decaf.eventespresso.com/' :
89
-            case 'http://ee4hf.eventespresso.com/' :
90
-            case 'http://ee4a.eventespresso.com/' :
91
-            case 'http://ee4ad.eventespresso.com/' :
92
-            case 'http://ee4b.eventespresso.com/' :
93
-            case 'http://ee4bd.eventespresso.com/' :
94
-            case 'http://ee4d.eventespresso.com/' :
95
-            case 'http://ee4dd.eventespresso.com/' :
96
-                $to = '[email protected]';
97
-                break;
98
-            default :
99
-                $to = get_option('admin_email');
100
-        }
101
-        $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
102
-        $msg = EE_Error::_format_error($type, $message, $file, $line);
103
-        if (function_exists('wp_mail')) {
104
-            add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
105
-            wp_mail($to, $subject, $msg);
106
-        }
107
-        echo '<div id="message" class="espresso-notices error"><p>';
108
-        echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
109
-        echo '<br /></p></div>';
110
-    }
111
-
112
-
113
-
114
-    /**
115
-     * error_type
116
-     * http://www.php.net/manual/en/errorfunc.constants.php#109430
117
-     *
118
-     * @param $code
119
-     * @return string
120
-     */
121
-    public static function error_type($code)
122
-    {
123
-        switch ($code) {
124
-            case E_ERROR: // 1 //
125
-                return 'E_ERROR';
126
-            case E_WARNING: // 2 //
127
-                return 'E_WARNING';
128
-            case E_PARSE: // 4 //
129
-                return 'E_PARSE';
130
-            case E_NOTICE: // 8 //
131
-                return 'E_NOTICE';
132
-            case E_CORE_ERROR: // 16 //
133
-                return 'E_CORE_ERROR';
134
-            case E_CORE_WARNING: // 32 //
135
-                return 'E_CORE_WARNING';
136
-            case E_COMPILE_ERROR: // 64 //
137
-                return 'E_COMPILE_ERROR';
138
-            case E_COMPILE_WARNING: // 128 //
139
-                return 'E_COMPILE_WARNING';
140
-            case E_USER_ERROR: // 256 //
141
-                return 'E_USER_ERROR';
142
-            case E_USER_WARNING: // 512 //
143
-                return 'E_USER_WARNING';
144
-            case E_USER_NOTICE: // 1024 //
145
-                return 'E_USER_NOTICE';
146
-            case E_STRICT: // 2048 //
147
-                return 'E_STRICT';
148
-            case E_RECOVERABLE_ERROR: // 4096 //
149
-                return 'E_RECOVERABLE_ERROR';
150
-            case E_DEPRECATED: // 8192 //
151
-                return 'E_DEPRECATED';
152
-            case E_USER_DEPRECATED: // 16384 //
153
-                return 'E_USER_DEPRECATED';
154
-            case E_ALL: // 16384 //
155
-                return 'E_ALL';
156
-        }
157
-        return '';
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     *    fatal_error_handler
164
-     *
165
-     * @return void
166
-     */
167
-    public static function fatal_error_handler()
168
-    {
169
-        $last_error = error_get_last();
170
-        if ($last_error['type'] === E_ERROR) {
171
-            EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
172
-        }
173
-    }
174
-
175
-
176
-
177
-    /**
178
-     * _format_error
179
-     *
180
-     * @param $code
181
-     * @param $message
182
-     * @param $file
183
-     * @param $line
184
-     * @return string
185
-     */
186
-    private static function _format_error($code, $message, $file, $line)
187
-    {
188
-        $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
189
-        $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
190
-        $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
191
-        $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>";
192
-        $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>";
193
-        $html .= '</tbody></table>';
194
-        return $html;
195
-    }
196
-
197
-
198
-
199
-    /**
200
-     * set_content_type
201
-     *
202
-     * @param $content_type
203
-     * @return string
204
-     */
205
-    public static function set_content_type($content_type)
206
-    {
207
-        return 'text/html';
208
-    }
209
-
210
-
211
-
212
-    /**
213
-     * @return void
214
-     * @throws EE_Error
215
-     * @throws ReflectionException
216
-     */
217
-    public function get_error()
218
-    {
219
-        if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
220
-            throw $this;
221
-        }
222
-        // get separate user and developer messages if they exist
223
-        $msg = explode('||', $this->getMessage());
224
-        $user_msg = $msg[0];
225
-        $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
226
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
227
-        // add details to _all_exceptions array
228
-        $x_time = time();
229
-        self::$_all_exceptions[$x_time]['name'] = get_class($this);
230
-        self::$_all_exceptions[$x_time]['file'] = $this->getFile();
231
-        self::$_all_exceptions[$x_time]['line'] = $this->getLine();
232
-        self::$_all_exceptions[$x_time]['msg'] = $msg;
233
-        self::$_all_exceptions[$x_time]['code'] = $this->getCode();
234
-        self::$_all_exceptions[$x_time]['trace'] = $this->getTrace();
235
-        self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
236
-        self::$_error_count++;
237
-        //add_action( 'shutdown', array( $this, 'display_errors' ));
238
-        $this->display_errors();
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     *    has_error
245
-     *
246
-     * @param bool   $check_stored
247
-     * @param string $type_to_check
248
-     * @return bool
249
-     */
250
-    public static function has_error($check_stored = false, $type_to_check = 'errors')
251
-    {
252
-        $has_error = isset(self::$_espresso_notices[$type_to_check])
253
-                     && ! empty(self::$_espresso_notices[$type_to_check])
254
-            ? true
255
-            : false;
256
-        if ($check_stored && ! $has_error) {
257
-            $notices = (array)get_option('ee_notices', array());
258
-            foreach ($notices as $type => $notice) {
259
-                if ($type === $type_to_check && $notice) {
260
-                    return true;
261
-                }
262
-            }
263
-        }
264
-        return $has_error;
265
-    }
266
-
267
-
268
-
269
-    /**
270
-     *    display_errors
271
-     *
272
-     * @echo   string
273
-     * @throws \ReflectionException
274
-     */
275
-    public function display_errors()
276
-    {
277
-        $trace_details = '';
278
-        $output = '
26
+	/**
27
+	 *    name of the file to log exceptions to
28
+	 *
29
+	 * @var string
30
+	 */
31
+	private static $_exception_log_file = 'espresso_error_log.txt';
32
+
33
+	/**
34
+	 *    stores details for all exception
35
+	 *
36
+	 * @var array
37
+	 */
38
+	private static $_all_exceptions = array();
39
+
40
+	/**
41
+	 *    tracks number of errors
42
+	 *
43
+	 * @var int
44
+	 */
45
+	private static $_error_count = 0;
46
+
47
+	/**
48
+	 *    has shutdown action been added ?
49
+	 *
50
+	 * @var array $_espresso_notices
51
+	 */
52
+	private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
53
+
54
+
55
+
56
+	/**
57
+	 * @override default exception handling
58
+	 * @param string         $message
59
+	 * @param int            $code
60
+	 * @param Exception|null $previous
61
+	 */
62
+	public function __construct($message, $code = 0, Exception $previous = null)
63
+	{
64
+		if (version_compare(PHP_VERSION, '5.3.0', '<')) {
65
+			parent::__construct($message, $code);
66
+		} else {
67
+			parent::__construct($message, $code, $previous);
68
+		}
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 *    error_handler
75
+	 *
76
+	 * @param $code
77
+	 * @param $message
78
+	 * @param $file
79
+	 * @param $line
80
+	 * @return void
81
+	 */
82
+	public static function error_handler($code, $message, $file, $line)
83
+	{
84
+		$type = EE_Error::error_type($code);
85
+		$site = site_url();
86
+		switch ($site) {
87
+			case 'http://ee4.eventespresso.com/' :
88
+			case 'http://ee4decaf.eventespresso.com/' :
89
+			case 'http://ee4hf.eventespresso.com/' :
90
+			case 'http://ee4a.eventespresso.com/' :
91
+			case 'http://ee4ad.eventespresso.com/' :
92
+			case 'http://ee4b.eventespresso.com/' :
93
+			case 'http://ee4bd.eventespresso.com/' :
94
+			case 'http://ee4d.eventespresso.com/' :
95
+			case 'http://ee4dd.eventespresso.com/' :
96
+				$to = '[email protected]';
97
+				break;
98
+			default :
99
+				$to = get_option('admin_email');
100
+		}
101
+		$subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
102
+		$msg = EE_Error::_format_error($type, $message, $file, $line);
103
+		if (function_exists('wp_mail')) {
104
+			add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
105
+			wp_mail($to, $subject, $msg);
106
+		}
107
+		echo '<div id="message" class="espresso-notices error"><p>';
108
+		echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
109
+		echo '<br /></p></div>';
110
+	}
111
+
112
+
113
+
114
+	/**
115
+	 * error_type
116
+	 * http://www.php.net/manual/en/errorfunc.constants.php#109430
117
+	 *
118
+	 * @param $code
119
+	 * @return string
120
+	 */
121
+	public static function error_type($code)
122
+	{
123
+		switch ($code) {
124
+			case E_ERROR: // 1 //
125
+				return 'E_ERROR';
126
+			case E_WARNING: // 2 //
127
+				return 'E_WARNING';
128
+			case E_PARSE: // 4 //
129
+				return 'E_PARSE';
130
+			case E_NOTICE: // 8 //
131
+				return 'E_NOTICE';
132
+			case E_CORE_ERROR: // 16 //
133
+				return 'E_CORE_ERROR';
134
+			case E_CORE_WARNING: // 32 //
135
+				return 'E_CORE_WARNING';
136
+			case E_COMPILE_ERROR: // 64 //
137
+				return 'E_COMPILE_ERROR';
138
+			case E_COMPILE_WARNING: // 128 //
139
+				return 'E_COMPILE_WARNING';
140
+			case E_USER_ERROR: // 256 //
141
+				return 'E_USER_ERROR';
142
+			case E_USER_WARNING: // 512 //
143
+				return 'E_USER_WARNING';
144
+			case E_USER_NOTICE: // 1024 //
145
+				return 'E_USER_NOTICE';
146
+			case E_STRICT: // 2048 //
147
+				return 'E_STRICT';
148
+			case E_RECOVERABLE_ERROR: // 4096 //
149
+				return 'E_RECOVERABLE_ERROR';
150
+			case E_DEPRECATED: // 8192 //
151
+				return 'E_DEPRECATED';
152
+			case E_USER_DEPRECATED: // 16384 //
153
+				return 'E_USER_DEPRECATED';
154
+			case E_ALL: // 16384 //
155
+				return 'E_ALL';
156
+		}
157
+		return '';
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 *    fatal_error_handler
164
+	 *
165
+	 * @return void
166
+	 */
167
+	public static function fatal_error_handler()
168
+	{
169
+		$last_error = error_get_last();
170
+		if ($last_error['type'] === E_ERROR) {
171
+			EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
172
+		}
173
+	}
174
+
175
+
176
+
177
+	/**
178
+	 * _format_error
179
+	 *
180
+	 * @param $code
181
+	 * @param $message
182
+	 * @param $file
183
+	 * @param $line
184
+	 * @return string
185
+	 */
186
+	private static function _format_error($code, $message, $file, $line)
187
+	{
188
+		$html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
189
+		$html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
190
+		$html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
191
+		$html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>";
192
+		$html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>";
193
+		$html .= '</tbody></table>';
194
+		return $html;
195
+	}
196
+
197
+
198
+
199
+	/**
200
+	 * set_content_type
201
+	 *
202
+	 * @param $content_type
203
+	 * @return string
204
+	 */
205
+	public static function set_content_type($content_type)
206
+	{
207
+		return 'text/html';
208
+	}
209
+
210
+
211
+
212
+	/**
213
+	 * @return void
214
+	 * @throws EE_Error
215
+	 * @throws ReflectionException
216
+	 */
217
+	public function get_error()
218
+	{
219
+		if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
220
+			throw $this;
221
+		}
222
+		// get separate user and developer messages if they exist
223
+		$msg = explode('||', $this->getMessage());
224
+		$user_msg = $msg[0];
225
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
226
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
227
+		// add details to _all_exceptions array
228
+		$x_time = time();
229
+		self::$_all_exceptions[$x_time]['name'] = get_class($this);
230
+		self::$_all_exceptions[$x_time]['file'] = $this->getFile();
231
+		self::$_all_exceptions[$x_time]['line'] = $this->getLine();
232
+		self::$_all_exceptions[$x_time]['msg'] = $msg;
233
+		self::$_all_exceptions[$x_time]['code'] = $this->getCode();
234
+		self::$_all_exceptions[$x_time]['trace'] = $this->getTrace();
235
+		self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
236
+		self::$_error_count++;
237
+		//add_action( 'shutdown', array( $this, 'display_errors' ));
238
+		$this->display_errors();
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 *    has_error
245
+	 *
246
+	 * @param bool   $check_stored
247
+	 * @param string $type_to_check
248
+	 * @return bool
249
+	 */
250
+	public static function has_error($check_stored = false, $type_to_check = 'errors')
251
+	{
252
+		$has_error = isset(self::$_espresso_notices[$type_to_check])
253
+					 && ! empty(self::$_espresso_notices[$type_to_check])
254
+			? true
255
+			: false;
256
+		if ($check_stored && ! $has_error) {
257
+			$notices = (array)get_option('ee_notices', array());
258
+			foreach ($notices as $type => $notice) {
259
+				if ($type === $type_to_check && $notice) {
260
+					return true;
261
+				}
262
+			}
263
+		}
264
+		return $has_error;
265
+	}
266
+
267
+
268
+
269
+	/**
270
+	 *    display_errors
271
+	 *
272
+	 * @echo   string
273
+	 * @throws \ReflectionException
274
+	 */
275
+	public function display_errors()
276
+	{
277
+		$trace_details = '';
278
+		$output = '
279 279
 <style type="text/css">
280 280
 	#ee-error-message {
281 281
 		max-width:90% !important;
@@ -331,19 +331,19 @@  discard block
 block discarded – undo
331 331
 	}
332 332
 </style>
333 333
 <div id="ee-error-message" class="error">';
334
-        if (! WP_DEBUG) {
335
-            $output .= '
334
+		if (! WP_DEBUG) {
335
+			$output .= '
336 336
 	<p>';
337
-        }
338
-        // cycle thru errors
339
-        foreach (self::$_all_exceptions as $time => $ex) {
340
-            $error_code = '';
341
-            // process trace info
342
-            if (empty($ex['trace'])) {
343
-                $trace_details .= __('Sorry, but no trace information was available for this exception.',
344
-                    'event_espresso');
345
-            } else {
346
-                $trace_details .= '
337
+		}
338
+		// cycle thru errors
339
+		foreach (self::$_all_exceptions as $time => $ex) {
340
+			$error_code = '';
341
+			// process trace info
342
+			if (empty($ex['trace'])) {
343
+				$trace_details .= __('Sorry, but no trace information was available for this exception.',
344
+					'event_espresso');
345
+			} else {
346
+				$trace_details .= '
347 347
 			<div id="ee-trace-details">
348 348
 			<table width="100%" border="0" cellpadding="5" cellspacing="0">
349 349
 				<tr>
@@ -353,43 +353,43 @@  discard block
 block discarded – undo
353 353
 					<th scope="col" align="left">Class</th>
354 354
 					<th scope="col" align="left">Method( arguments )</th>
355 355
 				</tr>';
356
-                $last_on_stack = count($ex['trace']) - 1;
357
-                // reverse array so that stack is in proper chronological order
358
-                $sorted_trace = array_reverse($ex['trace']);
359
-                foreach ($sorted_trace as $nmbr => $trace) {
360
-                    $file = isset($trace['file']) ? $trace['file'] : '';
361
-                    $class = isset($trace['class']) ? $trace['class'] : '';
362
-                    $type = isset($trace['type']) ? $trace['type'] : '';
363
-                    $function = isset($trace['function']) ? $trace['function'] : '';
364
-                    $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
365
-                    $line = isset($trace['line']) ? $trace['line'] : '';
366
-                    $zebra = ($nmbr % 2) ? ' odd' : '';
367
-                    if (empty($file) && ! empty($class)) {
368
-                        $a = new ReflectionClass($class);
369
-                        $file = $a->getFileName();
370
-                        if (empty($line) && ! empty($function)) {
371
-                            try {
372
-                                //if $function is a closure, this throws an exception
373
-                                $b = new ReflectionMethod($class, $function);
374
-                                $line = $b->getStartLine();
375
-                            } catch (Exception $closure_exception) {
376
-                                $line = 'unknown';
377
-                            }
378
-                        }
379
-                    }
380
-                    if ($nmbr === $last_on_stack) {
381
-                        $file = $ex['file'] !== '' ? $ex['file'] : $file;
382
-                        $line = $ex['line'] !== '' ? $ex['line'] : $line;
383
-                        $error_code = self::generate_error_code($file, $trace['function'], $line);
384
-                    }
385
-                    $nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
386
-                    $line_dsply = ! empty($line) ? $line : '&nbsp;';
387
-                    $file_dsply = ! empty($file) ? $file : '&nbsp;';
388
-                    $class_dsply = ! empty($class) ? $class : '&nbsp;';
389
-                    $type_dsply = ! empty($type) ? $type : '&nbsp;';
390
-                    $function_dsply = ! empty($function) ? $function : '&nbsp;';
391
-                    $args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
392
-                    $trace_details .= '
356
+				$last_on_stack = count($ex['trace']) - 1;
357
+				// reverse array so that stack is in proper chronological order
358
+				$sorted_trace = array_reverse($ex['trace']);
359
+				foreach ($sorted_trace as $nmbr => $trace) {
360
+					$file = isset($trace['file']) ? $trace['file'] : '';
361
+					$class = isset($trace['class']) ? $trace['class'] : '';
362
+					$type = isset($trace['type']) ? $trace['type'] : '';
363
+					$function = isset($trace['function']) ? $trace['function'] : '';
364
+					$args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
365
+					$line = isset($trace['line']) ? $trace['line'] : '';
366
+					$zebra = ($nmbr % 2) ? ' odd' : '';
367
+					if (empty($file) && ! empty($class)) {
368
+						$a = new ReflectionClass($class);
369
+						$file = $a->getFileName();
370
+						if (empty($line) && ! empty($function)) {
371
+							try {
372
+								//if $function is a closure, this throws an exception
373
+								$b = new ReflectionMethod($class, $function);
374
+								$line = $b->getStartLine();
375
+							} catch (Exception $closure_exception) {
376
+								$line = 'unknown';
377
+							}
378
+						}
379
+					}
380
+					if ($nmbr === $last_on_stack) {
381
+						$file = $ex['file'] !== '' ? $ex['file'] : $file;
382
+						$line = $ex['line'] !== '' ? $ex['line'] : $line;
383
+						$error_code = self::generate_error_code($file, $trace['function'], $line);
384
+					}
385
+					$nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
386
+					$line_dsply = ! empty($line) ? $line : '&nbsp;';
387
+					$file_dsply = ! empty($file) ? $file : '&nbsp;';
388
+					$class_dsply = ! empty($class) ? $class : '&nbsp;';
389
+					$type_dsply = ! empty($type) ? $type : '&nbsp;';
390
+					$function_dsply = ! empty($function) ? $function : '&nbsp;';
391
+					$args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
392
+					$trace_details .= '
393 393
 					<tr>
394 394
 						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
395 395
 						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
@@ -397,674 +397,674 @@  discard block
 block discarded – undo
397 397
 						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
398 398
 						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
399 399
 					</tr>';
400
-                }
401
-                $trace_details .= '
400
+				}
401
+				$trace_details .= '
402 402
 			 </table>
403 403
 			</div>';
404
-            }
405
-            $ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
406
-            // add generic non-identifying messages for non-privileged users
407
-            if (! WP_DEBUG) {
408
-                $output .= '<span class="ee-error-user-msg-spn">'
409
-                           . trim($ex['msg'])
410
-                           . '</span> &nbsp; <sup>'
411
-                           . $ex['code']
412
-                           . '</sup><br />';
413
-            } else {
414
-                // or helpful developer messages if debugging is on
415
-                $output .= '
404
+			}
405
+			$ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
406
+			// add generic non-identifying messages for non-privileged users
407
+			if (! WP_DEBUG) {
408
+				$output .= '<span class="ee-error-user-msg-spn">'
409
+						   . trim($ex['msg'])
410
+						   . '</span> &nbsp; <sup>'
411
+						   . $ex['code']
412
+						   . '</sup><br />';
413
+			} else {
414
+				// or helpful developer messages if debugging is on
415
+				$output .= '
416 416
 		<div class="ee-error-dev-msg-dv">
417 417
 			<p class="ee-error-dev-msg-pg">
418 418
 				<strong class="ee-error-dev-msg-str">An '
419
-                           . $ex['name']
420
-                           . ' exception was thrown!</strong>  &nbsp; <span>code: '
421
-                           . $ex['code']
422
-                           . '</span><br />
419
+						   . $ex['name']
420
+						   . ' exception was thrown!</strong>  &nbsp; <span>code: '
421
+						   . $ex['code']
422
+						   . '</span><br />
423 423
 				<span class="big-text">"'
424
-                           . trim($ex['msg'])
425
-                           . '"</span><br/>
424
+						   . trim($ex['msg'])
425
+						   . '"</span><br/>
426 426
 				<a id="display-ee-error-trace-'
427
-                           . self::$_error_count
428
-                           . $time
429
-                           . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
430
-                           . self::$_error_count
431
-                           . $time
432
-                           . '">
427
+						   . self::$_error_count
428
+						   . $time
429
+						   . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
430
+						   . self::$_error_count
431
+						   . $time
432
+						   . '">
433 433
 					'
434
-                           . __('click to view backtrace and class/method details', 'event_espresso')
435
-                           . '
434
+						   . __('click to view backtrace and class/method details', 'event_espresso')
435
+						   . '
436 436
 				</a><br />
437 437
 				<span class="small-text lt-grey-text">'
438
-                           . $ex['file']
439
-                           . ' &nbsp; ( line no: '
440
-                           . $ex['line']
441
-                           . ' )</span>
438
+						   . $ex['file']
439
+						   . ' &nbsp; ( line no: '
440
+						   . $ex['line']
441
+						   . ' )</span>
442 442
 			</p>
443 443
 			<div id="ee-error-trace-'
444
-                           . self::$_error_count
445
-                           . $time
446
-                           . '-dv" class="ee-error-trace-dv" style="display: none;">
444
+						   . self::$_error_count
445
+						   . $time
446
+						   . '-dv" class="ee-error-trace-dv" style="display: none;">
447 447
 				'
448
-                           . $trace_details;
449
-                if (! empty($class)) {
450
-                    $output .= '
448
+						   . $trace_details;
449
+				if (! empty($class)) {
450
+					$output .= '
451 451
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
452 452
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
453 453
 						<h3>Class Details</h3>';
454
-                    $a = new ReflectionClass($class);
455
-                    $output .= '
454
+					$a = new ReflectionClass($class);
455
+					$output .= '
456 456
 						<pre>' . $a . '</pre>
457 457
 					</div>
458 458
 				</div>';
459
-                }
460
-                $output .= '
459
+				}
460
+				$output .= '
461 461
 			</div>
462 462
 		</div>
463 463
 		<br />';
464
-            }
465
-            $this->write_to_error_log($time, $ex);
466
-        }
467
-        // remove last linebreak
468
-        $output = substr($output, 0, -6);
469
-        if (! WP_DEBUG) {
470
-            $output .= '
464
+			}
465
+			$this->write_to_error_log($time, $ex);
466
+		}
467
+		// remove last linebreak
468
+		$output = substr($output, 0, -6);
469
+		if (! WP_DEBUG) {
470
+			$output .= '
471 471
 	</p>';
472
-        }
473
-        $output .= '
472
+		}
473
+		$output .= '
474 474
 </div>';
475
-        $output .= self::_print_scripts(true);
476
-        if (defined('DOING_AJAX')) {
477
-            echo wp_json_encode(array('error' => $output));
478
-            exit();
479
-        }
480
-        echo $output;
481
-        die();
482
-    }
483
-
484
-
485
-
486
-    /**
487
-     *    generate string from exception trace args
488
-     *
489
-     * @param array $arguments
490
-     * @param bool  $array
491
-     * @return string
492
-     */
493
-    private function _convert_args_to_string($arguments = array(), $array = false)
494
-    {
495
-        $arg_string = '';
496
-        if (! empty($arguments)) {
497
-            $args = array();
498
-            foreach ($arguments as $arg) {
499
-                if (! empty($arg)) {
500
-                    if (is_string($arg)) {
501
-                        $args[] = " '" . $arg . "'";
502
-                    } elseif (is_array($arg)) {
503
-                        $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
504
-                    } elseif ($arg === null) {
505
-                        $args[] = ' NULL';
506
-                    } elseif (is_bool($arg)) {
507
-                        $args[] = ($arg) ? ' TRUE' : ' FALSE';
508
-                    } elseif (is_object($arg)) {
509
-                        $args[] = ' OBJECT ' . get_class($arg);
510
-                    } elseif (is_resource($arg)) {
511
-                        $args[] = get_resource_type($arg);
512
-                    } else {
513
-                        $args[] = $arg;
514
-                    }
515
-                }
516
-            }
517
-            $arg_string = implode(', ', $args);
518
-        }
519
-        if ($array) {
520
-            $arg_string .= ' )';
521
-        }
522
-        return $arg_string;
523
-    }
524
-
525
-
526
-
527
-    /**
528
-     *    add error message
529
-     *
530
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
531
-     *                            separate messages for user || dev
532
-     * @param        string $file the file that the error occurred in - just use __FILE__
533
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
534
-     * @param        string $line the line number where the error occurred - just use __LINE__
535
-     * @return        void
536
-     */
537
-    public static function add_error($msg = null, $file = null, $func = null, $line = null)
538
-    {
539
-        self::_add_notice('errors', $msg, $file, $func, $line);
540
-        self::$_error_count++;
541
-    }
542
-
543
-
544
-
545
-    /**
546
-     * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just
547
-     * adds an error
548
-     *
549
-     * @param string $msg
550
-     * @param string $file
551
-     * @param string $func
552
-     * @param string $line
553
-     * @throws EE_Error
554
-     */
555
-    public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null)
556
-    {
557
-        if (WP_DEBUG) {
558
-            throw new EE_Error($msg);
559
-        }
560
-        EE_Error::add_error($msg, $file, $func, $line);
561
-    }
562
-
563
-
564
-
565
-    /**
566
-     *    add success message
567
-     *
568
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
569
-     *                            separate messages for user || dev
570
-     * @param        string $file the file that the error occurred in - just use __FILE__
571
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
572
-     * @param        string $line the line number where the error occurred - just use __LINE__
573
-     * @return        void
574
-     */
575
-    public static function add_success($msg = null, $file = null, $func = null, $line = null)
576
-    {
577
-        self::_add_notice('success', $msg, $file, $func, $line);
578
-    }
579
-
580
-
581
-
582
-    /**
583
-     *    add attention message
584
-     *
585
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
586
-     *                            separate messages for user || dev
587
-     * @param        string $file the file that the error occurred in - just use __FILE__
588
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
589
-     * @param        string $line the line number where the error occurred - just use __LINE__
590
-     * @return        void
591
-     */
592
-    public static function add_attention($msg = null, $file = null, $func = null, $line = null)
593
-    {
594
-        self::_add_notice('attention', $msg, $file, $func, $line);
595
-    }
596
-
597
-
598
-
599
-    /**
600
-     *    add success message
601
-     *
602
-     * @param        string $type whether the message is for a success or error notification
603
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
604
-     *                            separate messages for user || dev
605
-     * @param        string $file the file that the error occurred in - just use __FILE__
606
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
607
-     * @param        string $line the line number where the error occurred - just use __LINE__
608
-     * @return        void
609
-     */
610
-    private static function _add_notice($type = 'success', $msg = null, $file = null, $func = null, $line = null)
611
-    {
612
-        if (empty($msg)) {
613
-            EE_Error::doing_it_wrong(
614
-                'EE_Error::add_' . $type . '()',
615
-                sprintf(
616
-                    __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
617
-                        'event_espresso'),
618
-                    $type,
619
-                    $file,
620
-                    $line
621
-                ),
622
-                EVENT_ESPRESSO_VERSION
623
-            );
624
-        }
625
-        if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
626
-            EE_Error::doing_it_wrong(
627
-                'EE_Error::add_error()',
628
-                __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
629
-                    'event_espresso'),
630
-                EVENT_ESPRESSO_VERSION
631
-            );
632
-        }
633
-        // get separate user and developer messages if they exist
634
-        $msg = explode('||', $msg);
635
-        $user_msg = $msg[0];
636
-        $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
637
-        /**
638
-         * Do an action so other code can be triggered when a notice is created
639
-         *
640
-         * @param string $type     can be 'errors', 'attention', or 'success'
641
-         * @param string $user_msg message displayed to user when WP_DEBUG is off
642
-         * @param string $user_msg message displayed to user when WP_DEBUG is on
643
-         * @param string $file     file where error was generated
644
-         * @param string $func     function where error was generated
645
-         * @param string $line     line where error was generated
646
-         */
647
-        do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
648
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
649
-        // add notice if message exists
650
-        if (! empty($msg)) {
651
-            // get error code
652
-            $notice_code = EE_Error::generate_error_code($file, $func, $line);
653
-            if (WP_DEBUG && $type === 'errors') {
654
-                $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
655
-            }
656
-            // add notice. Index by code if it's not blank
657
-            if ($notice_code) {
658
-                self::$_espresso_notices[$type][$notice_code] = $msg;
659
-            } else {
660
-                self::$_espresso_notices[$type][] = $msg;
661
-            }
662
-            add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
663
-        }
664
-    }
665
-
666
-
667
-
668
-    /**
669
-     *    in some case it may be necessary to overwrite the existing success messages
670
-     *
671
-     * @return        void
672
-     */
673
-    public static function overwrite_success()
674
-    {
675
-        self::$_espresso_notices['success'] = false;
676
-    }
677
-
678
-
679
-
680
-    /**
681
-     *    in some case it may be necessary to overwrite the existing attention messages
682
-     *
683
-     * @return        void
684
-     */
685
-    public static function overwrite_attention()
686
-    {
687
-        self::$_espresso_notices['attention'] = false;
688
-    }
689
-
690
-
691
-
692
-    /**
693
-     *    in some case it may be necessary to overwrite the existing error messages
694
-     *
695
-     * @return        void
696
-     */
697
-    public static function overwrite_errors()
698
-    {
699
-        self::$_espresso_notices['errors'] = false;
700
-    }
701
-
702
-
703
-
704
-    /**
705
-     *    reset_notices
706
-     *
707
-     * @return void
708
-     */
709
-    public static function reset_notices()
710
-    {
711
-        self::$_espresso_notices['success'] = false;
712
-        self::$_espresso_notices['attention'] = false;
713
-        self::$_espresso_notices['errors'] = false;
714
-    }
715
-
716
-
717
-
718
-    /**
719
-     *    has_errors
720
-     *
721
-     * @return int
722
-     */
723
-    public static function has_notices()
724
-    {
725
-        $has_notices = 0;
726
-        // check for success messages
727
-        $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) ? 3
728
-            : $has_notices;
729
-        // check for attention messages
730
-        $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) ? 2
731
-            : $has_notices;
732
-        // check for error messages
733
-        $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) ? 1
734
-            : $has_notices;
735
-        return $has_notices;
736
-    }
737
-
738
-
739
-
740
-    /**
741
-     * This simply returns non formatted error notices as they were sent into the EE_Error object.
742
-     *
743
-     * @since 4.9.0
744
-     * @return array
745
-     */
746
-    public static function get_vanilla_notices()
747
-    {
748
-        return array(
749
-            'success'   => isset(self::$_espresso_notices['success']) ? self::$_espresso_notices['success'] : array(),
750
-            'attention' => isset(self::$_espresso_notices['attention']) ? self::$_espresso_notices['attention']
751
-                : array(),
752
-            'errors'    => isset(self::$_espresso_notices['errors']) ? self::$_espresso_notices['errors'] : array(),
753
-        );
754
-    }
755
-
756
-
757
-
758
-    /**
759
-     *    compile all error or success messages into one string
760
-     *
761
-     * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
762
-     * @param        boolean $format_output     whether or not to format the messages for display in the WP admin
763
-     * @param        boolean $save_to_transient whether or not to save notices to the db for retrieval on next request
764
-     *                                          - ONLY do this just before redirecting
765
-     * @param        boolean $remove_empty      whether or not to unset empty messages
766
-     * @return        array
767
-     */
768
-    public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
769
-    {
770
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
771
-        $success_messages = '';
772
-        $attention_messages = '';
773
-        $error_messages = '';
774
-        $print_scripts = false;
775
-        // either save notices to the db
776
-        if ($save_to_transient) {
777
-            update_option('ee_notices', self::$_espresso_notices);
778
-            return array();
779
-        }
780
-        // grab any notices that have been previously saved
781
-        if ($notices = get_option('ee_notices', false)) {
782
-            foreach ($notices as $type => $notice) {
783
-                if (is_array($notice) && ! empty($notice)) {
784
-                    // make sure that existing notice type is an array
785
-                    self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type])
786
-                                                      && ! empty(self::$_espresso_notices[$type])
787
-                        ? self::$_espresso_notices[$type] : array();
788
-                    // merge stored notices with any newly created ones
789
-                    self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice);
790
-                    $print_scripts = true;
791
-                }
792
-            }
793
-            // now clear any stored notices
794
-            update_option('ee_notices', false);
795
-        }
796
-        // check for success messages
797
-        if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
798
-            // combine messages
799
-            $success_messages .= implode(self::$_espresso_notices['success'], '<br /><br />');
800
-            $print_scripts = true;
801
-        }
802
-        // check for attention messages
803
-        if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
804
-            // combine messages
805
-            $attention_messages .= implode(self::$_espresso_notices['attention'], '<br /><br />');
806
-            $print_scripts = true;
807
-        }
808
-        // check for error messages
809
-        if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
810
-            $error_messages .= count(self::$_espresso_notices['errors']) > 1
811
-                ? __('The following errors have occurred:<br />', 'event_espresso')
812
-                : __('An error has occurred:<br />', 'event_espresso');
813
-            // combine messages
814
-            $error_messages .= implode(self::$_espresso_notices['errors'], '<br /><br />');
815
-            $print_scripts = true;
816
-        }
817
-        if ($format_output) {
818
-            $notices = '<div id="espresso-notices">';
819
-            $close = is_admin() ? ''
820
-                : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>';
821
-            if ($success_messages !== '') {
822
-                $css_id = is_admin() ? 'message' : 'espresso-notices-success';
823
-                $css_class = is_admin() ? 'updated fade' : 'success fade-away';
824
-                //showMessage( $success_messages );
825
-                $notices .= '<div id="'
826
-                            . $css_id
827
-                            . '" class="espresso-notices '
828
-                            . $css_class
829
-                            . '" style="display:none;"><p>'
830
-                            . $success_messages
831
-                            . '</p>'
832
-                            . $close
833
-                            . '</div>';
834
-            }
835
-            if ($attention_messages !== '') {
836
-                $css_id = is_admin() ? 'message' : 'espresso-notices-attention';
837
-                $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
838
-                //showMessage( $error_messages, TRUE );
839
-                $notices .= '<div id="'
840
-                            . $css_id
841
-                            . '" class="espresso-notices '
842
-                            . $css_class
843
-                            . '" style="display:none;"><p>'
844
-                            . $attention_messages
845
-                            . '</p>'
846
-                            . $close
847
-                            . '</div>';
848
-            }
849
-            if ($error_messages !== '') {
850
-                $css_id = is_admin() ? 'message' : 'espresso-notices-error';
851
-                $css_class = is_admin() ? 'error' : 'error fade-away';
852
-                //showMessage( $error_messages, TRUE );
853
-                $notices .= '<div id="'
854
-                            . $css_id
855
-                            . '" class="espresso-notices '
856
-                            . $css_class
857
-                            . '" style="display:none;"><p>'
858
-                            . $error_messages
859
-                            . '</p>'
860
-                            . $close
861
-                            . '</div>';
862
-            }
863
-            $notices .= '</div>';
864
-        } else {
865
-            $notices = array(
866
-                'success'   => $success_messages,
867
-                'attention' => $attention_messages,
868
-                'errors'    => $error_messages,
869
-            );
870
-            if ($remove_empty) {
871
-                // remove empty notices
872
-                foreach ($notices as $type => $notice) {
873
-                    if (empty($notice)) {
874
-                        unset($notices[$type]);
875
-                    }
876
-                }
877
-            }
878
-        }
879
-        if ($print_scripts) {
880
-            self::_print_scripts();
881
-        }
882
-        return $notices;
883
-    }
884
-
885
-
886
-
887
-    /**
888
-     *    add_persistent_admin_notice
889
-     *
890
-     * @param        string $pan_name     the name, or key of the Persistent Admin Notice to be stored
891
-     * @param        string $pan_message  the message to be stored persistently until dismissed
892
-     * @param bool          $force_update allows one to enforce the reappearance of a persistent message.
893
-     * @return        void
894
-     */
895
-    public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
896
-    {
897
-        if (! empty($pan_name) && ! empty($pan_message)) {
898
-            $persistent_admin_notices = get_option('ee_pers_admin_notices', array());
899
-            //maybe initialize persistent_admin_notices
900
-            if (empty($persistent_admin_notices)) {
901
-                add_option('ee_pers_admin_notices', array(), '', 'no');
902
-            }
903
-            $pan_name = sanitize_key($pan_name);
904
-            if (! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) {
905
-                $persistent_admin_notices[$pan_name] = $pan_message;
906
-                update_option('ee_pers_admin_notices', $persistent_admin_notices);
907
-            }
908
-        }
909
-    }
910
-
911
-
912
-
913
-    /**
914
-     *    dismiss_persistent_admin_notice
915
-     *
916
-     * @param        string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
917
-     * @param bool          $purge
918
-     * @param bool          $return_immediately
919
-     * @return        void
920
-     */
921
-    public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return_immediately = false)
922
-    {
923
-        $pan_name = EE_Registry::instance()->REQ->is_set('ee_nag_notice')
924
-            ? EE_Registry::instance()->REQ->get('ee_nag_notice') : $pan_name;
925
-        if (! empty($pan_name)) {
926
-            $persistent_admin_notices = get_option('ee_pers_admin_notices', array());
927
-            // check if notice we wish to dismiss is actually in the $persistent_admin_notices array
928
-            if (is_array($persistent_admin_notices) && isset($persistent_admin_notices[$pan_name])) {
929
-                // completely delete nag notice, or just NULL message so that it can NOT be added again ?
930
-                if ($purge) {
931
-                    unset($persistent_admin_notices[$pan_name]);
932
-                } else {
933
-                    $persistent_admin_notices[$pan_name] = null;
934
-                }
935
-                if (update_option('ee_pers_admin_notices', $persistent_admin_notices) === false) {
936
-                    EE_Error::add_error(sprintf(__('The persistent admin notice for "%s" could not be deleted.',
937
-                        'event_espresso'), $pan_name), __FILE__, __FUNCTION__, __LINE__);
938
-                }
939
-            }
940
-        }
941
-        if ($return_immediately) {
942
-            return;
943
-        }
944
-        if (EE_Registry::instance()->REQ->ajax) {
945
-            // grab any notices and concatenate into string
946
-            echo wp_json_encode(array('errors' => implode('<br />', EE_Error::get_notices(false))));
947
-            exit();
948
-        }
949
-        // save errors to a transient to be displayed on next request (after redirect)
950
-        EE_Error::get_notices(false, true);
951
-        $return_url = EE_Registry::instance()->REQ->is_set('return_url')
952
-            ? EE_Registry::instance()->REQ->get('return_url') : '';
953
-        wp_safe_redirect(urldecode($return_url));
954
-    }
955
-
956
-
957
-
958
-    /**
959
-     * display_persistent_admin_notices
960
-     *
961
-     * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
962
-     * @param  string $pan_message the message to be stored persistently until dismissed
963
-     * @param  string $return_url  URL to go back to after nag notice is dismissed
964
-     * @return string
965
-     */
966
-    public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
967
-    {
968
-        if (! empty($pan_name) && ! empty($pan_message)) {
969
-            $args = array(
970
-                'nag_notice'    => $pan_name,
971
-                'return_url'    => urlencode($return_url),
972
-                'ajax_url'      => WP_AJAX_URL,
973
-                'unknown_error' => esc_html__(
974
-                    'An unknown error has occurred on the server while attempting to dismiss this notice.',
975
-                    'event_espresso'
976
-                ),
977
-            );
978
-            EE_Registry::$i18n_js_strings = array_merge(
979
-                EE_Registry::$i18n_js_strings,
980
-                array('ee_dismiss' => $args)
981
-            );
982
-            return '
475
+		$output .= self::_print_scripts(true);
476
+		if (defined('DOING_AJAX')) {
477
+			echo wp_json_encode(array('error' => $output));
478
+			exit();
479
+		}
480
+		echo $output;
481
+		die();
482
+	}
483
+
484
+
485
+
486
+	/**
487
+	 *    generate string from exception trace args
488
+	 *
489
+	 * @param array $arguments
490
+	 * @param bool  $array
491
+	 * @return string
492
+	 */
493
+	private function _convert_args_to_string($arguments = array(), $array = false)
494
+	{
495
+		$arg_string = '';
496
+		if (! empty($arguments)) {
497
+			$args = array();
498
+			foreach ($arguments as $arg) {
499
+				if (! empty($arg)) {
500
+					if (is_string($arg)) {
501
+						$args[] = " '" . $arg . "'";
502
+					} elseif (is_array($arg)) {
503
+						$args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
504
+					} elseif ($arg === null) {
505
+						$args[] = ' NULL';
506
+					} elseif (is_bool($arg)) {
507
+						$args[] = ($arg) ? ' TRUE' : ' FALSE';
508
+					} elseif (is_object($arg)) {
509
+						$args[] = ' OBJECT ' . get_class($arg);
510
+					} elseif (is_resource($arg)) {
511
+						$args[] = get_resource_type($arg);
512
+					} else {
513
+						$args[] = $arg;
514
+					}
515
+				}
516
+			}
517
+			$arg_string = implode(', ', $args);
518
+		}
519
+		if ($array) {
520
+			$arg_string .= ' )';
521
+		}
522
+		return $arg_string;
523
+	}
524
+
525
+
526
+
527
+	/**
528
+	 *    add error message
529
+	 *
530
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
531
+	 *                            separate messages for user || dev
532
+	 * @param        string $file the file that the error occurred in - just use __FILE__
533
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
534
+	 * @param        string $line the line number where the error occurred - just use __LINE__
535
+	 * @return        void
536
+	 */
537
+	public static function add_error($msg = null, $file = null, $func = null, $line = null)
538
+	{
539
+		self::_add_notice('errors', $msg, $file, $func, $line);
540
+		self::$_error_count++;
541
+	}
542
+
543
+
544
+
545
+	/**
546
+	 * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just
547
+	 * adds an error
548
+	 *
549
+	 * @param string $msg
550
+	 * @param string $file
551
+	 * @param string $func
552
+	 * @param string $line
553
+	 * @throws EE_Error
554
+	 */
555
+	public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null)
556
+	{
557
+		if (WP_DEBUG) {
558
+			throw new EE_Error($msg);
559
+		}
560
+		EE_Error::add_error($msg, $file, $func, $line);
561
+	}
562
+
563
+
564
+
565
+	/**
566
+	 *    add success message
567
+	 *
568
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
569
+	 *                            separate messages for user || dev
570
+	 * @param        string $file the file that the error occurred in - just use __FILE__
571
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
572
+	 * @param        string $line the line number where the error occurred - just use __LINE__
573
+	 * @return        void
574
+	 */
575
+	public static function add_success($msg = null, $file = null, $func = null, $line = null)
576
+	{
577
+		self::_add_notice('success', $msg, $file, $func, $line);
578
+	}
579
+
580
+
581
+
582
+	/**
583
+	 *    add attention message
584
+	 *
585
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
586
+	 *                            separate messages for user || dev
587
+	 * @param        string $file the file that the error occurred in - just use __FILE__
588
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
589
+	 * @param        string $line the line number where the error occurred - just use __LINE__
590
+	 * @return        void
591
+	 */
592
+	public static function add_attention($msg = null, $file = null, $func = null, $line = null)
593
+	{
594
+		self::_add_notice('attention', $msg, $file, $func, $line);
595
+	}
596
+
597
+
598
+
599
+	/**
600
+	 *    add success message
601
+	 *
602
+	 * @param        string $type whether the message is for a success or error notification
603
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
604
+	 *                            separate messages for user || dev
605
+	 * @param        string $file the file that the error occurred in - just use __FILE__
606
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
607
+	 * @param        string $line the line number where the error occurred - just use __LINE__
608
+	 * @return        void
609
+	 */
610
+	private static function _add_notice($type = 'success', $msg = null, $file = null, $func = null, $line = null)
611
+	{
612
+		if (empty($msg)) {
613
+			EE_Error::doing_it_wrong(
614
+				'EE_Error::add_' . $type . '()',
615
+				sprintf(
616
+					__('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
617
+						'event_espresso'),
618
+					$type,
619
+					$file,
620
+					$line
621
+				),
622
+				EVENT_ESPRESSO_VERSION
623
+			);
624
+		}
625
+		if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
626
+			EE_Error::doing_it_wrong(
627
+				'EE_Error::add_error()',
628
+				__('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
629
+					'event_espresso'),
630
+				EVENT_ESPRESSO_VERSION
631
+			);
632
+		}
633
+		// get separate user and developer messages if they exist
634
+		$msg = explode('||', $msg);
635
+		$user_msg = $msg[0];
636
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
637
+		/**
638
+		 * Do an action so other code can be triggered when a notice is created
639
+		 *
640
+		 * @param string $type     can be 'errors', 'attention', or 'success'
641
+		 * @param string $user_msg message displayed to user when WP_DEBUG is off
642
+		 * @param string $user_msg message displayed to user when WP_DEBUG is on
643
+		 * @param string $file     file where error was generated
644
+		 * @param string $func     function where error was generated
645
+		 * @param string $line     line where error was generated
646
+		 */
647
+		do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
648
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
649
+		// add notice if message exists
650
+		if (! empty($msg)) {
651
+			// get error code
652
+			$notice_code = EE_Error::generate_error_code($file, $func, $line);
653
+			if (WP_DEBUG && $type === 'errors') {
654
+				$msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
655
+			}
656
+			// add notice. Index by code if it's not blank
657
+			if ($notice_code) {
658
+				self::$_espresso_notices[$type][$notice_code] = $msg;
659
+			} else {
660
+				self::$_espresso_notices[$type][] = $msg;
661
+			}
662
+			add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
663
+		}
664
+	}
665
+
666
+
667
+
668
+	/**
669
+	 *    in some case it may be necessary to overwrite the existing success messages
670
+	 *
671
+	 * @return        void
672
+	 */
673
+	public static function overwrite_success()
674
+	{
675
+		self::$_espresso_notices['success'] = false;
676
+	}
677
+
678
+
679
+
680
+	/**
681
+	 *    in some case it may be necessary to overwrite the existing attention messages
682
+	 *
683
+	 * @return        void
684
+	 */
685
+	public static function overwrite_attention()
686
+	{
687
+		self::$_espresso_notices['attention'] = false;
688
+	}
689
+
690
+
691
+
692
+	/**
693
+	 *    in some case it may be necessary to overwrite the existing error messages
694
+	 *
695
+	 * @return        void
696
+	 */
697
+	public static function overwrite_errors()
698
+	{
699
+		self::$_espresso_notices['errors'] = false;
700
+	}
701
+
702
+
703
+
704
+	/**
705
+	 *    reset_notices
706
+	 *
707
+	 * @return void
708
+	 */
709
+	public static function reset_notices()
710
+	{
711
+		self::$_espresso_notices['success'] = false;
712
+		self::$_espresso_notices['attention'] = false;
713
+		self::$_espresso_notices['errors'] = false;
714
+	}
715
+
716
+
717
+
718
+	/**
719
+	 *    has_errors
720
+	 *
721
+	 * @return int
722
+	 */
723
+	public static function has_notices()
724
+	{
725
+		$has_notices = 0;
726
+		// check for success messages
727
+		$has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) ? 3
728
+			: $has_notices;
729
+		// check for attention messages
730
+		$has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) ? 2
731
+			: $has_notices;
732
+		// check for error messages
733
+		$has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) ? 1
734
+			: $has_notices;
735
+		return $has_notices;
736
+	}
737
+
738
+
739
+
740
+	/**
741
+	 * This simply returns non formatted error notices as they were sent into the EE_Error object.
742
+	 *
743
+	 * @since 4.9.0
744
+	 * @return array
745
+	 */
746
+	public static function get_vanilla_notices()
747
+	{
748
+		return array(
749
+			'success'   => isset(self::$_espresso_notices['success']) ? self::$_espresso_notices['success'] : array(),
750
+			'attention' => isset(self::$_espresso_notices['attention']) ? self::$_espresso_notices['attention']
751
+				: array(),
752
+			'errors'    => isset(self::$_espresso_notices['errors']) ? self::$_espresso_notices['errors'] : array(),
753
+		);
754
+	}
755
+
756
+
757
+
758
+	/**
759
+	 *    compile all error or success messages into one string
760
+	 *
761
+	 * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
762
+	 * @param        boolean $format_output     whether or not to format the messages for display in the WP admin
763
+	 * @param        boolean $save_to_transient whether or not to save notices to the db for retrieval on next request
764
+	 *                                          - ONLY do this just before redirecting
765
+	 * @param        boolean $remove_empty      whether or not to unset empty messages
766
+	 * @return        array
767
+	 */
768
+	public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
769
+	{
770
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
771
+		$success_messages = '';
772
+		$attention_messages = '';
773
+		$error_messages = '';
774
+		$print_scripts = false;
775
+		// either save notices to the db
776
+		if ($save_to_transient) {
777
+			update_option('ee_notices', self::$_espresso_notices);
778
+			return array();
779
+		}
780
+		// grab any notices that have been previously saved
781
+		if ($notices = get_option('ee_notices', false)) {
782
+			foreach ($notices as $type => $notice) {
783
+				if (is_array($notice) && ! empty($notice)) {
784
+					// make sure that existing notice type is an array
785
+					self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type])
786
+													  && ! empty(self::$_espresso_notices[$type])
787
+						? self::$_espresso_notices[$type] : array();
788
+					// merge stored notices with any newly created ones
789
+					self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice);
790
+					$print_scripts = true;
791
+				}
792
+			}
793
+			// now clear any stored notices
794
+			update_option('ee_notices', false);
795
+		}
796
+		// check for success messages
797
+		if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
798
+			// combine messages
799
+			$success_messages .= implode(self::$_espresso_notices['success'], '<br /><br />');
800
+			$print_scripts = true;
801
+		}
802
+		// check for attention messages
803
+		if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
804
+			// combine messages
805
+			$attention_messages .= implode(self::$_espresso_notices['attention'], '<br /><br />');
806
+			$print_scripts = true;
807
+		}
808
+		// check for error messages
809
+		if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
810
+			$error_messages .= count(self::$_espresso_notices['errors']) > 1
811
+				? __('The following errors have occurred:<br />', 'event_espresso')
812
+				: __('An error has occurred:<br />', 'event_espresso');
813
+			// combine messages
814
+			$error_messages .= implode(self::$_espresso_notices['errors'], '<br /><br />');
815
+			$print_scripts = true;
816
+		}
817
+		if ($format_output) {
818
+			$notices = '<div id="espresso-notices">';
819
+			$close = is_admin() ? ''
820
+				: '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>';
821
+			if ($success_messages !== '') {
822
+				$css_id = is_admin() ? 'message' : 'espresso-notices-success';
823
+				$css_class = is_admin() ? 'updated fade' : 'success fade-away';
824
+				//showMessage( $success_messages );
825
+				$notices .= '<div id="'
826
+							. $css_id
827
+							. '" class="espresso-notices '
828
+							. $css_class
829
+							. '" style="display:none;"><p>'
830
+							. $success_messages
831
+							. '</p>'
832
+							. $close
833
+							. '</div>';
834
+			}
835
+			if ($attention_messages !== '') {
836
+				$css_id = is_admin() ? 'message' : 'espresso-notices-attention';
837
+				$css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
838
+				//showMessage( $error_messages, TRUE );
839
+				$notices .= '<div id="'
840
+							. $css_id
841
+							. '" class="espresso-notices '
842
+							. $css_class
843
+							. '" style="display:none;"><p>'
844
+							. $attention_messages
845
+							. '</p>'
846
+							. $close
847
+							. '</div>';
848
+			}
849
+			if ($error_messages !== '') {
850
+				$css_id = is_admin() ? 'message' : 'espresso-notices-error';
851
+				$css_class = is_admin() ? 'error' : 'error fade-away';
852
+				//showMessage( $error_messages, TRUE );
853
+				$notices .= '<div id="'
854
+							. $css_id
855
+							. '" class="espresso-notices '
856
+							. $css_class
857
+							. '" style="display:none;"><p>'
858
+							. $error_messages
859
+							. '</p>'
860
+							. $close
861
+							. '</div>';
862
+			}
863
+			$notices .= '</div>';
864
+		} else {
865
+			$notices = array(
866
+				'success'   => $success_messages,
867
+				'attention' => $attention_messages,
868
+				'errors'    => $error_messages,
869
+			);
870
+			if ($remove_empty) {
871
+				// remove empty notices
872
+				foreach ($notices as $type => $notice) {
873
+					if (empty($notice)) {
874
+						unset($notices[$type]);
875
+					}
876
+				}
877
+			}
878
+		}
879
+		if ($print_scripts) {
880
+			self::_print_scripts();
881
+		}
882
+		return $notices;
883
+	}
884
+
885
+
886
+
887
+	/**
888
+	 *    add_persistent_admin_notice
889
+	 *
890
+	 * @param        string $pan_name     the name, or key of the Persistent Admin Notice to be stored
891
+	 * @param        string $pan_message  the message to be stored persistently until dismissed
892
+	 * @param bool          $force_update allows one to enforce the reappearance of a persistent message.
893
+	 * @return        void
894
+	 */
895
+	public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
896
+	{
897
+		if (! empty($pan_name) && ! empty($pan_message)) {
898
+			$persistent_admin_notices = get_option('ee_pers_admin_notices', array());
899
+			//maybe initialize persistent_admin_notices
900
+			if (empty($persistent_admin_notices)) {
901
+				add_option('ee_pers_admin_notices', array(), '', 'no');
902
+			}
903
+			$pan_name = sanitize_key($pan_name);
904
+			if (! array_key_exists($pan_name, $persistent_admin_notices) || $force_update) {
905
+				$persistent_admin_notices[$pan_name] = $pan_message;
906
+				update_option('ee_pers_admin_notices', $persistent_admin_notices);
907
+			}
908
+		}
909
+	}
910
+
911
+
912
+
913
+	/**
914
+	 *    dismiss_persistent_admin_notice
915
+	 *
916
+	 * @param        string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
917
+	 * @param bool          $purge
918
+	 * @param bool          $return_immediately
919
+	 * @return        void
920
+	 */
921
+	public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return_immediately = false)
922
+	{
923
+		$pan_name = EE_Registry::instance()->REQ->is_set('ee_nag_notice')
924
+			? EE_Registry::instance()->REQ->get('ee_nag_notice') : $pan_name;
925
+		if (! empty($pan_name)) {
926
+			$persistent_admin_notices = get_option('ee_pers_admin_notices', array());
927
+			// check if notice we wish to dismiss is actually in the $persistent_admin_notices array
928
+			if (is_array($persistent_admin_notices) && isset($persistent_admin_notices[$pan_name])) {
929
+				// completely delete nag notice, or just NULL message so that it can NOT be added again ?
930
+				if ($purge) {
931
+					unset($persistent_admin_notices[$pan_name]);
932
+				} else {
933
+					$persistent_admin_notices[$pan_name] = null;
934
+				}
935
+				if (update_option('ee_pers_admin_notices', $persistent_admin_notices) === false) {
936
+					EE_Error::add_error(sprintf(__('The persistent admin notice for "%s" could not be deleted.',
937
+						'event_espresso'), $pan_name), __FILE__, __FUNCTION__, __LINE__);
938
+				}
939
+			}
940
+		}
941
+		if ($return_immediately) {
942
+			return;
943
+		}
944
+		if (EE_Registry::instance()->REQ->ajax) {
945
+			// grab any notices and concatenate into string
946
+			echo wp_json_encode(array('errors' => implode('<br />', EE_Error::get_notices(false))));
947
+			exit();
948
+		}
949
+		// save errors to a transient to be displayed on next request (after redirect)
950
+		EE_Error::get_notices(false, true);
951
+		$return_url = EE_Registry::instance()->REQ->is_set('return_url')
952
+			? EE_Registry::instance()->REQ->get('return_url') : '';
953
+		wp_safe_redirect(urldecode($return_url));
954
+	}
955
+
956
+
957
+
958
+	/**
959
+	 * display_persistent_admin_notices
960
+	 *
961
+	 * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
962
+	 * @param  string $pan_message the message to be stored persistently until dismissed
963
+	 * @param  string $return_url  URL to go back to after nag notice is dismissed
964
+	 * @return string
965
+	 */
966
+	public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
967
+	{
968
+		if (! empty($pan_name) && ! empty($pan_message)) {
969
+			$args = array(
970
+				'nag_notice'    => $pan_name,
971
+				'return_url'    => urlencode($return_url),
972
+				'ajax_url'      => WP_AJAX_URL,
973
+				'unknown_error' => esc_html__(
974
+					'An unknown error has occurred on the server while attempting to dismiss this notice.',
975
+					'event_espresso'
976
+				),
977
+			);
978
+			EE_Registry::$i18n_js_strings = array_merge(
979
+				EE_Registry::$i18n_js_strings,
980
+				array('ee_dismiss' => $args)
981
+			);
982
+			return '
983 983
 			<div id="'
984
-                   . $pan_name
985
-                   . '" class="espresso-notices updated ee-nag-notice clearfix" style="border-left: 4px solid #fcb93c;">
984
+				   . $pan_name
985
+				   . '" class="espresso-notices updated ee-nag-notice clearfix" style="border-left: 4px solid #fcb93c;">
986 986
 				<p>'
987
-                   . $pan_message
988
-                   . '</p>
987
+				   . $pan_message
988
+				   . '</p>
989 989
 				<a class="dismiss-ee-nag-notice hide-if-no-js" style="float: right; cursor: pointer; text-decoration:none;" rel="'
990
-                   . $pan_name
991
-                   . '">
990
+				   . $pan_name
991
+				   . '">
992 992
 					<span class="dashicons dashicons-dismiss" style="position:relative; top:-1px; margin-right:.25em;"></span>'
993
-                   . __('Dismiss', 'event_espresso')
994
-                   . '
993
+				   . __('Dismiss', 'event_espresso')
994
+				   . '
995 995
 				</a>
996 996
 				<div style="clear:both;"></div>
997 997
 			</div>';
998
-        }
999
-        return '';
1000
-    }
1001
-
1002
-
1003
-
1004
-    /**
1005
-     *    get_persistent_admin_notices
1006
-     *
1007
-     * @param string $return_url
1008
-     * @return string
1009
-     */
1010
-    public static function get_persistent_admin_notices($return_url = '')
1011
-    {
1012
-        $notices = '';
1013
-        // check for persistent admin notices
1014
-        //filter the list though so plugins can notify the admin in a different way if they want
1015
-        $persistent_admin_notices = apply_filters(
1016
-            'FHEE__EE_Error__get_persistent_admin_notices',
1017
-            get_option('ee_pers_admin_notices', false),
1018
-            'ee_pers_admin_notices',
1019
-            $return_url
1020
-        );
1021
-        if ($persistent_admin_notices) {
1022
-            // load scripts
1023
-            wp_register_script(
1024
-                'espresso_core',
1025
-                EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1026
-                array('jquery'),
1027
-                EVENT_ESPRESSO_VERSION,
1028
-                true
1029
-            );
1030
-            wp_register_script(
1031
-                'ee_error_js',
1032
-                EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1033
-                array('espresso_core'),
1034
-                EVENT_ESPRESSO_VERSION,
1035
-                true
1036
-            );
1037
-            wp_enqueue_script('ee_error_js');
1038
-            // and display notices
1039
-            foreach ($persistent_admin_notices as $pan_name => $pan_message) {
1040
-                $notices .= self::display_persistent_admin_notices($pan_name, $pan_message, $return_url);
1041
-            }
1042
-        }
1043
-        return $notices;
1044
-    }
1045
-
1046
-
1047
-
1048
-    /**
1049
-     * _print_scripts
1050
-     *
1051
-     * @param    bool $force_print
1052
-     * @return    string
1053
-     */
1054
-    private static function _print_scripts($force_print = false)
1055
-    {
1056
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1057
-            if (wp_script_is('ee_error_js', 'enqueued')) {
1058
-                return '';
1059
-            }
1060
-            if (wp_script_is('ee_error_js', 'registered')) {
1061
-                wp_enqueue_style('espresso_default');
1062
-                wp_enqueue_style('espresso_custom_css');
1063
-                wp_enqueue_script('ee_error_js');
1064
-                wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
1065
-            }
1066
-        } else {
1067
-            return '
998
+		}
999
+		return '';
1000
+	}
1001
+
1002
+
1003
+
1004
+	/**
1005
+	 *    get_persistent_admin_notices
1006
+	 *
1007
+	 * @param string $return_url
1008
+	 * @return string
1009
+	 */
1010
+	public static function get_persistent_admin_notices($return_url = '')
1011
+	{
1012
+		$notices = '';
1013
+		// check for persistent admin notices
1014
+		//filter the list though so plugins can notify the admin in a different way if they want
1015
+		$persistent_admin_notices = apply_filters(
1016
+			'FHEE__EE_Error__get_persistent_admin_notices',
1017
+			get_option('ee_pers_admin_notices', false),
1018
+			'ee_pers_admin_notices',
1019
+			$return_url
1020
+		);
1021
+		if ($persistent_admin_notices) {
1022
+			// load scripts
1023
+			wp_register_script(
1024
+				'espresso_core',
1025
+				EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1026
+				array('jquery'),
1027
+				EVENT_ESPRESSO_VERSION,
1028
+				true
1029
+			);
1030
+			wp_register_script(
1031
+				'ee_error_js',
1032
+				EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1033
+				array('espresso_core'),
1034
+				EVENT_ESPRESSO_VERSION,
1035
+				true
1036
+			);
1037
+			wp_enqueue_script('ee_error_js');
1038
+			// and display notices
1039
+			foreach ($persistent_admin_notices as $pan_name => $pan_message) {
1040
+				$notices .= self::display_persistent_admin_notices($pan_name, $pan_message, $return_url);
1041
+			}
1042
+		}
1043
+		return $notices;
1044
+	}
1045
+
1046
+
1047
+
1048
+	/**
1049
+	 * _print_scripts
1050
+	 *
1051
+	 * @param    bool $force_print
1052
+	 * @return    string
1053
+	 */
1054
+	private static function _print_scripts($force_print = false)
1055
+	{
1056
+		if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1057
+			if (wp_script_is('ee_error_js', 'enqueued')) {
1058
+				return '';
1059
+			}
1060
+			if (wp_script_is('ee_error_js', 'registered')) {
1061
+				wp_enqueue_style('espresso_default');
1062
+				wp_enqueue_style('espresso_custom_css');
1063
+				wp_enqueue_script('ee_error_js');
1064
+				wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
1065
+			}
1066
+		} else {
1067
+			return '
1068 1068
 <script>
1069 1069
 /* <![CDATA[ */
1070 1070
 var ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
@@ -1074,143 +1074,143 @@  discard block
 block discarded – undo
1074 1074
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1075 1075
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1076 1076
 ';
1077
-        }
1078
-        return '';
1079
-    }
1080
-
1081
-
1082
-
1083
-    /**
1084
-     *    enqueue_error_scripts
1085
-     *
1086
-     * @return        void
1087
-     */
1088
-    public static function enqueue_error_scripts()
1089
-    {
1090
-        self::_print_scripts();
1091
-    }
1092
-
1093
-
1094
-
1095
-    /**
1096
-     *    create error code from filepath, function name,
1097
-     *    and line number where exception or error was thrown
1098
-     *
1099
-     * @param string $file
1100
-     * @param string $func
1101
-     * @param string $line
1102
-     * @return string
1103
-     */
1104
-    public static function generate_error_code($file = '', $func = '', $line = '')
1105
-    {
1106
-        $file = explode('.', basename($file));
1107
-        $error_code = ! empty($file[0]) ? $file[0] : '';
1108
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
1109
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
1110
-        return $error_code;
1111
-    }
1112
-
1113
-
1114
-
1115
-    /**
1116
-     *    write exception details to log file
1117
-     *
1118
-     * @param int   $time
1119
-     * @param array $ex
1120
-     * @param bool  $clear
1121
-     * @return void
1122
-     */
1123
-    public function write_to_error_log($time = 0, $ex = array(), $clear = false)
1124
-    {
1125
-        if (empty($ex)) {
1126
-            return;
1127
-        }
1128
-        if (! $time) {
1129
-            $time = time();
1130
-        }
1131
-        $exception_log = '----------------------------------------------------------------------------------------'
1132
-                         . PHP_EOL;
1133
-        $exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1134
-        $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1135
-        $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1136
-        $exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1137
-        $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1138
-        $exception_log .= 'Stack trace: ' . PHP_EOL;
1139
-        $exception_log .= $ex['string'] . PHP_EOL;
1140
-        $exception_log .= '----------------------------------------------------------------------------------------'
1141
-                          . PHP_EOL;
1142
-        try {
1143
-            EEH_File::ensure_file_exists_and_is_writable(
1144
-                EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1145
-            );
1146
-            EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs');
1147
-            if (! $clear) {
1148
-                //get existing log file and append new log info
1149
-                $exception_log = EEH_File::get_file_contents(
1150
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1151
-                ) . $exception_log;
1152
-            }
1153
-            EEH_File::write_to_file(
1154
-                EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file,
1155
-                $exception_log
1156
-            );
1157
-        } catch (EE_Error $e) {
1158
-            EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s',
1159
-                'event_espresso'), $e->getMessage()));
1160
-            return;
1161
-        }
1162
-    }
1163
-
1164
-
1165
-
1166
-    /**
1167
-     * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1168
-     * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1169
-     * but the code execution is done in a manner that could lead to unexpected results
1170
-     * (i.e. running to early, or too late in WP or EE loading process).
1171
-     * A good test for knowing whether to use this method is:
1172
-     * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1173
-     * Yes -> use EE_Error::add_error() or throw new EE_Error()
1174
-     * 2. If this is loaded before something else, it won't break anything,
1175
-     * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1176
-     *
1177
-     * @uses   constant WP_DEBUG test if wp_debug is on or not
1178
-     * @param string $function      The function that was called
1179
-     * @param string $message       A message explaining what has been done incorrectly
1180
-     * @param string $version       The version of Event Espresso where the error was added
1181
-     * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1182
-     *                              for a deprecated function. This allows deprecation to occur during one version,
1183
-     *                              but not have any notices appear until a later version. This allows developers
1184
-     *                              extra time to update their code before notices appear.
1185
-     * @param int    $error_type
1186
-     */
1187
-    public static function doing_it_wrong(
1188
-        $function,
1189
-        $message,
1190
-        $version,
1191
-        $applies_when = '',
1192
-        $error_type = null
1193
-    ) {
1194
-        if (defined('WP_DEBUG') && WP_DEBUG) {
1195
-            EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1196
-        }
1197
-    }
1198
-
1199
-
1200
-
1201
-    /**
1202
-     * Like get_notices, but returns an array of all the notices of the given type.
1203
-     *
1204
-     * @return array {
1205
-     * @type array $success   all the success messages
1206
-     * @type array $errors    all the error messages
1207
-     * @type array $attention all the attention messages
1208
-     * }
1209
-     */
1210
-    public static function get_raw_notices()
1211
-    {
1212
-        return self::$_espresso_notices;
1213
-    }
1077
+		}
1078
+		return '';
1079
+	}
1080
+
1081
+
1082
+
1083
+	/**
1084
+	 *    enqueue_error_scripts
1085
+	 *
1086
+	 * @return        void
1087
+	 */
1088
+	public static function enqueue_error_scripts()
1089
+	{
1090
+		self::_print_scripts();
1091
+	}
1092
+
1093
+
1094
+
1095
+	/**
1096
+	 *    create error code from filepath, function name,
1097
+	 *    and line number where exception or error was thrown
1098
+	 *
1099
+	 * @param string $file
1100
+	 * @param string $func
1101
+	 * @param string $line
1102
+	 * @return string
1103
+	 */
1104
+	public static function generate_error_code($file = '', $func = '', $line = '')
1105
+	{
1106
+		$file = explode('.', basename($file));
1107
+		$error_code = ! empty($file[0]) ? $file[0] : '';
1108
+		$error_code .= ! empty($func) ? ' - ' . $func : '';
1109
+		$error_code .= ! empty($line) ? ' - ' . $line : '';
1110
+		return $error_code;
1111
+	}
1112
+
1113
+
1114
+
1115
+	/**
1116
+	 *    write exception details to log file
1117
+	 *
1118
+	 * @param int   $time
1119
+	 * @param array $ex
1120
+	 * @param bool  $clear
1121
+	 * @return void
1122
+	 */
1123
+	public function write_to_error_log($time = 0, $ex = array(), $clear = false)
1124
+	{
1125
+		if (empty($ex)) {
1126
+			return;
1127
+		}
1128
+		if (! $time) {
1129
+			$time = time();
1130
+		}
1131
+		$exception_log = '----------------------------------------------------------------------------------------'
1132
+						 . PHP_EOL;
1133
+		$exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1134
+		$exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1135
+		$exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1136
+		$exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1137
+		$exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1138
+		$exception_log .= 'Stack trace: ' . PHP_EOL;
1139
+		$exception_log .= $ex['string'] . PHP_EOL;
1140
+		$exception_log .= '----------------------------------------------------------------------------------------'
1141
+						  . PHP_EOL;
1142
+		try {
1143
+			EEH_File::ensure_file_exists_and_is_writable(
1144
+				EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1145
+			);
1146
+			EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs');
1147
+			if (! $clear) {
1148
+				//get existing log file and append new log info
1149
+				$exception_log = EEH_File::get_file_contents(
1150
+					EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file
1151
+				) . $exception_log;
1152
+			}
1153
+			EEH_File::write_to_file(
1154
+				EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . self::$_exception_log_file,
1155
+				$exception_log
1156
+			);
1157
+		} catch (EE_Error $e) {
1158
+			EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s',
1159
+				'event_espresso'), $e->getMessage()));
1160
+			return;
1161
+		}
1162
+	}
1163
+
1164
+
1165
+
1166
+	/**
1167
+	 * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1168
+	 * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1169
+	 * but the code execution is done in a manner that could lead to unexpected results
1170
+	 * (i.e. running to early, or too late in WP or EE loading process).
1171
+	 * A good test for knowing whether to use this method is:
1172
+	 * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1173
+	 * Yes -> use EE_Error::add_error() or throw new EE_Error()
1174
+	 * 2. If this is loaded before something else, it won't break anything,
1175
+	 * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1176
+	 *
1177
+	 * @uses   constant WP_DEBUG test if wp_debug is on or not
1178
+	 * @param string $function      The function that was called
1179
+	 * @param string $message       A message explaining what has been done incorrectly
1180
+	 * @param string $version       The version of Event Espresso where the error was added
1181
+	 * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1182
+	 *                              for a deprecated function. This allows deprecation to occur during one version,
1183
+	 *                              but not have any notices appear until a later version. This allows developers
1184
+	 *                              extra time to update their code before notices appear.
1185
+	 * @param int    $error_type
1186
+	 */
1187
+	public static function doing_it_wrong(
1188
+		$function,
1189
+		$message,
1190
+		$version,
1191
+		$applies_when = '',
1192
+		$error_type = null
1193
+	) {
1194
+		if (defined('WP_DEBUG') && WP_DEBUG) {
1195
+			EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1196
+		}
1197
+	}
1198
+
1199
+
1200
+
1201
+	/**
1202
+	 * Like get_notices, but returns an array of all the notices of the given type.
1203
+	 *
1204
+	 * @return array {
1205
+	 * @type array $success   all the success messages
1206
+	 * @type array $errors    all the error messages
1207
+	 * @type array $attention all the attention messages
1208
+	 * }
1209
+	 */
1210
+	public static function get_raw_notices()
1211
+	{
1212
+		return self::$_espresso_notices;
1213
+	}
1214 1214
 
1215 1215
 
1216 1216
 
@@ -1226,27 +1226,27 @@  discard block
 block discarded – undo
1226 1226
  */
1227 1227
 function espresso_error_enqueue_scripts()
1228 1228
 {
1229
-    // js for error handling
1230
-    wp_register_script(
1231
-        'espresso_core',
1232
-        EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1233
-        array('jquery'),
1234
-        EVENT_ESPRESSO_VERSION,
1235
-        false
1236
-    );
1237
-    wp_register_script(
1238
-        'ee_error_js',
1239
-        EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1240
-        array('espresso_core'),
1241
-        EVENT_ESPRESSO_VERSION,
1242
-        false
1243
-    );
1229
+	// js for error handling
1230
+	wp_register_script(
1231
+		'espresso_core',
1232
+		EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1233
+		array('jquery'),
1234
+		EVENT_ESPRESSO_VERSION,
1235
+		false
1236
+	);
1237
+	wp_register_script(
1238
+		'ee_error_js',
1239
+		EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1240
+		array('espresso_core'),
1241
+		EVENT_ESPRESSO_VERSION,
1242
+		false
1243
+	);
1244 1244
 }
1245 1245
 
1246 1246
 if (is_admin()) {
1247
-    add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1247
+	add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1248 1248
 } else {
1249
-    add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1249
+	add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1250 1250
 }
1251 1251
 
1252 1252
 
Please login to merge, or discard this patch.
core/EE_Capabilities.core.php 1 patch
Indentation   +1388 added lines, -1388 removed lines patch added patch discarded remove patch
@@ -18,1000 +18,1000 @@  discard block
 block discarded – undo
18 18
 final class EE_Capabilities extends EE_Base
19 19
 {
20 20
 
21
-    /**
22
-     * the name of the wp option used to store caps previously initialized
23
-     */
24
-    const option_name = 'ee_caps_initialized';
25
-
26
-    /**
27
-     * instance of EE_Capabilities object
28
-     *
29
-     * @var EE_Capabilities
30
-     */
31
-    private static $_instance;
32
-
33
-
34
-    /**
35
-     * This is a map of caps that correspond to a default WP_Role.
36
-     * Array is indexed by Role and values are ee capabilities.
37
-     *
38
-     * @since 4.5.0
39
-     *
40
-     * @var array
41
-     */
42
-    private $capabilities_map = array();
43
-
44
-    /**
45
-     * This used to hold an array of EE_Meta_Capability_Map objects
46
-     * that define the granular capabilities mapped to for a user depending on context.
47
-     *
48
-     * @var EE_Meta_Capability_Map[]
49
-     */
50
-    private $_meta_caps = array();
51
-
52
-    /**
53
-     * The internal $capabilities_map needs to be initialized before it can be used.
54
-     * This flag tracks whether that has happened or not.
55
-     * But for this to work, we need three states to indicate:
56
-     *      initialization has not occurred at all
57
-     *      initialization has started but is not complete
58
-     *      initialization is complete
59
-     * The reason this is needed is because the addCaps() method
60
-     * normally requires the $capabilities_map to be initialized,
61
-     * but is also used during the initialization process.
62
-     * So:
63
-     *      If initialized === null, init_caps() will be called before any other methods will run.
64
-     *      If initialized === false, then init_caps() is in the process of running it's logic.
65
-     *      If initialized === true, then init_caps() has completed the initialization process.
66
-     *
67
-     * @var boolean|null $initialized
68
-     */
69
-    private $initialized;
70
-
71
-    /**
72
-     * @var boolean $reset
73
-     */
74
-    private $reset = false;
75
-
76
-
77
-
78
-    /**
79
-     * singleton method used to instantiate class object
80
-     *
81
-     * @since 4.5.0
82
-     *
83
-     * @return EE_Capabilities
84
-     */
85
-    public static function instance()
86
-    {
87
-        //check if instantiated, and if not do so.
88
-        if (! self::$_instance instanceof EE_Capabilities) {
89
-            self::$_instance = new self();
90
-        }
91
-        return self::$_instance;
92
-    }
93
-
94
-
95
-
96
-    /**
97
-     * private constructor
98
-     *
99
-     * @since 4.5.0
100
-     */
101
-    private function __construct()
102
-    {
103
-    }
104
-
105
-
106
-
107
-    /**
108
-     * This delays the initialization of the capabilities class until EE_System core is loaded and ready.
109
-     *
110
-     * @param bool $reset allows for resetting the default capabilities saved on roles.  Note that this doesn't
111
-     *                    actually REMOVE any capabilities from existing roles, it just resaves defaults roles and
112
-     *                    ensures that they are up to date.
113
-     *
114
-     * @since 4.5.0
115
-     * @return bool
116
-     * @throws EE_Error
117
-     */
118
-    public function init_caps($reset = false)
119
-    {
120
-        if(! EE_Maintenance_Mode::instance()->models_can_query()){
121
-            return false;
122
-        }
123
-        $this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN);
124
-        // if reset, then completely delete the cache option and clear the $capabilities_map property.
125
-        if ($this->reset) {
126
-            $this->initialized = null;
127
-            $this->capabilities_map = array();
128
-            delete_option(self::option_name);
129
-        }
130
-        if ($this->initialized === null) {
131
-            $this->initialized = false;
132
-            do_action(
133
-                'AHEE__EE_Capabilities__init_caps__before_initialization',
134
-                $this->reset
135
-            );
136
-            $this->addCaps($this->_init_caps_map());
137
-            $this->_set_meta_caps();
138
-            do_action(
139
-                'AHEE__EE_Capabilities__init_caps__after_initialization',
140
-                $this->capabilities_map
141
-            );
142
-            $this->initialized = true;
143
-        }
144
-        // reset $this->reset so that it's not stuck on true if init_caps() gets called again
145
-        $this->reset = false;
146
-        return true;
147
-    }
148
-
149
-
150
-
151
-
152
-    /**
153
-     * This sets the meta caps property.
154
-     *
155
-     * @since 4.5.0
156
-     * @return void
157
-     * @throws EE_Error
158
-     */
159
-    private function _set_meta_caps()
160
-    {
161
-        // get default meta caps and filter the returned array
162
-        $this->_meta_caps = apply_filters(
163
-            'FHEE__EE_Capabilities___set_meta_caps__meta_caps',
164
-            $this->_get_default_meta_caps_array()
165
-        );
166
-        //add filter for map_meta_caps but only if models can query.
167
-        if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
168
-            add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4);
169
-        }
170
-    }
171
-
172
-
173
-
174
-    /**
175
-     * This builds and returns the default meta_caps array only once.
176
-     *
177
-     * @since  4.8.28.rc.012
178
-     * @return array
179
-     * @throws EE_Error
180
-     */
181
-    private function _get_default_meta_caps_array()
182
-    {
183
-        static $default_meta_caps = array();
184
-        // make sure we're only ever initializing the default _meta_caps array once if it's empty.
185
-        if (empty($default_meta_caps)) {
186
-            $default_meta_caps = array(
187
-                //edits
188
-                new EE_Meta_Capability_Map_Edit(
189
-                    'ee_edit_event',
190
-                    array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events')
191
-                ),
192
-                new EE_Meta_Capability_Map_Edit(
193
-                    'ee_edit_venue',
194
-                    array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues')
195
-                ),
196
-                new EE_Meta_Capability_Map_Edit(
197
-                    'ee_edit_registration',
198
-                    array('Registration', '', 'ee_edit_others_registrations', '')
199
-                ),
200
-                new EE_Meta_Capability_Map_Edit(
201
-                    'ee_edit_checkin',
202
-                    array('Registration', '', 'ee_edit_others_checkins', '')
203
-                ),
204
-                new EE_Meta_Capability_Map_Messages_Cap(
205
-                    'ee_edit_message',
206
-                    array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages')
207
-                ),
208
-                new EE_Meta_Capability_Map_Edit(
209
-                    'ee_edit_default_ticket',
210
-                    array('Ticket', '', 'ee_edit_others_default_tickets', '')
211
-                ),
212
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
213
-                    'ee_edit_question',
214
-                    array('Question', '', '', 'ee_edit_system_questions')
215
-                ),
216
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
217
-                    'ee_edit_question_group',
218
-                    array('Question_Group', '', '', 'ee_edit_system_question_groups')
219
-                ),
220
-                new EE_Meta_Capability_Map_Edit(
221
-                    'ee_edit_payment_method',
222
-                    array('Payment_Method', '', 'ee_edit_others_payment_methods', '')
223
-                ),
224
-                //reads
225
-                new EE_Meta_Capability_Map_Read(
226
-                    'ee_read_event',
227
-                    array('Event', '', 'ee_read_others_events', 'ee_read_private_events')
228
-                ),
229
-                new EE_Meta_Capability_Map_Read(
230
-                    'ee_read_venue',
231
-                    array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues')
232
-                ),
233
-                new EE_Meta_Capability_Map_Read(
234
-                    'ee_read_registration',
235
-                    array('Registration', '', 'ee_read_others_registrations', '')
236
-                ),
237
-                new EE_Meta_Capability_Map_Read(
238
-                    'ee_read_checkin',
239
-                    array('Registration', '', 'ee_read_others_checkins', '')
240
-                ),
241
-                new EE_Meta_Capability_Map_Messages_Cap(
242
-                    'ee_read_message',
243
-                    array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages')
244
-                ),
245
-                new EE_Meta_Capability_Map_Read(
246
-                    'ee_read_default_ticket',
247
-                    array('Ticket', '', 'ee_read_others_default_tickets', '')
248
-                ),
249
-                new EE_Meta_Capability_Map_Read(
250
-                    'ee_read_payment_method',
251
-                    array('Payment_Method', '', 'ee_read_others_payment_methods', '')
252
-                ),
253
-                //deletes
254
-                new EE_Meta_Capability_Map_Delete(
255
-                    'ee_delete_event',
256
-                    array(
257
-                        'Event',
258
-                        'ee_delete_published_events',
259
-                        'ee_delete_others_events',
260
-                        'ee_delete_private_events',
261
-                    )
262
-                ),
263
-                new EE_Meta_Capability_Map_Delete(
264
-                    'ee_delete_venue',
265
-                    array(
266
-                        'Venue',
267
-                        'ee_delete_published_venues',
268
-                        'ee_delete_others_venues',
269
-                        'ee_delete_private_venues',
270
-                    )
271
-                ),
272
-                new EE_Meta_Capability_Map_Delete(
273
-                    'ee_delete_registration',
274
-                    array('Registration', '', 'ee_delete_others_registrations', '')
275
-                ),
276
-                new EE_Meta_Capability_Map_Delete(
277
-                    'ee_delete_checkin',
278
-                    array('Registration', '', 'ee_delete_others_checkins', '')
279
-                ),
280
-                new EE_Meta_Capability_Map_Messages_Cap(
281
-                    'ee_delete_message',
282
-                    array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages')
283
-                ),
284
-                new EE_Meta_Capability_Map_Delete(
285
-                    'ee_delete_default_ticket',
286
-                    array('Ticket', '', 'ee_delete_others_default_tickets', '')
287
-                ),
288
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
289
-                    'ee_delete_question',
290
-                    array('Question', '', '', 'delete_system_questions')
291
-                ),
292
-                new EE_Meta_Capability_Map_Registration_Form_Cap(
293
-                    'ee_delete_question_group',
294
-                    array('Question_Group', '', '', 'delete_system_question_groups')
295
-                ),
296
-                new EE_Meta_Capability_Map_Delete(
297
-                    'ee_delete_payment_method',
298
-                    array('Payment_Method', '', 'ee_delete_others_payment_methods', '')
299
-                ),
300
-            );
301
-        }
302
-        return $default_meta_caps;
303
-    }
304
-
305
-
306
-
307
-    /**
308
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
309
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
310
-     *
311
-     * The actual logic is carried out by implementer classes in their definition of _map_meta_caps.
312
-     *
313
-     * @since 4.5.0
314
-     * @see   wp-includes/capabilities.php
315
-     *
316
-     * @param array  $caps    actual users capabilities
317
-     * @param string $cap     initial capability name that is being checked (the "map" key)
318
-     * @param int    $user_id The user id
319
-     * @param array  $args    Adds context to the cap. Typically the object ID.
320
-     * @return array actual users capabilities
321
-     * @throws EE_Error
322
-     */
323
-    public function map_meta_caps($caps, $cap, $user_id, $args)
324
-    {
325
-        if (did_action('AHEE__EE_System__load_espresso_addons__complete')) {
326
-            //loop through our _meta_caps array
327
-            foreach ($this->_meta_caps as $meta_map) {
328
-                if (! $meta_map instanceof EE_Meta_Capability_Map) {
329
-                    continue;
330
-                }
331
-                // don't load models if there is no object ID in the args
332
-                if (! empty($args[0])) {
333
-                    $meta_map->ensure_is_model();
334
-                }
335
-                $caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args);
336
-            }
337
-        }
338
-        return $caps;
339
-    }
340
-
341
-
342
-
343
-    /**
344
-     * This sets up and returns the initial capabilities map for Event Espresso
345
-     * Note this array is filtered.
346
-     * It is assumed that all available EE capabilities are assigned to the administrator role.
347
-     *
348
-     * @since 4.5.0
349
-     *
350
-     * @return array
351
-     */
352
-    private function _init_caps_map()
353
-    {
354
-        return apply_filters(
355
-            'FHEE__EE_Capabilities__init_caps_map__caps',
356
-            array(
357
-                'administrator'           => array(
358
-                    //basic access
359
-                    'ee_read_ee',
360
-                    //gateways
361
-                    /**
362
-                     * note that with payment method capabilities, although we've implemented
363
-                     * capability mapping which will be used for accessing payment methods owned by
364
-                     * other users.  This is not fully implemented yet in the payment method ui.
365
-                     * Currently only the "plural" caps are in active use.
366
-                     * (Specific payment method caps are in use as well).
367
-                     **/
368
-                    'ee_manage_gateways',
369
-                    'ee_read_payment_methods',
370
-                    'ee_read_others_payment_methods',
371
-                    'ee_edit_payment_methods',
372
-                    'ee_edit_others_payment_methods',
373
-                    'ee_delete_payment_methods',
374
-                    //events
375
-                    'ee_publish_events',
376
-                    'ee_read_private_events',
377
-                    'ee_read_others_events',
378
-                    'ee_read_events',
379
-                    'ee_edit_events',
380
-                    'ee_edit_published_events',
381
-                    'ee_edit_others_events',
382
-                    'ee_edit_private_events',
383
-                    'ee_delete_published_events',
384
-                    'ee_delete_private_events',
385
-                    'ee_delete_events',
386
-                    'ee_delete_others_events',
387
-                    //event categories
388
-                    'ee_manage_event_categories',
389
-                    'ee_edit_event_category',
390
-                    'ee_delete_event_category',
391
-                    'ee_assign_event_category',
392
-                    //venues
393
-                    'ee_publish_venues',
394
-                    'ee_read_venues',
395
-                    'ee_read_others_venues',
396
-                    'ee_read_private_venues',
397
-                    'ee_edit_venues',
398
-                    'ee_edit_others_venues',
399
-                    'ee_edit_published_venues',
400
-                    'ee_edit_private_venues',
401
-                    'ee_delete_venues',
402
-                    'ee_delete_others_venues',
403
-                    'ee_delete_private_venues',
404
-                    'ee_delete_published_venues',
405
-                    //venue categories
406
-                    'ee_manage_venue_categories',
407
-                    'ee_edit_venue_category',
408
-                    'ee_delete_venue_category',
409
-                    'ee_assign_venue_category',
410
-                    //contacts
411
-                    'ee_read_contacts',
412
-                    'ee_edit_contacts',
413
-                    'ee_delete_contacts',
414
-                    //registrations
415
-                    'ee_read_registrations',
416
-                    'ee_read_others_registrations',
417
-                    'ee_edit_registrations',
418
-                    'ee_edit_others_registrations',
419
-                    'ee_delete_registrations',
420
-                    //checkins
421
-                    'ee_read_others_checkins',
422
-                    'ee_read_checkins',
423
-                    'ee_edit_checkins',
424
-                    'ee_edit_others_checkins',
425
-                    'ee_delete_checkins',
426
-                    'ee_delete_others_checkins',
427
-                    //transactions && payments
428
-                    'ee_read_transaction',
429
-                    'ee_read_transactions',
430
-                    'ee_edit_payments',
431
-                    'ee_delete_payments',
432
-                    //messages
433
-                    'ee_read_messages',
434
-                    'ee_read_others_messages',
435
-                    'ee_read_global_messages',
436
-                    'ee_edit_global_messages',
437
-                    'ee_edit_messages',
438
-                    'ee_edit_others_messages',
439
-                    'ee_delete_messages',
440
-                    'ee_delete_others_messages',
441
-                    'ee_delete_global_messages',
442
-                    'ee_send_message',
443
-                    //tickets
444
-                    'ee_read_default_tickets',
445
-                    'ee_read_others_default_tickets',
446
-                    'ee_edit_default_tickets',
447
-                    'ee_edit_others_default_tickets',
448
-                    'ee_delete_default_tickets',
449
-                    'ee_delete_others_default_tickets',
450
-                    //prices
451
-                    'ee_edit_default_price',
452
-                    'ee_edit_default_prices',
453
-                    'ee_delete_default_price',
454
-                    'ee_delete_default_prices',
455
-                    'ee_edit_default_price_type',
456
-                    'ee_edit_default_price_types',
457
-                    'ee_delete_default_price_type',
458
-                    'ee_delete_default_price_types',
459
-                    'ee_read_default_prices',
460
-                    'ee_read_default_price_types',
461
-                    //registration form
462
-                    'ee_edit_questions',
463
-                    'ee_edit_system_questions',
464
-                    'ee_read_questions',
465
-                    'ee_delete_questions',
466
-                    'ee_edit_question_groups',
467
-                    'ee_read_question_groups',
468
-                    'ee_edit_system_question_groups',
469
-                    'ee_delete_question_groups',
470
-                    //event_type taxonomy
471
-                    'ee_assign_event_type',
472
-                    'ee_manage_event_types',
473
-                    'ee_edit_event_type',
474
-                    'ee_delete_event_type',
475
-                ),
476
-                'ee_events_administrator' => array(
477
-                    //core wp caps
478
-                    'read',
479
-                    'read_private_pages',
480
-                    'read_private_posts',
481
-                    'edit_users',
482
-                    'edit_posts',
483
-                    'edit_pages',
484
-                    'edit_published_posts',
485
-                    'edit_published_pages',
486
-                    'edit_private_pages',
487
-                    'edit_private_posts',
488
-                    'edit_others_posts',
489
-                    'edit_others_pages',
490
-                    'publish_posts',
491
-                    'publish_pages',
492
-                    'delete_posts',
493
-                    'delete_pages',
494
-                    'delete_private_pages',
495
-                    'delete_private_posts',
496
-                    'delete_published_pages',
497
-                    'delete_published_posts',
498
-                    'delete_others_posts',
499
-                    'delete_others_pages',
500
-                    'manage_categories',
501
-                    'manage_links',
502
-                    'moderate_comments',
503
-                    'unfiltered_html',
504
-                    'upload_files',
505
-                    'export',
506
-                    'import',
507
-                    'list_users',
508
-                    'level_1', //required if user with this role shows up in author dropdowns
509
-                    //basic ee access
510
-                    'ee_read_ee',
511
-                    //events
512
-                    'ee_publish_events',
513
-                    'ee_read_private_events',
514
-                    'ee_read_others_events',
515
-                    'ee_read_event',
516
-                    'ee_read_events',
517
-                    'ee_edit_event',
518
-                    'ee_edit_events',
519
-                    'ee_edit_published_events',
520
-                    'ee_edit_others_events',
521
-                    'ee_edit_private_events',
522
-                    'ee_delete_published_events',
523
-                    'ee_delete_private_events',
524
-                    'ee_delete_event',
525
-                    'ee_delete_events',
526
-                    'ee_delete_others_events',
527
-                    //event categories
528
-                    'ee_manage_event_categories',
529
-                    'ee_edit_event_category',
530
-                    'ee_delete_event_category',
531
-                    'ee_assign_event_category',
532
-                    //venues
533
-                    'ee_publish_venues',
534
-                    'ee_read_venue',
535
-                    'ee_read_venues',
536
-                    'ee_read_others_venues',
537
-                    'ee_read_private_venues',
538
-                    'ee_edit_venue',
539
-                    'ee_edit_venues',
540
-                    'ee_edit_others_venues',
541
-                    'ee_edit_published_venues',
542
-                    'ee_edit_private_venues',
543
-                    'ee_delete_venue',
544
-                    'ee_delete_venues',
545
-                    'ee_delete_others_venues',
546
-                    'ee_delete_private_venues',
547
-                    'ee_delete_published_venues',
548
-                    //venue categories
549
-                    'ee_manage_venue_categories',
550
-                    'ee_edit_venue_category',
551
-                    'ee_delete_venue_category',
552
-                    'ee_assign_venue_category',
553
-                    //contacts
554
-                    'ee_read_contacts',
555
-                    'ee_edit_contacts',
556
-                    'ee_delete_contacts',
557
-                    //registrations
558
-                    'ee_read_registrations',
559
-                    'ee_read_others_registrations',
560
-                    'ee_edit_registration',
561
-                    'ee_edit_registrations',
562
-                    'ee_edit_others_registrations',
563
-                    'ee_delete_registration',
564
-                    'ee_delete_registrations',
565
-                    //checkins
566
-                    'ee_read_others_checkins',
567
-                    'ee_read_checkins',
568
-                    'ee_edit_checkins',
569
-                    'ee_edit_others_checkins',
570
-                    'ee_delete_checkins',
571
-                    'ee_delete_others_checkins',
572
-                    //transactions && payments
573
-                    'ee_read_transaction',
574
-                    'ee_read_transactions',
575
-                    'ee_edit_payments',
576
-                    'ee_delete_payments',
577
-                    //messages
578
-                    'ee_read_messages',
579
-                    'ee_read_others_messages',
580
-                    'ee_read_global_messages',
581
-                    'ee_edit_global_messages',
582
-                    'ee_edit_messages',
583
-                    'ee_edit_others_messages',
584
-                    'ee_delete_messages',
585
-                    'ee_delete_others_messages',
586
-                    'ee_delete_global_messages',
587
-                    'ee_send_message',
588
-                    //tickets
589
-                    'ee_read_default_tickets',
590
-                    'ee_read_others_default_tickets',
591
-                    'ee_edit_default_tickets',
592
-                    'ee_edit_others_default_tickets',
593
-                    'ee_delete_default_tickets',
594
-                    'ee_delete_others_default_tickets',
595
-                    //prices
596
-                    'ee_edit_default_price',
597
-                    'ee_edit_default_prices',
598
-                    'ee_delete_default_price',
599
-                    'ee_delete_default_prices',
600
-                    'ee_edit_default_price_type',
601
-                    'ee_edit_default_price_types',
602
-                    'ee_delete_default_price_type',
603
-                    'ee_delete_default_price_types',
604
-                    'ee_read_default_prices',
605
-                    'ee_read_default_price_types',
606
-                    //registration form
607
-                    'ee_edit_questions',
608
-                    'ee_edit_system_questions',
609
-                    'ee_read_questions',
610
-                    'ee_delete_questions',
611
-                    'ee_edit_question_groups',
612
-                    'ee_read_question_groups',
613
-                    'ee_edit_system_question_groups',
614
-                    'ee_delete_question_groups',
615
-                    //event_type taxonomy
616
-                    'ee_assign_event_type',
617
-                    'ee_manage_event_types',
618
-                    'ee_edit_event_type',
619
-                    'ee_delete_event_type',
620
-                )
621
-            )
622
-        );
623
-    }
624
-
625
-
626
-
627
-    /**
628
-     * @return bool
629
-     * @throws EE_Error
630
-     */
631
-    private function setupCapabilitiesMap()
632
-    {
633
-        // if the initialization process hasn't even started, then we need to call init_caps()
634
-        if($this->initialized === null) {
635
-            return $this->init_caps();
636
-        }
637
-        // unless resetting, get caps from db if we haven't already
638
-        $this->capabilities_map = $this->reset || ! empty($this->capabilities_map)
639
-            ? $this->capabilities_map
640
-            : get_option(self::option_name, array());
641
-        return true;
642
-    }
643
-
644
-
645
-
646
-    /**
647
-     * @param bool $update
648
-     * @return bool
649
-     */
650
-    private function updateCapabilitiesMap($update = true)
651
-    {
652
-        return $update ? update_option(self::option_name, $this->capabilities_map) : false;
653
-    }
654
-
655
-
656
-
657
-    /**
658
-     * Adds capabilities to roles.
659
-     *
660
-     * @since 4.9.42
661
-     * @param array $capabilities_to_add array of capabilities to add, indexed by roles.
662
-     *                                   Note that this should ONLY be called on activation hook
663
-     *                                   otherwise the caps will be added on every request.
664
-     * @return bool
665
-     * @throws \EE_Error
666
-     */
667
-    public function addCaps(array $capabilities_to_add)
668
-    {
669
-        // don't do anything if the capabilities map can not be initialized
670
-        if (! $this->setupCapabilitiesMap()) {
671
-            return false;
672
-        }
673
-        // and filter the array so others can get in on the fun during resets
674
-        $capabilities_to_add = apply_filters(
675
-            'FHEE__EE_Capabilities__addCaps__capabilities_to_add',
676
-            $capabilities_to_add,
677
-            $this->reset,
678
-            $this->capabilities_map
679
-        );
680
-        $update_capabilities_map = false;
681
-        // if not reset, see what caps are new for each role. if they're new, add them.
682
-        foreach ($capabilities_to_add as $role => $caps_for_role) {
683
-            if (is_array($caps_for_role)) {
684
-                foreach ($caps_for_role as $cap) {
685
-                    if (
686
-                        ! $this->capHasBeenAddedToRole($role, $cap)
687
-                        && $this->add_cap_to_role($role, $cap, true, false)
688
-                    ) {
689
-                        $update_capabilities_map = true;
690
-                    }
691
-                }
692
-            }
693
-        }
694
-        // now let's just save the cap that has been set but only if there's been a change.
695
-        $updated = $this->updateCapabilitiesMap($update_capabilities_map);
696
-        $this->flushWpUser($updated);
697
-        do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated);
698
-        return $updated;
699
-    }
700
-
701
-
702
-
703
-    /**
704
-     * Loops through the capabilities map and removes the role caps specified by the incoming array
705
-     *
706
-     * @param array $caps_map map of capabilities to be removed (indexed by roles)
707
-     * @return bool
708
-     * @throws \EE_Error
709
-     */
710
-    public function removeCaps($caps_map)
711
-    {
712
-        // don't do anything if the capabilities map can not be initialized
713
-        if (! $this->setupCapabilitiesMap()) {
714
-            return false;
715
-        }
716
-        $update_capabilities_map = false;
717
-        foreach ($caps_map as $role => $caps_for_role) {
718
-            if (is_array($caps_for_role)) {
719
-                foreach ($caps_for_role as $cap) {
720
-                    if ($this->capHasBeenAddedToRole($role, $cap)
721
-                        && $this->remove_cap_from_role($role, $cap, false)
722
-                    ) {
723
-                        $update_capabilities_map = true;
724
-                    }
725
-                }
726
-            }
727
-        }
728
-        // maybe resave the caps
729
-        $updated = $this->updateCapabilitiesMap($update_capabilities_map);
730
-        $this->flushWpUser($updated);
731
-        return $updated;
732
-    }
733
-
734
-
735
-    /**
736
-     * This ensures that the WP User object cached on the $current_user global in WP has the latest capabilities from
737
-     * the roles on that user.
738
-     *
739
-     * @param bool $flush  Default is to flush the WP_User object.  If false, then this method effectively does nothing.
740
-     */
741
-    private function flushWpUser($flush = true)
742
-    {
743
-        if ($flush) {
744
-            $user = wp_get_current_user();
745
-            if ($user instanceof WP_User) {
746
-                $user->get_role_caps();
747
-            }
748
-        }
749
-    }
750
-
751
-
752
-
753
-    /**
754
-     * This method sets a capability on a role.  Note this should only be done on activation, or if you have something
755
-     * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note.
756
-     * this is a wrapper for $wp_role->add_cap()
757
-     *
758
-     * @see   wp-includes/capabilities.php
759
-     * @since 4.5.0
760
-     * @param string|WP_Role $role  A WordPress role the capability is being added to
761
-     * @param string         $cap   The capability being added to the role
762
-     * @param bool           $grant Whether to grant access to this cap on this role.
763
-     * @param bool           $update_capabilities_map
764
-     * @return bool
765
-     * @throws \EE_Error
766
-     */
767
-    public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true)
768
-    {
769
-        // capture incoming value for $role because we may need it to create a new WP_Role
770
-        $orig_role = $role;
771
-        $role = $role instanceof WP_Role ? $role : get_role($role);
772
-        //if the role isn't available then we create it.
773
-        if (! $role instanceof WP_Role) {
774
-            // if a plugin wants to create a specific role name then they should create the role before
775
-            // EE_Capabilities does.  Otherwise this function will create the role name from the slug:
776
-            // - removes any `ee_` namespacing from the start of the slug.
777
-            // - replaces `_` with ` ` (empty space).
778
-            // - sentence case on the resulting string.
779
-            $role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role));
780
-            $role = add_role($orig_role, $role_label);
781
-        }
782
-        if ($role instanceof WP_Role) {
783
-            // don't do anything if the capabilities map can not be initialized
784
-            if (! $this->setupCapabilitiesMap()) {
785
-                return false;
786
-            }
787
-            if (! $this->capHasBeenAddedToRole($role->name, $cap)) {
788
-                $role->add_cap($cap, $grant);
789
-                $this->capabilities_map[ $role->name ][] = $cap;
790
-                $this->updateCapabilitiesMap($update_capabilities_map);
791
-                return true;
792
-            }
793
-        }
794
-        return false;
795
-    }
796
-
797
-
798
-
799
-    /**
800
-     * Functions similarly to add_cap_to_role except removes cap from given role.
801
-     * Wrapper for $wp_role->remove_cap()
802
-     *
803
-     * @see   wp-includes/capabilities.php
804
-     * @since 4.5.0
805
-     * @param string|WP_Role $role A WordPress role the capability is being removed from.
806
-     * @param string         $cap  The capability being removed
807
-     * @param bool           $update_capabilities_map
808
-     * @return bool
809
-     * @throws \EE_Error
810
-     */
811
-    public function remove_cap_from_role($role, $cap, $update_capabilities_map = true)
812
-    {
813
-        // don't do anything if the capabilities map can not be initialized
814
-        if (! $this->setupCapabilitiesMap()) {
815
-            return false;
816
-        }
817
-        $role = $role instanceof WP_Role ? $role :get_role($role);
818
-        if ($index = $this->capHasBeenAddedToRole($role->name, $cap, true)) {
819
-            $role->remove_cap($cap);
820
-            unset($this->capabilities_map[ $role->name ][ $index ]);
821
-            $this->updateCapabilitiesMap($update_capabilities_map);
822
-            return true;
823
-        }
824
-        return false;
825
-    }
826
-
827
-
828
-
829
-    /**
830
-     * @param string $role_name
831
-     * @param string $cap
832
-     * @param bool   $get_index
833
-     * @return bool|mixed
834
-     */
835
-    private function capHasBeenAddedToRole($role_name='', $cap='', $get_index = false)
836
-    {
837
-        if (
838
-            isset($this->capabilities_map[$role_name])
839
-            && ($index = array_search($cap, $this->capabilities_map[$role_name], true)) !== false
840
-        ) {
841
-            return $get_index ? $index : true;
842
-        }
843
-        return false;
844
-    }
845
-
846
-
847
-
848
-    /**
849
-     * Wrapper for the native WP current_user_can() method.
850
-     * This is provided as a handy method for a couple things:
851
-     * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
852
-     * write those filters wherever current_user_can is called).
853
-     * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
854
-     *
855
-     * @since 4.5.0
856
-     *
857
-     * @param string $cap     The cap being checked.
858
-     * @param string $context The context where the current_user_can is being called from.
859
-     * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
860
-     *                        filters.
861
-     *
862
-     * @return bool  Whether user can or not.
863
-     */
864
-    public function current_user_can($cap, $context, $id = 0)
865
-    {
866
-        //apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
867
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id);
868
-        $filtered_cap = apply_filters(
869
-            'FHEE__EE_Capabilities__current_user_can__cap',
870
-            $filtered_cap,
871
-            $context,
872
-            $cap,
873
-            $id
874
-        );
875
-        return ! empty($id)
876
-            ? current_user_can($filtered_cap, $id)
877
-            : current_user_can($filtered_cap);
878
-    }
879
-
880
-
881
-
882
-    /**
883
-     * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class.
884
-     *
885
-     * @param int|WP_User $user    Either the user_id or a WP_User object
886
-     * @param string      $cap     The capability string being checked
887
-     * @param string      $context The context where the user_can is being called from (used in filters).
888
-     * @param int         $id      Optional. Id for item where user_can is being called from ( used in map_meta_cap()
889
-     *                             filters)
890
-     *
891
-     * @return bool Whether user can or not.
892
-     */
893
-    public function user_can($user, $cap, $context, $id = 0)
894
-    {
895
-        //apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
896
-        $filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id);
897
-        $filtered_cap = apply_filters(
898
-            'FHEE__EE_Capabilities__user_can__cap',
899
-            $filtered_cap,
900
-            $context,
901
-            $cap,
902
-            $user,
903
-            $id
904
-        );
905
-        return ! empty($id)
906
-            ? user_can($user, $filtered_cap, $id)
907
-            : user_can($user, $filtered_cap);
908
-    }
909
-
910
-
911
-
912
-    /**
913
-     * Wrapper for the native WP current_user_can_for_blog() method.
914
-     * This is provided as a handy method for a couple things:
915
-     * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
916
-     * write those filters wherever current_user_can is called).
917
-     * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
918
-     *
919
-     * @since 4.5.0
920
-     *
921
-     * @param int    $blog_id The blog id that is being checked for.
922
-     * @param string $cap     The cap being checked.
923
-     * @param string $context The context where the current_user_can is being called from.
924
-     * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
925
-     *                        filters.
926
-     *
927
-     * @return bool  Whether user can or not.
928
-     */
929
-    public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0)
930
-    {
931
-        $user_can = ! empty($id)
932
-            ? current_user_can_for_blog($blog_id, $cap, $id)
933
-            : current_user_can($blog_id, $cap);
934
-        //apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
935
-        $user_can = apply_filters(
936
-            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context,
937
-            $user_can,
938
-            $blog_id,
939
-            $cap,
940
-            $id
941
-        );
942
-        $user_can = apply_filters(
943
-            'FHEE__EE_Capabilities__current_user_can_for_blog__user_can',
944
-            $user_can,
945
-            $context,
946
-            $blog_id,
947
-            $cap,
948
-            $id
949
-        );
950
-        return $user_can;
951
-    }
952
-
953
-
954
-
955
-    /**
956
-     * This helper method just returns an array of registered EE capabilities.
957
-     *
958
-     * @since 4.5.0
959
-     * @param string $role If empty then the entire role/capability map is returned.
960
-     *                     Otherwise just the capabilities for the given role are returned.
961
-     * @return array
962
-     * @throws EE_Error
963
-     */
964
-    public function get_ee_capabilities($role = 'administrator')
965
-    {
966
-        if (! $this->initialized) {
967
-            $this->init_caps();
968
-        }
969
-        if (empty($role)) {
970
-            return $this->capabilities_map;
971
-        }
972
-        return isset($this->capabilities_map[ $role ])
973
-            ? $this->capabilities_map[ $role ]
974
-            : array();
975
-    }
976
-
977
-
978
-
979
-    /**
980
-     * @deprecated 4.9.42
981
-     * @param bool  $reset      If you need to reset Event Espresso's capabilities,
982
-     *                          then please use the init_caps() method with the "$reset" parameter set to "true"
983
-     * @param array $caps_map   Optional.
984
-     *                          Can be used to send a custom map of roles and capabilities for setting them up.
985
-     *                          Note that this should ONLY be called on activation hook or some other one-time
986
-     *                          task otherwise the caps will be added on every request.
987
-     * @return void
988
-     * @throws EE_Error
989
-     */
990
-    public function init_role_caps($reset = false, $caps_map = array())
991
-    {
992
-        // If this method is called directly and reset is set as 'true',
993
-        // then display a doing it wrong notice, because we want resets to go through init_caps()
994
-        // to guarantee that everything is set up correctly.
995
-        // This prevents the capabilities map getting reset incorrectly by direct calls to this method.
996
-        if ($reset) {
997
-            EE_Error::doing_it_wrong(
998
-                __METHOD__,
999
-                sprintf(
1000
-                    esc_html__(
1001
-                        'The "%1$s" parameter for the "%2$s" method is deprecated. If you need to reset Event Espresso\'s capabilities, then please use the "%3$s" method with the "%1$s" parameter set to "%4$s".',
1002
-                        'event_espresso'
1003
-                    ),
1004
-                    '$reset',
1005
-                    __METHOD__ . '()',
1006
-                    'EE_Capabilities::init_caps()',
1007
-                    'true'
1008
-                ),
1009
-                '4.9.42',
1010
-                '5.0.0'
1011
-            );
1012
-        }
1013
-        $this->addCaps($caps_map);
1014
-    }
21
+	/**
22
+	 * the name of the wp option used to store caps previously initialized
23
+	 */
24
+	const option_name = 'ee_caps_initialized';
25
+
26
+	/**
27
+	 * instance of EE_Capabilities object
28
+	 *
29
+	 * @var EE_Capabilities
30
+	 */
31
+	private static $_instance;
32
+
33
+
34
+	/**
35
+	 * This is a map of caps that correspond to a default WP_Role.
36
+	 * Array is indexed by Role and values are ee capabilities.
37
+	 *
38
+	 * @since 4.5.0
39
+	 *
40
+	 * @var array
41
+	 */
42
+	private $capabilities_map = array();
43
+
44
+	/**
45
+	 * This used to hold an array of EE_Meta_Capability_Map objects
46
+	 * that define the granular capabilities mapped to for a user depending on context.
47
+	 *
48
+	 * @var EE_Meta_Capability_Map[]
49
+	 */
50
+	private $_meta_caps = array();
51
+
52
+	/**
53
+	 * The internal $capabilities_map needs to be initialized before it can be used.
54
+	 * This flag tracks whether that has happened or not.
55
+	 * But for this to work, we need three states to indicate:
56
+	 *      initialization has not occurred at all
57
+	 *      initialization has started but is not complete
58
+	 *      initialization is complete
59
+	 * The reason this is needed is because the addCaps() method
60
+	 * normally requires the $capabilities_map to be initialized,
61
+	 * but is also used during the initialization process.
62
+	 * So:
63
+	 *      If initialized === null, init_caps() will be called before any other methods will run.
64
+	 *      If initialized === false, then init_caps() is in the process of running it's logic.
65
+	 *      If initialized === true, then init_caps() has completed the initialization process.
66
+	 *
67
+	 * @var boolean|null $initialized
68
+	 */
69
+	private $initialized;
70
+
71
+	/**
72
+	 * @var boolean $reset
73
+	 */
74
+	private $reset = false;
75
+
76
+
77
+
78
+	/**
79
+	 * singleton method used to instantiate class object
80
+	 *
81
+	 * @since 4.5.0
82
+	 *
83
+	 * @return EE_Capabilities
84
+	 */
85
+	public static function instance()
86
+	{
87
+		//check if instantiated, and if not do so.
88
+		if (! self::$_instance instanceof EE_Capabilities) {
89
+			self::$_instance = new self();
90
+		}
91
+		return self::$_instance;
92
+	}
93
+
94
+
95
+
96
+	/**
97
+	 * private constructor
98
+	 *
99
+	 * @since 4.5.0
100
+	 */
101
+	private function __construct()
102
+	{
103
+	}
104
+
105
+
106
+
107
+	/**
108
+	 * This delays the initialization of the capabilities class until EE_System core is loaded and ready.
109
+	 *
110
+	 * @param bool $reset allows for resetting the default capabilities saved on roles.  Note that this doesn't
111
+	 *                    actually REMOVE any capabilities from existing roles, it just resaves defaults roles and
112
+	 *                    ensures that they are up to date.
113
+	 *
114
+	 * @since 4.5.0
115
+	 * @return bool
116
+	 * @throws EE_Error
117
+	 */
118
+	public function init_caps($reset = false)
119
+	{
120
+		if(! EE_Maintenance_Mode::instance()->models_can_query()){
121
+			return false;
122
+		}
123
+		$this->reset = filter_var($reset, FILTER_VALIDATE_BOOLEAN);
124
+		// if reset, then completely delete the cache option and clear the $capabilities_map property.
125
+		if ($this->reset) {
126
+			$this->initialized = null;
127
+			$this->capabilities_map = array();
128
+			delete_option(self::option_name);
129
+		}
130
+		if ($this->initialized === null) {
131
+			$this->initialized = false;
132
+			do_action(
133
+				'AHEE__EE_Capabilities__init_caps__before_initialization',
134
+				$this->reset
135
+			);
136
+			$this->addCaps($this->_init_caps_map());
137
+			$this->_set_meta_caps();
138
+			do_action(
139
+				'AHEE__EE_Capabilities__init_caps__after_initialization',
140
+				$this->capabilities_map
141
+			);
142
+			$this->initialized = true;
143
+		}
144
+		// reset $this->reset so that it's not stuck on true if init_caps() gets called again
145
+		$this->reset = false;
146
+		return true;
147
+	}
148
+
149
+
150
+
151
+
152
+	/**
153
+	 * This sets the meta caps property.
154
+	 *
155
+	 * @since 4.5.0
156
+	 * @return void
157
+	 * @throws EE_Error
158
+	 */
159
+	private function _set_meta_caps()
160
+	{
161
+		// get default meta caps and filter the returned array
162
+		$this->_meta_caps = apply_filters(
163
+			'FHEE__EE_Capabilities___set_meta_caps__meta_caps',
164
+			$this->_get_default_meta_caps_array()
165
+		);
166
+		//add filter for map_meta_caps but only if models can query.
167
+		if (! has_filter('map_meta_cap', array($this, 'map_meta_caps'))) {
168
+			add_filter('map_meta_cap', array($this, 'map_meta_caps'), 10, 4);
169
+		}
170
+	}
171
+
172
+
173
+
174
+	/**
175
+	 * This builds and returns the default meta_caps array only once.
176
+	 *
177
+	 * @since  4.8.28.rc.012
178
+	 * @return array
179
+	 * @throws EE_Error
180
+	 */
181
+	private function _get_default_meta_caps_array()
182
+	{
183
+		static $default_meta_caps = array();
184
+		// make sure we're only ever initializing the default _meta_caps array once if it's empty.
185
+		if (empty($default_meta_caps)) {
186
+			$default_meta_caps = array(
187
+				//edits
188
+				new EE_Meta_Capability_Map_Edit(
189
+					'ee_edit_event',
190
+					array('Event', 'ee_edit_published_events', 'ee_edit_others_events', 'ee_edit_private_events')
191
+				),
192
+				new EE_Meta_Capability_Map_Edit(
193
+					'ee_edit_venue',
194
+					array('Venue', 'ee_edit_published_venues', 'ee_edit_others_venues', 'ee_edit_private_venues')
195
+				),
196
+				new EE_Meta_Capability_Map_Edit(
197
+					'ee_edit_registration',
198
+					array('Registration', '', 'ee_edit_others_registrations', '')
199
+				),
200
+				new EE_Meta_Capability_Map_Edit(
201
+					'ee_edit_checkin',
202
+					array('Registration', '', 'ee_edit_others_checkins', '')
203
+				),
204
+				new EE_Meta_Capability_Map_Messages_Cap(
205
+					'ee_edit_message',
206
+					array('Message_Template_Group', '', 'ee_edit_others_messages', 'ee_edit_global_messages')
207
+				),
208
+				new EE_Meta_Capability_Map_Edit(
209
+					'ee_edit_default_ticket',
210
+					array('Ticket', '', 'ee_edit_others_default_tickets', '')
211
+				),
212
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
213
+					'ee_edit_question',
214
+					array('Question', '', '', 'ee_edit_system_questions')
215
+				),
216
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
217
+					'ee_edit_question_group',
218
+					array('Question_Group', '', '', 'ee_edit_system_question_groups')
219
+				),
220
+				new EE_Meta_Capability_Map_Edit(
221
+					'ee_edit_payment_method',
222
+					array('Payment_Method', '', 'ee_edit_others_payment_methods', '')
223
+				),
224
+				//reads
225
+				new EE_Meta_Capability_Map_Read(
226
+					'ee_read_event',
227
+					array('Event', '', 'ee_read_others_events', 'ee_read_private_events')
228
+				),
229
+				new EE_Meta_Capability_Map_Read(
230
+					'ee_read_venue',
231
+					array('Venue', '', 'ee_read_others_venues', 'ee_read_private_venues')
232
+				),
233
+				new EE_Meta_Capability_Map_Read(
234
+					'ee_read_registration',
235
+					array('Registration', '', 'ee_read_others_registrations', '')
236
+				),
237
+				new EE_Meta_Capability_Map_Read(
238
+					'ee_read_checkin',
239
+					array('Registration', '', 'ee_read_others_checkins', '')
240
+				),
241
+				new EE_Meta_Capability_Map_Messages_Cap(
242
+					'ee_read_message',
243
+					array('Message_Template_Group', '', 'ee_read_others_messages', 'ee_read_global_messages')
244
+				),
245
+				new EE_Meta_Capability_Map_Read(
246
+					'ee_read_default_ticket',
247
+					array('Ticket', '', 'ee_read_others_default_tickets', '')
248
+				),
249
+				new EE_Meta_Capability_Map_Read(
250
+					'ee_read_payment_method',
251
+					array('Payment_Method', '', 'ee_read_others_payment_methods', '')
252
+				),
253
+				//deletes
254
+				new EE_Meta_Capability_Map_Delete(
255
+					'ee_delete_event',
256
+					array(
257
+						'Event',
258
+						'ee_delete_published_events',
259
+						'ee_delete_others_events',
260
+						'ee_delete_private_events',
261
+					)
262
+				),
263
+				new EE_Meta_Capability_Map_Delete(
264
+					'ee_delete_venue',
265
+					array(
266
+						'Venue',
267
+						'ee_delete_published_venues',
268
+						'ee_delete_others_venues',
269
+						'ee_delete_private_venues',
270
+					)
271
+				),
272
+				new EE_Meta_Capability_Map_Delete(
273
+					'ee_delete_registration',
274
+					array('Registration', '', 'ee_delete_others_registrations', '')
275
+				),
276
+				new EE_Meta_Capability_Map_Delete(
277
+					'ee_delete_checkin',
278
+					array('Registration', '', 'ee_delete_others_checkins', '')
279
+				),
280
+				new EE_Meta_Capability_Map_Messages_Cap(
281
+					'ee_delete_message',
282
+					array('Message_Template_Group', '', 'ee_delete_others_messages', 'ee_delete_global_messages')
283
+				),
284
+				new EE_Meta_Capability_Map_Delete(
285
+					'ee_delete_default_ticket',
286
+					array('Ticket', '', 'ee_delete_others_default_tickets', '')
287
+				),
288
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
289
+					'ee_delete_question',
290
+					array('Question', '', '', 'delete_system_questions')
291
+				),
292
+				new EE_Meta_Capability_Map_Registration_Form_Cap(
293
+					'ee_delete_question_group',
294
+					array('Question_Group', '', '', 'delete_system_question_groups')
295
+				),
296
+				new EE_Meta_Capability_Map_Delete(
297
+					'ee_delete_payment_method',
298
+					array('Payment_Method', '', 'ee_delete_others_payment_methods', '')
299
+				),
300
+			);
301
+		}
302
+		return $default_meta_caps;
303
+	}
304
+
305
+
306
+
307
+	/**
308
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
309
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
310
+	 *
311
+	 * The actual logic is carried out by implementer classes in their definition of _map_meta_caps.
312
+	 *
313
+	 * @since 4.5.0
314
+	 * @see   wp-includes/capabilities.php
315
+	 *
316
+	 * @param array  $caps    actual users capabilities
317
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
318
+	 * @param int    $user_id The user id
319
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
320
+	 * @return array actual users capabilities
321
+	 * @throws EE_Error
322
+	 */
323
+	public function map_meta_caps($caps, $cap, $user_id, $args)
324
+	{
325
+		if (did_action('AHEE__EE_System__load_espresso_addons__complete')) {
326
+			//loop through our _meta_caps array
327
+			foreach ($this->_meta_caps as $meta_map) {
328
+				if (! $meta_map instanceof EE_Meta_Capability_Map) {
329
+					continue;
330
+				}
331
+				// don't load models if there is no object ID in the args
332
+				if (! empty($args[0])) {
333
+					$meta_map->ensure_is_model();
334
+				}
335
+				$caps = $meta_map->map_meta_caps($caps, $cap, $user_id, $args);
336
+			}
337
+		}
338
+		return $caps;
339
+	}
340
+
341
+
342
+
343
+	/**
344
+	 * This sets up and returns the initial capabilities map for Event Espresso
345
+	 * Note this array is filtered.
346
+	 * It is assumed that all available EE capabilities are assigned to the administrator role.
347
+	 *
348
+	 * @since 4.5.0
349
+	 *
350
+	 * @return array
351
+	 */
352
+	private function _init_caps_map()
353
+	{
354
+		return apply_filters(
355
+			'FHEE__EE_Capabilities__init_caps_map__caps',
356
+			array(
357
+				'administrator'           => array(
358
+					//basic access
359
+					'ee_read_ee',
360
+					//gateways
361
+					/**
362
+					 * note that with payment method capabilities, although we've implemented
363
+					 * capability mapping which will be used for accessing payment methods owned by
364
+					 * other users.  This is not fully implemented yet in the payment method ui.
365
+					 * Currently only the "plural" caps are in active use.
366
+					 * (Specific payment method caps are in use as well).
367
+					 **/
368
+					'ee_manage_gateways',
369
+					'ee_read_payment_methods',
370
+					'ee_read_others_payment_methods',
371
+					'ee_edit_payment_methods',
372
+					'ee_edit_others_payment_methods',
373
+					'ee_delete_payment_methods',
374
+					//events
375
+					'ee_publish_events',
376
+					'ee_read_private_events',
377
+					'ee_read_others_events',
378
+					'ee_read_events',
379
+					'ee_edit_events',
380
+					'ee_edit_published_events',
381
+					'ee_edit_others_events',
382
+					'ee_edit_private_events',
383
+					'ee_delete_published_events',
384
+					'ee_delete_private_events',
385
+					'ee_delete_events',
386
+					'ee_delete_others_events',
387
+					//event categories
388
+					'ee_manage_event_categories',
389
+					'ee_edit_event_category',
390
+					'ee_delete_event_category',
391
+					'ee_assign_event_category',
392
+					//venues
393
+					'ee_publish_venues',
394
+					'ee_read_venues',
395
+					'ee_read_others_venues',
396
+					'ee_read_private_venues',
397
+					'ee_edit_venues',
398
+					'ee_edit_others_venues',
399
+					'ee_edit_published_venues',
400
+					'ee_edit_private_venues',
401
+					'ee_delete_venues',
402
+					'ee_delete_others_venues',
403
+					'ee_delete_private_venues',
404
+					'ee_delete_published_venues',
405
+					//venue categories
406
+					'ee_manage_venue_categories',
407
+					'ee_edit_venue_category',
408
+					'ee_delete_venue_category',
409
+					'ee_assign_venue_category',
410
+					//contacts
411
+					'ee_read_contacts',
412
+					'ee_edit_contacts',
413
+					'ee_delete_contacts',
414
+					//registrations
415
+					'ee_read_registrations',
416
+					'ee_read_others_registrations',
417
+					'ee_edit_registrations',
418
+					'ee_edit_others_registrations',
419
+					'ee_delete_registrations',
420
+					//checkins
421
+					'ee_read_others_checkins',
422
+					'ee_read_checkins',
423
+					'ee_edit_checkins',
424
+					'ee_edit_others_checkins',
425
+					'ee_delete_checkins',
426
+					'ee_delete_others_checkins',
427
+					//transactions && payments
428
+					'ee_read_transaction',
429
+					'ee_read_transactions',
430
+					'ee_edit_payments',
431
+					'ee_delete_payments',
432
+					//messages
433
+					'ee_read_messages',
434
+					'ee_read_others_messages',
435
+					'ee_read_global_messages',
436
+					'ee_edit_global_messages',
437
+					'ee_edit_messages',
438
+					'ee_edit_others_messages',
439
+					'ee_delete_messages',
440
+					'ee_delete_others_messages',
441
+					'ee_delete_global_messages',
442
+					'ee_send_message',
443
+					//tickets
444
+					'ee_read_default_tickets',
445
+					'ee_read_others_default_tickets',
446
+					'ee_edit_default_tickets',
447
+					'ee_edit_others_default_tickets',
448
+					'ee_delete_default_tickets',
449
+					'ee_delete_others_default_tickets',
450
+					//prices
451
+					'ee_edit_default_price',
452
+					'ee_edit_default_prices',
453
+					'ee_delete_default_price',
454
+					'ee_delete_default_prices',
455
+					'ee_edit_default_price_type',
456
+					'ee_edit_default_price_types',
457
+					'ee_delete_default_price_type',
458
+					'ee_delete_default_price_types',
459
+					'ee_read_default_prices',
460
+					'ee_read_default_price_types',
461
+					//registration form
462
+					'ee_edit_questions',
463
+					'ee_edit_system_questions',
464
+					'ee_read_questions',
465
+					'ee_delete_questions',
466
+					'ee_edit_question_groups',
467
+					'ee_read_question_groups',
468
+					'ee_edit_system_question_groups',
469
+					'ee_delete_question_groups',
470
+					//event_type taxonomy
471
+					'ee_assign_event_type',
472
+					'ee_manage_event_types',
473
+					'ee_edit_event_type',
474
+					'ee_delete_event_type',
475
+				),
476
+				'ee_events_administrator' => array(
477
+					//core wp caps
478
+					'read',
479
+					'read_private_pages',
480
+					'read_private_posts',
481
+					'edit_users',
482
+					'edit_posts',
483
+					'edit_pages',
484
+					'edit_published_posts',
485
+					'edit_published_pages',
486
+					'edit_private_pages',
487
+					'edit_private_posts',
488
+					'edit_others_posts',
489
+					'edit_others_pages',
490
+					'publish_posts',
491
+					'publish_pages',
492
+					'delete_posts',
493
+					'delete_pages',
494
+					'delete_private_pages',
495
+					'delete_private_posts',
496
+					'delete_published_pages',
497
+					'delete_published_posts',
498
+					'delete_others_posts',
499
+					'delete_others_pages',
500
+					'manage_categories',
501
+					'manage_links',
502
+					'moderate_comments',
503
+					'unfiltered_html',
504
+					'upload_files',
505
+					'export',
506
+					'import',
507
+					'list_users',
508
+					'level_1', //required if user with this role shows up in author dropdowns
509
+					//basic ee access
510
+					'ee_read_ee',
511
+					//events
512
+					'ee_publish_events',
513
+					'ee_read_private_events',
514
+					'ee_read_others_events',
515
+					'ee_read_event',
516
+					'ee_read_events',
517
+					'ee_edit_event',
518
+					'ee_edit_events',
519
+					'ee_edit_published_events',
520
+					'ee_edit_others_events',
521
+					'ee_edit_private_events',
522
+					'ee_delete_published_events',
523
+					'ee_delete_private_events',
524
+					'ee_delete_event',
525
+					'ee_delete_events',
526
+					'ee_delete_others_events',
527
+					//event categories
528
+					'ee_manage_event_categories',
529
+					'ee_edit_event_category',
530
+					'ee_delete_event_category',
531
+					'ee_assign_event_category',
532
+					//venues
533
+					'ee_publish_venues',
534
+					'ee_read_venue',
535
+					'ee_read_venues',
536
+					'ee_read_others_venues',
537
+					'ee_read_private_venues',
538
+					'ee_edit_venue',
539
+					'ee_edit_venues',
540
+					'ee_edit_others_venues',
541
+					'ee_edit_published_venues',
542
+					'ee_edit_private_venues',
543
+					'ee_delete_venue',
544
+					'ee_delete_venues',
545
+					'ee_delete_others_venues',
546
+					'ee_delete_private_venues',
547
+					'ee_delete_published_venues',
548
+					//venue categories
549
+					'ee_manage_venue_categories',
550
+					'ee_edit_venue_category',
551
+					'ee_delete_venue_category',
552
+					'ee_assign_venue_category',
553
+					//contacts
554
+					'ee_read_contacts',
555
+					'ee_edit_contacts',
556
+					'ee_delete_contacts',
557
+					//registrations
558
+					'ee_read_registrations',
559
+					'ee_read_others_registrations',
560
+					'ee_edit_registration',
561
+					'ee_edit_registrations',
562
+					'ee_edit_others_registrations',
563
+					'ee_delete_registration',
564
+					'ee_delete_registrations',
565
+					//checkins
566
+					'ee_read_others_checkins',
567
+					'ee_read_checkins',
568
+					'ee_edit_checkins',
569
+					'ee_edit_others_checkins',
570
+					'ee_delete_checkins',
571
+					'ee_delete_others_checkins',
572
+					//transactions && payments
573
+					'ee_read_transaction',
574
+					'ee_read_transactions',
575
+					'ee_edit_payments',
576
+					'ee_delete_payments',
577
+					//messages
578
+					'ee_read_messages',
579
+					'ee_read_others_messages',
580
+					'ee_read_global_messages',
581
+					'ee_edit_global_messages',
582
+					'ee_edit_messages',
583
+					'ee_edit_others_messages',
584
+					'ee_delete_messages',
585
+					'ee_delete_others_messages',
586
+					'ee_delete_global_messages',
587
+					'ee_send_message',
588
+					//tickets
589
+					'ee_read_default_tickets',
590
+					'ee_read_others_default_tickets',
591
+					'ee_edit_default_tickets',
592
+					'ee_edit_others_default_tickets',
593
+					'ee_delete_default_tickets',
594
+					'ee_delete_others_default_tickets',
595
+					//prices
596
+					'ee_edit_default_price',
597
+					'ee_edit_default_prices',
598
+					'ee_delete_default_price',
599
+					'ee_delete_default_prices',
600
+					'ee_edit_default_price_type',
601
+					'ee_edit_default_price_types',
602
+					'ee_delete_default_price_type',
603
+					'ee_delete_default_price_types',
604
+					'ee_read_default_prices',
605
+					'ee_read_default_price_types',
606
+					//registration form
607
+					'ee_edit_questions',
608
+					'ee_edit_system_questions',
609
+					'ee_read_questions',
610
+					'ee_delete_questions',
611
+					'ee_edit_question_groups',
612
+					'ee_read_question_groups',
613
+					'ee_edit_system_question_groups',
614
+					'ee_delete_question_groups',
615
+					//event_type taxonomy
616
+					'ee_assign_event_type',
617
+					'ee_manage_event_types',
618
+					'ee_edit_event_type',
619
+					'ee_delete_event_type',
620
+				)
621
+			)
622
+		);
623
+	}
624
+
625
+
626
+
627
+	/**
628
+	 * @return bool
629
+	 * @throws EE_Error
630
+	 */
631
+	private function setupCapabilitiesMap()
632
+	{
633
+		// if the initialization process hasn't even started, then we need to call init_caps()
634
+		if($this->initialized === null) {
635
+			return $this->init_caps();
636
+		}
637
+		// unless resetting, get caps from db if we haven't already
638
+		$this->capabilities_map = $this->reset || ! empty($this->capabilities_map)
639
+			? $this->capabilities_map
640
+			: get_option(self::option_name, array());
641
+		return true;
642
+	}
643
+
644
+
645
+
646
+	/**
647
+	 * @param bool $update
648
+	 * @return bool
649
+	 */
650
+	private function updateCapabilitiesMap($update = true)
651
+	{
652
+		return $update ? update_option(self::option_name, $this->capabilities_map) : false;
653
+	}
654
+
655
+
656
+
657
+	/**
658
+	 * Adds capabilities to roles.
659
+	 *
660
+	 * @since 4.9.42
661
+	 * @param array $capabilities_to_add array of capabilities to add, indexed by roles.
662
+	 *                                   Note that this should ONLY be called on activation hook
663
+	 *                                   otherwise the caps will be added on every request.
664
+	 * @return bool
665
+	 * @throws \EE_Error
666
+	 */
667
+	public function addCaps(array $capabilities_to_add)
668
+	{
669
+		// don't do anything if the capabilities map can not be initialized
670
+		if (! $this->setupCapabilitiesMap()) {
671
+			return false;
672
+		}
673
+		// and filter the array so others can get in on the fun during resets
674
+		$capabilities_to_add = apply_filters(
675
+			'FHEE__EE_Capabilities__addCaps__capabilities_to_add',
676
+			$capabilities_to_add,
677
+			$this->reset,
678
+			$this->capabilities_map
679
+		);
680
+		$update_capabilities_map = false;
681
+		// if not reset, see what caps are new for each role. if they're new, add them.
682
+		foreach ($capabilities_to_add as $role => $caps_for_role) {
683
+			if (is_array($caps_for_role)) {
684
+				foreach ($caps_for_role as $cap) {
685
+					if (
686
+						! $this->capHasBeenAddedToRole($role, $cap)
687
+						&& $this->add_cap_to_role($role, $cap, true, false)
688
+					) {
689
+						$update_capabilities_map = true;
690
+					}
691
+				}
692
+			}
693
+		}
694
+		// now let's just save the cap that has been set but only if there's been a change.
695
+		$updated = $this->updateCapabilitiesMap($update_capabilities_map);
696
+		$this->flushWpUser($updated);
697
+		do_action('AHEE__EE_Capabilities__addCaps__complete', $this->capabilities_map, $updated);
698
+		return $updated;
699
+	}
700
+
701
+
702
+
703
+	/**
704
+	 * Loops through the capabilities map and removes the role caps specified by the incoming array
705
+	 *
706
+	 * @param array $caps_map map of capabilities to be removed (indexed by roles)
707
+	 * @return bool
708
+	 * @throws \EE_Error
709
+	 */
710
+	public function removeCaps($caps_map)
711
+	{
712
+		// don't do anything if the capabilities map can not be initialized
713
+		if (! $this->setupCapabilitiesMap()) {
714
+			return false;
715
+		}
716
+		$update_capabilities_map = false;
717
+		foreach ($caps_map as $role => $caps_for_role) {
718
+			if (is_array($caps_for_role)) {
719
+				foreach ($caps_for_role as $cap) {
720
+					if ($this->capHasBeenAddedToRole($role, $cap)
721
+						&& $this->remove_cap_from_role($role, $cap, false)
722
+					) {
723
+						$update_capabilities_map = true;
724
+					}
725
+				}
726
+			}
727
+		}
728
+		// maybe resave the caps
729
+		$updated = $this->updateCapabilitiesMap($update_capabilities_map);
730
+		$this->flushWpUser($updated);
731
+		return $updated;
732
+	}
733
+
734
+
735
+	/**
736
+	 * This ensures that the WP User object cached on the $current_user global in WP has the latest capabilities from
737
+	 * the roles on that user.
738
+	 *
739
+	 * @param bool $flush  Default is to flush the WP_User object.  If false, then this method effectively does nothing.
740
+	 */
741
+	private function flushWpUser($flush = true)
742
+	{
743
+		if ($flush) {
744
+			$user = wp_get_current_user();
745
+			if ($user instanceof WP_User) {
746
+				$user->get_role_caps();
747
+			}
748
+		}
749
+	}
750
+
751
+
752
+
753
+	/**
754
+	 * This method sets a capability on a role.  Note this should only be done on activation, or if you have something
755
+	 * specific to prevent the cap from being added on every page load (adding caps are persistent to the db). Note.
756
+	 * this is a wrapper for $wp_role->add_cap()
757
+	 *
758
+	 * @see   wp-includes/capabilities.php
759
+	 * @since 4.5.0
760
+	 * @param string|WP_Role $role  A WordPress role the capability is being added to
761
+	 * @param string         $cap   The capability being added to the role
762
+	 * @param bool           $grant Whether to grant access to this cap on this role.
763
+	 * @param bool           $update_capabilities_map
764
+	 * @return bool
765
+	 * @throws \EE_Error
766
+	 */
767
+	public function add_cap_to_role($role, $cap, $grant = true, $update_capabilities_map = true)
768
+	{
769
+		// capture incoming value for $role because we may need it to create a new WP_Role
770
+		$orig_role = $role;
771
+		$role = $role instanceof WP_Role ? $role : get_role($role);
772
+		//if the role isn't available then we create it.
773
+		if (! $role instanceof WP_Role) {
774
+			// if a plugin wants to create a specific role name then they should create the role before
775
+			// EE_Capabilities does.  Otherwise this function will create the role name from the slug:
776
+			// - removes any `ee_` namespacing from the start of the slug.
777
+			// - replaces `_` with ` ` (empty space).
778
+			// - sentence case on the resulting string.
779
+			$role_label = ucwords(str_replace(array('ee_', '_'), array('', ' '), $orig_role));
780
+			$role = add_role($orig_role, $role_label);
781
+		}
782
+		if ($role instanceof WP_Role) {
783
+			// don't do anything if the capabilities map can not be initialized
784
+			if (! $this->setupCapabilitiesMap()) {
785
+				return false;
786
+			}
787
+			if (! $this->capHasBeenAddedToRole($role->name, $cap)) {
788
+				$role->add_cap($cap, $grant);
789
+				$this->capabilities_map[ $role->name ][] = $cap;
790
+				$this->updateCapabilitiesMap($update_capabilities_map);
791
+				return true;
792
+			}
793
+		}
794
+		return false;
795
+	}
796
+
797
+
798
+
799
+	/**
800
+	 * Functions similarly to add_cap_to_role except removes cap from given role.
801
+	 * Wrapper for $wp_role->remove_cap()
802
+	 *
803
+	 * @see   wp-includes/capabilities.php
804
+	 * @since 4.5.0
805
+	 * @param string|WP_Role $role A WordPress role the capability is being removed from.
806
+	 * @param string         $cap  The capability being removed
807
+	 * @param bool           $update_capabilities_map
808
+	 * @return bool
809
+	 * @throws \EE_Error
810
+	 */
811
+	public function remove_cap_from_role($role, $cap, $update_capabilities_map = true)
812
+	{
813
+		// don't do anything if the capabilities map can not be initialized
814
+		if (! $this->setupCapabilitiesMap()) {
815
+			return false;
816
+		}
817
+		$role = $role instanceof WP_Role ? $role :get_role($role);
818
+		if ($index = $this->capHasBeenAddedToRole($role->name, $cap, true)) {
819
+			$role->remove_cap($cap);
820
+			unset($this->capabilities_map[ $role->name ][ $index ]);
821
+			$this->updateCapabilitiesMap($update_capabilities_map);
822
+			return true;
823
+		}
824
+		return false;
825
+	}
826
+
827
+
828
+
829
+	/**
830
+	 * @param string $role_name
831
+	 * @param string $cap
832
+	 * @param bool   $get_index
833
+	 * @return bool|mixed
834
+	 */
835
+	private function capHasBeenAddedToRole($role_name='', $cap='', $get_index = false)
836
+	{
837
+		if (
838
+			isset($this->capabilities_map[$role_name])
839
+			&& ($index = array_search($cap, $this->capabilities_map[$role_name], true)) !== false
840
+		) {
841
+			return $get_index ? $index : true;
842
+		}
843
+		return false;
844
+	}
845
+
846
+
847
+
848
+	/**
849
+	 * Wrapper for the native WP current_user_can() method.
850
+	 * This is provided as a handy method for a couple things:
851
+	 * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
852
+	 * write those filters wherever current_user_can is called).
853
+	 * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
854
+	 *
855
+	 * @since 4.5.0
856
+	 *
857
+	 * @param string $cap     The cap being checked.
858
+	 * @param string $context The context where the current_user_can is being called from.
859
+	 * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
860
+	 *                        filters.
861
+	 *
862
+	 * @return bool  Whether user can or not.
863
+	 */
864
+	public function current_user_can($cap, $context, $id = 0)
865
+	{
866
+		//apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
867
+		$filtered_cap = apply_filters('FHEE__EE_Capabilities__current_user_can__cap__' . $context, $cap, $id);
868
+		$filtered_cap = apply_filters(
869
+			'FHEE__EE_Capabilities__current_user_can__cap',
870
+			$filtered_cap,
871
+			$context,
872
+			$cap,
873
+			$id
874
+		);
875
+		return ! empty($id)
876
+			? current_user_can($filtered_cap, $id)
877
+			: current_user_can($filtered_cap);
878
+	}
879
+
880
+
881
+
882
+	/**
883
+	 * This is a wrapper for the WP user_can() function and follows the same style as the other wrappers in this class.
884
+	 *
885
+	 * @param int|WP_User $user    Either the user_id or a WP_User object
886
+	 * @param string      $cap     The capability string being checked
887
+	 * @param string      $context The context where the user_can is being called from (used in filters).
888
+	 * @param int         $id      Optional. Id for item where user_can is being called from ( used in map_meta_cap()
889
+	 *                             filters)
890
+	 *
891
+	 * @return bool Whether user can or not.
892
+	 */
893
+	public function user_can($user, $cap, $context, $id = 0)
894
+	{
895
+		//apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
896
+		$filtered_cap = apply_filters('FHEE__EE_Capabilities__user_can__cap__' . $context, $cap, $user, $id);
897
+		$filtered_cap = apply_filters(
898
+			'FHEE__EE_Capabilities__user_can__cap',
899
+			$filtered_cap,
900
+			$context,
901
+			$cap,
902
+			$user,
903
+			$id
904
+		);
905
+		return ! empty($id)
906
+			? user_can($user, $filtered_cap, $id)
907
+			: user_can($user, $filtered_cap);
908
+	}
909
+
910
+
911
+
912
+	/**
913
+	 * Wrapper for the native WP current_user_can_for_blog() method.
914
+	 * This is provided as a handy method for a couple things:
915
+	 * 1. Using the context string it allows for targeted filtering by addons for a specific check (without having to
916
+	 * write those filters wherever current_user_can is called).
917
+	 * 2. Explicit passing of $id from a given context ( useful in the cases of map_meta_cap filters )
918
+	 *
919
+	 * @since 4.5.0
920
+	 *
921
+	 * @param int    $blog_id The blog id that is being checked for.
922
+	 * @param string $cap     The cap being checked.
923
+	 * @param string $context The context where the current_user_can is being called from.
924
+	 * @param int    $id      Optional. Id for item where current_user_can is being called from (used in map_meta_cap()
925
+	 *                        filters.
926
+	 *
927
+	 * @return bool  Whether user can or not.
928
+	 */
929
+	public function current_user_can_for_blog($blog_id, $cap, $context, $id = 0)
930
+	{
931
+		$user_can = ! empty($id)
932
+			? current_user_can_for_blog($blog_id, $cap, $id)
933
+			: current_user_can($blog_id, $cap);
934
+		//apply filters (both a global on just the cap, and context specific.  Global overrides context specific)
935
+		$user_can = apply_filters(
936
+			'FHEE__EE_Capabilities__current_user_can_for_blog__user_can__' . $context,
937
+			$user_can,
938
+			$blog_id,
939
+			$cap,
940
+			$id
941
+		);
942
+		$user_can = apply_filters(
943
+			'FHEE__EE_Capabilities__current_user_can_for_blog__user_can',
944
+			$user_can,
945
+			$context,
946
+			$blog_id,
947
+			$cap,
948
+			$id
949
+		);
950
+		return $user_can;
951
+	}
952
+
953
+
954
+
955
+	/**
956
+	 * This helper method just returns an array of registered EE capabilities.
957
+	 *
958
+	 * @since 4.5.0
959
+	 * @param string $role If empty then the entire role/capability map is returned.
960
+	 *                     Otherwise just the capabilities for the given role are returned.
961
+	 * @return array
962
+	 * @throws EE_Error
963
+	 */
964
+	public function get_ee_capabilities($role = 'administrator')
965
+	{
966
+		if (! $this->initialized) {
967
+			$this->init_caps();
968
+		}
969
+		if (empty($role)) {
970
+			return $this->capabilities_map;
971
+		}
972
+		return isset($this->capabilities_map[ $role ])
973
+			? $this->capabilities_map[ $role ]
974
+			: array();
975
+	}
976
+
977
+
978
+
979
+	/**
980
+	 * @deprecated 4.9.42
981
+	 * @param bool  $reset      If you need to reset Event Espresso's capabilities,
982
+	 *                          then please use the init_caps() method with the "$reset" parameter set to "true"
983
+	 * @param array $caps_map   Optional.
984
+	 *                          Can be used to send a custom map of roles and capabilities for setting them up.
985
+	 *                          Note that this should ONLY be called on activation hook or some other one-time
986
+	 *                          task otherwise the caps will be added on every request.
987
+	 * @return void
988
+	 * @throws EE_Error
989
+	 */
990
+	public function init_role_caps($reset = false, $caps_map = array())
991
+	{
992
+		// If this method is called directly and reset is set as 'true',
993
+		// then display a doing it wrong notice, because we want resets to go through init_caps()
994
+		// to guarantee that everything is set up correctly.
995
+		// This prevents the capabilities map getting reset incorrectly by direct calls to this method.
996
+		if ($reset) {
997
+			EE_Error::doing_it_wrong(
998
+				__METHOD__,
999
+				sprintf(
1000
+					esc_html__(
1001
+						'The "%1$s" parameter for the "%2$s" method is deprecated. If you need to reset Event Espresso\'s capabilities, then please use the "%3$s" method with the "%1$s" parameter set to "%4$s".',
1002
+						'event_espresso'
1003
+					),
1004
+					'$reset',
1005
+					__METHOD__ . '()',
1006
+					'EE_Capabilities::init_caps()',
1007
+					'true'
1008
+				),
1009
+				'4.9.42',
1010
+				'5.0.0'
1011
+			);
1012
+		}
1013
+		$this->addCaps($caps_map);
1014
+	}
1015 1015
 
1016 1016
 
1017 1017
 
@@ -1032,142 +1032,142 @@  discard block
 block discarded – undo
1032 1032
 abstract class EE_Meta_Capability_Map
1033 1033
 {
1034 1034
 
1035
-    public $meta_cap;
1036
-
1037
-    /**
1038
-     * @var EEM_Base
1039
-     */
1040
-    protected $_model;
1041
-
1042
-    protected $_model_name;
1043
-
1044
-    public $published_cap = '';
1045
-
1046
-    public $others_cap = '';
1047
-
1048
-    public $private_cap = '';
1049
-
1050
-
1051
-    /**
1052
-     * constructor.
1053
-     * Receives the setup arguments for the map.
1054
-     *
1055
-     * @since                        4.5.0
1056
-     *
1057
-     * @param string $meta_cap   What meta capability is this mapping.
1058
-     * @param array  $map_values array {
1059
-     *                           //array of values that MUST match a count of 4.  It's okay to send an empty string for
1060
-     *                           capabilities that don't get mapped to.
1061
-     *
1062
-     * @type         $map_values [0] string A string representing the model name. Required.  String's
1063
-     *                               should always be used when Menu Maps are registered via the
1064
-     *                               plugin API as models are not allowed to be instantiated when
1065
-     *                               in maintenance mode 2 (migrations).
1066
-     * @type         $map_values [1] string represents the capability used for published. Optional.
1067
-     * @type         $map_values [2] string represents the capability used for "others". Optional.
1068
-     * @type         $map_values [3] string represents the capability used for private. Optional.
1069
-     *                               }
1070
-     * @throws EE_Error
1071
-     */
1072
-    public function __construct($meta_cap, $map_values)
1073
-    {
1074
-        $this->meta_cap = $meta_cap;
1075
-        //verify there are four args in the $map_values array;
1076
-        if (count($map_values) !== 4) {
1077
-            throw new EE_Error(
1078
-                sprintf(
1079
-                    __(
1080
-                        'Incoming $map_values array should have a count of four values in it.  This is what was given: %s',
1081
-                        'event_espresso'
1082
-                    ),
1083
-                    '<br>' . print_r($map_values, true)
1084
-                )
1085
-            );
1086
-        }
1087
-        //set properties
1088
-        $this->_model = null;
1089
-        $this->_model_name = $map_values[0];
1090
-        $this->published_cap = (string)$map_values[1];
1091
-        $this->others_cap = (string)$map_values[2];
1092
-        $this->private_cap = (string)$map_values[3];
1093
-    }
1094
-
1095
-    /**
1096
-     * Makes it so this object stops filtering caps
1097
-     */
1098
-    public function remove_filters()
1099
-    {
1100
-        remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10);
1101
-    }
1102
-
1103
-
1104
-    /**
1105
-     * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class
1106
-     *
1107
-     * @since 4.5.0
1108
-     * @throws EE_Error
1109
-     *
1110
-     * @return void
1111
-     */
1112
-    public function ensure_is_model()
1113
-    {
1114
-        //is it already instantiated?
1115
-        if ($this->_model instanceof EEM_Base) {
1116
-            return;
1117
-        }
1118
-        //ensure model name is string
1119
-        $this->_model_name = (string)$this->_model_name;
1120
-        //error proof if the name has EEM in it
1121
-        $this->_model_name = str_replace('EEM', '', $this->_model_name);
1122
-        $this->_model = EE_Registry::instance()->load_model($this->_model_name);
1123
-        if (! $this->_model instanceof EEM_Base) {
1124
-            throw new EE_Error(
1125
-                sprintf(
1126
-                    __(
1127
-                        'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class.   Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s',
1128
-                        'event_espresso'
1129
-                    ),
1130
-                    get_class($this),
1131
-                    $this->_model
1132
-                )
1133
-            );
1134
-        }
1135
-    }
1136
-
1137
-
1138
-    /**
1139
-     *
1140
-     * @see   EE_Meta_Capability_Map::_map_meta_caps() for docs on params.
1141
-     * @since 4.6.x
1142
-     *
1143
-     * @param $caps
1144
-     * @param $cap
1145
-     * @param $user_id
1146
-     * @param $args
1147
-     *
1148
-     * @return array
1149
-     */
1150
-    public function map_meta_caps($caps, $cap, $user_id, $args)
1151
-    {
1152
-        return $this->_map_meta_caps($caps, $cap, $user_id, $args);
1153
-    }
1154
-
1155
-
1156
-    /**
1157
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1158
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1159
-     *
1160
-     * @since 4.5.0
1161
-     * @see   wp-includes/capabilities.php
1162
-     *
1163
-     * @param array  $caps    actual users capabilities
1164
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1165
-     * @param int    $user_id The user id
1166
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1167
-     *
1168
-     * @return array   actual users capabilities
1169
-     */
1170
-    abstract protected function _map_meta_caps($caps, $cap, $user_id, $args);
1035
+	public $meta_cap;
1036
+
1037
+	/**
1038
+	 * @var EEM_Base
1039
+	 */
1040
+	protected $_model;
1041
+
1042
+	protected $_model_name;
1043
+
1044
+	public $published_cap = '';
1045
+
1046
+	public $others_cap = '';
1047
+
1048
+	public $private_cap = '';
1049
+
1050
+
1051
+	/**
1052
+	 * constructor.
1053
+	 * Receives the setup arguments for the map.
1054
+	 *
1055
+	 * @since                        4.5.0
1056
+	 *
1057
+	 * @param string $meta_cap   What meta capability is this mapping.
1058
+	 * @param array  $map_values array {
1059
+	 *                           //array of values that MUST match a count of 4.  It's okay to send an empty string for
1060
+	 *                           capabilities that don't get mapped to.
1061
+	 *
1062
+	 * @type         $map_values [0] string A string representing the model name. Required.  String's
1063
+	 *                               should always be used when Menu Maps are registered via the
1064
+	 *                               plugin API as models are not allowed to be instantiated when
1065
+	 *                               in maintenance mode 2 (migrations).
1066
+	 * @type         $map_values [1] string represents the capability used for published. Optional.
1067
+	 * @type         $map_values [2] string represents the capability used for "others". Optional.
1068
+	 * @type         $map_values [3] string represents the capability used for private. Optional.
1069
+	 *                               }
1070
+	 * @throws EE_Error
1071
+	 */
1072
+	public function __construct($meta_cap, $map_values)
1073
+	{
1074
+		$this->meta_cap = $meta_cap;
1075
+		//verify there are four args in the $map_values array;
1076
+		if (count($map_values) !== 4) {
1077
+			throw new EE_Error(
1078
+				sprintf(
1079
+					__(
1080
+						'Incoming $map_values array should have a count of four values in it.  This is what was given: %s',
1081
+						'event_espresso'
1082
+					),
1083
+					'<br>' . print_r($map_values, true)
1084
+				)
1085
+			);
1086
+		}
1087
+		//set properties
1088
+		$this->_model = null;
1089
+		$this->_model_name = $map_values[0];
1090
+		$this->published_cap = (string)$map_values[1];
1091
+		$this->others_cap = (string)$map_values[2];
1092
+		$this->private_cap = (string)$map_values[3];
1093
+	}
1094
+
1095
+	/**
1096
+	 * Makes it so this object stops filtering caps
1097
+	 */
1098
+	public function remove_filters()
1099
+	{
1100
+		remove_filter('map_meta_cap', array($this, 'map_meta_caps'), 10);
1101
+	}
1102
+
1103
+
1104
+	/**
1105
+	 * This method ensures that the $model property is converted from the model name string to a proper EEM_Base class
1106
+	 *
1107
+	 * @since 4.5.0
1108
+	 * @throws EE_Error
1109
+	 *
1110
+	 * @return void
1111
+	 */
1112
+	public function ensure_is_model()
1113
+	{
1114
+		//is it already instantiated?
1115
+		if ($this->_model instanceof EEM_Base) {
1116
+			return;
1117
+		}
1118
+		//ensure model name is string
1119
+		$this->_model_name = (string)$this->_model_name;
1120
+		//error proof if the name has EEM in it
1121
+		$this->_model_name = str_replace('EEM', '', $this->_model_name);
1122
+		$this->_model = EE_Registry::instance()->load_model($this->_model_name);
1123
+		if (! $this->_model instanceof EEM_Base) {
1124
+			throw new EE_Error(
1125
+				sprintf(
1126
+					__(
1127
+						'This string passed in to %s to represent a EEM_Base model class was not able to be used to instantiate the class.   Please ensure that the string is a match for the EEM_Base model name (not including the EEM_ part). This was given: %s',
1128
+						'event_espresso'
1129
+					),
1130
+					get_class($this),
1131
+					$this->_model
1132
+				)
1133
+			);
1134
+		}
1135
+	}
1136
+
1137
+
1138
+	/**
1139
+	 *
1140
+	 * @see   EE_Meta_Capability_Map::_map_meta_caps() for docs on params.
1141
+	 * @since 4.6.x
1142
+	 *
1143
+	 * @param $caps
1144
+	 * @param $cap
1145
+	 * @param $user_id
1146
+	 * @param $args
1147
+	 *
1148
+	 * @return array
1149
+	 */
1150
+	public function map_meta_caps($caps, $cap, $user_id, $args)
1151
+	{
1152
+		return $this->_map_meta_caps($caps, $cap, $user_id, $args);
1153
+	}
1154
+
1155
+
1156
+	/**
1157
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1158
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1159
+	 *
1160
+	 * @since 4.5.0
1161
+	 * @see   wp-includes/capabilities.php
1162
+	 *
1163
+	 * @param array  $caps    actual users capabilities
1164
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1165
+	 * @param int    $user_id The user id
1166
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1167
+	 *
1168
+	 * @return array   actual users capabilities
1169
+	 */
1170
+	abstract protected function _map_meta_caps($caps, $cap, $user_id, $args);
1171 1171
 }
1172 1172
 
1173 1173
 
@@ -1183,81 +1183,81 @@  discard block
 block discarded – undo
1183 1183
 class EE_Meta_Capability_Map_Edit extends EE_Meta_Capability_Map
1184 1184
 {
1185 1185
 
1186
-    /**
1187
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1188
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1189
-     *
1190
-     * @since 4.5.0
1191
-     * @see   wp-includes/capabilities.php
1192
-     *
1193
-     * @param array  $caps    actual users capabilities
1194
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1195
-     * @param int    $user_id The user id
1196
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1197
-     *
1198
-     * @return array   actual users capabilities
1199
-     */
1200
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1201
-    {
1202
-        //only process if we're checking our mapped_cap
1203
-        if ($cap !== $this->meta_cap) {
1204
-            return $caps;
1205
-        }
1206
-
1207
-        //okay it is a meta cap so let's first remove that cap from the $caps array.
1208
-        if (($key = array_search($cap, $caps)) !== false) {
1209
-            unset($caps[$key]);
1210
-        }
1211
-
1212
-        //cast $user_id to int for later explicit comparisons
1213
-        $user_id = (int) $user_id;
1214
-
1215
-        /** @var EE_Base_Class $obj */
1216
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1217
-        //if no obj then let's just do cap
1218
-        if (! $obj instanceof EE_Base_Class) {
1219
-            $caps[] = 'do_not_allow';
1220
-            return $caps;
1221
-        }
1222
-        $caps[] = $cap . 's';
1223
-        if ($obj instanceof EE_CPT_Base) {
1224
-            //if the item author is set and the user is the author...
1225
-            if ($obj->wp_user() && $user_id === $obj->wp_user()) {
1226
-                //if obj is published...
1227
-                if ($obj->status() === 'publish') {
1228
-                    $caps[] = $this->published_cap;
1229
-                }
1230
-            } else {
1231
-                //the user is trying to edit someone else's obj
1232
-                if (! empty($this->others_cap)) {
1233
-                    $caps[] = $this->others_cap;
1234
-                }
1235
-                if (! empty($this->published_cap) && $obj->status() === 'publish') {
1236
-                    $caps[] = $this->published_cap;
1237
-                } elseif (! empty($this->private_cap) && $obj->status() === 'private') {
1238
-                    $caps[] = $this->private_cap;
1239
-                }
1240
-            }
1241
-        } else {
1242
-            //not a cpt object so handled differently
1243
-            $has_cap = false;
1244
-            try {
1245
-                $has_cap = method_exists($obj, 'wp_user')
1246
-                    && $obj->wp_user()
1247
-                    && $obj->wp_user() === $user_id;
1248
-            } catch (Exception $e) {
1249
-                if (WP_DEBUG) {
1250
-                    EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1251
-                }
1252
-            }
1253
-            if (! $has_cap) {
1254
-                if (! empty($this->others_cap)) {
1255
-                    $caps[] = $this->others_cap;
1256
-                }
1257
-            }
1258
-        }
1259
-        return $caps;
1260
-    }
1186
+	/**
1187
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1188
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1189
+	 *
1190
+	 * @since 4.5.0
1191
+	 * @see   wp-includes/capabilities.php
1192
+	 *
1193
+	 * @param array  $caps    actual users capabilities
1194
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1195
+	 * @param int    $user_id The user id
1196
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1197
+	 *
1198
+	 * @return array   actual users capabilities
1199
+	 */
1200
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1201
+	{
1202
+		//only process if we're checking our mapped_cap
1203
+		if ($cap !== $this->meta_cap) {
1204
+			return $caps;
1205
+		}
1206
+
1207
+		//okay it is a meta cap so let's first remove that cap from the $caps array.
1208
+		if (($key = array_search($cap, $caps)) !== false) {
1209
+			unset($caps[$key]);
1210
+		}
1211
+
1212
+		//cast $user_id to int for later explicit comparisons
1213
+		$user_id = (int) $user_id;
1214
+
1215
+		/** @var EE_Base_Class $obj */
1216
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1217
+		//if no obj then let's just do cap
1218
+		if (! $obj instanceof EE_Base_Class) {
1219
+			$caps[] = 'do_not_allow';
1220
+			return $caps;
1221
+		}
1222
+		$caps[] = $cap . 's';
1223
+		if ($obj instanceof EE_CPT_Base) {
1224
+			//if the item author is set and the user is the author...
1225
+			if ($obj->wp_user() && $user_id === $obj->wp_user()) {
1226
+				//if obj is published...
1227
+				if ($obj->status() === 'publish') {
1228
+					$caps[] = $this->published_cap;
1229
+				}
1230
+			} else {
1231
+				//the user is trying to edit someone else's obj
1232
+				if (! empty($this->others_cap)) {
1233
+					$caps[] = $this->others_cap;
1234
+				}
1235
+				if (! empty($this->published_cap) && $obj->status() === 'publish') {
1236
+					$caps[] = $this->published_cap;
1237
+				} elseif (! empty($this->private_cap) && $obj->status() === 'private') {
1238
+					$caps[] = $this->private_cap;
1239
+				}
1240
+			}
1241
+		} else {
1242
+			//not a cpt object so handled differently
1243
+			$has_cap = false;
1244
+			try {
1245
+				$has_cap = method_exists($obj, 'wp_user')
1246
+					&& $obj->wp_user()
1247
+					&& $obj->wp_user() === $user_id;
1248
+			} catch (Exception $e) {
1249
+				if (WP_DEBUG) {
1250
+					EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1251
+				}
1252
+			}
1253
+			if (! $has_cap) {
1254
+				if (! empty($this->others_cap)) {
1255
+					$caps[] = $this->others_cap;
1256
+				}
1257
+			}
1258
+		}
1259
+		return $caps;
1260
+	}
1261 1261
 }
1262 1262
 
1263 1263
 
@@ -1274,24 +1274,24 @@  discard block
 block discarded – undo
1274 1274
 class EE_Meta_Capability_Map_Delete extends EE_Meta_Capability_Map_Edit
1275 1275
 {
1276 1276
 
1277
-    /**
1278
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1279
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1280
-     *
1281
-     * @since 4.5.0
1282
-     * @see   wp-includes/capabilities.php
1283
-     *
1284
-     * @param array  $caps    actual users capabilities
1285
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1286
-     * @param int    $user_id The user id
1287
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1288
-     *
1289
-     * @return array   actual users capabilities
1290
-     */
1291
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1292
-    {
1293
-        return parent::_map_meta_caps($caps, $cap, $user_id, $args);
1294
-    }
1277
+	/**
1278
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1279
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1280
+	 *
1281
+	 * @since 4.5.0
1282
+	 * @see   wp-includes/capabilities.php
1283
+	 *
1284
+	 * @param array  $caps    actual users capabilities
1285
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1286
+	 * @param int    $user_id The user id
1287
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1288
+	 *
1289
+	 * @return array   actual users capabilities
1290
+	 */
1291
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1292
+	{
1293
+		return parent::_map_meta_caps($caps, $cap, $user_id, $args);
1294
+	}
1295 1295
 }
1296 1296
 
1297 1297
 
@@ -1307,85 +1307,85 @@  discard block
 block discarded – undo
1307 1307
 class EE_Meta_Capability_Map_Read extends EE_Meta_Capability_Map
1308 1308
 {
1309 1309
 
1310
-    /**
1311
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1312
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1313
-     *
1314
-     * @since 4.5.0
1315
-     * @see   wp-includes/capabilities.php
1316
-     *
1317
-     * @param array  $caps    actual users capabilities
1318
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1319
-     * @param int    $user_id The user id
1320
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1321
-     *
1322
-     * @return array   actual users capabilities
1323
-     */
1324
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1325
-    {
1326
-        //only process if we're checking our mapped cap;
1327
-        if ($cap !== $this->meta_cap) {
1328
-            return $caps;
1329
-        }
1330
-
1331
-        //okay it is a meta cap so let's first remove that cap from the $caps array.
1332
-        if (($key = array_search($cap, $caps)) !== false) {
1333
-            unset($caps[$key]);
1334
-        }
1335
-
1336
-        //cast $user_id to int for later explicit comparisons
1337
-        $user_id = (int) $user_id;
1338
-
1339
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1340
-        //if no obj then let's just do cap
1341
-        if (! $obj instanceof EE_Base_Class) {
1342
-            $caps[] = 'do_not_allow';
1343
-            return $caps;
1344
-        }
1345
-
1346
-        $caps[] = $cap . 's';
1347
-        if ($obj instanceof EE_CPT_Base) {
1348
-            $status_obj = get_post_status_object($obj->status());
1349
-            if ($status_obj->public) {
1350
-                return $caps;
1351
-            }
1352
-            //if the item author is set and the user is not the author...
1353
-            if ($obj->wp_user() && $obj->wp_user() !== $user_id) {
1354
-                if (! empty($this->others_cap)) {
1355
-                    $caps[] = $this->others_cap;
1356
-                }
1357
-            }
1358
-            //yes this means that if users created the private post, they are able to see it regardless of private cap.
1359
-            if ($status_obj->private
1360
-                && ! empty($this->private_cap)
1361
-                && $obj->wp_user() !== $user_id
1362
-            ) {
1363
-                //the user is trying to view a private object for an object they don't own.
1364
-                $caps[] = $this->private_cap;
1365
-            }
1366
-        } else {
1367
-            //not a cpt object so handled differently
1368
-            $has_cap = false;
1369
-            try {
1370
-                $has_cap = method_exists($obj, 'wp_user')
1371
-                           && $obj->wp_user()
1372
-                           && $obj->wp_user() === $user_id;
1373
-            } catch (Exception $e) {
1374
-                if (WP_DEBUG) {
1375
-                    EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1376
-                }
1377
-            }
1378
-            if (! $has_cap) {
1379
-                if (! empty($this->private_cap)) {
1380
-                    $caps[] = $this->private_cap;
1381
-                }
1382
-                if (! empty($this->others_cap)) {
1383
-                    $caps[] = $this->others_cap;
1384
-                }
1385
-            }
1386
-        }
1387
-        return $caps;
1388
-    }
1310
+	/**
1311
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1312
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1313
+	 *
1314
+	 * @since 4.5.0
1315
+	 * @see   wp-includes/capabilities.php
1316
+	 *
1317
+	 * @param array  $caps    actual users capabilities
1318
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1319
+	 * @param int    $user_id The user id
1320
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1321
+	 *
1322
+	 * @return array   actual users capabilities
1323
+	 */
1324
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1325
+	{
1326
+		//only process if we're checking our mapped cap;
1327
+		if ($cap !== $this->meta_cap) {
1328
+			return $caps;
1329
+		}
1330
+
1331
+		//okay it is a meta cap so let's first remove that cap from the $caps array.
1332
+		if (($key = array_search($cap, $caps)) !== false) {
1333
+			unset($caps[$key]);
1334
+		}
1335
+
1336
+		//cast $user_id to int for later explicit comparisons
1337
+		$user_id = (int) $user_id;
1338
+
1339
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1340
+		//if no obj then let's just do cap
1341
+		if (! $obj instanceof EE_Base_Class) {
1342
+			$caps[] = 'do_not_allow';
1343
+			return $caps;
1344
+		}
1345
+
1346
+		$caps[] = $cap . 's';
1347
+		if ($obj instanceof EE_CPT_Base) {
1348
+			$status_obj = get_post_status_object($obj->status());
1349
+			if ($status_obj->public) {
1350
+				return $caps;
1351
+			}
1352
+			//if the item author is set and the user is not the author...
1353
+			if ($obj->wp_user() && $obj->wp_user() !== $user_id) {
1354
+				if (! empty($this->others_cap)) {
1355
+					$caps[] = $this->others_cap;
1356
+				}
1357
+			}
1358
+			//yes this means that if users created the private post, they are able to see it regardless of private cap.
1359
+			if ($status_obj->private
1360
+				&& ! empty($this->private_cap)
1361
+				&& $obj->wp_user() !== $user_id
1362
+			) {
1363
+				//the user is trying to view a private object for an object they don't own.
1364
+				$caps[] = $this->private_cap;
1365
+			}
1366
+		} else {
1367
+			//not a cpt object so handled differently
1368
+			$has_cap = false;
1369
+			try {
1370
+				$has_cap = method_exists($obj, 'wp_user')
1371
+						   && $obj->wp_user()
1372
+						   && $obj->wp_user() === $user_id;
1373
+			} catch (Exception $e) {
1374
+				if (WP_DEBUG) {
1375
+					EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1376
+				}
1377
+			}
1378
+			if (! $has_cap) {
1379
+				if (! empty($this->private_cap)) {
1380
+					$caps[] = $this->private_cap;
1381
+				}
1382
+				if (! empty($this->others_cap)) {
1383
+					$caps[] = $this->others_cap;
1384
+				}
1385
+			}
1386
+		}
1387
+		return $caps;
1388
+	}
1389 1389
 }
1390 1390
 
1391 1391
 
@@ -1402,56 +1402,56 @@  discard block
 block discarded – undo
1402 1402
 class EE_Meta_Capability_Map_Messages_Cap extends EE_Meta_Capability_Map
1403 1403
 {
1404 1404
 
1405
-    /**
1406
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1407
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1408
-     *
1409
-     * @since 4.5.0
1410
-     * @see   wp-includes/capabilities.php
1411
-     *
1412
-     * @param array  $caps    actual users capabilities
1413
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1414
-     * @param int    $user_id The user id
1415
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1416
-     *
1417
-     * @return array   actual users capabilities
1418
-     */
1419
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1420
-    {
1421
-        //only process if we're checking our mapped_cap
1422
-        if ($cap !== $this->meta_cap) {
1423
-            return $caps;
1424
-        }
1425
-
1426
-        //okay it is a meta cap so let's first remove that cap from the $caps array.
1427
-        if (($key = array_search($cap, $caps)) !== false) {
1428
-            unset($caps[$key]);
1429
-        }
1430
-
1431
-        //cast $user_id to int for later explicit comparisons
1432
-        $user_id = (int) $user_id;
1433
-
1434
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1435
-        //if no obj then let's just do cap
1436
-        if (! $obj instanceof EE_Message_Template_Group) {
1437
-            $caps[] = 'do_not_allow';
1438
-            return $caps;
1439
-        }
1440
-        $caps[] = $cap . 's';
1441
-        $is_global = $obj->is_global();
1442
-        if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1443
-            if ($is_global) {
1444
-                $caps[] = $this->private_cap;
1445
-            }
1446
-        } else {
1447
-            if ($is_global) {
1448
-                $caps[] = $this->private_cap;
1449
-            } else {
1450
-                $caps[] = $this->others_cap;
1451
-            }
1452
-        }
1453
-        return $caps;
1454
-    }
1405
+	/**
1406
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1407
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1408
+	 *
1409
+	 * @since 4.5.0
1410
+	 * @see   wp-includes/capabilities.php
1411
+	 *
1412
+	 * @param array  $caps    actual users capabilities
1413
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1414
+	 * @param int    $user_id The user id
1415
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1416
+	 *
1417
+	 * @return array   actual users capabilities
1418
+	 */
1419
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1420
+	{
1421
+		//only process if we're checking our mapped_cap
1422
+		if ($cap !== $this->meta_cap) {
1423
+			return $caps;
1424
+		}
1425
+
1426
+		//okay it is a meta cap so let's first remove that cap from the $caps array.
1427
+		if (($key = array_search($cap, $caps)) !== false) {
1428
+			unset($caps[$key]);
1429
+		}
1430
+
1431
+		//cast $user_id to int for later explicit comparisons
1432
+		$user_id = (int) $user_id;
1433
+
1434
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1435
+		//if no obj then let's just do cap
1436
+		if (! $obj instanceof EE_Message_Template_Group) {
1437
+			$caps[] = 'do_not_allow';
1438
+			return $caps;
1439
+		}
1440
+		$caps[] = $cap . 's';
1441
+		$is_global = $obj->is_global();
1442
+		if ($obj->wp_user() && $obj->wp_user() === $user_id) {
1443
+			if ($is_global) {
1444
+				$caps[] = $this->private_cap;
1445
+			}
1446
+		} else {
1447
+			if ($is_global) {
1448
+				$caps[] = $this->private_cap;
1449
+			} else {
1450
+				$caps[] = $this->others_cap;
1451
+			}
1452
+		}
1453
+		return $caps;
1454
+	}
1455 1455
 }
1456 1456
 
1457 1457
 
@@ -1468,40 +1468,40 @@  discard block
 block discarded – undo
1468 1468
 class EE_Meta_Capability_Map_Registration_Form_Cap extends EE_Meta_Capability_Map
1469 1469
 {
1470 1470
 
1471
-    /**
1472
-     * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1473
-     * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1474
-     *
1475
-     * @since 4.5.0
1476
-     * @see   wp-includes/capabilities.php
1477
-     * @param array  $caps    actual users capabilities
1478
-     * @param string $cap     initial capability name that is being checked (the "map" key)
1479
-     * @param int    $user_id The user id
1480
-     * @param array  $args    Adds context to the cap. Typically the object ID.
1481
-     * @return array   actual users capabilities
1482
-     */
1483
-    protected function _map_meta_caps($caps, $cap, $user_id, $args)
1484
-    {
1485
-        //only process if we're checking our mapped_cap
1486
-        if ($cap !== $this->meta_cap) {
1487
-            return $caps;
1488
-        }
1489
-        //okay it is a meta cap so let's first remove that cap from the $caps array.
1490
-        if (($key = array_search($cap, $caps)) !== false) {
1491
-            unset($caps[$key]);
1492
-        }
1493
-        $obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1494
-        //if no obj then let's just do cap
1495
-        if (! $obj instanceof EE_Base_Class) {
1496
-            $caps[] = 'do_not_allow';
1497
-            return $caps;
1498
-        }
1499
-        $caps[]    = $cap . 's';
1500
-        $is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false;
1501
-        $is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system;
1502
-        if ($is_system) {
1503
-            $caps[] = $this->private_cap;
1504
-        }
1505
-        return $caps;
1506
-    }
1471
+	/**
1472
+	 * This is the callback for the wp map_meta_caps() function which allows for ensuring certain caps that act as a
1473
+	 * "meta" for other caps ( i.e. ee_edit_event is a meta for ee_edit_others_events ) work as expected.
1474
+	 *
1475
+	 * @since 4.5.0
1476
+	 * @see   wp-includes/capabilities.php
1477
+	 * @param array  $caps    actual users capabilities
1478
+	 * @param string $cap     initial capability name that is being checked (the "map" key)
1479
+	 * @param int    $user_id The user id
1480
+	 * @param array  $args    Adds context to the cap. Typically the object ID.
1481
+	 * @return array   actual users capabilities
1482
+	 */
1483
+	protected function _map_meta_caps($caps, $cap, $user_id, $args)
1484
+	{
1485
+		//only process if we're checking our mapped_cap
1486
+		if ($cap !== $this->meta_cap) {
1487
+			return $caps;
1488
+		}
1489
+		//okay it is a meta cap so let's first remove that cap from the $caps array.
1490
+		if (($key = array_search($cap, $caps)) !== false) {
1491
+			unset($caps[$key]);
1492
+		}
1493
+		$obj = ! empty($args[0]) ? $this->_model->get_one_by_ID($args[0]) : null;
1494
+		//if no obj then let's just do cap
1495
+		if (! $obj instanceof EE_Base_Class) {
1496
+			$caps[] = 'do_not_allow';
1497
+			return $caps;
1498
+		}
1499
+		$caps[]    = $cap . 's';
1500
+		$is_system = $obj instanceof EE_Question_Group ? $obj->system_group() : false;
1501
+		$is_system = $obj instanceof EE_Question ? $obj->is_system_question() : $is_system;
1502
+		if ($is_system) {
1503
+			$caps[] = $this->private_cap;
1504
+		}
1505
+		return $caps;
1506
+	}
1507 1507
 }
Please login to merge, or discard this patch.
core/domain/entities/shortcodes/EspressoEventAttendees.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
     public function processShortcode($attributes = array())
113 113
     {
114 114
         // grab attributes and merge with defaults
115
-        $attributes = $this->getAttributes((array)$attributes);
115
+        $attributes = $this->getAttributes((array) $attributes);
116 116
         $archive = is_archive();
117 117
         $display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN);
118 118
         // don't display on archives unless 'display_on_archives' is true
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
      */
201 201
     private function validateEntities(array $attributes)
202 202
     {
203
-        if (! $this->template_args['event'] instanceof EE_Event
203
+        if ( ! $this->template_args['event'] instanceof EE_Event
204 204
             || (
205 205
                 empty($attributes['event_id'])
206 206
                 && $attributes['datetime_id']
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
      */
316 316
     private function getDatetime(array $attributes)
317 317
     {
318
-        if (! empty($attributes['datetime_id'])) {
318
+        if ( ! empty($attributes['datetime_id'])) {
319 319
             $datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']);
320 320
             if ($datetime instanceof EE_Datetime) {
321 321
                 return $datetime;
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
      */
336 336
     private function getTicket(array $attributes)
337 337
     {
338
-        if (! empty($attributes['ticket_id'])) {
338
+        if ( ! empty($attributes['ticket_id'])) {
339 339
             $ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']);
340 340
             if ($ticket instanceof EE_Ticket) {
341 341
                 return $ticket;
Please login to merge, or discard this patch.
Indentation   +333 added lines, -333 removed lines patch added patch discarded remove patch
@@ -30,339 +30,339 @@
 block discarded – undo
30 30
 class EspressoEventAttendees extends EspressoShortcode
31 31
 {
32 32
 
33
-    private $query_params = array(
34
-        0 => array()
35
-    );
36
-
37
-    private $template_args = array(
38
-        'contacts'      => array(),
39
-        'event'         => null,
40
-        'datetime'      => null,
41
-        'ticket'        => null,
42
-    );
43
-
44
-    /**
45
-     * the actual shortcode tag that gets registered with WordPress
46
-     *
47
-     * @return string
48
-     */
49
-    public function getTag()
50
-    {
51
-        return 'ESPRESSO_EVENT_ATTENDEES';
52
-    }
53
-
54
-
55
-
56
-    /**
57
-     * the time in seconds to cache the results of the processShortcode() method
58
-     * 0 means the processShortcode() results will NOT be cached at all
59
-     *
60
-     * @return int
61
-     */
62
-    public function cacheExpiration()
63
-    {
64
-        return 0;
65
-    }
66
-
67
-
68
-
69
-    /**
70
-     * a place for adding any initialization code that needs to run prior to wp_header().
71
-     * this may be required for shortcodes that utilize a corresponding module,
72
-     * and need to enqueue assets for that module
73
-     *
74
-     * @return void
75
-     */
76
-    public function initializeShortcode()
77
-    {
78
-        $this->shortcodeHasBeenInitialized();
79
-    }
80
-
81
-
82
-    /**
83
-     * process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event.
84
-     *  [ESPRESSO_EVENT_ATTENDEES]
85
-     *  - defaults to attendees for earliest active event, or earliest upcoming event.
86
-     *  [ESPRESSO_EVENT_ATTENDEES event_id=123]
87
-     *  - attendees for specific event.
88
-     *  [ESPRESSO_EVENT_ATTENDEES datetime_id=245]
89
-     *  - attendees for a specific datetime.
90
-     *  [ESPRESSO_EVENT_ATTENDEES ticket_id=123]
91
-     *  - attendees for a specific ticket.
92
-     *  [ESPRESSO_EVENT_ATTENDEES status=all]
93
-     *  - specific registration status (use status id) or all for all attendees regardless of status.
94
-     *  Note default is to only return approved attendees
95
-     *  [ESPRESSO_EVENT_ATTENDEES show_gravatar=true]
96
-     *  - default is to not return gravatar.  Otherwise if this is set then return gravatar for email address given.
97
-     *  [ESPRESSO_EVENT_ATTENDEES display_on_archives=true]
98
-     *  - default is to not display attendees list on archive pages.
99
-     * Note: because of the relationship between event_id, ticket_id, and datetime_id:
100
-     * If more than one of those params is included, then preference is given to the following:
101
-     *  - event_id is used whenever its present and any others are ignored.
102
-     *  - if no event_id then datetime is used whenever its present and any others are ignored.
103
-     *  - otherwise ticket_id is used if present.
104
-     *
105
-     * @param array $attributes
106
-     * @return string
107
-     * @throws EE_Error
108
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
109
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
110
-     * @throws \InvalidArgumentException
111
-     */
112
-    public function processShortcode($attributes = array())
113
-    {
114
-        // grab attributes and merge with defaults
115
-        $attributes = $this->getAttributes((array)$attributes);
116
-        $archive = is_archive();
117
-        $display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN);
118
-        // don't display on archives unless 'display_on_archives' is true
119
-        if ($archive && ! $display_on_archives) {
120
-            return '';
121
-        }
122
-
123
-        try {
124
-            $this->setBaseTemplateArguments($attributes);
125
-            $this->validateEntities($attributes);
126
-            $this->setBaseQueryParams();
127
-        } catch (EntityNotFoundException $e) {
128
-            if (WP_DEBUG) {
129
-                return '<div class="important-notice ee-error">'
130
-                       . $e->getMessage()
131
-                       . '</div>';
132
-            }
133
-            return '';
134
-        }
135
-        $this->setAdditionalQueryParams($attributes);
136
-        //get contacts!
137
-        $this->template_args['contacts'] = EEM_Attendee::instance()->get_all($this->query_params);
138
-        //all set let's load up the template and return.
139
-        return EEH_Template::locate_template(
140
-            'loop-espresso_event_attendees.php',
141
-            $this->template_args
142
-        );
143
-    }
144
-
145
-
146
-
147
-    /**
148
-     * merge incoming attributes with filtered defaults
149
-     *
150
-     * @param array $attributes
151
-     * @return array
152
-     */
153
-    private function getAttributes(array $attributes)
154
-    {
155
-        return (array) apply_filters(
156
-            'EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts',
157
-            $attributes + array(
158
-                'event_id'            => null,
159
-                'datetime_id'         => null,
160
-                'ticket_id'           => null,
161
-                'status'              => EEM_Registration::status_id_approved,
162
-                'show_gravatar'       => false,
163
-                'display_on_archives' => false,
164
-            )
165
-        );
166
-    }
167
-
168
-
169
-    /**
170
-     * Set all the base template arguments from the incoming attributes.
171
-     *
172
-     * * Note: because of the relationship between event_id, ticket_id, and datetime_id:
173
-     * If more than one of those params is included, then preference is given to the following:
174
-     *  - event_id is used whenever its present and any others are ignored.
175
-     *  - if no event_id then datetime is used whenever its present and any others are ignored.
176
-     *  - otherwise ticket_id is used if present.
177
-     *
178
-     * @param array $attributes
179
-     * @throws EE_Error
180
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
181
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
182
-     * @throws \InvalidArgumentException
183
-     */
184
-    private function setBaseTemplateArguments(array $attributes)
185
-    {
186
-        $this->template_args['show_gravatar'] = $attributes['show_gravatar'];
187
-        $this->template_args['event'] = $this->getEvent($attributes);
188
-        $this->template_args['datetime'] = empty($attributes['event_id'])
189
-            ? $this->getDatetime($attributes)
190
-            : null;
191
-        $this->template_args['ticket'] = empty($attributes['datetime_id']) && empty($attributes['event_id'])
192
-            ? $this->getTicket($attributes)
193
-            : null;
194
-    }
195
-
196
-
197
-    /**
198
-     * Validates the presence of entities for the given attribute values.
199
-     * @param array $attributes
200
-     * @throws EntityNotFoundException
201
-     */
202
-    private function validateEntities(array $attributes)
203
-    {
204
-        if (! $this->template_args['event'] instanceof EE_Event
205
-            || (
206
-                empty($attributes['event_id'])
207
-                && $attributes['datetime_id']
208
-                && ! $this->template_args['datetime'] instanceof EE_Datetime
209
-            )
210
-            || (
211
-                empty($attributes['event_id'])
212
-                && empty($attributes['datetime_id'])
213
-                && $attributes['ticket_id']
214
-                && ! $this->template_args['ticket'] instanceof EE_Ticket
215
-            )
216
-        ) {
217
-            throw new EntityNotFoundException(
218
-                '',
219
-                '',
220
-                esc_html__(
221
-                    'The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly.  Please double check the arguments you used for any typos.  In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.',
222
-                    'event_espresso'
223
-                )
224
-            );
225
-        }
226
-    }
227
-
228
-
229
-    /**
230
-     * Sets the query params for the base query elements.
231
-     */
232
-    private function setBaseQueryParams()
233
-    {
234
-        switch (true) {
235
-            case $this->template_args['datetime'] instanceof EE_Datetime:
236
-                $this->query_params = array(
237
-                    0 => array(
238
-                        'Registration.Ticket.Datetime.DTT_ID' => $this->template_args['datetime']->ID()
239
-                    ),
240
-                    'default_where_conditions' => 'this_model_only'
241
-                );
242
-                break;
243
-            case $this->template_args['ticket'] instanceof EE_Ticket:
244
-                $this->query_params[0] = array(
245
-                    'Registration.TKT_ID' => $this->template_args['ticket']->ID()
246
-                );
247
-                break;
248
-            case $this->template_args['event'] instanceof EE_Event:
249
-                $this->query_params[0] = array(
250
-                    'Registration.EVT_ID' => $this->template_args['event']->ID()
251
-                );
252
-                break;
253
-        }
254
-    }
255
-
256
-
257
-    /**
258
-     * @param array $attributes
259
-     * @return EE_Event|null
260
-     * @throws EE_Error
261
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
262
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
263
-     * @throws \InvalidArgumentException
264
-     */
265
-    private function getEvent(array $attributes)
266
-    {
267
-        switch (true) {
268
-            case ! empty($attributes['event_id']):
269
-                $event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']);
270
-                break;
271
-            case ! empty($attributes['datetime_id']):
272
-                $event = EEM_Event::instance()->get_one(array(
273
-                    array(
274
-                        'Datetime.DTT_ID' => $attributes['datetime_id']
275
-                    )
276
-                ));
277
-                break;
278
-            case ! empty($attributes['ticket_id']):
279
-                $event = EEM_Event::instance()->get_one(array(
280
-                    array(
281
-                        'Datetime.Ticket.TKT_ID' => $attributes['ticket_id']
282
-                    )
283
-                ));
284
-                break;
285
-            case is_espresso_event():
286
-                $event = EEH_Event_View::get_event();
287
-                break;
288
-            default:
289
-                // one last shot...
290
-                // try getting the earliest active event
291
-                $events = EEM_Event::instance()->get_active_events(array(
292
-                    'limit'    => 1,
293
-                    'order_by' => array('Datetime.DTT_EVT_start' => 'ASC')
294
-                ));
295
-                //  if none then get the next upcoming
296
-                $events = empty($events)
297
-                    ? EEM_Event::instance()->get_upcoming_events(array(
298
-                        'limit'    => 1,
299
-                        'order_by' => array('Datetime.DTT_EVT_start' => 'ASC')
300
-                    ))
301
-                    : $events;
302
-                $event = reset($events);
303
-        }
304
-
305
-        return $event instanceof EE_Event ? $event : null;
306
-    }
307
-
308
-
309
-    /**
310
-     * @param array         $attributes
311
-     * @return EE_Datetime|null
312
-     * @throws EE_Error
313
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
314
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
315
-     * @throws \InvalidArgumentException
316
-     */
317
-    private function getDatetime(array $attributes)
318
-    {
319
-        if (! empty($attributes['datetime_id'])) {
320
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']);
321
-            if ($datetime instanceof EE_Datetime) {
322
-                return $datetime;
323
-            }
324
-        }
325
-        return null;
326
-    }
327
-
328
-
329
-    /**
330
-     * @param array $attributes
331
-     * @return \EE_Base_Class|EE_Ticket|null
332
-     * @throws EE_Error
333
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
334
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
335
-     * @throws \InvalidArgumentException
336
-     */
337
-    private function getTicket(array $attributes)
338
-    {
339
-        if (! empty($attributes['ticket_id'])) {
340
-            $ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']);
341
-            if ($ticket instanceof EE_Ticket) {
342
-                return $ticket;
343
-            }
344
-        }
345
-        return null;
346
-    }
347
-
348
-
349
-
350
-    /**
351
-     * @param array $attributes
352
-     * @throws EE_Error
353
-     */
354
-    private function setAdditionalQueryParams(array $attributes)
355
-    {
356
-        $reg_status_array = EEM_Registration::reg_status_array();
357
-        if ($attributes['status'] !== 'all' && isset($reg_status_array[$attributes['status']])) {
358
-            $this->query_params[0]['Registration.STS_ID'] = $attributes['status'];
359
-        }
360
-        $this->query_params['group_by'] = array('ATT_ID');
361
-        $this->query_params['order_by'] = (array) apply_filters(
362
-            'FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by',
363
-            array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC')
364
-        );
365
-    }
33
+	private $query_params = array(
34
+		0 => array()
35
+	);
36
+
37
+	private $template_args = array(
38
+		'contacts'      => array(),
39
+		'event'         => null,
40
+		'datetime'      => null,
41
+		'ticket'        => null,
42
+	);
43
+
44
+	/**
45
+	 * the actual shortcode tag that gets registered with WordPress
46
+	 *
47
+	 * @return string
48
+	 */
49
+	public function getTag()
50
+	{
51
+		return 'ESPRESSO_EVENT_ATTENDEES';
52
+	}
53
+
54
+
55
+
56
+	/**
57
+	 * the time in seconds to cache the results of the processShortcode() method
58
+	 * 0 means the processShortcode() results will NOT be cached at all
59
+	 *
60
+	 * @return int
61
+	 */
62
+	public function cacheExpiration()
63
+	{
64
+		return 0;
65
+	}
66
+
67
+
68
+
69
+	/**
70
+	 * a place for adding any initialization code that needs to run prior to wp_header().
71
+	 * this may be required for shortcodes that utilize a corresponding module,
72
+	 * and need to enqueue assets for that module
73
+	 *
74
+	 * @return void
75
+	 */
76
+	public function initializeShortcode()
77
+	{
78
+		$this->shortcodeHasBeenInitialized();
79
+	}
80
+
81
+
82
+	/**
83
+	 * process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event.
84
+	 *  [ESPRESSO_EVENT_ATTENDEES]
85
+	 *  - defaults to attendees for earliest active event, or earliest upcoming event.
86
+	 *  [ESPRESSO_EVENT_ATTENDEES event_id=123]
87
+	 *  - attendees for specific event.
88
+	 *  [ESPRESSO_EVENT_ATTENDEES datetime_id=245]
89
+	 *  - attendees for a specific datetime.
90
+	 *  [ESPRESSO_EVENT_ATTENDEES ticket_id=123]
91
+	 *  - attendees for a specific ticket.
92
+	 *  [ESPRESSO_EVENT_ATTENDEES status=all]
93
+	 *  - specific registration status (use status id) or all for all attendees regardless of status.
94
+	 *  Note default is to only return approved attendees
95
+	 *  [ESPRESSO_EVENT_ATTENDEES show_gravatar=true]
96
+	 *  - default is to not return gravatar.  Otherwise if this is set then return gravatar for email address given.
97
+	 *  [ESPRESSO_EVENT_ATTENDEES display_on_archives=true]
98
+	 *  - default is to not display attendees list on archive pages.
99
+	 * Note: because of the relationship between event_id, ticket_id, and datetime_id:
100
+	 * If more than one of those params is included, then preference is given to the following:
101
+	 *  - event_id is used whenever its present and any others are ignored.
102
+	 *  - if no event_id then datetime is used whenever its present and any others are ignored.
103
+	 *  - otherwise ticket_id is used if present.
104
+	 *
105
+	 * @param array $attributes
106
+	 * @return string
107
+	 * @throws EE_Error
108
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
109
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
110
+	 * @throws \InvalidArgumentException
111
+	 */
112
+	public function processShortcode($attributes = array())
113
+	{
114
+		// grab attributes and merge with defaults
115
+		$attributes = $this->getAttributes((array)$attributes);
116
+		$archive = is_archive();
117
+		$display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN);
118
+		// don't display on archives unless 'display_on_archives' is true
119
+		if ($archive && ! $display_on_archives) {
120
+			return '';
121
+		}
122
+
123
+		try {
124
+			$this->setBaseTemplateArguments($attributes);
125
+			$this->validateEntities($attributes);
126
+			$this->setBaseQueryParams();
127
+		} catch (EntityNotFoundException $e) {
128
+			if (WP_DEBUG) {
129
+				return '<div class="important-notice ee-error">'
130
+					   . $e->getMessage()
131
+					   . '</div>';
132
+			}
133
+			return '';
134
+		}
135
+		$this->setAdditionalQueryParams($attributes);
136
+		//get contacts!
137
+		$this->template_args['contacts'] = EEM_Attendee::instance()->get_all($this->query_params);
138
+		//all set let's load up the template and return.
139
+		return EEH_Template::locate_template(
140
+			'loop-espresso_event_attendees.php',
141
+			$this->template_args
142
+		);
143
+	}
144
+
145
+
146
+
147
+	/**
148
+	 * merge incoming attributes with filtered defaults
149
+	 *
150
+	 * @param array $attributes
151
+	 * @return array
152
+	 */
153
+	private function getAttributes(array $attributes)
154
+	{
155
+		return (array) apply_filters(
156
+			'EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts',
157
+			$attributes + array(
158
+				'event_id'            => null,
159
+				'datetime_id'         => null,
160
+				'ticket_id'           => null,
161
+				'status'              => EEM_Registration::status_id_approved,
162
+				'show_gravatar'       => false,
163
+				'display_on_archives' => false,
164
+			)
165
+		);
166
+	}
167
+
168
+
169
+	/**
170
+	 * Set all the base template arguments from the incoming attributes.
171
+	 *
172
+	 * * Note: because of the relationship between event_id, ticket_id, and datetime_id:
173
+	 * If more than one of those params is included, then preference is given to the following:
174
+	 *  - event_id is used whenever its present and any others are ignored.
175
+	 *  - if no event_id then datetime is used whenever its present and any others are ignored.
176
+	 *  - otherwise ticket_id is used if present.
177
+	 *
178
+	 * @param array $attributes
179
+	 * @throws EE_Error
180
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
181
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
182
+	 * @throws \InvalidArgumentException
183
+	 */
184
+	private function setBaseTemplateArguments(array $attributes)
185
+	{
186
+		$this->template_args['show_gravatar'] = $attributes['show_gravatar'];
187
+		$this->template_args['event'] = $this->getEvent($attributes);
188
+		$this->template_args['datetime'] = empty($attributes['event_id'])
189
+			? $this->getDatetime($attributes)
190
+			: null;
191
+		$this->template_args['ticket'] = empty($attributes['datetime_id']) && empty($attributes['event_id'])
192
+			? $this->getTicket($attributes)
193
+			: null;
194
+	}
195
+
196
+
197
+	/**
198
+	 * Validates the presence of entities for the given attribute values.
199
+	 * @param array $attributes
200
+	 * @throws EntityNotFoundException
201
+	 */
202
+	private function validateEntities(array $attributes)
203
+	{
204
+		if (! $this->template_args['event'] instanceof EE_Event
205
+			|| (
206
+				empty($attributes['event_id'])
207
+				&& $attributes['datetime_id']
208
+				&& ! $this->template_args['datetime'] instanceof EE_Datetime
209
+			)
210
+			|| (
211
+				empty($attributes['event_id'])
212
+				&& empty($attributes['datetime_id'])
213
+				&& $attributes['ticket_id']
214
+				&& ! $this->template_args['ticket'] instanceof EE_Ticket
215
+			)
216
+		) {
217
+			throw new EntityNotFoundException(
218
+				'',
219
+				'',
220
+				esc_html__(
221
+					'The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly.  Please double check the arguments you used for any typos.  In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.',
222
+					'event_espresso'
223
+				)
224
+			);
225
+		}
226
+	}
227
+
228
+
229
+	/**
230
+	 * Sets the query params for the base query elements.
231
+	 */
232
+	private function setBaseQueryParams()
233
+	{
234
+		switch (true) {
235
+			case $this->template_args['datetime'] instanceof EE_Datetime:
236
+				$this->query_params = array(
237
+					0 => array(
238
+						'Registration.Ticket.Datetime.DTT_ID' => $this->template_args['datetime']->ID()
239
+					),
240
+					'default_where_conditions' => 'this_model_only'
241
+				);
242
+				break;
243
+			case $this->template_args['ticket'] instanceof EE_Ticket:
244
+				$this->query_params[0] = array(
245
+					'Registration.TKT_ID' => $this->template_args['ticket']->ID()
246
+				);
247
+				break;
248
+			case $this->template_args['event'] instanceof EE_Event:
249
+				$this->query_params[0] = array(
250
+					'Registration.EVT_ID' => $this->template_args['event']->ID()
251
+				);
252
+				break;
253
+		}
254
+	}
255
+
256
+
257
+	/**
258
+	 * @param array $attributes
259
+	 * @return EE_Event|null
260
+	 * @throws EE_Error
261
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
262
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
263
+	 * @throws \InvalidArgumentException
264
+	 */
265
+	private function getEvent(array $attributes)
266
+	{
267
+		switch (true) {
268
+			case ! empty($attributes['event_id']):
269
+				$event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']);
270
+				break;
271
+			case ! empty($attributes['datetime_id']):
272
+				$event = EEM_Event::instance()->get_one(array(
273
+					array(
274
+						'Datetime.DTT_ID' => $attributes['datetime_id']
275
+					)
276
+				));
277
+				break;
278
+			case ! empty($attributes['ticket_id']):
279
+				$event = EEM_Event::instance()->get_one(array(
280
+					array(
281
+						'Datetime.Ticket.TKT_ID' => $attributes['ticket_id']
282
+					)
283
+				));
284
+				break;
285
+			case is_espresso_event():
286
+				$event = EEH_Event_View::get_event();
287
+				break;
288
+			default:
289
+				// one last shot...
290
+				// try getting the earliest active event
291
+				$events = EEM_Event::instance()->get_active_events(array(
292
+					'limit'    => 1,
293
+					'order_by' => array('Datetime.DTT_EVT_start' => 'ASC')
294
+				));
295
+				//  if none then get the next upcoming
296
+				$events = empty($events)
297
+					? EEM_Event::instance()->get_upcoming_events(array(
298
+						'limit'    => 1,
299
+						'order_by' => array('Datetime.DTT_EVT_start' => 'ASC')
300
+					))
301
+					: $events;
302
+				$event = reset($events);
303
+		}
304
+
305
+		return $event instanceof EE_Event ? $event : null;
306
+	}
307
+
308
+
309
+	/**
310
+	 * @param array         $attributes
311
+	 * @return EE_Datetime|null
312
+	 * @throws EE_Error
313
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
314
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
315
+	 * @throws \InvalidArgumentException
316
+	 */
317
+	private function getDatetime(array $attributes)
318
+	{
319
+		if (! empty($attributes['datetime_id'])) {
320
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']);
321
+			if ($datetime instanceof EE_Datetime) {
322
+				return $datetime;
323
+			}
324
+		}
325
+		return null;
326
+	}
327
+
328
+
329
+	/**
330
+	 * @param array $attributes
331
+	 * @return \EE_Base_Class|EE_Ticket|null
332
+	 * @throws EE_Error
333
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
334
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
335
+	 * @throws \InvalidArgumentException
336
+	 */
337
+	private function getTicket(array $attributes)
338
+	{
339
+		if (! empty($attributes['ticket_id'])) {
340
+			$ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']);
341
+			if ($ticket instanceof EE_Ticket) {
342
+				return $ticket;
343
+			}
344
+		}
345
+		return null;
346
+	}
347
+
348
+
349
+
350
+	/**
351
+	 * @param array $attributes
352
+	 * @throws EE_Error
353
+	 */
354
+	private function setAdditionalQueryParams(array $attributes)
355
+	{
356
+		$reg_status_array = EEM_Registration::reg_status_array();
357
+		if ($attributes['status'] !== 'all' && isset($reg_status_array[$attributes['status']])) {
358
+			$this->query_params[0]['Registration.STS_ID'] = $attributes['status'];
359
+		}
360
+		$this->query_params['group_by'] = array('ATT_ID');
361
+		$this->query_params['order_by'] = (array) apply_filters(
362
+			'FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by',
363
+			array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC')
364
+		);
365
+	}
366 366
 
367 367
 
368 368
 
Please login to merge, or discard this patch.
admin/extend/registrations/EE_Event_Registrations_List_Table.class.php 2 patches
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 		$this->_columns = array_merge( $columns, $this->_columns );
91 91
 		$this->_primary_column = '_REG_att_checked_in';
92 92
 		if ( ! empty( $evt_id )
93
-		     && EE_Registry::instance()->CAP->current_user_can(
93
+			 && EE_Registry::instance()->CAP->current_user_can(
94 94
 				'ee_read_registrations',
95 95
 				'espresso_registrations_registrations_reports',
96 96
 				$evt_id
@@ -107,44 +107,44 @@  discard block
 block discarded – undo
107 107
 				),
108 108
 			);
109 109
 		}
110
-        $this->_bottom_buttons['report_filtered'] = array(
111
-            'route'         => 'registrations_checkin_report',
112
-            'extra_request' => array(
113
-                'use_filters' => true,
114
-                'filters'     => array_merge(
115
-                    array(
116
-                        'EVT_ID' => $evt_id,
117
-                    ),
118
-                    array_diff_key(
119
-                        $this->_req_data,
120
-                        array_flip(
121
-                            array(
122
-                                'page',
123
-                                'action',
124
-                                'default_nonce',
125
-                            )
126
-                        )
127
-                    )
128
-                ),
129
-                'return_url'  => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
130
-            ),
131
-        );
110
+		$this->_bottom_buttons['report_filtered'] = array(
111
+			'route'         => 'registrations_checkin_report',
112
+			'extra_request' => array(
113
+				'use_filters' => true,
114
+				'filters'     => array_merge(
115
+					array(
116
+						'EVT_ID' => $evt_id,
117
+					),
118
+					array_diff_key(
119
+						$this->_req_data,
120
+						array_flip(
121
+							array(
122
+								'page',
123
+								'action',
124
+								'default_nonce',
125
+							)
126
+						)
127
+					)
128
+				),
129
+				'return_url'  => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
130
+			),
131
+		);
132 132
 		$this->_sortable_columns = array(
133
-            /**
134
-             * Allows users to change the default sort if they wish.
135
-             * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name.
136
-             *
137
-             * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to
138
-             * change the sorts on any list table involving registration contacts.  If you want to only change the filter
139
-             * for a specific list table you can use the provided reference to this object instance.
140
-             */
133
+			/**
134
+			 * Allows users to change the default sort if they wish.
135
+			 * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name.
136
+			 *
137
+			 * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to
138
+			 * change the sorts on any list table involving registration contacts.  If you want to only change the filter
139
+			 * for a specific list table you can use the provided reference to this object instance.
140
+			 */
141 141
 			'ATT_name' => array(
142
-                    'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
143
-                    true,
144
-                    $this
145
-                )
146
-                ? array( 'ATT_lname' => true )
147
-                : array( 'ATT_fname' => true ),
142
+					'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name',
143
+					true,
144
+					$this
145
+				)
146
+				? array( 'ATT_lname' => true )
147
+				: array( 'ATT_fname' => true ),
148 148
 			'Event'    => array( 'Event.EVT.Name' => false ),
149 149
 		);
150 150
 		$this->_hidden_columns = array();
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 				if ( ! $evt->get_count_of_all_registrations() ) {
204 204
 					continue;
205 205
 				}
206
-                                $evts[] = array(
206
+								$evts[] = array(
207 207
 					'id'    => $evt->ID(),
208 208
 					'text'  => apply_filters('FHEE__EE_Event_Registrations___get_table_filters__event_name', $evt->get( 'EVT_name' ), $evt),
209 209
 					'class' => $evt->is_expired() ? 'ee-expired-event' : '',
@@ -227,8 +227,8 @@  discard block
 block discarded – undo
227 227
 			if ( count( $this->_dtts_for_event ) > 1 ) {
228 228
 				$dtts[0] = __( 'To toggle check-in status, select a datetime.', 'event_espresso' );
229 229
 				foreach ( $this->_dtts_for_event as $dtt ) {
230
-                    $datetime_string = $dtt->name();
231
-                    $datetime_string = ! empty($datetime_string ) ? ' (' . $datetime_string . ')' : '';
230
+					$datetime_string = $dtt->name();
231
+					$datetime_string = ! empty($datetime_string ) ? ' (' . $datetime_string . ')' : '';
232 232
 					$datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string;
233 233
 					$dtts[ $dtt->ID() ] = $datetime_string;
234 234
 				}
@@ -301,16 +301,16 @@  discard block
 block discarded – undo
301 301
 
302 302
 
303 303
 
304
-    /**
305
-     * column_REG_att_checked_in
306
-     *
307
-     * @param EE_Registration $item
308
-     * @return string
309
-     * @throws EE_Error
310
-     * @throws InvalidArgumentException
311
-     * @throws InvalidDataTypeException
312
-     * @throws InvalidInterfaceException
313
-     */
304
+	/**
305
+	 * column_REG_att_checked_in
306
+	 *
307
+	 * @param EE_Registration $item
308
+	 * @return string
309
+	 * @throws EE_Error
310
+	 * @throws InvalidArgumentException
311
+	 * @throws InvalidDataTypeException
312
+	 * @throws InvalidInterfaceException
313
+	 */
314 314
 	public function column__REG_att_checked_in( EE_Registration $item ) {
315 315
 		$attendee = $item->attendee();
316 316
 		$attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
@@ -321,13 +321,13 @@  discard block
 block discarded – undo
321 321
 				$this->_cur_dtt_id = $latest_related_datetime->ID();
322 322
 			}
323 323
 		}
324
-        $checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId(
325
-		    $item,
326
-            $this->_cur_dtt_id
327
-        );
324
+		$checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId(
325
+			$item,
326
+			$this->_cur_dtt_id
327
+		);
328 328
 		$nonce = wp_create_nonce( 'checkin_nonce' );
329 329
 		$toggle_active = ! empty ( $this->_cur_dtt_id )
330
-		                 && EE_Registry::instance()->CAP->current_user_can(
330
+						 && EE_Registry::instance()->CAP->current_user_can(
331 331
 			'ee_edit_checkin',
332 332
 			'espresso_registrations_toggle_checkin_status',
333 333
 			$item->ID()
@@ -336,11 +336,11 @@  discard block
 block discarded – undo
336 336
 			: '';
337 337
 		$mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
338 338
 		return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"'
339
-		       . ' data-_regid="' . $item->ID() . '"'
340
-		       . ' data-dttid="' . $this->_cur_dtt_id . '"'
341
-		       . ' data-nonce="' . $nonce . '">'
342
-		       . '</span>'
343
-		       . $mobile_view_content;
339
+			   . ' data-_regid="' . $item->ID() . '"'
340
+			   . ' data-dttid="' . $this->_cur_dtt_id . '"'
341
+			   . ' data-nonce="' . $nonce . '">'
342
+			   . '</span>'
343
+			   . $mobile_view_content;
344 344
 	}
345 345
 
346 346
 
@@ -365,8 +365,8 @@  discard block
 block discarded – undo
365 365
 			'espresso_registrations_edit_attendee'
366 366
 		)
367 367
 			? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">'
368
-			    . $item->attendee()->full_name()
369
-			    . '</a>'
368
+				. $item->attendee()->full_name()
369
+				. '</a>'
370 370
 			: $item->attendee()->full_name();
371 371
 		$name_link .= $item->count() === 1
372 372
 			? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>	'
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
 			? $latest_related_datetime->ID()
402 402
 			: $DTT_ID;
403 403
 		if ( ! empty( $DTT_ID )
404
-		     && EE_Registry::instance()->CAP->current_user_can(
404
+			 && EE_Registry::instance()->CAP->current_user_can(
405 405
 				'ee_read_checkins',
406 406
 				'espresso_registrations_registration_checkins'
407 407
 			)
@@ -515,15 +515,15 @@  discard block
 block discarded – undo
515 515
 				) ? '
516 516
 				<span class="reg-pad-rght">
517 517
 					<a class="status-'
518
-				    . $item->transaction()->status_ID()
519
-				    . '" href="'
520
-				    . $view_txn_lnk_url
521
-				    . '"  title="'
522
-				    . esc_attr__( 'View Transaction', 'event_espresso' )
523
-				    . '">
518
+					. $item->transaction()->status_ID()
519
+					. '" href="'
520
+					. $view_txn_lnk_url
521
+					. '"  title="'
522
+					. esc_attr__( 'View Transaction', 'event_espresso' )
523
+					. '">
524 524
 						'
525
-				    . $item->transaction()->pretty_paid()
526
-				    . '
525
+					. $item->transaction()->pretty_paid()
526
+					. '
527 527
 					</a>
528 528
 				<span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
529 529
 			}
@@ -556,12 +556,12 @@  discard block
 block discarded – undo
556 556
 				'ee_read_transaction',
557 557
 				'espresso_transactions_view_transaction'
558 558
 			) ? '<a href="'
559
-			    . $view_txn_url
560
-			    . '" title="'
561
-			    . esc_attr__( 'View Transaction', 'event_espresso' )
562
-			    . '"><span class="reg-pad-rght">'
563
-			    . $txn_total
564
-			    . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>';
559
+				. $view_txn_url
560
+				. '" title="'
561
+				. esc_attr__( 'View Transaction', 'event_espresso' )
562
+				. '"><span class="reg-pad-rght">'
563
+				. $txn_total
564
+				. '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>';
565 565
 		} else {
566 566
 			return '<span class="reg-pad-rght"></span>';
567 567
 		}
Please login to merge, or discard this patch.
Spacing   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -45,51 +45,51 @@  discard block
 block discarded – undo
45 45
 	 *
46 46
 	 * @param \Registrations_Admin_Page $admin_page
47 47
 	 */
48
-	public function __construct( $admin_page ) {
49
-		parent::__construct( $admin_page );
48
+	public function __construct($admin_page) {
49
+		parent::__construct($admin_page);
50 50
 		$this->_status = $this->_admin_page->get_registration_status_array();
51 51
 	}
52 52
 
53 53
 
54 54
 
55 55
 	protected function _setup_data() {
56
-		$this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees( $this->_per_page )
57
-			: $this->_admin_page->get_event_attendees( $this->_per_page, false, true );
56
+		$this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees($this->_per_page)
57
+			: $this->_admin_page->get_event_attendees($this->_per_page, false, true);
58 58
 		$this->_all_data_count = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees(
59 59
 			$this->_per_page,
60 60
 			true
61
-		) : $this->_admin_page->get_event_attendees( $this->_per_page, true, true );
61
+		) : $this->_admin_page->get_event_attendees($this->_per_page, true, true);
62 62
 	}
63 63
 
64 64
 
65 65
 
66 66
 	protected function _set_properties() {
67
-		$evt_id = isset( $this->_req_data['event_id'] ) ? $this->_req_data['event_id'] : null;
67
+		$evt_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
68 68
 		$this->_wp_list_args = array(
69
-			'singular' => __( 'registrant', 'event_espresso' ),
70
-			'plural'   => __( 'registrants', 'event_espresso' ),
69
+			'singular' => __('registrant', 'event_espresso'),
70
+			'plural'   => __('registrants', 'event_espresso'),
71 71
 			'ajax'     => true,
72 72
 			'screen'   => $this->_admin_page->get_current_screen()->id,
73 73
 		);
74 74
 		$columns = array();
75 75
 		//$columns['_Reg_Status'] = '';
76
-		if ( ! empty( $evt_id ) ) {
76
+		if ( ! empty($evt_id)) {
77 77
 			$columns['cb'] = '<input type="checkbox" />'; //Render a checkbox instead of text
78 78
 			$this->_has_checkbox_column = true;
79 79
 		}
80 80
 		$this->_columns = array(
81 81
 			'_REG_att_checked_in' => '<span class="dashicons dashicons-yes ee-icon-size-18"></span>',
82
-			'ATT_name'            => __( 'Registrant', 'event_espresso' ),
83
-			'ATT_email'           => __( 'Email Address', 'event_espresso' ),
84
-			'Event'               => __( 'Event', 'event_espresso' ),
85
-			'PRC_name'            => __( 'TKT Option', 'event_espresso' ),
86
-			'_REG_final_price'    => __( 'Price', 'event_espresso' ),
87
-			'TXN_paid'            => __( 'Paid', 'event_espresso' ),
88
-			'TXN_total'           => __( 'Total', 'event_espresso' ),
82
+			'ATT_name'            => __('Registrant', 'event_espresso'),
83
+			'ATT_email'           => __('Email Address', 'event_espresso'),
84
+			'Event'               => __('Event', 'event_espresso'),
85
+			'PRC_name'            => __('TKT Option', 'event_espresso'),
86
+			'_REG_final_price'    => __('Price', 'event_espresso'),
87
+			'TXN_paid'            => __('Paid', 'event_espresso'),
88
+			'TXN_total'           => __('Total', 'event_espresso'),
89 89
 		);
90
-		$this->_columns = array_merge( $columns, $this->_columns );
90
+		$this->_columns = array_merge($columns, $this->_columns);
91 91
 		$this->_primary_column = '_REG_att_checked_in';
92
-		if ( ! empty( $evt_id )
92
+		if ( ! empty($evt_id)
93 93
 		     && EE_Registry::instance()->CAP->current_user_can(
94 94
 				'ee_read_registrations',
95 95
 				'espresso_registrations_registrations_reports',
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 					'extra_request' =>
103 103
 						array(
104 104
 							'EVT_ID'     => $evt_id,
105
-							'return_url' => urlencode( "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}" ),
105
+							'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"),
106 106
 						),
107 107
 				),
108 108
 			);
@@ -143,12 +143,12 @@  discard block
 block discarded – undo
143 143
                     true,
144 144
                     $this
145 145
                 )
146
-                ? array( 'ATT_lname' => true )
147
-                : array( 'ATT_fname' => true ),
148
-			'Event'    => array( 'Event.EVT.Name' => false ),
146
+                ? array('ATT_lname' => true)
147
+                : array('ATT_fname' => true),
148
+			'Event'    => array('Event.EVT.Name' => false),
149 149
 		);
150 150
 		$this->_hidden_columns = array();
151
-		$this->_evt = EEM_Event::instance()->get_one_by_ID( $evt_id );
151
+		$this->_evt = EEM_Event::instance()->get_one_by_ID($evt_id);
152 152
 		$this->_dtts_for_event = $this->_evt instanceof EE_Event ? $this->_evt->datetimes_ordered() : array();
153 153
 	}
154 154
 
@@ -158,11 +158,11 @@  discard block
 block discarded – undo
158 158
 	 * @param \EE_Registration $item
159 159
 	 * @return string
160 160
 	 */
161
-	protected function _get_row_class( $item ) {
162
-		$class = parent::_get_row_class( $item );
161
+	protected function _get_row_class($item) {
162
+		$class = parent::_get_row_class($item);
163 163
 		//add status class
164
-		$class .= ' ee-status-strip reg-status-' . $item->status_ID();
165
-		if ( $this->_has_checkbox_column ) {
164
+		$class .= ' ee-status-strip reg-status-'.$item->status_ID();
165
+		if ($this->_has_checkbox_column) {
166 166
 			$class .= ' has-checkbox-column';
167 167
 		}
168 168
 		return $class;
@@ -176,61 +176,61 @@  discard block
 block discarded – undo
176 176
 	 */
177 177
 	protected function _get_table_filters() {
178 178
 		$filters = $where = array();
179
-		$current_EVT_ID = isset( $this->_req_data['event_id'] ) ? (int) $this->_req_data['event_id'] : 0;
180
-		if ( empty( $this->_dtts_for_event ) || count( $this->_dtts_for_event ) === 1 ) {
179
+		$current_EVT_ID = isset($this->_req_data['event_id']) ? (int) $this->_req_data['event_id'] : 0;
180
+		if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) {
181 181
 			//this means we don't have an event so let's setup a filter dropdown for all the events to select
182 182
 			//note possible capability restrictions
183
-			if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_private_events', 'get_events' ) ) {
184
-				$where['status**'] = array( '!=', 'private' );
183
+			if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
184
+				$where['status**'] = array('!=', 'private');
185 185
 			}
186
-			if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_events', 'get_events' ) ) {
186
+			if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
187 187
 				$where['EVT_wp_user'] = get_current_user_id();
188 188
 			}
189 189
 			$events = EEM_Event::instance()->get_all(
190 190
 				array(
191 191
 					$where,
192
-					'order_by' => array( 'Datetime.DTT_EVT_start' => 'DESC' ),
192
+					'order_by' => array('Datetime.DTT_EVT_start' => 'DESC'),
193 193
 				)
194 194
 			);
195 195
 			$evts[] = array(
196 196
 				'id'   => 0,
197
-				'text' => __( 'To toggle Check-in status, select an event', 'event_espresso' ),
197
+				'text' => __('To toggle Check-in status, select an event', 'event_espresso'),
198 198
 			);
199 199
 			$checked = 'checked';
200 200
 			/** @var EE_Event $evt */
201
-			foreach ( $events as $evt ) {
201
+			foreach ($events as $evt) {
202 202
 				//any registrations for this event?
203
-				if ( ! $evt->get_count_of_all_registrations() ) {
203
+				if ( ! $evt->get_count_of_all_registrations()) {
204 204
 					continue;
205 205
 				}
206 206
                                 $evts[] = array(
207 207
 					'id'    => $evt->ID(),
208
-					'text'  => apply_filters('FHEE__EE_Event_Registrations___get_table_filters__event_name', $evt->get( 'EVT_name' ), $evt),
208
+					'text'  => apply_filters('FHEE__EE_Event_Registrations___get_table_filters__event_name', $evt->get('EVT_name'), $evt),
209 209
 					'class' => $evt->is_expired() ? 'ee-expired-event' : '',
210 210
 				);
211
-				if ( $evt->ID() === $current_EVT_ID && $evt->is_expired() ) {
211
+				if ($evt->ID() === $current_EVT_ID && $evt->is_expired()) {
212 212
 					$checked = '';
213 213
 				}
214 214
 			}
215 215
 			$event_filter = '<div class="ee-event-filter">';
216
-			$event_filter .= EEH_Form_Fields::select_input( 'event_id', $evts, $current_EVT_ID );
216
+			$event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID);
217 217
 			$event_filter .= '<span class="ee-event-filter-toggle">';
218
-			$event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> ';
219
-			$event_filter .= __( 'Hide Expired Events', 'event_espresso' );
218
+			$event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" '.$checked.'> ';
219
+			$event_filter .= __('Hide Expired Events', 'event_espresso');
220 220
 			$event_filter .= '</span>';
221 221
 			$event_filter .= '</div>';
222 222
 			$filters[] = $event_filter;
223 223
 		}
224
-		if ( ! empty( $this->_dtts_for_event ) ) {
224
+		if ( ! empty($this->_dtts_for_event)) {
225 225
 			//DTT datetimes filter
226
-			$this->_cur_dtt_id = isset( $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : 0;
227
-			if ( count( $this->_dtts_for_event ) > 1 ) {
228
-				$dtts[0] = __( 'To toggle check-in status, select a datetime.', 'event_espresso' );
229
-				foreach ( $this->_dtts_for_event as $dtt ) {
226
+			$this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0;
227
+			if (count($this->_dtts_for_event) > 1) {
228
+				$dtts[0] = __('To toggle check-in status, select a datetime.', 'event_espresso');
229
+				foreach ($this->_dtts_for_event as $dtt) {
230 230
                     $datetime_string = $dtt->name();
231
-                    $datetime_string = ! empty($datetime_string ) ? ' (' . $datetime_string . ')' : '';
232
-					$datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string;
233
-					$dtts[ $dtt->ID() ] = $datetime_string;
231
+                    $datetime_string = ! empty($datetime_string) ? ' ('.$datetime_string.')' : '';
232
+					$datetime_string = $dtt->start_date_and_time().' - '.$dtt->end_date_and_time().$datetime_string;
233
+					$dtts[$dtt->ID()] = $datetime_string;
234 234
 				}
235 235
 				$input = new EE_Select_Input(
236 236
 					$dtts,
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 					)
242 242
 				);
243 243
 				$filters[] = $input->get_html_for_input();
244
-				$filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">';
244
+				$filters[] = '<input type="hidden" name="event_id" value="'.$current_EVT_ID.'">';
245 245
 			}
246 246
 		}
247 247
 		return $filters;
@@ -260,22 +260,22 @@  discard block
 block discarded – undo
260 260
 	 * @throws \EE_Error
261 261
 	 */
262 262
 	protected function _get_total_event_attendees() {
263
-		$EVT_ID = isset( $this->_req_data['event_id'] ) ? absint( $this->_req_data['event_id'] ) : false;
263
+		$EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false;
264 264
 		$DTT_ID = $this->_cur_dtt_id;
265 265
 		$query_params = array();
266
-		if ( $EVT_ID ) {
266
+		if ($EVT_ID) {
267 267
 			$query_params[0]['EVT_ID'] = $EVT_ID;
268 268
 		}
269 269
 		//if DTT is included we only show for that datetime.  Otherwise we're showing for all datetimes (the event).
270
-		if ( $DTT_ID ) {
270
+		if ($DTT_ID) {
271 271
 			$query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID;
272 272
 		}
273 273
 		$status_ids_array = apply_filters(
274 274
 			'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
275
-			array( EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved )
275
+			array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
276 276
 		);
277
-		$query_params[0]['STS_ID'] = array( 'IN', $status_ids_array );
278
-		return EEM_Registration::instance()->count( $query_params );
277
+		$query_params[0]['STS_ID'] = array('IN', $status_ids_array);
278
+		return EEM_Registration::instance()->count($query_params);
279 279
 	}
280 280
 
281 281
 
@@ -284,8 +284,8 @@  discard block
 block discarded – undo
284 284
 	 * @param \EE_Registration $item
285 285
 	 * @return string
286 286
 	 */
287
-	public function column__Reg_Status( EE_Registration $item ) {
288
-		return '<span class="ee-status-strip ee-status-strip-td reg-status-' . $item->status_ID() . '"></span>';
287
+	public function column__Reg_Status(EE_Registration $item) {
288
+		return '<span class="ee-status-strip ee-status-strip-td reg-status-'.$item->status_ID().'"></span>';
289 289
 	}
290 290
 
291 291
 
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 	 * @return string
296 296
 	 * @throws \EE_Error
297 297
 	 */
298
-	public function column_cb( $item ) {
299
-		return sprintf( '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID() );
298
+	public function column_cb($item) {
299
+		return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID());
300 300
 	}
301 301
 
302 302
 
@@ -311,13 +311,13 @@  discard block
 block discarded – undo
311 311
      * @throws InvalidDataTypeException
312 312
      * @throws InvalidInterfaceException
313 313
      */
314
-	public function column__REG_att_checked_in( EE_Registration $item ) {
314
+	public function column__REG_att_checked_in(EE_Registration $item) {
315 315
 		$attendee = $item->attendee();
316 316
 		$attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : '';
317 317
 
318
-		if ( $this->_cur_dtt_id === 0 && count( $this->_dtts_for_event ) === 1 ) {
318
+		if ($this->_cur_dtt_id === 0 && count($this->_dtts_for_event) === 1) {
319 319
 			$latest_related_datetime = $item->get_latest_related_datetime();
320
-			if ( $latest_related_datetime instanceof EE_Datetime ) {
320
+			if ($latest_related_datetime instanceof EE_Datetime) {
321 321
 				$this->_cur_dtt_id = $latest_related_datetime->ID();
322 322
 			}
323 323
 		}
@@ -325,8 +325,8 @@  discard block
 block discarded – undo
325 325
 		    $item,
326 326
             $this->_cur_dtt_id
327 327
         );
328
-		$nonce = wp_create_nonce( 'checkin_nonce' );
329
-		$toggle_active = ! empty ( $this->_cur_dtt_id )
328
+		$nonce = wp_create_nonce('checkin_nonce');
329
+		$toggle_active = ! empty ($this->_cur_dtt_id)
330 330
 		                 && EE_Registry::instance()->CAP->current_user_can(
331 331
 			'ee_edit_checkin',
332 332
 			'espresso_registrations_toggle_checkin_status',
@@ -334,11 +334,11 @@  discard block
 block discarded – undo
334 334
 		)
335 335
 			? ' clickable trigger-checkin'
336 336
 			: '';
337
-		$mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>';
338
-		return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"'
339
-		       . ' data-_regid="' . $item->ID() . '"'
340
-		       . ' data-dttid="' . $this->_cur_dtt_id . '"'
341
-		       . ' data-nonce="' . $nonce . '">'
337
+		$mobile_view_content = ' <span class="show-on-mobile-view-only">'.$attendee_name.'</span>';
338
+		return '<span class="'.$checkin_status_dashicon->cssClasses().$toggle_active.'"'
339
+		       . ' data-_regid="'.$item->ID().'"'
340
+		       . ' data-dttid="'.$this->_cur_dtt_id.'"'
341
+		       . ' data-nonce="'.$nonce.'">'
342 342
 		       . '</span>'
343 343
 		       . $mobile_view_content;
344 344
 	}
@@ -350,21 +350,21 @@  discard block
 block discarded – undo
350 350
 	 * @return mixed|string|void
351 351
 	 * @throws \EE_Error
352 352
 	 */
353
-	public function column_ATT_name( EE_Registration $item ) {
353
+	public function column_ATT_name(EE_Registration $item) {
354 354
 		$attendee = $item->attendee();
355
-		if ( ! $attendee instanceof EE_Attendee ) {
356
-			return __( 'No contact record for this registration.', 'event_espresso' );
355
+		if ( ! $attendee instanceof EE_Attendee) {
356
+			return __('No contact record for this registration.', 'event_espresso');
357 357
 		}
358 358
 		// edit attendee link
359 359
 		$edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
360
-			array( 'action' => 'view_registration', '_REG_ID' => $item->ID() ),
360
+			array('action' => 'view_registration', '_REG_ID' => $item->ID()),
361 361
 			REG_ADMIN_URL
362 362
 		);
363 363
 		$name_link = EE_Registry::instance()->CAP->current_user_can(
364 364
 			'ee_edit_contacts',
365 365
 			'espresso_registrations_edit_attendee'
366 366
 		)
367
-			? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">'
367
+			? '<a href="'.$edit_lnk_url.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'">'
368 368
 			    . $item->attendee()->full_name()
369 369
 			    . '</a>'
370 370
 			: $item->attendee()->full_name();
@@ -372,10 +372,10 @@  discard block
 block discarded – undo
372 372
 			? '&nbsp;<sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>	'
373 373
 			: '';
374 374
 		//add group details
375
-		$name_link .= '&nbsp;' . sprintf( __( '(%s of %s)', 'event_espresso' ), $item->count(), $item->group_size() );
375
+		$name_link .= '&nbsp;'.sprintf(__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size());
376 376
 		//add regcode
377 377
 		$link = EE_Admin_Page::add_query_args_and_nonce(
378
-			array( 'action' => 'view_registration', '_REG_ID' => $item->ID() ),
378
+			array('action' => 'view_registration', '_REG_ID' => $item->ID()),
379 379
 			REG_ADMIN_URL
380 380
 		);
381 381
 		$name_link .= '<br>';
@@ -384,50 +384,50 @@  discard block
 block discarded – undo
384 384
 			'view_registration',
385 385
 			$item->ID()
386 386
 		)
387
-			? '<a href="' . $link . '" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">'
387
+			? '<a href="'.$link.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'">'
388 388
 			  . $item->reg_code()
389 389
 			  . '</a>'
390 390
 			: $item->reg_code();
391 391
 		//status
392 392
 		$name_link .= '<br><span class="ee-status-text-small">';
393
-		$name_link .= EEH_Template::pretty_status( $item->status_ID(), false, 'sentence' );
393
+		$name_link .= EEH_Template::pretty_status($item->status_ID(), false, 'sentence');
394 394
 		$name_link .= '</span>';
395 395
 		$actions = array();
396 396
 		$DTT_ID = $this->_cur_dtt_id;
397
-		$latest_related_datetime = empty( $DTT_ID ) && ! empty( $this->_req_data['event_id'] ) && $item instanceof EE_Registration
397
+		$latest_related_datetime = empty($DTT_ID) && ! empty($this->_req_data['event_id']) && $item instanceof EE_Registration
398 398
 			? $item->get_latest_related_datetime()
399 399
 			: null;
400 400
 		$DTT_ID = $latest_related_datetime instanceof EE_Datetime
401 401
 			? $latest_related_datetime->ID()
402 402
 			: $DTT_ID;
403
-		if ( ! empty( $DTT_ID )
403
+		if ( ! empty($DTT_ID)
404 404
 		     && EE_Registry::instance()->CAP->current_user_can(
405 405
 				'ee_read_checkins',
406 406
 				'espresso_registrations_registration_checkins'
407 407
 			)
408 408
 		) {
409 409
 			$checkin_list_url = EE_Admin_Page::add_query_args_and_nonce(
410
-				array( 'action' => 'registration_checkins', '_REGID' => $item->ID(), 'DTT_ID' => $DTT_ID )
410
+				array('action' => 'registration_checkins', '_REGID' => $item->ID(), 'DTT_ID' => $DTT_ID)
411 411
 			);
412 412
 			// get the timestamps for this registration's checkins, related to the selected datetime
413
-			$timestamps = $item->get_many_related( 'Checkin', array( array( 'DTT_ID' => $DTT_ID ) ) );
414
-			if( ! empty( $timestamps ) ) {
413
+			$timestamps = $item->get_many_related('Checkin', array(array('DTT_ID' => $DTT_ID)));
414
+			if ( ! empty($timestamps)) {
415 415
 				// get the last timestamp
416
-				$last_timestamp = end( $timestamps );
416
+				$last_timestamp = end($timestamps);
417 417
 				// checked in or checked out?
418
-				$checkin_status = $last_timestamp->get( 'CHK_in' )
419
-					? esc_html__( 'Checked In', 'event_espresso' )
420
-					: esc_html__( 'Checked Out', 'event_espresso' );
418
+				$checkin_status = $last_timestamp->get('CHK_in')
419
+					? esc_html__('Checked In', 'event_espresso')
420
+					: esc_html__('Checked Out', 'event_espresso');
421 421
 				// get timestamp string
422
-				$timestamp_string = $last_timestamp->get_datetime( 'CHK_timestamp' );
423
-				$actions['checkin'] = '<a href="' . $checkin_list_url . '" title="' . esc_attr__(
422
+				$timestamp_string = $last_timestamp->get_datetime('CHK_timestamp');
423
+				$actions['checkin'] = '<a href="'.$checkin_list_url.'" title="'.esc_attr__(
424 424
 						'View this registrant\'s check-ins/checkouts for the datetime',
425 425
 						'event_espresso'
426
-					) . '">' . $checkin_status . ': ' . $timestamp_string . '</a>';
426
+					).'">'.$checkin_status.': '.$timestamp_string.'</a>';
427 427
 			}
428 428
 		}
429
-		return ( ! empty( $DTT_ID ) && ! empty( $timestamps ) )
430
-			? sprintf( '%1$s %2$s', $name_link, $this->row_actions( $actions, true ) )
429
+		return ( ! empty($DTT_ID) && ! empty($timestamps))
430
+			? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true))
431 431
 			: $name_link;
432 432
 	}
433 433
 
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
 	 * @param \EE_Registration $item
438 438
 	 * @return string
439 439
 	 */
440
-	public function column_ATT_email( EE_Registration $item ) {
440
+	public function column_ATT_email(EE_Registration $item) {
441 441
 		$attendee = $item->attendee();
442 442
 		return $attendee instanceof EE_Attendee ? $attendee->email() : '';
443 443
 	}
@@ -449,22 +449,22 @@  discard block
 block discarded – undo
449 449
 	 * @return bool|string
450 450
 	 * @throws \EE_Error
451 451
 	 */
452
-	public function column_Event( EE_Registration $item ) {
452
+	public function column_Event(EE_Registration $item) {
453 453
 		try {
454 454
 			$event = $this->_evt instanceof EE_Event ? $this->_evt : $item->event();
455 455
 			$chkin_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
456
-				array( 'action' => 'event_registrations', 'event_id' => $event->ID() ),
456
+				array('action' => 'event_registrations', 'event_id' => $event->ID()),
457 457
 				REG_ADMIN_URL
458 458
 			);
459 459
 			$event_label = EE_Registry::instance()->CAP->current_user_can(
460 460
 				'ee_read_checkins',
461 461
 				'espresso_registrations_registration_checkins'
462
-			) ? '<a href="' . $chkin_lnk_url . '" title="' . esc_attr__(
462
+			) ? '<a href="'.$chkin_lnk_url.'" title="'.esc_attr__(
463 463
 					'View Checkins for this Event',
464 464
 					'event_espresso'
465
-				) . '">' . $event->name() . '</a>' : $event->name();
466
-		} catch ( \EventEspresso\core\exceptions\EntityNotFoundException $e ) {
467
-			$event_label = esc_html__( 'Unknown', 'event_espresso' );
465
+				).'">'.$event->name().'</a>' : $event->name();
466
+		} catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) {
467
+			$event_label = esc_html__('Unknown', 'event_espresso');
468 468
 		}
469 469
 		return $event_label;
470 470
 	}
@@ -475,8 +475,8 @@  discard block
 block discarded – undo
475 475
 	 * @param \EE_Registration $item
476 476
 	 * @return mixed|string|void
477 477
 	 */
478
-	public function column_PRC_name( EE_Registration $item ) {
479
-		return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : __( "Unknown", "event_espresso" );
478
+	public function column_PRC_name(EE_Registration $item) {
479
+		return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : __("Unknown", "event_espresso");
480 480
 	}
481 481
 
482 482
 
@@ -487,8 +487,8 @@  discard block
 block discarded – undo
487 487
 	 * @param \EE_Registration $item
488 488
 	 * @return string
489 489
 	 */
490
-	public function column__REG_final_price( EE_Registration $item ) {
491
-		return '<span class="reg-pad-rght">' . ' ' . $item->pretty_final_price() . '</span>';
490
+	public function column__REG_final_price(EE_Registration $item) {
491
+		return '<span class="reg-pad-rght">'.' '.$item->pretty_final_price().'</span>';
492 492
 	}
493 493
 
494 494
 
@@ -500,13 +500,13 @@  discard block
 block discarded – undo
500 500
 	 * @return string
501 501
 	 * @throws \EE_Error
502 502
 	 */
503
-	public function column_TXN_paid( EE_Registration $item ) {
504
-		if ( $item->count() === 1 ) {
505
-			if ( $item->transaction()->paid() >= $item->transaction()->total() ) {
503
+	public function column_TXN_paid(EE_Registration $item) {
504
+		if ($item->count() === 1) {
505
+			if ($item->transaction()->paid() >= $item->transaction()->total()) {
506 506
 				return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>';
507 507
 			} else {
508 508
 				$view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(
509
-					array( 'action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID() ),
509
+					array('action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID()),
510 510
 					TXN_ADMIN_URL
511 511
 				);
512 512
 				return EE_Registry::instance()->CAP->current_user_can(
@@ -519,13 +519,13 @@  discard block
 block discarded – undo
519 519
 				    . '" href="'
520 520
 				    . $view_txn_lnk_url
521 521
 				    . '"  title="'
522
-				    . esc_attr__( 'View Transaction', 'event_espresso' )
522
+				    . esc_attr__('View Transaction', 'event_espresso')
523 523
 				    . '">
524 524
 						'
525 525
 				    . $item->transaction()->pretty_paid()
526 526
 				    . '
527 527
 					</a>
528
-				<span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>';
528
+				<span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_paid().'</span>';
529 529
 			}
530 530
 		} else {
531 531
 			return '<span class="reg-pad-rght"></span>';
@@ -541,13 +541,13 @@  discard block
 block discarded – undo
541 541
 	 * @return string
542 542
 	 * @throws \EE_Error
543 543
 	 */
544
-	public function column_TXN_total( EE_Registration $item ) {
544
+	public function column_TXN_total(EE_Registration $item) {
545 545
 		$txn = $item->transaction();
546
-		$view_txn_url = add_query_arg( array( 'action' => 'view_transaction', 'TXN_ID' => $txn->ID() ), TXN_ADMIN_URL );
547
-		if ( $item->get( 'REG_count' ) === 1 ) {
546
+		$view_txn_url = add_query_arg(array('action' => 'view_transaction', 'TXN_ID' => $txn->ID()), TXN_ADMIN_URL);
547
+		if ($item->get('REG_count') === 1) {
548 548
 			$line_total_obj = $txn->total_line_item();
549 549
 			$txn_total = $line_total_obj instanceof EE_Line_Item
550
-				? $line_total_obj->get_pretty( 'LIN_total' )
550
+				? $line_total_obj->get_pretty('LIN_total')
551 551
 				: __(
552 552
 					'View Transaction',
553 553
 					'event_espresso'
@@ -558,10 +558,10 @@  discard block
 block discarded – undo
558 558
 			) ? '<a href="'
559 559
 			    . $view_txn_url
560 560
 			    . '" title="'
561
-			    . esc_attr__( 'View Transaction', 'event_espresso' )
561
+			    . esc_attr__('View Transaction', 'event_espresso')
562 562
 			    . '"><span class="reg-pad-rght">'
563 563
 			    . $txn_total
564
-			    . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>';
564
+			    . '</span></a>' : '<span class="reg-pad-rght">'.$txn_total.'</span>';
565 565
 		} else {
566 566
 			return '<span class="reg-pad-rght"></span>';
567 567
 		}
Please login to merge, or discard this patch.
admin/extend/registrations/EE_Registration_CheckIn_List_Table.class.php 3 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -90,8 +90,8 @@
 block discarded – undo
90 90
 
91 91
 
92 92
 	public function column_CHK_in( EE_Checkin $item ) {
93
-        $checkin_status_dashicon = CheckinStatusDashicon::fromCheckin($item);
94
-        return '<span class="' . $checkin_status_dashicon->cssClasses() . '"></span><span class="show-on-mobile-view-only">' . $item->get_datetime('CHK_timestamp') . '</span>';
93
+		$checkin_status_dashicon = CheckinStatusDashicon::fromCheckin($item);
94
+		return '<span class="' . $checkin_status_dashicon->cssClasses() . '"></span><span class="show-on-mobile-view-only">' . $item->get_datetime('CHK_timestamp') . '</span>';
95 95
 	}
96 96
 
97 97
 
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 
31 31
 
32 32
 
33
-	public function __construct( $admin_page ) {
33
+	public function __construct($admin_page) {
34 34
 		parent::__construct($admin_page);
35 35
 	}
36 36
 
@@ -38,8 +38,8 @@  discard block
 block discarded – undo
38 38
 
39 39
 
40 40
 	protected function _setup_data() {
41
-		$this->_data = $this->_get_checkins( $this->_per_page );
42
-		$this->_all_data_count = $this->_get_checkins(  $this->_per_page, TRUE );
41
+		$this->_data = $this->_get_checkins($this->_per_page);
42
+		$this->_all_data_count = $this->_get_checkins($this->_per_page, TRUE);
43 43
 	}
44 44
 
45 45
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 			);
61 61
 
62 62
 		$this->_sortable_columns = array(
63
-			'CHK_timestamp' => array( 'CHK_timestamp' => TRUE )
63
+			'CHK_timestamp' => array('CHK_timestamp' => TRUE)
64 64
 			);
65 65
 
66 66
 		$this->_primary_column = 'CHK_in';
@@ -84,24 +84,24 @@  discard block
 block discarded – undo
84 84
 	}
85 85
 
86 86
 
87
-	function column_cb($item ) {
88
-		return sprintf( '<input type="checkbox" name="checkbox[%1$s]" />', $item->ID() );
87
+	function column_cb($item) {
88
+		return sprintf('<input type="checkbox" name="checkbox[%1$s]" />', $item->ID());
89 89
 	}
90 90
 
91 91
 
92
-	public function column_CHK_in( EE_Checkin $item ) {
92
+	public function column_CHK_in(EE_Checkin $item) {
93 93
         $checkin_status_dashicon = CheckinStatusDashicon::fromCheckin($item);
94
-        return '<span class="' . $checkin_status_dashicon->cssClasses() . '"></span><span class="show-on-mobile-view-only">' . $item->get_datetime('CHK_timestamp') . '</span>';
94
+        return '<span class="'.$checkin_status_dashicon->cssClasses().'"></span><span class="show-on-mobile-view-only">'.$item->get_datetime('CHK_timestamp').'</span>';
95 95
 	}
96 96
 
97 97
 
98 98
 
99
-	function column_CHK_timestamp( EE_Checkin $item ) {
99
+	function column_CHK_timestamp(EE_Checkin $item) {
100 100
 		$actions = array();
101
-		$delete_url = EE_Admin_Page::add_query_args_and_nonce( array('action' => 'delete_checkin_row', 'DTT_ID' => $this->_req_data['DTT_ID'], '_REGID' => $this->_req_data['_REGID'], 'CHK_ID' => $item->ID() ) );
102
-		$actions['delete_checkin'] = EE_Registry::instance()->CAP->current_user_can( 'ee_delete_checkins', 'espresso_registrations_delete_checkin_row' ) ? '<a href="' . $delete_url . '" title="' . esc_attr__('Click here to delete this check-in record', 'event_espresso') . '">' . __('Delete', 'event_espresso') . '</a>' : '';
101
+		$delete_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'delete_checkin_row', 'DTT_ID' => $this->_req_data['DTT_ID'], '_REGID' => $this->_req_data['_REGID'], 'CHK_ID' => $item->ID()));
102
+		$actions['delete_checkin'] = EE_Registry::instance()->CAP->current_user_can('ee_delete_checkins', 'espresso_registrations_delete_checkin_row') ? '<a href="'.$delete_url.'" title="'.esc_attr__('Click here to delete this check-in record', 'event_espresso').'">'.__('Delete', 'event_espresso').'</a>' : '';
103 103
 
104
-		return sprintf( '%1$s %2$s', $item->get_datetime('CHK_timestamp'), $this->row_actions($actions) );
104
+		return sprintf('%1$s %2$s', $item->get_datetime('CHK_timestamp'), $this->row_actions($actions));
105 105
 	}
106 106
 
107 107
 
@@ -116,30 +116,30 @@  discard block
 block discarded – undo
116 116
 	 * @param bool    $count        Whether to return a count or not
117 117
 	 * @return EE_Checkin[]|int
118 118
 	 */
119
-	protected function _get_checkins( $per_page = 10, $count = FALSE ) {
120
-		$REG_ID = isset( $this->_req_data['_REGID'] ) ? $this->_req_data['_REGID'] : FALSE;
121
-		$DTT_ID = isset( $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : FALSE;
119
+	protected function _get_checkins($per_page = 10, $count = FALSE) {
120
+		$REG_ID = isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : FALSE;
121
+		$DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : FALSE;
122 122
 
123 123
 		//if user does not have the capability for the checkins for this registration then get out!
124
-		if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_checkin', 'espresso_registrations_registration_checkins', $REG_ID ) ) {
124
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_checkin', 'espresso_registrations_registration_checkins', $REG_ID)) {
125 125
 			return $count ? 0 : array();
126 126
 		}
127 127
 
128 128
 		//if no reg id then get out cause need a reg id
129
-		if ( empty( $REG_ID ) || empty( $DTT_ID ) )
130
-			throw new EE_Error(__('This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', 'event_espresso') );
129
+		if (empty($REG_ID) || empty($DTT_ID))
130
+			throw new EE_Error(__('This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', 'event_espresso'));
131 131
 
132 132
 		//set orderby
133 133
 		$orderby = 'CHK_timestamp'; //note that with this table we're only providing the option to orderby the timestamp value.
134 134
 
135
-		$order = !empty( $this->_req_data['order'] ) ? $this->_req_data['order'] : 'ASC';
135
+		$order = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
136 136
 
137
-		$current_page = isset( $this->_req_data['paged'] ) && !empty( $this->_req_data['paged'] ) ? $this->_req_data['paged'] : 1;
138
-		$per_page = isset( $this->_req_data['perpage'] ) && !empty( $this->_req_data['perpage'] ) ? $this->_req_data['perpage'] : $per_page;
137
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
138
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page;
139 139
 		$limit = NULL;
140
-		if ( !$count ) {
141
-			$offset = ($current_page-1)*$per_page;
142
-			$limit = array( $offset, $per_page );
140
+		if ( ! $count) {
141
+			$offset = ($current_page - 1) * $per_page;
142
+			$limit = array($offset, $per_page);
143 143
 		}
144 144
 
145 145
 		$_where = array(
@@ -147,13 +147,13 @@  discard block
 block discarded – undo
147 147
 			'DTT_ID' => $DTT_ID
148 148
 			);
149 149
 
150
-		$query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit );
150
+		$query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit);
151 151
 
152 152
 		//if no per_page value then we just want to return a count of all Check-ins
153
-		if ( $count )
154
-			return EEM_Checkin::instance()->count( array( $_where ) );
153
+		if ($count)
154
+			return EEM_Checkin::instance()->count(array($_where));
155 155
 
156
-		return $count ? EEM_Checkin::instance()->count( array( $_where ) ) : EEM_Checkin::instance()->get_all($query_params);
156
+		return $count ? EEM_Checkin::instance()->count(array($_where)) : EEM_Checkin::instance()->get_all($query_params);
157 157
 	}
158 158
 
159 159
 } //end class EE_Registration_CheckIn_List_Table
Please login to merge, or discard this patch.
Braces   +9 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php use EventEspresso\ui\browser\checkins\entities\CheckinStatusDashicon;
2 2
 
3
-if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
3
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
4
+	exit('No direct script access allowed');
5
+}
4 6
 /**
5 7
  * Event Espresso
6 8
  *
@@ -126,8 +128,9 @@  discard block
 block discarded – undo
126 128
 		}
127 129
 
128 130
 		//if no reg id then get out cause need a reg id
129
-		if ( empty( $REG_ID ) || empty( $DTT_ID ) )
130
-			throw new EE_Error(__('This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', 'event_espresso') );
131
+		if ( empty( $REG_ID ) || empty( $DTT_ID ) ) {
132
+					throw new EE_Error(__('This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', 'event_espresso') );
133
+		}
131 134
 
132 135
 		//set orderby
133 136
 		$orderby = 'CHK_timestamp'; //note that with this table we're only providing the option to orderby the timestamp value.
@@ -150,8 +153,9 @@  discard block
 block discarded – undo
150 153
 		$query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit );
151 154
 
152 155
 		//if no per_page value then we just want to return a count of all Check-ins
153
-		if ( $count )
154
-			return EEM_Checkin::instance()->count( array( $_where ) );
156
+		if ( $count ) {
157
+					return EEM_Checkin::instance()->count( array( $_where ) );
158
+		}
155 159
 
156 160
 		return $count ? EEM_Checkin::instance()->count( array( $_where ) ) : EEM_Checkin::instance()->get_all($query_params);
157 161
 	}
Please login to merge, or discard this patch.
core/db_classes/EE_Checkin.class.php 1 patch
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -13,88 +13,88 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * Used to reference when a registration has been checked out.
18
-     *
19
-     * @type int
20
-     */
21
-    const status_checked_out = 0;
22
-
23
-    /**
24
-     * Used to reference when a registration has been checked in.
25
-     *
26
-     * @type int
27
-     */
28
-    const status_checked_in = 1;
29
-
30
-    /**
31
-     * Used to reference when a registration has never been checked in.
32
-     *
33
-     * @type int
34
-     */
35
-    const status_checked_never = 2;
36
-
37
-
38
-
39
-    /**
40
-     *
41
-     * @param array  $props_n_values    incoming values
42
-     * @param string $timezone          incoming timezone (if not set the timezone set for the website will be used.)
43
-     * @param array  $date_formats      incoming date_formats in an array
44
-     *                                  where the first value is the date_format
45
-     *                                  and the second value is the time format
46
-     * @return EE_Checkin
47
-     * @throws EE_Error
48
-     */
49
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
50
-    {
51
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
52
-        return $has_object
53
-            ? $has_object
54
-            : new self($props_n_values, false, $timezone, $date_formats);
55
-    }
56
-
57
-
58
-
59
-    /**
60
-     * @param array  $props_n_values  incoming values from the database
61
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
62
-     *                                the website will be used.
63
-     * @return EE_Checkin
64
-     * @throws EE_Error
65
-     */
66
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
67
-    {
68
-        return new self($props_n_values, true, $timezone);
69
-    }
70
-
71
-
72
-    public function ID()
73
-    {
74
-        return $this->get('CHK_ID');
75
-    }
76
-
77
-
78
-    public function registration_id()
79
-    {
80
-        return $this->get('REG_ID');
81
-    }
82
-
83
-
84
-    public function datetime_id()
85
-    {
86
-        return $this->get('DTT_ID');
87
-    }
88
-
89
-
90
-    public function status()
91
-    {
92
-        return $this->get('CHK_in');
93
-    }
94
-
95
-
96
-    public function timestamp()
97
-    {
98
-        return $this->get('CHK_timestamp');
99
-    }
16
+	/**
17
+	 * Used to reference when a registration has been checked out.
18
+	 *
19
+	 * @type int
20
+	 */
21
+	const status_checked_out = 0;
22
+
23
+	/**
24
+	 * Used to reference when a registration has been checked in.
25
+	 *
26
+	 * @type int
27
+	 */
28
+	const status_checked_in = 1;
29
+
30
+	/**
31
+	 * Used to reference when a registration has never been checked in.
32
+	 *
33
+	 * @type int
34
+	 */
35
+	const status_checked_never = 2;
36
+
37
+
38
+
39
+	/**
40
+	 *
41
+	 * @param array  $props_n_values    incoming values
42
+	 * @param string $timezone          incoming timezone (if not set the timezone set for the website will be used.)
43
+	 * @param array  $date_formats      incoming date_formats in an array
44
+	 *                                  where the first value is the date_format
45
+	 *                                  and the second value is the time format
46
+	 * @return EE_Checkin
47
+	 * @throws EE_Error
48
+	 */
49
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
50
+	{
51
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
52
+		return $has_object
53
+			? $has_object
54
+			: new self($props_n_values, false, $timezone, $date_formats);
55
+	}
56
+
57
+
58
+
59
+	/**
60
+	 * @param array  $props_n_values  incoming values from the database
61
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
62
+	 *                                the website will be used.
63
+	 * @return EE_Checkin
64
+	 * @throws EE_Error
65
+	 */
66
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
67
+	{
68
+		return new self($props_n_values, true, $timezone);
69
+	}
70
+
71
+
72
+	public function ID()
73
+	{
74
+		return $this->get('CHK_ID');
75
+	}
76
+
77
+
78
+	public function registration_id()
79
+	{
80
+		return $this->get('REG_ID');
81
+	}
82
+
83
+
84
+	public function datetime_id()
85
+	{
86
+		return $this->get('DTT_ID');
87
+	}
88
+
89
+
90
+	public function status()
91
+	{
92
+		return $this->get('CHK_in');
93
+	}
94
+
95
+
96
+	public function timestamp()
97
+	{
98
+		return $this->get('CHK_timestamp');
99
+	}
100 100
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Registration.class.php 1 patch
Indentation   +1815 added lines, -1815 removed lines patch added patch discarded remove patch
@@ -15,1821 +15,1821 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * Used to reference when a registration has never been checked in.
20
-     *
21
-     * @deprecated use \EE_Checkin::status_checked_never instead
22
-     * @type int
23
-     */
24
-    const checkin_status_never = 2;
25
-
26
-    /**
27
-     * Used to reference when a registration has been checked in.
28
-     *
29
-     * @deprecated use \EE_Checkin::status_checked_in instead
30
-     * @type int
31
-     */
32
-    const checkin_status_in = 1;
33
-
34
-
35
-    /**
36
-     * Used to reference when a registration has been checked out.
37
-     *
38
-     * @deprecated use \EE_Checkin::status_checked_out instead
39
-     * @type int
40
-     */
41
-    const checkin_status_out = 0;
42
-
43
-
44
-    /**
45
-     * extra meta key for tracking reg status os trashed registrations
46
-     *
47
-     * @type string
48
-     */
49
-    const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status';
50
-
51
-
52
-    /**
53
-     * extra meta key for tracking if registration has reserved ticket
54
-     *
55
-     * @type string
56
-     */
57
-    const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket';
58
-
59
-
60
-    /**
61
-     * @param array  $props_n_values          incoming values
62
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
63
-     *                                        used.)
64
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
65
-     *                                        date_format and the second value is the time format
66
-     * @return EE_Registration
67
-     * @throws EE_Error
68
-     */
69
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
70
-    {
71
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
72
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
73
-    }
74
-
75
-
76
-    /**
77
-     * @param array  $props_n_values  incoming values from the database
78
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
79
-     *                                the website will be used.
80
-     * @return EE_Registration
81
-     */
82
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
83
-    {
84
-        return new self($props_n_values, true, $timezone);
85
-    }
86
-
87
-
88
-    /**
89
-     *        Set Event ID
90
-     *
91
-     * @param        int $EVT_ID Event ID
92
-     * @throws EE_Error
93
-     * @throws RuntimeException
94
-     */
95
-    public function set_event($EVT_ID = 0)
96
-    {
97
-        $this->set('EVT_ID', $EVT_ID);
98
-    }
99
-
100
-
101
-    /**
102
-     * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can
103
-     * be routed to internal methods
104
-     *
105
-     * @param string $field_name
106
-     * @param mixed  $field_value
107
-     * @param bool   $use_default
108
-     * @throws \EE_Error
109
-     * @throws \RuntimeException
110
-     */
111
-    public function set($field_name, $field_value, $use_default = false)
112
-    {
113
-        switch ($field_name) {
114
-            case 'REG_code':
115
-                if (! empty($field_value) && $this->reg_code() === null) {
116
-                    $this->set_reg_code($field_value, $use_default);
117
-                }
118
-                break;
119
-            case 'STS_ID':
120
-                $this->set_status($field_value, $use_default);
121
-                break;
122
-            default:
123
-                parent::set($field_name, $field_value, $use_default);
124
-        }
125
-    }
126
-
127
-
128
-    /**
129
-     * Set Status ID
130
-     * updates the registration status and ALSO...
131
-     * calls reserve_registration_space() if the reg status changes TO approved from any other reg status
132
-     * calls release_registration_space() if the reg status changes FROM approved to any other reg status
133
-     *
134
-     * @param string  $new_STS_ID
135
-     * @param boolean $use_default
136
-     * @return bool
137
-     * @throws \RuntimeException
138
-     * @throws \EE_Error
139
-     */
140
-    public function set_status($new_STS_ID = null, $use_default = false)
141
-    {
142
-        // get current REG_Status
143
-        $old_STS_ID = $this->status_ID();
144
-        // if status has changed
145
-        if ($old_STS_ID !== $new_STS_ID // and that status has actually changed
146
-            && ! empty($old_STS_ID) // and that old status is actually set
147
-            && ! empty($new_STS_ID) // as well as the new status
148
-            && $this->ID() // ensure registration is in the db
149
-        ) {
150
-            // TO approved
151
-            if ($new_STS_ID === EEM_Registration::status_id_approved) {
152
-                // reserve a space by incrementing ticket and datetime sold values
153
-                $this->_reserve_registration_space();
154
-                do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID);
155
-                // OR FROM  approved
156
-            } elseif ($old_STS_ID === EEM_Registration::status_id_approved) {
157
-                // release a space by decrementing ticket and datetime sold values
158
-                $this->_release_registration_space();
159
-                do_action('AHEE__EE_Registration__set_status__from_approved', $this, $old_STS_ID, $new_STS_ID);
160
-            }
161
-            // update status
162
-            parent::set('STS_ID', $new_STS_ID, $use_default);
163
-            $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID);
164
-            /** @type EE_Transaction_Payments $transaction_payments */
165
-            $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
166
-            $transaction_payments->recalculate_transaction_total($this->transaction(), false);
167
-            $this->transaction()->update_status_based_on_total_paid(true);
168
-            do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID);
169
-            return true;
170
-        }
171
-        //even though the old value matches the new value, it's still good to
172
-        //allow the parent set method to have a say
173
-        parent::set('STS_ID', $new_STS_ID, $use_default);
174
-        return true;
175
-    }
176
-
177
-
178
-    /**
179
-     * update REGs and TXN when cancelled or declined registrations involved
180
-     *
181
-     * @param string $new_STS_ID
182
-     * @param string $old_STS_ID
183
-     * @throws \EE_Error
184
-     */
185
-    private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID)
186
-    {
187
-        // these reg statuses should not be considered in any calculations involving monies owing
188
-        $closed_reg_statuses = EEM_Registration::closed_reg_statuses();
189
-        // true if registration has been cancelled or declined
190
-        if (in_array($new_STS_ID, $closed_reg_statuses, true)
191
-            && ! in_array($old_STS_ID, $closed_reg_statuses, true)
192
-        ) {
193
-            /** @type EE_Registration_Processor $registration_processor */
194
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
195
-            /** @type EE_Transaction_Processor $transaction_processor */
196
-            $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
197
-            // cancelled or declined registration
198
-            $registration_processor->update_registration_after_being_canceled_or_declined(
199
-                $this,
200
-                $closed_reg_statuses
201
-            );
202
-            $transaction_processor->update_transaction_after_canceled_or_declined_registration(
203
-                $this,
204
-                $closed_reg_statuses,
205
-                false
206
-            );
207
-            do_action('AHEE__EE_Registration__set_status__canceled_or_declined', $this, $old_STS_ID, $new_STS_ID);
208
-            return;
209
-        }
210
-        // true if reinstating cancelled or declined registration
211
-        if (in_array($old_STS_ID, $closed_reg_statuses, true)
212
-            && ! in_array($new_STS_ID, $closed_reg_statuses, true)
213
-        ) {
214
-            /** @type EE_Registration_Processor $registration_processor */
215
-            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
216
-            /** @type EE_Transaction_Processor $transaction_processor */
217
-            $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
218
-            // reinstating cancelled or declined registration
219
-            $registration_processor->update_canceled_or_declined_registration_after_being_reinstated(
220
-                $this,
221
-                $closed_reg_statuses
222
-            );
223
-            $transaction_processor->update_transaction_after_reinstating_canceled_registration(
224
-                $this,
225
-                $closed_reg_statuses,
226
-                false
227
-            );
228
-            do_action('AHEE__EE_Registration__set_status__after_reinstated', $this, $old_STS_ID, $new_STS_ID);
229
-        }
230
-    }
231
-
232
-
233
-    /**
234
-     *        get Status ID
235
-     */
236
-    public function status_ID()
237
-    {
238
-        return $this->get('STS_ID');
239
-    }
240
-
241
-
242
-    /**
243
-     * increments this registration's related ticket sold and corresponding datetime sold values
244
-     *
245
-     * @return void
246
-     * @throws EE_Error
247
-     * @throws EntityNotFoundException
248
-     */
249
-    private function _reserve_registration_space()
250
-    {
251
-        // reserved ticket and datetime counts will be decremented as sold counts are incremented
252
-        // so stop tracking that this reg has a ticket reserved
253
-        $this->release_reserved_ticket();
254
-        $ticket = $this->ticket();
255
-        $ticket->increase_sold();
256
-        $ticket->save();
257
-        // possibly set event status to sold out
258
-        $this->event()->perform_sold_out_status_check();
259
-    }
260
-
261
-
262
-    /**
263
-     * Gets the ticket this registration is for
264
-     *
265
-     * @param boolean $include_archived whether to include archived tickets or not.
266
-     * @return EE_Ticket|EE_Base_Class
267
-     * @throws \EE_Error
268
-     */
269
-    public function ticket($include_archived = true)
270
-    {
271
-        $query_params = array();
272
-        if ($include_archived) {
273
-            $query_params['default_where_conditions'] = 'none';
274
-        }
275
-        return $this->get_first_related('Ticket', $query_params);
276
-    }
277
-
278
-
279
-    /**
280
-     * Gets the event this registration is for
281
-     *
282
-     * @return EE_Event
283
-     * @throws EE_Error
284
-     * @throws EntityNotFoundException
285
-     */
286
-    public function event()
287
-    {
288
-        $event = $this->get_first_related('Event');
289
-        if (! $event instanceof \EE_Event) {
290
-            throw new EntityNotFoundException('Event ID', $this->event_ID());
291
-        }
292
-        return $event;
293
-    }
294
-
295
-
296
-    /**
297
-     * Gets the "author" of the registration.  Note that for the purposes of registrations, the author will correspond
298
-     * with the author of the event this registration is for.
299
-     *
300
-     * @since 4.5.0
301
-     * @return int
302
-     * @throws EE_Error
303
-     * @throws EntityNotFoundException
304
-     */
305
-    public function wp_user()
306
-    {
307
-        $event = $this->event();
308
-        if ($event instanceof EE_Event) {
309
-            return $event->wp_user();
310
-        }
311
-        return 0;
312
-    }
313
-
314
-
315
-    /**
316
-     * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values
317
-     *
318
-     * @return void
319
-     * @throws \EE_Error
320
-     */
321
-    private function _release_registration_space()
322
-    {
323
-        $ticket = $this->ticket();
324
-        $ticket->decrease_sold();
325
-        $ticket->save();
326
-    }
327
-
328
-
329
-    /**
330
-     * tracks this registration's ticket reservation in extra meta
331
-     * and can increment related ticket reserved and corresponding datetime reserved values
332
-     *
333
-     * @param bool $update_ticket if true, will increment ticket and datetime reserved count
334
-     * @return void
335
-     * @throws \EE_Error
336
-     */
337
-    public function reserve_ticket($update_ticket = false)
338
-    {
339
-        if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) === false) {
340
-            // PLZ NOTE: although checking $update_ticket first would be more efficient,
341
-            // we NEED to ALWAYS call update_extra_meta(), which is why that is done first
342
-            if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) && $update_ticket) {
343
-                $ticket = $this->ticket();
344
-                $ticket->increase_reserved();
345
-                $ticket->save();
346
-            }
347
-        }
348
-    }
349
-
350
-
351
-    /**
352
-     * stops tracking this registration's ticket reservation in extra meta
353
-     * decrements (subtracts) related ticket reserved and corresponding datetime reserved values
354
-     *
355
-     * @param bool $update_ticket if true, will decrement ticket and datetime reserved count
356
-     * @return void
357
-     * @throws \EE_Error
358
-     */
359
-    public function release_reserved_ticket($update_ticket = false)
360
-    {
361
-        if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) !== false) {
362
-            // PLZ NOTE: although checking $update_ticket first would be more efficient,
363
-            // we NEED to ALWAYS call delete_extra_meta(), which is why that is done first
364
-            if ($this->delete_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY) && $update_ticket) {
365
-                $ticket = $this->ticket();
366
-                $ticket->decrease_reserved();
367
-                $ticket->save();
368
-            }
369
-        }
370
-    }
371
-
372
-
373
-    /**
374
-     * Set Attendee ID
375
-     *
376
-     * @param        int $ATT_ID Attendee ID
377
-     * @throws EE_Error
378
-     * @throws RuntimeException
379
-     */
380
-    public function set_attendee_id($ATT_ID = 0)
381
-    {
382
-        $this->set('ATT_ID', $ATT_ID);
383
-    }
384
-
385
-
386
-    /**
387
-     *        Set Transaction ID
388
-     *
389
-     * @param        int $TXN_ID Transaction ID
390
-     * @throws EE_Error
391
-     * @throws RuntimeException
392
-     */
393
-    public function set_transaction_id($TXN_ID = 0)
394
-    {
395
-        $this->set('TXN_ID', $TXN_ID);
396
-    }
397
-
398
-
399
-    /**
400
-     *        Set Session
401
-     *
402
-     * @param    string $REG_session PHP Session ID
403
-     * @throws EE_Error
404
-     * @throws RuntimeException
405
-     */
406
-    public function set_session($REG_session = '')
407
-    {
408
-        $this->set('REG_session', $REG_session);
409
-    }
410
-
411
-
412
-    /**
413
-     *        Set Registration URL Link
414
-     *
415
-     * @param    string $REG_url_link Registration URL Link
416
-     * @throws EE_Error
417
-     * @throws RuntimeException
418
-     */
419
-    public function set_reg_url_link($REG_url_link = '')
420
-    {
421
-        $this->set('REG_url_link', $REG_url_link);
422
-    }
423
-
424
-
425
-    /**
426
-     *        Set Attendee Counter
427
-     *
428
-     * @param        int $REG_count Primary Attendee
429
-     * @throws EE_Error
430
-     * @throws RuntimeException
431
-     */
432
-    public function set_count($REG_count = 1)
433
-    {
434
-        $this->set('REG_count', $REG_count);
435
-    }
436
-
437
-
438
-    /**
439
-     *        Set Group Size
440
-     *
441
-     * @param        boolean $REG_group_size Group Registration
442
-     * @throws EE_Error
443
-     * @throws RuntimeException
444
-     */
445
-    public function set_group_size($REG_group_size = false)
446
-    {
447
-        $this->set('REG_group_size', $REG_group_size);
448
-    }
449
-
450
-
451
-    /**
452
-     *    is_not_approved -  convenience method that returns TRUE if REG status ID ==
453
-     *    EEM_Registration::status_id_not_approved
454
-     *
455
-     * @return        boolean
456
-     */
457
-    public function is_not_approved()
458
-    {
459
-        return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false;
460
-    }
461
-
462
-
463
-    /**
464
-     *    is_pending_payment -  convenience method that returns TRUE if REG status ID ==
465
-     *    EEM_Registration::status_id_pending_payment
466
-     *
467
-     * @return        boolean
468
-     */
469
-    public function is_pending_payment()
470
-    {
471
-        return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false;
472
-    }
473
-
474
-
475
-    /**
476
-     *    is_approved -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved
477
-     *
478
-     * @return        boolean
479
-     */
480
-    public function is_approved()
481
-    {
482
-        return $this->status_ID() == EEM_Registration::status_id_approved ? true : false;
483
-    }
484
-
485
-
486
-    /**
487
-     *    is_cancelled -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled
488
-     *
489
-     * @return        boolean
490
-     */
491
-    public function is_cancelled()
492
-    {
493
-        return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false;
494
-    }
495
-
496
-
497
-    /**
498
-     *    is_declined -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined
499
-     *
500
-     * @return        boolean
501
-     */
502
-    public function is_declined()
503
-    {
504
-        return $this->status_ID() == EEM_Registration::status_id_declined ? true : false;
505
-    }
506
-
507
-
508
-    /**
509
-     *    is_incomplete -  convenience method that returns TRUE if REG status ID ==
510
-     *    EEM_Registration::status_id_incomplete
511
-     *
512
-     * @return        boolean
513
-     */
514
-    public function is_incomplete()
515
-    {
516
-        return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false;
517
-    }
518
-
519
-
520
-    /**
521
-     *        Set Registration Date
522
-     *
523
-     * @param        mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of
524
-     *                                                 Date
525
-     * @throws EE_Error
526
-     * @throws RuntimeException
527
-     */
528
-    public function set_reg_date($REG_date = false)
529
-    {
530
-        $this->set('REG_date', $REG_date);
531
-    }
532
-
533
-
534
-    /**
535
-     *    Set final price owing for this registration after all ticket/price modifications
536
-     *
537
-     * @access    public
538
-     * @param    float $REG_final_price
539
-     * @throws EE_Error
540
-     * @throws RuntimeException
541
-     */
542
-    public function set_final_price($REG_final_price = 0.00)
543
-    {
544
-        $this->set('REG_final_price', $REG_final_price);
545
-    }
546
-
547
-
548
-    /**
549
-     *    Set amount paid towards this registration's final price
550
-     *
551
-     * @access    public
552
-     * @param    float $REG_paid
553
-     * @throws EE_Error
554
-     * @throws RuntimeException
555
-     */
556
-    public function set_paid($REG_paid = 0.00)
557
-    {
558
-        $this->set('REG_paid', $REG_paid);
559
-    }
560
-
561
-
562
-    /**
563
-     *        Attendee Is Going
564
-     *
565
-     * @param        boolean $REG_att_is_going Attendee Is Going
566
-     * @throws EE_Error
567
-     * @throws RuntimeException
568
-     */
569
-    public function set_att_is_going($REG_att_is_going = false)
570
-    {
571
-        $this->set('REG_att_is_going', $REG_att_is_going);
572
-    }
573
-
574
-
575
-    /**
576
-     * Gets the related attendee
577
-     *
578
-     * @return EE_Attendee
579
-     * @throws EE_Error
580
-     */
581
-    public function attendee()
582
-    {
583
-        return $this->get_first_related('Attendee');
584
-    }
585
-
586
-
587
-    /**
588
-     *        get Event ID
589
-     */
590
-    public function event_ID()
591
-    {
592
-        return $this->get('EVT_ID');
593
-    }
594
-
595
-
596
-    /**
597
-     *        get Event ID
598
-     */
599
-    public function event_name()
600
-    {
601
-        $event = $this->event_obj();
602
-        if ($event) {
603
-            return $event->name();
604
-        } else {
605
-            return null;
606
-        }
607
-    }
608
-
609
-
610
-    /**
611
-     * Fetches the event this registration is for
612
-     *
613
-     * @return EE_Event
614
-     * @throws EE_Error
615
-     */
616
-    public function event_obj()
617
-    {
618
-        return $this->get_first_related('Event');
619
-    }
620
-
621
-
622
-    /**
623
-     *        get Attendee ID
624
-     */
625
-    public function attendee_ID()
626
-    {
627
-        return $this->get('ATT_ID');
628
-    }
629
-
630
-
631
-    /**
632
-     *        get PHP Session ID
633
-     */
634
-    public function session_ID()
635
-    {
636
-        return $this->get('REG_session');
637
-    }
638
-
639
-
640
-    /**
641
-     * Gets the string which represents the URL trigger for the receipt template in the message template system.
642
-     *
643
-     * @param string $messenger 'pdf' or 'html'.  Default 'html'.
644
-     * @return string
645
-     */
646
-    public function receipt_url($messenger = 'html')
647
-    {
648
-
649
-        /**
650
-         * The below will be deprecated one version after this.  We check first if there is a custom receipt template
651
-         * already in use on old system.  If there is then we just return the standard url for it.
652
-         *
653
-         * @since 4.5.0
654
-         */
655
-        $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php';
656
-        $has_custom             = EEH_Template::locate_template(
657
-            $template_relative_path,
658
-            array(),
659
-            true,
660
-            true,
661
-            true
662
-        );
663
-
664
-        if ($has_custom) {
665
-            return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch'));
666
-        }
667
-        return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt');
668
-    }
669
-
670
-
671
-    /**
672
-     * Gets the string which represents the URL trigger for the invoice template in the message template system.
673
-     *
674
-     * @param string $messenger 'pdf' or 'html'.  Default 'html'.
675
-     * @return string
676
-     * @throws EE_Error
677
-     */
678
-    public function invoice_url($messenger = 'html')
679
-    {
680
-        /**
681
-         * The below will be deprecated one version after this.  We check first if there is a custom invoice template
682
-         * already in use on old system.  If there is then we just return the standard url for it.
683
-         *
684
-         * @since 4.5.0
685
-         */
686
-        $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php';
687
-        $has_custom             = EEH_Template::locate_template(
688
-            $template_relative_path,
689
-            array(),
690
-            true,
691
-            true,
692
-            true
693
-        );
694
-
695
-        if ($has_custom) {
696
-            if ($messenger == 'html') {
697
-                return $this->invoice_url('launch');
698
-            }
699
-            $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice';
700
-
701
-            $query_args = array('ee' => $route, 'id' => $this->reg_url_link());
702
-            if ($messenger == 'html') {
703
-                $query_args['html'] = true;
704
-            }
705
-            return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id));
706
-        }
707
-        return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice');
708
-    }
709
-
710
-
711
-    /**
712
-     * get Registration URL Link
713
-     *
714
-     * @access public
715
-     * @return string
716
-     * @throws \EE_Error
717
-     */
718
-    public function reg_url_link()
719
-    {
720
-        return (string) $this->get('REG_url_link');
721
-    }
722
-
723
-
724
-    /**
725
-     * Echoes out invoice_url()
726
-     *
727
-     * @param string $type 'download','launch', or 'html' (default is 'launch')
728
-     * @return void
729
-     * @throws EE_Error
730
-     */
731
-    public function e_invoice_url($type = 'launch')
732
-    {
733
-        echo $this->invoice_url($type);
734
-    }
735
-
736
-
737
-    /**
738
-     * Echoes out payment_overview_url
739
-     */
740
-    public function e_payment_overview_url()
741
-    {
742
-        echo $this->payment_overview_url();
743
-    }
744
-
745
-
746
-    /**
747
-     * Gets the URL of the thank you page with this registration REG_url_link added as
748
-     * a query parameter
749
-     *
750
-     * @param bool $clear_session Set to true when you want to clear the session on revisiting the
751
-     *                            payment overview url.
752
-     * @return string
753
-     * @throws EE_Error
754
-     */
755
-    public function payment_overview_url($clear_session = false)
756
-    {
757
-        return add_query_arg(array(
758
-            'e_reg_url_link' => $this->reg_url_link(),
759
-            'step'           => 'payment_options',
760
-            'revisit'        => true,
761
-            'clear_session' => (bool) $clear_session
762
-        ), EE_Registry::instance()->CFG->core->reg_page_url());
763
-    }
764
-
765
-
766
-    /**
767
-     * Gets the URL of the thank you page with this registration REG_url_link added as
768
-     * a query parameter
769
-     *
770
-     * @return string
771
-     * @throws EE_Error
772
-     */
773
-    public function edit_attendee_information_url()
774
-    {
775
-        return add_query_arg(array(
776
-            'e_reg_url_link' => $this->reg_url_link(),
777
-            'step'           => 'attendee_information',
778
-            'revisit'        => true,
779
-        ), EE_Registry::instance()->CFG->core->reg_page_url());
780
-    }
781
-
782
-
783
-    /**
784
-     * Simply generates and returns the appropriate admin_url link to edit this registration
785
-     *
786
-     * @return string
787
-     * @throws EE_Error
788
-     */
789
-    public function get_admin_edit_url()
790
-    {
791
-        return EEH_URL::add_query_args_and_nonce(array(
792
-            'page'    => 'espresso_registrations',
793
-            'action'  => 'view_registration',
794
-            '_REG_ID' => $this->ID(),
795
-        ), admin_url('admin.php'));
796
-    }
797
-
798
-
799
-    /**
800
-     *    is_primary_registrant?
801
-     */
802
-    public function is_primary_registrant()
803
-    {
804
-        return $this->get('REG_count') == 1 ? true : false;
805
-    }
806
-
807
-
808
-    /**
809
-     * This returns the primary registration object for this registration group (which may be this object).
810
-     *
811
-     * @return EE_Registration
812
-     * @throws EE_Error
813
-     */
814
-    public function get_primary_registration()
815
-    {
816
-        if ($this->is_primary_registrant()) {
817
-            return $this;
818
-        }
819
-
820
-        //k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1
821
-        /** @var EE_Registration $primary_registrant */
822
-        $primary_registrant = EEM_Registration::instance()->get_one(array(
823
-            array(
824
-                'TXN_ID'    => $this->transaction_ID(),
825
-                'REG_count' => 1,
826
-            ),
827
-        ));
828
-        return $primary_registrant;
829
-    }
830
-
831
-
832
-    /**
833
-     *        get  Attendee Number
834
-     *
835
-     * @access        public
836
-     */
837
-    public function count()
838
-    {
839
-        return $this->get('REG_count');
840
-    }
841
-
842
-
843
-    /**
844
-     *        get Group Size
845
-     */
846
-    public function group_size()
847
-    {
848
-        return $this->get('REG_group_size');
849
-    }
850
-
851
-
852
-    /**
853
-     *        get Registration Date
854
-     */
855
-    public function date()
856
-    {
857
-        return $this->get('REG_date');
858
-    }
859
-
860
-
861
-    /**
862
-     * gets a pretty date
863
-     *
864
-     * @param string $date_format
865
-     * @param string $time_format
866
-     * @return string
867
-     * @throws EE_Error
868
-     */
869
-    public function pretty_date($date_format = null, $time_format = null)
870
-    {
871
-        return $this->get_datetime('REG_date', $date_format, $time_format);
872
-    }
873
-
874
-
875
-    /**
876
-     * final_price
877
-     * the registration's share of the transaction total, so that the
878
-     * sum of all the transaction's REG_final_prices equal the transaction's total
879
-     *
880
-     * @return float
881
-     * @throws EE_Error
882
-     */
883
-    public function final_price()
884
-    {
885
-        return $this->get('REG_final_price');
886
-    }
887
-
888
-
889
-    /**
890
-     * pretty_final_price
891
-     *  final price as formatted string, with correct decimal places and currency symbol
892
-     *
893
-     * @return string
894
-     * @throws EE_Error
895
-     */
896
-    public function pretty_final_price()
897
-    {
898
-        return $this->get_pretty('REG_final_price');
899
-    }
900
-
901
-
902
-    /**
903
-     * get paid (yeah)
904
-     *
905
-     * @return float
906
-     * @throws EE_Error
907
-     */
908
-    public function paid()
909
-    {
910
-        return $this->get('REG_paid');
911
-    }
912
-
913
-
914
-    /**
915
-     * pretty_paid
916
-     *
917
-     * @return float
918
-     * @throws EE_Error
919
-     */
920
-    public function pretty_paid()
921
-    {
922
-        return $this->get_pretty('REG_paid');
923
-    }
924
-
925
-
926
-    /**
927
-     * owes_monies_and_can_pay
928
-     * whether or not this registration has monies owing and it's' status allows payment
929
-     *
930
-     * @param array $requires_payment
931
-     * @return bool
932
-     * @throws EE_Error
933
-     */
934
-    public function owes_monies_and_can_pay($requires_payment = array())
935
-    {
936
-        // these reg statuses require payment (if event is not free)
937
-        $requires_payment = ! empty($requires_payment)
938
-            ? $requires_payment
939
-            : EEM_Registration::reg_statuses_that_allow_payment();
940
-        if (in_array($this->status_ID(), $requires_payment) &&
941
-            $this->final_price() != 0 &&
942
-            $this->final_price() != $this->paid()
943
-        ) {
944
-            return true;
945
-        } else {
946
-            return false;
947
-        }
948
-    }
949
-
950
-
951
-    /**
952
-     * Prints out the return value of $this->pretty_status()
953
-     *
954
-     * @param bool $show_icons
955
-     * @return void
956
-     * @throws EE_Error
957
-     */
958
-    public function e_pretty_status($show_icons = false)
959
-    {
960
-        echo $this->pretty_status($show_icons);
961
-    }
962
-
963
-
964
-    /**
965
-     * Returns a nice version of the status for displaying to customers
966
-     *
967
-     * @param bool $show_icons
968
-     * @return string
969
-     * @throws EE_Error
970
-     */
971
-    public function pretty_status($show_icons = false)
972
-    {
973
-        $status = EEM_Status::instance()->localized_status(
974
-            array($this->status_ID() => esc_html__('unknown', 'event_espresso')),
975
-            false,
976
-            'sentence'
977
-        );
978
-        $icon   = '';
979
-        switch ($this->status_ID()) {
980
-            case EEM_Registration::status_id_approved:
981
-                $icon = $show_icons
982
-                    ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>'
983
-                    : '';
984
-                break;
985
-            case EEM_Registration::status_id_pending_payment:
986
-                $icon = $show_icons
987
-                    ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>'
988
-                    : '';
989
-                break;
990
-            case EEM_Registration::status_id_not_approved:
991
-                $icon = $show_icons
992
-                    ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>'
993
-                    : '';
994
-                break;
995
-            case EEM_Registration::status_id_cancelled:
996
-                $icon = $show_icons
997
-                    ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>'
998
-                    : '';
999
-                break;
1000
-            case EEM_Registration::status_id_incomplete:
1001
-                $icon = $show_icons
1002
-                    ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>'
1003
-                    : '';
1004
-                break;
1005
-            case EEM_Registration::status_id_declined:
1006
-                $icon = $show_icons
1007
-                    ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>'
1008
-                    : '';
1009
-                break;
1010
-            case EEM_Registration::status_id_wait_list:
1011
-                $icon = $show_icons
1012
-                    ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>'
1013
-                    : '';
1014
-                break;
1015
-        }
1016
-        return $icon . $status[$this->status_ID()];
1017
-    }
1018
-
1019
-
1020
-    /**
1021
-     *        get Attendee Is Going
1022
-     */
1023
-    public function att_is_going()
1024
-    {
1025
-        return $this->get('REG_att_is_going');
1026
-    }
1027
-
1028
-
1029
-    /**
1030
-     * Gets related answers
1031
-     *
1032
-     * @param array $query_params like EEM_Base::get_all
1033
-     * @return EE_Answer[]
1034
-     * @throws EE_Error
1035
-     */
1036
-    public function answers($query_params = null)
1037
-    {
1038
-        return $this->get_many_related('Answer', $query_params);
1039
-    }
1040
-
1041
-
1042
-    /**
1043
-     * Gets the registration's answer value to the specified question
1044
-     * (either the question's ID or a question object)
1045
-     *
1046
-     * @param EE_Question|int $question
1047
-     * @param bool            $pretty_value
1048
-     * @return array|string if pretty_value= true, the result will always be a string
1049
-     * (because the answer might be an array of answer values, so passing pretty_value=true
1050
-     * will convert it into some kind of string)
1051
-     * @throws EE_Error
1052
-     */
1053
-    public function answer_value_to_question($question, $pretty_value = true)
1054
-    {
1055
-        $question_id = EEM_Question::instance()->ensure_is_ID($question);
1056
-        return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value);
1057
-    }
1058
-
1059
-
1060
-    /**
1061
-     * question_groups
1062
-     * returns an array of EE_Question_Group objects for this registration
1063
-     *
1064
-     * @return EE_Question_Group[]
1065
-     * @throws EE_Error
1066
-     * @throws EntityNotFoundException
1067
-     */
1068
-    public function question_groups()
1069
-    {
1070
-        $question_groups = array();
1071
-        if ($this->event() instanceof EE_Event) {
1072
-            $question_groups = $this->event()->question_groups(
1073
-                array(
1074
-                    array(
1075
-                        'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false,
1076
-                    ),
1077
-                    'order_by' => array('QSG_order' => 'ASC'),
1078
-                )
1079
-            );
1080
-        }
1081
-        return $question_groups;
1082
-    }
1083
-
1084
-
1085
-    /**
1086
-     * count_question_groups
1087
-     * returns a count of the number of EE_Question_Group objects for this registration
1088
-     *
1089
-     * @return int
1090
-     * @throws EE_Error
1091
-     * @throws EntityNotFoundException
1092
-     */
1093
-    public function count_question_groups()
1094
-    {
1095
-        $qg_count = 0;
1096
-        if ($this->event() instanceof EE_Event) {
1097
-            $qg_count = $this->event()->count_related(
1098
-                'Question_Group',
1099
-                array(
1100
-                    array(
1101
-                        'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false,
1102
-                    ),
1103
-                )
1104
-            );
1105
-        }
1106
-        return $qg_count;
1107
-    }
1108
-
1109
-
1110
-    /**
1111
-     * Returns the registration date in the 'standard' string format
1112
-     * (function may be improved in the future to allow for different formats and timezones)
1113
-     *
1114
-     * @return string
1115
-     * @throws EE_Error
1116
-     */
1117
-    public function reg_date()
1118
-    {
1119
-        return $this->get_datetime('REG_date');
1120
-    }
1121
-
1122
-
1123
-    /**
1124
-     * Gets the datetime-ticket for this registration (ie, it can be used to isolate
1125
-     * the ticket this registration purchased, or the datetime they have registered
1126
-     * to attend)
1127
-     *
1128
-     * @return EE_Datetime_Ticket
1129
-     * @throws EE_Error
1130
-     */
1131
-    public function datetime_ticket()
1132
-    {
1133
-        return $this->get_first_related('Datetime_Ticket');
1134
-    }
1135
-
1136
-
1137
-    /**
1138
-     * Sets the registration's datetime_ticket.
1139
-     *
1140
-     * @param EE_Datetime_Ticket $datetime_ticket
1141
-     * @return EE_Datetime_Ticket
1142
-     * @throws EE_Error
1143
-     */
1144
-    public function set_datetime_ticket($datetime_ticket)
1145
-    {
1146
-        return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket');
1147
-    }
1148
-
1149
-    /**
1150
-     * Gets deleted
1151
-     *
1152
-     * @return bool
1153
-     * @throws EE_Error
1154
-     */
1155
-    public function deleted()
1156
-    {
1157
-        return $this->get('REG_deleted');
1158
-    }
1159
-
1160
-    /**
1161
-     * Sets deleted
1162
-     *
1163
-     * @param boolean $deleted
1164
-     * @return bool
1165
-     * @throws EE_Error
1166
-     * @throws RuntimeException
1167
-     */
1168
-    public function set_deleted($deleted)
1169
-    {
1170
-        if ($deleted) {
1171
-            $this->delete();
1172
-        } else {
1173
-            $this->restore();
1174
-        }
1175
-    }
1176
-
1177
-
1178
-    /**
1179
-     * Get the status object of this object
1180
-     *
1181
-     * @return EE_Status
1182
-     * @throws EE_Error
1183
-     */
1184
-    public function status_obj()
1185
-    {
1186
-        return $this->get_first_related('Status');
1187
-    }
1188
-
1189
-
1190
-    /**
1191
-     * Returns the number of times this registration has checked into any of the datetimes
1192
-     * its available for
1193
-     *
1194
-     * @return int
1195
-     * @throws EE_Error
1196
-     */
1197
-    public function count_checkins()
1198
-    {
1199
-        return $this->get_model()->count_related($this, 'Checkin');
1200
-    }
1201
-
1202
-
1203
-    /**
1204
-     * Returns the number of current Check-ins this registration is checked into for any of the datetimes the
1205
-     * registration is for.  Note, this is ONLY checked in (does not include checkedout)
1206
-     *
1207
-     * @return int
1208
-     * @throws EE_Error
1209
-     */
1210
-    public function count_checkins_not_checkedout()
1211
-    {
1212
-        return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1)));
1213
-    }
1214
-
1215
-
1216
-    /**
1217
-     * The purpose of this method is simply to check whether this registration can checkin to the given datetime.
1218
-     *
1219
-     * @param int | EE_Datetime $DTT_OR_ID      The datetime the registration is being checked against
1220
-     * @param bool              $check_approved This is used to indicate whether the caller wants can_checkin to also
1221
-     *                                          consider registration status as well as datetime access.
1222
-     * @return bool
1223
-     * @throws EE_Error
1224
-     */
1225
-    public function can_checkin($DTT_OR_ID, $check_approved = true)
1226
-    {
1227
-        $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1228
-
1229
-        //first check registration status
1230
-        if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) {
1231
-            return false;
1232
-        }
1233
-        //is there a datetime ticket that matches this dtt_ID?
1234
-        if (! (EEM_Datetime_Ticket::instance()->exists(array(
1235
-            array(
1236
-                'TKT_ID' => $this->get('TKT_ID'),
1237
-                'DTT_ID' => $DTT_ID,
1238
-            ),
1239
-        )))
1240
-        ) {
1241
-            return false;
1242
-        }
1243
-
1244
-        //final check is against TKT_uses
1245
-        return $this->verify_can_checkin_against_TKT_uses($DTT_ID);
1246
-    }
1247
-
1248
-
1249
-    /**
1250
-     * This method verifies whether the user can checkin for the given datetime considering the max uses value set on
1251
-     * the ticket. To do this,  a query is done to get the count of the datetime records already checked into.  If the
1252
-     * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses,
1253
-     * then return false.  Otherwise return true.
1254
-     *
1255
-     * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against
1256
-     * @return bool true means can checkin.  false means cannot checkin.
1257
-     * @throws EE_Error
1258
-     */
1259
-    public function verify_can_checkin_against_TKT_uses($DTT_OR_ID)
1260
-    {
1261
-        $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1262
-
1263
-        if (! $DTT_ID) {
1264
-            return false;
1265
-        }
1266
-
1267
-        $max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF;
1268
-
1269
-        // if max uses is not set or equals infinity then return true cause its not a factor for whether user can
1270
-        // check-in or not.
1271
-        if (! $max_uses || $max_uses === EE_INF) {
1272
-            return true;
1273
-        }
1274
-
1275
-        //does this datetime have a checkin record?  If so, then the dtt count has already been verified so we can just
1276
-        //go ahead and toggle.
1277
-        if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) {
1278
-            return true;
1279
-        }
1280
-
1281
-        //made it here so the last check is whether the number of checkins per unique datetime on this registration
1282
-        //disallows further check-ins.
1283
-        $count_unique_dtt_checkins = EEM_Checkin::instance()->count(array(
1284
-            array(
1285
-                'REG_ID' => $this->ID(),
1286
-                'CHK_in' => true,
1287
-            ),
1288
-        ), 'DTT_ID', true);
1289
-        // checkins have already reached their max number of uses
1290
-        // so registrant can NOT checkin
1291
-        if ($count_unique_dtt_checkins >= $max_uses) {
1292
-            EE_Error::add_error(
1293
-                esc_html__(
1294
-                    'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.',
1295
-                    'event_espresso'
1296
-                ),
1297
-                __FILE__,
1298
-                __FUNCTION__,
1299
-                __LINE__
1300
-            );
1301
-            return false;
1302
-        }
1303
-        return true;
1304
-    }
1305
-
1306
-
1307
-    /**
1308
-     * toggle Check-in status for this registration
1309
-     * Check-ins are toggled in the following order:
1310
-     * never checked in -> checked in
1311
-     * checked in -> checked out
1312
-     * checked out -> checked in
1313
-     *
1314
-     * @param  int $DTT_ID  include specific datetime to toggle Check-in for.
1315
-     *                      If not included or null, then it is assumed latest datetime is being toggled.
1316
-     * @param bool $verify  If true then can_checkin() is used to verify whether the person
1317
-     *                      can be checked in or not.  Otherwise this forces change in checkin status.
1318
-     * @return bool|int     the chk_in status toggled to OR false if nothing got changed.
1319
-     * @throws EE_Error
1320
-     */
1321
-    public function toggle_checkin_status($DTT_ID = null, $verify = false)
1322
-    {
1323
-        if (empty($DTT_ID)) {
1324
-            $datetime = $this->get_latest_related_datetime();
1325
-            $DTT_ID   = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
1326
-            // verify the registration can checkin for the given DTT_ID
1327
-        } elseif (! $this->can_checkin($DTT_ID, $verify)) {
1328
-            EE_Error::add_error(
1329
-                sprintf(
1330
-                    esc_html__(
1331
-                        'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access',
1332
-                        'event_espresso'
1333
-                    ),
1334
-                    $this->ID(),
1335
-                    $DTT_ID
1336
-                ),
1337
-                __FILE__,
1338
-                __FUNCTION__,
1339
-                __LINE__
1340
-            );
1341
-            return false;
1342
-        }
1343
-        $status_paths = array(
1344
-            EE_Checkin::status_checked_never => EE_Checkin::status_checked_in,
1345
-            EE_Checkin::status_checked_in    => EE_Checkin::status_checked_out,
1346
-            EE_Checkin::status_checked_out   => EE_Checkin::status_checked_in,
1347
-        );
1348
-        //start by getting the current status so we know what status we'll be changing to.
1349
-        $cur_status = $this->check_in_status_for_datetime($DTT_ID, null);
1350
-        $status_to  = $status_paths[$cur_status];
1351
-        // database only records true for checked IN or false for checked OUT
1352
-        // no record ( null ) means checked in NEVER, but we obviously don't save that
1353
-        $new_status = $status_to === EE_Checkin::status_checked_in ? true : false;
1354
-        // add relation - note Check-ins are always creating new rows
1355
-        // because we are keeping track of Check-ins over time.
1356
-        // Eventually we'll probably want to show a list table
1357
-        // for the individual Check-ins so that they can be managed.
1358
-        $checkin = EE_Checkin::new_instance(array(
1359
-            'REG_ID' => $this->ID(),
1360
-            'DTT_ID' => $DTT_ID,
1361
-            'CHK_in' => $new_status,
1362
-        ));
1363
-        // if the record could not be saved then return false
1364
-        if ($checkin->save() === 0) {
1365
-            if (WP_DEBUG) {
1366
-                global $wpdb;
1367
-                $error = sprintf(
1368
-                    esc_html__(
1369
-                        'Registration check in update failed because of the following database error: %1$s%2$s',
1370
-                        'event_espresso'
1371
-                    ),
1372
-                    '<br />',
1373
-                    $wpdb->last_error
1374
-                );
1375
-            } else {
1376
-                $error = esc_html__(
1377
-                    'Registration check in update failed because of an unknown database error',
1378
-                    'event_espresso'
1379
-                );
1380
-            }
1381
-            EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
1382
-            return false;
1383
-        }
1384
-        return $status_to;
1385
-    }
1386
-
1387
-
1388
-    /**
1389
-     * Returns the latest datetime related to this registration (via the ticket attached to the registration).
1390
-     * "Latest" is defined by the `DTT_EVT_start` column.
1391
-     *
1392
-     * @return EE_Datetime|null
1393
-     * @throws \EE_Error
1394
-     */
1395
-    public function get_latest_related_datetime()
1396
-    {
1397
-        return EEM_Datetime::instance()->get_one(
1398
-            array(
1399
-                array(
1400
-                    'Ticket.Registration.REG_ID' => $this->ID(),
1401
-                ),
1402
-                'order_by' => array('DTT_EVT_start' => 'DESC'),
1403
-            )
1404
-        );
1405
-    }
1406
-
1407
-
1408
-    /**
1409
-     * Returns the earliest datetime related to this registration (via the ticket attached to the registration).
1410
-     * "Earliest" is defined by the `DTT_EVT_start` column.
1411
-     *
1412
-     * @throws \EE_Error
1413
-     */
1414
-    public function get_earliest_related_datetime()
1415
-    {
1416
-        return EEM_Datetime::instance()->get_one(
1417
-            array(
1418
-                array(
1419
-                    'Ticket.Registration.REG_ID' => $this->ID(),
1420
-                ),
1421
-                'order_by' => array('DTT_EVT_start' => 'ASC'),
1422
-            )
1423
-        );
1424
-    }
1425
-
1426
-
1427
-    /**
1428
-     * This method simply returns the check-in status for this registration and the given datetime.
1429
-     * If neither the datetime nor the checkin values are provided as arguments,
1430
-     * then this will return the LATEST check-in status for the registration across all datetimes it belongs to.
1431
-     *
1432
-     * @param  int       $DTT_ID  The ID of the datetime we're checking against
1433
-     *                            (if empty we'll get the primary datetime for
1434
-     *                            this registration (via event) and use it's ID);
1435
-     * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id.
1436
-     * @return int                Integer representing Check-in status.
1437
-     * @throws \EE_Error
1438
-     */
1439
-    public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null)
1440
-    {
1441
-        $checkin_query_params = array(
1442
-            'order_by' => array('CHK_timestamp' => 'DESC'),
1443
-        );
1444
-
1445
-        if ($DTT_ID > 0) {
1446
-            $checkin_query_params[0] = array('DTT_ID' => $DTT_ID);
1447
-        }
1448
-
1449
-        //get checkin object (if exists)
1450
-        $checkin = $checkin instanceof EE_Checkin
1451
-            ? $checkin
1452
-            : $this->get_first_related('Checkin', $checkin_query_params);
1453
-        if ($checkin instanceof EE_Checkin) {
1454
-            if ($checkin->get('CHK_in')) {
1455
-                return EE_Checkin::status_checked_in; //checked in
1456
-            }
1457
-            return EE_Checkin::status_checked_out; //had checked in but is now checked out.
1458
-        }
1459
-        return EE_Checkin::status_checked_never; //never been checked in
1460
-    }
1461
-
1462
-
1463
-    /**
1464
-     * This method returns a localized message for the toggled Check-in message.
1465
-     *
1466
-     * @param  int $DTT_ID include specific datetime to get the correct Check-in message.  If not included or null,
1467
-     *                     then it is assumed Check-in for primary datetime was toggled.
1468
-     * @param bool $error  This just flags that you want an error message returned. This is put in so that the error
1469
-     *                     message can be customized with the attendee name.
1470
-     * @return string internationalized message
1471
-     * @throws EE_Error
1472
-     */
1473
-    public function get_checkin_msg($DTT_ID, $error = false)
1474
-    {
1475
-        //let's get the attendee first so we can include the name of the attendee
1476
-        $attendee = $this->get_first_related('Attendee');
1477
-        if ($attendee instanceof EE_Attendee) {
1478
-            if ($error) {
1479
-                return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name());
1480
-            }
1481
-            $cur_status = $this->check_in_status_for_datetime($DTT_ID);
1482
-            //what is the status message going to be?
1483
-            switch ($cur_status) {
1484
-                case EE_Checkin::status_checked_never:
1485
-                    return sprintf(__("%s has been removed from Check-in records", "event_espresso"),
1486
-                        $attendee->full_name());
1487
-                    break;
1488
-                case EE_Checkin::status_checked_in:
1489
-                    return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name());
1490
-                    break;
1491
-                case EE_Checkin::status_checked_out:
1492
-                    return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name());
1493
-                    break;
1494
-            }
1495
-        }
1496
-        return esc_html__("The check-in status could not be determined.", "event_espresso");
1497
-    }
1498
-
1499
-
1500
-    /**
1501
-     * Returns the related EE_Transaction to this registration
1502
-     *
1503
-     * @return EE_Transaction
1504
-     * @throws EE_Error
1505
-     * @throws EntityNotFoundException
1506
-     */
1507
-    public function transaction()
1508
-    {
1509
-        $transaction = $this->get_first_related('Transaction');
1510
-        if (! $transaction instanceof \EE_Transaction) {
1511
-            throw new EntityNotFoundException('Transaction ID', $this->transaction_ID());
1512
-        }
1513
-        return $transaction;
1514
-    }
1515
-
1516
-
1517
-    /**
1518
-     *        get Registration Code
1519
-     */
1520
-    public function reg_code()
1521
-    {
1522
-        return $this->get('REG_code');
1523
-    }
1524
-
1525
-
1526
-    /**
1527
-     *        get Transaction ID
1528
-     */
1529
-    public function transaction_ID()
1530
-    {
1531
-        return $this->get('TXN_ID');
1532
-    }
1533
-
1534
-
1535
-    /**
1536
-     * @return int
1537
-     * @throws EE_Error
1538
-     */
1539
-    public function ticket_ID()
1540
-    {
1541
-        return $this->get('TKT_ID');
1542
-    }
1543
-
1544
-
1545
-    /**
1546
-     *        Set Registration Code
1547
-     *
1548
-     * @access    public
1549
-     * @param    string  $REG_code Registration Code
1550
-     * @param    boolean $use_default
1551
-     * @throws EE_Error
1552
-     */
1553
-    public function set_reg_code($REG_code, $use_default = false)
1554
-    {
1555
-        if (empty($REG_code)) {
1556
-            EE_Error::add_error(
1557
-                esc_html__('REG_code can not be empty.', 'event_espresso'),
1558
-                __FILE__,
1559
-                __FUNCTION__,
1560
-                __LINE__
1561
-            );
1562
-            return;
1563
-        }
1564
-        if (! $this->reg_code()) {
1565
-            parent::set('REG_code', $REG_code, $use_default);
1566
-        } else {
1567
-            EE_Error::doing_it_wrong(
1568
-                __CLASS__ . '::' . __FUNCTION__,
1569
-                esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'),
1570
-                '4.6.0'
1571
-            );
1572
-        }
1573
-    }
1574
-
1575
-
1576
-    /**
1577
-     * Returns all other registrations in the same group as this registrant who have the same ticket option.
1578
-     * Note, if you want to just get all registrations in the same transaction (group), use:
1579
-     *    $registration->transaction()->registrations();
1580
-     *
1581
-     * @since 4.5.0
1582
-     * @return EE_Registration[] or empty array if this isn't a group registration.
1583
-     * @throws EE_Error
1584
-     */
1585
-    public function get_all_other_registrations_in_group()
1586
-    {
1587
-        if ($this->group_size() < 2) {
1588
-            return array();
1589
-        }
1590
-
1591
-        $query[0] = array(
1592
-            'TXN_ID' => $this->transaction_ID(),
1593
-            'REG_ID' => array('!=', $this->ID()),
1594
-            'TKT_ID' => $this->ticket_ID(),
1595
-        );
1596
-        /** @var EE_Registration[] $registrations */
1597
-        $registrations = $this->get_model()->get_all($query);
1598
-        return $registrations;
1599
-    }
1600
-
1601
-    /**
1602
-     * Return the link to the admin details for the object.
1603
-     *
1604
-     * @return string
1605
-     * @throws EE_Error
1606
-     */
1607
-    public function get_admin_details_link()
1608
-    {
1609
-        EE_Registry::instance()->load_helper('URL');
1610
-        return EEH_URL::add_query_args_and_nonce(
1611
-            array(
1612
-                'page'    => 'espresso_registrations',
1613
-                'action'  => 'view_registration',
1614
-                '_REG_ID' => $this->ID(),
1615
-            ),
1616
-            admin_url('admin.php')
1617
-        );
1618
-    }
1619
-
1620
-    /**
1621
-     * Returns the link to the editor for the object.  Sometimes this is the same as the details.
1622
-     *
1623
-     * @return string
1624
-     * @throws EE_Error
1625
-     */
1626
-    public function get_admin_edit_link()
1627
-    {
1628
-        return $this->get_admin_details_link();
1629
-    }
1630
-
1631
-    /**
1632
-     * Returns the link to a settings page for the object.
1633
-     *
1634
-     * @return string
1635
-     * @throws EE_Error
1636
-     */
1637
-    public function get_admin_settings_link()
1638
-    {
1639
-        return $this->get_admin_details_link();
1640
-    }
1641
-
1642
-    /**
1643
-     * Returns the link to the "overview" for the object (typically the "list table" view).
1644
-     *
1645
-     * @return string
1646
-     */
1647
-    public function get_admin_overview_link()
1648
-    {
1649
-        EE_Registry::instance()->load_helper('URL');
1650
-        return EEH_URL::add_query_args_and_nonce(
1651
-            array(
1652
-                'page' => 'espresso_registrations',
1653
-            ),
1654
-            admin_url('admin.php')
1655
-        );
1656
-    }
1657
-
1658
-
1659
-    /**
1660
-     * @param array $query_params
1661
-     * @return \EE_Registration[]
1662
-     * @throws \EE_Error
1663
-     */
1664
-    public function payments($query_params = array())
1665
-    {
1666
-        return $this->get_many_related('Payment', $query_params);
1667
-    }
1668
-
1669
-
1670
-    /**
1671
-     * @param array $query_params
1672
-     * @return \EE_Registration_Payment[]
1673
-     * @throws \EE_Error
1674
-     */
1675
-    public function registration_payments($query_params = array())
1676
-    {
1677
-        return $this->get_many_related('Registration_Payment', $query_params);
1678
-    }
1679
-
1680
-
1681
-    /**
1682
-     * This grabs the payment method corresponding to the last payment made for the amount owing on the registration.
1683
-     * Note: if there are no payments on the registration there will be no payment method returned.
1684
-     *
1685
-     * @return EE_Payment_Method|null
1686
-     */
1687
-    public function payment_method()
1688
-    {
1689
-        return EEM_Payment_Method::instance()->get_last_used_for_registration($this);
1690
-    }
1691
-
1692
-
1693
-    /**
1694
-     * @return \EE_Line_Item
1695
-     * @throws EntityNotFoundException
1696
-     * @throws \EE_Error
1697
-     */
1698
-    public function ticket_line_item()
1699
-    {
1700
-        $ticket            = $this->ticket();
1701
-        $transaction       = $this->transaction();
1702
-        $line_item         = null;
1703
-        $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs(
1704
-            $transaction->total_line_item(),
1705
-            'Ticket',
1706
-            array($ticket->ID())
1707
-        );
1708
-        foreach ($ticket_line_items as $ticket_line_item) {
1709
-            if (
1710
-                $ticket_line_item instanceof \EE_Line_Item
1711
-                && $ticket_line_item->OBJ_type() === 'Ticket'
1712
-                && $ticket_line_item->OBJ_ID() === $ticket->ID()
1713
-            ) {
1714
-                $line_item = $ticket_line_item;
1715
-                break;
1716
-            }
1717
-        }
1718
-        if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
1719
-            throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID());
1720
-        }
1721
-        return $line_item;
1722
-    }
1723
-
1724
-
1725
-    /**
1726
-     * Soft Deletes this model object.
1727
-     *
1728
-     * @return boolean | int
1729
-     * @throws \RuntimeException
1730
-     * @throws \EE_Error
1731
-     */
1732
-    public function delete()
1733
-    {
1734
-        if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) {
1735
-            $this->set_status(EEM_Registration::status_id_cancelled);
1736
-        }
1737
-        return parent::delete();
1738
-    }
1739
-
1740
-
1741
-    /**
1742
-     * Restores whatever the previous status was on a registration before it was trashed (if possible)
1743
-     *
1744
-     * @throws \EE_Error
1745
-     * @throws \RuntimeException
1746
-     */
1747
-    public function restore()
1748
-    {
1749
-        $previous_status = $this->get_extra_meta(
1750
-            EE_Registration::PRE_TRASH_REG_STATUS_KEY,
1751
-            true,
1752
-            EEM_Registration::status_id_cancelled
1753
-        );
1754
-        if ($previous_status) {
1755
-            $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY);
1756
-            $this->set_status($previous_status);
1757
-        }
1758
-        return parent::restore();
1759
-    }
1760
-
1761
-
1762
-
1763
-    /*************************** DEPRECATED ***************************/
1764
-
1765
-
1766
-    /**
1767
-     * @deprecated
1768
-     * @since     4.7.0
1769
-     * @access    public
1770
-     */
1771
-    public function price_paid()
1772
-    {
1773
-        EE_Error::doing_it_wrong('EE_Registration::price_paid()',
1774
-            esc_html__('This method is deprecated, please use EE_Registration::final_price() instead.', 'event_espresso'),
1775
-            '4.7.0');
1776
-        return $this->final_price();
1777
-    }
1778
-
1779
-
1780
-    /**
1781
-     * @deprecated
1782
-     * @since     4.7.0
1783
-     * @access    public
1784
-     * @param    float $REG_final_price
1785
-     * @throws EE_Error
1786
-     * @throws RuntimeException
1787
-     */
1788
-    public function set_price_paid($REG_final_price = 0.00)
1789
-    {
1790
-        EE_Error::doing_it_wrong('EE_Registration::set_price_paid()',
1791
-            esc_html__('This method is deprecated, please use EE_Registration::set_final_price() instead.', 'event_espresso'),
1792
-            '4.7.0');
1793
-        $this->set_final_price($REG_final_price);
1794
-    }
1795
-
1796
-
1797
-    /**
1798
-     * @deprecated
1799
-     * @since 4.7.0
1800
-     * @return string
1801
-     * @throws EE_Error
1802
-     */
1803
-    public function pretty_price_paid()
1804
-    {
1805
-        EE_Error::doing_it_wrong('EE_Registration::pretty_price_paid()',
1806
-            esc_html__('This method is deprecated, please use EE_Registration::pretty_final_price() instead.',
1807
-                'event_espresso'), '4.7.0');
1808
-        return $this->pretty_final_price();
1809
-    }
1810
-
1811
-
1812
-    /**
1813
-     * Gets the primary datetime related to this registration via the related Event to this registration
1814
-     *
1815
-     * @deprecated 4.9.17
1816
-     * @return EE_Datetime
1817
-     * @throws EE_Error
1818
-     * @throws EntityNotFoundException
1819
-     */
1820
-    public function get_related_primary_datetime()
1821
-    {
1822
-        EE_Error::doing_it_wrong(
1823
-            __METHOD__,
1824
-            esc_html__(
1825
-                'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()',
1826
-                'event_espresso'
1827
-            ),
1828
-            '4.9.17',
1829
-            '5.0.0'
1830
-        );
1831
-        return $this->event()->primary_datetime();
1832
-    }
18
+	/**
19
+	 * Used to reference when a registration has never been checked in.
20
+	 *
21
+	 * @deprecated use \EE_Checkin::status_checked_never instead
22
+	 * @type int
23
+	 */
24
+	const checkin_status_never = 2;
25
+
26
+	/**
27
+	 * Used to reference when a registration has been checked in.
28
+	 *
29
+	 * @deprecated use \EE_Checkin::status_checked_in instead
30
+	 * @type int
31
+	 */
32
+	const checkin_status_in = 1;
33
+
34
+
35
+	/**
36
+	 * Used to reference when a registration has been checked out.
37
+	 *
38
+	 * @deprecated use \EE_Checkin::status_checked_out instead
39
+	 * @type int
40
+	 */
41
+	const checkin_status_out = 0;
42
+
43
+
44
+	/**
45
+	 * extra meta key for tracking reg status os trashed registrations
46
+	 *
47
+	 * @type string
48
+	 */
49
+	const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status';
50
+
51
+
52
+	/**
53
+	 * extra meta key for tracking if registration has reserved ticket
54
+	 *
55
+	 * @type string
56
+	 */
57
+	const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket';
58
+
59
+
60
+	/**
61
+	 * @param array  $props_n_values          incoming values
62
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
63
+	 *                                        used.)
64
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
65
+	 *                                        date_format and the second value is the time format
66
+	 * @return EE_Registration
67
+	 * @throws EE_Error
68
+	 */
69
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
70
+	{
71
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
72
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
73
+	}
74
+
75
+
76
+	/**
77
+	 * @param array  $props_n_values  incoming values from the database
78
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
79
+	 *                                the website will be used.
80
+	 * @return EE_Registration
81
+	 */
82
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
83
+	{
84
+		return new self($props_n_values, true, $timezone);
85
+	}
86
+
87
+
88
+	/**
89
+	 *        Set Event ID
90
+	 *
91
+	 * @param        int $EVT_ID Event ID
92
+	 * @throws EE_Error
93
+	 * @throws RuntimeException
94
+	 */
95
+	public function set_event($EVT_ID = 0)
96
+	{
97
+		$this->set('EVT_ID', $EVT_ID);
98
+	}
99
+
100
+
101
+	/**
102
+	 * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can
103
+	 * be routed to internal methods
104
+	 *
105
+	 * @param string $field_name
106
+	 * @param mixed  $field_value
107
+	 * @param bool   $use_default
108
+	 * @throws \EE_Error
109
+	 * @throws \RuntimeException
110
+	 */
111
+	public function set($field_name, $field_value, $use_default = false)
112
+	{
113
+		switch ($field_name) {
114
+			case 'REG_code':
115
+				if (! empty($field_value) && $this->reg_code() === null) {
116
+					$this->set_reg_code($field_value, $use_default);
117
+				}
118
+				break;
119
+			case 'STS_ID':
120
+				$this->set_status($field_value, $use_default);
121
+				break;
122
+			default:
123
+				parent::set($field_name, $field_value, $use_default);
124
+		}
125
+	}
126
+
127
+
128
+	/**
129
+	 * Set Status ID
130
+	 * updates the registration status and ALSO...
131
+	 * calls reserve_registration_space() if the reg status changes TO approved from any other reg status
132
+	 * calls release_registration_space() if the reg status changes FROM approved to any other reg status
133
+	 *
134
+	 * @param string  $new_STS_ID
135
+	 * @param boolean $use_default
136
+	 * @return bool
137
+	 * @throws \RuntimeException
138
+	 * @throws \EE_Error
139
+	 */
140
+	public function set_status($new_STS_ID = null, $use_default = false)
141
+	{
142
+		// get current REG_Status
143
+		$old_STS_ID = $this->status_ID();
144
+		// if status has changed
145
+		if ($old_STS_ID !== $new_STS_ID // and that status has actually changed
146
+			&& ! empty($old_STS_ID) // and that old status is actually set
147
+			&& ! empty($new_STS_ID) // as well as the new status
148
+			&& $this->ID() // ensure registration is in the db
149
+		) {
150
+			// TO approved
151
+			if ($new_STS_ID === EEM_Registration::status_id_approved) {
152
+				// reserve a space by incrementing ticket and datetime sold values
153
+				$this->_reserve_registration_space();
154
+				do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID);
155
+				// OR FROM  approved
156
+			} elseif ($old_STS_ID === EEM_Registration::status_id_approved) {
157
+				// release a space by decrementing ticket and datetime sold values
158
+				$this->_release_registration_space();
159
+				do_action('AHEE__EE_Registration__set_status__from_approved', $this, $old_STS_ID, $new_STS_ID);
160
+			}
161
+			// update status
162
+			parent::set('STS_ID', $new_STS_ID, $use_default);
163
+			$this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID);
164
+			/** @type EE_Transaction_Payments $transaction_payments */
165
+			$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
166
+			$transaction_payments->recalculate_transaction_total($this->transaction(), false);
167
+			$this->transaction()->update_status_based_on_total_paid(true);
168
+			do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID);
169
+			return true;
170
+		}
171
+		//even though the old value matches the new value, it's still good to
172
+		//allow the parent set method to have a say
173
+		parent::set('STS_ID', $new_STS_ID, $use_default);
174
+		return true;
175
+	}
176
+
177
+
178
+	/**
179
+	 * update REGs and TXN when cancelled or declined registrations involved
180
+	 *
181
+	 * @param string $new_STS_ID
182
+	 * @param string $old_STS_ID
183
+	 * @throws \EE_Error
184
+	 */
185
+	private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID)
186
+	{
187
+		// these reg statuses should not be considered in any calculations involving monies owing
188
+		$closed_reg_statuses = EEM_Registration::closed_reg_statuses();
189
+		// true if registration has been cancelled or declined
190
+		if (in_array($new_STS_ID, $closed_reg_statuses, true)
191
+			&& ! in_array($old_STS_ID, $closed_reg_statuses, true)
192
+		) {
193
+			/** @type EE_Registration_Processor $registration_processor */
194
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
195
+			/** @type EE_Transaction_Processor $transaction_processor */
196
+			$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
197
+			// cancelled or declined registration
198
+			$registration_processor->update_registration_after_being_canceled_or_declined(
199
+				$this,
200
+				$closed_reg_statuses
201
+			);
202
+			$transaction_processor->update_transaction_after_canceled_or_declined_registration(
203
+				$this,
204
+				$closed_reg_statuses,
205
+				false
206
+			);
207
+			do_action('AHEE__EE_Registration__set_status__canceled_or_declined', $this, $old_STS_ID, $new_STS_ID);
208
+			return;
209
+		}
210
+		// true if reinstating cancelled or declined registration
211
+		if (in_array($old_STS_ID, $closed_reg_statuses, true)
212
+			&& ! in_array($new_STS_ID, $closed_reg_statuses, true)
213
+		) {
214
+			/** @type EE_Registration_Processor $registration_processor */
215
+			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
216
+			/** @type EE_Transaction_Processor $transaction_processor */
217
+			$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
218
+			// reinstating cancelled or declined registration
219
+			$registration_processor->update_canceled_or_declined_registration_after_being_reinstated(
220
+				$this,
221
+				$closed_reg_statuses
222
+			);
223
+			$transaction_processor->update_transaction_after_reinstating_canceled_registration(
224
+				$this,
225
+				$closed_reg_statuses,
226
+				false
227
+			);
228
+			do_action('AHEE__EE_Registration__set_status__after_reinstated', $this, $old_STS_ID, $new_STS_ID);
229
+		}
230
+	}
231
+
232
+
233
+	/**
234
+	 *        get Status ID
235
+	 */
236
+	public function status_ID()
237
+	{
238
+		return $this->get('STS_ID');
239
+	}
240
+
241
+
242
+	/**
243
+	 * increments this registration's related ticket sold and corresponding datetime sold values
244
+	 *
245
+	 * @return void
246
+	 * @throws EE_Error
247
+	 * @throws EntityNotFoundException
248
+	 */
249
+	private function _reserve_registration_space()
250
+	{
251
+		// reserved ticket and datetime counts will be decremented as sold counts are incremented
252
+		// so stop tracking that this reg has a ticket reserved
253
+		$this->release_reserved_ticket();
254
+		$ticket = $this->ticket();
255
+		$ticket->increase_sold();
256
+		$ticket->save();
257
+		// possibly set event status to sold out
258
+		$this->event()->perform_sold_out_status_check();
259
+	}
260
+
261
+
262
+	/**
263
+	 * Gets the ticket this registration is for
264
+	 *
265
+	 * @param boolean $include_archived whether to include archived tickets or not.
266
+	 * @return EE_Ticket|EE_Base_Class
267
+	 * @throws \EE_Error
268
+	 */
269
+	public function ticket($include_archived = true)
270
+	{
271
+		$query_params = array();
272
+		if ($include_archived) {
273
+			$query_params['default_where_conditions'] = 'none';
274
+		}
275
+		return $this->get_first_related('Ticket', $query_params);
276
+	}
277
+
278
+
279
+	/**
280
+	 * Gets the event this registration is for
281
+	 *
282
+	 * @return EE_Event
283
+	 * @throws EE_Error
284
+	 * @throws EntityNotFoundException
285
+	 */
286
+	public function event()
287
+	{
288
+		$event = $this->get_first_related('Event');
289
+		if (! $event instanceof \EE_Event) {
290
+			throw new EntityNotFoundException('Event ID', $this->event_ID());
291
+		}
292
+		return $event;
293
+	}
294
+
295
+
296
+	/**
297
+	 * Gets the "author" of the registration.  Note that for the purposes of registrations, the author will correspond
298
+	 * with the author of the event this registration is for.
299
+	 *
300
+	 * @since 4.5.0
301
+	 * @return int
302
+	 * @throws EE_Error
303
+	 * @throws EntityNotFoundException
304
+	 */
305
+	public function wp_user()
306
+	{
307
+		$event = $this->event();
308
+		if ($event instanceof EE_Event) {
309
+			return $event->wp_user();
310
+		}
311
+		return 0;
312
+	}
313
+
314
+
315
+	/**
316
+	 * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values
317
+	 *
318
+	 * @return void
319
+	 * @throws \EE_Error
320
+	 */
321
+	private function _release_registration_space()
322
+	{
323
+		$ticket = $this->ticket();
324
+		$ticket->decrease_sold();
325
+		$ticket->save();
326
+	}
327
+
328
+
329
+	/**
330
+	 * tracks this registration's ticket reservation in extra meta
331
+	 * and can increment related ticket reserved and corresponding datetime reserved values
332
+	 *
333
+	 * @param bool $update_ticket if true, will increment ticket and datetime reserved count
334
+	 * @return void
335
+	 * @throws \EE_Error
336
+	 */
337
+	public function reserve_ticket($update_ticket = false)
338
+	{
339
+		if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) === false) {
340
+			// PLZ NOTE: although checking $update_ticket first would be more efficient,
341
+			// we NEED to ALWAYS call update_extra_meta(), which is why that is done first
342
+			if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) && $update_ticket) {
343
+				$ticket = $this->ticket();
344
+				$ticket->increase_reserved();
345
+				$ticket->save();
346
+			}
347
+		}
348
+	}
349
+
350
+
351
+	/**
352
+	 * stops tracking this registration's ticket reservation in extra meta
353
+	 * decrements (subtracts) related ticket reserved and corresponding datetime reserved values
354
+	 *
355
+	 * @param bool $update_ticket if true, will decrement ticket and datetime reserved count
356
+	 * @return void
357
+	 * @throws \EE_Error
358
+	 */
359
+	public function release_reserved_ticket($update_ticket = false)
360
+	{
361
+		if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) !== false) {
362
+			// PLZ NOTE: although checking $update_ticket first would be more efficient,
363
+			// we NEED to ALWAYS call delete_extra_meta(), which is why that is done first
364
+			if ($this->delete_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY) && $update_ticket) {
365
+				$ticket = $this->ticket();
366
+				$ticket->decrease_reserved();
367
+				$ticket->save();
368
+			}
369
+		}
370
+	}
371
+
372
+
373
+	/**
374
+	 * Set Attendee ID
375
+	 *
376
+	 * @param        int $ATT_ID Attendee ID
377
+	 * @throws EE_Error
378
+	 * @throws RuntimeException
379
+	 */
380
+	public function set_attendee_id($ATT_ID = 0)
381
+	{
382
+		$this->set('ATT_ID', $ATT_ID);
383
+	}
384
+
385
+
386
+	/**
387
+	 *        Set Transaction ID
388
+	 *
389
+	 * @param        int $TXN_ID Transaction ID
390
+	 * @throws EE_Error
391
+	 * @throws RuntimeException
392
+	 */
393
+	public function set_transaction_id($TXN_ID = 0)
394
+	{
395
+		$this->set('TXN_ID', $TXN_ID);
396
+	}
397
+
398
+
399
+	/**
400
+	 *        Set Session
401
+	 *
402
+	 * @param    string $REG_session PHP Session ID
403
+	 * @throws EE_Error
404
+	 * @throws RuntimeException
405
+	 */
406
+	public function set_session($REG_session = '')
407
+	{
408
+		$this->set('REG_session', $REG_session);
409
+	}
410
+
411
+
412
+	/**
413
+	 *        Set Registration URL Link
414
+	 *
415
+	 * @param    string $REG_url_link Registration URL Link
416
+	 * @throws EE_Error
417
+	 * @throws RuntimeException
418
+	 */
419
+	public function set_reg_url_link($REG_url_link = '')
420
+	{
421
+		$this->set('REG_url_link', $REG_url_link);
422
+	}
423
+
424
+
425
+	/**
426
+	 *        Set Attendee Counter
427
+	 *
428
+	 * @param        int $REG_count Primary Attendee
429
+	 * @throws EE_Error
430
+	 * @throws RuntimeException
431
+	 */
432
+	public function set_count($REG_count = 1)
433
+	{
434
+		$this->set('REG_count', $REG_count);
435
+	}
436
+
437
+
438
+	/**
439
+	 *        Set Group Size
440
+	 *
441
+	 * @param        boolean $REG_group_size Group Registration
442
+	 * @throws EE_Error
443
+	 * @throws RuntimeException
444
+	 */
445
+	public function set_group_size($REG_group_size = false)
446
+	{
447
+		$this->set('REG_group_size', $REG_group_size);
448
+	}
449
+
450
+
451
+	/**
452
+	 *    is_not_approved -  convenience method that returns TRUE if REG status ID ==
453
+	 *    EEM_Registration::status_id_not_approved
454
+	 *
455
+	 * @return        boolean
456
+	 */
457
+	public function is_not_approved()
458
+	{
459
+		return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false;
460
+	}
461
+
462
+
463
+	/**
464
+	 *    is_pending_payment -  convenience method that returns TRUE if REG status ID ==
465
+	 *    EEM_Registration::status_id_pending_payment
466
+	 *
467
+	 * @return        boolean
468
+	 */
469
+	public function is_pending_payment()
470
+	{
471
+		return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false;
472
+	}
473
+
474
+
475
+	/**
476
+	 *    is_approved -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved
477
+	 *
478
+	 * @return        boolean
479
+	 */
480
+	public function is_approved()
481
+	{
482
+		return $this->status_ID() == EEM_Registration::status_id_approved ? true : false;
483
+	}
484
+
485
+
486
+	/**
487
+	 *    is_cancelled -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled
488
+	 *
489
+	 * @return        boolean
490
+	 */
491
+	public function is_cancelled()
492
+	{
493
+		return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false;
494
+	}
495
+
496
+
497
+	/**
498
+	 *    is_declined -  convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined
499
+	 *
500
+	 * @return        boolean
501
+	 */
502
+	public function is_declined()
503
+	{
504
+		return $this->status_ID() == EEM_Registration::status_id_declined ? true : false;
505
+	}
506
+
507
+
508
+	/**
509
+	 *    is_incomplete -  convenience method that returns TRUE if REG status ID ==
510
+	 *    EEM_Registration::status_id_incomplete
511
+	 *
512
+	 * @return        boolean
513
+	 */
514
+	public function is_incomplete()
515
+	{
516
+		return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false;
517
+	}
518
+
519
+
520
+	/**
521
+	 *        Set Registration Date
522
+	 *
523
+	 * @param        mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of
524
+	 *                                                 Date
525
+	 * @throws EE_Error
526
+	 * @throws RuntimeException
527
+	 */
528
+	public function set_reg_date($REG_date = false)
529
+	{
530
+		$this->set('REG_date', $REG_date);
531
+	}
532
+
533
+
534
+	/**
535
+	 *    Set final price owing for this registration after all ticket/price modifications
536
+	 *
537
+	 * @access    public
538
+	 * @param    float $REG_final_price
539
+	 * @throws EE_Error
540
+	 * @throws RuntimeException
541
+	 */
542
+	public function set_final_price($REG_final_price = 0.00)
543
+	{
544
+		$this->set('REG_final_price', $REG_final_price);
545
+	}
546
+
547
+
548
+	/**
549
+	 *    Set amount paid towards this registration's final price
550
+	 *
551
+	 * @access    public
552
+	 * @param    float $REG_paid
553
+	 * @throws EE_Error
554
+	 * @throws RuntimeException
555
+	 */
556
+	public function set_paid($REG_paid = 0.00)
557
+	{
558
+		$this->set('REG_paid', $REG_paid);
559
+	}
560
+
561
+
562
+	/**
563
+	 *        Attendee Is Going
564
+	 *
565
+	 * @param        boolean $REG_att_is_going Attendee Is Going
566
+	 * @throws EE_Error
567
+	 * @throws RuntimeException
568
+	 */
569
+	public function set_att_is_going($REG_att_is_going = false)
570
+	{
571
+		$this->set('REG_att_is_going', $REG_att_is_going);
572
+	}
573
+
574
+
575
+	/**
576
+	 * Gets the related attendee
577
+	 *
578
+	 * @return EE_Attendee
579
+	 * @throws EE_Error
580
+	 */
581
+	public function attendee()
582
+	{
583
+		return $this->get_first_related('Attendee');
584
+	}
585
+
586
+
587
+	/**
588
+	 *        get Event ID
589
+	 */
590
+	public function event_ID()
591
+	{
592
+		return $this->get('EVT_ID');
593
+	}
594
+
595
+
596
+	/**
597
+	 *        get Event ID
598
+	 */
599
+	public function event_name()
600
+	{
601
+		$event = $this->event_obj();
602
+		if ($event) {
603
+			return $event->name();
604
+		} else {
605
+			return null;
606
+		}
607
+	}
608
+
609
+
610
+	/**
611
+	 * Fetches the event this registration is for
612
+	 *
613
+	 * @return EE_Event
614
+	 * @throws EE_Error
615
+	 */
616
+	public function event_obj()
617
+	{
618
+		return $this->get_first_related('Event');
619
+	}
620
+
621
+
622
+	/**
623
+	 *        get Attendee ID
624
+	 */
625
+	public function attendee_ID()
626
+	{
627
+		return $this->get('ATT_ID');
628
+	}
629
+
630
+
631
+	/**
632
+	 *        get PHP Session ID
633
+	 */
634
+	public function session_ID()
635
+	{
636
+		return $this->get('REG_session');
637
+	}
638
+
639
+
640
+	/**
641
+	 * Gets the string which represents the URL trigger for the receipt template in the message template system.
642
+	 *
643
+	 * @param string $messenger 'pdf' or 'html'.  Default 'html'.
644
+	 * @return string
645
+	 */
646
+	public function receipt_url($messenger = 'html')
647
+	{
648
+
649
+		/**
650
+		 * The below will be deprecated one version after this.  We check first if there is a custom receipt template
651
+		 * already in use on old system.  If there is then we just return the standard url for it.
652
+		 *
653
+		 * @since 4.5.0
654
+		 */
655
+		$template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php';
656
+		$has_custom             = EEH_Template::locate_template(
657
+			$template_relative_path,
658
+			array(),
659
+			true,
660
+			true,
661
+			true
662
+		);
663
+
664
+		if ($has_custom) {
665
+			return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch'));
666
+		}
667
+		return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt');
668
+	}
669
+
670
+
671
+	/**
672
+	 * Gets the string which represents the URL trigger for the invoice template in the message template system.
673
+	 *
674
+	 * @param string $messenger 'pdf' or 'html'.  Default 'html'.
675
+	 * @return string
676
+	 * @throws EE_Error
677
+	 */
678
+	public function invoice_url($messenger = 'html')
679
+	{
680
+		/**
681
+		 * The below will be deprecated one version after this.  We check first if there is a custom invoice template
682
+		 * already in use on old system.  If there is then we just return the standard url for it.
683
+		 *
684
+		 * @since 4.5.0
685
+		 */
686
+		$template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php';
687
+		$has_custom             = EEH_Template::locate_template(
688
+			$template_relative_path,
689
+			array(),
690
+			true,
691
+			true,
692
+			true
693
+		);
694
+
695
+		if ($has_custom) {
696
+			if ($messenger == 'html') {
697
+				return $this->invoice_url('launch');
698
+			}
699
+			$route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice';
700
+
701
+			$query_args = array('ee' => $route, 'id' => $this->reg_url_link());
702
+			if ($messenger == 'html') {
703
+				$query_args['html'] = true;
704
+			}
705
+			return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id));
706
+		}
707
+		return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice');
708
+	}
709
+
710
+
711
+	/**
712
+	 * get Registration URL Link
713
+	 *
714
+	 * @access public
715
+	 * @return string
716
+	 * @throws \EE_Error
717
+	 */
718
+	public function reg_url_link()
719
+	{
720
+		return (string) $this->get('REG_url_link');
721
+	}
722
+
723
+
724
+	/**
725
+	 * Echoes out invoice_url()
726
+	 *
727
+	 * @param string $type 'download','launch', or 'html' (default is 'launch')
728
+	 * @return void
729
+	 * @throws EE_Error
730
+	 */
731
+	public function e_invoice_url($type = 'launch')
732
+	{
733
+		echo $this->invoice_url($type);
734
+	}
735
+
736
+
737
+	/**
738
+	 * Echoes out payment_overview_url
739
+	 */
740
+	public function e_payment_overview_url()
741
+	{
742
+		echo $this->payment_overview_url();
743
+	}
744
+
745
+
746
+	/**
747
+	 * Gets the URL of the thank you page with this registration REG_url_link added as
748
+	 * a query parameter
749
+	 *
750
+	 * @param bool $clear_session Set to true when you want to clear the session on revisiting the
751
+	 *                            payment overview url.
752
+	 * @return string
753
+	 * @throws EE_Error
754
+	 */
755
+	public function payment_overview_url($clear_session = false)
756
+	{
757
+		return add_query_arg(array(
758
+			'e_reg_url_link' => $this->reg_url_link(),
759
+			'step'           => 'payment_options',
760
+			'revisit'        => true,
761
+			'clear_session' => (bool) $clear_session
762
+		), EE_Registry::instance()->CFG->core->reg_page_url());
763
+	}
764
+
765
+
766
+	/**
767
+	 * Gets the URL of the thank you page with this registration REG_url_link added as
768
+	 * a query parameter
769
+	 *
770
+	 * @return string
771
+	 * @throws EE_Error
772
+	 */
773
+	public function edit_attendee_information_url()
774
+	{
775
+		return add_query_arg(array(
776
+			'e_reg_url_link' => $this->reg_url_link(),
777
+			'step'           => 'attendee_information',
778
+			'revisit'        => true,
779
+		), EE_Registry::instance()->CFG->core->reg_page_url());
780
+	}
781
+
782
+
783
+	/**
784
+	 * Simply generates and returns the appropriate admin_url link to edit this registration
785
+	 *
786
+	 * @return string
787
+	 * @throws EE_Error
788
+	 */
789
+	public function get_admin_edit_url()
790
+	{
791
+		return EEH_URL::add_query_args_and_nonce(array(
792
+			'page'    => 'espresso_registrations',
793
+			'action'  => 'view_registration',
794
+			'_REG_ID' => $this->ID(),
795
+		), admin_url('admin.php'));
796
+	}
797
+
798
+
799
+	/**
800
+	 *    is_primary_registrant?
801
+	 */
802
+	public function is_primary_registrant()
803
+	{
804
+		return $this->get('REG_count') == 1 ? true : false;
805
+	}
806
+
807
+
808
+	/**
809
+	 * This returns the primary registration object for this registration group (which may be this object).
810
+	 *
811
+	 * @return EE_Registration
812
+	 * @throws EE_Error
813
+	 */
814
+	public function get_primary_registration()
815
+	{
816
+		if ($this->is_primary_registrant()) {
817
+			return $this;
818
+		}
819
+
820
+		//k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1
821
+		/** @var EE_Registration $primary_registrant */
822
+		$primary_registrant = EEM_Registration::instance()->get_one(array(
823
+			array(
824
+				'TXN_ID'    => $this->transaction_ID(),
825
+				'REG_count' => 1,
826
+			),
827
+		));
828
+		return $primary_registrant;
829
+	}
830
+
831
+
832
+	/**
833
+	 *        get  Attendee Number
834
+	 *
835
+	 * @access        public
836
+	 */
837
+	public function count()
838
+	{
839
+		return $this->get('REG_count');
840
+	}
841
+
842
+
843
+	/**
844
+	 *        get Group Size
845
+	 */
846
+	public function group_size()
847
+	{
848
+		return $this->get('REG_group_size');
849
+	}
850
+
851
+
852
+	/**
853
+	 *        get Registration Date
854
+	 */
855
+	public function date()
856
+	{
857
+		return $this->get('REG_date');
858
+	}
859
+
860
+
861
+	/**
862
+	 * gets a pretty date
863
+	 *
864
+	 * @param string $date_format
865
+	 * @param string $time_format
866
+	 * @return string
867
+	 * @throws EE_Error
868
+	 */
869
+	public function pretty_date($date_format = null, $time_format = null)
870
+	{
871
+		return $this->get_datetime('REG_date', $date_format, $time_format);
872
+	}
873
+
874
+
875
+	/**
876
+	 * final_price
877
+	 * the registration's share of the transaction total, so that the
878
+	 * sum of all the transaction's REG_final_prices equal the transaction's total
879
+	 *
880
+	 * @return float
881
+	 * @throws EE_Error
882
+	 */
883
+	public function final_price()
884
+	{
885
+		return $this->get('REG_final_price');
886
+	}
887
+
888
+
889
+	/**
890
+	 * pretty_final_price
891
+	 *  final price as formatted string, with correct decimal places and currency symbol
892
+	 *
893
+	 * @return string
894
+	 * @throws EE_Error
895
+	 */
896
+	public function pretty_final_price()
897
+	{
898
+		return $this->get_pretty('REG_final_price');
899
+	}
900
+
901
+
902
+	/**
903
+	 * get paid (yeah)
904
+	 *
905
+	 * @return float
906
+	 * @throws EE_Error
907
+	 */
908
+	public function paid()
909
+	{
910
+		return $this->get('REG_paid');
911
+	}
912
+
913
+
914
+	/**
915
+	 * pretty_paid
916
+	 *
917
+	 * @return float
918
+	 * @throws EE_Error
919
+	 */
920
+	public function pretty_paid()
921
+	{
922
+		return $this->get_pretty('REG_paid');
923
+	}
924
+
925
+
926
+	/**
927
+	 * owes_monies_and_can_pay
928
+	 * whether or not this registration has monies owing and it's' status allows payment
929
+	 *
930
+	 * @param array $requires_payment
931
+	 * @return bool
932
+	 * @throws EE_Error
933
+	 */
934
+	public function owes_monies_and_can_pay($requires_payment = array())
935
+	{
936
+		// these reg statuses require payment (if event is not free)
937
+		$requires_payment = ! empty($requires_payment)
938
+			? $requires_payment
939
+			: EEM_Registration::reg_statuses_that_allow_payment();
940
+		if (in_array($this->status_ID(), $requires_payment) &&
941
+			$this->final_price() != 0 &&
942
+			$this->final_price() != $this->paid()
943
+		) {
944
+			return true;
945
+		} else {
946
+			return false;
947
+		}
948
+	}
949
+
950
+
951
+	/**
952
+	 * Prints out the return value of $this->pretty_status()
953
+	 *
954
+	 * @param bool $show_icons
955
+	 * @return void
956
+	 * @throws EE_Error
957
+	 */
958
+	public function e_pretty_status($show_icons = false)
959
+	{
960
+		echo $this->pretty_status($show_icons);
961
+	}
962
+
963
+
964
+	/**
965
+	 * Returns a nice version of the status for displaying to customers
966
+	 *
967
+	 * @param bool $show_icons
968
+	 * @return string
969
+	 * @throws EE_Error
970
+	 */
971
+	public function pretty_status($show_icons = false)
972
+	{
973
+		$status = EEM_Status::instance()->localized_status(
974
+			array($this->status_ID() => esc_html__('unknown', 'event_espresso')),
975
+			false,
976
+			'sentence'
977
+		);
978
+		$icon   = '';
979
+		switch ($this->status_ID()) {
980
+			case EEM_Registration::status_id_approved:
981
+				$icon = $show_icons
982
+					? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>'
983
+					: '';
984
+				break;
985
+			case EEM_Registration::status_id_pending_payment:
986
+				$icon = $show_icons
987
+					? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>'
988
+					: '';
989
+				break;
990
+			case EEM_Registration::status_id_not_approved:
991
+				$icon = $show_icons
992
+					? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>'
993
+					: '';
994
+				break;
995
+			case EEM_Registration::status_id_cancelled:
996
+				$icon = $show_icons
997
+					? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>'
998
+					: '';
999
+				break;
1000
+			case EEM_Registration::status_id_incomplete:
1001
+				$icon = $show_icons
1002
+					? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>'
1003
+					: '';
1004
+				break;
1005
+			case EEM_Registration::status_id_declined:
1006
+				$icon = $show_icons
1007
+					? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>'
1008
+					: '';
1009
+				break;
1010
+			case EEM_Registration::status_id_wait_list:
1011
+				$icon = $show_icons
1012
+					? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>'
1013
+					: '';
1014
+				break;
1015
+		}
1016
+		return $icon . $status[$this->status_ID()];
1017
+	}
1018
+
1019
+
1020
+	/**
1021
+	 *        get Attendee Is Going
1022
+	 */
1023
+	public function att_is_going()
1024
+	{
1025
+		return $this->get('REG_att_is_going');
1026
+	}
1027
+
1028
+
1029
+	/**
1030
+	 * Gets related answers
1031
+	 *
1032
+	 * @param array $query_params like EEM_Base::get_all
1033
+	 * @return EE_Answer[]
1034
+	 * @throws EE_Error
1035
+	 */
1036
+	public function answers($query_params = null)
1037
+	{
1038
+		return $this->get_many_related('Answer', $query_params);
1039
+	}
1040
+
1041
+
1042
+	/**
1043
+	 * Gets the registration's answer value to the specified question
1044
+	 * (either the question's ID or a question object)
1045
+	 *
1046
+	 * @param EE_Question|int $question
1047
+	 * @param bool            $pretty_value
1048
+	 * @return array|string if pretty_value= true, the result will always be a string
1049
+	 * (because the answer might be an array of answer values, so passing pretty_value=true
1050
+	 * will convert it into some kind of string)
1051
+	 * @throws EE_Error
1052
+	 */
1053
+	public function answer_value_to_question($question, $pretty_value = true)
1054
+	{
1055
+		$question_id = EEM_Question::instance()->ensure_is_ID($question);
1056
+		return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value);
1057
+	}
1058
+
1059
+
1060
+	/**
1061
+	 * question_groups
1062
+	 * returns an array of EE_Question_Group objects for this registration
1063
+	 *
1064
+	 * @return EE_Question_Group[]
1065
+	 * @throws EE_Error
1066
+	 * @throws EntityNotFoundException
1067
+	 */
1068
+	public function question_groups()
1069
+	{
1070
+		$question_groups = array();
1071
+		if ($this->event() instanceof EE_Event) {
1072
+			$question_groups = $this->event()->question_groups(
1073
+				array(
1074
+					array(
1075
+						'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false,
1076
+					),
1077
+					'order_by' => array('QSG_order' => 'ASC'),
1078
+				)
1079
+			);
1080
+		}
1081
+		return $question_groups;
1082
+	}
1083
+
1084
+
1085
+	/**
1086
+	 * count_question_groups
1087
+	 * returns a count of the number of EE_Question_Group objects for this registration
1088
+	 *
1089
+	 * @return int
1090
+	 * @throws EE_Error
1091
+	 * @throws EntityNotFoundException
1092
+	 */
1093
+	public function count_question_groups()
1094
+	{
1095
+		$qg_count = 0;
1096
+		if ($this->event() instanceof EE_Event) {
1097
+			$qg_count = $this->event()->count_related(
1098
+				'Question_Group',
1099
+				array(
1100
+					array(
1101
+						'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false,
1102
+					),
1103
+				)
1104
+			);
1105
+		}
1106
+		return $qg_count;
1107
+	}
1108
+
1109
+
1110
+	/**
1111
+	 * Returns the registration date in the 'standard' string format
1112
+	 * (function may be improved in the future to allow for different formats and timezones)
1113
+	 *
1114
+	 * @return string
1115
+	 * @throws EE_Error
1116
+	 */
1117
+	public function reg_date()
1118
+	{
1119
+		return $this->get_datetime('REG_date');
1120
+	}
1121
+
1122
+
1123
+	/**
1124
+	 * Gets the datetime-ticket for this registration (ie, it can be used to isolate
1125
+	 * the ticket this registration purchased, or the datetime they have registered
1126
+	 * to attend)
1127
+	 *
1128
+	 * @return EE_Datetime_Ticket
1129
+	 * @throws EE_Error
1130
+	 */
1131
+	public function datetime_ticket()
1132
+	{
1133
+		return $this->get_first_related('Datetime_Ticket');
1134
+	}
1135
+
1136
+
1137
+	/**
1138
+	 * Sets the registration's datetime_ticket.
1139
+	 *
1140
+	 * @param EE_Datetime_Ticket $datetime_ticket
1141
+	 * @return EE_Datetime_Ticket
1142
+	 * @throws EE_Error
1143
+	 */
1144
+	public function set_datetime_ticket($datetime_ticket)
1145
+	{
1146
+		return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket');
1147
+	}
1148
+
1149
+	/**
1150
+	 * Gets deleted
1151
+	 *
1152
+	 * @return bool
1153
+	 * @throws EE_Error
1154
+	 */
1155
+	public function deleted()
1156
+	{
1157
+		return $this->get('REG_deleted');
1158
+	}
1159
+
1160
+	/**
1161
+	 * Sets deleted
1162
+	 *
1163
+	 * @param boolean $deleted
1164
+	 * @return bool
1165
+	 * @throws EE_Error
1166
+	 * @throws RuntimeException
1167
+	 */
1168
+	public function set_deleted($deleted)
1169
+	{
1170
+		if ($deleted) {
1171
+			$this->delete();
1172
+		} else {
1173
+			$this->restore();
1174
+		}
1175
+	}
1176
+
1177
+
1178
+	/**
1179
+	 * Get the status object of this object
1180
+	 *
1181
+	 * @return EE_Status
1182
+	 * @throws EE_Error
1183
+	 */
1184
+	public function status_obj()
1185
+	{
1186
+		return $this->get_first_related('Status');
1187
+	}
1188
+
1189
+
1190
+	/**
1191
+	 * Returns the number of times this registration has checked into any of the datetimes
1192
+	 * its available for
1193
+	 *
1194
+	 * @return int
1195
+	 * @throws EE_Error
1196
+	 */
1197
+	public function count_checkins()
1198
+	{
1199
+		return $this->get_model()->count_related($this, 'Checkin');
1200
+	}
1201
+
1202
+
1203
+	/**
1204
+	 * Returns the number of current Check-ins this registration is checked into for any of the datetimes the
1205
+	 * registration is for.  Note, this is ONLY checked in (does not include checkedout)
1206
+	 *
1207
+	 * @return int
1208
+	 * @throws EE_Error
1209
+	 */
1210
+	public function count_checkins_not_checkedout()
1211
+	{
1212
+		return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1)));
1213
+	}
1214
+
1215
+
1216
+	/**
1217
+	 * The purpose of this method is simply to check whether this registration can checkin to the given datetime.
1218
+	 *
1219
+	 * @param int | EE_Datetime $DTT_OR_ID      The datetime the registration is being checked against
1220
+	 * @param bool              $check_approved This is used to indicate whether the caller wants can_checkin to also
1221
+	 *                                          consider registration status as well as datetime access.
1222
+	 * @return bool
1223
+	 * @throws EE_Error
1224
+	 */
1225
+	public function can_checkin($DTT_OR_ID, $check_approved = true)
1226
+	{
1227
+		$DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1228
+
1229
+		//first check registration status
1230
+		if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) {
1231
+			return false;
1232
+		}
1233
+		//is there a datetime ticket that matches this dtt_ID?
1234
+		if (! (EEM_Datetime_Ticket::instance()->exists(array(
1235
+			array(
1236
+				'TKT_ID' => $this->get('TKT_ID'),
1237
+				'DTT_ID' => $DTT_ID,
1238
+			),
1239
+		)))
1240
+		) {
1241
+			return false;
1242
+		}
1243
+
1244
+		//final check is against TKT_uses
1245
+		return $this->verify_can_checkin_against_TKT_uses($DTT_ID);
1246
+	}
1247
+
1248
+
1249
+	/**
1250
+	 * This method verifies whether the user can checkin for the given datetime considering the max uses value set on
1251
+	 * the ticket. To do this,  a query is done to get the count of the datetime records already checked into.  If the
1252
+	 * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses,
1253
+	 * then return false.  Otherwise return true.
1254
+	 *
1255
+	 * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against
1256
+	 * @return bool true means can checkin.  false means cannot checkin.
1257
+	 * @throws EE_Error
1258
+	 */
1259
+	public function verify_can_checkin_against_TKT_uses($DTT_OR_ID)
1260
+	{
1261
+		$DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID);
1262
+
1263
+		if (! $DTT_ID) {
1264
+			return false;
1265
+		}
1266
+
1267
+		$max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF;
1268
+
1269
+		// if max uses is not set or equals infinity then return true cause its not a factor for whether user can
1270
+		// check-in or not.
1271
+		if (! $max_uses || $max_uses === EE_INF) {
1272
+			return true;
1273
+		}
1274
+
1275
+		//does this datetime have a checkin record?  If so, then the dtt count has already been verified so we can just
1276
+		//go ahead and toggle.
1277
+		if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) {
1278
+			return true;
1279
+		}
1280
+
1281
+		//made it here so the last check is whether the number of checkins per unique datetime on this registration
1282
+		//disallows further check-ins.
1283
+		$count_unique_dtt_checkins = EEM_Checkin::instance()->count(array(
1284
+			array(
1285
+				'REG_ID' => $this->ID(),
1286
+				'CHK_in' => true,
1287
+			),
1288
+		), 'DTT_ID', true);
1289
+		// checkins have already reached their max number of uses
1290
+		// so registrant can NOT checkin
1291
+		if ($count_unique_dtt_checkins >= $max_uses) {
1292
+			EE_Error::add_error(
1293
+				esc_html__(
1294
+					'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.',
1295
+					'event_espresso'
1296
+				),
1297
+				__FILE__,
1298
+				__FUNCTION__,
1299
+				__LINE__
1300
+			);
1301
+			return false;
1302
+		}
1303
+		return true;
1304
+	}
1305
+
1306
+
1307
+	/**
1308
+	 * toggle Check-in status for this registration
1309
+	 * Check-ins are toggled in the following order:
1310
+	 * never checked in -> checked in
1311
+	 * checked in -> checked out
1312
+	 * checked out -> checked in
1313
+	 *
1314
+	 * @param  int $DTT_ID  include specific datetime to toggle Check-in for.
1315
+	 *                      If not included or null, then it is assumed latest datetime is being toggled.
1316
+	 * @param bool $verify  If true then can_checkin() is used to verify whether the person
1317
+	 *                      can be checked in or not.  Otherwise this forces change in checkin status.
1318
+	 * @return bool|int     the chk_in status toggled to OR false if nothing got changed.
1319
+	 * @throws EE_Error
1320
+	 */
1321
+	public function toggle_checkin_status($DTT_ID = null, $verify = false)
1322
+	{
1323
+		if (empty($DTT_ID)) {
1324
+			$datetime = $this->get_latest_related_datetime();
1325
+			$DTT_ID   = $datetime instanceof EE_Datetime ? $datetime->ID() : 0;
1326
+			// verify the registration can checkin for the given DTT_ID
1327
+		} elseif (! $this->can_checkin($DTT_ID, $verify)) {
1328
+			EE_Error::add_error(
1329
+				sprintf(
1330
+					esc_html__(
1331
+						'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access',
1332
+						'event_espresso'
1333
+					),
1334
+					$this->ID(),
1335
+					$DTT_ID
1336
+				),
1337
+				__FILE__,
1338
+				__FUNCTION__,
1339
+				__LINE__
1340
+			);
1341
+			return false;
1342
+		}
1343
+		$status_paths = array(
1344
+			EE_Checkin::status_checked_never => EE_Checkin::status_checked_in,
1345
+			EE_Checkin::status_checked_in    => EE_Checkin::status_checked_out,
1346
+			EE_Checkin::status_checked_out   => EE_Checkin::status_checked_in,
1347
+		);
1348
+		//start by getting the current status so we know what status we'll be changing to.
1349
+		$cur_status = $this->check_in_status_for_datetime($DTT_ID, null);
1350
+		$status_to  = $status_paths[$cur_status];
1351
+		// database only records true for checked IN or false for checked OUT
1352
+		// no record ( null ) means checked in NEVER, but we obviously don't save that
1353
+		$new_status = $status_to === EE_Checkin::status_checked_in ? true : false;
1354
+		// add relation - note Check-ins are always creating new rows
1355
+		// because we are keeping track of Check-ins over time.
1356
+		// Eventually we'll probably want to show a list table
1357
+		// for the individual Check-ins so that they can be managed.
1358
+		$checkin = EE_Checkin::new_instance(array(
1359
+			'REG_ID' => $this->ID(),
1360
+			'DTT_ID' => $DTT_ID,
1361
+			'CHK_in' => $new_status,
1362
+		));
1363
+		// if the record could not be saved then return false
1364
+		if ($checkin->save() === 0) {
1365
+			if (WP_DEBUG) {
1366
+				global $wpdb;
1367
+				$error = sprintf(
1368
+					esc_html__(
1369
+						'Registration check in update failed because of the following database error: %1$s%2$s',
1370
+						'event_espresso'
1371
+					),
1372
+					'<br />',
1373
+					$wpdb->last_error
1374
+				);
1375
+			} else {
1376
+				$error = esc_html__(
1377
+					'Registration check in update failed because of an unknown database error',
1378
+					'event_espresso'
1379
+				);
1380
+			}
1381
+			EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
1382
+			return false;
1383
+		}
1384
+		return $status_to;
1385
+	}
1386
+
1387
+
1388
+	/**
1389
+	 * Returns the latest datetime related to this registration (via the ticket attached to the registration).
1390
+	 * "Latest" is defined by the `DTT_EVT_start` column.
1391
+	 *
1392
+	 * @return EE_Datetime|null
1393
+	 * @throws \EE_Error
1394
+	 */
1395
+	public function get_latest_related_datetime()
1396
+	{
1397
+		return EEM_Datetime::instance()->get_one(
1398
+			array(
1399
+				array(
1400
+					'Ticket.Registration.REG_ID' => $this->ID(),
1401
+				),
1402
+				'order_by' => array('DTT_EVT_start' => 'DESC'),
1403
+			)
1404
+		);
1405
+	}
1406
+
1407
+
1408
+	/**
1409
+	 * Returns the earliest datetime related to this registration (via the ticket attached to the registration).
1410
+	 * "Earliest" is defined by the `DTT_EVT_start` column.
1411
+	 *
1412
+	 * @throws \EE_Error
1413
+	 */
1414
+	public function get_earliest_related_datetime()
1415
+	{
1416
+		return EEM_Datetime::instance()->get_one(
1417
+			array(
1418
+				array(
1419
+					'Ticket.Registration.REG_ID' => $this->ID(),
1420
+				),
1421
+				'order_by' => array('DTT_EVT_start' => 'ASC'),
1422
+			)
1423
+		);
1424
+	}
1425
+
1426
+
1427
+	/**
1428
+	 * This method simply returns the check-in status for this registration and the given datetime.
1429
+	 * If neither the datetime nor the checkin values are provided as arguments,
1430
+	 * then this will return the LATEST check-in status for the registration across all datetimes it belongs to.
1431
+	 *
1432
+	 * @param  int       $DTT_ID  The ID of the datetime we're checking against
1433
+	 *                            (if empty we'll get the primary datetime for
1434
+	 *                            this registration (via event) and use it's ID);
1435
+	 * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id.
1436
+	 * @return int                Integer representing Check-in status.
1437
+	 * @throws \EE_Error
1438
+	 */
1439
+	public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null)
1440
+	{
1441
+		$checkin_query_params = array(
1442
+			'order_by' => array('CHK_timestamp' => 'DESC'),
1443
+		);
1444
+
1445
+		if ($DTT_ID > 0) {
1446
+			$checkin_query_params[0] = array('DTT_ID' => $DTT_ID);
1447
+		}
1448
+
1449
+		//get checkin object (if exists)
1450
+		$checkin = $checkin instanceof EE_Checkin
1451
+			? $checkin
1452
+			: $this->get_first_related('Checkin', $checkin_query_params);
1453
+		if ($checkin instanceof EE_Checkin) {
1454
+			if ($checkin->get('CHK_in')) {
1455
+				return EE_Checkin::status_checked_in; //checked in
1456
+			}
1457
+			return EE_Checkin::status_checked_out; //had checked in but is now checked out.
1458
+		}
1459
+		return EE_Checkin::status_checked_never; //never been checked in
1460
+	}
1461
+
1462
+
1463
+	/**
1464
+	 * This method returns a localized message for the toggled Check-in message.
1465
+	 *
1466
+	 * @param  int $DTT_ID include specific datetime to get the correct Check-in message.  If not included or null,
1467
+	 *                     then it is assumed Check-in for primary datetime was toggled.
1468
+	 * @param bool $error  This just flags that you want an error message returned. This is put in so that the error
1469
+	 *                     message can be customized with the attendee name.
1470
+	 * @return string internationalized message
1471
+	 * @throws EE_Error
1472
+	 */
1473
+	public function get_checkin_msg($DTT_ID, $error = false)
1474
+	{
1475
+		//let's get the attendee first so we can include the name of the attendee
1476
+		$attendee = $this->get_first_related('Attendee');
1477
+		if ($attendee instanceof EE_Attendee) {
1478
+			if ($error) {
1479
+				return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name());
1480
+			}
1481
+			$cur_status = $this->check_in_status_for_datetime($DTT_ID);
1482
+			//what is the status message going to be?
1483
+			switch ($cur_status) {
1484
+				case EE_Checkin::status_checked_never:
1485
+					return sprintf(__("%s has been removed from Check-in records", "event_espresso"),
1486
+						$attendee->full_name());
1487
+					break;
1488
+				case EE_Checkin::status_checked_in:
1489
+					return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name());
1490
+					break;
1491
+				case EE_Checkin::status_checked_out:
1492
+					return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name());
1493
+					break;
1494
+			}
1495
+		}
1496
+		return esc_html__("The check-in status could not be determined.", "event_espresso");
1497
+	}
1498
+
1499
+
1500
+	/**
1501
+	 * Returns the related EE_Transaction to this registration
1502
+	 *
1503
+	 * @return EE_Transaction
1504
+	 * @throws EE_Error
1505
+	 * @throws EntityNotFoundException
1506
+	 */
1507
+	public function transaction()
1508
+	{
1509
+		$transaction = $this->get_first_related('Transaction');
1510
+		if (! $transaction instanceof \EE_Transaction) {
1511
+			throw new EntityNotFoundException('Transaction ID', $this->transaction_ID());
1512
+		}
1513
+		return $transaction;
1514
+	}
1515
+
1516
+
1517
+	/**
1518
+	 *        get Registration Code
1519
+	 */
1520
+	public function reg_code()
1521
+	{
1522
+		return $this->get('REG_code');
1523
+	}
1524
+
1525
+
1526
+	/**
1527
+	 *        get Transaction ID
1528
+	 */
1529
+	public function transaction_ID()
1530
+	{
1531
+		return $this->get('TXN_ID');
1532
+	}
1533
+
1534
+
1535
+	/**
1536
+	 * @return int
1537
+	 * @throws EE_Error
1538
+	 */
1539
+	public function ticket_ID()
1540
+	{
1541
+		return $this->get('TKT_ID');
1542
+	}
1543
+
1544
+
1545
+	/**
1546
+	 *        Set Registration Code
1547
+	 *
1548
+	 * @access    public
1549
+	 * @param    string  $REG_code Registration Code
1550
+	 * @param    boolean $use_default
1551
+	 * @throws EE_Error
1552
+	 */
1553
+	public function set_reg_code($REG_code, $use_default = false)
1554
+	{
1555
+		if (empty($REG_code)) {
1556
+			EE_Error::add_error(
1557
+				esc_html__('REG_code can not be empty.', 'event_espresso'),
1558
+				__FILE__,
1559
+				__FUNCTION__,
1560
+				__LINE__
1561
+			);
1562
+			return;
1563
+		}
1564
+		if (! $this->reg_code()) {
1565
+			parent::set('REG_code', $REG_code, $use_default);
1566
+		} else {
1567
+			EE_Error::doing_it_wrong(
1568
+				__CLASS__ . '::' . __FUNCTION__,
1569
+				esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'),
1570
+				'4.6.0'
1571
+			);
1572
+		}
1573
+	}
1574
+
1575
+
1576
+	/**
1577
+	 * Returns all other registrations in the same group as this registrant who have the same ticket option.
1578
+	 * Note, if you want to just get all registrations in the same transaction (group), use:
1579
+	 *    $registration->transaction()->registrations();
1580
+	 *
1581
+	 * @since 4.5.0
1582
+	 * @return EE_Registration[] or empty array if this isn't a group registration.
1583
+	 * @throws EE_Error
1584
+	 */
1585
+	public function get_all_other_registrations_in_group()
1586
+	{
1587
+		if ($this->group_size() < 2) {
1588
+			return array();
1589
+		}
1590
+
1591
+		$query[0] = array(
1592
+			'TXN_ID' => $this->transaction_ID(),
1593
+			'REG_ID' => array('!=', $this->ID()),
1594
+			'TKT_ID' => $this->ticket_ID(),
1595
+		);
1596
+		/** @var EE_Registration[] $registrations */
1597
+		$registrations = $this->get_model()->get_all($query);
1598
+		return $registrations;
1599
+	}
1600
+
1601
+	/**
1602
+	 * Return the link to the admin details for the object.
1603
+	 *
1604
+	 * @return string
1605
+	 * @throws EE_Error
1606
+	 */
1607
+	public function get_admin_details_link()
1608
+	{
1609
+		EE_Registry::instance()->load_helper('URL');
1610
+		return EEH_URL::add_query_args_and_nonce(
1611
+			array(
1612
+				'page'    => 'espresso_registrations',
1613
+				'action'  => 'view_registration',
1614
+				'_REG_ID' => $this->ID(),
1615
+			),
1616
+			admin_url('admin.php')
1617
+		);
1618
+	}
1619
+
1620
+	/**
1621
+	 * Returns the link to the editor for the object.  Sometimes this is the same as the details.
1622
+	 *
1623
+	 * @return string
1624
+	 * @throws EE_Error
1625
+	 */
1626
+	public function get_admin_edit_link()
1627
+	{
1628
+		return $this->get_admin_details_link();
1629
+	}
1630
+
1631
+	/**
1632
+	 * Returns the link to a settings page for the object.
1633
+	 *
1634
+	 * @return string
1635
+	 * @throws EE_Error
1636
+	 */
1637
+	public function get_admin_settings_link()
1638
+	{
1639
+		return $this->get_admin_details_link();
1640
+	}
1641
+
1642
+	/**
1643
+	 * Returns the link to the "overview" for the object (typically the "list table" view).
1644
+	 *
1645
+	 * @return string
1646
+	 */
1647
+	public function get_admin_overview_link()
1648
+	{
1649
+		EE_Registry::instance()->load_helper('URL');
1650
+		return EEH_URL::add_query_args_and_nonce(
1651
+			array(
1652
+				'page' => 'espresso_registrations',
1653
+			),
1654
+			admin_url('admin.php')
1655
+		);
1656
+	}
1657
+
1658
+
1659
+	/**
1660
+	 * @param array $query_params
1661
+	 * @return \EE_Registration[]
1662
+	 * @throws \EE_Error
1663
+	 */
1664
+	public function payments($query_params = array())
1665
+	{
1666
+		return $this->get_many_related('Payment', $query_params);
1667
+	}
1668
+
1669
+
1670
+	/**
1671
+	 * @param array $query_params
1672
+	 * @return \EE_Registration_Payment[]
1673
+	 * @throws \EE_Error
1674
+	 */
1675
+	public function registration_payments($query_params = array())
1676
+	{
1677
+		return $this->get_many_related('Registration_Payment', $query_params);
1678
+	}
1679
+
1680
+
1681
+	/**
1682
+	 * This grabs the payment method corresponding to the last payment made for the amount owing on the registration.
1683
+	 * Note: if there are no payments on the registration there will be no payment method returned.
1684
+	 *
1685
+	 * @return EE_Payment_Method|null
1686
+	 */
1687
+	public function payment_method()
1688
+	{
1689
+		return EEM_Payment_Method::instance()->get_last_used_for_registration($this);
1690
+	}
1691
+
1692
+
1693
+	/**
1694
+	 * @return \EE_Line_Item
1695
+	 * @throws EntityNotFoundException
1696
+	 * @throws \EE_Error
1697
+	 */
1698
+	public function ticket_line_item()
1699
+	{
1700
+		$ticket            = $this->ticket();
1701
+		$transaction       = $this->transaction();
1702
+		$line_item         = null;
1703
+		$ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs(
1704
+			$transaction->total_line_item(),
1705
+			'Ticket',
1706
+			array($ticket->ID())
1707
+		);
1708
+		foreach ($ticket_line_items as $ticket_line_item) {
1709
+			if (
1710
+				$ticket_line_item instanceof \EE_Line_Item
1711
+				&& $ticket_line_item->OBJ_type() === 'Ticket'
1712
+				&& $ticket_line_item->OBJ_ID() === $ticket->ID()
1713
+			) {
1714
+				$line_item = $ticket_line_item;
1715
+				break;
1716
+			}
1717
+		}
1718
+		if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) {
1719
+			throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID());
1720
+		}
1721
+		return $line_item;
1722
+	}
1723
+
1724
+
1725
+	/**
1726
+	 * Soft Deletes this model object.
1727
+	 *
1728
+	 * @return boolean | int
1729
+	 * @throws \RuntimeException
1730
+	 * @throws \EE_Error
1731
+	 */
1732
+	public function delete()
1733
+	{
1734
+		if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) {
1735
+			$this->set_status(EEM_Registration::status_id_cancelled);
1736
+		}
1737
+		return parent::delete();
1738
+	}
1739
+
1740
+
1741
+	/**
1742
+	 * Restores whatever the previous status was on a registration before it was trashed (if possible)
1743
+	 *
1744
+	 * @throws \EE_Error
1745
+	 * @throws \RuntimeException
1746
+	 */
1747
+	public function restore()
1748
+	{
1749
+		$previous_status = $this->get_extra_meta(
1750
+			EE_Registration::PRE_TRASH_REG_STATUS_KEY,
1751
+			true,
1752
+			EEM_Registration::status_id_cancelled
1753
+		);
1754
+		if ($previous_status) {
1755
+			$this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY);
1756
+			$this->set_status($previous_status);
1757
+		}
1758
+		return parent::restore();
1759
+	}
1760
+
1761
+
1762
+
1763
+	/*************************** DEPRECATED ***************************/
1764
+
1765
+
1766
+	/**
1767
+	 * @deprecated
1768
+	 * @since     4.7.0
1769
+	 * @access    public
1770
+	 */
1771
+	public function price_paid()
1772
+	{
1773
+		EE_Error::doing_it_wrong('EE_Registration::price_paid()',
1774
+			esc_html__('This method is deprecated, please use EE_Registration::final_price() instead.', 'event_espresso'),
1775
+			'4.7.0');
1776
+		return $this->final_price();
1777
+	}
1778
+
1779
+
1780
+	/**
1781
+	 * @deprecated
1782
+	 * @since     4.7.0
1783
+	 * @access    public
1784
+	 * @param    float $REG_final_price
1785
+	 * @throws EE_Error
1786
+	 * @throws RuntimeException
1787
+	 */
1788
+	public function set_price_paid($REG_final_price = 0.00)
1789
+	{
1790
+		EE_Error::doing_it_wrong('EE_Registration::set_price_paid()',
1791
+			esc_html__('This method is deprecated, please use EE_Registration::set_final_price() instead.', 'event_espresso'),
1792
+			'4.7.0');
1793
+		$this->set_final_price($REG_final_price);
1794
+	}
1795
+
1796
+
1797
+	/**
1798
+	 * @deprecated
1799
+	 * @since 4.7.0
1800
+	 * @return string
1801
+	 * @throws EE_Error
1802
+	 */
1803
+	public function pretty_price_paid()
1804
+	{
1805
+		EE_Error::doing_it_wrong('EE_Registration::pretty_price_paid()',
1806
+			esc_html__('This method is deprecated, please use EE_Registration::pretty_final_price() instead.',
1807
+				'event_espresso'), '4.7.0');
1808
+		return $this->pretty_final_price();
1809
+	}
1810
+
1811
+
1812
+	/**
1813
+	 * Gets the primary datetime related to this registration via the related Event to this registration
1814
+	 *
1815
+	 * @deprecated 4.9.17
1816
+	 * @return EE_Datetime
1817
+	 * @throws EE_Error
1818
+	 * @throws EntityNotFoundException
1819
+	 */
1820
+	public function get_related_primary_datetime()
1821
+	{
1822
+		EE_Error::doing_it_wrong(
1823
+			__METHOD__,
1824
+			esc_html__(
1825
+				'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()',
1826
+				'event_espresso'
1827
+			),
1828
+			'4.9.17',
1829
+			'5.0.0'
1830
+		);
1831
+		return $this->event()->primary_datetime();
1832
+	}
1833 1833
 
1834 1834
 
1835 1835
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/calculations/Registration.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  * @since                 $VID:$
18 18
  */
19 19
 if (! defined('EVENT_ESPRESSO_VERSION')) {
20
-    exit('No direct script access allowed');
20
+	exit('No direct script access allowed');
21 21
 }
22 22
 
23 23
 
@@ -25,62 +25,62 @@  discard block
 block discarded – undo
25 25
 class Registration extends Calculations_Base
26 26
 {
27 27
 
28
-    /**
29
-     * Calculates the checkin status for each datetime this registration has access to
30
-     *
31
-     * @param array            $wpdb_row
32
-     * @param \WP_REST_Request $request
33
-     * @param Base             $controller
34
-     * @return array
35
-     * @throws \EE_Error
36
-     */
37
-    public static function datetimeCheckinStati($wpdb_row, $request, $controller)
38
-    {
39
-        if (is_array($wpdb_row) && isset($wpdb_row['Registration.REG_ID'])) {
40
-            $reg = EEM_Registration::instance()->get_one_by_ID($wpdb_row['Registration.REG_ID']);
41
-        } else {
42
-            $reg = null;
43
-        }
44
-        if (! $reg instanceof EE_Registration
45
-        ) {
46
-            throw new \EE_Error(
47
-                sprintf(
48
-                    __(
49
-                        // @codingStandardsIgnoreStart
50
-                        'Cannot calculate datetime_checkin_stati because the registration with ID %1$s (from database row %2$s) was not found',
51
-                        // @codingStandardsIgnoreEnd
52
-                        'event_espresso'
53
-                    ),
54
-                    $wpdb_row['Registration.REG_ID'],
55
-                    print_r($wpdb_row, true)
56
-                )
57
-            );
58
-        }
59
-        $datetime_ids = EEM_Datetime::instance()->get_col(
60
-            array(
61
-                array(
62
-                    'Ticket.TKT_ID' => $reg->ticket_ID(),
63
-                ),
64
-                'default_where_conditions' => \EEM_Base::default_where_conditions_minimum_all
65
-            )
66
-        );
67
-        $checkin_stati = array();
68
-        foreach ($datetime_ids as $datetime_id) {
69
-            $status = $reg->check_in_status_for_datetime($datetime_id);
70
-            switch ($status) {
71
-                case EE_Checkin::status_checked_out:
72
-                    $status_pretty = 'OUT';
73
-                    break;
74
-                case EE_Checkin::status_checked_in:
75
-                    $status_pretty = 'IN';
76
-                    break;
77
-                case EE_Checkin::status_checked_never:
78
-                default:
79
-                    $status_pretty = 'NEVER';
80
-                    break;
81
-            }
82
-            $checkin_stati[$datetime_id] = $status_pretty;
83
-        }
84
-        return $checkin_stati;
85
-    }
28
+	/**
29
+	 * Calculates the checkin status for each datetime this registration has access to
30
+	 *
31
+	 * @param array            $wpdb_row
32
+	 * @param \WP_REST_Request $request
33
+	 * @param Base             $controller
34
+	 * @return array
35
+	 * @throws \EE_Error
36
+	 */
37
+	public static function datetimeCheckinStati($wpdb_row, $request, $controller)
38
+	{
39
+		if (is_array($wpdb_row) && isset($wpdb_row['Registration.REG_ID'])) {
40
+			$reg = EEM_Registration::instance()->get_one_by_ID($wpdb_row['Registration.REG_ID']);
41
+		} else {
42
+			$reg = null;
43
+		}
44
+		if (! $reg instanceof EE_Registration
45
+		) {
46
+			throw new \EE_Error(
47
+				sprintf(
48
+					__(
49
+						// @codingStandardsIgnoreStart
50
+						'Cannot calculate datetime_checkin_stati because the registration with ID %1$s (from database row %2$s) was not found',
51
+						// @codingStandardsIgnoreEnd
52
+						'event_espresso'
53
+					),
54
+					$wpdb_row['Registration.REG_ID'],
55
+					print_r($wpdb_row, true)
56
+				)
57
+			);
58
+		}
59
+		$datetime_ids = EEM_Datetime::instance()->get_col(
60
+			array(
61
+				array(
62
+					'Ticket.TKT_ID' => $reg->ticket_ID(),
63
+				),
64
+				'default_where_conditions' => \EEM_Base::default_where_conditions_minimum_all
65
+			)
66
+		);
67
+		$checkin_stati = array();
68
+		foreach ($datetime_ids as $datetime_id) {
69
+			$status = $reg->check_in_status_for_datetime($datetime_id);
70
+			switch ($status) {
71
+				case EE_Checkin::status_checked_out:
72
+					$status_pretty = 'OUT';
73
+					break;
74
+				case EE_Checkin::status_checked_in:
75
+					$status_pretty = 'IN';
76
+					break;
77
+				case EE_Checkin::status_checked_never:
78
+				default:
79
+					$status_pretty = 'NEVER';
80
+					break;
81
+			}
82
+			$checkin_stati[$datetime_id] = $status_pretty;
83
+		}
84
+		return $checkin_stati;
85
+	}
86 86
 }
Please login to merge, or discard this patch.
admin/extend/registrations/Extend_Registrations_Admin_Page.core.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -863,7 +863,7 @@
 block discarded – undo
863 863
      * handles toggling the checkin status for the registration,
864 864
      *
865 865
      * @access protected
866
-     * @return int|void
866
+     * @return integer
867 867
      */
868 868
     protected function _toggle_checkin_status()
869 869
     {
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -38,9 +38,9 @@  discard block
 block discarded – undo
38 38
     {
39 39
         parent::__construct($routing);
40 40
         if ( ! defined('REG_CAF_TEMPLATE_PATH')) {
41
-            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
42
-            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
43
-            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
41
+            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'registrations/templates/');
42
+            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'registrations/assets/');
43
+            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registrations/assets/');
44 44
         }
45 45
     }
46 46
 
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 
49 49
     protected function _extend_page_config()
50 50
     {
51
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
51
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'registrations';
52 52
         $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
53 53
             ? $this->_req_data['_REG_ID']
54 54
             : 0;
@@ -181,14 +181,14 @@  discard block
 block discarded – undo
181 181
             //enqueue newsletter js
182 182
             wp_enqueue_script(
183 183
                 'ee-newsletter-trigger',
184
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
184
+                REG_CAF_ASSETS_URL.'ee-newsletter-trigger.js',
185 185
                 array('ee-dialog'),
186 186
                 EVENT_ESPRESSO_VERSION,
187 187
                 true
188 188
             );
189 189
             wp_enqueue_style(
190 190
                 'ee-newsletter-trigger-css',
191
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
191
+                REG_CAF_ASSETS_URL.'ee-newsletter-trigger.css',
192 192
                 array(),
193 193
                 EVENT_ESPRESSO_VERSION
194 194
             );
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
     {
208 208
         wp_register_script(
209 209
             'ee-reg-reports-js',
210
-            REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
210
+            REG_CAF_ASSETS_URL.'ee-registration-admin-reports.js',
211 211
             array('google-charts'),
212 212
             EVENT_ESPRESSO_VERSION,
213 213
             true
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
             $codes[$field] = implode(', ', array_keys($shortcode_array));
413 413
         }
414 414
         $shortcodes = $codes;
415
-        $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
415
+        $form_template = REG_CAF_TEMPLATE_PATH.'newsletter-send-form.template.php';
416 416
         $form_template_args = array(
417 417
             'form_action'       => admin_url('admin.php?page=espresso_registrations'),
418 418
             'form_route'        => 'newsletter_selected_send',
@@ -573,7 +573,7 @@  discard block
 block discarded – undo
573 573
      */
574 574
     protected function _registration_reports()
575 575
     {
576
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
576
+        $template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php';
577 577
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
578 578
             $template_path,
579 579
             $this->_reports_template_data,
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
     {
596 596
         $report_ID = 'reg-admin-registrations-per-day-report-dv';
597 597
         $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
598
-        $results = (array)$results;
598
+        $results = (array) $results;
599 599
         $regs = array();
600 600
         $subtitle = '';
601 601
         if ($results) {
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
                 $report_column_values = array();
606 606
                 foreach ($result as $property_name => $property_value) {
607 607
                     $property_value = $property_name === 'Registration_REG_date' ? $property_value
608
-                        : (int)$property_value;
608
+                        : (int) $property_value;
609 609
                     $report_column_values[] = $property_value;
610 610
                     if ($tracker === 0) {
611 611
                         if ($property_name === 'Registration_REG_date') {
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
             array_unshift($regs, $column_titles);
623 623
             //setup the date range.
624 624
             $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
625
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
625
+            $beginning_date = new DateTime("now ".$period, $DateTimeZone);
626 626
             $ending_date = new DateTime("now", $DateTimeZone);
627 627
             $subtitle = sprintf(
628 628
                 _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
                     '%sThere are currently no registration records in the last month for this report.%s',
643 643
                     'event_espresso'
644 644
                 ),
645
-                '<h2>' . $report_title . '</h2><p>',
645
+                '<h2>'.$report_title.'</h2><p>',
646 646
                 '</p>'
647 647
             ),
648 648
         );
@@ -662,7 +662,7 @@  discard block
 block discarded – undo
662 662
     {
663 663
         $report_ID = 'reg-admin-registrations-per-event-report-dv';
664 664
         $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
665
-        $results = (array)$results;
665
+        $results = (array) $results;
666 666
         $regs = array();
667 667
         $subtitle = '';
668 668
         if ($results) {
@@ -675,7 +675,7 @@  discard block
 block discarded – undo
675 675
                         $property_value,
676 676
                         4,
677 677
                         '...'
678
-                    ) : (int)$property_value;
678
+                    ) : (int) $property_value;
679 679
                     $report_column_values[] = $property_value;
680 680
                     if ($tracker === 0) {
681 681
                         if ($property_name === 'Registration_Event') {
@@ -692,7 +692,7 @@  discard block
 block discarded – undo
692 692
             array_unshift($regs, $column_titles);
693 693
             //setup the date range.
694 694
             $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
695
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
695
+            $beginning_date = new DateTime("now ".$period, $DateTimeZone);
696 696
             $ending_date = new DateTime("now", $DateTimeZone);
697 697
             $subtitle = sprintf(
698 698
                 _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
@@ -712,7 +712,7 @@  discard block
 block discarded – undo
712 712
                     '%sThere are currently no registration records in the last month for this report.%s',
713 713
                     'event_espresso'
714 714
                 ),
715
-                '<h2>' . $report_title . '</h2><p>',
715
+                '<h2>'.$report_title.'</h2><p>',
716 716
                 '</p>'
717 717
             ),
718 718
         );
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
         if ($datetime instanceof EE_Datetime) {
763 763
             $datetime_label = $datetime->get_dtt_display_name(true);
764 764
             $datetime_label .= ! empty($datetime_label)
765
-                ? ' (' . $datetime->get_dtt_display_name() . ')'
765
+                ? ' ('.$datetime->get_dtt_display_name().')'
766 766
                 : $datetime->get_dtt_display_name();
767 767
         }
768 768
         $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
@@ -776,7 +776,7 @@  discard block
 block discarded – undo
776 776
             )
777 777
             : '';
778 778
         $datetime_link = ! empty($datetime_link)
779
-            ? '<a href="' . $datetime_link . '">'
779
+            ? '<a href="'.$datetime_link.'">'
780 780
               . '<span id="checkin-dtt">'
781 781
               . $datetime_label
782 782
               . '</span></a>'
@@ -788,8 +788,8 @@  discard block
 block discarded – undo
788 788
             ? $attendee->get_admin_details_link()
789 789
             : '';
790 790
         $attendee_link = ! empty($attendee_link)
791
-            ? '<a href="' . $attendee->get_admin_details_link() . '"'
792
-              . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
791
+            ? '<a href="'.$attendee->get_admin_details_link().'"'
792
+              . ' title="'.esc_html__('Click for attendee details', 'event_espresso').'">'
793 793
               . '<span id="checkin-attendee-name">'
794 794
               . $attendee_name
795 795
               . '</span></a>'
@@ -798,25 +798,25 @@  discard block
 block discarded – undo
798 798
             ? $registration->event()->get_admin_details_link()
799 799
             : '';
800 800
         $event_link = ! empty($event_link)
801
-            ? '<a href="' . $event_link . '"'
802
-              . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
801
+            ? '<a href="'.$event_link.'"'
802
+              . ' title="'.esc_html__('Click here to edit event.', 'event_espresso').'">'
803 803
               . '<span id="checkin-event-name">'
804 804
               . $registration->event_name()
805 805
               . '</span>'
806 806
               . '</a>'
807 807
             : '';
808 808
         $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
809
-            ? '<h2>' . sprintf(
809
+            ? '<h2>'.sprintf(
810 810
                 esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
811 811
                 $attendee_link,
812 812
                 $datetime_link,
813 813
                 $event_link
814
-            ) . '</h2>'
814
+            ).'</h2>'
815 815
             : '';
816 816
         $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
817
-            ? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : '';
817
+            ? '<input type="hidden" name="_REGID" value="'.$reg_id.'">' : '';
818 818
         $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
819
-            ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
819
+            ? '<input type="hidden" name="DTT_ID" value="'.$dtt_id.'">' : '';
820 820
         $this->display_admin_list_table_page_with_no_sidebar();
821 821
     }
822 822
 
@@ -852,7 +852,7 @@  discard block
 block discarded – undo
852 852
         //beautiful! Made it this far so let's get the status.
853 853
         $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status());
854 854
         //setup new class to return via ajax
855
-        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses();
855
+        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin '.$new_status->cssClasses();
856 856
         $this->_template_args['success'] = true;
857 857
         $this->_return_json();
858 858
     }
@@ -1059,37 +1059,37 @@  discard block
 block discarded – undo
1059 1059
                 'desc'  => __('View All Check-in Records for this Registrant', 'event_espresso'),
1060 1060
             ),
1061 1061
             'approved_status'  => array(
1062
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1062
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
1063 1063
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1064 1064
             ),
1065 1065
             'cancelled_status' => array(
1066
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1066
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
1067 1067
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1068 1068
             ),
1069 1069
             'declined_status'  => array(
1070
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1070
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
1071 1071
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1072 1072
             ),
1073 1073
             'not_approved'     => array(
1074
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1074
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
1075 1075
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1076 1076
             ),
1077 1077
             'pending_status'   => array(
1078
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1078
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
1079 1079
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1080 1080
             ),
1081 1081
             'wait_list'        => array(
1082
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1082
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
1083 1083
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1084 1084
             ),
1085 1085
         );
1086 1086
         $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1087 1087
         $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1088 1088
         $this->_template_args['before_list_table'] = ! empty($event_id)
1089
-            ? '<h2>' . sprintf(
1089
+            ? '<h2>'.sprintf(
1090 1090
                 __('Viewing Registrations for Event: %s', 'event_espresso'),
1091 1091
                 EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1092
-            ) . '</h2>'
1092
+            ).'</h2>'
1093 1093
             : '';
1094 1094
         //need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on the event.
1095 1095
         /** @var EE_Event $event */
@@ -1108,7 +1108,7 @@  discard block
 block discarded – undo
1108 1108
             $this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1109 1109
             $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1110 1110
             $this->_template_args['before_list_table'] .= $datetime->name();
1111
-            $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1111
+            $this->_template_args['before_list_table'] .= ' ( '.$datetime->date_and_time_range().' )';
1112 1112
             $this->_template_args['before_list_table'] .= '</span></h2>';
1113 1113
         }
1114 1114
         //if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status column
@@ -1175,11 +1175,11 @@  discard block
 block discarded – undo
1175 1175
         //normalize some request params that get setup by the parent `get_registrations` method.
1176 1176
         $request = $this->_req_data;
1177 1177
         $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1178
-        $request['order'] =  ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1179
-        if($trash){
1178
+        $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1179
+        if ($trash) {
1180 1180
             $request['status'] = 'trash';
1181 1181
         }
1182
-        $query_params = $this->_get_checkin_query_params_from_request( $request, $per_page, $count );
1182
+        $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count);
1183 1183
         /**
1184 1184
          * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1185 1185
          * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
Please login to merge, or discard this patch.
Indentation   +1177 added lines, -1177 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\ui\browser\checkins\entities\CheckinStatusDashicon;
4 4
 
5 5
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
6
-    exit('NO direct script access allowed');
6
+	exit('NO direct script access allowed');
7 7
 }
8 8
 
9 9
 
@@ -20,1182 +20,1182 @@  discard block
 block discarded – undo
20 20
 {
21 21
 
22 22
 
23
-    /**
24
-     * This is used to hold the reports template data which is setup early in the request.
25
-     *
26
-     * @type array
27
-     */
28
-    protected $_reports_template_data = array();
29
-
30
-
31
-
32
-    /**
33
-     * Extend_Registrations_Admin_Page constructor.
34
-     *
35
-     * @param bool $routing
36
-     */
37
-    public function __construct($routing = true)
38
-    {
39
-        parent::__construct($routing);
40
-        if ( ! defined('REG_CAF_TEMPLATE_PATH')) {
41
-            define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
42
-            define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
43
-            define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
44
-        }
45
-    }
46
-
47
-
48
-
49
-    protected function _extend_page_config()
50
-    {
51
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
52
-        $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
53
-            ? $this->_req_data['_REG_ID']
54
-            : 0;
55
-        // $att_id = ! empty( $this->_req_data['ATT_ID'] ) ? ! is_array( $this->_req_data['ATT_ID'] ) : 0;
56
-        // $att_id = ! empty( $this->_req_data['post'] ) && ! is_array( $this->_req_data['post'] )
57
-        // 	? $this->_req_data['post'] : $att_id;
58
-        $new_page_routes = array(
59
-            'reports'                  => array(
60
-                'func'       => '_registration_reports',
61
-                'capability' => 'ee_read_registrations',
62
-            ),
63
-            'registration_checkins'    => array(
64
-                'func'       => '_registration_checkin_list_table',
65
-                'capability' => 'ee_read_checkins',
66
-            ),
67
-            'newsletter_selected_send' => array(
68
-                'func'       => '_newsletter_selected_send',
69
-                'noheader'   => true,
70
-                'capability' => 'ee_send_message',
71
-            ),
72
-            'delete_checkin_rows'      => array(
73
-                'func'       => '_delete_checkin_rows',
74
-                'noheader'   => true,
75
-                'capability' => 'ee_delete_checkins',
76
-            ),
77
-            'delete_checkin_row'       => array(
78
-                'func'       => '_delete_checkin_row',
79
-                'noheader'   => true,
80
-                'capability' => 'ee_delete_checkin',
81
-                'obj_id'     => $reg_id,
82
-            ),
83
-            'toggle_checkin_status'    => array(
84
-                'func'       => '_toggle_checkin_status',
85
-                'noheader'   => true,
86
-                'capability' => 'ee_edit_checkin',
87
-                'obj_id'     => $reg_id,
88
-            ),
89
-            'toggle_checkin_status_bulk' => array(
90
-                'func' => '_toggle_checkin_status',
91
-                'noheader' => true,
92
-                'capability' => 'ee_edit_checkins'
93
-            ),
94
-            'event_registrations'      => array(
95
-                'func'       => '_event_registrations_list_table',
96
-                'capability' => 'ee_read_checkins',
97
-            ),
98
-            'registrations_checkin_report' => array(
99
-                'func'       => '_registrations_checkin_report',
100
-                'noheader'   => true,
101
-                'capability' => 'ee_read_registrations',
102
-            ),
103
-        );
104
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
105
-        $new_page_config = array(
106
-            'reports'               => array(
107
-                'nav'           => array(
108
-                    'label' => __('Reports', 'event_espresso'),
109
-                    'order' => 30,
110
-                ),
111
-                'help_tabs'     => array(
112
-                    'registrations_reports_help_tab' => array(
113
-                        'title'    => __('Registration Reports', 'event_espresso'),
114
-                        'filename' => 'registrations_reports',
115
-                    ),
116
-                ),
117
-                /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/
118
-                'require_nonce' => false,
119
-            ),
120
-            'event_registrations'   => array(
121
-                'nav'           => array(
122
-                    'label'      => __('Event Check-In', 'event_espresso'),
123
-                    'order'      => 10,
124
-                    'persistent' => true,
125
-                ),
126
-                'help_tabs'     => array(
127
-                    'registrations_event_checkin_help_tab'                       => array(
128
-                        'title'    => __('Registrations Event Check-In', 'event_espresso'),
129
-                        'filename' => 'registrations_event_checkin',
130
-                    ),
131
-                    'registrations_event_checkin_table_column_headings_help_tab' => array(
132
-                        'title'    => __('Event Check-In Table Column Headings', 'event_espresso'),
133
-                        'filename' => 'registrations_event_checkin_table_column_headings',
134
-                    ),
135
-                    'registrations_event_checkin_filters_help_tab'               => array(
136
-                        'title'    => __('Event Check-In Filters', 'event_espresso'),
137
-                        'filename' => 'registrations_event_checkin_filters',
138
-                    ),
139
-                    'registrations_event_checkin_views_help_tab'                 => array(
140
-                        'title'    => __('Event Check-In Views', 'event_espresso'),
141
-                        'filename' => 'registrations_event_checkin_views',
142
-                    ),
143
-                    'registrations_event_checkin_other_help_tab'                 => array(
144
-                        'title'    => __('Event Check-In Other', 'event_espresso'),
145
-                        'filename' => 'registrations_event_checkin_other',
146
-                    ),
147
-                ),
148
-                'help_tour'     => array('Event_Checkin_Help_Tour'),
149
-                'qtips'         => array('Registration_List_Table_Tips'),
150
-                'list_table'    => 'EE_Event_Registrations_List_Table',
151
-                'metaboxes'     => array(),
152
-                'require_nonce' => false,
153
-            ),
154
-            'registration_checkins' => array(
155
-                'nav'           => array(
156
-                    'label'      => __('Check-In Records', 'event_espresso'),
157
-                    'order'      => 15,
158
-                    'persistent' => false,
159
-                ),
160
-                'list_table'    => 'EE_Registration_CheckIn_List_Table',
161
-                //'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ),
162
-                'metaboxes'     => array(),
163
-                'require_nonce' => false,
164
-            ),
165
-        );
166
-        $this->_page_config = array_merge($this->_page_config, $new_page_config);
167
-        $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
168
-        $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
169
-    }
170
-
171
-
172
-
173
-    protected function _ajax_hooks()
174
-    {
175
-        parent::_ajax_hooks();
176
-        add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content'));
177
-    }
178
-
179
-
180
-
181
-    public function load_scripts_styles()
182
-    {
183
-        parent::load_scripts_styles();
184
-        //if newsletter message type is active then let's add filter and load js for it.
185
-        if (EEH_MSG_Template::is_mt_active('newsletter')) {
186
-            //enqueue newsletter js
187
-            wp_enqueue_script(
188
-                'ee-newsletter-trigger',
189
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
190
-                array('ee-dialog'),
191
-                EVENT_ESPRESSO_VERSION,
192
-                true
193
-            );
194
-            wp_enqueue_style(
195
-                'ee-newsletter-trigger-css',
196
-                REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
197
-                array(),
198
-                EVENT_ESPRESSO_VERSION
199
-            );
200
-            //hook in buttons for newsletter message type trigger.
201
-            add_action(
202
-                'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
203
-                array($this, 'add_newsletter_action_buttons'),
204
-                10
205
-            );
206
-        }
207
-    }
208
-
209
-
210
-
211
-    public function load_scripts_styles_reports()
212
-    {
213
-        wp_register_script(
214
-            'ee-reg-reports-js',
215
-            REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
216
-            array('google-charts'),
217
-            EVENT_ESPRESSO_VERSION,
218
-            true
219
-        );
220
-        wp_enqueue_script('ee-reg-reports-js');
221
-        $this->_registration_reports_js_setup();
222
-    }
223
-
224
-
225
-
226
-    protected function _add_screen_options_event_registrations()
227
-    {
228
-        $this->_per_page_screen_option();
229
-    }
230
-
231
-
232
-
233
-    protected function _add_screen_options_registration_checkins()
234
-    {
235
-        $page_title = $this->_admin_page_title;
236
-        $this->_admin_page_title = __('Check-In Records', 'event_espresso');
237
-        $this->_per_page_screen_option();
238
-        $this->_admin_page_title = $page_title;
239
-    }
240
-
241
-
242
-
243
-    protected function _set_list_table_views_event_registrations()
244
-    {
245
-        $this->_views = array(
246
-            'all' => array(
247
-                'slug'        => 'all',
248
-                'label'       => __('All', 'event_espresso'),
249
-                'count'       => 0,
250
-                'bulk_action' => ! isset($this->_req_data['event_id'])
251
-                    ? array()
252
-                    : array(
253
-                        'toggle_checkin_status_bulk' => __('Toggle Check-In', 'event_espresso'),
254
-                    ),
255
-            ),
256
-        );
257
-    }
258
-
259
-
260
-
261
-    protected function _set_list_table_views_registration_checkins()
262
-    {
263
-        $this->_views = array(
264
-            'all' => array(
265
-                'slug'        => 'all',
266
-                'label'       => __('All', 'event_espresso'),
267
-                'count'       => 0,
268
-                'bulk_action' => array('delete_checkin_rows' => __('Delete Check-In Rows', 'event_espresso')),
269
-            ),
270
-        );
271
-    }
272
-
273
-
274
-
275
-    /**
276
-     * callback for ajax action.
277
-     *
278
-     * @since 4.3.0
279
-     * @return void (JSON)
280
-     * @throws \EE_Error
281
-     */
282
-    public function get_newsletter_form_content()
283
-    {
284
-        //do a nonce check cause we're not coming in from an normal route here.
285
-        $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field(
286
-            $this->_req_data['get_newsletter_form_content_nonce']
287
-        ) : '';
288
-        $nonce_ref = 'get_newsletter_form_content_nonce';
289
-        $this->_verify_nonce($nonce, $nonce_ref);
290
-        //let's get the mtp for the incoming MTP_ ID
291
-        if ( ! isset($this->_req_data['GRP_ID'])) {
292
-            EE_Error::add_error(
293
-                __(
294
-                    'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
295
-                    'event_espresso'
296
-                ),
297
-                __FILE__,
298
-                __FUNCTION__,
299
-                __LINE__
300
-            );
301
-            $this->_template_args['success'] = false;
302
-            $this->_template_args['error'] = true;
303
-            $this->_return_json();
304
-        }
305
-        $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
306
-        if ( ! $MTPG instanceof EE_Message_Template_Group) {
307
-            EE_Error::add_error(
308
-                sprintf(
309
-                    __(
310
-                        'The GRP_ID given (%d) does not appear to have a corresponding row in the database.',
311
-                        'event_espresso'
312
-                    ),
313
-                    $this->_req_data['GRP_ID']
314
-                ),
315
-                __FILE__,
316
-                __FUNCTION__,
317
-                __LINE__
318
-            );
319
-            $this->_template_args['success'] = false;
320
-            $this->_template_args['error'] = true;
321
-            $this->_return_json();
322
-        }
323
-        $MTPs = $MTPG->context_templates();
324
-        $MTPs = $MTPs['attendee'];
325
-        $template_fields = array();
326
-        /** @var EE_Message_Template $MTP */
327
-        foreach ($MTPs as $MTP) {
328
-            $field = $MTP->get('MTP_template_field');
329
-            if ($field === 'content') {
330
-                $content = $MTP->get('MTP_content');
331
-                if ( ! empty($content['newsletter_content'])) {
332
-                    $template_fields['newsletter_content'] = $content['newsletter_content'];
333
-                }
334
-                continue;
335
-            }
336
-            $template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content');
337
-        }
338
-        $this->_template_args['success'] = true;
339
-        $this->_template_args['error'] = false;
340
-        $this->_template_args['data'] = array(
341
-            'batch_message_from'    => isset($template_fields['from'])
342
-                ? $template_fields['from']
343
-                : '',
344
-            'batch_message_subject' => isset($template_fields['subject'])
345
-                ? $template_fields['subject']
346
-                : '',
347
-            'batch_message_content' => isset($template_fields['newsletter_content'])
348
-                ? $template_fields['newsletter_content']
349
-                : '',
350
-        );
351
-        $this->_return_json();
352
-    }
353
-
354
-
355
-
356
-    /**
357
-     * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action
358
-     *
359
-     * @since 4.3.0
360
-     * @param EE_Admin_List_Table $list_table
361
-     * @return void
362
-     */
363
-    public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
364
-    {
365
-        if ( ! EE_Registry::instance()->CAP->current_user_can(
366
-            'ee_send_message',
367
-            'espresso_registrations_newsletter_selected_send'
368
-        )
369
-        ) {
370
-            return;
371
-        }
372
-        $routes_to_add_to = array(
373
-            'contact_list',
374
-            'event_registrations',
375
-            'default',
376
-        );
377
-        if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) {
378
-            if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id']))
379
-                || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash')
380
-            ) {
381
-                echo '';
382
-            } else {
383
-                $button_text = sprintf(
384
-                    __('Send Batch Message (%s selected)', 'event_espresso'),
385
-                    '<span class="send-selected-newsletter-count">0</span>'
386
-                );
387
-                echo '<button id="selected-batch-send-trigger" class="button secondary-button"><span class="dashicons dashicons-email "></span>'
388
-                     . $button_text
389
-                     . '</button>';
390
-                add_action('admin_footer', array($this, 'newsletter_send_form_skeleton'));
391
-            }
392
-        }
393
-    }
394
-
395
-
396
-
397
-    public function newsletter_send_form_skeleton()
398
-    {
399
-        $list_table = $this->_list_table_object;
400
-        $codes = array();
401
-        //need to templates for the newsletter message type for the template selector.
402
-        $values[] = array('text' => __('Select Template to Use', 'event_espresso'), 'id' => 0);
403
-        $mtps = EEM_Message_Template_Group::instance()->get_all(
404
-            array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email'))
405
-        );
406
-        foreach ($mtps as $mtp) {
407
-            $name = $mtp->name();
408
-            $values[] = array(
409
-                'text' => empty($name) ? __('Global', 'event_espresso') : $name,
410
-                'id'   => $mtp->ID(),
411
-            );
412
-        }
413
-        //need to get a list of shortcodes that are available for the newsletter message type.
414
-        $shortcodes = EEH_MSG_Template::get_shortcodes('newsletter', 'email', array(), 'attendee', false);
415
-        foreach ($shortcodes as $field => $shortcode_array) {
416
-            $codes[$field] = implode(', ', array_keys($shortcode_array));
417
-        }
418
-        $shortcodes = $codes;
419
-        $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
420
-        $form_template_args = array(
421
-            'form_action'       => admin_url('admin.php?page=espresso_registrations'),
422
-            'form_route'        => 'newsletter_selected_send',
423
-            'form_nonce_name'   => 'newsletter_selected_send_nonce',
424
-            'form_nonce'        => wp_create_nonce('newsletter_selected_send_nonce'),
425
-            'redirect_back_to'  => $this->_req_action,
426
-            'ajax_nonce'        => wp_create_nonce('get_newsletter_form_content_nonce'),
427
-            'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values),
428
-            'shortcodes'        => $shortcodes,
429
-            'id_type'           => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration',
430
-        );
431
-        EEH_Template::display_template($form_template, $form_template_args);
432
-    }
433
-
434
-
435
-
436
-    /**
437
-     * Handles sending selected registrations/contacts a newsletter.
438
-     *
439
-     * @since  4.3.0
440
-     * @return void
441
-     * @throws \EE_Error
442
-     */
443
-    protected function _newsletter_selected_send()
444
-    {
445
-        $success = true;
446
-        //first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
447
-        if (empty($this->_req_data['newsletter_mtp_selected'])) {
448
-            EE_Error::add_error(
449
-                __(
450
-                    'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.',
451
-                    'event_espresso'
452
-                ),
453
-                __FILE__,
454
-                __FUNCTION__,
455
-                __LINE__
456
-            );
457
-            $success = false;
458
-        }
459
-        if ($success) {
460
-            //update Message template in case there are any changes
461
-            $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID(
462
-                $this->_req_data['newsletter_mtp_selected']
463
-            );
464
-            $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group
465
-                ? $Message_Template_Group->context_templates()
466
-                : array();
467
-            if (empty($Message_Templates)) {
468
-                EE_Error::add_error(
469
-                    __(
470
-                        'Unable to retrieve message template fields from the db. Messages not sent.',
471
-                        'event_espresso'
472
-                    ),
473
-                    __FILE__,
474
-                    __FUNCTION__,
475
-                    __LINE__
476
-                );
477
-            }
478
-            //let's just update the specific fields
479
-            foreach ($Message_Templates['attendee'] as $Message_Template) {
480
-                if ($Message_Template instanceof EE_Message_Template) {
481
-                    $field = $Message_Template->get('MTP_template_field');
482
-                    $content = $Message_Template->get('MTP_content');
483
-                    $new_content = $content;
484
-                    switch ($field) {
485
-                        case 'from' :
486
-                            $new_content = ! empty($this->_req_data['batch_message']['from'])
487
-                                ? $this->_req_data['batch_message']['from']
488
-                                : $content;
489
-                            break;
490
-                        case 'subject' :
491
-                            $new_content = ! empty($this->_req_data['batch_message']['subject'])
492
-                                ? $this->_req_data['batch_message']['subject']
493
-                                : $content;
494
-                            break;
495
-                        case 'content' :
496
-                            $new_content = $content;
497
-                            $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content'])
498
-                                ? $this->_req_data['batch_message']['content']
499
-                                : $content['newsletter_content'];
500
-                            break;
501
-                        default :
502
-                            //continue the foreach loop, we don't want to set $new_content nor save.
503
-                            continue 2;
504
-                    }
505
-                    $Message_Template->set('MTP_content', $new_content);
506
-                    $Message_Template->save();
507
-                }
508
-            }
509
-            //great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
510
-            $id_type = ! empty($this->_req_data['batch_message']['id_type'])
511
-                ? $this->_req_data['batch_message']['id_type']
512
-                : 'registration';
513
-            //id_type will affect how we assemble the ids.
514
-            $ids = ! empty($this->_req_data['batch_message']['ids'])
515
-                ? json_decode(stripslashes($this->_req_data['batch_message']['ids']))
516
-                : array();
517
-            $registrations_used_for_contact_data = array();
518
-            //using switch because eventually we'll have other contexts that will be used for generating messages.
519
-            switch ($id_type) {
520
-                case 'registration' :
521
-                    $registrations_used_for_contact_data = EEM_Registration::instance()->get_all(
522
-                        array(
523
-                            array(
524
-                                'REG_ID' => array('IN', $ids),
525
-                            ),
526
-                        )
527
-                    );
528
-                    break;
529
-                case 'contact' :
530
-                    $registrations_used_for_contact_data = EEM_Registration::instance()
531
-                                                                           ->get_latest_registration_for_each_of_given_contacts($ids);
532
-                    break;
533
-            }
534
-            do_action(
535
-                'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
536
-                $registrations_used_for_contact_data,
537
-                $Message_Template_Group->ID()
538
-            );
539
-            //kept for backward compat, internally we no longer use this action.
540
-            //@deprecated 4.8.36.rc.002
541
-            $contacts = $id_type === 'registration'
542
-                ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids)
543
-                : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids))));
544
-            do_action(
545
-                'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send',
546
-                $contacts,
547
-                $Message_Template_Group->ID()
548
-            );
549
-        }
550
-        $query_args = array(
551
-            'action' => ! empty($this->_req_data['redirect_back_to'])
552
-                ? $this->_req_data['redirect_back_to']
553
-                : 'default',
554
-        );
555
-        $this->_redirect_after_action(false, '', '', $query_args, true);
556
-    }
557
-
558
-
559
-
560
-    /**
561
-     * This is called when javascript is being enqueued to setup the various data needed for the reports js.
562
-     * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method.
563
-     */
564
-    protected function _registration_reports_js_setup()
565
-    {
566
-        $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report();
567
-        $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report();
568
-    }
569
-
570
-
571
-
572
-    /**
573
-     *        generates Business Reports regarding Registrations
574
-     *
575
-     * @access protected
576
-     * @return void
577
-     */
578
-    protected function _registration_reports()
579
-    {
580
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
581
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
582
-            $template_path,
583
-            $this->_reports_template_data,
584
-            true
585
-        );
586
-        // the final template wrapper
587
-        $this->display_admin_page_with_no_sidebar();
588
-    }
589
-
590
-
591
-
592
-    /**
593
-     * Generates Business Report showing total registrations per day.
594
-     *
595
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
596
-     * @return string
597
-     */
598
-    private function _registrations_per_day_report($period = '-1 month')
599
-    {
600
-        $report_ID = 'reg-admin-registrations-per-day-report-dv';
601
-        $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
602
-        $results = (array)$results;
603
-        $regs = array();
604
-        $subtitle = '';
605
-        if ($results) {
606
-            $column_titles = array();
607
-            $tracker = 0;
608
-            foreach ($results as $result) {
609
-                $report_column_values = array();
610
-                foreach ($result as $property_name => $property_value) {
611
-                    $property_value = $property_name === 'Registration_REG_date' ? $property_value
612
-                        : (int)$property_value;
613
-                    $report_column_values[] = $property_value;
614
-                    if ($tracker === 0) {
615
-                        if ($property_name === 'Registration_REG_date') {
616
-                            $column_titles[] = __('Date (only days with registrations are shown)', 'event_espresso');
617
-                        } else {
618
-                            $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
619
-                        }
620
-                    }
621
-                }
622
-                $tracker++;
623
-                $regs[] = $report_column_values;
624
-            }
625
-            //make sure the column_titles is pushed to the beginning of the array
626
-            array_unshift($regs, $column_titles);
627
-            //setup the date range.
628
-            $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
629
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
630
-            $ending_date = new DateTime("now", $DateTimeZone);
631
-            $subtitle = sprintf(
632
-                _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
633
-                $beginning_date->format('Y-m-d'),
634
-                $ending_date->format('Y-m-d')
635
-            );
636
-        }
637
-        $report_title = __('Total Registrations per Day', 'event_espresso');
638
-        $report_params = array(
639
-            'title'     => $report_title,
640
-            'subtitle'  => $subtitle,
641
-            'id'        => $report_ID,
642
-            'regs'      => $regs,
643
-            'noResults' => empty($regs),
644
-            'noRegsMsg' => sprintf(
645
-                __(
646
-                    '%sThere are currently no registration records in the last month for this report.%s',
647
-                    'event_espresso'
648
-                ),
649
-                '<h2>' . $report_title . '</h2><p>',
650
-                '</p>'
651
-            ),
652
-        );
653
-        wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params);
654
-        return $report_ID;
655
-    }
656
-
657
-
658
-
659
-    /**
660
-     * Generates Business Report showing total registrations per event.
661
-     *
662
-     * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
663
-     * @return string
664
-     */
665
-    private function _registrations_per_event_report($period = '-1 month')
666
-    {
667
-        $report_ID = 'reg-admin-registrations-per-event-report-dv';
668
-        $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
669
-        $results = (array)$results;
670
-        $regs = array();
671
-        $subtitle = '';
672
-        if ($results) {
673
-            $column_titles = array();
674
-            $tracker = 0;
675
-            foreach ($results as $result) {
676
-                $report_column_values = array();
677
-                foreach ($result as $property_name => $property_value) {
678
-                    $property_value = $property_name === 'Registration_Event' ? wp_trim_words(
679
-                        $property_value,
680
-                        4,
681
-                        '...'
682
-                    ) : (int)$property_value;
683
-                    $report_column_values[] = $property_value;
684
-                    if ($tracker === 0) {
685
-                        if ($property_name === 'Registration_Event') {
686
-                            $column_titles[] = __('Event', 'event_espresso');
687
-                        } else {
688
-                            $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
689
-                        }
690
-                    }
691
-                }
692
-                $tracker++;
693
-                $regs[] = $report_column_values;
694
-            }
695
-            //make sure the column_titles is pushed to the beginning of the array
696
-            array_unshift($regs, $column_titles);
697
-            //setup the date range.
698
-            $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
699
-            $beginning_date = new DateTime("now " . $period, $DateTimeZone);
700
-            $ending_date = new DateTime("now", $DateTimeZone);
701
-            $subtitle = sprintf(
702
-                _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
703
-                $beginning_date->format('Y-m-d'),
704
-                $ending_date->format('Y-m-d')
705
-            );
706
-        }
707
-        $report_title = __('Total Registrations per Event', 'event_espresso');
708
-        $report_params = array(
709
-            'title'     => $report_title,
710
-            'subtitle'  => $subtitle,
711
-            'id'        => $report_ID,
712
-            'regs'      => $regs,
713
-            'noResults' => empty($regs),
714
-            'noRegsMsg' => sprintf(
715
-                __(
716
-                    '%sThere are currently no registration records in the last month for this report.%s',
717
-                    'event_espresso'
718
-                ),
719
-                '<h2>' . $report_title . '</h2><p>',
720
-                '</p>'
721
-            ),
722
-        );
723
-        wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params);
724
-        return $report_ID;
725
-    }
726
-
727
-
728
-
729
-    /**
730
-     * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration)
731
-     *
732
-     * @access protected
733
-     * @return void
734
-     * @throws \EE_Error
735
-     */
736
-    protected function _registration_checkin_list_table()
737
-    {
738
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
739
-        $reg_id = isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : null;
740
-        /** @var EE_Registration $registration */
741
-        $registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
742
-        $attendee = $registration->attendee();
743
-        $this->_admin_page_title .= $this->get_action_link_or_button(
744
-            'new_registration',
745
-            'add-registrant',
746
-            array('event_id' => $registration->event_ID()),
747
-            'add-new-h2'
748
-        );
749
-        $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
750
-        $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
751
-        $legend_items = array(
752
-            'checkin'  => array(
753
-                'class' => $checked_in->cssClasses(),
754
-                'desc'  => $checked_in->legendLabel(),
755
-            ),
756
-            'checkout' => array(
757
-                'class' => $checked_out->cssClasses(),
758
-                'desc'  => $checked_out->legendLabel(),
759
-            ),
760
-        );
761
-        $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
762
-        $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
763
-        /** @var EE_Datetime $datetime */
764
-        $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id);
765
-        $datetime_label = '';
766
-        if ($datetime instanceof EE_Datetime) {
767
-            $datetime_label = $datetime->get_dtt_display_name(true);
768
-            $datetime_label .= ! empty($datetime_label)
769
-                ? ' (' . $datetime->get_dtt_display_name() . ')'
770
-                : $datetime->get_dtt_display_name();
771
-        }
772
-        $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
773
-            ? EE_Admin_Page::add_query_args_and_nonce(
774
-                array(
775
-                    'action'   => 'event_registrations',
776
-                    'event_id' => $registration->event_ID(),
777
-                    'DTT_ID'   => $dtt_id,
778
-                ),
779
-                $this->_admin_base_url
780
-            )
781
-            : '';
782
-        $datetime_link = ! empty($datetime_link)
783
-            ? '<a href="' . $datetime_link . '">'
784
-              . '<span id="checkin-dtt">'
785
-              . $datetime_label
786
-              . '</span></a>'
787
-            : $datetime_label;
788
-        $attendee_name = $attendee instanceof EE_Attendee
789
-            ? $attendee->full_name()
790
-            : '';
791
-        $attendee_link = $attendee instanceof EE_Attendee
792
-            ? $attendee->get_admin_details_link()
793
-            : '';
794
-        $attendee_link = ! empty($attendee_link)
795
-            ? '<a href="' . $attendee->get_admin_details_link() . '"'
796
-              . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
797
-              . '<span id="checkin-attendee-name">'
798
-              . $attendee_name
799
-              . '</span></a>'
800
-            : '';
801
-        $event_link = $registration->event() instanceof EE_Event
802
-            ? $registration->event()->get_admin_details_link()
803
-            : '';
804
-        $event_link = ! empty($event_link)
805
-            ? '<a href="' . $event_link . '"'
806
-              . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
807
-              . '<span id="checkin-event-name">'
808
-              . $registration->event_name()
809
-              . '</span>'
810
-              . '</a>'
811
-            : '';
812
-        $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
813
-            ? '<h2>' . sprintf(
814
-                esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
815
-                $attendee_link,
816
-                $datetime_link,
817
-                $event_link
818
-            ) . '</h2>'
819
-            : '';
820
-        $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
821
-            ? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : '';
822
-        $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
823
-            ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
824
-        $this->display_admin_list_table_page_with_no_sidebar();
825
-    }
826
-
827
-
828
-
829
-    /**
830
-     * toggle the Check-in status for the given registration (coming from ajax)
831
-     *
832
-     * @return void (JSON)
833
-     */
834
-    public function toggle_checkin_status()
835
-    {
836
-        //first make sure we have the necessary data
837
-        if ( ! isset($this->_req_data['_regid'])) {
838
-            EE_Error::add_error(
839
-                __(
840
-                    'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
841
-                    'event_espresso'
842
-                ),
843
-                __FILE__,
844
-                __FUNCTION__,
845
-                __LINE__
846
-            );
847
-            $this->_template_args['success'] = false;
848
-            $this->_template_args['error'] = true;
849
-            $this->_return_json();
850
-        };
851
-        //do a nonce check cause we're not coming in from an normal route here.
852
-        $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce'])
853
-            : '';
854
-        $nonce_ref = 'checkin_nonce';
855
-        $this->_verify_nonce($nonce, $nonce_ref);
856
-        //beautiful! Made it this far so let's get the status.
857
-        $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status());
858
-        //setup new class to return via ajax
859
-        $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses();
860
-        $this->_template_args['success'] = true;
861
-        $this->_return_json();
862
-    }
863
-
864
-
865
-
866
-    /**
867
-     * handles toggling the checkin status for the registration,
868
-     *
869
-     * @access protected
870
-     * @return int|void
871
-     */
872
-    protected function _toggle_checkin_status()
873
-    {
874
-        //first let's get the query args out of the way for the redirect
875
-        $query_args = array(
876
-            'action'   => 'event_registrations',
877
-            'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
878
-            'DTT_ID'   => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null,
879
-        );
880
-        $new_status = false;
881
-        // bulk action check in toggle
882
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
883
-            // cycle thru checkboxes
884
-            while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
885
-                $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
886
-                $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
887
-            }
888
-        } elseif (isset($this->_req_data['_regid'])) {
889
-            //coming from ajax request
890
-            $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null;
891
-            $query_args['DTT_ID'] = $DTT_ID;
892
-            $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
893
-        } else {
894
-            EE_Error::add_error(
895
-                __('Missing some required data to toggle the Check-in', 'event_espresso'),
896
-                __FILE__,
897
-                __FUNCTION__,
898
-                __LINE__
899
-            );
900
-        }
901
-        if (defined('DOING_AJAX')) {
902
-            return $new_status;
903
-        }
904
-        $this->_redirect_after_action(false, '', '', $query_args, true);
905
-    }
906
-
907
-
908
-
909
-    /**
910
-     * This is toggles a single Check-in for the given registration and datetime.
911
-     *
912
-     * @param  int $REG_ID The registration we're toggling
913
-     * @param  int $DTT_ID The datetime we're toggling
914
-     * @return int            The new status toggled to.
915
-     * @throws \EE_Error
916
-     */
917
-    private function _toggle_checkin($REG_ID, $DTT_ID)
918
-    {
919
-        /** @var EE_Registration $REG */
920
-        $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
921
-        $new_status = $REG->toggle_checkin_status($DTT_ID);
922
-        if ($new_status !== false) {
923
-            EE_Error::add_success($REG->get_checkin_msg($DTT_ID));
924
-        } else {
925
-            EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__);
926
-            $new_status = false;
927
-        }
928
-        return $new_status;
929
-    }
930
-
931
-
932
-
933
-    /**
934
-     * Takes care of deleting multiple EE_Checkin table rows
935
-     *
936
-     * @access protected
937
-     * @return void
938
-     * @throws \EE_Error
939
-     */
940
-    protected function _delete_checkin_rows()
941
-    {
942
-        $query_args = array(
943
-            'action' => 'registration_checkins',
944
-            'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
945
-            '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0,
946
-        );
947
-        $errors = 0;
948
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
949
-            while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
950
-                if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
951
-                    $errors++;
952
-                }
953
-            }
954
-        } else {
955
-            EE_Error::add_error(
956
-                __(
957
-                    'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!',
958
-                    'event_espresso'
959
-                ),
960
-                __FILE__,
961
-                __FUNCTION__,
962
-                __LINE__
963
-            );
964
-            $this->_redirect_after_action(false, '', '', $query_args, true);
965
-        }
966
-        if ($errors > 0) {
967
-            EE_Error::add_error(
968
-                sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors),
969
-                __FILE__,
970
-                __FUNCTION__,
971
-                __LINE__
972
-            );
973
-        } else {
974
-            EE_Error::add_success(__('Records were successfully deleted', 'event_espresso'));
975
-        }
976
-        $this->_redirect_after_action(false, '', '', $query_args, true);
977
-    }
978
-
979
-
980
-
981
-    /**
982
-     * Deletes a single EE_Checkin row
983
-     *
984
-     * @return void
985
-     * @throws \EE_Error
986
-     */
987
-    protected function _delete_checkin_row()
988
-    {
989
-        $query_args = array(
990
-            'action' => 'registration_checkins',
991
-            'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
992
-            '_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0,
993
-        );
994
-        if ( ! empty($this->_req_data['CHK_ID'])) {
995
-            if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
996
-                EE_Error::add_error(
997
-                    __('Something went wrong and this check-in record was not deleted', 'event_espresso'),
998
-                    __FILE__,
999
-                    __FUNCTION__,
1000
-                    __LINE__
1001
-                );
1002
-            } else {
1003
-                EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso'));
1004
-            }
1005
-        } else {
1006
-            EE_Error::add_error(
1007
-                __(
1008
-                    'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code',
1009
-                    'event_espresso'
1010
-                ),
1011
-                __FILE__,
1012
-                __FUNCTION__,
1013
-                __LINE__
1014
-            );
1015
-        }
1016
-        $this->_redirect_after_action(false, '', '', $query_args, true);
1017
-    }
1018
-
1019
-
1020
-
1021
-    /**
1022
-     *        generates HTML for the Event Registrations List Table
1023
-     *
1024
-     * @access protected
1025
-     * @return void
1026
-     * @throws \EE_Error
1027
-     */
1028
-    protected function _event_registrations_list_table()
1029
-    {
1030
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1031
-        $this->_admin_page_title .= isset($this->_req_data['event_id'])
1032
-            ? $this->get_action_link_or_button(
1033
-                'new_registration',
1034
-                'add-registrant',
1035
-                array('event_id' => $this->_req_data['event_id']),
1036
-                'add-new-h2',
1037
-                '',
1038
-                false
1039
-            )
1040
-            : '';
1041
-        $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
1042
-        $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
1043
-        $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never);
1044
-        $legend_items = array(
1045
-            'star-icon'        => array(
1046
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1047
-                'desc'  => __('This Registrant is the Primary Registrant', 'event_espresso'),
1048
-            ),
1049
-            'checkin'          => array(
1050
-                'class' => $checked_in->cssClasses(),
1051
-                'desc'  => $checked_in->legendLabel(),
1052
-            ),
1053
-            'checkout'         => array(
1054
-                'class' => $checked_out->cssClasses(),
1055
-                'desc'  => $checked_out->legendLabel(),
1056
-            ),
1057
-            'nocheckinrecord'  => array(
1058
-                'class' => $checked_never->cssClasses(),
1059
-                'desc'  => $checked_never->legendLabel(),
1060
-            ),
1061
-            'view_details'     => array(
1062
-                'class' => 'dashicons dashicons-search',
1063
-                'desc'  => __('View All Check-in Records for this Registrant', 'event_espresso'),
1064
-            ),
1065
-            'approved_status'  => array(
1066
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1067
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1068
-            ),
1069
-            'cancelled_status' => array(
1070
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1071
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1072
-            ),
1073
-            'declined_status'  => array(
1074
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1075
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1076
-            ),
1077
-            'not_approved'     => array(
1078
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1079
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1080
-            ),
1081
-            'pending_status'   => array(
1082
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1083
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1084
-            ),
1085
-            'wait_list'        => array(
1086
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1087
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1088
-            ),
1089
-        );
1090
-        $this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1091
-        $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1092
-        $this->_template_args['before_list_table'] = ! empty($event_id)
1093
-            ? '<h2>' . sprintf(
1094
-                __('Viewing Registrations for Event: %s', 'event_espresso'),
1095
-                EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1096
-            ) . '</h2>'
1097
-            : '';
1098
-        //need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on the event.
1099
-        /** @var EE_Event $event */
1100
-        $event = EEM_Event::instance()->get_one_by_ID($event_id);
1101
-        $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0;
1102
-        $datetime = null;
1103
-        if ($event instanceof EE_Event) {
1104
-            $datetimes_on_event = $event->datetimes();
1105
-            if (count($datetimes_on_event) === 1) {
1106
-                $datetime = reset($datetimes_on_event);
1107
-            }
1108
-        }
1109
-        $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1110
-        if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') {
1111
-            $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5);
1112
-            $this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1113
-            $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1114
-            $this->_template_args['before_list_table'] .= $datetime->name();
1115
-            $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1116
-            $this->_template_args['before_list_table'] .= '</span></h2>';
1117
-        }
1118
-        //if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status column
1119
-        //represents
1120
-        if ( ! $datetime instanceof EE_Datetime) {
1121
-            $this->_template_args['before_list_table'] .= '<br><p class="description">'
1122
-                                                          . __('In this view, the check-in status represents the latest check-in record for the registration in that row.',
1123
-                    'event_espresso')
1124
-                                                          . '</p>';
1125
-        }
1126
-        $this->display_admin_list_table_page_with_no_sidebar();
1127
-    }
1128
-
1129
-    /**
1130
-     * Download the registrations check-in report (same as the normal registration report, but with different where
1131
-     * conditions)
1132
-     *
1133
-     * @return void ends the request by a redirect or download
1134
-     */
1135
-    public function _registrations_checkin_report()
1136
-    {
1137
-        $this->_registrations_report_base('_get_checkin_query_params_from_request');
1138
-    }
1139
-
1140
-    /**
1141
-     * Gets the query params from the request, plus adds a where condition for the registration status,
1142
-     * because on the checkin page we only ever want to see approved and pending-approval registrations
1143
-     *
1144
-     * @param array     $request
1145
-     * @param int  $per_page
1146
-     * @param bool $count
1147
-     * @return array
1148
-     */
1149
-    protected function _get_checkin_query_params_from_request(
1150
-        $request,
1151
-        $per_page = 10,
1152
-        $count = false
1153
-    ) {
1154
-        $query_params = $this->_get_registration_query_parameters($request, $per_page, $count);
1155
-        //unlike the regular registrations list table,
1156
-        $status_ids_array = apply_filters(
1157
-            'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
1158
-            array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
1159
-        );
1160
-        $query_params[0]['STS_ID'] = array('IN', $status_ids_array);
1161
-        return $query_params;
1162
-    }
1163
-
1164
-
1165
-
1166
-
1167
-    /**
1168
-     * Gets registrations for an event
1169
-     *
1170
-     * @param int    $per_page
1171
-     * @param bool   $count whether to return count or data.
1172
-     * @param bool   $trash
1173
-     * @param string $orderby
1174
-     * @return EE_Registration[]|int
1175
-     * @throws \EE_Error
1176
-     */
1177
-    public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname')
1178
-    {
1179
-        //normalize some request params that get setup by the parent `get_registrations` method.
1180
-        $request = $this->_req_data;
1181
-        $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1182
-        $request['order'] =  ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1183
-        if($trash){
1184
-            $request['status'] = 'trash';
1185
-        }
1186
-        $query_params = $this->_get_checkin_query_params_from_request( $request, $per_page, $count );
1187
-        /**
1188
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1189
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1190
-         * @see EEM_Base::get_all()
1191
-         */
1192
-        $query_params['group_by'] = '';
1193
-
1194
-        return $count
1195
-            ? EEM_Registration::instance()->count($query_params)
1196
-            /** @type EE_Registration[] */
1197
-            : EEM_Registration::instance()->get_all($query_params);
1198
-    }
23
+	/**
24
+	 * This is used to hold the reports template data which is setup early in the request.
25
+	 *
26
+	 * @type array
27
+	 */
28
+	protected $_reports_template_data = array();
29
+
30
+
31
+
32
+	/**
33
+	 * Extend_Registrations_Admin_Page constructor.
34
+	 *
35
+	 * @param bool $routing
36
+	 */
37
+	public function __construct($routing = true)
38
+	{
39
+		parent::__construct($routing);
40
+		if ( ! defined('REG_CAF_TEMPLATE_PATH')) {
41
+			define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/');
42
+			define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/');
43
+			define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/');
44
+		}
45
+	}
46
+
47
+
48
+
49
+	protected function _extend_page_config()
50
+	{
51
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations';
52
+		$reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
53
+			? $this->_req_data['_REG_ID']
54
+			: 0;
55
+		// $att_id = ! empty( $this->_req_data['ATT_ID'] ) ? ! is_array( $this->_req_data['ATT_ID'] ) : 0;
56
+		// $att_id = ! empty( $this->_req_data['post'] ) && ! is_array( $this->_req_data['post'] )
57
+		// 	? $this->_req_data['post'] : $att_id;
58
+		$new_page_routes = array(
59
+			'reports'                  => array(
60
+				'func'       => '_registration_reports',
61
+				'capability' => 'ee_read_registrations',
62
+			),
63
+			'registration_checkins'    => array(
64
+				'func'       => '_registration_checkin_list_table',
65
+				'capability' => 'ee_read_checkins',
66
+			),
67
+			'newsletter_selected_send' => array(
68
+				'func'       => '_newsletter_selected_send',
69
+				'noheader'   => true,
70
+				'capability' => 'ee_send_message',
71
+			),
72
+			'delete_checkin_rows'      => array(
73
+				'func'       => '_delete_checkin_rows',
74
+				'noheader'   => true,
75
+				'capability' => 'ee_delete_checkins',
76
+			),
77
+			'delete_checkin_row'       => array(
78
+				'func'       => '_delete_checkin_row',
79
+				'noheader'   => true,
80
+				'capability' => 'ee_delete_checkin',
81
+				'obj_id'     => $reg_id,
82
+			),
83
+			'toggle_checkin_status'    => array(
84
+				'func'       => '_toggle_checkin_status',
85
+				'noheader'   => true,
86
+				'capability' => 'ee_edit_checkin',
87
+				'obj_id'     => $reg_id,
88
+			),
89
+			'toggle_checkin_status_bulk' => array(
90
+				'func' => '_toggle_checkin_status',
91
+				'noheader' => true,
92
+				'capability' => 'ee_edit_checkins'
93
+			),
94
+			'event_registrations'      => array(
95
+				'func'       => '_event_registrations_list_table',
96
+				'capability' => 'ee_read_checkins',
97
+			),
98
+			'registrations_checkin_report' => array(
99
+				'func'       => '_registrations_checkin_report',
100
+				'noheader'   => true,
101
+				'capability' => 'ee_read_registrations',
102
+			),
103
+		);
104
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
105
+		$new_page_config = array(
106
+			'reports'               => array(
107
+				'nav'           => array(
108
+					'label' => __('Reports', 'event_espresso'),
109
+					'order' => 30,
110
+				),
111
+				'help_tabs'     => array(
112
+					'registrations_reports_help_tab' => array(
113
+						'title'    => __('Registration Reports', 'event_espresso'),
114
+						'filename' => 'registrations_reports',
115
+					),
116
+				),
117
+				/*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/
118
+				'require_nonce' => false,
119
+			),
120
+			'event_registrations'   => array(
121
+				'nav'           => array(
122
+					'label'      => __('Event Check-In', 'event_espresso'),
123
+					'order'      => 10,
124
+					'persistent' => true,
125
+				),
126
+				'help_tabs'     => array(
127
+					'registrations_event_checkin_help_tab'                       => array(
128
+						'title'    => __('Registrations Event Check-In', 'event_espresso'),
129
+						'filename' => 'registrations_event_checkin',
130
+					),
131
+					'registrations_event_checkin_table_column_headings_help_tab' => array(
132
+						'title'    => __('Event Check-In Table Column Headings', 'event_espresso'),
133
+						'filename' => 'registrations_event_checkin_table_column_headings',
134
+					),
135
+					'registrations_event_checkin_filters_help_tab'               => array(
136
+						'title'    => __('Event Check-In Filters', 'event_espresso'),
137
+						'filename' => 'registrations_event_checkin_filters',
138
+					),
139
+					'registrations_event_checkin_views_help_tab'                 => array(
140
+						'title'    => __('Event Check-In Views', 'event_espresso'),
141
+						'filename' => 'registrations_event_checkin_views',
142
+					),
143
+					'registrations_event_checkin_other_help_tab'                 => array(
144
+						'title'    => __('Event Check-In Other', 'event_espresso'),
145
+						'filename' => 'registrations_event_checkin_other',
146
+					),
147
+				),
148
+				'help_tour'     => array('Event_Checkin_Help_Tour'),
149
+				'qtips'         => array('Registration_List_Table_Tips'),
150
+				'list_table'    => 'EE_Event_Registrations_List_Table',
151
+				'metaboxes'     => array(),
152
+				'require_nonce' => false,
153
+			),
154
+			'registration_checkins' => array(
155
+				'nav'           => array(
156
+					'label'      => __('Check-In Records', 'event_espresso'),
157
+					'order'      => 15,
158
+					'persistent' => false,
159
+				),
160
+				'list_table'    => 'EE_Registration_CheckIn_List_Table',
161
+				//'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ),
162
+				'metaboxes'     => array(),
163
+				'require_nonce' => false,
164
+			),
165
+		);
166
+		$this->_page_config = array_merge($this->_page_config, $new_page_config);
167
+		$this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table';
168
+		$this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table';
169
+	}
170
+
171
+
172
+
173
+	protected function _ajax_hooks()
174
+	{
175
+		parent::_ajax_hooks();
176
+		add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content'));
177
+	}
178
+
179
+
180
+
181
+	public function load_scripts_styles()
182
+	{
183
+		parent::load_scripts_styles();
184
+		//if newsletter message type is active then let's add filter and load js for it.
185
+		if (EEH_MSG_Template::is_mt_active('newsletter')) {
186
+			//enqueue newsletter js
187
+			wp_enqueue_script(
188
+				'ee-newsletter-trigger',
189
+				REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js',
190
+				array('ee-dialog'),
191
+				EVENT_ESPRESSO_VERSION,
192
+				true
193
+			);
194
+			wp_enqueue_style(
195
+				'ee-newsletter-trigger-css',
196
+				REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css',
197
+				array(),
198
+				EVENT_ESPRESSO_VERSION
199
+			);
200
+			//hook in buttons for newsletter message type trigger.
201
+			add_action(
202
+				'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons',
203
+				array($this, 'add_newsletter_action_buttons'),
204
+				10
205
+			);
206
+		}
207
+	}
208
+
209
+
210
+
211
+	public function load_scripts_styles_reports()
212
+	{
213
+		wp_register_script(
214
+			'ee-reg-reports-js',
215
+			REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js',
216
+			array('google-charts'),
217
+			EVENT_ESPRESSO_VERSION,
218
+			true
219
+		);
220
+		wp_enqueue_script('ee-reg-reports-js');
221
+		$this->_registration_reports_js_setup();
222
+	}
223
+
224
+
225
+
226
+	protected function _add_screen_options_event_registrations()
227
+	{
228
+		$this->_per_page_screen_option();
229
+	}
230
+
231
+
232
+
233
+	protected function _add_screen_options_registration_checkins()
234
+	{
235
+		$page_title = $this->_admin_page_title;
236
+		$this->_admin_page_title = __('Check-In Records', 'event_espresso');
237
+		$this->_per_page_screen_option();
238
+		$this->_admin_page_title = $page_title;
239
+	}
240
+
241
+
242
+
243
+	protected function _set_list_table_views_event_registrations()
244
+	{
245
+		$this->_views = array(
246
+			'all' => array(
247
+				'slug'        => 'all',
248
+				'label'       => __('All', 'event_espresso'),
249
+				'count'       => 0,
250
+				'bulk_action' => ! isset($this->_req_data['event_id'])
251
+					? array()
252
+					: array(
253
+						'toggle_checkin_status_bulk' => __('Toggle Check-In', 'event_espresso'),
254
+					),
255
+			),
256
+		);
257
+	}
258
+
259
+
260
+
261
+	protected function _set_list_table_views_registration_checkins()
262
+	{
263
+		$this->_views = array(
264
+			'all' => array(
265
+				'slug'        => 'all',
266
+				'label'       => __('All', 'event_espresso'),
267
+				'count'       => 0,
268
+				'bulk_action' => array('delete_checkin_rows' => __('Delete Check-In Rows', 'event_espresso')),
269
+			),
270
+		);
271
+	}
272
+
273
+
274
+
275
+	/**
276
+	 * callback for ajax action.
277
+	 *
278
+	 * @since 4.3.0
279
+	 * @return void (JSON)
280
+	 * @throws \EE_Error
281
+	 */
282
+	public function get_newsletter_form_content()
283
+	{
284
+		//do a nonce check cause we're not coming in from an normal route here.
285
+		$nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field(
286
+			$this->_req_data['get_newsletter_form_content_nonce']
287
+		) : '';
288
+		$nonce_ref = 'get_newsletter_form_content_nonce';
289
+		$this->_verify_nonce($nonce, $nonce_ref);
290
+		//let's get the mtp for the incoming MTP_ ID
291
+		if ( ! isset($this->_req_data['GRP_ID'])) {
292
+			EE_Error::add_error(
293
+				__(
294
+					'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).',
295
+					'event_espresso'
296
+				),
297
+				__FILE__,
298
+				__FUNCTION__,
299
+				__LINE__
300
+			);
301
+			$this->_template_args['success'] = false;
302
+			$this->_template_args['error'] = true;
303
+			$this->_return_json();
304
+		}
305
+		$MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']);
306
+		if ( ! $MTPG instanceof EE_Message_Template_Group) {
307
+			EE_Error::add_error(
308
+				sprintf(
309
+					__(
310
+						'The GRP_ID given (%d) does not appear to have a corresponding row in the database.',
311
+						'event_espresso'
312
+					),
313
+					$this->_req_data['GRP_ID']
314
+				),
315
+				__FILE__,
316
+				__FUNCTION__,
317
+				__LINE__
318
+			);
319
+			$this->_template_args['success'] = false;
320
+			$this->_template_args['error'] = true;
321
+			$this->_return_json();
322
+		}
323
+		$MTPs = $MTPG->context_templates();
324
+		$MTPs = $MTPs['attendee'];
325
+		$template_fields = array();
326
+		/** @var EE_Message_Template $MTP */
327
+		foreach ($MTPs as $MTP) {
328
+			$field = $MTP->get('MTP_template_field');
329
+			if ($field === 'content') {
330
+				$content = $MTP->get('MTP_content');
331
+				if ( ! empty($content['newsletter_content'])) {
332
+					$template_fields['newsletter_content'] = $content['newsletter_content'];
333
+				}
334
+				continue;
335
+			}
336
+			$template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content');
337
+		}
338
+		$this->_template_args['success'] = true;
339
+		$this->_template_args['error'] = false;
340
+		$this->_template_args['data'] = array(
341
+			'batch_message_from'    => isset($template_fields['from'])
342
+				? $template_fields['from']
343
+				: '',
344
+			'batch_message_subject' => isset($template_fields['subject'])
345
+				? $template_fields['subject']
346
+				: '',
347
+			'batch_message_content' => isset($template_fields['newsletter_content'])
348
+				? $template_fields['newsletter_content']
349
+				: '',
350
+		);
351
+		$this->_return_json();
352
+	}
353
+
354
+
355
+
356
+	/**
357
+	 * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action
358
+	 *
359
+	 * @since 4.3.0
360
+	 * @param EE_Admin_List_Table $list_table
361
+	 * @return void
362
+	 */
363
+	public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table)
364
+	{
365
+		if ( ! EE_Registry::instance()->CAP->current_user_can(
366
+			'ee_send_message',
367
+			'espresso_registrations_newsletter_selected_send'
368
+		)
369
+		) {
370
+			return;
371
+		}
372
+		$routes_to_add_to = array(
373
+			'contact_list',
374
+			'event_registrations',
375
+			'default',
376
+		);
377
+		if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) {
378
+			if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id']))
379
+				|| (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash')
380
+			) {
381
+				echo '';
382
+			} else {
383
+				$button_text = sprintf(
384
+					__('Send Batch Message (%s selected)', 'event_espresso'),
385
+					'<span class="send-selected-newsletter-count">0</span>'
386
+				);
387
+				echo '<button id="selected-batch-send-trigger" class="button secondary-button"><span class="dashicons dashicons-email "></span>'
388
+					 . $button_text
389
+					 . '</button>';
390
+				add_action('admin_footer', array($this, 'newsletter_send_form_skeleton'));
391
+			}
392
+		}
393
+	}
394
+
395
+
396
+
397
+	public function newsletter_send_form_skeleton()
398
+	{
399
+		$list_table = $this->_list_table_object;
400
+		$codes = array();
401
+		//need to templates for the newsletter message type for the template selector.
402
+		$values[] = array('text' => __('Select Template to Use', 'event_espresso'), 'id' => 0);
403
+		$mtps = EEM_Message_Template_Group::instance()->get_all(
404
+			array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email'))
405
+		);
406
+		foreach ($mtps as $mtp) {
407
+			$name = $mtp->name();
408
+			$values[] = array(
409
+				'text' => empty($name) ? __('Global', 'event_espresso') : $name,
410
+				'id'   => $mtp->ID(),
411
+			);
412
+		}
413
+		//need to get a list of shortcodes that are available for the newsletter message type.
414
+		$shortcodes = EEH_MSG_Template::get_shortcodes('newsletter', 'email', array(), 'attendee', false);
415
+		foreach ($shortcodes as $field => $shortcode_array) {
416
+			$codes[$field] = implode(', ', array_keys($shortcode_array));
417
+		}
418
+		$shortcodes = $codes;
419
+		$form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php';
420
+		$form_template_args = array(
421
+			'form_action'       => admin_url('admin.php?page=espresso_registrations'),
422
+			'form_route'        => 'newsletter_selected_send',
423
+			'form_nonce_name'   => 'newsletter_selected_send_nonce',
424
+			'form_nonce'        => wp_create_nonce('newsletter_selected_send_nonce'),
425
+			'redirect_back_to'  => $this->_req_action,
426
+			'ajax_nonce'        => wp_create_nonce('get_newsletter_form_content_nonce'),
427
+			'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values),
428
+			'shortcodes'        => $shortcodes,
429
+			'id_type'           => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration',
430
+		);
431
+		EEH_Template::display_template($form_template, $form_template_args);
432
+	}
433
+
434
+
435
+
436
+	/**
437
+	 * Handles sending selected registrations/contacts a newsletter.
438
+	 *
439
+	 * @since  4.3.0
440
+	 * @return void
441
+	 * @throws \EE_Error
442
+	 */
443
+	protected function _newsletter_selected_send()
444
+	{
445
+		$success = true;
446
+		//first we need to make sure we have a GRP_ID so we know what template we're sending and updating!
447
+		if (empty($this->_req_data['newsletter_mtp_selected'])) {
448
+			EE_Error::add_error(
449
+				__(
450
+					'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.',
451
+					'event_espresso'
452
+				),
453
+				__FILE__,
454
+				__FUNCTION__,
455
+				__LINE__
456
+			);
457
+			$success = false;
458
+		}
459
+		if ($success) {
460
+			//update Message template in case there are any changes
461
+			$Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID(
462
+				$this->_req_data['newsletter_mtp_selected']
463
+			);
464
+			$Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group
465
+				? $Message_Template_Group->context_templates()
466
+				: array();
467
+			if (empty($Message_Templates)) {
468
+				EE_Error::add_error(
469
+					__(
470
+						'Unable to retrieve message template fields from the db. Messages not sent.',
471
+						'event_espresso'
472
+					),
473
+					__FILE__,
474
+					__FUNCTION__,
475
+					__LINE__
476
+				);
477
+			}
478
+			//let's just update the specific fields
479
+			foreach ($Message_Templates['attendee'] as $Message_Template) {
480
+				if ($Message_Template instanceof EE_Message_Template) {
481
+					$field = $Message_Template->get('MTP_template_field');
482
+					$content = $Message_Template->get('MTP_content');
483
+					$new_content = $content;
484
+					switch ($field) {
485
+						case 'from' :
486
+							$new_content = ! empty($this->_req_data['batch_message']['from'])
487
+								? $this->_req_data['batch_message']['from']
488
+								: $content;
489
+							break;
490
+						case 'subject' :
491
+							$new_content = ! empty($this->_req_data['batch_message']['subject'])
492
+								? $this->_req_data['batch_message']['subject']
493
+								: $content;
494
+							break;
495
+						case 'content' :
496
+							$new_content = $content;
497
+							$new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content'])
498
+								? $this->_req_data['batch_message']['content']
499
+								: $content['newsletter_content'];
500
+							break;
501
+						default :
502
+							//continue the foreach loop, we don't want to set $new_content nor save.
503
+							continue 2;
504
+					}
505
+					$Message_Template->set('MTP_content', $new_content);
506
+					$Message_Template->save();
507
+				}
508
+			}
509
+			//great fields are updated!  now let's make sure we just have contact objects (EE_Attendee).
510
+			$id_type = ! empty($this->_req_data['batch_message']['id_type'])
511
+				? $this->_req_data['batch_message']['id_type']
512
+				: 'registration';
513
+			//id_type will affect how we assemble the ids.
514
+			$ids = ! empty($this->_req_data['batch_message']['ids'])
515
+				? json_decode(stripslashes($this->_req_data['batch_message']['ids']))
516
+				: array();
517
+			$registrations_used_for_contact_data = array();
518
+			//using switch because eventually we'll have other contexts that will be used for generating messages.
519
+			switch ($id_type) {
520
+				case 'registration' :
521
+					$registrations_used_for_contact_data = EEM_Registration::instance()->get_all(
522
+						array(
523
+							array(
524
+								'REG_ID' => array('IN', $ids),
525
+							),
526
+						)
527
+					);
528
+					break;
529
+				case 'contact' :
530
+					$registrations_used_for_contact_data = EEM_Registration::instance()
531
+																		   ->get_latest_registration_for_each_of_given_contacts($ids);
532
+					break;
533
+			}
534
+			do_action(
535
+				'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
536
+				$registrations_used_for_contact_data,
537
+				$Message_Template_Group->ID()
538
+			);
539
+			//kept for backward compat, internally we no longer use this action.
540
+			//@deprecated 4.8.36.rc.002
541
+			$contacts = $id_type === 'registration'
542
+				? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids)
543
+				: EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids))));
544
+			do_action(
545
+				'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send',
546
+				$contacts,
547
+				$Message_Template_Group->ID()
548
+			);
549
+		}
550
+		$query_args = array(
551
+			'action' => ! empty($this->_req_data['redirect_back_to'])
552
+				? $this->_req_data['redirect_back_to']
553
+				: 'default',
554
+		);
555
+		$this->_redirect_after_action(false, '', '', $query_args, true);
556
+	}
557
+
558
+
559
+
560
+	/**
561
+	 * This is called when javascript is being enqueued to setup the various data needed for the reports js.
562
+	 * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method.
563
+	 */
564
+	protected function _registration_reports_js_setup()
565
+	{
566
+		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report();
567
+		$this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report();
568
+	}
569
+
570
+
571
+
572
+	/**
573
+	 *        generates Business Reports regarding Registrations
574
+	 *
575
+	 * @access protected
576
+	 * @return void
577
+	 */
578
+	protected function _registration_reports()
579
+	{
580
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php';
581
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
582
+			$template_path,
583
+			$this->_reports_template_data,
584
+			true
585
+		);
586
+		// the final template wrapper
587
+		$this->display_admin_page_with_no_sidebar();
588
+	}
589
+
590
+
591
+
592
+	/**
593
+	 * Generates Business Report showing total registrations per day.
594
+	 *
595
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
596
+	 * @return string
597
+	 */
598
+	private function _registrations_per_day_report($period = '-1 month')
599
+	{
600
+		$report_ID = 'reg-admin-registrations-per-day-report-dv';
601
+		$results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period);
602
+		$results = (array)$results;
603
+		$regs = array();
604
+		$subtitle = '';
605
+		if ($results) {
606
+			$column_titles = array();
607
+			$tracker = 0;
608
+			foreach ($results as $result) {
609
+				$report_column_values = array();
610
+				foreach ($result as $property_name => $property_value) {
611
+					$property_value = $property_name === 'Registration_REG_date' ? $property_value
612
+						: (int)$property_value;
613
+					$report_column_values[] = $property_value;
614
+					if ($tracker === 0) {
615
+						if ($property_name === 'Registration_REG_date') {
616
+							$column_titles[] = __('Date (only days with registrations are shown)', 'event_espresso');
617
+						} else {
618
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
619
+						}
620
+					}
621
+				}
622
+				$tracker++;
623
+				$regs[] = $report_column_values;
624
+			}
625
+			//make sure the column_titles is pushed to the beginning of the array
626
+			array_unshift($regs, $column_titles);
627
+			//setup the date range.
628
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
629
+			$beginning_date = new DateTime("now " . $period, $DateTimeZone);
630
+			$ending_date = new DateTime("now", $DateTimeZone);
631
+			$subtitle = sprintf(
632
+				_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
633
+				$beginning_date->format('Y-m-d'),
634
+				$ending_date->format('Y-m-d')
635
+			);
636
+		}
637
+		$report_title = __('Total Registrations per Day', 'event_espresso');
638
+		$report_params = array(
639
+			'title'     => $report_title,
640
+			'subtitle'  => $subtitle,
641
+			'id'        => $report_ID,
642
+			'regs'      => $regs,
643
+			'noResults' => empty($regs),
644
+			'noRegsMsg' => sprintf(
645
+				__(
646
+					'%sThere are currently no registration records in the last month for this report.%s',
647
+					'event_espresso'
648
+				),
649
+				'<h2>' . $report_title . '</h2><p>',
650
+				'</p>'
651
+			),
652
+		);
653
+		wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params);
654
+		return $report_ID;
655
+	}
656
+
657
+
658
+
659
+	/**
660
+	 * Generates Business Report showing total registrations per event.
661
+	 *
662
+	 * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated.
663
+	 * @return string
664
+	 */
665
+	private function _registrations_per_event_report($period = '-1 month')
666
+	{
667
+		$report_ID = 'reg-admin-registrations-per-event-report-dv';
668
+		$results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period);
669
+		$results = (array)$results;
670
+		$regs = array();
671
+		$subtitle = '';
672
+		if ($results) {
673
+			$column_titles = array();
674
+			$tracker = 0;
675
+			foreach ($results as $result) {
676
+				$report_column_values = array();
677
+				foreach ($result as $property_name => $property_value) {
678
+					$property_value = $property_name === 'Registration_Event' ? wp_trim_words(
679
+						$property_value,
680
+						4,
681
+						'...'
682
+					) : (int)$property_value;
683
+					$report_column_values[] = $property_value;
684
+					if ($tracker === 0) {
685
+						if ($property_name === 'Registration_Event') {
686
+							$column_titles[] = __('Event', 'event_espresso');
687
+						} else {
688
+							$column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence');
689
+						}
690
+					}
691
+				}
692
+				$tracker++;
693
+				$regs[] = $report_column_values;
694
+			}
695
+			//make sure the column_titles is pushed to the beginning of the array
696
+			array_unshift($regs, $column_titles);
697
+			//setup the date range.
698
+			$DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone());
699
+			$beginning_date = new DateTime("now " . $period, $DateTimeZone);
700
+			$ending_date = new DateTime("now", $DateTimeZone);
701
+			$subtitle = sprintf(
702
+				_x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'),
703
+				$beginning_date->format('Y-m-d'),
704
+				$ending_date->format('Y-m-d')
705
+			);
706
+		}
707
+		$report_title = __('Total Registrations per Event', 'event_espresso');
708
+		$report_params = array(
709
+			'title'     => $report_title,
710
+			'subtitle'  => $subtitle,
711
+			'id'        => $report_ID,
712
+			'regs'      => $regs,
713
+			'noResults' => empty($regs),
714
+			'noRegsMsg' => sprintf(
715
+				__(
716
+					'%sThere are currently no registration records in the last month for this report.%s',
717
+					'event_espresso'
718
+				),
719
+				'<h2>' . $report_title . '</h2><p>',
720
+				'</p>'
721
+			),
722
+		);
723
+		wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params);
724
+		return $report_ID;
725
+	}
726
+
727
+
728
+
729
+	/**
730
+	 * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration)
731
+	 *
732
+	 * @access protected
733
+	 * @return void
734
+	 * @throws \EE_Error
735
+	 */
736
+	protected function _registration_checkin_list_table()
737
+	{
738
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
739
+		$reg_id = isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : null;
740
+		/** @var EE_Registration $registration */
741
+		$registration = EEM_Registration::instance()->get_one_by_ID($reg_id);
742
+		$attendee = $registration->attendee();
743
+		$this->_admin_page_title .= $this->get_action_link_or_button(
744
+			'new_registration',
745
+			'add-registrant',
746
+			array('event_id' => $registration->event_ID()),
747
+			'add-new-h2'
748
+		);
749
+		$checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
750
+		$checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
751
+		$legend_items = array(
752
+			'checkin'  => array(
753
+				'class' => $checked_in->cssClasses(),
754
+				'desc'  => $checked_in->legendLabel(),
755
+			),
756
+			'checkout' => array(
757
+				'class' => $checked_out->cssClasses(),
758
+				'desc'  => $checked_out->legendLabel(),
759
+			),
760
+		);
761
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
762
+		$dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
763
+		/** @var EE_Datetime $datetime */
764
+		$datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id);
765
+		$datetime_label = '';
766
+		if ($datetime instanceof EE_Datetime) {
767
+			$datetime_label = $datetime->get_dtt_display_name(true);
768
+			$datetime_label .= ! empty($datetime_label)
769
+				? ' (' . $datetime->get_dtt_display_name() . ')'
770
+				: $datetime->get_dtt_display_name();
771
+		}
772
+		$datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration
773
+			? EE_Admin_Page::add_query_args_and_nonce(
774
+				array(
775
+					'action'   => 'event_registrations',
776
+					'event_id' => $registration->event_ID(),
777
+					'DTT_ID'   => $dtt_id,
778
+				),
779
+				$this->_admin_base_url
780
+			)
781
+			: '';
782
+		$datetime_link = ! empty($datetime_link)
783
+			? '<a href="' . $datetime_link . '">'
784
+			  . '<span id="checkin-dtt">'
785
+			  . $datetime_label
786
+			  . '</span></a>'
787
+			: $datetime_label;
788
+		$attendee_name = $attendee instanceof EE_Attendee
789
+			? $attendee->full_name()
790
+			: '';
791
+		$attendee_link = $attendee instanceof EE_Attendee
792
+			? $attendee->get_admin_details_link()
793
+			: '';
794
+		$attendee_link = ! empty($attendee_link)
795
+			? '<a href="' . $attendee->get_admin_details_link() . '"'
796
+			  . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">'
797
+			  . '<span id="checkin-attendee-name">'
798
+			  . $attendee_name
799
+			  . '</span></a>'
800
+			: '';
801
+		$event_link = $registration->event() instanceof EE_Event
802
+			? $registration->event()->get_admin_details_link()
803
+			: '';
804
+		$event_link = ! empty($event_link)
805
+			? '<a href="' . $event_link . '"'
806
+			  . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">'
807
+			  . '<span id="checkin-event-name">'
808
+			  . $registration->event_name()
809
+			  . '</span>'
810
+			  . '</a>'
811
+			: '';
812
+		$this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id)
813
+			? '<h2>' . sprintf(
814
+				esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'),
815
+				$attendee_link,
816
+				$datetime_link,
817
+				$event_link
818
+			) . '</h2>'
819
+			: '';
820
+		$this->_template_args['list_table_hidden_fields'] = ! empty($reg_id)
821
+			? '<input type="hidden" name="_REGID" value="' . $reg_id . '">' : '';
822
+		$this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id)
823
+			? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : '';
824
+		$this->display_admin_list_table_page_with_no_sidebar();
825
+	}
826
+
827
+
828
+
829
+	/**
830
+	 * toggle the Check-in status for the given registration (coming from ajax)
831
+	 *
832
+	 * @return void (JSON)
833
+	 */
834
+	public function toggle_checkin_status()
835
+	{
836
+		//first make sure we have the necessary data
837
+		if ( ! isset($this->_req_data['_regid'])) {
838
+			EE_Error::add_error(
839
+				__(
840
+					'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax',
841
+					'event_espresso'
842
+				),
843
+				__FILE__,
844
+				__FUNCTION__,
845
+				__LINE__
846
+			);
847
+			$this->_template_args['success'] = false;
848
+			$this->_template_args['error'] = true;
849
+			$this->_return_json();
850
+		};
851
+		//do a nonce check cause we're not coming in from an normal route here.
852
+		$nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce'])
853
+			: '';
854
+		$nonce_ref = 'checkin_nonce';
855
+		$this->_verify_nonce($nonce, $nonce_ref);
856
+		//beautiful! Made it this far so let's get the status.
857
+		$new_status = new CheckinStatusDashicon($this->_toggle_checkin_status());
858
+		//setup new class to return via ajax
859
+		$this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses();
860
+		$this->_template_args['success'] = true;
861
+		$this->_return_json();
862
+	}
863
+
864
+
865
+
866
+	/**
867
+	 * handles toggling the checkin status for the registration,
868
+	 *
869
+	 * @access protected
870
+	 * @return int|void
871
+	 */
872
+	protected function _toggle_checkin_status()
873
+	{
874
+		//first let's get the query args out of the way for the redirect
875
+		$query_args = array(
876
+			'action'   => 'event_registrations',
877
+			'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null,
878
+			'DTT_ID'   => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null,
879
+		);
880
+		$new_status = false;
881
+		// bulk action check in toggle
882
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
883
+			// cycle thru checkboxes
884
+			while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) {
885
+				$DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null;
886
+				$new_status = $this->_toggle_checkin($REG_ID, $DTT_ID);
887
+			}
888
+		} elseif (isset($this->_req_data['_regid'])) {
889
+			//coming from ajax request
890
+			$DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null;
891
+			$query_args['DTT_ID'] = $DTT_ID;
892
+			$new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID);
893
+		} else {
894
+			EE_Error::add_error(
895
+				__('Missing some required data to toggle the Check-in', 'event_espresso'),
896
+				__FILE__,
897
+				__FUNCTION__,
898
+				__LINE__
899
+			);
900
+		}
901
+		if (defined('DOING_AJAX')) {
902
+			return $new_status;
903
+		}
904
+		$this->_redirect_after_action(false, '', '', $query_args, true);
905
+	}
906
+
907
+
908
+
909
+	/**
910
+	 * This is toggles a single Check-in for the given registration and datetime.
911
+	 *
912
+	 * @param  int $REG_ID The registration we're toggling
913
+	 * @param  int $DTT_ID The datetime we're toggling
914
+	 * @return int            The new status toggled to.
915
+	 * @throws \EE_Error
916
+	 */
917
+	private function _toggle_checkin($REG_ID, $DTT_ID)
918
+	{
919
+		/** @var EE_Registration $REG */
920
+		$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
921
+		$new_status = $REG->toggle_checkin_status($DTT_ID);
922
+		if ($new_status !== false) {
923
+			EE_Error::add_success($REG->get_checkin_msg($DTT_ID));
924
+		} else {
925
+			EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__);
926
+			$new_status = false;
927
+		}
928
+		return $new_status;
929
+	}
930
+
931
+
932
+
933
+	/**
934
+	 * Takes care of deleting multiple EE_Checkin table rows
935
+	 *
936
+	 * @access protected
937
+	 * @return void
938
+	 * @throws \EE_Error
939
+	 */
940
+	protected function _delete_checkin_rows()
941
+	{
942
+		$query_args = array(
943
+			'action' => 'registration_checkins',
944
+			'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
945
+			'_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0,
946
+		);
947
+		$errors = 0;
948
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
949
+			while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) {
950
+				if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) {
951
+					$errors++;
952
+				}
953
+			}
954
+		} else {
955
+			EE_Error::add_error(
956
+				__(
957
+					'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!',
958
+					'event_espresso'
959
+				),
960
+				__FILE__,
961
+				__FUNCTION__,
962
+				__LINE__
963
+			);
964
+			$this->_redirect_after_action(false, '', '', $query_args, true);
965
+		}
966
+		if ($errors > 0) {
967
+			EE_Error::add_error(
968
+				sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors),
969
+				__FILE__,
970
+				__FUNCTION__,
971
+				__LINE__
972
+			);
973
+		} else {
974
+			EE_Error::add_success(__('Records were successfully deleted', 'event_espresso'));
975
+		}
976
+		$this->_redirect_after_action(false, '', '', $query_args, true);
977
+	}
978
+
979
+
980
+
981
+	/**
982
+	 * Deletes a single EE_Checkin row
983
+	 *
984
+	 * @return void
985
+	 * @throws \EE_Error
986
+	 */
987
+	protected function _delete_checkin_row()
988
+	{
989
+		$query_args = array(
990
+			'action' => 'registration_checkins',
991
+			'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0,
992
+			'_REGID' => isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : 0,
993
+		);
994
+		if ( ! empty($this->_req_data['CHK_ID'])) {
995
+			if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) {
996
+				EE_Error::add_error(
997
+					__('Something went wrong and this check-in record was not deleted', 'event_espresso'),
998
+					__FILE__,
999
+					__FUNCTION__,
1000
+					__LINE__
1001
+				);
1002
+			} else {
1003
+				EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso'));
1004
+			}
1005
+		} else {
1006
+			EE_Error::add_error(
1007
+				__(
1008
+					'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code',
1009
+					'event_espresso'
1010
+				),
1011
+				__FILE__,
1012
+				__FUNCTION__,
1013
+				__LINE__
1014
+			);
1015
+		}
1016
+		$this->_redirect_after_action(false, '', '', $query_args, true);
1017
+	}
1018
+
1019
+
1020
+
1021
+	/**
1022
+	 *        generates HTML for the Event Registrations List Table
1023
+	 *
1024
+	 * @access protected
1025
+	 * @return void
1026
+	 * @throws \EE_Error
1027
+	 */
1028
+	protected function _event_registrations_list_table()
1029
+	{
1030
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1031
+		$this->_admin_page_title .= isset($this->_req_data['event_id'])
1032
+			? $this->get_action_link_or_button(
1033
+				'new_registration',
1034
+				'add-registrant',
1035
+				array('event_id' => $this->_req_data['event_id']),
1036
+				'add-new-h2',
1037
+				'',
1038
+				false
1039
+			)
1040
+			: '';
1041
+		$checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in);
1042
+		$checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out);
1043
+		$checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never);
1044
+		$legend_items = array(
1045
+			'star-icon'        => array(
1046
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
1047
+				'desc'  => __('This Registrant is the Primary Registrant', 'event_espresso'),
1048
+			),
1049
+			'checkin'          => array(
1050
+				'class' => $checked_in->cssClasses(),
1051
+				'desc'  => $checked_in->legendLabel(),
1052
+			),
1053
+			'checkout'         => array(
1054
+				'class' => $checked_out->cssClasses(),
1055
+				'desc'  => $checked_out->legendLabel(),
1056
+			),
1057
+			'nocheckinrecord'  => array(
1058
+				'class' => $checked_never->cssClasses(),
1059
+				'desc'  => $checked_never->legendLabel(),
1060
+			),
1061
+			'view_details'     => array(
1062
+				'class' => 'dashicons dashicons-search',
1063
+				'desc'  => __('View All Check-in Records for this Registrant', 'event_espresso'),
1064
+			),
1065
+			'approved_status'  => array(
1066
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
1067
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
1068
+			),
1069
+			'cancelled_status' => array(
1070
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1071
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
1072
+			),
1073
+			'declined_status'  => array(
1074
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
1075
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
1076
+			),
1077
+			'not_approved'     => array(
1078
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
1079
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
1080
+			),
1081
+			'pending_status'   => array(
1082
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
1083
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
1084
+			),
1085
+			'wait_list'        => array(
1086
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
1087
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
1088
+			),
1089
+		);
1090
+		$this->_template_args['after_list_table'] = $this->_display_legend($legend_items);
1091
+		$event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null;
1092
+		$this->_template_args['before_list_table'] = ! empty($event_id)
1093
+			? '<h2>' . sprintf(
1094
+				__('Viewing Registrations for Event: %s', 'event_espresso'),
1095
+				EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name')
1096
+			) . '</h2>'
1097
+			: '';
1098
+		//need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on the event.
1099
+		/** @var EE_Event $event */
1100
+		$event = EEM_Event::instance()->get_one_by_ID($event_id);
1101
+		$DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0;
1102
+		$datetime = null;
1103
+		if ($event instanceof EE_Event) {
1104
+			$datetimes_on_event = $event->datetimes();
1105
+			if (count($datetimes_on_event) === 1) {
1106
+				$datetime = reset($datetimes_on_event);
1107
+			}
1108
+		}
1109
+		$datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1110
+		if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') {
1111
+			$this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5);
1112
+			$this->_template_args['before_list_table'] .= ' &nbsp;<span class="drk-grey-text">';
1113
+			$this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>';
1114
+			$this->_template_args['before_list_table'] .= $datetime->name();
1115
+			$this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )';
1116
+			$this->_template_args['before_list_table'] .= '</span></h2>';
1117
+		}
1118
+		//if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status column
1119
+		//represents
1120
+		if ( ! $datetime instanceof EE_Datetime) {
1121
+			$this->_template_args['before_list_table'] .= '<br><p class="description">'
1122
+														  . __('In this view, the check-in status represents the latest check-in record for the registration in that row.',
1123
+					'event_espresso')
1124
+														  . '</p>';
1125
+		}
1126
+		$this->display_admin_list_table_page_with_no_sidebar();
1127
+	}
1128
+
1129
+	/**
1130
+	 * Download the registrations check-in report (same as the normal registration report, but with different where
1131
+	 * conditions)
1132
+	 *
1133
+	 * @return void ends the request by a redirect or download
1134
+	 */
1135
+	public function _registrations_checkin_report()
1136
+	{
1137
+		$this->_registrations_report_base('_get_checkin_query_params_from_request');
1138
+	}
1139
+
1140
+	/**
1141
+	 * Gets the query params from the request, plus adds a where condition for the registration status,
1142
+	 * because on the checkin page we only ever want to see approved and pending-approval registrations
1143
+	 *
1144
+	 * @param array     $request
1145
+	 * @param int  $per_page
1146
+	 * @param bool $count
1147
+	 * @return array
1148
+	 */
1149
+	protected function _get_checkin_query_params_from_request(
1150
+		$request,
1151
+		$per_page = 10,
1152
+		$count = false
1153
+	) {
1154
+		$query_params = $this->_get_registration_query_parameters($request, $per_page, $count);
1155
+		//unlike the regular registrations list table,
1156
+		$status_ids_array = apply_filters(
1157
+			'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array',
1158
+			array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved)
1159
+		);
1160
+		$query_params[0]['STS_ID'] = array('IN', $status_ids_array);
1161
+		return $query_params;
1162
+	}
1163
+
1164
+
1165
+
1166
+
1167
+	/**
1168
+	 * Gets registrations for an event
1169
+	 *
1170
+	 * @param int    $per_page
1171
+	 * @param bool   $count whether to return count or data.
1172
+	 * @param bool   $trash
1173
+	 * @param string $orderby
1174
+	 * @return EE_Registration[]|int
1175
+	 * @throws \EE_Error
1176
+	 */
1177
+	public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname')
1178
+	{
1179
+		//normalize some request params that get setup by the parent `get_registrations` method.
1180
+		$request = $this->_req_data;
1181
+		$request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby;
1182
+		$request['order'] =  ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC';
1183
+		if($trash){
1184
+			$request['status'] = 'trash';
1185
+		}
1186
+		$query_params = $this->_get_checkin_query_params_from_request( $request, $per_page, $count );
1187
+		/**
1188
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1189
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1190
+		 * @see EEM_Base::get_all()
1191
+		 */
1192
+		$query_params['group_by'] = '';
1193
+
1194
+		return $count
1195
+			? EEM_Registration::instance()->count($query_params)
1196
+			/** @type EE_Registration[] */
1197
+			: EEM_Registration::instance()->get_all($query_params);
1198
+	}
1199 1199
 
1200 1200
 
1201 1201
 } //end class Registrations Admin Page
Please login to merge, or discard this patch.