Completed
Branch updates-from-cafe (c7978b)
by
unknown
23:42 queued 17:07
created
caffeinated/core/domain/services/pue/RegisterAddonPUE.php 2 patches
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -12,98 +12,98 @@
 block discarded – undo
12 12
 
13 13
 class RegisterAddonPUE
14 14
 {
15
-    /**
16
-     * @var array
17
-     */
18
-    private static $addon_api_settings;
15
+	/**
16
+	 * @var array
17
+	 */
18
+	private static $addon_api_settings;
19 19
 
20 20
 
21
-    public static function registerPUE(
22
-        array $addon_api_settings,
23
-        string $addon_name,
24
-        string $class_name,
25
-        array $addon_args
26
-    ): array {
27
-        if (! empty($addon_args['pue_options'])) {
28
-            $addon_api_settings[ $addon_name ]['pue_options'] = [
29
-                'pue_plugin_slug' => isset($addon_args['pue_options']['pue_plugin_slug'])
30
-                    ? (string) $addon_args['pue_options']['pue_plugin_slug']
31
-                    : 'espresso_' . strtolower($class_name),
32
-                'plugin_basename' => isset($addon_args['pue_options']['plugin_basename'])
33
-                    ? (string) $addon_args['pue_options']['plugin_basename']
34
-                    : plugin_basename($addon_args['main_file_path']),
35
-                'checkPeriod'     => isset($addon_args['pue_options']['checkPeriod'])
36
-                    ? (string) $addon_args['pue_options']['checkPeriod']
37
-                    : '24',
38
-                'use_wp_update'   => isset($addon_args['pue_options']['use_wp_update'])
39
-                    ? (string) $addon_args['pue_options']['use_wp_update']
40
-                    : false,
41
-            ];
42
-            add_action(
43
-                'AHEE__EE_System__brew_espresso__after_pue_init',
44
-                [RegisterAddonPUE::class, 'loadPueUpdate']
45
-            );
46
-        }
47
-        RegisterAddonPUE::$addon_api_settings = $addon_api_settings;
48
-        return $addon_api_settings;
49
-    }
21
+	public static function registerPUE(
22
+		array $addon_api_settings,
23
+		string $addon_name,
24
+		string $class_name,
25
+		array $addon_args
26
+	): array {
27
+		if (! empty($addon_args['pue_options'])) {
28
+			$addon_api_settings[ $addon_name ]['pue_options'] = [
29
+				'pue_plugin_slug' => isset($addon_args['pue_options']['pue_plugin_slug'])
30
+					? (string) $addon_args['pue_options']['pue_plugin_slug']
31
+					: 'espresso_' . strtolower($class_name),
32
+				'plugin_basename' => isset($addon_args['pue_options']['plugin_basename'])
33
+					? (string) $addon_args['pue_options']['plugin_basename']
34
+					: plugin_basename($addon_args['main_file_path']),
35
+				'checkPeriod'     => isset($addon_args['pue_options']['checkPeriod'])
36
+					? (string) $addon_args['pue_options']['checkPeriod']
37
+					: '24',
38
+				'use_wp_update'   => isset($addon_args['pue_options']['use_wp_update'])
39
+					? (string) $addon_args['pue_options']['use_wp_update']
40
+					: false,
41
+			];
42
+			add_action(
43
+				'AHEE__EE_System__brew_espresso__after_pue_init',
44
+				[RegisterAddonPUE::class, 'loadPueUpdate']
45
+			);
46
+		}
47
+		RegisterAddonPUE::$addon_api_settings = $addon_api_settings;
48
+		return $addon_api_settings;
49
+	}
50 50
 
51 51
 
52
-    public static function setAddonPueSlug(EE_Addon $addon, string $addon_name)
53
-    {
54
-        // setup the add-on's pue_slug if we have one.
55
-        if (! empty($addon_api_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) {
56
-            $addon->setPueSlug($addon_api_settings[ $addon_name ]['pue_options']['pue_plugin_slug']);
57
-        }
58
-    }
52
+	public static function setAddonPueSlug(EE_Addon $addon, string $addon_name)
53
+	{
54
+		// setup the add-on's pue_slug if we have one.
55
+		if (! empty($addon_api_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) {
56
+			$addon->setPueSlug($addon_api_settings[ $addon_name ]['pue_options']['pue_plugin_slug']);
57
+		}
58
+	}
59 59
 
60 60
 
61
-    /**
62
-     *    load_pue_update - Update notifications
63
-     *
64
-     * @return void
65
-     * @throws InvalidArgumentException
66
-     * @throws InvalidDataTypeException
67
-     * @throws InvalidInterfaceException
68
-     */
69
-    public static function loadPueUpdate()
70
-    {
71
-        // PUE client existence
72
-        if (! is_readable(EE_THIRD_PARTY . 'pue/pue-client.php')) {
73
-            return;
74
-        }
61
+	/**
62
+	 *    load_pue_update - Update notifications
63
+	 *
64
+	 * @return void
65
+	 * @throws InvalidArgumentException
66
+	 * @throws InvalidDataTypeException
67
+	 * @throws InvalidInterfaceException
68
+	 */
69
+	public static function loadPueUpdate()
70
+	{
71
+		// PUE client existence
72
+		if (! is_readable(EE_THIRD_PARTY . 'pue/pue-client.php')) {
73
+			return;
74
+		}
75 75
 
76
-        /** @var EE_Network_Config $network_config */
77
-        $network_config = LoaderFactory::getLoader()->getShared('EE_Network_Config');
78
-        // load PUE client
79
-        require_once EE_THIRD_PARTY . 'pue/pue-client.php';
80
-        $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com';
81
-        // cycle thru settings
82
-        foreach (RegisterAddonPUE::$addon_api_settings as $settings) {
83
-            if (empty($settings['pue_options'])) {
84
-                continue;
85
-            }
86
-            // initiate the class and start the plugin update engine!
87
-            new PluginUpdateEngineChecker(
88
-            // host file URL
89
-                $license_server,
90
-                // plugin slug(s)
91
-                [
92
-                    'premium'    => ['p' => $settings['pue_options']['pue_plugin_slug']],
93
-                    'prerelease' => ['beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'],
94
-                ],
95
-                // options
96
-                [
97
-                    'apikey'            => $network_config->core->site_license_key,
98
-                    'lang_domain'       => 'event_espresso',
99
-                    'checkPeriod'       => $settings['pue_options']['checkPeriod'],
100
-                    'option_key'        => 'ee_site_license_key',
101
-                    'options_page_slug' => 'event_espresso',
102
-                    'plugin_basename'   => $settings['pue_options']['plugin_basename'],
103
-                    // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP
104
-                    'use_wp_update'     => $settings['pue_options']['use_wp_update'],
105
-                ]
106
-            );
107
-        }
108
-    }
76
+		/** @var EE_Network_Config $network_config */
77
+		$network_config = LoaderFactory::getLoader()->getShared('EE_Network_Config');
78
+		// load PUE client
79
+		require_once EE_THIRD_PARTY . 'pue/pue-client.php';
80
+		$license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com';
81
+		// cycle thru settings
82
+		foreach (RegisterAddonPUE::$addon_api_settings as $settings) {
83
+			if (empty($settings['pue_options'])) {
84
+				continue;
85
+			}
86
+			// initiate the class and start the plugin update engine!
87
+			new PluginUpdateEngineChecker(
88
+			// host file URL
89
+				$license_server,
90
+				// plugin slug(s)
91
+				[
92
+					'premium'    => ['p' => $settings['pue_options']['pue_plugin_slug']],
93
+					'prerelease' => ['beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'],
94
+				],
95
+				// options
96
+				[
97
+					'apikey'            => $network_config->core->site_license_key,
98
+					'lang_domain'       => 'event_espresso',
99
+					'checkPeriod'       => $settings['pue_options']['checkPeriod'],
100
+					'option_key'        => 'ee_site_license_key',
101
+					'options_page_slug' => 'event_espresso',
102
+					'plugin_basename'   => $settings['pue_options']['plugin_basename'],
103
+					// if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP
104
+					'use_wp_update'     => $settings['pue_options']['use_wp_update'],
105
+				]
106
+			);
107
+		}
108
+	}
109 109
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -24,11 +24,11 @@  discard block
 block discarded – undo
24 24
         string $class_name,
25 25
         array $addon_args
26 26
     ): array {
27
-        if (! empty($addon_args['pue_options'])) {
28
-            $addon_api_settings[ $addon_name ]['pue_options'] = [
27
+        if ( ! empty($addon_args['pue_options'])) {
28
+            $addon_api_settings[$addon_name]['pue_options'] = [
29 29
                 'pue_plugin_slug' => isset($addon_args['pue_options']['pue_plugin_slug'])
30 30
                     ? (string) $addon_args['pue_options']['pue_plugin_slug']
31
-                    : 'espresso_' . strtolower($class_name),
31
+                    : 'espresso_'.strtolower($class_name),
32 32
                 'plugin_basename' => isset($addon_args['pue_options']['plugin_basename'])
33 33
                     ? (string) $addon_args['pue_options']['plugin_basename']
34 34
                     : plugin_basename($addon_args['main_file_path']),
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
     public static function setAddonPueSlug(EE_Addon $addon, string $addon_name)
53 53
     {
54 54
         // setup the add-on's pue_slug if we have one.
55
-        if (! empty($addon_api_settings[ $addon_name ]['pue_options']['pue_plugin_slug'])) {
56
-            $addon->setPueSlug($addon_api_settings[ $addon_name ]['pue_options']['pue_plugin_slug']);
55
+        if ( ! empty($addon_api_settings[$addon_name]['pue_options']['pue_plugin_slug'])) {
56
+            $addon->setPueSlug($addon_api_settings[$addon_name]['pue_options']['pue_plugin_slug']);
57 57
         }
58 58
     }
59 59
 
@@ -69,14 +69,14 @@  discard block
 block discarded – undo
69 69
     public static function loadPueUpdate()
70 70
     {
71 71
         // PUE client existence
72
-        if (! is_readable(EE_THIRD_PARTY . 'pue/pue-client.php')) {
72
+        if ( ! is_readable(EE_THIRD_PARTY.'pue/pue-client.php')) {
73 73
             return;
74 74
         }
75 75
 
76 76
         /** @var EE_Network_Config $network_config */
77 77
         $network_config = LoaderFactory::getLoader()->getShared('EE_Network_Config');
78 78
         // load PUE client
79
-        require_once EE_THIRD_PARTY . 'pue/pue-client.php';
79
+        require_once EE_THIRD_PARTY.'pue/pue-client.php';
80 80
         $license_server = defined('PUE_UPDATES_ENDPOINT') ? PUE_UPDATES_ENDPOINT : 'https://eventespresso.com';
81 81
         // cycle thru settings
82 82
         foreach (RegisterAddonPUE::$addon_api_settings as $settings) {
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
                 // plugin slug(s)
91 91
                 [
92 92
                     'premium'    => ['p' => $settings['pue_options']['pue_plugin_slug']],
93
-                    'prerelease' => ['beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'],
93
+                    'prerelease' => ['beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'],
94 94
                 ],
95 95
                 // options
96 96
                 [
Please login to merge, or discard this patch.
caffeinated/core/domain/services/pue/StatsGatherer.php 2 patches
Indentation   +265 added lines, -265 removed lines patch added patch discarded remove patch
@@ -15,288 +15,288 @@
 block discarded – undo
15 15
 
16 16
 class StatsGatherer
17 17
 {
18
-    public const COUNT_ALL_EVENTS                 = 'event';
18
+	public const COUNT_ALL_EVENTS                 = 'event';
19 19
 
20
-    public const COUNT_ACTIVE_EVENTS              = 'active_event';
20
+	public const COUNT_ACTIVE_EVENTS              = 'active_event';
21 21
 
22
-    public const COUNT_DATETIMES                  = 'datetime';
22
+	public const COUNT_DATETIMES                  = 'datetime';
23 23
 
24
-    public const COUNT_TICKETS                    = 'ticket';
24
+	public const COUNT_TICKETS                    = 'ticket';
25 25
 
26
-    public const COUNT_DATETIMES_SOLD             = 'datetime_sold';
26
+	public const COUNT_DATETIMES_SOLD             = 'datetime_sold';
27 27
 
28
-    public const COUNT_TICKETS_FREE               = 'free_ticket';
28
+	public const COUNT_TICKETS_FREE               = 'free_ticket';
29 29
 
30
-    public const COUNT_TICKETS_PAID               = 'paid_ticket';
30
+	public const COUNT_TICKETS_PAID               = 'paid_ticket';
31 31
 
32
-    public const COUNT_TICKETS_SOLD               = 'ticket_sold';
32
+	public const COUNT_TICKETS_SOLD               = 'ticket_sold';
33 33
 
34
-    public const COUNT_REGISTRATIONS_APPROVED     = 'registrations_approved';
34
+	public const COUNT_REGISTRATIONS_APPROVED     = 'registrations_approved';
35 35
 
36
-    public const COUNT_REGISTRATIONS_NOT_APPROVED = 'registrations_not_approved';
36
+	public const COUNT_REGISTRATIONS_NOT_APPROVED = 'registrations_not_approved';
37 37
 
38
-    public const COUNT_REGISTRATIONS_PENDING      = 'registrations_pending';
38
+	public const COUNT_REGISTRATIONS_PENDING      = 'registrations_pending';
39 39
 
40
-    public const COUNT_REGISTRATIONS_INCOMPLETE   = 'registrations_incomplete';
40
+	public const COUNT_REGISTRATIONS_INCOMPLETE   = 'registrations_incomplete';
41 41
 
42
-    public const COUNT_REGISTRATIONS_ALL          = 'registrations_all';
42
+	public const COUNT_REGISTRATIONS_ALL          = 'registrations_all';
43 43
 
44
-    public const COUNT_REGISTRATIONS_CANCELLED    = 'registrations_cancelled';
44
+	public const COUNT_REGISTRATIONS_CANCELLED    = 'registrations_cancelled';
45 45
 
46
-    public const COUNT_REGISTRATIONS_DECLINED     = 'registrations_declined';
46
+	public const COUNT_REGISTRATIONS_DECLINED     = 'registrations_declined';
47 47
 
48
-    public const SUM_TRANSACTIONS_COMPLETE_TOTAL  = 'transactions_complete_total_sum';
48
+	public const SUM_TRANSACTIONS_COMPLETE_TOTAL  = 'transactions_complete_total_sum';
49 49
 
50
-    public const SUM_TRANSACTIONS_ALL_PAID        = 'transactions_all_paid';
50
+	public const SUM_TRANSACTIONS_ALL_PAID        = 'transactions_all_paid';
51 51
 
52
-    public const INFO_SITE_CURRENCY               = 'site_currency';
52
+	public const INFO_SITE_CURRENCY               = 'site_currency';
53 53
 
54 54
 
55
-    /**
56
-     * @var EEM_Payment_Method
57
-     */
58
-    private EEM_Payment_Method $payment_method_model;
59
-
60
-
61
-    /**
62
-     * @var EEM_Event
63
-     */
64
-    private $event_model;
65
-
66
-    /**
67
-     * @var EEM_Datetime
68
-     */
69
-    private $datetime_model;
70
-
71
-
72
-    /**
73
-     * @var EEM_Ticket
74
-     */
75
-    private $ticket_model;
76
-
77
-
78
-    /**
79
-     * @var EEM_Registration
80
-     */
81
-    private $registration_model;
82
-
83
-
84
-    /**
85
-     * @var EEM_Transaction
86
-     */
87
-    private $transaction_model;
88
-
89
-
90
-    /**
91
-     * @var EE_Config
92
-     */
93
-    private $config;
94
-
95
-
96
-    /**
97
-     * StatsGatherer constructor.
98
-     *
99
-     * @param EEM_Payment_Method $payment_method_model
100
-     * @param EEM_Event          $event_model
101
-     * @param EEM_Datetime       $datetime_model
102
-     * @param EEM_Ticket         $ticket_model
103
-     * @param EEM_Registration   $registration_model
104
-     * @param EEM_Transaction    $transaction_model
105
-     * @param EE_Config          $config
106
-     */
107
-    public function __construct(
108
-        EEM_Payment_Method $payment_method_model,
109
-        EEM_Event $event_model,
110
-        EEM_Datetime $datetime_model,
111
-        EEM_Ticket $ticket_model,
112
-        EEM_Registration $registration_model,
113
-        EEM_Transaction $transaction_model,
114
-        EE_Config $config
115
-    ) {
116
-        $this->payment_method_model = $payment_method_model;
117
-        $this->event_model          = $event_model;
118
-        $this->datetime_model       = $datetime_model;
119
-        $this->ticket_model         = $ticket_model;
120
-        $this->registration_model   = $registration_model;
121
-        $this->transaction_model    = $transaction_model;
122
-        $this->config               = $config;
123
-    }
124
-
125
-
126
-    /**
127
-     * Return the stats array for PUE UXIP stats.
128
-     *
129
-     * @return array
130
-     */
131
-    public function stats(): array
132
-    {
133
-        global $wp_version;
134
-        $stats = $this->paymentMethodStats();
135
-        // a-ok so let's setup our stats.
136
-        $stats = array_merge(
137
-            $stats,
138
-            [
139
-                'is_multisite'                    => is_multisite() && is_main_site(),
140
-                'active_theme'                    => $this->getActiveThemeStat(),
141
-                'ee4_all_events_count'            => $this->getCountFor(self::COUNT_ALL_EVENTS),
142
-                'ee4_active_events_count'         => $this->getCountFor(self::COUNT_ACTIVE_EVENTS),
143
-                'all_dtts_count'                  => $this->getCountFor(self::COUNT_DATETIMES),
144
-                'dtt_sold'                        => $this->getCountFor(self::COUNT_DATETIMES_SOLD),
145
-                'all_tkt_count'                   => $this->getCountFor(self::COUNT_TICKETS),
146
-                'free_tkt_count'                  => $this->getCountFor(self::COUNT_TICKETS_FREE),
147
-                'paid_tkt_count'                  => $this->getCountFor(self::COUNT_TICKETS_PAID),
148
-                'tkt_sold'                        => $this->getCountFor(self::COUNT_TICKETS_SOLD),
149
-                'approve_registration_count'      => $this->getCountFor(self::COUNT_REGISTRATIONS_APPROVED),
150
-                'pending_registration_count'      => $this->getCountFor(self::COUNT_REGISTRATIONS_PENDING),
151
-                'not_approved_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_NOT_APPROVED),
152
-                'incomplete_registration_count'   => $this->getCountFor(self::COUNT_REGISTRATIONS_INCOMPLETE),
153
-                'cancelled_registration_count'    => $this->getCountFor(self::COUNT_REGISTRATIONS_CANCELLED),
154
-                'declined_registration_count'     => $this->getCountFor(self::COUNT_REGISTRATIONS_DECLINED),
155
-                'all_registration_count'          => $this->getCountFor(self::COUNT_REGISTRATIONS_ALL),
156
-                'completed_transaction_total_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_COMPLETE_TOTAL),
157
-                'all_transaction_paid_sum'        => $this->getCountFor(self::SUM_TRANSACTIONS_ALL_PAID),
158
-                self::INFO_SITE_CURRENCY          => $this->config->currency instanceof EE_Currency_Config
159
-                    ? $this->config->currency->code
160
-                    : 'unknown',
161
-                'phpversion'                      => implode(
162
-                    '.',
163
-                    [PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION]
164
-                ),
165
-                'wpversion'                       => $wp_version,
166
-                'active_addons'                   => $this->getActiveAddons(),
167
-            ]
168
-        );
169
-        // remove any values that equal null.  This ensures any stats that weren't retrieved successfully are excluded.
170
-        return array_filter($stats, function ($value) {
171
-            return $value !== null;
172
-        });
173
-    }
174
-
175
-
176
-    /**
177
-     * @param string $which enum (@see constants prefixed with COUNT)
178
-     * @return int|null
179
-     */
180
-    private function getCountFor(string $which): ?int
181
-    {
182
-        try {
183
-            switch ($which) {
184
-                case self::COUNT_ALL_EVENTS:
185
-                    $count = $this->event_model->count();
186
-                    break;
187
-                case self::COUNT_TICKETS:
188
-                    $count = $this->ticket_model->count();
189
-                    break;
190
-                case self::COUNT_DATETIMES:
191
-                    $count = $this->datetime_model->count();
192
-                    break;
193
-                case self::COUNT_ACTIVE_EVENTS:
194
-                    $count = $this->event_model->get_active_events([], true);
195
-                    break;
196
-                case self::COUNT_DATETIMES_SOLD:
197
-                    $count = $this->datetime_model->sum([], 'DTT_sold');
198
-                    break;
199
-                case self::COUNT_TICKETS_FREE:
200
-                    $count = $this->ticket_model->count([['TKT_price' => 0]]);
201
-                    break;
202
-                case self::COUNT_TICKETS_PAID:
203
-                    $count = $this->ticket_model->count([['TKT_price' => ['>', 0]]]);
204
-                    break;
205
-                case self::COUNT_TICKETS_SOLD:
206
-                    $count = $this->ticket_model->sum([], 'TKT_sold');
207
-                    break;
208
-                case self::COUNT_REGISTRATIONS_ALL:
209
-                    $count = $this->registration_model->count();
210
-                    break;
211
-                case self::COUNT_REGISTRATIONS_CANCELLED:
212
-                    $count = $this->registration_model->count([['STS_ID' => EEM_Registration::status_id_cancelled]]);
213
-                    break;
214
-                case self::COUNT_REGISTRATIONS_INCOMPLETE:
215
-                    $count = $this->registration_model->count([['STS_ID' => EEM_Registration::status_id_incomplete]]);
216
-                    break;
217
-                case self::COUNT_REGISTRATIONS_NOT_APPROVED:
218
-                    $count = $this->registration_model->count([['STS_ID' => EEM_Registration::status_id_not_approved]]);
219
-                    break;
220
-                case self::COUNT_REGISTRATIONS_DECLINED:
221
-                    $count = $this->registration_model->count([['STS_ID' => EEM_Registration::status_id_declined]]);
222
-                    break;
223
-                case self::COUNT_REGISTRATIONS_PENDING:
224
-                    $count = $this->registration_model->count(
225
-                        [['STS_ID' => EEM_Registration::status_id_pending_payment]]
226
-                    );
227
-                    break;
228
-                case self::COUNT_REGISTRATIONS_APPROVED:
229
-                    $count = $this->registration_model->count([['STS_ID' => EEM_Registration::status_id_approved]]);
230
-                    break;
231
-                case self::SUM_TRANSACTIONS_COMPLETE_TOTAL:
232
-                    $count = $this->transaction_model->sum(
233
-                        [['STS_ID' => EEM_Transaction::complete_status_code]],
234
-                        'TXN_total'
235
-                    );
236
-                    break;
237
-                case self::SUM_TRANSACTIONS_ALL_PAID:
238
-                    $count = $this->transaction_model->sum([], 'TXN_paid');
239
-                    break;
240
-                default:
241
-                    $count = null;
242
-                    break;
243
-            }
244
-        } catch (Exception $e) {
245
-            $count = null;
246
-        }
247
-        return $count;
248
-    }
249
-
250
-
251
-    /**
252
-     * Return the active theme.
253
-     *
254
-     * @return false|string
255
-     */
256
-    private function getActiveThemeStat()
257
-    {
258
-        $theme = wp_get_theme();
259
-        return $theme->get('Name');
260
-    }
261
-
262
-
263
-    /**
264
-     * @return array
265
-     */
266
-    private function paymentMethodStats(): array
267
-    {
268
-        $payment_method_stats = [];
269
-        try {
270
-            $active_payment_methods = $this->payment_method_model->get_all_active(
271
-                null,
272
-                ['group_by' => 'PMD_type']
273
-            );
274
-            if ($active_payment_methods) {
275
-                foreach ($active_payment_methods as $payment_method) {
276
-                    $payment_method_stats[ $payment_method->name() . '_active_payment_method' ] = 1;
277
-                }
278
-            }
279
-        } catch (Exception $e) {
280
-            // do nothing just prevents fatals.
281
-        }
282
-        return $payment_method_stats;
283
-    }
284
-
285
-
286
-    /**
287
-     * Return a list of active EE add-ons and their versions.
288
-     *
289
-     * @return string
290
-     */
291
-    private function getActiveAddons(): string
292
-    {
293
-        $activeAddons = [];
294
-        $addOns       = EE_Registry::instance()->addons;
295
-        if (! empty($addOns)) {
296
-            foreach ($addOns as $addon) {
297
-                $activeAddons[] = $addon->name() . '@' . $addon->version();
298
-            }
299
-        }
300
-        return implode(',', $activeAddons);
301
-    }
55
+	/**
56
+	 * @var EEM_Payment_Method
57
+	 */
58
+	private EEM_Payment_Method $payment_method_model;
59
+
60
+
61
+	/**
62
+	 * @var EEM_Event
63
+	 */
64
+	private $event_model;
65
+
66
+	/**
67
+	 * @var EEM_Datetime
68
+	 */
69
+	private $datetime_model;
70
+
71
+
72
+	/**
73
+	 * @var EEM_Ticket
74
+	 */
75
+	private $ticket_model;
76
+
77
+
78
+	/**
79
+	 * @var EEM_Registration
80
+	 */
81
+	private $registration_model;
82
+
83
+
84
+	/**
85
+	 * @var EEM_Transaction
86
+	 */
87
+	private $transaction_model;
88
+
89
+
90
+	/**
91
+	 * @var EE_Config
92
+	 */
93
+	private $config;
94
+
95
+
96
+	/**
97
+	 * StatsGatherer constructor.
98
+	 *
99
+	 * @param EEM_Payment_Method $payment_method_model
100
+	 * @param EEM_Event          $event_model
101
+	 * @param EEM_Datetime       $datetime_model
102
+	 * @param EEM_Ticket         $ticket_model
103
+	 * @param EEM_Registration   $registration_model
104
+	 * @param EEM_Transaction    $transaction_model
105
+	 * @param EE_Config          $config
106
+	 */
107
+	public function __construct(
108
+		EEM_Payment_Method $payment_method_model,
109
+		EEM_Event $event_model,
110
+		EEM_Datetime $datetime_model,
111
+		EEM_Ticket $ticket_model,
112
+		EEM_Registration $registration_model,
113
+		EEM_Transaction $transaction_model,
114
+		EE_Config $config
115
+	) {
116
+		$this->payment_method_model = $payment_method_model;
117
+		$this->event_model          = $event_model;
118
+		$this->datetime_model       = $datetime_model;
119
+		$this->ticket_model         = $ticket_model;
120
+		$this->registration_model   = $registration_model;
121
+		$this->transaction_model    = $transaction_model;
122
+		$this->config               = $config;
123
+	}
124
+
125
+
126
+	/**
127
+	 * Return the stats array for PUE UXIP stats.
128
+	 *
129
+	 * @return array
130
+	 */
131
+	public function stats(): array
132
+	{
133
+		global $wp_version;
134
+		$stats = $this->paymentMethodStats();
135
+		// a-ok so let's setup our stats.
136
+		$stats = array_merge(
137
+			$stats,
138
+			[
139
+				'is_multisite'                    => is_multisite() && is_main_site(),
140
+				'active_theme'                    => $this->getActiveThemeStat(),
141
+				'ee4_all_events_count'            => $this->getCountFor(self::COUNT_ALL_EVENTS),
142
+				'ee4_active_events_count'         => $this->getCountFor(self::COUNT_ACTIVE_EVENTS),
143
+				'all_dtts_count'                  => $this->getCountFor(self::COUNT_DATETIMES),
144
+				'dtt_sold'                        => $this->getCountFor(self::COUNT_DATETIMES_SOLD),
145
+				'all_tkt_count'                   => $this->getCountFor(self::COUNT_TICKETS),
146
+				'free_tkt_count'                  => $this->getCountFor(self::COUNT_TICKETS_FREE),
147
+				'paid_tkt_count'                  => $this->getCountFor(self::COUNT_TICKETS_PAID),
148
+				'tkt_sold'                        => $this->getCountFor(self::COUNT_TICKETS_SOLD),
149
+				'approve_registration_count'      => $this->getCountFor(self::COUNT_REGISTRATIONS_APPROVED),
150
+				'pending_registration_count'      => $this->getCountFor(self::COUNT_REGISTRATIONS_PENDING),
151
+				'not_approved_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_NOT_APPROVED),
152
+				'incomplete_registration_count'   => $this->getCountFor(self::COUNT_REGISTRATIONS_INCOMPLETE),
153
+				'cancelled_registration_count'    => $this->getCountFor(self::COUNT_REGISTRATIONS_CANCELLED),
154
+				'declined_registration_count'     => $this->getCountFor(self::COUNT_REGISTRATIONS_DECLINED),
155
+				'all_registration_count'          => $this->getCountFor(self::COUNT_REGISTRATIONS_ALL),
156
+				'completed_transaction_total_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_COMPLETE_TOTAL),
157
+				'all_transaction_paid_sum'        => $this->getCountFor(self::SUM_TRANSACTIONS_ALL_PAID),
158
+				self::INFO_SITE_CURRENCY          => $this->config->currency instanceof EE_Currency_Config
159
+					? $this->config->currency->code
160
+					: 'unknown',
161
+				'phpversion'                      => implode(
162
+					'.',
163
+					[PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION]
164
+				),
165
+				'wpversion'                       => $wp_version,
166
+				'active_addons'                   => $this->getActiveAddons(),
167
+			]
168
+		);
169
+		// remove any values that equal null.  This ensures any stats that weren't retrieved successfully are excluded.
170
+		return array_filter($stats, function ($value) {
171
+			return $value !== null;
172
+		});
173
+	}
174
+
175
+
176
+	/**
177
+	 * @param string $which enum (@see constants prefixed with COUNT)
178
+	 * @return int|null
179
+	 */
180
+	private function getCountFor(string $which): ?int
181
+	{
182
+		try {
183
+			switch ($which) {
184
+				case self::COUNT_ALL_EVENTS:
185
+					$count = $this->event_model->count();
186
+					break;
187
+				case self::COUNT_TICKETS:
188
+					$count = $this->ticket_model->count();
189
+					break;
190
+				case self::COUNT_DATETIMES:
191
+					$count = $this->datetime_model->count();
192
+					break;
193
+				case self::COUNT_ACTIVE_EVENTS:
194
+					$count = $this->event_model->get_active_events([], true);
195
+					break;
196
+				case self::COUNT_DATETIMES_SOLD:
197
+					$count = $this->datetime_model->sum([], 'DTT_sold');
198
+					break;
199
+				case self::COUNT_TICKETS_FREE:
200
+					$count = $this->ticket_model->count([['TKT_price' => 0]]);
201
+					break;
202
+				case self::COUNT_TICKETS_PAID:
203
+					$count = $this->ticket_model->count([['TKT_price' => ['>', 0]]]);
204
+					break;
205
+				case self::COUNT_TICKETS_SOLD:
206
+					$count = $this->ticket_model->sum([], 'TKT_sold');
207
+					break;
208
+				case self::COUNT_REGISTRATIONS_ALL:
209
+					$count = $this->registration_model->count();
210
+					break;
211
+				case self::COUNT_REGISTRATIONS_CANCELLED:
212
+					$count = $this->registration_model->count([['STS_ID' => EEM_Registration::status_id_cancelled]]);
213
+					break;
214
+				case self::COUNT_REGISTRATIONS_INCOMPLETE:
215
+					$count = $this->registration_model->count([['STS_ID' => EEM_Registration::status_id_incomplete]]);
216
+					break;
217
+				case self::COUNT_REGISTRATIONS_NOT_APPROVED:
218
+					$count = $this->registration_model->count([['STS_ID' => EEM_Registration::status_id_not_approved]]);
219
+					break;
220
+				case self::COUNT_REGISTRATIONS_DECLINED:
221
+					$count = $this->registration_model->count([['STS_ID' => EEM_Registration::status_id_declined]]);
222
+					break;
223
+				case self::COUNT_REGISTRATIONS_PENDING:
224
+					$count = $this->registration_model->count(
225
+						[['STS_ID' => EEM_Registration::status_id_pending_payment]]
226
+					);
227
+					break;
228
+				case self::COUNT_REGISTRATIONS_APPROVED:
229
+					$count = $this->registration_model->count([['STS_ID' => EEM_Registration::status_id_approved]]);
230
+					break;
231
+				case self::SUM_TRANSACTIONS_COMPLETE_TOTAL:
232
+					$count = $this->transaction_model->sum(
233
+						[['STS_ID' => EEM_Transaction::complete_status_code]],
234
+						'TXN_total'
235
+					);
236
+					break;
237
+				case self::SUM_TRANSACTIONS_ALL_PAID:
238
+					$count = $this->transaction_model->sum([], 'TXN_paid');
239
+					break;
240
+				default:
241
+					$count = null;
242
+					break;
243
+			}
244
+		} catch (Exception $e) {
245
+			$count = null;
246
+		}
247
+		return $count;
248
+	}
249
+
250
+
251
+	/**
252
+	 * Return the active theme.
253
+	 *
254
+	 * @return false|string
255
+	 */
256
+	private function getActiveThemeStat()
257
+	{
258
+		$theme = wp_get_theme();
259
+		return $theme->get('Name');
260
+	}
261
+
262
+
263
+	/**
264
+	 * @return array
265
+	 */
266
+	private function paymentMethodStats(): array
267
+	{
268
+		$payment_method_stats = [];
269
+		try {
270
+			$active_payment_methods = $this->payment_method_model->get_all_active(
271
+				null,
272
+				['group_by' => 'PMD_type']
273
+			);
274
+			if ($active_payment_methods) {
275
+				foreach ($active_payment_methods as $payment_method) {
276
+					$payment_method_stats[ $payment_method->name() . '_active_payment_method' ] = 1;
277
+				}
278
+			}
279
+		} catch (Exception $e) {
280
+			// do nothing just prevents fatals.
281
+		}
282
+		return $payment_method_stats;
283
+	}
284
+
285
+
286
+	/**
287
+	 * Return a list of active EE add-ons and their versions.
288
+	 *
289
+	 * @return string
290
+	 */
291
+	private function getActiveAddons(): string
292
+	{
293
+		$activeAddons = [];
294
+		$addOns       = EE_Registry::instance()->addons;
295
+		if (! empty($addOns)) {
296
+			foreach ($addOns as $addon) {
297
+				$activeAddons[] = $addon->name() . '@' . $addon->version();
298
+			}
299
+		}
300
+		return implode(',', $activeAddons);
301
+	}
302 302
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
             ]
168 168
         );
169 169
         // remove any values that equal null.  This ensures any stats that weren't retrieved successfully are excluded.
170
-        return array_filter($stats, function ($value) {
170
+        return array_filter($stats, function($value) {
171 171
             return $value !== null;
172 172
         });
173 173
     }
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
             );
274 274
             if ($active_payment_methods) {
275 275
                 foreach ($active_payment_methods as $payment_method) {
276
-                    $payment_method_stats[ $payment_method->name() . '_active_payment_method' ] = 1;
276
+                    $payment_method_stats[$payment_method->name().'_active_payment_method'] = 1;
277 277
                 }
278 278
             }
279 279
         } catch (Exception $e) {
@@ -292,9 +292,9 @@  discard block
 block discarded – undo
292 292
     {
293 293
         $activeAddons = [];
294 294
         $addOns       = EE_Registry::instance()->addons;
295
-        if (! empty($addOns)) {
295
+        if ( ! empty($addOns)) {
296 296
             foreach ($addOns as $addon) {
297
-                $activeAddons[] = $addon->name() . '@' . $addon->version();
297
+                $activeAddons[] = $addon->name().'@'.$addon->version();
298 298
             }
299 299
         }
300 300
         return implode(',', $activeAddons);
Please login to merge, or discard this patch.
caffeinated/core/domain/services/pue/PueLicensingManager.php 2 patches
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -11,104 +11,104 @@
 block discarded – undo
11 11
 
12 12
 class PueLicensingManager
13 13
 {
14
-    /**
15
-     * @var EE_Dependency_Map
16
-     */
17
-    protected $dependency_map;
14
+	/**
15
+	 * @var EE_Dependency_Map
16
+	 */
17
+	protected $dependency_map;
18 18
 
19
-    /**
20
-     * @var LoaderInterface
21
-     */
22
-    protected $loader;
19
+	/**
20
+	 * @var LoaderInterface
21
+	 */
22
+	protected $loader;
23 23
 
24 24
 
25
-    /**
26
-     * @param EE_Dependency_Map $dependency_map
27
-     * @param LoaderInterface   $loader
28
-     */
29
-    public function __construct(EE_Dependency_Map $dependency_map, LoaderInterface $loader)
30
-    {
31
-        $this->dependency_map = $dependency_map;
32
-        $this->loader         = $loader;
33
-    }
25
+	/**
26
+	 * @param EE_Dependency_Map $dependency_map
27
+	 * @param LoaderInterface   $loader
28
+	 */
29
+	public function __construct(EE_Dependency_Map $dependency_map, LoaderInterface $loader)
30
+	{
31
+		$this->dependency_map = $dependency_map;
32
+		$this->loader         = $loader;
33
+	}
34 34
 
35 35
 
36
-    public function registerDependencies()
37
-    {
38
-        $pue_dependencies = [
39
-            'EventEspresso\caffeinated\core\services\licensing\LicenseService'     => [
40
-                'EventEspresso\caffeinated\core\domain\services\pue\Stats'  => EE_Dependency_Map::load_from_cache,
41
-                'EventEspresso\caffeinated\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache,
42
-            ],
43
-            'EventEspresso\caffeinated\core\domain\services\pue\Stats'             => [
44
-                'EventEspresso\caffeinated\core\domain\services\pue\Config'        => EE_Dependency_Map::load_from_cache,
45
-                'EE_Maintenance_Mode'                                              => EE_Dependency_Map::load_from_cache,
46
-                'EventEspresso\caffeinated\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache,
47
-            ],
48
-            'EventEspresso\caffeinated\core\domain\services\pue\Config'            => [
49
-                'EE_Network_Config' => EE_Dependency_Map::load_from_cache,
50
-                'EE_Config'         => EE_Dependency_Map::load_from_cache,
51
-            ],
52
-            'EventEspresso\caffeinated\core\domain\services\pue\StatsGatherer'     => [
53
-                'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
54
-                'EEM_Event'          => EE_Dependency_Map::load_from_cache,
55
-                'EEM_Datetime'       => EE_Dependency_Map::load_from_cache,
56
-                'EEM_Ticket'         => EE_Dependency_Map::load_from_cache,
57
-                'EEM_Registration'   => EE_Dependency_Map::load_from_cache,
58
-                'EEM_Transaction'    => EE_Dependency_Map::load_from_cache,
59
-                'EE_Config'          => EE_Dependency_Map::load_from_cache,
60
-            ],
61
-            'EventEspresso\caffeinated\core\services\licensing\UserExperienceForm' => [
62
-                'EE_Core_Config'         => EE_Dependency_Map::load_from_cache,
63
-                'EE_Network_Core_Config' => EE_Dependency_Map::load_from_cache,
64
-            ],
65
-        ];
66
-        foreach ($pue_dependencies as $class => $dependencies) {
67
-            $this->dependency_map->registerDependencies($class, $dependencies);
68
-        }
69
-    }
36
+	public function registerDependencies()
37
+	{
38
+		$pue_dependencies = [
39
+			'EventEspresso\caffeinated\core\services\licensing\LicenseService'     => [
40
+				'EventEspresso\caffeinated\core\domain\services\pue\Stats'  => EE_Dependency_Map::load_from_cache,
41
+				'EventEspresso\caffeinated\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache,
42
+			],
43
+			'EventEspresso\caffeinated\core\domain\services\pue\Stats'             => [
44
+				'EventEspresso\caffeinated\core\domain\services\pue\Config'        => EE_Dependency_Map::load_from_cache,
45
+				'EE_Maintenance_Mode'                                              => EE_Dependency_Map::load_from_cache,
46
+				'EventEspresso\caffeinated\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache,
47
+			],
48
+			'EventEspresso\caffeinated\core\domain\services\pue\Config'            => [
49
+				'EE_Network_Config' => EE_Dependency_Map::load_from_cache,
50
+				'EE_Config'         => EE_Dependency_Map::load_from_cache,
51
+			],
52
+			'EventEspresso\caffeinated\core\domain\services\pue\StatsGatherer'     => [
53
+				'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
54
+				'EEM_Event'          => EE_Dependency_Map::load_from_cache,
55
+				'EEM_Datetime'       => EE_Dependency_Map::load_from_cache,
56
+				'EEM_Ticket'         => EE_Dependency_Map::load_from_cache,
57
+				'EEM_Registration'   => EE_Dependency_Map::load_from_cache,
58
+				'EEM_Transaction'    => EE_Dependency_Map::load_from_cache,
59
+				'EE_Config'          => EE_Dependency_Map::load_from_cache,
60
+			],
61
+			'EventEspresso\caffeinated\core\services\licensing\UserExperienceForm' => [
62
+				'EE_Core_Config'         => EE_Dependency_Map::load_from_cache,
63
+				'EE_Network_Core_Config' => EE_Dependency_Map::load_from_cache,
64
+			],
65
+		];
66
+		foreach ($pue_dependencies as $class => $dependencies) {
67
+			$this->dependency_map->registerDependencies($class, $dependencies);
68
+		}
69
+	}
70 70
 
71 71
 
72
-    public function registerHooks()
73
-    {
74
-        add_filter(
75
-            'FHEE__EE_Register_Addon__register',
76
-            [RegisterAddonPUE::class, 'registerPUE'],
77
-            10,
78
-            4
79
-        );
80
-        add_action(
81
-            'AHEE__EE_Register_Addon___load_and_init_addon_class',
82
-            [RegisterAddonPUE::class, 'setAddonPueSlug'],
83
-            10,
84
-            2
85
-        );
86
-        if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
87
-            add_action('AHEE__EE_System__brew_espresso__complete', [$this, 'loadLicenseService']);
88
-        }
89
-        add_filter(
90
-            'FHEE__EventEspresso_admin_pages_general_settings_OrganizationSettings__generate__form',
91
-            [$this, 'loadUserExperienceForm']
92
-        );
72
+	public function registerHooks()
73
+	{
74
+		add_filter(
75
+			'FHEE__EE_Register_Addon__register',
76
+			[RegisterAddonPUE::class, 'registerPUE'],
77
+			10,
78
+			4
79
+		);
80
+		add_action(
81
+			'AHEE__EE_Register_Addon___load_and_init_addon_class',
82
+			[RegisterAddonPUE::class, 'setAddonPueSlug'],
83
+			10,
84
+			2
85
+		);
86
+		if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) {
87
+			add_action('AHEE__EE_System__brew_espresso__complete', [$this, 'loadLicenseService']);
88
+		}
89
+		add_filter(
90
+			'FHEE__EventEspresso_admin_pages_general_settings_OrganizationSettings__generate__form',
91
+			[$this, 'loadUserExperienceForm']
92
+		);
93 93
 
94
-    }
94
+	}
95 95
 
96 96
 
97
-    public function loadLicenseService()
98
-    {
99
-        /** @var LicenseService $license_service */
100
-        $license_service = $this->loader->getShared(LicenseService::class );
101
-        $license_service->loadPueClient();
102
-    }
97
+	public function loadLicenseService()
98
+	{
99
+		/** @var LicenseService $license_service */
100
+		$license_service = $this->loader->getShared(LicenseService::class );
101
+		$license_service->loadPueClient();
102
+	}
103 103
 
104 104
 
105
-    /**
106
-     * @throws EE_Error
107
-     */
108
-    public function loadUserExperienceForm(EE_Form_Section_Proper $org_settings_form): EE_Form_Section_Proper
109
-    {
110
-        /** @var UserExperienceForm $uxip_form */
111
-        $uxip_form = $this->loader->getShared(UserExperienceForm::class);
112
-        return $uxip_form->uxipFormSections($org_settings_form);
113
-    }
105
+	/**
106
+	 * @throws EE_Error
107
+	 */
108
+	public function loadUserExperienceForm(EE_Form_Section_Proper $org_settings_form): EE_Form_Section_Proper
109
+	{
110
+		/** @var UserExperienceForm $uxip_form */
111
+		$uxip_form = $this->loader->getShared(UserExperienceForm::class);
112
+		return $uxip_form->uxipFormSections($org_settings_form);
113
+	}
114 114
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@
 block discarded – undo
97 97
     public function loadLicenseService()
98 98
     {
99 99
         /** @var LicenseService $license_service */
100
-        $license_service = $this->loader->getShared(LicenseService::class );
100
+        $license_service = $this->loader->getShared(LicenseService::class);
101 101
         $license_service->loadPueClient();
102 102
     }
103 103
 
Please login to merge, or discard this patch.
core/admin/EE_Admin_List_Table.core.php 1 patch
Indentation   +884 added lines, -884 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use EventEspresso\core\services\request\sanitizers\AllowedTags;
4 4
 
5 5
 if (! class_exists('WP_List_Table')) {
6
-    require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
6
+	require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
7 7
 }
8 8
 
9 9
 
@@ -21,897 +21,897 @@  discard block
 block discarded – undo
21 21
  */
22 22
 abstract class EE_Admin_List_Table extends WP_List_Table
23 23
 {
24
-    const ACTION_COPY    = 'duplicate';
25
-
26
-    const ACTION_DELETE  = 'delete';
27
-
28
-    const ACTION_EDIT    = 'edit';
29
-
30
-    const ACTION_RESTORE = 'restore';
31
-
32
-    const ACTION_TRASH   = 'trash';
33
-
34
-    protected static $actions = [
35
-        self::ACTION_COPY,
36
-        self::ACTION_DELETE,
37
-        self::ACTION_EDIT,
38
-        self::ACTION_RESTORE,
39
-        self::ACTION_TRASH,
40
-    ];
41
-
42
-    /**
43
-     * holds the data that will be processed for the table
44
-     *
45
-     * @var array $_data
46
-     */
47
-    protected $_data;
48
-
49
-
50
-    /**
51
-     * This holds the value of all the data available for the given view (for all pages).
52
-     *
53
-     * @var int $_all_data_count
54
-     */
55
-    protected $_all_data_count;
56
-
57
-
58
-    /**
59
-     * Will contain the count of trashed items for the view label.
60
-     *
61
-     * @var int $_trashed_count
62
-     */
63
-    protected $_trashed_count;
64
-
65
-
66
-    /**
67
-     * This is what will be referenced as the slug for the current screen
68
-     *
69
-     * @var string $_screen
70
-     */
71
-    protected $_screen;
72
-
73
-
74
-    /**
75
-     * this is the EE_Admin_Page object
76
-     *
77
-     * @var EE_Admin_Page $_admin_page
78
-     */
79
-    protected $_admin_page;
80
-
81
-
82
-    /**
83
-     * The current view
84
-     *
85
-     * @var string $_view
86
-     */
87
-    protected $_view;
88
-
89
-
90
-    /**
91
-     * array of possible views for this table
92
-     *
93
-     * @var array $_views
94
-     */
95
-    protected $_views;
96
-
97
-
98
-    /**
99
-     * An array of key => value pairs containing information about the current table
100
-     * array(
101
-     *        'plural' => 'plural label',
102
-     *        'singular' => 'singular label',
103
-     *        'ajax' => false, //whether to use ajax or not
104
-     *        'screen' => null, //string used to reference what screen this is
105
-     *        (WP_List_table converts to screen object)
106
-     * )
107
-     *
108
-     * @var array $_wp_list_args
109
-     */
110
-    protected $_wp_list_args;
111
-
112
-    /**
113
-     * an array of column names
114
-     * array(
115
-     *    'internal-name' => 'Title'
116
-     * )
117
-     *
118
-     * @var array $_columns
119
-     */
120
-    protected $_columns;
121
-
122
-    /**
123
-     * An array of sortable columns
124
-     * array(
125
-     *    'internal-name' => 'orderby' //or
126
-     *    'internal-name' => array( 'orderby', true )
127
-     * )
128
-     *
129
-     * @var array $_sortable_columns
130
-     */
131
-    protected $_sortable_columns;
132
-
133
-    /**
134
-     * callback method used to perform AJAX row reordering
135
-     *
136
-     * @var string $_ajax_sorting_callback
137
-     */
138
-    protected $_ajax_sorting_callback;
139
-
140
-    /**
141
-     * An array of hidden columns (if needed)
142
-     * array('internal-name', 'internal-name')
143
-     *
144
-     * @var array $_hidden_columns
145
-     */
146
-    protected $_hidden_columns;
147
-
148
-    /**
149
-     * holds the per_page value
150
-     *
151
-     * @var int $_per_page
152
-     */
153
-    protected $_per_page;
154
-
155
-    /**
156
-     * holds what page number is currently being viewed
157
-     *
158
-     * @var int $_current_page
159
-     */
160
-    protected $_current_page;
161
-
162
-    /**
163
-     * the reference string for the nonce_action
164
-     *
165
-     * @var string $_nonce_action_ref
166
-     */
167
-    protected $_nonce_action_ref;
168
-
169
-    /**
170
-     * property to hold incoming request data (as set by the admin_page_core)
171
-     *
172
-     * @var array $_req_data
173
-     */
174
-    protected $_req_data;
175
-
176
-
177
-    /**
178
-     * yes / no array for admin form fields
179
-     *
180
-     * @var array $_yes_no
181
-     */
182
-    protected $_yes_no = [];
183
-
184
-    /**
185
-     * Array describing buttons that should appear at the bottom of the page
186
-     * Keys are strings that represent the button's function (specifically a key in _labels['buttons']),
187
-     * and the values are another array with the following keys
188
-     * array(
189
-     *    'route' => 'page_route',
190
-     *    'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button.
191
-     * )
192
-     *
193
-     * @var array $_bottom_buttons
194
-     */
195
-    protected $_bottom_buttons = [];
196
-
197
-
198
-    /**
199
-     * Used to indicate what should be the primary column for the list table.
200
-     * If not present then falls back to what WP calculates
201
-     * as the primary column.
202
-     *
203
-     * @type string $_primary_column
204
-     */
205
-    protected $_primary_column = '';
206
-
207
-
208
-    /**
209
-     * Used to indicate whether the table has a checkbox column or not.
210
-     *
211
-     * @type bool $_has_checkbox_column
212
-     */
213
-    protected $_has_checkbox_column = false;
214
-
215
-
216
-    /**
217
-     * @param EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table
218
-     */
219
-    public function __construct(EE_Admin_Page $admin_page)
220
-    {
221
-        $this->_admin_page   = $admin_page;
222
-        $this->_req_data     = $this->_admin_page->get_request_data();
223
-        $this->_view         = $this->_admin_page->get_view();
224
-        $this->_views        = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views;
225
-        $this->_current_page = $this->get_pagenum();
226
-        $this->_screen       = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view();
227
-        $this->_yes_no       = [
228
-            esc_html__('No', 'event_espresso'),
229
-            esc_html__('Yes', 'event_espresso')
230
-        ];
231
-
232
-        $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page');
233
-
234
-        $this->_setup_data();
235
-        $this->_add_view_counts();
236
-
237
-        $this->_nonce_action_ref = $this->_view;
238
-
239
-        $this->_set_properties();
240
-
241
-        // set primary column
242
-        add_filter('list_table_primary_column', [$this, 'set_primary_column']);
243
-
244
-        // set parent defaults
245
-        parent::__construct($this->_wp_list_args);
246
-
247
-        $this->prepare_items();
248
-    }
249
-
250
-
251
-    /**
252
-     * _setup_data
253
-     * this method is used to setup the $_data, $_all_data_count, and _per_page properties
254
-     *
255
-     * @return void
256
-     * @uses $this->_admin_page
257
-     */
258
-    abstract protected function _setup_data();
259
-
260
-
261
-    /**
262
-     * set the properties that this class needs to be able to execute wp_list_table properly
263
-     * properties set:
264
-     * _wp_list_args = what the arguments required for the parent _wp_list_table.
265
-     * _columns = set the columns in an array.
266
-     * _sortable_columns = columns that are sortable (array).
267
-     * _hidden_columns = columns that are hidden (array)
268
-     * _default_orderby = the default orderby for sorting.
269
-     *
270
-     * @abstract
271
-     * @access protected
272
-     * @return void
273
-     */
274
-    abstract protected function _set_properties();
275
-
276
-
277
-    /**
278
-     * _get_table_filters
279
-     * We use this to assemble and return any filters that are associated with this table that help further refine what
280
-     * gets shown in the table.
281
-     *
282
-     * @abstract
283
-     * @access protected
284
-     * @return string
285
-     */
286
-    abstract protected function _get_table_filters();
287
-
288
-
289
-    /**
290
-     * this is a method that child class will do to add counts to the views array so when views are displayed the
291
-     * counts of the views is accurate.
292
-     *
293
-     * @abstract
294
-     * @access protected
295
-     * @return void
296
-     */
297
-    abstract protected function _add_view_counts();
298
-
299
-
300
-    /**
301
-     * _get_hidden_fields
302
-     * returns a html string of hidden fields so if any table filters are used the current view will be respected.
303
-     *
304
-     * @return string
305
-     */
306
-    protected function _get_hidden_fields()
307
-    {
308
-        $action = isset($this->_req_data['route']) ? $this->_req_data['route'] : '';
309
-        $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action;
310
-        // if action is STILL empty, then we set it to default
311
-        $action = empty($action) ? 'default' : $action;
312
-        $field  = '<input type="hidden" name="page" value="' . esc_attr($this->_req_data['page']) . '" />' . "\n";
313
-        $field  .= '<input type="hidden" name="route" value="' . esc_attr($action) . '" />' . "\n";
314
-        $field  .= '<input type="hidden" name="perpage" value="' . esc_attr($this->_per_page) . '" />' . "\n";
315
-
316
-        $bulk_actions = $this->_get_bulk_actions();
317
-        foreach ($bulk_actions as $bulk_action => $label) {
318
-            $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"'
319
-                      . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n";
320
-        }
321
-
322
-        return $field;
323
-    }
324
-
325
-
326
-    /**
327
-     * _set_column_info
328
-     * we're using this to set the column headers property.
329
-     *
330
-     * @access protected
331
-     * @return void
332
-     */
333
-    protected function _set_column_info()
334
-    {
335
-        $columns   = $this->get_columns();
336
-        $hidden    = $this->get_hidden_columns();
337
-        $_sortable = $this->get_sortable_columns();
338
-
339
-        /**
340
-         * Dynamic hook allowing for adding sortable columns in this list table.
341
-         * Note that $this->screen->id is in the format
342
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
343
-         * table it is: event-espresso_page_espresso_messages.
344
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
345
-         * hook prefix ("event-espresso") will be different.
346
-         *
347
-         * @var array
348
-         */
349
-        $_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen);
350
-
351
-        $sortable = [];
352
-        foreach ($_sortable as $id => $data) {
353
-            if (empty($data)) {
354
-                continue;
355
-            }
356
-            // fix for offset errors with WP_List_Table default get_columninfo()
357
-            if (is_array($data)) {
358
-                $_data[0] = key($data);
359
-                $_data[1] = isset($data[1]) ? $data[1] : false;
360
-            } else {
361
-                $_data[0] = $data;
362
-            }
363
-
364
-            $data = (array) $data;
365
-
366
-            if (! isset($data[1])) {
367
-                $_data[1] = false;
368
-            }
369
-
370
-            $sortable[ $id ] = $_data;
371
-        }
372
-        $primary               = $this->get_primary_column_name();
373
-        $this->_column_headers = [$columns, $hidden, $sortable, $primary];
374
-    }
375
-
376
-
377
-    /**
378
-     * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
379
-     *
380
-     * @return string
381
-     */
382
-    protected function get_primary_column_name()
383
-    {
384
-        foreach (class_parents($this) as $parent) {
385
-            if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) {
386
-                return parent::get_primary_column_name();
387
-            }
388
-        }
389
-        return $this->_primary_column;
390
-    }
391
-
392
-
393
-    /**
394
-     * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
395
-     *
396
-     * @param EE_Base_Class $item
397
-     * @param string        $column_name
398
-     * @param string        $primary
399
-     * @return string
400
-     */
401
-    protected function handle_row_actions($item, $column_name, $primary)
402
-    {
403
-        foreach (class_parents($this) as $parent) {
404
-            if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) {
405
-                return parent::handle_row_actions($item, $column_name, $primary);
406
-            }
407
-        }
408
-        return '';
409
-    }
410
-
411
-
412
-    /**
413
-     * _get_bulk_actions
414
-     * This is a wrapper called by WP_List_Table::get_bulk_actions()
415
-     *
416
-     * @access protected
417
-     * @return array bulk_actions
418
-     */
419
-    protected function _get_bulk_actions()
420
-    {
421
-        $actions = [];
422
-        // the _views property should have the bulk_actions, so let's go through and extract them into a properly
423
-        // formatted array for the wp_list_table();
424
-        foreach ($this->_views as $view => $args) {
425
-            if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) {
426
-                // each bulk action will correspond with a admin page route, so we can check whatever the capability is
427
-                // for that page route and skip adding the bulk action if no access for the current logged in user.
428
-                foreach ($args['bulk_action'] as $route => $label) {
429
-                    if ($this->_admin_page->check_user_access($route, true)) {
430
-                        $actions[ $route ] = $label;
431
-                    }
432
-                }
433
-            }
434
-        }
435
-        return $actions;
436
-    }
437
-
438
-
439
-    /**
440
-     * Generate the table navigation above or below the table.
441
-     * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions.
442
-     *
443
-     * @throws EE_Error
444
-     * @since 4.9.44.rc.001
445
-     */
446
-    public function display_tablenav($which)
447
-    {
448
-        if ('top' === $which) {
449
-            wp_nonce_field('bulk-' . $this->_args['plural']);
450
-        }
451
-        ?>
24
+	const ACTION_COPY    = 'duplicate';
25
+
26
+	const ACTION_DELETE  = 'delete';
27
+
28
+	const ACTION_EDIT    = 'edit';
29
+
30
+	const ACTION_RESTORE = 'restore';
31
+
32
+	const ACTION_TRASH   = 'trash';
33
+
34
+	protected static $actions = [
35
+		self::ACTION_COPY,
36
+		self::ACTION_DELETE,
37
+		self::ACTION_EDIT,
38
+		self::ACTION_RESTORE,
39
+		self::ACTION_TRASH,
40
+	];
41
+
42
+	/**
43
+	 * holds the data that will be processed for the table
44
+	 *
45
+	 * @var array $_data
46
+	 */
47
+	protected $_data;
48
+
49
+
50
+	/**
51
+	 * This holds the value of all the data available for the given view (for all pages).
52
+	 *
53
+	 * @var int $_all_data_count
54
+	 */
55
+	protected $_all_data_count;
56
+
57
+
58
+	/**
59
+	 * Will contain the count of trashed items for the view label.
60
+	 *
61
+	 * @var int $_trashed_count
62
+	 */
63
+	protected $_trashed_count;
64
+
65
+
66
+	/**
67
+	 * This is what will be referenced as the slug for the current screen
68
+	 *
69
+	 * @var string $_screen
70
+	 */
71
+	protected $_screen;
72
+
73
+
74
+	/**
75
+	 * this is the EE_Admin_Page object
76
+	 *
77
+	 * @var EE_Admin_Page $_admin_page
78
+	 */
79
+	protected $_admin_page;
80
+
81
+
82
+	/**
83
+	 * The current view
84
+	 *
85
+	 * @var string $_view
86
+	 */
87
+	protected $_view;
88
+
89
+
90
+	/**
91
+	 * array of possible views for this table
92
+	 *
93
+	 * @var array $_views
94
+	 */
95
+	protected $_views;
96
+
97
+
98
+	/**
99
+	 * An array of key => value pairs containing information about the current table
100
+	 * array(
101
+	 *        'plural' => 'plural label',
102
+	 *        'singular' => 'singular label',
103
+	 *        'ajax' => false, //whether to use ajax or not
104
+	 *        'screen' => null, //string used to reference what screen this is
105
+	 *        (WP_List_table converts to screen object)
106
+	 * )
107
+	 *
108
+	 * @var array $_wp_list_args
109
+	 */
110
+	protected $_wp_list_args;
111
+
112
+	/**
113
+	 * an array of column names
114
+	 * array(
115
+	 *    'internal-name' => 'Title'
116
+	 * )
117
+	 *
118
+	 * @var array $_columns
119
+	 */
120
+	protected $_columns;
121
+
122
+	/**
123
+	 * An array of sortable columns
124
+	 * array(
125
+	 *    'internal-name' => 'orderby' //or
126
+	 *    'internal-name' => array( 'orderby', true )
127
+	 * )
128
+	 *
129
+	 * @var array $_sortable_columns
130
+	 */
131
+	protected $_sortable_columns;
132
+
133
+	/**
134
+	 * callback method used to perform AJAX row reordering
135
+	 *
136
+	 * @var string $_ajax_sorting_callback
137
+	 */
138
+	protected $_ajax_sorting_callback;
139
+
140
+	/**
141
+	 * An array of hidden columns (if needed)
142
+	 * array('internal-name', 'internal-name')
143
+	 *
144
+	 * @var array $_hidden_columns
145
+	 */
146
+	protected $_hidden_columns;
147
+
148
+	/**
149
+	 * holds the per_page value
150
+	 *
151
+	 * @var int $_per_page
152
+	 */
153
+	protected $_per_page;
154
+
155
+	/**
156
+	 * holds what page number is currently being viewed
157
+	 *
158
+	 * @var int $_current_page
159
+	 */
160
+	protected $_current_page;
161
+
162
+	/**
163
+	 * the reference string for the nonce_action
164
+	 *
165
+	 * @var string $_nonce_action_ref
166
+	 */
167
+	protected $_nonce_action_ref;
168
+
169
+	/**
170
+	 * property to hold incoming request data (as set by the admin_page_core)
171
+	 *
172
+	 * @var array $_req_data
173
+	 */
174
+	protected $_req_data;
175
+
176
+
177
+	/**
178
+	 * yes / no array for admin form fields
179
+	 *
180
+	 * @var array $_yes_no
181
+	 */
182
+	protected $_yes_no = [];
183
+
184
+	/**
185
+	 * Array describing buttons that should appear at the bottom of the page
186
+	 * Keys are strings that represent the button's function (specifically a key in _labels['buttons']),
187
+	 * and the values are another array with the following keys
188
+	 * array(
189
+	 *    'route' => 'page_route',
190
+	 *    'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button.
191
+	 * )
192
+	 *
193
+	 * @var array $_bottom_buttons
194
+	 */
195
+	protected $_bottom_buttons = [];
196
+
197
+
198
+	/**
199
+	 * Used to indicate what should be the primary column for the list table.
200
+	 * If not present then falls back to what WP calculates
201
+	 * as the primary column.
202
+	 *
203
+	 * @type string $_primary_column
204
+	 */
205
+	protected $_primary_column = '';
206
+
207
+
208
+	/**
209
+	 * Used to indicate whether the table has a checkbox column or not.
210
+	 *
211
+	 * @type bool $_has_checkbox_column
212
+	 */
213
+	protected $_has_checkbox_column = false;
214
+
215
+
216
+	/**
217
+	 * @param EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table
218
+	 */
219
+	public function __construct(EE_Admin_Page $admin_page)
220
+	{
221
+		$this->_admin_page   = $admin_page;
222
+		$this->_req_data     = $this->_admin_page->get_request_data();
223
+		$this->_view         = $this->_admin_page->get_view();
224
+		$this->_views        = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views;
225
+		$this->_current_page = $this->get_pagenum();
226
+		$this->_screen       = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view();
227
+		$this->_yes_no       = [
228
+			esc_html__('No', 'event_espresso'),
229
+			esc_html__('Yes', 'event_espresso')
230
+		];
231
+
232
+		$this->_per_page = $this->get_items_per_page($this->_screen . '_per_page');
233
+
234
+		$this->_setup_data();
235
+		$this->_add_view_counts();
236
+
237
+		$this->_nonce_action_ref = $this->_view;
238
+
239
+		$this->_set_properties();
240
+
241
+		// set primary column
242
+		add_filter('list_table_primary_column', [$this, 'set_primary_column']);
243
+
244
+		// set parent defaults
245
+		parent::__construct($this->_wp_list_args);
246
+
247
+		$this->prepare_items();
248
+	}
249
+
250
+
251
+	/**
252
+	 * _setup_data
253
+	 * this method is used to setup the $_data, $_all_data_count, and _per_page properties
254
+	 *
255
+	 * @return void
256
+	 * @uses $this->_admin_page
257
+	 */
258
+	abstract protected function _setup_data();
259
+
260
+
261
+	/**
262
+	 * set the properties that this class needs to be able to execute wp_list_table properly
263
+	 * properties set:
264
+	 * _wp_list_args = what the arguments required for the parent _wp_list_table.
265
+	 * _columns = set the columns in an array.
266
+	 * _sortable_columns = columns that are sortable (array).
267
+	 * _hidden_columns = columns that are hidden (array)
268
+	 * _default_orderby = the default orderby for sorting.
269
+	 *
270
+	 * @abstract
271
+	 * @access protected
272
+	 * @return void
273
+	 */
274
+	abstract protected function _set_properties();
275
+
276
+
277
+	/**
278
+	 * _get_table_filters
279
+	 * We use this to assemble and return any filters that are associated with this table that help further refine what
280
+	 * gets shown in the table.
281
+	 *
282
+	 * @abstract
283
+	 * @access protected
284
+	 * @return string
285
+	 */
286
+	abstract protected function _get_table_filters();
287
+
288
+
289
+	/**
290
+	 * this is a method that child class will do to add counts to the views array so when views are displayed the
291
+	 * counts of the views is accurate.
292
+	 *
293
+	 * @abstract
294
+	 * @access protected
295
+	 * @return void
296
+	 */
297
+	abstract protected function _add_view_counts();
298
+
299
+
300
+	/**
301
+	 * _get_hidden_fields
302
+	 * returns a html string of hidden fields so if any table filters are used the current view will be respected.
303
+	 *
304
+	 * @return string
305
+	 */
306
+	protected function _get_hidden_fields()
307
+	{
308
+		$action = isset($this->_req_data['route']) ? $this->_req_data['route'] : '';
309
+		$action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action;
310
+		// if action is STILL empty, then we set it to default
311
+		$action = empty($action) ? 'default' : $action;
312
+		$field  = '<input type="hidden" name="page" value="' . esc_attr($this->_req_data['page']) . '" />' . "\n";
313
+		$field  .= '<input type="hidden" name="route" value="' . esc_attr($action) . '" />' . "\n";
314
+		$field  .= '<input type="hidden" name="perpage" value="' . esc_attr($this->_per_page) . '" />' . "\n";
315
+
316
+		$bulk_actions = $this->_get_bulk_actions();
317
+		foreach ($bulk_actions as $bulk_action => $label) {
318
+			$field .= '<input type="hidden" name="' . $bulk_action . '_nonce"'
319
+					  . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n";
320
+		}
321
+
322
+		return $field;
323
+	}
324
+
325
+
326
+	/**
327
+	 * _set_column_info
328
+	 * we're using this to set the column headers property.
329
+	 *
330
+	 * @access protected
331
+	 * @return void
332
+	 */
333
+	protected function _set_column_info()
334
+	{
335
+		$columns   = $this->get_columns();
336
+		$hidden    = $this->get_hidden_columns();
337
+		$_sortable = $this->get_sortable_columns();
338
+
339
+		/**
340
+		 * Dynamic hook allowing for adding sortable columns in this list table.
341
+		 * Note that $this->screen->id is in the format
342
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
343
+		 * table it is: event-espresso_page_espresso_messages.
344
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
345
+		 * hook prefix ("event-espresso") will be different.
346
+		 *
347
+		 * @var array
348
+		 */
349
+		$_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen);
350
+
351
+		$sortable = [];
352
+		foreach ($_sortable as $id => $data) {
353
+			if (empty($data)) {
354
+				continue;
355
+			}
356
+			// fix for offset errors with WP_List_Table default get_columninfo()
357
+			if (is_array($data)) {
358
+				$_data[0] = key($data);
359
+				$_data[1] = isset($data[1]) ? $data[1] : false;
360
+			} else {
361
+				$_data[0] = $data;
362
+			}
363
+
364
+			$data = (array) $data;
365
+
366
+			if (! isset($data[1])) {
367
+				$_data[1] = false;
368
+			}
369
+
370
+			$sortable[ $id ] = $_data;
371
+		}
372
+		$primary               = $this->get_primary_column_name();
373
+		$this->_column_headers = [$columns, $hidden, $sortable, $primary];
374
+	}
375
+
376
+
377
+	/**
378
+	 * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
379
+	 *
380
+	 * @return string
381
+	 */
382
+	protected function get_primary_column_name()
383
+	{
384
+		foreach (class_parents($this) as $parent) {
385
+			if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) {
386
+				return parent::get_primary_column_name();
387
+			}
388
+		}
389
+		return $this->_primary_column;
390
+	}
391
+
392
+
393
+	/**
394
+	 * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814)
395
+	 *
396
+	 * @param EE_Base_Class $item
397
+	 * @param string        $column_name
398
+	 * @param string        $primary
399
+	 * @return string
400
+	 */
401
+	protected function handle_row_actions($item, $column_name, $primary)
402
+	{
403
+		foreach (class_parents($this) as $parent) {
404
+			if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) {
405
+				return parent::handle_row_actions($item, $column_name, $primary);
406
+			}
407
+		}
408
+		return '';
409
+	}
410
+
411
+
412
+	/**
413
+	 * _get_bulk_actions
414
+	 * This is a wrapper called by WP_List_Table::get_bulk_actions()
415
+	 *
416
+	 * @access protected
417
+	 * @return array bulk_actions
418
+	 */
419
+	protected function _get_bulk_actions()
420
+	{
421
+		$actions = [];
422
+		// the _views property should have the bulk_actions, so let's go through and extract them into a properly
423
+		// formatted array for the wp_list_table();
424
+		foreach ($this->_views as $view => $args) {
425
+			if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) {
426
+				// each bulk action will correspond with a admin page route, so we can check whatever the capability is
427
+				// for that page route and skip adding the bulk action if no access for the current logged in user.
428
+				foreach ($args['bulk_action'] as $route => $label) {
429
+					if ($this->_admin_page->check_user_access($route, true)) {
430
+						$actions[ $route ] = $label;
431
+					}
432
+				}
433
+			}
434
+		}
435
+		return $actions;
436
+	}
437
+
438
+
439
+	/**
440
+	 * Generate the table navigation above or below the table.
441
+	 * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions.
442
+	 *
443
+	 * @throws EE_Error
444
+	 * @since 4.9.44.rc.001
445
+	 */
446
+	public function display_tablenav($which)
447
+	{
448
+		if ('top' === $which) {
449
+			wp_nonce_field('bulk-' . $this->_args['plural']);
450
+		}
451
+		?>
452 452
         <div class="tablenav <?php echo esc_attr($which); ?>">
453 453
             <?php if ($this->_get_bulk_actions()) { ?>
454 454
                 <div class="alignleft actions bulkactions">
455 455
                     <?php $this->bulk_actions(); ?>
456 456
                 </div>
457 457
             <?php }
458
-            $this->extra_tablenav($which);
459
-            $this->pagination($which);
460
-            ?>
458
+			$this->extra_tablenav($which);
459
+			$this->pagination($which);
460
+			?>
461 461
 
462 462
             <br class="clear" />
463 463
         </div>
464 464
         <?php
465
-    }
466
-
467
-
468
-    /**
469
-     * _filters
470
-     * This receives the filters array from children _get_table_filters() and assembles the string including the filter
471
-     * button.
472
-     *
473
-     * @access private
474
-     * @return void  echos html showing filters
475
-     */
476
-    private function _filters()
477
-    {
478
-        $classname = get_class($this);
479
-        $filters   = apply_filters(
480
-            "FHEE__{$classname}__filters",
481
-            (array) $this->_get_table_filters(),
482
-            $this,
483
-            $this->_screen
484
-        );
485
-
486
-        if (empty($filters)) {
487
-            return;
488
-        }
489
-        $use_filters = isset($this->_req_data['use_filters'])
490
-                       && filter_var($this->_req_data['use_filters'], FILTER_VALIDATE_BOOLEAN)
491
-            ? 'yes'
492
-            : 'no';
493
-
494
-        echo '<div class="ee-list-table-filters actions alignleft">';
495
-        foreach ($filters as $filter) {
496
-            echo wp_kses($filter, AllowedTags::getWithFormTags());
497
-        }
498
-        // add filter button at end
499
-        echo '<input type="submit" class="ee-list-table-filter-submit button button--secondary" value="'
500
-             . esc_html__('Filter', 'event_espresso')
501
-             . '" id="post-query-submit" />';
502
-        echo '<input type="hidden" id="ee-list-table-use-filters" name="use_filters" value="' . $use_filters . '"/>';
503
-
504
-        // add reset filters button at end
505
-        echo '<a class="button button--secondary"  href="'
506
-             . esc_url_raw($this->_admin_page->get_current_page_view_url())
507
-             . '" style="display:inline-block">'
508
-             . esc_html__('Reset Filters', 'event_espresso')
509
-             . '</a>';
510
-        echo '</div>';
511
-    }
512
-
513
-
514
-    /**
515
-     * Callback for 'list_table_primary_column' WordPress filter
516
-     * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary
517
-     * column when class is instantiated.
518
-     *
519
-     * @param string $column_name
520
-     * @return string
521
-     * @see WP_List_Table::get_primary_column_name
522
-     */
523
-    public function set_primary_column($column_name)
524
-    {
525
-        return ! empty($this->_primary_column) ? $this->_primary_column : $column_name;
526
-    }
527
-
528
-
529
-    /**
530
-     *
531
-     */
532
-    public function prepare_items()
533
-    {
534
-        $this->_set_column_info();
535
-        $this->process_bulk_action();
536
-
537
-        $this->items = $this->_data;
538
-        $this->set_pagination_args(
539
-            [
540
-                'total_items' => $this->_all_data_count,
541
-                'per_page'    => $this->_per_page,
542
-                'total_pages' => (int) ceil($this->_all_data_count / $this->_per_page),
543
-            ]
544
-        );
545
-    }
546
-
547
-
548
-    /**
549
-     * @param object|array $item
550
-     * @return string html content for the column
551
-     */
552
-    protected function column_cb($item)
553
-    {
554
-        return '';
555
-    }
556
-
557
-
558
-    /**
559
-     * This column is the default for when there is no defined column method for a registered column.
560
-     * This can be overridden by child classes, but allows for hooking in for custom columns.
561
-     *
562
-     * @param EE_Base_Class $item
563
-     * @param string        $column_name The column being called.
564
-     * @return string html content for the column
565
-     */
566
-    public function column_default($item, $column_name)
567
-    {
568
-        /**
569
-         * Dynamic hook allowing for adding additional column content in this list table.
570
-         * Note that $this->screen->id is in the format
571
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
572
-         * table it is: event-espresso_page_espresso_messages.
573
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
574
-         * hook prefix ("event-espresso") will be different.
575
-         */
576
-        ob_start();
577
-        do_action(
578
-            'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id,
579
-            $item,
580
-            $this->_screen
581
-        );
582
-        return ob_get_clean();
583
-    }
584
-
585
-
586
-    /**
587
-     * Get a list of columns. The format is:
588
-     * 'internal-name' => 'Title'
589
-     *
590
-     * @return array
591
-     * @since  3.1.0
592
-     * @access public
593
-     * @abstract
594
-     */
595
-    public function get_columns()
596
-    {
597
-        /**
598
-         * Dynamic hook allowing for adding additional columns in this list table.
599
-         * Note that $this->screen->id is in the format
600
-         * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
601
-         * table it is: event-espresso_page_espresso_messages.
602
-         * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
603
-         * hook prefix ("event-espresso") will be different.
604
-         *
605
-         * @var array
606
-         */
607
-        return apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen);
608
-    }
609
-
610
-
611
-    /**
612
-     * Get an associative array ( id => link ) with the list
613
-     * of views available on this table.
614
-     *
615
-     * @return array
616
-     * @since  3.1.0
617
-     * @access protected
618
-     */
619
-    public function get_views()
620
-    {
621
-        return $this->_views;
622
-    }
623
-
624
-
625
-    /**
626
-     * Generate the views html.
627
-     */
628
-    public function display_views()
629
-    {
630
-        $views           = $this->get_views();
631
-        $assembled_views = [];
632
-
633
-        if (empty($views)) {
634
-            return;
635
-        }
636
-        echo "<ul class='subsubsub'>\n";
637
-        foreach ($views as $view) {
638
-            $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0;
639
-            if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) {
640
-                $filter = "<li";
641
-                $filter .= $view['class'] ? " class='" . esc_attr($view['class']) . "'" : '';
642
-                $filter .= ">";
643
-                $filter .= '<a href="' . esc_url_raw($view['url']) . '">' . esc_html($view['label']) . '</a>';
644
-                $filter .= '<span class="count">(' . $count . ')</span>';
645
-                $filter .= '</li>';
646
-                $assembled_views[ $view['slug'] ] = $filter;
647
-            }
648
-        }
649
-
650
-        echo ! empty($assembled_views)
651
-            ? implode("<li style='margin:0 .5rem;'>|</li>", $assembled_views)
652
-            : '';
653
-        echo "</ul>";
654
-    }
655
-
656
-
657
-    /**
658
-     * Generates content for a single row of the table
659
-     *
660
-     * @param EE_Base_Class $item The current item
661
-     * @since  4.1
662
-     * @access public
663
-     */
664
-    public function single_row($item)
665
-    {
666
-        $row_class = $this->_get_row_class($item);
667
-        echo '<tr class="' . esc_attr($row_class) . '">';
668
-        $this->single_row_columns($item); // already escaped
669
-        echo '</tr>';
670
-    }
671
-
672
-
673
-    /**
674
-     * This simply sets up the row class for the table rows.
675
-     * Allows for easier overriding of child methods for setting up sorting.
676
-     *
677
-     * @param EE_Base_Class $item the current item
678
-     * @return string
679
-     */
680
-    protected function _get_row_class($item)
681
-    {
682
-        static $row_class = '';
683
-        $row_class = ($row_class === '' ? 'alternate' : '');
684
-
685
-        $new_row_class = $row_class;
686
-
687
-        if (! empty($this->_ajax_sorting_callback)) {
688
-            $new_row_class .= ' rowsortable';
689
-        }
690
-
691
-        return $new_row_class;
692
-    }
693
-
694
-
695
-    /**
696
-     * @return array
697
-     */
698
-    public function get_sortable_columns()
699
-    {
700
-        return (array) $this->_sortable_columns;
701
-    }
702
-
703
-
704
-    /**
705
-     * @return string
706
-     */
707
-    public function get_ajax_sorting_callback()
708
-    {
709
-        return $this->_ajax_sorting_callback;
710
-    }
711
-
712
-
713
-    /**
714
-     * @return array
715
-     */
716
-    public function get_hidden_columns()
717
-    {
718
-        $user_id     = get_current_user_id();
719
-        $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id);
720
-        if (empty($has_default) && ! empty($this->_hidden_columns)) {
721
-            update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true);
722
-            update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true);
723
-        }
724
-        $ref = 'manage' . $this->screen->id . 'columnshidden';
725
-        return (array) get_user_option($ref, $user_id);
726
-    }
727
-
728
-
729
-    /**
730
-     * Generates the columns for a single row of the table.
731
-     * Overridden from wp_list_table so as to allow us to filter the column content for a given
732
-     * column.
733
-     *
734
-     * @param EE_Base_Class $item The current item
735
-     * @since 3.1.0
736
-     */
737
-    public function single_row_columns($item)
738
-    {
739
-        [$columns, $hidden, $sortable, $primary] = $this->get_column_info();
740
-
741
-        foreach ($columns as $column_name => $column_display_name) {
742
-
743
-            /**
744
-             * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns
745
-             * are hidden or not instead of using "display:none;".  This bit of code provides backward compat.
746
-             */
747
-            $hidden_class = in_array($column_name, $hidden) ? ' hidden' : '';
748
-
749
-            $classes = $column_name . ' column-' . $column_name . $hidden_class;
750
-            if ($primary === $column_name) {
751
-                $classes .= ' has-row-actions column-primary';
752
-            }
753
-
754
-            $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"';
755
-
756
-            $class = 'class="' . esc_attr($classes) . '"';
757
-
758
-            $attributes = "{$class}{$data}";
759
-
760
-            if ($column_name === 'cb') {
761
-                echo '<th scope="row" class="check-column">';
762
-                echo apply_filters(
763
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content',
764
-                    $this->column_cb($item), // already escaped
765
-                    $item,
766
-                    $this
767
-                );
768
-                echo '</th>';
769
-            } elseif (method_exists($this, 'column_' . $column_name)) {
770
-                echo "<td $attributes>"; // already escaped
771
-                echo apply_filters(
772
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content',
773
-                    call_user_func([$this, 'column_' . $column_name], $item),
774
-                    $item,
775
-                    $this
776
-                );
777
-                echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags());
778
-                echo "</td>";
779
-            } else {
780
-                echo "<td $attributes>"; // already escaped
781
-                echo apply_filters(
782
-                    'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content',
783
-                    $this->column_default($item, $column_name),
784
-                    $item,
785
-                    $column_name,
786
-                    $this
787
-                );
788
-                echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags());
789
-                echo "</td>";
790
-            }
791
-        }
792
-    }
793
-
794
-
795
-    /**
796
-     * Extra controls to be displayed between bulk actions and pagination
797
-     *
798
-     * @access public
799
-     * @param string $which
800
-     * @throws EE_Error
801
-     */
802
-    public function extra_tablenav($which)
803
-    {
804
-        if ($which === 'top') {
805
-            $this->_filters();
806
-            echo wp_kses($this->_get_hidden_fields(), AllowedTags::getWithFormTags());
807
-        } else {
808
-            echo '<div class="list-table-bottom-buttons alignleft actions">';
809
-            foreach ($this->_bottom_buttons as $type => $action) {
810
-                $route         = isset($action['route']) ? $action['route'] : '';
811
-                $extra_request = isset($action['extra_request']) ? $action['extra_request'] : '';
812
-                // already escaped
813
-                echo wp_kses($this->_admin_page->get_action_link_or_button(
814
-                    $route,
815
-                    $type,
816
-                    $extra_request,
817
-                    'button button--secondary'
818
-                ), AllowedTags::getWithFormTags());
819
-            }
820
-            do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen);
821
-            echo '</div>';
822
-        }
823
-    }
824
-
825
-
826
-    /**
827
-     * Get an associative array ( option_name => option_title ) with the list
828
-     * of bulk actions available on this table.
829
-     *
830
-     * @return array
831
-     * @since  3.1.0
832
-     * @access protected
833
-     */
834
-    public function get_bulk_actions()
835
-    {
836
-        return (array) $this->_get_bulk_actions();
837
-    }
838
-
839
-
840
-    /**
841
-     * Processing bulk actions.
842
-     */
843
-    public function process_bulk_action()
844
-    {
845
-        // this is not used it is handled by the child EE_Admin_Page class (routes).  However, including here for
846
-        // reference in case there is a case where it gets used.
847
-    }
848
-
849
-
850
-    /**
851
-     * returns the EE admin page this list table is associated with
852
-     *
853
-     * @return EE_Admin_Page
854
-     */
855
-    public function get_admin_page()
856
-    {
857
-        return $this->_admin_page;
858
-    }
859
-
860
-
861
-    /**
862
-     * A "helper" function for all children to provide an html string of
863
-     * actions to output in their content.  It is preferable for child classes
864
-     * to use this method for generating their actions content so that it's
865
-     * filterable by plugins
866
-     *
867
-     * @param string        $action_container           what are the html container
868
-     *                                                  elements for this actions string?
869
-     * @param string        $action_class               What class is for the container
870
-     *                                                  element.
871
-     * @param string        $action_items               The contents for the action items
872
-     *                                                  container.  This is filtered before
873
-     *                                                  returned.
874
-     * @param string        $action_id                  What id (optional) is used for the
875
-     *                                                  container element.
876
-     * @param EE_Base_Class $item                       The object for the column displaying
877
-     *                                                  the actions.
878
-     * @return string The assembled action elements container.
879
-     */
880
-    protected function _action_string(
881
-        $action_items,
882
-        $item,
883
-        $action_container = 'ul',
884
-        $action_class = '',
885
-        $action_id = ''
886
-    ) {
887
-        $action_class = ! empty($action_class) ? ' class="' . esc_attr($action_class) . '"' : '';
888
-        $action_id    = ! empty($action_id) ? ' id="' . esc_attr($action_id) . '"' : '';
889
-        $open_tag     = ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : '';
890
-        $close_tag    = ! empty($action_container) ? '</' . $action_container . '>' : '';
891
-        try {
892
-            $content = apply_filters(
893
-                'FHEE__EE_Admin_List_Table___action_string__action_items',
894
-                $action_items,
895
-                $item,
896
-                $this
897
-            );
898
-        } catch (Exception $e) {
899
-            if (WP_DEBUG) {
900
-                EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
901
-            }
902
-            $content = $action_items;
903
-        }
904
-        return "{$open_tag}{$content}{$close_tag}";
905
-    }
906
-
907
-
908
-    /**
909
-     * @return string
910
-     */
911
-    protected function getReturnUrl()
912
-    {
913
-        $host = $this->_admin_page->get_request()->getServerParam('HTTP_HOST');
914
-        $uri  = $this->_admin_page->get_request()->getServerParam('REQUEST_URI');
915
-        return urlencode(esc_url_raw("//{$host}{$uri}"));
916
-    }
465
+	}
466
+
467
+
468
+	/**
469
+	 * _filters
470
+	 * This receives the filters array from children _get_table_filters() and assembles the string including the filter
471
+	 * button.
472
+	 *
473
+	 * @access private
474
+	 * @return void  echos html showing filters
475
+	 */
476
+	private function _filters()
477
+	{
478
+		$classname = get_class($this);
479
+		$filters   = apply_filters(
480
+			"FHEE__{$classname}__filters",
481
+			(array) $this->_get_table_filters(),
482
+			$this,
483
+			$this->_screen
484
+		);
485
+
486
+		if (empty($filters)) {
487
+			return;
488
+		}
489
+		$use_filters = isset($this->_req_data['use_filters'])
490
+					   && filter_var($this->_req_data['use_filters'], FILTER_VALIDATE_BOOLEAN)
491
+			? 'yes'
492
+			: 'no';
493
+
494
+		echo '<div class="ee-list-table-filters actions alignleft">';
495
+		foreach ($filters as $filter) {
496
+			echo wp_kses($filter, AllowedTags::getWithFormTags());
497
+		}
498
+		// add filter button at end
499
+		echo '<input type="submit" class="ee-list-table-filter-submit button button--secondary" value="'
500
+			 . esc_html__('Filter', 'event_espresso')
501
+			 . '" id="post-query-submit" />';
502
+		echo '<input type="hidden" id="ee-list-table-use-filters" name="use_filters" value="' . $use_filters . '"/>';
503
+
504
+		// add reset filters button at end
505
+		echo '<a class="button button--secondary"  href="'
506
+			 . esc_url_raw($this->_admin_page->get_current_page_view_url())
507
+			 . '" style="display:inline-block">'
508
+			 . esc_html__('Reset Filters', 'event_espresso')
509
+			 . '</a>';
510
+		echo '</div>';
511
+	}
512
+
513
+
514
+	/**
515
+	 * Callback for 'list_table_primary_column' WordPress filter
516
+	 * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary
517
+	 * column when class is instantiated.
518
+	 *
519
+	 * @param string $column_name
520
+	 * @return string
521
+	 * @see WP_List_Table::get_primary_column_name
522
+	 */
523
+	public function set_primary_column($column_name)
524
+	{
525
+		return ! empty($this->_primary_column) ? $this->_primary_column : $column_name;
526
+	}
527
+
528
+
529
+	/**
530
+	 *
531
+	 */
532
+	public function prepare_items()
533
+	{
534
+		$this->_set_column_info();
535
+		$this->process_bulk_action();
536
+
537
+		$this->items = $this->_data;
538
+		$this->set_pagination_args(
539
+			[
540
+				'total_items' => $this->_all_data_count,
541
+				'per_page'    => $this->_per_page,
542
+				'total_pages' => (int) ceil($this->_all_data_count / $this->_per_page),
543
+			]
544
+		);
545
+	}
546
+
547
+
548
+	/**
549
+	 * @param object|array $item
550
+	 * @return string html content for the column
551
+	 */
552
+	protected function column_cb($item)
553
+	{
554
+		return '';
555
+	}
556
+
557
+
558
+	/**
559
+	 * This column is the default for when there is no defined column method for a registered column.
560
+	 * This can be overridden by child classes, but allows for hooking in for custom columns.
561
+	 *
562
+	 * @param EE_Base_Class $item
563
+	 * @param string        $column_name The column being called.
564
+	 * @return string html content for the column
565
+	 */
566
+	public function column_default($item, $column_name)
567
+	{
568
+		/**
569
+		 * Dynamic hook allowing for adding additional column content in this list table.
570
+		 * Note that $this->screen->id is in the format
571
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
572
+		 * table it is: event-espresso_page_espresso_messages.
573
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
574
+		 * hook prefix ("event-espresso") will be different.
575
+		 */
576
+		ob_start();
577
+		do_action(
578
+			'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id,
579
+			$item,
580
+			$this->_screen
581
+		);
582
+		return ob_get_clean();
583
+	}
584
+
585
+
586
+	/**
587
+	 * Get a list of columns. The format is:
588
+	 * 'internal-name' => 'Title'
589
+	 *
590
+	 * @return array
591
+	 * @since  3.1.0
592
+	 * @access public
593
+	 * @abstract
594
+	 */
595
+	public function get_columns()
596
+	{
597
+		/**
598
+		 * Dynamic hook allowing for adding additional columns in this list table.
599
+		 * Note that $this->screen->id is in the format
600
+		 * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}.  So for the messages list
601
+		 * table it is: event-espresso_page_espresso_messages.
602
+		 * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the
603
+		 * hook prefix ("event-espresso") will be different.
604
+		 *
605
+		 * @var array
606
+		 */
607
+		return apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen);
608
+	}
609
+
610
+
611
+	/**
612
+	 * Get an associative array ( id => link ) with the list
613
+	 * of views available on this table.
614
+	 *
615
+	 * @return array
616
+	 * @since  3.1.0
617
+	 * @access protected
618
+	 */
619
+	public function get_views()
620
+	{
621
+		return $this->_views;
622
+	}
623
+
624
+
625
+	/**
626
+	 * Generate the views html.
627
+	 */
628
+	public function display_views()
629
+	{
630
+		$views           = $this->get_views();
631
+		$assembled_views = [];
632
+
633
+		if (empty($views)) {
634
+			return;
635
+		}
636
+		echo "<ul class='subsubsub'>\n";
637
+		foreach ($views as $view) {
638
+			$count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0;
639
+			if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) {
640
+				$filter = "<li";
641
+				$filter .= $view['class'] ? " class='" . esc_attr($view['class']) . "'" : '';
642
+				$filter .= ">";
643
+				$filter .= '<a href="' . esc_url_raw($view['url']) . '">' . esc_html($view['label']) . '</a>';
644
+				$filter .= '<span class="count">(' . $count . ')</span>';
645
+				$filter .= '</li>';
646
+				$assembled_views[ $view['slug'] ] = $filter;
647
+			}
648
+		}
649
+
650
+		echo ! empty($assembled_views)
651
+			? implode("<li style='margin:0 .5rem;'>|</li>", $assembled_views)
652
+			: '';
653
+		echo "</ul>";
654
+	}
655
+
656
+
657
+	/**
658
+	 * Generates content for a single row of the table
659
+	 *
660
+	 * @param EE_Base_Class $item The current item
661
+	 * @since  4.1
662
+	 * @access public
663
+	 */
664
+	public function single_row($item)
665
+	{
666
+		$row_class = $this->_get_row_class($item);
667
+		echo '<tr class="' . esc_attr($row_class) . '">';
668
+		$this->single_row_columns($item); // already escaped
669
+		echo '</tr>';
670
+	}
671
+
672
+
673
+	/**
674
+	 * This simply sets up the row class for the table rows.
675
+	 * Allows for easier overriding of child methods for setting up sorting.
676
+	 *
677
+	 * @param EE_Base_Class $item the current item
678
+	 * @return string
679
+	 */
680
+	protected function _get_row_class($item)
681
+	{
682
+		static $row_class = '';
683
+		$row_class = ($row_class === '' ? 'alternate' : '');
684
+
685
+		$new_row_class = $row_class;
686
+
687
+		if (! empty($this->_ajax_sorting_callback)) {
688
+			$new_row_class .= ' rowsortable';
689
+		}
690
+
691
+		return $new_row_class;
692
+	}
693
+
694
+
695
+	/**
696
+	 * @return array
697
+	 */
698
+	public function get_sortable_columns()
699
+	{
700
+		return (array) $this->_sortable_columns;
701
+	}
702
+
703
+
704
+	/**
705
+	 * @return string
706
+	 */
707
+	public function get_ajax_sorting_callback()
708
+	{
709
+		return $this->_ajax_sorting_callback;
710
+	}
711
+
712
+
713
+	/**
714
+	 * @return array
715
+	 */
716
+	public function get_hidden_columns()
717
+	{
718
+		$user_id     = get_current_user_id();
719
+		$has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id);
720
+		if (empty($has_default) && ! empty($this->_hidden_columns)) {
721
+			update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true);
722
+			update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true);
723
+		}
724
+		$ref = 'manage' . $this->screen->id . 'columnshidden';
725
+		return (array) get_user_option($ref, $user_id);
726
+	}
727
+
728
+
729
+	/**
730
+	 * Generates the columns for a single row of the table.
731
+	 * Overridden from wp_list_table so as to allow us to filter the column content for a given
732
+	 * column.
733
+	 *
734
+	 * @param EE_Base_Class $item The current item
735
+	 * @since 3.1.0
736
+	 */
737
+	public function single_row_columns($item)
738
+	{
739
+		[$columns, $hidden, $sortable, $primary] = $this->get_column_info();
740
+
741
+		foreach ($columns as $column_name => $column_display_name) {
742
+
743
+			/**
744
+			 * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns
745
+			 * are hidden or not instead of using "display:none;".  This bit of code provides backward compat.
746
+			 */
747
+			$hidden_class = in_array($column_name, $hidden) ? ' hidden' : '';
748
+
749
+			$classes = $column_name . ' column-' . $column_name . $hidden_class;
750
+			if ($primary === $column_name) {
751
+				$classes .= ' has-row-actions column-primary';
752
+			}
753
+
754
+			$data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"';
755
+
756
+			$class = 'class="' . esc_attr($classes) . '"';
757
+
758
+			$attributes = "{$class}{$data}";
759
+
760
+			if ($column_name === 'cb') {
761
+				echo '<th scope="row" class="check-column">';
762
+				echo apply_filters(
763
+					'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content',
764
+					$this->column_cb($item), // already escaped
765
+					$item,
766
+					$this
767
+				);
768
+				echo '</th>';
769
+			} elseif (method_exists($this, 'column_' . $column_name)) {
770
+				echo "<td $attributes>"; // already escaped
771
+				echo apply_filters(
772
+					'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content',
773
+					call_user_func([$this, 'column_' . $column_name], $item),
774
+					$item,
775
+					$this
776
+				);
777
+				echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags());
778
+				echo "</td>";
779
+			} else {
780
+				echo "<td $attributes>"; // already escaped
781
+				echo apply_filters(
782
+					'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content',
783
+					$this->column_default($item, $column_name),
784
+					$item,
785
+					$column_name,
786
+					$this
787
+				);
788
+				echo wp_kses($this->handle_row_actions($item, $column_name, $primary), AllowedTags::getWithFormTags());
789
+				echo "</td>";
790
+			}
791
+		}
792
+	}
793
+
794
+
795
+	/**
796
+	 * Extra controls to be displayed between bulk actions and pagination
797
+	 *
798
+	 * @access public
799
+	 * @param string $which
800
+	 * @throws EE_Error
801
+	 */
802
+	public function extra_tablenav($which)
803
+	{
804
+		if ($which === 'top') {
805
+			$this->_filters();
806
+			echo wp_kses($this->_get_hidden_fields(), AllowedTags::getWithFormTags());
807
+		} else {
808
+			echo '<div class="list-table-bottom-buttons alignleft actions">';
809
+			foreach ($this->_bottom_buttons as $type => $action) {
810
+				$route         = isset($action['route']) ? $action['route'] : '';
811
+				$extra_request = isset($action['extra_request']) ? $action['extra_request'] : '';
812
+				// already escaped
813
+				echo wp_kses($this->_admin_page->get_action_link_or_button(
814
+					$route,
815
+					$type,
816
+					$extra_request,
817
+					'button button--secondary'
818
+				), AllowedTags::getWithFormTags());
819
+			}
820
+			do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen);
821
+			echo '</div>';
822
+		}
823
+	}
824
+
825
+
826
+	/**
827
+	 * Get an associative array ( option_name => option_title ) with the list
828
+	 * of bulk actions available on this table.
829
+	 *
830
+	 * @return array
831
+	 * @since  3.1.0
832
+	 * @access protected
833
+	 */
834
+	public function get_bulk_actions()
835
+	{
836
+		return (array) $this->_get_bulk_actions();
837
+	}
838
+
839
+
840
+	/**
841
+	 * Processing bulk actions.
842
+	 */
843
+	public function process_bulk_action()
844
+	{
845
+		// this is not used it is handled by the child EE_Admin_Page class (routes).  However, including here for
846
+		// reference in case there is a case where it gets used.
847
+	}
848
+
849
+
850
+	/**
851
+	 * returns the EE admin page this list table is associated with
852
+	 *
853
+	 * @return EE_Admin_Page
854
+	 */
855
+	public function get_admin_page()
856
+	{
857
+		return $this->_admin_page;
858
+	}
859
+
860
+
861
+	/**
862
+	 * A "helper" function for all children to provide an html string of
863
+	 * actions to output in their content.  It is preferable for child classes
864
+	 * to use this method for generating their actions content so that it's
865
+	 * filterable by plugins
866
+	 *
867
+	 * @param string        $action_container           what are the html container
868
+	 *                                                  elements for this actions string?
869
+	 * @param string        $action_class               What class is for the container
870
+	 *                                                  element.
871
+	 * @param string        $action_items               The contents for the action items
872
+	 *                                                  container.  This is filtered before
873
+	 *                                                  returned.
874
+	 * @param string        $action_id                  What id (optional) is used for the
875
+	 *                                                  container element.
876
+	 * @param EE_Base_Class $item                       The object for the column displaying
877
+	 *                                                  the actions.
878
+	 * @return string The assembled action elements container.
879
+	 */
880
+	protected function _action_string(
881
+		$action_items,
882
+		$item,
883
+		$action_container = 'ul',
884
+		$action_class = '',
885
+		$action_id = ''
886
+	) {
887
+		$action_class = ! empty($action_class) ? ' class="' . esc_attr($action_class) . '"' : '';
888
+		$action_id    = ! empty($action_id) ? ' id="' . esc_attr($action_id) . '"' : '';
889
+		$open_tag     = ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : '';
890
+		$close_tag    = ! empty($action_container) ? '</' . $action_container . '>' : '';
891
+		try {
892
+			$content = apply_filters(
893
+				'FHEE__EE_Admin_List_Table___action_string__action_items',
894
+				$action_items,
895
+				$item,
896
+				$this
897
+			);
898
+		} catch (Exception $e) {
899
+			if (WP_DEBUG) {
900
+				EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
901
+			}
902
+			$content = $action_items;
903
+		}
904
+		return "{$open_tag}{$content}{$close_tag}";
905
+	}
906
+
907
+
908
+	/**
909
+	 * @return string
910
+	 */
911
+	protected function getReturnUrl()
912
+	{
913
+		$host = $this->_admin_page->get_request()->getServerParam('HTTP_HOST');
914
+		$uri  = $this->_admin_page->get_request()->getServerParam('REQUEST_URI');
915
+		return urlencode(esc_url_raw("//{$host}{$uri}"));
916
+	}
917 917
 }
Please login to merge, or discard this patch.
core/EE_Deprecated.core.php 1 patch
Indentation   +1222 added lines, -1222 removed lines patch added patch discarded remove patch
@@ -39,31 +39,31 @@  discard block
 block discarded – undo
39 39
  * @param string $action_or_filter
40 40
  */
41 41
 function deprecated_espresso_action_or_filter_doing_it_wrong(
42
-    $deprecated_filter,
43
-    $replacement,
44
-    $replacement_location,
45
-    $version_deprecated,
46
-    $version_applies,
47
-    $action_or_filter = 'action'
42
+	$deprecated_filter,
43
+	$replacement,
44
+	$replacement_location,
45
+	$version_deprecated,
46
+	$version_applies,
47
+	$action_or_filter = 'action'
48 48
 ) {
49
-    $action_or_filter = $action_or_filter === 'action'
50
-        ? esc_html__('action', 'event_espresso')
51
-        : esc_html__('filter', 'event_espresso');
52
-    EE_Error::doing_it_wrong(
53
-        $deprecated_filter,
54
-        sprintf(
55
-            esc_html__(
56
-                'This %1$s is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new %1$s: %4$s"%2$s" found in "%3$s"',
57
-                'event_espresso'
58
-            ),
59
-            $action_or_filter,
60
-            $replacement,
61
-            $replacement_location,
62
-            '<br />'
63
-        ),
64
-        $version_deprecated,
65
-        $version_applies
66
-    );
49
+	$action_or_filter = $action_or_filter === 'action'
50
+		? esc_html__('action', 'event_espresso')
51
+		: esc_html__('filter', 'event_espresso');
52
+	EE_Error::doing_it_wrong(
53
+		$deprecated_filter,
54
+		sprintf(
55
+			esc_html__(
56
+				'This %1$s is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new %1$s: %4$s"%2$s" found in "%3$s"',
57
+				'event_espresso'
58
+			),
59
+			$action_or_filter,
60
+			$replacement,
61
+			$replacement_location,
62
+			'<br />'
63
+		),
64
+		$version_deprecated,
65
+		$version_applies
66
+	);
67 67
 }
68 68
 
69 69
 /**
@@ -75,90 +75,90 @@  discard block
 block discarded – undo
75 75
  */
76 76
 function ee_deprecated__registration_checkout__button_text($submit_button_text, EE_Checkout $checkout)
77 77
 {
78
-    // list of old filters
79
-    $deprecated_filters = array(
80
-        'update_registration_details' => true,
81
-        'process_payment'             => true,
82
-        'finalize_registration'       => true,
83
-        'and_proceed_to_payment'      => true,
84
-        'proceed_to'                  => true,
85
-    );
86
-    // loop thru and call doing_it_wrong() or remove any that aren't being used
87
-    foreach ($deprecated_filters as $deprecated_filter => $on) {
88
-        // was this filter called ?
89
-        if (has_action('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter)) {
90
-            // only display doing_it_wrong() notice to Event Admins during non-AJAX requests
91
-            if (EE_Registry::instance()->CAP->current_user_can(
92
-                    'ee_read_ee',
93
-                    'hide_doing_it_wrong_for_deprecated_SPCO_filter'
94
-                ) && ! defined('DOING_AJAX')) {
95
-                EE_Error::doing_it_wrong(
96
-                    'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter,
97
-                    sprintf(
98
-                        esc_html__(
99
-                            'The %1$s filter is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"',
100
-                            'event_espresso'
101
-                        ),
102
-                        'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter,
103
-                        '<br />',
104
-                        'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
105
-                        '/modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php'
106
-                    ),
107
-                    '4.6.10'
108
-                );
109
-            }
110
-        } else {
111
-            unset($deprecated_filters[ $deprecated_filter ]);
112
-        }
113
-    }
114
-    if (! empty($deprecated_filters)) {
115
-
116
-        if ($checkout->current_step->slug(
117
-            ) == 'attendee_information' && $checkout->revisit && isset($deprecated_filters['update_registration_details'])) {
118
-            $submit_button_text = apply_filters(
119
-                'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details',
120
-                $submit_button_text
121
-            );
122
-        } elseif ($checkout->current_step->slug(
123
-            ) == 'payment_options' && $checkout->revisit && isset($deprecated_filters['process_payment'])) {
124
-            $submit_button_text = apply_filters(
125
-                'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment',
126
-                $submit_button_text
127
-            );
128
-        } elseif ($checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug(
129
-            ) == 'finalize_registration' && isset($deprecated_filters['finalize_registration'])) {
130
-            $submit_button_text = apply_filters(
131
-                'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration',
132
-                $submit_button_text
133
-            );
134
-        }
135
-        if ($checkout->next_step instanceof EE_SPCO_Reg_Step) {
136
-            if ($checkout->payment_required() && $checkout->next_step->slug(
137
-                ) == 'payment_options' && isset($deprecated_filters['and_proceed_to_payment'])) {
138
-                $submit_button_text .= apply_filters(
139
-                    'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment',
140
-                    $submit_button_text
141
-                );
142
-            }
143
-            if ($checkout->next_step->slug(
144
-                ) != 'finalize_registration' && ! $checkout->revisit && isset($deprecated_filters['proceed_to'])) {
145
-                $submit_button_text = apply_filters(
146
-                                          'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to',
147
-                                          $submit_button_text
148
-                                      ) . $checkout->next_step->name();
149
-            }
150
-        }
151
-
152
-    }
153
-    return $submit_button_text;
78
+	// list of old filters
79
+	$deprecated_filters = array(
80
+		'update_registration_details' => true,
81
+		'process_payment'             => true,
82
+		'finalize_registration'       => true,
83
+		'and_proceed_to_payment'      => true,
84
+		'proceed_to'                  => true,
85
+	);
86
+	// loop thru and call doing_it_wrong() or remove any that aren't being used
87
+	foreach ($deprecated_filters as $deprecated_filter => $on) {
88
+		// was this filter called ?
89
+		if (has_action('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter)) {
90
+			// only display doing_it_wrong() notice to Event Admins during non-AJAX requests
91
+			if (EE_Registry::instance()->CAP->current_user_can(
92
+					'ee_read_ee',
93
+					'hide_doing_it_wrong_for_deprecated_SPCO_filter'
94
+				) && ! defined('DOING_AJAX')) {
95
+				EE_Error::doing_it_wrong(
96
+					'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter,
97
+					sprintf(
98
+						esc_html__(
99
+							'The %1$s filter is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new filter: %2$s"%3$s" found in "%4$s"',
100
+							'event_espresso'
101
+						),
102
+						'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__' . $deprecated_filter,
103
+						'<br />',
104
+						'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
105
+						'/modules/single_page_checkout/inc/EE_SPCO_Reg_Step.class.php'
106
+					),
107
+					'4.6.10'
108
+				);
109
+			}
110
+		} else {
111
+			unset($deprecated_filters[ $deprecated_filter ]);
112
+		}
113
+	}
114
+	if (! empty($deprecated_filters)) {
115
+
116
+		if ($checkout->current_step->slug(
117
+			) == 'attendee_information' && $checkout->revisit && isset($deprecated_filters['update_registration_details'])) {
118
+			$submit_button_text = apply_filters(
119
+				'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details',
120
+				$submit_button_text
121
+			);
122
+		} elseif ($checkout->current_step->slug(
123
+			) == 'payment_options' && $checkout->revisit && isset($deprecated_filters['process_payment'])) {
124
+			$submit_button_text = apply_filters(
125
+				'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment',
126
+				$submit_button_text
127
+			);
128
+		} elseif ($checkout->next_step instanceof EE_SPCO_Reg_Step && $checkout->next_step->slug(
129
+			) == 'finalize_registration' && isset($deprecated_filters['finalize_registration'])) {
130
+			$submit_button_text = apply_filters(
131
+				'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration',
132
+				$submit_button_text
133
+			);
134
+		}
135
+		if ($checkout->next_step instanceof EE_SPCO_Reg_Step) {
136
+			if ($checkout->payment_required() && $checkout->next_step->slug(
137
+				) == 'payment_options' && isset($deprecated_filters['and_proceed_to_payment'])) {
138
+				$submit_button_text .= apply_filters(
139
+					'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment',
140
+					$submit_button_text
141
+				);
142
+			}
143
+			if ($checkout->next_step->slug(
144
+				) != 'finalize_registration' && ! $checkout->revisit && isset($deprecated_filters['proceed_to'])) {
145
+				$submit_button_text = apply_filters(
146
+										  'FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to',
147
+										  $submit_button_text
148
+									  ) . $checkout->next_step->name();
149
+			}
150
+		}
151
+
152
+	}
153
+	return $submit_button_text;
154 154
 
155 155
 }
156 156
 
157 157
 add_filter(
158
-    'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
159
-    'ee_deprecated__registration_checkout__button_text',
160
-    10,
161
-    2
158
+	'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text',
159
+	'ee_deprecated__registration_checkout__button_text',
160
+	10,
161
+	2
162 162
 );
163 163
 
164 164
 
@@ -170,54 +170,54 @@  discard block
 block discarded – undo
170 170
  */
171 171
 function ee_deprecated_finalize_transaction(EE_Checkout $checkout, $status_updates)
172 172
 {
173
-    $action_ref = null;
174
-    $action_ref = has_action('AHEE__EE_Transaction__finalize__new_transaction')
175
-        ? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref;
176
-    $action_ref = has_action('AHEE__EE_Transaction__finalize__all_transaction')
177
-        ? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref;
178
-    if ($action_ref) {
179
-
180
-        EE_Error::doing_it_wrong(
181
-            $action_ref,
182
-            sprintf(
183
-                esc_html__(
184
-                    'This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"',
185
-                    'event_espresso'
186
-                ),
187
-                '<br />',
188
-                '/core/business/EE_Transaction_Processor.class.php',
189
-                'AHEE__EE_Transaction_Processor__finalize',
190
-                'AHEE__EE_Transaction_Processor__manually_update_registration_statuses',
191
-                'AHEE__EE_Transaction_Processor__toggle_registration_statuses_for_default_approved_events',
192
-                'AHEE__EE_Transaction_Processor__toggle_registration_statuses_if_no_monies_owing'
193
-            ),
194
-            '4.6.0'
195
-        );
196
-        switch ($action_ref) {
197
-            case 'AHEE__EE_Transaction__finalize__new_transaction' :
198
-                do_action(
199
-                    'AHEE__EE_Transaction__finalize__new_transaction',
200
-                    $checkout->transaction,
201
-                    $checkout->admin_request
202
-                );
203
-                break;
204
-            case 'AHEE__EE_Transaction__finalize__all_transaction' :
205
-                do_action(
206
-                    'AHEE__EE_Transaction__finalize__new_transaction',
207
-                    $checkout->transaction,
208
-                    array('new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates),
209
-                    $checkout->admin_request
210
-                );
211
-                break;
212
-        }
213
-    }
173
+	$action_ref = null;
174
+	$action_ref = has_action('AHEE__EE_Transaction__finalize__new_transaction')
175
+		? 'AHEE__EE_Transaction__finalize__new_transaction' : $action_ref;
176
+	$action_ref = has_action('AHEE__EE_Transaction__finalize__all_transaction')
177
+		? 'AHEE__EE_Transaction__finalize__all_transaction' : $action_ref;
178
+	if ($action_ref) {
179
+
180
+		EE_Error::doing_it_wrong(
181
+			$action_ref,
182
+			sprintf(
183
+				esc_html__(
184
+					'This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use one of the following new actions: %1$s"%3$s" found in "%2$s" %1$s"%4$s" found in "%2$s" %1$s"%5$s" found in "%2$s" %1$s"%6$s" found in "%2$s"',
185
+					'event_espresso'
186
+				),
187
+				'<br />',
188
+				'/core/business/EE_Transaction_Processor.class.php',
189
+				'AHEE__EE_Transaction_Processor__finalize',
190
+				'AHEE__EE_Transaction_Processor__manually_update_registration_statuses',
191
+				'AHEE__EE_Transaction_Processor__toggle_registration_statuses_for_default_approved_events',
192
+				'AHEE__EE_Transaction_Processor__toggle_registration_statuses_if_no_monies_owing'
193
+			),
194
+			'4.6.0'
195
+		);
196
+		switch ($action_ref) {
197
+			case 'AHEE__EE_Transaction__finalize__new_transaction' :
198
+				do_action(
199
+					'AHEE__EE_Transaction__finalize__new_transaction',
200
+					$checkout->transaction,
201
+					$checkout->admin_request
202
+				);
203
+				break;
204
+			case 'AHEE__EE_Transaction__finalize__all_transaction' :
205
+				do_action(
206
+					'AHEE__EE_Transaction__finalize__new_transaction',
207
+					$checkout->transaction,
208
+					array('new_reg' => ! $checkout->revisit, 'to_approved' => $status_updates),
209
+					$checkout->admin_request
210
+				);
211
+				break;
212
+		}
213
+	}
214 214
 }
215 215
 
216 216
 add_action(
217
-    'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed',
218
-    'ee_deprecated_finalize_transaction',
219
-    10,
220
-    2
217
+	'AHEE__EE_SPCO_Reg_Step_Finalize_Registration__process_reg_step__completed',
218
+	'ee_deprecated_finalize_transaction',
219
+	10,
220
+	2
221 221
 );
222 222
 /**
223 223
  * ee_deprecated_finalize_registration
@@ -226,35 +226,35 @@  discard block
 block discarded – undo
226 226
  */
227 227
 function ee_deprecated_finalize_registration(EE_Registration $registration)
228 228
 {
229
-    $action_ref = has_action('AHEE__EE_Registration__finalize__update_and_new_reg')
230
-        ? 'AHEE__EE_Registration__finalize__update_and_new_reg' : null;
231
-    if ($action_ref) {
232
-        EE_Error::doing_it_wrong(
233
-            $action_ref,
234
-            sprintf(
235
-                esc_html__(
236
-                    'This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"',
237
-                    'event_espresso'
238
-                ),
239
-                '<br />',
240
-                '/core/business/EE_Registration_Processor.class.php',
241
-                'AHEE__EE_Registration_Processor__trigger_registration_update_notifications'
242
-            ),
243
-            '4.6.0'
244
-        );
245
-        do_action(
246
-            'AHEE__EE_Registration__finalize__update_and_new_reg',
247
-            $registration,
248
-            (is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX))
249
-        );
250
-    }
229
+	$action_ref = has_action('AHEE__EE_Registration__finalize__update_and_new_reg')
230
+		? 'AHEE__EE_Registration__finalize__update_and_new_reg' : null;
231
+	if ($action_ref) {
232
+		EE_Error::doing_it_wrong(
233
+			$action_ref,
234
+			sprintf(
235
+				esc_html__(
236
+					'This action is deprecated.  It *may* work as an attempt to build in backwards compatibility.  However, it is recommended to use the following new action: %1$s"%3$s" found in "%2$s"',
237
+					'event_espresso'
238
+				),
239
+				'<br />',
240
+				'/core/business/EE_Registration_Processor.class.php',
241
+				'AHEE__EE_Registration_Processor__trigger_registration_update_notifications'
242
+			),
243
+			'4.6.0'
244
+		);
245
+		do_action(
246
+			'AHEE__EE_Registration__finalize__update_and_new_reg',
247
+			$registration,
248
+			(is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX))
249
+		);
250
+	}
251 251
 }
252 252
 
253 253
 add_action(
254
-    'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
255
-    'ee_deprecated_finalize_registration',
256
-    10,
257
-    1
254
+	'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
255
+	'ee_deprecated_finalize_registration',
256
+	10,
257
+	1
258 258
 );
259 259
 
260 260
 
@@ -264,44 +264,44 @@  discard block
 block discarded – undo
264 264
  */
265 265
 function ee_deprecated_hooks()
266 266
 {
267
-    /**
268
-     * @var          $hooks       array where keys are hook names, and their values are array{
269
-     * @type string  $version     when deprecated
270
-     * @type string  $alternative saying what to use instead
271
-     * @type boolean $still_works whether or not the hook still works
272
-     *        }
273
-     */
274
-    $hooks = array(
275
-        'AHEE__EE_System___do_setup_validations' => array(
276
-            'version'     => '4.6.0',
277
-            'alternative' => esc_html__(
278
-                'Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)',
279
-                'event_espresso'
280
-            ),
281
-            'still_works' => false,
282
-        ),
283
-    );
284
-    foreach ($hooks as $name => $deprecation_info) {
285
-        if (has_action($name)) {
286
-            EE_Error::doing_it_wrong(
287
-                $name,
288
-                sprintf(
289
-                    esc_html__('This filter is deprecated. %1$s%2$s', 'event_espresso'),
290
-                    $deprecation_info['still_works'] ? esc_html__(
291
-                        'It *may* work as an attempt to build in backwards compatibility.',
292
-                        'event_espresso'
293
-                    ) : esc_html__('It has been completely removed.', 'event_espresso'),
294
-                    isset($deprecation_info['alternative'])
295
-                        ? $deprecation_info['alternative']
296
-                        : esc_html__(
297
-                        'Please read the current EE4 documentation further or contact Support.',
298
-                        'event_espresso'
299
-                    )
300
-                ),
301
-                isset($deprecation_info['version']) ? $deprecation_info['version'] : esc_html__('recently', 'event_espresso')
302
-            );
303
-        }
304
-    }
267
+	/**
268
+	 * @var          $hooks       array where keys are hook names, and their values are array{
269
+	 * @type string  $version     when deprecated
270
+	 * @type string  $alternative saying what to use instead
271
+	 * @type boolean $still_works whether or not the hook still works
272
+	 *        }
273
+	 */
274
+	$hooks = array(
275
+		'AHEE__EE_System___do_setup_validations' => array(
276
+			'version'     => '4.6.0',
277
+			'alternative' => esc_html__(
278
+				'Instead use "AHEE__EEH_Activation__validate_messages_system" which is called after validating messages (done on every new install, upgrade, reactivation, and downgrade)',
279
+				'event_espresso'
280
+			),
281
+			'still_works' => false,
282
+		),
283
+	);
284
+	foreach ($hooks as $name => $deprecation_info) {
285
+		if (has_action($name)) {
286
+			EE_Error::doing_it_wrong(
287
+				$name,
288
+				sprintf(
289
+					esc_html__('This filter is deprecated. %1$s%2$s', 'event_espresso'),
290
+					$deprecation_info['still_works'] ? esc_html__(
291
+						'It *may* work as an attempt to build in backwards compatibility.',
292
+						'event_espresso'
293
+					) : esc_html__('It has been completely removed.', 'event_espresso'),
294
+					isset($deprecation_info['alternative'])
295
+						? $deprecation_info['alternative']
296
+						: esc_html__(
297
+						'Please read the current EE4 documentation further or contact Support.',
298
+						'event_espresso'
299
+					)
300
+				),
301
+				isset($deprecation_info['version']) ? $deprecation_info['version'] : esc_html__('recently', 'event_espresso')
302
+			);
303
+		}
304
+	}
305 305
 }
306 306
 
307 307
 add_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', 'ee_deprecated_hooks');
@@ -316,34 +316,34 @@  discard block
 block discarded – undo
316 316
  */
317 317
 function ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
318 318
 {
319
-    $in_use = has_filter('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns')
320
-              || has_action(
321
-                  'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save'
322
-              );
323
-    if ($in_use) {
324
-        $msg = esc_html__(
325
-            'We detected you are using the filter FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns or AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save.'
326
-            . 'Both of these have been deprecated and should not be used anymore. You should instead use FHEE__EE_Form_Section_Proper___construct__options_array to customize the contents of the form,'
327
-            . 'use FHEE__EE_Form_Section_Proper__receive_form_submission__req_data to customize the submission data, or AHEE__EE_Form_Section_Proper__receive_form_submission__end '
328
-            . 'to add other actions after a form submission has been received.',
329
-            'event_espresso'
330
-        );
331
-        EE_Error::doing_it_wrong(
332
-            __CLASS__ . '::' . __FUNCTION__,
333
-            $msg,
334
-            '4.8.32.rc.000'
335
-        );
336
-        // it seems the doing_it_wrong messages get output during some hidden html tags, so add an error to make sure this gets noticed
337
-        if (is_admin() && ! defined('DOING_AJAX')) {
338
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
339
-        }
340
-    }
341
-    return $in_use;
319
+	$in_use = has_filter('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns')
320
+			  || has_action(
321
+				  'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save'
322
+			  );
323
+	if ($in_use) {
324
+		$msg = esc_html__(
325
+			'We detected you are using the filter FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns or AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save.'
326
+			. 'Both of these have been deprecated and should not be used anymore. You should instead use FHEE__EE_Form_Section_Proper___construct__options_array to customize the contents of the form,'
327
+			. 'use FHEE__EE_Form_Section_Proper__receive_form_submission__req_data to customize the submission data, or AHEE__EE_Form_Section_Proper__receive_form_submission__end '
328
+			. 'to add other actions after a form submission has been received.',
329
+			'event_espresso'
330
+		);
331
+		EE_Error::doing_it_wrong(
332
+			__CLASS__ . '::' . __FUNCTION__,
333
+			$msg,
334
+			'4.8.32.rc.000'
335
+		);
336
+		// it seems the doing_it_wrong messages get output during some hidden html tags, so add an error to make sure this gets noticed
337
+		if (is_admin() && ! defined('DOING_AJAX')) {
338
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
339
+		}
340
+	}
341
+	return $in_use;
342 342
 }
343 343
 
344 344
 add_action(
345
-    'AHEE__Registrations_Admin_Page___registration_details_metabox__start',
346
-    'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks'
345
+	'AHEE__Registrations_Admin_Page___registration_details_metabox__start',
346
+	'ee_deprecated_using_old_registration_admin_custom_questions_form_hooks'
347 347
 );
348 348
 
349 349
 /**
@@ -355,82 +355,82 @@  discard block
 block discarded – undo
355 355
  */
356 356
 function ee_deprecated_update_attendee_registration_form_old($admin_page)
357 357
 {
358
-    // check if the old hooks are in use. If not, do the default
359
-    if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
360
-        || ! $admin_page instanceof EE_Admin_Page) {
361
-        return;
362
-    }
363
-    $req_data = $admin_page->get_request_data();
364
-    $qstns = isset($req_data['qstn']) ? $req_data['qstn'] : false;
365
-    $REG_ID = isset($req_data['_REG_ID']) ? absint($req_data['_REG_ID']) : false;
366
-    $qstns = apply_filters('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns);
367
-    if (! $REG_ID || ! $qstns) {
368
-        EE_Error::add_error(
369
-            esc_html__('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'),
370
-            __FILE__,
371
-            __FUNCTION__,
372
-            __LINE__
373
-        );
374
-    }
375
-    $success = true;
376
-
377
-    // allow others to get in on this awesome fun   :D
378
-    do_action(
379
-        'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save',
380
-        $REG_ID,
381
-        $qstns
382
-    );
383
-    // loop thru questions... FINALLY!!!
384
-
385
-    foreach ($qstns as $QST_ID => $qstn) {
386
-        // if $qstn isn't an array then it doesn't already have an answer, so let's create the answer
387
-        if (! is_array($qstn)) {
388
-            $set_values = [
389
-                'QST_ID'    => $QST_ID,
390
-                'REG_ID'    => $REG_ID,
391
-                'ANS_value' => $qstn,
392
-            ];
393
-            $success    = EEM_Answer::instance()->insert($set_values);
394
-            continue;
395
-        }
396
-
397
-
398
-        foreach ($qstn as $ANS_ID => $ANS_value) {
399
-            // get answer
400
-            $query_params = array(
401
-                0 => array(
402
-                    'ANS_ID' => $ANS_ID,
403
-                    'REG_ID' => $REG_ID,
404
-                    'QST_ID' => $QST_ID,
405
-                ),
406
-            );
407
-            $answer = EEM_Answer::instance()->get_one($query_params);
408
-            // this MAY be an array but NOT have an answer because its multi select.  If so then we need to create the answer
409
-            if (! $answer instanceof EE_Answer) {
410
-                $set_values = array(
411
-                    'QST_ID'    => $QST_ID,
412
-                    'REG_ID'    => $REG_ID,
413
-                    'ANS_value' => $qstn,
414
-                );
415
-                $success = EEM_Answer::instance()->insert($set_values);
416
-                continue 2;
417
-            }
418
-
419
-            $answer->set('ANS_value', $ANS_value);
420
-            $success = $answer->save();
421
-        }
422
-    }
423
-    $what = esc_html__('Registration Form', 'event_espresso');
424
-    $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) : array('action' => 'default');
425
-    $admin_page->redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
426
-    exit;
358
+	// check if the old hooks are in use. If not, do the default
359
+	if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
360
+		|| ! $admin_page instanceof EE_Admin_Page) {
361
+		return;
362
+	}
363
+	$req_data = $admin_page->get_request_data();
364
+	$qstns = isset($req_data['qstn']) ? $req_data['qstn'] : false;
365
+	$REG_ID = isset($req_data['_REG_ID']) ? absint($req_data['_REG_ID']) : false;
366
+	$qstns = apply_filters('FHEE__Registrations_Admin_Page___update_attendee_registration_form__qstns', $qstns);
367
+	if (! $REG_ID || ! $qstns) {
368
+		EE_Error::add_error(
369
+			esc_html__('An error occurred. No registration ID and/or registration questions were received.', 'event_espresso'),
370
+			__FILE__,
371
+			__FUNCTION__,
372
+			__LINE__
373
+		);
374
+	}
375
+	$success = true;
376
+
377
+	// allow others to get in on this awesome fun   :D
378
+	do_action(
379
+		'AHEE__Registrations_Admin_Page___save_attendee_registration_form__after_reg_and_attendee_save',
380
+		$REG_ID,
381
+		$qstns
382
+	);
383
+	// loop thru questions... FINALLY!!!
384
+
385
+	foreach ($qstns as $QST_ID => $qstn) {
386
+		// if $qstn isn't an array then it doesn't already have an answer, so let's create the answer
387
+		if (! is_array($qstn)) {
388
+			$set_values = [
389
+				'QST_ID'    => $QST_ID,
390
+				'REG_ID'    => $REG_ID,
391
+				'ANS_value' => $qstn,
392
+			];
393
+			$success    = EEM_Answer::instance()->insert($set_values);
394
+			continue;
395
+		}
396
+
397
+
398
+		foreach ($qstn as $ANS_ID => $ANS_value) {
399
+			// get answer
400
+			$query_params = array(
401
+				0 => array(
402
+					'ANS_ID' => $ANS_ID,
403
+					'REG_ID' => $REG_ID,
404
+					'QST_ID' => $QST_ID,
405
+				),
406
+			);
407
+			$answer = EEM_Answer::instance()->get_one($query_params);
408
+			// this MAY be an array but NOT have an answer because its multi select.  If so then we need to create the answer
409
+			if (! $answer instanceof EE_Answer) {
410
+				$set_values = array(
411
+					'QST_ID'    => $QST_ID,
412
+					'REG_ID'    => $REG_ID,
413
+					'ANS_value' => $qstn,
414
+				);
415
+				$success = EEM_Answer::instance()->insert($set_values);
416
+				continue 2;
417
+			}
418
+
419
+			$answer->set('ANS_value', $ANS_value);
420
+			$success = $answer->save();
421
+		}
422
+	}
423
+	$what = esc_html__('Registration Form', 'event_espresso');
424
+	$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) : array('action' => 'default');
425
+	$admin_page->redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
426
+	exit;
427 427
 }
428 428
 
429 429
 add_action(
430
-    'AHEE__Registrations_Admin_Page___update_attendee_registration_form__start',
431
-    'ee_deprecated_update_attendee_registration_form_old',
432
-    10,
433
-    1
430
+	'AHEE__Registrations_Admin_Page___update_attendee_registration_form__start',
431
+	'ee_deprecated_update_attendee_registration_form_old',
432
+	10,
433
+	1
434 434
 );
435 435
 /**
436 436
  * Render the registration admin page's custom questions area in the old fashion
@@ -446,50 +446,50 @@  discard block
 block discarded – undo
446 446
  */
447 447
 function ee_deprecated_reg_questions_meta_box_old($do_default_action, $admin_page, $registration)
448 448
 {
449
-    // check if the old hooks are in use. If not, do the default
450
-    if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
451
-        || ! $admin_page instanceof EE_Admin_Page) {
452
-        return $do_default_action;
453
-    }
454
-    add_filter(
455
-        'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions',
456
-        array($admin_page, 'form_before_question_group'),
457
-        10,
458
-        1
459
-    );
460
-    add_filter(
461
-        'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions',
462
-        array($admin_page, 'form_after_question_group'),
463
-        10,
464
-        1
465
-    );
466
-    add_filter('FHEE__EEH_Form_Fields__label_html', array($admin_page, 'form_form_field_label_wrap'), 10, 1);
467
-    add_filter('FHEE__EEH_Form_Fields__input_html', array($admin_page, 'form_form_field_input__wrap'), 10, 1);
468
-
469
-    $question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options(
470
-        $registration,
471
-        $registration->get(
472
-            'EVT_ID'
473
-        )
474
-    );
475
-
476
-    EE_Registry::instance()->load_helper('Form_Fields');
477
-    $template_args = array(
478
-        'att_questions'             => EEH_Form_Fields::generate_question_groups_html($question_groups),
479
-        'reg_questions_form_action' => 'edit_registration',
480
-        'REG_ID'                    => $registration->ID(),
481
-    );
482
-    $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
483
-    echo EEH_Template::display_template($template_path, $template_args, true);
484
-    // indicate that we should not do the default admin page code
485
-    return false;
449
+	// check if the old hooks are in use. If not, do the default
450
+	if (! ee_deprecated_using_old_registration_admin_custom_questions_form_hooks()
451
+		|| ! $admin_page instanceof EE_Admin_Page) {
452
+		return $do_default_action;
453
+	}
454
+	add_filter(
455
+		'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions',
456
+		array($admin_page, 'form_before_question_group'),
457
+		10,
458
+		1
459
+	);
460
+	add_filter(
461
+		'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions',
462
+		array($admin_page, 'form_after_question_group'),
463
+		10,
464
+		1
465
+	);
466
+	add_filter('FHEE__EEH_Form_Fields__label_html', array($admin_page, 'form_form_field_label_wrap'), 10, 1);
467
+	add_filter('FHEE__EEH_Form_Fields__input_html', array($admin_page, 'form_form_field_input__wrap'), 10, 1);
468
+
469
+	$question_groups = EEM_Event::instance()->assemble_array_of_groups_questions_and_options(
470
+		$registration,
471
+		$registration->get(
472
+			'EVT_ID'
473
+		)
474
+	);
475
+
476
+	EE_Registry::instance()->load_helper('Form_Fields');
477
+	$template_args = array(
478
+		'att_questions'             => EEH_Form_Fields::generate_question_groups_html($question_groups),
479
+		'reg_questions_form_action' => 'edit_registration',
480
+		'REG_ID'                    => $registration->ID(),
481
+	);
482
+	$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
483
+	echo EEH_Template::display_template($template_path, $template_args, true);
484
+	// indicate that we should not do the default admin page code
485
+	return false;
486 486
 }
487 487
 
488 488
 add_action(
489
-    'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
490
-    'ee_deprecated_reg_questions_meta_box_old',
491
-    10,
492
-    3
489
+	'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
490
+	'ee_deprecated_reg_questions_meta_box_old',
491
+	10,
492
+	3
493 493
 );
494 494
 
495 495
 
@@ -506,42 +506,42 @@  discard block
 block discarded – undo
506 506
 class EE_Message_Template_Defaults extends EE_Base
507 507
 {
508 508
 
509
-    /**
510
-     * EE_Message_Template_Defaults constructor.
511
-     *
512
-     * @param EE_messages $messages
513
-     * @param             $messenger_name
514
-     * @param             $message_type_name
515
-     * @param int         $GRP_ID
516
-     * @return EE_Messages_Template_Defaults
517
-     */
518
-    public function __construct(
519
-        EE_messages $messages,
520
-        $messenger_name,
521
-        $message_type_name,
522
-        $GRP_ID = 0
523
-    ) {
524
-        EE_Error::doing_it_wrong(
525
-            __FUNCTION__,
526
-            esc_html__(
527
-                'The class EE_Message_Template_Defaults has been deprecated and replaced by EE_Messages_Template_Defaults.',
528
-                'event_espresso'
529
-            ),
530
-            '4.9.0'
531
-        );
532
-        /** @var EE_Message_Resource_Manager $message_resource_manager */
533
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
534
-        $messenger = $message_resource_manager->get_messenger($messenger_name);
535
-        $message_type = $message_resource_manager->get_message_type($message_type_name);
536
-        return EE_Registry::instance()->load_lib(
537
-            'Messages_Template_Defaults',
538
-            array(
539
-                $messenger,
540
-                $message_type,
541
-                $GRP_ID,
542
-            )
543
-        );
544
-    }
509
+	/**
510
+	 * EE_Message_Template_Defaults constructor.
511
+	 *
512
+	 * @param EE_messages $messages
513
+	 * @param             $messenger_name
514
+	 * @param             $message_type_name
515
+	 * @param int         $GRP_ID
516
+	 * @return EE_Messages_Template_Defaults
517
+	 */
518
+	public function __construct(
519
+		EE_messages $messages,
520
+		$messenger_name,
521
+		$message_type_name,
522
+		$GRP_ID = 0
523
+	) {
524
+		EE_Error::doing_it_wrong(
525
+			__FUNCTION__,
526
+			esc_html__(
527
+				'The class EE_Message_Template_Defaults has been deprecated and replaced by EE_Messages_Template_Defaults.',
528
+				'event_espresso'
529
+			),
530
+			'4.9.0'
531
+		);
532
+		/** @var EE_Message_Resource_Manager $message_resource_manager */
533
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
534
+		$messenger = $message_resource_manager->get_messenger($messenger_name);
535
+		$message_type = $message_resource_manager->get_message_type($message_type_name);
536
+		return EE_Registry::instance()->load_lib(
537
+			'Messages_Template_Defaults',
538
+			array(
539
+				$messenger,
540
+				$message_type,
541
+				$GRP_ID,
542
+			)
543
+		);
544
+	}
545 545
 }
546 546
 
547 547
 
@@ -559,525 +559,525 @@  discard block
 block discarded – undo
559 559
 class EE_messages
560 560
 {
561 561
 
562
-    /** @type EE_messenger[] */
563
-    protected $_active_messengers = array();
564
-
565
-    /** @type array */
566
-    protected $_active_message_types = array();
567
-
568
-    /** @type EE_message_type[] */
569
-    protected $_installed_message_types = array();
570
-
571
-    /** @type EE_messenger */
572
-    protected $_messenger;
573
-
574
-    /** @type EE_message_type */
575
-    protected $_message_type;
576
-
577
-    /** @type array */
578
-    protected $_contexts = array();
579
-
580
-    /** @type EE_Message_Resource_Manager $_message_resource_manager */
581
-    protected $_message_resource_manager;
582
-
583
-
584
-    /**
585
-     * EE_messages constructor.
586
-     *
587
-     * @deprecated 4.9.0
588
-     */
589
-    public function __construct()
590
-    {
591
-    }
592
-
593
-
594
-    /**
595
-     * @param string $method
596
-     */
597
-    public function _class_is_deprecated($method)
598
-    {
599
-        EE_Error::doing_it_wrong(
600
-            'EE_messages::' . $method,
601
-            esc_html__('EE_messages has been deprecated.  Please use EE_Message_Resource_Manager instead.'),
602
-            '4.9.0',
603
-            '4.10.0.p'
604
-        );
605
-        // Please use EE_Message_Resource_Manager instead
606
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
607
-    }
608
-
609
-
610
-    /**
611
-     * @deprecated 4.9.0
612
-     * @param string $messenger_name
613
-     * @return boolean TRUE if it was PREVIOUSLY active, and FALSE if it was previously inactive
614
-     */
615
-    public function ensure_messenger_is_active($messenger_name)
616
-    {
617
-        // EE_messages has been deprecated
618
-        $this->_class_is_deprecated(__FUNCTION__);
619
-        return $this->_message_resource_manager->ensure_messenger_is_active($messenger_name);
620
-    }
621
-
622
-
623
-    /**
624
-     * @deprecated 4.9.0
625
-     * @param string $message_type message type name
626
-     * @param        $messenger
627
-     * @return bool true if it got activated (or was active) and false if not.
628
-     * @throws \EE_Error
629
-     */
630
-    public function ensure_message_type_is_active($message_type, $messenger)
631
-    {
632
-        // EE_messages has been deprecated
633
-        $this->_class_is_deprecated(__FUNCTION__);
634
-        return $this->_message_resource_manager->ensure_message_type_is_active($message_type, $messenger);
635
-    }
636
-
637
-
638
-    /**
639
-     * @deprecated 4.9.0
640
-     * @param string $messenger_name
641
-     * @param array  $mts_to_activate             (optional) An array of message types to activate with this messenger.
642
-     *                                             If included we do NOT setup the default message types (assuming they
643
-     *                                             are already setup.)
644
-     * @return boolean an array of generated templates or false if nothing generated/activated.
645
-     */
646
-    public function activate_messenger($messenger_name, $mts_to_activate = array())
647
-    {
648
-        // EE_messages has been deprecated
649
-        $this->_class_is_deprecated(__FUNCTION__);
650
-        return $this->_message_resource_manager->activate_messenger($messenger_name, $mts_to_activate);
651
-    }
652
-
653
-
654
-    /**
655
-     * @deprecated 4.9.0
656
-     * @param EE_messenger    $messenger    messenger used in trigger
657
-     * @param EE_message_type $message_type message type used in trigger
658
-     *
659
-     * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
660
-     */
661
-    public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
662
-    {
663
-        // EE_messages has been deprecated
664
-        $this->_class_is_deprecated(__FUNCTION__);
665
-        return $this->_message_resource_manager->is_generating_messenger_and_active($messenger, $message_type);
666
-    }
667
-
668
-
669
-    /**
670
-     * @deprecated 4.9.0
671
-     * @param string $messenger
672
-     * @return EE_messenger | null
673
-     */
674
-    public function get_messenger_if_active($messenger)
675
-    {
676
-        // EE_messages has been deprecated
677
-        $this->_class_is_deprecated(__FUNCTION__);
678
-        return $this->_message_resource_manager->get_active_messenger($messenger);
679
-    }
680
-
681
-
682
-    /**
683
-     * @deprecated 4.9.0
684
-     * @param EE_Message $message
685
-     * @return array  An array with 'messenger' and 'message_type' as the index and the corresponding valid object if
686
-     *                  available.
687
-     *                  Eg. Valid Messenger and Message Type:
688
-     *                  array(
689
-     *                  'messenger' => new EE_Email_messenger(),
690
-     *                  'message_type' => new EE_Registration_Approved_message_type()
691
-     *                  )
692
-     *                  Valid Messenger and Invalid Message Type:
693
-     *                  array(
694
-     *                  'messenger' => new EE_Email_messenger(),
695
-     *                  'message_type' => null
696
-     *                  )
697
-     */
698
-    public function validate_for_use(EE_Message $message)
699
-    {
700
-        // EE_messages has been deprecated
701
-        $this->_class_is_deprecated(__FUNCTION__);
702
-        return array(
703
-            'messenger'    => $message->messenger_object(),
704
-            'message_type' => $message->message_type_object(),
705
-        );
706
-    }
707
-
708
-
709
-    /**
710
-     * @deprecated 4.9.0
711
-     * @param  string $type                 What type of message are we sending (corresponds to message types)
712
-     * @param  mixed  $vars                 Data being sent for parsing in the message
713
-     * @param  string $sending_messenger    if included then we ONLY use the specified messenger for delivery.
714
-     *                                      Otherwise we cycle through all active messengers.
715
-     * @param string  $generating_messenger if included then this messenger is used for generating the message
716
-     *                                      templates (but not for sending).
717
-     * @param string  $context              If included then only a message type for a specific context will be
718
-     *                                      generated.
719
-     * @param bool    $send                 Default TRUE.  If false, then this will just return the generated
720
-     *                                      EE_messages objects which might be used by the trigger to setup a batch
721
-     *                                      message (typically html messenger uses it).
722
-     * @return bool
723
-     */
724
-    public function send_message(
725
-        $type,
726
-        $vars,
727
-        $sending_messenger = '',
728
-        $generating_messenger = '',
729
-        $context = '',
730
-        $send = true
731
-    ) {
732
-        // EE_messages has been deprecated
733
-        $this->_class_is_deprecated(__FUNCTION__);
734
-        /** @type EE_Messages_Processor $processor */
735
-        $processor = EE_Registry::instance()->load_lib('Messages_Processor');
736
-        $error = false;
737
-        // try to intelligently determine what method we'll call based on the incoming data.
738
-        // if generating and sending are different then generate and send immediately.
739
-        if (! empty($sending_messenger) && $sending_messenger != $generating_messenger && $send) {
740
-            // in the legacy system, when generating and sending were different, that means all the
741
-            // vars are already in the request object.  So let's just use that.
742
-            try {
743
-                /** @type EE_Message_To_Generate_From_Request $mtg */
744
-                $mtg = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
745
-                $processor->generate_and_send_now($mtg);
746
-            } catch (EE_Error $e) {
747
-                $error_msg = esc_html__(
748
-                    'Please note that a system message failed to send due to a technical issue.',
749
-                    'event_espresso'
750
-                );
751
-                // add specific message for developers if WP_DEBUG in on
752
-                $error_msg .= '||' . $e->getMessage();
753
-                EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
754
-                $error = true;
755
-            }
756
-        } else {
757
-            $processor->generate_for_all_active_messengers($type, $vars, $send);
758
-            // let's find out if there were any errors and how many successfully were queued.
759
-            $count_errors = $processor->get_queue()->count_STS_in_queue(
760
-                array(EEM_Message::status_failed, EEM_Message::status_debug_only)
761
-            );
762
-            $count_queued = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_incomplete);
763
-            $count_retry = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_retry);
764
-            $count_errors = $count_errors + $count_retry;
765
-            if ($count_errors > 0) {
766
-                $error = true;
767
-                if ($count_errors > 1 && $count_retry > 1 && $count_queued > 1) {
768
-                    $message = sprintf(
769
-                        esc_html__(
770
-                            'There were %d errors and %d messages successfully queued for generation and sending',
771
-                            'event_espresso'
772
-                        ),
773
-                        $count_errors,
774
-                        $count_queued
775
-                    );
776
-                } elseif ($count_errors > 1 && $count_queued === 1) {
777
-                    $message = sprintf(
778
-                        esc_html__(
779
-                            'There were %d errors and %d message successfully queued for generation.',
780
-                            'event_espresso'
781
-                        ),
782
-                        $count_errors,
783
-                        $count_queued
784
-                    );
785
-                } elseif ($count_errors === 1 && $count_queued > 1) {
786
-                    $message = sprintf(
787
-                        esc_html__(
788
-                            'There was %d error and %d messages successfully queued for generation.',
789
-                            'event_espresso'
790
-                        ),
791
-                        $count_errors,
792
-                        $count_queued
793
-                    );
794
-                } else {
795
-                    $message = sprintf(
796
-                        esc_html__(
797
-                            'There was %d message that failed to be queued for generation.',
798
-                            'event_espresso'
799
-                        ),
800
-                        $count_errors
801
-                    );
802
-                }
803
-                EE_Error::add_error($message, __FILE__, __FUNCTION__, __LINE__);
804
-            } else {
805
-                if ($count_queued === 1) {
806
-                    $message = sprintf(
807
-                        esc_html__(
808
-                            '%d message successfully queued for generation.',
809
-                            'event_espresso'
810
-                        ),
811
-                        $count_queued
812
-                    );
813
-                } else {
814
-                    $message = sprintf(
815
-                        esc_html__(
816
-                            '%d messages were successfully queued for generation.',
817
-                            'event_espresso'
818
-                        ),
819
-                        $count_queued
820
-                    );
821
-                }
822
-                EE_Error::add_success($message);
823
-            }
824
-        }
825
-        // if no error then return the generated message(s).
826
-        if (! $error && ! $send) {
827
-            $generated_queue = $processor->generate_queue(false);
828
-            // get message and return.
829
-            $generated_queue->get_message_repository()->rewind();
830
-            $messages = array();
831
-            while ($generated_queue->get_message_repository()->valid()) {
832
-                $message = $generated_queue->get_message_repository()->current();
833
-                if ($message instanceof EE_Message) {
834
-                    // set properties that might be expected by add-ons (backward compat)
835
-                    $message->content = $message->content();
836
-                    $message->template_pack = $message->get_template_pack();
837
-                    $message->template_variation = $message->get_template_pack_variation();
838
-                    $messages[] = $message;
839
-                }
840
-                $generated_queue->get_message_repository()->next();
841
-            }
842
-            return $messages;
843
-        }
844
-        return $error ? false
845
-            : true; // yeah backwards eh?  Really what we're returning is if there is a total success for all the messages or not.  We'll modify this once we get message recording in place.
846
-    }
847
-
848
-
849
-    /**
850
-     * @deprecated 4.9.0
851
-     * @param  string $type      This should correspond with a valid message type
852
-     * @param  string $context   This should correspond with a valid context for the message type
853
-     * @param  string $messenger This should correspond with a valid messenger.
854
-     * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
855
-     *                           preview
856
-     * @return string          The body of the message.
857
-     */
858
-    public function preview_message($type, $context, $messenger, $send = false)
859
-    {
860
-        // EE_messages has been deprecated
861
-        $this->_class_is_deprecated(__FUNCTION__);
862
-        return EED_Messages::preview_message($type, $context, $messenger, $send);
863
-    }
864
-
865
-
866
-    /**
867
-     * @since      4.5.0
868
-     * @deprecated 4.9.0   Moved to EED_Messages Module
869
-     * @param string   $messenger    a string matching a valid active messenger in the system
870
-     * @param string   $message_type Although it seems contrary to the name of the method, a message type name is still
871
-     *                               required to send along the message type to the messenger because this is used for
872
-     *                               determining what specific variations might be loaded for the generated message.
873
-     * @param stdClass $message      a stdClass object in the format expected by the messenger.
874
-     *
875
-     * @return bool          success or fail.
876
-     */
877
-    public function send_message_with_messenger_only($messenger, $message_type, $message)
878
-    {
879
-        // EE_messages has been deprecated
880
-        $this->_class_is_deprecated(__FUNCTION__);
881
-        // setup for sending to new method.
882
-        /** @type EE_Messages_Queue $queue */
883
-        $queue = EE_Registry::instance()->load_lib('Messages_Queue');
884
-        // make sure we have a proper message object
885
-        if (! $message instanceof EE_Message && is_object($message) && isset($message->content)) {
886
-            $msg = EE_Message_Factory::create(
887
-                array(
888
-                    'MSG_messenger'    => $messenger,
889
-                    'MSG_message_type' => $message_type,
890
-                    'MSG_content'      => $message->content,
891
-                    'MSG_subject'      => $message->subject,
892
-                )
893
-            );
894
-        } else {
895
-            $msg = $message;
896
-        }
897
-        if (! $msg instanceof EE_Message) {
898
-            return false;
899
-        }
900
-        // make sure any content in a content property (if not empty) is set on the MSG_content.
901
-        if (! empty($msg->content)) {
902
-            $msg->set('MSG_content', $msg->content);
903
-        }
904
-        $queue->add($msg);
905
-        return EED_Messages::send_message_with_messenger_only($messenger, $message_type, $queue);
906
-    }
907
-
908
-
909
-    /**
910
-     * @deprecated 4.9.0
911
-     * @param         $messenger
912
-     * @param  string $message_type message type that the templates are being created for
913
-     * @param int     $GRP_ID
914
-     * @param bool    $is_global
915
-     * @return array|object if creation is successful then we return an array of info, otherwise an error_object is
916
-     *                      returned.
917
-     * @throws \EE_Error
918
-     */
919
-    public function create_new_templates($messenger, $message_type, $GRP_ID = 0, $is_global = false)
920
-    {
921
-        // EE_messages has been deprecated
922
-        $this->_class_is_deprecated(__FUNCTION__);
923
-        EE_Registry::instance()->load_helper('MSG_Template');
924
-        return EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $is_global);
925
-    }
926
-
927
-
928
-    /**
929
-     * @deprecated 4.9.0
930
-     * @param  string $messenger_name    name of EE_messenger
931
-     * @param  string $message_type_name name of EE_message_type
932
-     * @return array
933
-     */
934
-    public function get_fields($messenger_name, $message_type_name)
935
-    {
936
-        // EE_messages has been deprecated
937
-        $this->_class_is_deprecated(__FUNCTION__);
938
-        EE_Registry::instance()->load_helper('MSG_Template');
939
-        return EEH_MSG_Template::get_fields($messenger_name, $message_type_name);
940
-    }
941
-
942
-
943
-    /**
944
-     * @deprecated 4.9.0
945
-     * @access     public
946
-     * @param string $type                we can indicate just returning installed message types
947
-     *                                    or messengers (or both) via this parameter.
948
-     * @param bool   $skip_cache          if true then we skip the cache and retrieve via files.
949
-     * @return array                    multidimensional array of messenger and message_type objects
950
-     *                                    (messengers index, and message_type index);
951
-     */
952
-    public function get_installed($type = 'all', $skip_cache = false)
953
-    {
954
-        // EE_messages has been deprecated
955
-        $this->_class_is_deprecated(__FUNCTION__);
956
-        if ($skip_cache) {
957
-            $this->_message_resource_manager->reset_active_messengers_and_message_types();
958
-        }
959
-        switch ($type) {
960
-            case 'messengers' :
961
-                return array(
962
-                    'messenger' => $this->_message_resource_manager->installed_messengers(),
963
-                );
964
-                break;
965
-            case 'message_types' :
966
-                return array(
967
-                    'message_type' => $this->_message_resource_manager->installed_message_types(),
968
-                );
969
-                break;
970
-            case 'all' :
971
-            default :
972
-                return array(
973
-                    'messenger'    => $this->_message_resource_manager->installed_messengers(),
974
-                    'message_type' => $this->_message_resource_manager->installed_message_types(),
975
-                );
976
-                break;
977
-        }
978
-    }
979
-
980
-
981
-    /**
982
-     * @deprecated 4.9.0
983
-     * @return \EE_messenger[]
984
-     */
985
-    public function get_active_messengers()
986
-    {
987
-        // EE_messages has been deprecated
988
-        $this->_class_is_deprecated(__FUNCTION__);
989
-        return $this->_message_resource_manager->active_messengers();
990
-    }
991
-
992
-
993
-    /**
994
-     * @deprecated 4.9.0
995
-     * @return array array of message_type references (string)
996
-     */
997
-    public function get_active_message_types()
998
-    {
999
-        // EE_messages has been deprecated
1000
-        $this->_class_is_deprecated(__FUNCTION__);
1001
-        return $this->_message_resource_manager->list_of_active_message_types();
1002
-    }
1003
-
1004
-
1005
-    /**
1006
-     * @deprecated 4.9.0
1007
-     * @return EE_message_type[]
1008
-     */
1009
-    public function get_active_message_type_objects()
1010
-    {
1011
-        // EE_messages has been deprecated
1012
-        $this->_class_is_deprecated(__FUNCTION__);
1013
-        return $this->_message_resource_manager->get_active_message_type_objects();
1014
-    }
1015
-
1016
-
1017
-    /**
1018
-     * @deprecated 4.9.0
1019
-     * @since      4.5.0
1020
-     * @param string $messenger The messenger being checked
1021
-     * @return EE_message_type[]    (or empty array if none present)
1022
-     */
1023
-    public function get_active_message_types_per_messenger($messenger)
1024
-    {
1025
-        // EE_messages has been deprecated
1026
-        $this->_class_is_deprecated(__FUNCTION__);
1027
-        return $this->_message_resource_manager->get_active_message_types_for_messenger($messenger);
1028
-    }
1029
-
1030
-
1031
-    /**
1032
-     * @deprecated 4.9.0
1033
-     * @param string $messenger    The string should correspond to the messenger (message types are
1034
-     * @param string $message_type The string should correspond to a message type.
1035
-     * @return EE_message_type|null
1036
-     */
1037
-    public function get_active_message_type($messenger, $message_type)
1038
-    {
1039
-        // EE_messages has been deprecated
1040
-        $this->_class_is_deprecated(__FUNCTION__);
1041
-        return $this->_message_resource_manager->get_active_message_type_for_messenger($messenger, $message_type);
1042
-    }
1043
-
1044
-
1045
-    /**
1046
-     * @deprecated 4.9.0
1047
-     * @return array|\EE_message_type[]
1048
-     */
1049
-    public function get_installed_message_types()
1050
-    {
1051
-        // EE_messages has been deprecated
1052
-        $this->_class_is_deprecated(__FUNCTION__);
1053
-        return $this->_message_resource_manager->installed_message_types();
1054
-    }
1055
-
1056
-
1057
-    /**
1058
-     * @deprecated 4.9.0
1059
-     * @return array
1060
-     */
1061
-    public function get_installed_messengers()
1062
-    {
1063
-        // EE_messages has been deprecated
1064
-        $this->_class_is_deprecated(__FUNCTION__);
1065
-        return $this->_message_resource_manager->installed_messengers();
1066
-    }
1067
-
1068
-
1069
-    /**
1070
-     * @deprecated 4.9.0
1071
-     * @param   bool $slugs_only Whether to return an array of just slugs and labels (true) or all contexts indexed by
1072
-     *                           message type.
1073
-     * @return array
1074
-     */
1075
-    public function get_all_contexts($slugs_only = true)
1076
-    {
1077
-        // EE_messages has been deprecated
1078
-        $this->_class_is_deprecated(__FUNCTION__);
1079
-        return $this->_message_resource_manager->get_all_contexts($slugs_only);
1080
-    }
562
+	/** @type EE_messenger[] */
563
+	protected $_active_messengers = array();
564
+
565
+	/** @type array */
566
+	protected $_active_message_types = array();
567
+
568
+	/** @type EE_message_type[] */
569
+	protected $_installed_message_types = array();
570
+
571
+	/** @type EE_messenger */
572
+	protected $_messenger;
573
+
574
+	/** @type EE_message_type */
575
+	protected $_message_type;
576
+
577
+	/** @type array */
578
+	protected $_contexts = array();
579
+
580
+	/** @type EE_Message_Resource_Manager $_message_resource_manager */
581
+	protected $_message_resource_manager;
582
+
583
+
584
+	/**
585
+	 * EE_messages constructor.
586
+	 *
587
+	 * @deprecated 4.9.0
588
+	 */
589
+	public function __construct()
590
+	{
591
+	}
592
+
593
+
594
+	/**
595
+	 * @param string $method
596
+	 */
597
+	public function _class_is_deprecated($method)
598
+	{
599
+		EE_Error::doing_it_wrong(
600
+			'EE_messages::' . $method,
601
+			esc_html__('EE_messages has been deprecated.  Please use EE_Message_Resource_Manager instead.'),
602
+			'4.9.0',
603
+			'4.10.0.p'
604
+		);
605
+		// Please use EE_Message_Resource_Manager instead
606
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
607
+	}
608
+
609
+
610
+	/**
611
+	 * @deprecated 4.9.0
612
+	 * @param string $messenger_name
613
+	 * @return boolean TRUE if it was PREVIOUSLY active, and FALSE if it was previously inactive
614
+	 */
615
+	public function ensure_messenger_is_active($messenger_name)
616
+	{
617
+		// EE_messages has been deprecated
618
+		$this->_class_is_deprecated(__FUNCTION__);
619
+		return $this->_message_resource_manager->ensure_messenger_is_active($messenger_name);
620
+	}
621
+
622
+
623
+	/**
624
+	 * @deprecated 4.9.0
625
+	 * @param string $message_type message type name
626
+	 * @param        $messenger
627
+	 * @return bool true if it got activated (or was active) and false if not.
628
+	 * @throws \EE_Error
629
+	 */
630
+	public function ensure_message_type_is_active($message_type, $messenger)
631
+	{
632
+		// EE_messages has been deprecated
633
+		$this->_class_is_deprecated(__FUNCTION__);
634
+		return $this->_message_resource_manager->ensure_message_type_is_active($message_type, $messenger);
635
+	}
636
+
637
+
638
+	/**
639
+	 * @deprecated 4.9.0
640
+	 * @param string $messenger_name
641
+	 * @param array  $mts_to_activate             (optional) An array of message types to activate with this messenger.
642
+	 *                                             If included we do NOT setup the default message types (assuming they
643
+	 *                                             are already setup.)
644
+	 * @return boolean an array of generated templates or false if nothing generated/activated.
645
+	 */
646
+	public function activate_messenger($messenger_name, $mts_to_activate = array())
647
+	{
648
+		// EE_messages has been deprecated
649
+		$this->_class_is_deprecated(__FUNCTION__);
650
+		return $this->_message_resource_manager->activate_messenger($messenger_name, $mts_to_activate);
651
+	}
652
+
653
+
654
+	/**
655
+	 * @deprecated 4.9.0
656
+	 * @param EE_messenger    $messenger    messenger used in trigger
657
+	 * @param EE_message_type $message_type message type used in trigger
658
+	 *
659
+	 * @return bool true is a generating messenger and can be sent OR FALSE meaning cannot send.
660
+	 */
661
+	public function is_generating_messenger_and_active(EE_messenger $messenger, EE_message_type $message_type)
662
+	{
663
+		// EE_messages has been deprecated
664
+		$this->_class_is_deprecated(__FUNCTION__);
665
+		return $this->_message_resource_manager->is_generating_messenger_and_active($messenger, $message_type);
666
+	}
667
+
668
+
669
+	/**
670
+	 * @deprecated 4.9.0
671
+	 * @param string $messenger
672
+	 * @return EE_messenger | null
673
+	 */
674
+	public function get_messenger_if_active($messenger)
675
+	{
676
+		// EE_messages has been deprecated
677
+		$this->_class_is_deprecated(__FUNCTION__);
678
+		return $this->_message_resource_manager->get_active_messenger($messenger);
679
+	}
680
+
681
+
682
+	/**
683
+	 * @deprecated 4.9.0
684
+	 * @param EE_Message $message
685
+	 * @return array  An array with 'messenger' and 'message_type' as the index and the corresponding valid object if
686
+	 *                  available.
687
+	 *                  Eg. Valid Messenger and Message Type:
688
+	 *                  array(
689
+	 *                  'messenger' => new EE_Email_messenger(),
690
+	 *                  'message_type' => new EE_Registration_Approved_message_type()
691
+	 *                  )
692
+	 *                  Valid Messenger and Invalid Message Type:
693
+	 *                  array(
694
+	 *                  'messenger' => new EE_Email_messenger(),
695
+	 *                  'message_type' => null
696
+	 *                  )
697
+	 */
698
+	public function validate_for_use(EE_Message $message)
699
+	{
700
+		// EE_messages has been deprecated
701
+		$this->_class_is_deprecated(__FUNCTION__);
702
+		return array(
703
+			'messenger'    => $message->messenger_object(),
704
+			'message_type' => $message->message_type_object(),
705
+		);
706
+	}
707
+
708
+
709
+	/**
710
+	 * @deprecated 4.9.0
711
+	 * @param  string $type                 What type of message are we sending (corresponds to message types)
712
+	 * @param  mixed  $vars                 Data being sent for parsing in the message
713
+	 * @param  string $sending_messenger    if included then we ONLY use the specified messenger for delivery.
714
+	 *                                      Otherwise we cycle through all active messengers.
715
+	 * @param string  $generating_messenger if included then this messenger is used for generating the message
716
+	 *                                      templates (but not for sending).
717
+	 * @param string  $context              If included then only a message type for a specific context will be
718
+	 *                                      generated.
719
+	 * @param bool    $send                 Default TRUE.  If false, then this will just return the generated
720
+	 *                                      EE_messages objects which might be used by the trigger to setup a batch
721
+	 *                                      message (typically html messenger uses it).
722
+	 * @return bool
723
+	 */
724
+	public function send_message(
725
+		$type,
726
+		$vars,
727
+		$sending_messenger = '',
728
+		$generating_messenger = '',
729
+		$context = '',
730
+		$send = true
731
+	) {
732
+		// EE_messages has been deprecated
733
+		$this->_class_is_deprecated(__FUNCTION__);
734
+		/** @type EE_Messages_Processor $processor */
735
+		$processor = EE_Registry::instance()->load_lib('Messages_Processor');
736
+		$error = false;
737
+		// try to intelligently determine what method we'll call based on the incoming data.
738
+		// if generating and sending are different then generate and send immediately.
739
+		if (! empty($sending_messenger) && $sending_messenger != $generating_messenger && $send) {
740
+			// in the legacy system, when generating and sending were different, that means all the
741
+			// vars are already in the request object.  So let's just use that.
742
+			try {
743
+				/** @type EE_Message_To_Generate_From_Request $mtg */
744
+				$mtg = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
745
+				$processor->generate_and_send_now($mtg);
746
+			} catch (EE_Error $e) {
747
+				$error_msg = esc_html__(
748
+					'Please note that a system message failed to send due to a technical issue.',
749
+					'event_espresso'
750
+				);
751
+				// add specific message for developers if WP_DEBUG in on
752
+				$error_msg .= '||' . $e->getMessage();
753
+				EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
754
+				$error = true;
755
+			}
756
+		} else {
757
+			$processor->generate_for_all_active_messengers($type, $vars, $send);
758
+			// let's find out if there were any errors and how many successfully were queued.
759
+			$count_errors = $processor->get_queue()->count_STS_in_queue(
760
+				array(EEM_Message::status_failed, EEM_Message::status_debug_only)
761
+			);
762
+			$count_queued = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_incomplete);
763
+			$count_retry = $processor->get_queue()->count_STS_in_queue(EEM_Message::status_retry);
764
+			$count_errors = $count_errors + $count_retry;
765
+			if ($count_errors > 0) {
766
+				$error = true;
767
+				if ($count_errors > 1 && $count_retry > 1 && $count_queued > 1) {
768
+					$message = sprintf(
769
+						esc_html__(
770
+							'There were %d errors and %d messages successfully queued for generation and sending',
771
+							'event_espresso'
772
+						),
773
+						$count_errors,
774
+						$count_queued
775
+					);
776
+				} elseif ($count_errors > 1 && $count_queued === 1) {
777
+					$message = sprintf(
778
+						esc_html__(
779
+							'There were %d errors and %d message successfully queued for generation.',
780
+							'event_espresso'
781
+						),
782
+						$count_errors,
783
+						$count_queued
784
+					);
785
+				} elseif ($count_errors === 1 && $count_queued > 1) {
786
+					$message = sprintf(
787
+						esc_html__(
788
+							'There was %d error and %d messages successfully queued for generation.',
789
+							'event_espresso'
790
+						),
791
+						$count_errors,
792
+						$count_queued
793
+					);
794
+				} else {
795
+					$message = sprintf(
796
+						esc_html__(
797
+							'There was %d message that failed to be queued for generation.',
798
+							'event_espresso'
799
+						),
800
+						$count_errors
801
+					);
802
+				}
803
+				EE_Error::add_error($message, __FILE__, __FUNCTION__, __LINE__);
804
+			} else {
805
+				if ($count_queued === 1) {
806
+					$message = sprintf(
807
+						esc_html__(
808
+							'%d message successfully queued for generation.',
809
+							'event_espresso'
810
+						),
811
+						$count_queued
812
+					);
813
+				} else {
814
+					$message = sprintf(
815
+						esc_html__(
816
+							'%d messages were successfully queued for generation.',
817
+							'event_espresso'
818
+						),
819
+						$count_queued
820
+					);
821
+				}
822
+				EE_Error::add_success($message);
823
+			}
824
+		}
825
+		// if no error then return the generated message(s).
826
+		if (! $error && ! $send) {
827
+			$generated_queue = $processor->generate_queue(false);
828
+			// get message and return.
829
+			$generated_queue->get_message_repository()->rewind();
830
+			$messages = array();
831
+			while ($generated_queue->get_message_repository()->valid()) {
832
+				$message = $generated_queue->get_message_repository()->current();
833
+				if ($message instanceof EE_Message) {
834
+					// set properties that might be expected by add-ons (backward compat)
835
+					$message->content = $message->content();
836
+					$message->template_pack = $message->get_template_pack();
837
+					$message->template_variation = $message->get_template_pack_variation();
838
+					$messages[] = $message;
839
+				}
840
+				$generated_queue->get_message_repository()->next();
841
+			}
842
+			return $messages;
843
+		}
844
+		return $error ? false
845
+			: true; // yeah backwards eh?  Really what we're returning is if there is a total success for all the messages or not.  We'll modify this once we get message recording in place.
846
+	}
847
+
848
+
849
+	/**
850
+	 * @deprecated 4.9.0
851
+	 * @param  string $type      This should correspond with a valid message type
852
+	 * @param  string $context   This should correspond with a valid context for the message type
853
+	 * @param  string $messenger This should correspond with a valid messenger.
854
+	 * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
855
+	 *                           preview
856
+	 * @return string          The body of the message.
857
+	 */
858
+	public function preview_message($type, $context, $messenger, $send = false)
859
+	{
860
+		// EE_messages has been deprecated
861
+		$this->_class_is_deprecated(__FUNCTION__);
862
+		return EED_Messages::preview_message($type, $context, $messenger, $send);
863
+	}
864
+
865
+
866
+	/**
867
+	 * @since      4.5.0
868
+	 * @deprecated 4.9.0   Moved to EED_Messages Module
869
+	 * @param string   $messenger    a string matching a valid active messenger in the system
870
+	 * @param string   $message_type Although it seems contrary to the name of the method, a message type name is still
871
+	 *                               required to send along the message type to the messenger because this is used for
872
+	 *                               determining what specific variations might be loaded for the generated message.
873
+	 * @param stdClass $message      a stdClass object in the format expected by the messenger.
874
+	 *
875
+	 * @return bool          success or fail.
876
+	 */
877
+	public function send_message_with_messenger_only($messenger, $message_type, $message)
878
+	{
879
+		// EE_messages has been deprecated
880
+		$this->_class_is_deprecated(__FUNCTION__);
881
+		// setup for sending to new method.
882
+		/** @type EE_Messages_Queue $queue */
883
+		$queue = EE_Registry::instance()->load_lib('Messages_Queue');
884
+		// make sure we have a proper message object
885
+		if (! $message instanceof EE_Message && is_object($message) && isset($message->content)) {
886
+			$msg = EE_Message_Factory::create(
887
+				array(
888
+					'MSG_messenger'    => $messenger,
889
+					'MSG_message_type' => $message_type,
890
+					'MSG_content'      => $message->content,
891
+					'MSG_subject'      => $message->subject,
892
+				)
893
+			);
894
+		} else {
895
+			$msg = $message;
896
+		}
897
+		if (! $msg instanceof EE_Message) {
898
+			return false;
899
+		}
900
+		// make sure any content in a content property (if not empty) is set on the MSG_content.
901
+		if (! empty($msg->content)) {
902
+			$msg->set('MSG_content', $msg->content);
903
+		}
904
+		$queue->add($msg);
905
+		return EED_Messages::send_message_with_messenger_only($messenger, $message_type, $queue);
906
+	}
907
+
908
+
909
+	/**
910
+	 * @deprecated 4.9.0
911
+	 * @param         $messenger
912
+	 * @param  string $message_type message type that the templates are being created for
913
+	 * @param int     $GRP_ID
914
+	 * @param bool    $is_global
915
+	 * @return array|object if creation is successful then we return an array of info, otherwise an error_object is
916
+	 *                      returned.
917
+	 * @throws \EE_Error
918
+	 */
919
+	public function create_new_templates($messenger, $message_type, $GRP_ID = 0, $is_global = false)
920
+	{
921
+		// EE_messages has been deprecated
922
+		$this->_class_is_deprecated(__FUNCTION__);
923
+		EE_Registry::instance()->load_helper('MSG_Template');
924
+		return EEH_MSG_Template::create_new_templates($messenger, $message_type, $GRP_ID, $is_global);
925
+	}
926
+
927
+
928
+	/**
929
+	 * @deprecated 4.9.0
930
+	 * @param  string $messenger_name    name of EE_messenger
931
+	 * @param  string $message_type_name name of EE_message_type
932
+	 * @return array
933
+	 */
934
+	public function get_fields($messenger_name, $message_type_name)
935
+	{
936
+		// EE_messages has been deprecated
937
+		$this->_class_is_deprecated(__FUNCTION__);
938
+		EE_Registry::instance()->load_helper('MSG_Template');
939
+		return EEH_MSG_Template::get_fields($messenger_name, $message_type_name);
940
+	}
941
+
942
+
943
+	/**
944
+	 * @deprecated 4.9.0
945
+	 * @access     public
946
+	 * @param string $type                we can indicate just returning installed message types
947
+	 *                                    or messengers (or both) via this parameter.
948
+	 * @param bool   $skip_cache          if true then we skip the cache and retrieve via files.
949
+	 * @return array                    multidimensional array of messenger and message_type objects
950
+	 *                                    (messengers index, and message_type index);
951
+	 */
952
+	public function get_installed($type = 'all', $skip_cache = false)
953
+	{
954
+		// EE_messages has been deprecated
955
+		$this->_class_is_deprecated(__FUNCTION__);
956
+		if ($skip_cache) {
957
+			$this->_message_resource_manager->reset_active_messengers_and_message_types();
958
+		}
959
+		switch ($type) {
960
+			case 'messengers' :
961
+				return array(
962
+					'messenger' => $this->_message_resource_manager->installed_messengers(),
963
+				);
964
+				break;
965
+			case 'message_types' :
966
+				return array(
967
+					'message_type' => $this->_message_resource_manager->installed_message_types(),
968
+				);
969
+				break;
970
+			case 'all' :
971
+			default :
972
+				return array(
973
+					'messenger'    => $this->_message_resource_manager->installed_messengers(),
974
+					'message_type' => $this->_message_resource_manager->installed_message_types(),
975
+				);
976
+				break;
977
+		}
978
+	}
979
+
980
+
981
+	/**
982
+	 * @deprecated 4.9.0
983
+	 * @return \EE_messenger[]
984
+	 */
985
+	public function get_active_messengers()
986
+	{
987
+		// EE_messages has been deprecated
988
+		$this->_class_is_deprecated(__FUNCTION__);
989
+		return $this->_message_resource_manager->active_messengers();
990
+	}
991
+
992
+
993
+	/**
994
+	 * @deprecated 4.9.0
995
+	 * @return array array of message_type references (string)
996
+	 */
997
+	public function get_active_message_types()
998
+	{
999
+		// EE_messages has been deprecated
1000
+		$this->_class_is_deprecated(__FUNCTION__);
1001
+		return $this->_message_resource_manager->list_of_active_message_types();
1002
+	}
1003
+
1004
+
1005
+	/**
1006
+	 * @deprecated 4.9.0
1007
+	 * @return EE_message_type[]
1008
+	 */
1009
+	public function get_active_message_type_objects()
1010
+	{
1011
+		// EE_messages has been deprecated
1012
+		$this->_class_is_deprecated(__FUNCTION__);
1013
+		return $this->_message_resource_manager->get_active_message_type_objects();
1014
+	}
1015
+
1016
+
1017
+	/**
1018
+	 * @deprecated 4.9.0
1019
+	 * @since      4.5.0
1020
+	 * @param string $messenger The messenger being checked
1021
+	 * @return EE_message_type[]    (or empty array if none present)
1022
+	 */
1023
+	public function get_active_message_types_per_messenger($messenger)
1024
+	{
1025
+		// EE_messages has been deprecated
1026
+		$this->_class_is_deprecated(__FUNCTION__);
1027
+		return $this->_message_resource_manager->get_active_message_types_for_messenger($messenger);
1028
+	}
1029
+
1030
+
1031
+	/**
1032
+	 * @deprecated 4.9.0
1033
+	 * @param string $messenger    The string should correspond to the messenger (message types are
1034
+	 * @param string $message_type The string should correspond to a message type.
1035
+	 * @return EE_message_type|null
1036
+	 */
1037
+	public function get_active_message_type($messenger, $message_type)
1038
+	{
1039
+		// EE_messages has been deprecated
1040
+		$this->_class_is_deprecated(__FUNCTION__);
1041
+		return $this->_message_resource_manager->get_active_message_type_for_messenger($messenger, $message_type);
1042
+	}
1043
+
1044
+
1045
+	/**
1046
+	 * @deprecated 4.9.0
1047
+	 * @return array|\EE_message_type[]
1048
+	 */
1049
+	public function get_installed_message_types()
1050
+	{
1051
+		// EE_messages has been deprecated
1052
+		$this->_class_is_deprecated(__FUNCTION__);
1053
+		return $this->_message_resource_manager->installed_message_types();
1054
+	}
1055
+
1056
+
1057
+	/**
1058
+	 * @deprecated 4.9.0
1059
+	 * @return array
1060
+	 */
1061
+	public function get_installed_messengers()
1062
+	{
1063
+		// EE_messages has been deprecated
1064
+		$this->_class_is_deprecated(__FUNCTION__);
1065
+		return $this->_message_resource_manager->installed_messengers();
1066
+	}
1067
+
1068
+
1069
+	/**
1070
+	 * @deprecated 4.9.0
1071
+	 * @param   bool $slugs_only Whether to return an array of just slugs and labels (true) or all contexts indexed by
1072
+	 *                           message type.
1073
+	 * @return array
1074
+	 */
1075
+	public function get_all_contexts($slugs_only = true)
1076
+	{
1077
+		// EE_messages has been deprecated
1078
+		$this->_class_is_deprecated(__FUNCTION__);
1079
+		return $this->_message_resource_manager->get_all_contexts($slugs_only);
1080
+	}
1081 1081
 
1082 1082
 
1083 1083
 }
@@ -1136,88 +1136,88 @@  discard block
 block discarded – undo
1136 1136
 
1137 1137
 
1138 1138
 add_filter(
1139
-    'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
1140
-    function ($event_list_iframe_css) {
1141
-        if (! has_filter('FHEE__EventsArchiveIframe__event_list_iframe__css')) {
1142
-            return $event_list_iframe_css;
1143
-        }
1144
-        deprecated_espresso_action_or_filter_doing_it_wrong(
1145
-            'FHEE__EventsArchiveIframe__event_list_iframe__css',
1146
-            'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
1147
-            '\EventEspresso\modules\events_archive\EventsArchiveIframe::display()',
1148
-            '4.9.14',
1149
-            '5.0.0',
1150
-            'filter'
1151
-        );
1152
-        return apply_filters(
1153
-            'FHEE__EventsArchiveIframe__event_list_iframe__css',
1154
-            $event_list_iframe_css
1155
-        );
1156
-    }
1139
+	'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
1140
+	function ($event_list_iframe_css) {
1141
+		if (! has_filter('FHEE__EventsArchiveIframe__event_list_iframe__css')) {
1142
+			return $event_list_iframe_css;
1143
+		}
1144
+		deprecated_espresso_action_or_filter_doing_it_wrong(
1145
+			'FHEE__EventsArchiveIframe__event_list_iframe__css',
1146
+			'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
1147
+			'\EventEspresso\modules\events_archive\EventsArchiveIframe::display()',
1148
+			'4.9.14',
1149
+			'5.0.0',
1150
+			'filter'
1151
+		);
1152
+		return apply_filters(
1153
+			'FHEE__EventsArchiveIframe__event_list_iframe__css',
1154
+			$event_list_iframe_css
1155
+		);
1156
+	}
1157 1157
 );
1158 1158
 add_filter(
1159
-    'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
1160
-    function ($event_list_iframe_js) {
1161
-        if (! has_filter('FHEE__EED_Ticket_Selector__ticket_selector_iframe__js')) {
1162
-            return $event_list_iframe_js;
1163
-        }
1164
-        deprecated_espresso_action_or_filter_doing_it_wrong(
1165
-            'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
1166
-            'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
1167
-            '\EventEspresso\modules\events_archive\EventsArchiveIframe::display()',
1168
-            '4.9.14',
1169
-            '5.0.0',
1170
-            'filter'
1171
-        );
1172
-        return apply_filters(
1173
-            'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
1174
-            $event_list_iframe_js
1175
-        );
1176
-    }
1159
+	'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
1160
+	function ($event_list_iframe_js) {
1161
+		if (! has_filter('FHEE__EED_Ticket_Selector__ticket_selector_iframe__js')) {
1162
+			return $event_list_iframe_js;
1163
+		}
1164
+		deprecated_espresso_action_or_filter_doing_it_wrong(
1165
+			'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
1166
+			'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
1167
+			'\EventEspresso\modules\events_archive\EventsArchiveIframe::display()',
1168
+			'4.9.14',
1169
+			'5.0.0',
1170
+			'filter'
1171
+		);
1172
+		return apply_filters(
1173
+			'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
1174
+			$event_list_iframe_js
1175
+		);
1176
+	}
1177 1177
 );
1178 1178
 add_action(
1179
-    'AHEE__EE_Capabilities__addCaps__complete',
1180
-    function ($capabilities_map) {
1181
-        if (! has_action('AHEE__EE_Capabilities__init_role_caps__complete')) {
1182
-            return;
1183
-        }
1184
-        deprecated_espresso_action_or_filter_doing_it_wrong(
1185
-            'AHEE__EE_Capabilities__init_role_caps__complete',
1186
-            'AHEE__EE_Capabilities__addCaps__complete',
1187
-            '\EE_Capabilities::addCaps()',
1188
-            '4.9.42',
1189
-            '5.0.0'
1190
-        );
1191
-        do_action(
1192
-            'AHEE__EE_Capabilities__init_role_caps__complete',
1193
-            $capabilities_map
1194
-        );
1195
-    }
1179
+	'AHEE__EE_Capabilities__addCaps__complete',
1180
+	function ($capabilities_map) {
1181
+		if (! has_action('AHEE__EE_Capabilities__init_role_caps__complete')) {
1182
+			return;
1183
+		}
1184
+		deprecated_espresso_action_or_filter_doing_it_wrong(
1185
+			'AHEE__EE_Capabilities__init_role_caps__complete',
1186
+			'AHEE__EE_Capabilities__addCaps__complete',
1187
+			'\EE_Capabilities::addCaps()',
1188
+			'4.9.42',
1189
+			'5.0.0'
1190
+		);
1191
+		do_action(
1192
+			'AHEE__EE_Capabilities__init_role_caps__complete',
1193
+			$capabilities_map
1194
+		);
1195
+	}
1196 1196
 );
1197 1197
 
1198 1198
 add_filter(
1199
-    'FHEE_EventEspresso_core_domain_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee',
1200
-    function($existing_attendee, $registration, $attendee_data) {
1201
-        if ( ! has_filter( 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee' )) {
1202
-            return $existing_attendee;
1203
-        }
1204
-        deprecated_espresso_action_or_filter_doing_it_wrong(
1205
-            'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee',
1206
-            'FHEE_EventEspresso_core_domain_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee',
1207
-            '\EventEspresso\core\domain\services\commands\attendee\CreateAttendeeCommandHandler::findExistingAttendee()',
1208
-            '4.9.34',
1209
-            '5.0.0',
1210
-            'filter'
1211
-        );
1212
-        return apply_filters(
1213
-            'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee',
1214
-            $existing_attendee,
1215
-            $registration,
1216
-            $attendee_data
1217
-        );
1218
-    },
1219
-    10,
1220
-    3
1199
+	'FHEE_EventEspresso_core_domain_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee',
1200
+	function($existing_attendee, $registration, $attendee_data) {
1201
+		if ( ! has_filter( 'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee' )) {
1202
+			return $existing_attendee;
1203
+		}
1204
+		deprecated_espresso_action_or_filter_doing_it_wrong(
1205
+			'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee',
1206
+			'FHEE_EventEspresso_core_domain_services_commands_attendee_CreateAttendeeCommandHandler__findExistingAttendee__existing_attendee',
1207
+			'\EventEspresso\core\domain\services\commands\attendee\CreateAttendeeCommandHandler::findExistingAttendee()',
1208
+			'4.9.34',
1209
+			'5.0.0',
1210
+			'filter'
1211
+		);
1212
+		return apply_filters(
1213
+			'FHEE_EE_Single_Page_Checkout__save_registration_items__find_existing_attendee',
1214
+			$existing_attendee,
1215
+			$registration,
1216
+			$attendee_data
1217
+		);
1218
+	},
1219
+	10,
1220
+	3
1221 1221
 );
1222 1222
 
1223 1223
 /**
@@ -1228,88 +1228,88 @@  discard block
 block discarded – undo
1228 1228
 class EE_Event_List_Query extends WP_Query
1229 1229
 {
1230 1230
 
1231
-    private $title;
1232
-
1233
-    private $css_class;
1234
-
1235
-    private $category_slug;
1236
-
1237
-    /**
1238
-     * EE_Event_List_Query constructor.
1239
-     *
1240
-     * @param array $args
1241
-     */
1242
-    public function __construct($args = array())
1243
-    {
1244
-        \EE_Error::doing_it_wrong(
1245
-            __METHOD__,
1246
-            esc_html__(
1247
-                'Usage is deprecated. Please use \EventEspresso\core\domain\services\wp_queries\EventListQuery instead.',
1248
-                'event_espresso'
1249
-            ),
1250
-            '4.9.27',
1251
-            '5.0.0'
1252
-        );
1253
-        $this->title = isset($args['title']) ? $args['title'] : '';
1254
-        $this->css_class = isset($args['css_class']) ? $args['css_class'] : '';
1255
-        $this->category_slug = isset($args['category_slug']) ? $args['category_slug'] : '';
1256
-        $limit = isset($args['limit']) && absint($args['limit']) ? $args['limit'] : 10;
1257
-        // the current "page" we are viewing
1258
-        $paged = max(1, get_query_var('paged'));
1259
-        // Force these args
1260
-        $args = array_merge(
1261
-            $args,
1262
-            array(
1263
-                'post_type'              => 'espresso_events',
1264
-                'posts_per_page'         => $limit,
1265
-                'update_post_term_cache' => false,
1266
-                'update_post_meta_cache' => false,
1267
-                'paged'                  => $paged,
1268
-                'offset'                 => ($paged - 1) * $limit,
1269
-            )
1270
-        );
1271
-        // run the query
1272
-        parent::__construct($args);
1273
-    }
1274
-
1275
-
1276
-    /**
1277
-     * event_list_title
1278
-     *
1279
-     * @param string $event_list_title
1280
-     * @return string
1281
-     */
1282
-    public function event_list_title($event_list_title = '')
1283
-    {
1284
-        if (! empty($this->title)) {
1285
-            return $this->title;
1286
-        }
1287
-        return $event_list_title;
1288
-    }
1289
-
1290
-
1291
-    /**
1292
-     * event_list_css
1293
-     *
1294
-     * @param string $event_list_css
1295
-     * @return string
1296
-     */
1297
-    public function event_list_css($event_list_css = '')
1298
-    {
1299
-        $event_list_css .= ! empty($event_list_css)
1300
-            ? ' '
1301
-            : '';
1302
-        $event_list_css .= ! empty($this->css_class)
1303
-            ? $this->css_class
1304
-            : '';
1305
-        $event_list_css .= ! empty($event_list_css)
1306
-            ? ' '
1307
-            : '';
1308
-        $event_list_css .= ! empty($this->category_slug)
1309
-            ? $this->category_slug
1310
-            : '';
1311
-        return $event_list_css;
1312
-    }
1231
+	private $title;
1232
+
1233
+	private $css_class;
1234
+
1235
+	private $category_slug;
1236
+
1237
+	/**
1238
+	 * EE_Event_List_Query constructor.
1239
+	 *
1240
+	 * @param array $args
1241
+	 */
1242
+	public function __construct($args = array())
1243
+	{
1244
+		\EE_Error::doing_it_wrong(
1245
+			__METHOD__,
1246
+			esc_html__(
1247
+				'Usage is deprecated. Please use \EventEspresso\core\domain\services\wp_queries\EventListQuery instead.',
1248
+				'event_espresso'
1249
+			),
1250
+			'4.9.27',
1251
+			'5.0.0'
1252
+		);
1253
+		$this->title = isset($args['title']) ? $args['title'] : '';
1254
+		$this->css_class = isset($args['css_class']) ? $args['css_class'] : '';
1255
+		$this->category_slug = isset($args['category_slug']) ? $args['category_slug'] : '';
1256
+		$limit = isset($args['limit']) && absint($args['limit']) ? $args['limit'] : 10;
1257
+		// the current "page" we are viewing
1258
+		$paged = max(1, get_query_var('paged'));
1259
+		// Force these args
1260
+		$args = array_merge(
1261
+			$args,
1262
+			array(
1263
+				'post_type'              => 'espresso_events',
1264
+				'posts_per_page'         => $limit,
1265
+				'update_post_term_cache' => false,
1266
+				'update_post_meta_cache' => false,
1267
+				'paged'                  => $paged,
1268
+				'offset'                 => ($paged - 1) * $limit,
1269
+			)
1270
+		);
1271
+		// run the query
1272
+		parent::__construct($args);
1273
+	}
1274
+
1275
+
1276
+	/**
1277
+	 * event_list_title
1278
+	 *
1279
+	 * @param string $event_list_title
1280
+	 * @return string
1281
+	 */
1282
+	public function event_list_title($event_list_title = '')
1283
+	{
1284
+		if (! empty($this->title)) {
1285
+			return $this->title;
1286
+		}
1287
+		return $event_list_title;
1288
+	}
1289
+
1290
+
1291
+	/**
1292
+	 * event_list_css
1293
+	 *
1294
+	 * @param string $event_list_css
1295
+	 * @return string
1296
+	 */
1297
+	public function event_list_css($event_list_css = '')
1298
+	{
1299
+		$event_list_css .= ! empty($event_list_css)
1300
+			? ' '
1301
+			: '';
1302
+		$event_list_css .= ! empty($this->css_class)
1303
+			? $this->css_class
1304
+			: '';
1305
+		$event_list_css .= ! empty($event_list_css)
1306
+			? ' '
1307
+			: '';
1308
+		$event_list_css .= ! empty($this->category_slug)
1309
+			? $this->category_slug
1310
+			: '';
1311
+		return $event_list_css;
1312
+	}
1313 1313
 
1314 1314
 }
1315 1315
 
@@ -1326,75 +1326,75 @@  discard block
 block discarded – undo
1326 1326
 {
1327 1327
 
1328 1328
 
1329
-    /**
1330
-     *    class constructor
1331
-     *
1332
-     * @deprecated 4.9.59.p
1333
-     */
1334
-    public function __construct()
1335
-    {
1336
-        EE_Error::doing_it_wrong(
1337
-            __METHOD__,
1338
-            sprintf(
1339
-                esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'),
1340
-                __CLASS__,
1341
-                'EventEspresso\core\services\licensing\LicenseServices'
1342
-            ),
1343
-            '4.9.59.p'
1344
-        );
1345
-    }
1346
-
1347
-
1348
-    /**
1349
-     * The purpose of this function is to display information about Event Espresso data collection
1350
-     * and a optin selection for extra data collecting by users.
1351
-     *
1352
-     * @param bool $extra
1353
-     * @return string html.
1354
-     * @deprecated 4.9.59.p
1355
-     */
1356
-    public static function espresso_data_collection_optin_text($extra = true)
1357
-    {
1358
-        EE_Error::doing_it_wrong(
1359
-            __METHOD__,
1360
-            sprintf(
1361
-                esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'),
1362
-                __METHOD__,
1363
-                'EventEspresso\core\domain\services\Stats::optinText'
1364
-            ),
1365
-            '4.9.59.p'
1366
-        );
1367
-        Stats::optinText($extra);
1368
-    }
1369
-
1370
-    /**
1371
-     * This is a handy helper method for retrieving whether there is an update available for the given plugin.
1372
-     *
1373
-     * @param  string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to
1374
-     *                          identify plugins. Defaults to core update
1375
-     * @return boolean           True if update available, false if not.
1376
-     * @deprecated 4.9.59.p
1377
-     */
1378
-    public static function is_update_available($basename = '')
1379
-    {
1380
-        EE_Error::doing_it_wrong(
1381
-            __METHOD__,
1382
-            sprintf(
1383
-                esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'),
1384
-                __METHOD__,
1385
-                'EventEspresso\caffeinated\core\services\licensing\LicenseService::isUpdateAvailable'
1386
-            ),
1387
-            '4.9.59.p'
1388
-        );
1389
-        return LicenseService::isUpdateAvailable($basename);
1390
-    }
1329
+	/**
1330
+	 *    class constructor
1331
+	 *
1332
+	 * @deprecated 4.9.59.p
1333
+	 */
1334
+	public function __construct()
1335
+	{
1336
+		EE_Error::doing_it_wrong(
1337
+			__METHOD__,
1338
+			sprintf(
1339
+				esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'),
1340
+				__CLASS__,
1341
+				'EventEspresso\core\services\licensing\LicenseServices'
1342
+			),
1343
+			'4.9.59.p'
1344
+		);
1345
+	}
1346
+
1347
+
1348
+	/**
1349
+	 * The purpose of this function is to display information about Event Espresso data collection
1350
+	 * and a optin selection for extra data collecting by users.
1351
+	 *
1352
+	 * @param bool $extra
1353
+	 * @return string html.
1354
+	 * @deprecated 4.9.59.p
1355
+	 */
1356
+	public static function espresso_data_collection_optin_text($extra = true)
1357
+	{
1358
+		EE_Error::doing_it_wrong(
1359
+			__METHOD__,
1360
+			sprintf(
1361
+				esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'),
1362
+				__METHOD__,
1363
+				'EventEspresso\core\domain\services\Stats::optinText'
1364
+			),
1365
+			'4.9.59.p'
1366
+		);
1367
+		Stats::optinText($extra);
1368
+	}
1369
+
1370
+	/**
1371
+	 * This is a handy helper method for retrieving whether there is an update available for the given plugin.
1372
+	 *
1373
+	 * @param  string $basename Use the equivalent result from plugin_basename() for this param as WP uses that to
1374
+	 *                          identify plugins. Defaults to core update
1375
+	 * @return boolean           True if update available, false if not.
1376
+	 * @deprecated 4.9.59.p
1377
+	 */
1378
+	public static function is_update_available($basename = '')
1379
+	{
1380
+		EE_Error::doing_it_wrong(
1381
+			__METHOD__,
1382
+			sprintf(
1383
+				esc_html__('%1$s has been replaced by %2$s.', 'event_espresso'),
1384
+				__METHOD__,
1385
+				'EventEspresso\caffeinated\core\services\licensing\LicenseService::isUpdateAvailable'
1386
+			),
1387
+			'4.9.59.p'
1388
+		);
1389
+		return LicenseService::isUpdateAvailable($basename);
1390
+	}
1391 1391
 }
1392 1392
 
1393 1393
 add_filter(
1394
-    'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array',
1395
-    'ee_deprecated_registrations_report_csv_legacy_fields',
1396
-    10,
1397
-    2
1394
+	'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array',
1395
+	'ee_deprecated_registrations_report_csv_legacy_fields',
1396
+	10,
1397
+	2
1398 1398
 );
1399 1399
 /**
1400 1400
  * Filters the CSV row to make it appear like the old labels (which were "$pretty_name[$field_name]").
@@ -1411,96 +1411,96 @@  discard block
 block discarded – undo
1411 1411
  */
1412 1412
 function ee_deprecated_registrations_report_csv_legacy_fields($csv_row_data, $reg_row)
1413 1413
 {
1414
-    // no need for all this if nobody is using the deprecated filter
1415
-    if (has_filter('FHEE__EE_Export__report_registrations__reg_csv_array')) {
1416
-        EE_Error::doing_it_wrong(
1417
-            __FUNCTION__,
1418
-            sprintf(
1419
-                // EE_Error::doing_it_wrong with escape HTML, so don't escape it twice by doing it here too.
1420
-                _x(
1421
-                    'The filter "%1$s" has been deprecated. Please use "%2$s" instead.',
1422
-                    'The filter "FHEE__EE_Export__report_registrations__reg_csv_array" has been deprecated. Please use "FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array" instead.',
1423
-                    'event_espresso'
1424
-                ),
1425
-                'FHEE__EE_Export__report_registrations__reg_csv_array',
1426
-                'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array'
1427
-            ),
1428
-            '4.9.69.p',
1429
-            '4.9.75.p'
1430
-        );
1431
-        // there's code that expected the old csv column headers/labels. Let's oblige. Put it back in the old format!
1432
-        // first: what model fields might be used as column headers? (whose format we need to change)
1433
-        $model_fields = array_merge(
1434
-            EEM_Registration::instance()->field_settings(),
1435
-            EEM_Attendee::instance()->field_settings()
1436
-        );
1437
-        // create an array that uses the legacy column headers/labels.
1438
-        $new_csv_row = array();
1439
-        foreach ($csv_row_data as $label => $value) {
1440
-            $new_label = $label;
1441
-            foreach ($model_fields as $field) {
1442
-                if ($label === EEH_Export::get_column_name_for_field($field)) {
1443
-                    // re-add the old field name
1444
-                    $new_label = $label . '[' . $field->get_name() . ']';
1445
-                    break;
1446
-                }
1447
-            }
1448
-            $new_csv_row[$new_label] = $value;
1449
-        }
1450
-        // before we run it through the deprecated filter, set the method `EEH_Export::get_column_name_for_field()`
1451
-        // to create the old column names, because that's what's in the row temporarily
1452
-        add_filter(
1453
-            'FHEE__EEH_Export__get_column_name_for_field__add_field_name',
1454
-            '__return_true',
1455
-            777
1456
-        );
1457
-        // now, those old filters can be run on this data. Have fun!
1458
-        /**
1459
-         * Deprecated. Use FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array instead.
1460
-         *
1461
-         * Filter to change the contents of each row of the registrations report CSV file.
1462
-         * This can be used to add or remote columns from the CSV file, or change their values.                 *
1463
-         * Note: it has this name because originally that's where this filter resided,
1464
-         * and we've left its name as-is for backward compatibility.
1465
-         * Note when using: all rows in the CSV should have the same columns.
1466
-         *
1467
-         * @param array $reg_csv_array keys are column-header names, and values are that columns' value
1468
-         *                             in this row
1469
-         * @param array $reg_row is the row from the database's wp_esp_registration table
1470
-         */
1471
-        $updated_row = apply_filters(
1472
-            'FHEE__EE_Export__report_registrations__reg_csv_array',
1473
-            $new_csv_row,
1474
-            $reg_row
1475
-        );
1476
-
1477
-        // ok now we can revert to normal for EEH_Export::get_column_name_for_field().
1478
-        remove_filter(
1479
-            'FHEE__EEH_Export__get_column_name_for_field__add_field_name',
1480
-            '__return_true',
1481
-            777
1482
-        );
1483
-
1484
-        // great. Now that the old filters are done, we can remove the ugly square brackets from column headers/labels.
1485
-        $updated_and_restored_row = array();
1486
-        foreach ($updated_row as $label => $value) {
1487
-            $matches = array();
1488
-            if (preg_match(
1489
-                    '~([^\[]*)\[(.*)\]~',
1490
-                    $label,
1491
-                    $matches
1492
-                )
1493
-                && isset(
1494
-                    $matches[0],
1495
-                    $matches[1],
1496
-                    $matches[2]
1497
-                )
1498
-            ) {
1499
-                $label = $matches[1];
1500
-            }
1501
-            $updated_and_restored_row[$label] = $value;
1502
-        }
1503
-        $csv_row_data = $updated_and_restored_row;
1504
-    }
1505
-    return $csv_row_data;
1414
+	// no need for all this if nobody is using the deprecated filter
1415
+	if (has_filter('FHEE__EE_Export__report_registrations__reg_csv_array')) {
1416
+		EE_Error::doing_it_wrong(
1417
+			__FUNCTION__,
1418
+			sprintf(
1419
+				// EE_Error::doing_it_wrong with escape HTML, so don't escape it twice by doing it here too.
1420
+				_x(
1421
+					'The filter "%1$s" has been deprecated. Please use "%2$s" instead.',
1422
+					'The filter "FHEE__EE_Export__report_registrations__reg_csv_array" has been deprecated. Please use "FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array" instead.',
1423
+					'event_espresso'
1424
+				),
1425
+				'FHEE__EE_Export__report_registrations__reg_csv_array',
1426
+				'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array'
1427
+			),
1428
+			'4.9.69.p',
1429
+			'4.9.75.p'
1430
+		);
1431
+		// there's code that expected the old csv column headers/labels. Let's oblige. Put it back in the old format!
1432
+		// first: what model fields might be used as column headers? (whose format we need to change)
1433
+		$model_fields = array_merge(
1434
+			EEM_Registration::instance()->field_settings(),
1435
+			EEM_Attendee::instance()->field_settings()
1436
+		);
1437
+		// create an array that uses the legacy column headers/labels.
1438
+		$new_csv_row = array();
1439
+		foreach ($csv_row_data as $label => $value) {
1440
+			$new_label = $label;
1441
+			foreach ($model_fields as $field) {
1442
+				if ($label === EEH_Export::get_column_name_for_field($field)) {
1443
+					// re-add the old field name
1444
+					$new_label = $label . '[' . $field->get_name() . ']';
1445
+					break;
1446
+				}
1447
+			}
1448
+			$new_csv_row[$new_label] = $value;
1449
+		}
1450
+		// before we run it through the deprecated filter, set the method `EEH_Export::get_column_name_for_field()`
1451
+		// to create the old column names, because that's what's in the row temporarily
1452
+		add_filter(
1453
+			'FHEE__EEH_Export__get_column_name_for_field__add_field_name',
1454
+			'__return_true',
1455
+			777
1456
+		);
1457
+		// now, those old filters can be run on this data. Have fun!
1458
+		/**
1459
+		 * Deprecated. Use FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array instead.
1460
+		 *
1461
+		 * Filter to change the contents of each row of the registrations report CSV file.
1462
+		 * This can be used to add or remote columns from the CSV file, or change their values.                 *
1463
+		 * Note: it has this name because originally that's where this filter resided,
1464
+		 * and we've left its name as-is for backward compatibility.
1465
+		 * Note when using: all rows in the CSV should have the same columns.
1466
+		 *
1467
+		 * @param array $reg_csv_array keys are column-header names, and values are that columns' value
1468
+		 *                             in this row
1469
+		 * @param array $reg_row is the row from the database's wp_esp_registration table
1470
+		 */
1471
+		$updated_row = apply_filters(
1472
+			'FHEE__EE_Export__report_registrations__reg_csv_array',
1473
+			$new_csv_row,
1474
+			$reg_row
1475
+		);
1476
+
1477
+		// ok now we can revert to normal for EEH_Export::get_column_name_for_field().
1478
+		remove_filter(
1479
+			'FHEE__EEH_Export__get_column_name_for_field__add_field_name',
1480
+			'__return_true',
1481
+			777
1482
+		);
1483
+
1484
+		// great. Now that the old filters are done, we can remove the ugly square brackets from column headers/labels.
1485
+		$updated_and_restored_row = array();
1486
+		foreach ($updated_row as $label => $value) {
1487
+			$matches = array();
1488
+			if (preg_match(
1489
+					'~([^\[]*)\[(.*)\]~',
1490
+					$label,
1491
+					$matches
1492
+				)
1493
+				&& isset(
1494
+					$matches[0],
1495
+					$matches[1],
1496
+					$matches[2]
1497
+				)
1498
+			) {
1499
+				$label = $matches[1];
1500
+			}
1501
+			$updated_and_restored_row[$label] = $value;
1502
+		}
1503
+		$csv_row_data = $updated_and_restored_row;
1504
+	}
1505
+	return $csv_row_data;
1506 1506
 }
Please login to merge, or discard this patch.
core/services/request/RequestParams.php 1 patch
Indentation   +345 added lines, -345 removed lines patch added patch discarded remove patch
@@ -13,349 +13,349 @@
 block discarded – undo
13 13
  */
14 14
 class RequestParams
15 15
 {
16
-    /**
17
-     * Used for matches() and parameterDrillDown()
18
-     * 'bool' will return true or false if match is found or not
19
-     */
20
-    const RETURN_BOOL  = 'bool';
21
-
22
-    /**
23
-     * Used for matches() and parameterDrillDown()
24
-     * 'key' will return the first key found that matches the supplied pattern
25
-     */
26
-    const RETURN_KEY   = 'key';
27
-
28
-    /**
29
-     * Used for matches() and parameterDrillDown()
30
-     * 'value' will return the value for the first request parameter
31
-     */
32
-    const RETURN_VALUE = 'value';
33
-
34
-    /**
35
-     * $_GET parameters
36
-     *
37
-     * @var array
38
-     */
39
-    protected $get;
40
-
41
-    /**
42
-     * $_POST parameters
43
-     *
44
-     * @var array
45
-     */
46
-    protected $post;
47
-
48
-    /**
49
-     * $_REQUEST parameters
50
-     *
51
-     * @var array
52
-     */
53
-    protected $request;
54
-
55
-    /**
56
-     * @var RequestSanitizer
57
-     */
58
-    protected $sanitizer;
59
-
60
-
61
-    /**
62
-     * RequestParams constructor.
63
-     *
64
-     * @param RequestSanitizer $sanitizer
65
-     * @param array            $get
66
-     * @param array            $post
67
-     */
68
-    public function __construct(RequestSanitizer $sanitizer, array $get = [], array $post = [])
69
-    {
70
-        $this->sanitizer = $sanitizer;
71
-        $this->get       = $get;
72
-        $this->post      = $post;
73
-        $this->request   = array_merge($this->get, $this->post);
74
-    }
75
-
76
-
77
-    /**
78
-     * @return array
79
-     */
80
-    public function getParams()
81
-    {
82
-        return $this->get;
83
-    }
84
-
85
-
86
-    /**
87
-     * @return array
88
-     */
89
-    public function postParams()
90
-    {
91
-        return $this->post;
92
-    }
93
-
94
-
95
-    /**
96
-     * returns contents of $_REQUEST
97
-     *
98
-     * @return array
99
-     */
100
-    public function requestParams()
101
-    {
102
-        return $this->request;
103
-    }
104
-
105
-
106
-    /**
107
-     * @param string     $key
108
-     * @param mixed|null $value
109
-     * @param bool       $override_ee
110
-     * @return    void
111
-     */
112
-    public function setRequestParam($key, $value, $override_ee = false)
113
-    {
114
-        // don't allow "ee" to be overwritten unless explicitly instructed to do so
115
-        if ($override_ee || $key !== 'ee' || empty($this->request['ee'])) {
116
-            $this->request[ $key ] = $value;
117
-        }
118
-    }
119
-
120
-
121
-    /**
122
-     * merges the incoming array of parameters into the existing request parameters
123
-     *
124
-     * @param array $request_params
125
-     * @return void
126
-     * @since   4.10.24.p
127
-     */
128
-    public function mergeRequestParams(array $request_params)
129
-    {
130
-        $this->request = array_merge($this->request, $request_params);
131
-    }
132
-
133
-
134
-    /**
135
-     * returns   the value for a request param if the given key exists
136
-     *
137
-     * @param string     $key
138
-     * @param mixed|null $default
139
-     * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
140
-     * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
141
-     * @param string     $delimiter for CSV type strings that should be returned as an array
142
-     * @return array|bool|float|int|string
143
-     */
144
-    public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '')
145
-    {
146
-        $param = $this->sanitizer->clean(
147
-            $this->parameterDrillDown($key, $default, 'get'),
148
-            $type,
149
-            $is_array,
150
-            $delimiter
151
-        );
152
-        $type = $is_array ? 'array' : $type;
153
-        return DataType::setDataType($param, $type);
154
-    }
155
-
156
-
157
-    /**
158
-     * check if param exists
159
-     *
160
-     * @param string $key
161
-     * @return bool
162
-     */
163
-    public function requestParamIsSet($key)
164
-    {
165
-        return (bool) $this->parameterDrillDown($key);
166
-    }
167
-
168
-
169
-    /**
170
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
171
-     * and return the value for the first match found
172
-     * wildcards can be either of the following:
173
-     *      ? to represent a single character of any type
174
-     *      * to represent one or more characters of any type
175
-     *
176
-     * @param string     $pattern
177
-     * @param mixed|null $default
178
-     * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
179
-     * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
180
-     * @param string     $delimiter for CSV type strings that should be returned as an array
181
-     * @return array|bool|float|int|string
182
-     */
183
-    public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '')
184
-    {
185
-        $param = $this->sanitizer->clean(
186
-            $this->parameterDrillDown($pattern, $default, 'match'),
187
-            $type,
188
-            $is_array,
189
-            $delimiter
190
-        );
191
-        $type = $is_array ? 'array' : $type;
192
-        return DataType::setDataType($param, $type);
193
-    }
194
-
195
-
196
-    /**
197
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
198
-     * wildcards can be either of the following:
199
-     *      ? to represent a single character of any type
200
-     *      * to represent one or more characters of any type
201
-     * returns true if a match is found or false if not
202
-     *
203
-     * @param string $pattern
204
-     * @return bool
205
-     */
206
-    public function matches($pattern)
207
-    {
208
-        return (bool) $this->parameterDrillDown($pattern, false, 'match', self::RETURN_BOOL);
209
-    }
210
-
211
-
212
-    /**
213
-     * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
214
-     * @param string $pattern               A string including wildcards to be converted to a regex pattern
215
-     *                                      and used to search through the current request's parameter keys
216
-     * @param array  $request_params        The array of request parameters to search through
217
-     * @param mixed  $default               [optional] The value to be returned if no match is found.
218
-     *                                      Default is null
219
-     * @param string $return                [optional] Controls what kind of value is returned.
220
-     *                                      Options are the RETURN_* constants:
221
-     *                                      RETURN_BOOL will return true or false if match is found or not
222
-     *                                      RETURN_KEY will return the first key found that matches the supplied pattern
223
-     *                                      RETURN_VALUE will return the value for the first request parameter
224
-     *                                      whose key matches the supplied pattern
225
-     *                                      Default is 'value'
226
-     * @return boolean|string
227
-     */
228
-    private function match($pattern, array $request_params, $default = null, $return = self::RETURN_VALUE)
229
-    {
230
-        $return = in_array($return, [self::RETURN_BOOL, self::RETURN_KEY, self::RETURN_VALUE], true)
231
-            ? $return
232
-            : 'is_set';
233
-        // replace wildcard chars with regex chars
234
-        $pattern = str_replace(
235
-            ['\*', '\?'],
236
-            ['.*', '.'],
237
-            preg_quote($pattern, '/')
238
-        );
239
-        foreach ($request_params as $key => $request_param) {
240
-            if (preg_match('/^' . $pattern . '$/is', $key)) {
241
-                // return value for request param
242
-                if ($return === self::RETURN_VALUE) {
243
-                    return $request_param;
244
-                }
245
-                // or actual key or true just to indicate it was found
246
-                return $return === self::RETURN_KEY ? $key : true;
247
-            }
248
-        }
249
-        // match not found so return default value or false
250
-        return $return === self::RETURN_VALUE ? $default : false;
251
-    }
252
-
253
-
254
-    /**
255
-     * the supplied key can be a simple string to represent a "top-level" request parameter
256
-     * or represent a key for a request parameter that is nested deeper within the request parameter array,
257
-     * by using square brackets to surround keys for deeper array elements.
258
-     * For example :
259
-     * if the supplied $key was: "first[second][third]"
260
-     * then this will attempt to drill down into the request parameter array to find a value.
261
-     * Given the following request parameters:
262
-     *  array(
263
-     *      'first' => array(
264
-     *          'second' => array(
265
-     *              'third' => 'has a value'
266
-     *          )
267
-     *      )
268
-     *  )
269
-     * would return true if default parameters were set
270
-     *
271
-     * @param string $callback
272
-     * @param        $key
273
-     * @param null   $default
274
-     * @param string $return
275
-     * @param mixed  $request_params
276
-     * @return bool|mixed|null
277
-     */
278
-    private function parameterDrillDown(
279
-        $key,
280
-        $default = null,
281
-        $callback = 'is_set',
282
-        $return = self::RETURN_VALUE,
283
-        $request_params = []
284
-    ) {
285
-        $callback       = in_array($callback, ['is_set', 'get', 'match'], true)
286
-            ? $callback
287
-            : 'is_set';
288
-        $request_params = ! empty($request_params)
289
-            ? $request_params
290
-            : $this->request;
291
-        // does incoming key represent an array like 'first[second][third]'  ?
292
-        if (strpos($key, '[') !== false) {
293
-            // turn it into an actual array
294
-            $key  = str_replace(']', '', $key);
295
-            $keys = explode('[', $key);
296
-            $key  = array_shift($keys);
297
-            if ($callback === 'match') {
298
-                $real_key = $this->match($key, $request_params, $default, self::RETURN_KEY);
299
-                $key      = $real_key ?: $key;
300
-            }
301
-            // check if top level key exists
302
-            if (isset($request_params[ $key ])) {
303
-                // build a new key to pass along like: 'second[third]'
304
-                // or just 'second' depending on depth of keys
305
-                $key_string = array_shift($keys);
306
-                if (! empty($keys)) {
307
-                    $key_string .= '[' . implode('][', $keys) . ']';
308
-                }
309
-                return $this->parameterDrillDown(
310
-                    $key_string,
311
-                    $default,
312
-                    $callback,
313
-                    $return,
314
-                    $request_params[ $key ]
315
-                );
316
-            }
317
-        }
318
-        if ($callback === 'is_set') {
319
-            return isset($request_params[ $key ]);
320
-        }
321
-        if ($callback === 'match') {
322
-            return $this->match($key, $request_params, $default, $return);
323
-        }
324
-        return isset($request_params[ $key ])
325
-            ? $request_params[ $key ]
326
-            : $default;
327
-    }
328
-
329
-
330
-    /**
331
-     * remove param
332
-     *
333
-     * @param      $key
334
-     * @param bool $unset_from_global_too
335
-     */
336
-    public function unSetRequestParam($key, $unset_from_global_too = false)
337
-    {
338
-        // because unset may not actually remove var
339
-        $this->get[ $key ]     = null;
340
-        $this->post[ $key ]    = null;
341
-        $this->request[ $key ] = null;
342
-        unset($this->get[ $key ], $this->post[ $key ], $this->request[ $key ]);
343
-        if ($unset_from_global_too) {
344
-            unset($_GET[ $key ], $_POST[ $key ], $_REQUEST[ $key ]);
345
-        }
346
-    }
347
-
348
-
349
-    /**
350
-     * remove params
351
-     *
352
-     * @param array $keys
353
-     * @param bool  $unset_from_global_too
354
-     */
355
-    public function unSetRequestParams(array $keys, $unset_from_global_too = false)
356
-    {
357
-        foreach ($keys as $key) {
358
-            $this->unSetRequestParam($key, $unset_from_global_too);
359
-        }
360
-    }
16
+	/**
17
+	 * Used for matches() and parameterDrillDown()
18
+	 * 'bool' will return true or false if match is found or not
19
+	 */
20
+	const RETURN_BOOL  = 'bool';
21
+
22
+	/**
23
+	 * Used for matches() and parameterDrillDown()
24
+	 * 'key' will return the first key found that matches the supplied pattern
25
+	 */
26
+	const RETURN_KEY   = 'key';
27
+
28
+	/**
29
+	 * Used for matches() and parameterDrillDown()
30
+	 * 'value' will return the value for the first request parameter
31
+	 */
32
+	const RETURN_VALUE = 'value';
33
+
34
+	/**
35
+	 * $_GET parameters
36
+	 *
37
+	 * @var array
38
+	 */
39
+	protected $get;
40
+
41
+	/**
42
+	 * $_POST parameters
43
+	 *
44
+	 * @var array
45
+	 */
46
+	protected $post;
47
+
48
+	/**
49
+	 * $_REQUEST parameters
50
+	 *
51
+	 * @var array
52
+	 */
53
+	protected $request;
54
+
55
+	/**
56
+	 * @var RequestSanitizer
57
+	 */
58
+	protected $sanitizer;
59
+
60
+
61
+	/**
62
+	 * RequestParams constructor.
63
+	 *
64
+	 * @param RequestSanitizer $sanitizer
65
+	 * @param array            $get
66
+	 * @param array            $post
67
+	 */
68
+	public function __construct(RequestSanitizer $sanitizer, array $get = [], array $post = [])
69
+	{
70
+		$this->sanitizer = $sanitizer;
71
+		$this->get       = $get;
72
+		$this->post      = $post;
73
+		$this->request   = array_merge($this->get, $this->post);
74
+	}
75
+
76
+
77
+	/**
78
+	 * @return array
79
+	 */
80
+	public function getParams()
81
+	{
82
+		return $this->get;
83
+	}
84
+
85
+
86
+	/**
87
+	 * @return array
88
+	 */
89
+	public function postParams()
90
+	{
91
+		return $this->post;
92
+	}
93
+
94
+
95
+	/**
96
+	 * returns contents of $_REQUEST
97
+	 *
98
+	 * @return array
99
+	 */
100
+	public function requestParams()
101
+	{
102
+		return $this->request;
103
+	}
104
+
105
+
106
+	/**
107
+	 * @param string     $key
108
+	 * @param mixed|null $value
109
+	 * @param bool       $override_ee
110
+	 * @return    void
111
+	 */
112
+	public function setRequestParam($key, $value, $override_ee = false)
113
+	{
114
+		// don't allow "ee" to be overwritten unless explicitly instructed to do so
115
+		if ($override_ee || $key !== 'ee' || empty($this->request['ee'])) {
116
+			$this->request[ $key ] = $value;
117
+		}
118
+	}
119
+
120
+
121
+	/**
122
+	 * merges the incoming array of parameters into the existing request parameters
123
+	 *
124
+	 * @param array $request_params
125
+	 * @return void
126
+	 * @since   4.10.24.p
127
+	 */
128
+	public function mergeRequestParams(array $request_params)
129
+	{
130
+		$this->request = array_merge($this->request, $request_params);
131
+	}
132
+
133
+
134
+	/**
135
+	 * returns   the value for a request param if the given key exists
136
+	 *
137
+	 * @param string     $key
138
+	 * @param mixed|null $default
139
+	 * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
140
+	 * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
141
+	 * @param string     $delimiter for CSV type strings that should be returned as an array
142
+	 * @return array|bool|float|int|string
143
+	 */
144
+	public function getRequestParam($key, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '')
145
+	{
146
+		$param = $this->sanitizer->clean(
147
+			$this->parameterDrillDown($key, $default, 'get'),
148
+			$type,
149
+			$is_array,
150
+			$delimiter
151
+		);
152
+		$type = $is_array ? 'array' : $type;
153
+		return DataType::setDataType($param, $type);
154
+	}
155
+
156
+
157
+	/**
158
+	 * check if param exists
159
+	 *
160
+	 * @param string $key
161
+	 * @return bool
162
+	 */
163
+	public function requestParamIsSet($key)
164
+	{
165
+		return (bool) $this->parameterDrillDown($key);
166
+	}
167
+
168
+
169
+	/**
170
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
171
+	 * and return the value for the first match found
172
+	 * wildcards can be either of the following:
173
+	 *      ? to represent a single character of any type
174
+	 *      * to represent one or more characters of any type
175
+	 *
176
+	 * @param string     $pattern
177
+	 * @param mixed|null $default
178
+	 * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
179
+	 * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
180
+	 * @param string     $delimiter for CSV type strings that should be returned as an array
181
+	 * @return array|bool|float|int|string
182
+	 */
183
+	public function getMatch($pattern, $default = null, $type = DataType::STRING, $is_array = false, $delimiter = '')
184
+	{
185
+		$param = $this->sanitizer->clean(
186
+			$this->parameterDrillDown($pattern, $default, 'match'),
187
+			$type,
188
+			$is_array,
189
+			$delimiter
190
+		);
191
+		$type = $is_array ? 'array' : $type;
192
+		return DataType::setDataType($param, $type);
193
+	}
194
+
195
+
196
+	/**
197
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
198
+	 * wildcards can be either of the following:
199
+	 *      ? to represent a single character of any type
200
+	 *      * to represent one or more characters of any type
201
+	 * returns true if a match is found or false if not
202
+	 *
203
+	 * @param string $pattern
204
+	 * @return bool
205
+	 */
206
+	public function matches($pattern)
207
+	{
208
+		return (bool) $this->parameterDrillDown($pattern, false, 'match', self::RETURN_BOOL);
209
+	}
210
+
211
+
212
+	/**
213
+	 * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
214
+	 * @param string $pattern               A string including wildcards to be converted to a regex pattern
215
+	 *                                      and used to search through the current request's parameter keys
216
+	 * @param array  $request_params        The array of request parameters to search through
217
+	 * @param mixed  $default               [optional] The value to be returned if no match is found.
218
+	 *                                      Default is null
219
+	 * @param string $return                [optional] Controls what kind of value is returned.
220
+	 *                                      Options are the RETURN_* constants:
221
+	 *                                      RETURN_BOOL will return true or false if match is found or not
222
+	 *                                      RETURN_KEY will return the first key found that matches the supplied pattern
223
+	 *                                      RETURN_VALUE will return the value for the first request parameter
224
+	 *                                      whose key matches the supplied pattern
225
+	 *                                      Default is 'value'
226
+	 * @return boolean|string
227
+	 */
228
+	private function match($pattern, array $request_params, $default = null, $return = self::RETURN_VALUE)
229
+	{
230
+		$return = in_array($return, [self::RETURN_BOOL, self::RETURN_KEY, self::RETURN_VALUE], true)
231
+			? $return
232
+			: 'is_set';
233
+		// replace wildcard chars with regex chars
234
+		$pattern = str_replace(
235
+			['\*', '\?'],
236
+			['.*', '.'],
237
+			preg_quote($pattern, '/')
238
+		);
239
+		foreach ($request_params as $key => $request_param) {
240
+			if (preg_match('/^' . $pattern . '$/is', $key)) {
241
+				// return value for request param
242
+				if ($return === self::RETURN_VALUE) {
243
+					return $request_param;
244
+				}
245
+				// or actual key or true just to indicate it was found
246
+				return $return === self::RETURN_KEY ? $key : true;
247
+			}
248
+		}
249
+		// match not found so return default value or false
250
+		return $return === self::RETURN_VALUE ? $default : false;
251
+	}
252
+
253
+
254
+	/**
255
+	 * the supplied key can be a simple string to represent a "top-level" request parameter
256
+	 * or represent a key for a request parameter that is nested deeper within the request parameter array,
257
+	 * by using square brackets to surround keys for deeper array elements.
258
+	 * For example :
259
+	 * if the supplied $key was: "first[second][third]"
260
+	 * then this will attempt to drill down into the request parameter array to find a value.
261
+	 * Given the following request parameters:
262
+	 *  array(
263
+	 *      'first' => array(
264
+	 *          'second' => array(
265
+	 *              'third' => 'has a value'
266
+	 *          )
267
+	 *      )
268
+	 *  )
269
+	 * would return true if default parameters were set
270
+	 *
271
+	 * @param string $callback
272
+	 * @param        $key
273
+	 * @param null   $default
274
+	 * @param string $return
275
+	 * @param mixed  $request_params
276
+	 * @return bool|mixed|null
277
+	 */
278
+	private function parameterDrillDown(
279
+		$key,
280
+		$default = null,
281
+		$callback = 'is_set',
282
+		$return = self::RETURN_VALUE,
283
+		$request_params = []
284
+	) {
285
+		$callback       = in_array($callback, ['is_set', 'get', 'match'], true)
286
+			? $callback
287
+			: 'is_set';
288
+		$request_params = ! empty($request_params)
289
+			? $request_params
290
+			: $this->request;
291
+		// does incoming key represent an array like 'first[second][third]'  ?
292
+		if (strpos($key, '[') !== false) {
293
+			// turn it into an actual array
294
+			$key  = str_replace(']', '', $key);
295
+			$keys = explode('[', $key);
296
+			$key  = array_shift($keys);
297
+			if ($callback === 'match') {
298
+				$real_key = $this->match($key, $request_params, $default, self::RETURN_KEY);
299
+				$key      = $real_key ?: $key;
300
+			}
301
+			// check if top level key exists
302
+			if (isset($request_params[ $key ])) {
303
+				// build a new key to pass along like: 'second[third]'
304
+				// or just 'second' depending on depth of keys
305
+				$key_string = array_shift($keys);
306
+				if (! empty($keys)) {
307
+					$key_string .= '[' . implode('][', $keys) . ']';
308
+				}
309
+				return $this->parameterDrillDown(
310
+					$key_string,
311
+					$default,
312
+					$callback,
313
+					$return,
314
+					$request_params[ $key ]
315
+				);
316
+			}
317
+		}
318
+		if ($callback === 'is_set') {
319
+			return isset($request_params[ $key ]);
320
+		}
321
+		if ($callback === 'match') {
322
+			return $this->match($key, $request_params, $default, $return);
323
+		}
324
+		return isset($request_params[ $key ])
325
+			? $request_params[ $key ]
326
+			: $default;
327
+	}
328
+
329
+
330
+	/**
331
+	 * remove param
332
+	 *
333
+	 * @param      $key
334
+	 * @param bool $unset_from_global_too
335
+	 */
336
+	public function unSetRequestParam($key, $unset_from_global_too = false)
337
+	{
338
+		// because unset may not actually remove var
339
+		$this->get[ $key ]     = null;
340
+		$this->post[ $key ]    = null;
341
+		$this->request[ $key ] = null;
342
+		unset($this->get[ $key ], $this->post[ $key ], $this->request[ $key ]);
343
+		if ($unset_from_global_too) {
344
+			unset($_GET[ $key ], $_POST[ $key ], $_REQUEST[ $key ]);
345
+		}
346
+	}
347
+
348
+
349
+	/**
350
+	 * remove params
351
+	 *
352
+	 * @param array $keys
353
+	 * @param bool  $unset_from_global_too
354
+	 */
355
+	public function unSetRequestParams(array $keys, $unset_from_global_too = false)
356
+	{
357
+		foreach ($keys as $key) {
358
+			$this->unSetRequestParam($key, $unset_from_global_too);
359
+		}
360
+	}
361 361
 }
Please login to merge, or discard this patch.
core/services/request/sanitizers/AllowedTags.php 1 patch
Indentation   +284 added lines, -284 removed lines patch added patch discarded remove patch
@@ -12,288 +12,288 @@
 block discarded – undo
12 12
  */
13 13
 class AllowedTags
14 14
 {
15
-    /**
16
-     * @var array[]
17
-     */
18
-    private static $attributes = [
19
-        'accept-charset'    => 1,
20
-        'action'            => 1,
21
-        'alt'               => 1,
22
-        'allow'             => 1,
23
-        'allowfullscreen'   => 1,
24
-        'align'             => 1,
25
-        'aria-*'            => 1,
26
-        'autocomplete'      => 1,
27
-        'bgcolor'           => 1,
28
-        'border'            => 1,
29
-        'cellpadding'       => 1,
30
-        'cellspacing'       => 1,
31
-        'checked'           => 1,
32
-        'class'             => 1,
33
-        'cols'              => 1,
34
-        'content'           => 1,
35
-        'data-*'            => 1,
36
-        'dir'               => 1,
37
-        'disabled'          => 1,
38
-        'enctype'           => 1,
39
-        'extension'         => 1,
40
-        'for'               => 1,
41
-        'frameborder'       => 1,
42
-        'height'            => 1,
43
-        'href'              => 1,
44
-        'id'                => 1,
45
-        'itemprop'          => 1,
46
-        'itemscope'         => 1,
47
-        'itemtype'          => 1,
48
-        'label'             => 1,
49
-        'lang'              => 1,
50
-        'leftmargin'        => 1,
51
-        'marginheight'      => 1,
52
-        'marginwidth'       => 1,
53
-        'max'               => 1,
54
-        'maxlength'         => 1,
55
-        'media'             => 1,
56
-        'method'            => 1,
57
-        'min'               => 1,
58
-        'multiple'          => 1,
59
-        'name'              => 1,
60
-        'novalidate'        => 1,
61
-        'placeholder'       => 1,
62
-        'property'          => 1,
63
-        'readonly'          => 1,
64
-        'rel'               => 1,
65
-        'required'          => 1,
66
-        'rows'              => 1,
67
-        'selected'          => 1,
68
-        'src'               => 1,
69
-        'size'              => 1,
70
-        'style'             => 1,
71
-        'step'              => 1,
72
-        'tabindex'          => 1,
73
-        'target'            => 1,
74
-        'title'             => 1,
75
-        'topmargin'         => 1,
76
-        'type'              => 1,
77
-        'value'             => 1,
78
-        'width'             => 1,
79
-    ];
80
-
81
-
82
-    /**
83
-     * @var array
84
-     */
85
-    private static $tags = [
86
-        'a',
87
-        'abbr',
88
-        'b',
89
-        'br',
90
-        'code',
91
-        'div',
92
-        'em',
93
-        'h1',
94
-        'h2',
95
-        'h3',
96
-        'h4',
97
-        'h5',
98
-        'h6',
99
-        'hr',
100
-        'i',
101
-        'img',
102
-        'li',
103
-        'ol',
104
-        'p',
105
-        'pre',
106
-        'small',
107
-        'span',
108
-        'strong',
109
-        'table',
110
-        'td',
111
-        'tr',
112
-        'ul',
113
-    ];
114
-
115
-
116
-    /**
117
-     * @var array
118
-     */
119
-    private static $allowed_tags;
120
-
121
-
122
-    /**
123
-     * @var array
124
-     */
125
-    private static $allowed_with_embed_tags;
126
-
127
-
128
-    /**
129
-     * @var array
130
-     */
131
-    private static $allowed_with_form_tags;
132
-
133
-
134
-    /**
135
-     * @var array
136
-     */
137
-    private static $allowed_with_script_and_style_tags;
138
-
139
-    /**
140
-     * @var array
141
-     */
142
-    private static $allowed_with_full_tags;
143
-
144
-
145
-    /**
146
-     * merges additional tags and attributes into the WP post tags
147
-     */
148
-    private static function initializeAllowedTags()
149
-    {
150
-        $allowed_post_tags = wp_kses_allowed_html('post');
151
-        $allowed_tags = [];
152
-        foreach (AllowedTags::$tags as $tag) {
153
-            $allowed_tags[ $tag ] = AllowedTags::$attributes;
154
-        }
155
-        AllowedTags::$allowed_tags = array_merge_recursive($allowed_post_tags, $allowed_tags);
156
-    }
157
-
158
-
159
-    /**
160
-     * merges embed tags and attributes into the EE all tags
161
-     */
162
-    private static function initializeWithEmbedTags()
163
-    {
164
-        $all_tags = AllowedTags::getAllowedTags();
165
-        $embed_tags = [
166
-            'iframe' => AllowedTags::$attributes
167
-        ];
168
-        AllowedTags::$allowed_with_embed_tags = array_merge_recursive($all_tags, $embed_tags);
169
-    }
170
-
171
-
172
-    /**
173
-     * merges form tags and attributes into the EE all tags
174
-     */
175
-    private static function initializeWithFormTags()
176
-    {
177
-        $all_tags = AllowedTags::getAllowedTags();
178
-        $form_tags = [
179
-            'form'     => AllowedTags::$attributes,
180
-            'label'    => AllowedTags::$attributes,
181
-            'input'    => AllowedTags::$attributes,
182
-            'select'   => AllowedTags::$attributes,
183
-            'option'   => AllowedTags::$attributes,
184
-            'optgroup' => AllowedTags::$attributes,
185
-            'textarea' => AllowedTags::$attributes,
186
-            'button'   => AllowedTags::$attributes,
187
-            'fieldset' => AllowedTags::$attributes,
188
-            'output'   => AllowedTags::$attributes,
189
-        ];
190
-        AllowedTags::$allowed_with_form_tags = array_merge_recursive($all_tags, $form_tags);
191
-    }
192
-
193
-
194
-    /**
195
-     * merges form script and style tags and attributes into the EE all tags
196
-     */
197
-    private static function initializeWithScriptAndStyleTags()
198
-    {
199
-        $all_tags = AllowedTags::getAllowedTags();
200
-        $script_and_style_tags = [
201
-            'script'   => AllowedTags::$attributes,
202
-            'style'    => AllowedTags::$attributes,
203
-            'link'     => AllowedTags::$attributes,
204
-            'noscript' => AllowedTags::$attributes,
205
-        ];
206
-        AllowedTags::$allowed_with_script_and_style_tags = array_merge_recursive($all_tags, $script_and_style_tags);
207
-    }
208
-
209
-    /**
210
-     * merges all head and body tags and attributes into the EE all tags
211
-     */
212
-    private static function initializeWithFullTags()
213
-    {
214
-        $all_tags = AllowedTags::getAllowedTags();
215
-        $full_tags = [
216
-            'script'    => AllowedTags::$attributes,
217
-            'style'     => AllowedTags::$attributes,
218
-            'link'      => AllowedTags::$attributes,
219
-            'title'     => AllowedTags::$attributes,
220
-            'meta'      => AllowedTags::$attributes,
221
-            'iframe'    => AllowedTags::$attributes,
222
-            'form'      => AllowedTags::$attributes,
223
-            'label'     => AllowedTags::$attributes,
224
-            'input'     => AllowedTags::$attributes,
225
-            'select'    => AllowedTags::$attributes,
226
-            'option'    => AllowedTags::$attributes,
227
-            'optgroup'  => AllowedTags::$attributes,
228
-            'textarea'  => AllowedTags::$attributes,
229
-            'button'    => AllowedTags::$attributes,
230
-            'fieldset'  => AllowedTags::$attributes,
231
-            'output'    => AllowedTags::$attributes,
232
-            'noscript'  => AllowedTags::$attributes,
233
-            'html'      => AllowedTags::$attributes,
234
-            'body'      => AllowedTags::$attributes,
235
-            'head'      => AllowedTags::$attributes,
236
-        ];
237
-        AllowedTags::$allowed_with_full_tags = array_merge_recursive($all_tags, $full_tags);
238
-    }
239
-
240
-
241
-    /**
242
-     * @return array[]
243
-     */
244
-    public static function getAllowedTags()
245
-    {
246
-        if (empty(AllowedTags::$allowed_tags)) {
247
-            AllowedTags::initializeAllowedTags();
248
-        }
249
-        return AllowedTags::$allowed_tags;
250
-    }
251
-
252
-
253
-    /**
254
-     * @return array[]
255
-     */
256
-    public static function getWithEmbedTags()
257
-    {
258
-        if (empty(AllowedTags::$allowed_with_embed_tags)) {
259
-            AllowedTags::initializeWithEmbedTags();
260
-        }
261
-        return AllowedTags::$allowed_with_embed_tags;
262
-    }
263
-
264
-
265
-    /**
266
-     * @return array[]
267
-     */
268
-    public static function getWithFormTags()
269
-    {
270
-        if (empty(AllowedTags::$allowed_with_form_tags)) {
271
-            AllowedTags::initializeWithFormTags();
272
-        }
273
-        return AllowedTags::$allowed_with_form_tags;
274
-    }
275
-
276
-
277
-    /**
278
-     * @return array[]
279
-     */
280
-    public static function getWithScriptAndStyleTags()
281
-    {
282
-        if (empty(AllowedTags::$allowed_with_script_and_style_tags)) {
283
-            AllowedTags::initializeWithScriptAndStyleTags();
284
-        }
285
-        return AllowedTags::$allowed_with_script_and_style_tags;
286
-    }
287
-
288
-
289
-    /**
290
-     * @return array[]
291
-     */
292
-    public static function getWithFullTags()
293
-    {
294
-        if (empty(AllowedTags::$allowed_with_full_tags)) {
295
-            AllowedTags::initializeWithFullTags();
296
-        }
297
-        return AllowedTags::$allowed_with_full_tags;
298
-    }
15
+	/**
16
+	 * @var array[]
17
+	 */
18
+	private static $attributes = [
19
+		'accept-charset'    => 1,
20
+		'action'            => 1,
21
+		'alt'               => 1,
22
+		'allow'             => 1,
23
+		'allowfullscreen'   => 1,
24
+		'align'             => 1,
25
+		'aria-*'            => 1,
26
+		'autocomplete'      => 1,
27
+		'bgcolor'           => 1,
28
+		'border'            => 1,
29
+		'cellpadding'       => 1,
30
+		'cellspacing'       => 1,
31
+		'checked'           => 1,
32
+		'class'             => 1,
33
+		'cols'              => 1,
34
+		'content'           => 1,
35
+		'data-*'            => 1,
36
+		'dir'               => 1,
37
+		'disabled'          => 1,
38
+		'enctype'           => 1,
39
+		'extension'         => 1,
40
+		'for'               => 1,
41
+		'frameborder'       => 1,
42
+		'height'            => 1,
43
+		'href'              => 1,
44
+		'id'                => 1,
45
+		'itemprop'          => 1,
46
+		'itemscope'         => 1,
47
+		'itemtype'          => 1,
48
+		'label'             => 1,
49
+		'lang'              => 1,
50
+		'leftmargin'        => 1,
51
+		'marginheight'      => 1,
52
+		'marginwidth'       => 1,
53
+		'max'               => 1,
54
+		'maxlength'         => 1,
55
+		'media'             => 1,
56
+		'method'            => 1,
57
+		'min'               => 1,
58
+		'multiple'          => 1,
59
+		'name'              => 1,
60
+		'novalidate'        => 1,
61
+		'placeholder'       => 1,
62
+		'property'          => 1,
63
+		'readonly'          => 1,
64
+		'rel'               => 1,
65
+		'required'          => 1,
66
+		'rows'              => 1,
67
+		'selected'          => 1,
68
+		'src'               => 1,
69
+		'size'              => 1,
70
+		'style'             => 1,
71
+		'step'              => 1,
72
+		'tabindex'          => 1,
73
+		'target'            => 1,
74
+		'title'             => 1,
75
+		'topmargin'         => 1,
76
+		'type'              => 1,
77
+		'value'             => 1,
78
+		'width'             => 1,
79
+	];
80
+
81
+
82
+	/**
83
+	 * @var array
84
+	 */
85
+	private static $tags = [
86
+		'a',
87
+		'abbr',
88
+		'b',
89
+		'br',
90
+		'code',
91
+		'div',
92
+		'em',
93
+		'h1',
94
+		'h2',
95
+		'h3',
96
+		'h4',
97
+		'h5',
98
+		'h6',
99
+		'hr',
100
+		'i',
101
+		'img',
102
+		'li',
103
+		'ol',
104
+		'p',
105
+		'pre',
106
+		'small',
107
+		'span',
108
+		'strong',
109
+		'table',
110
+		'td',
111
+		'tr',
112
+		'ul',
113
+	];
114
+
115
+
116
+	/**
117
+	 * @var array
118
+	 */
119
+	private static $allowed_tags;
120
+
121
+
122
+	/**
123
+	 * @var array
124
+	 */
125
+	private static $allowed_with_embed_tags;
126
+
127
+
128
+	/**
129
+	 * @var array
130
+	 */
131
+	private static $allowed_with_form_tags;
132
+
133
+
134
+	/**
135
+	 * @var array
136
+	 */
137
+	private static $allowed_with_script_and_style_tags;
138
+
139
+	/**
140
+	 * @var array
141
+	 */
142
+	private static $allowed_with_full_tags;
143
+
144
+
145
+	/**
146
+	 * merges additional tags and attributes into the WP post tags
147
+	 */
148
+	private static function initializeAllowedTags()
149
+	{
150
+		$allowed_post_tags = wp_kses_allowed_html('post');
151
+		$allowed_tags = [];
152
+		foreach (AllowedTags::$tags as $tag) {
153
+			$allowed_tags[ $tag ] = AllowedTags::$attributes;
154
+		}
155
+		AllowedTags::$allowed_tags = array_merge_recursive($allowed_post_tags, $allowed_tags);
156
+	}
157
+
158
+
159
+	/**
160
+	 * merges embed tags and attributes into the EE all tags
161
+	 */
162
+	private static function initializeWithEmbedTags()
163
+	{
164
+		$all_tags = AllowedTags::getAllowedTags();
165
+		$embed_tags = [
166
+			'iframe' => AllowedTags::$attributes
167
+		];
168
+		AllowedTags::$allowed_with_embed_tags = array_merge_recursive($all_tags, $embed_tags);
169
+	}
170
+
171
+
172
+	/**
173
+	 * merges form tags and attributes into the EE all tags
174
+	 */
175
+	private static function initializeWithFormTags()
176
+	{
177
+		$all_tags = AllowedTags::getAllowedTags();
178
+		$form_tags = [
179
+			'form'     => AllowedTags::$attributes,
180
+			'label'    => AllowedTags::$attributes,
181
+			'input'    => AllowedTags::$attributes,
182
+			'select'   => AllowedTags::$attributes,
183
+			'option'   => AllowedTags::$attributes,
184
+			'optgroup' => AllowedTags::$attributes,
185
+			'textarea' => AllowedTags::$attributes,
186
+			'button'   => AllowedTags::$attributes,
187
+			'fieldset' => AllowedTags::$attributes,
188
+			'output'   => AllowedTags::$attributes,
189
+		];
190
+		AllowedTags::$allowed_with_form_tags = array_merge_recursive($all_tags, $form_tags);
191
+	}
192
+
193
+
194
+	/**
195
+	 * merges form script and style tags and attributes into the EE all tags
196
+	 */
197
+	private static function initializeWithScriptAndStyleTags()
198
+	{
199
+		$all_tags = AllowedTags::getAllowedTags();
200
+		$script_and_style_tags = [
201
+			'script'   => AllowedTags::$attributes,
202
+			'style'    => AllowedTags::$attributes,
203
+			'link'     => AllowedTags::$attributes,
204
+			'noscript' => AllowedTags::$attributes,
205
+		];
206
+		AllowedTags::$allowed_with_script_and_style_tags = array_merge_recursive($all_tags, $script_and_style_tags);
207
+	}
208
+
209
+	/**
210
+	 * merges all head and body tags and attributes into the EE all tags
211
+	 */
212
+	private static function initializeWithFullTags()
213
+	{
214
+		$all_tags = AllowedTags::getAllowedTags();
215
+		$full_tags = [
216
+			'script'    => AllowedTags::$attributes,
217
+			'style'     => AllowedTags::$attributes,
218
+			'link'      => AllowedTags::$attributes,
219
+			'title'     => AllowedTags::$attributes,
220
+			'meta'      => AllowedTags::$attributes,
221
+			'iframe'    => AllowedTags::$attributes,
222
+			'form'      => AllowedTags::$attributes,
223
+			'label'     => AllowedTags::$attributes,
224
+			'input'     => AllowedTags::$attributes,
225
+			'select'    => AllowedTags::$attributes,
226
+			'option'    => AllowedTags::$attributes,
227
+			'optgroup'  => AllowedTags::$attributes,
228
+			'textarea'  => AllowedTags::$attributes,
229
+			'button'    => AllowedTags::$attributes,
230
+			'fieldset'  => AllowedTags::$attributes,
231
+			'output'    => AllowedTags::$attributes,
232
+			'noscript'  => AllowedTags::$attributes,
233
+			'html'      => AllowedTags::$attributes,
234
+			'body'      => AllowedTags::$attributes,
235
+			'head'      => AllowedTags::$attributes,
236
+		];
237
+		AllowedTags::$allowed_with_full_tags = array_merge_recursive($all_tags, $full_tags);
238
+	}
239
+
240
+
241
+	/**
242
+	 * @return array[]
243
+	 */
244
+	public static function getAllowedTags()
245
+	{
246
+		if (empty(AllowedTags::$allowed_tags)) {
247
+			AllowedTags::initializeAllowedTags();
248
+		}
249
+		return AllowedTags::$allowed_tags;
250
+	}
251
+
252
+
253
+	/**
254
+	 * @return array[]
255
+	 */
256
+	public static function getWithEmbedTags()
257
+	{
258
+		if (empty(AllowedTags::$allowed_with_embed_tags)) {
259
+			AllowedTags::initializeWithEmbedTags();
260
+		}
261
+		return AllowedTags::$allowed_with_embed_tags;
262
+	}
263
+
264
+
265
+	/**
266
+	 * @return array[]
267
+	 */
268
+	public static function getWithFormTags()
269
+	{
270
+		if (empty(AllowedTags::$allowed_with_form_tags)) {
271
+			AllowedTags::initializeWithFormTags();
272
+		}
273
+		return AllowedTags::$allowed_with_form_tags;
274
+	}
275
+
276
+
277
+	/**
278
+	 * @return array[]
279
+	 */
280
+	public static function getWithScriptAndStyleTags()
281
+	{
282
+		if (empty(AllowedTags::$allowed_with_script_and_style_tags)) {
283
+			AllowedTags::initializeWithScriptAndStyleTags();
284
+		}
285
+		return AllowedTags::$allowed_with_script_and_style_tags;
286
+	}
287
+
288
+
289
+	/**
290
+	 * @return array[]
291
+	 */
292
+	public static function getWithFullTags()
293
+	{
294
+		if (empty(AllowedTags::$allowed_with_full_tags)) {
295
+			AllowedTags::initializeWithFullTags();
296
+		}
297
+		return AllowedTags::$allowed_with_full_tags;
298
+	}
299 299
 }
Please login to merge, or discard this patch.
core/services/request/ServerParams.php 2 patches
Indentation   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -6,203 +6,203 @@
 block discarded – undo
6 6
 
7 7
 class ServerParams
8 8
 {
9
-    /**
10
-     * IP address for request
11
-     *
12
-     * @var string
13
-     */
14
-    protected $ip_address;
15
-
16
-
17
-    /**
18
-     * @var ServerSanitizer
19
-     */
20
-    protected $sanitizer;
21
-
22
-    /**
23
-     * sanitized $_SERVER parameters
24
-     *
25
-     * @var array
26
-     */
27
-    protected $server;
28
-
29
-    /**
30
-     * @var string
31
-     */
32
-    protected $request_uri;
33
-
34
-    /**
35
-     * @var string
36
-     */
37
-    protected $user_agent;
38
-
39
-
40
-    /**
41
-     * ServerParams constructor.
42
-     *
43
-     * @param ServerSanitizer $sanitizer
44
-     * @param array           $server
45
-     */
46
-    public function __construct(ServerSanitizer $sanitizer, array $server = [])
47
-    {
48
-        $this->sanitizer  = $sanitizer;
49
-        $this->server     = $this->cleanServerParams($server);
50
-        $this->ip_address = $this->setVisitorIp();
51
-    }
52
-
53
-
54
-    /**
55
-     * @return array
56
-     */
57
-    private function cleanServerParams(array $server)
58
-    {
59
-        $cleaned = [];
60
-        foreach ($server as $key => $value) {
61
-            $cleaned[ $key ] = $this->sanitizer->clean($key, $value);
62
-        }
63
-        return $cleaned;
64
-    }
65
-
66
-
67
-    /**
68
-     * @return array
69
-     */
70
-    public function getAllServerParams()
71
-    {
72
-        return $this->server;
73
-    }
74
-
75
-
76
-    /**
77
-     * @param string $key
78
-     * @param mixed|null $default
79
-     * @return array|int|float|string
80
-     */
81
-    public function getServerParam($key, $default = null)
82
-    {
83
-        return $this->serverParamIsSet($key) ? $this->server[ $key ] : $default;
84
-    }
85
-
86
-
87
-    /**
88
-     * @param string                 $key
89
-     * @param array|int|float|string $value
90
-     * @return void
91
-     */
92
-    public function setServerParam($key, $value)
93
-    {
94
-        $clean_value = $this->sanitizer->clean($key, $value);
95
-        $this->server[ $key ] = $clean_value;
96
-        // modify global too
97
-        $_SERVER[ $key ] = $clean_value;
98
-    }
99
-
100
-
101
-    /**
102
-     * @return bool
103
-     */
104
-    public function serverParamIsSet($key)
105
-    {
106
-        return isset($this->server[ $key ]);
107
-    }
108
-
109
-
110
-    /**
111
-     * remove param
112
-     *
113
-     * @param string $key
114
-     * @param bool   $unset_from_global_too
115
-     */
116
-    public function unSetServerParam($key, $unset_from_global_too = false)
117
-    {
118
-        // because unset may not actually remove var
119
-        $this->server[ $key ] = null;
120
-        unset($this->server[ $key ]);
121
-        if ($unset_from_global_too) {
122
-            unset($_SERVER[ $key ]);
123
-        }
124
-    }
125
-
126
-
127
-    /**
128
-     * @return string
129
-     */
130
-    public function ipAddress()
131
-    {
132
-        return $this->ip_address;
133
-    }
134
-
135
-
136
-    /**
137
-     * attempt to get IP address of current visitor from server
138
-     * plz see: http://stackoverflow.com/a/2031935/1475279
139
-     *
140
-     * @access public
141
-     * @return string
142
-     */
143
-    private function setVisitorIp()
144
-    {
145
-        $visitor_ip  = '0.0.0.0';
146
-        $server_keys = [
147
-            'HTTP_CLIENT_IP',
148
-            'HTTP_FORWARDED',
149
-            'HTTP_FORWARDED_FOR',
150
-            'HTTP_X_CLUSTER_CLIENT_IP',
151
-            'HTTP_X_FORWARDED',
152
-            'HTTP_X_FORWARDED_FOR',
153
-            'REMOTE_ADDR',
154
-        ];
155
-        foreach ($server_keys as $key) {
156
-            if (isset($this->server[ $key ])) {
157
-                $potential_ip = array_map('trim', explode(',', $this->server[ $key ]));
158
-                foreach ($potential_ip as $ip) {
159
-                    if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
160
-                        $visitor_ip = $ip;
161
-                    }
162
-                }
163
-            }
164
-        }
165
-        return $visitor_ip;
166
-    }
167
-
168
-
169
-    /**
170
-     * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison.
171
-     *
172
-     * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to
173
-     *                                  "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return
174
-     *                                  "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/".
175
-     * @return string
176
-     */
177
-    public function requestUri($relativeToWpRoot = false)
178
-    {
179
-        if ($relativeToWpRoot) {
180
-            $home_path = untrailingslashit(parse_url(home_url(), PHP_URL_PATH));
181
-            return str_replace($home_path, '', $this->server['REQUEST_URI']);
182
-        }
183
-        return $this->server['REQUEST_URI'];
184
-    }
185
-
186
-
187
-    /**
188
-     * @return string
189
-     */
190
-    public function userAgent()
191
-    {
192
-        if (empty($this->user_agent)) {
193
-            $this->setUserAgent();
194
-        }
195
-        return $this->user_agent;
196
-    }
197
-
198
-
199
-    /**
200
-     * @param string $user_agent
201
-     */
202
-    public function setUserAgent($user_agent = '')
203
-    {
204
-        $this->user_agent = $user_agent === '' || ! is_string($user_agent)
205
-            ? $this->getServerParam('HTTP_USER_AGENT')
206
-            : esc_attr($user_agent);
207
-    }
9
+	/**
10
+	 * IP address for request
11
+	 *
12
+	 * @var string
13
+	 */
14
+	protected $ip_address;
15
+
16
+
17
+	/**
18
+	 * @var ServerSanitizer
19
+	 */
20
+	protected $sanitizer;
21
+
22
+	/**
23
+	 * sanitized $_SERVER parameters
24
+	 *
25
+	 * @var array
26
+	 */
27
+	protected $server;
28
+
29
+	/**
30
+	 * @var string
31
+	 */
32
+	protected $request_uri;
33
+
34
+	/**
35
+	 * @var string
36
+	 */
37
+	protected $user_agent;
38
+
39
+
40
+	/**
41
+	 * ServerParams constructor.
42
+	 *
43
+	 * @param ServerSanitizer $sanitizer
44
+	 * @param array           $server
45
+	 */
46
+	public function __construct(ServerSanitizer $sanitizer, array $server = [])
47
+	{
48
+		$this->sanitizer  = $sanitizer;
49
+		$this->server     = $this->cleanServerParams($server);
50
+		$this->ip_address = $this->setVisitorIp();
51
+	}
52
+
53
+
54
+	/**
55
+	 * @return array
56
+	 */
57
+	private function cleanServerParams(array $server)
58
+	{
59
+		$cleaned = [];
60
+		foreach ($server as $key => $value) {
61
+			$cleaned[ $key ] = $this->sanitizer->clean($key, $value);
62
+		}
63
+		return $cleaned;
64
+	}
65
+
66
+
67
+	/**
68
+	 * @return array
69
+	 */
70
+	public function getAllServerParams()
71
+	{
72
+		return $this->server;
73
+	}
74
+
75
+
76
+	/**
77
+	 * @param string $key
78
+	 * @param mixed|null $default
79
+	 * @return array|int|float|string
80
+	 */
81
+	public function getServerParam($key, $default = null)
82
+	{
83
+		return $this->serverParamIsSet($key) ? $this->server[ $key ] : $default;
84
+	}
85
+
86
+
87
+	/**
88
+	 * @param string                 $key
89
+	 * @param array|int|float|string $value
90
+	 * @return void
91
+	 */
92
+	public function setServerParam($key, $value)
93
+	{
94
+		$clean_value = $this->sanitizer->clean($key, $value);
95
+		$this->server[ $key ] = $clean_value;
96
+		// modify global too
97
+		$_SERVER[ $key ] = $clean_value;
98
+	}
99
+
100
+
101
+	/**
102
+	 * @return bool
103
+	 */
104
+	public function serverParamIsSet($key)
105
+	{
106
+		return isset($this->server[ $key ]);
107
+	}
108
+
109
+
110
+	/**
111
+	 * remove param
112
+	 *
113
+	 * @param string $key
114
+	 * @param bool   $unset_from_global_too
115
+	 */
116
+	public function unSetServerParam($key, $unset_from_global_too = false)
117
+	{
118
+		// because unset may not actually remove var
119
+		$this->server[ $key ] = null;
120
+		unset($this->server[ $key ]);
121
+		if ($unset_from_global_too) {
122
+			unset($_SERVER[ $key ]);
123
+		}
124
+	}
125
+
126
+
127
+	/**
128
+	 * @return string
129
+	 */
130
+	public function ipAddress()
131
+	{
132
+		return $this->ip_address;
133
+	}
134
+
135
+
136
+	/**
137
+	 * attempt to get IP address of current visitor from server
138
+	 * plz see: http://stackoverflow.com/a/2031935/1475279
139
+	 *
140
+	 * @access public
141
+	 * @return string
142
+	 */
143
+	private function setVisitorIp()
144
+	{
145
+		$visitor_ip  = '0.0.0.0';
146
+		$server_keys = [
147
+			'HTTP_CLIENT_IP',
148
+			'HTTP_FORWARDED',
149
+			'HTTP_FORWARDED_FOR',
150
+			'HTTP_X_CLUSTER_CLIENT_IP',
151
+			'HTTP_X_FORWARDED',
152
+			'HTTP_X_FORWARDED_FOR',
153
+			'REMOTE_ADDR',
154
+		];
155
+		foreach ($server_keys as $key) {
156
+			if (isset($this->server[ $key ])) {
157
+				$potential_ip = array_map('trim', explode(',', $this->server[ $key ]));
158
+				foreach ($potential_ip as $ip) {
159
+					if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
160
+						$visitor_ip = $ip;
161
+					}
162
+				}
163
+			}
164
+		}
165
+		return $visitor_ip;
166
+	}
167
+
168
+
169
+	/**
170
+	 * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison.
171
+	 *
172
+	 * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to
173
+	 *                                  "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return
174
+	 *                                  "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/".
175
+	 * @return string
176
+	 */
177
+	public function requestUri($relativeToWpRoot = false)
178
+	{
179
+		if ($relativeToWpRoot) {
180
+			$home_path = untrailingslashit(parse_url(home_url(), PHP_URL_PATH));
181
+			return str_replace($home_path, '', $this->server['REQUEST_URI']);
182
+		}
183
+		return $this->server['REQUEST_URI'];
184
+	}
185
+
186
+
187
+	/**
188
+	 * @return string
189
+	 */
190
+	public function userAgent()
191
+	{
192
+		if (empty($this->user_agent)) {
193
+			$this->setUserAgent();
194
+		}
195
+		return $this->user_agent;
196
+	}
197
+
198
+
199
+	/**
200
+	 * @param string $user_agent
201
+	 */
202
+	public function setUserAgent($user_agent = '')
203
+	{
204
+		$this->user_agent = $user_agent === '' || ! is_string($user_agent)
205
+			? $this->getServerParam('HTTP_USER_AGENT')
206
+			: esc_attr($user_agent);
207
+	}
208 208
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
     {
59 59
         $cleaned = [];
60 60
         foreach ($server as $key => $value) {
61
-            $cleaned[ $key ] = $this->sanitizer->clean($key, $value);
61
+            $cleaned[$key] = $this->sanitizer->clean($key, $value);
62 62
         }
63 63
         return $cleaned;
64 64
     }
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      */
81 81
     public function getServerParam($key, $default = null)
82 82
     {
83
-        return $this->serverParamIsSet($key) ? $this->server[ $key ] : $default;
83
+        return $this->serverParamIsSet($key) ? $this->server[$key] : $default;
84 84
     }
85 85
 
86 86
 
@@ -92,9 +92,9 @@  discard block
 block discarded – undo
92 92
     public function setServerParam($key, $value)
93 93
     {
94 94
         $clean_value = $this->sanitizer->clean($key, $value);
95
-        $this->server[ $key ] = $clean_value;
95
+        $this->server[$key] = $clean_value;
96 96
         // modify global too
97
-        $_SERVER[ $key ] = $clean_value;
97
+        $_SERVER[$key] = $clean_value;
98 98
     }
99 99
 
100 100
 
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
      */
104 104
     public function serverParamIsSet($key)
105 105
     {
106
-        return isset($this->server[ $key ]);
106
+        return isset($this->server[$key]);
107 107
     }
108 108
 
109 109
 
@@ -116,10 +116,10 @@  discard block
 block discarded – undo
116 116
     public function unSetServerParam($key, $unset_from_global_too = false)
117 117
     {
118 118
         // because unset may not actually remove var
119
-        $this->server[ $key ] = null;
120
-        unset($this->server[ $key ]);
119
+        $this->server[$key] = null;
120
+        unset($this->server[$key]);
121 121
         if ($unset_from_global_too) {
122
-            unset($_SERVER[ $key ]);
122
+            unset($_SERVER[$key]);
123 123
         }
124 124
     }
125 125
 
@@ -153,8 +153,8 @@  discard block
 block discarded – undo
153 153
             'REMOTE_ADDR',
154 154
         ];
155 155
         foreach ($server_keys as $key) {
156
-            if (isset($this->server[ $key ])) {
157
-                $potential_ip = array_map('trim', explode(',', $this->server[ $key ]));
156
+            if (isset($this->server[$key])) {
157
+                $potential_ip = array_map('trim', explode(',', $this->server[$key]));
158 158
                 foreach ($potential_ip as $ip) {
159 159
                     if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
160 160
                         $visitor_ip = $ip;
Please login to merge, or discard this patch.
core/services/bootstrap/BootstrapRequestResponseObjects.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -28,84 +28,84 @@
 block discarded – undo
28 28
  */
29 29
 class BootstrapRequestResponseObjects
30 30
 {
31
-    /**
32
-     * @type LegacyRequestInterface $legacy_request
33
-     */
34
-    protected $legacy_request;
31
+	/**
32
+	 * @type LegacyRequestInterface $legacy_request
33
+	 */
34
+	protected $legacy_request;
35 35
 
36
-    /**
37
-     * @type LoaderInterface $loader
38
-     */
39
-    protected $loader;
36
+	/**
37
+	 * @type LoaderInterface $loader
38
+	 */
39
+	protected $loader;
40 40
 
41
-    /**
42
-     * @var RequestInterface $request
43
-     */
44
-    protected $request;
41
+	/**
42
+	 * @var RequestInterface $request
43
+	 */
44
+	protected $request;
45 45
 
46
-    /**
47
-     * @var ResponseInterface $response
48
-     */
49
-    protected $response;
46
+	/**
47
+	 * @var ResponseInterface $response
48
+	 */
49
+	protected $response;
50 50
 
51 51
 
52
-    /**
53
-     * BootstrapRequestResponseObjects constructor.
54
-     *
55
-     * @param LoaderInterface $loader
56
-     */
57
-    public function __construct(LoaderInterface $loader)
58
-    {
59
-        $this->loader = $loader;
60
-    }
52
+	/**
53
+	 * BootstrapRequestResponseObjects constructor.
54
+	 *
55
+	 * @param LoaderInterface $loader
56
+	 */
57
+	public function __construct(LoaderInterface $loader)
58
+	{
59
+		$this->loader = $loader;
60
+	}
61 61
 
62 62
 
63
-    /**
64
-     * @return void
65
-     */
66
-    public function buildRequestResponse()
67
-    {
68
-        $request_params = new RequestParams(new RequestSanitizer(), $_GET, $_POST);
69
-        $server_params = new ServerParams(new ServerSanitizer(), $_SERVER);
70
-        // load our Request and Response objects
71
-        $this->request = new Request($request_params, $server_params);
72
-        $this->response = new Response();
73
-        $this->loader->share(RequestParams::class, $request_params);
74
-        $this->loader->share(ServerParams::class, $server_params);
75
-    }
63
+	/**
64
+	 * @return void
65
+	 */
66
+	public function buildRequestResponse()
67
+	{
68
+		$request_params = new RequestParams(new RequestSanitizer(), $_GET, $_POST);
69
+		$server_params = new ServerParams(new ServerSanitizer(), $_SERVER);
70
+		// load our Request and Response objects
71
+		$this->request = new Request($request_params, $server_params);
72
+		$this->response = new Response();
73
+		$this->loader->share(RequestParams::class, $request_params);
74
+		$this->loader->share(ServerParams::class, $server_params);
75
+	}
76 76
 
77 77
 
78
-    /**
79
-     * @return void
80
-     * @throws InvalidArgumentException
81
-     */
82
-    public function shareRequestResponse()
83
-    {
84
-        $this->loader->share('EventEspresso\core\services\request\Request', $this->request);
85
-        $this->loader->share('EventEspresso\core\services\request\Response', $this->response);
86
-        EE_Dependency_Map::instance()->setRequest($this->request);
87
-        EE_Dependency_Map::instance()->setResponse($this->response);
88
-    }
78
+	/**
79
+	 * @return void
80
+	 * @throws InvalidArgumentException
81
+	 */
82
+	public function shareRequestResponse()
83
+	{
84
+		$this->loader->share('EventEspresso\core\services\request\Request', $this->request);
85
+		$this->loader->share('EventEspresso\core\services\request\Response', $this->response);
86
+		EE_Dependency_Map::instance()->setRequest($this->request);
87
+		EE_Dependency_Map::instance()->setResponse($this->response);
88
+	}
89 89
 
90 90
 
91
-    /**
92
-     * @return void
93
-     * @throws InvalidArgumentException
94
-     * @throws EE_Error
95
-     */
96
-    public function setupLegacyRequest()
97
-    {
98
-        espresso_load_required(
99
-            'EE_Request',
100
-            EE_CORE . 'request_stack/EE_Request.core.php'
101
-        );
102
-        $this->legacy_request = new EE_Request($_GET, $_POST, $_COOKIE, $_SERVER);
103
-        $this->legacy_request->setRequest($this->request);
104
-        $this->legacy_request->admin = $this->request->isAdmin();
105
-        $this->legacy_request->ajax = $this->request->isAjax();
106
-        $this->legacy_request->front_ajax = $this->request->isFrontAjax();
107
-        EE_Dependency_Map::instance()->setLegacyRequest($this->legacy_request);
108
-        $this->loader->share('EE_Request', $this->legacy_request);
109
-        $this->loader->share('EventEspresso\core\services\request\LegacyRequestInterface', $this->legacy_request);
110
-    }
91
+	/**
92
+	 * @return void
93
+	 * @throws InvalidArgumentException
94
+	 * @throws EE_Error
95
+	 */
96
+	public function setupLegacyRequest()
97
+	{
98
+		espresso_load_required(
99
+			'EE_Request',
100
+			EE_CORE . 'request_stack/EE_Request.core.php'
101
+		);
102
+		$this->legacy_request = new EE_Request($_GET, $_POST, $_COOKIE, $_SERVER);
103
+		$this->legacy_request->setRequest($this->request);
104
+		$this->legacy_request->admin = $this->request->isAdmin();
105
+		$this->legacy_request->ajax = $this->request->isAjax();
106
+		$this->legacy_request->front_ajax = $this->request->isFrontAjax();
107
+		EE_Dependency_Map::instance()->setLegacyRequest($this->legacy_request);
108
+		$this->loader->share('EE_Request', $this->legacy_request);
109
+		$this->loader->share('EventEspresso\core\services\request\LegacyRequestInterface', $this->legacy_request);
110
+	}
111 111
 }
Please login to merge, or discard this patch.