Completed
Branch master (c5fa03)
by
unknown
10:39 queued 08:42
created
caffeinated/modules/events_archive_caff/EED_Events_Archive_Caff.module.php 1 patch
Indentation   +249 added lines, -249 removed lines patch added patch discarded remove patch
@@ -14,268 +14,268 @@
 block discarded – undo
14 14
 class EED_Events_Archive_Caff extends EED_Events_Archive
15 15
 {
16 16
 
17
-    /**
18
-     * @return EED_Events_Archive_Caff|EED_Module
19
-     */
20
-    public static function instance()
21
-    {
22
-        return parent::get_instance(__CLASS__);
23
-    }
17
+	/**
18
+	 * @return EED_Events_Archive_Caff|EED_Module
19
+	 */
20
+	public static function instance()
21
+	{
22
+		return parent::get_instance(__CLASS__);
23
+	}
24 24
 
25 25
 
26
-    /**
27
-     * set_hooks - for hooking into EE Core, other modules, etc
28
-     *
29
-     * @return    void
30
-     */
31
-    public static function set_hooks()
32
-    {
33
-    }
26
+	/**
27
+	 * set_hooks - for hooking into EE Core, other modules, etc
28
+	 *
29
+	 * @return    void
30
+	 */
31
+	public static function set_hooks()
32
+	{
33
+	}
34 34
 
35
-    /**
36
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
37
-     *
38
-     * @access    public
39
-     * @return    void
40
-     */
41
-    public static function set_hooks_admin()
42
-    {
43
-        self::setDefinitions();
44
-        add_action(
45
-            'AHEE__template_settings__template__before_settings_form',
46
-            array('EED_Events_Archive_Caff', 'template_settings_form'),
47
-            10
48
-        );
49
-        add_filter(
50
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
51
-            array('EED_Events_Archive_Caff', 'update_template_settings'),
52
-            10,
53
-            2
54
-        );
55
-        // AJAX
56
-        add_action(
57
-            'wp_ajax_espresso_update_event_archive_order',
58
-            array('EED_Events_Archive_Caff', 'update_event_archive_order')
59
-        );
60
-        add_action(
61
-            'wp_ajax_nopriv_espresso_update_event_archive_order',
62
-            array('EED_Events_Archive_Caff', 'update_event_archive_order')
63
-        );
64
-    }
35
+	/**
36
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
37
+	 *
38
+	 * @access    public
39
+	 * @return    void
40
+	 */
41
+	public static function set_hooks_admin()
42
+	{
43
+		self::setDefinitions();
44
+		add_action(
45
+			'AHEE__template_settings__template__before_settings_form',
46
+			array('EED_Events_Archive_Caff', 'template_settings_form'),
47
+			10
48
+		);
49
+		add_filter(
50
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
51
+			array('EED_Events_Archive_Caff', 'update_template_settings'),
52
+			10,
53
+			2
54
+		);
55
+		// AJAX
56
+		add_action(
57
+			'wp_ajax_espresso_update_event_archive_order',
58
+			array('EED_Events_Archive_Caff', 'update_event_archive_order')
59
+		);
60
+		add_action(
61
+			'wp_ajax_nopriv_espresso_update_event_archive_order',
62
+			array('EED_Events_Archive_Caff', 'update_event_archive_order')
63
+		);
64
+	}
65 65
 
66 66
 
67
-    /**
68
-     * run - initial module setup
69
-     *
70
-     * @param    WP $WP
71
-     * @return    void
72
-     */
73
-    public function run($WP)
74
-    {
75
-    }
67
+	/**
68
+	 * run - initial module setup
69
+	 *
70
+	 * @param    WP $WP
71
+	 * @return    void
72
+	 */
73
+	public function run($WP)
74
+	{
75
+	}
76 76
 
77 77
 
78
-    /**
79
-     * Conditionally set constants if they haven't been defined yet.
80
-     */
81
-    public static function setDefinitions()
82
-    {
83
-        if (! defined('EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH')) {
84
-            define(
85
-                'EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH',
86
-                str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates/'
87
-            );
88
-            define('EVENT_ARCHIVE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
89
-        }
90
-    }
78
+	/**
79
+	 * Conditionally set constants if they haven't been defined yet.
80
+	 */
81
+	public static function setDefinitions()
82
+	{
83
+		if (! defined('EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH')) {
84
+			define(
85
+				'EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH',
86
+				str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates/'
87
+			);
88
+			define('EVENT_ARCHIVE_CAFF_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
89
+		}
90
+	}
91 91
 
92 92
 
93
-    /**
94
-     * @return void
95
-     * @throws DomainException
96
-     * @throws InvalidArgumentException
97
-     * @throws InvalidDataTypeException
98
-     * @throws InvalidInterfaceException
99
-     */
100
-    public static function template_settings_form()
101
-    {
102
-        /** @var EE_Admin_Page_Loader $admin_page_loader */
103
-        $admin_page_loader = LoaderFactory::getLoader()->getShared('EE_Admin_Page_Loader');
104
-        // grab general settings admin page and remove the existing hook callback
105
-        $gen_set_admin = $admin_page_loader->get_admin_page_object('general_settings');
106
-        if ($gen_set_admin instanceof General_Settings_Admin_Page) {
107
-            remove_action(
108
-                'AHEE__template_settings__template__before_settings_form',
109
-                array($gen_set_admin, 'template_settings_caff_features'),
110
-                100
111
-            );
112
-        }
113
-        // first just grab the template settings
114
-        $config = EE_Registry::instance()->CFG->template_settings;
115
-        // then if the Event Archive config is valid, use that, else create a new one
116
-        $config = $config instanceof EE_Template_Config
117
-                  && $config->EED_Events_Archive instanceof EE_Events_Archive_Config
118
-            ? $config->EED_Events_Archive
119
-            : new EE_Events_Archive_Config();
120
-        $config = apply_filters(
121
-            'FHEE__EED_Events_Archive__template_settings_form__event_list_config',
122
-            $config
123
-        );
124
-        $config->display_status_banner = isset($config->display_status_banner)
125
-            ? $config->display_status_banner
126
-            : 0;
127
-        $config->display_description = isset($config->display_description)
128
-            ? $config->display_description
129
-            : 1;
130
-        $config->display_ticket_selector = isset($config->display_ticket_selector)
131
-            ? $config->display_ticket_selector
132
-            : 0;
133
-        $config->display_datetimes = isset($config->display_datetimes)
134
-            ? $config->display_datetimes
135
-            : 1;
136
-        $config->display_venue = isset($config->display_venue)
137
-            ? $config->display_venue
138
-            : 0;
139
-        $config->display_expired_events = isset($config->display_expired_events)
140
-            ? $config->display_expired_events
141
-            : 0;
142
-        // display order options
143
-        $config->use_sortable_display_order = isset($config->use_sortable_display_order)
144
-            ? $config->use_sortable_display_order
145
-            : false;
146
-        $config->display_order_tickets = isset($config->display_order_tickets)
147
-            ? $config->display_order_tickets
148
-            : 120;
149
-        $config->display_order_datetimes = isset($config->display_order_datetimes)
150
-            ? $config->display_order_datetimes
151
-            : 110;
152
-        $config->display_order_event = isset($config->display_order_event)
153
-            ? $config->display_order_event
154
-            : 100;
155
-        $config->display_order_venue = isset($config->display_order_venue)
156
-            ? $config->display_order_venue
157
-            : 130;
158
-        // get template parts
159
-        $template_parts = EED_Events_Archive::instance()->initialize_template_parts($config);
160
-        // convert to array so that we can add more properties
161
-        $config = get_object_vars($config);
162
-        $config['event_archive_display_order'] = $template_parts->generate_sortable_list_of_template_parts(
163
-            'event-archive-sortable-js',
164
-            '',
165
-            'archive-sortable-li archive-sortable-js'
166
-        );
167
-        EEH_Template::display_template(
168
-            EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH . 'admin-event-list-settings.template.php',
169
-            $config
170
-        );
171
-    }
93
+	/**
94
+	 * @return void
95
+	 * @throws DomainException
96
+	 * @throws InvalidArgumentException
97
+	 * @throws InvalidDataTypeException
98
+	 * @throws InvalidInterfaceException
99
+	 */
100
+	public static function template_settings_form()
101
+	{
102
+		/** @var EE_Admin_Page_Loader $admin_page_loader */
103
+		$admin_page_loader = LoaderFactory::getLoader()->getShared('EE_Admin_Page_Loader');
104
+		// grab general settings admin page and remove the existing hook callback
105
+		$gen_set_admin = $admin_page_loader->get_admin_page_object('general_settings');
106
+		if ($gen_set_admin instanceof General_Settings_Admin_Page) {
107
+			remove_action(
108
+				'AHEE__template_settings__template__before_settings_form',
109
+				array($gen_set_admin, 'template_settings_caff_features'),
110
+				100
111
+			);
112
+		}
113
+		// first just grab the template settings
114
+		$config = EE_Registry::instance()->CFG->template_settings;
115
+		// then if the Event Archive config is valid, use that, else create a new one
116
+		$config = $config instanceof EE_Template_Config
117
+				  && $config->EED_Events_Archive instanceof EE_Events_Archive_Config
118
+			? $config->EED_Events_Archive
119
+			: new EE_Events_Archive_Config();
120
+		$config = apply_filters(
121
+			'FHEE__EED_Events_Archive__template_settings_form__event_list_config',
122
+			$config
123
+		);
124
+		$config->display_status_banner = isset($config->display_status_banner)
125
+			? $config->display_status_banner
126
+			: 0;
127
+		$config->display_description = isset($config->display_description)
128
+			? $config->display_description
129
+			: 1;
130
+		$config->display_ticket_selector = isset($config->display_ticket_selector)
131
+			? $config->display_ticket_selector
132
+			: 0;
133
+		$config->display_datetimes = isset($config->display_datetimes)
134
+			? $config->display_datetimes
135
+			: 1;
136
+		$config->display_venue = isset($config->display_venue)
137
+			? $config->display_venue
138
+			: 0;
139
+		$config->display_expired_events = isset($config->display_expired_events)
140
+			? $config->display_expired_events
141
+			: 0;
142
+		// display order options
143
+		$config->use_sortable_display_order = isset($config->use_sortable_display_order)
144
+			? $config->use_sortable_display_order
145
+			: false;
146
+		$config->display_order_tickets = isset($config->display_order_tickets)
147
+			? $config->display_order_tickets
148
+			: 120;
149
+		$config->display_order_datetimes = isset($config->display_order_datetimes)
150
+			? $config->display_order_datetimes
151
+			: 110;
152
+		$config->display_order_event = isset($config->display_order_event)
153
+			? $config->display_order_event
154
+			: 100;
155
+		$config->display_order_venue = isset($config->display_order_venue)
156
+			? $config->display_order_venue
157
+			: 130;
158
+		// get template parts
159
+		$template_parts = EED_Events_Archive::instance()->initialize_template_parts($config);
160
+		// convert to array so that we can add more properties
161
+		$config = get_object_vars($config);
162
+		$config['event_archive_display_order'] = $template_parts->generate_sortable_list_of_template_parts(
163
+			'event-archive-sortable-js',
164
+			'',
165
+			'archive-sortable-li archive-sortable-js'
166
+		);
167
+		EEH_Template::display_template(
168
+			EVENTS_ARCHIVE_CAFF_TEMPLATES_PATH . 'admin-event-list-settings.template.php',
169
+			$config
170
+		);
171
+	}
172 172
 
173 173
 
174
-    /**
175
-     * @param EE_Template_Config $CFG
176
-     * @param array              $REQ
177
-     * @return EE_Template_Config
178
-     */
179
-    public static function update_template_settings($CFG, $REQ)
180
-    {
181
-        // unless we are resetting the config...
182
-        if (
183
-            ! isset($REQ['EED_Events_Archive_reset_event_list_settings'])
184
-            || absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1
185
-        ) {
186
-            /** @var EE_Events_Archive_Config $config */
187
-            $config = $CFG->EED_Events_Archive instanceof EE_Events_Archive_Config
188
-                ? $CFG->EED_Events_Archive
189
-                : new EE_Events_Archive_Config();
174
+	/**
175
+	 * @param EE_Template_Config $CFG
176
+	 * @param array              $REQ
177
+	 * @return EE_Template_Config
178
+	 */
179
+	public static function update_template_settings($CFG, $REQ)
180
+	{
181
+		// unless we are resetting the config...
182
+		if (
183
+			! isset($REQ['EED_Events_Archive_reset_event_list_settings'])
184
+			|| absint($REQ['EED_Events_Archive_reset_event_list_settings']) !== 1
185
+		) {
186
+			/** @var EE_Events_Archive_Config $config */
187
+			$config = $CFG->EED_Events_Archive instanceof EE_Events_Archive_Config
188
+				? $CFG->EED_Events_Archive
189
+				: new EE_Events_Archive_Config();
190 190
 
191
-            $config->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner'])
192
-                ? absint($REQ['EED_Events_Archive_display_status_banner'])
193
-                : 0;
194
-            $config->display_description = isset($REQ['EED_Events_Archive_display_description'])
195
-                ? absint($REQ['EED_Events_Archive_display_description'])
196
-                : 1;
197
-            $config->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector'])
198
-                ? absint($REQ['EED_Events_Archive_display_ticket_selector'])
199
-                : 0;
200
-            $config->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes'])
201
-                ? absint($REQ['EED_Events_Archive_display_datetimes'])
202
-                : 1;
203
-            $config->display_venue = isset($REQ['EED_Events_Archive_display_venue'])
204
-                ? absint($REQ['EED_Events_Archive_display_venue'])
205
-                : 0;
206
-            $config->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events'])
207
-                ? absint($REQ['EED_Events_Archive_display_expired_events'])
208
-                : 0;
209
-            $config->use_sortable_display_order = isset($REQ['EED_Events_Archive_use_sortable_display_order'])
210
-                ? absint($REQ['EED_Events_Archive_use_sortable_display_order'])
211
-                : 0;
212
-            $config->display_order_event = $config->display_order_event !== null
213
-                                           && $config->use_sortable_display_order
214
-                ? $config->display_order_event
215
-                : EED_Events_Archive::EVENT_DETAILS_PRIORITY;
216
-            $config->display_order_datetimes = $config->display_order_datetimes !== null
217
-                                               && $config->use_sortable_display_order
218
-                ? $config->display_order_datetimes
219
-                : EED_Events_Archive::EVENT_DATETIMES_PRIORITY;
220
-            $config->display_order_tickets = $config->display_order_tickets !== null
221
-                                             && $config->use_sortable_display_order
222
-                ? $config->display_order_tickets
223
-                : EED_Events_Archive::EVENT_TICKETS_PRIORITY;
224
-            $config->display_order_venue = $config->display_order_venue !== null
225
-                                           && $config->use_sortable_display_order
226
-                ? $config->display_order_venue
227
-                : EED_Events_Archive::EVENT_VENUES_PRIORITY;
228
-        } else {
229
-            $config = new EE_Events_Archive_Config();
230
-        }
191
+			$config->display_status_banner = isset($REQ['EED_Events_Archive_display_status_banner'])
192
+				? absint($REQ['EED_Events_Archive_display_status_banner'])
193
+				: 0;
194
+			$config->display_description = isset($REQ['EED_Events_Archive_display_description'])
195
+				? absint($REQ['EED_Events_Archive_display_description'])
196
+				: 1;
197
+			$config->display_ticket_selector = isset($REQ['EED_Events_Archive_display_ticket_selector'])
198
+				? absint($REQ['EED_Events_Archive_display_ticket_selector'])
199
+				: 0;
200
+			$config->display_datetimes = isset($REQ['EED_Events_Archive_display_datetimes'])
201
+				? absint($REQ['EED_Events_Archive_display_datetimes'])
202
+				: 1;
203
+			$config->display_venue = isset($REQ['EED_Events_Archive_display_venue'])
204
+				? absint($REQ['EED_Events_Archive_display_venue'])
205
+				: 0;
206
+			$config->display_expired_events = isset($REQ['EED_Events_Archive_display_expired_events'])
207
+				? absint($REQ['EED_Events_Archive_display_expired_events'])
208
+				: 0;
209
+			$config->use_sortable_display_order = isset($REQ['EED_Events_Archive_use_sortable_display_order'])
210
+				? absint($REQ['EED_Events_Archive_use_sortable_display_order'])
211
+				: 0;
212
+			$config->display_order_event = $config->display_order_event !== null
213
+										   && $config->use_sortable_display_order
214
+				? $config->display_order_event
215
+				: EED_Events_Archive::EVENT_DETAILS_PRIORITY;
216
+			$config->display_order_datetimes = $config->display_order_datetimes !== null
217
+											   && $config->use_sortable_display_order
218
+				? $config->display_order_datetimes
219
+				: EED_Events_Archive::EVENT_DATETIMES_PRIORITY;
220
+			$config->display_order_tickets = $config->display_order_tickets !== null
221
+											 && $config->use_sortable_display_order
222
+				? $config->display_order_tickets
223
+				: EED_Events_Archive::EVENT_TICKETS_PRIORITY;
224
+			$config->display_order_venue = $config->display_order_venue !== null
225
+										   && $config->use_sortable_display_order
226
+				? $config->display_order_venue
227
+				: EED_Events_Archive::EVENT_VENUES_PRIORITY;
228
+		} else {
229
+			$config = new EE_Events_Archive_Config();
230
+		}
231 231
 
232
-        $CFG->EED_Events_Archive = $config;
233
-        do_action('AHEE__EED_Events_Archive__update_template_settings__after_update', $CFG, $REQ);
234
-        return $CFG;
235
-    }
232
+		$CFG->EED_Events_Archive = $config;
233
+		do_action('AHEE__EED_Events_Archive__update_template_settings__after_update', $CFG, $REQ);
234
+		return $CFG;
235
+	}
236 236
 
237 237
 
238
-    /**
239
-     * @return void
240
-     * @throws InvalidArgumentException
241
-     * @throws InvalidDataTypeException
242
-     * @throws InvalidInterfaceException
243
-     */
244
-    public static function update_event_archive_order()
245
-    {
246
-        /** @var EE_Config $config */
247
-        $config = EE_Registry::instance()->CFG;
248
-        $config_saved = false;
249
-        $template_parts = EED_Events_Archive_Caff::getRequest()->getRequestParam('elements');
250
-        if (! empty($template_parts)) {
251
-            $template_parts = explode(',', trim($template_parts, ','));
252
-            foreach ($template_parts as $key => $template_part) {
253
-                $template_part = "display_order_$template_part";
254
-                $priority = ($key * 10) + EED_Events_Archive::EVENT_DETAILS_PRIORITY;
255
-                if (
256
-                    $config->template_settings->EED_Events_Archive instanceof EE_Events_Archive_Config
257
-                    && property_exists(
258
-                        $config->template_settings->EED_Events_Archive,
259
-                        $template_part
260
-                    )
261
-                ) {
262
-                    $config->template_settings->EED_Events_Archive->{$template_part} = $priority;
263
-                }
264
-                do_action("AHEE__EED_Events_Archive__update_event_archive_order__$template_part", $priority);
265
-            }
266
-            $config_saved = $config->update_espresso_config(false, false);
267
-        }
268
-        if ($config_saved) {
269
-            EE_Error::add_success(esc_html__('Display Order has been successfully updated.', 'event_espresso'));
270
-        } else {
271
-            EE_Error::add_error(
272
-                esc_html__('Display Order was not updated.', 'event_espresso'),
273
-                __FILE__,
274
-                __FUNCTION__,
275
-                __LINE__
276
-            );
277
-        }
278
-        echo wp_json_encode(EE_Error::get_notices(false));
279
-        exit();
280
-    }
238
+	/**
239
+	 * @return void
240
+	 * @throws InvalidArgumentException
241
+	 * @throws InvalidDataTypeException
242
+	 * @throws InvalidInterfaceException
243
+	 */
244
+	public static function update_event_archive_order()
245
+	{
246
+		/** @var EE_Config $config */
247
+		$config = EE_Registry::instance()->CFG;
248
+		$config_saved = false;
249
+		$template_parts = EED_Events_Archive_Caff::getRequest()->getRequestParam('elements');
250
+		if (! empty($template_parts)) {
251
+			$template_parts = explode(',', trim($template_parts, ','));
252
+			foreach ($template_parts as $key => $template_part) {
253
+				$template_part = "display_order_$template_part";
254
+				$priority = ($key * 10) + EED_Events_Archive::EVENT_DETAILS_PRIORITY;
255
+				if (
256
+					$config->template_settings->EED_Events_Archive instanceof EE_Events_Archive_Config
257
+					&& property_exists(
258
+						$config->template_settings->EED_Events_Archive,
259
+						$template_part
260
+					)
261
+				) {
262
+					$config->template_settings->EED_Events_Archive->{$template_part} = $priority;
263
+				}
264
+				do_action("AHEE__EED_Events_Archive__update_event_archive_order__$template_part", $priority);
265
+			}
266
+			$config_saved = $config->update_espresso_config(false, false);
267
+		}
268
+		if ($config_saved) {
269
+			EE_Error::add_success(esc_html__('Display Order has been successfully updated.', 'event_espresso'));
270
+		} else {
271
+			EE_Error::add_error(
272
+				esc_html__('Display Order was not updated.', 'event_espresso'),
273
+				__FILE__,
274
+				__FUNCTION__,
275
+				__LINE__
276
+			);
277
+		}
278
+		echo wp_json_encode(EE_Error::get_notices(false));
279
+		exit();
280
+	}
281 281
 }
Please login to merge, or discard this patch.
caffeinated/admin/extend/events/Extend_Events_Admin_Page.core.php 2 patches
Indentation   +1304 added lines, -1304 removed lines patch added patch discarded remove patch
@@ -14,1308 +14,1308 @@
 block discarded – undo
14 14
 {
15 15
 
16 16
 
17
-    /**
18
-     * Extend_Events_Admin_Page constructor.
19
-     *
20
-     * @param bool $routing
21
-     * @throws EE_Error
22
-     * @throws ReflectionException
23
-     */
24
-    public function __construct($routing = true)
25
-    {
26
-        parent::__construct($routing);
27
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
29
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
30
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
31
-        }
32
-    }
33
-
34
-
35
-    /**
36
-     * Sets routes.
37
-     *
38
-     * @throws EE_Error
39
-     */
40
-    protected function _extend_page_config()
41
-    {
42
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
43
-        // is there a evt_id in the request?
44
-        $EVT_ID             = $this->request->getRequestParam('EVT_ID', 0, 'int');
45
-        $EVT_ID             = $this->request->getRequestParam('post', $EVT_ID, 'int');
46
-        $TKT_ID             = $this->request->getRequestParam('TKT_ID', 0, 'int');
47
-        $new_page_routes    = [
48
-            'duplicate_event'          => [
49
-                'func'       => '_duplicate_event',
50
-                'capability' => 'ee_edit_event',
51
-                'obj_id'     => $EVT_ID,
52
-                'noheader'   => true,
53
-            ],
54
-            'ticket_list_table'        => [
55
-                'func'       => '_tickets_overview_list_table',
56
-                'capability' => 'ee_read_default_tickets',
57
-            ],
58
-            'trash_ticket'             => [
59
-                'func'       => '_trash_or_restore_ticket',
60
-                'capability' => 'ee_delete_default_ticket',
61
-                'obj_id'     => $TKT_ID,
62
-                'noheader'   => true,
63
-                'args'       => ['trash' => true],
64
-            ],
65
-            'trash_tickets'            => [
66
-                'func'       => '_trash_or_restore_ticket',
67
-                'capability' => 'ee_delete_default_tickets',
68
-                'noheader'   => true,
69
-                'args'       => ['trash' => true],
70
-            ],
71
-            'restore_ticket'           => [
72
-                'func'       => '_trash_or_restore_ticket',
73
-                'capability' => 'ee_delete_default_ticket',
74
-                'obj_id'     => $TKT_ID,
75
-                'noheader'   => true,
76
-            ],
77
-            'restore_tickets'          => [
78
-                'func'       => '_trash_or_restore_ticket',
79
-                'capability' => 'ee_delete_default_tickets',
80
-                'noheader'   => true,
81
-            ],
82
-            'delete_ticket'            => [
83
-                'func'       => '_delete_ticket',
84
-                'capability' => 'ee_delete_default_ticket',
85
-                'obj_id'     => $TKT_ID,
86
-                'noheader'   => true,
87
-            ],
88
-            'delete_tickets'           => [
89
-                'func'       => '_delete_ticket',
90
-                'capability' => 'ee_delete_default_tickets',
91
-                'noheader'   => true,
92
-            ],
93
-            'import_page'              => [
94
-                'func'       => '_import_page',
95
-                'capability' => 'import',
96
-            ],
97
-            'import'                   => [
98
-                'func'       => '_import_events',
99
-                'capability' => 'import',
100
-                'noheader'   => true,
101
-            ],
102
-            'import_events'            => [
103
-                'func'       => '_import_events',
104
-                'capability' => 'import',
105
-                'noheader'   => true,
106
-            ],
107
-            'export_events'            => [
108
-                'func'       => '_events_export',
109
-                'capability' => 'export',
110
-                'noheader'   => true,
111
-            ],
112
-            'export_categories'        => [
113
-                'func'       => '_categories_export',
114
-                'capability' => 'export',
115
-                'noheader'   => true,
116
-            ],
117
-            'sample_export_file'       => [
118
-                'func'       => '_sample_export_file',
119
-                'capability' => 'export',
120
-                'noheader'   => true,
121
-            ],
122
-            'update_template_settings' => [
123
-                'func'       => '_update_template_settings',
124
-                'capability' => 'manage_options',
125
-                'noheader'   => true,
126
-            ],
127
-        ];
128
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
129
-        // partial route/config override
130
-        $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
131
-        $this->_page_config['create_new']['metaboxes'][]  = '_premium_event_editor_meta_boxes';
132
-        $this->_page_config['create_new']['qtips'][]      = 'EE_Event_Editor_Tips';
133
-        $this->_page_config['edit']['qtips'][]            = 'EE_Event_Editor_Tips';
134
-        $this->_page_config['edit']['metaboxes'][]        = '_premium_event_editor_meta_boxes';
135
-        $this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
136
-        // add tickets tab but only if there are more than one default ticket!
137
-        $ticket_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
138
-            [['TKT_is_default' => 1]],
139
-            'TKT_ID',
140
-            true
141
-        );
142
-        if ($ticket_count > 1) {
143
-            $new_page_config = [
144
-                'ticket_list_table' => [
145
-                    'nav'           => [
146
-                        'label' => esc_html__('Default Tickets', 'event_espresso'),
147
-                        'order' => 60,
148
-                    ],
149
-                    'list_table'    => 'Tickets_List_Table',
150
-                    'require_nonce' => false,
151
-                ],
152
-            ];
153
-        }
154
-        // template settings
155
-        $new_page_config['template_settings'] = [
156
-            'nav'           => [
157
-                'label' => esc_html__('Templates', 'event_espresso'),
158
-                'order' => 30,
159
-            ],
160
-            'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
161
-            'help_tabs'     => [
162
-                'general_settings_templates_help_tab' => [
163
-                    'title'    => esc_html__('Templates', 'event_espresso'),
164
-                    'filename' => 'general_settings_templates',
165
-                ],
166
-            ],
167
-            // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
168
-            // 'help_tour'     => array('Templates_Help_Tour'),
169
-            'require_nonce' => false,
170
-        ];
171
-        $this->_page_config                   = array_merge($this->_page_config, $new_page_config);
172
-        // add filters and actions
173
-        // modifying _views
174
-        add_filter(
175
-            'FHEE_event_datetime_metabox_add_additional_date_time_template',
176
-            [$this, 'add_additional_datetime_button'],
177
-            10,
178
-            2
179
-        );
180
-        add_filter(
181
-            'FHEE_event_datetime_metabox_clone_button_template',
182
-            [$this, 'add_datetime_clone_button'],
183
-            10,
184
-            2
185
-        );
186
-        add_filter(
187
-            'FHEE_event_datetime_metabox_timezones_template',
188
-            [$this, 'datetime_timezones_template'],
189
-            10,
190
-            2
191
-        );
192
-        // filters for event list table
193
-        add_filter('FHEE__Extend_Events_Admin_List_Table__filters', [$this, 'list_table_filters'], 10, 2);
194
-        add_filter(
195
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
196
-            [$this, 'extra_list_table_actions'],
197
-            10,
198
-            2
199
-        );
200
-        // legend item
201
-        add_filter('FHEE__Events_Admin_Page___event_legend_items__items', [$this, 'additional_legend_items']);
202
-        add_action('admin_init', [$this, 'admin_init']);
203
-    }
204
-
205
-
206
-    /**
207
-     * admin_init
208
-     */
209
-    public function admin_init()
210
-    {
211
-        EE_Registry::$i18n_js_strings = array_merge(
212
-            EE_Registry::$i18n_js_strings,
213
-            [
214
-                'image_confirm'          => esc_html__(
215
-                    'Do you really want to delete this image? Please remember to update your event to complete the removal.',
216
-                    'event_espresso'
217
-                ),
218
-                'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
219
-                'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
220
-                'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
221
-                'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
222
-                'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
223
-            ]
224
-        );
225
-    }
226
-
227
-
228
-    /**
229
-     * Add per page screen options to the default ticket list table view.
230
-     */
231
-    protected function _add_screen_options_ticket_list_table()
232
-    {
233
-        $this->_per_page_screen_option();
234
-    }
235
-
236
-
237
-    /**
238
-     * @param string $return
239
-     * @param int    $id
240
-     * @param string $new_title
241
-     * @param string $new_slug
242
-     * @return string
243
-     */
244
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
245
-    {
246
-        $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
247
-        // make sure this is only when editing
248
-        if (! empty($id)) {
249
-            $href   = EE_Admin_Page::add_query_args_and_nonce(
250
-                ['action' => 'duplicate_event', 'EVT_ID' => $id],
251
-                $this->_admin_base_url
252
-            );
253
-            $title  = esc_attr__('Duplicate Event', 'event_espresso');
254
-            $return .= '<a href="'
255
-                       . $href
256
-                       . '" title="'
257
-                       . $title
258
-                       . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
259
-                       . $title
260
-                       . '</a>';
261
-        }
262
-        return $return;
263
-    }
264
-
265
-
266
-    /**
267
-     * Set the list table views for the default ticket list table view.
268
-     */
269
-    public function _set_list_table_views_ticket_list_table()
270
-    {
271
-        $this->_views = [
272
-            'all'     => [
273
-                'slug'        => 'all',
274
-                'label'       => esc_html__('All', 'event_espresso'),
275
-                'count'       => 0,
276
-                'bulk_action' => [
277
-                    'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
278
-                ],
279
-            ],
280
-            'trashed' => [
281
-                'slug'        => 'trashed',
282
-                'label'       => esc_html__('Trash', 'event_espresso'),
283
-                'count'       => 0,
284
-                'bulk_action' => [
285
-                    'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
286
-                    'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
287
-                ],
288
-            ],
289
-        ];
290
-    }
291
-
292
-
293
-    /**
294
-     * Enqueue scripts and styles for the event editor.
295
-     */
296
-    public function load_scripts_styles_edit()
297
-    {
298
-        wp_register_script(
299
-            'ee-event-editor-heartbeat',
300
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
301
-            ['ee_admin_js', 'heartbeat'],
302
-            EVENT_ESPRESSO_VERSION,
303
-            true
304
-        );
305
-        wp_enqueue_script('ee-accounting');
306
-        // styles
307
-        wp_enqueue_style('espresso-ui-theme');
308
-        wp_enqueue_script('event_editor_js');
309
-        wp_enqueue_script('ee-event-editor-heartbeat');
310
-    }
311
-
312
-
313
-    /**
314
-     * Returns template for the additional datetime.
315
-     *
316
-     * @param string $template
317
-     * @param array  $template_args
318
-     * @return string
319
-     * @throws DomainException
320
-     */
321
-    public function add_additional_datetime_button($template, $template_args)
322
-    {
323
-        return EEH_Template::display_template(
324
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
325
-            $template_args,
326
-            true
327
-        );
328
-    }
329
-
330
-
331
-    /**
332
-     * Returns the template for cloning a datetime.
333
-     *
334
-     * @param $template
335
-     * @param $template_args
336
-     * @return string
337
-     * @throws DomainException
338
-     */
339
-    public function add_datetime_clone_button($template, $template_args)
340
-    {
341
-        return EEH_Template::display_template(
342
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
343
-            $template_args,
344
-            true
345
-        );
346
-    }
347
-
348
-
349
-    /**
350
-     * Returns the template for datetime timezones.
351
-     *
352
-     * @param $template
353
-     * @param $template_args
354
-     * @return string
355
-     * @throws DomainException
356
-     */
357
-    public function datetime_timezones_template($template, $template_args)
358
-    {
359
-        return EEH_Template::display_template(
360
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
361
-            $template_args,
362
-            true
363
-        );
364
-    }
365
-
366
-
367
-    /**
368
-     * Sets the views for the default list table view.
369
-     *
370
-     * @throws EE_Error
371
-     */
372
-    protected function _set_list_table_views_default()
373
-    {
374
-        parent::_set_list_table_views_default();
375
-        $new_views    = [
376
-            'today' => [
377
-                'slug'        => 'today',
378
-                'label'       => esc_html__('Today', 'event_espresso'),
379
-                'count'       => $this->total_events_today(),
380
-                'bulk_action' => [
381
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
382
-                ],
383
-            ],
384
-            'month' => [
385
-                'slug'        => 'month',
386
-                'label'       => esc_html__('This Month', 'event_espresso'),
387
-                'count'       => $this->total_events_this_month(),
388
-                'bulk_action' => [
389
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
390
-                ],
391
-            ],
392
-        ];
393
-        $this->_views = array_merge($this->_views, $new_views);
394
-    }
395
-
396
-
397
-    /**
398
-     * Returns the extra action links for the default list table view.
399
-     *
400
-     * @param array    $action_links
401
-     * @param EE_Event $event
402
-     * @return array
403
-     * @throws EE_Error
404
-     * @throws ReflectionException
405
-     */
406
-    public function extra_list_table_actions(array $action_links, EE_Event $event)
407
-    {
408
-        if (
409
-            EE_Registry::instance()->CAP->current_user_can(
410
-                'ee_read_registrations',
411
-                'espresso_registrations_reports',
412
-                $event->ID()
413
-            )
414
-        ) {
415
-            $reports_query_args = [
416
-                'action' => 'reports',
417
-                'EVT_ID' => $event->ID(),
418
-            ];
419
-            $reports_link       = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
420
-            $action_links[]     = '<a href="'
421
-                                  . $reports_link
422
-                                  . '" title="'
423
-                                  . esc_attr__('View Report', 'event_espresso')
424
-                                  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
425
-                                  . "\n\t";
426
-        }
427
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
428
-            EE_Registry::instance()->load_helper('MSG_Template');
429
-            $action_links[] = EEH_MSG_Template::get_message_action_link(
430
-                'see_notifications_for',
431
-                null,
432
-                ['EVT_ID' => $event->ID()]
433
-            );
434
-        }
435
-        return $action_links;
436
-    }
437
-
438
-
439
-    /**
440
-     * @param $items
441
-     * @return mixed
442
-     */
443
-    public function additional_legend_items($items)
444
-    {
445
-        if (
446
-            EE_Registry::instance()->CAP->current_user_can(
447
-                'ee_read_registrations',
448
-                'espresso_registrations_reports'
449
-            )
450
-        ) {
451
-            $items['reports'] = [
452
-                'class' => 'dashicons dashicons-chart-bar',
453
-                'desc'  => esc_html__('Event Reports', 'event_espresso'),
454
-            ];
455
-        }
456
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
457
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
458
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
459
-                $items['view_related_messages'] = [
460
-                    'class' => $related_for_icon['css_class'],
461
-                    'desc'  => $related_for_icon['label'],
462
-                ];
463
-            }
464
-        }
465
-        return $items;
466
-    }
467
-
468
-
469
-    /**
470
-     * This is the callback method for the duplicate event route
471
-     * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
472
-     * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
473
-     * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
474
-     * After duplication the redirect is to the new event edit page.
475
-     *
476
-     * @return void
477
-     * @throws EE_Error If EE_Event is not available with given ID
478
-     * @throws ReflectionException
479
-     * @access protected
480
-     */
481
-    protected function _duplicate_event()
482
-    {
483
-        // first make sure the ID for the event is in the request.
484
-        //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
485
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
486
-        if (! $EVT_ID) {
487
-            EE_Error::add_error(
488
-                esc_html__(
489
-                    'In order to duplicate an event an Event ID is required.  None was given.',
490
-                    'event_espresso'
491
-                ),
492
-                __FILE__,
493
-                __FUNCTION__,
494
-                __LINE__
495
-            );
496
-            $this->_redirect_after_action(false, '', '', [], true);
497
-            return;
498
-        }
499
-        // k we've got EVT_ID so let's use that to get the event we'll duplicate
500
-        $orig_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
501
-        if (! $orig_event instanceof EE_Event) {
502
-            throw new EE_Error(
503
-                sprintf(
504
-                    esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
505
-                    $EVT_ID
506
-                )
507
-            );
508
-        }
509
-        // k now let's clone the $orig_event before getting relations
510
-        $new_event = clone $orig_event;
511
-        // original datetimes
512
-        $orig_datetimes = $orig_event->get_many_related('Datetime');
513
-        // other original relations
514
-        $orig_ven = $orig_event->get_many_related('Venue');
515
-        // reset the ID and modify other details to make it clear this is a dupe
516
-        $new_event->set('EVT_ID', 0);
517
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
518
-        $new_event->set('EVT_name', $new_name);
519
-        $new_event->set(
520
-            'EVT_slug',
521
-            wp_unique_post_slug(
522
-                sanitize_title($orig_event->name()),
523
-                0,
524
-                'publish',
525
-                'espresso_events',
526
-                0
527
-            )
528
-        );
529
-        $new_event->set('status', 'draft');
530
-        // duplicate discussion settings
531
-        $new_event->set('comment_status', $orig_event->get('comment_status'));
532
-        $new_event->set('ping_status', $orig_event->get('ping_status'));
533
-        // save the new event
534
-        $new_event->save();
535
-        // venues
536
-        foreach ($orig_ven as $ven) {
537
-            $new_event->_add_relation_to($ven, 'Venue');
538
-        }
539
-        $new_event->save();
540
-        // now we need to get the question group relations and handle that
541
-        // first primary question groups
542
-        $orig_primary_qgs = $orig_event->get_many_related(
543
-            'Question_Group',
544
-            [['Event_Question_Group.EQG_primary' => true]]
545
-        );
546
-        if (! empty($orig_primary_qgs)) {
547
-            foreach ($orig_primary_qgs as $obj) {
548
-                if ($obj instanceof EE_Question_Group) {
549
-                    $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]);
550
-                }
551
-            }
552
-        }
553
-        // next additional attendee question groups
554
-        $orig_additional_qgs = $orig_event->get_many_related(
555
-            'Question_Group',
556
-            [['Event_Question_Group.EQG_additional' => true]]
557
-        );
558
-        if (! empty($orig_additional_qgs)) {
559
-            foreach ($orig_additional_qgs as $obj) {
560
-                if ($obj instanceof EE_Question_Group) {
561
-                    $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]);
562
-                }
563
-            }
564
-        }
565
-
566
-        $new_event->save();
567
-
568
-        // k now that we have the new event saved we can loop through the datetimes and start adding relations.
569
-        $cloned_tickets = [];
570
-        foreach ($orig_datetimes as $orig_dtt) {
571
-            if (! $orig_dtt instanceof EE_Datetime) {
572
-                continue;
573
-            }
574
-            $new_dtt      = clone $orig_dtt;
575
-            $orig_tickets = $orig_dtt->tickets();
576
-            // save new dtt then add to event
577
-            $new_dtt->set('DTT_ID', 0);
578
-            $new_dtt->set('DTT_sold', 0);
579
-            $new_dtt->set_reserved(0);
580
-            $new_dtt->save();
581
-            $new_event->_add_relation_to($new_dtt, 'Datetime');
582
-            $new_event->save();
583
-            // now let's get the ticket relations setup.
584
-            foreach ((array) $orig_tickets as $orig_ticket) {
585
-                // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
586
-                if (! $orig_ticket instanceof EE_Ticket) {
587
-                    continue;
588
-                }
589
-                // is this ticket archived?  If it is then let's skip
590
-                if ($orig_ticket->get('TKT_deleted')) {
591
-                    continue;
592
-                }
593
-                // does this original ticket already exist in the clone_tickets cache?
594
-                //  If so we'll just use the new ticket from it.
595
-                if (isset($cloned_tickets[ $orig_ticket->ID() ])) {
596
-                    $new_ticket = $cloned_tickets[ $orig_ticket->ID() ];
597
-                } else {
598
-                    $new_ticket = clone $orig_ticket;
599
-                    // get relations on the $orig_ticket that we need to setup.
600
-                    $orig_prices = $orig_ticket->prices();
601
-                    $new_ticket->set('TKT_ID', 0);
602
-                    $new_ticket->set('TKT_sold', 0);
603
-                    $new_ticket->set('TKT_reserved', 0);
604
-                    $new_ticket->save(); // make sure new ticket has ID.
605
-                    // price relations on new ticket need to be setup.
606
-                    foreach ($orig_prices as $orig_price) {
607
-                        $new_price = clone $orig_price;
608
-                        $new_price->set('PRC_ID', 0);
609
-                        $new_price->save();
610
-                        $new_ticket->_add_relation_to($new_price, 'Price');
611
-                        $new_ticket->save();
612
-                    }
613
-
614
-                    do_action(
615
-                        'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
616
-                        $orig_ticket,
617
-                        $new_ticket,
618
-                        $orig_prices,
619
-                        $orig_event,
620
-                        $orig_dtt,
621
-                        $new_dtt
622
-                    );
623
-                }
624
-                // k now we can add the new ticket as a relation to the new datetime
625
-                // and make sure its added to our cached $cloned_tickets array
626
-                // for use with later datetimes that have the same ticket.
627
-                $new_dtt->_add_relation_to($new_ticket, 'Ticket');
628
-                $new_dtt->save();
629
-                $cloned_tickets[ $orig_ticket->ID() ] = $new_ticket;
630
-            }
631
-        }
632
-        // clone taxonomy information
633
-        $taxonomies_to_clone_with = apply_filters(
634
-            'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
635
-            ['espresso_event_categories', 'espresso_event_type', 'post_tag']
636
-        );
637
-        // get terms for original event (notice)
638
-        $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
639
-        // loop through terms and add them to new event.
640
-        foreach ($orig_terms as $term) {
641
-            wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
642
-        }
643
-
644
-        // duplicate other core WP_Post items for this event.
645
-        // post thumbnail (feature image).
646
-        $feature_image_id = get_post_thumbnail_id($orig_event->ID());
647
-        if ($feature_image_id) {
648
-            update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
649
-        }
650
-
651
-        // duplicate page_template setting
652
-        $page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
653
-        if ($page_template) {
654
-            update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
655
-        }
656
-
657
-        do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
658
-        // now let's redirect to the edit page for this duplicated event if we have a new event id.
659
-        if ($new_event->ID()) {
660
-            $redirect_args = [
661
-                'post'   => $new_event->ID(),
662
-                'action' => 'edit',
663
-            ];
664
-            EE_Error::add_success(
665
-                esc_html__(
666
-                    'Event successfully duplicated.  Please review the details below and make any necessary edits',
667
-                    'event_espresso'
668
-                )
669
-            );
670
-        } else {
671
-            $redirect_args = [
672
-                'action' => 'default',
673
-            ];
674
-            EE_Error::add_error(
675
-                esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
676
-                __FILE__,
677
-                __FUNCTION__,
678
-                __LINE__
679
-            );
680
-        }
681
-        $this->_redirect_after_action(false, '', '', $redirect_args, true);
682
-    }
683
-
684
-
685
-    /**
686
-     * Generates output for the import page.
687
-     *
688
-     * @throws EE_Error
689
-     */
690
-    protected function _import_page()
691
-    {
692
-        $title = esc_html__('Import', 'event_espresso');
693
-        $intro = esc_html__(
694
-            'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
695
-            'event_espresso'
696
-        );
697
-
698
-        $form_url = EVENTS_ADMIN_URL;
699
-        $action   = 'import_events';
700
-        $type     = 'csv';
701
-
702
-        $this->_template_args['form'] = EE_Import::instance()->upload_form(
703
-            $title,
704
-            $intro,
705
-            $form_url,
706
-            $action,
707
-            $type
708
-        );
709
-
710
-        $this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
711
-            ['action' => 'sample_export_file'],
712
-            $this->_admin_base_url
713
-        );
714
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
715
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
716
-            $this->_template_args,
717
-            true
718
-        );
719
-        $this->display_admin_page_with_sidebar();
720
-    }
721
-
722
-
723
-    /**
724
-     * _import_events
725
-     * This handles displaying the screen and running imports for importing events.
726
-     *
727
-     * @return void
728
-     * @throws EE_Error
729
-     */
730
-    protected function _import_events()
731
-    {
732
-        require_once(EE_CLASSES . 'EE_Import.class.php');
733
-        $success = EE_Import::instance()->import();
734
-        $this->_redirect_after_action(
735
-            $success,
736
-            esc_html__('Import File', 'event_espresso'),
737
-            'ran',
738
-            ['action' => 'import_page'],
739
-            true
740
-        );
741
-    }
742
-
743
-
744
-    /**
745
-     * _events_export
746
-     * Will export all (or just the given event) to a Excel compatible file.
747
-     *
748
-     * @access protected
749
-     * @return void
750
-     */
751
-    protected function _events_export()
752
-    {
753
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
754
-        $EVT_ID = $this->request->getRequestParam('EVT_IDs', $EVT_ID, 'int');
755
-        $this->request->mergeRequestParams(
756
-            [
757
-                'export' => 'report',
758
-                'action' => 'all_event_data',
759
-                'EVT_ID' => $EVT_ID,
760
-            ]
761
-        );
762
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
763
-            require_once(EE_CLASSES . 'EE_Export.class.php');
764
-            $EE_Export = EE_Export::instance($this->request->requestParams());
765
-            $EE_Export->export();
766
-        }
767
-    }
768
-
769
-
770
-    /**
771
-     * handle category exports()
772
-     *
773
-     * @return void
774
-     */
775
-    protected function _categories_export()
776
-    {
777
-        $EVT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
778
-        $this->request->mergeRequestParams(
779
-            [
780
-                'export' => 'report',
781
-                'action' => 'categories',
782
-                'EVT_ID' => $EVT_ID,
783
-            ]
784
-        );
785
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
786
-            require_once(EE_CLASSES . 'EE_Export.class.php');
787
-            $EE_Export = EE_Export::instance($this->request->requestParams());
788
-            $EE_Export->export();
789
-        }
790
-    }
791
-
792
-
793
-    /**
794
-     * Creates a sample CSV file for importing
795
-     */
796
-    protected function _sample_export_file()
797
-    {
798
-        // require_once(EE_CLASSES . 'EE_Export.class.php');
799
-        EE_Export::instance()->export_sample();
800
-    }
801
-
802
-
803
-    /*************        Template Settings        *************/
804
-    /**
805
-     * Generates template settings page output
806
-     *
807
-     * @throws DomainException
808
-     * @throws EE_Error
809
-     */
810
-    protected function _template_settings()
811
-    {
812
-        $this->_template_args['values'] = $this->_yes_no_values;
813
-        /**
814
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
815
-         * from General_Settings_Admin_Page to here.
816
-         */
817
-        $this->_template_args = apply_filters(
818
-            'FHEE__General_Settings_Admin_Page__template_settings__template_args',
819
-            $this->_template_args
820
-        );
821
-        $this->_set_add_edit_form_tags('update_template_settings');
822
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
823
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
824
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
825
-            $this->_template_args,
826
-            true
827
-        );
828
-        $this->display_admin_page_with_sidebar();
829
-    }
830
-
831
-
832
-    /**
833
-     * Handler for updating template settings.
834
-     *
835
-     * @throws EE_Error
836
-     */
837
-    protected function _update_template_settings()
838
-    {
839
-        /**
840
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
841
-         * from General_Settings_Admin_Page to here.
842
-         */
843
-        EE_Registry::instance()->CFG->template_settings = apply_filters(
844
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
845
-            EE_Registry::instance()->CFG->template_settings,
846
-            $this->request->requestParams()
847
-        );
848
-        // update custom post type slugs and detect if we need to flush rewrite rules
849
-        $old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
850
-
851
-        $event_cpt_slug = $this->request->getRequestParam('event_cpt_slug');
852
-
853
-        EE_Registry::instance()->CFG->core->event_cpt_slug = $event_cpt_slug
854
-            ? EE_Registry::instance()->CFG->core->event_cpt_slug
855
-            : EEH_URL::slugify($event_cpt_slug, 'events');
856
-
857
-        $what    = esc_html__('Template Settings', 'event_espresso');
858
-        $success = $this->_update_espresso_configuration(
859
-            $what,
860
-            EE_Registry::instance()->CFG->template_settings,
861
-            __FILE__,
862
-            __FUNCTION__,
863
-            __LINE__
864
-        );
865
-        if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
866
-            /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
867
-            $rewrite_rules = LoaderFactory::getLoader()->getShared(
868
-                'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
869
-            );
870
-            $rewrite_rules->flush();
871
-        }
872
-        $this->_redirect_after_action($success, $what, 'updated', ['action' => 'template_settings']);
873
-    }
874
-
875
-
876
-    /**
877
-     * _premium_event_editor_meta_boxes
878
-     * add all metaboxes related to the event_editor
879
-     *
880
-     * @access protected
881
-     * @return void
882
-     * @throws EE_Error
883
-     * @throws ReflectionException
884
-     */
885
-    protected function _premium_event_editor_meta_boxes()
886
-    {
887
-        $this->verify_cpt_object();
888
-        add_meta_box(
889
-            'espresso_event_editor_event_options',
890
-            esc_html__('Event Registration Options', 'event_espresso'),
891
-            [$this, 'registration_options_meta_box'],
892
-            $this->page_slug,
893
-            'side',
894
-            'core'
895
-        );
896
-    }
897
-
898
-
899
-    /**
900
-     * override caf metabox
901
-     *
902
-     * @return void
903
-     * @throws EE_Error
904
-     * @throws ReflectionException
905
-     */
906
-    public function registration_options_meta_box()
907
-    {
908
-        $yes_no_values = [
909
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
910
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
911
-        ];
912
-
913
-        $default_reg_status_values = EEM_Registration::reg_status_array(
914
-            [
915
-                EEM_Registration::status_id_cancelled,
916
-                EEM_Registration::status_id_declined,
917
-                EEM_Registration::status_id_incomplete,
918
-                EEM_Registration::status_id_wait_list,
919
-            ],
920
-            true
921
-        );
922
-
923
-        $template_args['active_status']    = $this->_cpt_model_obj->pretty_active_status(false);
924
-        $template_args['_event']           = $this->_cpt_model_obj;
925
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
926
-
927
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
928
-            'default_reg_status',
929
-            $default_reg_status_values,
930
-            $this->_cpt_model_obj->default_registration_status()
931
-        );
932
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
933
-            'display_desc',
934
-            $yes_no_values,
935
-            $this->_cpt_model_obj->display_description()
936
-        );
937
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
938
-            'display_ticket_selector',
939
-            $yes_no_values,
940
-            $this->_cpt_model_obj->display_ticket_selector(),
941
-            '',
942
-            '',
943
-            false
944
-        );
945
-        $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
946
-            'EVT_default_registration_status',
947
-            $default_reg_status_values,
948
-            $this->_cpt_model_obj->default_registration_status()
949
-        );
950
-        $template_args['additional_registration_options'] = apply_filters(
951
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
952
-            '',
953
-            $template_args,
954
-            $yes_no_values,
955
-            $default_reg_status_values
956
-        );
957
-        EEH_Template::display_template(
958
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
959
-            $template_args
960
-        );
961
-    }
962
-
963
-
964
-
965
-    /**
966
-     * wp_list_table_mods for caf
967
-     * ============================
968
-     */
969
-    /**
970
-     * hook into list table filters and provide filters for caffeinated list table
971
-     *
972
-     * @param array $old_filters    any existing filters present
973
-     * @param array $list_table_obj the list table object
974
-     * @return array                  new filters
975
-     * @throws EE_Error
976
-     * @throws ReflectionException
977
-     */
978
-    public function list_table_filters($old_filters, $list_table_obj)
979
-    {
980
-        $filters = [];
981
-        // first month/year filters
982
-        $filters[] = $this->espresso_event_months_dropdown();
983
-        $status    = $this->request->getRequestParam('status');
984
-        // active status dropdown
985
-        if ($status !== 'draft') {
986
-            $filters[] = $this->active_status_dropdown($this->request->getRequestParam('active_status'));
987
-            $filters[] = $this->venuesDropdown($this->request->getRequestParam('venue'));
988
-        }
989
-        // category filter
990
-        $filters[] = $this->category_dropdown();
991
-        return array_merge($old_filters, $filters);
992
-    }
993
-
994
-
995
-    /**
996
-     * espresso_event_months_dropdown
997
-     *
998
-     * @access public
999
-     * @return string                dropdown listing month/year selections for events.
1000
-     * @throws EE_Error
1001
-     */
1002
-    public function espresso_event_months_dropdown()
1003
-    {
1004
-        // what we need to do is get all PRIMARY datetimes for all events to filter on.
1005
-        // Note we need to include any other filters that are set!
1006
-        return EEH_Form_Fields::generate_event_months_dropdown(
1007
-            $this->request->getRequestParam('month_range'),
1008
-            $this->request->getRequestParam('status'),
1009
-            $this->request->getRequestParam('EVT_CAT', 0, 'int'),
1010
-            $this->request->getRequestParam('active_status')
1011
-        );
1012
-    }
1013
-
1014
-
1015
-    /**
1016
-     * returns a list of "active" statuses on the event
1017
-     *
1018
-     * @param string $current_value whatever the current active status is
1019
-     * @return string
1020
-     */
1021
-    public function active_status_dropdown($current_value = '')
1022
-    {
1023
-        $select_name = 'active_status';
1024
-        $values      = [
1025
-            'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1026
-            'active'   => esc_html__('Active', 'event_espresso'),
1027
-            'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1028
-            'expired'  => esc_html__('Expired', 'event_espresso'),
1029
-            'inactive' => esc_html__('Inactive', 'event_espresso'),
1030
-        ];
1031
-
1032
-        return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide');
1033
-    }
1034
-
1035
-
1036
-    /**
1037
-     * returns a list of "venues"
1038
-     *
1039
-     * @param string $current_value whatever the current active status is
1040
-     * @return string
1041
-     * @throws EE_Error
1042
-     * @throws ReflectionException
1043
-     */
1044
-    protected function venuesDropdown($current_value = '')
1045
-    {
1046
-        $values = [
1047
-            '' => esc_html__('All Venues', 'event_espresso'),
1048
-        ];
1049
-        // populate the list of venues.
1050
-        $venues = EEM_Venue::instance()->get_all(['order_by' => ['VNU_name' => 'ASC']]);
1051
-
1052
-        foreach ($venues as $venue) {
1053
-            $values[ $venue->ID() ] = $venue->name();
1054
-        }
1055
-
1056
-        return EEH_Form_Fields::select_input('venue', $values, $current_value, '', 'wide');
1057
-    }
1058
-
1059
-
1060
-    /**
1061
-     * output a dropdown of the categories for the category filter on the event admin list table
1062
-     *
1063
-     * @access  public
1064
-     * @return string html
1065
-     * @throws EE_Error
1066
-     * @throws ReflectionException
1067
-     */
1068
-    public function category_dropdown()
1069
-    {
1070
-        return EEH_Form_Fields::generate_event_category_dropdown(
1071
-            $this->request->getRequestParam('EVT_CAT', -1, 'int')
1072
-        );
1073
-    }
1074
-
1075
-
1076
-    /**
1077
-     * get total number of events today
1078
-     *
1079
-     * @access public
1080
-     * @return int
1081
-     * @throws EE_Error
1082
-     */
1083
-    public function total_events_today()
1084
-    {
1085
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1086
-            'DTT_EVT_start',
1087
-            date('Y-m-d') . ' 00:00:00',
1088
-            'Y-m-d H:i:s',
1089
-            'UTC'
1090
-        );
1091
-        $end   = EEM_Datetime::instance()->convert_datetime_for_query(
1092
-            'DTT_EVT_start',
1093
-            date('Y-m-d') . ' 23:59:59',
1094
-            'Y-m-d H:i:s',
1095
-            'UTC'
1096
-        );
1097
-        $where = [
1098
-            'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1099
-        ];
1100
-        return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1101
-    }
1102
-
1103
-
1104
-    /**
1105
-     * get total number of events this month
1106
-     *
1107
-     * @access public
1108
-     * @return int
1109
-     * @throws EE_Error
1110
-     */
1111
-    public function total_events_this_month()
1112
-    {
1113
-        // Dates
1114
-        $this_year_r     = date('Y');
1115
-        $this_month_r    = date('m');
1116
-        $days_this_month = date('t');
1117
-        $start           = EEM_Datetime::instance()->convert_datetime_for_query(
1118
-            'DTT_EVT_start',
1119
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1120
-            'Y-m-d H:i:s',
1121
-            'UTC'
1122
-        );
1123
-        $end             = EEM_Datetime::instance()->convert_datetime_for_query(
1124
-            'DTT_EVT_start',
1125
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1126
-            'Y-m-d H:i:s',
1127
-            'UTC'
1128
-        );
1129
-        $where           = [
1130
-            'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1131
-        ];
1132
-        return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1133
-    }
1134
-
1135
-
1136
-    /** DEFAULT TICKETS STUFF **/
1137
-
1138
-    /**
1139
-     * Output default tickets list table view.
1140
-     *
1141
-     * @throws EE_Error
1142
-     */
1143
-    public function _tickets_overview_list_table()
1144
-    {
1145
-        $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1146
-        $this->display_admin_list_table_page_with_no_sidebar();
1147
-    }
1148
-
1149
-
1150
-    /**
1151
-     * @param int  $per_page
1152
-     * @param bool $count
1153
-     * @param bool $trashed
1154
-     * @return EE_Soft_Delete_Base_Class[]|int
1155
-     * @throws EE_Error
1156
-     */
1157
-    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1158
-    {
1159
-        $orderby = $this->request->getRequestParam('orderby', 'TKT_name');
1160
-        $order   = $this->request->getRequestParam('order', 'ASC');
1161
-        switch ($orderby) {
1162
-            case 'TKT_name':
1163
-                $orderby = ['TKT_name' => $order];
1164
-                break;
1165
-            case 'TKT_price':
1166
-                $orderby = ['TKT_price' => $order];
1167
-                break;
1168
-            case 'TKT_uses':
1169
-                $orderby = ['TKT_uses' => $order];
1170
-                break;
1171
-            case 'TKT_min':
1172
-                $orderby = ['TKT_min' => $order];
1173
-                break;
1174
-            case 'TKT_max':
1175
-                $orderby = ['TKT_max' => $order];
1176
-                break;
1177
-            case 'TKT_qty':
1178
-                $orderby = ['TKT_qty' => $order];
1179
-                break;
1180
-        }
1181
-
1182
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
1183
-        $per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1184
-        $offset       = ($current_page - 1) * $per_page;
1185
-
1186
-        $where = [
1187
-            'TKT_is_default' => 1,
1188
-            'TKT_deleted'    => $trashed,
1189
-        ];
1190
-
1191
-        $search_term = $this->request->getRequestParam('s');
1192
-        if ($search_term) {
1193
-            $search_term = '%' . $search_term . '%';
1194
-            $where['OR'] = [
1195
-                'TKT_name'        => ['LIKE', $search_term],
1196
-                'TKT_description' => ['LIKE', $search_term],
1197
-            ];
1198
-        }
1199
-
1200
-        return $count
1201
-            ? EEM_Ticket::instance()->count_deleted_and_undeleted([$where])
1202
-            : EEM_Ticket::instance()->get_all_deleted_and_undeleted(
1203
-                [
1204
-                    $where,
1205
-                    'order_by' => $orderby,
1206
-                    'limit'    => [$offset, $per_page],
1207
-                    'group_by' => 'TKT_ID',
1208
-                ]
1209
-            );
1210
-    }
1211
-
1212
-
1213
-    /**
1214
-     * @param bool $trash
1215
-     * @throws EE_Error
1216
-     */
1217
-    protected function _trash_or_restore_ticket($trash = false)
1218
-    {
1219
-        $success = 1;
1220
-        $TKT     = EEM_Ticket::instance();
1221
-        // checkboxes?
1222
-        $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1223
-        if (! empty($checkboxes)) {
1224
-            // if array has more than one element then success message should be plural
1225
-            $success = count($checkboxes) > 1 ? 2 : 1;
1226
-            // cycle thru the boxes
1227
-            while (list($TKT_ID, $value) = each($checkboxes)) {
1228
-                if ($trash) {
1229
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1230
-                        $success = 0;
1231
-                    }
1232
-                } else {
1233
-                    if (! $TKT->restore_by_ID($TKT_ID)) {
1234
-                        $success = 0;
1235
-                    }
1236
-                }
1237
-            }
1238
-        } else {
1239
-            // grab single id and trash
1240
-            $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1241
-            if ($trash) {
1242
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1243
-                    $success = 0;
1244
-                }
1245
-            } else {
1246
-                if (! $TKT->restore_by_ID($TKT_ID)) {
1247
-                    $success = 0;
1248
-                }
1249
-            }
1250
-        }
1251
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
1252
-        $query_args  = [
1253
-            'action' => 'ticket_list_table',
1254
-            'status' => $trash ? '' : 'trashed',
1255
-        ];
1256
-        $this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args);
1257
-    }
1258
-
1259
-
1260
-    /**
1261
-     * Handles trashing default ticket.
1262
-     *
1263
-     * @throws EE_Error
1264
-     * @throws ReflectionException
1265
-     */
1266
-    protected function _delete_ticket()
1267
-    {
1268
-        $success = 1;
1269
-        // checkboxes?
1270
-        $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1271
-        if (! empty($checkboxes)) {
1272
-            // if array has more than one element then success message should be plural
1273
-            $success = count($checkboxes) > 1 ? 2 : 1;
1274
-            // cycle thru the boxes
1275
-            while (list($TKT_ID, $value) = each($checkboxes)) {
1276
-                // delete
1277
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1278
-                    $success = 0;
1279
-                }
1280
-            }
1281
-        } else {
1282
-            // grab single id and trash
1283
-            $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1284
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1285
-                $success = 0;
1286
-            }
1287
-        }
1288
-        $action_desc = 'deleted';
1289
-        $query_args  = [
1290
-            'action' => 'ticket_list_table',
1291
-            'status' => 'trashed',
1292
-        ];
1293
-        // fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1294
-        if (
1295
-            EEM_Ticket::instance()->count_deleted_and_undeleted(
1296
-                [['TKT_is_default' => 1]],
1297
-                'TKT_ID',
1298
-                true
1299
-            )
1300
-        ) {
1301
-            $query_args = [];
1302
-        }
1303
-        $this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args);
1304
-    }
1305
-
1306
-
1307
-    /**
1308
-     * @param int $TKT_ID
1309
-     * @return bool|int
1310
-     * @throws EE_Error
1311
-     * @throws ReflectionException
1312
-     */
1313
-    protected function _delete_the_ticket($TKT_ID)
1314
-    {
1315
-        $ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1316
-        $ticket->_remove_relations('Datetime');
1317
-        // delete all related prices first
1318
-        $ticket->delete_related_permanently('Price');
1319
-        return $ticket->delete_permanently();
1320
-    }
17
+	/**
18
+	 * Extend_Events_Admin_Page constructor.
19
+	 *
20
+	 * @param bool $routing
21
+	 * @throws EE_Error
22
+	 * @throws ReflectionException
23
+	 */
24
+	public function __construct($routing = true)
25
+	{
26
+		parent::__construct($routing);
27
+		if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
+			define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
29
+			define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
30
+			define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
31
+		}
32
+	}
33
+
34
+
35
+	/**
36
+	 * Sets routes.
37
+	 *
38
+	 * @throws EE_Error
39
+	 */
40
+	protected function _extend_page_config()
41
+	{
42
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
43
+		// is there a evt_id in the request?
44
+		$EVT_ID             = $this->request->getRequestParam('EVT_ID', 0, 'int');
45
+		$EVT_ID             = $this->request->getRequestParam('post', $EVT_ID, 'int');
46
+		$TKT_ID             = $this->request->getRequestParam('TKT_ID', 0, 'int');
47
+		$new_page_routes    = [
48
+			'duplicate_event'          => [
49
+				'func'       => '_duplicate_event',
50
+				'capability' => 'ee_edit_event',
51
+				'obj_id'     => $EVT_ID,
52
+				'noheader'   => true,
53
+			],
54
+			'ticket_list_table'        => [
55
+				'func'       => '_tickets_overview_list_table',
56
+				'capability' => 'ee_read_default_tickets',
57
+			],
58
+			'trash_ticket'             => [
59
+				'func'       => '_trash_or_restore_ticket',
60
+				'capability' => 'ee_delete_default_ticket',
61
+				'obj_id'     => $TKT_ID,
62
+				'noheader'   => true,
63
+				'args'       => ['trash' => true],
64
+			],
65
+			'trash_tickets'            => [
66
+				'func'       => '_trash_or_restore_ticket',
67
+				'capability' => 'ee_delete_default_tickets',
68
+				'noheader'   => true,
69
+				'args'       => ['trash' => true],
70
+			],
71
+			'restore_ticket'           => [
72
+				'func'       => '_trash_or_restore_ticket',
73
+				'capability' => 'ee_delete_default_ticket',
74
+				'obj_id'     => $TKT_ID,
75
+				'noheader'   => true,
76
+			],
77
+			'restore_tickets'          => [
78
+				'func'       => '_trash_or_restore_ticket',
79
+				'capability' => 'ee_delete_default_tickets',
80
+				'noheader'   => true,
81
+			],
82
+			'delete_ticket'            => [
83
+				'func'       => '_delete_ticket',
84
+				'capability' => 'ee_delete_default_ticket',
85
+				'obj_id'     => $TKT_ID,
86
+				'noheader'   => true,
87
+			],
88
+			'delete_tickets'           => [
89
+				'func'       => '_delete_ticket',
90
+				'capability' => 'ee_delete_default_tickets',
91
+				'noheader'   => true,
92
+			],
93
+			'import_page'              => [
94
+				'func'       => '_import_page',
95
+				'capability' => 'import',
96
+			],
97
+			'import'                   => [
98
+				'func'       => '_import_events',
99
+				'capability' => 'import',
100
+				'noheader'   => true,
101
+			],
102
+			'import_events'            => [
103
+				'func'       => '_import_events',
104
+				'capability' => 'import',
105
+				'noheader'   => true,
106
+			],
107
+			'export_events'            => [
108
+				'func'       => '_events_export',
109
+				'capability' => 'export',
110
+				'noheader'   => true,
111
+			],
112
+			'export_categories'        => [
113
+				'func'       => '_categories_export',
114
+				'capability' => 'export',
115
+				'noheader'   => true,
116
+			],
117
+			'sample_export_file'       => [
118
+				'func'       => '_sample_export_file',
119
+				'capability' => 'export',
120
+				'noheader'   => true,
121
+			],
122
+			'update_template_settings' => [
123
+				'func'       => '_update_template_settings',
124
+				'capability' => 'manage_options',
125
+				'noheader'   => true,
126
+			],
127
+		];
128
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
129
+		// partial route/config override
130
+		$this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
131
+		$this->_page_config['create_new']['metaboxes'][]  = '_premium_event_editor_meta_boxes';
132
+		$this->_page_config['create_new']['qtips'][]      = 'EE_Event_Editor_Tips';
133
+		$this->_page_config['edit']['qtips'][]            = 'EE_Event_Editor_Tips';
134
+		$this->_page_config['edit']['metaboxes'][]        = '_premium_event_editor_meta_boxes';
135
+		$this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
136
+		// add tickets tab but only if there are more than one default ticket!
137
+		$ticket_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
138
+			[['TKT_is_default' => 1]],
139
+			'TKT_ID',
140
+			true
141
+		);
142
+		if ($ticket_count > 1) {
143
+			$new_page_config = [
144
+				'ticket_list_table' => [
145
+					'nav'           => [
146
+						'label' => esc_html__('Default Tickets', 'event_espresso'),
147
+						'order' => 60,
148
+					],
149
+					'list_table'    => 'Tickets_List_Table',
150
+					'require_nonce' => false,
151
+				],
152
+			];
153
+		}
154
+		// template settings
155
+		$new_page_config['template_settings'] = [
156
+			'nav'           => [
157
+				'label' => esc_html__('Templates', 'event_espresso'),
158
+				'order' => 30,
159
+			],
160
+			'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
161
+			'help_tabs'     => [
162
+				'general_settings_templates_help_tab' => [
163
+					'title'    => esc_html__('Templates', 'event_espresso'),
164
+					'filename' => 'general_settings_templates',
165
+				],
166
+			],
167
+			// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
168
+			// 'help_tour'     => array('Templates_Help_Tour'),
169
+			'require_nonce' => false,
170
+		];
171
+		$this->_page_config                   = array_merge($this->_page_config, $new_page_config);
172
+		// add filters and actions
173
+		// modifying _views
174
+		add_filter(
175
+			'FHEE_event_datetime_metabox_add_additional_date_time_template',
176
+			[$this, 'add_additional_datetime_button'],
177
+			10,
178
+			2
179
+		);
180
+		add_filter(
181
+			'FHEE_event_datetime_metabox_clone_button_template',
182
+			[$this, 'add_datetime_clone_button'],
183
+			10,
184
+			2
185
+		);
186
+		add_filter(
187
+			'FHEE_event_datetime_metabox_timezones_template',
188
+			[$this, 'datetime_timezones_template'],
189
+			10,
190
+			2
191
+		);
192
+		// filters for event list table
193
+		add_filter('FHEE__Extend_Events_Admin_List_Table__filters', [$this, 'list_table_filters'], 10, 2);
194
+		add_filter(
195
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
196
+			[$this, 'extra_list_table_actions'],
197
+			10,
198
+			2
199
+		);
200
+		// legend item
201
+		add_filter('FHEE__Events_Admin_Page___event_legend_items__items', [$this, 'additional_legend_items']);
202
+		add_action('admin_init', [$this, 'admin_init']);
203
+	}
204
+
205
+
206
+	/**
207
+	 * admin_init
208
+	 */
209
+	public function admin_init()
210
+	{
211
+		EE_Registry::$i18n_js_strings = array_merge(
212
+			EE_Registry::$i18n_js_strings,
213
+			[
214
+				'image_confirm'          => esc_html__(
215
+					'Do you really want to delete this image? Please remember to update your event to complete the removal.',
216
+					'event_espresso'
217
+				),
218
+				'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
219
+				'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
220
+				'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
221
+				'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
222
+				'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
223
+			]
224
+		);
225
+	}
226
+
227
+
228
+	/**
229
+	 * Add per page screen options to the default ticket list table view.
230
+	 */
231
+	protected function _add_screen_options_ticket_list_table()
232
+	{
233
+		$this->_per_page_screen_option();
234
+	}
235
+
236
+
237
+	/**
238
+	 * @param string $return
239
+	 * @param int    $id
240
+	 * @param string $new_title
241
+	 * @param string $new_slug
242
+	 * @return string
243
+	 */
244
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
245
+	{
246
+		$return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
247
+		// make sure this is only when editing
248
+		if (! empty($id)) {
249
+			$href   = EE_Admin_Page::add_query_args_and_nonce(
250
+				['action' => 'duplicate_event', 'EVT_ID' => $id],
251
+				$this->_admin_base_url
252
+			);
253
+			$title  = esc_attr__('Duplicate Event', 'event_espresso');
254
+			$return .= '<a href="'
255
+					   . $href
256
+					   . '" title="'
257
+					   . $title
258
+					   . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
259
+					   . $title
260
+					   . '</a>';
261
+		}
262
+		return $return;
263
+	}
264
+
265
+
266
+	/**
267
+	 * Set the list table views for the default ticket list table view.
268
+	 */
269
+	public function _set_list_table_views_ticket_list_table()
270
+	{
271
+		$this->_views = [
272
+			'all'     => [
273
+				'slug'        => 'all',
274
+				'label'       => esc_html__('All', 'event_espresso'),
275
+				'count'       => 0,
276
+				'bulk_action' => [
277
+					'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
278
+				],
279
+			],
280
+			'trashed' => [
281
+				'slug'        => 'trashed',
282
+				'label'       => esc_html__('Trash', 'event_espresso'),
283
+				'count'       => 0,
284
+				'bulk_action' => [
285
+					'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
286
+					'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
287
+				],
288
+			],
289
+		];
290
+	}
291
+
292
+
293
+	/**
294
+	 * Enqueue scripts and styles for the event editor.
295
+	 */
296
+	public function load_scripts_styles_edit()
297
+	{
298
+		wp_register_script(
299
+			'ee-event-editor-heartbeat',
300
+			EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
301
+			['ee_admin_js', 'heartbeat'],
302
+			EVENT_ESPRESSO_VERSION,
303
+			true
304
+		);
305
+		wp_enqueue_script('ee-accounting');
306
+		// styles
307
+		wp_enqueue_style('espresso-ui-theme');
308
+		wp_enqueue_script('event_editor_js');
309
+		wp_enqueue_script('ee-event-editor-heartbeat');
310
+	}
311
+
312
+
313
+	/**
314
+	 * Returns template for the additional datetime.
315
+	 *
316
+	 * @param string $template
317
+	 * @param array  $template_args
318
+	 * @return string
319
+	 * @throws DomainException
320
+	 */
321
+	public function add_additional_datetime_button($template, $template_args)
322
+	{
323
+		return EEH_Template::display_template(
324
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
325
+			$template_args,
326
+			true
327
+		);
328
+	}
329
+
330
+
331
+	/**
332
+	 * Returns the template for cloning a datetime.
333
+	 *
334
+	 * @param $template
335
+	 * @param $template_args
336
+	 * @return string
337
+	 * @throws DomainException
338
+	 */
339
+	public function add_datetime_clone_button($template, $template_args)
340
+	{
341
+		return EEH_Template::display_template(
342
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
343
+			$template_args,
344
+			true
345
+		);
346
+	}
347
+
348
+
349
+	/**
350
+	 * Returns the template for datetime timezones.
351
+	 *
352
+	 * @param $template
353
+	 * @param $template_args
354
+	 * @return string
355
+	 * @throws DomainException
356
+	 */
357
+	public function datetime_timezones_template($template, $template_args)
358
+	{
359
+		return EEH_Template::display_template(
360
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
361
+			$template_args,
362
+			true
363
+		);
364
+	}
365
+
366
+
367
+	/**
368
+	 * Sets the views for the default list table view.
369
+	 *
370
+	 * @throws EE_Error
371
+	 */
372
+	protected function _set_list_table_views_default()
373
+	{
374
+		parent::_set_list_table_views_default();
375
+		$new_views    = [
376
+			'today' => [
377
+				'slug'        => 'today',
378
+				'label'       => esc_html__('Today', 'event_espresso'),
379
+				'count'       => $this->total_events_today(),
380
+				'bulk_action' => [
381
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
382
+				],
383
+			],
384
+			'month' => [
385
+				'slug'        => 'month',
386
+				'label'       => esc_html__('This Month', 'event_espresso'),
387
+				'count'       => $this->total_events_this_month(),
388
+				'bulk_action' => [
389
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
390
+				],
391
+			],
392
+		];
393
+		$this->_views = array_merge($this->_views, $new_views);
394
+	}
395
+
396
+
397
+	/**
398
+	 * Returns the extra action links for the default list table view.
399
+	 *
400
+	 * @param array    $action_links
401
+	 * @param EE_Event $event
402
+	 * @return array
403
+	 * @throws EE_Error
404
+	 * @throws ReflectionException
405
+	 */
406
+	public function extra_list_table_actions(array $action_links, EE_Event $event)
407
+	{
408
+		if (
409
+			EE_Registry::instance()->CAP->current_user_can(
410
+				'ee_read_registrations',
411
+				'espresso_registrations_reports',
412
+				$event->ID()
413
+			)
414
+		) {
415
+			$reports_query_args = [
416
+				'action' => 'reports',
417
+				'EVT_ID' => $event->ID(),
418
+			];
419
+			$reports_link       = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
420
+			$action_links[]     = '<a href="'
421
+								  . $reports_link
422
+								  . '" title="'
423
+								  . esc_attr__('View Report', 'event_espresso')
424
+								  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
425
+								  . "\n\t";
426
+		}
427
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
428
+			EE_Registry::instance()->load_helper('MSG_Template');
429
+			$action_links[] = EEH_MSG_Template::get_message_action_link(
430
+				'see_notifications_for',
431
+				null,
432
+				['EVT_ID' => $event->ID()]
433
+			);
434
+		}
435
+		return $action_links;
436
+	}
437
+
438
+
439
+	/**
440
+	 * @param $items
441
+	 * @return mixed
442
+	 */
443
+	public function additional_legend_items($items)
444
+	{
445
+		if (
446
+			EE_Registry::instance()->CAP->current_user_can(
447
+				'ee_read_registrations',
448
+				'espresso_registrations_reports'
449
+			)
450
+		) {
451
+			$items['reports'] = [
452
+				'class' => 'dashicons dashicons-chart-bar',
453
+				'desc'  => esc_html__('Event Reports', 'event_espresso'),
454
+			];
455
+		}
456
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
457
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
458
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
459
+				$items['view_related_messages'] = [
460
+					'class' => $related_for_icon['css_class'],
461
+					'desc'  => $related_for_icon['label'],
462
+				];
463
+			}
464
+		}
465
+		return $items;
466
+	}
467
+
468
+
469
+	/**
470
+	 * This is the callback method for the duplicate event route
471
+	 * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
472
+	 * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
473
+	 * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
474
+	 * After duplication the redirect is to the new event edit page.
475
+	 *
476
+	 * @return void
477
+	 * @throws EE_Error If EE_Event is not available with given ID
478
+	 * @throws ReflectionException
479
+	 * @access protected
480
+	 */
481
+	protected function _duplicate_event()
482
+	{
483
+		// first make sure the ID for the event is in the request.
484
+		//  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
485
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
486
+		if (! $EVT_ID) {
487
+			EE_Error::add_error(
488
+				esc_html__(
489
+					'In order to duplicate an event an Event ID is required.  None was given.',
490
+					'event_espresso'
491
+				),
492
+				__FILE__,
493
+				__FUNCTION__,
494
+				__LINE__
495
+			);
496
+			$this->_redirect_after_action(false, '', '', [], true);
497
+			return;
498
+		}
499
+		// k we've got EVT_ID so let's use that to get the event we'll duplicate
500
+		$orig_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
501
+		if (! $orig_event instanceof EE_Event) {
502
+			throw new EE_Error(
503
+				sprintf(
504
+					esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
505
+					$EVT_ID
506
+				)
507
+			);
508
+		}
509
+		// k now let's clone the $orig_event before getting relations
510
+		$new_event = clone $orig_event;
511
+		// original datetimes
512
+		$orig_datetimes = $orig_event->get_many_related('Datetime');
513
+		// other original relations
514
+		$orig_ven = $orig_event->get_many_related('Venue');
515
+		// reset the ID and modify other details to make it clear this is a dupe
516
+		$new_event->set('EVT_ID', 0);
517
+		$new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
518
+		$new_event->set('EVT_name', $new_name);
519
+		$new_event->set(
520
+			'EVT_slug',
521
+			wp_unique_post_slug(
522
+				sanitize_title($orig_event->name()),
523
+				0,
524
+				'publish',
525
+				'espresso_events',
526
+				0
527
+			)
528
+		);
529
+		$new_event->set('status', 'draft');
530
+		// duplicate discussion settings
531
+		$new_event->set('comment_status', $orig_event->get('comment_status'));
532
+		$new_event->set('ping_status', $orig_event->get('ping_status'));
533
+		// save the new event
534
+		$new_event->save();
535
+		// venues
536
+		foreach ($orig_ven as $ven) {
537
+			$new_event->_add_relation_to($ven, 'Venue');
538
+		}
539
+		$new_event->save();
540
+		// now we need to get the question group relations and handle that
541
+		// first primary question groups
542
+		$orig_primary_qgs = $orig_event->get_many_related(
543
+			'Question_Group',
544
+			[['Event_Question_Group.EQG_primary' => true]]
545
+		);
546
+		if (! empty($orig_primary_qgs)) {
547
+			foreach ($orig_primary_qgs as $obj) {
548
+				if ($obj instanceof EE_Question_Group) {
549
+					$new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]);
550
+				}
551
+			}
552
+		}
553
+		// next additional attendee question groups
554
+		$orig_additional_qgs = $orig_event->get_many_related(
555
+			'Question_Group',
556
+			[['Event_Question_Group.EQG_additional' => true]]
557
+		);
558
+		if (! empty($orig_additional_qgs)) {
559
+			foreach ($orig_additional_qgs as $obj) {
560
+				if ($obj instanceof EE_Question_Group) {
561
+					$new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]);
562
+				}
563
+			}
564
+		}
565
+
566
+		$new_event->save();
567
+
568
+		// k now that we have the new event saved we can loop through the datetimes and start adding relations.
569
+		$cloned_tickets = [];
570
+		foreach ($orig_datetimes as $orig_dtt) {
571
+			if (! $orig_dtt instanceof EE_Datetime) {
572
+				continue;
573
+			}
574
+			$new_dtt      = clone $orig_dtt;
575
+			$orig_tickets = $orig_dtt->tickets();
576
+			// save new dtt then add to event
577
+			$new_dtt->set('DTT_ID', 0);
578
+			$new_dtt->set('DTT_sold', 0);
579
+			$new_dtt->set_reserved(0);
580
+			$new_dtt->save();
581
+			$new_event->_add_relation_to($new_dtt, 'Datetime');
582
+			$new_event->save();
583
+			// now let's get the ticket relations setup.
584
+			foreach ((array) $orig_tickets as $orig_ticket) {
585
+				// it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
586
+				if (! $orig_ticket instanceof EE_Ticket) {
587
+					continue;
588
+				}
589
+				// is this ticket archived?  If it is then let's skip
590
+				if ($orig_ticket->get('TKT_deleted')) {
591
+					continue;
592
+				}
593
+				// does this original ticket already exist in the clone_tickets cache?
594
+				//  If so we'll just use the new ticket from it.
595
+				if (isset($cloned_tickets[ $orig_ticket->ID() ])) {
596
+					$new_ticket = $cloned_tickets[ $orig_ticket->ID() ];
597
+				} else {
598
+					$new_ticket = clone $orig_ticket;
599
+					// get relations on the $orig_ticket that we need to setup.
600
+					$orig_prices = $orig_ticket->prices();
601
+					$new_ticket->set('TKT_ID', 0);
602
+					$new_ticket->set('TKT_sold', 0);
603
+					$new_ticket->set('TKT_reserved', 0);
604
+					$new_ticket->save(); // make sure new ticket has ID.
605
+					// price relations on new ticket need to be setup.
606
+					foreach ($orig_prices as $orig_price) {
607
+						$new_price = clone $orig_price;
608
+						$new_price->set('PRC_ID', 0);
609
+						$new_price->save();
610
+						$new_ticket->_add_relation_to($new_price, 'Price');
611
+						$new_ticket->save();
612
+					}
613
+
614
+					do_action(
615
+						'AHEE__Extend_Events_Admin_Page___duplicate_event__duplicate_ticket__after',
616
+						$orig_ticket,
617
+						$new_ticket,
618
+						$orig_prices,
619
+						$orig_event,
620
+						$orig_dtt,
621
+						$new_dtt
622
+					);
623
+				}
624
+				// k now we can add the new ticket as a relation to the new datetime
625
+				// and make sure its added to our cached $cloned_tickets array
626
+				// for use with later datetimes that have the same ticket.
627
+				$new_dtt->_add_relation_to($new_ticket, 'Ticket');
628
+				$new_dtt->save();
629
+				$cloned_tickets[ $orig_ticket->ID() ] = $new_ticket;
630
+			}
631
+		}
632
+		// clone taxonomy information
633
+		$taxonomies_to_clone_with = apply_filters(
634
+			'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
635
+			['espresso_event_categories', 'espresso_event_type', 'post_tag']
636
+		);
637
+		// get terms for original event (notice)
638
+		$orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
639
+		// loop through terms and add them to new event.
640
+		foreach ($orig_terms as $term) {
641
+			wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
642
+		}
643
+
644
+		// duplicate other core WP_Post items for this event.
645
+		// post thumbnail (feature image).
646
+		$feature_image_id = get_post_thumbnail_id($orig_event->ID());
647
+		if ($feature_image_id) {
648
+			update_post_meta($new_event->ID(), '_thumbnail_id', $feature_image_id);
649
+		}
650
+
651
+		// duplicate page_template setting
652
+		$page_template = get_post_meta($orig_event->ID(), '_wp_page_template', true);
653
+		if ($page_template) {
654
+			update_post_meta($new_event->ID(), '_wp_page_template', $page_template);
655
+		}
656
+
657
+		do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
658
+		// now let's redirect to the edit page for this duplicated event if we have a new event id.
659
+		if ($new_event->ID()) {
660
+			$redirect_args = [
661
+				'post'   => $new_event->ID(),
662
+				'action' => 'edit',
663
+			];
664
+			EE_Error::add_success(
665
+				esc_html__(
666
+					'Event successfully duplicated.  Please review the details below and make any necessary edits',
667
+					'event_espresso'
668
+				)
669
+			);
670
+		} else {
671
+			$redirect_args = [
672
+				'action' => 'default',
673
+			];
674
+			EE_Error::add_error(
675
+				esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
676
+				__FILE__,
677
+				__FUNCTION__,
678
+				__LINE__
679
+			);
680
+		}
681
+		$this->_redirect_after_action(false, '', '', $redirect_args, true);
682
+	}
683
+
684
+
685
+	/**
686
+	 * Generates output for the import page.
687
+	 *
688
+	 * @throws EE_Error
689
+	 */
690
+	protected function _import_page()
691
+	{
692
+		$title = esc_html__('Import', 'event_espresso');
693
+		$intro = esc_html__(
694
+			'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
695
+			'event_espresso'
696
+		);
697
+
698
+		$form_url = EVENTS_ADMIN_URL;
699
+		$action   = 'import_events';
700
+		$type     = 'csv';
701
+
702
+		$this->_template_args['form'] = EE_Import::instance()->upload_form(
703
+			$title,
704
+			$intro,
705
+			$form_url,
706
+			$action,
707
+			$type
708
+		);
709
+
710
+		$this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
711
+			['action' => 'sample_export_file'],
712
+			$this->_admin_base_url
713
+		);
714
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
715
+			EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
716
+			$this->_template_args,
717
+			true
718
+		);
719
+		$this->display_admin_page_with_sidebar();
720
+	}
721
+
722
+
723
+	/**
724
+	 * _import_events
725
+	 * This handles displaying the screen and running imports for importing events.
726
+	 *
727
+	 * @return void
728
+	 * @throws EE_Error
729
+	 */
730
+	protected function _import_events()
731
+	{
732
+		require_once(EE_CLASSES . 'EE_Import.class.php');
733
+		$success = EE_Import::instance()->import();
734
+		$this->_redirect_after_action(
735
+			$success,
736
+			esc_html__('Import File', 'event_espresso'),
737
+			'ran',
738
+			['action' => 'import_page'],
739
+			true
740
+		);
741
+	}
742
+
743
+
744
+	/**
745
+	 * _events_export
746
+	 * Will export all (or just the given event) to a Excel compatible file.
747
+	 *
748
+	 * @access protected
749
+	 * @return void
750
+	 */
751
+	protected function _events_export()
752
+	{
753
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
754
+		$EVT_ID = $this->request->getRequestParam('EVT_IDs', $EVT_ID, 'int');
755
+		$this->request->mergeRequestParams(
756
+			[
757
+				'export' => 'report',
758
+				'action' => 'all_event_data',
759
+				'EVT_ID' => $EVT_ID,
760
+			]
761
+		);
762
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
763
+			require_once(EE_CLASSES . 'EE_Export.class.php');
764
+			$EE_Export = EE_Export::instance($this->request->requestParams());
765
+			$EE_Export->export();
766
+		}
767
+	}
768
+
769
+
770
+	/**
771
+	 * handle category exports()
772
+	 *
773
+	 * @return void
774
+	 */
775
+	protected function _categories_export()
776
+	{
777
+		$EVT_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
778
+		$this->request->mergeRequestParams(
779
+			[
780
+				'export' => 'report',
781
+				'action' => 'categories',
782
+				'EVT_ID' => $EVT_ID,
783
+			]
784
+		);
785
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
786
+			require_once(EE_CLASSES . 'EE_Export.class.php');
787
+			$EE_Export = EE_Export::instance($this->request->requestParams());
788
+			$EE_Export->export();
789
+		}
790
+	}
791
+
792
+
793
+	/**
794
+	 * Creates a sample CSV file for importing
795
+	 */
796
+	protected function _sample_export_file()
797
+	{
798
+		// require_once(EE_CLASSES . 'EE_Export.class.php');
799
+		EE_Export::instance()->export_sample();
800
+	}
801
+
802
+
803
+	/*************        Template Settings        *************/
804
+	/**
805
+	 * Generates template settings page output
806
+	 *
807
+	 * @throws DomainException
808
+	 * @throws EE_Error
809
+	 */
810
+	protected function _template_settings()
811
+	{
812
+		$this->_template_args['values'] = $this->_yes_no_values;
813
+		/**
814
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
815
+		 * from General_Settings_Admin_Page to here.
816
+		 */
817
+		$this->_template_args = apply_filters(
818
+			'FHEE__General_Settings_Admin_Page__template_settings__template_args',
819
+			$this->_template_args
820
+		);
821
+		$this->_set_add_edit_form_tags('update_template_settings');
822
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
823
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
824
+			EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
825
+			$this->_template_args,
826
+			true
827
+		);
828
+		$this->display_admin_page_with_sidebar();
829
+	}
830
+
831
+
832
+	/**
833
+	 * Handler for updating template settings.
834
+	 *
835
+	 * @throws EE_Error
836
+	 */
837
+	protected function _update_template_settings()
838
+	{
839
+		/**
840
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
841
+		 * from General_Settings_Admin_Page to here.
842
+		 */
843
+		EE_Registry::instance()->CFG->template_settings = apply_filters(
844
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
845
+			EE_Registry::instance()->CFG->template_settings,
846
+			$this->request->requestParams()
847
+		);
848
+		// update custom post type slugs and detect if we need to flush rewrite rules
849
+		$old_slug = EE_Registry::instance()->CFG->core->event_cpt_slug;
850
+
851
+		$event_cpt_slug = $this->request->getRequestParam('event_cpt_slug');
852
+
853
+		EE_Registry::instance()->CFG->core->event_cpt_slug = $event_cpt_slug
854
+			? EE_Registry::instance()->CFG->core->event_cpt_slug
855
+			: EEH_URL::slugify($event_cpt_slug, 'events');
856
+
857
+		$what    = esc_html__('Template Settings', 'event_espresso');
858
+		$success = $this->_update_espresso_configuration(
859
+			$what,
860
+			EE_Registry::instance()->CFG->template_settings,
861
+			__FILE__,
862
+			__FUNCTION__,
863
+			__LINE__
864
+		);
865
+		if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
866
+			/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
867
+			$rewrite_rules = LoaderFactory::getLoader()->getShared(
868
+				'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
869
+			);
870
+			$rewrite_rules->flush();
871
+		}
872
+		$this->_redirect_after_action($success, $what, 'updated', ['action' => 'template_settings']);
873
+	}
874
+
875
+
876
+	/**
877
+	 * _premium_event_editor_meta_boxes
878
+	 * add all metaboxes related to the event_editor
879
+	 *
880
+	 * @access protected
881
+	 * @return void
882
+	 * @throws EE_Error
883
+	 * @throws ReflectionException
884
+	 */
885
+	protected function _premium_event_editor_meta_boxes()
886
+	{
887
+		$this->verify_cpt_object();
888
+		add_meta_box(
889
+			'espresso_event_editor_event_options',
890
+			esc_html__('Event Registration Options', 'event_espresso'),
891
+			[$this, 'registration_options_meta_box'],
892
+			$this->page_slug,
893
+			'side',
894
+			'core'
895
+		);
896
+	}
897
+
898
+
899
+	/**
900
+	 * override caf metabox
901
+	 *
902
+	 * @return void
903
+	 * @throws EE_Error
904
+	 * @throws ReflectionException
905
+	 */
906
+	public function registration_options_meta_box()
907
+	{
908
+		$yes_no_values = [
909
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
910
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
911
+		];
912
+
913
+		$default_reg_status_values = EEM_Registration::reg_status_array(
914
+			[
915
+				EEM_Registration::status_id_cancelled,
916
+				EEM_Registration::status_id_declined,
917
+				EEM_Registration::status_id_incomplete,
918
+				EEM_Registration::status_id_wait_list,
919
+			],
920
+			true
921
+		);
922
+
923
+		$template_args['active_status']    = $this->_cpt_model_obj->pretty_active_status(false);
924
+		$template_args['_event']           = $this->_cpt_model_obj;
925
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
926
+
927
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
928
+			'default_reg_status',
929
+			$default_reg_status_values,
930
+			$this->_cpt_model_obj->default_registration_status()
931
+		);
932
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
933
+			'display_desc',
934
+			$yes_no_values,
935
+			$this->_cpt_model_obj->display_description()
936
+		);
937
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
938
+			'display_ticket_selector',
939
+			$yes_no_values,
940
+			$this->_cpt_model_obj->display_ticket_selector(),
941
+			'',
942
+			'',
943
+			false
944
+		);
945
+		$template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
946
+			'EVT_default_registration_status',
947
+			$default_reg_status_values,
948
+			$this->_cpt_model_obj->default_registration_status()
949
+		);
950
+		$template_args['additional_registration_options'] = apply_filters(
951
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
952
+			'',
953
+			$template_args,
954
+			$yes_no_values,
955
+			$default_reg_status_values
956
+		);
957
+		EEH_Template::display_template(
958
+			EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
959
+			$template_args
960
+		);
961
+	}
962
+
963
+
964
+
965
+	/**
966
+	 * wp_list_table_mods for caf
967
+	 * ============================
968
+	 */
969
+	/**
970
+	 * hook into list table filters and provide filters for caffeinated list table
971
+	 *
972
+	 * @param array $old_filters    any existing filters present
973
+	 * @param array $list_table_obj the list table object
974
+	 * @return array                  new filters
975
+	 * @throws EE_Error
976
+	 * @throws ReflectionException
977
+	 */
978
+	public function list_table_filters($old_filters, $list_table_obj)
979
+	{
980
+		$filters = [];
981
+		// first month/year filters
982
+		$filters[] = $this->espresso_event_months_dropdown();
983
+		$status    = $this->request->getRequestParam('status');
984
+		// active status dropdown
985
+		if ($status !== 'draft') {
986
+			$filters[] = $this->active_status_dropdown($this->request->getRequestParam('active_status'));
987
+			$filters[] = $this->venuesDropdown($this->request->getRequestParam('venue'));
988
+		}
989
+		// category filter
990
+		$filters[] = $this->category_dropdown();
991
+		return array_merge($old_filters, $filters);
992
+	}
993
+
994
+
995
+	/**
996
+	 * espresso_event_months_dropdown
997
+	 *
998
+	 * @access public
999
+	 * @return string                dropdown listing month/year selections for events.
1000
+	 * @throws EE_Error
1001
+	 */
1002
+	public function espresso_event_months_dropdown()
1003
+	{
1004
+		// what we need to do is get all PRIMARY datetimes for all events to filter on.
1005
+		// Note we need to include any other filters that are set!
1006
+		return EEH_Form_Fields::generate_event_months_dropdown(
1007
+			$this->request->getRequestParam('month_range'),
1008
+			$this->request->getRequestParam('status'),
1009
+			$this->request->getRequestParam('EVT_CAT', 0, 'int'),
1010
+			$this->request->getRequestParam('active_status')
1011
+		);
1012
+	}
1013
+
1014
+
1015
+	/**
1016
+	 * returns a list of "active" statuses on the event
1017
+	 *
1018
+	 * @param string $current_value whatever the current active status is
1019
+	 * @return string
1020
+	 */
1021
+	public function active_status_dropdown($current_value = '')
1022
+	{
1023
+		$select_name = 'active_status';
1024
+		$values      = [
1025
+			'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
1026
+			'active'   => esc_html__('Active', 'event_espresso'),
1027
+			'upcoming' => esc_html__('Upcoming', 'event_espresso'),
1028
+			'expired'  => esc_html__('Expired', 'event_espresso'),
1029
+			'inactive' => esc_html__('Inactive', 'event_espresso'),
1030
+		];
1031
+
1032
+		return EEH_Form_Fields::select_input($select_name, $values, $current_value, '', 'wide');
1033
+	}
1034
+
1035
+
1036
+	/**
1037
+	 * returns a list of "venues"
1038
+	 *
1039
+	 * @param string $current_value whatever the current active status is
1040
+	 * @return string
1041
+	 * @throws EE_Error
1042
+	 * @throws ReflectionException
1043
+	 */
1044
+	protected function venuesDropdown($current_value = '')
1045
+	{
1046
+		$values = [
1047
+			'' => esc_html__('All Venues', 'event_espresso'),
1048
+		];
1049
+		// populate the list of venues.
1050
+		$venues = EEM_Venue::instance()->get_all(['order_by' => ['VNU_name' => 'ASC']]);
1051
+
1052
+		foreach ($venues as $venue) {
1053
+			$values[ $venue->ID() ] = $venue->name();
1054
+		}
1055
+
1056
+		return EEH_Form_Fields::select_input('venue', $values, $current_value, '', 'wide');
1057
+	}
1058
+
1059
+
1060
+	/**
1061
+	 * output a dropdown of the categories for the category filter on the event admin list table
1062
+	 *
1063
+	 * @access  public
1064
+	 * @return string html
1065
+	 * @throws EE_Error
1066
+	 * @throws ReflectionException
1067
+	 */
1068
+	public function category_dropdown()
1069
+	{
1070
+		return EEH_Form_Fields::generate_event_category_dropdown(
1071
+			$this->request->getRequestParam('EVT_CAT', -1, 'int')
1072
+		);
1073
+	}
1074
+
1075
+
1076
+	/**
1077
+	 * get total number of events today
1078
+	 *
1079
+	 * @access public
1080
+	 * @return int
1081
+	 * @throws EE_Error
1082
+	 */
1083
+	public function total_events_today()
1084
+	{
1085
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1086
+			'DTT_EVT_start',
1087
+			date('Y-m-d') . ' 00:00:00',
1088
+			'Y-m-d H:i:s',
1089
+			'UTC'
1090
+		);
1091
+		$end   = EEM_Datetime::instance()->convert_datetime_for_query(
1092
+			'DTT_EVT_start',
1093
+			date('Y-m-d') . ' 23:59:59',
1094
+			'Y-m-d H:i:s',
1095
+			'UTC'
1096
+		);
1097
+		$where = [
1098
+			'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1099
+		];
1100
+		return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1101
+	}
1102
+
1103
+
1104
+	/**
1105
+	 * get total number of events this month
1106
+	 *
1107
+	 * @access public
1108
+	 * @return int
1109
+	 * @throws EE_Error
1110
+	 */
1111
+	public function total_events_this_month()
1112
+	{
1113
+		// Dates
1114
+		$this_year_r     = date('Y');
1115
+		$this_month_r    = date('m');
1116
+		$days_this_month = date('t');
1117
+		$start           = EEM_Datetime::instance()->convert_datetime_for_query(
1118
+			'DTT_EVT_start',
1119
+			$this_year_r . '-' . $this_month_r . '-01 00:00:00',
1120
+			'Y-m-d H:i:s',
1121
+			'UTC'
1122
+		);
1123
+		$end             = EEM_Datetime::instance()->convert_datetime_for_query(
1124
+			'DTT_EVT_start',
1125
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1126
+			'Y-m-d H:i:s',
1127
+			'UTC'
1128
+		);
1129
+		$where           = [
1130
+			'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1131
+		];
1132
+		return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
1133
+	}
1134
+
1135
+
1136
+	/** DEFAULT TICKETS STUFF **/
1137
+
1138
+	/**
1139
+	 * Output default tickets list table view.
1140
+	 *
1141
+	 * @throws EE_Error
1142
+	 */
1143
+	public function _tickets_overview_list_table()
1144
+	{
1145
+		$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1146
+		$this->display_admin_list_table_page_with_no_sidebar();
1147
+	}
1148
+
1149
+
1150
+	/**
1151
+	 * @param int  $per_page
1152
+	 * @param bool $count
1153
+	 * @param bool $trashed
1154
+	 * @return EE_Soft_Delete_Base_Class[]|int
1155
+	 * @throws EE_Error
1156
+	 */
1157
+	public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1158
+	{
1159
+		$orderby = $this->request->getRequestParam('orderby', 'TKT_name');
1160
+		$order   = $this->request->getRequestParam('order', 'ASC');
1161
+		switch ($orderby) {
1162
+			case 'TKT_name':
1163
+				$orderby = ['TKT_name' => $order];
1164
+				break;
1165
+			case 'TKT_price':
1166
+				$orderby = ['TKT_price' => $order];
1167
+				break;
1168
+			case 'TKT_uses':
1169
+				$orderby = ['TKT_uses' => $order];
1170
+				break;
1171
+			case 'TKT_min':
1172
+				$orderby = ['TKT_min' => $order];
1173
+				break;
1174
+			case 'TKT_max':
1175
+				$orderby = ['TKT_max' => $order];
1176
+				break;
1177
+			case 'TKT_qty':
1178
+				$orderby = ['TKT_qty' => $order];
1179
+				break;
1180
+		}
1181
+
1182
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
1183
+		$per_page     = $this->request->getRequestParam('perpage', $per_page, 'int');
1184
+		$offset       = ($current_page - 1) * $per_page;
1185
+
1186
+		$where = [
1187
+			'TKT_is_default' => 1,
1188
+			'TKT_deleted'    => $trashed,
1189
+		];
1190
+
1191
+		$search_term = $this->request->getRequestParam('s');
1192
+		if ($search_term) {
1193
+			$search_term = '%' . $search_term . '%';
1194
+			$where['OR'] = [
1195
+				'TKT_name'        => ['LIKE', $search_term],
1196
+				'TKT_description' => ['LIKE', $search_term],
1197
+			];
1198
+		}
1199
+
1200
+		return $count
1201
+			? EEM_Ticket::instance()->count_deleted_and_undeleted([$where])
1202
+			: EEM_Ticket::instance()->get_all_deleted_and_undeleted(
1203
+				[
1204
+					$where,
1205
+					'order_by' => $orderby,
1206
+					'limit'    => [$offset, $per_page],
1207
+					'group_by' => 'TKT_ID',
1208
+				]
1209
+			);
1210
+	}
1211
+
1212
+
1213
+	/**
1214
+	 * @param bool $trash
1215
+	 * @throws EE_Error
1216
+	 */
1217
+	protected function _trash_or_restore_ticket($trash = false)
1218
+	{
1219
+		$success = 1;
1220
+		$TKT     = EEM_Ticket::instance();
1221
+		// checkboxes?
1222
+		$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1223
+		if (! empty($checkboxes)) {
1224
+			// if array has more than one element then success message should be plural
1225
+			$success = count($checkboxes) > 1 ? 2 : 1;
1226
+			// cycle thru the boxes
1227
+			while (list($TKT_ID, $value) = each($checkboxes)) {
1228
+				if ($trash) {
1229
+					if (! $TKT->delete_by_ID($TKT_ID)) {
1230
+						$success = 0;
1231
+					}
1232
+				} else {
1233
+					if (! $TKT->restore_by_ID($TKT_ID)) {
1234
+						$success = 0;
1235
+					}
1236
+				}
1237
+			}
1238
+		} else {
1239
+			// grab single id and trash
1240
+			$TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1241
+			if ($trash) {
1242
+				if (! $TKT->delete_by_ID($TKT_ID)) {
1243
+					$success = 0;
1244
+				}
1245
+			} else {
1246
+				if (! $TKT->restore_by_ID($TKT_ID)) {
1247
+					$success = 0;
1248
+				}
1249
+			}
1250
+		}
1251
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
1252
+		$query_args  = [
1253
+			'action' => 'ticket_list_table',
1254
+			'status' => $trash ? '' : 'trashed',
1255
+		];
1256
+		$this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args);
1257
+	}
1258
+
1259
+
1260
+	/**
1261
+	 * Handles trashing default ticket.
1262
+	 *
1263
+	 * @throws EE_Error
1264
+	 * @throws ReflectionException
1265
+	 */
1266
+	protected function _delete_ticket()
1267
+	{
1268
+		$success = 1;
1269
+		// checkboxes?
1270
+		$checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1271
+		if (! empty($checkboxes)) {
1272
+			// if array has more than one element then success message should be plural
1273
+			$success = count($checkboxes) > 1 ? 2 : 1;
1274
+			// cycle thru the boxes
1275
+			while (list($TKT_ID, $value) = each($checkboxes)) {
1276
+				// delete
1277
+				if (! $this->_delete_the_ticket($TKT_ID)) {
1278
+					$success = 0;
1279
+				}
1280
+			}
1281
+		} else {
1282
+			// grab single id and trash
1283
+			$TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1284
+			if (! $this->_delete_the_ticket($TKT_ID)) {
1285
+				$success = 0;
1286
+			}
1287
+		}
1288
+		$action_desc = 'deleted';
1289
+		$query_args  = [
1290
+			'action' => 'ticket_list_table',
1291
+			'status' => 'trashed',
1292
+		];
1293
+		// fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1294
+		if (
1295
+			EEM_Ticket::instance()->count_deleted_and_undeleted(
1296
+				[['TKT_is_default' => 1]],
1297
+				'TKT_ID',
1298
+				true
1299
+			)
1300
+		) {
1301
+			$query_args = [];
1302
+		}
1303
+		$this->_redirect_after_action($success, esc_html__('Tickets', 'event_espresso'), $action_desc, $query_args);
1304
+	}
1305
+
1306
+
1307
+	/**
1308
+	 * @param int $TKT_ID
1309
+	 * @return bool|int
1310
+	 * @throws EE_Error
1311
+	 * @throws ReflectionException
1312
+	 */
1313
+	protected function _delete_the_ticket($TKT_ID)
1314
+	{
1315
+		$ticket = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1316
+		$ticket->_remove_relations('Datetime');
1317
+		// delete all related prices first
1318
+		$ticket->delete_related_permanently('Price');
1319
+		return $ticket->delete_permanently();
1320
+	}
1321 1321
 }
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -24,10 +24,10 @@  discard block
 block discarded – undo
24 24
     public function __construct($routing = true)
25 25
     {
26 26
         parent::__construct($routing);
27
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
29
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
30
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
27
+        if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) {
28
+            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'events/templates/');
29
+            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'events/assets/');
30
+            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'events/assets/');
31 31
         }
32 32
     }
33 33
 
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
      */
40 40
     protected function _extend_page_config()
41 41
     {
42
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
42
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'events';
43 43
         // is there a evt_id in the request?
44 44
         $EVT_ID             = $this->request->getRequestParam('EVT_ID', 0, 'int');
45 45
         $EVT_ID             = $this->request->getRequestParam('post', $EVT_ID, 'int');
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
             // 'help_tour'     => array('Templates_Help_Tour'),
169 169
             'require_nonce' => false,
170 170
         ];
171
-        $this->_page_config                   = array_merge($this->_page_config, $new_page_config);
171
+        $this->_page_config = array_merge($this->_page_config, $new_page_config);
172 172
         // add filters and actions
173 173
         // modifying _views
174 174
         add_filter(
@@ -245,12 +245,12 @@  discard block
 block discarded – undo
245 245
     {
246 246
         $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
247 247
         // make sure this is only when editing
248
-        if (! empty($id)) {
249
-            $href   = EE_Admin_Page::add_query_args_and_nonce(
248
+        if ( ! empty($id)) {
249
+            $href = EE_Admin_Page::add_query_args_and_nonce(
250 250
                 ['action' => 'duplicate_event', 'EVT_ID' => $id],
251 251
                 $this->_admin_base_url
252 252
             );
253
-            $title  = esc_attr__('Duplicate Event', 'event_espresso');
253
+            $title = esc_attr__('Duplicate Event', 'event_espresso');
254 254
             $return .= '<a href="'
255 255
                        . $href
256 256
                        . '" title="'
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
     {
298 298
         wp_register_script(
299 299
             'ee-event-editor-heartbeat',
300
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
300
+            EVENTS_CAF_ASSETS_URL.'event-editor-heartbeat.js',
301 301
             ['ee_admin_js', 'heartbeat'],
302 302
             EVENT_ESPRESSO_VERSION,
303 303
             true
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
     public function add_additional_datetime_button($template, $template_args)
322 322
     {
323 323
         return EEH_Template::display_template(
324
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
324
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_add_additional_time.template.php',
325 325
             $template_args,
326 326
             true
327 327
         );
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
     public function add_datetime_clone_button($template, $template_args)
340 340
     {
341 341
         return EEH_Template::display_template(
342
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
342
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_metabox_clone_button.template.php',
343 343
             $template_args,
344 344
             true
345 345
         );
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
     public function datetime_timezones_template($template, $template_args)
358 358
     {
359 359
         return EEH_Template::display_template(
360
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
360
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_timezones.template.php',
361 361
             $template_args,
362 362
             true
363 363
         );
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
     protected function _set_list_table_views_default()
373 373
     {
374 374
         parent::_set_list_table_views_default();
375
-        $new_views    = [
375
+        $new_views = [
376 376
             'today' => [
377 377
                 'slug'        => 'today',
378 378
                 'label'       => esc_html__('Today', 'event_espresso'),
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
         // first make sure the ID for the event is in the request.
484 484
         //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
485 485
         $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
486
-        if (! $EVT_ID) {
486
+        if ( ! $EVT_ID) {
487 487
             EE_Error::add_error(
488 488
                 esc_html__(
489 489
                     'In order to duplicate an event an Event ID is required.  None was given.',
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
         }
499 499
         // k we've got EVT_ID so let's use that to get the event we'll duplicate
500 500
         $orig_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
501
-        if (! $orig_event instanceof EE_Event) {
501
+        if ( ! $orig_event instanceof EE_Event) {
502 502
             throw new EE_Error(
503 503
                 sprintf(
504 504
                     esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
         $orig_ven = $orig_event->get_many_related('Venue');
515 515
         // reset the ID and modify other details to make it clear this is a dupe
516 516
         $new_event->set('EVT_ID', 0);
517
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
517
+        $new_name = $new_event->name().' '.esc_html__('**DUPLICATE**', 'event_espresso');
518 518
         $new_event->set('EVT_name', $new_name);
519 519
         $new_event->set(
520 520
             'EVT_slug',
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
             'Question_Group',
544 544
             [['Event_Question_Group.EQG_primary' => true]]
545 545
         );
546
-        if (! empty($orig_primary_qgs)) {
546
+        if ( ! empty($orig_primary_qgs)) {
547 547
             foreach ($orig_primary_qgs as $obj) {
548 548
                 if ($obj instanceof EE_Question_Group) {
549 549
                     $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_primary' => true]);
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
             'Question_Group',
556 556
             [['Event_Question_Group.EQG_additional' => true]]
557 557
         );
558
-        if (! empty($orig_additional_qgs)) {
558
+        if ( ! empty($orig_additional_qgs)) {
559 559
             foreach ($orig_additional_qgs as $obj) {
560 560
                 if ($obj instanceof EE_Question_Group) {
561 561
                     $new_event->_add_relation_to($obj, 'Question_Group', ['EQG_additional' => true]);
@@ -568,7 +568,7 @@  discard block
 block discarded – undo
568 568
         // k now that we have the new event saved we can loop through the datetimes and start adding relations.
569 569
         $cloned_tickets = [];
570 570
         foreach ($orig_datetimes as $orig_dtt) {
571
-            if (! $orig_dtt instanceof EE_Datetime) {
571
+            if ( ! $orig_dtt instanceof EE_Datetime) {
572 572
                 continue;
573 573
             }
574 574
             $new_dtt      = clone $orig_dtt;
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
             // now let's get the ticket relations setup.
584 584
             foreach ((array) $orig_tickets as $orig_ticket) {
585 585
                 // it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
586
-                if (! $orig_ticket instanceof EE_Ticket) {
586
+                if ( ! $orig_ticket instanceof EE_Ticket) {
587 587
                     continue;
588 588
                 }
589 589
                 // is this ticket archived?  If it is then let's skip
@@ -592,8 +592,8 @@  discard block
 block discarded – undo
592 592
                 }
593 593
                 // does this original ticket already exist in the clone_tickets cache?
594 594
                 //  If so we'll just use the new ticket from it.
595
-                if (isset($cloned_tickets[ $orig_ticket->ID() ])) {
596
-                    $new_ticket = $cloned_tickets[ $orig_ticket->ID() ];
595
+                if (isset($cloned_tickets[$orig_ticket->ID()])) {
596
+                    $new_ticket = $cloned_tickets[$orig_ticket->ID()];
597 597
                 } else {
598 598
                     $new_ticket = clone $orig_ticket;
599 599
                     // get relations on the $orig_ticket that we need to setup.
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
                 // for use with later datetimes that have the same ticket.
627 627
                 $new_dtt->_add_relation_to($new_ticket, 'Ticket');
628 628
                 $new_dtt->save();
629
-                $cloned_tickets[ $orig_ticket->ID() ] = $new_ticket;
629
+                $cloned_tickets[$orig_ticket->ID()] = $new_ticket;
630 630
             }
631 631
         }
632 632
         // clone taxonomy information
@@ -707,12 +707,12 @@  discard block
 block discarded – undo
707 707
             $type
708 708
         );
709 709
 
710
-        $this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
710
+        $this->_template_args['sample_file_link'] = EE_Admin_Page::add_query_args_and_nonce(
711 711
             ['action' => 'sample_export_file'],
712 712
             $this->_admin_base_url
713 713
         );
714 714
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
715
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
715
+            EVENTS_CAF_TEMPLATE_PATH.'import_page.template.php',
716 716
             $this->_template_args,
717 717
             true
718 718
         );
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
      */
730 730
     protected function _import_events()
731 731
     {
732
-        require_once(EE_CLASSES . 'EE_Import.class.php');
732
+        require_once(EE_CLASSES.'EE_Import.class.php');
733 733
         $success = EE_Import::instance()->import();
734 734
         $this->_redirect_after_action(
735 735
             $success,
@@ -759,8 +759,8 @@  discard block
 block discarded – undo
759 759
                 'EVT_ID' => $EVT_ID,
760 760
             ]
761 761
         );
762
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
763
-            require_once(EE_CLASSES . 'EE_Export.class.php');
762
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
763
+            require_once(EE_CLASSES.'EE_Export.class.php');
764 764
             $EE_Export = EE_Export::instance($this->request->requestParams());
765 765
             $EE_Export->export();
766 766
         }
@@ -782,8 +782,8 @@  discard block
 block discarded – undo
782 782
                 'EVT_ID' => $EVT_ID,
783 783
             ]
784 784
         );
785
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
786
-            require_once(EE_CLASSES . 'EE_Export.class.php');
785
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
786
+            require_once(EE_CLASSES.'EE_Export.class.php');
787 787
             $EE_Export = EE_Export::instance($this->request->requestParams());
788 788
             $EE_Export->export();
789 789
         }
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
         $this->_set_add_edit_form_tags('update_template_settings');
822 822
         $this->_set_publish_post_box_vars(null, false, false, null, false);
823 823
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
824
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
824
+            EVENTS_CAF_TEMPLATE_PATH.'template_settings.template.php',
825 825
             $this->_template_args,
826 826
             true
827 827
         );
@@ -924,17 +924,17 @@  discard block
 block discarded – undo
924 924
         $template_args['_event']           = $this->_cpt_model_obj;
925 925
         $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
926 926
 
927
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
927
+        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
928 928
             'default_reg_status',
929 929
             $default_reg_status_values,
930 930
             $this->_cpt_model_obj->default_registration_status()
931 931
         );
932
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
932
+        $template_args['display_description'] = EEH_Form_Fields::select_input(
933 933
             'display_desc',
934 934
             $yes_no_values,
935 935
             $this->_cpt_model_obj->display_description()
936 936
         );
937
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
937
+        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
938 938
             'display_ticket_selector',
939 939
             $yes_no_values,
940 940
             $this->_cpt_model_obj->display_ticket_selector(),
@@ -955,7 +955,7 @@  discard block
 block discarded – undo
955 955
             $default_reg_status_values
956 956
         );
957 957
         EEH_Template::display_template(
958
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
958
+            EVENTS_CAF_TEMPLATE_PATH.'event_registration_options.template.php',
959 959
             $template_args
960 960
         );
961 961
     }
@@ -1050,7 +1050,7 @@  discard block
 block discarded – undo
1050 1050
         $venues = EEM_Venue::instance()->get_all(['order_by' => ['VNU_name' => 'ASC']]);
1051 1051
 
1052 1052
         foreach ($venues as $venue) {
1053
-            $values[ $venue->ID() ] = $venue->name();
1053
+            $values[$venue->ID()] = $venue->name();
1054 1054
         }
1055 1055
 
1056 1056
         return EEH_Form_Fields::select_input('venue', $values, $current_value, '', 'wide');
@@ -1084,13 +1084,13 @@  discard block
 block discarded – undo
1084 1084
     {
1085 1085
         $start = EEM_Datetime::instance()->convert_datetime_for_query(
1086 1086
             'DTT_EVT_start',
1087
-            date('Y-m-d') . ' 00:00:00',
1087
+            date('Y-m-d').' 00:00:00',
1088 1088
             'Y-m-d H:i:s',
1089 1089
             'UTC'
1090 1090
         );
1091
-        $end   = EEM_Datetime::instance()->convert_datetime_for_query(
1091
+        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1092 1092
             'DTT_EVT_start',
1093
-            date('Y-m-d') . ' 23:59:59',
1093
+            date('Y-m-d').' 23:59:59',
1094 1094
             'Y-m-d H:i:s',
1095 1095
             'UTC'
1096 1096
         );
@@ -1116,17 +1116,17 @@  discard block
 block discarded – undo
1116 1116
         $days_this_month = date('t');
1117 1117
         $start           = EEM_Datetime::instance()->convert_datetime_for_query(
1118 1118
             'DTT_EVT_start',
1119
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1119
+            $this_year_r.'-'.$this_month_r.'-01 00:00:00',
1120 1120
             'Y-m-d H:i:s',
1121 1121
             'UTC'
1122 1122
         );
1123
-        $end             = EEM_Datetime::instance()->convert_datetime_for_query(
1123
+        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1124 1124
             'DTT_EVT_start',
1125
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1125
+            $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' 23:59:59',
1126 1126
             'Y-m-d H:i:s',
1127 1127
             'UTC'
1128 1128
         );
1129
-        $where           = [
1129
+        $where = [
1130 1130
             'Datetime.DTT_EVT_start' => ['BETWEEN', [$start, $end]],
1131 1131
         ];
1132 1132
         return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
@@ -1190,7 +1190,7 @@  discard block
 block discarded – undo
1190 1190
 
1191 1191
         $search_term = $this->request->getRequestParam('s');
1192 1192
         if ($search_term) {
1193
-            $search_term = '%' . $search_term . '%';
1193
+            $search_term = '%'.$search_term.'%';
1194 1194
             $where['OR'] = [
1195 1195
                 'TKT_name'        => ['LIKE', $search_term],
1196 1196
                 'TKT_description' => ['LIKE', $search_term],
@@ -1220,17 +1220,17 @@  discard block
 block discarded – undo
1220 1220
         $TKT     = EEM_Ticket::instance();
1221 1221
         // checkboxes?
1222 1222
         $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1223
-        if (! empty($checkboxes)) {
1223
+        if ( ! empty($checkboxes)) {
1224 1224
             // if array has more than one element then success message should be plural
1225 1225
             $success = count($checkboxes) > 1 ? 2 : 1;
1226 1226
             // cycle thru the boxes
1227 1227
             while (list($TKT_ID, $value) = each($checkboxes)) {
1228 1228
                 if ($trash) {
1229
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1229
+                    if ( ! $TKT->delete_by_ID($TKT_ID)) {
1230 1230
                         $success = 0;
1231 1231
                     }
1232 1232
                 } else {
1233
-                    if (! $TKT->restore_by_ID($TKT_ID)) {
1233
+                    if ( ! $TKT->restore_by_ID($TKT_ID)) {
1234 1234
                         $success = 0;
1235 1235
                     }
1236 1236
                 }
@@ -1239,11 +1239,11 @@  discard block
 block discarded – undo
1239 1239
             // grab single id and trash
1240 1240
             $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1241 1241
             if ($trash) {
1242
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1242
+                if ( ! $TKT->delete_by_ID($TKT_ID)) {
1243 1243
                     $success = 0;
1244 1244
                 }
1245 1245
             } else {
1246
-                if (! $TKT->restore_by_ID($TKT_ID)) {
1246
+                if ( ! $TKT->restore_by_ID($TKT_ID)) {
1247 1247
                     $success = 0;
1248 1248
                 }
1249 1249
             }
@@ -1268,20 +1268,20 @@  discard block
 block discarded – undo
1268 1268
         $success = 1;
1269 1269
         // checkboxes?
1270 1270
         $checkboxes = $this->request->getRequestParam('checkbox', [], 'int', true);
1271
-        if (! empty($checkboxes)) {
1271
+        if ( ! empty($checkboxes)) {
1272 1272
             // if array has more than one element then success message should be plural
1273 1273
             $success = count($checkboxes) > 1 ? 2 : 1;
1274 1274
             // cycle thru the boxes
1275 1275
             while (list($TKT_ID, $value) = each($checkboxes)) {
1276 1276
                 // delete
1277
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1277
+                if ( ! $this->_delete_the_ticket($TKT_ID)) {
1278 1278
                     $success = 0;
1279 1279
                 }
1280 1280
             }
1281 1281
         } else {
1282 1282
             // grab single id and trash
1283 1283
             $TKT_ID = $this->request->getRequestParam('TKT_ID', 0, 'int');
1284
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1284
+            if ( ! $this->_delete_the_ticket($TKT_ID)) {
1285 1285
                 $success = 0;
1286 1286
             }
1287 1287
         }
Please login to merge, or discard this patch.
core/services/request/RequestParams.php 1 patch
Indentation   +323 added lines, -323 removed lines patch added patch discarded remove patch
@@ -14,327 +14,327 @@
 block discarded – undo
14 14
 class RequestParams
15 15
 {
16 16
 
17
-    /**
18
-     * $_GET parameters
19
-     *
20
-     * @var array
21
-     */
22
-    protected $get;
23
-
24
-    /**
25
-     * $_POST parameters
26
-     *
27
-     * @var array
28
-     */
29
-    protected $post;
30
-
31
-    /**
32
-     * $_REQUEST parameters
33
-     *
34
-     * @var array
35
-     */
36
-    protected $request;
37
-
38
-    /**
39
-     * @var RequestSanitizer
40
-     */
41
-    protected $sanitizer;
42
-
43
-
44
-    /**
45
-     * RequestParams constructor.
46
-     *
47
-     * @param RequestSanitizer $sanitizer
48
-     * @param array            $get
49
-     * @param array            $post
50
-     */
51
-    public function __construct(RequestSanitizer $sanitizer, array $get = [], array $post = [])
52
-    {
53
-        $this->sanitizer = $sanitizer;
54
-        $this->get       = ! empty($get) ? $get : $_GET;
55
-        $this->post      = ! empty($post) ? $post : $_POST;
56
-        $this->request   = array_merge($this->get, $this->post);
57
-    }
58
-
59
-
60
-    /**
61
-     * @return array
62
-     */
63
-    public function getParams()
64
-    {
65
-        return $this->get;
66
-    }
67
-
68
-
69
-    /**
70
-     * @return array
71
-     */
72
-    public function postParams()
73
-    {
74
-        return $this->post;
75
-    }
76
-
77
-
78
-    /**
79
-     * returns contents of $_REQUEST
80
-     *
81
-     * @return array
82
-     */
83
-    public function requestParams()
84
-    {
85
-        return $this->request;
86
-    }
87
-
88
-
89
-    /**
90
-     * @param string     $key
91
-     * @param mixed|null $value
92
-     * @param bool       $override_ee
93
-     * @return    void
94
-     */
95
-    public function setRequestParam($key, $value, $override_ee = false)
96
-    {
97
-        // don't allow "ee" to be overwritten unless explicitly instructed to do so
98
-        if ($override_ee || $key !== 'ee' || empty($this->request['ee'])) {
99
-            $this->request[ $key ] = $value;
100
-        }
101
-    }
102
-
103
-
104
-    /**
105
-     * merges the incoming array of parameters into the existing request parameters
106
-     *
107
-     * @param array $request_params
108
-     * @return void
109
-     * @since   4.10.24.p
110
-     */
111
-    public function mergeRequestParams(array $request_params)
112
-    {
113
-        $this->request = array_merge($this->request, $request_params);
114
-    }
115
-
116
-
117
-    /**
118
-     * returns   the value for a request param if the given key exists
119
-     *
120
-     * @param string     $key
121
-     * @param mixed|null $default
122
-     * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
123
-     * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
124
-     * @param string     $delimiter for CSV type strings that should be returned as an array
125
-     * @return array|bool|float|int|string
126
-     */
127
-    public function getRequestParam($key, $default = null, $type = 'string', $is_array = false, $delimiter = '')
128
-    {
129
-        return $this->sanitizer->clean(
130
-            $this->parameterDrillDown($key, $default, 'get'),
131
-            $type,
132
-            $is_array,
133
-            $delimiter
134
-        );
135
-    }
136
-
137
-
138
-    /**
139
-     * check if param exists
140
-     *
141
-     * @param string $key
142
-     * @return bool
143
-     */
144
-    public function requestParamIsSet($key)
145
-    {
146
-        return (bool) $this->parameterDrillDown($key);
147
-    }
148
-
149
-
150
-    /**
151
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
152
-     * and return the value for the first match found
153
-     * wildcards can be either of the following:
154
-     *      ? to represent a single character of any type
155
-     *      * to represent one or more characters of any type
156
-     *
157
-     * @param string     $pattern
158
-     * @param mixed|null $default
159
-     * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
160
-     * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
161
-     * @param string     $delimiter for CSV type strings that should be returned as an array
162
-     * @return array|bool|float|int|string
163
-     */
164
-    public function getMatch($pattern, $default = null, $type = 'string', $is_array = false, $delimiter = '')
165
-    {
166
-        return $this->sanitizer->clean(
167
-            $this->parameterDrillDown($pattern, $default, 'match'),
168
-            $type,
169
-            $is_array,
170
-            $delimiter
171
-        );
172
-    }
173
-
174
-
175
-    /**
176
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
177
-     * wildcards can be either of the following:
178
-     *      ? to represent a single character of any type
179
-     *      * to represent one or more characters of any type
180
-     * returns true if a match is found or false if not
181
-     *
182
-     * @param string $pattern
183
-     * @return bool
184
-     */
185
-    public function matches($pattern)
186
-    {
187
-        return (bool) $this->parameterDrillDown($pattern, false, 'match', 'bool');
188
-    }
189
-
190
-
191
-    /**
192
-     * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
193
-     * @param string $pattern               A string including wildcards to be converted to a regex pattern
194
-     *                                      and used to search through the current request's parameter keys
195
-     * @param array  $request_params        The array of request parameters to search through
196
-     * @param mixed  $default               [optional] The value to be returned if no match is found.
197
-     *                                      Default is null
198
-     * @param string $return                [optional] Controls what kind of value is returned.
199
-     *                                      Options are:
200
-     *                                      'bool' will return true or false if match is found or not
201
-     *                                      'key' will return the first key found that matches the supplied pattern
202
-     *                                      'value' will return the value for the first request parameter
203
-     *                                      whose key matches the supplied pattern
204
-     *                                      Default is 'value'
205
-     * @return boolean|string
206
-     */
207
-    private function match($pattern, array $request_params, $default = null, $return = 'value')
208
-    {
209
-        $return = in_array($return, ['bool', 'key', 'value'], true)
210
-            ? $return
211
-            : 'is_set';
212
-        // replace wildcard chars with regex chars
213
-        $pattern = str_replace(
214
-            ['\*', '\?'],
215
-            ['.*', '.'],
216
-            preg_quote($pattern, '/')
217
-        );
218
-        foreach ($request_params as $key => $request_param) {
219
-            if (preg_match('/^' . $pattern . '$/is', $key)) {
220
-                // return value for request param
221
-                if ($return === 'value') {
222
-                    return $request_param;
223
-                }
224
-                // or actual key or true just to indicate it was found
225
-                return $return === 'key' ? $key : true;
226
-            }
227
-        }
228
-        // match not found so return default value or false
229
-        return $return === 'value' ? $default : false;
230
-    }
231
-
232
-
233
-    /**
234
-     * the supplied key can be a simple string to represent a "top-level" request parameter
235
-     * or represent a key for a request parameter that is nested deeper within the request parameter array,
236
-     * by using square brackets to surround keys for deeper array elements.
237
-     * For example :
238
-     * if the supplied $key was: "first[second][third]"
239
-     * then this will attempt to drill down into the request parameter array to find a value.
240
-     * Given the following request parameters:
241
-     *  array(
242
-     *      'first' => array(
243
-     *          'second' => array(
244
-     *              'third' => 'has a value'
245
-     *          )
246
-     *      )
247
-     *  )
248
-     * would return true if default parameters were set
249
-     *
250
-     * @param string $callback
251
-     * @param        $key
252
-     * @param null   $default
253
-     * @param string $return
254
-     * @param mixed  $request_params
255
-     * @return bool|mixed|null
256
-     */
257
-    private function parameterDrillDown(
258
-        $key,
259
-        $default = null,
260
-        $callback = 'is_set',
261
-        $return = 'value',
262
-        $request_params = []
263
-    ) {
264
-        $callback       = in_array($callback, ['is_set', 'get', 'match'], true)
265
-            ? $callback
266
-            : 'is_set';
267
-        $request_params = ! empty($request_params)
268
-            ? $request_params
269
-            : $this->request;
270
-        // does incoming key represent an array like 'first[second][third]'  ?
271
-        if (strpos($key, '[') !== false) {
272
-            // turn it into an actual array
273
-            $key  = str_replace(']', '', $key);
274
-            $keys = explode('[', $key);
275
-            $key  = array_shift($keys);
276
-            if ($callback === 'match') {
277
-                $real_key = $this->match($key, $request_params, $default, 'key');
278
-                $key      = $real_key ?: $key;
279
-            }
280
-            // check if top level key exists
281
-            if (isset($request_params[ $key ])) {
282
-                // build a new key to pass along like: 'second[third]'
283
-                // or just 'second' depending on depth of keys
284
-                $key_string = array_shift($keys);
285
-                if (! empty($keys)) {
286
-                    $key_string .= '[' . implode('][', $keys) . ']';
287
-                }
288
-                return $this->parameterDrillDown(
289
-                    $key_string,
290
-                    $default,
291
-                    $callback,
292
-                    $return,
293
-                    $request_params[ $key ]
294
-                );
295
-            }
296
-        }
297
-        if ($callback === 'is_set') {
298
-            return isset($request_params[ $key ]);
299
-        }
300
-        if ($callback === 'match') {
301
-            return $this->match($key, $request_params, $default, $return);
302
-        }
303
-        return isset($request_params[ $key ])
304
-            ? $request_params[ $key ]
305
-            : $default;
306
-    }
307
-
308
-
309
-    /**
310
-     * remove param
311
-     *
312
-     * @param      $key
313
-     * @param bool $unset_from_global_too
314
-     */
315
-    public function unSetRequestParam($key, $unset_from_global_too = false)
316
-    {
317
-        // because unset may not actually remove var
318
-        $this->get[ $key ]     = null;
319
-        $this->post[ $key ]    = null;
320
-        $this->request[ $key ] = null;
321
-        unset($this->get[ $key ], $this->post[ $key ], $this->request[ $key ]);
322
-        if ($unset_from_global_too) {
323
-            unset($_GET[ $key ], $_POST[ $key ], $_REQUEST[ $key ]);
324
-        }
325
-    }
326
-
327
-
328
-    /**
329
-     * remove params
330
-     *
331
-     * @param array $keys
332
-     * @param bool  $unset_from_global_too
333
-     */
334
-    public function unSetRequestParams(array $keys, $unset_from_global_too = false)
335
-    {
336
-        foreach ($keys as $key) {
337
-            $this->unSetRequestParam($key, $unset_from_global_too);
338
-        }
339
-    }
17
+	/**
18
+	 * $_GET parameters
19
+	 *
20
+	 * @var array
21
+	 */
22
+	protected $get;
23
+
24
+	/**
25
+	 * $_POST parameters
26
+	 *
27
+	 * @var array
28
+	 */
29
+	protected $post;
30
+
31
+	/**
32
+	 * $_REQUEST parameters
33
+	 *
34
+	 * @var array
35
+	 */
36
+	protected $request;
37
+
38
+	/**
39
+	 * @var RequestSanitizer
40
+	 */
41
+	protected $sanitizer;
42
+
43
+
44
+	/**
45
+	 * RequestParams constructor.
46
+	 *
47
+	 * @param RequestSanitizer $sanitizer
48
+	 * @param array            $get
49
+	 * @param array            $post
50
+	 */
51
+	public function __construct(RequestSanitizer $sanitizer, array $get = [], array $post = [])
52
+	{
53
+		$this->sanitizer = $sanitizer;
54
+		$this->get       = ! empty($get) ? $get : $_GET;
55
+		$this->post      = ! empty($post) ? $post : $_POST;
56
+		$this->request   = array_merge($this->get, $this->post);
57
+	}
58
+
59
+
60
+	/**
61
+	 * @return array
62
+	 */
63
+	public function getParams()
64
+	{
65
+		return $this->get;
66
+	}
67
+
68
+
69
+	/**
70
+	 * @return array
71
+	 */
72
+	public function postParams()
73
+	{
74
+		return $this->post;
75
+	}
76
+
77
+
78
+	/**
79
+	 * returns contents of $_REQUEST
80
+	 *
81
+	 * @return array
82
+	 */
83
+	public function requestParams()
84
+	{
85
+		return $this->request;
86
+	}
87
+
88
+
89
+	/**
90
+	 * @param string     $key
91
+	 * @param mixed|null $value
92
+	 * @param bool       $override_ee
93
+	 * @return    void
94
+	 */
95
+	public function setRequestParam($key, $value, $override_ee = false)
96
+	{
97
+		// don't allow "ee" to be overwritten unless explicitly instructed to do so
98
+		if ($override_ee || $key !== 'ee' || empty($this->request['ee'])) {
99
+			$this->request[ $key ] = $value;
100
+		}
101
+	}
102
+
103
+
104
+	/**
105
+	 * merges the incoming array of parameters into the existing request parameters
106
+	 *
107
+	 * @param array $request_params
108
+	 * @return void
109
+	 * @since   4.10.24.p
110
+	 */
111
+	public function mergeRequestParams(array $request_params)
112
+	{
113
+		$this->request = array_merge($this->request, $request_params);
114
+	}
115
+
116
+
117
+	/**
118
+	 * returns   the value for a request param if the given key exists
119
+	 *
120
+	 * @param string     $key
121
+	 * @param mixed|null $default
122
+	 * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
123
+	 * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
124
+	 * @param string     $delimiter for CSV type strings that should be returned as an array
125
+	 * @return array|bool|float|int|string
126
+	 */
127
+	public function getRequestParam($key, $default = null, $type = 'string', $is_array = false, $delimiter = '')
128
+	{
129
+		return $this->sanitizer->clean(
130
+			$this->parameterDrillDown($key, $default, 'get'),
131
+			$type,
132
+			$is_array,
133
+			$delimiter
134
+		);
135
+	}
136
+
137
+
138
+	/**
139
+	 * check if param exists
140
+	 *
141
+	 * @param string $key
142
+	 * @return bool
143
+	 */
144
+	public function requestParamIsSet($key)
145
+	{
146
+		return (bool) $this->parameterDrillDown($key);
147
+	}
148
+
149
+
150
+	/**
151
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
152
+	 * and return the value for the first match found
153
+	 * wildcards can be either of the following:
154
+	 *      ? to represent a single character of any type
155
+	 *      * to represent one or more characters of any type
156
+	 *
157
+	 * @param string     $pattern
158
+	 * @param mixed|null $default
159
+	 * @param string     $type      the expected data type for the parameter's value, ie: string, int, bool, etc
160
+	 * @param bool       $is_array  if true, then parameter value will be treated as an array of $type
161
+	 * @param string     $delimiter for CSV type strings that should be returned as an array
162
+	 * @return array|bool|float|int|string
163
+	 */
164
+	public function getMatch($pattern, $default = null, $type = 'string', $is_array = false, $delimiter = '')
165
+	{
166
+		return $this->sanitizer->clean(
167
+			$this->parameterDrillDown($pattern, $default, 'match'),
168
+			$type,
169
+			$is_array,
170
+			$delimiter
171
+		);
172
+	}
173
+
174
+
175
+	/**
176
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
177
+	 * wildcards can be either of the following:
178
+	 *      ? to represent a single character of any type
179
+	 *      * to represent one or more characters of any type
180
+	 * returns true if a match is found or false if not
181
+	 *
182
+	 * @param string $pattern
183
+	 * @return bool
184
+	 */
185
+	public function matches($pattern)
186
+	{
187
+		return (bool) $this->parameterDrillDown($pattern, false, 'match', 'bool');
188
+	}
189
+
190
+
191
+	/**
192
+	 * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
193
+	 * @param string $pattern               A string including wildcards to be converted to a regex pattern
194
+	 *                                      and used to search through the current request's parameter keys
195
+	 * @param array  $request_params        The array of request parameters to search through
196
+	 * @param mixed  $default               [optional] The value to be returned if no match is found.
197
+	 *                                      Default is null
198
+	 * @param string $return                [optional] Controls what kind of value is returned.
199
+	 *                                      Options are:
200
+	 *                                      'bool' will return true or false if match is found or not
201
+	 *                                      'key' will return the first key found that matches the supplied pattern
202
+	 *                                      'value' will return the value for the first request parameter
203
+	 *                                      whose key matches the supplied pattern
204
+	 *                                      Default is 'value'
205
+	 * @return boolean|string
206
+	 */
207
+	private function match($pattern, array $request_params, $default = null, $return = 'value')
208
+	{
209
+		$return = in_array($return, ['bool', 'key', 'value'], true)
210
+			? $return
211
+			: 'is_set';
212
+		// replace wildcard chars with regex chars
213
+		$pattern = str_replace(
214
+			['\*', '\?'],
215
+			['.*', '.'],
216
+			preg_quote($pattern, '/')
217
+		);
218
+		foreach ($request_params as $key => $request_param) {
219
+			if (preg_match('/^' . $pattern . '$/is', $key)) {
220
+				// return value for request param
221
+				if ($return === 'value') {
222
+					return $request_param;
223
+				}
224
+				// or actual key or true just to indicate it was found
225
+				return $return === 'key' ? $key : true;
226
+			}
227
+		}
228
+		// match not found so return default value or false
229
+		return $return === 'value' ? $default : false;
230
+	}
231
+
232
+
233
+	/**
234
+	 * the supplied key can be a simple string to represent a "top-level" request parameter
235
+	 * or represent a key for a request parameter that is nested deeper within the request parameter array,
236
+	 * by using square brackets to surround keys for deeper array elements.
237
+	 * For example :
238
+	 * if the supplied $key was: "first[second][third]"
239
+	 * then this will attempt to drill down into the request parameter array to find a value.
240
+	 * Given the following request parameters:
241
+	 *  array(
242
+	 *      'first' => array(
243
+	 *          'second' => array(
244
+	 *              'third' => 'has a value'
245
+	 *          )
246
+	 *      )
247
+	 *  )
248
+	 * would return true if default parameters were set
249
+	 *
250
+	 * @param string $callback
251
+	 * @param        $key
252
+	 * @param null   $default
253
+	 * @param string $return
254
+	 * @param mixed  $request_params
255
+	 * @return bool|mixed|null
256
+	 */
257
+	private function parameterDrillDown(
258
+		$key,
259
+		$default = null,
260
+		$callback = 'is_set',
261
+		$return = 'value',
262
+		$request_params = []
263
+	) {
264
+		$callback       = in_array($callback, ['is_set', 'get', 'match'], true)
265
+			? $callback
266
+			: 'is_set';
267
+		$request_params = ! empty($request_params)
268
+			? $request_params
269
+			: $this->request;
270
+		// does incoming key represent an array like 'first[second][third]'  ?
271
+		if (strpos($key, '[') !== false) {
272
+			// turn it into an actual array
273
+			$key  = str_replace(']', '', $key);
274
+			$keys = explode('[', $key);
275
+			$key  = array_shift($keys);
276
+			if ($callback === 'match') {
277
+				$real_key = $this->match($key, $request_params, $default, 'key');
278
+				$key      = $real_key ?: $key;
279
+			}
280
+			// check if top level key exists
281
+			if (isset($request_params[ $key ])) {
282
+				// build a new key to pass along like: 'second[third]'
283
+				// or just 'second' depending on depth of keys
284
+				$key_string = array_shift($keys);
285
+				if (! empty($keys)) {
286
+					$key_string .= '[' . implode('][', $keys) . ']';
287
+				}
288
+				return $this->parameterDrillDown(
289
+					$key_string,
290
+					$default,
291
+					$callback,
292
+					$return,
293
+					$request_params[ $key ]
294
+				);
295
+			}
296
+		}
297
+		if ($callback === 'is_set') {
298
+			return isset($request_params[ $key ]);
299
+		}
300
+		if ($callback === 'match') {
301
+			return $this->match($key, $request_params, $default, $return);
302
+		}
303
+		return isset($request_params[ $key ])
304
+			? $request_params[ $key ]
305
+			: $default;
306
+	}
307
+
308
+
309
+	/**
310
+	 * remove param
311
+	 *
312
+	 * @param      $key
313
+	 * @param bool $unset_from_global_too
314
+	 */
315
+	public function unSetRequestParam($key, $unset_from_global_too = false)
316
+	{
317
+		// because unset may not actually remove var
318
+		$this->get[ $key ]     = null;
319
+		$this->post[ $key ]    = null;
320
+		$this->request[ $key ] = null;
321
+		unset($this->get[ $key ], $this->post[ $key ], $this->request[ $key ]);
322
+		if ($unset_from_global_too) {
323
+			unset($_GET[ $key ], $_POST[ $key ], $_REQUEST[ $key ]);
324
+		}
325
+	}
326
+
327
+
328
+	/**
329
+	 * remove params
330
+	 *
331
+	 * @param array $keys
332
+	 * @param bool  $unset_from_global_too
333
+	 */
334
+	public function unSetRequestParams(array $keys, $unset_from_global_too = false)
335
+	{
336
+		foreach ($keys as $key) {
337
+			$this->unSetRequestParam($key, $unset_from_global_too);
338
+		}
339
+	}
340 340
 }
Please login to merge, or discard this patch.
core/business/EE_Registration_Processor.class.php 2 patches
Indentation   +773 added lines, -773 removed lines patch added patch discarded remove patch
@@ -26,778 +26,778 @@
 block discarded – undo
26 26
 class EE_Registration_Processor extends EE_Processor_Base
27 27
 {
28 28
 
29
-    /**
30
-     * @var EE_Registration_Processor $_instance
31
-     * @access    private
32
-     */
33
-    private static $_instance;
34
-
35
-    /**
36
-     * initial reg status at the beginning of this request.
37
-     * indexed by registration ID
38
-     *
39
-     * @var array
40
-     */
41
-    protected $_old_reg_status = [];
42
-
43
-    /**
44
-     * reg status at the end of the request after all processing.
45
-     * indexed by registration ID
46
-     *
47
-     * @var array
48
-     */
49
-    protected $_new_reg_status = [];
50
-
51
-    /**
52
-     * amounts paid at the end of the request after all processing.
53
-     * indexed by registration ID
54
-     *
55
-     * @var array
56
-     */
57
-    protected static $_amount_paid = [];
58
-
59
-    /**
60
-     * Cache of the reg final price for registrations corresponding to a ticket line item
61
-     *
62
-     * @deprecated
63
-     * @var array @see EEH_Line_Item::calculate_reg_final_prices_per_line_item()'s return value
64
-     */
65
-    protected $_reg_final_price_per_tkt_line_item;
66
-
67
-    /**
68
-     * @var RequestInterface $request
69
-     */
70
-    protected $request;
71
-
72
-
73
-    /**
74
-     * @singleton method used to instantiate class object
75
-     * @param RequestInterface|null $request
76
-     * @return EE_Registration_Processor instance
77
-     * @throws InvalidArgumentException
78
-     * @throws InvalidInterfaceException
79
-     * @throws InvalidDataTypeException
80
-     */
81
-    public static function instance(RequestInterface $request = null)
82
-    {
83
-        // check if class object is instantiated
84
-        if (! self::$_instance instanceof EE_Registration_Processor) {
85
-            if (! $request instanceof RequestInterface) {
86
-                $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request');
87
-            }
88
-            self::$_instance = new self($request);
89
-        }
90
-        return self::$_instance;
91
-    }
92
-
93
-
94
-    /**
95
-     * EE_Registration_Processor constructor.
96
-     *
97
-     * @param RequestInterface $request
98
-     */
99
-    public function __construct(RequestInterface $request)
100
-    {
101
-        $this->request = $request;
102
-    }
103
-
104
-
105
-    /**
106
-     * @param int $REG_ID
107
-     * @return string
108
-     */
109
-    public function old_reg_status($REG_ID)
110
-    {
111
-        return isset($this->_old_reg_status[ $REG_ID ]) ? $this->_old_reg_status[ $REG_ID ] : null;
112
-    }
113
-
114
-
115
-    /**
116
-     * @param int    $REG_ID
117
-     * @param string $old_reg_status
118
-     */
119
-    public function set_old_reg_status($REG_ID, $old_reg_status)
120
-    {
121
-        // only set the first time
122
-        if (! isset($this->_old_reg_status[ $REG_ID ])) {
123
-            $this->_old_reg_status[ $REG_ID ] = $old_reg_status;
124
-        }
125
-    }
126
-
127
-
128
-    /**
129
-     * @param int $REG_ID
130
-     * @return string
131
-     */
132
-    public function new_reg_status($REG_ID)
133
-    {
134
-        return isset($this->_new_reg_status[ $REG_ID ]) ? $this->_new_reg_status[ $REG_ID ] : null;
135
-    }
136
-
137
-
138
-    /**
139
-     * @param int    $REG_ID
140
-     * @param string $new_reg_status
141
-     */
142
-    public function set_new_reg_status($REG_ID, $new_reg_status)
143
-    {
144
-        $this->_new_reg_status[ $REG_ID ] = $new_reg_status;
145
-    }
146
-
147
-
148
-    /**
149
-     * reg_status_updated
150
-     *
151
-     * @param int $REG_ID
152
-     * @return bool
153
-     */
154
-    public function reg_status_updated($REG_ID)
155
-    {
156
-        return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID);
157
-    }
158
-
159
-
160
-    /**
161
-     * @param EE_Registration $registration
162
-     * @throws EE_Error
163
-     * @throws EntityNotFoundException
164
-     * @throws InvalidArgumentException
165
-     * @throws InvalidDataTypeException
166
-     * @throws InvalidInterfaceException
167
-     * @throws ReflectionException
168
-     * @throws RuntimeException
169
-     */
170
-    public function update_registration_status_and_trigger_notifications(EE_Registration $registration)
171
-    {
172
-        $this->toggle_incomplete_registration_status_to_default($registration, false);
173
-        $this->toggle_registration_status_for_default_approved_events($registration, false);
174
-        $this->toggle_registration_status_if_no_monies_owing($registration, false);
175
-        $registration->save();
176
-        // trigger notifications
177
-        $this->trigger_registration_update_notifications($registration);
178
-    }
179
-
180
-
181
-    /**
182
-     *    manually_update_registration_status
183
-     *
184
-     * @access public
185
-     * @param EE_Registration $registration
186
-     * @param string          $new_reg_status
187
-     * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
188
-     *                              to client code
189
-     * @return bool
190
-     * @throws EE_Error
191
-     * @throws EntityNotFoundException
192
-     * @throws InvalidArgumentException
193
-     * @throws InvalidDataTypeException
194
-     * @throws InvalidInterfaceException
195
-     * @throws ReflectionException
196
-     * @throws RuntimeException
197
-     */
198
-    public function manually_update_registration_status(
199
-        EE_Registration $registration,
200
-        $new_reg_status = '',
201
-        $save = true
202
-    ) {
203
-        // set initial REG_Status
204
-        $this->set_old_reg_status($registration->ID(), $registration->status_ID());
205
-        // set incoming REG_Status
206
-        $this->set_new_reg_status($registration->ID(), $new_reg_status);
207
-        // toggle reg status but only if it has changed and the user can do so
208
-        if (
209
-            $this->reg_status_updated($registration->ID())
210
-            && (
211
-                (! $this->request->isAdmin() || $this->request->isFrontAjax())
212
-                || EE_Registry::instance()->CAP->current_user_can(
213
-                    'ee_edit_registration',
214
-                    'toggle_registration_status',
215
-                    $registration->ID()
216
-                )
217
-            )
218
-        ) {
219
-            // change status to new value
220
-            $updated = $registration->set_status($this->new_reg_status($registration->ID()));
221
-            if ($updated && $save) {
222
-                $registration->save();
223
-            }
224
-            return true;
225
-        }
226
-        return false;
227
-    }
228
-
229
-
230
-    /**
231
-     *    toggle_incomplete_registration_status_to_default
232
-     *        changes any incomplete registrations to either the event or global default registration status
233
-     *
234
-     * @access public
235
-     * @param EE_Registration       $registration
236
-     * @param bool                  $save TRUE will save the registration if the status is updated, FALSE will leave
237
-     *                                    that up to client code
238
-     * @param ContextInterface|null $context
239
-     * @return void
240
-     * @throws EE_Error
241
-     * @throws InvalidArgumentException
242
-     * @throws ReflectionException
243
-     * @throws RuntimeException
244
-     * @throws EntityNotFoundException
245
-     * @throws InvalidDataTypeException
246
-     * @throws InvalidInterfaceException
247
-     */
248
-    public function toggle_incomplete_registration_status_to_default(
249
-        EE_Registration $registration,
250
-        $save = true,
251
-        ContextInterface $context = null
252
-    ) {
253
-        $existing_reg_status = $registration->status_ID();
254
-        // set initial REG_Status
255
-        $this->set_old_reg_status($registration->ID(), $existing_reg_status);
256
-        // is the registration currently incomplete ?
257
-        if ($registration->status_ID() === EEM_Registration::status_id_incomplete) {
258
-            // grab default reg status for the event, if set
259
-            $event_default_registration_status = $registration->event()->default_registration_status();
260
-            // if no default reg status is set for the event, then use the global value
261
-            $STS_ID = ! empty($event_default_registration_status)
262
-                ? $event_default_registration_status
263
-                : EE_Registry::instance()->CFG->registration->default_STS_ID;
264
-            // if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered
265
-            $STS_ID = $STS_ID === EEM_Registration::status_id_approved ? EEM_Registration::status_id_pending_payment
266
-                : $STS_ID;
267
-            // set incoming REG_Status
268
-            $this->set_new_reg_status($registration->ID(), $STS_ID);
269
-            $registration->set_status($STS_ID, false, $context);
270
-            if ($save) {
271
-                $registration->save();
272
-            }
273
-            // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
274
-            if (! EE_Processor_Base::$IPN) {
275
-                // otherwise, send out notifications
276
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
277
-            }
278
-            // DEBUG LOG
279
-            // $this->log(
280
-            //     __CLASS__,
281
-            //     __FUNCTION__,
282
-            //     __LINE__,
283
-            //     $registration->transaction(),
284
-            //     array(
285
-            //         'IPN' => EE_Processor_Base::$IPN,
286
-            //         'deliver_notifications' => has_filter(
287
-            //             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
288
-            //         ),
289
-            //     )
290
-            // );
291
-        }
292
-    }
293
-
294
-
295
-    /**
296
-     *    toggle_registration_status_for_default_approved_events
297
-     *
298
-     * @access public
299
-     * @param EE_Registration $registration
300
-     * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
301
-     *                              to client code
302
-     * @return bool
303
-     * @throws EE_Error
304
-     * @throws EntityNotFoundException
305
-     * @throws InvalidArgumentException
306
-     * @throws InvalidDataTypeException
307
-     * @throws InvalidInterfaceException
308
-     * @throws ReflectionException
309
-     * @throws RuntimeException
310
-     */
311
-    public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = true)
312
-    {
313
-        $reg_status = $registration->status_ID();
314
-        // set initial REG_Status
315
-        $this->set_old_reg_status($registration->ID(), $reg_status);
316
-        // if not already, toggle reg status to approved IF the event default reg status is approved
317
-        // ( as long as the registration wasn't cancelled or declined at some point )
318
-        if (
319
-            $reg_status !== EEM_Registration::status_id_cancelled
320
-            && $reg_status
321
-               !== EEM_Registration::status_id_declined
322
-            && $reg_status !== EEM_Registration::status_id_approved
323
-            && $registration->event()->default_registration_status() === EEM_Registration::status_id_approved
324
-        ) {
325
-            // set incoming REG_Status
326
-            $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
327
-            // toggle status to approved
328
-            $registration->set_status(EEM_Registration::status_id_approved);
329
-            if ($save) {
330
-                $registration->save();
331
-            }
332
-            // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
333
-            if (! EE_Processor_Base::$IPN) {
334
-                // otherwise, send out notifications
335
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
336
-            }
337
-            // DEBUG LOG
338
-            // $this->log(
339
-            //     __CLASS__,
340
-            //     __FUNCTION__,
341
-            //     __LINE__,
342
-            //     $registration->transaction(),
343
-            //     array(
344
-            //         'IPN' => EE_Processor_Base::$IPN,
345
-            //         'deliver_notifications' => has_filter(
346
-            //             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
347
-            //         ),
348
-            //     )
349
-            // );
350
-            return true;
351
-        }
352
-        return false;
353
-    }
354
-
355
-
356
-    /**
357
-     *    toggle_registration_statuses_if_no_monies_owing
358
-     *
359
-     * @access public
360
-     * @param EE_Registration $registration
361
-     * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
362
-     *                              to client code
363
-     * @param array           $additional_details
364
-     * @return bool
365
-     * @throws EE_Error
366
-     * @throws EntityNotFoundException
367
-     * @throws InvalidArgumentException
368
-     * @throws InvalidDataTypeException
369
-     * @throws InvalidInterfaceException
370
-     * @throws ReflectionException
371
-     * @throws RuntimeException
372
-     */
373
-    public function toggle_registration_status_if_no_monies_owing(
374
-        EE_Registration $registration,
375
-        $save = true,
376
-        array $additional_details = []
377
-    ) {
378
-        // set initial REG_Status
379
-        $this->set_old_reg_status($registration->ID(), $registration->status_ID());
380
-        // was a payment just made ?
381
-        $payment    = isset($additional_details['payment_updates'], $additional_details['last_payment'])
382
-                      && $additional_details['payment_updates']
383
-                      && $additional_details['last_payment'] instanceof EE_Payment
384
-            ? $additional_details['last_payment']
385
-            : null;
386
-        $total_paid = array_sum(self::$_amount_paid);
387
-        // toggle reg status to approved IF
388
-        if (
29
+	/**
30
+	 * @var EE_Registration_Processor $_instance
31
+	 * @access    private
32
+	 */
33
+	private static $_instance;
34
+
35
+	/**
36
+	 * initial reg status at the beginning of this request.
37
+	 * indexed by registration ID
38
+	 *
39
+	 * @var array
40
+	 */
41
+	protected $_old_reg_status = [];
42
+
43
+	/**
44
+	 * reg status at the end of the request after all processing.
45
+	 * indexed by registration ID
46
+	 *
47
+	 * @var array
48
+	 */
49
+	protected $_new_reg_status = [];
50
+
51
+	/**
52
+	 * amounts paid at the end of the request after all processing.
53
+	 * indexed by registration ID
54
+	 *
55
+	 * @var array
56
+	 */
57
+	protected static $_amount_paid = [];
58
+
59
+	/**
60
+	 * Cache of the reg final price for registrations corresponding to a ticket line item
61
+	 *
62
+	 * @deprecated
63
+	 * @var array @see EEH_Line_Item::calculate_reg_final_prices_per_line_item()'s return value
64
+	 */
65
+	protected $_reg_final_price_per_tkt_line_item;
66
+
67
+	/**
68
+	 * @var RequestInterface $request
69
+	 */
70
+	protected $request;
71
+
72
+
73
+	/**
74
+	 * @singleton method used to instantiate class object
75
+	 * @param RequestInterface|null $request
76
+	 * @return EE_Registration_Processor instance
77
+	 * @throws InvalidArgumentException
78
+	 * @throws InvalidInterfaceException
79
+	 * @throws InvalidDataTypeException
80
+	 */
81
+	public static function instance(RequestInterface $request = null)
82
+	{
83
+		// check if class object is instantiated
84
+		if (! self::$_instance instanceof EE_Registration_Processor) {
85
+			if (! $request instanceof RequestInterface) {
86
+				$request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request');
87
+			}
88
+			self::$_instance = new self($request);
89
+		}
90
+		return self::$_instance;
91
+	}
92
+
93
+
94
+	/**
95
+	 * EE_Registration_Processor constructor.
96
+	 *
97
+	 * @param RequestInterface $request
98
+	 */
99
+	public function __construct(RequestInterface $request)
100
+	{
101
+		$this->request = $request;
102
+	}
103
+
104
+
105
+	/**
106
+	 * @param int $REG_ID
107
+	 * @return string
108
+	 */
109
+	public function old_reg_status($REG_ID)
110
+	{
111
+		return isset($this->_old_reg_status[ $REG_ID ]) ? $this->_old_reg_status[ $REG_ID ] : null;
112
+	}
113
+
114
+
115
+	/**
116
+	 * @param int    $REG_ID
117
+	 * @param string $old_reg_status
118
+	 */
119
+	public function set_old_reg_status($REG_ID, $old_reg_status)
120
+	{
121
+		// only set the first time
122
+		if (! isset($this->_old_reg_status[ $REG_ID ])) {
123
+			$this->_old_reg_status[ $REG_ID ] = $old_reg_status;
124
+		}
125
+	}
126
+
127
+
128
+	/**
129
+	 * @param int $REG_ID
130
+	 * @return string
131
+	 */
132
+	public function new_reg_status($REG_ID)
133
+	{
134
+		return isset($this->_new_reg_status[ $REG_ID ]) ? $this->_new_reg_status[ $REG_ID ] : null;
135
+	}
136
+
137
+
138
+	/**
139
+	 * @param int    $REG_ID
140
+	 * @param string $new_reg_status
141
+	 */
142
+	public function set_new_reg_status($REG_ID, $new_reg_status)
143
+	{
144
+		$this->_new_reg_status[ $REG_ID ] = $new_reg_status;
145
+	}
146
+
147
+
148
+	/**
149
+	 * reg_status_updated
150
+	 *
151
+	 * @param int $REG_ID
152
+	 * @return bool
153
+	 */
154
+	public function reg_status_updated($REG_ID)
155
+	{
156
+		return $this->new_reg_status($REG_ID) !== $this->old_reg_status($REG_ID);
157
+	}
158
+
159
+
160
+	/**
161
+	 * @param EE_Registration $registration
162
+	 * @throws EE_Error
163
+	 * @throws EntityNotFoundException
164
+	 * @throws InvalidArgumentException
165
+	 * @throws InvalidDataTypeException
166
+	 * @throws InvalidInterfaceException
167
+	 * @throws ReflectionException
168
+	 * @throws RuntimeException
169
+	 */
170
+	public function update_registration_status_and_trigger_notifications(EE_Registration $registration)
171
+	{
172
+		$this->toggle_incomplete_registration_status_to_default($registration, false);
173
+		$this->toggle_registration_status_for_default_approved_events($registration, false);
174
+		$this->toggle_registration_status_if_no_monies_owing($registration, false);
175
+		$registration->save();
176
+		// trigger notifications
177
+		$this->trigger_registration_update_notifications($registration);
178
+	}
179
+
180
+
181
+	/**
182
+	 *    manually_update_registration_status
183
+	 *
184
+	 * @access public
185
+	 * @param EE_Registration $registration
186
+	 * @param string          $new_reg_status
187
+	 * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
188
+	 *                              to client code
189
+	 * @return bool
190
+	 * @throws EE_Error
191
+	 * @throws EntityNotFoundException
192
+	 * @throws InvalidArgumentException
193
+	 * @throws InvalidDataTypeException
194
+	 * @throws InvalidInterfaceException
195
+	 * @throws ReflectionException
196
+	 * @throws RuntimeException
197
+	 */
198
+	public function manually_update_registration_status(
199
+		EE_Registration $registration,
200
+		$new_reg_status = '',
201
+		$save = true
202
+	) {
203
+		// set initial REG_Status
204
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
205
+		// set incoming REG_Status
206
+		$this->set_new_reg_status($registration->ID(), $new_reg_status);
207
+		// toggle reg status but only if it has changed and the user can do so
208
+		if (
209
+			$this->reg_status_updated($registration->ID())
210
+			&& (
211
+				(! $this->request->isAdmin() || $this->request->isFrontAjax())
212
+				|| EE_Registry::instance()->CAP->current_user_can(
213
+					'ee_edit_registration',
214
+					'toggle_registration_status',
215
+					$registration->ID()
216
+				)
217
+			)
218
+		) {
219
+			// change status to new value
220
+			$updated = $registration->set_status($this->new_reg_status($registration->ID()));
221
+			if ($updated && $save) {
222
+				$registration->save();
223
+			}
224
+			return true;
225
+		}
226
+		return false;
227
+	}
228
+
229
+
230
+	/**
231
+	 *    toggle_incomplete_registration_status_to_default
232
+	 *        changes any incomplete registrations to either the event or global default registration status
233
+	 *
234
+	 * @access public
235
+	 * @param EE_Registration       $registration
236
+	 * @param bool                  $save TRUE will save the registration if the status is updated, FALSE will leave
237
+	 *                                    that up to client code
238
+	 * @param ContextInterface|null $context
239
+	 * @return void
240
+	 * @throws EE_Error
241
+	 * @throws InvalidArgumentException
242
+	 * @throws ReflectionException
243
+	 * @throws RuntimeException
244
+	 * @throws EntityNotFoundException
245
+	 * @throws InvalidDataTypeException
246
+	 * @throws InvalidInterfaceException
247
+	 */
248
+	public function toggle_incomplete_registration_status_to_default(
249
+		EE_Registration $registration,
250
+		$save = true,
251
+		ContextInterface $context = null
252
+	) {
253
+		$existing_reg_status = $registration->status_ID();
254
+		// set initial REG_Status
255
+		$this->set_old_reg_status($registration->ID(), $existing_reg_status);
256
+		// is the registration currently incomplete ?
257
+		if ($registration->status_ID() === EEM_Registration::status_id_incomplete) {
258
+			// grab default reg status for the event, if set
259
+			$event_default_registration_status = $registration->event()->default_registration_status();
260
+			// if no default reg status is set for the event, then use the global value
261
+			$STS_ID = ! empty($event_default_registration_status)
262
+				? $event_default_registration_status
263
+				: EE_Registry::instance()->CFG->registration->default_STS_ID;
264
+			// if the event default reg status is approved, then downgrade temporarily to payment pending to ensure that payments are triggered
265
+			$STS_ID = $STS_ID === EEM_Registration::status_id_approved ? EEM_Registration::status_id_pending_payment
266
+				: $STS_ID;
267
+			// set incoming REG_Status
268
+			$this->set_new_reg_status($registration->ID(), $STS_ID);
269
+			$registration->set_status($STS_ID, false, $context);
270
+			if ($save) {
271
+				$registration->save();
272
+			}
273
+			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
274
+			if (! EE_Processor_Base::$IPN) {
275
+				// otherwise, send out notifications
276
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
277
+			}
278
+			// DEBUG LOG
279
+			// $this->log(
280
+			//     __CLASS__,
281
+			//     __FUNCTION__,
282
+			//     __LINE__,
283
+			//     $registration->transaction(),
284
+			//     array(
285
+			//         'IPN' => EE_Processor_Base::$IPN,
286
+			//         'deliver_notifications' => has_filter(
287
+			//             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
288
+			//         ),
289
+			//     )
290
+			// );
291
+		}
292
+	}
293
+
294
+
295
+	/**
296
+	 *    toggle_registration_status_for_default_approved_events
297
+	 *
298
+	 * @access public
299
+	 * @param EE_Registration $registration
300
+	 * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
301
+	 *                              to client code
302
+	 * @return bool
303
+	 * @throws EE_Error
304
+	 * @throws EntityNotFoundException
305
+	 * @throws InvalidArgumentException
306
+	 * @throws InvalidDataTypeException
307
+	 * @throws InvalidInterfaceException
308
+	 * @throws ReflectionException
309
+	 * @throws RuntimeException
310
+	 */
311
+	public function toggle_registration_status_for_default_approved_events(EE_Registration $registration, $save = true)
312
+	{
313
+		$reg_status = $registration->status_ID();
314
+		// set initial REG_Status
315
+		$this->set_old_reg_status($registration->ID(), $reg_status);
316
+		// if not already, toggle reg status to approved IF the event default reg status is approved
317
+		// ( as long as the registration wasn't cancelled or declined at some point )
318
+		if (
319
+			$reg_status !== EEM_Registration::status_id_cancelled
320
+			&& $reg_status
321
+			   !== EEM_Registration::status_id_declined
322
+			&& $reg_status !== EEM_Registration::status_id_approved
323
+			&& $registration->event()->default_registration_status() === EEM_Registration::status_id_approved
324
+		) {
325
+			// set incoming REG_Status
326
+			$this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
327
+			// toggle status to approved
328
+			$registration->set_status(EEM_Registration::status_id_approved);
329
+			if ($save) {
330
+				$registration->save();
331
+			}
332
+			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
333
+			if (! EE_Processor_Base::$IPN) {
334
+				// otherwise, send out notifications
335
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
336
+			}
337
+			// DEBUG LOG
338
+			// $this->log(
339
+			//     __CLASS__,
340
+			//     __FUNCTION__,
341
+			//     __LINE__,
342
+			//     $registration->transaction(),
343
+			//     array(
344
+			//         'IPN' => EE_Processor_Base::$IPN,
345
+			//         'deliver_notifications' => has_filter(
346
+			//             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
347
+			//         ),
348
+			//     )
349
+			// );
350
+			return true;
351
+		}
352
+		return false;
353
+	}
354
+
355
+
356
+	/**
357
+	 *    toggle_registration_statuses_if_no_monies_owing
358
+	 *
359
+	 * @access public
360
+	 * @param EE_Registration $registration
361
+	 * @param bool            $save TRUE will save the registration if the status is updated, FALSE will leave that up
362
+	 *                              to client code
363
+	 * @param array           $additional_details
364
+	 * @return bool
365
+	 * @throws EE_Error
366
+	 * @throws EntityNotFoundException
367
+	 * @throws InvalidArgumentException
368
+	 * @throws InvalidDataTypeException
369
+	 * @throws InvalidInterfaceException
370
+	 * @throws ReflectionException
371
+	 * @throws RuntimeException
372
+	 */
373
+	public function toggle_registration_status_if_no_monies_owing(
374
+		EE_Registration $registration,
375
+		$save = true,
376
+		array $additional_details = []
377
+	) {
378
+		// set initial REG_Status
379
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
380
+		// was a payment just made ?
381
+		$payment    = isset($additional_details['payment_updates'], $additional_details['last_payment'])
382
+					  && $additional_details['payment_updates']
383
+					  && $additional_details['last_payment'] instanceof EE_Payment
384
+			? $additional_details['last_payment']
385
+			: null;
386
+		$total_paid = array_sum(self::$_amount_paid);
387
+		// toggle reg status to approved IF
388
+		if (
389 389
 // REG status is pending payment
390
-            $registration->status_ID() === EEM_Registration::status_id_pending_payment
391
-            // AND no monies are owing
392
-            && (
393
-                (
394
-                    $registration->transaction()->is_completed()
395
-                    || $registration->transaction()->is_overpaid()
396
-                    || $registration->transaction()->is_free()
397
-                    || apply_filters(
398
-                        'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing',
399
-                        false,
400
-                        $registration
401
-                    )
402
-                )
403
-                || (
404
-                    $payment instanceof EE_Payment && $payment->is_approved()
405
-                    && // this specific registration has not yet been paid for
406
-                    ! isset(self::$_amount_paid[ $registration->ID() ])
407
-                    && // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price
408
-                    $payment->amount() - $total_paid >= $registration->final_price()
409
-                )
410
-            )
411
-        ) {
412
-            // mark as paid
413
-            self::$_amount_paid[ $registration->ID() ] = $registration->final_price();
414
-            // track new REG_Status
415
-            $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
416
-            // toggle status to approved
417
-            $registration->set_status(EEM_Registration::status_id_approved);
418
-            if ($save) {
419
-                $registration->save();
420
-            }
421
-            // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
422
-            if (! EE_Processor_Base::$IPN) {
423
-                // otherwise, send out notifications
424
-                add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
425
-            }
426
-            // DEBUG LOG
427
-            // $this->log(
428
-            //     __CLASS__,
429
-            //     __FUNCTION__,
430
-            //     __LINE__,
431
-            //     $registration->transaction(),
432
-            //     array(
433
-            //         'IPN' => EE_Processor_Base::$IPN,
434
-            //         'deliver_notifications' => has_filter(
435
-            //             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
436
-            //         ),
437
-            //     )
438
-            // );
439
-            return true;
440
-        }
441
-        return false;
442
-    }
443
-
444
-
445
-    /**
446
-     *    registration_status_changed
447
-     *
448
-     * @access public
449
-     * @param EE_Registration $registration
450
-     * @param array           $additional_details
451
-     * @return void
452
-     */
453
-    public function trigger_registration_update_notifications($registration, array $additional_details = [])
454
-    {
455
-        try {
456
-            if (! $registration instanceof EE_Registration) {
457
-                throw new EE_Error(
458
-                    esc_html__('An invalid registration was received.', 'event_espresso')
459
-                );
460
-            }
461
-            // EE_Registry::instance()->load_helper('Debug_Tools');
462
-            // EEH_Debug_Tools::log(
463
-            //     __CLASS__,
464
-            //     __FUNCTION__,
465
-            //     __LINE__,
466
-            //     array($registration->transaction(), $additional_details),
467
-            //     false,
468
-            //     'EE_Transaction: ' . $registration->transaction()->ID()
469
-            // );
470
-            if (
471
-                ! $this->request->getRequestParam('non_primary_reg_notification', 0, 'int')
472
-                && ! $registration->is_primary_registrant()
473
-            ) {
474
-                return;
475
-            }
476
-            do_action(
477
-                'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
478
-                $registration,
479
-                $additional_details
480
-            );
481
-        } catch (Exception $e) {
482
-            EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine());
483
-        }
484
-    }
485
-
486
-
487
-    /**
488
-     * sets reg status based either on passed param or on transaction status and event pre-approval setting
489
-     *
490
-     * @param EE_Registration $registration
491
-     * @param array           $additional_details
492
-     * @return bool
493
-     * @throws EE_Error
494
-     * @throws EntityNotFoundException
495
-     * @throws InvalidArgumentException
496
-     * @throws InvalidDataTypeException
497
-     * @throws InvalidInterfaceException
498
-     * @throws ReflectionException
499
-     * @throws RuntimeException
500
-     */
501
-    public function update_registration_after_checkout_or_payment(
502
-        EE_Registration $registration,
503
-        array $additional_details = []
504
-    ) {
505
-        // set initial REG_Status
506
-        $this->set_old_reg_status($registration->ID(), $registration->status_ID());
507
-        // if the registration status gets updated, then save the registration
508
-        if (
509
-            $this->toggle_registration_status_for_default_approved_events($registration, false)
510
-            || $this->toggle_registration_status_if_no_monies_owing(
511
-                $registration,
512
-                false,
513
-                $additional_details
514
-            )
515
-        ) {
516
-            $registration->save();
517
-        }
518
-        // set new  REG_Status
519
-        $this->set_new_reg_status($registration->ID(), $registration->status_ID());
520
-        return $this->reg_status_updated($registration->ID())
521
-               && $this->new_reg_status($registration->ID()) === EEM_Registration::status_id_approved;
522
-    }
523
-
524
-
525
-    /**
526
-     * Updates the registration' final prices based on the current line item tree (taking into account
527
-     * discounts, taxes, and other line items unrelated to tickets.)
528
-     *
529
-     * @param EE_Transaction $transaction
530
-     * @param boolean        $save_regs whether to immediately save registrations in this function or not
531
-     * @return void
532
-     * @throws EE_Error
533
-     * @throws InvalidArgumentException
534
-     * @throws InvalidDataTypeException
535
-     * @throws InvalidInterfaceException
536
-     * @throws RuntimeException
537
-     * @throws ReflectionException
538
-     */
539
-    public function update_registration_final_prices($transaction, $save_regs = true)
540
-    {
541
-        $reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item(
542
-            $transaction->total_line_item()
543
-        );
544
-        foreach ($transaction->registrations() as $registration) {
545
-            /** @var EE_Line_Item $line_item */
546
-            $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration);
547
-            if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) {
548
-                $registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]);
549
-                if ($save_regs) {
550
-                    $registration->save();
551
-                }
552
-            }
553
-        }
554
-        // and make sure there's no rounding problem
555
-        $this->fix_reg_final_price_rounding_issue($transaction);
556
-    }
557
-
558
-
559
-    /**
560
-     * Makes sure there is no rounding errors for the REG_final_prices.
561
-     * Eg, if we have 3 registrations for $1, and there is a $0.01 discount between the three of them,
562
-     * they will each be for $0.99333333, which gets rounded to $1 again.
563
-     * So the transaction total will be $2.99, but each registration will be for $1,
564
-     * so if each registrant paid individually they will have overpaid by $0.01.
565
-     * So in order to overcome this, we check for any difference, and if there is a difference
566
-     * we just grab one registrant at random and make them responsible for it.
567
-     * This should be used after setting REG_final_prices (it's done automatically as part of
568
-     * EE_Registration_Processor::update_registration_final_prices())
569
-     *
570
-     * @param EE_Transaction $transaction
571
-     * @return bool success verifying that there is NO difference after this method is done
572
-     * @throws EE_Error
573
-     * @throws InvalidArgumentException
574
-     * @throws InvalidDataTypeException
575
-     * @throws InvalidInterfaceException
576
-     * @throws ReflectionException
577
-     */
578
-    public function fix_reg_final_price_rounding_issue($transaction)
579
-    {
580
-        $reg_final_price_sum = EEM_Registration::instance()->sum(
581
-            [
582
-                [
583
-                    'TXN_ID' => $transaction->ID(),
584
-                ],
585
-            ],
586
-            'REG_final_price'
587
-        );
588
-        $diff                = $transaction->total() - $reg_final_price_sum;
589
-        // ok then, just grab one of the registrations
590
-        if ($diff !== (float) 0) {
591
-            $a_reg = EEM_Registration::instance()->get_one(
592
-                [
593
-                    [
594
-                        'TXN_ID' => $transaction->ID(),
595
-                    ],
596
-                ]
597
-            );
598
-            return $a_reg instanceof EE_Registration
599
-                   && $a_reg->save(['REG_final_price' => $a_reg->final_price() + $diff]);
600
-        }
601
-        return true;
602
-    }
603
-
604
-
605
-    /**
606
-     * update_registration_after_being_canceled_or_declined
607
-     *
608
-     * @param EE_Registration $registration
609
-     * @param array           $closed_reg_statuses
610
-     * @param bool            $update_reg
611
-     * @return bool
612
-     * @throws EE_Error
613
-     * @throws RuntimeException
614
-     * @throws ReflectionException
615
-     */
616
-    public function update_registration_after_being_canceled_or_declined(
617
-        EE_Registration $registration,
618
-        array $closed_reg_statuses = [],
619
-        $update_reg = true
620
-    ) {
621
-        // these reg statuses should not be considered in any calculations involving monies owing
622
-        $closed_reg_statuses = ! empty($closed_reg_statuses)
623
-            ? $closed_reg_statuses
624
-            : EEM_Registration::closed_reg_statuses();
625
-        if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
626
-            return false;
627
-        }
628
-        // release a reserved ticket by decrementing ticket and datetime reserved values
629
-        $registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__);
630
-        $registration->set_final_price(0);
631
-        if ($update_reg) {
632
-            $registration->save();
633
-        }
634
-        return true;
635
-    }
636
-
637
-
638
-    /**
639
-     * update_canceled_or_declined_registration_after_being_reinstated
640
-     *
641
-     * @param EE_Registration $registration
642
-     * @param array           $closed_reg_statuses
643
-     * @param bool            $update_reg
644
-     * @return bool
645
-     * @throws EE_Error
646
-     * @throws RuntimeException
647
-     * @throws ReflectionException
648
-     */
649
-    public function update_canceled_or_declined_registration_after_being_reinstated(
650
-        EE_Registration $registration,
651
-        array $closed_reg_statuses = [],
652
-        $update_reg = true
653
-    ) {
654
-        // these reg statuses should not be considered in any calculations involving monies owing
655
-        $closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
656
-            : EEM_Registration::closed_reg_statuses();
657
-        if (in_array($registration->status_ID(), $closed_reg_statuses, true)) {
658
-            return false;
659
-        }
660
-        $ticket = $registration->ticket();
661
-        if (! $ticket instanceof EE_Ticket) {
662
-            throw new EE_Error(
663
-                sprintf(
664
-                    esc_html__(
665
-                        'The Ticket for Registration %1$d was not found or is invalid.',
666
-                        'event_espresso'
667
-                    ),
668
-                    $registration->ticket_ID()
669
-                )
670
-            );
671
-        }
672
-        $registration->set_final_price($ticket->price());
673
-        if ($update_reg) {
674
-            $registration->save();
675
-        }
676
-        return true;
677
-    }
678
-
679
-
680
-    /**
681
-     * generate_ONE_registration_from_line_item
682
-     * Although a ticket line item may have a quantity greater than 1,
683
-     * this method will ONLY CREATE ONE REGISTRATION !!!
684
-     * Regardless of the ticket line item quantity.
685
-     * This means that any code calling this method is responsible for ensuring
686
-     * that the final registration count matches the ticket line item quantity.
687
-     * This was done to make it easier to match the number of registrations
688
-     * to the number of tickets in the cart, when the cart has been edited
689
-     * after SPCO has already been initialized. So if an additional ticket was added to the cart, you can simply pass
690
-     * the line item to this method to add a second ticket, and in this case, you would not want to add 2 tickets.
691
-     *
692
-     * @param EE_Line_Item   $line_item
693
-     * @param EE_Transaction $transaction
694
-     * @param int            $att_nmbr
695
-     * @param int            $total_ticket_count
696
-     * @return EE_Registration | null
697
-     * @throws OutOfRangeException
698
-     * @throws UnexpectedEntityException
699
-     * @throws EE_Error
700
-     * @throws ReflectionException
701
-     * @deprecated
702
-     * @since 4.9.1
703
-     */
704
-    public function generate_ONE_registration_from_line_item(
705
-        EE_Line_Item $line_item,
706
-        EE_Transaction $transaction,
707
-        $att_nmbr = 1,
708
-        $total_ticket_count = 1
709
-    ) {
710
-        EE_Error::doing_it_wrong(
711
-            __CLASS__ . '::' . __FUNCTION__,
712
-            sprintf(
713
-                esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
714
-                '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()'
715
-            ),
716
-            '4.9.1',
717
-            '5.0.0'
718
-        );
719
-        // grab the related ticket object for this line_item
720
-        $ticket = $line_item->ticket();
721
-        if (! $ticket instanceof EE_Ticket) {
722
-            EE_Error::add_error(
723
-                sprintf(
724
-                    esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'),
725
-                    $line_item->ID()
726
-                ),
727
-                __FILE__,
728
-                __FUNCTION__,
729
-                __LINE__
730
-            );
731
-            return null;
732
-        }
733
-        $registration_service = new CreateRegistrationService();
734
-        // then generate a new registration from that
735
-        return $registration_service->create(
736
-            $ticket->get_related_event(),
737
-            $transaction,
738
-            $ticket,
739
-            $line_item,
740
-            $att_nmbr,
741
-            $total_ticket_count
742
-        );
743
-    }
744
-
745
-
746
-    /**
747
-     * generates reg_url_link
748
-     *
749
-     * @param int                   $att_nmbr
750
-     * @param EE_Line_Item | string $item
751
-     * @return RegUrlLink
752
-     * @throws InvalidArgumentException
753
-     * @deprecated
754
-     * @since 4.9.1
755
-     */
756
-    public function generate_reg_url_link($att_nmbr, $item)
757
-    {
758
-        EE_Error::doing_it_wrong(
759
-            __CLASS__ . '::' . __FUNCTION__,
760
-            sprintf(
761
-                esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
762
-                'EventEspresso\core\domain\entities\RegUrlLink'
763
-            ),
764
-            '4.9.1',
765
-            '5.0.0'
766
-        );
767
-        return new RegUrlLink($att_nmbr, $item);
768
-    }
769
-
770
-
771
-    /**
772
-     * generates reg code
773
-     *
774
-     * @param EE_Registration $registration
775
-     * @return RegCode
776
-     * @throws EE_Error
777
-     * @throws EntityNotFoundException
778
-     * @throws InvalidArgumentException
779
-     * @since 4.9.1
780
-     * @deprecated
781
-     */
782
-    public function generate_reg_code(EE_Registration $registration)
783
-    {
784
-        EE_Error::doing_it_wrong(
785
-            __CLASS__ . '::' . __FUNCTION__,
786
-            sprintf(
787
-                esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
788
-                'EventEspresso\core\domain\entities\RegCode'
789
-            ),
790
-            '4.9.1',
791
-            '5.0.0'
792
-        );
793
-        return apply_filters(
794
-            'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code',
795
-            new RegCode(
796
-                RegUrlLink::fromRegistration($registration),
797
-                $registration->transaction(),
798
-                $registration->ticket()
799
-            ),
800
-            $registration
801
-        );
802
-    }
390
+			$registration->status_ID() === EEM_Registration::status_id_pending_payment
391
+			// AND no monies are owing
392
+			&& (
393
+				(
394
+					$registration->transaction()->is_completed()
395
+					|| $registration->transaction()->is_overpaid()
396
+					|| $registration->transaction()->is_free()
397
+					|| apply_filters(
398
+						'FHEE__EE_Registration_Processor__toggle_registration_status_if_no_monies_owing',
399
+						false,
400
+						$registration
401
+					)
402
+				)
403
+				|| (
404
+					$payment instanceof EE_Payment && $payment->is_approved()
405
+					&& // this specific registration has not yet been paid for
406
+					! isset(self::$_amount_paid[ $registration->ID() ])
407
+					&& // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price
408
+					$payment->amount() - $total_paid >= $registration->final_price()
409
+				)
410
+			)
411
+		) {
412
+			// mark as paid
413
+			self::$_amount_paid[ $registration->ID() ] = $registration->final_price();
414
+			// track new REG_Status
415
+			$this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
416
+			// toggle status to approved
417
+			$registration->set_status(EEM_Registration::status_id_approved);
418
+			if ($save) {
419
+				$registration->save();
420
+			}
421
+			// don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
422
+			if (! EE_Processor_Base::$IPN) {
423
+				// otherwise, send out notifications
424
+				add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
425
+			}
426
+			// DEBUG LOG
427
+			// $this->log(
428
+			//     __CLASS__,
429
+			//     __FUNCTION__,
430
+			//     __LINE__,
431
+			//     $registration->transaction(),
432
+			//     array(
433
+			//         'IPN' => EE_Processor_Base::$IPN,
434
+			//         'deliver_notifications' => has_filter(
435
+			//             'FHEE__EED_Messages___maybe_registration__deliver_notifications'
436
+			//         ),
437
+			//     )
438
+			// );
439
+			return true;
440
+		}
441
+		return false;
442
+	}
443
+
444
+
445
+	/**
446
+	 *    registration_status_changed
447
+	 *
448
+	 * @access public
449
+	 * @param EE_Registration $registration
450
+	 * @param array           $additional_details
451
+	 * @return void
452
+	 */
453
+	public function trigger_registration_update_notifications($registration, array $additional_details = [])
454
+	{
455
+		try {
456
+			if (! $registration instanceof EE_Registration) {
457
+				throw new EE_Error(
458
+					esc_html__('An invalid registration was received.', 'event_espresso')
459
+				);
460
+			}
461
+			// EE_Registry::instance()->load_helper('Debug_Tools');
462
+			// EEH_Debug_Tools::log(
463
+			//     __CLASS__,
464
+			//     __FUNCTION__,
465
+			//     __LINE__,
466
+			//     array($registration->transaction(), $additional_details),
467
+			//     false,
468
+			//     'EE_Transaction: ' . $registration->transaction()->ID()
469
+			// );
470
+			if (
471
+				! $this->request->getRequestParam('non_primary_reg_notification', 0, 'int')
472
+				&& ! $registration->is_primary_registrant()
473
+			) {
474
+				return;
475
+			}
476
+			do_action(
477
+				'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
478
+				$registration,
479
+				$additional_details
480
+			);
481
+		} catch (Exception $e) {
482
+			EE_Error::add_error($e->getMessage(), $e->getFile(), 'unknown_function_from_exception', $e->getLine());
483
+		}
484
+	}
485
+
486
+
487
+	/**
488
+	 * sets reg status based either on passed param or on transaction status and event pre-approval setting
489
+	 *
490
+	 * @param EE_Registration $registration
491
+	 * @param array           $additional_details
492
+	 * @return bool
493
+	 * @throws EE_Error
494
+	 * @throws EntityNotFoundException
495
+	 * @throws InvalidArgumentException
496
+	 * @throws InvalidDataTypeException
497
+	 * @throws InvalidInterfaceException
498
+	 * @throws ReflectionException
499
+	 * @throws RuntimeException
500
+	 */
501
+	public function update_registration_after_checkout_or_payment(
502
+		EE_Registration $registration,
503
+		array $additional_details = []
504
+	) {
505
+		// set initial REG_Status
506
+		$this->set_old_reg_status($registration->ID(), $registration->status_ID());
507
+		// if the registration status gets updated, then save the registration
508
+		if (
509
+			$this->toggle_registration_status_for_default_approved_events($registration, false)
510
+			|| $this->toggle_registration_status_if_no_monies_owing(
511
+				$registration,
512
+				false,
513
+				$additional_details
514
+			)
515
+		) {
516
+			$registration->save();
517
+		}
518
+		// set new  REG_Status
519
+		$this->set_new_reg_status($registration->ID(), $registration->status_ID());
520
+		return $this->reg_status_updated($registration->ID())
521
+			   && $this->new_reg_status($registration->ID()) === EEM_Registration::status_id_approved;
522
+	}
523
+
524
+
525
+	/**
526
+	 * Updates the registration' final prices based on the current line item tree (taking into account
527
+	 * discounts, taxes, and other line items unrelated to tickets.)
528
+	 *
529
+	 * @param EE_Transaction $transaction
530
+	 * @param boolean        $save_regs whether to immediately save registrations in this function or not
531
+	 * @return void
532
+	 * @throws EE_Error
533
+	 * @throws InvalidArgumentException
534
+	 * @throws InvalidDataTypeException
535
+	 * @throws InvalidInterfaceException
536
+	 * @throws RuntimeException
537
+	 * @throws ReflectionException
538
+	 */
539
+	public function update_registration_final_prices($transaction, $save_regs = true)
540
+	{
541
+		$reg_final_price_per_ticket_line_item = EEH_Line_Item::calculate_reg_final_prices_per_line_item(
542
+			$transaction->total_line_item()
543
+		);
544
+		foreach ($transaction->registrations() as $registration) {
545
+			/** @var EE_Line_Item $line_item */
546
+			$line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration);
547
+			if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) {
548
+				$registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]);
549
+				if ($save_regs) {
550
+					$registration->save();
551
+				}
552
+			}
553
+		}
554
+		// and make sure there's no rounding problem
555
+		$this->fix_reg_final_price_rounding_issue($transaction);
556
+	}
557
+
558
+
559
+	/**
560
+	 * Makes sure there is no rounding errors for the REG_final_prices.
561
+	 * Eg, if we have 3 registrations for $1, and there is a $0.01 discount between the three of them,
562
+	 * they will each be for $0.99333333, which gets rounded to $1 again.
563
+	 * So the transaction total will be $2.99, but each registration will be for $1,
564
+	 * so if each registrant paid individually they will have overpaid by $0.01.
565
+	 * So in order to overcome this, we check for any difference, and if there is a difference
566
+	 * we just grab one registrant at random and make them responsible for it.
567
+	 * This should be used after setting REG_final_prices (it's done automatically as part of
568
+	 * EE_Registration_Processor::update_registration_final_prices())
569
+	 *
570
+	 * @param EE_Transaction $transaction
571
+	 * @return bool success verifying that there is NO difference after this method is done
572
+	 * @throws EE_Error
573
+	 * @throws InvalidArgumentException
574
+	 * @throws InvalidDataTypeException
575
+	 * @throws InvalidInterfaceException
576
+	 * @throws ReflectionException
577
+	 */
578
+	public function fix_reg_final_price_rounding_issue($transaction)
579
+	{
580
+		$reg_final_price_sum = EEM_Registration::instance()->sum(
581
+			[
582
+				[
583
+					'TXN_ID' => $transaction->ID(),
584
+				],
585
+			],
586
+			'REG_final_price'
587
+		);
588
+		$diff                = $transaction->total() - $reg_final_price_sum;
589
+		// ok then, just grab one of the registrations
590
+		if ($diff !== (float) 0) {
591
+			$a_reg = EEM_Registration::instance()->get_one(
592
+				[
593
+					[
594
+						'TXN_ID' => $transaction->ID(),
595
+					],
596
+				]
597
+			);
598
+			return $a_reg instanceof EE_Registration
599
+				   && $a_reg->save(['REG_final_price' => $a_reg->final_price() + $diff]);
600
+		}
601
+		return true;
602
+	}
603
+
604
+
605
+	/**
606
+	 * update_registration_after_being_canceled_or_declined
607
+	 *
608
+	 * @param EE_Registration $registration
609
+	 * @param array           $closed_reg_statuses
610
+	 * @param bool            $update_reg
611
+	 * @return bool
612
+	 * @throws EE_Error
613
+	 * @throws RuntimeException
614
+	 * @throws ReflectionException
615
+	 */
616
+	public function update_registration_after_being_canceled_or_declined(
617
+		EE_Registration $registration,
618
+		array $closed_reg_statuses = [],
619
+		$update_reg = true
620
+	) {
621
+		// these reg statuses should not be considered in any calculations involving monies owing
622
+		$closed_reg_statuses = ! empty($closed_reg_statuses)
623
+			? $closed_reg_statuses
624
+			: EEM_Registration::closed_reg_statuses();
625
+		if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
626
+			return false;
627
+		}
628
+		// release a reserved ticket by decrementing ticket and datetime reserved values
629
+		$registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__);
630
+		$registration->set_final_price(0);
631
+		if ($update_reg) {
632
+			$registration->save();
633
+		}
634
+		return true;
635
+	}
636
+
637
+
638
+	/**
639
+	 * update_canceled_or_declined_registration_after_being_reinstated
640
+	 *
641
+	 * @param EE_Registration $registration
642
+	 * @param array           $closed_reg_statuses
643
+	 * @param bool            $update_reg
644
+	 * @return bool
645
+	 * @throws EE_Error
646
+	 * @throws RuntimeException
647
+	 * @throws ReflectionException
648
+	 */
649
+	public function update_canceled_or_declined_registration_after_being_reinstated(
650
+		EE_Registration $registration,
651
+		array $closed_reg_statuses = [],
652
+		$update_reg = true
653
+	) {
654
+		// these reg statuses should not be considered in any calculations involving monies owing
655
+		$closed_reg_statuses = ! empty($closed_reg_statuses) ? $closed_reg_statuses
656
+			: EEM_Registration::closed_reg_statuses();
657
+		if (in_array($registration->status_ID(), $closed_reg_statuses, true)) {
658
+			return false;
659
+		}
660
+		$ticket = $registration->ticket();
661
+		if (! $ticket instanceof EE_Ticket) {
662
+			throw new EE_Error(
663
+				sprintf(
664
+					esc_html__(
665
+						'The Ticket for Registration %1$d was not found or is invalid.',
666
+						'event_espresso'
667
+					),
668
+					$registration->ticket_ID()
669
+				)
670
+			);
671
+		}
672
+		$registration->set_final_price($ticket->price());
673
+		if ($update_reg) {
674
+			$registration->save();
675
+		}
676
+		return true;
677
+	}
678
+
679
+
680
+	/**
681
+	 * generate_ONE_registration_from_line_item
682
+	 * Although a ticket line item may have a quantity greater than 1,
683
+	 * this method will ONLY CREATE ONE REGISTRATION !!!
684
+	 * Regardless of the ticket line item quantity.
685
+	 * This means that any code calling this method is responsible for ensuring
686
+	 * that the final registration count matches the ticket line item quantity.
687
+	 * This was done to make it easier to match the number of registrations
688
+	 * to the number of tickets in the cart, when the cart has been edited
689
+	 * after SPCO has already been initialized. So if an additional ticket was added to the cart, you can simply pass
690
+	 * the line item to this method to add a second ticket, and in this case, you would not want to add 2 tickets.
691
+	 *
692
+	 * @param EE_Line_Item   $line_item
693
+	 * @param EE_Transaction $transaction
694
+	 * @param int            $att_nmbr
695
+	 * @param int            $total_ticket_count
696
+	 * @return EE_Registration | null
697
+	 * @throws OutOfRangeException
698
+	 * @throws UnexpectedEntityException
699
+	 * @throws EE_Error
700
+	 * @throws ReflectionException
701
+	 * @deprecated
702
+	 * @since 4.9.1
703
+	 */
704
+	public function generate_ONE_registration_from_line_item(
705
+		EE_Line_Item $line_item,
706
+		EE_Transaction $transaction,
707
+		$att_nmbr = 1,
708
+		$total_ticket_count = 1
709
+	) {
710
+		EE_Error::doing_it_wrong(
711
+			__CLASS__ . '::' . __FUNCTION__,
712
+			sprintf(
713
+				esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
714
+				'\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()'
715
+			),
716
+			'4.9.1',
717
+			'5.0.0'
718
+		);
719
+		// grab the related ticket object for this line_item
720
+		$ticket = $line_item->ticket();
721
+		if (! $ticket instanceof EE_Ticket) {
722
+			EE_Error::add_error(
723
+				sprintf(
724
+					esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'),
725
+					$line_item->ID()
726
+				),
727
+				__FILE__,
728
+				__FUNCTION__,
729
+				__LINE__
730
+			);
731
+			return null;
732
+		}
733
+		$registration_service = new CreateRegistrationService();
734
+		// then generate a new registration from that
735
+		return $registration_service->create(
736
+			$ticket->get_related_event(),
737
+			$transaction,
738
+			$ticket,
739
+			$line_item,
740
+			$att_nmbr,
741
+			$total_ticket_count
742
+		);
743
+	}
744
+
745
+
746
+	/**
747
+	 * generates reg_url_link
748
+	 *
749
+	 * @param int                   $att_nmbr
750
+	 * @param EE_Line_Item | string $item
751
+	 * @return RegUrlLink
752
+	 * @throws InvalidArgumentException
753
+	 * @deprecated
754
+	 * @since 4.9.1
755
+	 */
756
+	public function generate_reg_url_link($att_nmbr, $item)
757
+	{
758
+		EE_Error::doing_it_wrong(
759
+			__CLASS__ . '::' . __FUNCTION__,
760
+			sprintf(
761
+				esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
762
+				'EventEspresso\core\domain\entities\RegUrlLink'
763
+			),
764
+			'4.9.1',
765
+			'5.0.0'
766
+		);
767
+		return new RegUrlLink($att_nmbr, $item);
768
+	}
769
+
770
+
771
+	/**
772
+	 * generates reg code
773
+	 *
774
+	 * @param EE_Registration $registration
775
+	 * @return RegCode
776
+	 * @throws EE_Error
777
+	 * @throws EntityNotFoundException
778
+	 * @throws InvalidArgumentException
779
+	 * @since 4.9.1
780
+	 * @deprecated
781
+	 */
782
+	public function generate_reg_code(EE_Registration $registration)
783
+	{
784
+		EE_Error::doing_it_wrong(
785
+			__CLASS__ . '::' . __FUNCTION__,
786
+			sprintf(
787
+				esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
788
+				'EventEspresso\core\domain\entities\RegCode'
789
+			),
790
+			'4.9.1',
791
+			'5.0.0'
792
+		);
793
+		return apply_filters(
794
+			'FHEE__EE_Registration_Processor___generate_reg_code__new_reg_code',
795
+			new RegCode(
796
+				RegUrlLink::fromRegistration($registration),
797
+				$registration->transaction(),
798
+				$registration->ticket()
799
+			),
800
+			$registration
801
+		);
802
+	}
803 803
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
     public static function instance(RequestInterface $request = null)
82 82
     {
83 83
         // check if class object is instantiated
84
-        if (! self::$_instance instanceof EE_Registration_Processor) {
85
-            if (! $request instanceof RequestInterface) {
84
+        if ( ! self::$_instance instanceof EE_Registration_Processor) {
85
+            if ( ! $request instanceof RequestInterface) {
86 86
                 $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request');
87 87
             }
88 88
             self::$_instance = new self($request);
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
      */
109 109
     public function old_reg_status($REG_ID)
110 110
     {
111
-        return isset($this->_old_reg_status[ $REG_ID ]) ? $this->_old_reg_status[ $REG_ID ] : null;
111
+        return isset($this->_old_reg_status[$REG_ID]) ? $this->_old_reg_status[$REG_ID] : null;
112 112
     }
113 113
 
114 114
 
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
     public function set_old_reg_status($REG_ID, $old_reg_status)
120 120
     {
121 121
         // only set the first time
122
-        if (! isset($this->_old_reg_status[ $REG_ID ])) {
123
-            $this->_old_reg_status[ $REG_ID ] = $old_reg_status;
122
+        if ( ! isset($this->_old_reg_status[$REG_ID])) {
123
+            $this->_old_reg_status[$REG_ID] = $old_reg_status;
124 124
         }
125 125
     }
126 126
 
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
      */
132 132
     public function new_reg_status($REG_ID)
133 133
     {
134
-        return isset($this->_new_reg_status[ $REG_ID ]) ? $this->_new_reg_status[ $REG_ID ] : null;
134
+        return isset($this->_new_reg_status[$REG_ID]) ? $this->_new_reg_status[$REG_ID] : null;
135 135
     }
136 136
 
137 137
 
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      */
142 142
     public function set_new_reg_status($REG_ID, $new_reg_status)
143 143
     {
144
-        $this->_new_reg_status[ $REG_ID ] = $new_reg_status;
144
+        $this->_new_reg_status[$REG_ID] = $new_reg_status;
145 145
     }
146 146
 
147 147
 
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
         if (
209 209
             $this->reg_status_updated($registration->ID())
210 210
             && (
211
-                (! $this->request->isAdmin() || $this->request->isFrontAjax())
211
+                ( ! $this->request->isAdmin() || $this->request->isFrontAjax())
212 212
                 || EE_Registry::instance()->CAP->current_user_can(
213 213
                     'ee_edit_registration',
214 214
                     'toggle_registration_status',
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
                 $registration->save();
272 272
             }
273 273
             // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
274
-            if (! EE_Processor_Base::$IPN) {
274
+            if ( ! EE_Processor_Base::$IPN) {
275 275
                 // otherwise, send out notifications
276 276
                 add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
277 277
             }
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
                 $registration->save();
331 331
             }
332 332
             // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
333
-            if (! EE_Processor_Base::$IPN) {
333
+            if ( ! EE_Processor_Base::$IPN) {
334 334
                 // otherwise, send out notifications
335 335
                 add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
336 336
             }
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
         // set initial REG_Status
379 379
         $this->set_old_reg_status($registration->ID(), $registration->status_ID());
380 380
         // was a payment just made ?
381
-        $payment    = isset($additional_details['payment_updates'], $additional_details['last_payment'])
381
+        $payment = isset($additional_details['payment_updates'], $additional_details['last_payment'])
382 382
                       && $additional_details['payment_updates']
383 383
                       && $additional_details['last_payment'] instanceof EE_Payment
384 384
             ? $additional_details['last_payment']
@@ -403,14 +403,14 @@  discard block
 block discarded – undo
403 403
                 || (
404 404
                     $payment instanceof EE_Payment && $payment->is_approved()
405 405
                     && // this specific registration has not yet been paid for
406
-                    ! isset(self::$_amount_paid[ $registration->ID() ])
406
+                    ! isset(self::$_amount_paid[$registration->ID()])
407 407
                     && // payment amount, less what we have already attributed to other registrations, is greater than this reg's final price
408 408
                     $payment->amount() - $total_paid >= $registration->final_price()
409 409
                 )
410 410
             )
411 411
         ) {
412 412
             // mark as paid
413
-            self::$_amount_paid[ $registration->ID() ] = $registration->final_price();
413
+            self::$_amount_paid[$registration->ID()] = $registration->final_price();
414 414
             // track new REG_Status
415 415
             $this->set_new_reg_status($registration->ID(), EEM_Registration::status_id_approved);
416 416
             // toggle status to approved
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
                 $registration->save();
420 420
             }
421 421
             // don't trigger notifications during IPNs because they will get triggered by EE_Payment_Processor
422
-            if (! EE_Processor_Base::$IPN) {
422
+            if ( ! EE_Processor_Base::$IPN) {
423 423
                 // otherwise, send out notifications
424 424
                 add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true', 10);
425 425
             }
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
     public function trigger_registration_update_notifications($registration, array $additional_details = [])
454 454
     {
455 455
         try {
456
-            if (! $registration instanceof EE_Registration) {
456
+            if ( ! $registration instanceof EE_Registration) {
457 457
                 throw new EE_Error(
458 458
                     esc_html__('An invalid registration was received.', 'event_espresso')
459 459
                 );
@@ -544,8 +544,8 @@  discard block
 block discarded – undo
544 544
         foreach ($transaction->registrations() as $registration) {
545 545
             /** @var EE_Line_Item $line_item */
546 546
             $line_item = EEM_Line_Item::instance()->get_line_item_for_registration($registration);
547
-            if (isset($reg_final_price_per_ticket_line_item[ $line_item->ID() ])) {
548
-                $registration->set_final_price($reg_final_price_per_ticket_line_item[ $line_item->ID() ]);
547
+            if (isset($reg_final_price_per_ticket_line_item[$line_item->ID()])) {
548
+                $registration->set_final_price($reg_final_price_per_ticket_line_item[$line_item->ID()]);
549 549
                 if ($save_regs) {
550 550
                     $registration->save();
551 551
                 }
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
             ],
586 586
             'REG_final_price'
587 587
         );
588
-        $diff                = $transaction->total() - $reg_final_price_sum;
588
+        $diff = $transaction->total() - $reg_final_price_sum;
589 589
         // ok then, just grab one of the registrations
590 590
         if ($diff !== (float) 0) {
591 591
             $a_reg = EEM_Registration::instance()->get_one(
@@ -622,11 +622,11 @@  discard block
 block discarded – undo
622 622
         $closed_reg_statuses = ! empty($closed_reg_statuses)
623 623
             ? $closed_reg_statuses
624 624
             : EEM_Registration::closed_reg_statuses();
625
-        if (! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
625
+        if ( ! in_array($registration->status_ID(), $closed_reg_statuses, true)) {
626 626
             return false;
627 627
         }
628 628
         // release a reserved ticket by decrementing ticket and datetime reserved values
629
-        $registration->release_reserved_ticket(true, 'RegProcessor:' . __LINE__);
629
+        $registration->release_reserved_ticket(true, 'RegProcessor:'.__LINE__);
630 630
         $registration->set_final_price(0);
631 631
         if ($update_reg) {
632 632
             $registration->save();
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
             return false;
659 659
         }
660 660
         $ticket = $registration->ticket();
661
-        if (! $ticket instanceof EE_Ticket) {
661
+        if ( ! $ticket instanceof EE_Ticket) {
662 662
             throw new EE_Error(
663 663
                 sprintf(
664 664
                     esc_html__(
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
         $total_ticket_count = 1
709 709
     ) {
710 710
         EE_Error::doing_it_wrong(
711
-            __CLASS__ . '::' . __FUNCTION__,
711
+            __CLASS__.'::'.__FUNCTION__,
712 712
             sprintf(
713 713
                 esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
714 714
                 '\EventEspresso\core\domain\services\registration\CreateRegistrationService::create()'
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
         );
719 719
         // grab the related ticket object for this line_item
720 720
         $ticket = $line_item->ticket();
721
-        if (! $ticket instanceof EE_Ticket) {
721
+        if ( ! $ticket instanceof EE_Ticket) {
722 722
             EE_Error::add_error(
723 723
                 sprintf(
724 724
                     esc_html__('Line item %s did not contain a valid ticket', 'event_espresso'),
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
     public function generate_reg_url_link($att_nmbr, $item)
757 757
     {
758 758
         EE_Error::doing_it_wrong(
759
-            __CLASS__ . '::' . __FUNCTION__,
759
+            __CLASS__.'::'.__FUNCTION__,
760 760
             sprintf(
761 761
                 esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
762 762
                 'EventEspresso\core\domain\entities\RegUrlLink'
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
     public function generate_reg_code(EE_Registration $registration)
783 783
     {
784 784
         EE_Error::doing_it_wrong(
785
-            __CLASS__ . '::' . __FUNCTION__,
785
+            __CLASS__.'::'.__FUNCTION__,
786 786
             sprintf(
787 787
                 esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
788 788
                 'EventEspresso\core\domain\entities\RegCode'
Please login to merge, or discard this patch.
modules/messages/EED_Messages.module.php 2 patches
Indentation   +1340 added lines, -1340 removed lines patch added patch discarded remove patch
@@ -16,1353 +16,1353 @@
 block discarded – undo
16 16
 class EED_Messages extends EED_Module
17 17
 {
18 18
 
19
-    /**
20
-     * This holds the EE_messages controller
21
-     *
22
-     * @deprecated 4.9.0
23
-     * @var EE_messages $_EEMSG
24
-     */
25
-    protected static $_EEMSG;
26
-
27
-    /**
28
-     * @type EE_Message_Resource_Manager $_message_resource_manager
29
-     */
30
-    protected static $_message_resource_manager;
31
-
32
-    /**
33
-     * This holds the EE_Messages_Processor business class.
34
-     *
35
-     * @type EE_Messages_Processor
36
-     */
37
-    protected static $_MSG_PROCESSOR;
38
-
39
-    /**
40
-     * holds all the paths for various messages components.
41
-     * Utilized by autoloader registry
42
-     *
43
-     * @var array
44
-     */
45
-    protected static $_MSG_PATHS;
46
-
47
-
48
-    /**
49
-     * This will hold an array of messages template packs that are registered in the messages system.
50
-     * Format is:
51
-     * array(
52
-     *    'template_pack_dbref' => EE_Messages_Template_Pack (instance)
53
-     * )
54
-     *
55
-     * @var EE_Messages_Template_Pack[]
56
-     */
57
-    protected static $_TMP_PACKS = array();
58
-
59
-
60
-    /**
61
-     * @return EED_Messages|EED_Module
62
-     * @throws EE_Error
63
-     * @throws ReflectionException
64
-     */
65
-    public static function instance()
66
-    {
67
-        return parent::get_instance(__CLASS__);
68
-    }
69
-
70
-
71
-    /**
72
-     *  set_hooks - for hooking into EE Core, other modules, etc
73
-     *
74
-     * @since 4.5.0
75
-     * @return    void
76
-     */
77
-    public static function set_hooks()
78
-    {
79
-        // actions
80
-        add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
81
-        add_action(
82
-            'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
83
-            array('EED_Messages', 'maybe_registration'),
84
-            10,
85
-            2
86
-        );
87
-        // filters
88
-        add_filter(
89
-            'FHEE__EE_Registration__receipt_url__receipt_url',
90
-            array('EED_Messages', 'registration_message_trigger_url'),
91
-            10,
92
-            4
93
-        );
94
-        add_filter(
95
-            'FHEE__EE_Registration__invoice_url__invoice_url',
96
-            array('EED_Messages', 'registration_message_trigger_url'),
97
-            10,
98
-            4
99
-        );
100
-        // register routes
101
-        self::_register_routes();
102
-    }
103
-
104
-    /**
105
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
106
-     *
107
-     * @access    public
108
-     * @return    void
109
-     */
110
-    public static function set_hooks_admin()
111
-    {
112
-        // actions
113
-        add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
114
-        add_action(
115
-            'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
116
-            array('EED_Messages', 'payment_reminder'),
117
-            10
118
-        );
119
-        add_action(
120
-            'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
121
-            array('EED_Messages', 'maybe_registration'),
122
-            10,
123
-            3
124
-        );
125
-        add_action(
126
-            'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
127
-            array('EED_Messages', 'send_newsletter_message'),
128
-            10,
129
-            2
130
-        );
131
-        add_action(
132
-            'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction',
133
-            array('EED_Messages', 'cancelled_registration'),
134
-            10
135
-        );
136
-        add_action(
137
-            'AHEE__EE_Admin_Page___process_admin_payment_notification',
138
-            array('EED_Messages', 'process_admin_payment'),
139
-            10,
140
-            1
141
-        );
142
-        // filters
143
-        add_filter(
144
-            'FHEE__EE_Admin_Page___process_resend_registration__success',
145
-            array('EED_Messages', 'process_resend'),
146
-            10,
147
-            2
148
-        );
149
-        add_filter(
150
-            'FHEE__EE_Registration__receipt_url__receipt_url',
151
-            array('EED_Messages', 'registration_message_trigger_url'),
152
-            10,
153
-            4
154
-        );
155
-        add_filter(
156
-            'FHEE__EE_Registration__invoice_url__invoice_url',
157
-            array('EED_Messages', 'registration_message_trigger_url'),
158
-            10,
159
-            4
160
-        );
161
-    }
162
-
163
-
164
-    /**
165
-     * All the message triggers done by route go in here.
166
-     *
167
-     * @since 4.5.0
168
-     * @return void
169
-     */
170
-    protected static function _register_routes()
171
-    {
172
-        EE_Config::register_route('msg_url_trigger', 'Messages', 'run');
173
-        EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request');
174
-        EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger');
175
-        EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger');
176
-        do_action('AHEE__EED_Messages___register_routes');
177
-    }
178
-
179
-
180
-    /**
181
-     * This is called when a browser display trigger is executed.
182
-     * The browser display trigger is typically used when a already generated message is displayed directly in the
183
-     * browser.
184
-     *
185
-     * @since 4.9.0
186
-     * @param WP $WP
187
-     * @throws EE_Error
188
-     * @throws InvalidArgumentException
189
-     * @throws ReflectionException
190
-     * @throws InvalidDataTypeException
191
-     * @throws InvalidInterfaceException
192
-     */
193
-    public function browser_trigger($WP)
194
-    {
195
-        // ensure controller is loaded
196
-        self::_load_controller();
197
-        $token = self::getRequest()->getRequestParam('token');
198
-        try {
199
-            $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager);
200
-            self::$_MSG_PROCESSOR->generate_and_send_now($mtg);
201
-        } catch (EE_Error $e) {
202
-            $error_msg = esc_html__(
203
-                'Please note that a system message failed to send due to a technical issue.',
204
-                'event_espresso'
205
-            );
206
-            // add specific message for developers if WP_DEBUG in on
207
-            $error_msg .= '||' . $e->getMessage();
208
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
209
-        }
210
-    }
211
-
212
-
213
-    /**
214
-     * This is called when a browser error trigger is executed.
215
-     * When triggered this will grab the EE_Message matching the token in the request and use that to get the error
216
-     * message and display it.
217
-     *
218
-     * @since 4.9.0
219
-     * @param $WP
220
-     * @throws EE_Error
221
-     * @throws InvalidArgumentException
222
-     * @throws InvalidDataTypeException
223
-     * @throws InvalidInterfaceException
224
-     */
225
-    public function browser_error_trigger($WP)
226
-    {
227
-        $token = self::getRequest()->getRequestParam('token');
228
-        if ($token) {
229
-            $message = EEM_Message::instance()->get_one_by_token($token);
230
-            if ($message instanceof EE_Message) {
231
-                header('HTTP/1.1 200 OK');
232
-                $error_msg = nl2br($message->error_message());
233
-                ?>
19
+	/**
20
+	 * This holds the EE_messages controller
21
+	 *
22
+	 * @deprecated 4.9.0
23
+	 * @var EE_messages $_EEMSG
24
+	 */
25
+	protected static $_EEMSG;
26
+
27
+	/**
28
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
29
+	 */
30
+	protected static $_message_resource_manager;
31
+
32
+	/**
33
+	 * This holds the EE_Messages_Processor business class.
34
+	 *
35
+	 * @type EE_Messages_Processor
36
+	 */
37
+	protected static $_MSG_PROCESSOR;
38
+
39
+	/**
40
+	 * holds all the paths for various messages components.
41
+	 * Utilized by autoloader registry
42
+	 *
43
+	 * @var array
44
+	 */
45
+	protected static $_MSG_PATHS;
46
+
47
+
48
+	/**
49
+	 * This will hold an array of messages template packs that are registered in the messages system.
50
+	 * Format is:
51
+	 * array(
52
+	 *    'template_pack_dbref' => EE_Messages_Template_Pack (instance)
53
+	 * )
54
+	 *
55
+	 * @var EE_Messages_Template_Pack[]
56
+	 */
57
+	protected static $_TMP_PACKS = array();
58
+
59
+
60
+	/**
61
+	 * @return EED_Messages|EED_Module
62
+	 * @throws EE_Error
63
+	 * @throws ReflectionException
64
+	 */
65
+	public static function instance()
66
+	{
67
+		return parent::get_instance(__CLASS__);
68
+	}
69
+
70
+
71
+	/**
72
+	 *  set_hooks - for hooking into EE Core, other modules, etc
73
+	 *
74
+	 * @since 4.5.0
75
+	 * @return    void
76
+	 */
77
+	public static function set_hooks()
78
+	{
79
+		// actions
80
+		add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
81
+		add_action(
82
+			'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
83
+			array('EED_Messages', 'maybe_registration'),
84
+			10,
85
+			2
86
+		);
87
+		// filters
88
+		add_filter(
89
+			'FHEE__EE_Registration__receipt_url__receipt_url',
90
+			array('EED_Messages', 'registration_message_trigger_url'),
91
+			10,
92
+			4
93
+		);
94
+		add_filter(
95
+			'FHEE__EE_Registration__invoice_url__invoice_url',
96
+			array('EED_Messages', 'registration_message_trigger_url'),
97
+			10,
98
+			4
99
+		);
100
+		// register routes
101
+		self::_register_routes();
102
+	}
103
+
104
+	/**
105
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
106
+	 *
107
+	 * @access    public
108
+	 * @return    void
109
+	 */
110
+	public static function set_hooks_admin()
111
+	{
112
+		// actions
113
+		add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2);
114
+		add_action(
115
+			'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
116
+			array('EED_Messages', 'payment_reminder'),
117
+			10
118
+		);
119
+		add_action(
120
+			'AHEE__EE_Registration_Processor__trigger_registration_update_notifications',
121
+			array('EED_Messages', 'maybe_registration'),
122
+			10,
123
+			3
124
+		);
125
+		add_action(
126
+			'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations',
127
+			array('EED_Messages', 'send_newsletter_message'),
128
+			10,
129
+			2
130
+		);
131
+		add_action(
132
+			'AHEE__EES_Espresso_Cancelled__process_shortcode__transaction',
133
+			array('EED_Messages', 'cancelled_registration'),
134
+			10
135
+		);
136
+		add_action(
137
+			'AHEE__EE_Admin_Page___process_admin_payment_notification',
138
+			array('EED_Messages', 'process_admin_payment'),
139
+			10,
140
+			1
141
+		);
142
+		// filters
143
+		add_filter(
144
+			'FHEE__EE_Admin_Page___process_resend_registration__success',
145
+			array('EED_Messages', 'process_resend'),
146
+			10,
147
+			2
148
+		);
149
+		add_filter(
150
+			'FHEE__EE_Registration__receipt_url__receipt_url',
151
+			array('EED_Messages', 'registration_message_trigger_url'),
152
+			10,
153
+			4
154
+		);
155
+		add_filter(
156
+			'FHEE__EE_Registration__invoice_url__invoice_url',
157
+			array('EED_Messages', 'registration_message_trigger_url'),
158
+			10,
159
+			4
160
+		);
161
+	}
162
+
163
+
164
+	/**
165
+	 * All the message triggers done by route go in here.
166
+	 *
167
+	 * @since 4.5.0
168
+	 * @return void
169
+	 */
170
+	protected static function _register_routes()
171
+	{
172
+		EE_Config::register_route('msg_url_trigger', 'Messages', 'run');
173
+		EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request');
174
+		EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger');
175
+		EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger');
176
+		do_action('AHEE__EED_Messages___register_routes');
177
+	}
178
+
179
+
180
+	/**
181
+	 * This is called when a browser display trigger is executed.
182
+	 * The browser display trigger is typically used when a already generated message is displayed directly in the
183
+	 * browser.
184
+	 *
185
+	 * @since 4.9.0
186
+	 * @param WP $WP
187
+	 * @throws EE_Error
188
+	 * @throws InvalidArgumentException
189
+	 * @throws ReflectionException
190
+	 * @throws InvalidDataTypeException
191
+	 * @throws InvalidInterfaceException
192
+	 */
193
+	public function browser_trigger($WP)
194
+	{
195
+		// ensure controller is loaded
196
+		self::_load_controller();
197
+		$token = self::getRequest()->getRequestParam('token');
198
+		try {
199
+			$mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager);
200
+			self::$_MSG_PROCESSOR->generate_and_send_now($mtg);
201
+		} catch (EE_Error $e) {
202
+			$error_msg = esc_html__(
203
+				'Please note that a system message failed to send due to a technical issue.',
204
+				'event_espresso'
205
+			);
206
+			// add specific message for developers if WP_DEBUG in on
207
+			$error_msg .= '||' . $e->getMessage();
208
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
209
+		}
210
+	}
211
+
212
+
213
+	/**
214
+	 * This is called when a browser error trigger is executed.
215
+	 * When triggered this will grab the EE_Message matching the token in the request and use that to get the error
216
+	 * message and display it.
217
+	 *
218
+	 * @since 4.9.0
219
+	 * @param $WP
220
+	 * @throws EE_Error
221
+	 * @throws InvalidArgumentException
222
+	 * @throws InvalidDataTypeException
223
+	 * @throws InvalidInterfaceException
224
+	 */
225
+	public function browser_error_trigger($WP)
226
+	{
227
+		$token = self::getRequest()->getRequestParam('token');
228
+		if ($token) {
229
+			$message = EEM_Message::instance()->get_one_by_token($token);
230
+			if ($message instanceof EE_Message) {
231
+				header('HTTP/1.1 200 OK');
232
+				$error_msg = nl2br($message->error_message());
233
+				?>
234 234
                 <!DOCTYPE html>
235 235
                 <html>
236 236
                 <head></head>
237 237
                 <body>
238 238
                 <?php echo empty($error_msg)
239
-                    ? esc_html__(
240
-                        'Unfortunately, we were unable to capture the error message for this message.',
241
-                        'event_espresso'
242
-                    )
243
-                    : wp_kses(
244
-                        $error_msg,
245
-                        array(
246
-                            'a'      => array(
247
-                                'href'  => array(),
248
-                                'title' => array(),
249
-                            ),
250
-                            'span'   => array(),
251
-                            'div'    => array(),
252
-                            'p'      => array(),
253
-                            'strong' => array(),
254
-                            'em'     => array(),
255
-                            'br'     => array(),
256
-                        )
257
-                    ); ?>
239
+					? esc_html__(
240
+						'Unfortunately, we were unable to capture the error message for this message.',
241
+						'event_espresso'
242
+					)
243
+					: wp_kses(
244
+						$error_msg,
245
+						array(
246
+							'a'      => array(
247
+								'href'  => array(),
248
+								'title' => array(),
249
+							),
250
+							'span'   => array(),
251
+							'div'    => array(),
252
+							'p'      => array(),
253
+							'strong' => array(),
254
+							'em'     => array(),
255
+							'br'     => array(),
256
+						)
257
+					); ?>
258 258
                 </body>
259 259
                 </html>
260 260
                 <?php
261
-                exit;
262
-            }
263
-        }
264
-    }
265
-
266
-
267
-    /**
268
-     *  This runs when the msg_url_trigger route has initiated.
269
-     *
270
-     * @since 4.5.0
271
-     * @param WP $WP
272
-     * @throws EE_Error
273
-     * @throws InvalidArgumentException
274
-     * @throws ReflectionException
275
-     * @throws InvalidDataTypeException
276
-     * @throws InvalidInterfaceException
277
-     */
278
-    public function run($WP)
279
-    {
280
-        // ensure controller is loaded
281
-        self::_load_controller();
282
-        // attempt to process message
283
-        try {
284
-            /** @type EE_Message_To_Generate_From_Request $message_to_generate */
285
-            $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
286
-            self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate);
287
-        } catch (EE_Error $e) {
288
-            $error_msg = esc_html__(
289
-                'Please note that a system message failed to send due to a technical issue.',
290
-                'event_espresso'
291
-            );
292
-            // add specific message for developers if WP_DEBUG in on
293
-            $error_msg .= '||' . $e->getMessage();
294
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
295
-        }
296
-    }
297
-
298
-
299
-    /**
300
-     * This is triggered by the 'msg_cron_trigger' route.
301
-     *
302
-     * @param WP $WP
303
-     */
304
-    public function execute_batch_request($WP)
305
-    {
306
-        $this->run_cron();
307
-        header('HTTP/1.1 200 OK');
308
-        exit();
309
-    }
310
-
311
-
312
-    /**
313
-     * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp
314
-     * request.
315
-     */
316
-    public function run_cron()
317
-    {
318
-        self::_load_controller();
319
-        $request = self::getRequest();
320
-        // get required vars
321
-        $cron_type = $request->getRequestParam('type');
322
-        $transient_key = $request->getRequestParam('key');
323
-
324
-        // now let's verify transient, if not valid exit immediately
325
-        if (! get_transient($transient_key)) {
326
-            /**
327
-             * trigger error so this gets in the error logs.  This is important because it happens on a non-user
328
-             * request.
329
-             */
330
-            trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso'));
331
-        }
332
-
333
-        // if made it here, lets' delete the transient to keep the db clean
334
-        delete_transient($transient_key);
335
-
336
-        if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
337
-            $method = 'batch_' . $cron_type . '_from_queue';
338
-            if (method_exists(self::$_MSG_PROCESSOR, $method)) {
339
-                self::$_MSG_PROCESSOR->$method();
340
-            } else {
341
-                // no matching task
342
-                /**
343
-                 * trigger error so this gets in the error logs.  This is important because it happens on a non user
344
-                 * request.
345
-                 */
346
-                trigger_error(
347
-                    esc_attr(
348
-                        sprintf(
349
-                            esc_html__('There is no task corresponding to this route %s', 'event_espresso'),
350
-                            $cron_type
351
-                        )
352
-                    )
353
-                );
354
-            }
355
-        }
356
-
357
-        do_action('FHEE__EED_Messages__run_cron__end');
358
-    }
359
-
360
-
361
-    /**
362
-     * This is used to retrieve the template pack for the given name.
363
-     * Retrieved packs are cached on the static $_TMP_PACKS array.  If there is no class matching the given name then
364
-     * the default template pack is returned.
365
-     *
366
-     * @deprecated 4.9.0  @see EEH_MSG_Template::get_template_pack()
367
-     * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used
368
-     *                                   in generating the Pack class name).
369
-     * @return EE_Messages_Template_Pack
370
-     * @throws EE_Error
371
-     * @throws InvalidArgumentException
372
-     * @throws ReflectionException
373
-     * @throws InvalidDataTypeException
374
-     * @throws InvalidInterfaceException
375
-     */
376
-    public static function get_template_pack($template_pack_name)
377
-    {
378
-        EE_Registry::instance()->load_helper('MSG_Template');
379
-        return EEH_MSG_Template::get_template_pack($template_pack_name);
380
-    }
381
-
382
-
383
-    /**
384
-     * Retrieves an array of all template packs.
385
-     * Array is in the format array( 'dbref' => EE_Messages_Template_Pack )
386
-     *
387
-     * @deprecated 4.9.0  @see EEH_MSG_Template_Pack::get_template_pack_collection
388
-     * @return EE_Messages_Template_Pack[]
389
-     * @throws EE_Error
390
-     * @throws InvalidArgumentException
391
-     * @throws ReflectionException
392
-     * @throws InvalidDataTypeException
393
-     * @throws InvalidInterfaceException
394
-     */
395
-    public static function get_template_packs()
396
-    {
397
-        EE_Registry::instance()->load_helper('MSG_Template');
398
-
399
-        // for backward compat, let's make sure this returns in the same format as originally.
400
-        $template_pack_collection = EEH_MSG_Template::get_template_pack_collection();
401
-        $template_pack_collection->rewind();
402
-        $template_packs = array();
403
-        while ($template_pack_collection->valid()) {
404
-            $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current();
405
-            $template_pack_collection->next();
406
-        }
407
-        return $template_packs;
408
-    }
409
-
410
-
411
-    /**
412
-     * This simply makes sure the autoloaders are registered for the EE_messages system.
413
-     *
414
-     * @since 4.5.0
415
-     * @return void
416
-     * @throws EE_Error
417
-     */
418
-    public static function set_autoloaders()
419
-    {
420
-        if (empty(self::$_MSG_PATHS)) {
421
-            self::_set_messages_paths();
422
-            foreach (self::$_MSG_PATHS as $path) {
423
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);
424
-            }
425
-            // add aliases
426
-            EEH_Autoloader::add_alias('EE_messages', 'EE_messages');
427
-            EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger');
428
-        }
429
-    }
430
-
431
-
432
-    /**
433
-     * Take care of adding all the paths for the messages components to the $_MSG_PATHS property
434
-     * for use by the Messages Autoloaders
435
-     *
436
-     * @since 4.5.0
437
-     * @return void.
438
-     */
439
-    protected static function _set_messages_paths()
440
-    {
441
-        $dir_ref = array(
442
-            'messages/message_type',
443
-            'messages/messenger',
444
-            'messages/defaults',
445
-            'messages/defaults/email',
446
-            'messages/data_class',
447
-            'messages/validators',
448
-            'messages/validators/email',
449
-            'messages/validators/html',
450
-            'shortcodes',
451
-        );
452
-        $paths = array();
453
-        foreach ($dir_ref as $index => $dir) {
454
-            $paths[ $index ] = EE_LIBRARIES . $dir;
455
-        }
456
-        self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths);
457
-    }
458
-
459
-
460
-    /**
461
-     * Takes care of loading dependencies
462
-     *
463
-     * @since 4.5.0
464
-     * @return void
465
-     * @throws EE_Error
466
-     * @throws InvalidArgumentException
467
-     * @throws ReflectionException
468
-     * @throws InvalidDataTypeException
469
-     * @throws InvalidInterfaceException
470
-     */
471
-    protected static function _load_controller()
472
-    {
473
-        if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
474
-            EE_Registry::instance()->load_core('Request_Handler');
475
-            self::set_autoloaders();
476
-            self::$_EEMSG = EE_Registry::instance()->load_lib('messages');
477
-            self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor');
478
-            self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
479
-        }
480
-    }
481
-
482
-
483
-    /**
484
-     * @param EE_Transaction $transaction
485
-     * @throws EE_Error
486
-     * @throws InvalidArgumentException
487
-     * @throws InvalidDataTypeException
488
-     * @throws InvalidInterfaceException
489
-     * @throws ReflectionException
490
-     */
491
-    public static function payment_reminder(EE_Transaction $transaction)
492
-    {
493
-        self::_load_controller();
494
-        $data = array($transaction, null);
495
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data);
496
-    }
497
-
498
-
499
-    /**
500
-     * Any messages triggers for after successful gateway payments should go in here.
501
-     *
502
-     * @param EE_Transaction  $transaction object
503
-     * @param EE_Payment|null $payment     object
504
-     * @return void
505
-     * @throws EE_Error
506
-     * @throws InvalidArgumentException
507
-     * @throws ReflectionException
508
-     * @throws InvalidDataTypeException
509
-     * @throws InvalidInterfaceException
510
-     */
511
-    public static function payment(EE_Transaction $transaction, EE_Payment $payment = null)
512
-    {
513
-        // if there's no payment object, then we cannot do a payment type message!
514
-        if (! $payment instanceof EE_Payment) {
515
-            return;
516
-        }
517
-        self::_load_controller();
518
-        $data = array($transaction, $payment);
519
-        EE_Registry::instance()->load_helper('MSG_Template');
520
-        $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
521
-        // if payment amount is less than 0 then switch to payment_refund message type.
522
-        $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
523
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
524
-    }
525
-
526
-
527
-    /**
528
-     * @param EE_Transaction $transaction
529
-     * @throws EE_Error
530
-     * @throws InvalidArgumentException
531
-     * @throws InvalidDataTypeException
532
-     * @throws InvalidInterfaceException
533
-     * @throws ReflectionException
534
-     */
535
-    public static function cancelled_registration(EE_Transaction $transaction)
536
-    {
537
-        self::_load_controller();
538
-        $data = array($transaction, null);
539
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data);
540
-    }
541
-
542
-
543
-    /**
544
-     * Trigger for Registration messages
545
-     * Note that what registration message type is sent depends on what the reg status is for the registrations on the
546
-     * incoming transaction.
547
-     *
548
-     * @param EE_Registration $registration
549
-     * @param array           $extra_details
550
-     * @return void
551
-     * @throws EE_Error
552
-     * @throws InvalidArgumentException
553
-     * @throws InvalidDataTypeException
554
-     * @throws InvalidInterfaceException
555
-     * @throws ReflectionException
556
-     * @throws EntityNotFoundException
557
-     */
558
-    public static function maybe_registration(EE_Registration $registration, $extra_details = array())
559
-    {
560
-
561
-        if (! self::_verify_registration_notification_send($registration, $extra_details)) {
562
-            // no messages please
563
-            return;
564
-        }
565
-
566
-        // get all non-trashed registrations so we make sure we send messages for the right status.
567
-        $all_registrations = $registration->transaction()->registrations(
568
-            array(
569
-                array('REG_deleted' => false),
570
-                'order_by' => array(
571
-                    'Event.EVT_name'     => 'ASC',
572
-                    'Attendee.ATT_lname' => 'ASC',
573
-                    'Attendee.ATT_fname' => 'ASC',
574
-                ),
575
-            )
576
-        );
577
-        // cached array of statuses so we only trigger messages once per status.
578
-        $statuses_sent = array();
579
-        self::_load_controller();
580
-        $mtgs = array();
581
-
582
-        // loop through registrations and trigger messages once per status.
583
-        foreach ($all_registrations as $reg) {
584
-            // already triggered?
585
-            if (in_array($reg->status_ID(), $statuses_sent)) {
586
-                continue;
587
-            }
588
-
589
-            $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID());
590
-            $mtgs = array_merge(
591
-                $mtgs,
592
-                self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
593
-                    $message_type,
594
-                    array($registration->transaction(), null, $reg->status_ID())
595
-                )
596
-            );
597
-            $statuses_sent[] = $reg->status_ID();
598
-        }
599
-
600
-        if (count($statuses_sent) > 1) {
601
-            $mtgs = array_merge(
602
-                $mtgs,
603
-                self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
604
-                    'registration_summary',
605
-                    array($registration->transaction(), null)
606
-                )
607
-            );
608
-        }
609
-
610
-        // batch queue and initiate request
611
-        self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs);
612
-        self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
613
-    }
614
-
615
-
616
-    /**
617
-     * This is a helper method used to very whether a registration notification should be sent or
618
-     * not.  Prevents duplicate notifications going out for registration context notifications.
619
-     *
620
-     * @param EE_Registration $registration  [description]
621
-     * @param array           $extra_details [description]
622
-     * @return bool          true = send away, false = nope halt the presses.
623
-     */
624
-    protected static function _verify_registration_notification_send(
625
-        EE_Registration $registration,
626
-        $extra_details = array()
627
-    ) {
628
-        $request = self::getRequest();
629
-        if (
630
-            ! $request->getRequestParam('non_primary_reg_notification', 0, 'int')
631
-            && ! $registration->is_primary_registrant()
632
-        ) {
633
-            return false;
634
-        }
635
-        // first we check if we're in admin and not doing front ajax
636
-        if (
637
-            ($request->isAdmin() || $request->isAdminAjax())
638
-            && ! $request->isFrontAjax()
639
-        ) {
640
-            $status_change = $request->getRequestParam('txn_reg_status_change', [], 'int', true);
641
-            // make sure appropriate admin params are set for sending messages
642
-            if (
643
-                ! isset($status_change['send_notifications'])
644
-                || (isset($status_change['send_notifications']) && ! $status_change['send_notifications'])
645
-            ) {
646
-                // no messages sent please.
647
-                return false;
648
-            }
649
-        } else {
650
-            // frontend request (either regular or via AJAX)
651
-            // TXN is NOT finalized ?
652
-            if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
653
-                return false;
654
-            }
655
-            // return visit but nothing changed ???
656
-            if (
657
-                isset($extra_details['revisit'], $extra_details['status_updates']) &&
658
-                $extra_details['revisit'] && ! $extra_details['status_updates']
659
-            ) {
660
-                return false;
661
-            }
662
-            // NOT sending messages && reg status is something other than "Not-Approved"
663
-            if (
664
-                ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) &&
665
-                $registration->status_ID() !== EEM_Registration::status_id_not_approved
666
-            ) {
667
-                return false;
668
-            }
669
-        }
670
-        // release the kraken
671
-        return true;
672
-    }
673
-
674
-
675
-    /**
676
-     * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that
677
-     * status id.
678
-     *
679
-     * @deprecated 4.9.0  Use EEH_MSG_Template::reg_status_to_message_type_array()
680
-     *                    or EEH_MSG_Template::convert_reg_status_to_message_type
681
-     * @param string $reg_status
682
-     * @return array
683
-     * @throws EE_Error
684
-     * @throws InvalidArgumentException
685
-     * @throws ReflectionException
686
-     * @throws InvalidDataTypeException
687
-     * @throws InvalidInterfaceException
688
-     */
689
-    protected static function _get_reg_status_array($reg_status = '')
690
-    {
691
-        EE_Registry::instance()->load_helper('MSG_Template');
692
-        return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
693
-            ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
694
-            : EEH_MSG_Template::reg_status_to_message_type_array();
695
-    }
696
-
697
-
698
-    /**
699
-     * Simply returns the payment message type for the given payment status.
700
-     *
701
-     * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array
702
-     *                   or EEH_MSG_Template::convert_payment_status_to_message_type
703
-     * @param string $payment_status The payment status being matched.
704
-     * @return bool|string The payment message type slug matching the status or false if no match.
705
-     * @throws EE_Error
706
-     * @throws InvalidArgumentException
707
-     * @throws ReflectionException
708
-     * @throws InvalidDataTypeException
709
-     * @throws InvalidInterfaceException
710
-     */
711
-    protected static function _get_payment_message_type($payment_status)
712
-    {
713
-        EE_Registry::instance()->load_helper('MSG_Template');
714
-        return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
715
-            ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
716
-            : false;
717
-    }
718
-
719
-
720
-    /**
721
-     * Message triggers for a resending already sent message(s) (via EE_Message list table)
722
-     *
723
-     * @access public
724
-     * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages
725
-     * @return bool success/fail
726
-     * @throws EE_Error
727
-     * @throws InvalidArgumentException
728
-     * @throws InvalidDataTypeException
729
-     * @throws InvalidInterfaceException
730
-     * @throws ReflectionException
731
-     */
732
-    public static function process_resend(array $req_data = [])
733
-    {
734
-        self::_load_controller();
735
-        $request = self::getRequest();
736
-        // if $msgID in this request then skip to the new resend_message
737
-        if ($request->getRequestParam('MSG_ID')) {
738
-            return self::resend_message();
739
-        }
740
-
741
-        // make sure any incoming request data is set on the request so that it gets picked up later.
742
-        foreach ((array) $req_data as $request_key => $request_value) {
743
-            if (! $request->requestParamIsSet($request_key)) {
744
-                $request->setRequestParam($request_key, $request_value);
745
-            }
746
-        }
747
-
748
-        if (
749
-            ! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()
750
-        ) {
751
-            return false;
752
-        }
753
-
754
-        try {
755
-            self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send);
756
-            self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
757
-        } catch (EE_Error $e) {
758
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
759
-            return false;
760
-        }
761
-        EE_Error::add_success(
762
-            esc_html__('Messages have been successfully queued for generation and sending.', 'event_espresso')
763
-        );
764
-        return true; // everything got queued.
765
-    }
766
-
767
-
768
-    /**
769
-     * Message triggers for a resending already sent message(s) (via EE_Message list table)
770
-     *
771
-     * @return bool
772
-     * @throws EE_Error
773
-     * @throws InvalidArgumentException
774
-     * @throws InvalidDataTypeException
775
-     * @throws InvalidInterfaceException
776
-     * @throws ReflectionException
777
-     */
778
-    public static function resend_message()
779
-    {
780
-        self::_load_controller();
781
-
782
-        $msgID = self::getRequest()->getRequestParam('MSG_ID', 0, 'int');
783
-        if (! $msgID) {
784
-            EE_Error::add_error(
785
-                esc_html__(
786
-                    'Something went wrong because there is no "MSG_ID" value in the request',
787
-                    'event_espresso'
788
-                ),
789
-                __FILE__,
790
-                __FUNCTION__,
791
-                __LINE__
792
-            );
793
-            return false;
794
-        }
795
-
796
-        self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID);
797
-
798
-        // setup success message.
799
-        $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
800
-        EE_Error::add_success(
801
-            sprintf(
802
-                _n(
803
-                    'There was %d message queued for resending.',
804
-                    'There were %d messages queued for resending.',
805
-                    $count_ready_for_resend,
806
-                    'event_espresso'
807
-                ),
808
-                $count_ready_for_resend
809
-            )
810
-        );
811
-        return true;
812
-    }
813
-
814
-
815
-    /**
816
-     * Message triggers for manual payment applied by admin
817
-     *
818
-     * @param  EE_Payment $payment EE_payment object
819
-     * @return bool success/fail
820
-     * @throws EE_Error
821
-     * @throws InvalidArgumentException
822
-     * @throws ReflectionException
823
-     * @throws InvalidDataTypeException
824
-     * @throws InvalidInterfaceException
825
-     */
826
-    public static function process_admin_payment(EE_Payment $payment)
827
-    {
828
-        EE_Registry::instance()->load_helper('MSG_Template');
829
-        // we need to get the transaction object
830
-        $transaction = $payment->transaction();
831
-        if ($transaction instanceof EE_Transaction) {
832
-            $data = array($transaction, $payment);
833
-            $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
834
-
835
-            // if payment amount is less than 0 then switch to payment_refund message type.
836
-            $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
837
-
838
-            // if payment_refund is selected, but the status is NOT accepted.  Then change message type to false so NO message notification goes out.
839
-            $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved
840
-                ? false : $message_type;
841
-
842
-            self::_load_controller();
843
-
844
-            self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
845
-
846
-            // get count of queued for generation
847
-            $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
848
-                array(
849
-                    EEM_Message::status_incomplete,
850
-                    EEM_Message::status_idle,
851
-                )
852
-            );
853
-
854
-            if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) {
855
-                add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
856
-                return true;
857
-            } else {
858
-                $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
859
-                    EEM_Message::instance()->stati_indicating_failed_sending()
860
-                );
861
-                /**
862
-                 * Verify that there are actually errors.  If not then we return a success message because the queue might have been emptied due to successful
863
-                 * IMMEDIATE generation.
864
-                 */
865
-                if ($count_failed > 0) {
866
-                    EE_Error::add_error(
867
-                        sprintf(
868
-                            _n(
869
-                                'The payment notification generation failed.',
870
-                                '%d payment notifications failed being sent.',
871
-                                $count_failed,
872
-                                'event_espresso'
873
-                            ),
874
-                            $count_failed
875
-                        ),
876
-                        __FILE__,
877
-                        __FUNCTION__,
878
-                        __LINE__
879
-                    );
880
-
881
-                    return false;
882
-                } else {
883
-                    add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
884
-                    return true;
885
-                }
886
-            }
887
-        } else {
888
-            EE_Error::add_error(
889
-                'Unable to generate the payment notification because the given value for the transaction is invalid.',
890
-                'event_espresso'
891
-            );
892
-            return false;
893
-        }
894
-    }
895
-
896
-
897
-    /**
898
-     * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger
899
-     *
900
-     * @since   4.3.0
901
-     * @param  EE_Registration[] $registrations an array of EE_Registration objects
902
-     * @param  int               $grp_id        a specific message template group id.
903
-     * @return void
904
-     * @throws EE_Error
905
-     * @throws InvalidArgumentException
906
-     * @throws InvalidDataTypeException
907
-     * @throws InvalidInterfaceException
908
-     * @throws ReflectionException
909
-     */
910
-    public static function send_newsletter_message($registrations, $grp_id)
911
-    {
912
-        // make sure mtp is id and set it in the request later messages setup.
913
-        self::getRequest()->setRequestParam('GRP_ID', (int) $grp_id);
914
-        self::_load_controller();
915
-        self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations);
916
-    }
917
-
918
-
919
-    /**
920
-     * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url
921
-     *
922
-     * @since   4.3.0
923
-     * @param    string          $registration_message_trigger_url
924
-     * @param    EE_Registration $registration
925
-     * @param string             $messenger
926
-     * @param string             $message_type
927
-     * @return string
928
-     * @throws EE_Error
929
-     * @throws InvalidArgumentException
930
-     * @throws InvalidDataTypeException
931
-     * @throws InvalidInterfaceException
932
-     */
933
-    public static function registration_message_trigger_url(
934
-        $registration_message_trigger_url,
935
-        EE_Registration $registration,
936
-        $messenger = 'html',
937
-        $message_type = 'invoice'
938
-    ) {
939
-        // whitelist $messenger
940
-        switch ($messenger) {
941
-            case 'pdf':
942
-                $sending_messenger = 'pdf';
943
-                $generating_messenger = 'html';
944
-                break;
945
-            case 'html':
946
-            default:
947
-                $sending_messenger = 'html';
948
-                $generating_messenger = 'html';
949
-                break;
950
-        }
951
-        // whitelist $message_type
952
-        switch ($message_type) {
953
-            case 'receipt':
954
-                $message_type = 'receipt';
955
-                break;
956
-            case 'invoice':
957
-            default:
958
-                $message_type = 'invoice';
959
-                break;
960
-        }
961
-        // verify that both the messenger AND the message type are active
962
-        if (
963
-            EEH_MSG_Template::is_messenger_active($sending_messenger)
964
-            && EEH_MSG_Template::is_mt_active($message_type)
965
-        ) {
966
-            // need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?)
967
-            $template_query_params = array(
968
-                'MTP_is_active'    => true,
969
-                'MTP_messenger'    => $generating_messenger,
970
-                'MTP_message_type' => $message_type,
971
-                'Event.EVT_ID'     => $registration->event_ID(),
972
-            );
973
-            // get the message template group.
974
-            $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
975
-            // if we don't have an EE_Message_Template_Group then return
976
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
977
-                // remove EVT_ID from query params so that global templates get picked up
978
-                unset($template_query_params['Event.EVT_ID']);
979
-                // get global template as the fallback
980
-                $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
981
-            }
982
-            // if we don't have an EE_Message_Template_Group then return
983
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
984
-                return '';
985
-            }
986
-            // generate the URL
987
-            $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger(
988
-                $sending_messenger,
989
-                $generating_messenger,
990
-                'purchaser',
991
-                $message_type,
992
-                $registration,
993
-                $msg_template_group->ID(),
994
-                $registration->transaction_ID()
995
-            );
996
-        }
997
-        return $registration_message_trigger_url;
998
-    }
999
-
1000
-
1001
-    /**
1002
-     * Use to generate and return a message preview!
1003
-     *
1004
-     * @param  string $type      This should correspond with a valid message type
1005
-     * @param  string $context   This should correspond with a valid context for the message type
1006
-     * @param  string $messenger This should correspond with a valid messenger.
1007
-     * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
1008
-     *                           preview
1009
-     * @return bool|string The body of the message or if send is requested, sends.
1010
-     * @throws EE_Error
1011
-     * @throws InvalidArgumentException
1012
-     * @throws InvalidDataTypeException
1013
-     * @throws InvalidInterfaceException
1014
-     * @throws ReflectionException
1015
-     */
1016
-    public static function preview_message($type, $context, $messenger, $send = false)
1017
-    {
1018
-        self::_load_controller();
1019
-        $mtg = new EE_Message_To_Generate(
1020
-            $messenger,
1021
-            $type,
1022
-            array(),
1023
-            $context,
1024
-            true
1025
-        );
1026
-        $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send);
1027
-        if ($generated_preview_queue instanceof EE_Messages_Queue) {
1028
-            // loop through all content for the preview and remove any persisted records.
1029
-            $content = '';
1030
-            foreach ($generated_preview_queue->get_message_repository() as $message) {
1031
-                $content = $message->content();
1032
-                if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) {
1033
-                    $message->delete();
1034
-                }
1035
-            }
1036
-            return $content;
1037
-        } else {
1038
-            return $generated_preview_queue;
1039
-        }
1040
-    }
1041
-
1042
-
1043
-    /**
1044
-     * This is a method that allows for sending a message using a messenger matching the string given and the provided
1045
-     * EE_Message_Queue object.  The EE_Message_Queue object is used to create a single aggregate EE_Message via the
1046
-     * content found in the EE_Message objects in the queue.
1047
-     *
1048
-     * @since 4.9.0
1049
-     * @param string            $messenger            a string matching a valid active messenger in the system
1050
-     * @param string            $message_type         Although it seems contrary to the name of the method, a message
1051
-     *                                                type name is still required to send along the message type to the
1052
-     *                                                messenger because this is used for determining what specific
1053
-     *                                                variations might be loaded for the generated message.
1054
-     * @param EE_Messages_Queue $queue
1055
-     * @param string            $custom_subject       Can be used to set what the custom subject string will be on the
1056
-     *                                                aggregate EE_Message object.
1057
-     * @return bool success or fail.
1058
-     * @throws EE_Error
1059
-     * @throws InvalidArgumentException
1060
-     * @throws ReflectionException
1061
-     * @throws InvalidDataTypeException
1062
-     * @throws InvalidInterfaceException
1063
-     */
1064
-    public static function send_message_with_messenger_only(
1065
-        $messenger,
1066
-        $message_type,
1067
-        EE_Messages_Queue $queue,
1068
-        $custom_subject = ''
1069
-    ) {
1070
-        self::_load_controller();
1071
-        /** @type EE_Message_To_Generate_From_Queue $message_to_generate */
1072
-        $message_to_generate = EE_Registry::instance()->load_lib(
1073
-            'Message_To_Generate_From_Queue',
1074
-            array(
1075
-                $messenger,
1076
-                $message_type,
1077
-                $queue,
1078
-                $custom_subject,
1079
-            )
1080
-        );
1081
-        return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate);
1082
-    }
1083
-
1084
-
1085
-    /**
1086
-     * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation)
1087
-     *
1088
-     * @since 4.9.0
1089
-     * @param array $message_ids An array of message ids
1090
-     * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated
1091
-     *                           messages.
1092
-     * @throws EE_Error
1093
-     * @throws InvalidArgumentException
1094
-     * @throws InvalidDataTypeException
1095
-     * @throws InvalidInterfaceException
1096
-     * @throws ReflectionException
1097
-     */
1098
-    public static function generate_now($message_ids)
1099
-    {
1100
-        self::_load_controller();
1101
-        $messages = EEM_Message::instance()->get_all(
1102
-            array(
1103
-                0 => array(
1104
-                    'MSG_ID' => array('IN', $message_ids),
1105
-                    'STS_ID' => EEM_Message::status_incomplete,
1106
-                ),
1107
-            )
1108
-        );
1109
-        $generated_queue = false;
1110
-        if ($messages) {
1111
-            $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
1112
-        }
1113
-
1114
-        if (! $generated_queue instanceof EE_Messages_Queue) {
1115
-            EE_Error::add_error(
1116
-                esc_html__(
1117
-                    'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.',
1118
-                    'event_espresso'
1119
-                ),
1120
-                __FILE__,
1121
-                __FUNCTION__,
1122
-                __LINE__
1123
-            );
1124
-        }
1125
-        return $generated_queue;
1126
-    }
1127
-
1128
-
1129
-    /**
1130
-     * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or,
1131
-     * EEM_Message::status_idle
1132
-     *
1133
-     * @since 4.9.0
1134
-     * @param $message_ids
1135
-     * @return bool|EE_Messages_Queue false if no messages sent.
1136
-     * @throws EE_Error
1137
-     * @throws InvalidArgumentException
1138
-     * @throws InvalidDataTypeException
1139
-     * @throws InvalidInterfaceException
1140
-     * @throws ReflectionException
1141
-     */
1142
-    public static function send_now($message_ids)
1143
-    {
1144
-        self::_load_controller();
1145
-        $messages = EEM_Message::instance()->get_all(
1146
-            array(
1147
-                0 => array(
1148
-                    'MSG_ID' => array('IN', $message_ids),
1149
-                    'STS_ID' => array(
1150
-                        'IN',
1151
-                        array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry),
1152
-                    ),
1153
-                ),
1154
-            )
1155
-        );
1156
-        $sent_queue = false;
1157
-        if ($messages) {
1158
-            $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
1159
-        }
1160
-
1161
-        if (! $sent_queue instanceof EE_Messages_Queue) {
1162
-            EE_Error::add_error(
1163
-                esc_html__(
1164
-                    'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.',
1165
-                    'event_espresso'
1166
-                ),
1167
-                __FILE__,
1168
-                __FUNCTION__,
1169
-                __LINE__
1170
-            );
1171
-        } else {
1172
-            // can count how many sent by using the messages in the queue
1173
-            $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent());
1174
-            if ($sent_count > 0) {
1175
-                EE_Error::add_success(
1176
-                    sprintf(
1177
-                        _n(
1178
-                            'There was %d message successfully sent.',
1179
-                            'There were %d messages successfully sent.',
1180
-                            $sent_count,
1181
-                            'event_espresso'
1182
-                        ),
1183
-                        $sent_count
1184
-                    )
1185
-                );
1186
-            } else {
1187
-                EE_Error::overwrite_errors();
1188
-                EE_Error::add_error(
1189
-                    esc_html__(
1190
-                        'No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error.
261
+				exit;
262
+			}
263
+		}
264
+	}
265
+
266
+
267
+	/**
268
+	 *  This runs when the msg_url_trigger route has initiated.
269
+	 *
270
+	 * @since 4.5.0
271
+	 * @param WP $WP
272
+	 * @throws EE_Error
273
+	 * @throws InvalidArgumentException
274
+	 * @throws ReflectionException
275
+	 * @throws InvalidDataTypeException
276
+	 * @throws InvalidInterfaceException
277
+	 */
278
+	public function run($WP)
279
+	{
280
+		// ensure controller is loaded
281
+		self::_load_controller();
282
+		// attempt to process message
283
+		try {
284
+			/** @type EE_Message_To_Generate_From_Request $message_to_generate */
285
+			$message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request');
286
+			self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate);
287
+		} catch (EE_Error $e) {
288
+			$error_msg = esc_html__(
289
+				'Please note that a system message failed to send due to a technical issue.',
290
+				'event_espresso'
291
+			);
292
+			// add specific message for developers if WP_DEBUG in on
293
+			$error_msg .= '||' . $e->getMessage();
294
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
295
+		}
296
+	}
297
+
298
+
299
+	/**
300
+	 * This is triggered by the 'msg_cron_trigger' route.
301
+	 *
302
+	 * @param WP $WP
303
+	 */
304
+	public function execute_batch_request($WP)
305
+	{
306
+		$this->run_cron();
307
+		header('HTTP/1.1 200 OK');
308
+		exit();
309
+	}
310
+
311
+
312
+	/**
313
+	 * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp
314
+	 * request.
315
+	 */
316
+	public function run_cron()
317
+	{
318
+		self::_load_controller();
319
+		$request = self::getRequest();
320
+		// get required vars
321
+		$cron_type = $request->getRequestParam('type');
322
+		$transient_key = $request->getRequestParam('key');
323
+
324
+		// now let's verify transient, if not valid exit immediately
325
+		if (! get_transient($transient_key)) {
326
+			/**
327
+			 * trigger error so this gets in the error logs.  This is important because it happens on a non-user
328
+			 * request.
329
+			 */
330
+			trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso'));
331
+		}
332
+
333
+		// if made it here, lets' delete the transient to keep the db clean
334
+		delete_transient($transient_key);
335
+
336
+		if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
337
+			$method = 'batch_' . $cron_type . '_from_queue';
338
+			if (method_exists(self::$_MSG_PROCESSOR, $method)) {
339
+				self::$_MSG_PROCESSOR->$method();
340
+			} else {
341
+				// no matching task
342
+				/**
343
+				 * trigger error so this gets in the error logs.  This is important because it happens on a non user
344
+				 * request.
345
+				 */
346
+				trigger_error(
347
+					esc_attr(
348
+						sprintf(
349
+							esc_html__('There is no task corresponding to this route %s', 'event_espresso'),
350
+							$cron_type
351
+						)
352
+					)
353
+				);
354
+			}
355
+		}
356
+
357
+		do_action('FHEE__EED_Messages__run_cron__end');
358
+	}
359
+
360
+
361
+	/**
362
+	 * This is used to retrieve the template pack for the given name.
363
+	 * Retrieved packs are cached on the static $_TMP_PACKS array.  If there is no class matching the given name then
364
+	 * the default template pack is returned.
365
+	 *
366
+	 * @deprecated 4.9.0  @see EEH_MSG_Template::get_template_pack()
367
+	 * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used
368
+	 *                                   in generating the Pack class name).
369
+	 * @return EE_Messages_Template_Pack
370
+	 * @throws EE_Error
371
+	 * @throws InvalidArgumentException
372
+	 * @throws ReflectionException
373
+	 * @throws InvalidDataTypeException
374
+	 * @throws InvalidInterfaceException
375
+	 */
376
+	public static function get_template_pack($template_pack_name)
377
+	{
378
+		EE_Registry::instance()->load_helper('MSG_Template');
379
+		return EEH_MSG_Template::get_template_pack($template_pack_name);
380
+	}
381
+
382
+
383
+	/**
384
+	 * Retrieves an array of all template packs.
385
+	 * Array is in the format array( 'dbref' => EE_Messages_Template_Pack )
386
+	 *
387
+	 * @deprecated 4.9.0  @see EEH_MSG_Template_Pack::get_template_pack_collection
388
+	 * @return EE_Messages_Template_Pack[]
389
+	 * @throws EE_Error
390
+	 * @throws InvalidArgumentException
391
+	 * @throws ReflectionException
392
+	 * @throws InvalidDataTypeException
393
+	 * @throws InvalidInterfaceException
394
+	 */
395
+	public static function get_template_packs()
396
+	{
397
+		EE_Registry::instance()->load_helper('MSG_Template');
398
+
399
+		// for backward compat, let's make sure this returns in the same format as originally.
400
+		$template_pack_collection = EEH_MSG_Template::get_template_pack_collection();
401
+		$template_pack_collection->rewind();
402
+		$template_packs = array();
403
+		while ($template_pack_collection->valid()) {
404
+			$template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current();
405
+			$template_pack_collection->next();
406
+		}
407
+		return $template_packs;
408
+	}
409
+
410
+
411
+	/**
412
+	 * This simply makes sure the autoloaders are registered for the EE_messages system.
413
+	 *
414
+	 * @since 4.5.0
415
+	 * @return void
416
+	 * @throws EE_Error
417
+	 */
418
+	public static function set_autoloaders()
419
+	{
420
+		if (empty(self::$_MSG_PATHS)) {
421
+			self::_set_messages_paths();
422
+			foreach (self::$_MSG_PATHS as $path) {
423
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path);
424
+			}
425
+			// add aliases
426
+			EEH_Autoloader::add_alias('EE_messages', 'EE_messages');
427
+			EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger');
428
+		}
429
+	}
430
+
431
+
432
+	/**
433
+	 * Take care of adding all the paths for the messages components to the $_MSG_PATHS property
434
+	 * for use by the Messages Autoloaders
435
+	 *
436
+	 * @since 4.5.0
437
+	 * @return void.
438
+	 */
439
+	protected static function _set_messages_paths()
440
+	{
441
+		$dir_ref = array(
442
+			'messages/message_type',
443
+			'messages/messenger',
444
+			'messages/defaults',
445
+			'messages/defaults/email',
446
+			'messages/data_class',
447
+			'messages/validators',
448
+			'messages/validators/email',
449
+			'messages/validators/html',
450
+			'shortcodes',
451
+		);
452
+		$paths = array();
453
+		foreach ($dir_ref as $index => $dir) {
454
+			$paths[ $index ] = EE_LIBRARIES . $dir;
455
+		}
456
+		self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths);
457
+	}
458
+
459
+
460
+	/**
461
+	 * Takes care of loading dependencies
462
+	 *
463
+	 * @since 4.5.0
464
+	 * @return void
465
+	 * @throws EE_Error
466
+	 * @throws InvalidArgumentException
467
+	 * @throws ReflectionException
468
+	 * @throws InvalidDataTypeException
469
+	 * @throws InvalidInterfaceException
470
+	 */
471
+	protected static function _load_controller()
472
+	{
473
+		if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
474
+			EE_Registry::instance()->load_core('Request_Handler');
475
+			self::set_autoloaders();
476
+			self::$_EEMSG = EE_Registry::instance()->load_lib('messages');
477
+			self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor');
478
+			self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
479
+		}
480
+	}
481
+
482
+
483
+	/**
484
+	 * @param EE_Transaction $transaction
485
+	 * @throws EE_Error
486
+	 * @throws InvalidArgumentException
487
+	 * @throws InvalidDataTypeException
488
+	 * @throws InvalidInterfaceException
489
+	 * @throws ReflectionException
490
+	 */
491
+	public static function payment_reminder(EE_Transaction $transaction)
492
+	{
493
+		self::_load_controller();
494
+		$data = array($transaction, null);
495
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data);
496
+	}
497
+
498
+
499
+	/**
500
+	 * Any messages triggers for after successful gateway payments should go in here.
501
+	 *
502
+	 * @param EE_Transaction  $transaction object
503
+	 * @param EE_Payment|null $payment     object
504
+	 * @return void
505
+	 * @throws EE_Error
506
+	 * @throws InvalidArgumentException
507
+	 * @throws ReflectionException
508
+	 * @throws InvalidDataTypeException
509
+	 * @throws InvalidInterfaceException
510
+	 */
511
+	public static function payment(EE_Transaction $transaction, EE_Payment $payment = null)
512
+	{
513
+		// if there's no payment object, then we cannot do a payment type message!
514
+		if (! $payment instanceof EE_Payment) {
515
+			return;
516
+		}
517
+		self::_load_controller();
518
+		$data = array($transaction, $payment);
519
+		EE_Registry::instance()->load_helper('MSG_Template');
520
+		$message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
521
+		// if payment amount is less than 0 then switch to payment_refund message type.
522
+		$message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
523
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
524
+	}
525
+
526
+
527
+	/**
528
+	 * @param EE_Transaction $transaction
529
+	 * @throws EE_Error
530
+	 * @throws InvalidArgumentException
531
+	 * @throws InvalidDataTypeException
532
+	 * @throws InvalidInterfaceException
533
+	 * @throws ReflectionException
534
+	 */
535
+	public static function cancelled_registration(EE_Transaction $transaction)
536
+	{
537
+		self::_load_controller();
538
+		$data = array($transaction, null);
539
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data);
540
+	}
541
+
542
+
543
+	/**
544
+	 * Trigger for Registration messages
545
+	 * Note that what registration message type is sent depends on what the reg status is for the registrations on the
546
+	 * incoming transaction.
547
+	 *
548
+	 * @param EE_Registration $registration
549
+	 * @param array           $extra_details
550
+	 * @return void
551
+	 * @throws EE_Error
552
+	 * @throws InvalidArgumentException
553
+	 * @throws InvalidDataTypeException
554
+	 * @throws InvalidInterfaceException
555
+	 * @throws ReflectionException
556
+	 * @throws EntityNotFoundException
557
+	 */
558
+	public static function maybe_registration(EE_Registration $registration, $extra_details = array())
559
+	{
560
+
561
+		if (! self::_verify_registration_notification_send($registration, $extra_details)) {
562
+			// no messages please
563
+			return;
564
+		}
565
+
566
+		// get all non-trashed registrations so we make sure we send messages for the right status.
567
+		$all_registrations = $registration->transaction()->registrations(
568
+			array(
569
+				array('REG_deleted' => false),
570
+				'order_by' => array(
571
+					'Event.EVT_name'     => 'ASC',
572
+					'Attendee.ATT_lname' => 'ASC',
573
+					'Attendee.ATT_fname' => 'ASC',
574
+				),
575
+			)
576
+		);
577
+		// cached array of statuses so we only trigger messages once per status.
578
+		$statuses_sent = array();
579
+		self::_load_controller();
580
+		$mtgs = array();
581
+
582
+		// loop through registrations and trigger messages once per status.
583
+		foreach ($all_registrations as $reg) {
584
+			// already triggered?
585
+			if (in_array($reg->status_ID(), $statuses_sent)) {
586
+				continue;
587
+			}
588
+
589
+			$message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID());
590
+			$mtgs = array_merge(
591
+				$mtgs,
592
+				self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
593
+					$message_type,
594
+					array($registration->transaction(), null, $reg->status_ID())
595
+				)
596
+			);
597
+			$statuses_sent[] = $reg->status_ID();
598
+		}
599
+
600
+		if (count($statuses_sent) > 1) {
601
+			$mtgs = array_merge(
602
+				$mtgs,
603
+				self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers(
604
+					'registration_summary',
605
+					array($registration->transaction(), null)
606
+				)
607
+			);
608
+		}
609
+
610
+		// batch queue and initiate request
611
+		self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs);
612
+		self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
613
+	}
614
+
615
+
616
+	/**
617
+	 * This is a helper method used to very whether a registration notification should be sent or
618
+	 * not.  Prevents duplicate notifications going out for registration context notifications.
619
+	 *
620
+	 * @param EE_Registration $registration  [description]
621
+	 * @param array           $extra_details [description]
622
+	 * @return bool          true = send away, false = nope halt the presses.
623
+	 */
624
+	protected static function _verify_registration_notification_send(
625
+		EE_Registration $registration,
626
+		$extra_details = array()
627
+	) {
628
+		$request = self::getRequest();
629
+		if (
630
+			! $request->getRequestParam('non_primary_reg_notification', 0, 'int')
631
+			&& ! $registration->is_primary_registrant()
632
+		) {
633
+			return false;
634
+		}
635
+		// first we check if we're in admin and not doing front ajax
636
+		if (
637
+			($request->isAdmin() || $request->isAdminAjax())
638
+			&& ! $request->isFrontAjax()
639
+		) {
640
+			$status_change = $request->getRequestParam('txn_reg_status_change', [], 'int', true);
641
+			// make sure appropriate admin params are set for sending messages
642
+			if (
643
+				! isset($status_change['send_notifications'])
644
+				|| (isset($status_change['send_notifications']) && ! $status_change['send_notifications'])
645
+			) {
646
+				// no messages sent please.
647
+				return false;
648
+			}
649
+		} else {
650
+			// frontend request (either regular or via AJAX)
651
+			// TXN is NOT finalized ?
652
+			if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
653
+				return false;
654
+			}
655
+			// return visit but nothing changed ???
656
+			if (
657
+				isset($extra_details['revisit'], $extra_details['status_updates']) &&
658
+				$extra_details['revisit'] && ! $extra_details['status_updates']
659
+			) {
660
+				return false;
661
+			}
662
+			// NOT sending messages && reg status is something other than "Not-Approved"
663
+			if (
664
+				! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) &&
665
+				$registration->status_ID() !== EEM_Registration::status_id_not_approved
666
+			) {
667
+				return false;
668
+			}
669
+		}
670
+		// release the kraken
671
+		return true;
672
+	}
673
+
674
+
675
+	/**
676
+	 * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that
677
+	 * status id.
678
+	 *
679
+	 * @deprecated 4.9.0  Use EEH_MSG_Template::reg_status_to_message_type_array()
680
+	 *                    or EEH_MSG_Template::convert_reg_status_to_message_type
681
+	 * @param string $reg_status
682
+	 * @return array
683
+	 * @throws EE_Error
684
+	 * @throws InvalidArgumentException
685
+	 * @throws ReflectionException
686
+	 * @throws InvalidDataTypeException
687
+	 * @throws InvalidInterfaceException
688
+	 */
689
+	protected static function _get_reg_status_array($reg_status = '')
690
+	{
691
+		EE_Registry::instance()->load_helper('MSG_Template');
692
+		return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
693
+			? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status)
694
+			: EEH_MSG_Template::reg_status_to_message_type_array();
695
+	}
696
+
697
+
698
+	/**
699
+	 * Simply returns the payment message type for the given payment status.
700
+	 *
701
+	 * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array
702
+	 *                   or EEH_MSG_Template::convert_payment_status_to_message_type
703
+	 * @param string $payment_status The payment status being matched.
704
+	 * @return bool|string The payment message type slug matching the status or false if no match.
705
+	 * @throws EE_Error
706
+	 * @throws InvalidArgumentException
707
+	 * @throws ReflectionException
708
+	 * @throws InvalidDataTypeException
709
+	 * @throws InvalidInterfaceException
710
+	 */
711
+	protected static function _get_payment_message_type($payment_status)
712
+	{
713
+		EE_Registry::instance()->load_helper('MSG_Template');
714
+		return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
715
+			? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status)
716
+			: false;
717
+	}
718
+
719
+
720
+	/**
721
+	 * Message triggers for a resending already sent message(s) (via EE_Message list table)
722
+	 *
723
+	 * @access public
724
+	 * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages
725
+	 * @return bool success/fail
726
+	 * @throws EE_Error
727
+	 * @throws InvalidArgumentException
728
+	 * @throws InvalidDataTypeException
729
+	 * @throws InvalidInterfaceException
730
+	 * @throws ReflectionException
731
+	 */
732
+	public static function process_resend(array $req_data = [])
733
+	{
734
+		self::_load_controller();
735
+		$request = self::getRequest();
736
+		// if $msgID in this request then skip to the new resend_message
737
+		if ($request->getRequestParam('MSG_ID')) {
738
+			return self::resend_message();
739
+		}
740
+
741
+		// make sure any incoming request data is set on the request so that it gets picked up later.
742
+		foreach ((array) $req_data as $request_key => $request_value) {
743
+			if (! $request->requestParamIsSet($request_key)) {
744
+				$request->setRequestParam($request_key, $request_value);
745
+			}
746
+		}
747
+
748
+		if (
749
+			! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()
750
+		) {
751
+			return false;
752
+		}
753
+
754
+		try {
755
+			self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send);
756
+			self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority();
757
+		} catch (EE_Error $e) {
758
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
759
+			return false;
760
+		}
761
+		EE_Error::add_success(
762
+			esc_html__('Messages have been successfully queued for generation and sending.', 'event_espresso')
763
+		);
764
+		return true; // everything got queued.
765
+	}
766
+
767
+
768
+	/**
769
+	 * Message triggers for a resending already sent message(s) (via EE_Message list table)
770
+	 *
771
+	 * @return bool
772
+	 * @throws EE_Error
773
+	 * @throws InvalidArgumentException
774
+	 * @throws InvalidDataTypeException
775
+	 * @throws InvalidInterfaceException
776
+	 * @throws ReflectionException
777
+	 */
778
+	public static function resend_message()
779
+	{
780
+		self::_load_controller();
781
+
782
+		$msgID = self::getRequest()->getRequestParam('MSG_ID', 0, 'int');
783
+		if (! $msgID) {
784
+			EE_Error::add_error(
785
+				esc_html__(
786
+					'Something went wrong because there is no "MSG_ID" value in the request',
787
+					'event_espresso'
788
+				),
789
+				__FILE__,
790
+				__FUNCTION__,
791
+				__LINE__
792
+			);
793
+			return false;
794
+		}
795
+
796
+		self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array) $msgID);
797
+
798
+		// setup success message.
799
+		$count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
800
+		EE_Error::add_success(
801
+			sprintf(
802
+				_n(
803
+					'There was %d message queued for resending.',
804
+					'There were %d messages queued for resending.',
805
+					$count_ready_for_resend,
806
+					'event_espresso'
807
+				),
808
+				$count_ready_for_resend
809
+			)
810
+		);
811
+		return true;
812
+	}
813
+
814
+
815
+	/**
816
+	 * Message triggers for manual payment applied by admin
817
+	 *
818
+	 * @param  EE_Payment $payment EE_payment object
819
+	 * @return bool success/fail
820
+	 * @throws EE_Error
821
+	 * @throws InvalidArgumentException
822
+	 * @throws ReflectionException
823
+	 * @throws InvalidDataTypeException
824
+	 * @throws InvalidInterfaceException
825
+	 */
826
+	public static function process_admin_payment(EE_Payment $payment)
827
+	{
828
+		EE_Registry::instance()->load_helper('MSG_Template');
829
+		// we need to get the transaction object
830
+		$transaction = $payment->transaction();
831
+		if ($transaction instanceof EE_Transaction) {
832
+			$data = array($transaction, $payment);
833
+			$message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID());
834
+
835
+			// if payment amount is less than 0 then switch to payment_refund message type.
836
+			$message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type;
837
+
838
+			// if payment_refund is selected, but the status is NOT accepted.  Then change message type to false so NO message notification goes out.
839
+			$message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved
840
+				? false : $message_type;
841
+
842
+			self::_load_controller();
843
+
844
+			self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data);
845
+
846
+			// get count of queued for generation
847
+			$count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
848
+				array(
849
+					EEM_Message::status_incomplete,
850
+					EEM_Message::status_idle,
851
+				)
852
+			);
853
+
854
+			if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) {
855
+				add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
856
+				return true;
857
+			} else {
858
+				$count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(
859
+					EEM_Message::instance()->stati_indicating_failed_sending()
860
+				);
861
+				/**
862
+				 * Verify that there are actually errors.  If not then we return a success message because the queue might have been emptied due to successful
863
+				 * IMMEDIATE generation.
864
+				 */
865
+				if ($count_failed > 0) {
866
+					EE_Error::add_error(
867
+						sprintf(
868
+							_n(
869
+								'The payment notification generation failed.',
870
+								'%d payment notifications failed being sent.',
871
+								$count_failed,
872
+								'event_espresso'
873
+							),
874
+							$count_failed
875
+						),
876
+						__FILE__,
877
+						__FUNCTION__,
878
+						__LINE__
879
+					);
880
+
881
+					return false;
882
+				} else {
883
+					add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true');
884
+					return true;
885
+				}
886
+			}
887
+		} else {
888
+			EE_Error::add_error(
889
+				'Unable to generate the payment notification because the given value for the transaction is invalid.',
890
+				'event_espresso'
891
+			);
892
+			return false;
893
+		}
894
+	}
895
+
896
+
897
+	/**
898
+	 * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger
899
+	 *
900
+	 * @since   4.3.0
901
+	 * @param  EE_Registration[] $registrations an array of EE_Registration objects
902
+	 * @param  int               $grp_id        a specific message template group id.
903
+	 * @return void
904
+	 * @throws EE_Error
905
+	 * @throws InvalidArgumentException
906
+	 * @throws InvalidDataTypeException
907
+	 * @throws InvalidInterfaceException
908
+	 * @throws ReflectionException
909
+	 */
910
+	public static function send_newsletter_message($registrations, $grp_id)
911
+	{
912
+		// make sure mtp is id and set it in the request later messages setup.
913
+		self::getRequest()->setRequestParam('GRP_ID', (int) $grp_id);
914
+		self::_load_controller();
915
+		self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations);
916
+	}
917
+
918
+
919
+	/**
920
+	 * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url
921
+	 *
922
+	 * @since   4.3.0
923
+	 * @param    string          $registration_message_trigger_url
924
+	 * @param    EE_Registration $registration
925
+	 * @param string             $messenger
926
+	 * @param string             $message_type
927
+	 * @return string
928
+	 * @throws EE_Error
929
+	 * @throws InvalidArgumentException
930
+	 * @throws InvalidDataTypeException
931
+	 * @throws InvalidInterfaceException
932
+	 */
933
+	public static function registration_message_trigger_url(
934
+		$registration_message_trigger_url,
935
+		EE_Registration $registration,
936
+		$messenger = 'html',
937
+		$message_type = 'invoice'
938
+	) {
939
+		// whitelist $messenger
940
+		switch ($messenger) {
941
+			case 'pdf':
942
+				$sending_messenger = 'pdf';
943
+				$generating_messenger = 'html';
944
+				break;
945
+			case 'html':
946
+			default:
947
+				$sending_messenger = 'html';
948
+				$generating_messenger = 'html';
949
+				break;
950
+		}
951
+		// whitelist $message_type
952
+		switch ($message_type) {
953
+			case 'receipt':
954
+				$message_type = 'receipt';
955
+				break;
956
+			case 'invoice':
957
+			default:
958
+				$message_type = 'invoice';
959
+				break;
960
+		}
961
+		// verify that both the messenger AND the message type are active
962
+		if (
963
+			EEH_MSG_Template::is_messenger_active($sending_messenger)
964
+			&& EEH_MSG_Template::is_mt_active($message_type)
965
+		) {
966
+			// need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?)
967
+			$template_query_params = array(
968
+				'MTP_is_active'    => true,
969
+				'MTP_messenger'    => $generating_messenger,
970
+				'MTP_message_type' => $message_type,
971
+				'Event.EVT_ID'     => $registration->event_ID(),
972
+			);
973
+			// get the message template group.
974
+			$msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
975
+			// if we don't have an EE_Message_Template_Group then return
976
+			if (! $msg_template_group instanceof EE_Message_Template_Group) {
977
+				// remove EVT_ID from query params so that global templates get picked up
978
+				unset($template_query_params['Event.EVT_ID']);
979
+				// get global template as the fallback
980
+				$msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
981
+			}
982
+			// if we don't have an EE_Message_Template_Group then return
983
+			if (! $msg_template_group instanceof EE_Message_Template_Group) {
984
+				return '';
985
+			}
986
+			// generate the URL
987
+			$registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger(
988
+				$sending_messenger,
989
+				$generating_messenger,
990
+				'purchaser',
991
+				$message_type,
992
+				$registration,
993
+				$msg_template_group->ID(),
994
+				$registration->transaction_ID()
995
+			);
996
+		}
997
+		return $registration_message_trigger_url;
998
+	}
999
+
1000
+
1001
+	/**
1002
+	 * Use to generate and return a message preview!
1003
+	 *
1004
+	 * @param  string $type      This should correspond with a valid message type
1005
+	 * @param  string $context   This should correspond with a valid context for the message type
1006
+	 * @param  string $messenger This should correspond with a valid messenger.
1007
+	 * @param bool    $send      true we will do a test send using the messenger delivery, false we just do a regular
1008
+	 *                           preview
1009
+	 * @return bool|string The body of the message or if send is requested, sends.
1010
+	 * @throws EE_Error
1011
+	 * @throws InvalidArgumentException
1012
+	 * @throws InvalidDataTypeException
1013
+	 * @throws InvalidInterfaceException
1014
+	 * @throws ReflectionException
1015
+	 */
1016
+	public static function preview_message($type, $context, $messenger, $send = false)
1017
+	{
1018
+		self::_load_controller();
1019
+		$mtg = new EE_Message_To_Generate(
1020
+			$messenger,
1021
+			$type,
1022
+			array(),
1023
+			$context,
1024
+			true
1025
+		);
1026
+		$generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send);
1027
+		if ($generated_preview_queue instanceof EE_Messages_Queue) {
1028
+			// loop through all content for the preview and remove any persisted records.
1029
+			$content = '';
1030
+			foreach ($generated_preview_queue->get_message_repository() as $message) {
1031
+				$content = $message->content();
1032
+				if ($message->ID() > 0 && $message->STS_ID() !== EEM_Message::status_failed) {
1033
+					$message->delete();
1034
+				}
1035
+			}
1036
+			return $content;
1037
+		} else {
1038
+			return $generated_preview_queue;
1039
+		}
1040
+	}
1041
+
1042
+
1043
+	/**
1044
+	 * This is a method that allows for sending a message using a messenger matching the string given and the provided
1045
+	 * EE_Message_Queue object.  The EE_Message_Queue object is used to create a single aggregate EE_Message via the
1046
+	 * content found in the EE_Message objects in the queue.
1047
+	 *
1048
+	 * @since 4.9.0
1049
+	 * @param string            $messenger            a string matching a valid active messenger in the system
1050
+	 * @param string            $message_type         Although it seems contrary to the name of the method, a message
1051
+	 *                                                type name is still required to send along the message type to the
1052
+	 *                                                messenger because this is used for determining what specific
1053
+	 *                                                variations might be loaded for the generated message.
1054
+	 * @param EE_Messages_Queue $queue
1055
+	 * @param string            $custom_subject       Can be used to set what the custom subject string will be on the
1056
+	 *                                                aggregate EE_Message object.
1057
+	 * @return bool success or fail.
1058
+	 * @throws EE_Error
1059
+	 * @throws InvalidArgumentException
1060
+	 * @throws ReflectionException
1061
+	 * @throws InvalidDataTypeException
1062
+	 * @throws InvalidInterfaceException
1063
+	 */
1064
+	public static function send_message_with_messenger_only(
1065
+		$messenger,
1066
+		$message_type,
1067
+		EE_Messages_Queue $queue,
1068
+		$custom_subject = ''
1069
+	) {
1070
+		self::_load_controller();
1071
+		/** @type EE_Message_To_Generate_From_Queue $message_to_generate */
1072
+		$message_to_generate = EE_Registry::instance()->load_lib(
1073
+			'Message_To_Generate_From_Queue',
1074
+			array(
1075
+				$messenger,
1076
+				$message_type,
1077
+				$queue,
1078
+				$custom_subject,
1079
+			)
1080
+		);
1081
+		return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate);
1082
+	}
1083
+
1084
+
1085
+	/**
1086
+	 * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation)
1087
+	 *
1088
+	 * @since 4.9.0
1089
+	 * @param array $message_ids An array of message ids
1090
+	 * @return bool|EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated
1091
+	 *                           messages.
1092
+	 * @throws EE_Error
1093
+	 * @throws InvalidArgumentException
1094
+	 * @throws InvalidDataTypeException
1095
+	 * @throws InvalidInterfaceException
1096
+	 * @throws ReflectionException
1097
+	 */
1098
+	public static function generate_now($message_ids)
1099
+	{
1100
+		self::_load_controller();
1101
+		$messages = EEM_Message::instance()->get_all(
1102
+			array(
1103
+				0 => array(
1104
+					'MSG_ID' => array('IN', $message_ids),
1105
+					'STS_ID' => EEM_Message::status_incomplete,
1106
+				),
1107
+			)
1108
+		);
1109
+		$generated_queue = false;
1110
+		if ($messages) {
1111
+			$generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
1112
+		}
1113
+
1114
+		if (! $generated_queue instanceof EE_Messages_Queue) {
1115
+			EE_Error::add_error(
1116
+				esc_html__(
1117
+					'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.',
1118
+					'event_espresso'
1119
+				),
1120
+				__FILE__,
1121
+				__FUNCTION__,
1122
+				__LINE__
1123
+			);
1124
+		}
1125
+		return $generated_queue;
1126
+	}
1127
+
1128
+
1129
+	/**
1130
+	 * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or,
1131
+	 * EEM_Message::status_idle
1132
+	 *
1133
+	 * @since 4.9.0
1134
+	 * @param $message_ids
1135
+	 * @return bool|EE_Messages_Queue false if no messages sent.
1136
+	 * @throws EE_Error
1137
+	 * @throws InvalidArgumentException
1138
+	 * @throws InvalidDataTypeException
1139
+	 * @throws InvalidInterfaceException
1140
+	 * @throws ReflectionException
1141
+	 */
1142
+	public static function send_now($message_ids)
1143
+	{
1144
+		self::_load_controller();
1145
+		$messages = EEM_Message::instance()->get_all(
1146
+			array(
1147
+				0 => array(
1148
+					'MSG_ID' => array('IN', $message_ids),
1149
+					'STS_ID' => array(
1150
+						'IN',
1151
+						array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry),
1152
+					),
1153
+				),
1154
+			)
1155
+		);
1156
+		$sent_queue = false;
1157
+		if ($messages) {
1158
+			$sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
1159
+		}
1160
+
1161
+		if (! $sent_queue instanceof EE_Messages_Queue) {
1162
+			EE_Error::add_error(
1163
+				esc_html__(
1164
+					'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.',
1165
+					'event_espresso'
1166
+				),
1167
+				__FILE__,
1168
+				__FUNCTION__,
1169
+				__LINE__
1170
+			);
1171
+		} else {
1172
+			// can count how many sent by using the messages in the queue
1173
+			$sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent());
1174
+			if ($sent_count > 0) {
1175
+				EE_Error::add_success(
1176
+					sprintf(
1177
+						_n(
1178
+							'There was %d message successfully sent.',
1179
+							'There were %d messages successfully sent.',
1180
+							$sent_count,
1181
+							'event_espresso'
1182
+						),
1183
+						$sent_count
1184
+					)
1185
+				);
1186
+			} else {
1187
+				EE_Error::overwrite_errors();
1188
+				EE_Error::add_error(
1189
+					esc_html__(
1190
+						'No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error.
1191 1191
 					If there was an error, you can look at the messages in the message activity list table for any error messages.',
1192
-                        'event_espresso'
1193
-                    ),
1194
-                    __FILE__,
1195
-                    __FUNCTION__,
1196
-                    __LINE__
1197
-                );
1198
-            }
1199
-        }
1200
-        return $sent_queue;
1201
-    }
1202
-
1203
-
1204
-    /**
1205
-     * Generate and send immediately from the given $message_ids
1206
-     *
1207
-     * @param array $message_ids EE_Message entity ids.
1208
-     * @throws EE_Error
1209
-     * @throws InvalidArgumentException
1210
-     * @throws InvalidDataTypeException
1211
-     * @throws InvalidInterfaceException
1212
-     * @throws ReflectionException
1213
-     */
1214
-    public static function generate_and_send_now(array $message_ids)
1215
-    {
1216
-        $generated_queue = self::generate_now($message_ids);
1217
-        // now let's just trigger sending immediately from this queue.
1218
-        $messages_sent = $generated_queue instanceof EE_Messages_Queue
1219
-            ? $generated_queue->execute()
1220
-            : 0;
1221
-        if ($messages_sent) {
1222
-            EE_Error::add_success(
1223
-                esc_html(
1224
-                    sprintf(
1225
-                        _n(
1226
-                            'There was %d message successfully generated and sent.',
1227
-                            'There were %d messages successfully generated and sent.',
1228
-                            $messages_sent,
1229
-                            'event_espresso'
1230
-                        ),
1231
-                        $messages_sent
1232
-                    )
1233
-                )
1234
-            );
1235
-            // errors would be added via the generate_now method.
1236
-        }
1237
-    }
1238
-
1239
-
1240
-    /**
1241
-     * This will queue the incoming message ids for resending.
1242
-     * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued.
1243
-     *
1244
-     * @since 4.9.0
1245
-     * @param array $message_ids An array of EE_Message IDs
1246
-     * @return bool true means messages were successfully queued for resending, false means none were queued for
1247
-     *                           resending.
1248
-     * @throws EE_Error
1249
-     * @throws InvalidArgumentException
1250
-     * @throws InvalidDataTypeException
1251
-     * @throws InvalidInterfaceException
1252
-     * @throws ReflectionException
1253
-     */
1254
-    public static function queue_for_resending($message_ids)
1255
-    {
1256
-        self::_load_controller();
1257
-        self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids);
1258
-
1259
-        // get queue and count
1260
-        $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
1261
-
1262
-        if (
1263
-            $queue_count > 0
1264
-        ) {
1265
-            EE_Error::add_success(
1266
-                sprintf(
1267
-                    _n(
1268
-                        '%d message successfully queued for resending.',
1269
-                        '%d messages successfully queued for resending.',
1270
-                        $queue_count,
1271
-                        'event_espresso'
1272
-                    ),
1273
-                    $queue_count
1274
-                )
1275
-            );
1276
-            /**
1277
-             * @see filter usage in EE_Messages_Queue::initiate_request_by_priority
1278
-             */
1279
-        } elseif (
1280
-            apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true)
1281
-            || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
1282
-        ) {
1283
-            $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent);
1284
-            if ($queue_count > 0) {
1285
-                EE_Error::add_success(
1286
-                    sprintf(
1287
-                        _n(
1288
-                            '%d message successfully sent.',
1289
-                            '%d messages successfully sent.',
1290
-                            $queue_count,
1291
-                            'event_espresso'
1292
-                        ),
1293
-                        $queue_count
1294
-                    )
1295
-                );
1296
-            } else {
1297
-                EE_Error::add_error(
1298
-                    esc_html__(
1299
-                        'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1300
-                        'event_espresso'
1301
-                    ),
1302
-                    __FILE__,
1303
-                    __FUNCTION__,
1304
-                    __LINE__
1305
-                );
1306
-            }
1307
-        } else {
1308
-            EE_Error::add_error(
1309
-                esc_html__(
1310
-                    'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1311
-                    'event_espresso'
1312
-                ),
1313
-                __FILE__,
1314
-                __FUNCTION__,
1315
-                __LINE__
1316
-            );
1317
-        }
1318
-        return (bool) $queue_count;
1319
-    }
1320
-
1321
-
1322
-    /**
1323
-     * debug
1324
-     *
1325
-     * @param string          $class
1326
-     * @param string          $func
1327
-     * @param string          $line
1328
-     * @param \EE_Transaction $transaction
1329
-     * @param array           $info
1330
-     * @param bool            $display_request
1331
-     * @throws EE_Error
1332
-     * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
1333
-     */
1334
-    protected static function log(
1335
-        $class = '',
1336
-        $func = '',
1337
-        $line = '',
1338
-        EE_Transaction $transaction,
1339
-        $info = array(),
1340
-        $display_request = false
1341
-    ) {
1342
-        if (defined('EE_DEBUG') && EE_DEBUG) {
1343
-            if ($transaction instanceof EE_Transaction) {
1344
-                // don't serialize objects
1345
-                $info = EEH_Debug_Tools::strip_objects($info);
1346
-                $info['TXN_status'] = $transaction->status_ID();
1347
-                $info['TXN_reg_steps'] = $transaction->reg_steps();
1348
-                if ($transaction->ID()) {
1349
-                    $index = 'EE_Transaction: ' . $transaction->ID();
1350
-                    EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1351
-                }
1352
-            }
1353
-        }
1354
-    }
1355
-
1356
-
1357
-    /**
1358
-     *  Resets all the static properties in this class when called.
1359
-     */
1360
-    public static function reset()
1361
-    {
1362
-        self::$_EEMSG = null;
1363
-        self::$_message_resource_manager = null;
1364
-        self::$_MSG_PROCESSOR = null;
1365
-        self::$_MSG_PATHS = null;
1366
-        self::$_TMP_PACKS = array();
1367
-    }
1192
+						'event_espresso'
1193
+					),
1194
+					__FILE__,
1195
+					__FUNCTION__,
1196
+					__LINE__
1197
+				);
1198
+			}
1199
+		}
1200
+		return $sent_queue;
1201
+	}
1202
+
1203
+
1204
+	/**
1205
+	 * Generate and send immediately from the given $message_ids
1206
+	 *
1207
+	 * @param array $message_ids EE_Message entity ids.
1208
+	 * @throws EE_Error
1209
+	 * @throws InvalidArgumentException
1210
+	 * @throws InvalidDataTypeException
1211
+	 * @throws InvalidInterfaceException
1212
+	 * @throws ReflectionException
1213
+	 */
1214
+	public static function generate_and_send_now(array $message_ids)
1215
+	{
1216
+		$generated_queue = self::generate_now($message_ids);
1217
+		// now let's just trigger sending immediately from this queue.
1218
+		$messages_sent = $generated_queue instanceof EE_Messages_Queue
1219
+			? $generated_queue->execute()
1220
+			: 0;
1221
+		if ($messages_sent) {
1222
+			EE_Error::add_success(
1223
+				esc_html(
1224
+					sprintf(
1225
+						_n(
1226
+							'There was %d message successfully generated and sent.',
1227
+							'There were %d messages successfully generated and sent.',
1228
+							$messages_sent,
1229
+							'event_espresso'
1230
+						),
1231
+						$messages_sent
1232
+					)
1233
+				)
1234
+			);
1235
+			// errors would be added via the generate_now method.
1236
+		}
1237
+	}
1238
+
1239
+
1240
+	/**
1241
+	 * This will queue the incoming message ids for resending.
1242
+	 * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued.
1243
+	 *
1244
+	 * @since 4.9.0
1245
+	 * @param array $message_ids An array of EE_Message IDs
1246
+	 * @return bool true means messages were successfully queued for resending, false means none were queued for
1247
+	 *                           resending.
1248
+	 * @throws EE_Error
1249
+	 * @throws InvalidArgumentException
1250
+	 * @throws InvalidDataTypeException
1251
+	 * @throws InvalidInterfaceException
1252
+	 * @throws ReflectionException
1253
+	 */
1254
+	public static function queue_for_resending($message_ids)
1255
+	{
1256
+		self::_load_controller();
1257
+		self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids);
1258
+
1259
+		// get queue and count
1260
+		$queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend);
1261
+
1262
+		if (
1263
+			$queue_count > 0
1264
+		) {
1265
+			EE_Error::add_success(
1266
+				sprintf(
1267
+					_n(
1268
+						'%d message successfully queued for resending.',
1269
+						'%d messages successfully queued for resending.',
1270
+						$queue_count,
1271
+						'event_espresso'
1272
+					),
1273
+					$queue_count
1274
+				)
1275
+			);
1276
+			/**
1277
+			 * @see filter usage in EE_Messages_Queue::initiate_request_by_priority
1278
+			 */
1279
+		} elseif (
1280
+			apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true)
1281
+			|| EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
1282
+		) {
1283
+			$queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent);
1284
+			if ($queue_count > 0) {
1285
+				EE_Error::add_success(
1286
+					sprintf(
1287
+						_n(
1288
+							'%d message successfully sent.',
1289
+							'%d messages successfully sent.',
1290
+							$queue_count,
1291
+							'event_espresso'
1292
+						),
1293
+						$queue_count
1294
+					)
1295
+				);
1296
+			} else {
1297
+				EE_Error::add_error(
1298
+					esc_html__(
1299
+						'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1300
+						'event_espresso'
1301
+					),
1302
+					__FILE__,
1303
+					__FUNCTION__,
1304
+					__LINE__
1305
+				);
1306
+			}
1307
+		} else {
1308
+			EE_Error::add_error(
1309
+				esc_html__(
1310
+					'No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.',
1311
+					'event_espresso'
1312
+				),
1313
+				__FILE__,
1314
+				__FUNCTION__,
1315
+				__LINE__
1316
+			);
1317
+		}
1318
+		return (bool) $queue_count;
1319
+	}
1320
+
1321
+
1322
+	/**
1323
+	 * debug
1324
+	 *
1325
+	 * @param string          $class
1326
+	 * @param string          $func
1327
+	 * @param string          $line
1328
+	 * @param \EE_Transaction $transaction
1329
+	 * @param array           $info
1330
+	 * @param bool            $display_request
1331
+	 * @throws EE_Error
1332
+	 * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
1333
+	 */
1334
+	protected static function log(
1335
+		$class = '',
1336
+		$func = '',
1337
+		$line = '',
1338
+		EE_Transaction $transaction,
1339
+		$info = array(),
1340
+		$display_request = false
1341
+	) {
1342
+		if (defined('EE_DEBUG') && EE_DEBUG) {
1343
+			if ($transaction instanceof EE_Transaction) {
1344
+				// don't serialize objects
1345
+				$info = EEH_Debug_Tools::strip_objects($info);
1346
+				$info['TXN_status'] = $transaction->status_ID();
1347
+				$info['TXN_reg_steps'] = $transaction->reg_steps();
1348
+				if ($transaction->ID()) {
1349
+					$index = 'EE_Transaction: ' . $transaction->ID();
1350
+					EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1351
+				}
1352
+			}
1353
+		}
1354
+	}
1355
+
1356
+
1357
+	/**
1358
+	 *  Resets all the static properties in this class when called.
1359
+	 */
1360
+	public static function reset()
1361
+	{
1362
+		self::$_EEMSG = null;
1363
+		self::$_message_resource_manager = null;
1364
+		self::$_MSG_PROCESSOR = null;
1365
+		self::$_MSG_PATHS = null;
1366
+		self::$_TMP_PACKS = array();
1367
+	}
1368 1368
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
                 'event_espresso'
205 205
             );
206 206
             // add specific message for developers if WP_DEBUG in on
207
-            $error_msg .= '||' . $e->getMessage();
207
+            $error_msg .= '||'.$e->getMessage();
208 208
             EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
209 209
         }
210 210
     }
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
                 'event_espresso'
291 291
             );
292 292
             // add specific message for developers if WP_DEBUG in on
293
-            $error_msg .= '||' . $e->getMessage();
293
+            $error_msg .= '||'.$e->getMessage();
294 294
             EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
295 295
         }
296 296
     }
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
         $transient_key = $request->getRequestParam('key');
323 323
 
324 324
         // now let's verify transient, if not valid exit immediately
325
-        if (! get_transient($transient_key)) {
325
+        if ( ! get_transient($transient_key)) {
326 326
             /**
327 327
              * trigger error so this gets in the error logs.  This is important because it happens on a non-user
328 328
              * request.
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
         delete_transient($transient_key);
335 335
 
336 336
         if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) {
337
-            $method = 'batch_' . $cron_type . '_from_queue';
337
+            $method = 'batch_'.$cron_type.'_from_queue';
338 338
             if (method_exists(self::$_MSG_PROCESSOR, $method)) {
339 339
                 self::$_MSG_PROCESSOR->$method();
340 340
             } else {
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
         $template_pack_collection->rewind();
402 402
         $template_packs = array();
403 403
         while ($template_pack_collection->valid()) {
404
-            $template_packs[ $template_pack_collection->current()->dbref ] = $template_pack_collection->current();
404
+            $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current();
405 405
             $template_pack_collection->next();
406 406
         }
407 407
         return $template_packs;
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
         );
452 452
         $paths = array();
453 453
         foreach ($dir_ref as $index => $dir) {
454
-            $paths[ $index ] = EE_LIBRARIES . $dir;
454
+            $paths[$index] = EE_LIBRARIES.$dir;
455 455
         }
456 456
         self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths);
457 457
     }
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
      */
471 471
     protected static function _load_controller()
472 472
     {
473
-        if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
473
+        if ( ! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) {
474 474
             EE_Registry::instance()->load_core('Request_Handler');
475 475
             self::set_autoloaders();
476 476
             self::$_EEMSG = EE_Registry::instance()->load_lib('messages');
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
     public static function payment(EE_Transaction $transaction, EE_Payment $payment = null)
512 512
     {
513 513
         // if there's no payment object, then we cannot do a payment type message!
514
-        if (! $payment instanceof EE_Payment) {
514
+        if ( ! $payment instanceof EE_Payment) {
515 515
             return;
516 516
         }
517 517
         self::_load_controller();
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
     public static function maybe_registration(EE_Registration $registration, $extra_details = array())
559 559
     {
560 560
 
561
-        if (! self::_verify_registration_notification_send($registration, $extra_details)) {
561
+        if ( ! self::_verify_registration_notification_send($registration, $extra_details)) {
562 562
             // no messages please
563 563
             return;
564 564
         }
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
         } else {
650 650
             // frontend request (either regular or via AJAX)
651 651
             // TXN is NOT finalized ?
652
-            if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
652
+            if ( ! isset($extra_details['finalized']) || $extra_details['finalized'] === false) {
653 653
                 return false;
654 654
             }
655 655
             // return visit but nothing changed ???
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
 
741 741
         // make sure any incoming request data is set on the request so that it gets picked up later.
742 742
         foreach ((array) $req_data as $request_key => $request_value) {
743
-            if (! $request->requestParamIsSet($request_key)) {
743
+            if ( ! $request->requestParamIsSet($request_key)) {
744 744
                 $request->setRequestParam($request_key, $request_value);
745 745
             }
746 746
         }
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
         self::_load_controller();
781 781
 
782 782
         $msgID = self::getRequest()->getRequestParam('MSG_ID', 0, 'int');
783
-        if (! $msgID) {
783
+        if ( ! $msgID) {
784 784
             EE_Error::add_error(
785 785
                 esc_html__(
786 786
                     'Something went wrong because there is no "MSG_ID" value in the request',
@@ -973,14 +973,14 @@  discard block
 block discarded – undo
973 973
             // get the message template group.
974 974
             $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
975 975
             // if we don't have an EE_Message_Template_Group then return
976
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
976
+            if ( ! $msg_template_group instanceof EE_Message_Template_Group) {
977 977
                 // remove EVT_ID from query params so that global templates get picked up
978 978
                 unset($template_query_params['Event.EVT_ID']);
979 979
                 // get global template as the fallback
980 980
                 $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params));
981 981
             }
982 982
             // if we don't have an EE_Message_Template_Group then return
983
-            if (! $msg_template_group instanceof EE_Message_Template_Group) {
983
+            if ( ! $msg_template_group instanceof EE_Message_Template_Group) {
984 984
                 return '';
985 985
             }
986 986
             // generate the URL
@@ -1111,7 +1111,7 @@  discard block
 block discarded – undo
1111 1111
             $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages);
1112 1112
         }
1113 1113
 
1114
-        if (! $generated_queue instanceof EE_Messages_Queue) {
1114
+        if ( ! $generated_queue instanceof EE_Messages_Queue) {
1115 1115
             EE_Error::add_error(
1116 1116
                 esc_html__(
1117 1117
                     'The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.',
@@ -1158,7 +1158,7 @@  discard block
 block discarded – undo
1158 1158
             $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages);
1159 1159
         }
1160 1160
 
1161
-        if (! $sent_queue instanceof EE_Messages_Queue) {
1161
+        if ( ! $sent_queue instanceof EE_Messages_Queue) {
1162 1162
             EE_Error::add_error(
1163 1163
                 esc_html__(
1164 1164
                     'The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.',
@@ -1346,7 +1346,7 @@  discard block
 block discarded – undo
1346 1346
                 $info['TXN_status'] = $transaction->status_ID();
1347 1347
                 $info['TXN_reg_steps'] = $transaction->reg_steps();
1348 1348
                 if ($transaction->ID()) {
1349
-                    $index = 'EE_Transaction: ' . $transaction->ID();
1349
+                    $index = 'EE_Transaction: '.$transaction->ID();
1350 1350
                     EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index);
1351 1351
                 }
1352 1352
             }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.10.29.rc.002');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.10.29.rc.002');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.