Completed
Branch FET/Gutenberg/11400/block-mana... (1c7938)
by
unknown
13:59 queued 16s
created
core/domain/Domain.php 2 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -19,54 +19,54 @@
 block discarded – undo
19 19
 class Domain extends DomainBase implements CaffeinatedInterface
20 20
 {
21 21
 
22
-    /**
23
-     * URL path component used to denote an API request
24
-     */
25
-    const API_NAMESPACE = 'ee/v';
22
+	/**
23
+	 * URL path component used to denote an API request
24
+	 */
25
+	const API_NAMESPACE = 'ee/v';
26 26
 
27
-    /**
28
-     * Slug used for the context where a registration status is changed from a manual trigger in the Registration Admin
29
-     * Page ui.
30
-     */
31
-    const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN
32
-        = 'manual_registration_status_change_from_registration_admin';
27
+	/**
28
+	 * Slug used for the context where a registration status is changed from a manual trigger in the Registration Admin
29
+	 * Page ui.
30
+	 */
31
+	const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN
32
+		= 'manual_registration_status_change_from_registration_admin';
33 33
 
34
-    const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
35
-        = 'manual_registration_status_change_from_registration_admin_and_notify';
34
+	const CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
35
+		= 'manual_registration_status_change_from_registration_admin_and_notify';
36 36
 
37 37
 
38
-    /**
39
-     * Whether or not EE core is the full premium version.
40
-     * @since $VID:$
41
-     * @var bool
42
-     */
43
-    private $caffeinated;
38
+	/**
39
+	 * Whether or not EE core is the full premium version.
40
+	 * @since $VID:$
41
+	 * @var bool
42
+	 */
43
+	private $caffeinated;
44 44
 
45 45
 
46
-    public function __construct(FilePath $plugin_file, Version $version)
47
-    {
48
-        parent::__construct($plugin_file, $version);
49
-        $this->setCaffeinated();
50
-    }
46
+	public function __construct(FilePath $plugin_file, Version $version)
47
+	{
48
+		parent::__construct($plugin_file, $version);
49
+		$this->setCaffeinated();
50
+	}
51 51
 
52
-    /**
53
-     * Whether or not EE core is the full premium version.
54
-     * @since $VID:$
55
-     * @return bool
56
-     */
57
-    public function isCaffeinated()
58
-    {
59
-        return $this->caffeinated;
60
-    }
52
+	/**
53
+	 * Whether or not EE core is the full premium version.
54
+	 * @since $VID:$
55
+	 * @return bool
56
+	 */
57
+	public function isCaffeinated()
58
+	{
59
+		return $this->caffeinated;
60
+	}
61 61
 
62 62
 
63
-    /**
64
-     * Setter for $is_caffeinated property.
65
-     * @since $VID:$
66
-     */
67
-    private function setCaffeinated()
68
-    {
69
-        $this->caffeinated = (! defined('EE_DECAF') || EE_DECAF !== true)
70
-            && is_readable($this->pluginPath() . 'caffeinated/brewing_regular.php');
71
-    }
63
+	/**
64
+	 * Setter for $is_caffeinated property.
65
+	 * @since $VID:$
66
+	 */
67
+	private function setCaffeinated()
68
+	{
69
+		$this->caffeinated = (! defined('EE_DECAF') || EE_DECAF !== true)
70
+			&& is_readable($this->pluginPath() . 'caffeinated/brewing_regular.php');
71
+	}
72 72
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -66,7 +66,7 @@
 block discarded – undo
66 66
      */
67 67
     private function setCaffeinated()
68 68
     {
69
-        $this->caffeinated = (! defined('EE_DECAF') || EE_DECAF !== true)
70
-            && is_readable($this->pluginPath() . 'caffeinated/brewing_regular.php');
69
+        $this->caffeinated = ( ! defined('EE_DECAF') || EE_DECAF !== true)
70
+            && is_readable($this->pluginPath().'caffeinated/brewing_regular.php');
71 71
     }
72 72
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin.core.php 1 patch
Indentation   +915 added lines, -915 removed lines patch added patch discarded remove patch
@@ -23,458 +23,458 @@  discard block
 block discarded – undo
23 23
 final class EE_Admin implements InterminableInterface
24 24
 {
25 25
 
26
-    /**
27
-     * @var EE_Admin $_instance
28
-     */
29
-    private static $_instance;
30
-
31
-    /**
32
-     * @var PersistentAdminNoticeManager $persistent_admin_notice_manager
33
-     */
34
-    private $persistent_admin_notice_manager;
35
-
36
-    /**
37
-     * @singleton method used to instantiate class object
38
-     * @return EE_Admin
39
-     * @throws EE_Error
40
-     */
41
-    public static function instance()
42
-    {
43
-        // check if class object is instantiated
44
-        if (! self::$_instance instanceof EE_Admin) {
45
-            self::$_instance = new self();
46
-        }
47
-        return self::$_instance;
48
-    }
49
-
50
-
51
-    /**
52
-     * @return EE_Admin
53
-     * @throws EE_Error
54
-     */
55
-    public static function reset()
56
-    {
57
-        self::$_instance = null;
58
-        return self::instance();
59
-    }
60
-
61
-
62
-    /**
63
-     * class constructor
64
-     *
65
-     * @throws EE_Error
66
-     * @throws InvalidDataTypeException
67
-     * @throws InvalidInterfaceException
68
-     * @throws InvalidArgumentException
69
-     */
70
-    protected function __construct()
71
-    {
72
-        // define global EE_Admin constants
73
-        $this->_define_all_constants();
74
-        // set autoloaders for our admin page classes based on included path information
75
-        EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN);
76
-        // admin hooks
77
-        add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2);
78
-        // load EE_Request_Handler early
79
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request'));
80
-        add_action('AHEE__EE_System__initialize_last', array($this, 'init'));
81
-        add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2);
82
-        add_action('wp_loaded', array($this, 'wp_loaded'), 100);
83
-        add_action('admin_init', array($this, 'admin_init'), 100);
84
-        add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20);
85
-        add_action('admin_notices', array($this, 'display_admin_notices'), 10);
86
-        add_action('network_admin_notices', array($this, 'display_admin_notices'), 10);
87
-        add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2);
88
-        add_filter('admin_footer_text', array($this, 'espresso_admin_footer'));
89
-        add_action('load-plugins.php', array($this, 'hookIntoWpPluginsPage'));
90
-        //reset Environment config (we only do this on admin page loads);
91
-        EE_Registry::instance()->CFG->environment->recheck_values();
92
-        do_action('AHEE__EE_Admin__loaded');
93
-    }
94
-
95
-
96
-
97
-    /**
98
-     * _define_all_constants
99
-     * define constants that are set globally for all admin pages
100
-     *
101
-     * @return void
102
-     */
103
-    private function _define_all_constants()
104
-    {
105
-        if (! defined('EE_ADMIN_URL')) {
106
-            define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
107
-            define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
108
-            define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS);
109
-            define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
110
-            define('WP_AJAX_URL', admin_url('admin-ajax.php'));
111
-        }
112
-    }
113
-
114
-
115
-    /**
116
-     * filter_plugin_actions - adds links to the Plugins page listing
117
-     *
118
-     * @param    array  $links
119
-     * @param    string $plugin
120
-     * @return    array
121
-     */
122
-    public function filter_plugin_actions($links, $plugin)
123
-    {
124
-        // set $main_file in stone
125
-        static $main_file;
126
-        // if $main_file is not set yet
127
-        if (! $main_file) {
128
-            $main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
129
-        }
130
-        if ($plugin === $main_file) {
131
-            // compare current plugin to this one
132
-            if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
133
-                $maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"'
134
-                                    . ' title="Event Espresso is in maintenance mode.  Click this link to learn why.">'
135
-                                    . esc_html__('Maintenance Mode Active', 'event_espresso')
136
-                                    . '</a>';
137
-                array_unshift($links, $maintenance_link);
138
-            } else {
139
-                $org_settings_link = '<a href="admin.php?page=espresso_general_settings">'
140
-                                     . esc_html__('Settings', 'event_espresso')
141
-                                     . '</a>';
142
-                $events_link       = '<a href="admin.php?page=espresso_events">'
143
-                                     . esc_html__('Events', 'event_espresso')
144
-                                     . '</a>';
145
-                // add before other links
146
-                array_unshift($links, $org_settings_link, $events_link);
147
-            }
148
-        }
149
-        return $links;
150
-    }
151
-
152
-
153
-    /**
154
-     * _get_request
155
-     *
156
-     * @return void
157
-     * @throws EE_Error
158
-     * @throws InvalidArgumentException
159
-     * @throws InvalidDataTypeException
160
-     * @throws InvalidInterfaceException
161
-     * @throws ReflectionException
162
-     */
163
-    public function get_request()
164
-    {
165
-        EE_Registry::instance()->load_core('Request_Handler');
166
-        EE_Registry::instance()->load_core('CPT_Strategy');
167
-    }
168
-
169
-
170
-
171
-    /**
172
-     * hide_admin_pages_except_maintenance_mode
173
-     *
174
-     * @param array $admin_page_folder_names
175
-     * @return array
176
-     */
177
-    public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
178
-    {
179
-        return array(
180
-            'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS,
181
-            'about'       => EE_ADMIN_PAGES . 'about' . DS,
182
-            'support'     => EE_ADMIN_PAGES . 'support' . DS,
183
-        );
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * init- should fire after shortcode, module,  addon, other plugin (default priority), and even
190
-     * EE_Front_Controller's init phases have run
191
-     *
192
-     * @return void
193
-     * @throws EE_Error
194
-     * @throws InvalidArgumentException
195
-     * @throws InvalidDataTypeException
196
-     * @throws InvalidInterfaceException
197
-     * @throws ReflectionException
198
-     * @throws ServiceNotFoundException
199
-     */
200
-    public function init()
201
-    {
202
-        //only enable most of the EE_Admin IF we're not in full maintenance mode
203
-        if (EE_Maintenance_Mode::instance()->models_can_query()) {
204
-            //ok so we want to enable the entire admin
205
-            $this->persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
206
-                'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
207
-            );
208
-            $this->persistent_admin_notice_manager->setReturnUrl(
209
-                EE_Admin_Page::add_query_args_and_nonce(
210
-                    array(
211
-                        'page'   => EE_Registry::instance()->REQ->get('page', ''),
212
-                        'action' => EE_Registry::instance()->REQ->get('action', ''),
213
-                    ),
214
-                    EE_ADMIN_URL
215
-                )
216
-            );
217
-            $this->maybeSetDatetimeWarningNotice();
218
-            //at a glance dashboard widget
219
-            add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10);
220
-            //filter for get_edit_post_link used on comments for custom post types
221
-            add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
222
-        }
223
-        // run the admin page factory but ONLY if we are doing an ee admin ajax request
224
-        if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
225
-            try {
226
-                //this loads the controller for the admin pages which will setup routing etc
227
-                EE_Registry::instance()->load_core('Admin_Page_Loader');
228
-            } catch (EE_Error $e) {
229
-                $e->get_error();
230
-            }
231
-        }
232
-        add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1);
233
-        //make sure our CPTs and custom taxonomy metaboxes get shown for first time users
234
-        add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10);
235
-        add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10);
236
-        //exclude EE critical pages from all nav menus and wp_list_pages
237
-        add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10);
238
-    }
239
-
240
-
241
-    /**
242
-     *    get_persistent_admin_notices
243
-     *
244
-     * @access    public
245
-     * @return void
246
-     * @throws EE_Error
247
-     * @throws InvalidArgumentException
248
-     * @throws InvalidDataTypeException
249
-     * @throws InvalidInterfaceException
250
-     */
251
-    public function maybeSetDatetimeWarningNotice()
252
-    {
253
-        //add dismissable notice for datetime changes.  Only valid if site does not have a timezone_string set.
254
-        //@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version
255
-        //with this.  But after enough time (indeterminate at this point) we can just remove this notice.
256
-        //this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626
257
-        if (apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true)
258
-            && ! get_option('timezone_string')
259
-            && EEM_Event::instance()->count() > 0
260
-        ) {
261
-            new PersistentAdminNotice(
262
-                'datetime_fix_notice',
263
-                sprintf(
264
-                    esc_html__(
265
-                        '%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times.  Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.',
266
-                        'event_espresso'
267
-                    ),
268
-                    '<strong>',
269
-                    '</strong>',
270
-                    '<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
271
-                    '</a>',
272
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
273
-                        array(
274
-                            'page' => 'espresso_maintenance_settings',
275
-                            'action' => 'datetime_tools'
276
-                        ),
277
-                        admin_url('admin.php')
278
-                    ) . '">'
279
-                ),
280
-                false,
281
-                'manage_options',
282
-                'datetime_fix_persistent_notice'
283
-            );
284
-        }
285
-    }
286
-
287
-
288
-
289
-    /**
290
-     * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from
291
-     * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in
292
-     * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that
293
-     * to override any queries found in the existing query for the given post type.  Note that _default_query is not a
294
-     * normal property on the post_type object.  It's found ONLY in this particular context.
295
-     *
296
-     * @param WP_Post $post_type WP post type object
297
-     * @return WP_Post
298
-     * @throws InvalidArgumentException
299
-     * @throws InvalidDataTypeException
300
-     * @throws InvalidInterfaceException
301
-     */
302
-    public function remove_pages_from_nav_menu($post_type)
303
-    {
304
-        //if this isn't the "pages" post type let's get out
305
-        if ($post_type->name !== 'page') {
306
-            return $post_type;
307
-        }
308
-        $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
309
-        $post_type->_default_query = array(
310
-            'post__not_in' => $critical_pages,
311
-        );
312
-        return $post_type;
313
-    }
314
-
315
-
316
-
317
-    /**
318
-     * WP by default only shows three metaboxes in "nav-menus.php" for first times users.  We want to make sure our
319
-     * metaboxes get shown as well
320
-     *
321
-     * @return void
322
-     */
323
-    public function enable_hidden_ee_nav_menu_metaboxes()
324
-    {
325
-        global $wp_meta_boxes, $pagenow;
326
-        if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
327
-            return;
328
-        }
329
-        $user = wp_get_current_user();
330
-        //has this been done yet?
331
-        if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
332
-            return;
333
-        }
334
-
335
-        $hidden_meta_boxes  = get_user_option('metaboxhidden_nav-menus', $user->ID);
336
-        $initial_meta_boxes = apply_filters(
337
-            'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes',
338
-            array(
339
-                'nav-menu-theme-locations',
340
-                'add-page',
341
-                'add-custom-links',
342
-                'add-category',
343
-                'add-espresso_events',
344
-                'add-espresso_venues',
345
-                'add-espresso_event_categories',
346
-                'add-espresso_venue_categories',
347
-                'add-post-type-post',
348
-                'add-post-type-page',
349
-            )
350
-        );
351
-
352
-        if (is_array($hidden_meta_boxes)) {
353
-            foreach ($hidden_meta_boxes as $key => $meta_box_id) {
354
-                if (in_array($meta_box_id, $initial_meta_boxes, true)) {
355
-                    unset($hidden_meta_boxes[$key]);
356
-                }
357
-            }
358
-        }
359
-        update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
360
-        update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
361
-    }
362
-
363
-
364
-
365
-    /**
366
-     * This method simply registers custom nav menu boxes for "nav_menus.php route"
367
-     * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
368
-     *
369
-     * @todo   modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by
370
-     *         addons etc.
371
-     * @return void
372
-     */
373
-    public function register_custom_nav_menu_boxes()
374
-    {
375
-        add_meta_box(
376
-            'add-extra-nav-menu-pages',
377
-            esc_html__('Event Espresso Pages', 'event_espresso'),
378
-            array($this, 'ee_cpt_archive_pages'),
379
-            'nav-menus',
380
-            'side',
381
-            'core'
382
-        );
383
-    }
384
-
385
-
386
-
387
-    /**
388
-     * Use this to edit the post link for our cpts so that the edit link points to the correct page.
389
-     *
390
-     * @since   4.3.0
391
-     * @param string $link the original link generated by wp
392
-     * @param int    $id   post id
393
-     * @return string  the (maybe) modified link
394
-     */
395
-    public function modify_edit_post_link($link, $id)
396
-    {
397
-        if (! $post = get_post($id)) {
398
-            return $link;
399
-        }
400
-        if ($post->post_type === 'espresso_attendees') {
401
-            $query_args = array(
402
-                'action' => 'edit_attendee',
403
-                'post'   => $id,
404
-            );
405
-            return EEH_URL::add_query_args_and_nonce(
406
-                $query_args,
407
-                admin_url('admin.php?page=espresso_registrations')
408
-            );
409
-        }
410
-        return $link;
411
-    }
412
-
413
-
414
-
415
-    public function ee_cpt_archive_pages()
416
-    {
417
-        global $nav_menu_selected_id;
418
-        $db_fields   = false;
419
-        $walker      = new Walker_Nav_Menu_Checklist($db_fields);
420
-        $current_tab = 'event-archives';
421
-        $removed_args = array(
422
-            'action',
423
-            'customlink-tab',
424
-            'edit-menu-item',
425
-            'menu-item',
426
-            'page-tab',
427
-            '_wpnonce',
428
-        );
429
-        ?>
26
+	/**
27
+	 * @var EE_Admin $_instance
28
+	 */
29
+	private static $_instance;
30
+
31
+	/**
32
+	 * @var PersistentAdminNoticeManager $persistent_admin_notice_manager
33
+	 */
34
+	private $persistent_admin_notice_manager;
35
+
36
+	/**
37
+	 * @singleton method used to instantiate class object
38
+	 * @return EE_Admin
39
+	 * @throws EE_Error
40
+	 */
41
+	public static function instance()
42
+	{
43
+		// check if class object is instantiated
44
+		if (! self::$_instance instanceof EE_Admin) {
45
+			self::$_instance = new self();
46
+		}
47
+		return self::$_instance;
48
+	}
49
+
50
+
51
+	/**
52
+	 * @return EE_Admin
53
+	 * @throws EE_Error
54
+	 */
55
+	public static function reset()
56
+	{
57
+		self::$_instance = null;
58
+		return self::instance();
59
+	}
60
+
61
+
62
+	/**
63
+	 * class constructor
64
+	 *
65
+	 * @throws EE_Error
66
+	 * @throws InvalidDataTypeException
67
+	 * @throws InvalidInterfaceException
68
+	 * @throws InvalidArgumentException
69
+	 */
70
+	protected function __construct()
71
+	{
72
+		// define global EE_Admin constants
73
+		$this->_define_all_constants();
74
+		// set autoloaders for our admin page classes based on included path information
75
+		EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_ADMIN);
76
+		// admin hooks
77
+		add_filter('plugin_action_links', array($this, 'filter_plugin_actions'), 10, 2);
78
+		// load EE_Request_Handler early
79
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'get_request'));
80
+		add_action('AHEE__EE_System__initialize_last', array($this, 'init'));
81
+		add_action('AHEE__EE_Admin_Page__route_admin_request', array($this, 'route_admin_request'), 100, 2);
82
+		add_action('wp_loaded', array($this, 'wp_loaded'), 100);
83
+		add_action('admin_init', array($this, 'admin_init'), 100);
84
+		add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'), 20);
85
+		add_action('admin_notices', array($this, 'display_admin_notices'), 10);
86
+		add_action('network_admin_notices', array($this, 'display_admin_notices'), 10);
87
+		add_filter('pre_update_option', array($this, 'check_for_invalid_datetime_formats'), 100, 2);
88
+		add_filter('admin_footer_text', array($this, 'espresso_admin_footer'));
89
+		add_action('load-plugins.php', array($this, 'hookIntoWpPluginsPage'));
90
+		//reset Environment config (we only do this on admin page loads);
91
+		EE_Registry::instance()->CFG->environment->recheck_values();
92
+		do_action('AHEE__EE_Admin__loaded');
93
+	}
94
+
95
+
96
+
97
+	/**
98
+	 * _define_all_constants
99
+	 * define constants that are set globally for all admin pages
100
+	 *
101
+	 * @return void
102
+	 */
103
+	private function _define_all_constants()
104
+	{
105
+		if (! defined('EE_ADMIN_URL')) {
106
+			define('EE_ADMIN_URL', EE_PLUGIN_DIR_URL . 'core/admin/');
107
+			define('EE_ADMIN_PAGES_URL', EE_PLUGIN_DIR_URL . 'admin_pages/');
108
+			define('EE_ADMIN_TEMPLATE', EE_ADMIN . 'templates' . DS);
109
+			define('WP_ADMIN_PATH', ABSPATH . 'wp-admin/');
110
+			define('WP_AJAX_URL', admin_url('admin-ajax.php'));
111
+		}
112
+	}
113
+
114
+
115
+	/**
116
+	 * filter_plugin_actions - adds links to the Plugins page listing
117
+	 *
118
+	 * @param    array  $links
119
+	 * @param    string $plugin
120
+	 * @return    array
121
+	 */
122
+	public function filter_plugin_actions($links, $plugin)
123
+	{
124
+		// set $main_file in stone
125
+		static $main_file;
126
+		// if $main_file is not set yet
127
+		if (! $main_file) {
128
+			$main_file = plugin_basename(EVENT_ESPRESSO_MAIN_FILE);
129
+		}
130
+		if ($plugin === $main_file) {
131
+			// compare current plugin to this one
132
+			if (EE_Maintenance_Mode::instance()->level() === EE_Maintenance_Mode::level_2_complete_maintenance) {
133
+				$maintenance_link = '<a href="admin.php?page=espresso_maintenance_settings"'
134
+									. ' title="Event Espresso is in maintenance mode.  Click this link to learn why.">'
135
+									. esc_html__('Maintenance Mode Active', 'event_espresso')
136
+									. '</a>';
137
+				array_unshift($links, $maintenance_link);
138
+			} else {
139
+				$org_settings_link = '<a href="admin.php?page=espresso_general_settings">'
140
+									 . esc_html__('Settings', 'event_espresso')
141
+									 . '</a>';
142
+				$events_link       = '<a href="admin.php?page=espresso_events">'
143
+									 . esc_html__('Events', 'event_espresso')
144
+									 . '</a>';
145
+				// add before other links
146
+				array_unshift($links, $org_settings_link, $events_link);
147
+			}
148
+		}
149
+		return $links;
150
+	}
151
+
152
+
153
+	/**
154
+	 * _get_request
155
+	 *
156
+	 * @return void
157
+	 * @throws EE_Error
158
+	 * @throws InvalidArgumentException
159
+	 * @throws InvalidDataTypeException
160
+	 * @throws InvalidInterfaceException
161
+	 * @throws ReflectionException
162
+	 */
163
+	public function get_request()
164
+	{
165
+		EE_Registry::instance()->load_core('Request_Handler');
166
+		EE_Registry::instance()->load_core('CPT_Strategy');
167
+	}
168
+
169
+
170
+
171
+	/**
172
+	 * hide_admin_pages_except_maintenance_mode
173
+	 *
174
+	 * @param array $admin_page_folder_names
175
+	 * @return array
176
+	 */
177
+	public function hide_admin_pages_except_maintenance_mode($admin_page_folder_names = array())
178
+	{
179
+		return array(
180
+			'maintenance' => EE_ADMIN_PAGES . 'maintenance' . DS,
181
+			'about'       => EE_ADMIN_PAGES . 'about' . DS,
182
+			'support'     => EE_ADMIN_PAGES . 'support' . DS,
183
+		);
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * init- should fire after shortcode, module,  addon, other plugin (default priority), and even
190
+	 * EE_Front_Controller's init phases have run
191
+	 *
192
+	 * @return void
193
+	 * @throws EE_Error
194
+	 * @throws InvalidArgumentException
195
+	 * @throws InvalidDataTypeException
196
+	 * @throws InvalidInterfaceException
197
+	 * @throws ReflectionException
198
+	 * @throws ServiceNotFoundException
199
+	 */
200
+	public function init()
201
+	{
202
+		//only enable most of the EE_Admin IF we're not in full maintenance mode
203
+		if (EE_Maintenance_Mode::instance()->models_can_query()) {
204
+			//ok so we want to enable the entire admin
205
+			$this->persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
206
+				'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
207
+			);
208
+			$this->persistent_admin_notice_manager->setReturnUrl(
209
+				EE_Admin_Page::add_query_args_and_nonce(
210
+					array(
211
+						'page'   => EE_Registry::instance()->REQ->get('page', ''),
212
+						'action' => EE_Registry::instance()->REQ->get('action', ''),
213
+					),
214
+					EE_ADMIN_URL
215
+				)
216
+			);
217
+			$this->maybeSetDatetimeWarningNotice();
218
+			//at a glance dashboard widget
219
+			add_filter('dashboard_glance_items', array($this, 'dashboard_glance_items'), 10);
220
+			//filter for get_edit_post_link used on comments for custom post types
221
+			add_filter('get_edit_post_link', array($this, 'modify_edit_post_link'), 10, 2);
222
+		}
223
+		// run the admin page factory but ONLY if we are doing an ee admin ajax request
224
+		if (! defined('DOING_AJAX') || EE_ADMIN_AJAX) {
225
+			try {
226
+				//this loads the controller for the admin pages which will setup routing etc
227
+				EE_Registry::instance()->load_core('Admin_Page_Loader');
228
+			} catch (EE_Error $e) {
229
+				$e->get_error();
230
+			}
231
+		}
232
+		add_filter('content_save_pre', array($this, 'its_eSpresso'), 10, 1);
233
+		//make sure our CPTs and custom taxonomy metaboxes get shown for first time users
234
+		add_action('admin_head', array($this, 'enable_hidden_ee_nav_menu_metaboxes'), 10);
235
+		add_action('admin_head', array($this, 'register_custom_nav_menu_boxes'), 10);
236
+		//exclude EE critical pages from all nav menus and wp_list_pages
237
+		add_filter('nav_menu_meta_box_object', array($this, 'remove_pages_from_nav_menu'), 10);
238
+	}
239
+
240
+
241
+	/**
242
+	 *    get_persistent_admin_notices
243
+	 *
244
+	 * @access    public
245
+	 * @return void
246
+	 * @throws EE_Error
247
+	 * @throws InvalidArgumentException
248
+	 * @throws InvalidDataTypeException
249
+	 * @throws InvalidInterfaceException
250
+	 */
251
+	public function maybeSetDatetimeWarningNotice()
252
+	{
253
+		//add dismissable notice for datetime changes.  Only valid if site does not have a timezone_string set.
254
+		//@todo This needs to stay in core for a bit to catch anyone upgrading from a version without this to a version
255
+		//with this.  But after enough time (indeterminate at this point) we can just remove this notice.
256
+		//this was added with https://events.codebasehq.com/projects/event-espresso/tickets/10626
257
+		if (apply_filters('FHEE__EE_Admin__maybeSetDatetimeWarningNotice', true)
258
+			&& ! get_option('timezone_string')
259
+			&& EEM_Event::instance()->count() > 0
260
+		) {
261
+			new PersistentAdminNotice(
262
+				'datetime_fix_notice',
263
+				sprintf(
264
+					esc_html__(
265
+						'%1$sImportant announcement related to your install of Event Espresso%2$s: There are some changes made to your site that could affect how dates display for your events and other related items with dates and times.  Read more about it %3$shere%4$s. If your dates and times are displaying incorrectly (incorrect offset), you can fix it using the tool on %5$sthis page%4$s.',
266
+						'event_espresso'
267
+					),
268
+					'<strong>',
269
+					'</strong>',
270
+					'<a href="https://eventespresso.com/2017/08/important-upcoming-changes-dates-times">',
271
+					'</a>',
272
+					'<a href="' . EE_Admin_Page::add_query_args_and_nonce(
273
+						array(
274
+							'page' => 'espresso_maintenance_settings',
275
+							'action' => 'datetime_tools'
276
+						),
277
+						admin_url('admin.php')
278
+					) . '">'
279
+				),
280
+				false,
281
+				'manage_options',
282
+				'datetime_fix_persistent_notice'
283
+			);
284
+		}
285
+	}
286
+
287
+
288
+
289
+	/**
290
+	 * this simply hooks into the nav menu setup of pages metabox and makes sure that we remove EE critical pages from
291
+	 * the list of options. the wp function "wp_nav_menu_item_post_type_meta_box" found in
292
+	 * wp-admin/includes/nav-menu.php looks for the "_default_query" property on the post_type object and it uses that
293
+	 * to override any queries found in the existing query for the given post type.  Note that _default_query is not a
294
+	 * normal property on the post_type object.  It's found ONLY in this particular context.
295
+	 *
296
+	 * @param WP_Post $post_type WP post type object
297
+	 * @return WP_Post
298
+	 * @throws InvalidArgumentException
299
+	 * @throws InvalidDataTypeException
300
+	 * @throws InvalidInterfaceException
301
+	 */
302
+	public function remove_pages_from_nav_menu($post_type)
303
+	{
304
+		//if this isn't the "pages" post type let's get out
305
+		if ($post_type->name !== 'page') {
306
+			return $post_type;
307
+		}
308
+		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
309
+		$post_type->_default_query = array(
310
+			'post__not_in' => $critical_pages,
311
+		);
312
+		return $post_type;
313
+	}
314
+
315
+
316
+
317
+	/**
318
+	 * WP by default only shows three metaboxes in "nav-menus.php" for first times users.  We want to make sure our
319
+	 * metaboxes get shown as well
320
+	 *
321
+	 * @return void
322
+	 */
323
+	public function enable_hidden_ee_nav_menu_metaboxes()
324
+	{
325
+		global $wp_meta_boxes, $pagenow;
326
+		if (! is_array($wp_meta_boxes) || $pagenow !== 'nav-menus.php') {
327
+			return;
328
+		}
329
+		$user = wp_get_current_user();
330
+		//has this been done yet?
331
+		if (get_user_option('ee_nav_menu_initialized', $user->ID)) {
332
+			return;
333
+		}
334
+
335
+		$hidden_meta_boxes  = get_user_option('metaboxhidden_nav-menus', $user->ID);
336
+		$initial_meta_boxes = apply_filters(
337
+			'FHEE__EE_Admin__enable_hidden_ee_nav_menu_boxes__initial_meta_boxes',
338
+			array(
339
+				'nav-menu-theme-locations',
340
+				'add-page',
341
+				'add-custom-links',
342
+				'add-category',
343
+				'add-espresso_events',
344
+				'add-espresso_venues',
345
+				'add-espresso_event_categories',
346
+				'add-espresso_venue_categories',
347
+				'add-post-type-post',
348
+				'add-post-type-page',
349
+			)
350
+		);
351
+
352
+		if (is_array($hidden_meta_boxes)) {
353
+			foreach ($hidden_meta_boxes as $key => $meta_box_id) {
354
+				if (in_array($meta_box_id, $initial_meta_boxes, true)) {
355
+					unset($hidden_meta_boxes[$key]);
356
+				}
357
+			}
358
+		}
359
+		update_user_option($user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, true);
360
+		update_user_option($user->ID, 'ee_nav_menu_initialized', 1, true);
361
+	}
362
+
363
+
364
+
365
+	/**
366
+	 * This method simply registers custom nav menu boxes for "nav_menus.php route"
367
+	 * Currently EE is using this to make sure there are menu options for our CPT archive page routes.
368
+	 *
369
+	 * @todo   modify this so its more dynamic and automatic for all ee CPTs and setups and can also be hooked into by
370
+	 *         addons etc.
371
+	 * @return void
372
+	 */
373
+	public function register_custom_nav_menu_boxes()
374
+	{
375
+		add_meta_box(
376
+			'add-extra-nav-menu-pages',
377
+			esc_html__('Event Espresso Pages', 'event_espresso'),
378
+			array($this, 'ee_cpt_archive_pages'),
379
+			'nav-menus',
380
+			'side',
381
+			'core'
382
+		);
383
+	}
384
+
385
+
386
+
387
+	/**
388
+	 * Use this to edit the post link for our cpts so that the edit link points to the correct page.
389
+	 *
390
+	 * @since   4.3.0
391
+	 * @param string $link the original link generated by wp
392
+	 * @param int    $id   post id
393
+	 * @return string  the (maybe) modified link
394
+	 */
395
+	public function modify_edit_post_link($link, $id)
396
+	{
397
+		if (! $post = get_post($id)) {
398
+			return $link;
399
+		}
400
+		if ($post->post_type === 'espresso_attendees') {
401
+			$query_args = array(
402
+				'action' => 'edit_attendee',
403
+				'post'   => $id,
404
+			);
405
+			return EEH_URL::add_query_args_and_nonce(
406
+				$query_args,
407
+				admin_url('admin.php?page=espresso_registrations')
408
+			);
409
+		}
410
+		return $link;
411
+	}
412
+
413
+
414
+
415
+	public function ee_cpt_archive_pages()
416
+	{
417
+		global $nav_menu_selected_id;
418
+		$db_fields   = false;
419
+		$walker      = new Walker_Nav_Menu_Checklist($db_fields);
420
+		$current_tab = 'event-archives';
421
+		$removed_args = array(
422
+			'action',
423
+			'customlink-tab',
424
+			'edit-menu-item',
425
+			'menu-item',
426
+			'page-tab',
427
+			'_wpnonce',
428
+		);
429
+		?>
430 430
         <div id="posttype-extra-nav-menu-pages" class="posttypediv">
431 431
             <ul id="posttype-extra-nav-menu-pages-tabs" class="posttype-tabs add-menu-item-tabs">
432 432
                 <li <?php echo('event-archives' === $current_tab ? ' class="tabs"' : ''); ?>>
433 433
                     <a class="nav-tab-link" data-type="tabs-panel-posttype-extra-nav-menu-pages-event-archives"
434 434
                        href="<?php if ($nav_menu_selected_id) {
435
-                            echo esc_url(
436
-                                add_query_arg(
437
-                                    'extra-nav-menu-pages-tab',
438
-                                    'event-archives',
439
-                                    remove_query_arg($removed_args)
440
-                                )
441
-                            );
442
-                       } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
435
+							echo esc_url(
436
+								add_query_arg(
437
+									'extra-nav-menu-pages-tab',
438
+									'event-archives',
439
+									remove_query_arg($removed_args)
440
+								)
441
+							);
442
+					   } ?>#tabs-panel-posttype-extra-nav-menu-pages-event-archives">
443 443
                         <?php _e('Event Archive Pages', 'event_espresso'); ?>
444 444
                     </a>
445 445
                 </li>
446 446
             </ul><!-- .posttype-tabs -->
447 447
 
448 448
             <div id="tabs-panel-posttype-extra-nav-menu-pages-event-archives" class="tabs-panel <?php
449
-                echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive');
450
-                ?>">
449
+				echo('event-archives' === $current_tab ? 'tabs-panel-active' : 'tabs-panel-inactive');
450
+				?>">
451 451
                     <ul id="extra-nav-menu-pageschecklist-event-archives" class="categorychecklist form-no-clear">
452 452
                         <?php
453
-                        $pages          = $this->_get_extra_nav_menu_pages_items();
454
-                        $args['walker'] = $walker;
455
-                        echo walk_nav_menu_tree(
456
-                            array_map(
457
-                                array($this, '_setup_extra_nav_menu_pages_items'),
458
-                                $pages
459
-                            ),
460
-                            0,
461
-                            (object) $args
462
-                        );
463
-                        ?>
453
+						$pages          = $this->_get_extra_nav_menu_pages_items();
454
+						$args['walker'] = $walker;
455
+						echo walk_nav_menu_tree(
456
+							array_map(
457
+								array($this, '_setup_extra_nav_menu_pages_items'),
458
+								$pages
459
+							),
460
+							0,
461
+							(object) $args
462
+						);
463
+						?>
464 464
                     </ul>
465 465
                 </div><!-- /.tabs-panel -->
466 466
 
467 467
                 <p class="button-controls">
468 468
                 <span class="list-controls">
469 469
                     <a href="<?php
470
-                    echo esc_url(add_query_arg(
471
-                        array(
472
-                            'extra-nav-menu-pages-tab' => 'event-archives',
473
-                            'selectall'                => 1,
474
-                        ),
475
-                        remove_query_arg($removed_args)
476
-                    ));
477
-                    ?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a>
470
+					echo esc_url(add_query_arg(
471
+						array(
472
+							'extra-nav-menu-pages-tab' => 'event-archives',
473
+							'selectall'                => 1,
474
+						),
475
+						remove_query_arg($removed_args)
476
+					));
477
+					?>#posttype-extra-nav-menu-pages>" class="select-all"><?php _e('Select All'); ?></a>
478 478
                 </span>
479 479
                 <span class="add-to-menu">
480 480
                     <input type="submit"<?php wp_nav_menu_disabled_check($nav_menu_selected_id); ?>
@@ -487,486 +487,486 @@  discard block
 block discarded – undo
487 487
 
488 488
         </div><!-- /.posttypediv -->
489 489
         <?php
490
-    }
491
-
492
-
493
-    /**
494
-     * Returns an array of event archive nav items.
495
-     *
496
-     * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever
497
-     *        method we use for getting the extra nav menu items
498
-     * @return array
499
-     */
500
-    private function _get_extra_nav_menu_pages_items()
501
-    {
502
-        $menuitems[] = array(
503
-            'title'       => esc_html__('Event List', 'event_espresso'),
504
-            'url'         => get_post_type_archive_link('espresso_events'),
505
-            'description' => esc_html__('Archive page for all events.', 'event_espresso'),
506
-        );
507
-        return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
508
-    }
509
-
510
-
511
-    /**
512
-     * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with
513
-     * the properties and converts it to the menu item object.
514
-     *
515
-     * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
516
-     * @param $menu_item_values
517
-     * @return stdClass
518
-     */
519
-    private function _setup_extra_nav_menu_pages_items($menu_item_values)
520
-    {
521
-        $menu_item = new stdClass();
522
-        $keys      = array(
523
-            'ID'               => 0,
524
-            'db_id'            => 0,
525
-            'menu_item_parent' => 0,
526
-            'object_id'        => -1,
527
-            'post_parent'      => 0,
528
-            'type'             => 'custom',
529
-            'object'           => '',
530
-            'type_label'       => esc_html__('Extra Nav Menu Item', 'event_espresso'),
531
-            'title'            => '',
532
-            'url'              => '',
533
-            'target'           => '',
534
-            'attr_title'       => '',
535
-            'description'      => '',
536
-            'classes'          => array(),
537
-            'xfn'              => '',
538
-        );
539
-
540
-        foreach ($keys as $key => $value) {
541
-            $menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value;
542
-        }
543
-        return $menu_item;
544
-    }
545
-
546
-
547
-    /**
548
-     * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an
549
-     * EE_Admin_Page route is called.
550
-     *
551
-     * @return void
552
-     */
553
-    public function route_admin_request()
554
-    {
555
-    }
556
-
557
-
558
-    /**
559
-     * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
560
-     *
561
-     * @return void
562
-     */
563
-    public function wp_loaded()
564
-    {
565
-    }
566
-
567
-
568
-    /**
569
-     * admin_init
570
-     *
571
-     * @return void
572
-     * @throws EE_Error
573
-     * @throws InvalidArgumentException
574
-     * @throws InvalidDataTypeException
575
-     * @throws InvalidInterfaceException
576
-     * @throws ReflectionException
577
-     */
578
-    public function admin_init()
579
-    {
580
-
581
-        /**
582
-         * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
583
-         * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
584
-         * - check if doing post processing.
585
-         * - check if doing post processing of one of EE CPTs
586
-         * - instantiate the corresponding EE CPT model for the post_type being processed.
587
-         */
588
-        if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') {
589
-            EE_Registry::instance()->load_core('Register_CPTs');
590
-            EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']);
591
-        }
592
-
593
-
594
-        /**
595
-         * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
596
-         * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
597
-         * Pages" tab in the EE General Settings Admin page.
598
-         * This is for user-proofing.
599
-         */
600
-        add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages'));
601
-    }
602
-
603
-
604
-    /**
605
-     * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
606
-     *
607
-     * @param string $output Current output.
608
-     * @return string
609
-     * @throws InvalidArgumentException
610
-     * @throws InvalidDataTypeException
611
-     * @throws InvalidInterfaceException
612
-     */
613
-    public function modify_dropdown_pages($output)
614
-    {
615
-        //get critical pages
616
-        $critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
617
-
618
-        //split current output by line break for easier parsing.
619
-        $split_output = explode("\n", $output);
620
-
621
-        //loop through to remove any critical pages from the array.
622
-        foreach ($critical_pages as $page_id) {
623
-            $needle = 'value="' . $page_id . '"';
624
-            foreach ($split_output as $key => $haystack) {
625
-                if (strpos($haystack, $needle) !== false) {
626
-                    unset($split_output[$key]);
627
-                }
628
-            }
629
-        }
630
-        //replace output with the new contents
631
-        return implode("\n", $split_output);
632
-    }
633
-
634
-
635
-    /**
636
-     * enqueue all admin scripts that need loaded for admin pages
637
-     *
638
-     * @return void
639
-     */
640
-    public function enqueue_admin_scripts()
641
-    {
642
-        // this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
643
-        // Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script
644
-        // calls.
645
-        wp_enqueue_script(
646
-            'ee-inject-wp',
647
-            EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
648
-            array('jquery'),
649
-            EVENT_ESPRESSO_VERSION,
650
-            true
651
-        );
652
-        // register cookie script for future dependencies
653
-        wp_register_script(
654
-            'jquery-cookie',
655
-            EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
656
-            array('jquery'),
657
-            '2.1',
658
-            true
659
-        );
660
-        //joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again
661
-        // via: add_filter('FHEE_load_joyride', '__return_true' );
662
-        if (apply_filters('FHEE_load_joyride', false)) {
663
-            //joyride style
664
-            wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
665
-            wp_register_style(
666
-                'ee-joyride-css',
667
-                EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
668
-                array('joyride-css'),
669
-                EVENT_ESPRESSO_VERSION
670
-            );
671
-            wp_register_script(
672
-                'joyride-modernizr',
673
-                EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
674
-                array(),
675
-                '2.1',
676
-                true
677
-            );
678
-            //joyride JS
679
-            wp_register_script(
680
-                'jquery-joyride',
681
-                EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
682
-                array('jquery-cookie', 'joyride-modernizr'),
683
-                '2.1',
684
-                true
685
-            );
686
-            // wanna go for a joyride?
687
-            wp_enqueue_style('ee-joyride-css');
688
-            wp_enqueue_script('jquery-joyride');
689
-        }
690
-    }
691
-
692
-
693
-    /**
694
-     * display_admin_notices
695
-     *
696
-     * @return void
697
-     */
698
-    public function display_admin_notices()
699
-    {
700
-        echo EE_Error::get_notices();
701
-    }
702
-
703
-
704
-
705
-    /**
706
-     * @param array $elements
707
-     * @return array
708
-     * @throws EE_Error
709
-     * @throws InvalidArgumentException
710
-     * @throws InvalidDataTypeException
711
-     * @throws InvalidInterfaceException
712
-     */
713
-    public function dashboard_glance_items($elements)
714
-    {
715
-        $elements                        = is_array($elements) ? $elements : array($elements);
716
-        $events                          = EEM_Event::instance()->count();
717
-        $items['events']['url']          = EE_Admin_Page::add_query_args_and_nonce(
718
-            array('page' => 'espresso_events'),
719
-            admin_url('admin.php')
720
-        );
721
-        $items['events']['text']         = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events));
722
-        $items['events']['title']        = esc_html__('Click to view all Events', 'event_espresso');
723
-        $registrations                   = EEM_Registration::instance()->count(
724
-            array(
725
-                array(
726
-                    'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
727
-                ),
728
-            )
729
-        );
730
-        $items['registrations']['url']   = EE_Admin_Page::add_query_args_and_nonce(
731
-            array('page' => 'espresso_registrations'),
732
-            admin_url('admin.php')
733
-        );
734
-        $items['registrations']['text']  = sprintf(
735
-            _n('%s Registration', '%s Registrations', $registrations),
736
-            number_format_i18n($registrations)
737
-        );
738
-        $items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
739
-
740
-        $items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
741
-
742
-        foreach ($items as $type => $item_properties) {
743
-            $elements[] = sprintf(
744
-                '<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
745
-                $item_properties['url'],
746
-                $item_properties['title'],
747
-                $item_properties['text']
748
-            );
749
-        }
750
-        return $elements;
751
-    }
752
-
753
-
754
-    /**
755
-     * check_for_invalid_datetime_formats
756
-     * if an admin changes their date or time format settings on the WP General Settings admin page, verify that
757
-     * their selected format can be parsed by PHP
758
-     *
759
-     * @param    $value
760
-     * @param    $option
761
-     * @throws EE_Error
762
-     * @return    string
763
-     */
764
-    public function check_for_invalid_datetime_formats($value, $option)
765
-    {
766
-        // check for date_format or time_format
767
-        switch ($option) {
768
-            case 'date_format':
769
-                $date_time_format = $value . ' ' . get_option('time_format');
770
-                break;
771
-            case 'time_format':
772
-                $date_time_format = get_option('date_format') . ' ' . $value;
773
-                break;
774
-            default:
775
-                $date_time_format = false;
776
-        }
777
-        // do we have a date_time format to check ?
778
-        if ($date_time_format) {
779
-            $error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
780
-
781
-            if (is_array($error_msg)) {
782
-                $msg = '<p>'
783
-                       . sprintf(
784
-                           esc_html__(
785
-                               'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
786
-                               'event_espresso'
787
-                           ),
788
-                           date($date_time_format),
789
-                           $date_time_format
790
-                       )
791
-                       . '</p><p><ul>';
792
-
793
-
794
-                foreach ($error_msg as $error) {
795
-                    $msg .= '<li>' . $error . '</li>';
796
-                }
797
-
798
-                $msg .= '</ul></p><p>'
799
-                        . sprintf(
800
-                            esc_html__(
801
-                                '%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
802
-                                'event_espresso'
803
-                            ),
804
-                            '<span style="color:#D54E21;">',
805
-                            '</span>'
806
-                        )
807
-                        . '</p>';
808
-
809
-                // trigger WP settings error
810
-                add_settings_error(
811
-                    'date_format',
812
-                    'date_format',
813
-                    $msg
814
-                );
815
-
816
-                // set format to something valid
817
-                switch ($option) {
818
-                    case 'date_format':
819
-                        $value = 'F j, Y';
820
-                        break;
821
-                    case 'time_format':
822
-                        $value = 'g:i a';
823
-                        break;
824
-                }
825
-            }
826
-        }
827
-        return $value;
828
-    }
829
-
830
-
831
-    /**
832
-     * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
833
-     *
834
-     * @param $content
835
-     * @return    string
836
-     */
837
-    public function its_eSpresso($content)
838
-    {
839
-        return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
840
-    }
841
-
842
-
843
-    /**
844
-     * espresso_admin_footer
845
-     *
846
-     * @return    string
847
-     */
848
-    public function espresso_admin_footer()
849
-    {
850
-        return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
851
-    }
852
-
853
-
854
-    /**
855
-     * static method for registering ee admin page.
856
-     * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
857
-     *
858
-     * @since      4.3.0
859
-     * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
860
-     * @see        EE_Register_Admin_Page::register()
861
-     * @param       $page_basename
862
-     * @param       $page_path
863
-     * @param array $config
864
-     * @return void
865
-     * @throws EE_Error
866
-     */
867
-    public static function register_ee_admin_page($page_basename, $page_path, $config = array())
868
-    {
869
-        EE_Error::doing_it_wrong(
870
-            __METHOD__,
871
-            sprintf(
872
-                esc_html__(
873
-                    'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
874
-                    'event_espresso'
875
-                ),
876
-                $page_basename
877
-            ),
878
-            '4.3'
879
-        );
880
-        if (class_exists('EE_Register_Admin_Page')) {
881
-            $config['page_path'] = $page_path;
882
-        }
883
-        EE_Register_Admin_Page::register($page_basename, $config);
884
-    }
885
-
886
-
887
-    /**
888
-     * @deprecated 4.8.41
889
-     * @param  int      $post_ID
890
-     * @param  \WP_Post $post
891
-     * @return void
892
-     */
893
-    public static function parse_post_content_on_save($post_ID, $post)
894
-    {
895
-        EE_Error::doing_it_wrong(
896
-            __METHOD__,
897
-            esc_html__('Usage is deprecated', 'event_espresso'),
898
-            '4.8.41'
899
-        );
900
-    }
901
-
902
-
903
-    /**
904
-     * @deprecated 4.8.41
905
-     * @param  $option
906
-     * @param  $old_value
907
-     * @param  $value
908
-     * @return void
909
-     */
910
-    public function reset_page_for_posts_on_change($option, $old_value, $value)
911
-    {
912
-        EE_Error::doing_it_wrong(
913
-            __METHOD__,
914
-            esc_html__('Usage is deprecated', 'event_espresso'),
915
-            '4.8.41'
916
-        );
917
-    }
918
-
919
-
920
-
921
-    /**
922
-     * @deprecated 4.9.27
923
-     * @return void
924
-     */
925
-    public function get_persistent_admin_notices()
926
-    {
927
-        EE_Error::doing_it_wrong(
928
-            __METHOD__,
929
-            sprintf(
930
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
931
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
932
-            ),
933
-            '4.9.27'
934
-        );
935
-    }
936
-
937
-
938
-
939
-    /**
940
-     * @deprecated 4.9.27
941
-     * @throws InvalidInterfaceException
942
-     * @throws InvalidDataTypeException
943
-     * @throws DomainException
944
-     */
945
-    public function dismiss_ee_nag_notice_callback()
946
-    {
947
-        EE_Error::doing_it_wrong(
948
-            __METHOD__,
949
-            sprintf(
950
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
951
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
952
-            ),
953
-            '4.9.27'
954
-        );
955
-        $this->persistent_admin_notice_manager->dismissNotice();
956
-    }
957
-
958
-
959
-    /**
960
-     * Callback on load-plugins.php hook for setting up anything hooking into the wp plugins page.
961
-     * @throws InvalidArgumentException
962
-     * @throws InvalidDataTypeException
963
-     * @throws InvalidInterfaceException
964
-     */
965
-    public function hookIntoWpPluginsPage()
966
-    {
967
-        LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\services\admin\ExitModal');
968
-        LoaderFactory::getLoader()
969
-                     ->getShared('EventEspresso\core\domain\services\admin\PluginUpsells')
970
-                     ->decafUpsells();
971
-    }
490
+	}
491
+
492
+
493
+	/**
494
+	 * Returns an array of event archive nav items.
495
+	 *
496
+	 * @todo  for now this method is just in place so when it gets abstracted further we can substitute in whatever
497
+	 *        method we use for getting the extra nav menu items
498
+	 * @return array
499
+	 */
500
+	private function _get_extra_nav_menu_pages_items()
501
+	{
502
+		$menuitems[] = array(
503
+			'title'       => esc_html__('Event List', 'event_espresso'),
504
+			'url'         => get_post_type_archive_link('espresso_events'),
505
+			'description' => esc_html__('Archive page for all events.', 'event_espresso'),
506
+		);
507
+		return apply_filters('FHEE__EE_Admin__get_extra_nav_menu_pages_items', $menuitems);
508
+	}
509
+
510
+
511
+	/**
512
+	 * Setup nav menu walker item for usage in the event archive nav menu metabox.  It receives a menu_item array with
513
+	 * the properties and converts it to the menu item object.
514
+	 *
515
+	 * @see wp_setup_nav_menu_item() in wp-includes/nav-menu.php
516
+	 * @param $menu_item_values
517
+	 * @return stdClass
518
+	 */
519
+	private function _setup_extra_nav_menu_pages_items($menu_item_values)
520
+	{
521
+		$menu_item = new stdClass();
522
+		$keys      = array(
523
+			'ID'               => 0,
524
+			'db_id'            => 0,
525
+			'menu_item_parent' => 0,
526
+			'object_id'        => -1,
527
+			'post_parent'      => 0,
528
+			'type'             => 'custom',
529
+			'object'           => '',
530
+			'type_label'       => esc_html__('Extra Nav Menu Item', 'event_espresso'),
531
+			'title'            => '',
532
+			'url'              => '',
533
+			'target'           => '',
534
+			'attr_title'       => '',
535
+			'description'      => '',
536
+			'classes'          => array(),
537
+			'xfn'              => '',
538
+		);
539
+
540
+		foreach ($keys as $key => $value) {
541
+			$menu_item->{$key} = isset($menu_item_values[$key]) ? $menu_item_values[$key] : $value;
542
+		}
543
+		return $menu_item;
544
+	}
545
+
546
+
547
+	/**
548
+	 * This is the action hook for the AHEE__EE_Admin_Page__route_admin_request hook that fires off right before an
549
+	 * EE_Admin_Page route is called.
550
+	 *
551
+	 * @return void
552
+	 */
553
+	public function route_admin_request()
554
+	{
555
+	}
556
+
557
+
558
+	/**
559
+	 * wp_loaded should fire on the WordPress wp_loaded hook.  This fires on a VERY late priority.
560
+	 *
561
+	 * @return void
562
+	 */
563
+	public function wp_loaded()
564
+	{
565
+	}
566
+
567
+
568
+	/**
569
+	 * admin_init
570
+	 *
571
+	 * @return void
572
+	 * @throws EE_Error
573
+	 * @throws InvalidArgumentException
574
+	 * @throws InvalidDataTypeException
575
+	 * @throws InvalidInterfaceException
576
+	 * @throws ReflectionException
577
+	 */
578
+	public function admin_init()
579
+	{
580
+
581
+		/**
582
+		 * our cpt models must be instantiated on WordPress post processing routes (wp-admin/post.php),
583
+		 * so any hooking into core WP routes is taken care of.  So in this next few lines of code:
584
+		 * - check if doing post processing.
585
+		 * - check if doing post processing of one of EE CPTs
586
+		 * - instantiate the corresponding EE CPT model for the post_type being processed.
587
+		 */
588
+		if (isset($_POST['action'], $_POST['post_type']) && $_POST['action'] === 'editpost') {
589
+			EE_Registry::instance()->load_core('Register_CPTs');
590
+			EE_Register_CPTs::instantiate_cpt_models($_POST['post_type']);
591
+		}
592
+
593
+
594
+		/**
595
+		 * This code excludes EE critical pages anywhere `wp_dropdown_pages` is used to create a dropdown for selecting
596
+		 * critical pages.  The only place critical pages need included in a generated dropdown is on the "Critical
597
+		 * Pages" tab in the EE General Settings Admin page.
598
+		 * This is for user-proofing.
599
+		 */
600
+		add_filter('wp_dropdown_pages', array($this, 'modify_dropdown_pages'));
601
+	}
602
+
603
+
604
+	/**
605
+	 * Callback for wp_dropdown_pages hook to remove ee critical pages from the dropdown selection.
606
+	 *
607
+	 * @param string $output Current output.
608
+	 * @return string
609
+	 * @throws InvalidArgumentException
610
+	 * @throws InvalidDataTypeException
611
+	 * @throws InvalidInterfaceException
612
+	 */
613
+	public function modify_dropdown_pages($output)
614
+	{
615
+		//get critical pages
616
+		$critical_pages = EE_Registry::instance()->CFG->core->get_critical_pages_array();
617
+
618
+		//split current output by line break for easier parsing.
619
+		$split_output = explode("\n", $output);
620
+
621
+		//loop through to remove any critical pages from the array.
622
+		foreach ($critical_pages as $page_id) {
623
+			$needle = 'value="' . $page_id . '"';
624
+			foreach ($split_output as $key => $haystack) {
625
+				if (strpos($haystack, $needle) !== false) {
626
+					unset($split_output[$key]);
627
+				}
628
+			}
629
+		}
630
+		//replace output with the new contents
631
+		return implode("\n", $split_output);
632
+	}
633
+
634
+
635
+	/**
636
+	 * enqueue all admin scripts that need loaded for admin pages
637
+	 *
638
+	 * @return void
639
+	 */
640
+	public function enqueue_admin_scripts()
641
+	{
642
+		// this javascript is loaded on every admin page to catch any injections ee needs to add to wp run js.
643
+		// Note: the intention of this script is to only do TARGETED injections.  I.E, only injecting on certain script
644
+		// calls.
645
+		wp_enqueue_script(
646
+			'ee-inject-wp',
647
+			EE_ADMIN_URL . 'assets/ee-cpt-wp-injects.js',
648
+			array('jquery'),
649
+			EVENT_ESPRESSO_VERSION,
650
+			true
651
+		);
652
+		// register cookie script for future dependencies
653
+		wp_register_script(
654
+			'jquery-cookie',
655
+			EE_THIRD_PARTY_URL . 'joyride/jquery.cookie.js',
656
+			array('jquery'),
657
+			'2.1',
658
+			true
659
+		);
660
+		//joyride is turned OFF by default, but prior to the admin_enqueue_scripts hook, can be turned back on again
661
+		// via: add_filter('FHEE_load_joyride', '__return_true' );
662
+		if (apply_filters('FHEE_load_joyride', false)) {
663
+			//joyride style
664
+			wp_register_style('joyride-css', EE_THIRD_PARTY_URL . 'joyride/joyride-2.1.css', array(), '2.1');
665
+			wp_register_style(
666
+				'ee-joyride-css',
667
+				EE_GLOBAL_ASSETS_URL . 'css/ee-joyride-styles.css',
668
+				array('joyride-css'),
669
+				EVENT_ESPRESSO_VERSION
670
+			);
671
+			wp_register_script(
672
+				'joyride-modernizr',
673
+				EE_THIRD_PARTY_URL . 'joyride/modernizr.mq.js',
674
+				array(),
675
+				'2.1',
676
+				true
677
+			);
678
+			//joyride JS
679
+			wp_register_script(
680
+				'jquery-joyride',
681
+				EE_THIRD_PARTY_URL . 'joyride/jquery.joyride-2.1.js',
682
+				array('jquery-cookie', 'joyride-modernizr'),
683
+				'2.1',
684
+				true
685
+			);
686
+			// wanna go for a joyride?
687
+			wp_enqueue_style('ee-joyride-css');
688
+			wp_enqueue_script('jquery-joyride');
689
+		}
690
+	}
691
+
692
+
693
+	/**
694
+	 * display_admin_notices
695
+	 *
696
+	 * @return void
697
+	 */
698
+	public function display_admin_notices()
699
+	{
700
+		echo EE_Error::get_notices();
701
+	}
702
+
703
+
704
+
705
+	/**
706
+	 * @param array $elements
707
+	 * @return array
708
+	 * @throws EE_Error
709
+	 * @throws InvalidArgumentException
710
+	 * @throws InvalidDataTypeException
711
+	 * @throws InvalidInterfaceException
712
+	 */
713
+	public function dashboard_glance_items($elements)
714
+	{
715
+		$elements                        = is_array($elements) ? $elements : array($elements);
716
+		$events                          = EEM_Event::instance()->count();
717
+		$items['events']['url']          = EE_Admin_Page::add_query_args_and_nonce(
718
+			array('page' => 'espresso_events'),
719
+			admin_url('admin.php')
720
+		);
721
+		$items['events']['text']         = sprintf(_n('%s Event', '%s Events', $events), number_format_i18n($events));
722
+		$items['events']['title']        = esc_html__('Click to view all Events', 'event_espresso');
723
+		$registrations                   = EEM_Registration::instance()->count(
724
+			array(
725
+				array(
726
+					'STS_ID' => array('!=', EEM_Registration::status_id_incomplete),
727
+				),
728
+			)
729
+		);
730
+		$items['registrations']['url']   = EE_Admin_Page::add_query_args_and_nonce(
731
+			array('page' => 'espresso_registrations'),
732
+			admin_url('admin.php')
733
+		);
734
+		$items['registrations']['text']  = sprintf(
735
+			_n('%s Registration', '%s Registrations', $registrations),
736
+			number_format_i18n($registrations)
737
+		);
738
+		$items['registrations']['title'] = esc_html__('Click to view all registrations', 'event_espresso');
739
+
740
+		$items = (array)apply_filters('FHEE__EE_Admin__dashboard_glance_items__items', $items);
741
+
742
+		foreach ($items as $type => $item_properties) {
743
+			$elements[] = sprintf(
744
+				'<a class="ee-dashboard-link-' . $type . '" href="%s" title="%s">%s</a>',
745
+				$item_properties['url'],
746
+				$item_properties['title'],
747
+				$item_properties['text']
748
+			);
749
+		}
750
+		return $elements;
751
+	}
752
+
753
+
754
+	/**
755
+	 * check_for_invalid_datetime_formats
756
+	 * if an admin changes their date or time format settings on the WP General Settings admin page, verify that
757
+	 * their selected format can be parsed by PHP
758
+	 *
759
+	 * @param    $value
760
+	 * @param    $option
761
+	 * @throws EE_Error
762
+	 * @return    string
763
+	 */
764
+	public function check_for_invalid_datetime_formats($value, $option)
765
+	{
766
+		// check for date_format or time_format
767
+		switch ($option) {
768
+			case 'date_format':
769
+				$date_time_format = $value . ' ' . get_option('time_format');
770
+				break;
771
+			case 'time_format':
772
+				$date_time_format = get_option('date_format') . ' ' . $value;
773
+				break;
774
+			default:
775
+				$date_time_format = false;
776
+		}
777
+		// do we have a date_time format to check ?
778
+		if ($date_time_format) {
779
+			$error_msg = EEH_DTT_Helper::validate_format_string($date_time_format);
780
+
781
+			if (is_array($error_msg)) {
782
+				$msg = '<p>'
783
+					   . sprintf(
784
+						   esc_html__(
785
+							   'The following date time "%s" ( %s ) is difficult to be properly parsed by PHP for the following reasons:',
786
+							   'event_espresso'
787
+						   ),
788
+						   date($date_time_format),
789
+						   $date_time_format
790
+					   )
791
+					   . '</p><p><ul>';
792
+
793
+
794
+				foreach ($error_msg as $error) {
795
+					$msg .= '<li>' . $error . '</li>';
796
+				}
797
+
798
+				$msg .= '</ul></p><p>'
799
+						. sprintf(
800
+							esc_html__(
801
+								'%sPlease note that your date and time formats have been reset to "F j, Y" and "g:i a" respectively.%s',
802
+								'event_espresso'
803
+							),
804
+							'<span style="color:#D54E21;">',
805
+							'</span>'
806
+						)
807
+						. '</p>';
808
+
809
+				// trigger WP settings error
810
+				add_settings_error(
811
+					'date_format',
812
+					'date_format',
813
+					$msg
814
+				);
815
+
816
+				// set format to something valid
817
+				switch ($option) {
818
+					case 'date_format':
819
+						$value = 'F j, Y';
820
+						break;
821
+					case 'time_format':
822
+						$value = 'g:i a';
823
+						break;
824
+				}
825
+			}
826
+		}
827
+		return $value;
828
+	}
829
+
830
+
831
+	/**
832
+	 * its_eSpresso - converts the less commonly used spelling of "Expresso" to "Espresso"
833
+	 *
834
+	 * @param $content
835
+	 * @return    string
836
+	 */
837
+	public function its_eSpresso($content)
838
+	{
839
+		return str_replace('[EXPRESSO_', '[ESPRESSO_', $content);
840
+	}
841
+
842
+
843
+	/**
844
+	 * espresso_admin_footer
845
+	 *
846
+	 * @return    string
847
+	 */
848
+	public function espresso_admin_footer()
849
+	{
850
+		return \EEH_Template::powered_by_event_espresso('aln-cntr', '', array('utm_content' => 'admin_footer'));
851
+	}
852
+
853
+
854
+	/**
855
+	 * static method for registering ee admin page.
856
+	 * This method is deprecated in favor of the new location in EE_Register_Admin_Page::register.
857
+	 *
858
+	 * @since      4.3.0
859
+	 * @deprecated 4.3.0    Use EE_Register_Admin_Page::register() instead
860
+	 * @see        EE_Register_Admin_Page::register()
861
+	 * @param       $page_basename
862
+	 * @param       $page_path
863
+	 * @param array $config
864
+	 * @return void
865
+	 * @throws EE_Error
866
+	 */
867
+	public static function register_ee_admin_page($page_basename, $page_path, $config = array())
868
+	{
869
+		EE_Error::doing_it_wrong(
870
+			__METHOD__,
871
+			sprintf(
872
+				esc_html__(
873
+					'Usage is deprecated.  Use EE_Register_Admin_Page::register() for registering the %s admin page.',
874
+					'event_espresso'
875
+				),
876
+				$page_basename
877
+			),
878
+			'4.3'
879
+		);
880
+		if (class_exists('EE_Register_Admin_Page')) {
881
+			$config['page_path'] = $page_path;
882
+		}
883
+		EE_Register_Admin_Page::register($page_basename, $config);
884
+	}
885
+
886
+
887
+	/**
888
+	 * @deprecated 4.8.41
889
+	 * @param  int      $post_ID
890
+	 * @param  \WP_Post $post
891
+	 * @return void
892
+	 */
893
+	public static function parse_post_content_on_save($post_ID, $post)
894
+	{
895
+		EE_Error::doing_it_wrong(
896
+			__METHOD__,
897
+			esc_html__('Usage is deprecated', 'event_espresso'),
898
+			'4.8.41'
899
+		);
900
+	}
901
+
902
+
903
+	/**
904
+	 * @deprecated 4.8.41
905
+	 * @param  $option
906
+	 * @param  $old_value
907
+	 * @param  $value
908
+	 * @return void
909
+	 */
910
+	public function reset_page_for_posts_on_change($option, $old_value, $value)
911
+	{
912
+		EE_Error::doing_it_wrong(
913
+			__METHOD__,
914
+			esc_html__('Usage is deprecated', 'event_espresso'),
915
+			'4.8.41'
916
+		);
917
+	}
918
+
919
+
920
+
921
+	/**
922
+	 * @deprecated 4.9.27
923
+	 * @return void
924
+	 */
925
+	public function get_persistent_admin_notices()
926
+	{
927
+		EE_Error::doing_it_wrong(
928
+			__METHOD__,
929
+			sprintf(
930
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
931
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
932
+			),
933
+			'4.9.27'
934
+		);
935
+	}
936
+
937
+
938
+
939
+	/**
940
+	 * @deprecated 4.9.27
941
+	 * @throws InvalidInterfaceException
942
+	 * @throws InvalidDataTypeException
943
+	 * @throws DomainException
944
+	 */
945
+	public function dismiss_ee_nag_notice_callback()
946
+	{
947
+		EE_Error::doing_it_wrong(
948
+			__METHOD__,
949
+			sprintf(
950
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
951
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
952
+			),
953
+			'4.9.27'
954
+		);
955
+		$this->persistent_admin_notice_manager->dismissNotice();
956
+	}
957
+
958
+
959
+	/**
960
+	 * Callback on load-plugins.php hook for setting up anything hooking into the wp plugins page.
961
+	 * @throws InvalidArgumentException
962
+	 * @throws InvalidDataTypeException
963
+	 * @throws InvalidInterfaceException
964
+	 */
965
+	public function hookIntoWpPluginsPage()
966
+	{
967
+		LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\services\admin\ExitModal');
968
+		LoaderFactory::getLoader()
969
+					 ->getShared('EventEspresso\core\domain\services\admin\PluginUpsells')
970
+					 ->decafUpsells();
971
+	}
972 972
 }
Please login to merge, or discard this patch.
admin_pages/transactions/templates/txn_admin_details_header.template.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,17 +1,17 @@
 block discarded – undo
1 1
 
2
-		<h3 class="txn-navigation-strip"><?php echo $previous_transaction . '&nbsp;'; echo __( 'Transaction # ', 'event_espresso' ) . $txn_nmbr['value']; echo '&nbsp;' . $next_transaction; ?></h3>
3
-		<h2 id="txn-date-h2" class="txn-date-h2"><?php echo $txn_datetime['value'];?></h2>
2
+		<h3 class="txn-navigation-strip"><?php echo $previous_transaction.'&nbsp;'; echo __('Transaction # ', 'event_espresso').$txn_nmbr['value']; echo '&nbsp;'.$next_transaction; ?></h3>
3
+		<h2 id="txn-date-h2" class="txn-date-h2"><?php echo $txn_datetime['value']; ?></h2>
4 4
 		<h2 id="txn-status-h2" class="txn-status-h2">
5
-			<?php echo __( 'Transaction Status: ', 'event_espresso' );?><span id="txn-status" class="<?php echo $txn_status['class'];?>"><?php echo $txn_status['value'];?></span>
5
+			<?php echo __('Transaction Status: ', 'event_espresso'); ?><span id="txn-status" class="<?php echo $txn_status['class']; ?>"><?php echo $txn_status['value']; ?></span>
6 6
 		</h2>
7 7
 
8 8
 	<?php $attributes = $amount_due ? 'class="txn-amount-due-h2"' : 'class="txn-amount-due-h2 hidden"'; ?>
9 9
 		<h2 id="txn-amount-due-h2" <?php echo $attributes; ?>>
10
-			<?php echo __( 'Total Amount Due: ', 'event_espresso' );?><span id="txn-admin-total-amount-due" class="<?php echo $amount_due_class;?>"><?php echo $amount_due;?></span>
10
+			<?php echo __('Total Amount Due: ', 'event_espresso'); ?><span id="txn-admin-total-amount-due" class="<?php echo $amount_due_class; ?>"><?php echo $amount_due; ?></span>
11 11
 		</h2>
12 12
 
13 13
 		<h3 id="txn-selected-method-of-payment-h3" class="txn-selected-method-of-payment-h3">
14
-			<?php echo __( 'Last Method of Payment: ', 'event_espresso' );?><?php echo $method_of_payment_name;?>
14
+			<?php echo __('Last Method of Payment: ', 'event_espresso'); ?><?php echo $method_of_payment_name; ?>
15 15
 		</h3>
16 16
 
17 17
 
Please login to merge, or discard this patch.
core/services/Benchmark.php 2 patches
Indentation   +304 added lines, -304 removed lines patch added patch discarded remove patch
@@ -20,310 +20,310 @@
 block discarded – undo
20 20
 class Benchmark
21 21
 {
22 22
 
23
-    /**
24
-     * array containing the start time for the timers
25
-     */
26
-    private static $start_times;
27
-
28
-    /**
29
-     * array containing all the timer'd times, which can be outputted via show_times()
30
-     */
31
-    private static $times = array();
32
-
33
-    /**
34
-     * @var array
35
-     */
36
-    protected static $memory_usage = array();
37
-
38
-
39
-
40
-    /**
41
-     * whether to benchmark code or not
42
-     */
43
-    public static function doNotRun()
44
-    {
45
-        return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX);
46
-    }
47
-
48
-
49
-
50
-    /**
51
-     * resetTimes
52
-     */
53
-    public static function resetTimes()
54
-    {
55
-        Benchmark::$times = array();
56
-    }
57
-
58
-
59
-
60
-    /**
61
-     * Add Benchmark::startTimer() before a block of code you want to measure the performance of
62
-     *
63
-     * @param null $timer_name
64
-     */
65
-    public static function startTimer($timer_name = null)
66
-    {
67
-        if (Benchmark::doNotRun()) {
68
-            return;
69
-        }
70
-        $timer_name = $timer_name !== '' ? $timer_name : get_called_class();
71
-        Benchmark::$start_times[$timer_name] = microtime(true);
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     * Add Benchmark::stopTimer() after a block of code you want to measure the performance of
78
-     *
79
-     * @param string $timer_name
80
-     */
81
-    public static function stopTimer($timer_name = '')
82
-    {
83
-        if (Benchmark::doNotRun()) {
84
-            return;
85
-        }
86
-        $timer_name = $timer_name !== '' ? $timer_name : get_called_class();
87
-        if (isset(Benchmark::$start_times[$timer_name])) {
88
-            $start_time = Benchmark::$start_times[$timer_name];
89
-            unset(Benchmark::$start_times[$timer_name]);
90
-        } else {
91
-            $start_time = array_pop(Benchmark::$start_times);
92
-        }
93
-        Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8);
94
-    }
95
-
96
-
97
-
98
-    /**
99
-     * Measure the memory usage by PHP so far.
100
-     *
101
-     * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
102
-     * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
103
-     * @param bool    $formatted
104
-     * @return void
105
-     */
106
-    public static function measureMemory($label = 'memory usage', $output_now = false, $formatted = true)
107
-    {
108
-        if (Benchmark::doNotRun()) {
109
-            return;
110
-        }
111
-        $memory_used = Benchmark::convert(memory_get_usage(true));
112
-        Benchmark::$memory_usage[$label] = $memory_used;
113
-        if ($output_now) {
114
-            echo $formatted
115
-                ? "<br>{$label} : {$memory_used}"
116
-                : "\n {$label} : {$memory_used}";
117
-        }
118
-    }
119
-
120
-
121
-
122
-    /**
123
-     * will display the benchmarking results at shutdown
124
-     *
125
-     * @param bool $formatted
126
-     * @return void
127
-     */
128
-    public static function displayResultsAtShutdown($formatted = true)
129
-    {
130
-        add_action(
131
-            'shutdown',
132
-            function () use ($formatted) {
133
-                Benchmark::displayResults(true, $formatted);
134
-            }
135
-        );
136
-    }
137
-
138
-
139
-
140
-    /**
141
-     * will display the benchmarking results at shutdown
142
-     *
143
-     * @param string $filepath
144
-     * @param bool   $formatted
145
-     * @param bool   $append
146
-     * @return void
147
-     */
148
-    public static function writeResultsAtShutdown($filepath = '', $formatted = true, $append = true)
149
-    {
150
-        add_action(
151
-            'shutdown',
152
-            function () use ($filepath, $formatted, $append) {
153
-                Benchmark::writeResultsToFile($filepath, $formatted, $append);
154
-            }
155
-        );
156
-    }
157
-
158
-
159
-
160
-    /**
161
-     * @param bool $formatted
162
-     * @return string
163
-     */
164
-    private static function generateResults($formatted = true)
165
-    {
166
-        if (Benchmark::doNotRun()) {
167
-            return '';
168
-        }
169
-        $output = '';
170
-        if (! empty(Benchmark::$times)) {
171
-            $total = 0;
172
-            $output .= $formatted
173
-                ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />'
174
-                : '';
175
-            foreach (Benchmark::$times as $timer_name => $total_time) {
176
-                $output .= Benchmark::formatTime($timer_name, $total_time, $formatted);
177
-                $output .= $formatted ? '<br />'  : "\n";
178
-                $total += $total_time;
179
-            }
180
-            if($formatted) {
181
-                $output .= '<br />';
182
-                $output .= '<h4>TOTAL TIME</h4>';
183
-                $output .= Benchmark::formatTime('', $total, $formatted);
184
-                $output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />';
185
-                $output .= '<br />';
186
-                $output .= '<h5>Performance scale (from best to worse)</h5>';
187
-                $output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />';
188
-                $output .= '<span style="color:deepskyblue">Like...no way man!</span><br />';
189
-                $output .= '<span style="color:limegreen">Like...groovy!</span><br />';
190
-                $output .= '<span style="color:gold">Ruh Oh</span><br />';
191
-                $output .= '<span style="color:darkorange">Zoinks!</span><br />';
192
-                $output .= '<span style="color:red">Like...HEEELLLP</span><br />';
193
-            }
194
-        }
195
-        if (! empty(Benchmark::$memory_usage)) {
196
-            $output .= $formatted
197
-                ? '<h5>Memory</h5>'
198
-                : "\nMemory";
199
-            foreach (Benchmark::$memory_usage as $label => $memory_usage) {
200
-                $output .= $formatted
201
-                    ? '<br />'
202
-                    : "\n";
203
-                $output .= "{$memory_usage} : {$label}";
204
-            }
205
-        }
206
-        if (empty($output)) {
207
-            return '';
208
-        }
209
-        $output = $formatted
210
-            ? '<div style="border:1px solid #dddddd; background-color:#ffffff;'
211
-              . (is_admin()
212
-                ? ' margin:2em 2em 2em 180px;'
213
-                : ' margin:2em;')
214
-              . ' padding:2em;">'
215
-              . '<h4>BENCHMARKING</h4>'
216
-              . $output
217
-              . '</div>'
218
-            : $output;
219
-        return $output;
220
-    }
221
-
222
-
223
-
224
-    /**
225
-     * @param bool $echo
226
-     * @param bool $formatted
227
-     * @return string
228
-     */
229
-    public static function displayResults($echo = true, $formatted = true)
230
-    {
231
-        $results = Benchmark::generateResults($formatted);
232
-        if ($echo) {
233
-            echo $results;
234
-            $results = '';
235
-        }
236
-        return $results;
237
-    }
238
-
239
-
240
-    /**
241
-     * @param string $filepath
242
-     * @param bool   $formatted
243
-     * @param bool   $append
244
-     * @throws EE_Error
245
-     */
246
-    public static function writeResultsToFile($filepath = '', $formatted = true, $append = true)
247
-    {
248
-        $filepath = ! empty($filepath) && is_readable(dirname($filepath))
249
-            ? $filepath
250
-            : '';
251
-        if( empty($filepath)) {
252
-            $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html';
253
-        }
254
-        EEH_File::ensure_file_exists_and_is_writable($filepath);
255
-        file_put_contents(
256
-            $filepath,
257
-            "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted),
258
-            $append ? FILE_APPEND | LOCK_EX : LOCK_EX
259
-        );
260
-    }
261
-
262
-
263
-
264
-    /**
265
-     * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc)
266
-     *
267
-     * @param int $size
268
-     * @return string
269
-     */
270
-    public static function convert($size)
271
-    {
272
-        $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb');
273
-        return round(
274
-            $size / pow(1024, $i = floor(log($size, 1024))),
275
-            2
276
-        ) . ' ' . $unit[absint($i)];
277
-    }
278
-
279
-
280
-
281
-    /**
282
-     * @param string $timer_name
283
-     * @param float  $total_time
284
-     * @param bool   $formatted
285
-     * @return string
286
-     */
287
-    public static function formatTime($timer_name, $total_time, $formatted = true)
288
-    {
289
-        $total_time *= 1000;
290
-        switch ($total_time) {
291
-            case $total_time > 12500 :
292
-                $color = 'red';
293
-                $bold = 'bold';
294
-                break;
295
-            case $total_time > 2500 :
296
-                $color = 'darkorange';
297
-                $bold = 'bold';
298
-                break;
299
-            case $total_time > 500 :
300
-                $color = 'gold';
301
-                $bold = 'bold';
302
-                break;
303
-            case $total_time > 100 :
304
-                $color = 'limegreen';
305
-                $bold = 'normal';
306
-                break;
307
-            case $total_time > 20 :
308
-                $color = 'deepskyblue';
309
-                $bold = 'normal';
310
-                break;
311
-            default :
312
-                $color = 'mediumpurple';
313
-                $bold = 'normal';
314
-                break;
315
-        }
316
-        return $formatted
317
-            ? '<span style="min-width: 10px; margin:0 1em; color:'
318
-               . $color
319
-               . '; font-weight:'
320
-               . $bold
321
-               . '; font-size:1.2em;">'
322
-               . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT)
323
-               . '</span> '
324
-               . $timer_name
325
-            :  str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT);
326
-    }
23
+	/**
24
+	 * array containing the start time for the timers
25
+	 */
26
+	private static $start_times;
27
+
28
+	/**
29
+	 * array containing all the timer'd times, which can be outputted via show_times()
30
+	 */
31
+	private static $times = array();
32
+
33
+	/**
34
+	 * @var array
35
+	 */
36
+	protected static $memory_usage = array();
37
+
38
+
39
+
40
+	/**
41
+	 * whether to benchmark code or not
42
+	 */
43
+	public static function doNotRun()
44
+	{
45
+		return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX);
46
+	}
47
+
48
+
49
+
50
+	/**
51
+	 * resetTimes
52
+	 */
53
+	public static function resetTimes()
54
+	{
55
+		Benchmark::$times = array();
56
+	}
57
+
58
+
59
+
60
+	/**
61
+	 * Add Benchmark::startTimer() before a block of code you want to measure the performance of
62
+	 *
63
+	 * @param null $timer_name
64
+	 */
65
+	public static function startTimer($timer_name = null)
66
+	{
67
+		if (Benchmark::doNotRun()) {
68
+			return;
69
+		}
70
+		$timer_name = $timer_name !== '' ? $timer_name : get_called_class();
71
+		Benchmark::$start_times[$timer_name] = microtime(true);
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 * Add Benchmark::stopTimer() after a block of code you want to measure the performance of
78
+	 *
79
+	 * @param string $timer_name
80
+	 */
81
+	public static function stopTimer($timer_name = '')
82
+	{
83
+		if (Benchmark::doNotRun()) {
84
+			return;
85
+		}
86
+		$timer_name = $timer_name !== '' ? $timer_name : get_called_class();
87
+		if (isset(Benchmark::$start_times[$timer_name])) {
88
+			$start_time = Benchmark::$start_times[$timer_name];
89
+			unset(Benchmark::$start_times[$timer_name]);
90
+		} else {
91
+			$start_time = array_pop(Benchmark::$start_times);
92
+		}
93
+		Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8);
94
+	}
95
+
96
+
97
+
98
+	/**
99
+	 * Measure the memory usage by PHP so far.
100
+	 *
101
+	 * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
102
+	 * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
103
+	 * @param bool    $formatted
104
+	 * @return void
105
+	 */
106
+	public static function measureMemory($label = 'memory usage', $output_now = false, $formatted = true)
107
+	{
108
+		if (Benchmark::doNotRun()) {
109
+			return;
110
+		}
111
+		$memory_used = Benchmark::convert(memory_get_usage(true));
112
+		Benchmark::$memory_usage[$label] = $memory_used;
113
+		if ($output_now) {
114
+			echo $formatted
115
+				? "<br>{$label} : {$memory_used}"
116
+				: "\n {$label} : {$memory_used}";
117
+		}
118
+	}
119
+
120
+
121
+
122
+	/**
123
+	 * will display the benchmarking results at shutdown
124
+	 *
125
+	 * @param bool $formatted
126
+	 * @return void
127
+	 */
128
+	public static function displayResultsAtShutdown($formatted = true)
129
+	{
130
+		add_action(
131
+			'shutdown',
132
+			function () use ($formatted) {
133
+				Benchmark::displayResults(true, $formatted);
134
+			}
135
+		);
136
+	}
137
+
138
+
139
+
140
+	/**
141
+	 * will display the benchmarking results at shutdown
142
+	 *
143
+	 * @param string $filepath
144
+	 * @param bool   $formatted
145
+	 * @param bool   $append
146
+	 * @return void
147
+	 */
148
+	public static function writeResultsAtShutdown($filepath = '', $formatted = true, $append = true)
149
+	{
150
+		add_action(
151
+			'shutdown',
152
+			function () use ($filepath, $formatted, $append) {
153
+				Benchmark::writeResultsToFile($filepath, $formatted, $append);
154
+			}
155
+		);
156
+	}
157
+
158
+
159
+
160
+	/**
161
+	 * @param bool $formatted
162
+	 * @return string
163
+	 */
164
+	private static function generateResults($formatted = true)
165
+	{
166
+		if (Benchmark::doNotRun()) {
167
+			return '';
168
+		}
169
+		$output = '';
170
+		if (! empty(Benchmark::$times)) {
171
+			$total = 0;
172
+			$output .= $formatted
173
+				? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />'
174
+				: '';
175
+			foreach (Benchmark::$times as $timer_name => $total_time) {
176
+				$output .= Benchmark::formatTime($timer_name, $total_time, $formatted);
177
+				$output .= $formatted ? '<br />'  : "\n";
178
+				$total += $total_time;
179
+			}
180
+			if($formatted) {
181
+				$output .= '<br />';
182
+				$output .= '<h4>TOTAL TIME</h4>';
183
+				$output .= Benchmark::formatTime('', $total, $formatted);
184
+				$output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />';
185
+				$output .= '<br />';
186
+				$output .= '<h5>Performance scale (from best to worse)</h5>';
187
+				$output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />';
188
+				$output .= '<span style="color:deepskyblue">Like...no way man!</span><br />';
189
+				$output .= '<span style="color:limegreen">Like...groovy!</span><br />';
190
+				$output .= '<span style="color:gold">Ruh Oh</span><br />';
191
+				$output .= '<span style="color:darkorange">Zoinks!</span><br />';
192
+				$output .= '<span style="color:red">Like...HEEELLLP</span><br />';
193
+			}
194
+		}
195
+		if (! empty(Benchmark::$memory_usage)) {
196
+			$output .= $formatted
197
+				? '<h5>Memory</h5>'
198
+				: "\nMemory";
199
+			foreach (Benchmark::$memory_usage as $label => $memory_usage) {
200
+				$output .= $formatted
201
+					? '<br />'
202
+					: "\n";
203
+				$output .= "{$memory_usage} : {$label}";
204
+			}
205
+		}
206
+		if (empty($output)) {
207
+			return '';
208
+		}
209
+		$output = $formatted
210
+			? '<div style="border:1px solid #dddddd; background-color:#ffffff;'
211
+			  . (is_admin()
212
+				? ' margin:2em 2em 2em 180px;'
213
+				: ' margin:2em;')
214
+			  . ' padding:2em;">'
215
+			  . '<h4>BENCHMARKING</h4>'
216
+			  . $output
217
+			  . '</div>'
218
+			: $output;
219
+		return $output;
220
+	}
221
+
222
+
223
+
224
+	/**
225
+	 * @param bool $echo
226
+	 * @param bool $formatted
227
+	 * @return string
228
+	 */
229
+	public static function displayResults($echo = true, $formatted = true)
230
+	{
231
+		$results = Benchmark::generateResults($formatted);
232
+		if ($echo) {
233
+			echo $results;
234
+			$results = '';
235
+		}
236
+		return $results;
237
+	}
238
+
239
+
240
+	/**
241
+	 * @param string $filepath
242
+	 * @param bool   $formatted
243
+	 * @param bool   $append
244
+	 * @throws EE_Error
245
+	 */
246
+	public static function writeResultsToFile($filepath = '', $formatted = true, $append = true)
247
+	{
248
+		$filepath = ! empty($filepath) && is_readable(dirname($filepath))
249
+			? $filepath
250
+			: '';
251
+		if( empty($filepath)) {
252
+			$filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html';
253
+		}
254
+		EEH_File::ensure_file_exists_and_is_writable($filepath);
255
+		file_put_contents(
256
+			$filepath,
257
+			"\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted),
258
+			$append ? FILE_APPEND | LOCK_EX : LOCK_EX
259
+		);
260
+	}
261
+
262
+
263
+
264
+	/**
265
+	 * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc)
266
+	 *
267
+	 * @param int $size
268
+	 * @return string
269
+	 */
270
+	public static function convert($size)
271
+	{
272
+		$unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb');
273
+		return round(
274
+			$size / pow(1024, $i = floor(log($size, 1024))),
275
+			2
276
+		) . ' ' . $unit[absint($i)];
277
+	}
278
+
279
+
280
+
281
+	/**
282
+	 * @param string $timer_name
283
+	 * @param float  $total_time
284
+	 * @param bool   $formatted
285
+	 * @return string
286
+	 */
287
+	public static function formatTime($timer_name, $total_time, $formatted = true)
288
+	{
289
+		$total_time *= 1000;
290
+		switch ($total_time) {
291
+			case $total_time > 12500 :
292
+				$color = 'red';
293
+				$bold = 'bold';
294
+				break;
295
+			case $total_time > 2500 :
296
+				$color = 'darkorange';
297
+				$bold = 'bold';
298
+				break;
299
+			case $total_time > 500 :
300
+				$color = 'gold';
301
+				$bold = 'bold';
302
+				break;
303
+			case $total_time > 100 :
304
+				$color = 'limegreen';
305
+				$bold = 'normal';
306
+				break;
307
+			case $total_time > 20 :
308
+				$color = 'deepskyblue';
309
+				$bold = 'normal';
310
+				break;
311
+			default :
312
+				$color = 'mediumpurple';
313
+				$bold = 'normal';
314
+				break;
315
+		}
316
+		return $formatted
317
+			? '<span style="min-width: 10px; margin:0 1em; color:'
318
+			   . $color
319
+			   . '; font-weight:'
320
+			   . $bold
321
+			   . '; font-size:1.2em;">'
322
+			   . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT)
323
+			   . '</span> '
324
+			   . $timer_name
325
+			:  str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT);
326
+	}
327 327
 
328 328
 
329 329
 
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
     {
130 130
         add_action(
131 131
             'shutdown',
132
-            function () use ($formatted) {
132
+            function() use ($formatted) {
133 133
                 Benchmark::displayResults(true, $formatted);
134 134
             }
135 135
         );
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
     {
150 150
         add_action(
151 151
             'shutdown',
152
-            function () use ($filepath, $formatted, $append) {
152
+            function() use ($filepath, $formatted, $append) {
153 153
                 Benchmark::writeResultsToFile($filepath, $formatted, $append);
154 154
             }
155 155
         );
@@ -167,17 +167,17 @@  discard block
 block discarded – undo
167 167
             return '';
168 168
         }
169 169
         $output = '';
170
-        if (! empty(Benchmark::$times)) {
170
+        if ( ! empty(Benchmark::$times)) {
171 171
             $total = 0;
172 172
             $output .= $formatted
173 173
                 ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />'
174 174
                 : '';
175 175
             foreach (Benchmark::$times as $timer_name => $total_time) {
176 176
                 $output .= Benchmark::formatTime($timer_name, $total_time, $formatted);
177
-                $output .= $formatted ? '<br />'  : "\n";
177
+                $output .= $formatted ? '<br />' : "\n";
178 178
                 $total += $total_time;
179 179
             }
180
-            if($formatted) {
180
+            if ($formatted) {
181 181
                 $output .= '<br />';
182 182
                 $output .= '<h4>TOTAL TIME</h4>';
183 183
                 $output .= Benchmark::formatTime('', $total, $formatted);
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
                 $output .= '<span style="color:red">Like...HEEELLLP</span><br />';
193 193
             }
194 194
         }
195
-        if (! empty(Benchmark::$memory_usage)) {
195
+        if ( ! empty(Benchmark::$memory_usage)) {
196 196
             $output .= $formatted
197 197
                 ? '<h5>Memory</h5>'
198 198
                 : "\nMemory";
@@ -248,13 +248,13 @@  discard block
 block discarded – undo
248 248
         $filepath = ! empty($filepath) && is_readable(dirname($filepath))
249 249
             ? $filepath
250 250
             : '';
251
-        if( empty($filepath)) {
252
-            $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html';
251
+        if (empty($filepath)) {
252
+            $filepath = EVENT_ESPRESSO_UPLOAD_DIR.'logs/benchmarking-'.date('Y-m-d').'.html';
253 253
         }
254 254
         EEH_File::ensure_file_exists_and_is_writable($filepath);
255 255
         file_put_contents(
256 256
             $filepath,
257
-            "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted),
257
+            "\n".date('Y-m-d H:i:s').Benchmark::generateResults($formatted),
258 258
             $append ? FILE_APPEND | LOCK_EX : LOCK_EX
259 259
         );
260 260
     }
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
         return round(
274 274
             $size / pow(1024, $i = floor(log($size, 1024))),
275 275
             2
276
-        ) . ' ' . $unit[absint($i)];
276
+        ).' '.$unit[absint($i)];
277 277
     }
278 278
 
279 279
 
Please login to merge, or discard this patch.
core/helpers/EEH_Activation.helper.php 2 patches
Indentation   +1581 added lines, -1581 removed lines patch added patch discarded remove patch
@@ -18,233 +18,233 @@  discard block
 block discarded – undo
18 18
 class EEH_Activation implements ResettableInterface
19 19
 {
20 20
 
21
-    /**
22
-     * constant used to indicate a cron task is no longer in use
23
-     */
24
-    const cron_task_no_longer_in_use = 'no_longer_in_use';
25
-
26
-    /**
27
-     * WP_User->ID
28
-     *
29
-     * @var int
30
-     */
31
-    private static $_default_creator_id;
32
-
33
-    /**
34
-     * indicates whether or not we've already verified core's default data during this request,
35
-     * because after migrations are done, any addons activated while in maintenance mode
36
-     * will want to setup their own default data, and they might hook into core's default data
37
-     * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
38
-     * This prevents doing that for EVERY single addon.
39
-     *
40
-     * @var boolean
41
-     */
42
-    protected static $_initialized_db_content_already_in_this_request = false;
43
-
44
-    /**
45
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
46
-     */
47
-    private static $table_analysis;
48
-
49
-    /**
50
-     * @var \EventEspresso\core\services\database\TableManager $table_manager
51
-     */
52
-    private static $table_manager;
53
-
54
-
55
-    /**
56
-     * @return \EventEspresso\core\services\database\TableAnalysis
57
-     */
58
-    public static function getTableAnalysis()
59
-    {
60
-        if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
61
-            self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
62
-        }
63
-        return self::$table_analysis;
64
-    }
65
-
66
-
67
-    /**
68
-     * @return \EventEspresso\core\services\database\TableManager
69
-     */
70
-    public static function getTableManager()
71
-    {
72
-        if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
73
-            self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
74
-        }
75
-        return self::$table_manager;
76
-    }
77
-
78
-
79
-    /**
80
-     *    _ensure_table_name_has_prefix
81
-     *
82
-     * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
83
-     * @access     public
84
-     * @static
85
-     * @param $table_name
86
-     * @return string
87
-     */
88
-    public static function ensure_table_name_has_prefix($table_name)
89
-    {
90
-        return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
91
-    }
92
-
93
-
94
-    /**
95
-     *    system_initialization
96
-     *    ensures the EE configuration settings are loaded with at least default options set
97
-     *    and that all critical EE pages have been generated with the appropriate shortcodes in place
98
-     *
99
-     * @access public
100
-     * @static
101
-     * @return void
102
-     */
103
-    public static function system_initialization()
104
-    {
105
-        EEH_Activation::reset_and_update_config();
106
-        //which is fired BEFORE activation of plugin anyways
107
-        EEH_Activation::verify_default_pages_exist();
108
-    }
109
-
110
-
111
-    /**
112
-     * Sets the database schema and creates folders. This should
113
-     * be called on plugin activation and reactivation
114
-     *
115
-     * @return boolean success, whether the database and folders are setup properly
116
-     * @throws \EE_Error
117
-     */
118
-    public static function initialize_db_and_folders()
119
-    {
120
-        return EEH_Activation::create_database_tables();
121
-    }
122
-
123
-
124
-    /**
125
-     * assuming we have an up-to-date database schema, this will populate it
126
-     * with default and initial data. This should be called
127
-     * upon activation of a new plugin, reactivation, and at the end
128
-     * of running migration scripts
129
-     *
130
-     * @throws \EE_Error
131
-     */
132
-    public static function initialize_db_content()
133
-    {
134
-        //let's avoid doing all this logic repeatedly, especially when addons are requesting it
135
-        if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
136
-            return;
137
-        }
138
-        EEH_Activation::$_initialized_db_content_already_in_this_request = true;
139
-
140
-        EEH_Activation::initialize_system_questions();
141
-        EEH_Activation::insert_default_status_codes();
142
-        EEH_Activation::generate_default_message_templates();
143
-        EEH_Activation::create_no_ticket_prices_array();
144
-
145
-        EEH_Activation::validate_messages_system();
146
-        EEH_Activation::insert_default_payment_methods();
147
-        //in case we've
148
-        EEH_Activation::remove_cron_tasks();
149
-        EEH_Activation::create_cron_tasks();
150
-        // remove all TXN locks since that is being done via extra meta now
151
-        delete_option('ee_locked_transactions');
152
-        //also, check for CAF default db content
153
-        do_action('AHEE__EEH_Activation__initialize_db_content');
154
-        //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
155
-        //which users really won't care about on initial activation
156
-        EE_Error::overwrite_success();
157
-    }
158
-
159
-
160
-    /**
161
-     * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
162
-     * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
163
-     * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
164
-     * (null)
165
-     *
166
-     * @param string $which_to_include can be 'current' (ones that are currently in use),
167
-     *                                 'old' (only returns ones that should no longer be used),or 'all',
168
-     * @return array
169
-     * @throws \EE_Error
170
-     */
171
-    public static function get_cron_tasks($which_to_include)
172
-    {
173
-        $cron_tasks = apply_filters(
174
-            'FHEE__EEH_Activation__get_cron_tasks',
175
-            array(
176
-                'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
21
+	/**
22
+	 * constant used to indicate a cron task is no longer in use
23
+	 */
24
+	const cron_task_no_longer_in_use = 'no_longer_in_use';
25
+
26
+	/**
27
+	 * WP_User->ID
28
+	 *
29
+	 * @var int
30
+	 */
31
+	private static $_default_creator_id;
32
+
33
+	/**
34
+	 * indicates whether or not we've already verified core's default data during this request,
35
+	 * because after migrations are done, any addons activated while in maintenance mode
36
+	 * will want to setup their own default data, and they might hook into core's default data
37
+	 * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
38
+	 * This prevents doing that for EVERY single addon.
39
+	 *
40
+	 * @var boolean
41
+	 */
42
+	protected static $_initialized_db_content_already_in_this_request = false;
43
+
44
+	/**
45
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
46
+	 */
47
+	private static $table_analysis;
48
+
49
+	/**
50
+	 * @var \EventEspresso\core\services\database\TableManager $table_manager
51
+	 */
52
+	private static $table_manager;
53
+
54
+
55
+	/**
56
+	 * @return \EventEspresso\core\services\database\TableAnalysis
57
+	 */
58
+	public static function getTableAnalysis()
59
+	{
60
+		if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
61
+			self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
62
+		}
63
+		return self::$table_analysis;
64
+	}
65
+
66
+
67
+	/**
68
+	 * @return \EventEspresso\core\services\database\TableManager
69
+	 */
70
+	public static function getTableManager()
71
+	{
72
+		if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
73
+			self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
74
+		}
75
+		return self::$table_manager;
76
+	}
77
+
78
+
79
+	/**
80
+	 *    _ensure_table_name_has_prefix
81
+	 *
82
+	 * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
83
+	 * @access     public
84
+	 * @static
85
+	 * @param $table_name
86
+	 * @return string
87
+	 */
88
+	public static function ensure_table_name_has_prefix($table_name)
89
+	{
90
+		return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
91
+	}
92
+
93
+
94
+	/**
95
+	 *    system_initialization
96
+	 *    ensures the EE configuration settings are loaded with at least default options set
97
+	 *    and that all critical EE pages have been generated with the appropriate shortcodes in place
98
+	 *
99
+	 * @access public
100
+	 * @static
101
+	 * @return void
102
+	 */
103
+	public static function system_initialization()
104
+	{
105
+		EEH_Activation::reset_and_update_config();
106
+		//which is fired BEFORE activation of plugin anyways
107
+		EEH_Activation::verify_default_pages_exist();
108
+	}
109
+
110
+
111
+	/**
112
+	 * Sets the database schema and creates folders. This should
113
+	 * be called on plugin activation and reactivation
114
+	 *
115
+	 * @return boolean success, whether the database and folders are setup properly
116
+	 * @throws \EE_Error
117
+	 */
118
+	public static function initialize_db_and_folders()
119
+	{
120
+		return EEH_Activation::create_database_tables();
121
+	}
122
+
123
+
124
+	/**
125
+	 * assuming we have an up-to-date database schema, this will populate it
126
+	 * with default and initial data. This should be called
127
+	 * upon activation of a new plugin, reactivation, and at the end
128
+	 * of running migration scripts
129
+	 *
130
+	 * @throws \EE_Error
131
+	 */
132
+	public static function initialize_db_content()
133
+	{
134
+		//let's avoid doing all this logic repeatedly, especially when addons are requesting it
135
+		if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
136
+			return;
137
+		}
138
+		EEH_Activation::$_initialized_db_content_already_in_this_request = true;
139
+
140
+		EEH_Activation::initialize_system_questions();
141
+		EEH_Activation::insert_default_status_codes();
142
+		EEH_Activation::generate_default_message_templates();
143
+		EEH_Activation::create_no_ticket_prices_array();
144
+
145
+		EEH_Activation::validate_messages_system();
146
+		EEH_Activation::insert_default_payment_methods();
147
+		//in case we've
148
+		EEH_Activation::remove_cron_tasks();
149
+		EEH_Activation::create_cron_tasks();
150
+		// remove all TXN locks since that is being done via extra meta now
151
+		delete_option('ee_locked_transactions');
152
+		//also, check for CAF default db content
153
+		do_action('AHEE__EEH_Activation__initialize_db_content');
154
+		//also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
155
+		//which users really won't care about on initial activation
156
+		EE_Error::overwrite_success();
157
+	}
158
+
159
+
160
+	/**
161
+	 * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
162
+	 * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
163
+	 * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
164
+	 * (null)
165
+	 *
166
+	 * @param string $which_to_include can be 'current' (ones that are currently in use),
167
+	 *                                 'old' (only returns ones that should no longer be used),or 'all',
168
+	 * @return array
169
+	 * @throws \EE_Error
170
+	 */
171
+	public static function get_cron_tasks($which_to_include)
172
+	{
173
+		$cron_tasks = apply_filters(
174
+			'FHEE__EEH_Activation__get_cron_tasks',
175
+			array(
176
+				'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
177 177
 //				'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use
178
-                'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
179
-                //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
180
-                'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
181
-            )
182
-        );
183
-        if ($which_to_include === 'old') {
184
-            $cron_tasks = array_filter(
185
-                $cron_tasks,
186
-                function ($value) {
187
-                    return $value === EEH_Activation::cron_task_no_longer_in_use;
188
-                }
189
-            );
190
-        } elseif ($which_to_include === 'current') {
191
-            $cron_tasks = array_filter($cron_tasks);
192
-        } elseif (WP_DEBUG && $which_to_include !== 'all') {
193
-            throw new EE_Error(
194
-                sprintf(
195
-                    __(
196
-                        'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
197
-                        'event_espresso'
198
-                    ),
199
-                    $which_to_include
200
-                )
201
-            );
202
-        }
203
-        return $cron_tasks;
204
-    }
205
-
206
-
207
-    /**
208
-     * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
209
-     *
210
-     * @throws \EE_Error
211
-     */
212
-    public static function create_cron_tasks()
213
-    {
214
-
215
-        foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
216
-            if (! wp_next_scheduled($hook_name)) {
217
-                /**
218
-                 * This allows client code to define the initial start timestamp for this schedule.
219
-                 */
220
-                if (is_array($frequency)
221
-                    && count($frequency) === 2
222
-                    && isset($frequency[0], $frequency[1])
223
-                ) {
224
-                    $start_timestamp = $frequency[0];
225
-                    $frequency = $frequency[1];
226
-                } else {
227
-                    $start_timestamp = time();
228
-                }
229
-                wp_schedule_event($start_timestamp, $frequency, $hook_name);
230
-            }
231
-        }
232
-
233
-    }
234
-
235
-
236
-    /**
237
-     * Remove the currently-existing and now-removed cron tasks.
238
-     *
239
-     * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
240
-     * @throws \EE_Error
241
-     */
242
-    public static function remove_cron_tasks($remove_all = true)
243
-    {
244
-        $cron_tasks_to_remove = $remove_all ? 'all' : 'old';
245
-        $crons                = _get_cron_array();
246
-        $crons                = is_array($crons) ? $crons : array();
247
-        /* reminder of what $crons look like:
178
+				'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
179
+				//there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
180
+				'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
181
+			)
182
+		);
183
+		if ($which_to_include === 'old') {
184
+			$cron_tasks = array_filter(
185
+				$cron_tasks,
186
+				function ($value) {
187
+					return $value === EEH_Activation::cron_task_no_longer_in_use;
188
+				}
189
+			);
190
+		} elseif ($which_to_include === 'current') {
191
+			$cron_tasks = array_filter($cron_tasks);
192
+		} elseif (WP_DEBUG && $which_to_include !== 'all') {
193
+			throw new EE_Error(
194
+				sprintf(
195
+					__(
196
+						'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
197
+						'event_espresso'
198
+					),
199
+					$which_to_include
200
+				)
201
+			);
202
+		}
203
+		return $cron_tasks;
204
+	}
205
+
206
+
207
+	/**
208
+	 * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
209
+	 *
210
+	 * @throws \EE_Error
211
+	 */
212
+	public static function create_cron_tasks()
213
+	{
214
+
215
+		foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
216
+			if (! wp_next_scheduled($hook_name)) {
217
+				/**
218
+				 * This allows client code to define the initial start timestamp for this schedule.
219
+				 */
220
+				if (is_array($frequency)
221
+					&& count($frequency) === 2
222
+					&& isset($frequency[0], $frequency[1])
223
+				) {
224
+					$start_timestamp = $frequency[0];
225
+					$frequency = $frequency[1];
226
+				} else {
227
+					$start_timestamp = time();
228
+				}
229
+				wp_schedule_event($start_timestamp, $frequency, $hook_name);
230
+			}
231
+		}
232
+
233
+	}
234
+
235
+
236
+	/**
237
+	 * Remove the currently-existing and now-removed cron tasks.
238
+	 *
239
+	 * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
240
+	 * @throws \EE_Error
241
+	 */
242
+	public static function remove_cron_tasks($remove_all = true)
243
+	{
244
+		$cron_tasks_to_remove = $remove_all ? 'all' : 'old';
245
+		$crons                = _get_cron_array();
246
+		$crons                = is_array($crons) ? $crons : array();
247
+		/* reminder of what $crons look like:
248 248
          * Top-level keys are timestamps, and their values are arrays.
249 249
          * The 2nd level arrays have keys with each of the cron task hook names to run at that time
250 250
          * and their values are arrays.
@@ -261,911 +261,911 @@  discard block
 block discarded – undo
261 261
          *					...
262 262
          *      ...
263 263
          */
264
-        $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
265
-        foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
266
-            if (is_array($hooks_to_fire_at_time)) {
267
-                foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
268
-                    if (isset($ee_cron_tasks_to_remove[$hook_name])
269
-                        && is_array($ee_cron_tasks_to_remove[$hook_name])
270
-                    ) {
271
-                        unset($crons[$timestamp][$hook_name]);
272
-                    }
273
-                }
274
-                //also take care of any empty cron timestamps.
275
-                if (empty($hooks_to_fire_at_time)) {
276
-                    unset($crons[$timestamp]);
277
-                }
278
-            }
279
-        }
280
-        _set_cron_array($crons);
281
-    }
282
-
283
-
284
-    /**
285
-     *    CPT_initialization
286
-     *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
287
-     *
288
-     * @access public
289
-     * @static
290
-     * @return void
291
-     */
292
-    public static function CPT_initialization()
293
-    {
294
-        // register Custom Post Types
295
-        EE_Registry::instance()->load_core('Register_CPTs');
296
-        flush_rewrite_rules();
297
-    }
298
-
299
-
300
-
301
-    /**
302
-     *    reset_and_update_config
303
-     * The following code was moved over from EE_Config so that it will no longer run on every request.
304
-     * If there is old calendar config data saved, then it will get converted on activation.
305
-     * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
306
-     *
307
-     * @access public
308
-     * @static
309
-     * @return void
310
-     */
311
-    public static function reset_and_update_config()
312
-    {
313
-        do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
314
-        add_filter(
315
-            'FHEE__EE_Config___load_core_config__config_settings',
316
-            array('EEH_Activation', 'migrate_old_config_data'),
317
-            10,
318
-            3
319
-        );
320
-        //EE_Config::reset();
321
-        if (! EE_Config::logging_enabled()) {
322
-            delete_option(EE_Config::LOG_NAME);
323
-        }
324
-    }
325
-
326
-
327
-    /**
328
-     *    load_calendar_config
329
-     *
330
-     * @access    public
331
-     * @return    void
332
-     */
333
-    public static function load_calendar_config()
334
-    {
335
-        // grab array of all plugin folders and loop thru it
336
-        $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
337
-        if (empty($plugins)) {
338
-            return;
339
-        }
340
-        foreach ($plugins as $plugin_path) {
341
-            // grab plugin folder name from path
342
-            $plugin = basename($plugin_path);
343
-            // drill down to Espresso plugins
344
-            // then to calendar related plugins
345
-            if (
346
-                strpos($plugin, 'espresso') !== false
347
-                || strpos($plugin, 'Espresso') !== false
348
-                || strpos($plugin, 'ee4') !== false
349
-                || strpos($plugin, 'EE4') !== false
350
-                || strpos($plugin, 'calendar') !== false
351
-            ) {
352
-                // this is what we are looking for
353
-                $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
354
-                // does it exist in this folder ?
355
-                if (is_readable($calendar_config)) {
356
-                    // YEAH! let's load it
357
-                    require_once($calendar_config);
358
-                }
359
-            }
360
-        }
361
-    }
362
-
363
-
364
-
365
-    /**
366
-     *    _migrate_old_config_data
367
-     *
368
-     * @access    public
369
-     * @param array|stdClass $settings
370
-     * @param string         $config
371
-     * @param \EE_Config     $EE_Config
372
-     * @return \stdClass
373
-     */
374
-    public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
375
-    {
376
-        $convert_from_array = array('addons');
377
-        // in case old settings were saved as an array
378
-        if (is_array($settings) && in_array($config, $convert_from_array)) {
379
-            // convert existing settings to an object
380
-            $config_array = $settings;
381
-            $settings = new stdClass();
382
-            foreach ($config_array as $key => $value) {
383
-                if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
384
-                    $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
385
-                } else {
386
-                    $settings->{$key} = $value;
387
-                }
388
-            }
389
-            add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
390
-        }
391
-        return $settings;
392
-    }
393
-
394
-
395
-    /**
396
-     * deactivate_event_espresso
397
-     *
398
-     * @access public
399
-     * @static
400
-     * @return void
401
-     */
402
-    public static function deactivate_event_espresso()
403
-    {
404
-        // check permissions
405
-        if (current_user_can('activate_plugins')) {
406
-            deactivate_plugins(EE_PLUGIN_BASENAME, true);
407
-        }
408
-    }
409
-
410
-
411
-
412
-    /**
413
-     * verify_default_pages_exist
414
-     *
415
-     * @access public
416
-     * @static
417
-     * @return void
418
-     * @throws InvalidDataTypeException
419
-     */
420
-    public static function verify_default_pages_exist()
421
-    {
422
-        $critical_page_problem = false;
423
-        $critical_pages = array(
424
-            array(
425
-                'id'   => 'reg_page_id',
426
-                'name' => __('Registration Checkout', 'event_espresso'),
427
-                'post' => null,
428
-                'code' => 'ESPRESSO_CHECKOUT',
429
-            ),
430
-            array(
431
-                'id'   => 'txn_page_id',
432
-                'name' => __('Transactions', 'event_espresso'),
433
-                'post' => null,
434
-                'code' => 'ESPRESSO_TXN_PAGE',
435
-            ),
436
-            array(
437
-                'id'   => 'thank_you_page_id',
438
-                'name' => __('Thank You', 'event_espresso'),
439
-                'post' => null,
440
-                'code' => 'ESPRESSO_THANK_YOU',
441
-            ),
442
-            array(
443
-                'id'   => 'cancel_page_id',
444
-                'name' => __('Registration Cancelled', 'event_espresso'),
445
-                'post' => null,
446
-                'code' => 'ESPRESSO_CANCELLED',
447
-            ),
448
-        );
449
-        $EE_Core_Config = EE_Registry::instance()->CFG->core;
450
-        foreach ($critical_pages as $critical_page) {
451
-            // is critical page ID set in config ?
452
-            if ($EE_Core_Config->{$critical_page['id']} !== false) {
453
-                // attempt to find post by ID
454
-                $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
455
-            }
456
-            // no dice?
457
-            if ($critical_page['post'] === null) {
458
-                // attempt to find post by title
459
-                $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
460
-                // still nothing?
461
-                if ($critical_page['post'] === null) {
462
-                    $critical_page = EEH_Activation::create_critical_page($critical_page);
463
-                    // REALLY? Still nothing ??!?!?
464
-                    if ($critical_page['post'] === null) {
465
-                        $msg = __(
466
-                            'The Event Espresso critical page configuration settings could not be updated.',
467
-                            'event_espresso'
468
-                        );
469
-                        EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
470
-                        break;
471
-                    }
472
-                }
473
-            }
474
-            // check that Post ID matches critical page ID in config
475
-            if (
476
-                isset($critical_page['post']->ID)
477
-                && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
478
-            ) {
479
-                //update Config with post ID
480
-                $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
481
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
482
-                    $msg = __(
483
-                        'The Event Espresso critical page configuration settings could not be updated.',
484
-                        'event_espresso'
485
-                    );
486
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
487
-                }
488
-            }
489
-            $critical_page_problem =
490
-                ! isset($critical_page['post']->post_status)
491
-                || $critical_page['post']->post_status !== 'publish'
492
-                || strpos($critical_page['post']->post_content, $critical_page['code']) === false
493
-                    ? true
494
-                    : $critical_page_problem;
495
-        }
496
-        if ($critical_page_problem) {
497
-            new PersistentAdminNotice(
498
-                'critical_page_problem',
499
-                sprintf(
500
-                    esc_html__(
501
-                        'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
502
-                        'event_espresso'
503
-                    ),
504
-                    '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
505
-                    . __('Event Espresso Critical Pages Settings', 'event_espresso')
506
-                    . '</a>'
507
-                )
508
-            );
509
-        }
510
-        if (EE_Error::has_notices()) {
511
-            EE_Error::get_notices(false, true, true);
512
-        }
513
-    }
514
-
515
-
516
-
517
-    /**
518
-     * Returns the first post which uses the specified shortcode
519
-     *
520
-     * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
521
-     *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
522
-     *                             "[ESPRESSO_THANK_YOU"
523
-     *                             (we don't search for the closing shortcode bracket because they might have added
524
-     *                             parameter to the shortcode
525
-     * @return WP_Post or NULl
526
-     */
527
-    public static function get_page_by_ee_shortcode($ee_shortcode)
528
-    {
529
-        global $wpdb;
530
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
531
-        $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
532
-        if ($post_id) {
533
-            return get_post($post_id);
534
-        } else {
535
-            return null;
536
-        }
537
-    }
538
-
539
-
540
-    /**
541
-     *    This function generates a post for critical espresso pages
542
-     *
543
-     * @access public
544
-     * @static
545
-     * @param array $critical_page
546
-     * @return array
547
-     */
548
-    public static function create_critical_page($critical_page)
549
-    {
550
-
551
-        $post_args = array(
552
-            'post_title'     => $critical_page['name'],
553
-            'post_status'    => 'publish',
554
-            'post_type'      => 'page',
555
-            'comment_status' => 'closed',
556
-            'post_content'   => '[' . $critical_page['code'] . ']',
557
-        );
558
-
559
-        $post_id = wp_insert_post($post_args);
560
-        if (! $post_id) {
561
-            $msg = sprintf(
562
-                __('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
563
-                $critical_page['name']
564
-            );
565
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
566
-            return $critical_page;
567
-        }
568
-        // get newly created post's details
569
-        if (! $critical_page['post'] = get_post($post_id)) {
570
-            $msg = sprintf(
571
-                __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
572
-                $critical_page['name']
573
-            );
574
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
575
-        }
576
-
577
-        return $critical_page;
578
-
579
-    }
580
-
581
-
582
-
583
-
584
-    /**
585
-     * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
586
-     * The role being used to check is filterable.
587
-     *
588
-     * @since  4.6.0
589
-     * @global WPDB $wpdb
590
-     * @return mixed null|int WP_user ID or NULL
591
-     */
592
-    public static function get_default_creator_id()
593
-    {
594
-        global $wpdb;
595
-        if ( ! empty(self::$_default_creator_id)) {
596
-            return self::$_default_creator_id;
597
-        }/**/
598
-        $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
599
-        //let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
600
-        $pre_filtered_id = apply_filters(
601
-            'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
602
-            false,
603
-            $role_to_check
604
-        );
605
-        if ($pre_filtered_id !== false) {
606
-            return (int)$pre_filtered_id;
607
-        }
608
-        $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
609
-        $query = $wpdb->prepare(
610
-            "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
611
-            '%' . $role_to_check . '%'
612
-        );
613
-        $user_id = $wpdb->get_var($query);
614
-        $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
615
-        if ($user_id && (int)$user_id) {
616
-            self::$_default_creator_id = (int)$user_id;
617
-            return self::$_default_creator_id;
618
-        } else {
619
-            return null;
620
-        }
621
-    }
622
-
623
-
624
-
625
-    /**
626
-     * used by EE and EE addons during plugin activation to create tables.
627
-     * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
628
-     * but includes extra logic regarding activations.
629
-     *
630
-     * @access public
631
-     * @static
632
-     * @param string  $table_name              without the $wpdb->prefix
633
-     * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
634
-     *                                         table query)
635
-     * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
636
-     * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
637
-     *                                         and new once this function is done (ie, you really do want to CREATE a
638
-     *                                         table, and expect it to be empty once you're done) leave as FALSE when
639
-     *                                         you just want to verify the table exists and matches this definition
640
-     *                                         (and if it HAS data in it you want to leave it be)
641
-     * @return void
642
-     * @throws EE_Error if there are database errors
643
-     */
644
-    public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
645
-    {
646
-        if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
647
-            return;
648
-        }
649
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
650
-        if ( ! function_exists('dbDelta')) {
651
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
652
-        }
653
-        $tableAnalysis = \EEH_Activation::getTableAnalysis();
654
-        $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
655
-        // do we need to first delete an existing version of this table ?
656
-        if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
657
-            // ok, delete the table... but ONLY if it's empty
658
-            $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
659
-            // table is NOT empty, are you SURE you want to delete this table ???
660
-            if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
661
-                \EEH_Activation::getTableManager()->dropTable($wp_table_name);
662
-            } else if ( ! $deleted_safely) {
663
-                // so we should be more cautious rather than just dropping tables so easily
664
-                error_log(
665
-                    sprintf(
666
-                        __(
667
-                            'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
668
-                            'event_espresso'
669
-                        ),
670
-                        $wp_table_name,
671
-                        '<br/>',
672
-                        'espresso_db_update'
673
-                    )
674
-                );
675
-            }
676
-        }
677
-        $engine = str_replace('ENGINE=', '', $engine);
678
-        \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
679
-    }
680
-
681
-
682
-
683
-    /**
684
-     *    add_column_if_it_doesn't_exist
685
-     *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
686
-     *
687
-     * @access     public
688
-     * @static
689
-     * @deprecated instead use TableManager::addColumn()
690
-     * @param string $table_name  (without "wp_", eg "esp_attendee"
691
-     * @param string $column_name
692
-     * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
693
-     *                            'VARCHAR(10)'
694
-     * @return bool|int
695
-     */
696
-    public static function add_column_if_it_doesnt_exist(
697
-        $table_name,
698
-        $column_name,
699
-        $column_info = 'INT UNSIGNED NOT NULL'
700
-    ) {
701
-        return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
702
-    }
703
-
704
-
705
-    /**
706
-     * get_fields_on_table
707
-     * Gets all the fields on the database table.
708
-     *
709
-     * @access     public
710
-     * @deprecated instead use TableManager::getTableColumns()
711
-     * @static
712
-     * @param string $table_name , without prefixed $wpdb->prefix
713
-     * @return array of database column names
714
-     */
715
-    public static function get_fields_on_table($table_name = null)
716
-    {
717
-        return \EEH_Activation::getTableManager()->getTableColumns($table_name);
718
-    }
719
-
720
-
721
-    /**
722
-     * db_table_is_empty
723
-     *
724
-     * @access     public\
725
-     * @deprecated instead use TableAnalysis::tableIsEmpty()
726
-     * @static
727
-     * @param string $table_name
728
-     * @return bool
729
-     */
730
-    public static function db_table_is_empty($table_name)
731
-    {
732
-        return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
733
-    }
734
-
735
-
736
-    /**
737
-     * delete_db_table_if_empty
738
-     *
739
-     * @access public
740
-     * @static
741
-     * @param string $table_name
742
-     * @return bool | int
743
-     */
744
-    public static function delete_db_table_if_empty($table_name)
745
-    {
746
-        if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
747
-            return \EEH_Activation::getTableManager()->dropTable($table_name);
748
-        }
749
-        return false;
750
-    }
751
-
752
-
753
-    /**
754
-     * delete_unused_db_table
755
-     *
756
-     * @access     public
757
-     * @static
758
-     * @deprecated instead use TableManager::dropTable()
759
-     * @param string $table_name
760
-     * @return bool | int
761
-     */
762
-    public static function delete_unused_db_table($table_name)
763
-    {
764
-        return \EEH_Activation::getTableManager()->dropTable($table_name);
765
-    }
766
-
767
-
768
-    /**
769
-     * drop_index
770
-     *
771
-     * @access     public
772
-     * @static
773
-     * @deprecated instead use TableManager::dropIndex()
774
-     * @param string $table_name
775
-     * @param string $index_name
776
-     * @return bool | int
777
-     */
778
-    public static function drop_index($table_name, $index_name)
779
-    {
780
-        return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
781
-    }
782
-
783
-
784
-
785
-    /**
786
-     * create_database_tables
787
-     *
788
-     * @access public
789
-     * @static
790
-     * @throws EE_Error
791
-     * @return boolean success (whether database is setup properly or not)
792
-     */
793
-    public static function create_database_tables()
794
-    {
795
-        EE_Registry::instance()->load_core('Data_Migration_Manager');
796
-        //find the migration script that sets the database to be compatible with the code
797
-        $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
798
-        if ($dms_name) {
799
-            $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
800
-            $current_data_migration_script->set_migrating(false);
801
-            $current_data_migration_script->schema_changes_before_migration();
802
-            $current_data_migration_script->schema_changes_after_migration();
803
-            if ($current_data_migration_script->get_errors()) {
804
-                if (WP_DEBUG) {
805
-                    foreach ($current_data_migration_script->get_errors() as $error) {
806
-                        EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
807
-                    }
808
-                } else {
809
-                    EE_Error::add_error(
810
-                        __(
811
-                            'There were errors creating the Event Espresso database tables and Event Espresso has been 
264
+		$ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
265
+		foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
266
+			if (is_array($hooks_to_fire_at_time)) {
267
+				foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
268
+					if (isset($ee_cron_tasks_to_remove[$hook_name])
269
+						&& is_array($ee_cron_tasks_to_remove[$hook_name])
270
+					) {
271
+						unset($crons[$timestamp][$hook_name]);
272
+					}
273
+				}
274
+				//also take care of any empty cron timestamps.
275
+				if (empty($hooks_to_fire_at_time)) {
276
+					unset($crons[$timestamp]);
277
+				}
278
+			}
279
+		}
280
+		_set_cron_array($crons);
281
+	}
282
+
283
+
284
+	/**
285
+	 *    CPT_initialization
286
+	 *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
287
+	 *
288
+	 * @access public
289
+	 * @static
290
+	 * @return void
291
+	 */
292
+	public static function CPT_initialization()
293
+	{
294
+		// register Custom Post Types
295
+		EE_Registry::instance()->load_core('Register_CPTs');
296
+		flush_rewrite_rules();
297
+	}
298
+
299
+
300
+
301
+	/**
302
+	 *    reset_and_update_config
303
+	 * The following code was moved over from EE_Config so that it will no longer run on every request.
304
+	 * If there is old calendar config data saved, then it will get converted on activation.
305
+	 * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
306
+	 *
307
+	 * @access public
308
+	 * @static
309
+	 * @return void
310
+	 */
311
+	public static function reset_and_update_config()
312
+	{
313
+		do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
314
+		add_filter(
315
+			'FHEE__EE_Config___load_core_config__config_settings',
316
+			array('EEH_Activation', 'migrate_old_config_data'),
317
+			10,
318
+			3
319
+		);
320
+		//EE_Config::reset();
321
+		if (! EE_Config::logging_enabled()) {
322
+			delete_option(EE_Config::LOG_NAME);
323
+		}
324
+	}
325
+
326
+
327
+	/**
328
+	 *    load_calendar_config
329
+	 *
330
+	 * @access    public
331
+	 * @return    void
332
+	 */
333
+	public static function load_calendar_config()
334
+	{
335
+		// grab array of all plugin folders and loop thru it
336
+		$plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
337
+		if (empty($plugins)) {
338
+			return;
339
+		}
340
+		foreach ($plugins as $plugin_path) {
341
+			// grab plugin folder name from path
342
+			$plugin = basename($plugin_path);
343
+			// drill down to Espresso plugins
344
+			// then to calendar related plugins
345
+			if (
346
+				strpos($plugin, 'espresso') !== false
347
+				|| strpos($plugin, 'Espresso') !== false
348
+				|| strpos($plugin, 'ee4') !== false
349
+				|| strpos($plugin, 'EE4') !== false
350
+				|| strpos($plugin, 'calendar') !== false
351
+			) {
352
+				// this is what we are looking for
353
+				$calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
354
+				// does it exist in this folder ?
355
+				if (is_readable($calendar_config)) {
356
+					// YEAH! let's load it
357
+					require_once($calendar_config);
358
+				}
359
+			}
360
+		}
361
+	}
362
+
363
+
364
+
365
+	/**
366
+	 *    _migrate_old_config_data
367
+	 *
368
+	 * @access    public
369
+	 * @param array|stdClass $settings
370
+	 * @param string         $config
371
+	 * @param \EE_Config     $EE_Config
372
+	 * @return \stdClass
373
+	 */
374
+	public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
375
+	{
376
+		$convert_from_array = array('addons');
377
+		// in case old settings were saved as an array
378
+		if (is_array($settings) && in_array($config, $convert_from_array)) {
379
+			// convert existing settings to an object
380
+			$config_array = $settings;
381
+			$settings = new stdClass();
382
+			foreach ($config_array as $key => $value) {
383
+				if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
384
+					$EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
385
+				} else {
386
+					$settings->{$key} = $value;
387
+				}
388
+			}
389
+			add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
390
+		}
391
+		return $settings;
392
+	}
393
+
394
+
395
+	/**
396
+	 * deactivate_event_espresso
397
+	 *
398
+	 * @access public
399
+	 * @static
400
+	 * @return void
401
+	 */
402
+	public static function deactivate_event_espresso()
403
+	{
404
+		// check permissions
405
+		if (current_user_can('activate_plugins')) {
406
+			deactivate_plugins(EE_PLUGIN_BASENAME, true);
407
+		}
408
+	}
409
+
410
+
411
+
412
+	/**
413
+	 * verify_default_pages_exist
414
+	 *
415
+	 * @access public
416
+	 * @static
417
+	 * @return void
418
+	 * @throws InvalidDataTypeException
419
+	 */
420
+	public static function verify_default_pages_exist()
421
+	{
422
+		$critical_page_problem = false;
423
+		$critical_pages = array(
424
+			array(
425
+				'id'   => 'reg_page_id',
426
+				'name' => __('Registration Checkout', 'event_espresso'),
427
+				'post' => null,
428
+				'code' => 'ESPRESSO_CHECKOUT',
429
+			),
430
+			array(
431
+				'id'   => 'txn_page_id',
432
+				'name' => __('Transactions', 'event_espresso'),
433
+				'post' => null,
434
+				'code' => 'ESPRESSO_TXN_PAGE',
435
+			),
436
+			array(
437
+				'id'   => 'thank_you_page_id',
438
+				'name' => __('Thank You', 'event_espresso'),
439
+				'post' => null,
440
+				'code' => 'ESPRESSO_THANK_YOU',
441
+			),
442
+			array(
443
+				'id'   => 'cancel_page_id',
444
+				'name' => __('Registration Cancelled', 'event_espresso'),
445
+				'post' => null,
446
+				'code' => 'ESPRESSO_CANCELLED',
447
+			),
448
+		);
449
+		$EE_Core_Config = EE_Registry::instance()->CFG->core;
450
+		foreach ($critical_pages as $critical_page) {
451
+			// is critical page ID set in config ?
452
+			if ($EE_Core_Config->{$critical_page['id']} !== false) {
453
+				// attempt to find post by ID
454
+				$critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
455
+			}
456
+			// no dice?
457
+			if ($critical_page['post'] === null) {
458
+				// attempt to find post by title
459
+				$critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
460
+				// still nothing?
461
+				if ($critical_page['post'] === null) {
462
+					$critical_page = EEH_Activation::create_critical_page($critical_page);
463
+					// REALLY? Still nothing ??!?!?
464
+					if ($critical_page['post'] === null) {
465
+						$msg = __(
466
+							'The Event Espresso critical page configuration settings could not be updated.',
467
+							'event_espresso'
468
+						);
469
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
470
+						break;
471
+					}
472
+				}
473
+			}
474
+			// check that Post ID matches critical page ID in config
475
+			if (
476
+				isset($critical_page['post']->ID)
477
+				&& $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
478
+			) {
479
+				//update Config with post ID
480
+				$EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
481
+				if (! EE_Config::instance()->update_espresso_config(false, false)) {
482
+					$msg = __(
483
+						'The Event Espresso critical page configuration settings could not be updated.',
484
+						'event_espresso'
485
+					);
486
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
487
+				}
488
+			}
489
+			$critical_page_problem =
490
+				! isset($critical_page['post']->post_status)
491
+				|| $critical_page['post']->post_status !== 'publish'
492
+				|| strpos($critical_page['post']->post_content, $critical_page['code']) === false
493
+					? true
494
+					: $critical_page_problem;
495
+		}
496
+		if ($critical_page_problem) {
497
+			new PersistentAdminNotice(
498
+				'critical_page_problem',
499
+				sprintf(
500
+					esc_html__(
501
+						'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
502
+						'event_espresso'
503
+					),
504
+					'<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
505
+					. __('Event Espresso Critical Pages Settings', 'event_espresso')
506
+					. '</a>'
507
+				)
508
+			);
509
+		}
510
+		if (EE_Error::has_notices()) {
511
+			EE_Error::get_notices(false, true, true);
512
+		}
513
+	}
514
+
515
+
516
+
517
+	/**
518
+	 * Returns the first post which uses the specified shortcode
519
+	 *
520
+	 * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
521
+	 *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
522
+	 *                             "[ESPRESSO_THANK_YOU"
523
+	 *                             (we don't search for the closing shortcode bracket because they might have added
524
+	 *                             parameter to the shortcode
525
+	 * @return WP_Post or NULl
526
+	 */
527
+	public static function get_page_by_ee_shortcode($ee_shortcode)
528
+	{
529
+		global $wpdb;
530
+		$shortcode_and_opening_bracket = '[' . $ee_shortcode;
531
+		$post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
532
+		if ($post_id) {
533
+			return get_post($post_id);
534
+		} else {
535
+			return null;
536
+		}
537
+	}
538
+
539
+
540
+	/**
541
+	 *    This function generates a post for critical espresso pages
542
+	 *
543
+	 * @access public
544
+	 * @static
545
+	 * @param array $critical_page
546
+	 * @return array
547
+	 */
548
+	public static function create_critical_page($critical_page)
549
+	{
550
+
551
+		$post_args = array(
552
+			'post_title'     => $critical_page['name'],
553
+			'post_status'    => 'publish',
554
+			'post_type'      => 'page',
555
+			'comment_status' => 'closed',
556
+			'post_content'   => '[' . $critical_page['code'] . ']',
557
+		);
558
+
559
+		$post_id = wp_insert_post($post_args);
560
+		if (! $post_id) {
561
+			$msg = sprintf(
562
+				__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
563
+				$critical_page['name']
564
+			);
565
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
566
+			return $critical_page;
567
+		}
568
+		// get newly created post's details
569
+		if (! $critical_page['post'] = get_post($post_id)) {
570
+			$msg = sprintf(
571
+				__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
572
+				$critical_page['name']
573
+			);
574
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
575
+		}
576
+
577
+		return $critical_page;
578
+
579
+	}
580
+
581
+
582
+
583
+
584
+	/**
585
+	 * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
586
+	 * The role being used to check is filterable.
587
+	 *
588
+	 * @since  4.6.0
589
+	 * @global WPDB $wpdb
590
+	 * @return mixed null|int WP_user ID or NULL
591
+	 */
592
+	public static function get_default_creator_id()
593
+	{
594
+		global $wpdb;
595
+		if ( ! empty(self::$_default_creator_id)) {
596
+			return self::$_default_creator_id;
597
+		}/**/
598
+		$role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
599
+		//let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
600
+		$pre_filtered_id = apply_filters(
601
+			'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
602
+			false,
603
+			$role_to_check
604
+		);
605
+		if ($pre_filtered_id !== false) {
606
+			return (int)$pre_filtered_id;
607
+		}
608
+		$capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
609
+		$query = $wpdb->prepare(
610
+			"SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
611
+			'%' . $role_to_check . '%'
612
+		);
613
+		$user_id = $wpdb->get_var($query);
614
+		$user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
615
+		if ($user_id && (int)$user_id) {
616
+			self::$_default_creator_id = (int)$user_id;
617
+			return self::$_default_creator_id;
618
+		} else {
619
+			return null;
620
+		}
621
+	}
622
+
623
+
624
+
625
+	/**
626
+	 * used by EE and EE addons during plugin activation to create tables.
627
+	 * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
628
+	 * but includes extra logic regarding activations.
629
+	 *
630
+	 * @access public
631
+	 * @static
632
+	 * @param string  $table_name              without the $wpdb->prefix
633
+	 * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
634
+	 *                                         table query)
635
+	 * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
636
+	 * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
637
+	 *                                         and new once this function is done (ie, you really do want to CREATE a
638
+	 *                                         table, and expect it to be empty once you're done) leave as FALSE when
639
+	 *                                         you just want to verify the table exists and matches this definition
640
+	 *                                         (and if it HAS data in it you want to leave it be)
641
+	 * @return void
642
+	 * @throws EE_Error if there are database errors
643
+	 */
644
+	public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
645
+	{
646
+		if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
647
+			return;
648
+		}
649
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
650
+		if ( ! function_exists('dbDelta')) {
651
+			require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
652
+		}
653
+		$tableAnalysis = \EEH_Activation::getTableAnalysis();
654
+		$wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
655
+		// do we need to first delete an existing version of this table ?
656
+		if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
657
+			// ok, delete the table... but ONLY if it's empty
658
+			$deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
659
+			// table is NOT empty, are you SURE you want to delete this table ???
660
+			if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
661
+				\EEH_Activation::getTableManager()->dropTable($wp_table_name);
662
+			} else if ( ! $deleted_safely) {
663
+				// so we should be more cautious rather than just dropping tables so easily
664
+				error_log(
665
+					sprintf(
666
+						__(
667
+							'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
668
+							'event_espresso'
669
+						),
670
+						$wp_table_name,
671
+						'<br/>',
672
+						'espresso_db_update'
673
+					)
674
+				);
675
+			}
676
+		}
677
+		$engine = str_replace('ENGINE=', '', $engine);
678
+		\EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
679
+	}
680
+
681
+
682
+
683
+	/**
684
+	 *    add_column_if_it_doesn't_exist
685
+	 *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
686
+	 *
687
+	 * @access     public
688
+	 * @static
689
+	 * @deprecated instead use TableManager::addColumn()
690
+	 * @param string $table_name  (without "wp_", eg "esp_attendee"
691
+	 * @param string $column_name
692
+	 * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
693
+	 *                            'VARCHAR(10)'
694
+	 * @return bool|int
695
+	 */
696
+	public static function add_column_if_it_doesnt_exist(
697
+		$table_name,
698
+		$column_name,
699
+		$column_info = 'INT UNSIGNED NOT NULL'
700
+	) {
701
+		return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
702
+	}
703
+
704
+
705
+	/**
706
+	 * get_fields_on_table
707
+	 * Gets all the fields on the database table.
708
+	 *
709
+	 * @access     public
710
+	 * @deprecated instead use TableManager::getTableColumns()
711
+	 * @static
712
+	 * @param string $table_name , without prefixed $wpdb->prefix
713
+	 * @return array of database column names
714
+	 */
715
+	public static function get_fields_on_table($table_name = null)
716
+	{
717
+		return \EEH_Activation::getTableManager()->getTableColumns($table_name);
718
+	}
719
+
720
+
721
+	/**
722
+	 * db_table_is_empty
723
+	 *
724
+	 * @access     public\
725
+	 * @deprecated instead use TableAnalysis::tableIsEmpty()
726
+	 * @static
727
+	 * @param string $table_name
728
+	 * @return bool
729
+	 */
730
+	public static function db_table_is_empty($table_name)
731
+	{
732
+		return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
733
+	}
734
+
735
+
736
+	/**
737
+	 * delete_db_table_if_empty
738
+	 *
739
+	 * @access public
740
+	 * @static
741
+	 * @param string $table_name
742
+	 * @return bool | int
743
+	 */
744
+	public static function delete_db_table_if_empty($table_name)
745
+	{
746
+		if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
747
+			return \EEH_Activation::getTableManager()->dropTable($table_name);
748
+		}
749
+		return false;
750
+	}
751
+
752
+
753
+	/**
754
+	 * delete_unused_db_table
755
+	 *
756
+	 * @access     public
757
+	 * @static
758
+	 * @deprecated instead use TableManager::dropTable()
759
+	 * @param string $table_name
760
+	 * @return bool | int
761
+	 */
762
+	public static function delete_unused_db_table($table_name)
763
+	{
764
+		return \EEH_Activation::getTableManager()->dropTable($table_name);
765
+	}
766
+
767
+
768
+	/**
769
+	 * drop_index
770
+	 *
771
+	 * @access     public
772
+	 * @static
773
+	 * @deprecated instead use TableManager::dropIndex()
774
+	 * @param string $table_name
775
+	 * @param string $index_name
776
+	 * @return bool | int
777
+	 */
778
+	public static function drop_index($table_name, $index_name)
779
+	{
780
+		return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
781
+	}
782
+
783
+
784
+
785
+	/**
786
+	 * create_database_tables
787
+	 *
788
+	 * @access public
789
+	 * @static
790
+	 * @throws EE_Error
791
+	 * @return boolean success (whether database is setup properly or not)
792
+	 */
793
+	public static function create_database_tables()
794
+	{
795
+		EE_Registry::instance()->load_core('Data_Migration_Manager');
796
+		//find the migration script that sets the database to be compatible with the code
797
+		$dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
798
+		if ($dms_name) {
799
+			$current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
800
+			$current_data_migration_script->set_migrating(false);
801
+			$current_data_migration_script->schema_changes_before_migration();
802
+			$current_data_migration_script->schema_changes_after_migration();
803
+			if ($current_data_migration_script->get_errors()) {
804
+				if (WP_DEBUG) {
805
+					foreach ($current_data_migration_script->get_errors() as $error) {
806
+						EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
807
+					}
808
+				} else {
809
+					EE_Error::add_error(
810
+						__(
811
+							'There were errors creating the Event Espresso database tables and Event Espresso has been 
812 812
                             deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.',
813
-                            'event_espresso'
814
-                        )
815
-                    );
816
-                }
817
-                return false;
818
-            }
819
-            EE_Data_Migration_Manager::instance()->update_current_database_state_to();
820
-        } else {
821
-            EE_Error::add_error(
822
-                __(
823
-                    'Could not determine most up-to-date data migration script from which to pull database schema
813
+							'event_espresso'
814
+						)
815
+					);
816
+				}
817
+				return false;
818
+			}
819
+			EE_Data_Migration_Manager::instance()->update_current_database_state_to();
820
+		} else {
821
+			EE_Error::add_error(
822
+				__(
823
+					'Could not determine most up-to-date data migration script from which to pull database schema
824 824
                      structure. So database is probably not setup properly',
825
-                    'event_espresso'
826
-                ),
827
-                __FILE__,
828
-                __FUNCTION__,
829
-                __LINE__
830
-            );
831
-            return false;
832
-        }
833
-        return true;
834
-    }
835
-
836
-
837
-
838
-    /**
839
-     * initialize_system_questions
840
-     *
841
-     * @access public
842
-     * @static
843
-     * @return void
844
-     */
845
-    public static function initialize_system_questions()
846
-    {
847
-        // QUESTION GROUPS
848
-        global $wpdb;
849
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
850
-        $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
851
-        // what we have
852
-        $question_groups = $wpdb->get_col($SQL);
853
-        // check the response
854
-        $question_groups = is_array($question_groups) ? $question_groups : array();
855
-        // what we should have
856
-        $QSG_systems = array(1, 2);
857
-        // loop thru what we should have and compare to what we have
858
-        foreach ($QSG_systems as $QSG_system) {
859
-            // reset values array
860
-            $QSG_values = array();
861
-            // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
862
-            if (! in_array("$QSG_system", $question_groups)) {
863
-                // add it
864
-                switch ($QSG_system) {
865
-                    case 1:
866
-                        $QSG_values = array(
867
-                            'QSG_name'            => __('Personal Information', 'event_espresso'),
868
-                            'QSG_identifier'      => 'personal-information-' . time(),
869
-                            'QSG_desc'            => '',
870
-                            'QSG_order'           => 1,
871
-                            'QSG_show_group_name' => 1,
872
-                            'QSG_show_group_desc' => 1,
873
-                            'QSG_system'          => EEM_Question_Group::system_personal,
874
-                            'QSG_deleted'         => 0,
875
-                        );
876
-                        break;
877
-                    case 2:
878
-                        $QSG_values = array(
879
-                            'QSG_name'            => __('Address Information', 'event_espresso'),
880
-                            'QSG_identifier'      => 'address-information-' . time(),
881
-                            'QSG_desc'            => '',
882
-                            'QSG_order'           => 2,
883
-                            'QSG_show_group_name' => 1,
884
-                            'QSG_show_group_desc' => 1,
885
-                            'QSG_system'          => EEM_Question_Group::system_address,
886
-                            'QSG_deleted'         => 0,
887
-                        );
888
-                        break;
889
-                }
890
-                // make sure we have some values before inserting them
891
-                if (! empty($QSG_values)) {
892
-                    // insert system question
893
-                    $wpdb->insert(
894
-                        $table_name,
895
-                        $QSG_values,
896
-                        array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
897
-                    );
898
-                    $QSG_IDs[$QSG_system] = $wpdb->insert_id;
899
-                }
900
-            }
901
-        }
902
-        // QUESTIONS
903
-        global $wpdb;
904
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
905
-        $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
906
-        // what we have
907
-        $questions = $wpdb->get_col($SQL);
908
-        // what we should have
909
-        $QST_systems = array(
910
-            'fname',
911
-            'lname',
912
-            'email',
913
-            'address',
914
-            'address2',
915
-            'city',
916
-            'country',
917
-            'state',
918
-            'zip',
919
-            'phone',
920
-        );
921
-        $order_for_group_1 = 1;
922
-        $order_for_group_2 = 1;
923
-        // loop thru what we should have and compare to what we have
924
-        foreach ($QST_systems as $QST_system) {
925
-            // reset values array
926
-            $QST_values = array();
927
-            // if we don't have what we should have
928
-            if (! in_array($QST_system, $questions)) {
929
-                // add it
930
-                switch ($QST_system) {
931
-                    case 'fname':
932
-                        $QST_values = array(
933
-                            'QST_display_text'  => __('First Name', 'event_espresso'),
934
-                            'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
935
-                            'QST_system'        => 'fname',
936
-                            'QST_type'          => 'TEXT',
937
-                            'QST_required'      => 1,
938
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
939
-                            'QST_order'         => 1,
940
-                            'QST_admin_only'    => 0,
941
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
942
-                            'QST_wp_user'       => self::get_default_creator_id(),
943
-                            'QST_deleted'       => 0,
944
-                        );
945
-                        break;
946
-                    case 'lname':
947
-                        $QST_values = array(
948
-                            'QST_display_text'  => __('Last Name', 'event_espresso'),
949
-                            'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
950
-                            'QST_system'        => 'lname',
951
-                            'QST_type'          => 'TEXT',
952
-                            'QST_required'      => 1,
953
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
954
-                            'QST_order'         => 2,
955
-                            'QST_admin_only'    => 0,
956
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
957
-                            'QST_wp_user'       => self::get_default_creator_id(),
958
-                            'QST_deleted'       => 0,
959
-                        );
960
-                        break;
961
-                    case 'email':
962
-                        $QST_values = array(
963
-                            'QST_display_text'  => __('Email Address', 'event_espresso'),
964
-                            'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
965
-                            'QST_system'        => 'email',
966
-                            'QST_type'          => 'EMAIL',
967
-                            'QST_required'      => 1,
968
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
969
-                            'QST_order'         => 3,
970
-                            'QST_admin_only'    => 0,
971
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
972
-                            'QST_wp_user'       => self::get_default_creator_id(),
973
-                            'QST_deleted'       => 0,
974
-                        );
975
-                        break;
976
-                    case 'address':
977
-                        $QST_values = array(
978
-                            'QST_display_text'  => __('Address', 'event_espresso'),
979
-                            'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
980
-                            'QST_system'        => 'address',
981
-                            'QST_type'          => 'TEXT',
982
-                            'QST_required'      => 0,
983
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
984
-                            'QST_order'         => 4,
985
-                            'QST_admin_only'    => 0,
986
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
987
-                            'QST_wp_user'       => self::get_default_creator_id(),
988
-                            'QST_deleted'       => 0,
989
-                        );
990
-                        break;
991
-                    case 'address2':
992
-                        $QST_values = array(
993
-                            'QST_display_text'  => __('Address2', 'event_espresso'),
994
-                            'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
995
-                            'QST_system'        => 'address2',
996
-                            'QST_type'          => 'TEXT',
997
-                            'QST_required'      => 0,
998
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
999
-                            'QST_order'         => 5,
1000
-                            'QST_admin_only'    => 0,
1001
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1002
-                            'QST_wp_user'       => self::get_default_creator_id(),
1003
-                            'QST_deleted'       => 0,
1004
-                        );
1005
-                        break;
1006
-                    case 'city':
1007
-                        $QST_values = array(
1008
-                            'QST_display_text'  => __('City', 'event_espresso'),
1009
-                            'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1010
-                            'QST_system'        => 'city',
1011
-                            'QST_type'          => 'TEXT',
1012
-                            'QST_required'      => 0,
1013
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1014
-                            'QST_order'         => 6,
1015
-                            'QST_admin_only'    => 0,
1016
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1017
-                            'QST_wp_user'       => self::get_default_creator_id(),
1018
-                            'QST_deleted'       => 0,
1019
-                        );
1020
-                        break;
1021
-                    case 'country':
1022
-                        $QST_values = array(
1023
-                            'QST_display_text'  => __('Country', 'event_espresso'),
1024
-                            'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1025
-                            'QST_system'        => 'country',
1026
-                            'QST_type'          => 'COUNTRY',
1027
-                            'QST_required'      => 0,
1028
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1029
-                            'QST_order'         => 7,
1030
-                            'QST_admin_only'    => 0,
1031
-                            'QST_wp_user'       => self::get_default_creator_id(),
1032
-                            'QST_deleted'       => 0,
1033
-                        );
1034
-                        break;
1035
-                    case 'state':
1036
-                        $QST_values = array(
1037
-                            'QST_display_text'  => __('State/Province', 'event_espresso'),
1038
-                            'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1039
-                            'QST_system'        => 'state',
1040
-                            'QST_type'          => 'STATE',
1041
-                            'QST_required'      => 0,
1042
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1043
-                            'QST_order'         => 8,
1044
-                            'QST_admin_only'    => 0,
1045
-                            'QST_wp_user'       => self::get_default_creator_id(),
1046
-                            'QST_deleted'       => 0,
1047
-                        );
1048
-                        break;
1049
-                    case 'zip':
1050
-                        $QST_values = array(
1051
-                            'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1052
-                            'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1053
-                            'QST_system'        => 'zip',
1054
-                            'QST_type'          => 'TEXT',
1055
-                            'QST_required'      => 0,
1056
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1057
-                            'QST_order'         => 9,
1058
-                            'QST_admin_only'    => 0,
1059
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1060
-                            'QST_wp_user'       => self::get_default_creator_id(),
1061
-                            'QST_deleted'       => 0,
1062
-                        );
1063
-                        break;
1064
-                    case 'phone':
1065
-                        $QST_values = array(
1066
-                            'QST_display_text'  => __('Phone Number', 'event_espresso'),
1067
-                            'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1068
-                            'QST_system'        => 'phone',
1069
-                            'QST_type'          => 'TEXT',
1070
-                            'QST_required'      => 0,
1071
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1072
-                            'QST_order'         => 10,
1073
-                            'QST_admin_only'    => 0,
1074
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1075
-                            'QST_wp_user'       => self::get_default_creator_id(),
1076
-                            'QST_deleted'       => 0,
1077
-                        );
1078
-                        break;
1079
-                }
1080
-                if (! empty($QST_values)) {
1081
-                    // insert system question
1082
-                    $wpdb->insert(
1083
-                        $table_name,
1084
-                        $QST_values,
1085
-                        array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1086
-                    );
1087
-                    $QST_ID = $wpdb->insert_id;
1088
-                    // QUESTION GROUP QUESTIONS
1089
-                    if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1090
-                        $system_question_we_want = EEM_Question_Group::system_personal;
1091
-                    } else {
1092
-                        $system_question_we_want = EEM_Question_Group::system_address;
1093
-                    }
1094
-                    if (isset($QSG_IDs[$system_question_we_want])) {
1095
-                        $QSG_ID = $QSG_IDs[$system_question_we_want];
1096
-                    } else {
1097
-                        $id_col = EEM_Question_Group::instance()
1098
-                                                    ->get_col(array(array('QSG_system' => $system_question_we_want)));
1099
-                        if (is_array($id_col)) {
1100
-                            $QSG_ID = reset($id_col);
1101
-                        } else {
1102
-                            //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1103
-                            EE_Log::instance()->log(
1104
-                                __FILE__,
1105
-                                __FUNCTION__,
1106
-                                sprintf(
1107
-                                    __(
1108
-                                        'Could not associate question %1$s to a question group because no system question
825
+					'event_espresso'
826
+				),
827
+				__FILE__,
828
+				__FUNCTION__,
829
+				__LINE__
830
+			);
831
+			return false;
832
+		}
833
+		return true;
834
+	}
835
+
836
+
837
+
838
+	/**
839
+	 * initialize_system_questions
840
+	 *
841
+	 * @access public
842
+	 * @static
843
+	 * @return void
844
+	 */
845
+	public static function initialize_system_questions()
846
+	{
847
+		// QUESTION GROUPS
848
+		global $wpdb;
849
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
850
+		$SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
851
+		// what we have
852
+		$question_groups = $wpdb->get_col($SQL);
853
+		// check the response
854
+		$question_groups = is_array($question_groups) ? $question_groups : array();
855
+		// what we should have
856
+		$QSG_systems = array(1, 2);
857
+		// loop thru what we should have and compare to what we have
858
+		foreach ($QSG_systems as $QSG_system) {
859
+			// reset values array
860
+			$QSG_values = array();
861
+			// if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
862
+			if (! in_array("$QSG_system", $question_groups)) {
863
+				// add it
864
+				switch ($QSG_system) {
865
+					case 1:
866
+						$QSG_values = array(
867
+							'QSG_name'            => __('Personal Information', 'event_espresso'),
868
+							'QSG_identifier'      => 'personal-information-' . time(),
869
+							'QSG_desc'            => '',
870
+							'QSG_order'           => 1,
871
+							'QSG_show_group_name' => 1,
872
+							'QSG_show_group_desc' => 1,
873
+							'QSG_system'          => EEM_Question_Group::system_personal,
874
+							'QSG_deleted'         => 0,
875
+						);
876
+						break;
877
+					case 2:
878
+						$QSG_values = array(
879
+							'QSG_name'            => __('Address Information', 'event_espresso'),
880
+							'QSG_identifier'      => 'address-information-' . time(),
881
+							'QSG_desc'            => '',
882
+							'QSG_order'           => 2,
883
+							'QSG_show_group_name' => 1,
884
+							'QSG_show_group_desc' => 1,
885
+							'QSG_system'          => EEM_Question_Group::system_address,
886
+							'QSG_deleted'         => 0,
887
+						);
888
+						break;
889
+				}
890
+				// make sure we have some values before inserting them
891
+				if (! empty($QSG_values)) {
892
+					// insert system question
893
+					$wpdb->insert(
894
+						$table_name,
895
+						$QSG_values,
896
+						array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
897
+					);
898
+					$QSG_IDs[$QSG_system] = $wpdb->insert_id;
899
+				}
900
+			}
901
+		}
902
+		// QUESTIONS
903
+		global $wpdb;
904
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
905
+		$SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
906
+		// what we have
907
+		$questions = $wpdb->get_col($SQL);
908
+		// what we should have
909
+		$QST_systems = array(
910
+			'fname',
911
+			'lname',
912
+			'email',
913
+			'address',
914
+			'address2',
915
+			'city',
916
+			'country',
917
+			'state',
918
+			'zip',
919
+			'phone',
920
+		);
921
+		$order_for_group_1 = 1;
922
+		$order_for_group_2 = 1;
923
+		// loop thru what we should have and compare to what we have
924
+		foreach ($QST_systems as $QST_system) {
925
+			// reset values array
926
+			$QST_values = array();
927
+			// if we don't have what we should have
928
+			if (! in_array($QST_system, $questions)) {
929
+				// add it
930
+				switch ($QST_system) {
931
+					case 'fname':
932
+						$QST_values = array(
933
+							'QST_display_text'  => __('First Name', 'event_espresso'),
934
+							'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
935
+							'QST_system'        => 'fname',
936
+							'QST_type'          => 'TEXT',
937
+							'QST_required'      => 1,
938
+							'QST_required_text' => __('This field is required', 'event_espresso'),
939
+							'QST_order'         => 1,
940
+							'QST_admin_only'    => 0,
941
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
942
+							'QST_wp_user'       => self::get_default_creator_id(),
943
+							'QST_deleted'       => 0,
944
+						);
945
+						break;
946
+					case 'lname':
947
+						$QST_values = array(
948
+							'QST_display_text'  => __('Last Name', 'event_espresso'),
949
+							'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
950
+							'QST_system'        => 'lname',
951
+							'QST_type'          => 'TEXT',
952
+							'QST_required'      => 1,
953
+							'QST_required_text' => __('This field is required', 'event_espresso'),
954
+							'QST_order'         => 2,
955
+							'QST_admin_only'    => 0,
956
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
957
+							'QST_wp_user'       => self::get_default_creator_id(),
958
+							'QST_deleted'       => 0,
959
+						);
960
+						break;
961
+					case 'email':
962
+						$QST_values = array(
963
+							'QST_display_text'  => __('Email Address', 'event_espresso'),
964
+							'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
965
+							'QST_system'        => 'email',
966
+							'QST_type'          => 'EMAIL',
967
+							'QST_required'      => 1,
968
+							'QST_required_text' => __('This field is required', 'event_espresso'),
969
+							'QST_order'         => 3,
970
+							'QST_admin_only'    => 0,
971
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
972
+							'QST_wp_user'       => self::get_default_creator_id(),
973
+							'QST_deleted'       => 0,
974
+						);
975
+						break;
976
+					case 'address':
977
+						$QST_values = array(
978
+							'QST_display_text'  => __('Address', 'event_espresso'),
979
+							'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
980
+							'QST_system'        => 'address',
981
+							'QST_type'          => 'TEXT',
982
+							'QST_required'      => 0,
983
+							'QST_required_text' => __('This field is required', 'event_espresso'),
984
+							'QST_order'         => 4,
985
+							'QST_admin_only'    => 0,
986
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
987
+							'QST_wp_user'       => self::get_default_creator_id(),
988
+							'QST_deleted'       => 0,
989
+						);
990
+						break;
991
+					case 'address2':
992
+						$QST_values = array(
993
+							'QST_display_text'  => __('Address2', 'event_espresso'),
994
+							'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
995
+							'QST_system'        => 'address2',
996
+							'QST_type'          => 'TEXT',
997
+							'QST_required'      => 0,
998
+							'QST_required_text' => __('This field is required', 'event_espresso'),
999
+							'QST_order'         => 5,
1000
+							'QST_admin_only'    => 0,
1001
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1002
+							'QST_wp_user'       => self::get_default_creator_id(),
1003
+							'QST_deleted'       => 0,
1004
+						);
1005
+						break;
1006
+					case 'city':
1007
+						$QST_values = array(
1008
+							'QST_display_text'  => __('City', 'event_espresso'),
1009
+							'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1010
+							'QST_system'        => 'city',
1011
+							'QST_type'          => 'TEXT',
1012
+							'QST_required'      => 0,
1013
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1014
+							'QST_order'         => 6,
1015
+							'QST_admin_only'    => 0,
1016
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1017
+							'QST_wp_user'       => self::get_default_creator_id(),
1018
+							'QST_deleted'       => 0,
1019
+						);
1020
+						break;
1021
+					case 'country':
1022
+						$QST_values = array(
1023
+							'QST_display_text'  => __('Country', 'event_espresso'),
1024
+							'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1025
+							'QST_system'        => 'country',
1026
+							'QST_type'          => 'COUNTRY',
1027
+							'QST_required'      => 0,
1028
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1029
+							'QST_order'         => 7,
1030
+							'QST_admin_only'    => 0,
1031
+							'QST_wp_user'       => self::get_default_creator_id(),
1032
+							'QST_deleted'       => 0,
1033
+						);
1034
+						break;
1035
+					case 'state':
1036
+						$QST_values = array(
1037
+							'QST_display_text'  => __('State/Province', 'event_espresso'),
1038
+							'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1039
+							'QST_system'        => 'state',
1040
+							'QST_type'          => 'STATE',
1041
+							'QST_required'      => 0,
1042
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1043
+							'QST_order'         => 8,
1044
+							'QST_admin_only'    => 0,
1045
+							'QST_wp_user'       => self::get_default_creator_id(),
1046
+							'QST_deleted'       => 0,
1047
+						);
1048
+						break;
1049
+					case 'zip':
1050
+						$QST_values = array(
1051
+							'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1052
+							'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1053
+							'QST_system'        => 'zip',
1054
+							'QST_type'          => 'TEXT',
1055
+							'QST_required'      => 0,
1056
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1057
+							'QST_order'         => 9,
1058
+							'QST_admin_only'    => 0,
1059
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1060
+							'QST_wp_user'       => self::get_default_creator_id(),
1061
+							'QST_deleted'       => 0,
1062
+						);
1063
+						break;
1064
+					case 'phone':
1065
+						$QST_values = array(
1066
+							'QST_display_text'  => __('Phone Number', 'event_espresso'),
1067
+							'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1068
+							'QST_system'        => 'phone',
1069
+							'QST_type'          => 'TEXT',
1070
+							'QST_required'      => 0,
1071
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1072
+							'QST_order'         => 10,
1073
+							'QST_admin_only'    => 0,
1074
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1075
+							'QST_wp_user'       => self::get_default_creator_id(),
1076
+							'QST_deleted'       => 0,
1077
+						);
1078
+						break;
1079
+				}
1080
+				if (! empty($QST_values)) {
1081
+					// insert system question
1082
+					$wpdb->insert(
1083
+						$table_name,
1084
+						$QST_values,
1085
+						array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1086
+					);
1087
+					$QST_ID = $wpdb->insert_id;
1088
+					// QUESTION GROUP QUESTIONS
1089
+					if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1090
+						$system_question_we_want = EEM_Question_Group::system_personal;
1091
+					} else {
1092
+						$system_question_we_want = EEM_Question_Group::system_address;
1093
+					}
1094
+					if (isset($QSG_IDs[$system_question_we_want])) {
1095
+						$QSG_ID = $QSG_IDs[$system_question_we_want];
1096
+					} else {
1097
+						$id_col = EEM_Question_Group::instance()
1098
+													->get_col(array(array('QSG_system' => $system_question_we_want)));
1099
+						if (is_array($id_col)) {
1100
+							$QSG_ID = reset($id_col);
1101
+						} else {
1102
+							//ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1103
+							EE_Log::instance()->log(
1104
+								__FILE__,
1105
+								__FUNCTION__,
1106
+								sprintf(
1107
+									__(
1108
+										'Could not associate question %1$s to a question group because no system question
1109 1109
                                          group existed',
1110
-                                        'event_espresso'
1111
-                                    ),
1112
-                                    $QST_ID),
1113
-                                'error');
1114
-                            continue;
1115
-                        }
1116
-                    }
1117
-                    // add system questions to groups
1118
-                    $wpdb->insert(
1119
-                        \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1120
-                        array(
1121
-                            'QSG_ID'    => $QSG_ID,
1122
-                            'QST_ID'    => $QST_ID,
1123
-                            'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1124
-                        ),
1125
-                        array('%d', '%d', '%d')
1126
-                    );
1127
-                }
1128
-            }
1129
-        }
1130
-    }
1131
-
1132
-
1133
-    /**
1134
-     * Makes sure the default payment method (Invoice) is active.
1135
-     * This used to be done automatically as part of constructing the old gateways config
1136
-     *
1137
-     * @throws \EE_Error
1138
-     */
1139
-    public static function insert_default_payment_methods()
1140
-    {
1141
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1142
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
1143
-            EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1144
-        } else {
1145
-            EEM_Payment_Method::instance()->verify_button_urls();
1146
-        }
1147
-    }
1148
-
1149
-    /**
1150
-     * insert_default_status_codes
1151
-     *
1152
-     * @access public
1153
-     * @static
1154
-     * @return void
1155
-     */
1156
-    public static function insert_default_status_codes()
1157
-    {
1158
-
1159
-        global $wpdb;
1160
-
1161
-        if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1162
-
1163
-            $table_name = EEM_Status::instance()->table();
1164
-
1165
-            $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1166
-            $wpdb->query($SQL);
1167
-
1168
-            $SQL = "INSERT INTO $table_name
1110
+										'event_espresso'
1111
+									),
1112
+									$QST_ID),
1113
+								'error');
1114
+							continue;
1115
+						}
1116
+					}
1117
+					// add system questions to groups
1118
+					$wpdb->insert(
1119
+						\EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1120
+						array(
1121
+							'QSG_ID'    => $QSG_ID,
1122
+							'QST_ID'    => $QST_ID,
1123
+							'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1124
+						),
1125
+						array('%d', '%d', '%d')
1126
+					);
1127
+				}
1128
+			}
1129
+		}
1130
+	}
1131
+
1132
+
1133
+	/**
1134
+	 * Makes sure the default payment method (Invoice) is active.
1135
+	 * This used to be done automatically as part of constructing the old gateways config
1136
+	 *
1137
+	 * @throws \EE_Error
1138
+	 */
1139
+	public static function insert_default_payment_methods()
1140
+	{
1141
+		if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1142
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
1143
+			EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1144
+		} else {
1145
+			EEM_Payment_Method::instance()->verify_button_urls();
1146
+		}
1147
+	}
1148
+
1149
+	/**
1150
+	 * insert_default_status_codes
1151
+	 *
1152
+	 * @access public
1153
+	 * @static
1154
+	 * @return void
1155
+	 */
1156
+	public static function insert_default_status_codes()
1157
+	{
1158
+
1159
+		global $wpdb;
1160
+
1161
+		if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1162
+
1163
+			$table_name = EEM_Status::instance()->table();
1164
+
1165
+			$SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1166
+			$wpdb->query($SQL);
1167
+
1168
+			$SQL = "INSERT INTO $table_name
1169 1169
 					(STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES
1170 1170
 					('ACT', 'ACTIVE', 'event', 0, NULL, 1),
1171 1171
 					('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0),
@@ -1205,462 +1205,462 @@  discard block
 block discarded – undo
1205 1205
 					('MID', 'IDLE', 'message', 0, NULL, 1),
1206 1206
 					('MRS', 'RESEND', 'message', 0, NULL, 1),
1207 1207
 					('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);";
1208
-            $wpdb->query($SQL);
1209
-
1210
-        }
1211
-
1212
-    }
1213
-
1214
-
1215
-    /**
1216
-     * generate_default_message_templates
1217
-     *
1218
-     * @static
1219
-     * @throws EE_Error
1220
-     * @return bool     true means new templates were created.
1221
-     *                  false means no templates were created.
1222
-     *                  This is NOT an error flag. To check for errors you will want
1223
-     *                  to use either EE_Error or a try catch for an EE_Error exception.
1224
-     */
1225
-    public static function generate_default_message_templates()
1226
-    {
1227
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1228
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1229
-        /*
1208
+			$wpdb->query($SQL);
1209
+
1210
+		}
1211
+
1212
+	}
1213
+
1214
+
1215
+	/**
1216
+	 * generate_default_message_templates
1217
+	 *
1218
+	 * @static
1219
+	 * @throws EE_Error
1220
+	 * @return bool     true means new templates were created.
1221
+	 *                  false means no templates were created.
1222
+	 *                  This is NOT an error flag. To check for errors you will want
1223
+	 *                  to use either EE_Error or a try catch for an EE_Error exception.
1224
+	 */
1225
+	public static function generate_default_message_templates()
1226
+	{
1227
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1228
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1229
+		/*
1230 1230
          * This first method is taking care of ensuring any default messengers
1231 1231
          * that should be made active and have templates generated are done.
1232 1232
          */
1233
-        $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1234
-            $message_resource_manager
1235
-        );
1236
-        /**
1237
-         * This method is verifying there are no NEW default message types
1238
-         * for ACTIVE messengers that need activated (and corresponding templates setup).
1239
-         */
1240
-        $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1241
-            $message_resource_manager
1242
-        );
1243
-        //after all is done, let's persist these changes to the db.
1244
-        $message_resource_manager->update_has_activated_messengers_option();
1245
-        $message_resource_manager->update_active_messengers_option();
1246
-        // will return true if either of these are true.  Otherwise will return false.
1247
-        return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1248
-    }
1249
-
1250
-
1251
-
1252
-    /**
1253
-     * @param \EE_Message_Resource_Manager $message_resource_manager
1254
-     * @return array|bool
1255
-     * @throws \EE_Error
1256
-     */
1257
-    protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1258
-        EE_Message_Resource_Manager $message_resource_manager
1259
-    ) {
1260
-        /** @type EE_messenger[] $active_messengers */
1261
-        $active_messengers = $message_resource_manager->active_messengers();
1262
-        $installed_message_types = $message_resource_manager->installed_message_types();
1263
-        $templates_created = false;
1264
-        foreach ($active_messengers as $active_messenger) {
1265
-            $default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1266
-            $default_message_type_names_to_activate = array();
1267
-            // looping through each default message type reported by the messenger
1268
-            // and setup the actual message types to activate.
1269
-            foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1270
-                // if already active or has already been activated before we skip
1271
-                // (otherwise we might reactivate something user's intentionally deactivated.)
1272
-                // we also skip if the message type is not installed.
1273
-                if (
1274
-                    $message_resource_manager->has_message_type_been_activated_for_messenger(
1275
-                        $default_message_type_name_for_messenger,
1276
-                        $active_messenger->name
1277
-                    )
1278
-                    || $message_resource_manager->is_message_type_active_for_messenger(
1279
-                        $active_messenger->name,
1280
-                        $default_message_type_name_for_messenger
1281
-                    )
1282
-                    || ! isset($installed_message_types[$default_message_type_name_for_messenger])
1283
-                ) {
1284
-                    continue;
1285
-                }
1286
-                $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1287
-            }
1288
-            //let's activate!
1289
-            $message_resource_manager->ensure_message_types_are_active(
1290
-                $default_message_type_names_to_activate,
1291
-                $active_messenger->name,
1292
-                false
1293
-            );
1294
-            //activate the templates for these message types
1295
-            if ( ! empty($default_message_type_names_to_activate)) {
1296
-                $templates_created = EEH_MSG_Template::generate_new_templates(
1297
-                    $active_messenger->name,
1298
-                    $default_message_type_names_for_messenger,
1299
-                    '',
1300
-                    true
1301
-                );
1302
-            }
1303
-        }
1304
-        return $templates_created;
1305
-    }
1306
-
1307
-
1308
-
1309
-    /**
1310
-     * This will activate and generate default messengers and default message types for those messengers.
1311
-     *
1312
-     * @param EE_message_Resource_Manager $message_resource_manager
1313
-     * @return array|bool  True means there were default messengers and message type templates generated.
1314
-     *                     False means that there were no templates generated
1315
-     *                     (which could simply mean there are no default message types for a messenger).
1316
-     * @throws EE_Error
1317
-     */
1318
-    protected static function _activate_and_generate_default_messengers_and_message_templates(
1319
-        EE_Message_Resource_Manager $message_resource_manager
1320
-    ) {
1321
-        /** @type EE_messenger[] $messengers_to_generate */
1322
-        $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1323
-        $installed_message_types = $message_resource_manager->installed_message_types();
1324
-        $templates_generated = false;
1325
-        foreach ($messengers_to_generate as $messenger_to_generate) {
1326
-            $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1327
-            //verify the default message types match an installed message type.
1328
-            foreach ($default_message_type_names_for_messenger as $key => $name) {
1329
-                if (
1330
-                    ! isset($installed_message_types[$name])
1331
-                    || $message_resource_manager->has_message_type_been_activated_for_messenger(
1332
-                        $name,
1333
-                        $messenger_to_generate->name
1334
-                    )
1335
-                ) {
1336
-                    unset($default_message_type_names_for_messenger[$key]);
1337
-                }
1338
-            }
1339
-            // in previous iterations, the active_messengers option in the db
1340
-            // needed updated before calling create templates. however with the changes this may not be necessary.
1341
-            // This comment is left here just in case we discover that we _do_ need to update before
1342
-            // passing off to create templates (after the refactor is done).
1343
-            // @todo remove this comment when determined not necessary.
1344
-            $message_resource_manager->activate_messenger(
1345
-                $messenger_to_generate->name,
1346
-                $default_message_type_names_for_messenger,
1347
-                false
1348
-            );
1349
-            //create any templates needing created (or will reactivate templates already generated as necessary).
1350
-            if ( ! empty($default_message_type_names_for_messenger)) {
1351
-                $templates_generated = EEH_MSG_Template::generate_new_templates(
1352
-                    $messenger_to_generate->name,
1353
-                    $default_message_type_names_for_messenger,
1354
-                    '',
1355
-                    true
1356
-                );
1357
-            }
1358
-        }
1359
-        return $templates_generated;
1360
-    }
1361
-
1362
-
1363
-    /**
1364
-     * This returns the default messengers to generate templates for on activation of EE.
1365
-     * It considers:
1366
-     * - whether a messenger is already active in the db.
1367
-     * - whether a messenger has been made active at any time in the past.
1368
-     *
1369
-     * @static
1370
-     * @param  EE_Message_Resource_Manager $message_resource_manager
1371
-     * @return EE_messenger[]
1372
-     */
1373
-    protected static function _get_default_messengers_to_generate_on_activation(
1374
-        EE_Message_Resource_Manager $message_resource_manager
1375
-    ) {
1376
-        $active_messengers    = $message_resource_manager->active_messengers();
1377
-        $installed_messengers = $message_resource_manager->installed_messengers();
1378
-        $has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1379
-
1380
-        $messengers_to_generate = array();
1381
-        foreach ($installed_messengers as $installed_messenger) {
1382
-            //if installed messenger is a messenger that should be activated on install
1383
-            //and is not already active
1384
-            //and has never been activated
1385
-            if (
1386
-                ! $installed_messenger->activate_on_install
1387
-                || isset($active_messengers[$installed_messenger->name])
1388
-                || isset($has_activated[$installed_messenger->name])
1389
-            ) {
1390
-                continue;
1391
-            }
1392
-            $messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1393
-        }
1394
-        return $messengers_to_generate;
1395
-    }
1396
-
1397
-
1398
-    /**
1399
-     * This simply validates active message types to ensure they actually match installed
1400
-     * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1401
-     * rows are set inactive.
1402
-     * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1403
-     * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1404
-     * are still handled in here.
1405
-     *
1406
-     * @since 4.3.1
1407
-     * @return void
1408
-     */
1409
-    public static function validate_messages_system()
1410
-    {
1411
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1412
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1413
-        $message_resource_manager->validate_active_message_types_are_installed();
1414
-        do_action('AHEE__EEH_Activation__validate_messages_system');
1415
-    }
1416
-
1417
-
1418
-    /**
1419
-     * create_no_ticket_prices_array
1420
-     *
1421
-     * @access public
1422
-     * @static
1423
-     * @return void
1424
-     */
1425
-    public static function create_no_ticket_prices_array()
1426
-    {
1427
-        // this creates an array for tracking events that have no active ticket prices created
1428
-        // this allows us to warn admins of the situation so that it can be corrected
1429
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1430
-        if (! $espresso_no_ticket_prices) {
1431
-            add_option('ee_no_ticket_prices', array(), '', false);
1432
-        }
1433
-    }
1434
-
1435
-
1436
-    /**
1437
-     * plugin_deactivation
1438
-     *
1439
-     * @access public
1440
-     * @static
1441
-     * @return void
1442
-     */
1443
-    public static function plugin_deactivation()
1444
-    {
1445
-    }
1446
-
1447
-
1448
-    /**
1449
-     * Finds all our EE4 custom post types, and deletes them and their associated data
1450
-     * (like post meta or term relations)
1451
-     *
1452
-     * @global wpdb $wpdb
1453
-     * @throws \EE_Error
1454
-     */
1455
-    public static function delete_all_espresso_cpt_data()
1456
-    {
1457
-        global $wpdb;
1458
-        //get all the CPT post_types
1459
-        $ee_post_types = array();
1460
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1461
-            if (method_exists($model_name, 'instance')) {
1462
-                $model_obj = call_user_func(array($model_name, 'instance'));
1463
-                if ($model_obj instanceof EEM_CPT_Base) {
1464
-                    $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1465
-                }
1466
-            }
1467
-        }
1468
-        //get all our CPTs
1469
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1470
-        $cpt_ids = $wpdb->get_col($query);
1471
-        //delete each post meta and term relations too
1472
-        foreach ($cpt_ids as $post_id) {
1473
-            wp_delete_post($post_id, true);
1474
-        }
1475
-    }
1476
-
1477
-    /**
1478
-     * Deletes all EE custom tables
1479
-     *
1480
-     * @return array
1481
-     */
1482
-    public static function drop_espresso_tables()
1483
-    {
1484
-        $tables = array();
1485
-        // load registry
1486
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1487
-            if (method_exists($model_name, 'instance')) {
1488
-                $model_obj = call_user_func(array($model_name, 'instance'));
1489
-                if ($model_obj instanceof EEM_Base) {
1490
-                    foreach ($model_obj->get_tables() as $table) {
1491
-                        if (strpos($table->get_table_name(), 'esp_')
1492
-                            &&
1493
-                            (
1494
-                                is_main_site()//main site? nuke them all
1495
-                                || ! $table->is_global()//not main site,but not global either. nuke it
1496
-                            )
1497
-                        ) {
1498
-                            $tables[$table->get_table_name()] = $table->get_table_name();
1499
-                        }
1500
-                    }
1501
-                }
1502
-            }
1503
-        }
1504
-
1505
-        //there are some tables whose models were removed.
1506
-        //they should be removed when removing all EE core's data
1507
-        $tables_without_models = array(
1508
-            'esp_promotion',
1509
-            'esp_promotion_applied',
1510
-            'esp_promotion_object',
1511
-            'esp_promotion_rule',
1512
-            'esp_rule',
1513
-        );
1514
-        foreach ($tables_without_models as $table) {
1515
-            $tables[$table] = $table;
1516
-        }
1517
-        return \EEH_Activation::getTableManager()->dropTables($tables);
1518
-    }
1519
-
1520
-
1521
-
1522
-    /**
1523
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
1524
-     * each table name provided has a wpdb prefix attached, and that it exists.
1525
-     * Returns the list actually deleted
1526
-     *
1527
-     * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1528
-     * @global WPDB $wpdb
1529
-     * @param array $table_names
1530
-     * @return array of table names which we deleted
1531
-     */
1532
-    public static function drop_tables($table_names)
1533
-    {
1534
-        return \EEH_Activation::getTableManager()->dropTables($table_names);
1535
-    }
1536
-
1537
-
1538
-
1539
-    /**
1540
-     * plugin_uninstall
1541
-     *
1542
-     * @access public
1543
-     * @static
1544
-     * @param bool $remove_all
1545
-     * @return void
1546
-     */
1547
-    public static function delete_all_espresso_tables_and_data($remove_all = true)
1548
-    {
1549
-        global $wpdb;
1550
-        self::drop_espresso_tables();
1551
-        $wp_options_to_delete = array(
1552
-            'ee_no_ticket_prices'                => true,
1553
-            'ee_active_messengers'               => true,
1554
-            'ee_has_activated_messenger'         => true,
1555
-            'ee_flush_rewrite_rules'             => true,
1556
-            'ee_config'                          => false,
1557
-            'ee_data_migration_current_db_state' => true,
1558
-            'ee_data_migration_mapping_'         => false,
1559
-            'ee_data_migration_script_'          => false,
1560
-            'ee_data_migrations'                 => true,
1561
-            'ee_dms_map'                         => false,
1562
-            'ee_notices'                         => true,
1563
-            'lang_file_check_'                   => false,
1564
-            'ee_maintenance_mode'                => true,
1565
-            'ee_ueip_optin'                      => true,
1566
-            'ee_ueip_has_notified'               => true,
1567
-            'ee_plugin_activation_errors'        => true,
1568
-            'ee_id_mapping_from'                 => false,
1569
-            'espresso_persistent_admin_notices'  => true,
1570
-            'ee_encryption_key'                  => true,
1571
-            'pue_force_upgrade_'                 => false,
1572
-            'pue_json_error_'                    => false,
1573
-            'pue_install_key_'                   => false,
1574
-            'pue_verification_error_'            => false,
1575
-            'pu_dismissed_upgrade_'              => false,
1576
-            'external_updates-'                  => false,
1577
-            'ee_extra_data'                      => true,
1578
-            'ee_ssn_'                            => false,
1579
-            'ee_rss_'                            => false,
1580
-            'ee_rte_n_tx_'                       => false,
1581
-            'ee_pers_admin_notices'              => true,
1582
-            'ee_job_parameters_'                 => false,
1583
-            'ee_upload_directories_incomplete'   => true,
1584
-            'ee_verified_db_collations'          => true,
1585
-        );
1586
-        if (is_main_site()) {
1587
-            $wp_options_to_delete['ee_network_config'] = true;
1588
-        }
1589
-        $undeleted_options = array();
1590
-        foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1591
-            if ($no_wildcard) {
1592
-                if ( ! delete_option($option_name)) {
1593
-                    $undeleted_options[] = $option_name;
1594
-                }
1595
-            } else {
1596
-                $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1597
-                foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1598
-                    if ( ! delete_option($option_name_from_wildcard)) {
1599
-                        $undeleted_options[] = $option_name_from_wildcard;
1600
-                    }
1601
-                }
1602
-            }
1603
-        }
1604
-        //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1605
-        remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1606
-        if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1607
-            $db_update_sans_ee4 = array();
1608
-            foreach ($espresso_db_update as $version => $times_activated) {
1609
-                if ((string)$version[0] === '3') {//if its NON EE4
1610
-                    $db_update_sans_ee4[$version] = $times_activated;
1611
-                }
1612
-            }
1613
-            update_option('espresso_db_update', $db_update_sans_ee4);
1614
-        }
1615
-        $errors = '';
1616
-        if ( ! empty($undeleted_options)) {
1617
-            $errors .= sprintf(
1618
-                __('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1619
-                '<br/>',
1620
-                implode(',<br/>', $undeleted_options)
1621
-            );
1622
-        }
1623
-        if ( ! empty($errors)) {
1624
-            EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1625
-        }
1626
-    }
1627
-
1628
-    /**
1629
-     * Gets the mysql error code from the last used query by wpdb
1630
-     *
1631
-     * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1632
-     */
1633
-    public static function last_wpdb_error_code()
1634
-    {
1635
-        global $wpdb;
1636
-        if ($wpdb->use_mysqli) {
1637
-            return mysqli_errno($wpdb->dbh);
1638
-        } else {
1639
-            return mysql_errno($wpdb->dbh);
1640
-        }
1641
-    }
1642
-
1643
-    /**
1644
-     * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1645
-     *
1646
-     * @global wpdb  $wpdb
1647
-     * @deprecated instead use TableAnalysis::tableExists()
1648
-     * @param string $table_name with or without $wpdb->prefix
1649
-     * @return boolean
1650
-     */
1651
-    public static function table_exists($table_name)
1652
-    {
1653
-        return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1654
-    }
1655
-
1656
-    /**
1657
-     * Resets the cache on EEH_Activation
1658
-     */
1659
-    public static function reset()
1660
-    {
1661
-        self::$_default_creator_id                             = null;
1662
-        self::$_initialized_db_content_already_in_this_request = false;
1663
-    }
1233
+		$new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1234
+			$message_resource_manager
1235
+		);
1236
+		/**
1237
+		 * This method is verifying there are no NEW default message types
1238
+		 * for ACTIVE messengers that need activated (and corresponding templates setup).
1239
+		 */
1240
+		$new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1241
+			$message_resource_manager
1242
+		);
1243
+		//after all is done, let's persist these changes to the db.
1244
+		$message_resource_manager->update_has_activated_messengers_option();
1245
+		$message_resource_manager->update_active_messengers_option();
1246
+		// will return true if either of these are true.  Otherwise will return false.
1247
+		return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1248
+	}
1249
+
1250
+
1251
+
1252
+	/**
1253
+	 * @param \EE_Message_Resource_Manager $message_resource_manager
1254
+	 * @return array|bool
1255
+	 * @throws \EE_Error
1256
+	 */
1257
+	protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1258
+		EE_Message_Resource_Manager $message_resource_manager
1259
+	) {
1260
+		/** @type EE_messenger[] $active_messengers */
1261
+		$active_messengers = $message_resource_manager->active_messengers();
1262
+		$installed_message_types = $message_resource_manager->installed_message_types();
1263
+		$templates_created = false;
1264
+		foreach ($active_messengers as $active_messenger) {
1265
+			$default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1266
+			$default_message_type_names_to_activate = array();
1267
+			// looping through each default message type reported by the messenger
1268
+			// and setup the actual message types to activate.
1269
+			foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1270
+				// if already active or has already been activated before we skip
1271
+				// (otherwise we might reactivate something user's intentionally deactivated.)
1272
+				// we also skip if the message type is not installed.
1273
+				if (
1274
+					$message_resource_manager->has_message_type_been_activated_for_messenger(
1275
+						$default_message_type_name_for_messenger,
1276
+						$active_messenger->name
1277
+					)
1278
+					|| $message_resource_manager->is_message_type_active_for_messenger(
1279
+						$active_messenger->name,
1280
+						$default_message_type_name_for_messenger
1281
+					)
1282
+					|| ! isset($installed_message_types[$default_message_type_name_for_messenger])
1283
+				) {
1284
+					continue;
1285
+				}
1286
+				$default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1287
+			}
1288
+			//let's activate!
1289
+			$message_resource_manager->ensure_message_types_are_active(
1290
+				$default_message_type_names_to_activate,
1291
+				$active_messenger->name,
1292
+				false
1293
+			);
1294
+			//activate the templates for these message types
1295
+			if ( ! empty($default_message_type_names_to_activate)) {
1296
+				$templates_created = EEH_MSG_Template::generate_new_templates(
1297
+					$active_messenger->name,
1298
+					$default_message_type_names_for_messenger,
1299
+					'',
1300
+					true
1301
+				);
1302
+			}
1303
+		}
1304
+		return $templates_created;
1305
+	}
1306
+
1307
+
1308
+
1309
+	/**
1310
+	 * This will activate and generate default messengers and default message types for those messengers.
1311
+	 *
1312
+	 * @param EE_message_Resource_Manager $message_resource_manager
1313
+	 * @return array|bool  True means there were default messengers and message type templates generated.
1314
+	 *                     False means that there were no templates generated
1315
+	 *                     (which could simply mean there are no default message types for a messenger).
1316
+	 * @throws EE_Error
1317
+	 */
1318
+	protected static function _activate_and_generate_default_messengers_and_message_templates(
1319
+		EE_Message_Resource_Manager $message_resource_manager
1320
+	) {
1321
+		/** @type EE_messenger[] $messengers_to_generate */
1322
+		$messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1323
+		$installed_message_types = $message_resource_manager->installed_message_types();
1324
+		$templates_generated = false;
1325
+		foreach ($messengers_to_generate as $messenger_to_generate) {
1326
+			$default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1327
+			//verify the default message types match an installed message type.
1328
+			foreach ($default_message_type_names_for_messenger as $key => $name) {
1329
+				if (
1330
+					! isset($installed_message_types[$name])
1331
+					|| $message_resource_manager->has_message_type_been_activated_for_messenger(
1332
+						$name,
1333
+						$messenger_to_generate->name
1334
+					)
1335
+				) {
1336
+					unset($default_message_type_names_for_messenger[$key]);
1337
+				}
1338
+			}
1339
+			// in previous iterations, the active_messengers option in the db
1340
+			// needed updated before calling create templates. however with the changes this may not be necessary.
1341
+			// This comment is left here just in case we discover that we _do_ need to update before
1342
+			// passing off to create templates (after the refactor is done).
1343
+			// @todo remove this comment when determined not necessary.
1344
+			$message_resource_manager->activate_messenger(
1345
+				$messenger_to_generate->name,
1346
+				$default_message_type_names_for_messenger,
1347
+				false
1348
+			);
1349
+			//create any templates needing created (or will reactivate templates already generated as necessary).
1350
+			if ( ! empty($default_message_type_names_for_messenger)) {
1351
+				$templates_generated = EEH_MSG_Template::generate_new_templates(
1352
+					$messenger_to_generate->name,
1353
+					$default_message_type_names_for_messenger,
1354
+					'',
1355
+					true
1356
+				);
1357
+			}
1358
+		}
1359
+		return $templates_generated;
1360
+	}
1361
+
1362
+
1363
+	/**
1364
+	 * This returns the default messengers to generate templates for on activation of EE.
1365
+	 * It considers:
1366
+	 * - whether a messenger is already active in the db.
1367
+	 * - whether a messenger has been made active at any time in the past.
1368
+	 *
1369
+	 * @static
1370
+	 * @param  EE_Message_Resource_Manager $message_resource_manager
1371
+	 * @return EE_messenger[]
1372
+	 */
1373
+	protected static function _get_default_messengers_to_generate_on_activation(
1374
+		EE_Message_Resource_Manager $message_resource_manager
1375
+	) {
1376
+		$active_messengers    = $message_resource_manager->active_messengers();
1377
+		$installed_messengers = $message_resource_manager->installed_messengers();
1378
+		$has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1379
+
1380
+		$messengers_to_generate = array();
1381
+		foreach ($installed_messengers as $installed_messenger) {
1382
+			//if installed messenger is a messenger that should be activated on install
1383
+			//and is not already active
1384
+			//and has never been activated
1385
+			if (
1386
+				! $installed_messenger->activate_on_install
1387
+				|| isset($active_messengers[$installed_messenger->name])
1388
+				|| isset($has_activated[$installed_messenger->name])
1389
+			) {
1390
+				continue;
1391
+			}
1392
+			$messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1393
+		}
1394
+		return $messengers_to_generate;
1395
+	}
1396
+
1397
+
1398
+	/**
1399
+	 * This simply validates active message types to ensure they actually match installed
1400
+	 * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1401
+	 * rows are set inactive.
1402
+	 * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1403
+	 * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1404
+	 * are still handled in here.
1405
+	 *
1406
+	 * @since 4.3.1
1407
+	 * @return void
1408
+	 */
1409
+	public static function validate_messages_system()
1410
+	{
1411
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1412
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1413
+		$message_resource_manager->validate_active_message_types_are_installed();
1414
+		do_action('AHEE__EEH_Activation__validate_messages_system');
1415
+	}
1416
+
1417
+
1418
+	/**
1419
+	 * create_no_ticket_prices_array
1420
+	 *
1421
+	 * @access public
1422
+	 * @static
1423
+	 * @return void
1424
+	 */
1425
+	public static function create_no_ticket_prices_array()
1426
+	{
1427
+		// this creates an array for tracking events that have no active ticket prices created
1428
+		// this allows us to warn admins of the situation so that it can be corrected
1429
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1430
+		if (! $espresso_no_ticket_prices) {
1431
+			add_option('ee_no_ticket_prices', array(), '', false);
1432
+		}
1433
+	}
1434
+
1435
+
1436
+	/**
1437
+	 * plugin_deactivation
1438
+	 *
1439
+	 * @access public
1440
+	 * @static
1441
+	 * @return void
1442
+	 */
1443
+	public static function plugin_deactivation()
1444
+	{
1445
+	}
1446
+
1447
+
1448
+	/**
1449
+	 * Finds all our EE4 custom post types, and deletes them and their associated data
1450
+	 * (like post meta or term relations)
1451
+	 *
1452
+	 * @global wpdb $wpdb
1453
+	 * @throws \EE_Error
1454
+	 */
1455
+	public static function delete_all_espresso_cpt_data()
1456
+	{
1457
+		global $wpdb;
1458
+		//get all the CPT post_types
1459
+		$ee_post_types = array();
1460
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1461
+			if (method_exists($model_name, 'instance')) {
1462
+				$model_obj = call_user_func(array($model_name, 'instance'));
1463
+				if ($model_obj instanceof EEM_CPT_Base) {
1464
+					$ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1465
+				}
1466
+			}
1467
+		}
1468
+		//get all our CPTs
1469
+		$query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1470
+		$cpt_ids = $wpdb->get_col($query);
1471
+		//delete each post meta and term relations too
1472
+		foreach ($cpt_ids as $post_id) {
1473
+			wp_delete_post($post_id, true);
1474
+		}
1475
+	}
1476
+
1477
+	/**
1478
+	 * Deletes all EE custom tables
1479
+	 *
1480
+	 * @return array
1481
+	 */
1482
+	public static function drop_espresso_tables()
1483
+	{
1484
+		$tables = array();
1485
+		// load registry
1486
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1487
+			if (method_exists($model_name, 'instance')) {
1488
+				$model_obj = call_user_func(array($model_name, 'instance'));
1489
+				if ($model_obj instanceof EEM_Base) {
1490
+					foreach ($model_obj->get_tables() as $table) {
1491
+						if (strpos($table->get_table_name(), 'esp_')
1492
+							&&
1493
+							(
1494
+								is_main_site()//main site? nuke them all
1495
+								|| ! $table->is_global()//not main site,but not global either. nuke it
1496
+							)
1497
+						) {
1498
+							$tables[$table->get_table_name()] = $table->get_table_name();
1499
+						}
1500
+					}
1501
+				}
1502
+			}
1503
+		}
1504
+
1505
+		//there are some tables whose models were removed.
1506
+		//they should be removed when removing all EE core's data
1507
+		$tables_without_models = array(
1508
+			'esp_promotion',
1509
+			'esp_promotion_applied',
1510
+			'esp_promotion_object',
1511
+			'esp_promotion_rule',
1512
+			'esp_rule',
1513
+		);
1514
+		foreach ($tables_without_models as $table) {
1515
+			$tables[$table] = $table;
1516
+		}
1517
+		return \EEH_Activation::getTableManager()->dropTables($tables);
1518
+	}
1519
+
1520
+
1521
+
1522
+	/**
1523
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
1524
+	 * each table name provided has a wpdb prefix attached, and that it exists.
1525
+	 * Returns the list actually deleted
1526
+	 *
1527
+	 * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1528
+	 * @global WPDB $wpdb
1529
+	 * @param array $table_names
1530
+	 * @return array of table names which we deleted
1531
+	 */
1532
+	public static function drop_tables($table_names)
1533
+	{
1534
+		return \EEH_Activation::getTableManager()->dropTables($table_names);
1535
+	}
1536
+
1537
+
1538
+
1539
+	/**
1540
+	 * plugin_uninstall
1541
+	 *
1542
+	 * @access public
1543
+	 * @static
1544
+	 * @param bool $remove_all
1545
+	 * @return void
1546
+	 */
1547
+	public static function delete_all_espresso_tables_and_data($remove_all = true)
1548
+	{
1549
+		global $wpdb;
1550
+		self::drop_espresso_tables();
1551
+		$wp_options_to_delete = array(
1552
+			'ee_no_ticket_prices'                => true,
1553
+			'ee_active_messengers'               => true,
1554
+			'ee_has_activated_messenger'         => true,
1555
+			'ee_flush_rewrite_rules'             => true,
1556
+			'ee_config'                          => false,
1557
+			'ee_data_migration_current_db_state' => true,
1558
+			'ee_data_migration_mapping_'         => false,
1559
+			'ee_data_migration_script_'          => false,
1560
+			'ee_data_migrations'                 => true,
1561
+			'ee_dms_map'                         => false,
1562
+			'ee_notices'                         => true,
1563
+			'lang_file_check_'                   => false,
1564
+			'ee_maintenance_mode'                => true,
1565
+			'ee_ueip_optin'                      => true,
1566
+			'ee_ueip_has_notified'               => true,
1567
+			'ee_plugin_activation_errors'        => true,
1568
+			'ee_id_mapping_from'                 => false,
1569
+			'espresso_persistent_admin_notices'  => true,
1570
+			'ee_encryption_key'                  => true,
1571
+			'pue_force_upgrade_'                 => false,
1572
+			'pue_json_error_'                    => false,
1573
+			'pue_install_key_'                   => false,
1574
+			'pue_verification_error_'            => false,
1575
+			'pu_dismissed_upgrade_'              => false,
1576
+			'external_updates-'                  => false,
1577
+			'ee_extra_data'                      => true,
1578
+			'ee_ssn_'                            => false,
1579
+			'ee_rss_'                            => false,
1580
+			'ee_rte_n_tx_'                       => false,
1581
+			'ee_pers_admin_notices'              => true,
1582
+			'ee_job_parameters_'                 => false,
1583
+			'ee_upload_directories_incomplete'   => true,
1584
+			'ee_verified_db_collations'          => true,
1585
+		);
1586
+		if (is_main_site()) {
1587
+			$wp_options_to_delete['ee_network_config'] = true;
1588
+		}
1589
+		$undeleted_options = array();
1590
+		foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1591
+			if ($no_wildcard) {
1592
+				if ( ! delete_option($option_name)) {
1593
+					$undeleted_options[] = $option_name;
1594
+				}
1595
+			} else {
1596
+				$option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1597
+				foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1598
+					if ( ! delete_option($option_name_from_wildcard)) {
1599
+						$undeleted_options[] = $option_name_from_wildcard;
1600
+					}
1601
+				}
1602
+			}
1603
+		}
1604
+		//also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1605
+		remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1606
+		if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1607
+			$db_update_sans_ee4 = array();
1608
+			foreach ($espresso_db_update as $version => $times_activated) {
1609
+				if ((string)$version[0] === '3') {//if its NON EE4
1610
+					$db_update_sans_ee4[$version] = $times_activated;
1611
+				}
1612
+			}
1613
+			update_option('espresso_db_update', $db_update_sans_ee4);
1614
+		}
1615
+		$errors = '';
1616
+		if ( ! empty($undeleted_options)) {
1617
+			$errors .= sprintf(
1618
+				__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1619
+				'<br/>',
1620
+				implode(',<br/>', $undeleted_options)
1621
+			);
1622
+		}
1623
+		if ( ! empty($errors)) {
1624
+			EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1625
+		}
1626
+	}
1627
+
1628
+	/**
1629
+	 * Gets the mysql error code from the last used query by wpdb
1630
+	 *
1631
+	 * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1632
+	 */
1633
+	public static function last_wpdb_error_code()
1634
+	{
1635
+		global $wpdb;
1636
+		if ($wpdb->use_mysqli) {
1637
+			return mysqli_errno($wpdb->dbh);
1638
+		} else {
1639
+			return mysql_errno($wpdb->dbh);
1640
+		}
1641
+	}
1642
+
1643
+	/**
1644
+	 * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1645
+	 *
1646
+	 * @global wpdb  $wpdb
1647
+	 * @deprecated instead use TableAnalysis::tableExists()
1648
+	 * @param string $table_name with or without $wpdb->prefix
1649
+	 * @return boolean
1650
+	 */
1651
+	public static function table_exists($table_name)
1652
+	{
1653
+		return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1654
+	}
1655
+
1656
+	/**
1657
+	 * Resets the cache on EEH_Activation
1658
+	 */
1659
+	public static function reset()
1660
+	{
1661
+		self::$_default_creator_id                             = null;
1662
+		self::$_initialized_db_content_already_in_this_request = false;
1663
+	}
1664 1664
 }
1665 1665
 // End of file EEH_Activation.helper.php
1666 1666
 // Location: /helpers/EEH_Activation.core.php
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      */
58 58
     public static function getTableAnalysis()
59 59
     {
60
-        if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
60
+        if ( ! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
61 61
             self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
62 62
         }
63 63
         return self::$table_analysis;
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
      */
70 70
     public static function getTableManager()
71 71
     {
72
-        if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
72
+        if ( ! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
73 73
             self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
74 74
         }
75 75
         return self::$table_manager;
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
         if ($which_to_include === 'old') {
184 184
             $cron_tasks = array_filter(
185 185
                 $cron_tasks,
186
-                function ($value) {
186
+                function($value) {
187 187
                     return $value === EEH_Activation::cron_task_no_longer_in_use;
188 188
                 }
189 189
             );
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
     {
214 214
 
215 215
         foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
216
-            if (! wp_next_scheduled($hook_name)) {
216
+            if ( ! wp_next_scheduled($hook_name)) {
217 217
                 /**
218 218
                  * This allows client code to define the initial start timestamp for this schedule.
219 219
                  */
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
             3
319 319
         );
320 320
         //EE_Config::reset();
321
-        if (! EE_Config::logging_enabled()) {
321
+        if ( ! EE_Config::logging_enabled()) {
322 322
             delete_option(EE_Config::LOG_NAME);
323 323
         }
324 324
     }
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
     public static function load_calendar_config()
334 334
     {
335 335
         // grab array of all plugin folders and loop thru it
336
-        $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
336
+        $plugins = glob(WP_PLUGIN_DIR.DS.'*', GLOB_ONLYDIR);
337 337
         if (empty($plugins)) {
338 338
             return;
339 339
         }
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
                 || strpos($plugin, 'calendar') !== false
351 351
             ) {
352 352
                 // this is what we are looking for
353
-                $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
353
+                $calendar_config = $plugin_path.DS.'EE_Calendar_Config.php';
354 354
                 // does it exist in this folder ?
355 355
                 if (is_readable($calendar_config)) {
356 356
                     // YEAH! let's load it
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
             ) {
479 479
                 //update Config with post ID
480 480
                 $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
481
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
481
+                if ( ! EE_Config::instance()->update_espresso_config(false, false)) {
482 482
                     $msg = __(
483 483
                         'The Event Espresso critical page configuration settings could not be updated.',
484 484
                         'event_espresso'
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
                         'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
502 502
                         'event_espresso'
503 503
                     ),
504
-                    '<a href="' . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') . '">'
504
+                    '<a href="'.admin_url('admin.php?page=espresso_general_settings&action=critical_pages').'">'
505 505
                     . __('Event Espresso Critical Pages Settings', 'event_espresso')
506 506
                     . '</a>'
507 507
                 )
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
     public static function get_page_by_ee_shortcode($ee_shortcode)
528 528
     {
529 529
         global $wpdb;
530
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
530
+        $shortcode_and_opening_bracket = '['.$ee_shortcode;
531 531
         $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
532 532
         if ($post_id) {
533 533
             return get_post($post_id);
@@ -553,11 +553,11 @@  discard block
 block discarded – undo
553 553
             'post_status'    => 'publish',
554 554
             'post_type'      => 'page',
555 555
             'comment_status' => 'closed',
556
-            'post_content'   => '[' . $critical_page['code'] . ']',
556
+            'post_content'   => '['.$critical_page['code'].']',
557 557
         );
558 558
 
559 559
         $post_id = wp_insert_post($post_args);
560
-        if (! $post_id) {
560
+        if ( ! $post_id) {
561 561
             $msg = sprintf(
562 562
                 __('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
563 563
                 $critical_page['name']
@@ -566,7 +566,7 @@  discard block
 block discarded – undo
566 566
             return $critical_page;
567 567
         }
568 568
         // get newly created post's details
569
-        if (! $critical_page['post'] = get_post($post_id)) {
569
+        if ( ! $critical_page['post'] = get_post($post_id)) {
570 570
             $msg = sprintf(
571 571
                 __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
572 572
                 $critical_page['name']
@@ -603,17 +603,17 @@  discard block
 block discarded – undo
603 603
             $role_to_check
604 604
         );
605 605
         if ($pre_filtered_id !== false) {
606
-            return (int)$pre_filtered_id;
606
+            return (int) $pre_filtered_id;
607 607
         }
608 608
         $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
609 609
         $query = $wpdb->prepare(
610 610
             "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
611
-            '%' . $role_to_check . '%'
611
+            '%'.$role_to_check.'%'
612 612
         );
613 613
         $user_id = $wpdb->get_var($query);
614 614
         $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
615
-        if ($user_id && (int)$user_id) {
616
-            self::$_default_creator_id = (int)$user_id;
615
+        if ($user_id && (int) $user_id) {
616
+            self::$_default_creator_id = (int) $user_id;
617 617
             return self::$_default_creator_id;
618 618
         } else {
619 619
             return null;
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
         }
649 649
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
650 650
         if ( ! function_exists('dbDelta')) {
651
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
651
+            require_once(ABSPATH.'wp-admin/includes/upgrade.php');
652 652
         }
653 653
         $tableAnalysis = \EEH_Activation::getTableAnalysis();
654 654
         $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
@@ -859,13 +859,13 @@  discard block
 block discarded – undo
859 859
             // reset values array
860 860
             $QSG_values = array();
861 861
             // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
862
-            if (! in_array("$QSG_system", $question_groups)) {
862
+            if ( ! in_array("$QSG_system", $question_groups)) {
863 863
                 // add it
864 864
                 switch ($QSG_system) {
865 865
                     case 1:
866 866
                         $QSG_values = array(
867 867
                             'QSG_name'            => __('Personal Information', 'event_espresso'),
868
-                            'QSG_identifier'      => 'personal-information-' . time(),
868
+                            'QSG_identifier'      => 'personal-information-'.time(),
869 869
                             'QSG_desc'            => '',
870 870
                             'QSG_order'           => 1,
871 871
                             'QSG_show_group_name' => 1,
@@ -877,7 +877,7 @@  discard block
 block discarded – undo
877 877
                     case 2:
878 878
                         $QSG_values = array(
879 879
                             'QSG_name'            => __('Address Information', 'event_espresso'),
880
-                            'QSG_identifier'      => 'address-information-' . time(),
880
+                            'QSG_identifier'      => 'address-information-'.time(),
881 881
                             'QSG_desc'            => '',
882 882
                             'QSG_order'           => 2,
883 883
                             'QSG_show_group_name' => 1,
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
                         break;
889 889
                 }
890 890
                 // make sure we have some values before inserting them
891
-                if (! empty($QSG_values)) {
891
+                if ( ! empty($QSG_values)) {
892 892
                     // insert system question
893 893
                     $wpdb->insert(
894 894
                         $table_name,
@@ -925,7 +925,7 @@  discard block
 block discarded – undo
925 925
             // reset values array
926 926
             $QST_values = array();
927 927
             // if we don't have what we should have
928
-            if (! in_array($QST_system, $questions)) {
928
+            if ( ! in_array($QST_system, $questions)) {
929 929
                 // add it
930 930
                 switch ($QST_system) {
931 931
                     case 'fname':
@@ -1077,7 +1077,7 @@  discard block
 block discarded – undo
1077 1077
                         );
1078 1078
                         break;
1079 1079
                 }
1080
-                if (! empty($QST_values)) {
1080
+                if ( ! empty($QST_values)) {
1081 1081
                     // insert system question
1082 1082
                     $wpdb->insert(
1083 1083
                         $table_name,
@@ -1138,7 +1138,7 @@  discard block
 block discarded – undo
1138 1138
      */
1139 1139
     public static function insert_default_payment_methods()
1140 1140
     {
1141
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1141
+        if ( ! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1142 1142
             EE_Registry::instance()->load_lib('Payment_Method_Manager');
1143 1143
             EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1144 1144
         } else {
@@ -1427,7 +1427,7 @@  discard block
 block discarded – undo
1427 1427
         // this creates an array for tracking events that have no active ticket prices created
1428 1428
         // this allows us to warn admins of the situation so that it can be corrected
1429 1429
         $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1430
-        if (! $espresso_no_ticket_prices) {
1430
+        if ( ! $espresso_no_ticket_prices) {
1431 1431
             add_option('ee_no_ticket_prices', array(), '', false);
1432 1432
         }
1433 1433
     }
@@ -1466,7 +1466,7 @@  discard block
 block discarded – undo
1466 1466
             }
1467 1467
         }
1468 1468
         //get all our CPTs
1469
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1469
+        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (".implode(",", $ee_post_types).")";
1470 1470
         $cpt_ids = $wpdb->get_col($query);
1471 1471
         //delete each post meta and term relations too
1472 1472
         foreach ($cpt_ids as $post_id) {
@@ -1606,7 +1606,7 @@  discard block
 block discarded – undo
1606 1606
         if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1607 1607
             $db_update_sans_ee4 = array();
1608 1608
             foreach ($espresso_db_update as $version => $times_activated) {
1609
-                if ((string)$version[0] === '3') {//if its NON EE4
1609
+                if ((string) $version[0] === '3') {//if its NON EE4
1610 1610
                     $db_update_sans_ee4[$version] = $times_activated;
1611 1611
                 }
1612 1612
             }
Please login to merge, or discard this patch.
reg_steps/payment_options/EE_SPCO_Reg_Step_Payment_Options.class.php 1 patch
Indentation   +2870 added lines, -2870 removed lines patch added patch discarded remove patch
@@ -15,2874 +15,2874 @@
 block discarded – undo
15 15
 class EE_SPCO_Reg_Step_Payment_Options extends EE_SPCO_Reg_Step
16 16
 {
17 17
 
18
-    /**
19
-     * @access protected
20
-     * @var EE_Line_Item_Display $Line_Item_Display
21
-     */
22
-    protected $line_item_display;
23
-
24
-    /**
25
-     * @access protected
26
-     * @var boolean $handle_IPN_in_this_request
27
-     */
28
-    protected $handle_IPN_in_this_request = false;
29
-
30
-
31
-    /**
32
-     *    set_hooks - for hooking into EE Core, other modules, etc
33
-     *
34
-     * @access    public
35
-     * @return    void
36
-     */
37
-    public static function set_hooks()
38
-    {
39
-        add_filter(
40
-            'FHEE__SPCO__EE_Line_Item_Filter_Collection',
41
-            array('EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters')
42
-        );
43
-        add_action(
44
-            'wp_ajax_switch_spco_billing_form',
45
-            array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form')
46
-        );
47
-        add_action(
48
-            'wp_ajax_nopriv_switch_spco_billing_form',
49
-            array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form')
50
-        );
51
-        add_action('wp_ajax_save_payer_details', array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details'));
52
-        add_action(
53
-            'wp_ajax_nopriv_save_payer_details',
54
-            array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details')
55
-        );
56
-        add_action(
57
-            'wp_ajax_get_transaction_details_for_gateways',
58
-            array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details')
59
-        );
60
-        add_action(
61
-            'wp_ajax_nopriv_get_transaction_details_for_gateways',
62
-            array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details')
63
-        );
64
-        add_filter(
65
-            'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
66
-            array('EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'),
67
-            10,
68
-            1
69
-        );
70
-    }
71
-
72
-
73
-    /**
74
-     *    ajax switch_spco_billing_form
75
-     *
76
-     * @throws \EE_Error
77
-     */
78
-    public static function switch_spco_billing_form()
79
-    {
80
-        EED_Single_Page_Checkout::process_ajax_request('switch_payment_method');
81
-    }
82
-
83
-
84
-    /**
85
-     *    ajax save_payer_details
86
-     *
87
-     * @throws \EE_Error
88
-     */
89
-    public static function save_payer_details()
90
-    {
91
-        EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax');
92
-    }
93
-
94
-
95
-    /**
96
-     *    ajax get_transaction_details
97
-     *
98
-     * @throws \EE_Error
99
-     */
100
-    public static function get_transaction_details()
101
-    {
102
-        EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways');
103
-    }
104
-
105
-
106
-    /**
107
-     * bypass_recaptcha_for_load_payment_method
108
-     *
109
-     * @access public
110
-     * @return array
111
-     * @throws InvalidArgumentException
112
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
113
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
114
-     */
115
-    public static function bypass_recaptcha_for_load_payment_method()
116
-    {
117
-        return array(
118
-            'EESID'  => EE_Registry::instance()->SSN->id(),
119
-            'step'   => 'payment_options',
120
-            'action' => 'spco_billing_form',
121
-        );
122
-    }
123
-
124
-
125
-    /**
126
-     *    class constructor
127
-     *
128
-     * @access    public
129
-     * @param    EE_Checkout $checkout
130
-     */
131
-    public function __construct(EE_Checkout $checkout)
132
-    {
133
-        $this->_slug     = 'payment_options';
134
-        $this->_name     = esc_html__('Payment Options', 'event_espresso');
135
-        $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'payment_options_main.template.php';
136
-        $this->checkout  = $checkout;
137
-        $this->_reset_success_message();
138
-        $this->set_instructions(
139
-            esc_html__(
140
-                'Please select a method of payment and provide any necessary billing information before proceeding.',
141
-                'event_espresso'
142
-            )
143
-        );
144
-    }
145
-
146
-
147
-    /**
148
-     * @return null
149
-     */
150
-    public function line_item_display()
151
-    {
152
-        return $this->line_item_display;
153
-    }
154
-
155
-
156
-    /**
157
-     * @param null $line_item_display
158
-     */
159
-    public function set_line_item_display($line_item_display)
160
-    {
161
-        $this->line_item_display = $line_item_display;
162
-    }
163
-
164
-
165
-    /**
166
-     * @return boolean
167
-     */
168
-    public function handle_IPN_in_this_request()
169
-    {
170
-        return $this->handle_IPN_in_this_request;
171
-    }
172
-
173
-
174
-    /**
175
-     * @param boolean $handle_IPN_in_this_request
176
-     */
177
-    public function set_handle_IPN_in_this_request($handle_IPN_in_this_request)
178
-    {
179
-        $this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN);
180
-    }
181
-
182
-
183
-    /**
184
-     * translate_js_strings
185
-     *
186
-     * @return void
187
-     */
188
-    public function translate_js_strings()
189
-    {
190
-        EE_Registry::$i18n_js_strings['no_payment_method']      = esc_html__(
191
-            'Please select a method of payment in order to continue.',
192
-            'event_espresso'
193
-        );
194
-        EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__(
195
-            'A valid method of payment could not be determined. Please refresh the page and try again.',
196
-            'event_espresso'
197
-        );
198
-        EE_Registry::$i18n_js_strings['forwarding_to_offsite']  = esc_html__(
199
-            'Forwarding to Secure Payment Provider.',
200
-            'event_espresso'
201
-        );
202
-    }
203
-
204
-
205
-    /**
206
-     * enqueue_styles_and_scripts
207
-     *
208
-     * @return void
209
-     * @throws EE_Error
210
-     * @throws InvalidArgumentException
211
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
212
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
213
-     */
214
-    public function enqueue_styles_and_scripts()
215
-    {
216
-        $transaction = $this->checkout->transaction;
217
-        //if the transaction isn't set or nothing is owed on it, don't enqueue any JS
218
-        if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) {
219
-            return;
220
-        }
221
-        foreach (EEM_Payment_Method::instance()->get_all_for_transaction($transaction, EEM_Payment_Method::scope_cart) as $payment_method) {
222
-            $type_obj = $payment_method->type_obj();
223
-            if ($type_obj instanceof EE_PMT_Base) {
224
-                $billing_form = $type_obj->generate_new_billing_form($transaction);
225
-                if ($billing_form instanceof EE_Form_Section_Proper) {
226
-                    $billing_form->enqueue_js();
227
-                }
228
-            }
229
-        }
230
-    }
231
-
232
-
233
-    /**
234
-     * initialize_reg_step
235
-     *
236
-     * @return bool
237
-     * @throws EE_Error
238
-     * @throws InvalidArgumentException
239
-     * @throws ReflectionException
240
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
241
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
242
-     */
243
-    public function initialize_reg_step()
244
-    {
245
-        // TODO: if /when we implement donations, then this will need overriding
246
-        if (// don't need payment options for:
247
-            // 	registrations made via the admin
248
-            // 	completed transactions
249
-            // 	overpaid transactions
250
-            // 	$ 0.00 transactions (no payment required)
251
-            ! $this->checkout->payment_required()
252
-            // but do NOT remove if current action being called belongs to this reg step
253
-            && ! is_callable(array($this, $this->checkout->action))
254
-            && ! $this->completed()
255
-        ) {
256
-            // and if so, then we no longer need the Payment Options step
257
-            if ($this->is_current_step()) {
258
-                $this->checkout->generate_reg_form = false;
259
-            }
260
-            $this->checkout->remove_reg_step($this->_slug);
261
-            // DEBUG LOG
262
-            //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
263
-            return false;
264
-        }
265
-        // load EEM_Payment_Method
266
-        EE_Registry::instance()->load_model('Payment_Method');
267
-        // get all active payment methods
268
-        $this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction(
269
-            $this->checkout->transaction,
270
-            EEM_Payment_Method::scope_cart
271
-        );
272
-        return true;
273
-    }
274
-
275
-
276
-    /**
277
-     * @return EE_Form_Section_Proper
278
-     * @throws EE_Error
279
-     * @throws InvalidArgumentException
280
-     * @throws ReflectionException
281
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
282
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
283
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
284
-     * @throws \EventEspresso\core\exceptions\InvalidStatusException
285
-     */
286
-    public function generate_reg_form()
287
-    {
288
-        // reset in case someone changes their mind
289
-        $this->_reset_selected_method_of_payment();
290
-        // set some defaults
291
-        $this->checkout->selected_method_of_payment = 'payments_closed';
292
-        $registrations_requiring_payment            = array();
293
-        $registrations_for_free_events              = array();
294
-        $registrations_requiring_pre_approval       = array();
295
-        $sold_out_events                            = array();
296
-        $insufficient_spaces_available              = array();
297
-        $no_payment_required                        = true;
298
-        // loop thru registrations to gather info
299
-        $registrations         = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
300
-        $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space(
301
-            $registrations,
302
-            $this->checkout->revisit
303
-        );
304
-        foreach ($registrations as $REG_ID => $registration) {
305
-            /** @var $registration EE_Registration */
306
-            // has this registration lost it's space ?
307
-            if (isset($ejected_registrations[ $REG_ID ])) {
308
-                if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) {
309
-                    $sold_out_events[ $registration->event()->ID() ] = $registration->event();
310
-                } else {
311
-                    $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event();
312
-                }
313
-                continue;
314
-            }
315
-            // event requires admin approval
316
-            if ($registration->status_ID() === EEM_Registration::status_id_not_approved) {
317
-                // add event to list of events with pre-approval reg status
318
-                $registrations_requiring_pre_approval[$REG_ID] = $registration;
319
-                do_action(
320
-                    'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval',
321
-                    $registration->event(),
322
-                    $this
323
-                );
324
-                continue;
325
-            }
326
-            if ($this->checkout->revisit
327
-                && $registration->status_ID() !== EEM_Registration::status_id_approved
328
-                && (
329
-                    $registration->event()->is_sold_out()
330
-                    || $registration->event()->is_sold_out(true)
331
-                )
332
-            ) {
333
-                // add event to list of events that are sold out
334
-                $sold_out_events[$registration->event()->ID()] = $registration->event();
335
-                do_action(
336
-                    'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event',
337
-                    $registration->event(),
338
-                    $this
339
-                );
340
-                continue;
341
-            }
342
-            // are they allowed to pay now and is there monies owing?
343
-            if ($registration->owes_monies_and_can_pay()) {
344
-                $registrations_requiring_payment[$REG_ID] = $registration;
345
-                do_action(
346
-                    'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment',
347
-                    $registration->event(),
348
-                    $this
349
-                );
350
-            } elseif (! $this->checkout->revisit
351
-                && $registration->status_ID() !== EEM_Registration::status_id_not_approved
352
-                && $registration->ticket()->is_free()
353
-            ) {
354
-                $registrations_for_free_events[$registration->event()->ID()] = $registration;
355
-            }
356
-        }
357
-        $subsections = array();
358
-        // now decide which template to load
359
-        if (! empty($sold_out_events)) {
360
-            $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events);
361
-        }
362
-        if (! empty($insufficient_spaces_available)) {
363
-            $subsections['insufficient_space'] = $this->_insufficient_spaces_available(
364
-                $insufficient_spaces_available
365
-            );
366
-        }
367
-        if (! empty($registrations_requiring_pre_approval)) {
368
-            $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval(
369
-                $registrations_requiring_pre_approval
370
-            );
371
-        }
372
-        if (! empty($registrations_for_free_events)) {
373
-            $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events);
374
-        }
375
-        if (! empty($registrations_requiring_payment)) {
376
-            if ($this->checkout->amount_owing > 0) {
377
-                // autoload Line_Item_Display classes
378
-                EEH_Autoloader::register_line_item_filter_autoloaders();
379
-                $line_item_filter_processor = new EE_Line_Item_Filter_Processor(
380
-                    apply_filters(
381
-                        'FHEE__SPCO__EE_Line_Item_Filter_Collection',
382
-                        new EE_Line_Item_Filter_Collection()
383
-                    ),
384
-                    $this->checkout->cart->get_grand_total()
385
-                );
386
-                /** @var EE_Line_Item $filtered_line_item_tree */
387
-                $filtered_line_item_tree = $line_item_filter_processor->process();
388
-                EEH_Autoloader::register_line_item_display_autoloaders();
389
-                $this->set_line_item_display(new EE_Line_Item_Display('spco'));
390
-                $subsections['payment_options'] = $this->_display_payment_options(
391
-                    $this->line_item_display->display_line_item(
392
-                        $filtered_line_item_tree,
393
-                        array('registrations' => $registrations)
394
-                    )
395
-                );
396
-                $this->checkout->amount_owing   = $filtered_line_item_tree->total();
397
-                $this->_apply_registration_payments_to_amount_owing($registrations);
398
-            }
399
-            $no_payment_required = false;
400
-        } else {
401
-            $this->_hide_reg_step_submit_button_if_revisit();
402
-        }
403
-        $this->_save_selected_method_of_payment();
404
-
405
-        $subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs();
406
-        $subsections['extra_hidden_inputs']   = $this->_extra_hidden_inputs($no_payment_required);
407
-
408
-        return new EE_Form_Section_Proper(
409
-            array(
410
-                'name'            => $this->reg_form_name(),
411
-                'html_id'         => $this->reg_form_name(),
412
-                'subsections'     => $subsections,
413
-                'layout_strategy' => new EE_No_Layout(),
414
-            )
415
-        );
416
-    }
417
-
418
-
419
-    /**
420
-     * add line item filters required for this reg step
421
-     * these filters are applied via this line in EE_SPCO_Reg_Step_Payment_Options::set_hooks():
422
-     *        add_filter( 'FHEE__SPCO__EE_Line_Item_Filter_Collection', array( 'EE_SPCO_Reg_Step_Payment_Options',
423
-     *        'add_spco_line_item_filters' ) ); so any code that wants to use the same set of filters during the
424
-     *        payment options reg step, can apply these filters via the following: apply_filters(
425
-     *        'FHEE__SPCO__EE_Line_Item_Filter_Collection', new EE_Line_Item_Filter_Collection() ) or to an existing
426
-     *        filter collection by passing that instead of instantiating a new collection
427
-     *
428
-     * @param \EE_Line_Item_Filter_Collection $line_item_filter_collection
429
-     * @return EE_Line_Item_Filter_Collection
430
-     * @throws EE_Error
431
-     * @throws InvalidArgumentException
432
-     * @throws ReflectionException
433
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
434
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
435
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
436
-     * @throws \EventEspresso\core\exceptions\InvalidStatusException
437
-     */
438
-    public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection)
439
-    {
440
-        if (! EE_Registry::instance()->SSN instanceof EE_Session) {
441
-            return $line_item_filter_collection;
442
-        }
443
-        if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) {
444
-            return $line_item_filter_collection;
445
-        }
446
-        if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) {
447
-            return $line_item_filter_collection;
448
-        }
449
-        $line_item_filter_collection->add(
450
-            new EE_Billable_Line_Item_Filter(
451
-                EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations(
452
-                    EE_Registry::instance()->SSN->checkout()->transaction->registrations(
453
-                        EE_Registry::instance()->SSN->checkout()->reg_cache_where_params
454
-                    )
455
-                )
456
-            )
457
-        );
458
-        $line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter());
459
-        return $line_item_filter_collection;
460
-    }
461
-
462
-
463
-    /**
464
-     * remove_ejected_registrations
465
-     * if a registrant has lost their potential space at an event due to lack of payment,
466
-     * then this method removes them from the list of registrations being paid for during this request
467
-     *
468
-     * @param \EE_Registration[] $registrations
469
-     * @return EE_Registration[]
470
-     * @throws EE_Error
471
-     * @throws InvalidArgumentException
472
-     * @throws ReflectionException
473
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
474
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
475
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
476
-     * @throws \EventEspresso\core\exceptions\InvalidStatusException
477
-     */
478
-    public static function remove_ejected_registrations(array $registrations)
479
-    {
480
-        $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space(
481
-            $registrations,
482
-            EE_Registry::instance()->SSN->checkout()->revisit
483
-        );
484
-        foreach ($registrations as $REG_ID => $registration) {
485
-            // has this registration lost it's space ?
486
-            if (isset($ejected_registrations[$REG_ID])) {
487
-                unset($registrations[$REG_ID]);
488
-                continue;
489
-            }
490
-        }
491
-        return $registrations;
492
-    }
493
-
494
-
495
-    /**
496
-     * find_registrations_that_lost_their_space
497
-     * If a registrant chooses an offline payment method like Invoice,
498
-     * then no space is reserved for them at the event until they fully pay fo that site
499
-     * (unless the event's default reg status is set to APPROVED)
500
-     * if a registrant then later returns to pay, but the number of spaces available has been reduced due to sales,
501
-     * then this method will determine which registrations have lost the ability to complete the reg process.
502
-     *
503
-     * @param \EE_Registration[] $registrations
504
-     * @param bool               $revisit
505
-     * @return array
506
-     * @throws EE_Error
507
-     * @throws InvalidArgumentException
508
-     * @throws ReflectionException
509
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
510
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
511
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
512
-     * @throws \EventEspresso\core\exceptions\InvalidStatusException
513
-     */
514
-    public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false)
515
-    {
516
-        // registrations per event
517
-        $event_reg_count = array();
518
-        // spaces left per event
519
-        $event_spaces_remaining = array();
520
-        // tickets left sorted by ID
521
-        $tickets_remaining = array();
522
-        // registrations that have lost their space
523
-        $ejected_registrations = array();
524
-        foreach ($registrations as $REG_ID => $registration) {
525
-            if ($registration->status_ID() === EEM_Registration::status_id_approved
526
-                || apply_filters(
527
-                    'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment',
528
-                    false,
529
-                    $registration,
530
-                    $revisit
531
-                )
532
-            ) {
533
-                continue;
534
-            }
535
-            $EVT_ID = $registration->event_ID();
536
-            $ticket = $registration->ticket();
537
-            if (! isset($tickets_remaining[$ticket->ID()])) {
538
-                $tickets_remaining[$ticket->ID()] = $ticket->remaining();
539
-            }
540
-            if ($tickets_remaining[$ticket->ID()] > 0) {
541
-                if (! isset($event_reg_count[$EVT_ID])) {
542
-                    $event_reg_count[$EVT_ID] = 0;
543
-                }
544
-                $event_reg_count[$EVT_ID]++;
545
-                if (! isset($event_spaces_remaining[$EVT_ID])) {
546
-                    $event_spaces_remaining[$EVT_ID] = $registration->event()->spaces_remaining_for_sale();
547
-                }
548
-            }
549
-            if ($revisit
550
-                && ($tickets_remaining[$ticket->ID()] === 0
551
-                    || $event_reg_count[$EVT_ID] > $event_spaces_remaining[$EVT_ID]
552
-                )
553
-            ) {
554
-                $ejected_registrations[$REG_ID] = $registration->event();
555
-                if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) {
556
-                    /** @type EE_Registration_Processor $registration_processor */
557
-                    $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
558
-                    // at this point, we should have enough details about the registrant to consider the registration
559
-                    // NOT incomplete
560
-                    $registration_processor->manually_update_registration_status(
561
-                        $registration,
562
-                        EEM_Registration::status_id_wait_list
563
-                    );
564
-                }
565
-            }
566
-        }
567
-        return $ejected_registrations;
568
-    }
569
-
570
-
571
-    /**
572
-     * _hide_reg_step_submit_button
573
-     * removes the html for the reg step submit button
574
-     * by replacing it with an empty string via filter callback
575
-     *
576
-     * @return void
577
-     */
578
-    protected function _adjust_registration_status_if_event_old_sold()
579
-    {
580
-    }
581
-
582
-
583
-    /**
584
-     * _hide_reg_step_submit_button
585
-     * removes the html for the reg step submit button
586
-     * by replacing it with an empty string via filter callback
587
-     *
588
-     * @return void
589
-     */
590
-    protected function _hide_reg_step_submit_button_if_revisit()
591
-    {
592
-        if ($this->checkout->revisit) {
593
-            add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string');
594
-        }
595
-    }
596
-
597
-
598
-    /**
599
-     * sold_out_events
600
-     * displays notices regarding events that have sold out since hte registrant first signed up
601
-     *
602
-     * @param \EE_Event[] $sold_out_events_array
603
-     * @return \EE_Form_Section_Proper
604
-     * @throws \EE_Error
605
-     */
606
-    private function _sold_out_events($sold_out_events_array = array())
607
-    {
608
-        // set some defaults
609
-        $this->checkout->selected_method_of_payment = 'events_sold_out';
610
-        $sold_out_events                            = '';
611
-        foreach ($sold_out_events_array as $sold_out_event) {
612
-            $sold_out_events .= EEH_HTML::li(
613
-                EEH_HTML::span(
614
-                    '  ' . $sold_out_event->name(),
615
-                    '',
616
-                    'dashicons dashicons-marker ee-icon-size-16 pink-text'
617
-                )
618
-            );
619
-        }
620
-        return new EE_Form_Section_Proper(
621
-            array(
622
-                'layout_strategy' => new EE_Template_Layout(
623
-                    array(
624
-                        'layout_template_file' => SPCO_REG_STEPS_PATH
625
-                                                  . $this->_slug
626
-                                                  . DS
627
-                                                  . 'sold_out_events.template.php',
628
-                        'template_args'        => apply_filters(
629
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args',
630
-                            array(
631
-                                'sold_out_events'     => $sold_out_events,
632
-                                'sold_out_events_msg' => apply_filters(
633
-                                    'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg',
634
-                                    sprintf(
635
-                                        esc_html__(
636
-                                            'It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s',
637
-                                            'event_espresso'
638
-                                        ),
639
-                                        '<strong>',
640
-                                        '</strong>',
641
-                                        '<br />'
642
-                                    )
643
-                                ),
644
-                            )
645
-                        ),
646
-                    )
647
-                ),
648
-            )
649
-        );
650
-    }
651
-
652
-
653
-    /**
654
-     * _insufficient_spaces_available
655
-     * displays notices regarding events that do not have enough remaining spaces
656
-     * to satisfy the current number of registrations looking to pay
657
-     *
658
-     * @param \EE_Event[] $insufficient_spaces_events_array
659
-     * @return \EE_Form_Section_Proper
660
-     * @throws \EE_Error
661
-     */
662
-    private function _insufficient_spaces_available($insufficient_spaces_events_array = array())
663
-    {
664
-        // set some defaults
665
-        $this->checkout->selected_method_of_payment = 'invoice';
666
-        $insufficient_space_events                  = '';
667
-        foreach ($insufficient_spaces_events_array as $event) {
668
-            if ($event instanceof EE_Event) {
669
-                $insufficient_space_events .= EEH_HTML::li(
670
-                    EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text')
671
-                );
672
-            }
673
-        }
674
-        return new EE_Form_Section_Proper(
675
-            array(
676
-                'subsections'     => array(
677
-                    'default_hidden_inputs' => $this->reg_step_hidden_inputs(),
678
-                    'extra_hidden_inputs'   => $this->_extra_hidden_inputs(),
679
-                ),
680
-                'layout_strategy' => new EE_Template_Layout(
681
-                    array(
682
-                        'layout_template_file' => SPCO_REG_STEPS_PATH
683
-                                                  . $this->_slug
684
-                                                  . DS
685
-                                                  . 'sold_out_events.template.php',
686
-                        'template_args'        => apply_filters(
687
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args',
688
-                            array(
689
-                                'sold_out_events'     => $insufficient_space_events,
690
-                                'sold_out_events_msg' => apply_filters(
691
-                                    'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__insufficient_space_msg',
692
-                                    esc_html__(
693
-                                        'It appears that the event you were about to make a payment for has sold additional tickets since you first registered, and there are no longer enough spaces left to accommodate your selections. You may continue to pay and secure the available space(s) remaining, or simply cancel if you no longer wish to purchase. If you have already made a partial payment towards this event, please contact the event administrator for a refund.',
694
-                                        'event_espresso'
695
-                                    )
696
-                                ),
697
-                            )
698
-                        ),
699
-                    )
700
-                ),
701
-            )
702
-        );
703
-    }
704
-
705
-
706
-    /**
707
-     * registrations_requiring_pre_approval
708
-     *
709
-     * @param array $registrations_requiring_pre_approval
710
-     * @return EE_Form_Section_Proper
711
-     * @throws EE_Error
712
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
713
-     */
714
-    private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = array())
715
-    {
716
-        $events_requiring_pre_approval = '';
717
-        foreach ($registrations_requiring_pre_approval as $registration) {
718
-            if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) {
719
-                $events_requiring_pre_approval[$registration->event()->ID()] = EEH_HTML::li(
720
-                    EEH_HTML::span(
721
-                        '',
722
-                        '',
723
-                        'dashicons dashicons-marker ee-icon-size-16 orange-text'
724
-                    )
725
-                    . EEH_HTML::span($registration->event()->name(), '', 'orange-text')
726
-                );
727
-            }
728
-        }
729
-        return new EE_Form_Section_Proper(
730
-            array(
731
-                'layout_strategy' => new EE_Template_Layout(
732
-                    array(
733
-                        'layout_template_file' => SPCO_REG_STEPS_PATH
734
-                                                  . $this->_slug
735
-                                                  . DS
736
-                                                  . 'events_requiring_pre_approval.template.php', // layout_template
737
-                        'template_args'        => apply_filters(
738
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args',
739
-                            array(
740
-                                'events_requiring_pre_approval'     => implode('', $events_requiring_pre_approval),
741
-                                'events_requiring_pre_approval_msg' => apply_filters(
742
-                                    'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg',
743
-                                    esc_html__(
744
-                                        'The following events do not require payment at this time and will not be billed during this transaction. Billing will only occur after the attendee has been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.',
745
-                                        'event_espresso'
746
-                                    )
747
-                                ),
748
-                            )
749
-                        ),
750
-                    )
751
-                ),
752
-            )
753
-        );
754
-    }
755
-
756
-
757
-    /**
758
-     * _no_payment_required
759
-     *
760
-     * @param \EE_Event[] $registrations_for_free_events
761
-     * @return \EE_Form_Section_Proper
762
-     * @throws \EE_Error
763
-     */
764
-    private function _no_payment_required($registrations_for_free_events = array())
765
-    {
766
-        // set some defaults
767
-        $this->checkout->selected_method_of_payment = 'no_payment_required';
768
-        // generate no_payment_required form
769
-        return new EE_Form_Section_Proper(
770
-            array(
771
-                'layout_strategy' => new EE_Template_Layout(
772
-                    array(
773
-                        'layout_template_file' => SPCO_REG_STEPS_PATH
774
-                                                  . $this->_slug
775
-                                                  . DS
776
-                                                  . 'no_payment_required.template.php', // layout_template
777
-                        'template_args'        => apply_filters(
778
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args',
779
-                            array(
780
-                                'revisit'                       => $this->checkout->revisit,
781
-                                'registrations'                 => array(),
782
-                                'ticket_count'                  => array(),
783
-                                'registrations_for_free_events' => $registrations_for_free_events,
784
-                                'no_payment_required_msg'       => EEH_HTML::p(
785
-                                    esc_html__('This is a free event, so no billing will occur.', 'event_espresso')
786
-                                ),
787
-                            )
788
-                        ),
789
-                    )
790
-                ),
791
-            )
792
-        );
793
-    }
794
-
795
-
796
-    /**
797
-     * _display_payment_options
798
-     *
799
-     * @param string $transaction_details
800
-     * @return EE_Form_Section_Proper
801
-     * @throws EE_Error
802
-     * @throws InvalidArgumentException
803
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
804
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
805
-     */
806
-    private function _display_payment_options($transaction_details = '')
807
-    {
808
-        // has method_of_payment been set by no-js user?
809
-        $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment();
810
-        // build payment options form
811
-        return apply_filters(
812
-            'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__payment_options_form',
813
-            new EE_Form_Section_Proper(
814
-                array(
815
-                    'subsections'     => array(
816
-                        'before_payment_options' => apply_filters(
817
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options',
818
-                            new EE_Form_Section_Proper(
819
-                                array('layout_strategy' => new EE_Div_Per_Section_Layout())
820
-                            )
821
-                        ),
822
-                        'payment_options'        => $this->_setup_payment_options(),
823
-                        'after_payment_options'  => apply_filters(
824
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options',
825
-                            new EE_Form_Section_Proper(
826
-                                array('layout_strategy' => new EE_Div_Per_Section_Layout())
827
-                            )
828
-                        ),
829
-                    ),
830
-                    'layout_strategy' => new EE_Template_Layout(
831
-                        array(
832
-                            'layout_template_file' => $this->_template,
833
-                            'template_args'        => apply_filters(
834
-                                'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__template_args',
835
-                                array(
836
-                                    'reg_count'                 => $this->line_item_display->total_items(),
837
-                                    'transaction_details'       => $transaction_details,
838
-                                    'available_payment_methods' => array(),
839
-                                )
840
-                            ),
841
-                        )
842
-                    ),
843
-                )
844
-            )
845
-        );
846
-    }
847
-
848
-
849
-    /**
850
-     * _extra_hidden_inputs
851
-     *
852
-     * @param bool $no_payment_required
853
-     * @return \EE_Form_Section_Proper
854
-     * @throws \EE_Error
855
-     */
856
-    private function _extra_hidden_inputs($no_payment_required = true)
857
-    {
858
-        return new EE_Form_Section_Proper(
859
-            array(
860
-                'html_id'         => 'ee-' . $this->slug() . '-extra-hidden-inputs',
861
-                'layout_strategy' => new EE_Div_Per_Section_Layout(),
862
-                'subsections'     => array(
863
-                    'spco_no_payment_required' => new EE_Hidden_Input(
864
-                        array(
865
-                            'normalization_strategy' => new EE_Boolean_Normalization(),
866
-                            'html_name'              => 'spco_no_payment_required',
867
-                            'html_id'                => 'spco-no-payment-required-payment_options',
868
-                            'default'                => $no_payment_required,
869
-                        )
870
-                    ),
871
-                    'spco_transaction_id'      => new EE_Fixed_Hidden_Input(
872
-                        array(
873
-                            'normalization_strategy' => new EE_Int_Normalization(),
874
-                            'html_name'              => 'spco_transaction_id',
875
-                            'html_id'                => 'spco-transaction-id',
876
-                            'default'                => $this->checkout->transaction->ID(),
877
-                        )
878
-                    ),
879
-                ),
880
-            )
881
-        );
882
-    }
883
-
884
-
885
-    /**
886
-     *    _apply_registration_payments_to_amount_owing
887
-     *
888
-     * @access protected
889
-     * @param array $registrations
890
-     * @throws EE_Error
891
-     */
892
-    protected function _apply_registration_payments_to_amount_owing(array $registrations)
893
-    {
894
-        $payments = array();
895
-        foreach ($registrations as $registration) {
896
-            if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
897
-                $payments += $registration->registration_payments();
898
-            }
899
-        }
900
-        if (! empty($payments)) {
901
-            foreach ($payments as $payment) {
902
-                if ($payment instanceof EE_Registration_Payment) {
903
-                    $this->checkout->amount_owing -= $payment->amount();
904
-                }
905
-            }
906
-        }
907
-    }
908
-
909
-
910
-    /**
911
-     *    _reset_selected_method_of_payment
912
-     *
913
-     * @access    private
914
-     * @param    bool $force_reset
915
-     * @return void
916
-     * @throws InvalidArgumentException
917
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
918
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
919
-     */
920
-    private function _reset_selected_method_of_payment($force_reset = false)
921
-    {
922
-        $reset_payment_method = $force_reset
923
-            ? true
924
-            : sanitize_text_field(EE_Registry::instance()->REQ->get('reset_payment_method', false));
925
-        if ($reset_payment_method) {
926
-            $this->checkout->selected_method_of_payment = null;
927
-            $this->checkout->payment_method             = null;
928
-            $this->checkout->billing_form               = null;
929
-            $this->_save_selected_method_of_payment();
930
-        }
931
-    }
932
-
933
-
934
-    /**
935
-     * _save_selected_method_of_payment
936
-     * stores the selected_method_of_payment in the session
937
-     * so that it's available for all subsequent requests including AJAX
938
-     *
939
-     * @access        private
940
-     * @param string $selected_method_of_payment
941
-     * @return void
942
-     * @throws InvalidArgumentException
943
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
944
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
945
-     */
946
-    private function _save_selected_method_of_payment($selected_method_of_payment = '')
947
-    {
948
-        $selected_method_of_payment = ! empty($selected_method_of_payment)
949
-            ? $selected_method_of_payment
950
-            : $this->checkout->selected_method_of_payment;
951
-        EE_Registry::instance()->SSN->set_session_data(
952
-            array('selected_method_of_payment' => $selected_method_of_payment)
953
-        );
954
-    }
955
-
956
-
957
-    /**
958
-     * _setup_payment_options
959
-     *
960
-     * @return EE_Form_Section_Proper
961
-     * @throws EE_Error
962
-     * @throws InvalidArgumentException
963
-     * @throws ReflectionException
964
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
965
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
966
-     */
967
-    public function _setup_payment_options()
968
-    {
969
-        // load payment method classes
970
-        $this->checkout->available_payment_methods = $this->_get_available_payment_methods();
971
-        if (empty($this->checkout->available_payment_methods)) {
972
-            EE_Error::add_error(
973
-                apply_filters(
974
-                    'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__error_message_no_payment_methods',
975
-                    sprintf(
976
-                        esc_html__(
977
-                            'Sorry, you cannot complete your purchase because a payment method is not active.%1$s Please contact %2$s for assistance and provide a description of the problem.',
978
-                            'event_espresso'
979
-                        ),
980
-                        '<br>',
981
-                        EE_Registry::instance()->CFG->organization->get_pretty('email')
982
-                    )
983
-                ),
984
-                __FILE__,
985
-                __FUNCTION__,
986
-                __LINE__
987
-            );
988
-        }
989
-        // switch up header depending on number of available payment methods
990
-        $payment_method_header     = count($this->checkout->available_payment_methods) > 1
991
-            ? apply_filters(
992
-                'FHEE__registration_page_payment_options__method_of_payment_hdr',
993
-                esc_html__('Please Select Your Method of Payment', 'event_espresso')
994
-            )
995
-            : apply_filters(
996
-                'FHEE__registration_page_payment_options__method_of_payment_hdr',
997
-                esc_html__('Method of Payment', 'event_espresso')
998
-            );
999
-        $available_payment_methods = array(
1000
-            // display the "Payment Method" header
1001
-            'payment_method_header' => new EE_Form_Section_HTML(
1002
-                EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr')
1003
-            ),
1004
-        );
1005
-        // the list of actual payment methods ( invoice, paypal, etc ) in a  ( slug => HTML )  format
1006
-        $available_payment_method_options = array();
1007
-        $default_payment_method_option    = array();
1008
-        // additional instructions to be displayed and hidden below payment methods (adding a clearing div to start)
1009
-        $payment_methods_billing_info = array(
1010
-            new EE_Form_Section_HTML(
1011
-                EEH_HTML::div('<br />', '', '', 'clear:both;')
1012
-            ),
1013
-        );
1014
-        // loop through payment methods
1015
-        foreach ($this->checkout->available_payment_methods as $payment_method) {
1016
-            if ($payment_method instanceof EE_Payment_Method) {
1017
-                $payment_method_button = EEH_HTML::img(
1018
-                    $payment_method->button_url(),
1019
-                    $payment_method->name(),
1020
-                    'spco-payment-method-' . $payment_method->slug() . '-btn-img',
1021
-                    'spco-payment-method-btn-img'
1022
-                );
1023
-                // check if any payment methods are set as default
1024
-                // if payment method is already selected OR nothing is selected and this payment method should be
1025
-                // open_by_default
1026
-                if (($this->checkout->selected_method_of_payment === $payment_method->slug())
1027
-                    || (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default())
1028
-                ) {
1029
-                    $this->checkout->selected_method_of_payment = $payment_method->slug();
1030
-                    $this->_save_selected_method_of_payment();
1031
-                    $default_payment_method_option[$payment_method->slug()] = $payment_method_button;
1032
-                } else {
1033
-                    $available_payment_method_options[$payment_method->slug()] = $payment_method_button;
1034
-                }
1035
-                $payment_methods_billing_info[$payment_method->slug() . '-info'] = $this->_payment_method_billing_info(
1036
-                    $payment_method
1037
-                );
1038
-            }
1039
-        }
1040
-        // prepend available_payment_method_options with default_payment_method_option so that it appears first in list
1041
-        // of PMs
1042
-        $available_payment_method_options = $default_payment_method_option + $available_payment_method_options;
1043
-        // now generate the actual form  inputs
1044
-        $available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs(
1045
-            $available_payment_method_options
1046
-        );
1047
-        $available_payment_methods                              += $payment_methods_billing_info;
1048
-        // build the available payment methods form
1049
-        return new EE_Form_Section_Proper(
1050
-            array(
1051
-                'html_id'         => 'spco-available-methods-of-payment-dv',
1052
-                'subsections'     => $available_payment_methods,
1053
-                'layout_strategy' => new EE_Div_Per_Section_Layout(),
1054
-            )
1055
-        );
1056
-    }
1057
-
1058
-
1059
-    /**
1060
-     * _get_available_payment_methods
1061
-     *
1062
-     * @return EE_Payment_Method[]
1063
-     * @throws EE_Error
1064
-     * @throws InvalidArgumentException
1065
-     * @throws ReflectionException
1066
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1067
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1068
-     */
1069
-    protected function _get_available_payment_methods()
1070
-    {
1071
-        if (! empty($this->checkout->available_payment_methods)) {
1072
-            return $this->checkout->available_payment_methods;
1073
-        }
1074
-        $available_payment_methods = array();
1075
-        // load EEM_Payment_Method
1076
-        EE_Registry::instance()->load_model('Payment_Method');
1077
-        /** @type EEM_Payment_Method $EEM_Payment_Method */
1078
-        $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method;
1079
-        // get all active payment methods
1080
-        $payment_methods = $EEM_Payment_Method->get_all_for_transaction(
1081
-            $this->checkout->transaction,
1082
-            EEM_Payment_Method::scope_cart
1083
-        );
1084
-        foreach ($payment_methods as $payment_method) {
1085
-            if ($payment_method instanceof EE_Payment_Method) {
1086
-                $available_payment_methods[$payment_method->slug()] = $payment_method;
1087
-            }
1088
-        }
1089
-        return $available_payment_methods;
1090
-    }
1091
-
1092
-
1093
-    /**
1094
-     *    _available_payment_method_inputs
1095
-     *
1096
-     * @access    private
1097
-     * @param    array $available_payment_method_options
1098
-     * @return    \EE_Form_Section_Proper
1099
-     */
1100
-    private function _available_payment_method_inputs($available_payment_method_options = array())
1101
-    {
1102
-        // generate inputs
1103
-        return new EE_Form_Section_Proper(
1104
-            array(
1105
-                'html_id'         => 'ee-available-payment-method-inputs',
1106
-                'layout_strategy' => new EE_Div_Per_Section_Layout(),
1107
-                'subsections'     => array(
1108
-                    '' => new EE_Radio_Button_Input(
1109
-                        $available_payment_method_options,
1110
-                        array(
1111
-                            'html_name'          => 'selected_method_of_payment',
1112
-                            'html_class'         => 'spco-payment-method',
1113
-                            'default'            => $this->checkout->selected_method_of_payment,
1114
-                            'label_size'         => 11,
1115
-                            'enforce_label_size' => true,
1116
-                        )
1117
-                    ),
1118
-                ),
1119
-            )
1120
-        );
1121
-    }
1122
-
1123
-
1124
-    /**
1125
-     *    _payment_method_billing_info
1126
-     *
1127
-     * @access    private
1128
-     * @param    EE_Payment_Method $payment_method
1129
-     * @return EE_Form_Section_Proper
1130
-     * @throws EE_Error
1131
-     * @throws InvalidArgumentException
1132
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1133
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1134
-     */
1135
-    private function _payment_method_billing_info(EE_Payment_Method $payment_method)
1136
-    {
1137
-        $currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug()
1138
-            ? true
1139
-            : false;
1140
-        // generate the billing form for payment method
1141
-        $billing_form                 = $currently_selected
1142
-            ? $this->_get_billing_form_for_payment_method($payment_method)
1143
-            : new EE_Form_Section_HTML();
1144
-        $this->checkout->billing_form = $currently_selected
1145
-            ? $billing_form
1146
-            : $this->checkout->billing_form;
1147
-        // it's all in the details
1148
-        $info_html = EEH_HTML::h3(
1149
-            esc_html__('Important information regarding your payment', 'event_espresso'),
1150
-            '',
1151
-            'spco-payment-method-hdr'
1152
-        );
1153
-        // add some info regarding the step, either from what's saved in the admin,
1154
-        // or a default string depending on whether the PM has a billing form or not
1155
-        if ($payment_method->description()) {
1156
-            $payment_method_info = $payment_method->description();
1157
-        } elseif ($billing_form instanceof EE_Billing_Info_Form) {
1158
-            $payment_method_info = sprintf(
1159
-                esc_html__(
1160
-                    'Please provide the following billing information, then click the "%1$s" button below in order to proceed.',
1161
-                    'event_espresso'
1162
-                ),
1163
-                $this->submit_button_text()
1164
-            );
1165
-        } else {
1166
-            $payment_method_info = sprintf(
1167
-                esc_html__('Please click the "%1$s" button below in order to proceed.', 'event_espresso'),
1168
-                $this->submit_button_text()
1169
-            );
1170
-        }
1171
-        $info_html .= EEH_HTML::p(
1172
-            apply_filters(
1173
-                'FHEE__EE_SPCO_Reg_Step_Payment_Options___payment_method_billing_info__payment_method_info',
1174
-                $payment_method_info
1175
-            ),
1176
-            '',
1177
-            'spco-payment-method-desc ee-attention'
1178
-        );
1179
-        return new EE_Form_Section_Proper(
1180
-            array(
1181
-                'html_id'         => 'spco-payment-method-info-' . $payment_method->slug(),
1182
-                'html_class'      => 'spco-payment-method-info-dv',
1183
-                // only display the selected or default PM
1184
-                'html_style'      => $currently_selected ? '' : 'display:none;',
1185
-                'layout_strategy' => new EE_Div_Per_Section_Layout(),
1186
-                'subsections'     => array(
1187
-                    'info'         => new EE_Form_Section_HTML($info_html),
1188
-                    'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML(),
1189
-                ),
1190
-            )
1191
-        );
1192
-    }
1193
-
1194
-
1195
-    /**
1196
-     * get_billing_form_html_for_payment_method
1197
-     *
1198
-     * @access public
1199
-     * @return string
1200
-     * @throws EE_Error
1201
-     * @throws InvalidArgumentException
1202
-     * @throws ReflectionException
1203
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1204
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1205
-     */
1206
-    public function get_billing_form_html_for_payment_method()
1207
-    {
1208
-        // how have they chosen to pay?
1209
-        $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
1210
-        $this->checkout->payment_method             = $this->_get_payment_method_for_selected_method_of_payment();
1211
-        if (! $this->checkout->payment_method instanceof EE_Payment_Method) {
1212
-            return false;
1213
-        }
1214
-        if (apply_filters(
1215
-            'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1216
-            false
1217
-        )) {
1218
-            EE_Error::add_success(
1219
-                apply_filters(
1220
-                    'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
1221
-                    sprintf(
1222
-                        esc_html__(
1223
-                            'You have selected "%s" as your method of payment. Please note the important payment information below.',
1224
-                            'event_espresso'
1225
-                        ),
1226
-                        $this->checkout->payment_method->name()
1227
-                    )
1228
-                )
1229
-            );
1230
-        }
1231
-        // now generate billing form for selected method of payment
1232
-        $payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method);
1233
-        // fill form with attendee info if applicable
1234
-        if ($payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form
1235
-            && $this->checkout->transaction_has_primary_registrant()
1236
-        ) {
1237
-            $payment_method_billing_form->populate_from_attendee(
1238
-                $this->checkout->transaction->primary_registration()->attendee()
1239
-            );
1240
-        }
1241
-        // and debug content
1242
-        if ($payment_method_billing_form instanceof EE_Billing_Info_Form
1243
-            && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base
1244
-        ) {
1245
-            $payment_method_billing_form =
1246
-                $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings(
1247
-                    $payment_method_billing_form
1248
-                );
1249
-        }
1250
-        $billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper
1251
-            ? $payment_method_billing_form->get_html()
1252
-            : '';
1253
-        $this->checkout->json_response->set_return_data(array('payment_method_info' => $billing_info));
1254
-        // localize validation rules for main form
1255
-        $this->checkout->current_step->reg_form->localize_validation_rules();
1256
-        $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
1257
-        return true;
1258
-    }
1259
-
1260
-
1261
-    /**
1262
-     * _get_billing_form_for_payment_method
1263
-     *
1264
-     * @access private
1265
-     * @param EE_Payment_Method $payment_method
1266
-     * @return EE_Billing_Info_Form|EE_Form_Section_HTML
1267
-     * @throws EE_Error
1268
-     * @throws InvalidArgumentException
1269
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1270
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1271
-     */
1272
-    private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method)
1273
-    {
1274
-        $billing_form = $payment_method->type_obj()->billing_form(
1275
-            $this->checkout->transaction,
1276
-            array('amount_owing' => $this->checkout->amount_owing)
1277
-        );
1278
-        if ($billing_form instanceof EE_Billing_Info_Form) {
1279
-            if (apply_filters(
1280
-                'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1281
-                false
1282
-            )
1283
-                && EE_Registry::instance()->REQ->is_set('payment_method')
1284
-            ) {
1285
-                EE_Error::add_success(
1286
-                    apply_filters(
1287
-                        'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
1288
-                        sprintf(
1289
-                            esc_html__(
1290
-                                'You have selected "%s" as your method of payment. Please note the important payment information below.',
1291
-                                'event_espresso'
1292
-                            ),
1293
-                            $payment_method->name()
1294
-                        )
1295
-                    )
1296
-                );
1297
-            }
1298
-            return apply_filters(
1299
-                'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
1300
-                $billing_form,
1301
-                $payment_method
1302
-            );
1303
-        }
1304
-        // no actual billing form, so return empty HTML form section
1305
-        return new EE_Form_Section_HTML();
1306
-    }
1307
-
1308
-
1309
-    /**
1310
-     * _get_selected_method_of_payment
1311
-     *
1312
-     * @access private
1313
-     * @param boolean $required whether to throw an error if the "selected_method_of_payment"
1314
-     *                          is not found in the incoming request
1315
-     * @param string  $request_param
1316
-     * @return NULL|string
1317
-     * @throws EE_Error
1318
-     * @throws InvalidArgumentException
1319
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1320
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1321
-     */
1322
-    private function _get_selected_method_of_payment(
1323
-        $required = false,
1324
-        $request_param = 'selected_method_of_payment'
1325
-    ) {
1326
-        // is selected_method_of_payment set in the request ?
1327
-        $selected_method_of_payment = EE_Registry::instance()->REQ->get($request_param, false);
1328
-        if ($selected_method_of_payment) {
1329
-            // sanitize it
1330
-            $selected_method_of_payment = is_array($selected_method_of_payment)
1331
-                ? array_shift($selected_method_of_payment)
1332
-                : $selected_method_of_payment;
1333
-            $selected_method_of_payment = sanitize_text_field($selected_method_of_payment);
1334
-            // store it in the session so that it's available for all subsequent requests including AJAX
1335
-            $this->_save_selected_method_of_payment($selected_method_of_payment);
1336
-        } else {
1337
-            // or is is set in the session ?
1338
-            $selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data(
1339
-                'selected_method_of_payment'
1340
-            );
1341
-        }
1342
-        // do ya really really gotta have it?
1343
-        if (empty($selected_method_of_payment) && $required) {
1344
-            EE_Error::add_error(
1345
-                sprintf(
1346
-                    esc_html__(
1347
-                        'The selected method of payment could not be determined.%sPlease ensure that you have selected one before proceeding.%sIf you continue to experience difficulties, then refresh your browser and try again, or contact %s for assistance.',
1348
-                        'event_espresso'
1349
-                    ),
1350
-                    '<br/>',
1351
-                    '<br/>',
1352
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
1353
-                ),
1354
-                __FILE__,
1355
-                __FUNCTION__,
1356
-                __LINE__
1357
-            );
1358
-            return null;
1359
-        }
1360
-        return $selected_method_of_payment;
1361
-    }
1362
-
1363
-
1364
-
1365
-
1366
-
1367
-
1368
-    /********************************************************************************************************/
1369
-    /***********************************  SWITCH PAYMENT METHOD  ************************************/
1370
-    /********************************************************************************************************/
1371
-    /**
1372
-     * switch_payment_method
1373
-     *
1374
-     * @access public
1375
-     * @return string
1376
-     * @throws EE_Error
1377
-     * @throws InvalidArgumentException
1378
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1379
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1380
-     */
1381
-    public function switch_payment_method()
1382
-    {
1383
-        if (! $this->_verify_payment_method_is_set()) {
1384
-            return false;
1385
-        }
1386
-        if (apply_filters(
1387
-            'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1388
-            false
1389
-        )) {
1390
-            EE_Error::add_success(
1391
-                apply_filters(
1392
-                    'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
1393
-                    sprintf(
1394
-                        esc_html__(
1395
-                            'You have selected "%s" as your method of payment. Please note the important payment information below.',
1396
-                            'event_espresso'
1397
-                        ),
1398
-                        $this->checkout->payment_method->name()
1399
-                    )
1400
-                )
1401
-            );
1402
-        }
1403
-        // generate billing form for selected method of payment if it hasn't been done already
1404
-        if ($this->checkout->payment_method->type_obj()->has_billing_form()) {
1405
-            $this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1406
-                $this->checkout->payment_method
1407
-            );
1408
-        }
1409
-        // fill form with attendee info if applicable
1410
-        if (apply_filters(
1411
-            'FHEE__populate_billing_form_fields_from_attendee',
1412
-            (
1413
-                $this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form
1414
-                && $this->checkout->transaction_has_primary_registrant()
1415
-            ),
1416
-            $this->checkout->billing_form,
1417
-            $this->checkout->transaction
1418
-        )
1419
-        ) {
1420
-            $this->checkout->billing_form->populate_from_attendee(
1421
-                $this->checkout->transaction->primary_registration()->attendee()
1422
-            );
1423
-        }
1424
-        // and debug content
1425
-        if ($this->checkout->billing_form instanceof EE_Billing_Info_Form
1426
-            && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base
1427
-        ) {
1428
-            $this->checkout->billing_form =
1429
-                $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings(
1430
-                    $this->checkout->billing_form
1431
-                );
1432
-        }
1433
-        // get html and validation rules for form
1434
-        if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) {
1435
-            $this->checkout->json_response->set_return_data(
1436
-                array('payment_method_info' => $this->checkout->billing_form->get_html())
1437
-            );
1438
-            // localize validation rules for main form
1439
-            $this->checkout->billing_form->localize_validation_rules(true);
1440
-            $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
1441
-        } else {
1442
-            $this->checkout->json_response->set_return_data(array('payment_method_info' => ''));
1443
-        }
1444
-        //prevents advancement to next step
1445
-        $this->checkout->continue_reg = false;
1446
-        return true;
1447
-    }
1448
-
1449
-
1450
-    /**
1451
-     * _verify_payment_method_is_set
1452
-     *
1453
-     * @return bool
1454
-     * @throws EE_Error
1455
-     * @throws InvalidArgumentException
1456
-     * @throws ReflectionException
1457
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1458
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1459
-     */
1460
-    protected function _verify_payment_method_is_set()
1461
-    {
1462
-        // generate billing form for selected method of payment if it hasn't been done already
1463
-        if (empty($this->checkout->selected_method_of_payment)) {
1464
-            // how have they chosen to pay?
1465
-            $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
1466
-        } else {
1467
-            // choose your own adventure based on method_of_payment
1468
-            switch ($this->checkout->selected_method_of_payment) {
1469
-                case 'events_sold_out' :
1470
-                    EE_Error::add_attention(
1471
-                        apply_filters(
1472
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg',
1473
-                            esc_html__(
1474
-                                'It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.',
1475
-                                'event_espresso'
1476
-                            )
1477
-                        ),
1478
-                        __FILE__, __FUNCTION__, __LINE__
1479
-                    );
1480
-                    return false;
1481
-                    break;
1482
-                case 'payments_closed' :
1483
-                    EE_Error::add_attention(
1484
-                        apply_filters(
1485
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg',
1486
-                            esc_html__(
1487
-                                'It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.',
1488
-                                'event_espresso'
1489
-                            )
1490
-                        ),
1491
-                        __FILE__, __FUNCTION__, __LINE__
1492
-                    );
1493
-                    return false;
1494
-                    break;
1495
-                case 'no_payment_required' :
1496
-                    EE_Error::add_attention(
1497
-                        apply_filters(
1498
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg',
1499
-                            esc_html__(
1500
-                                'It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.',
1501
-                                'event_espresso'
1502
-                            )
1503
-                        ),
1504
-                        __FILE__, __FUNCTION__, __LINE__
1505
-                    );
1506
-                    return false;
1507
-                    break;
1508
-                default:
1509
-            }
1510
-        }
1511
-        // verify payment method
1512
-        if (! $this->checkout->payment_method instanceof EE_Payment_Method) {
1513
-            // get payment method for selected method of payment
1514
-            $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment();
1515
-        }
1516
-        return $this->checkout->payment_method instanceof EE_Payment_Method ? true : false;
1517
-    }
1518
-
1519
-
1520
-
1521
-    /********************************************************************************************************/
1522
-    /***************************************  SAVE PAYER DETAILS  ****************************************/
1523
-    /********************************************************************************************************/
1524
-    /**
1525
-     * save_payer_details_via_ajax
1526
-     *
1527
-     * @return void
1528
-     * @throws EE_Error
1529
-     * @throws InvalidArgumentException
1530
-     * @throws ReflectionException
1531
-     * @throws RuntimeException
1532
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1533
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1534
-     */
1535
-    public function save_payer_details_via_ajax()
1536
-    {
1537
-        if (! $this->_verify_payment_method_is_set()) {
1538
-            return;
1539
-        }
1540
-        // generate billing form for selected method of payment if it hasn't been done already
1541
-        if ($this->checkout->payment_method->type_obj()->has_billing_form()) {
1542
-            $this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1543
-                $this->checkout->payment_method
1544
-            );
1545
-        }
1546
-        // generate primary attendee from payer info if applicable
1547
-        if (! $this->checkout->transaction_has_primary_registrant()) {
1548
-            $attendee = $this->_create_attendee_from_request_data();
1549
-            if ($attendee instanceof EE_Attendee) {
1550
-                foreach ($this->checkout->transaction->registrations() as $registration) {
1551
-                    if ($registration->is_primary_registrant()) {
1552
-                        $this->checkout->primary_attendee_obj = $attendee;
1553
-                        $registration->_add_relation_to($attendee, 'Attendee');
1554
-                        $registration->set_attendee_id($attendee->ID());
1555
-                        $registration->update_cache_after_object_save('Attendee', $attendee);
1556
-                    }
1557
-                }
1558
-            }
1559
-        }
1560
-    }
1561
-
1562
-
1563
-    /**
1564
-     * create_attendee_from_request_data
1565
-     * uses info from alternate GET or POST data (such as AJAX) to create a new attendee
1566
-     *
1567
-     * @return EE_Attendee
1568
-     * @throws EE_Error
1569
-     * @throws InvalidArgumentException
1570
-     * @throws ReflectionException
1571
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1572
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1573
-     */
1574
-    protected function _create_attendee_from_request_data()
1575
-    {
1576
-        // get State ID
1577
-        $STA_ID = ! empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : '';
1578
-        if (! empty($STA_ID)) {
1579
-            // can we get state object from name ?
1580
-            EE_Registry::instance()->load_model('State');
1581
-            $state  = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID');
1582
-            $STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID;
1583
-        }
1584
-        // get Country ISO
1585
-        $CNT_ISO = ! empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : '';
1586
-        if (! empty($CNT_ISO)) {
1587
-            // can we get country object from name ?
1588
-            EE_Registry::instance()->load_model('Country');
1589
-            $country = EEM_Country::instance()->get_col(
1590
-                array(array('CNT_name' => $CNT_ISO), 'limit' => 1),
1591
-                'CNT_ISO'
1592
-            );
1593
-            $CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO;
1594
-        }
1595
-        // grab attendee data
1596
-        $attendee_data = array(
1597
-            'ATT_fname'    => ! empty($_REQUEST['first_name']) ? sanitize_text_field($_REQUEST['first_name']) : '',
1598
-            'ATT_lname'    => ! empty($_REQUEST['last_name']) ? sanitize_text_field($_REQUEST['last_name']) : '',
1599
-            'ATT_email'    => ! empty($_REQUEST['email']) ? sanitize_email($_REQUEST['email']) : '',
1600
-            'ATT_address'  => ! empty($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '',
1601
-            'ATT_address2' => ! empty($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '',
1602
-            'ATT_city'     => ! empty($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '',
1603
-            'STA_ID'       => $STA_ID,
1604
-            'CNT_ISO'      => $CNT_ISO,
1605
-            'ATT_zip'      => ! empty($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '',
1606
-            'ATT_phone'    => ! empty($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : '',
1607
-        );
1608
-        // validate the email address since it is the most important piece of info
1609
-        if (empty($attendee_data['ATT_email']) || $attendee_data['ATT_email'] !== $_REQUEST['email']) {
1610
-            EE_Error::add_error(
1611
-                esc_html__('An invalid email address was submitted.', 'event_espresso'),
1612
-                __FILE__,
1613
-                __FUNCTION__,
1614
-                __LINE__
1615
-            );
1616
-        }
1617
-        // does this attendee already exist in the db ? we're searching using a combination of first name, last name,
1618
-        // AND email address
1619
-        if (! empty($attendee_data['ATT_fname'])
1620
-            && ! empty($attendee_data['ATT_lname'])
1621
-            && ! empty($attendee_data['ATT_email'])
1622
-        ) {
1623
-            $existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee(
1624
-                array(
1625
-                    'ATT_fname' => $attendee_data['ATT_fname'],
1626
-                    'ATT_lname' => $attendee_data['ATT_lname'],
1627
-                    'ATT_email' => $attendee_data['ATT_email'],
1628
-                )
1629
-            );
1630
-            if ($existing_attendee instanceof EE_Attendee) {
1631
-                return $existing_attendee;
1632
-            }
1633
-        }
1634
-        // no existing attendee? kk let's create a new one
1635
-        // kinda lame, but we need a first and last name to create an attendee, so use the email address if those
1636
-        // don't exist
1637
-        $attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname'])
1638
-            ? $attendee_data['ATT_fname']
1639
-            : $attendee_data['ATT_email'];
1640
-        $attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname'])
1641
-            ? $attendee_data['ATT_lname']
1642
-            : $attendee_data['ATT_email'];
1643
-        return EE_Attendee::new_instance($attendee_data);
1644
-    }
1645
-
1646
-
1647
-
1648
-    /********************************************************************************************************/
1649
-    /****************************************  PROCESS REG STEP  *****************************************/
1650
-    /********************************************************************************************************/
1651
-    /**
1652
-     * process_reg_step
1653
-     *
1654
-     * @return bool
1655
-     * @throws EE_Error
1656
-     * @throws InvalidArgumentException
1657
-     * @throws ReflectionException
1658
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1659
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1660
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1661
-     * @throws \EventEspresso\core\exceptions\InvalidStatusException
1662
-     */
1663
-    public function process_reg_step()
1664
-    {
1665
-        // how have they chosen to pay?
1666
-        $this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free()
1667
-            ? 'no_payment_required'
1668
-            : $this->_get_selected_method_of_payment(true);
1669
-        // choose your own adventure based on method_of_payment
1670
-        switch ($this->checkout->selected_method_of_payment) {
1671
-
1672
-            case 'events_sold_out' :
1673
-                $this->checkout->redirect     = true;
1674
-                $this->checkout->redirect_url = $this->checkout->cancel_page_url;
1675
-                $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1676
-                // mark this reg step as completed
1677
-                $this->set_completed();
1678
-                return false;
1679
-                break;
1680
-
1681
-            case 'payments_closed' :
1682
-                if (apply_filters(
1683
-                    'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success',
1684
-                    false
1685
-                )) {
1686
-                    EE_Error::add_success(
1687
-                        esc_html__('no payment required at this time.', 'event_espresso'),
1688
-                        __FILE__,
1689
-                        __FUNCTION__,
1690
-                        __LINE__
1691
-                    );
1692
-                }
1693
-                // mark this reg step as completed
1694
-                $this->set_completed();
1695
-                return true;
1696
-                break;
1697
-
1698
-            case 'no_payment_required' :
1699
-                if (apply_filters(
1700
-                    'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success',
1701
-                    false
1702
-                )) {
1703
-                    EE_Error::add_success(
1704
-                        esc_html__('no payment required.', 'event_espresso'),
1705
-                        __FILE__,
1706
-                        __FUNCTION__,
1707
-                        __LINE__
1708
-                    );
1709
-                }
1710
-                // mark this reg step as completed
1711
-                $this->set_completed();
1712
-                return true;
1713
-                break;
1714
-
1715
-            default:
1716
-                $registrations         = EE_Registry::instance()->SSN->checkout()->transaction->registrations(
1717
-                    EE_Registry::instance()->SSN->checkout()->reg_cache_where_params
1718
-                );
1719
-                $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space(
1720
-                    $registrations,
1721
-                    EE_Registry::instance()->SSN->checkout()->revisit
1722
-                );
1723
-                // calculate difference between the two arrays
1724
-                $registrations = array_diff($registrations, $ejected_registrations);
1725
-                if (empty($registrations)) {
1726
-                    $this->_redirect_because_event_sold_out();
1727
-                    return false;
1728
-                }
1729
-                $payment_successful = $this->_process_payment();
1730
-                if ($payment_successful) {
1731
-                    $this->checkout->continue_reg = true;
1732
-                    $this->_maybe_set_completed($this->checkout->payment_method);
1733
-                } else {
1734
-                    $this->checkout->continue_reg = false;
1735
-                }
1736
-                return $payment_successful;
1737
-        }
1738
-    }
1739
-
1740
-
1741
-    /**
1742
-     * _redirect_because_event_sold_out
1743
-     *
1744
-     * @access protected
1745
-     * @return void
1746
-     */
1747
-    protected function _redirect_because_event_sold_out()
1748
-    {
1749
-        $this->checkout->continue_reg = false;
1750
-        // set redirect URL
1751
-        $this->checkout->redirect_url = add_query_arg(
1752
-            array('e_reg_url_link' => $this->checkout->reg_url_link),
1753
-            $this->checkout->current_step->reg_step_url()
1754
-        );
1755
-        $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1756
-    }
1757
-
1758
-
1759
-    /**
1760
-     * _maybe_set_completed
1761
-     *
1762
-     * @access protected
1763
-     * @param \EE_Payment_Method $payment_method
1764
-     * @return void
1765
-     * @throws \EE_Error
1766
-     */
1767
-    protected function _maybe_set_completed(EE_Payment_Method $payment_method)
1768
-    {
1769
-        switch ($payment_method->type_obj()->payment_occurs()) {
1770
-            case EE_PMT_Base::offsite :
1771
-                break;
1772
-            case EE_PMT_Base::onsite :
1773
-            case EE_PMT_Base::offline :
1774
-                // mark this reg step as completed
1775
-                $this->set_completed();
1776
-                break;
1777
-        }
1778
-    }
1779
-
1780
-
1781
-    /**
1782
-     *    update_reg_step
1783
-     *    this is the final step after a user  revisits the site to retry a payment
1784
-     *
1785
-     * @return bool
1786
-     * @throws EE_Error
1787
-     * @throws InvalidArgumentException
1788
-     * @throws ReflectionException
1789
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1790
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1791
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1792
-     * @throws \EventEspresso\core\exceptions\InvalidStatusException
1793
-     */
1794
-    public function update_reg_step()
1795
-    {
1796
-        $success = true;
1797
-        // if payment required
1798
-        if ($this->checkout->transaction->total() > 0) {
1799
-            do_action(
1800
-                'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway',
1801
-                $this->checkout->transaction
1802
-            );
1803
-            // attempt payment via payment method
1804
-            $success = $this->process_reg_step();
1805
-        }
1806
-        if ($success && ! $this->checkout->redirect) {
1807
-            $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn(
1808
-                $this->checkout->transaction->ID()
1809
-            );
1810
-            // set return URL
1811
-            $this->checkout->redirect_url = add_query_arg(
1812
-                array('e_reg_url_link' => $this->checkout->reg_url_link),
1813
-                $this->checkout->thank_you_page_url
1814
-            );
1815
-        }
1816
-        return $success;
1817
-    }
1818
-
1819
-
1820
-    /**
1821
-     *    _process_payment
1822
-     *
1823
-     * @access private
1824
-     * @return bool
1825
-     * @throws EE_Error
1826
-     * @throws InvalidArgumentException
1827
-     * @throws ReflectionException
1828
-     * @throws RuntimeException
1829
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1830
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1831
-     */
1832
-    private function _process_payment()
1833
-    {
1834
-        // basically confirm that the event hasn't sold out since they hit the page
1835
-        if (! $this->_last_second_ticket_verifications()) {
1836
-            return false;
1837
-        }
1838
-        // ya gotta make a choice man
1839
-        if (empty($this->checkout->selected_method_of_payment)) {
1840
-            $this->checkout->json_response->set_plz_select_method_of_payment(
1841
-                esc_html__('Please select a method of payment before proceeding.', 'event_espresso')
1842
-            );
1843
-            return false;
1844
-        }
1845
-        // get EE_Payment_Method object
1846
-        if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
1847
-            return false;
1848
-        }
1849
-        // setup billing form
1850
-        if ($this->checkout->payment_method->is_on_site()) {
1851
-            $this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1852
-                $this->checkout->payment_method
1853
-            );
1854
-            // bad billing form ?
1855
-            if (! $this->_billing_form_is_valid()) {
1856
-                return false;
1857
-            }
1858
-        }
1859
-        // ensure primary registrant has been fully processed
1860
-        if (! $this->_setup_primary_registrant_prior_to_payment()) {
1861
-            return false;
1862
-        }
1863
-        // if session is close to expiring (under 10 minutes by default)
1864
-        if ((time() - EE_Registry::instance()->SSN->expiration()) < EE_Registry::instance()->SSN->extension()) {
1865
-            // add some time to session expiration so that payment can be completed
1866
-            EE_Registry::instance()->SSN->extend_expiration();
1867
-        }
1868
-        /** @type EE_Transaction_Processor $transaction_processor */
1869
-        //$transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' );
1870
-        // in case a registrant leaves to an Off-Site Gateway and never returns, we want to approve any registrations
1871
-        // for events with a default reg status of Approved
1872
-        // $transaction_processor->toggle_registration_statuses_for_default_approved_events(
1873
-        //      $this->checkout->transaction, $this->checkout->reg_cache_where_params
1874
-        // );
1875
-        // attempt payment
1876
-        $payment = $this->_attempt_payment($this->checkout->payment_method);
1877
-        // process results
1878
-        $payment = $this->_validate_payment($payment);
1879
-        $payment = $this->_post_payment_processing($payment);
1880
-        // verify payment
1881
-        if ($payment instanceof EE_Payment) {
1882
-            // store that for later
1883
-            $this->checkout->payment = $payment;
1884
-            // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned
1885
-            $this->checkout->transaction->toggle_failed_transaction_status();
1886
-            $payment_status = $payment->status();
1887
-            if (
1888
-                $payment_status === EEM_Payment::status_id_approved
1889
-                || $payment_status === EEM_Payment::status_id_pending
1890
-            ) {
1891
-                return true;
1892
-            } else {
1893
-                return false;
1894
-            }
1895
-        } else if ($payment === true) {
1896
-            // please note that offline payment methods will NOT make a payment,
1897
-            // but instead just mark themselves as the PMD_ID on the transaction, and return true
1898
-            $this->checkout->payment = $payment;
1899
-            return true;
1900
-        }
1901
-        // where's my money?
1902
-        return false;
1903
-    }
1904
-
1905
-
1906
-    /**
1907
-     * _last_second_ticket_verifications
1908
-     *
1909
-     * @access public
1910
-     * @return bool
1911
-     * @throws EE_Error
1912
-     */
1913
-    protected function _last_second_ticket_verifications()
1914
-    {
1915
-        // don't bother re-validating if not a return visit
1916
-        if (! $this->checkout->revisit) {
1917
-            return true;
1918
-        }
1919
-        $registrations = $this->checkout->transaction->registrations();
1920
-        if (empty($registrations)) {
1921
-            return false;
1922
-        }
1923
-        foreach ($registrations as $registration) {
1924
-            if ($registration instanceof EE_Registration && ! $registration->is_approved()) {
1925
-                $event = $registration->event_obj();
1926
-                if ($event instanceof EE_Event && $event->is_sold_out(true)) {
1927
-                    EE_Error::add_error(
1928
-                        apply_filters(
1929
-                            'FHEE__EE_SPCO_Reg_Step_Payment_Options___last_second_ticket_verifications__sold_out_events_msg',
1930
-                            sprintf(
1931
-                                esc_html__(
1932
-                                    'It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.',
1933
-                                    'event_espresso'
1934
-                                ),
1935
-                                $event->name()
1936
-                            )
1937
-                        ),
1938
-                        __FILE__,
1939
-                        __FUNCTION__,
1940
-                        __LINE__
1941
-                    );
1942
-                    return false;
1943
-                }
1944
-            }
1945
-        }
1946
-        return true;
1947
-    }
1948
-
1949
-
1950
-    /**
1951
-     * redirect_form
1952
-     *
1953
-     * @access public
1954
-     * @return bool
1955
-     * @throws EE_Error
1956
-     * @throws InvalidArgumentException
1957
-     * @throws ReflectionException
1958
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1959
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1960
-     */
1961
-    public function redirect_form()
1962
-    {
1963
-        $payment_method_billing_info = $this->_payment_method_billing_info(
1964
-            $this->_get_payment_method_for_selected_method_of_payment()
1965
-        );
1966
-        $html                        = $payment_method_billing_info->get_html();
1967
-        $html                        .= $this->checkout->redirect_form;
1968
-        EE_Registry::instance()->REQ->add_output($html);
1969
-        return true;
1970
-    }
1971
-
1972
-
1973
-    /**
1974
-     * _billing_form_is_valid
1975
-     *
1976
-     * @access private
1977
-     * @return bool
1978
-     * @throws \EE_Error
1979
-     */
1980
-    private function _billing_form_is_valid()
1981
-    {
1982
-        if (! $this->checkout->payment_method->type_obj()->has_billing_form()) {
1983
-            return true;
1984
-        }
1985
-        if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) {
1986
-            if ($this->checkout->billing_form->was_submitted()) {
1987
-                $this->checkout->billing_form->receive_form_submission();
1988
-                if ($this->checkout->billing_form->is_valid()) {
1989
-                    return true;
1990
-                }
1991
-                $validation_errors = $this->checkout->billing_form->get_validation_errors_accumulated();
1992
-                $error_strings     = array();
1993
-                foreach ($validation_errors as $validation_error) {
1994
-                    if ($validation_error instanceof EE_Validation_Error) {
1995
-                        $form_section = $validation_error->get_form_section();
1996
-                        if ($form_section instanceof EE_Form_Input_Base) {
1997
-                            $label = $form_section->html_label_text();
1998
-                        } elseif ($form_section instanceof EE_Form_Section_Base) {
1999
-                            $label = $form_section->name();
2000
-                        } else {
2001
-                            $label = esc_html__('Validation Error', 'event_espresso');
2002
-                        }
2003
-                        $error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage());
2004
-                    }
2005
-                }
2006
-                EE_Error::add_error(
2007
-                    sprintf(
2008
-                        esc_html__(
2009
-                            'One or more billing form inputs are invalid and require correction before proceeding. %1$s %2$s',
2010
-                            'event_espresso'
2011
-                        ),
2012
-                        '<br/>',
2013
-                        implode('<br/>', $error_strings)
2014
-                    ),
2015
-                    __FILE__,
2016
-                    __FUNCTION__,
2017
-                    __LINE__
2018
-                );
2019
-            } else {
2020
-                EE_Error::add_error(
2021
-                    esc_html__(
2022
-                        'The billing form was not submitted or something prevented it\'s submission.',
2023
-                        'event_espresso'
2024
-                    ),
2025
-                    __FILE__,
2026
-                    __FUNCTION__,
2027
-                    __LINE__
2028
-                );
2029
-            }
2030
-        } else {
2031
-            EE_Error::add_error(
2032
-                esc_html__('The submitted billing form is invalid possibly due to a technical reason.', 'event_espresso'),
2033
-                __FILE__,
2034
-                __FUNCTION__,
2035
-                __LINE__
2036
-            );
2037
-        }
2038
-        return false;
2039
-    }
2040
-
2041
-
2042
-    /**
2043
-     * _setup_primary_registrant_prior_to_payment
2044
-     * ensures that the primary registrant has a valid attendee object created with the critical details populated
2045
-     * (first & last name & email) and that both the transaction object and primary registration object have been saved
2046
-     * plz note that any other registrations will NOT be saved at this point (because they may not have any details
2047
-     * yet)
2048
-     *
2049
-     * @access private
2050
-     * @return bool
2051
-     * @throws EE_Error
2052
-     * @throws InvalidArgumentException
2053
-     * @throws ReflectionException
2054
-     * @throws RuntimeException
2055
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2056
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2057
-     */
2058
-    private function _setup_primary_registrant_prior_to_payment()
2059
-    {
2060
-        // check if transaction has a primary registrant and that it has a related Attendee object
2061
-        // if not, then we need to at least gather some primary registrant data before attempting payment
2062
-        if (
2063
-            $this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form
2064
-            && ! $this->checkout->transaction_has_primary_registrant()
2065
-            && ! $this->_capture_primary_registration_data_from_billing_form()
2066
-        ) {
2067
-            return false;
2068
-        }
2069
-        // because saving an object clears it's cache, we need to do the chevy shuffle
2070
-        // grab the primary_registration object
2071
-        $primary_registration = $this->checkout->transaction->primary_registration();
2072
-        // at this point we'll consider a TXN to not have been failed
2073
-        $this->checkout->transaction->toggle_failed_transaction_status();
2074
-        // save the TXN ( which clears cached copy of primary_registration)
2075
-        $this->checkout->transaction->save();
2076
-        // grab TXN ID and save it to the primary_registration
2077
-        $primary_registration->set_transaction_id($this->checkout->transaction->ID());
2078
-        // save what we have so far
2079
-        $primary_registration->save();
2080
-        return true;
2081
-    }
2082
-
2083
-
2084
-    /**
2085
-     * _capture_primary_registration_data_from_billing_form
2086
-     *
2087
-     * @access private
2088
-     * @return bool
2089
-     * @throws EE_Error
2090
-     * @throws InvalidArgumentException
2091
-     * @throws ReflectionException
2092
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2093
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2094
-     */
2095
-    private function _capture_primary_registration_data_from_billing_form()
2096
-    {
2097
-        // convert billing form data into an attendee
2098
-        $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data();
2099
-        if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) {
2100
-            EE_Error::add_error(
2101
-                sprintf(
2102
-                    esc_html__(
2103
-                        'The billing form details could not be used for attendee details due to a technical issue.%sPlease try again or contact %s for assistance.',
2104
-                        'event_espresso'
2105
-                    ),
2106
-                    '<br/>',
2107
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
2108
-                ),
2109
-                __FILE__,
2110
-                __FUNCTION__,
2111
-                __LINE__
2112
-            );
2113
-            return false;
2114
-        }
2115
-        $primary_registration = $this->checkout->transaction->primary_registration();
2116
-        if (! $primary_registration instanceof EE_Registration) {
2117
-            EE_Error::add_error(
2118
-                sprintf(
2119
-                    esc_html__(
2120
-                        'The primary registrant for this transaction could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
2121
-                        'event_espresso'
2122
-                    ),
2123
-                    '<br/>',
2124
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
2125
-                ),
2126
-                __FILE__,
2127
-                __FUNCTION__,
2128
-                __LINE__
2129
-            );
2130
-            return false;
2131
-        }
2132
-        if (! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee')
2133
-              instanceof
2134
-              EE_Attendee
2135
-        ) {
2136
-            EE_Error::add_error(
2137
-                sprintf(
2138
-                    esc_html__(
2139
-                        'The primary registrant could not be associated with this transaction due to a technical issue.%sPlease try again or contact %s for assistance.',
2140
-                        'event_espresso'
2141
-                    ),
2142
-                    '<br/>',
2143
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
2144
-                ),
2145
-                __FILE__,
2146
-                __FUNCTION__,
2147
-                __LINE__
2148
-            );
2149
-            return false;
2150
-        }
2151
-        /** @type EE_Registration_Processor $registration_processor */
2152
-        $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
2153
-        // at this point, we should have enough details about the registrant to consider the registration NOT incomplete
2154
-        $registration_processor->toggle_incomplete_registration_status_to_default($primary_registration);
2155
-        return true;
2156
-    }
2157
-
2158
-
2159
-    /**
2160
-     * _get_payment_method_for_selected_method_of_payment
2161
-     * retrieves a valid payment method
2162
-     *
2163
-     * @access public
2164
-     * @return EE_Payment_Method
2165
-     * @throws EE_Error
2166
-     * @throws InvalidArgumentException
2167
-     * @throws ReflectionException
2168
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2169
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2170
-     */
2171
-    private function _get_payment_method_for_selected_method_of_payment()
2172
-    {
2173
-        if ($this->checkout->selected_method_of_payment === 'events_sold_out') {
2174
-            $this->_redirect_because_event_sold_out();
2175
-            return null;
2176
-        }
2177
-        // get EE_Payment_Method object
2178
-        if (isset($this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment])) {
2179
-            $payment_method = $this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment];
2180
-        } else {
2181
-            // load EEM_Payment_Method
2182
-            EE_Registry::instance()->load_model('Payment_Method');
2183
-            /** @type EEM_Payment_Method $EEM_Payment_Method */
2184
-            $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method;
2185
-            $payment_method     = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment);
2186
-        }
2187
-        // verify $payment_method
2188
-        if (! $payment_method instanceof EE_Payment_Method) {
2189
-            // not a payment
2190
-            EE_Error::add_error(
2191
-                sprintf(
2192
-                    esc_html__(
2193
-                        'The selected method of payment could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
2194
-                        'event_espresso'
2195
-                    ),
2196
-                    '<br/>',
2197
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
2198
-                ),
2199
-                __FILE__,
2200
-                __FUNCTION__,
2201
-                __LINE__
2202
-            );
2203
-            return null;
2204
-        }
2205
-        // and verify it has a valid Payment_Method Type object
2206
-        if (! $payment_method->type_obj() instanceof EE_PMT_Base) {
2207
-            // not a payment
2208
-            EE_Error::add_error(
2209
-                sprintf(
2210
-                    esc_html__(
2211
-                        'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
2212
-                        'event_espresso'
2213
-                    ),
2214
-                    '<br/>',
2215
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
2216
-                ),
2217
-                __FILE__,
2218
-                __FUNCTION__,
2219
-                __LINE__
2220
-            );
2221
-            return null;
2222
-        }
2223
-        return $payment_method;
2224
-    }
2225
-
2226
-
2227
-    /**
2228
-     *    _attempt_payment
2229
-     *
2230
-     * @access    private
2231
-     * @type    EE_Payment_Method $payment_method
2232
-     * @return mixed EE_Payment | boolean
2233
-     * @throws EE_Error
2234
-     * @throws InvalidArgumentException
2235
-     * @throws ReflectionException
2236
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2237
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2238
-     */
2239
-    private function _attempt_payment(EE_Payment_Method $payment_method)
2240
-    {
2241
-        $payment = null;
2242
-        $this->checkout->transaction->save();
2243
-        $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2244
-        if (! $payment_processor instanceof EE_Payment_Processor) {
2245
-            return false;
2246
-        }
2247
-        try {
2248
-            $payment_processor->set_revisit($this->checkout->revisit);
2249
-            // generate payment object
2250
-            $payment = $payment_processor->process_payment(
2251
-                $payment_method,
2252
-                $this->checkout->transaction,
2253
-                $this->checkout->amount_owing,
2254
-                $this->checkout->billing_form,
2255
-                $this->_get_return_url($payment_method),
2256
-                'CART',
2257
-                $this->checkout->admin_request,
2258
-                true,
2259
-                $this->reg_step_url()
2260
-            );
2261
-        } catch (Exception $e) {
2262
-            $this->_handle_payment_processor_exception($e);
2263
-        }
2264
-        return $payment;
2265
-    }
2266
-
2267
-
2268
-    /**
2269
-     * _handle_payment_processor_exception
2270
-     *
2271
-     * @access protected
2272
-     * @param \Exception $e
2273
-     * @return void
2274
-     * @throws EE_Error
2275
-     * @throws InvalidArgumentException
2276
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2277
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2278
-     */
2279
-    protected function _handle_payment_processor_exception(Exception $e)
2280
-    {
2281
-        EE_Error::add_error(
2282
-            sprintf(
2283
-                esc_html__(
2284
-                    'The payment could not br processed due to a technical issue.%1$sPlease try again or contact %2$s for assistance.||The following Exception was thrown in %4$s on line %5$s:%1$s%3$s',
2285
-                    'event_espresso'
2286
-                ),
2287
-                '<br/>',
2288
-                EE_Registry::instance()->CFG->organization->get_pretty('email'),
2289
-                $e->getMessage(),
2290
-                $e->getFile(),
2291
-                $e->getLine()
2292
-            ),
2293
-            __FILE__,
2294
-            __FUNCTION__,
2295
-            __LINE__
2296
-        );
2297
-    }
2298
-
2299
-
2300
-    /**
2301
-     * _get_return_url
2302
-     *
2303
-     * @access protected
2304
-     * @param \EE_Payment_Method $payment_method
2305
-     * @return string
2306
-     * @throws \EE_Error
2307
-     */
2308
-    protected function _get_return_url(EE_Payment_Method $payment_method)
2309
-    {
2310
-        $return_url = '';
2311
-        switch ($payment_method->type_obj()->payment_occurs()) {
2312
-            case EE_PMT_Base::offsite :
2313
-                $return_url = add_query_arg(
2314
-                    array(
2315
-                        'action'                     => 'process_gateway_response',
2316
-                        'selected_method_of_payment' => $this->checkout->selected_method_of_payment,
2317
-                        'spco_txn'                   => $this->checkout->transaction->ID(),
2318
-                    ),
2319
-                    $this->reg_step_url()
2320
-                );
2321
-                break;
2322
-            case EE_PMT_Base::onsite :
2323
-            case EE_PMT_Base::offline :
2324
-                $return_url = $this->checkout->next_step->reg_step_url();
2325
-                break;
2326
-        }
2327
-        return $return_url;
2328
-    }
2329
-
2330
-
2331
-    /**
2332
-     * _validate_payment
2333
-     *
2334
-     * @access private
2335
-     * @param EE_Payment $payment
2336
-     * @return EE_Payment|FALSE
2337
-     * @throws EE_Error
2338
-     * @throws InvalidArgumentException
2339
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2340
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2341
-     */
2342
-    private function _validate_payment($payment = null)
2343
-    {
2344
-        if ($this->checkout->payment_method->is_off_line()) {
2345
-            return true;
2346
-        }
2347
-        // verify payment object
2348
-        if (! $payment instanceof EE_Payment) {
2349
-            // not a payment
2350
-            EE_Error::add_error(
2351
-                sprintf(
2352
-                    esc_html__(
2353
-                        'A valid payment was not generated due to a technical issue.%1$sPlease try again or contact %2$s for assistance.',
2354
-                        'event_espresso'
2355
-                    ),
2356
-                    '<br/>',
2357
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
2358
-                ),
2359
-                __FILE__,
2360
-                __FUNCTION__,
2361
-                __LINE__
2362
-            );
2363
-            return false;
2364
-        }
2365
-        return $payment;
2366
-    }
2367
-
2368
-
2369
-    /**
2370
-     * _post_payment_processing
2371
-     *
2372
-     * @access private
2373
-     * @param EE_Payment|bool $payment
2374
-     * @return bool
2375
-     * @throws EE_Error
2376
-     * @throws InvalidArgumentException
2377
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2378
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2379
-     */
2380
-    private function _post_payment_processing($payment = null)
2381
-    {
2382
-        // Off-Line payment?
2383
-        if ($payment === true) {
2384
-            //$this->_setup_redirect_for_next_step();
2385
-            return true;
2386
-            // On-Site payment?
2387
-        } else if ($this->checkout->payment_method->is_on_site()) {
2388
-            if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) {
2389
-                //$this->_setup_redirect_for_next_step();
2390
-                $this->checkout->continue_reg = false;
2391
-            }
2392
-            // Off-Site payment?
2393
-        } else if ($this->checkout->payment_method->is_off_site()) {
2394
-            // if a payment object was made and it specifies a redirect url, then we'll setup that redirect info
2395
-            if ($payment instanceof EE_Payment && $payment->redirect_url()) {
2396
-                do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()');
2397
-                $this->checkout->redirect      = true;
2398
-                $this->checkout->redirect_form = $payment->redirect_form();
2399
-                $this->checkout->redirect_url  = $this->reg_step_url('redirect_form');
2400
-                // set JSON response
2401
-                $this->checkout->json_response->set_redirect_form($this->checkout->redirect_form);
2402
-                // and lastly, let's bump the payment status to pending
2403
-                $payment->set_status(EEM_Payment::status_id_pending);
2404
-                $payment->save();
2405
-            } else {
2406
-                // not a payment
2407
-                $this->checkout->continue_reg = false;
2408
-                EE_Error::add_error(
2409
-                    sprintf(
2410
-                        esc_html__(
2411
-                            'It appears the Off Site Payment Method was not configured properly.%sPlease try again or contact %s for assistance.',
2412
-                            'event_espresso'
2413
-                        ),
2414
-                        '<br/>',
2415
-                        EE_Registry::instance()->CFG->organization->get_pretty('email')
2416
-                    ),
2417
-                    __FILE__,
2418
-                    __FUNCTION__,
2419
-                    __LINE__
2420
-                );
2421
-            }
2422
-        } else {
2423
-            // ummm ya... not Off-Line, not On-Site, not off-Site ????
2424
-            $this->checkout->continue_reg = false;
2425
-            return false;
2426
-        }
2427
-        return $payment;
2428
-    }
2429
-
2430
-
2431
-    /**
2432
-     *    _process_payment_status
2433
-     *
2434
-     * @access private
2435
-     * @type    EE_Payment $payment
2436
-     * @param string       $payment_occurs
2437
-     * @return bool
2438
-     * @throws EE_Error
2439
-     * @throws InvalidArgumentException
2440
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2441
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2442
-     */
2443
-    private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline)
2444
-    {
2445
-        // off-line payment? carry on
2446
-        if ($payment_occurs === EE_PMT_Base::offline) {
2447
-            return true;
2448
-        }
2449
-        // verify payment validity
2450
-        if ($payment instanceof EE_Payment) {
2451
-            do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()');
2452
-            $msg = $payment->gateway_response();
2453
-            // check results
2454
-            switch ($payment->status()) {
2455
-                // good payment
2456
-                case EEM_Payment::status_id_approved :
2457
-                    EE_Error::add_success(
2458
-                        esc_html__('Your payment was processed successfully.', 'event_espresso'),
2459
-                        __FILE__,
2460
-                        __FUNCTION__,
2461
-                        __LINE__
2462
-                    );
2463
-                    return true;
2464
-                    break;
2465
-                // slow payment
2466
-                case EEM_Payment::status_id_pending :
2467
-                    if (empty($msg)) {
2468
-                        $msg = esc_html__(
2469
-                            'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.',
2470
-                            'event_espresso'
2471
-                        );
2472
-                    }
2473
-                    EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__);
2474
-                    return true;
2475
-                    break;
2476
-                // don't wanna payment
2477
-                case EEM_Payment::status_id_cancelled :
2478
-                    if (empty($msg)) {
2479
-                        $msg = _n(
2480
-                            'Payment cancelled. Please try again.',
2481
-                            'Payment cancelled. Please try again or select another method of payment.',
2482
-                            count($this->checkout->available_payment_methods),
2483
-                            'event_espresso'
2484
-                        );
2485
-                    }
2486
-                    EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
2487
-                    return false;
2488
-                    break;
2489
-                // not enough payment
2490
-                case EEM_Payment::status_id_declined :
2491
-                    if (empty($msg)) {
2492
-                        $msg = _n(
2493
-                            'We\'re sorry but your payment was declined. Please try again.',
2494
-                            'We\'re sorry but your payment was declined. Please try again or select another method of payment.',
2495
-                            count($this->checkout->available_payment_methods),
2496
-                            'event_espresso'
2497
-                        );
2498
-                    }
2499
-                    EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
2500
-                    return false;
2501
-                    break;
2502
-                // bad payment
2503
-                case EEM_Payment::status_id_failed :
2504
-                    if (! empty($msg)) {
2505
-                        EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2506
-                        return false;
2507
-                    }
2508
-                    // default to error below
2509
-                    break;
2510
-            }
2511
-        }
2512
-        // off-site payment gateway responses are too unreliable, so let's just assume that
2513
-        // the payment processing is just running slower than the registrant's request
2514
-        if ($payment_occurs === EE_PMT_Base::offsite) {
2515
-            return true;
2516
-        }
2517
-        EE_Error::add_error(
2518
-            sprintf(
2519
-                esc_html__(
2520
-                    'Your payment could not be processed successfully due to a technical issue.%sPlease try again or contact %s for assistance.',
2521
-                    'event_espresso'
2522
-                ),
2523
-                '<br/>',
2524
-                EE_Registry::instance()->CFG->organization->get_pretty('email')
2525
-            ),
2526
-            __FILE__,
2527
-            __FUNCTION__,
2528
-            __LINE__
2529
-        );
2530
-        return false;
2531
-    }
2532
-
2533
-
2534
-
2535
-
2536
-
2537
-
2538
-    /********************************************************************************************************/
2539
-    /**********************************  PROCESS GATEWAY RESPONSE  **********************************/
2540
-    /********************************************************************************************************/
2541
-    /**
2542
-     * process_gateway_response
2543
-     * this is the return point for Off-Site Payment Methods
2544
-     * It will attempt to "handle the IPN" if it appears that this has not already occurred,
2545
-     * otherwise, it will load up the last payment made for the TXN.
2546
-     * If the payment retrieved looks good, it will then either:
2547
-     *    complete the current step and allow advancement to the next reg step
2548
-     *        or present the payment options again
2549
-     *
2550
-     * @access private
2551
-     * @return EE_Payment|FALSE
2552
-     * @throws EE_Error
2553
-     * @throws InvalidArgumentException
2554
-     * @throws ReflectionException
2555
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2556
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2557
-     * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
2558
-     */
2559
-    public function process_gateway_response()
2560
-    {
2561
-        $payment = null;
2562
-        // how have they chosen to pay?
2563
-        $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
2564
-        // get EE_Payment_Method object
2565
-        if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
2566
-            $this->checkout->continue_reg = false;
2567
-            return false;
2568
-        }
2569
-        if (! $this->checkout->payment_method->is_off_site()) {
2570
-            return false;
2571
-        }
2572
-        $this->_validate_offsite_return();
2573
-        // DEBUG LOG
2574
-        //$this->checkout->log(
2575
-        //	__CLASS__, __FUNCTION__, __LINE__,
2576
-        //	array(
2577
-        //		'selected_method_of_payment' => $this->checkout->selected_method_of_payment,
2578
-        //		'payment_method' => $this->checkout->payment_method,
2579
-        //	),
2580
-        //	true
2581
-        //);
2582
-        // verify TXN
2583
-        if ($this->checkout->transaction instanceof EE_Transaction) {
2584
-            $gateway = $this->checkout->payment_method->type_obj()->get_gateway();
2585
-            if (! $gateway instanceof EE_Offsite_Gateway) {
2586
-                $this->checkout->continue_reg = false;
2587
-                return false;
2588
-            }
2589
-            $payment = $this->_process_off_site_payment($gateway);
2590
-            $payment = $this->_process_cancelled_payments($payment);
2591
-            $payment = $this->_validate_payment($payment);
2592
-            // if payment was not declined by the payment gateway or cancelled by the registrant
2593
-            if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) {
2594
-                //$this->_setup_redirect_for_next_step();
2595
-                // store that for later
2596
-                $this->checkout->payment = $payment;
2597
-                // mark this reg step as completed, as long as gateway doesn't use a separate IPN request,
2598
-                // because we will complete this step during the IPN processing then
2599
-                if ($gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request()) {
2600
-                    $this->set_completed();
2601
-                }
2602
-                return true;
2603
-            }
2604
-        }
2605
-        // DEBUG LOG
2606
-        //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__,
2607
-        //	array( 'payment' => $payment )
2608
-        //);
2609
-        $this->checkout->continue_reg = false;
2610
-        return false;
2611
-    }
2612
-
2613
-
2614
-    /**
2615
-     * _validate_return
2616
-     *
2617
-     * @access private
2618
-     * @return void
2619
-     * @throws EE_Error
2620
-     * @throws InvalidArgumentException
2621
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2622
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2623
-     * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
2624
-     */
2625
-    private function _validate_offsite_return()
2626
-    {
2627
-        $TXN_ID = (int)EE_Registry::instance()->REQ->get('spco_txn', 0);
2628
-        if ($TXN_ID !== $this->checkout->transaction->ID()) {
2629
-            // Houston... we might have a problem
2630
-            $invalid_TXN = false;
2631
-            // first gather some info
2632
-            $valid_TXN          = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2633
-            $primary_registrant = $valid_TXN instanceof EE_Transaction
2634
-                ? $valid_TXN->primary_registration()
2635
-                : null;
2636
-            // let's start by retrieving the cart for this TXN
2637
-            $cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction);
2638
-            if ($cart instanceof EE_Cart) {
2639
-                // verify that the current cart has tickets
2640
-                $tickets = $cart->get_tickets();
2641
-                if (empty($tickets)) {
2642
-                    $invalid_TXN = true;
2643
-                }
2644
-            } else {
2645
-                $invalid_TXN = true;
2646
-            }
2647
-            $valid_TXN_SID = $primary_registrant instanceof EE_Registration
2648
-                ? $primary_registrant->session_ID()
2649
-                : null;
2650
-            // validate current Session ID and compare against valid TXN session ID
2651
-            if (
2652
-                $invalid_TXN // if this is already true, then skip other checks
2653
-                || EE_Session::instance()->id() === null
2654
-                || (
2655
-                    // WARNING !!!
2656
-                    // this could be PayPal sending back duplicate requests (ya they do that)
2657
-                    // or it **could** mean someone is simply registering AGAIN after having just done so
2658
-                    // so now we need to determine if this current TXN looks valid or not
2659
-                    // and whether this reg step has even been started ?
2660
-                    EE_Session::instance()->id() === $valid_TXN_SID
2661
-                    // really? you're half way through this reg step, but you never started it ?
2662
-                    && $this->checkout->transaction->reg_step_completed($this->slug()) === false
2663
-                )
2664
-            ) {
2665
-                $invalid_TXN = true;
2666
-            }
2667
-            if ($invalid_TXN) {
2668
-                // is the valid TXN completed ?
2669
-                if ($valid_TXN instanceof EE_Transaction) {
2670
-                    // has this step even been started ?
2671
-                    $reg_step_completed = $valid_TXN->reg_step_completed($this->slug());
2672
-                    if ($reg_step_completed !== false && $reg_step_completed !== true) {
2673
-                        // so it **looks** like this is a double request from PayPal
2674
-                        // so let's try to pick up where we left off
2675
-                        $this->checkout->transaction = $valid_TXN;
2676
-                        $this->checkout->refresh_all_entities(true);
2677
-                        return;
2678
-                    }
2679
-                }
2680
-                // you appear to be lost?
2681
-                $this->_redirect_wayward_request($primary_registrant);
2682
-            }
2683
-        }
2684
-    }
2685
-
2686
-
2687
-    /**
2688
-     * _redirect_wayward_request
2689
-     *
2690
-     * @access private
2691
-     * @param \EE_Registration|null $primary_registrant
2692
-     * @return bool
2693
-     * @throws EE_Error
2694
-     * @throws InvalidArgumentException
2695
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2696
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2697
-     */
2698
-    private function _redirect_wayward_request(EE_Registration $primary_registrant)
2699
-    {
2700
-        if (! $primary_registrant instanceof EE_Registration) {
2701
-            // try redirecting based on the current TXN
2702
-            $primary_registrant = $this->checkout->transaction instanceof EE_Transaction
2703
-                ? $this->checkout->transaction->primary_registration()
2704
-                : null;
2705
-        }
2706
-        if (! $primary_registrant instanceof EE_Registration) {
2707
-            EE_Error::add_error(
2708
-                sprintf(
2709
-                    esc_html__(
2710
-                        'Invalid information was received from the Off-Site Payment Processor and your Transaction details could not be retrieved from the database.%1$sPlease try again or contact %2$s for assistance.',
2711
-                        'event_espresso'
2712
-                    ),
2713
-                    '<br/>',
2714
-                    EE_Registry::instance()->CFG->organization->get_pretty('email')
2715
-                ),
2716
-                __FILE__,
2717
-                __FUNCTION__,
2718
-                __LINE__
2719
-            );
2720
-            return false;
2721
-        }
2722
-        // make sure transaction is not locked
2723
-        $this->checkout->transaction->unlock();
2724
-        wp_safe_redirect(
2725
-            add_query_arg(
2726
-                array(
2727
-                    'e_reg_url_link' => $primary_registrant->reg_url_link(),
2728
-                ),
2729
-                $this->checkout->thank_you_page_url
2730
-            )
2731
-        );
2732
-        exit();
2733
-    }
2734
-
2735
-
2736
-    /**
2737
-     * _process_off_site_payment
2738
-     *
2739
-     * @access private
2740
-     * @param \EE_Offsite_Gateway $gateway
2741
-     * @return EE_Payment
2742
-     * @throws EE_Error
2743
-     * @throws InvalidArgumentException
2744
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2745
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2746
-     */
2747
-    private function _process_off_site_payment(EE_Offsite_Gateway $gateway)
2748
-    {
2749
-        try {
2750
-            $request_data = \EE_Registry::instance()->REQ->params();
2751
-            // if gateway uses_separate_IPN_request, then we don't have to process the IPN manually
2752
-            $this->set_handle_IPN_in_this_request(
2753
-                $gateway->handle_IPN_in_this_request($request_data, false)
2754
-            );
2755
-            if ($this->handle_IPN_in_this_request()) {
2756
-                // get payment details and process results
2757
-                /** @type EE_Payment_Processor $payment_processor */
2758
-                $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2759
-                $payment           = $payment_processor->process_ipn(
2760
-                    $request_data,
2761
-                    $this->checkout->transaction,
2762
-                    $this->checkout->payment_method,
2763
-                    true,
2764
-                    false
2765
-                );
2766
-                //$payment_source = 'process_ipn';
2767
-            } else {
2768
-                $payment = $this->checkout->transaction->last_payment();
2769
-                //$payment_source = 'last_payment';
2770
-            }
2771
-        } catch (Exception $e) {
2772
-            // let's just eat the exception and try to move on using any previously set payment info
2773
-            $payment = $this->checkout->transaction->last_payment();
2774
-            //$payment_source = 'last_payment after Exception';
2775
-            // but if we STILL don't have a payment object
2776
-            if (! $payment instanceof EE_Payment) {
2777
-                // then we'll object ! ( not object like a thing... but object like what a lawyer says ! )
2778
-                $this->_handle_payment_processor_exception($e);
2779
-            }
2780
-        }
2781
-        // DEBUG LOG
2782
-        //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__,
2783
-        //	array(
2784
-        //		'process_ipn_payment' => $payment,
2785
-        //		'payment_source'      => $payment_source,
2786
-        //	)
2787
-        //);
2788
-        return $payment;
2789
-    }
2790
-
2791
-
2792
-    /**
2793
-     * _process_cancelled_payments
2794
-     * just makes sure that the payment status gets updated correctly
2795
-     * so tha tan error isn't generated during payment validation
2796
-     *
2797
-     * @access private
2798
-     * @param EE_Payment $payment
2799
-     * @return EE_Payment | FALSE
2800
-     * @throws \EE_Error
2801
-     */
2802
-    private function _process_cancelled_payments($payment = null)
2803
-    {
2804
-        if (
2805
-            $payment instanceof EE_Payment
2806
-            && isset($_REQUEST['ee_cancel_payment'])
2807
-            && $payment->status() === EEM_Payment::status_id_failed
2808
-        ) {
2809
-            $payment->set_status(EEM_Payment::status_id_cancelled);
2810
-        }
2811
-        return $payment;
2812
-    }
2813
-
2814
-
2815
-    /**
2816
-     *    get_transaction_details_for_gateways
2817
-     *
2818
-     * @access    public
2819
-     * @return int
2820
-     * @throws EE_Error
2821
-     * @throws InvalidArgumentException
2822
-     * @throws ReflectionException
2823
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2824
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2825
-     */
2826
-    public function get_transaction_details_for_gateways()
2827
-    {
2828
-        $txn_details = array();
2829
-        // ya gotta make a choice man
2830
-        if (empty($this->checkout->selected_method_of_payment)) {
2831
-            $txn_details = array(
2832
-                'error' => esc_html__('Please select a method of payment before proceeding.', 'event_espresso'),
2833
-            );
2834
-        }
2835
-        // get EE_Payment_Method object
2836
-        if (
2837
-            empty($txn_details)
2838
-            &&
2839
-            ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()
2840
-        ) {
2841
-            $txn_details = array(
2842
-                'selected_method_of_payment' => $this->checkout->selected_method_of_payment,
2843
-                'error'                      => esc_html__(
2844
-                    'A valid Payment Method could not be determined.',
2845
-                    'event_espresso'
2846
-                ),
2847
-            );
2848
-        }
2849
-        if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) {
2850
-            $return_url  = $this->_get_return_url($this->checkout->payment_method);
2851
-            $txn_details = array(
2852
-                'TXN_ID'         => $this->checkout->transaction->ID(),
2853
-                'TXN_timestamp'  => $this->checkout->transaction->datetime(),
2854
-                'TXN_total'      => $this->checkout->transaction->total(),
2855
-                'TXN_paid'       => $this->checkout->transaction->paid(),
2856
-                'TXN_reg_steps'  => $this->checkout->transaction->reg_steps(),
2857
-                'STS_ID'         => $this->checkout->transaction->status_ID(),
2858
-                'PMD_ID'         => $this->checkout->transaction->payment_method_ID(),
2859
-                'payment_amount' => $this->checkout->amount_owing,
2860
-                'return_url'     => $return_url,
2861
-                'cancel_url'     => add_query_arg(array('ee_cancel_payment' => true), $return_url),
2862
-                'notify_url'     => EE_Config::instance()->core->txn_page_url(
2863
-                    array(
2864
-                        'e_reg_url_link'    => $this->checkout->transaction->primary_registration()->reg_url_link(),
2865
-                        'ee_payment_method' => $this->checkout->payment_method->slug(),
2866
-                    )
2867
-                ),
2868
-            );
2869
-        }
2870
-        echo wp_json_encode($txn_details);
2871
-        exit();
2872
-    }
2873
-
2874
-
2875
-    /**
2876
-     *    __sleep
2877
-     * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon
2878
-     * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the
2879
-     * reg form, because if needed, it will be regenerated anyways
2880
-     *
2881
-     * @return array
2882
-     */
2883
-    public function __sleep()
2884
-    {
2885
-        // remove the reg form and the checkout
2886
-        return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout', 'line_item_display'));
2887
-    }
18
+	/**
19
+	 * @access protected
20
+	 * @var EE_Line_Item_Display $Line_Item_Display
21
+	 */
22
+	protected $line_item_display;
23
+
24
+	/**
25
+	 * @access protected
26
+	 * @var boolean $handle_IPN_in_this_request
27
+	 */
28
+	protected $handle_IPN_in_this_request = false;
29
+
30
+
31
+	/**
32
+	 *    set_hooks - for hooking into EE Core, other modules, etc
33
+	 *
34
+	 * @access    public
35
+	 * @return    void
36
+	 */
37
+	public static function set_hooks()
38
+	{
39
+		add_filter(
40
+			'FHEE__SPCO__EE_Line_Item_Filter_Collection',
41
+			array('EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters')
42
+		);
43
+		add_action(
44
+			'wp_ajax_switch_spco_billing_form',
45
+			array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form')
46
+		);
47
+		add_action(
48
+			'wp_ajax_nopriv_switch_spco_billing_form',
49
+			array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form')
50
+		);
51
+		add_action('wp_ajax_save_payer_details', array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details'));
52
+		add_action(
53
+			'wp_ajax_nopriv_save_payer_details',
54
+			array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details')
55
+		);
56
+		add_action(
57
+			'wp_ajax_get_transaction_details_for_gateways',
58
+			array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details')
59
+		);
60
+		add_action(
61
+			'wp_ajax_nopriv_get_transaction_details_for_gateways',
62
+			array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details')
63
+		);
64
+		add_filter(
65
+			'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array',
66
+			array('EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'),
67
+			10,
68
+			1
69
+		);
70
+	}
71
+
72
+
73
+	/**
74
+	 *    ajax switch_spco_billing_form
75
+	 *
76
+	 * @throws \EE_Error
77
+	 */
78
+	public static function switch_spco_billing_form()
79
+	{
80
+		EED_Single_Page_Checkout::process_ajax_request('switch_payment_method');
81
+	}
82
+
83
+
84
+	/**
85
+	 *    ajax save_payer_details
86
+	 *
87
+	 * @throws \EE_Error
88
+	 */
89
+	public static function save_payer_details()
90
+	{
91
+		EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax');
92
+	}
93
+
94
+
95
+	/**
96
+	 *    ajax get_transaction_details
97
+	 *
98
+	 * @throws \EE_Error
99
+	 */
100
+	public static function get_transaction_details()
101
+	{
102
+		EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways');
103
+	}
104
+
105
+
106
+	/**
107
+	 * bypass_recaptcha_for_load_payment_method
108
+	 *
109
+	 * @access public
110
+	 * @return array
111
+	 * @throws InvalidArgumentException
112
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
113
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
114
+	 */
115
+	public static function bypass_recaptcha_for_load_payment_method()
116
+	{
117
+		return array(
118
+			'EESID'  => EE_Registry::instance()->SSN->id(),
119
+			'step'   => 'payment_options',
120
+			'action' => 'spco_billing_form',
121
+		);
122
+	}
123
+
124
+
125
+	/**
126
+	 *    class constructor
127
+	 *
128
+	 * @access    public
129
+	 * @param    EE_Checkout $checkout
130
+	 */
131
+	public function __construct(EE_Checkout $checkout)
132
+	{
133
+		$this->_slug     = 'payment_options';
134
+		$this->_name     = esc_html__('Payment Options', 'event_espresso');
135
+		$this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'payment_options_main.template.php';
136
+		$this->checkout  = $checkout;
137
+		$this->_reset_success_message();
138
+		$this->set_instructions(
139
+			esc_html__(
140
+				'Please select a method of payment and provide any necessary billing information before proceeding.',
141
+				'event_espresso'
142
+			)
143
+		);
144
+	}
145
+
146
+
147
+	/**
148
+	 * @return null
149
+	 */
150
+	public function line_item_display()
151
+	{
152
+		return $this->line_item_display;
153
+	}
154
+
155
+
156
+	/**
157
+	 * @param null $line_item_display
158
+	 */
159
+	public function set_line_item_display($line_item_display)
160
+	{
161
+		$this->line_item_display = $line_item_display;
162
+	}
163
+
164
+
165
+	/**
166
+	 * @return boolean
167
+	 */
168
+	public function handle_IPN_in_this_request()
169
+	{
170
+		return $this->handle_IPN_in_this_request;
171
+	}
172
+
173
+
174
+	/**
175
+	 * @param boolean $handle_IPN_in_this_request
176
+	 */
177
+	public function set_handle_IPN_in_this_request($handle_IPN_in_this_request)
178
+	{
179
+		$this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN);
180
+	}
181
+
182
+
183
+	/**
184
+	 * translate_js_strings
185
+	 *
186
+	 * @return void
187
+	 */
188
+	public function translate_js_strings()
189
+	{
190
+		EE_Registry::$i18n_js_strings['no_payment_method']      = esc_html__(
191
+			'Please select a method of payment in order to continue.',
192
+			'event_espresso'
193
+		);
194
+		EE_Registry::$i18n_js_strings['invalid_payment_method'] = esc_html__(
195
+			'A valid method of payment could not be determined. Please refresh the page and try again.',
196
+			'event_espresso'
197
+		);
198
+		EE_Registry::$i18n_js_strings['forwarding_to_offsite']  = esc_html__(
199
+			'Forwarding to Secure Payment Provider.',
200
+			'event_espresso'
201
+		);
202
+	}
203
+
204
+
205
+	/**
206
+	 * enqueue_styles_and_scripts
207
+	 *
208
+	 * @return void
209
+	 * @throws EE_Error
210
+	 * @throws InvalidArgumentException
211
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
212
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
213
+	 */
214
+	public function enqueue_styles_and_scripts()
215
+	{
216
+		$transaction = $this->checkout->transaction;
217
+		//if the transaction isn't set or nothing is owed on it, don't enqueue any JS
218
+		if (! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) {
219
+			return;
220
+		}
221
+		foreach (EEM_Payment_Method::instance()->get_all_for_transaction($transaction, EEM_Payment_Method::scope_cart) as $payment_method) {
222
+			$type_obj = $payment_method->type_obj();
223
+			if ($type_obj instanceof EE_PMT_Base) {
224
+				$billing_form = $type_obj->generate_new_billing_form($transaction);
225
+				if ($billing_form instanceof EE_Form_Section_Proper) {
226
+					$billing_form->enqueue_js();
227
+				}
228
+			}
229
+		}
230
+	}
231
+
232
+
233
+	/**
234
+	 * initialize_reg_step
235
+	 *
236
+	 * @return bool
237
+	 * @throws EE_Error
238
+	 * @throws InvalidArgumentException
239
+	 * @throws ReflectionException
240
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
241
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
242
+	 */
243
+	public function initialize_reg_step()
244
+	{
245
+		// TODO: if /when we implement donations, then this will need overriding
246
+		if (// don't need payment options for:
247
+			// 	registrations made via the admin
248
+			// 	completed transactions
249
+			// 	overpaid transactions
250
+			// 	$ 0.00 transactions (no payment required)
251
+			! $this->checkout->payment_required()
252
+			// but do NOT remove if current action being called belongs to this reg step
253
+			&& ! is_callable(array($this, $this->checkout->action))
254
+			&& ! $this->completed()
255
+		) {
256
+			// and if so, then we no longer need the Payment Options step
257
+			if ($this->is_current_step()) {
258
+				$this->checkout->generate_reg_form = false;
259
+			}
260
+			$this->checkout->remove_reg_step($this->_slug);
261
+			// DEBUG LOG
262
+			//$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ );
263
+			return false;
264
+		}
265
+		// load EEM_Payment_Method
266
+		EE_Registry::instance()->load_model('Payment_Method');
267
+		// get all active payment methods
268
+		$this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction(
269
+			$this->checkout->transaction,
270
+			EEM_Payment_Method::scope_cart
271
+		);
272
+		return true;
273
+	}
274
+
275
+
276
+	/**
277
+	 * @return EE_Form_Section_Proper
278
+	 * @throws EE_Error
279
+	 * @throws InvalidArgumentException
280
+	 * @throws ReflectionException
281
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
282
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
283
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
284
+	 * @throws \EventEspresso\core\exceptions\InvalidStatusException
285
+	 */
286
+	public function generate_reg_form()
287
+	{
288
+		// reset in case someone changes their mind
289
+		$this->_reset_selected_method_of_payment();
290
+		// set some defaults
291
+		$this->checkout->selected_method_of_payment = 'payments_closed';
292
+		$registrations_requiring_payment            = array();
293
+		$registrations_for_free_events              = array();
294
+		$registrations_requiring_pre_approval       = array();
295
+		$sold_out_events                            = array();
296
+		$insufficient_spaces_available              = array();
297
+		$no_payment_required                        = true;
298
+		// loop thru registrations to gather info
299
+		$registrations         = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
300
+		$ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space(
301
+			$registrations,
302
+			$this->checkout->revisit
303
+		);
304
+		foreach ($registrations as $REG_ID => $registration) {
305
+			/** @var $registration EE_Registration */
306
+			// has this registration lost it's space ?
307
+			if (isset($ejected_registrations[ $REG_ID ])) {
308
+				if ($registration->event()->is_sold_out() || $registration->event()->is_sold_out(true)) {
309
+					$sold_out_events[ $registration->event()->ID() ] = $registration->event();
310
+				} else {
311
+					$insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event();
312
+				}
313
+				continue;
314
+			}
315
+			// event requires admin approval
316
+			if ($registration->status_ID() === EEM_Registration::status_id_not_approved) {
317
+				// add event to list of events with pre-approval reg status
318
+				$registrations_requiring_pre_approval[$REG_ID] = $registration;
319
+				do_action(
320
+					'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval',
321
+					$registration->event(),
322
+					$this
323
+				);
324
+				continue;
325
+			}
326
+			if ($this->checkout->revisit
327
+				&& $registration->status_ID() !== EEM_Registration::status_id_approved
328
+				&& (
329
+					$registration->event()->is_sold_out()
330
+					|| $registration->event()->is_sold_out(true)
331
+				)
332
+			) {
333
+				// add event to list of events that are sold out
334
+				$sold_out_events[$registration->event()->ID()] = $registration->event();
335
+				do_action(
336
+					'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event',
337
+					$registration->event(),
338
+					$this
339
+				);
340
+				continue;
341
+			}
342
+			// are they allowed to pay now and is there monies owing?
343
+			if ($registration->owes_monies_and_can_pay()) {
344
+				$registrations_requiring_payment[$REG_ID] = $registration;
345
+				do_action(
346
+					'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment',
347
+					$registration->event(),
348
+					$this
349
+				);
350
+			} elseif (! $this->checkout->revisit
351
+				&& $registration->status_ID() !== EEM_Registration::status_id_not_approved
352
+				&& $registration->ticket()->is_free()
353
+			) {
354
+				$registrations_for_free_events[$registration->event()->ID()] = $registration;
355
+			}
356
+		}
357
+		$subsections = array();
358
+		// now decide which template to load
359
+		if (! empty($sold_out_events)) {
360
+			$subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events);
361
+		}
362
+		if (! empty($insufficient_spaces_available)) {
363
+			$subsections['insufficient_space'] = $this->_insufficient_spaces_available(
364
+				$insufficient_spaces_available
365
+			);
366
+		}
367
+		if (! empty($registrations_requiring_pre_approval)) {
368
+			$subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval(
369
+				$registrations_requiring_pre_approval
370
+			);
371
+		}
372
+		if (! empty($registrations_for_free_events)) {
373
+			$subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events);
374
+		}
375
+		if (! empty($registrations_requiring_payment)) {
376
+			if ($this->checkout->amount_owing > 0) {
377
+				// autoload Line_Item_Display classes
378
+				EEH_Autoloader::register_line_item_filter_autoloaders();
379
+				$line_item_filter_processor = new EE_Line_Item_Filter_Processor(
380
+					apply_filters(
381
+						'FHEE__SPCO__EE_Line_Item_Filter_Collection',
382
+						new EE_Line_Item_Filter_Collection()
383
+					),
384
+					$this->checkout->cart->get_grand_total()
385
+				);
386
+				/** @var EE_Line_Item $filtered_line_item_tree */
387
+				$filtered_line_item_tree = $line_item_filter_processor->process();
388
+				EEH_Autoloader::register_line_item_display_autoloaders();
389
+				$this->set_line_item_display(new EE_Line_Item_Display('spco'));
390
+				$subsections['payment_options'] = $this->_display_payment_options(
391
+					$this->line_item_display->display_line_item(
392
+						$filtered_line_item_tree,
393
+						array('registrations' => $registrations)
394
+					)
395
+				);
396
+				$this->checkout->amount_owing   = $filtered_line_item_tree->total();
397
+				$this->_apply_registration_payments_to_amount_owing($registrations);
398
+			}
399
+			$no_payment_required = false;
400
+		} else {
401
+			$this->_hide_reg_step_submit_button_if_revisit();
402
+		}
403
+		$this->_save_selected_method_of_payment();
404
+
405
+		$subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs();
406
+		$subsections['extra_hidden_inputs']   = $this->_extra_hidden_inputs($no_payment_required);
407
+
408
+		return new EE_Form_Section_Proper(
409
+			array(
410
+				'name'            => $this->reg_form_name(),
411
+				'html_id'         => $this->reg_form_name(),
412
+				'subsections'     => $subsections,
413
+				'layout_strategy' => new EE_No_Layout(),
414
+			)
415
+		);
416
+	}
417
+
418
+
419
+	/**
420
+	 * add line item filters required for this reg step
421
+	 * these filters are applied via this line in EE_SPCO_Reg_Step_Payment_Options::set_hooks():
422
+	 *        add_filter( 'FHEE__SPCO__EE_Line_Item_Filter_Collection', array( 'EE_SPCO_Reg_Step_Payment_Options',
423
+	 *        'add_spco_line_item_filters' ) ); so any code that wants to use the same set of filters during the
424
+	 *        payment options reg step, can apply these filters via the following: apply_filters(
425
+	 *        'FHEE__SPCO__EE_Line_Item_Filter_Collection', new EE_Line_Item_Filter_Collection() ) or to an existing
426
+	 *        filter collection by passing that instead of instantiating a new collection
427
+	 *
428
+	 * @param \EE_Line_Item_Filter_Collection $line_item_filter_collection
429
+	 * @return EE_Line_Item_Filter_Collection
430
+	 * @throws EE_Error
431
+	 * @throws InvalidArgumentException
432
+	 * @throws ReflectionException
433
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
434
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
435
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
436
+	 * @throws \EventEspresso\core\exceptions\InvalidStatusException
437
+	 */
438
+	public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection)
439
+	{
440
+		if (! EE_Registry::instance()->SSN instanceof EE_Session) {
441
+			return $line_item_filter_collection;
442
+		}
443
+		if (! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) {
444
+			return $line_item_filter_collection;
445
+		}
446
+		if (! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) {
447
+			return $line_item_filter_collection;
448
+		}
449
+		$line_item_filter_collection->add(
450
+			new EE_Billable_Line_Item_Filter(
451
+				EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations(
452
+					EE_Registry::instance()->SSN->checkout()->transaction->registrations(
453
+						EE_Registry::instance()->SSN->checkout()->reg_cache_where_params
454
+					)
455
+				)
456
+			)
457
+		);
458
+		$line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter());
459
+		return $line_item_filter_collection;
460
+	}
461
+
462
+
463
+	/**
464
+	 * remove_ejected_registrations
465
+	 * if a registrant has lost their potential space at an event due to lack of payment,
466
+	 * then this method removes them from the list of registrations being paid for during this request
467
+	 *
468
+	 * @param \EE_Registration[] $registrations
469
+	 * @return EE_Registration[]
470
+	 * @throws EE_Error
471
+	 * @throws InvalidArgumentException
472
+	 * @throws ReflectionException
473
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
474
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
475
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
476
+	 * @throws \EventEspresso\core\exceptions\InvalidStatusException
477
+	 */
478
+	public static function remove_ejected_registrations(array $registrations)
479
+	{
480
+		$ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space(
481
+			$registrations,
482
+			EE_Registry::instance()->SSN->checkout()->revisit
483
+		);
484
+		foreach ($registrations as $REG_ID => $registration) {
485
+			// has this registration lost it's space ?
486
+			if (isset($ejected_registrations[$REG_ID])) {
487
+				unset($registrations[$REG_ID]);
488
+				continue;
489
+			}
490
+		}
491
+		return $registrations;
492
+	}
493
+
494
+
495
+	/**
496
+	 * find_registrations_that_lost_their_space
497
+	 * If a registrant chooses an offline payment method like Invoice,
498
+	 * then no space is reserved for them at the event until they fully pay fo that site
499
+	 * (unless the event's default reg status is set to APPROVED)
500
+	 * if a registrant then later returns to pay, but the number of spaces available has been reduced due to sales,
501
+	 * then this method will determine which registrations have lost the ability to complete the reg process.
502
+	 *
503
+	 * @param \EE_Registration[] $registrations
504
+	 * @param bool               $revisit
505
+	 * @return array
506
+	 * @throws EE_Error
507
+	 * @throws InvalidArgumentException
508
+	 * @throws ReflectionException
509
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
510
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
511
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
512
+	 * @throws \EventEspresso\core\exceptions\InvalidStatusException
513
+	 */
514
+	public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false)
515
+	{
516
+		// registrations per event
517
+		$event_reg_count = array();
518
+		// spaces left per event
519
+		$event_spaces_remaining = array();
520
+		// tickets left sorted by ID
521
+		$tickets_remaining = array();
522
+		// registrations that have lost their space
523
+		$ejected_registrations = array();
524
+		foreach ($registrations as $REG_ID => $registration) {
525
+			if ($registration->status_ID() === EEM_Registration::status_id_approved
526
+				|| apply_filters(
527
+					'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment',
528
+					false,
529
+					$registration,
530
+					$revisit
531
+				)
532
+			) {
533
+				continue;
534
+			}
535
+			$EVT_ID = $registration->event_ID();
536
+			$ticket = $registration->ticket();
537
+			if (! isset($tickets_remaining[$ticket->ID()])) {
538
+				$tickets_remaining[$ticket->ID()] = $ticket->remaining();
539
+			}
540
+			if ($tickets_remaining[$ticket->ID()] > 0) {
541
+				if (! isset($event_reg_count[$EVT_ID])) {
542
+					$event_reg_count[$EVT_ID] = 0;
543
+				}
544
+				$event_reg_count[$EVT_ID]++;
545
+				if (! isset($event_spaces_remaining[$EVT_ID])) {
546
+					$event_spaces_remaining[$EVT_ID] = $registration->event()->spaces_remaining_for_sale();
547
+				}
548
+			}
549
+			if ($revisit
550
+				&& ($tickets_remaining[$ticket->ID()] === 0
551
+					|| $event_reg_count[$EVT_ID] > $event_spaces_remaining[$EVT_ID]
552
+				)
553
+			) {
554
+				$ejected_registrations[$REG_ID] = $registration->event();
555
+				if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) {
556
+					/** @type EE_Registration_Processor $registration_processor */
557
+					$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
558
+					// at this point, we should have enough details about the registrant to consider the registration
559
+					// NOT incomplete
560
+					$registration_processor->manually_update_registration_status(
561
+						$registration,
562
+						EEM_Registration::status_id_wait_list
563
+					);
564
+				}
565
+			}
566
+		}
567
+		return $ejected_registrations;
568
+	}
569
+
570
+
571
+	/**
572
+	 * _hide_reg_step_submit_button
573
+	 * removes the html for the reg step submit button
574
+	 * by replacing it with an empty string via filter callback
575
+	 *
576
+	 * @return void
577
+	 */
578
+	protected function _adjust_registration_status_if_event_old_sold()
579
+	{
580
+	}
581
+
582
+
583
+	/**
584
+	 * _hide_reg_step_submit_button
585
+	 * removes the html for the reg step submit button
586
+	 * by replacing it with an empty string via filter callback
587
+	 *
588
+	 * @return void
589
+	 */
590
+	protected function _hide_reg_step_submit_button_if_revisit()
591
+	{
592
+		if ($this->checkout->revisit) {
593
+			add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string');
594
+		}
595
+	}
596
+
597
+
598
+	/**
599
+	 * sold_out_events
600
+	 * displays notices regarding events that have sold out since hte registrant first signed up
601
+	 *
602
+	 * @param \EE_Event[] $sold_out_events_array
603
+	 * @return \EE_Form_Section_Proper
604
+	 * @throws \EE_Error
605
+	 */
606
+	private function _sold_out_events($sold_out_events_array = array())
607
+	{
608
+		// set some defaults
609
+		$this->checkout->selected_method_of_payment = 'events_sold_out';
610
+		$sold_out_events                            = '';
611
+		foreach ($sold_out_events_array as $sold_out_event) {
612
+			$sold_out_events .= EEH_HTML::li(
613
+				EEH_HTML::span(
614
+					'  ' . $sold_out_event->name(),
615
+					'',
616
+					'dashicons dashicons-marker ee-icon-size-16 pink-text'
617
+				)
618
+			);
619
+		}
620
+		return new EE_Form_Section_Proper(
621
+			array(
622
+				'layout_strategy' => new EE_Template_Layout(
623
+					array(
624
+						'layout_template_file' => SPCO_REG_STEPS_PATH
625
+												  . $this->_slug
626
+												  . DS
627
+												  . 'sold_out_events.template.php',
628
+						'template_args'        => apply_filters(
629
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args',
630
+							array(
631
+								'sold_out_events'     => $sold_out_events,
632
+								'sold_out_events_msg' => apply_filters(
633
+									'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg',
634
+									sprintf(
635
+										esc_html__(
636
+											'It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s',
637
+											'event_espresso'
638
+										),
639
+										'<strong>',
640
+										'</strong>',
641
+										'<br />'
642
+									)
643
+								),
644
+							)
645
+						),
646
+					)
647
+				),
648
+			)
649
+		);
650
+	}
651
+
652
+
653
+	/**
654
+	 * _insufficient_spaces_available
655
+	 * displays notices regarding events that do not have enough remaining spaces
656
+	 * to satisfy the current number of registrations looking to pay
657
+	 *
658
+	 * @param \EE_Event[] $insufficient_spaces_events_array
659
+	 * @return \EE_Form_Section_Proper
660
+	 * @throws \EE_Error
661
+	 */
662
+	private function _insufficient_spaces_available($insufficient_spaces_events_array = array())
663
+	{
664
+		// set some defaults
665
+		$this->checkout->selected_method_of_payment = 'invoice';
666
+		$insufficient_space_events                  = '';
667
+		foreach ($insufficient_spaces_events_array as $event) {
668
+			if ($event instanceof EE_Event) {
669
+				$insufficient_space_events .= EEH_HTML::li(
670
+					EEH_HTML::span(' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text')
671
+				);
672
+			}
673
+		}
674
+		return new EE_Form_Section_Proper(
675
+			array(
676
+				'subsections'     => array(
677
+					'default_hidden_inputs' => $this->reg_step_hidden_inputs(),
678
+					'extra_hidden_inputs'   => $this->_extra_hidden_inputs(),
679
+				),
680
+				'layout_strategy' => new EE_Template_Layout(
681
+					array(
682
+						'layout_template_file' => SPCO_REG_STEPS_PATH
683
+												  . $this->_slug
684
+												  . DS
685
+												  . 'sold_out_events.template.php',
686
+						'template_args'        => apply_filters(
687
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args',
688
+							array(
689
+								'sold_out_events'     => $insufficient_space_events,
690
+								'sold_out_events_msg' => apply_filters(
691
+									'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__insufficient_space_msg',
692
+									esc_html__(
693
+										'It appears that the event you were about to make a payment for has sold additional tickets since you first registered, and there are no longer enough spaces left to accommodate your selections. You may continue to pay and secure the available space(s) remaining, or simply cancel if you no longer wish to purchase. If you have already made a partial payment towards this event, please contact the event administrator for a refund.',
694
+										'event_espresso'
695
+									)
696
+								),
697
+							)
698
+						),
699
+					)
700
+				),
701
+			)
702
+		);
703
+	}
704
+
705
+
706
+	/**
707
+	 * registrations_requiring_pre_approval
708
+	 *
709
+	 * @param array $registrations_requiring_pre_approval
710
+	 * @return EE_Form_Section_Proper
711
+	 * @throws EE_Error
712
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
713
+	 */
714
+	private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = array())
715
+	{
716
+		$events_requiring_pre_approval = '';
717
+		foreach ($registrations_requiring_pre_approval as $registration) {
718
+			if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) {
719
+				$events_requiring_pre_approval[$registration->event()->ID()] = EEH_HTML::li(
720
+					EEH_HTML::span(
721
+						'',
722
+						'',
723
+						'dashicons dashicons-marker ee-icon-size-16 orange-text'
724
+					)
725
+					. EEH_HTML::span($registration->event()->name(), '', 'orange-text')
726
+				);
727
+			}
728
+		}
729
+		return new EE_Form_Section_Proper(
730
+			array(
731
+				'layout_strategy' => new EE_Template_Layout(
732
+					array(
733
+						'layout_template_file' => SPCO_REG_STEPS_PATH
734
+												  . $this->_slug
735
+												  . DS
736
+												  . 'events_requiring_pre_approval.template.php', // layout_template
737
+						'template_args'        => apply_filters(
738
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args',
739
+							array(
740
+								'events_requiring_pre_approval'     => implode('', $events_requiring_pre_approval),
741
+								'events_requiring_pre_approval_msg' => apply_filters(
742
+									'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg',
743
+									esc_html__(
744
+										'The following events do not require payment at this time and will not be billed during this transaction. Billing will only occur after the attendee has been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.',
745
+										'event_espresso'
746
+									)
747
+								),
748
+							)
749
+						),
750
+					)
751
+				),
752
+			)
753
+		);
754
+	}
755
+
756
+
757
+	/**
758
+	 * _no_payment_required
759
+	 *
760
+	 * @param \EE_Event[] $registrations_for_free_events
761
+	 * @return \EE_Form_Section_Proper
762
+	 * @throws \EE_Error
763
+	 */
764
+	private function _no_payment_required($registrations_for_free_events = array())
765
+	{
766
+		// set some defaults
767
+		$this->checkout->selected_method_of_payment = 'no_payment_required';
768
+		// generate no_payment_required form
769
+		return new EE_Form_Section_Proper(
770
+			array(
771
+				'layout_strategy' => new EE_Template_Layout(
772
+					array(
773
+						'layout_template_file' => SPCO_REG_STEPS_PATH
774
+												  . $this->_slug
775
+												  . DS
776
+												  . 'no_payment_required.template.php', // layout_template
777
+						'template_args'        => apply_filters(
778
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args',
779
+							array(
780
+								'revisit'                       => $this->checkout->revisit,
781
+								'registrations'                 => array(),
782
+								'ticket_count'                  => array(),
783
+								'registrations_for_free_events' => $registrations_for_free_events,
784
+								'no_payment_required_msg'       => EEH_HTML::p(
785
+									esc_html__('This is a free event, so no billing will occur.', 'event_espresso')
786
+								),
787
+							)
788
+						),
789
+					)
790
+				),
791
+			)
792
+		);
793
+	}
794
+
795
+
796
+	/**
797
+	 * _display_payment_options
798
+	 *
799
+	 * @param string $transaction_details
800
+	 * @return EE_Form_Section_Proper
801
+	 * @throws EE_Error
802
+	 * @throws InvalidArgumentException
803
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
804
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
805
+	 */
806
+	private function _display_payment_options($transaction_details = '')
807
+	{
808
+		// has method_of_payment been set by no-js user?
809
+		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment();
810
+		// build payment options form
811
+		return apply_filters(
812
+			'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__payment_options_form',
813
+			new EE_Form_Section_Proper(
814
+				array(
815
+					'subsections'     => array(
816
+						'before_payment_options' => apply_filters(
817
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options',
818
+							new EE_Form_Section_Proper(
819
+								array('layout_strategy' => new EE_Div_Per_Section_Layout())
820
+							)
821
+						),
822
+						'payment_options'        => $this->_setup_payment_options(),
823
+						'after_payment_options'  => apply_filters(
824
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options',
825
+							new EE_Form_Section_Proper(
826
+								array('layout_strategy' => new EE_Div_Per_Section_Layout())
827
+							)
828
+						),
829
+					),
830
+					'layout_strategy' => new EE_Template_Layout(
831
+						array(
832
+							'layout_template_file' => $this->_template,
833
+							'template_args'        => apply_filters(
834
+								'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__template_args',
835
+								array(
836
+									'reg_count'                 => $this->line_item_display->total_items(),
837
+									'transaction_details'       => $transaction_details,
838
+									'available_payment_methods' => array(),
839
+								)
840
+							),
841
+						)
842
+					),
843
+				)
844
+			)
845
+		);
846
+	}
847
+
848
+
849
+	/**
850
+	 * _extra_hidden_inputs
851
+	 *
852
+	 * @param bool $no_payment_required
853
+	 * @return \EE_Form_Section_Proper
854
+	 * @throws \EE_Error
855
+	 */
856
+	private function _extra_hidden_inputs($no_payment_required = true)
857
+	{
858
+		return new EE_Form_Section_Proper(
859
+			array(
860
+				'html_id'         => 'ee-' . $this->slug() . '-extra-hidden-inputs',
861
+				'layout_strategy' => new EE_Div_Per_Section_Layout(),
862
+				'subsections'     => array(
863
+					'spco_no_payment_required' => new EE_Hidden_Input(
864
+						array(
865
+							'normalization_strategy' => new EE_Boolean_Normalization(),
866
+							'html_name'              => 'spco_no_payment_required',
867
+							'html_id'                => 'spco-no-payment-required-payment_options',
868
+							'default'                => $no_payment_required,
869
+						)
870
+					),
871
+					'spco_transaction_id'      => new EE_Fixed_Hidden_Input(
872
+						array(
873
+							'normalization_strategy' => new EE_Int_Normalization(),
874
+							'html_name'              => 'spco_transaction_id',
875
+							'html_id'                => 'spco-transaction-id',
876
+							'default'                => $this->checkout->transaction->ID(),
877
+						)
878
+					),
879
+				),
880
+			)
881
+		);
882
+	}
883
+
884
+
885
+	/**
886
+	 *    _apply_registration_payments_to_amount_owing
887
+	 *
888
+	 * @access protected
889
+	 * @param array $registrations
890
+	 * @throws EE_Error
891
+	 */
892
+	protected function _apply_registration_payments_to_amount_owing(array $registrations)
893
+	{
894
+		$payments = array();
895
+		foreach ($registrations as $registration) {
896
+			if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
897
+				$payments += $registration->registration_payments();
898
+			}
899
+		}
900
+		if (! empty($payments)) {
901
+			foreach ($payments as $payment) {
902
+				if ($payment instanceof EE_Registration_Payment) {
903
+					$this->checkout->amount_owing -= $payment->amount();
904
+				}
905
+			}
906
+		}
907
+	}
908
+
909
+
910
+	/**
911
+	 *    _reset_selected_method_of_payment
912
+	 *
913
+	 * @access    private
914
+	 * @param    bool $force_reset
915
+	 * @return void
916
+	 * @throws InvalidArgumentException
917
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
918
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
919
+	 */
920
+	private function _reset_selected_method_of_payment($force_reset = false)
921
+	{
922
+		$reset_payment_method = $force_reset
923
+			? true
924
+			: sanitize_text_field(EE_Registry::instance()->REQ->get('reset_payment_method', false));
925
+		if ($reset_payment_method) {
926
+			$this->checkout->selected_method_of_payment = null;
927
+			$this->checkout->payment_method             = null;
928
+			$this->checkout->billing_form               = null;
929
+			$this->_save_selected_method_of_payment();
930
+		}
931
+	}
932
+
933
+
934
+	/**
935
+	 * _save_selected_method_of_payment
936
+	 * stores the selected_method_of_payment in the session
937
+	 * so that it's available for all subsequent requests including AJAX
938
+	 *
939
+	 * @access        private
940
+	 * @param string $selected_method_of_payment
941
+	 * @return void
942
+	 * @throws InvalidArgumentException
943
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
944
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
945
+	 */
946
+	private function _save_selected_method_of_payment($selected_method_of_payment = '')
947
+	{
948
+		$selected_method_of_payment = ! empty($selected_method_of_payment)
949
+			? $selected_method_of_payment
950
+			: $this->checkout->selected_method_of_payment;
951
+		EE_Registry::instance()->SSN->set_session_data(
952
+			array('selected_method_of_payment' => $selected_method_of_payment)
953
+		);
954
+	}
955
+
956
+
957
+	/**
958
+	 * _setup_payment_options
959
+	 *
960
+	 * @return EE_Form_Section_Proper
961
+	 * @throws EE_Error
962
+	 * @throws InvalidArgumentException
963
+	 * @throws ReflectionException
964
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
965
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
966
+	 */
967
+	public function _setup_payment_options()
968
+	{
969
+		// load payment method classes
970
+		$this->checkout->available_payment_methods = $this->_get_available_payment_methods();
971
+		if (empty($this->checkout->available_payment_methods)) {
972
+			EE_Error::add_error(
973
+				apply_filters(
974
+					'FHEE__EE_SPCO_Reg_Step_Payment_Options___setup_payment_options__error_message_no_payment_methods',
975
+					sprintf(
976
+						esc_html__(
977
+							'Sorry, you cannot complete your purchase because a payment method is not active.%1$s Please contact %2$s for assistance and provide a description of the problem.',
978
+							'event_espresso'
979
+						),
980
+						'<br>',
981
+						EE_Registry::instance()->CFG->organization->get_pretty('email')
982
+					)
983
+				),
984
+				__FILE__,
985
+				__FUNCTION__,
986
+				__LINE__
987
+			);
988
+		}
989
+		// switch up header depending on number of available payment methods
990
+		$payment_method_header     = count($this->checkout->available_payment_methods) > 1
991
+			? apply_filters(
992
+				'FHEE__registration_page_payment_options__method_of_payment_hdr',
993
+				esc_html__('Please Select Your Method of Payment', 'event_espresso')
994
+			)
995
+			: apply_filters(
996
+				'FHEE__registration_page_payment_options__method_of_payment_hdr',
997
+				esc_html__('Method of Payment', 'event_espresso')
998
+			);
999
+		$available_payment_methods = array(
1000
+			// display the "Payment Method" header
1001
+			'payment_method_header' => new EE_Form_Section_HTML(
1002
+				EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr')
1003
+			),
1004
+		);
1005
+		// the list of actual payment methods ( invoice, paypal, etc ) in a  ( slug => HTML )  format
1006
+		$available_payment_method_options = array();
1007
+		$default_payment_method_option    = array();
1008
+		// additional instructions to be displayed and hidden below payment methods (adding a clearing div to start)
1009
+		$payment_methods_billing_info = array(
1010
+			new EE_Form_Section_HTML(
1011
+				EEH_HTML::div('<br />', '', '', 'clear:both;')
1012
+			),
1013
+		);
1014
+		// loop through payment methods
1015
+		foreach ($this->checkout->available_payment_methods as $payment_method) {
1016
+			if ($payment_method instanceof EE_Payment_Method) {
1017
+				$payment_method_button = EEH_HTML::img(
1018
+					$payment_method->button_url(),
1019
+					$payment_method->name(),
1020
+					'spco-payment-method-' . $payment_method->slug() . '-btn-img',
1021
+					'spco-payment-method-btn-img'
1022
+				);
1023
+				// check if any payment methods are set as default
1024
+				// if payment method is already selected OR nothing is selected and this payment method should be
1025
+				// open_by_default
1026
+				if (($this->checkout->selected_method_of_payment === $payment_method->slug())
1027
+					|| (! $this->checkout->selected_method_of_payment && $payment_method->open_by_default())
1028
+				) {
1029
+					$this->checkout->selected_method_of_payment = $payment_method->slug();
1030
+					$this->_save_selected_method_of_payment();
1031
+					$default_payment_method_option[$payment_method->slug()] = $payment_method_button;
1032
+				} else {
1033
+					$available_payment_method_options[$payment_method->slug()] = $payment_method_button;
1034
+				}
1035
+				$payment_methods_billing_info[$payment_method->slug() . '-info'] = $this->_payment_method_billing_info(
1036
+					$payment_method
1037
+				);
1038
+			}
1039
+		}
1040
+		// prepend available_payment_method_options with default_payment_method_option so that it appears first in list
1041
+		// of PMs
1042
+		$available_payment_method_options = $default_payment_method_option + $available_payment_method_options;
1043
+		// now generate the actual form  inputs
1044
+		$available_payment_methods['available_payment_methods'] = $this->_available_payment_method_inputs(
1045
+			$available_payment_method_options
1046
+		);
1047
+		$available_payment_methods                              += $payment_methods_billing_info;
1048
+		// build the available payment methods form
1049
+		return new EE_Form_Section_Proper(
1050
+			array(
1051
+				'html_id'         => 'spco-available-methods-of-payment-dv',
1052
+				'subsections'     => $available_payment_methods,
1053
+				'layout_strategy' => new EE_Div_Per_Section_Layout(),
1054
+			)
1055
+		);
1056
+	}
1057
+
1058
+
1059
+	/**
1060
+	 * _get_available_payment_methods
1061
+	 *
1062
+	 * @return EE_Payment_Method[]
1063
+	 * @throws EE_Error
1064
+	 * @throws InvalidArgumentException
1065
+	 * @throws ReflectionException
1066
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1067
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1068
+	 */
1069
+	protected function _get_available_payment_methods()
1070
+	{
1071
+		if (! empty($this->checkout->available_payment_methods)) {
1072
+			return $this->checkout->available_payment_methods;
1073
+		}
1074
+		$available_payment_methods = array();
1075
+		// load EEM_Payment_Method
1076
+		EE_Registry::instance()->load_model('Payment_Method');
1077
+		/** @type EEM_Payment_Method $EEM_Payment_Method */
1078
+		$EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method;
1079
+		// get all active payment methods
1080
+		$payment_methods = $EEM_Payment_Method->get_all_for_transaction(
1081
+			$this->checkout->transaction,
1082
+			EEM_Payment_Method::scope_cart
1083
+		);
1084
+		foreach ($payment_methods as $payment_method) {
1085
+			if ($payment_method instanceof EE_Payment_Method) {
1086
+				$available_payment_methods[$payment_method->slug()] = $payment_method;
1087
+			}
1088
+		}
1089
+		return $available_payment_methods;
1090
+	}
1091
+
1092
+
1093
+	/**
1094
+	 *    _available_payment_method_inputs
1095
+	 *
1096
+	 * @access    private
1097
+	 * @param    array $available_payment_method_options
1098
+	 * @return    \EE_Form_Section_Proper
1099
+	 */
1100
+	private function _available_payment_method_inputs($available_payment_method_options = array())
1101
+	{
1102
+		// generate inputs
1103
+		return new EE_Form_Section_Proper(
1104
+			array(
1105
+				'html_id'         => 'ee-available-payment-method-inputs',
1106
+				'layout_strategy' => new EE_Div_Per_Section_Layout(),
1107
+				'subsections'     => array(
1108
+					'' => new EE_Radio_Button_Input(
1109
+						$available_payment_method_options,
1110
+						array(
1111
+							'html_name'          => 'selected_method_of_payment',
1112
+							'html_class'         => 'spco-payment-method',
1113
+							'default'            => $this->checkout->selected_method_of_payment,
1114
+							'label_size'         => 11,
1115
+							'enforce_label_size' => true,
1116
+						)
1117
+					),
1118
+				),
1119
+			)
1120
+		);
1121
+	}
1122
+
1123
+
1124
+	/**
1125
+	 *    _payment_method_billing_info
1126
+	 *
1127
+	 * @access    private
1128
+	 * @param    EE_Payment_Method $payment_method
1129
+	 * @return EE_Form_Section_Proper
1130
+	 * @throws EE_Error
1131
+	 * @throws InvalidArgumentException
1132
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1133
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1134
+	 */
1135
+	private function _payment_method_billing_info(EE_Payment_Method $payment_method)
1136
+	{
1137
+		$currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug()
1138
+			? true
1139
+			: false;
1140
+		// generate the billing form for payment method
1141
+		$billing_form                 = $currently_selected
1142
+			? $this->_get_billing_form_for_payment_method($payment_method)
1143
+			: new EE_Form_Section_HTML();
1144
+		$this->checkout->billing_form = $currently_selected
1145
+			? $billing_form
1146
+			: $this->checkout->billing_form;
1147
+		// it's all in the details
1148
+		$info_html = EEH_HTML::h3(
1149
+			esc_html__('Important information regarding your payment', 'event_espresso'),
1150
+			'',
1151
+			'spco-payment-method-hdr'
1152
+		);
1153
+		// add some info regarding the step, either from what's saved in the admin,
1154
+		// or a default string depending on whether the PM has a billing form or not
1155
+		if ($payment_method->description()) {
1156
+			$payment_method_info = $payment_method->description();
1157
+		} elseif ($billing_form instanceof EE_Billing_Info_Form) {
1158
+			$payment_method_info = sprintf(
1159
+				esc_html__(
1160
+					'Please provide the following billing information, then click the "%1$s" button below in order to proceed.',
1161
+					'event_espresso'
1162
+				),
1163
+				$this->submit_button_text()
1164
+			);
1165
+		} else {
1166
+			$payment_method_info = sprintf(
1167
+				esc_html__('Please click the "%1$s" button below in order to proceed.', 'event_espresso'),
1168
+				$this->submit_button_text()
1169
+			);
1170
+		}
1171
+		$info_html .= EEH_HTML::p(
1172
+			apply_filters(
1173
+				'FHEE__EE_SPCO_Reg_Step_Payment_Options___payment_method_billing_info__payment_method_info',
1174
+				$payment_method_info
1175
+			),
1176
+			'',
1177
+			'spco-payment-method-desc ee-attention'
1178
+		);
1179
+		return new EE_Form_Section_Proper(
1180
+			array(
1181
+				'html_id'         => 'spco-payment-method-info-' . $payment_method->slug(),
1182
+				'html_class'      => 'spco-payment-method-info-dv',
1183
+				// only display the selected or default PM
1184
+				'html_style'      => $currently_selected ? '' : 'display:none;',
1185
+				'layout_strategy' => new EE_Div_Per_Section_Layout(),
1186
+				'subsections'     => array(
1187
+					'info'         => new EE_Form_Section_HTML($info_html),
1188
+					'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML(),
1189
+				),
1190
+			)
1191
+		);
1192
+	}
1193
+
1194
+
1195
+	/**
1196
+	 * get_billing_form_html_for_payment_method
1197
+	 *
1198
+	 * @access public
1199
+	 * @return string
1200
+	 * @throws EE_Error
1201
+	 * @throws InvalidArgumentException
1202
+	 * @throws ReflectionException
1203
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1204
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1205
+	 */
1206
+	public function get_billing_form_html_for_payment_method()
1207
+	{
1208
+		// how have they chosen to pay?
1209
+		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
1210
+		$this->checkout->payment_method             = $this->_get_payment_method_for_selected_method_of_payment();
1211
+		if (! $this->checkout->payment_method instanceof EE_Payment_Method) {
1212
+			return false;
1213
+		}
1214
+		if (apply_filters(
1215
+			'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1216
+			false
1217
+		)) {
1218
+			EE_Error::add_success(
1219
+				apply_filters(
1220
+					'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
1221
+					sprintf(
1222
+						esc_html__(
1223
+							'You have selected "%s" as your method of payment. Please note the important payment information below.',
1224
+							'event_espresso'
1225
+						),
1226
+						$this->checkout->payment_method->name()
1227
+					)
1228
+				)
1229
+			);
1230
+		}
1231
+		// now generate billing form for selected method of payment
1232
+		$payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method);
1233
+		// fill form with attendee info if applicable
1234
+		if ($payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form
1235
+			&& $this->checkout->transaction_has_primary_registrant()
1236
+		) {
1237
+			$payment_method_billing_form->populate_from_attendee(
1238
+				$this->checkout->transaction->primary_registration()->attendee()
1239
+			);
1240
+		}
1241
+		// and debug content
1242
+		if ($payment_method_billing_form instanceof EE_Billing_Info_Form
1243
+			&& $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base
1244
+		) {
1245
+			$payment_method_billing_form =
1246
+				$this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings(
1247
+					$payment_method_billing_form
1248
+				);
1249
+		}
1250
+		$billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper
1251
+			? $payment_method_billing_form->get_html()
1252
+			: '';
1253
+		$this->checkout->json_response->set_return_data(array('payment_method_info' => $billing_info));
1254
+		// localize validation rules for main form
1255
+		$this->checkout->current_step->reg_form->localize_validation_rules();
1256
+		$this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
1257
+		return true;
1258
+	}
1259
+
1260
+
1261
+	/**
1262
+	 * _get_billing_form_for_payment_method
1263
+	 *
1264
+	 * @access private
1265
+	 * @param EE_Payment_Method $payment_method
1266
+	 * @return EE_Billing_Info_Form|EE_Form_Section_HTML
1267
+	 * @throws EE_Error
1268
+	 * @throws InvalidArgumentException
1269
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1270
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1271
+	 */
1272
+	private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method)
1273
+	{
1274
+		$billing_form = $payment_method->type_obj()->billing_form(
1275
+			$this->checkout->transaction,
1276
+			array('amount_owing' => $this->checkout->amount_owing)
1277
+		);
1278
+		if ($billing_form instanceof EE_Billing_Info_Form) {
1279
+			if (apply_filters(
1280
+				'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1281
+				false
1282
+			)
1283
+				&& EE_Registry::instance()->REQ->is_set('payment_method')
1284
+			) {
1285
+				EE_Error::add_success(
1286
+					apply_filters(
1287
+						'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
1288
+						sprintf(
1289
+							esc_html__(
1290
+								'You have selected "%s" as your method of payment. Please note the important payment information below.',
1291
+								'event_espresso'
1292
+							),
1293
+							$payment_method->name()
1294
+						)
1295
+					)
1296
+				);
1297
+			}
1298
+			return apply_filters(
1299
+				'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
1300
+				$billing_form,
1301
+				$payment_method
1302
+			);
1303
+		}
1304
+		// no actual billing form, so return empty HTML form section
1305
+		return new EE_Form_Section_HTML();
1306
+	}
1307
+
1308
+
1309
+	/**
1310
+	 * _get_selected_method_of_payment
1311
+	 *
1312
+	 * @access private
1313
+	 * @param boolean $required whether to throw an error if the "selected_method_of_payment"
1314
+	 *                          is not found in the incoming request
1315
+	 * @param string  $request_param
1316
+	 * @return NULL|string
1317
+	 * @throws EE_Error
1318
+	 * @throws InvalidArgumentException
1319
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1320
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1321
+	 */
1322
+	private function _get_selected_method_of_payment(
1323
+		$required = false,
1324
+		$request_param = 'selected_method_of_payment'
1325
+	) {
1326
+		// is selected_method_of_payment set in the request ?
1327
+		$selected_method_of_payment = EE_Registry::instance()->REQ->get($request_param, false);
1328
+		if ($selected_method_of_payment) {
1329
+			// sanitize it
1330
+			$selected_method_of_payment = is_array($selected_method_of_payment)
1331
+				? array_shift($selected_method_of_payment)
1332
+				: $selected_method_of_payment;
1333
+			$selected_method_of_payment = sanitize_text_field($selected_method_of_payment);
1334
+			// store it in the session so that it's available for all subsequent requests including AJAX
1335
+			$this->_save_selected_method_of_payment($selected_method_of_payment);
1336
+		} else {
1337
+			// or is is set in the session ?
1338
+			$selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data(
1339
+				'selected_method_of_payment'
1340
+			);
1341
+		}
1342
+		// do ya really really gotta have it?
1343
+		if (empty($selected_method_of_payment) && $required) {
1344
+			EE_Error::add_error(
1345
+				sprintf(
1346
+					esc_html__(
1347
+						'The selected method of payment could not be determined.%sPlease ensure that you have selected one before proceeding.%sIf you continue to experience difficulties, then refresh your browser and try again, or contact %s for assistance.',
1348
+						'event_espresso'
1349
+					),
1350
+					'<br/>',
1351
+					'<br/>',
1352
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
1353
+				),
1354
+				__FILE__,
1355
+				__FUNCTION__,
1356
+				__LINE__
1357
+			);
1358
+			return null;
1359
+		}
1360
+		return $selected_method_of_payment;
1361
+	}
1362
+
1363
+
1364
+
1365
+
1366
+
1367
+
1368
+	/********************************************************************************************************/
1369
+	/***********************************  SWITCH PAYMENT METHOD  ************************************/
1370
+	/********************************************************************************************************/
1371
+	/**
1372
+	 * switch_payment_method
1373
+	 *
1374
+	 * @access public
1375
+	 * @return string
1376
+	 * @throws EE_Error
1377
+	 * @throws InvalidArgumentException
1378
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1379
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1380
+	 */
1381
+	public function switch_payment_method()
1382
+	{
1383
+		if (! $this->_verify_payment_method_is_set()) {
1384
+			return false;
1385
+		}
1386
+		if (apply_filters(
1387
+			'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success',
1388
+			false
1389
+		)) {
1390
+			EE_Error::add_success(
1391
+				apply_filters(
1392
+					'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method',
1393
+					sprintf(
1394
+						esc_html__(
1395
+							'You have selected "%s" as your method of payment. Please note the important payment information below.',
1396
+							'event_espresso'
1397
+						),
1398
+						$this->checkout->payment_method->name()
1399
+					)
1400
+				)
1401
+			);
1402
+		}
1403
+		// generate billing form for selected method of payment if it hasn't been done already
1404
+		if ($this->checkout->payment_method->type_obj()->has_billing_form()) {
1405
+			$this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1406
+				$this->checkout->payment_method
1407
+			);
1408
+		}
1409
+		// fill form with attendee info if applicable
1410
+		if (apply_filters(
1411
+			'FHEE__populate_billing_form_fields_from_attendee',
1412
+			(
1413
+				$this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form
1414
+				&& $this->checkout->transaction_has_primary_registrant()
1415
+			),
1416
+			$this->checkout->billing_form,
1417
+			$this->checkout->transaction
1418
+		)
1419
+		) {
1420
+			$this->checkout->billing_form->populate_from_attendee(
1421
+				$this->checkout->transaction->primary_registration()->attendee()
1422
+			);
1423
+		}
1424
+		// and debug content
1425
+		if ($this->checkout->billing_form instanceof EE_Billing_Info_Form
1426
+			&& $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base
1427
+		) {
1428
+			$this->checkout->billing_form =
1429
+				$this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings(
1430
+					$this->checkout->billing_form
1431
+				);
1432
+		}
1433
+		// get html and validation rules for form
1434
+		if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) {
1435
+			$this->checkout->json_response->set_return_data(
1436
+				array('payment_method_info' => $this->checkout->billing_form->get_html())
1437
+			);
1438
+			// localize validation rules for main form
1439
+			$this->checkout->billing_form->localize_validation_rules(true);
1440
+			$this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization());
1441
+		} else {
1442
+			$this->checkout->json_response->set_return_data(array('payment_method_info' => ''));
1443
+		}
1444
+		//prevents advancement to next step
1445
+		$this->checkout->continue_reg = false;
1446
+		return true;
1447
+	}
1448
+
1449
+
1450
+	/**
1451
+	 * _verify_payment_method_is_set
1452
+	 *
1453
+	 * @return bool
1454
+	 * @throws EE_Error
1455
+	 * @throws InvalidArgumentException
1456
+	 * @throws ReflectionException
1457
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1458
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1459
+	 */
1460
+	protected function _verify_payment_method_is_set()
1461
+	{
1462
+		// generate billing form for selected method of payment if it hasn't been done already
1463
+		if (empty($this->checkout->selected_method_of_payment)) {
1464
+			// how have they chosen to pay?
1465
+			$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
1466
+		} else {
1467
+			// choose your own adventure based on method_of_payment
1468
+			switch ($this->checkout->selected_method_of_payment) {
1469
+				case 'events_sold_out' :
1470
+					EE_Error::add_attention(
1471
+						apply_filters(
1472
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg',
1473
+							esc_html__(
1474
+								'It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.',
1475
+								'event_espresso'
1476
+							)
1477
+						),
1478
+						__FILE__, __FUNCTION__, __LINE__
1479
+					);
1480
+					return false;
1481
+					break;
1482
+				case 'payments_closed' :
1483
+					EE_Error::add_attention(
1484
+						apply_filters(
1485
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg',
1486
+							esc_html__(
1487
+								'It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.',
1488
+								'event_espresso'
1489
+							)
1490
+						),
1491
+						__FILE__, __FUNCTION__, __LINE__
1492
+					);
1493
+					return false;
1494
+					break;
1495
+				case 'no_payment_required' :
1496
+					EE_Error::add_attention(
1497
+						apply_filters(
1498
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg',
1499
+							esc_html__(
1500
+								'It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.',
1501
+								'event_espresso'
1502
+							)
1503
+						),
1504
+						__FILE__, __FUNCTION__, __LINE__
1505
+					);
1506
+					return false;
1507
+					break;
1508
+				default:
1509
+			}
1510
+		}
1511
+		// verify payment method
1512
+		if (! $this->checkout->payment_method instanceof EE_Payment_Method) {
1513
+			// get payment method for selected method of payment
1514
+			$this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment();
1515
+		}
1516
+		return $this->checkout->payment_method instanceof EE_Payment_Method ? true : false;
1517
+	}
1518
+
1519
+
1520
+
1521
+	/********************************************************************************************************/
1522
+	/***************************************  SAVE PAYER DETAILS  ****************************************/
1523
+	/********************************************************************************************************/
1524
+	/**
1525
+	 * save_payer_details_via_ajax
1526
+	 *
1527
+	 * @return void
1528
+	 * @throws EE_Error
1529
+	 * @throws InvalidArgumentException
1530
+	 * @throws ReflectionException
1531
+	 * @throws RuntimeException
1532
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1533
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1534
+	 */
1535
+	public function save_payer_details_via_ajax()
1536
+	{
1537
+		if (! $this->_verify_payment_method_is_set()) {
1538
+			return;
1539
+		}
1540
+		// generate billing form for selected method of payment if it hasn't been done already
1541
+		if ($this->checkout->payment_method->type_obj()->has_billing_form()) {
1542
+			$this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1543
+				$this->checkout->payment_method
1544
+			);
1545
+		}
1546
+		// generate primary attendee from payer info if applicable
1547
+		if (! $this->checkout->transaction_has_primary_registrant()) {
1548
+			$attendee = $this->_create_attendee_from_request_data();
1549
+			if ($attendee instanceof EE_Attendee) {
1550
+				foreach ($this->checkout->transaction->registrations() as $registration) {
1551
+					if ($registration->is_primary_registrant()) {
1552
+						$this->checkout->primary_attendee_obj = $attendee;
1553
+						$registration->_add_relation_to($attendee, 'Attendee');
1554
+						$registration->set_attendee_id($attendee->ID());
1555
+						$registration->update_cache_after_object_save('Attendee', $attendee);
1556
+					}
1557
+				}
1558
+			}
1559
+		}
1560
+	}
1561
+
1562
+
1563
+	/**
1564
+	 * create_attendee_from_request_data
1565
+	 * uses info from alternate GET or POST data (such as AJAX) to create a new attendee
1566
+	 *
1567
+	 * @return EE_Attendee
1568
+	 * @throws EE_Error
1569
+	 * @throws InvalidArgumentException
1570
+	 * @throws ReflectionException
1571
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1572
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1573
+	 */
1574
+	protected function _create_attendee_from_request_data()
1575
+	{
1576
+		// get State ID
1577
+		$STA_ID = ! empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : '';
1578
+		if (! empty($STA_ID)) {
1579
+			// can we get state object from name ?
1580
+			EE_Registry::instance()->load_model('State');
1581
+			$state  = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID');
1582
+			$STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID;
1583
+		}
1584
+		// get Country ISO
1585
+		$CNT_ISO = ! empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : '';
1586
+		if (! empty($CNT_ISO)) {
1587
+			// can we get country object from name ?
1588
+			EE_Registry::instance()->load_model('Country');
1589
+			$country = EEM_Country::instance()->get_col(
1590
+				array(array('CNT_name' => $CNT_ISO), 'limit' => 1),
1591
+				'CNT_ISO'
1592
+			);
1593
+			$CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO;
1594
+		}
1595
+		// grab attendee data
1596
+		$attendee_data = array(
1597
+			'ATT_fname'    => ! empty($_REQUEST['first_name']) ? sanitize_text_field($_REQUEST['first_name']) : '',
1598
+			'ATT_lname'    => ! empty($_REQUEST['last_name']) ? sanitize_text_field($_REQUEST['last_name']) : '',
1599
+			'ATT_email'    => ! empty($_REQUEST['email']) ? sanitize_email($_REQUEST['email']) : '',
1600
+			'ATT_address'  => ! empty($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '',
1601
+			'ATT_address2' => ! empty($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '',
1602
+			'ATT_city'     => ! empty($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '',
1603
+			'STA_ID'       => $STA_ID,
1604
+			'CNT_ISO'      => $CNT_ISO,
1605
+			'ATT_zip'      => ! empty($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '',
1606
+			'ATT_phone'    => ! empty($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : '',
1607
+		);
1608
+		// validate the email address since it is the most important piece of info
1609
+		if (empty($attendee_data['ATT_email']) || $attendee_data['ATT_email'] !== $_REQUEST['email']) {
1610
+			EE_Error::add_error(
1611
+				esc_html__('An invalid email address was submitted.', 'event_espresso'),
1612
+				__FILE__,
1613
+				__FUNCTION__,
1614
+				__LINE__
1615
+			);
1616
+		}
1617
+		// does this attendee already exist in the db ? we're searching using a combination of first name, last name,
1618
+		// AND email address
1619
+		if (! empty($attendee_data['ATT_fname'])
1620
+			&& ! empty($attendee_data['ATT_lname'])
1621
+			&& ! empty($attendee_data['ATT_email'])
1622
+		) {
1623
+			$existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee(
1624
+				array(
1625
+					'ATT_fname' => $attendee_data['ATT_fname'],
1626
+					'ATT_lname' => $attendee_data['ATT_lname'],
1627
+					'ATT_email' => $attendee_data['ATT_email'],
1628
+				)
1629
+			);
1630
+			if ($existing_attendee instanceof EE_Attendee) {
1631
+				return $existing_attendee;
1632
+			}
1633
+		}
1634
+		// no existing attendee? kk let's create a new one
1635
+		// kinda lame, but we need a first and last name to create an attendee, so use the email address if those
1636
+		// don't exist
1637
+		$attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname'])
1638
+			? $attendee_data['ATT_fname']
1639
+			: $attendee_data['ATT_email'];
1640
+		$attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname'])
1641
+			? $attendee_data['ATT_lname']
1642
+			: $attendee_data['ATT_email'];
1643
+		return EE_Attendee::new_instance($attendee_data);
1644
+	}
1645
+
1646
+
1647
+
1648
+	/********************************************************************************************************/
1649
+	/****************************************  PROCESS REG STEP  *****************************************/
1650
+	/********************************************************************************************************/
1651
+	/**
1652
+	 * process_reg_step
1653
+	 *
1654
+	 * @return bool
1655
+	 * @throws EE_Error
1656
+	 * @throws InvalidArgumentException
1657
+	 * @throws ReflectionException
1658
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1659
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1660
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1661
+	 * @throws \EventEspresso\core\exceptions\InvalidStatusException
1662
+	 */
1663
+	public function process_reg_step()
1664
+	{
1665
+		// how have they chosen to pay?
1666
+		$this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free()
1667
+			? 'no_payment_required'
1668
+			: $this->_get_selected_method_of_payment(true);
1669
+		// choose your own adventure based on method_of_payment
1670
+		switch ($this->checkout->selected_method_of_payment) {
1671
+
1672
+			case 'events_sold_out' :
1673
+				$this->checkout->redirect     = true;
1674
+				$this->checkout->redirect_url = $this->checkout->cancel_page_url;
1675
+				$this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1676
+				// mark this reg step as completed
1677
+				$this->set_completed();
1678
+				return false;
1679
+				break;
1680
+
1681
+			case 'payments_closed' :
1682
+				if (apply_filters(
1683
+					'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success',
1684
+					false
1685
+				)) {
1686
+					EE_Error::add_success(
1687
+						esc_html__('no payment required at this time.', 'event_espresso'),
1688
+						__FILE__,
1689
+						__FUNCTION__,
1690
+						__LINE__
1691
+					);
1692
+				}
1693
+				// mark this reg step as completed
1694
+				$this->set_completed();
1695
+				return true;
1696
+				break;
1697
+
1698
+			case 'no_payment_required' :
1699
+				if (apply_filters(
1700
+					'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success',
1701
+					false
1702
+				)) {
1703
+					EE_Error::add_success(
1704
+						esc_html__('no payment required.', 'event_espresso'),
1705
+						__FILE__,
1706
+						__FUNCTION__,
1707
+						__LINE__
1708
+					);
1709
+				}
1710
+				// mark this reg step as completed
1711
+				$this->set_completed();
1712
+				return true;
1713
+				break;
1714
+
1715
+			default:
1716
+				$registrations         = EE_Registry::instance()->SSN->checkout()->transaction->registrations(
1717
+					EE_Registry::instance()->SSN->checkout()->reg_cache_where_params
1718
+				);
1719
+				$ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space(
1720
+					$registrations,
1721
+					EE_Registry::instance()->SSN->checkout()->revisit
1722
+				);
1723
+				// calculate difference between the two arrays
1724
+				$registrations = array_diff($registrations, $ejected_registrations);
1725
+				if (empty($registrations)) {
1726
+					$this->_redirect_because_event_sold_out();
1727
+					return false;
1728
+				}
1729
+				$payment_successful = $this->_process_payment();
1730
+				if ($payment_successful) {
1731
+					$this->checkout->continue_reg = true;
1732
+					$this->_maybe_set_completed($this->checkout->payment_method);
1733
+				} else {
1734
+					$this->checkout->continue_reg = false;
1735
+				}
1736
+				return $payment_successful;
1737
+		}
1738
+	}
1739
+
1740
+
1741
+	/**
1742
+	 * _redirect_because_event_sold_out
1743
+	 *
1744
+	 * @access protected
1745
+	 * @return void
1746
+	 */
1747
+	protected function _redirect_because_event_sold_out()
1748
+	{
1749
+		$this->checkout->continue_reg = false;
1750
+		// set redirect URL
1751
+		$this->checkout->redirect_url = add_query_arg(
1752
+			array('e_reg_url_link' => $this->checkout->reg_url_link),
1753
+			$this->checkout->current_step->reg_step_url()
1754
+		);
1755
+		$this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1756
+	}
1757
+
1758
+
1759
+	/**
1760
+	 * _maybe_set_completed
1761
+	 *
1762
+	 * @access protected
1763
+	 * @param \EE_Payment_Method $payment_method
1764
+	 * @return void
1765
+	 * @throws \EE_Error
1766
+	 */
1767
+	protected function _maybe_set_completed(EE_Payment_Method $payment_method)
1768
+	{
1769
+		switch ($payment_method->type_obj()->payment_occurs()) {
1770
+			case EE_PMT_Base::offsite :
1771
+				break;
1772
+			case EE_PMT_Base::onsite :
1773
+			case EE_PMT_Base::offline :
1774
+				// mark this reg step as completed
1775
+				$this->set_completed();
1776
+				break;
1777
+		}
1778
+	}
1779
+
1780
+
1781
+	/**
1782
+	 *    update_reg_step
1783
+	 *    this is the final step after a user  revisits the site to retry a payment
1784
+	 *
1785
+	 * @return bool
1786
+	 * @throws EE_Error
1787
+	 * @throws InvalidArgumentException
1788
+	 * @throws ReflectionException
1789
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1790
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1791
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1792
+	 * @throws \EventEspresso\core\exceptions\InvalidStatusException
1793
+	 */
1794
+	public function update_reg_step()
1795
+	{
1796
+		$success = true;
1797
+		// if payment required
1798
+		if ($this->checkout->transaction->total() > 0) {
1799
+			do_action(
1800
+				'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway',
1801
+				$this->checkout->transaction
1802
+			);
1803
+			// attempt payment via payment method
1804
+			$success = $this->process_reg_step();
1805
+		}
1806
+		if ($success && ! $this->checkout->redirect) {
1807
+			$this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn(
1808
+				$this->checkout->transaction->ID()
1809
+			);
1810
+			// set return URL
1811
+			$this->checkout->redirect_url = add_query_arg(
1812
+				array('e_reg_url_link' => $this->checkout->reg_url_link),
1813
+				$this->checkout->thank_you_page_url
1814
+			);
1815
+		}
1816
+		return $success;
1817
+	}
1818
+
1819
+
1820
+	/**
1821
+	 *    _process_payment
1822
+	 *
1823
+	 * @access private
1824
+	 * @return bool
1825
+	 * @throws EE_Error
1826
+	 * @throws InvalidArgumentException
1827
+	 * @throws ReflectionException
1828
+	 * @throws RuntimeException
1829
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1830
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1831
+	 */
1832
+	private function _process_payment()
1833
+	{
1834
+		// basically confirm that the event hasn't sold out since they hit the page
1835
+		if (! $this->_last_second_ticket_verifications()) {
1836
+			return false;
1837
+		}
1838
+		// ya gotta make a choice man
1839
+		if (empty($this->checkout->selected_method_of_payment)) {
1840
+			$this->checkout->json_response->set_plz_select_method_of_payment(
1841
+				esc_html__('Please select a method of payment before proceeding.', 'event_espresso')
1842
+			);
1843
+			return false;
1844
+		}
1845
+		// get EE_Payment_Method object
1846
+		if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
1847
+			return false;
1848
+		}
1849
+		// setup billing form
1850
+		if ($this->checkout->payment_method->is_on_site()) {
1851
+			$this->checkout->billing_form = $this->_get_billing_form_for_payment_method(
1852
+				$this->checkout->payment_method
1853
+			);
1854
+			// bad billing form ?
1855
+			if (! $this->_billing_form_is_valid()) {
1856
+				return false;
1857
+			}
1858
+		}
1859
+		// ensure primary registrant has been fully processed
1860
+		if (! $this->_setup_primary_registrant_prior_to_payment()) {
1861
+			return false;
1862
+		}
1863
+		// if session is close to expiring (under 10 minutes by default)
1864
+		if ((time() - EE_Registry::instance()->SSN->expiration()) < EE_Registry::instance()->SSN->extension()) {
1865
+			// add some time to session expiration so that payment can be completed
1866
+			EE_Registry::instance()->SSN->extend_expiration();
1867
+		}
1868
+		/** @type EE_Transaction_Processor $transaction_processor */
1869
+		//$transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' );
1870
+		// in case a registrant leaves to an Off-Site Gateway and never returns, we want to approve any registrations
1871
+		// for events with a default reg status of Approved
1872
+		// $transaction_processor->toggle_registration_statuses_for_default_approved_events(
1873
+		//      $this->checkout->transaction, $this->checkout->reg_cache_where_params
1874
+		// );
1875
+		// attempt payment
1876
+		$payment = $this->_attempt_payment($this->checkout->payment_method);
1877
+		// process results
1878
+		$payment = $this->_validate_payment($payment);
1879
+		$payment = $this->_post_payment_processing($payment);
1880
+		// verify payment
1881
+		if ($payment instanceof EE_Payment) {
1882
+			// store that for later
1883
+			$this->checkout->payment = $payment;
1884
+			// we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned
1885
+			$this->checkout->transaction->toggle_failed_transaction_status();
1886
+			$payment_status = $payment->status();
1887
+			if (
1888
+				$payment_status === EEM_Payment::status_id_approved
1889
+				|| $payment_status === EEM_Payment::status_id_pending
1890
+			) {
1891
+				return true;
1892
+			} else {
1893
+				return false;
1894
+			}
1895
+		} else if ($payment === true) {
1896
+			// please note that offline payment methods will NOT make a payment,
1897
+			// but instead just mark themselves as the PMD_ID on the transaction, and return true
1898
+			$this->checkout->payment = $payment;
1899
+			return true;
1900
+		}
1901
+		// where's my money?
1902
+		return false;
1903
+	}
1904
+
1905
+
1906
+	/**
1907
+	 * _last_second_ticket_verifications
1908
+	 *
1909
+	 * @access public
1910
+	 * @return bool
1911
+	 * @throws EE_Error
1912
+	 */
1913
+	protected function _last_second_ticket_verifications()
1914
+	{
1915
+		// don't bother re-validating if not a return visit
1916
+		if (! $this->checkout->revisit) {
1917
+			return true;
1918
+		}
1919
+		$registrations = $this->checkout->transaction->registrations();
1920
+		if (empty($registrations)) {
1921
+			return false;
1922
+		}
1923
+		foreach ($registrations as $registration) {
1924
+			if ($registration instanceof EE_Registration && ! $registration->is_approved()) {
1925
+				$event = $registration->event_obj();
1926
+				if ($event instanceof EE_Event && $event->is_sold_out(true)) {
1927
+					EE_Error::add_error(
1928
+						apply_filters(
1929
+							'FHEE__EE_SPCO_Reg_Step_Payment_Options___last_second_ticket_verifications__sold_out_events_msg',
1930
+							sprintf(
1931
+								esc_html__(
1932
+									'It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.',
1933
+									'event_espresso'
1934
+								),
1935
+								$event->name()
1936
+							)
1937
+						),
1938
+						__FILE__,
1939
+						__FUNCTION__,
1940
+						__LINE__
1941
+					);
1942
+					return false;
1943
+				}
1944
+			}
1945
+		}
1946
+		return true;
1947
+	}
1948
+
1949
+
1950
+	/**
1951
+	 * redirect_form
1952
+	 *
1953
+	 * @access public
1954
+	 * @return bool
1955
+	 * @throws EE_Error
1956
+	 * @throws InvalidArgumentException
1957
+	 * @throws ReflectionException
1958
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
1959
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
1960
+	 */
1961
+	public function redirect_form()
1962
+	{
1963
+		$payment_method_billing_info = $this->_payment_method_billing_info(
1964
+			$this->_get_payment_method_for_selected_method_of_payment()
1965
+		);
1966
+		$html                        = $payment_method_billing_info->get_html();
1967
+		$html                        .= $this->checkout->redirect_form;
1968
+		EE_Registry::instance()->REQ->add_output($html);
1969
+		return true;
1970
+	}
1971
+
1972
+
1973
+	/**
1974
+	 * _billing_form_is_valid
1975
+	 *
1976
+	 * @access private
1977
+	 * @return bool
1978
+	 * @throws \EE_Error
1979
+	 */
1980
+	private function _billing_form_is_valid()
1981
+	{
1982
+		if (! $this->checkout->payment_method->type_obj()->has_billing_form()) {
1983
+			return true;
1984
+		}
1985
+		if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) {
1986
+			if ($this->checkout->billing_form->was_submitted()) {
1987
+				$this->checkout->billing_form->receive_form_submission();
1988
+				if ($this->checkout->billing_form->is_valid()) {
1989
+					return true;
1990
+				}
1991
+				$validation_errors = $this->checkout->billing_form->get_validation_errors_accumulated();
1992
+				$error_strings     = array();
1993
+				foreach ($validation_errors as $validation_error) {
1994
+					if ($validation_error instanceof EE_Validation_Error) {
1995
+						$form_section = $validation_error->get_form_section();
1996
+						if ($form_section instanceof EE_Form_Input_Base) {
1997
+							$label = $form_section->html_label_text();
1998
+						} elseif ($form_section instanceof EE_Form_Section_Base) {
1999
+							$label = $form_section->name();
2000
+						} else {
2001
+							$label = esc_html__('Validation Error', 'event_espresso');
2002
+						}
2003
+						$error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage());
2004
+					}
2005
+				}
2006
+				EE_Error::add_error(
2007
+					sprintf(
2008
+						esc_html__(
2009
+							'One or more billing form inputs are invalid and require correction before proceeding. %1$s %2$s',
2010
+							'event_espresso'
2011
+						),
2012
+						'<br/>',
2013
+						implode('<br/>', $error_strings)
2014
+					),
2015
+					__FILE__,
2016
+					__FUNCTION__,
2017
+					__LINE__
2018
+				);
2019
+			} else {
2020
+				EE_Error::add_error(
2021
+					esc_html__(
2022
+						'The billing form was not submitted or something prevented it\'s submission.',
2023
+						'event_espresso'
2024
+					),
2025
+					__FILE__,
2026
+					__FUNCTION__,
2027
+					__LINE__
2028
+				);
2029
+			}
2030
+		} else {
2031
+			EE_Error::add_error(
2032
+				esc_html__('The submitted billing form is invalid possibly due to a technical reason.', 'event_espresso'),
2033
+				__FILE__,
2034
+				__FUNCTION__,
2035
+				__LINE__
2036
+			);
2037
+		}
2038
+		return false;
2039
+	}
2040
+
2041
+
2042
+	/**
2043
+	 * _setup_primary_registrant_prior_to_payment
2044
+	 * ensures that the primary registrant has a valid attendee object created with the critical details populated
2045
+	 * (first & last name & email) and that both the transaction object and primary registration object have been saved
2046
+	 * plz note that any other registrations will NOT be saved at this point (because they may not have any details
2047
+	 * yet)
2048
+	 *
2049
+	 * @access private
2050
+	 * @return bool
2051
+	 * @throws EE_Error
2052
+	 * @throws InvalidArgumentException
2053
+	 * @throws ReflectionException
2054
+	 * @throws RuntimeException
2055
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2056
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2057
+	 */
2058
+	private function _setup_primary_registrant_prior_to_payment()
2059
+	{
2060
+		// check if transaction has a primary registrant and that it has a related Attendee object
2061
+		// if not, then we need to at least gather some primary registrant data before attempting payment
2062
+		if (
2063
+			$this->checkout->billing_form instanceof EE_Billing_Attendee_Info_Form
2064
+			&& ! $this->checkout->transaction_has_primary_registrant()
2065
+			&& ! $this->_capture_primary_registration_data_from_billing_form()
2066
+		) {
2067
+			return false;
2068
+		}
2069
+		// because saving an object clears it's cache, we need to do the chevy shuffle
2070
+		// grab the primary_registration object
2071
+		$primary_registration = $this->checkout->transaction->primary_registration();
2072
+		// at this point we'll consider a TXN to not have been failed
2073
+		$this->checkout->transaction->toggle_failed_transaction_status();
2074
+		// save the TXN ( which clears cached copy of primary_registration)
2075
+		$this->checkout->transaction->save();
2076
+		// grab TXN ID and save it to the primary_registration
2077
+		$primary_registration->set_transaction_id($this->checkout->transaction->ID());
2078
+		// save what we have so far
2079
+		$primary_registration->save();
2080
+		return true;
2081
+	}
2082
+
2083
+
2084
+	/**
2085
+	 * _capture_primary_registration_data_from_billing_form
2086
+	 *
2087
+	 * @access private
2088
+	 * @return bool
2089
+	 * @throws EE_Error
2090
+	 * @throws InvalidArgumentException
2091
+	 * @throws ReflectionException
2092
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2093
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2094
+	 */
2095
+	private function _capture_primary_registration_data_from_billing_form()
2096
+	{
2097
+		// convert billing form data into an attendee
2098
+		$this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data();
2099
+		if (! $this->checkout->primary_attendee_obj instanceof EE_Attendee) {
2100
+			EE_Error::add_error(
2101
+				sprintf(
2102
+					esc_html__(
2103
+						'The billing form details could not be used for attendee details due to a technical issue.%sPlease try again or contact %s for assistance.',
2104
+						'event_espresso'
2105
+					),
2106
+					'<br/>',
2107
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2108
+				),
2109
+				__FILE__,
2110
+				__FUNCTION__,
2111
+				__LINE__
2112
+			);
2113
+			return false;
2114
+		}
2115
+		$primary_registration = $this->checkout->transaction->primary_registration();
2116
+		if (! $primary_registration instanceof EE_Registration) {
2117
+			EE_Error::add_error(
2118
+				sprintf(
2119
+					esc_html__(
2120
+						'The primary registrant for this transaction could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
2121
+						'event_espresso'
2122
+					),
2123
+					'<br/>',
2124
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2125
+				),
2126
+				__FILE__,
2127
+				__FUNCTION__,
2128
+				__LINE__
2129
+			);
2130
+			return false;
2131
+		}
2132
+		if (! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee')
2133
+			  instanceof
2134
+			  EE_Attendee
2135
+		) {
2136
+			EE_Error::add_error(
2137
+				sprintf(
2138
+					esc_html__(
2139
+						'The primary registrant could not be associated with this transaction due to a technical issue.%sPlease try again or contact %s for assistance.',
2140
+						'event_espresso'
2141
+					),
2142
+					'<br/>',
2143
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2144
+				),
2145
+				__FILE__,
2146
+				__FUNCTION__,
2147
+				__LINE__
2148
+			);
2149
+			return false;
2150
+		}
2151
+		/** @type EE_Registration_Processor $registration_processor */
2152
+		$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
2153
+		// at this point, we should have enough details about the registrant to consider the registration NOT incomplete
2154
+		$registration_processor->toggle_incomplete_registration_status_to_default($primary_registration);
2155
+		return true;
2156
+	}
2157
+
2158
+
2159
+	/**
2160
+	 * _get_payment_method_for_selected_method_of_payment
2161
+	 * retrieves a valid payment method
2162
+	 *
2163
+	 * @access public
2164
+	 * @return EE_Payment_Method
2165
+	 * @throws EE_Error
2166
+	 * @throws InvalidArgumentException
2167
+	 * @throws ReflectionException
2168
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2169
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2170
+	 */
2171
+	private function _get_payment_method_for_selected_method_of_payment()
2172
+	{
2173
+		if ($this->checkout->selected_method_of_payment === 'events_sold_out') {
2174
+			$this->_redirect_because_event_sold_out();
2175
+			return null;
2176
+		}
2177
+		// get EE_Payment_Method object
2178
+		if (isset($this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment])) {
2179
+			$payment_method = $this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment];
2180
+		} else {
2181
+			// load EEM_Payment_Method
2182
+			EE_Registry::instance()->load_model('Payment_Method');
2183
+			/** @type EEM_Payment_Method $EEM_Payment_Method */
2184
+			$EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method;
2185
+			$payment_method     = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment);
2186
+		}
2187
+		// verify $payment_method
2188
+		if (! $payment_method instanceof EE_Payment_Method) {
2189
+			// not a payment
2190
+			EE_Error::add_error(
2191
+				sprintf(
2192
+					esc_html__(
2193
+						'The selected method of payment could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
2194
+						'event_espresso'
2195
+					),
2196
+					'<br/>',
2197
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2198
+				),
2199
+				__FILE__,
2200
+				__FUNCTION__,
2201
+				__LINE__
2202
+			);
2203
+			return null;
2204
+		}
2205
+		// and verify it has a valid Payment_Method Type object
2206
+		if (! $payment_method->type_obj() instanceof EE_PMT_Base) {
2207
+			// not a payment
2208
+			EE_Error::add_error(
2209
+				sprintf(
2210
+					esc_html__(
2211
+						'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.',
2212
+						'event_espresso'
2213
+					),
2214
+					'<br/>',
2215
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2216
+				),
2217
+				__FILE__,
2218
+				__FUNCTION__,
2219
+				__LINE__
2220
+			);
2221
+			return null;
2222
+		}
2223
+		return $payment_method;
2224
+	}
2225
+
2226
+
2227
+	/**
2228
+	 *    _attempt_payment
2229
+	 *
2230
+	 * @access    private
2231
+	 * @type    EE_Payment_Method $payment_method
2232
+	 * @return mixed EE_Payment | boolean
2233
+	 * @throws EE_Error
2234
+	 * @throws InvalidArgumentException
2235
+	 * @throws ReflectionException
2236
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2237
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2238
+	 */
2239
+	private function _attempt_payment(EE_Payment_Method $payment_method)
2240
+	{
2241
+		$payment = null;
2242
+		$this->checkout->transaction->save();
2243
+		$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2244
+		if (! $payment_processor instanceof EE_Payment_Processor) {
2245
+			return false;
2246
+		}
2247
+		try {
2248
+			$payment_processor->set_revisit($this->checkout->revisit);
2249
+			// generate payment object
2250
+			$payment = $payment_processor->process_payment(
2251
+				$payment_method,
2252
+				$this->checkout->transaction,
2253
+				$this->checkout->amount_owing,
2254
+				$this->checkout->billing_form,
2255
+				$this->_get_return_url($payment_method),
2256
+				'CART',
2257
+				$this->checkout->admin_request,
2258
+				true,
2259
+				$this->reg_step_url()
2260
+			);
2261
+		} catch (Exception $e) {
2262
+			$this->_handle_payment_processor_exception($e);
2263
+		}
2264
+		return $payment;
2265
+	}
2266
+
2267
+
2268
+	/**
2269
+	 * _handle_payment_processor_exception
2270
+	 *
2271
+	 * @access protected
2272
+	 * @param \Exception $e
2273
+	 * @return void
2274
+	 * @throws EE_Error
2275
+	 * @throws InvalidArgumentException
2276
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2277
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2278
+	 */
2279
+	protected function _handle_payment_processor_exception(Exception $e)
2280
+	{
2281
+		EE_Error::add_error(
2282
+			sprintf(
2283
+				esc_html__(
2284
+					'The payment could not br processed due to a technical issue.%1$sPlease try again or contact %2$s for assistance.||The following Exception was thrown in %4$s on line %5$s:%1$s%3$s',
2285
+					'event_espresso'
2286
+				),
2287
+				'<br/>',
2288
+				EE_Registry::instance()->CFG->organization->get_pretty('email'),
2289
+				$e->getMessage(),
2290
+				$e->getFile(),
2291
+				$e->getLine()
2292
+			),
2293
+			__FILE__,
2294
+			__FUNCTION__,
2295
+			__LINE__
2296
+		);
2297
+	}
2298
+
2299
+
2300
+	/**
2301
+	 * _get_return_url
2302
+	 *
2303
+	 * @access protected
2304
+	 * @param \EE_Payment_Method $payment_method
2305
+	 * @return string
2306
+	 * @throws \EE_Error
2307
+	 */
2308
+	protected function _get_return_url(EE_Payment_Method $payment_method)
2309
+	{
2310
+		$return_url = '';
2311
+		switch ($payment_method->type_obj()->payment_occurs()) {
2312
+			case EE_PMT_Base::offsite :
2313
+				$return_url = add_query_arg(
2314
+					array(
2315
+						'action'                     => 'process_gateway_response',
2316
+						'selected_method_of_payment' => $this->checkout->selected_method_of_payment,
2317
+						'spco_txn'                   => $this->checkout->transaction->ID(),
2318
+					),
2319
+					$this->reg_step_url()
2320
+				);
2321
+				break;
2322
+			case EE_PMT_Base::onsite :
2323
+			case EE_PMT_Base::offline :
2324
+				$return_url = $this->checkout->next_step->reg_step_url();
2325
+				break;
2326
+		}
2327
+		return $return_url;
2328
+	}
2329
+
2330
+
2331
+	/**
2332
+	 * _validate_payment
2333
+	 *
2334
+	 * @access private
2335
+	 * @param EE_Payment $payment
2336
+	 * @return EE_Payment|FALSE
2337
+	 * @throws EE_Error
2338
+	 * @throws InvalidArgumentException
2339
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2340
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2341
+	 */
2342
+	private function _validate_payment($payment = null)
2343
+	{
2344
+		if ($this->checkout->payment_method->is_off_line()) {
2345
+			return true;
2346
+		}
2347
+		// verify payment object
2348
+		if (! $payment instanceof EE_Payment) {
2349
+			// not a payment
2350
+			EE_Error::add_error(
2351
+				sprintf(
2352
+					esc_html__(
2353
+						'A valid payment was not generated due to a technical issue.%1$sPlease try again or contact %2$s for assistance.',
2354
+						'event_espresso'
2355
+					),
2356
+					'<br/>',
2357
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2358
+				),
2359
+				__FILE__,
2360
+				__FUNCTION__,
2361
+				__LINE__
2362
+			);
2363
+			return false;
2364
+		}
2365
+		return $payment;
2366
+	}
2367
+
2368
+
2369
+	/**
2370
+	 * _post_payment_processing
2371
+	 *
2372
+	 * @access private
2373
+	 * @param EE_Payment|bool $payment
2374
+	 * @return bool
2375
+	 * @throws EE_Error
2376
+	 * @throws InvalidArgumentException
2377
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2378
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2379
+	 */
2380
+	private function _post_payment_processing($payment = null)
2381
+	{
2382
+		// Off-Line payment?
2383
+		if ($payment === true) {
2384
+			//$this->_setup_redirect_for_next_step();
2385
+			return true;
2386
+			// On-Site payment?
2387
+		} else if ($this->checkout->payment_method->is_on_site()) {
2388
+			if (! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) {
2389
+				//$this->_setup_redirect_for_next_step();
2390
+				$this->checkout->continue_reg = false;
2391
+			}
2392
+			// Off-Site payment?
2393
+		} else if ($this->checkout->payment_method->is_off_site()) {
2394
+			// if a payment object was made and it specifies a redirect url, then we'll setup that redirect info
2395
+			if ($payment instanceof EE_Payment && $payment->redirect_url()) {
2396
+				do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()');
2397
+				$this->checkout->redirect      = true;
2398
+				$this->checkout->redirect_form = $payment->redirect_form();
2399
+				$this->checkout->redirect_url  = $this->reg_step_url('redirect_form');
2400
+				// set JSON response
2401
+				$this->checkout->json_response->set_redirect_form($this->checkout->redirect_form);
2402
+				// and lastly, let's bump the payment status to pending
2403
+				$payment->set_status(EEM_Payment::status_id_pending);
2404
+				$payment->save();
2405
+			} else {
2406
+				// not a payment
2407
+				$this->checkout->continue_reg = false;
2408
+				EE_Error::add_error(
2409
+					sprintf(
2410
+						esc_html__(
2411
+							'It appears the Off Site Payment Method was not configured properly.%sPlease try again or contact %s for assistance.',
2412
+							'event_espresso'
2413
+						),
2414
+						'<br/>',
2415
+						EE_Registry::instance()->CFG->organization->get_pretty('email')
2416
+					),
2417
+					__FILE__,
2418
+					__FUNCTION__,
2419
+					__LINE__
2420
+				);
2421
+			}
2422
+		} else {
2423
+			// ummm ya... not Off-Line, not On-Site, not off-Site ????
2424
+			$this->checkout->continue_reg = false;
2425
+			return false;
2426
+		}
2427
+		return $payment;
2428
+	}
2429
+
2430
+
2431
+	/**
2432
+	 *    _process_payment_status
2433
+	 *
2434
+	 * @access private
2435
+	 * @type    EE_Payment $payment
2436
+	 * @param string       $payment_occurs
2437
+	 * @return bool
2438
+	 * @throws EE_Error
2439
+	 * @throws InvalidArgumentException
2440
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2441
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2442
+	 */
2443
+	private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline)
2444
+	{
2445
+		// off-line payment? carry on
2446
+		if ($payment_occurs === EE_PMT_Base::offline) {
2447
+			return true;
2448
+		}
2449
+		// verify payment validity
2450
+		if ($payment instanceof EE_Payment) {
2451
+			do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()');
2452
+			$msg = $payment->gateway_response();
2453
+			// check results
2454
+			switch ($payment->status()) {
2455
+				// good payment
2456
+				case EEM_Payment::status_id_approved :
2457
+					EE_Error::add_success(
2458
+						esc_html__('Your payment was processed successfully.', 'event_espresso'),
2459
+						__FILE__,
2460
+						__FUNCTION__,
2461
+						__LINE__
2462
+					);
2463
+					return true;
2464
+					break;
2465
+				// slow payment
2466
+				case EEM_Payment::status_id_pending :
2467
+					if (empty($msg)) {
2468
+						$msg = esc_html__(
2469
+							'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.',
2470
+							'event_espresso'
2471
+						);
2472
+					}
2473
+					EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__);
2474
+					return true;
2475
+					break;
2476
+				// don't wanna payment
2477
+				case EEM_Payment::status_id_cancelled :
2478
+					if (empty($msg)) {
2479
+						$msg = _n(
2480
+							'Payment cancelled. Please try again.',
2481
+							'Payment cancelled. Please try again or select another method of payment.',
2482
+							count($this->checkout->available_payment_methods),
2483
+							'event_espresso'
2484
+						);
2485
+					}
2486
+					EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
2487
+					return false;
2488
+					break;
2489
+				// not enough payment
2490
+				case EEM_Payment::status_id_declined :
2491
+					if (empty($msg)) {
2492
+						$msg = _n(
2493
+							'We\'re sorry but your payment was declined. Please try again.',
2494
+							'We\'re sorry but your payment was declined. Please try again or select another method of payment.',
2495
+							count($this->checkout->available_payment_methods),
2496
+							'event_espresso'
2497
+						);
2498
+					}
2499
+					EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__);
2500
+					return false;
2501
+					break;
2502
+				// bad payment
2503
+				case EEM_Payment::status_id_failed :
2504
+					if (! empty($msg)) {
2505
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2506
+						return false;
2507
+					}
2508
+					// default to error below
2509
+					break;
2510
+			}
2511
+		}
2512
+		// off-site payment gateway responses are too unreliable, so let's just assume that
2513
+		// the payment processing is just running slower than the registrant's request
2514
+		if ($payment_occurs === EE_PMT_Base::offsite) {
2515
+			return true;
2516
+		}
2517
+		EE_Error::add_error(
2518
+			sprintf(
2519
+				esc_html__(
2520
+					'Your payment could not be processed successfully due to a technical issue.%sPlease try again or contact %s for assistance.',
2521
+					'event_espresso'
2522
+				),
2523
+				'<br/>',
2524
+				EE_Registry::instance()->CFG->organization->get_pretty('email')
2525
+			),
2526
+			__FILE__,
2527
+			__FUNCTION__,
2528
+			__LINE__
2529
+		);
2530
+		return false;
2531
+	}
2532
+
2533
+
2534
+
2535
+
2536
+
2537
+
2538
+	/********************************************************************************************************/
2539
+	/**********************************  PROCESS GATEWAY RESPONSE  **********************************/
2540
+	/********************************************************************************************************/
2541
+	/**
2542
+	 * process_gateway_response
2543
+	 * this is the return point for Off-Site Payment Methods
2544
+	 * It will attempt to "handle the IPN" if it appears that this has not already occurred,
2545
+	 * otherwise, it will load up the last payment made for the TXN.
2546
+	 * If the payment retrieved looks good, it will then either:
2547
+	 *    complete the current step and allow advancement to the next reg step
2548
+	 *        or present the payment options again
2549
+	 *
2550
+	 * @access private
2551
+	 * @return EE_Payment|FALSE
2552
+	 * @throws EE_Error
2553
+	 * @throws InvalidArgumentException
2554
+	 * @throws ReflectionException
2555
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2556
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2557
+	 * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
2558
+	 */
2559
+	public function process_gateway_response()
2560
+	{
2561
+		$payment = null;
2562
+		// how have they chosen to pay?
2563
+		$this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true);
2564
+		// get EE_Payment_Method object
2565
+		if (! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) {
2566
+			$this->checkout->continue_reg = false;
2567
+			return false;
2568
+		}
2569
+		if (! $this->checkout->payment_method->is_off_site()) {
2570
+			return false;
2571
+		}
2572
+		$this->_validate_offsite_return();
2573
+		// DEBUG LOG
2574
+		//$this->checkout->log(
2575
+		//	__CLASS__, __FUNCTION__, __LINE__,
2576
+		//	array(
2577
+		//		'selected_method_of_payment' => $this->checkout->selected_method_of_payment,
2578
+		//		'payment_method' => $this->checkout->payment_method,
2579
+		//	),
2580
+		//	true
2581
+		//);
2582
+		// verify TXN
2583
+		if ($this->checkout->transaction instanceof EE_Transaction) {
2584
+			$gateway = $this->checkout->payment_method->type_obj()->get_gateway();
2585
+			if (! $gateway instanceof EE_Offsite_Gateway) {
2586
+				$this->checkout->continue_reg = false;
2587
+				return false;
2588
+			}
2589
+			$payment = $this->_process_off_site_payment($gateway);
2590
+			$payment = $this->_process_cancelled_payments($payment);
2591
+			$payment = $this->_validate_payment($payment);
2592
+			// if payment was not declined by the payment gateway or cancelled by the registrant
2593
+			if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) {
2594
+				//$this->_setup_redirect_for_next_step();
2595
+				// store that for later
2596
+				$this->checkout->payment = $payment;
2597
+				// mark this reg step as completed, as long as gateway doesn't use a separate IPN request,
2598
+				// because we will complete this step during the IPN processing then
2599
+				if ($gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request()) {
2600
+					$this->set_completed();
2601
+				}
2602
+				return true;
2603
+			}
2604
+		}
2605
+		// DEBUG LOG
2606
+		//$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__,
2607
+		//	array( 'payment' => $payment )
2608
+		//);
2609
+		$this->checkout->continue_reg = false;
2610
+		return false;
2611
+	}
2612
+
2613
+
2614
+	/**
2615
+	 * _validate_return
2616
+	 *
2617
+	 * @access private
2618
+	 * @return void
2619
+	 * @throws EE_Error
2620
+	 * @throws InvalidArgumentException
2621
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2622
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2623
+	 * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
2624
+	 */
2625
+	private function _validate_offsite_return()
2626
+	{
2627
+		$TXN_ID = (int)EE_Registry::instance()->REQ->get('spco_txn', 0);
2628
+		if ($TXN_ID !== $this->checkout->transaction->ID()) {
2629
+			// Houston... we might have a problem
2630
+			$invalid_TXN = false;
2631
+			// first gather some info
2632
+			$valid_TXN          = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2633
+			$primary_registrant = $valid_TXN instanceof EE_Transaction
2634
+				? $valid_TXN->primary_registration()
2635
+				: null;
2636
+			// let's start by retrieving the cart for this TXN
2637
+			$cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction);
2638
+			if ($cart instanceof EE_Cart) {
2639
+				// verify that the current cart has tickets
2640
+				$tickets = $cart->get_tickets();
2641
+				if (empty($tickets)) {
2642
+					$invalid_TXN = true;
2643
+				}
2644
+			} else {
2645
+				$invalid_TXN = true;
2646
+			}
2647
+			$valid_TXN_SID = $primary_registrant instanceof EE_Registration
2648
+				? $primary_registrant->session_ID()
2649
+				: null;
2650
+			// validate current Session ID and compare against valid TXN session ID
2651
+			if (
2652
+				$invalid_TXN // if this is already true, then skip other checks
2653
+				|| EE_Session::instance()->id() === null
2654
+				|| (
2655
+					// WARNING !!!
2656
+					// this could be PayPal sending back duplicate requests (ya they do that)
2657
+					// or it **could** mean someone is simply registering AGAIN after having just done so
2658
+					// so now we need to determine if this current TXN looks valid or not
2659
+					// and whether this reg step has even been started ?
2660
+					EE_Session::instance()->id() === $valid_TXN_SID
2661
+					// really? you're half way through this reg step, but you never started it ?
2662
+					&& $this->checkout->transaction->reg_step_completed($this->slug()) === false
2663
+				)
2664
+			) {
2665
+				$invalid_TXN = true;
2666
+			}
2667
+			if ($invalid_TXN) {
2668
+				// is the valid TXN completed ?
2669
+				if ($valid_TXN instanceof EE_Transaction) {
2670
+					// has this step even been started ?
2671
+					$reg_step_completed = $valid_TXN->reg_step_completed($this->slug());
2672
+					if ($reg_step_completed !== false && $reg_step_completed !== true) {
2673
+						// so it **looks** like this is a double request from PayPal
2674
+						// so let's try to pick up where we left off
2675
+						$this->checkout->transaction = $valid_TXN;
2676
+						$this->checkout->refresh_all_entities(true);
2677
+						return;
2678
+					}
2679
+				}
2680
+				// you appear to be lost?
2681
+				$this->_redirect_wayward_request($primary_registrant);
2682
+			}
2683
+		}
2684
+	}
2685
+
2686
+
2687
+	/**
2688
+	 * _redirect_wayward_request
2689
+	 *
2690
+	 * @access private
2691
+	 * @param \EE_Registration|null $primary_registrant
2692
+	 * @return bool
2693
+	 * @throws EE_Error
2694
+	 * @throws InvalidArgumentException
2695
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2696
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2697
+	 */
2698
+	private function _redirect_wayward_request(EE_Registration $primary_registrant)
2699
+	{
2700
+		if (! $primary_registrant instanceof EE_Registration) {
2701
+			// try redirecting based on the current TXN
2702
+			$primary_registrant = $this->checkout->transaction instanceof EE_Transaction
2703
+				? $this->checkout->transaction->primary_registration()
2704
+				: null;
2705
+		}
2706
+		if (! $primary_registrant instanceof EE_Registration) {
2707
+			EE_Error::add_error(
2708
+				sprintf(
2709
+					esc_html__(
2710
+						'Invalid information was received from the Off-Site Payment Processor and your Transaction details could not be retrieved from the database.%1$sPlease try again or contact %2$s for assistance.',
2711
+						'event_espresso'
2712
+					),
2713
+					'<br/>',
2714
+					EE_Registry::instance()->CFG->organization->get_pretty('email')
2715
+				),
2716
+				__FILE__,
2717
+				__FUNCTION__,
2718
+				__LINE__
2719
+			);
2720
+			return false;
2721
+		}
2722
+		// make sure transaction is not locked
2723
+		$this->checkout->transaction->unlock();
2724
+		wp_safe_redirect(
2725
+			add_query_arg(
2726
+				array(
2727
+					'e_reg_url_link' => $primary_registrant->reg_url_link(),
2728
+				),
2729
+				$this->checkout->thank_you_page_url
2730
+			)
2731
+		);
2732
+		exit();
2733
+	}
2734
+
2735
+
2736
+	/**
2737
+	 * _process_off_site_payment
2738
+	 *
2739
+	 * @access private
2740
+	 * @param \EE_Offsite_Gateway $gateway
2741
+	 * @return EE_Payment
2742
+	 * @throws EE_Error
2743
+	 * @throws InvalidArgumentException
2744
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2745
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2746
+	 */
2747
+	private function _process_off_site_payment(EE_Offsite_Gateway $gateway)
2748
+	{
2749
+		try {
2750
+			$request_data = \EE_Registry::instance()->REQ->params();
2751
+			// if gateway uses_separate_IPN_request, then we don't have to process the IPN manually
2752
+			$this->set_handle_IPN_in_this_request(
2753
+				$gateway->handle_IPN_in_this_request($request_data, false)
2754
+			);
2755
+			if ($this->handle_IPN_in_this_request()) {
2756
+				// get payment details and process results
2757
+				/** @type EE_Payment_Processor $payment_processor */
2758
+				$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2759
+				$payment           = $payment_processor->process_ipn(
2760
+					$request_data,
2761
+					$this->checkout->transaction,
2762
+					$this->checkout->payment_method,
2763
+					true,
2764
+					false
2765
+				);
2766
+				//$payment_source = 'process_ipn';
2767
+			} else {
2768
+				$payment = $this->checkout->transaction->last_payment();
2769
+				//$payment_source = 'last_payment';
2770
+			}
2771
+		} catch (Exception $e) {
2772
+			// let's just eat the exception and try to move on using any previously set payment info
2773
+			$payment = $this->checkout->transaction->last_payment();
2774
+			//$payment_source = 'last_payment after Exception';
2775
+			// but if we STILL don't have a payment object
2776
+			if (! $payment instanceof EE_Payment) {
2777
+				// then we'll object ! ( not object like a thing... but object like what a lawyer says ! )
2778
+				$this->_handle_payment_processor_exception($e);
2779
+			}
2780
+		}
2781
+		// DEBUG LOG
2782
+		//$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__,
2783
+		//	array(
2784
+		//		'process_ipn_payment' => $payment,
2785
+		//		'payment_source'      => $payment_source,
2786
+		//	)
2787
+		//);
2788
+		return $payment;
2789
+	}
2790
+
2791
+
2792
+	/**
2793
+	 * _process_cancelled_payments
2794
+	 * just makes sure that the payment status gets updated correctly
2795
+	 * so tha tan error isn't generated during payment validation
2796
+	 *
2797
+	 * @access private
2798
+	 * @param EE_Payment $payment
2799
+	 * @return EE_Payment | FALSE
2800
+	 * @throws \EE_Error
2801
+	 */
2802
+	private function _process_cancelled_payments($payment = null)
2803
+	{
2804
+		if (
2805
+			$payment instanceof EE_Payment
2806
+			&& isset($_REQUEST['ee_cancel_payment'])
2807
+			&& $payment->status() === EEM_Payment::status_id_failed
2808
+		) {
2809
+			$payment->set_status(EEM_Payment::status_id_cancelled);
2810
+		}
2811
+		return $payment;
2812
+	}
2813
+
2814
+
2815
+	/**
2816
+	 *    get_transaction_details_for_gateways
2817
+	 *
2818
+	 * @access    public
2819
+	 * @return int
2820
+	 * @throws EE_Error
2821
+	 * @throws InvalidArgumentException
2822
+	 * @throws ReflectionException
2823
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
2824
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
2825
+	 */
2826
+	public function get_transaction_details_for_gateways()
2827
+	{
2828
+		$txn_details = array();
2829
+		// ya gotta make a choice man
2830
+		if (empty($this->checkout->selected_method_of_payment)) {
2831
+			$txn_details = array(
2832
+				'error' => esc_html__('Please select a method of payment before proceeding.', 'event_espresso'),
2833
+			);
2834
+		}
2835
+		// get EE_Payment_Method object
2836
+		if (
2837
+			empty($txn_details)
2838
+			&&
2839
+			! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()
2840
+		) {
2841
+			$txn_details = array(
2842
+				'selected_method_of_payment' => $this->checkout->selected_method_of_payment,
2843
+				'error'                      => esc_html__(
2844
+					'A valid Payment Method could not be determined.',
2845
+					'event_espresso'
2846
+				),
2847
+			);
2848
+		}
2849
+		if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) {
2850
+			$return_url  = $this->_get_return_url($this->checkout->payment_method);
2851
+			$txn_details = array(
2852
+				'TXN_ID'         => $this->checkout->transaction->ID(),
2853
+				'TXN_timestamp'  => $this->checkout->transaction->datetime(),
2854
+				'TXN_total'      => $this->checkout->transaction->total(),
2855
+				'TXN_paid'       => $this->checkout->transaction->paid(),
2856
+				'TXN_reg_steps'  => $this->checkout->transaction->reg_steps(),
2857
+				'STS_ID'         => $this->checkout->transaction->status_ID(),
2858
+				'PMD_ID'         => $this->checkout->transaction->payment_method_ID(),
2859
+				'payment_amount' => $this->checkout->amount_owing,
2860
+				'return_url'     => $return_url,
2861
+				'cancel_url'     => add_query_arg(array('ee_cancel_payment' => true), $return_url),
2862
+				'notify_url'     => EE_Config::instance()->core->txn_page_url(
2863
+					array(
2864
+						'e_reg_url_link'    => $this->checkout->transaction->primary_registration()->reg_url_link(),
2865
+						'ee_payment_method' => $this->checkout->payment_method->slug(),
2866
+					)
2867
+				),
2868
+			);
2869
+		}
2870
+		echo wp_json_encode($txn_details);
2871
+		exit();
2872
+	}
2873
+
2874
+
2875
+	/**
2876
+	 *    __sleep
2877
+	 * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon
2878
+	 * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the
2879
+	 * reg form, because if needed, it will be regenerated anyways
2880
+	 *
2881
+	 * @return array
2882
+	 */
2883
+	public function __sleep()
2884
+	{
2885
+		// remove the reg form and the checkout
2886
+		return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout', 'line_item_display'));
2887
+	}
2888 2888
 }
Please login to merge, or discard this patch.
admin_pages/transactions/Transactions_Admin_Page.core.php 2 patches
Indentation   +2433 added lines, -2433 removed lines patch added patch discarded remove patch
@@ -16,2437 +16,2437 @@
 block discarded – undo
16 16
 class Transactions_Admin_Page extends EE_Admin_Page
17 17
 {
18 18
 
19
-    /**
20
-     * @var EE_Transaction
21
-     */
22
-    private $_transaction;
23
-
24
-    /**
25
-     * @var EE_Session
26
-     */
27
-    private $_session;
28
-
29
-    /**
30
-     * @var array $_txn_status
31
-     */
32
-    private static $_txn_status;
33
-
34
-    /**
35
-     * @var array $_pay_status
36
-     */
37
-    private static $_pay_status;
38
-
39
-    /**
40
-     * @var array $_existing_reg_payment_REG_IDs
41
-     */
42
-    protected $_existing_reg_payment_REG_IDs = null;
43
-
44
-
45
-    /**
46
-     * @Constructor
47
-     * @access public
48
-     * @param bool $routing
49
-     * @throws EE_Error
50
-     * @throws InvalidArgumentException
51
-     * @throws ReflectionException
52
-     * @throws InvalidDataTypeException
53
-     * @throws InvalidInterfaceException
54
-     */
55
-    public function __construct($routing = true)
56
-    {
57
-        parent::__construct($routing);
58
-    }
59
-
60
-
61
-    /**
62
-     *    _init_page_props
63
-     *
64
-     * @return void
65
-     */
66
-    protected function _init_page_props()
67
-    {
68
-        $this->page_slug        = TXN_PG_SLUG;
69
-        $this->page_label       = esc_html__('Transactions', 'event_espresso');
70
-        $this->_admin_base_url  = TXN_ADMIN_URL;
71
-        $this->_admin_base_path = TXN_ADMIN;
72
-    }
73
-
74
-
75
-    /**
76
-     *    _ajax_hooks
77
-     *
78
-     * @return void
79
-     */
80
-    protected function _ajax_hooks()
81
-    {
82
-        add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds'));
83
-        add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds'));
84
-        add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment'));
85
-    }
86
-
87
-
88
-    /**
89
-     *    _define_page_props
90
-     *
91
-     * @return void
92
-     */
93
-    protected function _define_page_props()
94
-    {
95
-        $this->_admin_page_title = $this->page_label;
96
-        $this->_labels           = array(
97
-            'buttons' => array(
98
-                'add'    => esc_html__('Add New Transaction', 'event_espresso'),
99
-                'edit'   => esc_html__('Edit Transaction', 'event_espresso'),
100
-                'delete' => esc_html__('Delete Transaction', 'event_espresso'),
101
-            ),
102
-        );
103
-    }
104
-
105
-
106
-    /**
107
-     *        grab url requests and route them
108
-     *
109
-     * @access private
110
-     * @return void
111
-     * @throws EE_Error
112
-     * @throws InvalidArgumentException
113
-     * @throws InvalidDataTypeException
114
-     * @throws InvalidInterfaceException
115
-     */
116
-    public function _set_page_routes()
117
-    {
118
-
119
-        $this->_set_transaction_status_array();
120
-
121
-        $txn_id = ! empty($this->_req_data['TXN_ID'])
122
-                  && ! is_array($this->_req_data['TXN_ID'])
123
-            ? $this->_req_data['TXN_ID']
124
-            : 0;
125
-
126
-        $this->_page_routes = array(
127
-
128
-            'default' => array(
129
-                'func'       => '_transactions_overview_list_table',
130
-                'capability' => 'ee_read_transactions',
131
-            ),
132
-
133
-            'view_transaction' => array(
134
-                'func'       => '_transaction_details',
135
-                'capability' => 'ee_read_transaction',
136
-                'obj_id'     => $txn_id,
137
-            ),
138
-
139
-            'send_payment_reminder' => array(
140
-                'func'       => '_send_payment_reminder',
141
-                'noheader'   => true,
142
-                'capability' => 'ee_send_message',
143
-            ),
144
-
145
-            'espresso_apply_payment' => array(
146
-                'func'       => 'apply_payments_or_refunds',
147
-                'noheader'   => true,
148
-                'capability' => 'ee_edit_payments',
149
-            ),
150
-
151
-            'espresso_apply_refund' => array(
152
-                'func'       => 'apply_payments_or_refunds',
153
-                'noheader'   => true,
154
-                'capability' => 'ee_edit_payments',
155
-            ),
156
-
157
-            'espresso_delete_payment' => array(
158
-                'func'       => 'delete_payment',
159
-                'noheader'   => true,
160
-                'capability' => 'ee_delete_payments',
161
-            ),
162
-
163
-        );
164
-    }
165
-
166
-
167
-    protected function _set_page_config()
168
-    {
169
-        $this->_page_config = array(
170
-            'default'          => array(
171
-                'nav'           => array(
172
-                    'label' => esc_html__('Overview', 'event_espresso'),
173
-                    'order' => 10,
174
-                ),
175
-                'list_table'    => 'EE_Admin_Transactions_List_Table',
176
-                'help_tabs'     => array(
177
-                    'transactions_overview_help_tab'                       => array(
178
-                        'title'    => esc_html__('Transactions Overview', 'event_espresso'),
179
-                        'filename' => 'transactions_overview',
180
-                    ),
181
-                    'transactions_overview_table_column_headings_help_tab' => array(
182
-                        'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'),
183
-                        'filename' => 'transactions_overview_table_column_headings',
184
-                    ),
185
-                    'transactions_overview_views_filters_help_tab'         => array(
186
-                        'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'),
187
-                        'filename' => 'transactions_overview_views_filters_search',
188
-                    ),
189
-                ),
190
-                'help_tour'     => array('Transactions_Overview_Help_Tour'),
191
-                /**
192
-                 * commented out because currently we are not displaying tips for transaction list table status but this
193
-                 * may change in a later iteration so want to keep the code for then.
194
-                 */
195
-                //'qtips' => array( 'Transactions_List_Table_Tips' ),
196
-                'require_nonce' => false,
197
-            ),
198
-            'view_transaction' => array(
199
-                'nav'       => array(
200
-                    'label'      => esc_html__('View Transaction', 'event_espresso'),
201
-                    'order'      => 5,
202
-                    'url'        => isset($this->_req_data['TXN_ID'])
203
-                        ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url)
204
-                        : $this->_admin_base_url,
205
-                    'persistent' => false,
206
-                ),
207
-                'help_tabs' => array(
208
-                    'transactions_view_transaction_help_tab'                                              => array(
209
-                        'title'    => esc_html__('View Transaction', 'event_espresso'),
210
-                        'filename' => 'transactions_view_transaction',
211
-                    ),
212
-                    'transactions_view_transaction_transaction_details_table_help_tab'                    => array(
213
-                        'title'    => esc_html__('Transaction Details Table', 'event_espresso'),
214
-                        'filename' => 'transactions_view_transaction_transaction_details_table',
215
-                    ),
216
-                    'transactions_view_transaction_attendees_registered_help_tab'                         => array(
217
-                        'title'    => esc_html__('Attendees Registered', 'event_espresso'),
218
-                        'filename' => 'transactions_view_transaction_attendees_registered',
219
-                    ),
220
-                    'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array(
221
-                        'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'),
222
-                        'filename' => 'transactions_view_transaction_primary_registrant_billing_information',
223
-                    ),
224
-                ),
225
-                'qtips'     => array('Transaction_Details_Tips'),
226
-                'help_tour' => array('Transaction_Details_Help_Tour'),
227
-                'metaboxes' => array('_transaction_details_metaboxes'),
228
-
229
-                'require_nonce' => false,
230
-            ),
231
-        );
232
-    }
233
-
234
-
235
-    /**
236
-     * The below methods aren't used by this class currently
237
-     */
238
-    protected function _add_screen_options()
239
-    {
240
-        //noop
241
-    }
242
-
243
-    protected function _add_feature_pointers()
244
-    {
245
-        //noop
246
-    }
247
-
248
-    public function admin_init()
249
-    {
250
-        // IF a registration was JUST added via the admin...
251
-        if (isset(
252
-            $this->_req_data['redirect_from'],
253
-            $this->_req_data['EVT_ID'],
254
-            $this->_req_data['event_name']
255
-        )) {
256
-            // then set a cookie so that we can block any attempts to use
257
-            // the back button as a way to enter another registration.
258
-            setcookie(
259
-                'ee_registration_added',
260
-                $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/'
261
-            );
262
-            // and update the global
263
-            $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID'];
264
-        }
265
-        EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__(
266
-            'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
267
-            'event_espresso'
268
-        );
269
-        EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__(
270
-            'An error occurred! Please refresh the page and try again.',
271
-            'event_espresso'
272
-        );
273
-        EE_Registry::$i18n_js_strings['txn_status_array']        = self::$_txn_status;
274
-        EE_Registry::$i18n_js_strings['pay_status_array']        = self::$_pay_status;
275
-        EE_Registry::$i18n_js_strings['payments_total']          = esc_html__('Payments Total', 'event_espresso');
276
-        EE_Registry::$i18n_js_strings['transaction_overpaid']    = esc_html__(
277
-            'This transaction has been overpaid ! Payments Total',
278
-            'event_espresso'
279
-        );
280
-    }
281
-
282
-    public function admin_notices()
283
-    {
284
-        //noop
285
-    }
286
-
287
-    public function admin_footer_scripts()
288
-    {
289
-        //noop
290
-    }
291
-
292
-
293
-    /**
294
-     * _set_transaction_status_array
295
-     * sets list of transaction statuses
296
-     *
297
-     * @access private
298
-     * @return void
299
-     * @throws EE_Error
300
-     * @throws InvalidArgumentException
301
-     * @throws InvalidDataTypeException
302
-     * @throws InvalidInterfaceException
303
-     */
304
-    private function _set_transaction_status_array()
305
-    {
306
-        self::$_txn_status = EEM_Transaction::instance()->status_array(true);
307
-    }
308
-
309
-
310
-    /**
311
-     * get_transaction_status_array
312
-     * return the transaction status array for wp_list_table
313
-     *
314
-     * @access public
315
-     * @return array
316
-     */
317
-    public function get_transaction_status_array()
318
-    {
319
-        return self::$_txn_status;
320
-    }
321
-
322
-
323
-    /**
324
-     *    get list of payment statuses
325
-     *
326
-     * @access private
327
-     * @return void
328
-     * @throws EE_Error
329
-     * @throws InvalidArgumentException
330
-     * @throws InvalidDataTypeException
331
-     * @throws InvalidInterfaceException
332
-     */
333
-    private function _get_payment_status_array()
334
-    {
335
-        self::$_pay_status                      = EEM_Payment::instance()->status_array(true);
336
-        $this->_template_args['payment_status'] = self::$_pay_status;
337
-
338
-    }
339
-
340
-
341
-    /**
342
-     *    _add_screen_options_default
343
-     *
344
-     * @access protected
345
-     * @return void
346
-     * @throws InvalidArgumentException
347
-     * @throws InvalidDataTypeException
348
-     * @throws InvalidInterfaceException
349
-     */
350
-    protected function _add_screen_options_default()
351
-    {
352
-        $this->_per_page_screen_option();
353
-    }
354
-
355
-
356
-    /**
357
-     * load_scripts_styles
358
-     *
359
-     * @access public
360
-     * @return void
361
-     */
362
-    public function load_scripts_styles()
363
-    {
364
-        //enqueue style
365
-        wp_register_style(
366
-            'espresso_txn',
367
-            TXN_ASSETS_URL . 'espresso_transactions_admin.css',
368
-            array(),
369
-            EVENT_ESPRESSO_VERSION
370
-        );
371
-        wp_enqueue_style('espresso_txn');
372
-        //scripts
373
-        wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array(
374
-            'ee_admin_js',
375
-            'ee-datepicker',
376
-            'jquery-ui-datepicker',
377
-            'jquery-ui-draggable',
378
-            'ee-dialog',
379
-            'ee-accounting',
380
-            'ee-serialize-full-array',
381
-        ), EVENT_ESPRESSO_VERSION, true);
382
-        wp_enqueue_script('espresso_txn');
383
-    }
384
-
385
-
386
-    /**
387
-     *    load_scripts_styles_view_transaction
388
-     *
389
-     * @access public
390
-     * @return void
391
-     */
392
-    public function load_scripts_styles_view_transaction()
393
-    {
394
-        //styles
395
-        wp_enqueue_style('espresso-ui-theme');
396
-    }
397
-
398
-
399
-    /**
400
-     *    load_scripts_styles_default
401
-     *
402
-     * @access public
403
-     * @return void
404
-     */
405
-    public function load_scripts_styles_default()
406
-    {
407
-        //styles
408
-        wp_enqueue_style('espresso-ui-theme');
409
-    }
410
-
411
-
412
-    /**
413
-     *    _set_list_table_views_default
414
-     *
415
-     * @access protected
416
-     * @return void
417
-     */
418
-    protected function _set_list_table_views_default()
419
-    {
420
-        $this->_views = array(
421
-            'all'       => array(
422
-                'slug'  => 'all',
423
-                'label' => esc_html__('View All Transactions', 'event_espresso'),
424
-                'count' => 0,
425
-            ),
426
-            'abandoned' => array(
427
-                'slug'  => 'abandoned',
428
-                'label' => esc_html__('Abandoned Transactions', 'event_espresso'),
429
-                'count' => 0,
430
-            ),
431
-            'failed'    => array(
432
-                'slug'  => 'failed',
433
-                'label' => esc_html__('Failed Transactions', 'event_espresso'),
434
-                'count' => 0,
435
-            ),
436
-        );
437
-    }
438
-
439
-
440
-    /**
441
-     * _set_transaction_object
442
-     * This sets the _transaction property for the transaction details screen
443
-     *
444
-     * @access private
445
-     * @return void
446
-     * @throws EE_Error
447
-     * @throws InvalidArgumentException
448
-     * @throws RuntimeException
449
-     * @throws InvalidDataTypeException
450
-     * @throws InvalidInterfaceException
451
-     * @throws ReflectionException
452
-     */
453
-    private function _set_transaction_object()
454
-    {
455
-        if ($this->_transaction instanceof EE_Transaction) {
456
-            return;
457
-        } //get out we've already set the object
458
-
459
-        $TXN_ID = ! empty($this->_req_data['TXN_ID'])
460
-            ? absint($this->_req_data['TXN_ID'])
461
-            : false;
462
-
463
-        //get transaction object
464
-        $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
465
-        $this->_session     = $this->_transaction instanceof EE_Transaction
466
-            ? $this->_transaction->get('TXN_session_data')
467
-            : null;
468
-        $this->_transaction->verify_abandoned_transaction_status();
469
-
470
-        if (! $this->_transaction instanceof EE_Transaction) {
471
-            $error_msg = sprintf(
472
-                esc_html__(
473
-                    'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
474
-                    'event_espresso'
475
-                ),
476
-                $TXN_ID
477
-            );
478
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
479
-        }
480
-    }
481
-
482
-
483
-    /**
484
-     *    _transaction_legend_items
485
-     *
486
-     * @access protected
487
-     * @return array
488
-     * @throws EE_Error
489
-     * @throws InvalidArgumentException
490
-     * @throws ReflectionException
491
-     * @throws InvalidDataTypeException
492
-     * @throws InvalidInterfaceException
493
-     */
494
-    protected function _transaction_legend_items()
495
-    {
496
-        EE_Registry::instance()->load_helper('MSG_Template');
497
-        $items = array();
498
-
499
-        if (EE_Registry::instance()->CAP->current_user_can(
500
-            'ee_read_global_messages',
501
-            'view_filtered_messages'
502
-        )) {
503
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
504
-            if (is_array($related_for_icon)
505
-                && isset($related_for_icon['css_class'], $related_for_icon['label'])
506
-            ) {
507
-                $items['view_related_messages'] = array(
508
-                    'class' => $related_for_icon['css_class'],
509
-                    'desc'  => $related_for_icon['label'],
510
-                );
511
-            }
512
-        }
513
-
514
-        $items = apply_filters(
515
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
516
-            array_merge(
517
-                $items,
518
-                array(
519
-                    'view_details'          => array(
520
-                        'class' => 'dashicons dashicons-cart',
521
-                        'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
522
-                    ),
523
-                    'view_invoice'          => array(
524
-                        'class' => 'dashicons dashicons-media-spreadsheet',
525
-                        'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
526
-                    ),
527
-                    'view_receipt'          => array(
528
-                        'class' => 'dashicons dashicons-media-default',
529
-                        'desc'  => esc_html__('View Transaction Receipt', 'event_espresso'),
530
-                    ),
531
-                    'view_registration'     => array(
532
-                        'class' => 'dashicons dashicons-clipboard',
533
-                        'desc'  => esc_html__('View Registration Details', 'event_espresso'),
534
-                    ),
535
-                    'payment_overview_link' => array(
536
-                        'class' => 'dashicons dashicons-money',
537
-                        'desc'  => esc_html__('Make Payment on Frontend', 'event_espresso'),
538
-                    ),
539
-                )
540
-            )
541
-        );
542
-
543
-        if (EE_Registry::instance()->CAP->current_user_can(
544
-            'ee_send_message',
545
-            'espresso_transactions_send_payment_reminder'
546
-        )) {
547
-            if (EEH_MSG_Template::is_mt_active('payment_reminder')) {
548
-                $items['send_payment_reminder'] = array(
549
-                    'class' => 'dashicons dashicons-email-alt',
550
-                    'desc'  => esc_html__('Send Payment Reminder', 'event_espresso'),
551
-                );
552
-            } else {
553
-                $items['blank*'] = array(
554
-                    'class' => '',
555
-                    'desc'  => '',
556
-                );
557
-            }
558
-        } else {
559
-            $items['blank*'] = array(
560
-                'class' => '',
561
-                'desc'  => '',
562
-            );
563
-        }
564
-        $more_items = apply_filters(
565
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
566
-            array(
567
-                'overpaid'   => array(
568
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
569
-                    'desc'  => EEH_Template::pretty_status(
570
-                        EEM_Transaction::overpaid_status_code,
571
-                        false,
572
-                        'sentence'
573
-                    ),
574
-                ),
575
-                'complete'   => array(
576
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
577
-                    'desc'  => EEH_Template::pretty_status(
578
-                        EEM_Transaction::complete_status_code,
579
-                        false,
580
-                        'sentence'
581
-                    ),
582
-                ),
583
-                'incomplete' => array(
584
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
585
-                    'desc'  => EEH_Template::pretty_status(
586
-                        EEM_Transaction::incomplete_status_code,
587
-                        false,
588
-                        'sentence'
589
-                    ),
590
-                ),
591
-                'abandoned'  => array(
592
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
593
-                    'desc'  => EEH_Template::pretty_status(
594
-                        EEM_Transaction::abandoned_status_code,
595
-                        false,
596
-                        'sentence'
597
-                    ),
598
-                ),
599
-                'failed'     => array(
600
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
601
-                    'desc'  => EEH_Template::pretty_status(
602
-                        EEM_Transaction::failed_status_code,
603
-                        false,
604
-                        'sentence'
605
-                    ),
606
-                ),
607
-            )
608
-        );
609
-
610
-        return array_merge($items, $more_items);
611
-    }
612
-
613
-
614
-    /**
615
-     *    _transactions_overview_list_table
616
-     *
617
-     * @access protected
618
-     * @return void
619
-     * @throws DomainException
620
-     * @throws EE_Error
621
-     * @throws InvalidArgumentException
622
-     * @throws InvalidDataTypeException
623
-     * @throws InvalidInterfaceException
624
-     * @throws ReflectionException
625
-     */
626
-    protected function _transactions_overview_list_table()
627
-    {
628
-        $this->_admin_page_title = esc_html__('Transactions', 'event_espresso');
629
-        $event = isset($this->_req_data['EVT_ID'])
630
-            ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID'])
631
-            : null;
632
-        $this->_template_args['admin_page_header'] = $event instanceof EE_Event
633
-            ? sprintf(
634
-                esc_html__(
635
-                    '%sViewing Transactions for the Event: %s%s',
636
-                    'event_espresso'
637
-                ),
638
-                '<h3>',
639
-                '<a href="'
640
-                . EE_Admin_Page::add_query_args_and_nonce(
641
-                    array('action' => 'edit', 'post' => $event->ID()),
642
-                    EVENTS_ADMIN_URL
643
-                )
644
-                . '" title="'
645
-                . esc_attr__(
646
-                    'Click to Edit event',
647
-                    'event_espresso'
648
-                )
649
-                . '">' . $event->get('EVT_name') . '</a>',
650
-                '</h3>'
651
-            )
652
-            : '';
653
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
654
-        $this->display_admin_list_table_page_with_no_sidebar();
655
-    }
656
-
657
-
658
-    /**
659
-     *    _transaction_details
660
-     * generates HTML for the View Transaction Details Admin page
661
-     *
662
-     * @access protected
663
-     * @return void
664
-     * @throws DomainException
665
-     * @throws EE_Error
666
-     * @throws InvalidArgumentException
667
-     * @throws InvalidDataTypeException
668
-     * @throws InvalidInterfaceException
669
-     * @throws RuntimeException
670
-     * @throws ReflectionException
671
-     */
672
-    protected function _transaction_details()
673
-    {
674
-        do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
675
-
676
-        $this->_set_transaction_status_array();
677
-
678
-        $this->_template_args                      = array();
679
-        $this->_template_args['transactions_page'] = $this->_wp_page_slug;
680
-
681
-        $this->_set_transaction_object();
682
-
683
-        $primary_registration = $this->_transaction->primary_registration();
684
-        $attendee = $primary_registration instanceof EE_Registration
685
-            ? $primary_registration->attendee()
686
-            : null;
687
-
688
-        $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
689
-        $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
690
-
691
-        $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
692
-        $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
693
-
694
-        $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')];
695
-        $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
696
-        $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
697
-
698
-        $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
699
-        $this->_template_args['total_paid']  = $this->_transaction->get('TXN_paid');
700
-
701
-        $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid');
702
-        $this->_template_args['amount_due'] = EEH_Template::format_currency(
703
-            $amount_due,
704
-            true
705
-        );
706
-        if (EE_Registry::instance()->CFG->currency->sign_b4) {
707
-            $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign
708
-                                                  . $this->_template_args['amount_due'];
709
-        } else {
710
-            $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign;
711
-        }
712
-        $this->_template_args['amount_due_class'] = '';
713
-
714
-        if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) {
715
-            // paid in full
716
-            $this->_template_args['amount_due'] = false;
717
-        } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) {
718
-            // overpaid
719
-            $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
720
-        } elseif ($this->_transaction->get('TXN_total') > 0
721
-                  && $this->_transaction->get('TXN_paid') > 0
722
-        ) {
723
-            // monies owing
724
-            $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
725
-        } elseif ($this->_transaction->get('TXN_total') > 0
726
-                  && $this->_transaction->get('TXN_paid') == 0
727
-        ) {
728
-            // no payments made yet
729
-            $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
730
-        } elseif ($this->_transaction->get('TXN_total') == 0) {
731
-            // free event
732
-            $this->_template_args['amount_due'] = false;
733
-        }
734
-
735
-        $payment_method = $this->_transaction->payment_method();
736
-
737
-        $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
738
-            ? $payment_method->admin_name()
739
-            : esc_html__('Unknown', 'event_espresso');
740
-
741
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
742
-        // link back to overview
743
-        $this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER'])
744
-            ? $_SERVER['HTTP_REFERER']
745
-            : TXN_ADMIN_URL;
746
-
747
-
748
-        // next link
749
-        $next_txn                                 = $this->_transaction->next(
750
-            null,
751
-            array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
752
-            'TXN_ID'
753
-        );
754
-        $this->_template_args['next_transaction'] = $next_txn
755
-            ? $this->_next_link(
756
-                EE_Admin_Page::add_query_args_and_nonce(
757
-                    array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']),
758
-                    TXN_ADMIN_URL
759
-                ),
760
-                'dashicons dashicons-arrow-right ee-icon-size-22'
761
-            )
762
-            : '';
763
-        // previous link
764
-        $previous_txn                                 = $this->_transaction->previous(
765
-            null,
766
-            array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
767
-            'TXN_ID'
768
-        );
769
-        $this->_template_args['previous_transaction'] = $previous_txn
770
-            ? $this->_previous_link(
771
-                EE_Admin_Page::add_query_args_and_nonce(
772
-                    array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']),
773
-                    TXN_ADMIN_URL
774
-                ),
775
-                'dashicons dashicons-arrow-left ee-icon-size-22'
776
-            )
777
-            : '';
778
-
779
-        // were we just redirected here after adding a new registration ???
780
-        if (isset(
781
-            $this->_req_data['redirect_from'],
782
-            $this->_req_data['EVT_ID'],
783
-            $this->_req_data['event_name']
784
-        )) {
785
-            if (EE_Registry::instance()->CAP->current_user_can(
786
-                'ee_edit_registrations',
787
-                'espresso_registrations_new_registration',
788
-                $this->_req_data['EVT_ID']
789
-            )) {
790
-                $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
791
-                $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
792
-                    array(
793
-                        'page'     => 'espresso_registrations',
794
-                        'action'   => 'new_registration',
795
-                        'return'   => 'default',
796
-                        'TXN_ID'   => $this->_transaction->ID(),
797
-                        'event_id' => $this->_req_data['EVT_ID'],
798
-                    ),
799
-                    REG_ADMIN_URL
800
-                );
801
-                $this->_admin_page_title .= '">';
802
-
803
-                $this->_admin_page_title .= sprintf(
804
-                    esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
805
-                    htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8')
806
-                );
807
-                $this->_admin_page_title .= '</a>';
808
-            }
809
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
810
-        }
811
-        // grab messages at the last second
812
-        $this->_template_args['notices'] = EE_Error::get_notices();
813
-        // path to template
814
-        $template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
815
-        $this->_template_args['admin_page_header'] = EEH_Template::display_template(
816
-            $template_path,
817
-            $this->_template_args,
818
-            true
819
-        );
820
-
821
-        // the details template wrapper
822
-        $this->display_admin_page_with_sidebar();
823
-
824
-    }
825
-
826
-
827
-    /**
828
-     *        _transaction_details_metaboxes
829
-     *
830
-     * @access protected
831
-     * @return void
832
-     * @throws EE_Error
833
-     * @throws InvalidArgumentException
834
-     * @throws InvalidDataTypeException
835
-     * @throws InvalidInterfaceException
836
-     * @throws RuntimeException
837
-     * @throws ReflectionException
838
-     */
839
-    protected function _transaction_details_metaboxes()
840
-    {
841
-
842
-        $this->_set_transaction_object();
843
-
844
-        add_meta_box(
845
-            'edit-txn-details-mbox',
846
-            esc_html__('Transaction Details', 'event_espresso'),
847
-            array($this, 'txn_details_meta_box'),
848
-            $this->_wp_page_slug,
849
-            'normal',
850
-            'high'
851
-        );
852
-        add_meta_box(
853
-            'edit-txn-attendees-mbox',
854
-            esc_html__('Attendees Registered in this Transaction', 'event_espresso'),
855
-            array($this, 'txn_attendees_meta_box'),
856
-            $this->_wp_page_slug,
857
-            'normal',
858
-            'high',
859
-            array('TXN_ID' => $this->_transaction->ID())
860
-        );
861
-        add_meta_box(
862
-            'edit-txn-registrant-mbox',
863
-            esc_html__('Primary Contact', 'event_espresso'),
864
-            array($this, 'txn_registrant_side_meta_box'),
865
-            $this->_wp_page_slug,
866
-            'side',
867
-            'high'
868
-        );
869
-        add_meta_box(
870
-            'edit-txn-billing-info-mbox',
871
-            esc_html__('Billing Information', 'event_espresso'),
872
-            array($this, 'txn_billing_info_side_meta_box'),
873
-            $this->_wp_page_slug,
874
-            'side',
875
-            'high'
876
-        );
877
-    }
878
-
879
-
880
-    /**
881
-     * Callback for transaction actions metabox.
882
-     *
883
-     * @param EE_Transaction|null $transaction
884
-     * @throws DomainException
885
-     * @throws EE_Error
886
-     * @throws InvalidArgumentException
887
-     * @throws InvalidDataTypeException
888
-     * @throws InvalidInterfaceException
889
-     * @throws ReflectionException
890
-     * @throws RuntimeException
891
-     */
892
-    public function getActionButtons(EE_Transaction $transaction = null)
893
-    {
894
-        $content = '';
895
-        $actions = array();
896
-        if (! $transaction instanceof EE_Transaction) {
897
-            return $content;
898
-        }
899
-        /** @var EE_Registration $primary_registration */
900
-        $primary_registration = $transaction->primary_registration();
901
-        $attendee = $primary_registration instanceof EE_Registration
902
-            ? $primary_registration->attendee()
903
-            : null;
904
-
905
-        if ($attendee instanceof EE_Attendee
906
-            && EE_Registry::instance()->CAP->current_user_can(
907
-                'ee_send_message',
908
-                'espresso_transactions_send_payment_reminder'
909
-            )
910
-        ) {
911
-            $actions['payment_reminder'] =
912
-                EEH_MSG_Template::is_mt_active('payment_reminder')
913
-                && $this->_transaction->get('STS_ID') !== EEM_Transaction::complete_status_code
914
-                && $this->_transaction->get('STS_ID') !== EEM_Transaction::overpaid_status_code
915
-                    ? EEH_Template::get_button_or_link(
916
-                        EE_Admin_Page::add_query_args_and_nonce(
917
-                            array(
918
-                                'action'      => 'send_payment_reminder',
919
-                                'TXN_ID'      => $this->_transaction->ID(),
920
-                                'redirect_to' => 'view_transaction',
921
-                            ),
922
-                            TXN_ADMIN_URL
923
-                        ),
924
-                        esc_html__(' Send Payment Reminder', 'event_espresso'),
925
-                        'button secondary-button',
926
-                        'dashicons dashicons-email-alt'
927
-                    )
928
-                    : '';
929
-        }
930
-
931
-        if ($primary_registration instanceof EE_Registration
932
-            && EEH_MSG_Template::is_mt_active('receipt')
933
-        ) {
934
-            $actions['receipt'] = EEH_Template::get_button_or_link(
935
-                $primary_registration->receipt_url(),
936
-                esc_html__('View Receipt', 'event_espresso'),
937
-                'button secondary-button',
938
-                'dashicons dashicons-media-default'
939
-            );
940
-        }
941
-
942
-        if ($primary_registration instanceof EE_Registration
943
-            && EEH_MSG_Template::is_mt_active('invoice')
944
-        ) {
945
-            $actions['invoice'] = EEH_Template::get_button_or_link(
946
-                $primary_registration->invoice_url(),
947
-                esc_html__('View Invoice', 'event_espresso'),
948
-                'button secondary-button',
949
-                'dashicons dashicons-media-spreadsheet'
950
-            );
951
-        }
952
-        $actions = array_filter(
953
-            apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction)
954
-        );
955
-        if ($actions) {
956
-            $content = '<ul>';
957
-            $content .= '<li>' . implode('</li><li>', $actions) . '</li>';
958
-            $content .= '</uL>';
959
-        }
960
-        return $content;
961
-    }
962
-
963
-
964
-    /**
965
-     * txn_details_meta_box
966
-     * generates HTML for the Transaction main meta box
967
-     *
968
-     * @return void
969
-     * @throws DomainException
970
-     * @throws EE_Error
971
-     * @throws InvalidArgumentException
972
-     * @throws InvalidDataTypeException
973
-     * @throws InvalidInterfaceException
974
-     * @throws RuntimeException
975
-     * @throws ReflectionException
976
-     */
977
-    public function txn_details_meta_box()
978
-    {
979
-        $this->_set_transaction_object();
980
-        $this->_template_args['TXN_ID']   = $this->_transaction->ID();
981
-        $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration
982
-            ? $this->_transaction->primary_registration()->attendee()
983
-            : null;
984
-        $this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can(
985
-            'ee_edit_payments',
986
-            'apply_payment_or_refund_from_registration_details'
987
-        );
988
-        $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can(
989
-            'ee_delete_payments',
990
-            'delete_payment_from_registration_details'
991
-        );
992
-
993
-        //get line table
994
-        EEH_Autoloader::register_line_item_display_autoloaders();
995
-        $Line_Item_Display                       = new EE_Line_Item_Display(
996
-            'admin_table',
997
-            'EE_Admin_Table_Line_Item_Display_Strategy'
998
-        );
999
-        $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item(
1000
-            $this->_transaction->total_line_item()
1001
-        );
1002
-        $this->_template_args['REG_code']        = $this->_transaction->get_first_related('Registration')
1003
-                                                                      ->get('REG_code');
1004
-
1005
-        // process taxes
1006
-        $taxes                         = $this->_transaction->get_many_related(
1007
-            'Line_Item',
1008
-            array(array('LIN_type' => EEM_Line_Item::type_tax))
1009
-        );
1010
-        $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
1011
-
1012
-        $this->_template_args['grand_total']     = EEH_Template::format_currency(
1013
-            $this->_transaction->get('TXN_total'),
1014
-            false,
1015
-            false
1016
-        );
1017
-        $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total');
1018
-        $this->_template_args['TXN_status']      = $this->_transaction->get('STS_ID');
1019
-
1020
-        // process payment details
1021
-        $payments = $this->_transaction->get_many_related('Payment');
1022
-        if (! empty($payments)) {
1023
-            $this->_template_args['payments']              = $payments;
1024
-            $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
1025
-        } else {
1026
-            $this->_template_args['payments']              = false;
1027
-            $this->_template_args['existing_reg_payments'] = array();
1028
-        }
1029
-
1030
-        $this->_template_args['edit_payment_url']   = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL);
1031
-        $this->_template_args['delete_payment_url'] = add_query_arg(
1032
-            array('action' => 'espresso_delete_payment'),
1033
-            TXN_ADMIN_URL
1034
-        );
1035
-
1036
-        if (isset($txn_details['invoice_number'])) {
1037
-            $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code'];
1038
-            $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__(
1039
-                'Invoice Number',
1040
-                'event_espresso'
1041
-            );
1042
-        }
1043
-
1044
-        $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction
1045
-            ->get_first_related('Registration')
1046
-            ->get('REG_session');
1047
-        $this->_template_args['txn_details']['registration_session']['label'] = esc_html__(
1048
-            'Registration Session',
1049
-            'event_espresso'
1050
-        );
1051
-
1052
-        $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address'])
1053
-            ? $this->_session['ip_address']
1054
-            : '';
1055
-        $this->_template_args['txn_details']['ip_address']['label'] = esc_html__(
1056
-            'Transaction placed from IP',
1057
-            'event_espresso'
1058
-        );
1059
-
1060
-        $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent'])
1061
-            ? $this->_session['user_agent']
1062
-            : '';
1063
-        $this->_template_args['txn_details']['user_agent']['label'] = esc_html__(
1064
-            'Registrant User Agent',
1065
-            'event_espresso'
1066
-        );
1067
-
1068
-        $reg_steps = '<ul>';
1069
-        foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
1070
-            if ($reg_step_status === true) {
1071
-                $reg_steps .= '<li style="color:#70cc50">'
1072
-                              . sprintf(
1073
-                                  esc_html__('%1$s : Completed', 'event_espresso'),
1074
-                                  ucwords(str_replace('_', ' ', $reg_step))
1075
-                              )
1076
-                              . '</li>';
1077
-            } elseif (is_numeric($reg_step_status) && $reg_step_status !== false) {
1078
-                $reg_steps .= '<li style="color:#2EA2CC">'
1079
-                              . sprintf(
1080
-                                  esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1081
-                                  ucwords(str_replace('_', ' ', $reg_step)),
1082
-                                  date(
1083
-                                      get_option('date_format') . ' ' . get_option('time_format'),
1084
-                                      ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))
1085
-                                  )
1086
-                              )
1087
-                              . '</li>';
1088
-            } else {
1089
-                $reg_steps .= '<li style="color:#E76700">'
1090
-                              . sprintf(
1091
-                                  esc_html__('%1$s : Never Initiated', 'event_espresso'),
1092
-                                  ucwords(str_replace('_', ' ', $reg_step))
1093
-                              )
1094
-                              . '</li>';
1095
-            }
1096
-        }
1097
-        $reg_steps                                                 .= '</ul>';
1098
-        $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
1099
-        $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__(
1100
-            'Registration Step Progress',
1101
-            'event_espresso'
1102
-        );
1103
-
1104
-
1105
-        $this->_get_registrations_to_apply_payment_to();
1106
-        $this->_get_payment_methods($payments);
1107
-        $this->_get_payment_status_array();
1108
-        $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction.
1109
-
1110
-        $this->_template_args['transaction_form_url']    = add_query_arg(array(
1111
-            'action'  => 'edit_transaction',
1112
-            'process' => 'transaction',
1113
-        ), TXN_ADMIN_URL);
1114
-        $this->_template_args['apply_payment_form_url']  = add_query_arg(array(
1115
-            'page'   => 'espresso_transactions',
1116
-            'action' => 'espresso_apply_payment',
1117
-        ), WP_AJAX_URL);
1118
-        $this->_template_args['delete_payment_form_url'] = add_query_arg(array(
1119
-            'page'   => 'espresso_transactions',
1120
-            'action' => 'espresso_delete_payment',
1121
-        ), WP_AJAX_URL);
1122
-
1123
-        $this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction);
1124
-
1125
-        // 'espresso_delete_payment_nonce'
1126
-
1127
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1128
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
1129
-    }
1130
-
1131
-
1132
-    /**
1133
-     * _get_registration_payment_IDs
1134
-     *    generates an array of Payment IDs and their corresponding Registration IDs
1135
-     *
1136
-     * @access protected
1137
-     * @param EE_Payment[] $payments
1138
-     * @return array
1139
-     * @throws EE_Error
1140
-     * @throws InvalidArgumentException
1141
-     * @throws InvalidDataTypeException
1142
-     * @throws InvalidInterfaceException
1143
-     * @throws ReflectionException
1144
-     */
1145
-    protected function _get_registration_payment_IDs($payments = array())
1146
-    {
1147
-        $existing_reg_payments = array();
1148
-        // get all reg payments for these payments
1149
-        $reg_payments = EEM_Registration_Payment::instance()->get_all(array(
1150
-            array(
1151
-                'PAY_ID' => array(
1152
-                    'IN',
1153
-                    array_keys($payments),
1154
-                ),
1155
-            ),
1156
-        ));
1157
-        if (! empty($reg_payments)) {
1158
-            foreach ($payments as $payment) {
1159
-                if (! $payment instanceof EE_Payment) {
1160
-                    continue;
1161
-                } elseif (! isset($existing_reg_payments[$payment->ID()])) {
1162
-                    $existing_reg_payments[$payment->ID()] = array();
1163
-                }
1164
-                foreach ($reg_payments as $reg_payment) {
1165
-                    if ($reg_payment instanceof EE_Registration_Payment
1166
-                        && $reg_payment->payment_ID() === $payment->ID()
1167
-                    ) {
1168
-                        $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID();
1169
-                    }
1170
-                }
1171
-            }
1172
-        }
1173
-
1174
-        return $existing_reg_payments;
1175
-    }
1176
-
1177
-
1178
-    /**
1179
-     * _get_registrations_to_apply_payment_to
1180
-     *    generates HTML for displaying a series of checkboxes in the admin payment modal window
1181
-     * which allows the admin to only apply the payment to the specific registrations
1182
-     *
1183
-     * @access protected
1184
-     * @return void
1185
-     * @throws \EE_Error
1186
-     */
1187
-    protected function _get_registrations_to_apply_payment_to()
1188
-    {
1189
-        // we want any registration with an active status (ie: not deleted or cancelled)
1190
-        $query_params                      = array(
1191
-            array(
1192
-                'STS_ID' => array(
1193
-                    'IN',
1194
-                    array(
1195
-                        EEM_Registration::status_id_approved,
1196
-                        EEM_Registration::status_id_pending_payment,
1197
-                        EEM_Registration::status_id_not_approved,
1198
-                    ),
1199
-                ),
1200
-            ),
1201
-        );
1202
-        $registrations_to_apply_payment_to = EEH_HTML::br()
1203
-                                             . EEH_HTML::div(
1204
-                                                 '',
1205
-                                                 'txn-admin-apply-payment-to-registrations-dv',
1206
-                                                 '',
1207
-                                                 'clear: both; margin: 1.5em 0 0; display: none;'
1208
-                                             );
1209
-        $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1210
-        $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
1211
-        $registrations_to_apply_payment_to .= EEH_HTML::thead(
1212
-            EEH_HTML::tr(
1213
-                EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1214
-                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1215
-                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1216
-                EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1217
-                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1218
-                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1219
-                EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1220
-            )
1221
-        );
1222
-        $registrations_to_apply_payment_to .= EEH_HTML::tbody();
1223
-        // get registrations for TXN
1224
-        $registrations = $this->_transaction->registrations($query_params);
1225
-        $existing_reg_payments = $this->_template_args['existing_reg_payments'];
1226
-        foreach ($registrations as $registration) {
1227
-            if ($registration instanceof EE_Registration) {
1228
-                $attendee_name                     = $registration->attendee() instanceof EE_Attendee
1229
-                    ? $registration->attendee()->full_name()
1230
-                    : esc_html__('Unknown Attendee', 'event_espresso');
1231
-                $owing                             = $registration->final_price() - $registration->paid();
1232
-                $taxable                           = $registration->ticket()->taxable()
1233
-                    ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1234
-                    : '';
1235
-                $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments)
1236
-                    ? ' checked="checked"'
1237
-                    : '';
1238
-                $disabled                          = $registration->final_price() > 0 ? '' : ' disabled';
1239
-                $registrations_to_apply_payment_to .= EEH_HTML::tr(
1240
-                    EEH_HTML::td($registration->ID()) .
1241
-                    EEH_HTML::td($attendee_name) .
1242
-                    EEH_HTML::td(
1243
-                        $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1244
-                    ) .
1245
-                    EEH_HTML::td($registration->event_name()) .
1246
-                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1247
-                    EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') .
1248
-                    EEH_HTML::td(
1249
-                        '<input type="checkbox" value="' . $registration->ID()
1250
-                        . '" name="txn_admin_payment[registrations]"'
1251
-                        . $checked . $disabled . '>',
1252
-                        '',
1253
-                        'jst-cntr'
1254
-                    ),
1255
-                    'apply-payment-registration-row-' . $registration->ID()
1256
-                );
1257
-            }
1258
-        }
1259
-        $registrations_to_apply_payment_to                         .= EEH_HTML::tbodyx();
1260
-        $registrations_to_apply_payment_to                         .= EEH_HTML::tablex();
1261
-        $registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1262
-        $registrations_to_apply_payment_to                         .= EEH_HTML::p(
1263
-            esc_html__(
1264
-                'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.',
1265
-                'event_espresso'
1266
-            ),
1267
-            '',
1268
-            'clear description'
1269
-        );
1270
-        $registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1271
-        $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1272
-    }
1273
-
1274
-
1275
-    /**
1276
-     * _get_reg_status_selection
1277
-     *
1278
-     * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1279
-     *         instead of events.
1280
-     * @access protected
1281
-     * @return void
1282
-     * @throws EE_Error
1283
-     */
1284
-    protected function _get_reg_status_selection()
1285
-    {
1286
-        //first get all possible statuses
1287
-        $statuses = EEM_Registration::reg_status_array(array(), true);
1288
-        //let's add a "don't change" option.
1289
-        $status_array['NAN']                                 = esc_html__('Leave the Same', 'event_espresso');
1290
-        $status_array                                        = array_merge($status_array, $statuses);
1291
-        $this->_template_args['status_change_select']        = EEH_Form_Fields::select_input(
1292
-            'txn_reg_status_change[reg_status]',
1293
-            $status_array,
1294
-            'NAN',
1295
-            'id="txn-admin-payment-reg-status-inp"',
1296
-            'txn-reg-status-change-reg-status'
1297
-        );
1298
-        $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input(
1299
-            'delete_txn_reg_status_change[reg_status]',
1300
-            $status_array,
1301
-            'NAN',
1302
-            'delete-txn-admin-payment-reg-status-inp',
1303
-            'delete-txn-reg-status-change-reg-status'
1304
-        );
1305
-    }
1306
-
1307
-
1308
-    /**
1309
-     *    _get_payment_methods
1310
-     * Gets all the payment methods available generally, or the ones that are already
1311
-     * selected on these payments (in case their payment methods are no longer active).
1312
-     * Has the side-effect of updating the template args' payment_methods item
1313
-     *
1314
-     * @access private
1315
-     * @param EE_Payment[] to show on this page
1316
-     * @return void
1317
-     * @throws EE_Error
1318
-     * @throws InvalidArgumentException
1319
-     * @throws InvalidDataTypeException
1320
-     * @throws InvalidInterfaceException
1321
-     * @throws ReflectionException
1322
-     */
1323
-    private function _get_payment_methods($payments = array())
1324
-    {
1325
-        $payment_methods_of_payments = array();
1326
-        foreach ($payments as $payment) {
1327
-            if ($payment instanceof EE_Payment) {
1328
-                $payment_methods_of_payments[] = $payment->get('PMD_ID');
1329
-            }
1330
-        }
1331
-        if ($payment_methods_of_payments) {
1332
-            $query_args = array(
1333
-                array(
1334
-                    'OR*payment_method_for_payment' => array(
1335
-                        'PMD_ID'    => array('IN', $payment_methods_of_payments),
1336
-                        'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'),
1337
-                    ),
1338
-                ),
1339
-            );
1340
-        } else {
1341
-            $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1342
-        }
1343
-        $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1344
-    }
1345
-
1346
-
1347
-    /**
1348
-     * txn_attendees_meta_box
1349
-     *    generates HTML for the Attendees Transaction main meta box
1350
-     *
1351
-     * @access public
1352
-     * @param WP_Post $post
1353
-     * @param array   $metabox
1354
-     * @return void
1355
-     * @throws DomainException
1356
-     * @throws EE_Error
1357
-     */
1358
-    public function txn_attendees_meta_box($post, $metabox = array('args' => array()))
1359
-    {
1360
-
1361
-        /** @noinspection NonSecureExtractUsageInspection */
1362
-        extract($metabox['args']);
1363
-        $this->_template_args['post']            = $post;
1364
-        $this->_template_args['event_attendees'] = array();
1365
-        // process items in cart
1366
-        $line_items = $this->_transaction->get_many_related(
1367
-            'Line_Item',
1368
-            array(array('LIN_type' => 'line-item'))
1369
-        );
1370
-        if (! empty($line_items)) {
1371
-            foreach ($line_items as $item) {
1372
-                if ($item instanceof EE_Line_Item) {
1373
-                    switch ($item->OBJ_type()) {
1374
-                        case 'Event':
1375
-                            break;
1376
-                        case 'Ticket':
1377
-                            $ticket = $item->ticket();
1378
-                            //right now we're only handling tickets here.
1379
-                            //Cause its expected that only tickets will have attendees right?
1380
-                            if (! $ticket instanceof EE_Ticket) {
1381
-                                continue;
1382
-                            }
1383
-                            try {
1384
-                                $event_name = $ticket->get_event_name();
1385
-                            } catch (Exception $e) {
1386
-                                EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1387
-                                $event_name = esc_html__('Unknown Event', 'event_espresso');
1388
-                            }
1389
-                            $event_name   .= ' - ' . $item->get('LIN_name');
1390
-                            $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price'));
1391
-                            // now get all of the registrations for this transaction that use this ticket
1392
-                            $registrations = $ticket->get_many_related(
1393
-                                'Registration',
1394
-                                array(array('TXN_ID' => $this->_transaction->ID()))
1395
-                            );
1396
-                            foreach ($registrations as $registration) {
1397
-                                if (! $registration instanceof EE_Registration) {
1398
-                                    continue;
1399
-                                }
1400
-                                $this->_template_args['event_attendees'][$registration->ID()]['STS_ID']
1401
-                                    = $registration->status_ID();
1402
-                                $this->_template_args['event_attendees'][$registration->ID()]['att_num']
1403
-                                    = $registration->count();
1404
-                                $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name']
1405
-                                    = $event_name;
1406
-                                $this->_template_args['event_attendees'][$registration->ID()]['ticket_price']
1407
-                                    = $ticket_price;
1408
-                                // attendee info
1409
-                                $attendee = $registration->get_first_related('Attendee');
1410
-                                if ($attendee instanceof EE_Attendee) {
1411
-                                    $this->_template_args['event_attendees'][$registration->ID()]['att_id']
1412
-                                        = $attendee->ID();
1413
-                                    $this->_template_args['event_attendees'][$registration->ID()]['attendee']
1414
-                                        = $attendee->full_name();
1415
-                                    $this->_template_args['event_attendees'][$registration->ID()]['email']
1416
-                                        = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1417
-                                          . esc_html__(
1418
-                                              ' Event',
1419
-                                              'event_espresso'
1420
-                                          )
1421
-                                          . '">' . $attendee->email() . '</a>';
1422
-                                    $this->_template_args['event_attendees'][$registration->ID()]['address']
1423
-                                        = EEH_Address::format($attendee, 'inline', false, false);
1424
-                                } else {
1425
-                                    $this->_template_args['event_attendees'][$registration->ID()]['att_id']   = '';
1426
-                                    $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = '';
1427
-                                    $this->_template_args['event_attendees'][$registration->ID()]['email']    = '';
1428
-                                    $this->_template_args['event_attendees'][$registration->ID()]['address']  = '';
1429
-                                }
1430
-                            }
1431
-                            break;
1432
-
1433
-                    }
1434
-                }
1435
-            }
1436
-
1437
-            $this->_template_args['transaction_form_url'] = add_query_arg(
1438
-                array(
1439
-                    'action'  => 'edit_transaction',
1440
-                    'process' => 'attendees',
1441
-                ),
1442
-                TXN_ADMIN_URL
1443
-            );
1444
-            echo EEH_Template::display_template(
1445
-                TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1446
-                $this->_template_args,
1447
-                true
1448
-            );
1449
-
1450
-        } else {
1451
-            echo sprintf(
1452
-                esc_html__(
1453
-                    '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1454
-                    'event_espresso'
1455
-                ),
1456
-                '<p class="important-notice">',
1457
-                '</p>'
1458
-            );
1459
-        }
1460
-    }
1461
-
1462
-
1463
-    /**
1464
-     * txn_registrant_side_meta_box
1465
-     * generates HTML for the Edit Transaction side meta box
1466
-     *
1467
-     * @access public
1468
-     * @return void
1469
-     * @throws DomainException
1470
-     * @throws EE_Error
1471
-     * @throws InvalidArgumentException
1472
-     * @throws InvalidDataTypeException
1473
-     * @throws InvalidInterfaceException
1474
-     * @throws ReflectionException
1475
-     */
1476
-    public function txn_registrant_side_meta_box()
1477
-    {
1478
-        $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1479
-            ? $this->_transaction->primary_registration()->get_first_related('Attendee')
1480
-            : null;
1481
-        if (! $primary_att instanceof EE_Attendee) {
1482
-            $this->_template_args['no_attendee_message'] = esc_html__(
1483
-                'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1484
-                'event_espresso'
1485
-            );
1486
-            $primary_att                                 = EEM_Attendee::instance()->create_default_object();
1487
-        }
1488
-        $this->_template_args['ATT_ID']            = $primary_att->ID();
1489
-        $this->_template_args['prime_reg_fname']   = $primary_att->fname();
1490
-        $this->_template_args['prime_reg_lname']   = $primary_att->lname();
1491
-        $this->_template_args['prime_reg_email']   = $primary_att->email();
1492
-        $this->_template_args['prime_reg_phone']   = $primary_att->phone();
1493
-        $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array(
1494
-            'action' => 'edit_attendee',
1495
-            'post'   => $primary_att->ID(),
1496
-        ), REG_ADMIN_URL);
1497
-        // get formatted address for registrant
1498
-        $this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1499
-        echo EEH_Template::display_template(
1500
-            TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1501
-            $this->_template_args,
1502
-            true
1503
-        );
1504
-    }
1505
-
1506
-
1507
-    /**
1508
-     * txn_billing_info_side_meta_box
1509
-     *    generates HTML for the Edit Transaction side meta box
1510
-     *
1511
-     * @access public
1512
-     * @return void
1513
-     * @throws DomainException
1514
-     * @throws EE_Error
1515
-     */
1516
-    public function txn_billing_info_side_meta_box()
1517
-    {
1518
-
1519
-        $this->_template_args['billing_form']     = $this->_transaction->billing_info();
1520
-        $this->_template_args['billing_form_url'] = add_query_arg(
1521
-            array('action' => 'edit_transaction', 'process' => 'billing'),
1522
-            TXN_ADMIN_URL
1523
-        );
1524
-
1525
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1526
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/
1527
-    }
1528
-
1529
-
1530
-    /**
1531
-     * apply_payments_or_refunds
1532
-     *    registers a payment or refund made towards a transaction
1533
-     *
1534
-     * @access public
1535
-     * @return void
1536
-     * @throws EE_Error
1537
-     * @throws InvalidArgumentException
1538
-     * @throws ReflectionException
1539
-     * @throws RuntimeException
1540
-     * @throws InvalidDataTypeException
1541
-     * @throws InvalidInterfaceException
1542
-     */
1543
-    public function apply_payments_or_refunds()
1544
-    {
1545
-        $json_response_data = array('return_data' => false);
1546
-        $valid_data         = $this->_validate_payment_request_data();
1547
-        $has_access = EE_Registry::instance()->CAP->current_user_can(
1548
-            'ee_edit_payments',
1549
-            'apply_payment_or_refund_from_registration_details'
1550
-        );
1551
-        if (! empty($valid_data) && $has_access) {
1552
-            $PAY_ID = $valid_data['PAY_ID'];
1553
-            //save  the new payment
1554
-            $payment = $this->_create_payment_from_request_data($valid_data);
1555
-            // get the TXN for this payment
1556
-            $transaction = $payment->transaction();
1557
-            // verify transaction
1558
-            if ($transaction instanceof EE_Transaction) {
1559
-                // calculate_total_payments_and_update_status
1560
-                $this->_process_transaction_payments($transaction);
1561
-                $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1562
-                $this->_remove_existing_registration_payments($payment, $PAY_ID);
1563
-                // apply payment to registrations (if applicable)
1564
-                if (! empty($REG_IDs)) {
1565
-                    $this->_update_registration_payments($transaction, $payment, $REG_IDs);
1566
-                    $this->_maybe_send_notifications();
1567
-                    // now process status changes for the same registrations
1568
-                    $this->_process_registration_status_change($transaction, $REG_IDs);
1569
-                }
1570
-                $this->_maybe_send_notifications($payment);
1571
-                //prepare to render page
1572
-                $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1573
-                do_action(
1574
-                    'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording',
1575
-                    $transaction,
1576
-                    $payment
1577
-                );
1578
-            } else {
1579
-                EE_Error::add_error(
1580
-                    esc_html__(
1581
-                        'A valid Transaction for this payment could not be retrieved.',
1582
-                        'event_espresso'
1583
-                    ),
1584
-                    __FILE__,
1585
-                    __FUNCTION__,
1586
-                    __LINE__
1587
-                );
1588
-            }
1589
-        } else {
1590
-            if ($has_access) {
1591
-                EE_Error::add_error(
1592
-                    esc_html__(
1593
-                        'The payment form data could not be processed. Please try again.',
1594
-                        'event_espresso'
1595
-                    ),
1596
-                    __FILE__,
1597
-                    __FUNCTION__,
1598
-                    __LINE__
1599
-                );
1600
-            } else {
1601
-                EE_Error::add_error(
1602
-                    esc_html__(
1603
-                        'You do not have access to apply payments or refunds to a registration.',
1604
-                        'event_espresso'
1605
-                    ),
1606
-                    __FILE__,
1607
-                    __FUNCTION__,
1608
-                    __LINE__
1609
-                );
1610
-            }
1611
-        }
1612
-        $notices              = EE_Error::get_notices(
1613
-            false,
1614
-            false,
1615
-            false
1616
-        );
1617
-        $this->_template_args = array(
1618
-            'data'    => $json_response_data,
1619
-            'error'   => $notices['errors'],
1620
-            'success' => $notices['success'],
1621
-        );
1622
-        $this->_return_json();
1623
-    }
1624
-
1625
-
1626
-    /**
1627
-     * _validate_payment_request_data
1628
-     *
1629
-     * @return array
1630
-     * @throws EE_Error
1631
-     */
1632
-    protected function _validate_payment_request_data()
1633
-    {
1634
-        if (! isset($this->_req_data['txn_admin_payment'])) {
1635
-            return false;
1636
-        }
1637
-        $payment_form = $this->_generate_payment_form_section();
1638
-        try {
1639
-            if ($payment_form->was_submitted()) {
1640
-                $payment_form->receive_form_submission();
1641
-                if (! $payment_form->is_valid()) {
1642
-                    $submission_error_messages = array();
1643
-                    foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1644
-                        if ($validation_error instanceof EE_Validation_Error) {
1645
-                            $submission_error_messages[] = sprintf(
1646
-                                _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1647
-                                $validation_error->get_form_section()->html_label_text(),
1648
-                                $validation_error->getMessage()
1649
-                            );
1650
-                        }
1651
-                    }
1652
-                    EE_Error::add_error(
1653
-                        implode('<br />', $submission_error_messages),
1654
-                        __FILE__,
1655
-                        __FUNCTION__,
1656
-                        __LINE__
1657
-                    );
1658
-
1659
-                    return array();
1660
-                }
1661
-            }
1662
-        } catch (EE_Error $e) {
1663
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1664
-
1665
-            return array();
1666
-        }
1667
-
1668
-        return $payment_form->valid_data();
1669
-    }
1670
-
1671
-
1672
-    /**
1673
-     * _generate_payment_form_section
1674
-     *
1675
-     * @return EE_Form_Section_Proper
1676
-     * @throws EE_Error
1677
-     */
1678
-    protected function _generate_payment_form_section()
1679
-    {
1680
-        return new EE_Form_Section_Proper(
1681
-            array(
1682
-                'name'        => 'txn_admin_payment',
1683
-                'subsections' => array(
1684
-                    'PAY_ID'          => new EE_Text_Input(
1685
-                        array(
1686
-                            'default'               => 0,
1687
-                            'required'              => false,
1688
-                            'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1689
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1690
-                        )
1691
-                    ),
1692
-                    'TXN_ID'          => new EE_Text_Input(
1693
-                        array(
1694
-                            'default'               => 0,
1695
-                            'required'              => true,
1696
-                            'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1697
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1698
-                        )
1699
-                    ),
1700
-                    'type'            => new EE_Text_Input(
1701
-                        array(
1702
-                            'default'               => 1,
1703
-                            'required'              => true,
1704
-                            'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1705
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1706
-                        )
1707
-                    ),
1708
-                    'amount'          => new EE_Text_Input(
1709
-                        array(
1710
-                            'default'               => 0,
1711
-                            'required'              => true,
1712
-                            'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1713
-                            'validation_strategies' => array(new EE_Float_Normalization()),
1714
-                        )
1715
-                    ),
1716
-                    'status'          => new EE_Text_Input(
1717
-                        array(
1718
-                            'default'         => EEM_Payment::status_id_approved,
1719
-                            'required'        => true,
1720
-                            'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1721
-                        )
1722
-                    ),
1723
-                    'PMD_ID'          => new EE_Text_Input(
1724
-                        array(
1725
-                            'default'               => 2,
1726
-                            'required'              => true,
1727
-                            'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1728
-                            'validation_strategies' => array(new EE_Int_Normalization()),
1729
-                        )
1730
-                    ),
1731
-                    'date'            => new EE_Text_Input(
1732
-                        array(
1733
-                            'default'         => time(),
1734
-                            'required'        => true,
1735
-                            'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1736
-                        )
1737
-                    ),
1738
-                    'txn_id_chq_nmbr' => new EE_Text_Input(
1739
-                        array(
1740
-                            'default'               => '',
1741
-                            'required'              => false,
1742
-                            'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1743
-                            'validation_strategies' => array(
1744
-                                new EE_Max_Length_Validation_Strategy(
1745
-                                    esc_html__('Input too long', 'event_espresso'),
1746
-                                    100
1747
-                                ),
1748
-                            ),
1749
-                        )
1750
-                    ),
1751
-                    'po_number'       => new EE_Text_Input(
1752
-                        array(
1753
-                            'default'               => '',
1754
-                            'required'              => false,
1755
-                            'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1756
-                            'validation_strategies' => array(
1757
-                                new EE_Max_Length_Validation_Strategy(
1758
-                                    esc_html__('Input too long', 'event_espresso'),
1759
-                                    100
1760
-                                ),
1761
-                            ),
1762
-                        )
1763
-                    ),
1764
-                    'accounting'      => new EE_Text_Input(
1765
-                        array(
1766
-                            'default'               => '',
1767
-                            'required'              => false,
1768
-                            'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1769
-                            'validation_strategies' => array(
1770
-                                new EE_Max_Length_Validation_Strategy(
1771
-                                    esc_html__('Input too long', 'event_espresso'),
1772
-                                    100
1773
-                                ),
1774
-                            ),
1775
-                        )
1776
-                    ),
1777
-                ),
1778
-            )
1779
-        );
1780
-    }
1781
-
1782
-
1783
-    /**
1784
-     * _create_payment_from_request_data
1785
-     *
1786
-     * @param array $valid_data
1787
-     * @return EE_Payment
1788
-     * @throws EE_Error
1789
-     */
1790
-    protected function _create_payment_from_request_data($valid_data)
1791
-    {
1792
-        $PAY_ID = $valid_data['PAY_ID'];
1793
-        // get payment amount
1794
-        $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1795
-        // payments have a type value of 1 and refunds have a type value of -1
1796
-        // so multiplying amount by type will give a positive value for payments, and negative values for refunds
1797
-        $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1798
-        // for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1799
-        $date    = $valid_data['date']
1800
-            ? preg_replace('/\s+/', ' ', $valid_data['date'])
1801
-            : date('Y-m-d g:i a', current_time('timestamp'));
1802
-        $payment = EE_Payment::new_instance(
1803
-            array(
1804
-                'TXN_ID'              => $valid_data['TXN_ID'],
1805
-                'STS_ID'              => $valid_data['status'],
1806
-                'PAY_timestamp'       => $date,
1807
-                'PAY_source'          => EEM_Payment_Method::scope_admin,
1808
-                'PMD_ID'              => $valid_data['PMD_ID'],
1809
-                'PAY_amount'          => $amount,
1810
-                'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1811
-                'PAY_po_number'       => $valid_data['po_number'],
1812
-                'PAY_extra_accntng'   => $valid_data['accounting'],
1813
-                'PAY_details'         => $valid_data,
1814
-                'PAY_ID'              => $PAY_ID,
1815
-            ),
1816
-            '',
1817
-            array('Y-m-d', 'g:i a')
1818
-        );
1819
-
1820
-        if (! $payment->save()) {
1821
-            EE_Error::add_error(
1822
-                sprintf(
1823
-                    esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1824
-                    $payment->ID()
1825
-                ),
1826
-                __FILE__, __FUNCTION__, __LINE__
1827
-            );
1828
-        }
1829
-
1830
-        return $payment;
1831
-    }
1832
-
1833
-
1834
-    /**
1835
-     * _process_transaction_payments
1836
-     *
1837
-     * @param \EE_Transaction $transaction
1838
-     * @return void
1839
-     * @throws EE_Error
1840
-     * @throws InvalidArgumentException
1841
-     * @throws ReflectionException
1842
-     * @throws InvalidDataTypeException
1843
-     * @throws InvalidInterfaceException
1844
-     */
1845
-    protected function _process_transaction_payments(EE_Transaction $transaction)
1846
-    {
1847
-        /** @type EE_Transaction_Payments $transaction_payments */
1848
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1849
-        //update the transaction with this payment
1850
-        if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1851
-            EE_Error::add_success(esc_html__(
1852
-                'The payment has been processed successfully.', 'event_espresso'),
1853
-                __FILE__,
1854
-                __FUNCTION__,
1855
-                __LINE__
1856
-            );
1857
-        } else {
1858
-            EE_Error::add_error(
1859
-                esc_html__(
1860
-                    'The payment was processed successfully but the amount paid for the transaction was not updated.',
1861
-                    'event_espresso'
1862
-                )
1863
-                ,
1864
-                __FILE__,
1865
-                __FUNCTION__,
1866
-                __LINE__
1867
-            );
1868
-        }
1869
-    }
1870
-
1871
-
1872
-    /**
1873
-     * _get_REG_IDs_to_apply_payment_to
1874
-     * returns a list of registration IDs that the payment will apply to
1875
-     *
1876
-     * @param \EE_Payment $payment
1877
-     * @return array
1878
-     * @throws EE_Error
1879
-     */
1880
-    protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1881
-    {
1882
-        $REG_IDs = array();
1883
-        // grab array of IDs for specific registrations to apply changes to
1884
-        if (isset($this->_req_data['txn_admin_payment']['registrations'])) {
1885
-            $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations'];
1886
-        }
1887
-        //nothing specified ? then get all reg IDs
1888
-        if (empty($REG_IDs)) {
1889
-            $registrations = $payment->transaction()->registrations();
1890
-            $REG_IDs       = ! empty($registrations)
1891
-                ? array_keys($registrations)
1892
-                : $this->_get_existing_reg_payment_REG_IDs($payment);
1893
-        }
1894
-
1895
-        // ensure that REG_IDs are integers and NOT strings
1896
-        return array_map('intval', $REG_IDs);
1897
-    }
1898
-
1899
-
1900
-    /**
1901
-     * @return array
1902
-     */
1903
-    public function existing_reg_payment_REG_IDs()
1904
-    {
1905
-        return $this->_existing_reg_payment_REG_IDs;
1906
-    }
1907
-
1908
-
1909
-    /**
1910
-     * @param array $existing_reg_payment_REG_IDs
1911
-     */
1912
-    public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1913
-    {
1914
-        $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1915
-    }
1916
-
1917
-
1918
-    /**
1919
-     * _get_existing_reg_payment_REG_IDs
1920
-     * returns a list of registration IDs that the payment is currently related to
1921
-     * as recorded in the database
1922
-     *
1923
-     * @param \EE_Payment $payment
1924
-     * @return array
1925
-     * @throws EE_Error
1926
-     */
1927
-    protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
1928
-    {
1929
-        if ($this->existing_reg_payment_REG_IDs() === null) {
1930
-            // let's get any existing reg payment records for this payment
1931
-            $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
1932
-            // but we only want the REG IDs, so grab the array keys
1933
-            $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs)
1934
-                ? array_keys($existing_reg_payment_REG_IDs)
1935
-                : array();
1936
-            $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
1937
-        }
1938
-
1939
-        return $this->existing_reg_payment_REG_IDs();
1940
-    }
1941
-
1942
-
1943
-    /**
1944
-     * _remove_existing_registration_payments
1945
-     * this calculates the difference between existing relations
1946
-     * to the supplied payment and the new list registration IDs,
1947
-     * removes any related registrations that no longer apply,
1948
-     * and then updates the registration paid fields
1949
-     *
1950
-     * @param \EE_Payment $payment
1951
-     * @param int         $PAY_ID
1952
-     * @return bool;
1953
-     * @throws EE_Error
1954
-     * @throws InvalidArgumentException
1955
-     * @throws ReflectionException
1956
-     * @throws InvalidDataTypeException
1957
-     * @throws InvalidInterfaceException
1958
-     */
1959
-    protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
1960
-    {
1961
-        // newly created payments will have nothing recorded for $PAY_ID
1962
-        if ($PAY_ID == 0) {
1963
-            return false;
1964
-        }
1965
-        $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
1966
-        if (empty($existing_reg_payment_REG_IDs)) {
1967
-            return false;
1968
-        }
1969
-        /** @type EE_Transaction_Payments $transaction_payments */
1970
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1971
-
1972
-        return $transaction_payments->delete_registration_payments_and_update_registrations(
1973
-            $payment,
1974
-            array(
1975
-                array(
1976
-                    'PAY_ID' => $payment->ID(),
1977
-                    'REG_ID' => array('IN', $existing_reg_payment_REG_IDs),
1978
-                ),
1979
-            )
1980
-        );
1981
-    }
1982
-
1983
-
1984
-    /**
1985
-     * _update_registration_payments
1986
-     * this applies the payments to the selected registrations
1987
-     * but only if they have not already been paid for
1988
-     *
1989
-     * @param  EE_Transaction $transaction
1990
-     * @param \EE_Payment     $payment
1991
-     * @param array           $REG_IDs
1992
-     * @return void
1993
-     * @throws EE_Error
1994
-     * @throws InvalidArgumentException
1995
-     * @throws ReflectionException
1996
-     * @throws RuntimeException
1997
-     * @throws InvalidDataTypeException
1998
-     * @throws InvalidInterfaceException
1999
-     */
2000
-    protected function _update_registration_payments(
2001
-        EE_Transaction $transaction,
2002
-        EE_Payment $payment,
2003
-        $REG_IDs = array()
2004
-    ) {
2005
-        // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
2006
-        // so let's do that using our set of REG_IDs from the form
2007
-        $registration_query_where_params = array(
2008
-            'REG_ID' => array('IN', $REG_IDs),
2009
-        );
2010
-        // but add in some conditions regarding payment,
2011
-        // so that we don't apply payments to registrations that are free or have already been paid for
2012
-        // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
2013
-        if (! $payment->is_a_refund()) {
2014
-            $registration_query_where_params['REG_final_price']  = array('!=', 0);
2015
-            $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true);
2016
-        }
2017
-        $registrations = $transaction->registrations(array($registration_query_where_params));
2018
-        if (! empty($registrations)) {
2019
-            /** @type EE_Payment_Processor $payment_processor */
2020
-            $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2021
-            $payment_processor->process_registration_payments($transaction, $payment, $registrations);
2022
-        }
2023
-    }
2024
-
2025
-
2026
-    /**
2027
-     * _process_registration_status_change
2028
-     * This processes requested registration status changes for all the registrations
2029
-     * on a given transaction and (optionally) sends out notifications for the changes.
2030
-     *
2031
-     * @param  EE_Transaction $transaction
2032
-     * @param array           $REG_IDs
2033
-     * @return bool
2034
-     * @throws EE_Error
2035
-     * @throws InvalidArgumentException
2036
-     * @throws ReflectionException
2037
-     * @throws InvalidDataTypeException
2038
-     * @throws InvalidInterfaceException
2039
-     */
2040
-    protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array())
2041
-    {
2042
-        // first if there is no change in status then we get out.
2043
-        if (
2044
-            ! isset($this->_req_data['txn_reg_status_change']['reg_status'])
2045
-            || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN'
2046
-        ) {
2047
-            //no error message, no change requested, just nothing to do man.
2048
-            return false;
2049
-        }
2050
-        /** @type EE_Transaction_Processor $transaction_processor */
2051
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
2052
-
2053
-        // made it here dude?  Oh WOW.  K, let's take care of changing the statuses
2054
-        return $transaction_processor->manually_update_registration_statuses(
2055
-            $transaction,
2056
-            sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']),
2057
-            array(array('REG_ID' => array('IN', $REG_IDs)))
2058
-        );
2059
-    }
2060
-
2061
-
2062
-    /**
2063
-     * _build_payment_json_response
2064
-     *
2065
-     * @access public
2066
-     * @param \EE_Payment $payment
2067
-     * @param array       $REG_IDs
2068
-     * @param bool | null $delete_txn_reg_status_change
2069
-     * @return array
2070
-     * @throws EE_Error
2071
-     * @throws InvalidArgumentException
2072
-     * @throws InvalidDataTypeException
2073
-     * @throws InvalidInterfaceException
2074
-     * @throws ReflectionException
2075
-     */
2076
-    protected function _build_payment_json_response(
2077
-        EE_Payment $payment,
2078
-        $REG_IDs = array(),
2079
-        $delete_txn_reg_status_change = null
2080
-    ) {
2081
-        // was the payment deleted ?
2082
-        if (is_bool($delete_txn_reg_status_change)) {
2083
-            return array(
2084
-                'PAY_ID'                       => $payment->ID(),
2085
-                'amount'                       => $payment->amount(),
2086
-                'total_paid'                   => $payment->transaction()->paid(),
2087
-                'txn_status'                   => $payment->transaction()->status_ID(),
2088
-                'pay_status'                   => $payment->STS_ID(),
2089
-                'registrations'                => $this->_registration_payment_data_array($REG_IDs),
2090
-                'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
2091
-            );
2092
-        } else {
2093
-            $this->_get_payment_status_array();
2094
-
2095
-            return array(
2096
-                'amount'           => $payment->amount(),
2097
-                'total_paid'       => $payment->transaction()->paid(),
2098
-                'txn_status'       => $payment->transaction()->status_ID(),
2099
-                'pay_status'       => $payment->STS_ID(),
2100
-                'PAY_ID'           => $payment->ID(),
2101
-                'STS_ID'           => $payment->STS_ID(),
2102
-                'status'           => self::$_pay_status[$payment->STS_ID()],
2103
-                'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
2104
-                'method'           => strtoupper($payment->source()),
2105
-                'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
2106
-                'gateway'          => $payment->payment_method()
2107
-                    ? $payment->payment_method()->admin_name()
2108
-                    : esc_html__("Unknown", 'event_espresso'),
2109
-                'gateway_response' => $payment->gateway_response(),
2110
-                'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
2111
-                'po_number'        => $payment->po_number(),
2112
-                'extra_accntng'    => $payment->extra_accntng(),
2113
-                'registrations'    => $this->_registration_payment_data_array($REG_IDs),
2114
-            );
2115
-        }
2116
-    }
2117
-
2118
-
2119
-    /**
2120
-     * delete_payment
2121
-     *    delete a payment or refund made towards a transaction
2122
-     *
2123
-     * @access public
2124
-     * @return void
2125
-     * @throws EE_Error
2126
-     * @throws InvalidArgumentException
2127
-     * @throws ReflectionException
2128
-     * @throws InvalidDataTypeException
2129
-     * @throws InvalidInterfaceException
2130
-     */
2131
-    public function delete_payment()
2132
-    {
2133
-        $json_response_data = array('return_data' => false);
2134
-        $PAY_ID             = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2135
-            ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2136
-            : 0;
2137
-        $can_delete = EE_Registry::instance()->CAP->current_user_can(
2138
-            'ee_delete_payments',
2139
-            'delete_payment_from_registration_details'
2140
-        );
2141
-        if ($PAY_ID && $can_delete) {
2142
-            $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change'])
2143
-                ? $this->_req_data['delete_txn_reg_status_change']
2144
-                : false;
2145
-            $payment                      = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
2146
-            if ($payment instanceof EE_Payment) {
2147
-                $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2148
-                /** @type EE_Transaction_Payments $transaction_payments */
2149
-                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2150
-                if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
2151
-                    $json_response_data['return_data'] = $this->_build_payment_json_response(
2152
-                        $payment,
2153
-                        $REG_IDs,
2154
-                        $delete_txn_reg_status_change
2155
-                    );
2156
-                    if ($delete_txn_reg_status_change) {
2157
-                        $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change;
2158
-                        //MAKE sure we also add the delete_txn_req_status_change to the
2159
-                        //$_REQUEST global because that's how messages will be looking for it.
2160
-                        $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change;
2161
-                        $this->_maybe_send_notifications();
2162
-                        $this->_process_registration_status_change($payment->transaction(), $REG_IDs);
2163
-                    }
2164
-                }
2165
-            } else {
2166
-                EE_Error::add_error(
2167
-                    esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
2168
-                    __FILE__, __FUNCTION__, __LINE__
2169
-                );
2170
-            }
2171
-        } else {
2172
-            if ($can_delete) {
2173
-                EE_Error::add_error(
2174
-                    esc_html__(
2175
-                        'A valid Payment ID was not received, therefore payment form data could not be loaded.',
2176
-                        'event_espresso'
2177
-                    ),
2178
-                    __FILE__, __FUNCTION__, __LINE__
2179
-                );
2180
-            } else {
2181
-                EE_Error::add_error(
2182
-                    esc_html__(
2183
-                        'You do not have access to delete a payment.',
2184
-                        'event_espresso'
2185
-                    ),
2186
-                    __FILE__,
2187
-                    __FUNCTION__,
2188
-                    __LINE__
2189
-                );
2190
-            }
2191
-        }
2192
-        $notices              = EE_Error::get_notices(false, false, false);
2193
-        $this->_template_args = array(
2194
-            'data'      => $json_response_data,
2195
-            'success'   => $notices['success'],
2196
-            'error'     => $notices['errors'],
2197
-            'attention' => $notices['attention'],
2198
-        );
2199
-        $this->_return_json();
2200
-    }
2201
-
2202
-
2203
-    /**
2204
-     * _registration_payment_data_array
2205
-     * adds info for 'owing' and 'paid' for each registration to the json response
2206
-     *
2207
-     * @access protected
2208
-     * @param array $REG_IDs
2209
-     * @return array
2210
-     * @throws EE_Error
2211
-     * @throws InvalidArgumentException
2212
-     * @throws InvalidDataTypeException
2213
-     * @throws InvalidInterfaceException
2214
-     * @throws ReflectionException
2215
-     */
2216
-    protected function _registration_payment_data_array($REG_IDs)
2217
-    {
2218
-        $registration_payment_data = array();
2219
-        //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2220
-        if (! empty($REG_IDs)) {
2221
-            $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs))));
2222
-            foreach ($registrations as $registration) {
2223
-                if ($registration instanceof EE_Registration) {
2224
-                    $registration_payment_data[$registration->ID()] = array(
2225
-                        'paid'  => $registration->pretty_paid(),
2226
-                        'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
2227
-                    );
2228
-                }
2229
-            }
2230
-        }
2231
-
2232
-        return $registration_payment_data;
2233
-    }
2234
-
2235
-
2236
-    /**
2237
-     * _maybe_send_notifications
2238
-     * determines whether or not the admin has indicated that notifications should be sent.
2239
-     * If so, will toggle a filter switch for delivering registration notices.
2240
-     * If passed an EE_Payment object, then it will trigger payment notifications instead.
2241
-     *
2242
-     * @access protected
2243
-     * @param \EE_Payment | null $payment
2244
-     */
2245
-    protected function _maybe_send_notifications($payment = null)
2246
-    {
2247
-        switch ($payment instanceof EE_Payment) {
2248
-            // payment notifications
2249
-            case true :
2250
-                if (
2251
-                    isset(
2252
-                        $this->_req_data['txn_payments'],
2253
-                        $this->_req_data['txn_payments']['send_notifications']
2254
-                    ) &&
2255
-                    filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
2256
-                ) {
2257
-                    $this->_process_payment_notification($payment);
2258
-                }
2259
-                break;
2260
-            // registration notifications
2261
-            case false :
2262
-                if (
2263
-                    isset(
2264
-                        $this->_req_data['txn_reg_status_change'],
2265
-                        $this->_req_data['txn_reg_status_change']['send_notifications']
2266
-                    ) &&
2267
-                    filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
2268
-                ) {
2269
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
2270
-                }
2271
-                break;
2272
-        }
2273
-    }
2274
-
2275
-
2276
-    /**
2277
-     * _send_payment_reminder
2278
-     *    generates HTML for the View Transaction Details Admin page
2279
-     *
2280
-     * @access protected
2281
-     * @return void
2282
-     * @throws EE_Error
2283
-     * @throws InvalidArgumentException
2284
-     * @throws InvalidDataTypeException
2285
-     * @throws InvalidInterfaceException
2286
-     */
2287
-    protected function _send_payment_reminder()
2288
-    {
2289
-        $TXN_ID      = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false;
2290
-        $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2291
-        $query_args  = isset($this->_req_data['redirect_to']) ? array(
2292
-            'action' => $this->_req_data['redirect_to'],
2293
-            'TXN_ID' => $this->_req_data['TXN_ID'],
2294
-        ) : array();
2295
-        do_action(
2296
-            'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
2297
-            $transaction
2298
-        );
2299
-        $this->_redirect_after_action(
2300
-            false,
2301
-            esc_html__('payment reminder', 'event_espresso'),
2302
-            esc_html__('sent', 'event_espresso'),
2303
-            $query_args,
2304
-            true
2305
-        );
2306
-    }
2307
-
2308
-
2309
-    /**
2310
-     *  get_transactions
2311
-     *    get transactions for given parameters (used by list table)
2312
-     *
2313
-     * @param  int     $perpage how many transactions displayed per page
2314
-     * @param  boolean $count   return the count or objects
2315
-     * @param string   $view
2316
-     * @return mixed int = count || array of transaction objects
2317
-     * @throws EE_Error
2318
-     * @throws InvalidArgumentException
2319
-     * @throws InvalidDataTypeException
2320
-     * @throws InvalidInterfaceException
2321
-     */
2322
-    public function get_transactions($perpage, $count = false, $view = '')
2323
-    {
2324
-
2325
-        $TXN = EEM_Transaction::instance();
2326
-
2327
-        $start_date = isset($this->_req_data['txn-filter-start-date'])
2328
-            ? wp_strip_all_tags($this->_req_data['txn-filter-start-date'])
2329
-            : date(
2330
-                'm/d/Y',
2331
-                strtotime('-10 year')
2332
-            );
2333
-        $end_date   = isset($this->_req_data['txn-filter-end-date'])
2334
-            ? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
2335
-            : date('m/d/Y');
2336
-
2337
-        //make sure our timestamps start and end right at the boundaries for each day
2338
-        $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2339
-        $end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2340
-
2341
-
2342
-        //convert to timestamps
2343
-        $start_date = strtotime($start_date);
2344
-        $end_date   = strtotime($end_date);
2345
-
2346
-        //makes sure start date is the lowest value and vice versa
2347
-        $start_date = min($start_date, $end_date);
2348
-        $end_date   = max($start_date, $end_date);
2349
-
2350
-        //convert to correct format for query
2351
-        $start_date = EEM_Transaction::instance()->convert_datetime_for_query(
2352
-            'TXN_timestamp',
2353
-            date('Y-m-d H:i:s', $start_date),
2354
-            'Y-m-d H:i:s'
2355
-        );
2356
-        $end_date   = EEM_Transaction::instance()->convert_datetime_for_query(
2357
-            'TXN_timestamp',
2358
-            date('Y-m-d H:i:s', $end_date),
2359
-            'Y-m-d H:i:s'
2360
-        );
2361
-
2362
-
2363
-        //set orderby
2364
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2365
-
2366
-        switch ($this->_req_data['orderby']) {
2367
-            case 'TXN_ID':
2368
-                $orderby = 'TXN_ID';
2369
-                break;
2370
-            case 'ATT_fname':
2371
-                $orderby = 'Registration.Attendee.ATT_fname';
2372
-                break;
2373
-            case 'event_name':
2374
-                $orderby = 'Registration.Event.EVT_name';
2375
-                break;
2376
-            default: //'TXN_timestamp'
2377
-                $orderby = 'TXN_timestamp';
2378
-        }
2379
-
2380
-        $sort         = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2381
-        $current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
2382
-        $per_page     = ! empty($perpage) ? $perpage : 10;
2383
-        $per_page     = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page;
2384
-
2385
-        $offset = ($current_page - 1) * $per_page;
2386
-        $limit  = array($offset, $per_page);
2387
-
2388
-        $_where = array(
2389
-            'TXN_timestamp'          => array('BETWEEN', array($start_date, $end_date)),
2390
-            'Registration.REG_count' => 1,
2391
-        );
2392
-
2393
-        if (isset($this->_req_data['EVT_ID'])) {
2394
-            $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID'];
2395
-        }
2396
-
2397
-        if (isset($this->_req_data['s'])) {
2398
-            $search_string = '%' . $this->_req_data['s'] . '%';
2399
-            $_where['OR']  = array(
2400
-                'Registration.Event.EVT_name'         => array('LIKE', $search_string),
2401
-                'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
2402
-                'Registration.Event.EVT_short_desc'   => array('LIKE', $search_string),
2403
-                'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string),
2404
-                'Registration.Attendee.ATT_fname'     => array('LIKE', $search_string),
2405
-                'Registration.Attendee.ATT_lname'     => array('LIKE', $search_string),
2406
-                'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string),
2407
-                'Registration.Attendee.ATT_email'     => array('LIKE', $search_string),
2408
-                'Registration.Attendee.ATT_address'   => array('LIKE', $search_string),
2409
-                'Registration.Attendee.ATT_address2'  => array('LIKE', $search_string),
2410
-                'Registration.Attendee.ATT_city'      => array('LIKE', $search_string),
2411
-                'Registration.REG_final_price'        => array('LIKE', $search_string),
2412
-                'Registration.REG_code'               => array('LIKE', $search_string),
2413
-                'Registration.REG_count'              => array('LIKE', $search_string),
2414
-                'Registration.REG_group_size'         => array('LIKE', $search_string),
2415
-                'Registration.Ticket.TKT_name'        => array('LIKE', $search_string),
2416
-                'Registration.Ticket.TKT_description' => array('LIKE', $search_string),
2417
-                'Payment.PAY_source'                  => array('LIKE', $search_string),
2418
-                'Payment.Payment_Method.PMD_name'     => array('LIKE', $search_string),
2419
-                'TXN_session_data'                    => array('LIKE', $search_string),
2420
-                'Payment.PAY_txn_id_chq_nmbr'         => array('LIKE', $search_string),
2421
-            );
2422
-        }
2423
-
2424
-        //failed transactions
2425
-        $failed    = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count)
2426
-                     || ($count && $view === 'failed');
2427
-        $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count)
2428
-                     || ($count && $view === 'abandoned');
2429
-
2430
-        if ($failed) {
2431
-            $_where['STS_ID'] = EEM_Transaction::failed_status_code;
2432
-        } else if ($abandoned) {
2433
-            $_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
2434
-        } else {
2435
-            $_where['STS_ID']  = array('!=', EEM_Transaction::failed_status_code);
2436
-            $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code);
2437
-        }
2438
-
2439
-        $query_params = array(
2440
-            $_where,
2441
-            'order_by'                 => array($orderby => $sort),
2442
-            'limit'                    => $limit,
2443
-            'default_where_conditions' => EEM_Base::default_where_conditions_this_only,
2444
-        );
2445
-
2446
-        $transactions = $count
2447
-            ? $TXN->count(array($_where), 'TXN_ID', true)
2448
-            : $TXN->get_all($query_params);
2449
-
2450
-        return $transactions;
2451
-    }
19
+	/**
20
+	 * @var EE_Transaction
21
+	 */
22
+	private $_transaction;
23
+
24
+	/**
25
+	 * @var EE_Session
26
+	 */
27
+	private $_session;
28
+
29
+	/**
30
+	 * @var array $_txn_status
31
+	 */
32
+	private static $_txn_status;
33
+
34
+	/**
35
+	 * @var array $_pay_status
36
+	 */
37
+	private static $_pay_status;
38
+
39
+	/**
40
+	 * @var array $_existing_reg_payment_REG_IDs
41
+	 */
42
+	protected $_existing_reg_payment_REG_IDs = null;
43
+
44
+
45
+	/**
46
+	 * @Constructor
47
+	 * @access public
48
+	 * @param bool $routing
49
+	 * @throws EE_Error
50
+	 * @throws InvalidArgumentException
51
+	 * @throws ReflectionException
52
+	 * @throws InvalidDataTypeException
53
+	 * @throws InvalidInterfaceException
54
+	 */
55
+	public function __construct($routing = true)
56
+	{
57
+		parent::__construct($routing);
58
+	}
59
+
60
+
61
+	/**
62
+	 *    _init_page_props
63
+	 *
64
+	 * @return void
65
+	 */
66
+	protected function _init_page_props()
67
+	{
68
+		$this->page_slug        = TXN_PG_SLUG;
69
+		$this->page_label       = esc_html__('Transactions', 'event_espresso');
70
+		$this->_admin_base_url  = TXN_ADMIN_URL;
71
+		$this->_admin_base_path = TXN_ADMIN;
72
+	}
73
+
74
+
75
+	/**
76
+	 *    _ajax_hooks
77
+	 *
78
+	 * @return void
79
+	 */
80
+	protected function _ajax_hooks()
81
+	{
82
+		add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds'));
83
+		add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds'));
84
+		add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment'));
85
+	}
86
+
87
+
88
+	/**
89
+	 *    _define_page_props
90
+	 *
91
+	 * @return void
92
+	 */
93
+	protected function _define_page_props()
94
+	{
95
+		$this->_admin_page_title = $this->page_label;
96
+		$this->_labels           = array(
97
+			'buttons' => array(
98
+				'add'    => esc_html__('Add New Transaction', 'event_espresso'),
99
+				'edit'   => esc_html__('Edit Transaction', 'event_espresso'),
100
+				'delete' => esc_html__('Delete Transaction', 'event_espresso'),
101
+			),
102
+		);
103
+	}
104
+
105
+
106
+	/**
107
+	 *        grab url requests and route them
108
+	 *
109
+	 * @access private
110
+	 * @return void
111
+	 * @throws EE_Error
112
+	 * @throws InvalidArgumentException
113
+	 * @throws InvalidDataTypeException
114
+	 * @throws InvalidInterfaceException
115
+	 */
116
+	public function _set_page_routes()
117
+	{
118
+
119
+		$this->_set_transaction_status_array();
120
+
121
+		$txn_id = ! empty($this->_req_data['TXN_ID'])
122
+				  && ! is_array($this->_req_data['TXN_ID'])
123
+			? $this->_req_data['TXN_ID']
124
+			: 0;
125
+
126
+		$this->_page_routes = array(
127
+
128
+			'default' => array(
129
+				'func'       => '_transactions_overview_list_table',
130
+				'capability' => 'ee_read_transactions',
131
+			),
132
+
133
+			'view_transaction' => array(
134
+				'func'       => '_transaction_details',
135
+				'capability' => 'ee_read_transaction',
136
+				'obj_id'     => $txn_id,
137
+			),
138
+
139
+			'send_payment_reminder' => array(
140
+				'func'       => '_send_payment_reminder',
141
+				'noheader'   => true,
142
+				'capability' => 'ee_send_message',
143
+			),
144
+
145
+			'espresso_apply_payment' => array(
146
+				'func'       => 'apply_payments_or_refunds',
147
+				'noheader'   => true,
148
+				'capability' => 'ee_edit_payments',
149
+			),
150
+
151
+			'espresso_apply_refund' => array(
152
+				'func'       => 'apply_payments_or_refunds',
153
+				'noheader'   => true,
154
+				'capability' => 'ee_edit_payments',
155
+			),
156
+
157
+			'espresso_delete_payment' => array(
158
+				'func'       => 'delete_payment',
159
+				'noheader'   => true,
160
+				'capability' => 'ee_delete_payments',
161
+			),
162
+
163
+		);
164
+	}
165
+
166
+
167
+	protected function _set_page_config()
168
+	{
169
+		$this->_page_config = array(
170
+			'default'          => array(
171
+				'nav'           => array(
172
+					'label' => esc_html__('Overview', 'event_espresso'),
173
+					'order' => 10,
174
+				),
175
+				'list_table'    => 'EE_Admin_Transactions_List_Table',
176
+				'help_tabs'     => array(
177
+					'transactions_overview_help_tab'                       => array(
178
+						'title'    => esc_html__('Transactions Overview', 'event_espresso'),
179
+						'filename' => 'transactions_overview',
180
+					),
181
+					'transactions_overview_table_column_headings_help_tab' => array(
182
+						'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'),
183
+						'filename' => 'transactions_overview_table_column_headings',
184
+					),
185
+					'transactions_overview_views_filters_help_tab'         => array(
186
+						'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'),
187
+						'filename' => 'transactions_overview_views_filters_search',
188
+					),
189
+				),
190
+				'help_tour'     => array('Transactions_Overview_Help_Tour'),
191
+				/**
192
+				 * commented out because currently we are not displaying tips for transaction list table status but this
193
+				 * may change in a later iteration so want to keep the code for then.
194
+				 */
195
+				//'qtips' => array( 'Transactions_List_Table_Tips' ),
196
+				'require_nonce' => false,
197
+			),
198
+			'view_transaction' => array(
199
+				'nav'       => array(
200
+					'label'      => esc_html__('View Transaction', 'event_espresso'),
201
+					'order'      => 5,
202
+					'url'        => isset($this->_req_data['TXN_ID'])
203
+						? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url)
204
+						: $this->_admin_base_url,
205
+					'persistent' => false,
206
+				),
207
+				'help_tabs' => array(
208
+					'transactions_view_transaction_help_tab'                                              => array(
209
+						'title'    => esc_html__('View Transaction', 'event_espresso'),
210
+						'filename' => 'transactions_view_transaction',
211
+					),
212
+					'transactions_view_transaction_transaction_details_table_help_tab'                    => array(
213
+						'title'    => esc_html__('Transaction Details Table', 'event_espresso'),
214
+						'filename' => 'transactions_view_transaction_transaction_details_table',
215
+					),
216
+					'transactions_view_transaction_attendees_registered_help_tab'                         => array(
217
+						'title'    => esc_html__('Attendees Registered', 'event_espresso'),
218
+						'filename' => 'transactions_view_transaction_attendees_registered',
219
+					),
220
+					'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array(
221
+						'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'),
222
+						'filename' => 'transactions_view_transaction_primary_registrant_billing_information',
223
+					),
224
+				),
225
+				'qtips'     => array('Transaction_Details_Tips'),
226
+				'help_tour' => array('Transaction_Details_Help_Tour'),
227
+				'metaboxes' => array('_transaction_details_metaboxes'),
228
+
229
+				'require_nonce' => false,
230
+			),
231
+		);
232
+	}
233
+
234
+
235
+	/**
236
+	 * The below methods aren't used by this class currently
237
+	 */
238
+	protected function _add_screen_options()
239
+	{
240
+		//noop
241
+	}
242
+
243
+	protected function _add_feature_pointers()
244
+	{
245
+		//noop
246
+	}
247
+
248
+	public function admin_init()
249
+	{
250
+		// IF a registration was JUST added via the admin...
251
+		if (isset(
252
+			$this->_req_data['redirect_from'],
253
+			$this->_req_data['EVT_ID'],
254
+			$this->_req_data['event_name']
255
+		)) {
256
+			// then set a cookie so that we can block any attempts to use
257
+			// the back button as a way to enter another registration.
258
+			setcookie(
259
+				'ee_registration_added',
260
+				$this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/'
261
+			);
262
+			// and update the global
263
+			$_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID'];
264
+		}
265
+		EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__(
266
+			'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
267
+			'event_espresso'
268
+		);
269
+		EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__(
270
+			'An error occurred! Please refresh the page and try again.',
271
+			'event_espresso'
272
+		);
273
+		EE_Registry::$i18n_js_strings['txn_status_array']        = self::$_txn_status;
274
+		EE_Registry::$i18n_js_strings['pay_status_array']        = self::$_pay_status;
275
+		EE_Registry::$i18n_js_strings['payments_total']          = esc_html__('Payments Total', 'event_espresso');
276
+		EE_Registry::$i18n_js_strings['transaction_overpaid']    = esc_html__(
277
+			'This transaction has been overpaid ! Payments Total',
278
+			'event_espresso'
279
+		);
280
+	}
281
+
282
+	public function admin_notices()
283
+	{
284
+		//noop
285
+	}
286
+
287
+	public function admin_footer_scripts()
288
+	{
289
+		//noop
290
+	}
291
+
292
+
293
+	/**
294
+	 * _set_transaction_status_array
295
+	 * sets list of transaction statuses
296
+	 *
297
+	 * @access private
298
+	 * @return void
299
+	 * @throws EE_Error
300
+	 * @throws InvalidArgumentException
301
+	 * @throws InvalidDataTypeException
302
+	 * @throws InvalidInterfaceException
303
+	 */
304
+	private function _set_transaction_status_array()
305
+	{
306
+		self::$_txn_status = EEM_Transaction::instance()->status_array(true);
307
+	}
308
+
309
+
310
+	/**
311
+	 * get_transaction_status_array
312
+	 * return the transaction status array for wp_list_table
313
+	 *
314
+	 * @access public
315
+	 * @return array
316
+	 */
317
+	public function get_transaction_status_array()
318
+	{
319
+		return self::$_txn_status;
320
+	}
321
+
322
+
323
+	/**
324
+	 *    get list of payment statuses
325
+	 *
326
+	 * @access private
327
+	 * @return void
328
+	 * @throws EE_Error
329
+	 * @throws InvalidArgumentException
330
+	 * @throws InvalidDataTypeException
331
+	 * @throws InvalidInterfaceException
332
+	 */
333
+	private function _get_payment_status_array()
334
+	{
335
+		self::$_pay_status                      = EEM_Payment::instance()->status_array(true);
336
+		$this->_template_args['payment_status'] = self::$_pay_status;
337
+
338
+	}
339
+
340
+
341
+	/**
342
+	 *    _add_screen_options_default
343
+	 *
344
+	 * @access protected
345
+	 * @return void
346
+	 * @throws InvalidArgumentException
347
+	 * @throws InvalidDataTypeException
348
+	 * @throws InvalidInterfaceException
349
+	 */
350
+	protected function _add_screen_options_default()
351
+	{
352
+		$this->_per_page_screen_option();
353
+	}
354
+
355
+
356
+	/**
357
+	 * load_scripts_styles
358
+	 *
359
+	 * @access public
360
+	 * @return void
361
+	 */
362
+	public function load_scripts_styles()
363
+	{
364
+		//enqueue style
365
+		wp_register_style(
366
+			'espresso_txn',
367
+			TXN_ASSETS_URL . 'espresso_transactions_admin.css',
368
+			array(),
369
+			EVENT_ESPRESSO_VERSION
370
+		);
371
+		wp_enqueue_style('espresso_txn');
372
+		//scripts
373
+		wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array(
374
+			'ee_admin_js',
375
+			'ee-datepicker',
376
+			'jquery-ui-datepicker',
377
+			'jquery-ui-draggable',
378
+			'ee-dialog',
379
+			'ee-accounting',
380
+			'ee-serialize-full-array',
381
+		), EVENT_ESPRESSO_VERSION, true);
382
+		wp_enqueue_script('espresso_txn');
383
+	}
384
+
385
+
386
+	/**
387
+	 *    load_scripts_styles_view_transaction
388
+	 *
389
+	 * @access public
390
+	 * @return void
391
+	 */
392
+	public function load_scripts_styles_view_transaction()
393
+	{
394
+		//styles
395
+		wp_enqueue_style('espresso-ui-theme');
396
+	}
397
+
398
+
399
+	/**
400
+	 *    load_scripts_styles_default
401
+	 *
402
+	 * @access public
403
+	 * @return void
404
+	 */
405
+	public function load_scripts_styles_default()
406
+	{
407
+		//styles
408
+		wp_enqueue_style('espresso-ui-theme');
409
+	}
410
+
411
+
412
+	/**
413
+	 *    _set_list_table_views_default
414
+	 *
415
+	 * @access protected
416
+	 * @return void
417
+	 */
418
+	protected function _set_list_table_views_default()
419
+	{
420
+		$this->_views = array(
421
+			'all'       => array(
422
+				'slug'  => 'all',
423
+				'label' => esc_html__('View All Transactions', 'event_espresso'),
424
+				'count' => 0,
425
+			),
426
+			'abandoned' => array(
427
+				'slug'  => 'abandoned',
428
+				'label' => esc_html__('Abandoned Transactions', 'event_espresso'),
429
+				'count' => 0,
430
+			),
431
+			'failed'    => array(
432
+				'slug'  => 'failed',
433
+				'label' => esc_html__('Failed Transactions', 'event_espresso'),
434
+				'count' => 0,
435
+			),
436
+		);
437
+	}
438
+
439
+
440
+	/**
441
+	 * _set_transaction_object
442
+	 * This sets the _transaction property for the transaction details screen
443
+	 *
444
+	 * @access private
445
+	 * @return void
446
+	 * @throws EE_Error
447
+	 * @throws InvalidArgumentException
448
+	 * @throws RuntimeException
449
+	 * @throws InvalidDataTypeException
450
+	 * @throws InvalidInterfaceException
451
+	 * @throws ReflectionException
452
+	 */
453
+	private function _set_transaction_object()
454
+	{
455
+		if ($this->_transaction instanceof EE_Transaction) {
456
+			return;
457
+		} //get out we've already set the object
458
+
459
+		$TXN_ID = ! empty($this->_req_data['TXN_ID'])
460
+			? absint($this->_req_data['TXN_ID'])
461
+			: false;
462
+
463
+		//get transaction object
464
+		$this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
465
+		$this->_session     = $this->_transaction instanceof EE_Transaction
466
+			? $this->_transaction->get('TXN_session_data')
467
+			: null;
468
+		$this->_transaction->verify_abandoned_transaction_status();
469
+
470
+		if (! $this->_transaction instanceof EE_Transaction) {
471
+			$error_msg = sprintf(
472
+				esc_html__(
473
+					'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
474
+					'event_espresso'
475
+				),
476
+				$TXN_ID
477
+			);
478
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
479
+		}
480
+	}
481
+
482
+
483
+	/**
484
+	 *    _transaction_legend_items
485
+	 *
486
+	 * @access protected
487
+	 * @return array
488
+	 * @throws EE_Error
489
+	 * @throws InvalidArgumentException
490
+	 * @throws ReflectionException
491
+	 * @throws InvalidDataTypeException
492
+	 * @throws InvalidInterfaceException
493
+	 */
494
+	protected function _transaction_legend_items()
495
+	{
496
+		EE_Registry::instance()->load_helper('MSG_Template');
497
+		$items = array();
498
+
499
+		if (EE_Registry::instance()->CAP->current_user_can(
500
+			'ee_read_global_messages',
501
+			'view_filtered_messages'
502
+		)) {
503
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
504
+			if (is_array($related_for_icon)
505
+				&& isset($related_for_icon['css_class'], $related_for_icon['label'])
506
+			) {
507
+				$items['view_related_messages'] = array(
508
+					'class' => $related_for_icon['css_class'],
509
+					'desc'  => $related_for_icon['label'],
510
+				);
511
+			}
512
+		}
513
+
514
+		$items = apply_filters(
515
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
516
+			array_merge(
517
+				$items,
518
+				array(
519
+					'view_details'          => array(
520
+						'class' => 'dashicons dashicons-cart',
521
+						'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
522
+					),
523
+					'view_invoice'          => array(
524
+						'class' => 'dashicons dashicons-media-spreadsheet',
525
+						'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
526
+					),
527
+					'view_receipt'          => array(
528
+						'class' => 'dashicons dashicons-media-default',
529
+						'desc'  => esc_html__('View Transaction Receipt', 'event_espresso'),
530
+					),
531
+					'view_registration'     => array(
532
+						'class' => 'dashicons dashicons-clipboard',
533
+						'desc'  => esc_html__('View Registration Details', 'event_espresso'),
534
+					),
535
+					'payment_overview_link' => array(
536
+						'class' => 'dashicons dashicons-money',
537
+						'desc'  => esc_html__('Make Payment on Frontend', 'event_espresso'),
538
+					),
539
+				)
540
+			)
541
+		);
542
+
543
+		if (EE_Registry::instance()->CAP->current_user_can(
544
+			'ee_send_message',
545
+			'espresso_transactions_send_payment_reminder'
546
+		)) {
547
+			if (EEH_MSG_Template::is_mt_active('payment_reminder')) {
548
+				$items['send_payment_reminder'] = array(
549
+					'class' => 'dashicons dashicons-email-alt',
550
+					'desc'  => esc_html__('Send Payment Reminder', 'event_espresso'),
551
+				);
552
+			} else {
553
+				$items['blank*'] = array(
554
+					'class' => '',
555
+					'desc'  => '',
556
+				);
557
+			}
558
+		} else {
559
+			$items['blank*'] = array(
560
+				'class' => '',
561
+				'desc'  => '',
562
+			);
563
+		}
564
+		$more_items = apply_filters(
565
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
566
+			array(
567
+				'overpaid'   => array(
568
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
569
+					'desc'  => EEH_Template::pretty_status(
570
+						EEM_Transaction::overpaid_status_code,
571
+						false,
572
+						'sentence'
573
+					),
574
+				),
575
+				'complete'   => array(
576
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
577
+					'desc'  => EEH_Template::pretty_status(
578
+						EEM_Transaction::complete_status_code,
579
+						false,
580
+						'sentence'
581
+					),
582
+				),
583
+				'incomplete' => array(
584
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
585
+					'desc'  => EEH_Template::pretty_status(
586
+						EEM_Transaction::incomplete_status_code,
587
+						false,
588
+						'sentence'
589
+					),
590
+				),
591
+				'abandoned'  => array(
592
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
593
+					'desc'  => EEH_Template::pretty_status(
594
+						EEM_Transaction::abandoned_status_code,
595
+						false,
596
+						'sentence'
597
+					),
598
+				),
599
+				'failed'     => array(
600
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
601
+					'desc'  => EEH_Template::pretty_status(
602
+						EEM_Transaction::failed_status_code,
603
+						false,
604
+						'sentence'
605
+					),
606
+				),
607
+			)
608
+		);
609
+
610
+		return array_merge($items, $more_items);
611
+	}
612
+
613
+
614
+	/**
615
+	 *    _transactions_overview_list_table
616
+	 *
617
+	 * @access protected
618
+	 * @return void
619
+	 * @throws DomainException
620
+	 * @throws EE_Error
621
+	 * @throws InvalidArgumentException
622
+	 * @throws InvalidDataTypeException
623
+	 * @throws InvalidInterfaceException
624
+	 * @throws ReflectionException
625
+	 */
626
+	protected function _transactions_overview_list_table()
627
+	{
628
+		$this->_admin_page_title = esc_html__('Transactions', 'event_espresso');
629
+		$event = isset($this->_req_data['EVT_ID'])
630
+			? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID'])
631
+			: null;
632
+		$this->_template_args['admin_page_header'] = $event instanceof EE_Event
633
+			? sprintf(
634
+				esc_html__(
635
+					'%sViewing Transactions for the Event: %s%s',
636
+					'event_espresso'
637
+				),
638
+				'<h3>',
639
+				'<a href="'
640
+				. EE_Admin_Page::add_query_args_and_nonce(
641
+					array('action' => 'edit', 'post' => $event->ID()),
642
+					EVENTS_ADMIN_URL
643
+				)
644
+				. '" title="'
645
+				. esc_attr__(
646
+					'Click to Edit event',
647
+					'event_espresso'
648
+				)
649
+				. '">' . $event->get('EVT_name') . '</a>',
650
+				'</h3>'
651
+			)
652
+			: '';
653
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
654
+		$this->display_admin_list_table_page_with_no_sidebar();
655
+	}
656
+
657
+
658
+	/**
659
+	 *    _transaction_details
660
+	 * generates HTML for the View Transaction Details Admin page
661
+	 *
662
+	 * @access protected
663
+	 * @return void
664
+	 * @throws DomainException
665
+	 * @throws EE_Error
666
+	 * @throws InvalidArgumentException
667
+	 * @throws InvalidDataTypeException
668
+	 * @throws InvalidInterfaceException
669
+	 * @throws RuntimeException
670
+	 * @throws ReflectionException
671
+	 */
672
+	protected function _transaction_details()
673
+	{
674
+		do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
675
+
676
+		$this->_set_transaction_status_array();
677
+
678
+		$this->_template_args                      = array();
679
+		$this->_template_args['transactions_page'] = $this->_wp_page_slug;
680
+
681
+		$this->_set_transaction_object();
682
+
683
+		$primary_registration = $this->_transaction->primary_registration();
684
+		$attendee = $primary_registration instanceof EE_Registration
685
+			? $primary_registration->attendee()
686
+			: null;
687
+
688
+		$this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
689
+		$this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
690
+
691
+		$this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
692
+		$this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
693
+
694
+		$this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')];
695
+		$this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
696
+		$this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
697
+
698
+		$this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
699
+		$this->_template_args['total_paid']  = $this->_transaction->get('TXN_paid');
700
+
701
+		$amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid');
702
+		$this->_template_args['amount_due'] = EEH_Template::format_currency(
703
+			$amount_due,
704
+			true
705
+		);
706
+		if (EE_Registry::instance()->CFG->currency->sign_b4) {
707
+			$this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign
708
+												  . $this->_template_args['amount_due'];
709
+		} else {
710
+			$this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign;
711
+		}
712
+		$this->_template_args['amount_due_class'] = '';
713
+
714
+		if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) {
715
+			// paid in full
716
+			$this->_template_args['amount_due'] = false;
717
+		} elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) {
718
+			// overpaid
719
+			$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
720
+		} elseif ($this->_transaction->get('TXN_total') > 0
721
+				  && $this->_transaction->get('TXN_paid') > 0
722
+		) {
723
+			// monies owing
724
+			$this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
725
+		} elseif ($this->_transaction->get('TXN_total') > 0
726
+				  && $this->_transaction->get('TXN_paid') == 0
727
+		) {
728
+			// no payments made yet
729
+			$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
730
+		} elseif ($this->_transaction->get('TXN_total') == 0) {
731
+			// free event
732
+			$this->_template_args['amount_due'] = false;
733
+		}
734
+
735
+		$payment_method = $this->_transaction->payment_method();
736
+
737
+		$this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
738
+			? $payment_method->admin_name()
739
+			: esc_html__('Unknown', 'event_espresso');
740
+
741
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
742
+		// link back to overview
743
+		$this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER'])
744
+			? $_SERVER['HTTP_REFERER']
745
+			: TXN_ADMIN_URL;
746
+
747
+
748
+		// next link
749
+		$next_txn                                 = $this->_transaction->next(
750
+			null,
751
+			array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
752
+			'TXN_ID'
753
+		);
754
+		$this->_template_args['next_transaction'] = $next_txn
755
+			? $this->_next_link(
756
+				EE_Admin_Page::add_query_args_and_nonce(
757
+					array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']),
758
+					TXN_ADMIN_URL
759
+				),
760
+				'dashicons dashicons-arrow-right ee-icon-size-22'
761
+			)
762
+			: '';
763
+		// previous link
764
+		$previous_txn                                 = $this->_transaction->previous(
765
+			null,
766
+			array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
767
+			'TXN_ID'
768
+		);
769
+		$this->_template_args['previous_transaction'] = $previous_txn
770
+			? $this->_previous_link(
771
+				EE_Admin_Page::add_query_args_and_nonce(
772
+					array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']),
773
+					TXN_ADMIN_URL
774
+				),
775
+				'dashicons dashicons-arrow-left ee-icon-size-22'
776
+			)
777
+			: '';
778
+
779
+		// were we just redirected here after adding a new registration ???
780
+		if (isset(
781
+			$this->_req_data['redirect_from'],
782
+			$this->_req_data['EVT_ID'],
783
+			$this->_req_data['event_name']
784
+		)) {
785
+			if (EE_Registry::instance()->CAP->current_user_can(
786
+				'ee_edit_registrations',
787
+				'espresso_registrations_new_registration',
788
+				$this->_req_data['EVT_ID']
789
+			)) {
790
+				$this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
791
+				$this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
792
+					array(
793
+						'page'     => 'espresso_registrations',
794
+						'action'   => 'new_registration',
795
+						'return'   => 'default',
796
+						'TXN_ID'   => $this->_transaction->ID(),
797
+						'event_id' => $this->_req_data['EVT_ID'],
798
+					),
799
+					REG_ADMIN_URL
800
+				);
801
+				$this->_admin_page_title .= '">';
802
+
803
+				$this->_admin_page_title .= sprintf(
804
+					esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
805
+					htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8')
806
+				);
807
+				$this->_admin_page_title .= '</a>';
808
+			}
809
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
810
+		}
811
+		// grab messages at the last second
812
+		$this->_template_args['notices'] = EE_Error::get_notices();
813
+		// path to template
814
+		$template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
815
+		$this->_template_args['admin_page_header'] = EEH_Template::display_template(
816
+			$template_path,
817
+			$this->_template_args,
818
+			true
819
+		);
820
+
821
+		// the details template wrapper
822
+		$this->display_admin_page_with_sidebar();
823
+
824
+	}
825
+
826
+
827
+	/**
828
+	 *        _transaction_details_metaboxes
829
+	 *
830
+	 * @access protected
831
+	 * @return void
832
+	 * @throws EE_Error
833
+	 * @throws InvalidArgumentException
834
+	 * @throws InvalidDataTypeException
835
+	 * @throws InvalidInterfaceException
836
+	 * @throws RuntimeException
837
+	 * @throws ReflectionException
838
+	 */
839
+	protected function _transaction_details_metaboxes()
840
+	{
841
+
842
+		$this->_set_transaction_object();
843
+
844
+		add_meta_box(
845
+			'edit-txn-details-mbox',
846
+			esc_html__('Transaction Details', 'event_espresso'),
847
+			array($this, 'txn_details_meta_box'),
848
+			$this->_wp_page_slug,
849
+			'normal',
850
+			'high'
851
+		);
852
+		add_meta_box(
853
+			'edit-txn-attendees-mbox',
854
+			esc_html__('Attendees Registered in this Transaction', 'event_espresso'),
855
+			array($this, 'txn_attendees_meta_box'),
856
+			$this->_wp_page_slug,
857
+			'normal',
858
+			'high',
859
+			array('TXN_ID' => $this->_transaction->ID())
860
+		);
861
+		add_meta_box(
862
+			'edit-txn-registrant-mbox',
863
+			esc_html__('Primary Contact', 'event_espresso'),
864
+			array($this, 'txn_registrant_side_meta_box'),
865
+			$this->_wp_page_slug,
866
+			'side',
867
+			'high'
868
+		);
869
+		add_meta_box(
870
+			'edit-txn-billing-info-mbox',
871
+			esc_html__('Billing Information', 'event_espresso'),
872
+			array($this, 'txn_billing_info_side_meta_box'),
873
+			$this->_wp_page_slug,
874
+			'side',
875
+			'high'
876
+		);
877
+	}
878
+
879
+
880
+	/**
881
+	 * Callback for transaction actions metabox.
882
+	 *
883
+	 * @param EE_Transaction|null $transaction
884
+	 * @throws DomainException
885
+	 * @throws EE_Error
886
+	 * @throws InvalidArgumentException
887
+	 * @throws InvalidDataTypeException
888
+	 * @throws InvalidInterfaceException
889
+	 * @throws ReflectionException
890
+	 * @throws RuntimeException
891
+	 */
892
+	public function getActionButtons(EE_Transaction $transaction = null)
893
+	{
894
+		$content = '';
895
+		$actions = array();
896
+		if (! $transaction instanceof EE_Transaction) {
897
+			return $content;
898
+		}
899
+		/** @var EE_Registration $primary_registration */
900
+		$primary_registration = $transaction->primary_registration();
901
+		$attendee = $primary_registration instanceof EE_Registration
902
+			? $primary_registration->attendee()
903
+			: null;
904
+
905
+		if ($attendee instanceof EE_Attendee
906
+			&& EE_Registry::instance()->CAP->current_user_can(
907
+				'ee_send_message',
908
+				'espresso_transactions_send_payment_reminder'
909
+			)
910
+		) {
911
+			$actions['payment_reminder'] =
912
+				EEH_MSG_Template::is_mt_active('payment_reminder')
913
+				&& $this->_transaction->get('STS_ID') !== EEM_Transaction::complete_status_code
914
+				&& $this->_transaction->get('STS_ID') !== EEM_Transaction::overpaid_status_code
915
+					? EEH_Template::get_button_or_link(
916
+						EE_Admin_Page::add_query_args_and_nonce(
917
+							array(
918
+								'action'      => 'send_payment_reminder',
919
+								'TXN_ID'      => $this->_transaction->ID(),
920
+								'redirect_to' => 'view_transaction',
921
+							),
922
+							TXN_ADMIN_URL
923
+						),
924
+						esc_html__(' Send Payment Reminder', 'event_espresso'),
925
+						'button secondary-button',
926
+						'dashicons dashicons-email-alt'
927
+					)
928
+					: '';
929
+		}
930
+
931
+		if ($primary_registration instanceof EE_Registration
932
+			&& EEH_MSG_Template::is_mt_active('receipt')
933
+		) {
934
+			$actions['receipt'] = EEH_Template::get_button_or_link(
935
+				$primary_registration->receipt_url(),
936
+				esc_html__('View Receipt', 'event_espresso'),
937
+				'button secondary-button',
938
+				'dashicons dashicons-media-default'
939
+			);
940
+		}
941
+
942
+		if ($primary_registration instanceof EE_Registration
943
+			&& EEH_MSG_Template::is_mt_active('invoice')
944
+		) {
945
+			$actions['invoice'] = EEH_Template::get_button_or_link(
946
+				$primary_registration->invoice_url(),
947
+				esc_html__('View Invoice', 'event_espresso'),
948
+				'button secondary-button',
949
+				'dashicons dashicons-media-spreadsheet'
950
+			);
951
+		}
952
+		$actions = array_filter(
953
+			apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction)
954
+		);
955
+		if ($actions) {
956
+			$content = '<ul>';
957
+			$content .= '<li>' . implode('</li><li>', $actions) . '</li>';
958
+			$content .= '</uL>';
959
+		}
960
+		return $content;
961
+	}
962
+
963
+
964
+	/**
965
+	 * txn_details_meta_box
966
+	 * generates HTML for the Transaction main meta box
967
+	 *
968
+	 * @return void
969
+	 * @throws DomainException
970
+	 * @throws EE_Error
971
+	 * @throws InvalidArgumentException
972
+	 * @throws InvalidDataTypeException
973
+	 * @throws InvalidInterfaceException
974
+	 * @throws RuntimeException
975
+	 * @throws ReflectionException
976
+	 */
977
+	public function txn_details_meta_box()
978
+	{
979
+		$this->_set_transaction_object();
980
+		$this->_template_args['TXN_ID']   = $this->_transaction->ID();
981
+		$this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration
982
+			? $this->_transaction->primary_registration()->attendee()
983
+			: null;
984
+		$this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can(
985
+			'ee_edit_payments',
986
+			'apply_payment_or_refund_from_registration_details'
987
+		);
988
+		$this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can(
989
+			'ee_delete_payments',
990
+			'delete_payment_from_registration_details'
991
+		);
992
+
993
+		//get line table
994
+		EEH_Autoloader::register_line_item_display_autoloaders();
995
+		$Line_Item_Display                       = new EE_Line_Item_Display(
996
+			'admin_table',
997
+			'EE_Admin_Table_Line_Item_Display_Strategy'
998
+		);
999
+		$this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item(
1000
+			$this->_transaction->total_line_item()
1001
+		);
1002
+		$this->_template_args['REG_code']        = $this->_transaction->get_first_related('Registration')
1003
+																	  ->get('REG_code');
1004
+
1005
+		// process taxes
1006
+		$taxes                         = $this->_transaction->get_many_related(
1007
+			'Line_Item',
1008
+			array(array('LIN_type' => EEM_Line_Item::type_tax))
1009
+		);
1010
+		$this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
1011
+
1012
+		$this->_template_args['grand_total']     = EEH_Template::format_currency(
1013
+			$this->_transaction->get('TXN_total'),
1014
+			false,
1015
+			false
1016
+		);
1017
+		$this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total');
1018
+		$this->_template_args['TXN_status']      = $this->_transaction->get('STS_ID');
1019
+
1020
+		// process payment details
1021
+		$payments = $this->_transaction->get_many_related('Payment');
1022
+		if (! empty($payments)) {
1023
+			$this->_template_args['payments']              = $payments;
1024
+			$this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
1025
+		} else {
1026
+			$this->_template_args['payments']              = false;
1027
+			$this->_template_args['existing_reg_payments'] = array();
1028
+		}
1029
+
1030
+		$this->_template_args['edit_payment_url']   = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL);
1031
+		$this->_template_args['delete_payment_url'] = add_query_arg(
1032
+			array('action' => 'espresso_delete_payment'),
1033
+			TXN_ADMIN_URL
1034
+		);
1035
+
1036
+		if (isset($txn_details['invoice_number'])) {
1037
+			$this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code'];
1038
+			$this->_template_args['txn_details']['invoice_number']['label'] = esc_html__(
1039
+				'Invoice Number',
1040
+				'event_espresso'
1041
+			);
1042
+		}
1043
+
1044
+		$this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction
1045
+			->get_first_related('Registration')
1046
+			->get('REG_session');
1047
+		$this->_template_args['txn_details']['registration_session']['label'] = esc_html__(
1048
+			'Registration Session',
1049
+			'event_espresso'
1050
+		);
1051
+
1052
+		$this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address'])
1053
+			? $this->_session['ip_address']
1054
+			: '';
1055
+		$this->_template_args['txn_details']['ip_address']['label'] = esc_html__(
1056
+			'Transaction placed from IP',
1057
+			'event_espresso'
1058
+		);
1059
+
1060
+		$this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent'])
1061
+			? $this->_session['user_agent']
1062
+			: '';
1063
+		$this->_template_args['txn_details']['user_agent']['label'] = esc_html__(
1064
+			'Registrant User Agent',
1065
+			'event_espresso'
1066
+		);
1067
+
1068
+		$reg_steps = '<ul>';
1069
+		foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
1070
+			if ($reg_step_status === true) {
1071
+				$reg_steps .= '<li style="color:#70cc50">'
1072
+							  . sprintf(
1073
+								  esc_html__('%1$s : Completed', 'event_espresso'),
1074
+								  ucwords(str_replace('_', ' ', $reg_step))
1075
+							  )
1076
+							  . '</li>';
1077
+			} elseif (is_numeric($reg_step_status) && $reg_step_status !== false) {
1078
+				$reg_steps .= '<li style="color:#2EA2CC">'
1079
+							  . sprintf(
1080
+								  esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1081
+								  ucwords(str_replace('_', ' ', $reg_step)),
1082
+								  date(
1083
+									  get_option('date_format') . ' ' . get_option('time_format'),
1084
+									  ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))
1085
+								  )
1086
+							  )
1087
+							  . '</li>';
1088
+			} else {
1089
+				$reg_steps .= '<li style="color:#E76700">'
1090
+							  . sprintf(
1091
+								  esc_html__('%1$s : Never Initiated', 'event_espresso'),
1092
+								  ucwords(str_replace('_', ' ', $reg_step))
1093
+							  )
1094
+							  . '</li>';
1095
+			}
1096
+		}
1097
+		$reg_steps                                                 .= '</ul>';
1098
+		$this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
1099
+		$this->_template_args['txn_details']['reg_steps']['label'] = esc_html__(
1100
+			'Registration Step Progress',
1101
+			'event_espresso'
1102
+		);
1103
+
1104
+
1105
+		$this->_get_registrations_to_apply_payment_to();
1106
+		$this->_get_payment_methods($payments);
1107
+		$this->_get_payment_status_array();
1108
+		$this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction.
1109
+
1110
+		$this->_template_args['transaction_form_url']    = add_query_arg(array(
1111
+			'action'  => 'edit_transaction',
1112
+			'process' => 'transaction',
1113
+		), TXN_ADMIN_URL);
1114
+		$this->_template_args['apply_payment_form_url']  = add_query_arg(array(
1115
+			'page'   => 'espresso_transactions',
1116
+			'action' => 'espresso_apply_payment',
1117
+		), WP_AJAX_URL);
1118
+		$this->_template_args['delete_payment_form_url'] = add_query_arg(array(
1119
+			'page'   => 'espresso_transactions',
1120
+			'action' => 'espresso_delete_payment',
1121
+		), WP_AJAX_URL);
1122
+
1123
+		$this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction);
1124
+
1125
+		// 'espresso_delete_payment_nonce'
1126
+
1127
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1128
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
1129
+	}
1130
+
1131
+
1132
+	/**
1133
+	 * _get_registration_payment_IDs
1134
+	 *    generates an array of Payment IDs and their corresponding Registration IDs
1135
+	 *
1136
+	 * @access protected
1137
+	 * @param EE_Payment[] $payments
1138
+	 * @return array
1139
+	 * @throws EE_Error
1140
+	 * @throws InvalidArgumentException
1141
+	 * @throws InvalidDataTypeException
1142
+	 * @throws InvalidInterfaceException
1143
+	 * @throws ReflectionException
1144
+	 */
1145
+	protected function _get_registration_payment_IDs($payments = array())
1146
+	{
1147
+		$existing_reg_payments = array();
1148
+		// get all reg payments for these payments
1149
+		$reg_payments = EEM_Registration_Payment::instance()->get_all(array(
1150
+			array(
1151
+				'PAY_ID' => array(
1152
+					'IN',
1153
+					array_keys($payments),
1154
+				),
1155
+			),
1156
+		));
1157
+		if (! empty($reg_payments)) {
1158
+			foreach ($payments as $payment) {
1159
+				if (! $payment instanceof EE_Payment) {
1160
+					continue;
1161
+				} elseif (! isset($existing_reg_payments[$payment->ID()])) {
1162
+					$existing_reg_payments[$payment->ID()] = array();
1163
+				}
1164
+				foreach ($reg_payments as $reg_payment) {
1165
+					if ($reg_payment instanceof EE_Registration_Payment
1166
+						&& $reg_payment->payment_ID() === $payment->ID()
1167
+					) {
1168
+						$existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID();
1169
+					}
1170
+				}
1171
+			}
1172
+		}
1173
+
1174
+		return $existing_reg_payments;
1175
+	}
1176
+
1177
+
1178
+	/**
1179
+	 * _get_registrations_to_apply_payment_to
1180
+	 *    generates HTML for displaying a series of checkboxes in the admin payment modal window
1181
+	 * which allows the admin to only apply the payment to the specific registrations
1182
+	 *
1183
+	 * @access protected
1184
+	 * @return void
1185
+	 * @throws \EE_Error
1186
+	 */
1187
+	protected function _get_registrations_to_apply_payment_to()
1188
+	{
1189
+		// we want any registration with an active status (ie: not deleted or cancelled)
1190
+		$query_params                      = array(
1191
+			array(
1192
+				'STS_ID' => array(
1193
+					'IN',
1194
+					array(
1195
+						EEM_Registration::status_id_approved,
1196
+						EEM_Registration::status_id_pending_payment,
1197
+						EEM_Registration::status_id_not_approved,
1198
+					),
1199
+				),
1200
+			),
1201
+		);
1202
+		$registrations_to_apply_payment_to = EEH_HTML::br()
1203
+											 . EEH_HTML::div(
1204
+												 '',
1205
+												 'txn-admin-apply-payment-to-registrations-dv',
1206
+												 '',
1207
+												 'clear: both; margin: 1.5em 0 0; display: none;'
1208
+											 );
1209
+		$registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1210
+		$registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
1211
+		$registrations_to_apply_payment_to .= EEH_HTML::thead(
1212
+			EEH_HTML::tr(
1213
+				EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1214
+				EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1215
+				EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1216
+				EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1217
+				EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1218
+				EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1219
+				EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1220
+			)
1221
+		);
1222
+		$registrations_to_apply_payment_to .= EEH_HTML::tbody();
1223
+		// get registrations for TXN
1224
+		$registrations = $this->_transaction->registrations($query_params);
1225
+		$existing_reg_payments = $this->_template_args['existing_reg_payments'];
1226
+		foreach ($registrations as $registration) {
1227
+			if ($registration instanceof EE_Registration) {
1228
+				$attendee_name                     = $registration->attendee() instanceof EE_Attendee
1229
+					? $registration->attendee()->full_name()
1230
+					: esc_html__('Unknown Attendee', 'event_espresso');
1231
+				$owing                             = $registration->final_price() - $registration->paid();
1232
+				$taxable                           = $registration->ticket()->taxable()
1233
+					? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1234
+					: '';
1235
+				$checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments)
1236
+					? ' checked="checked"'
1237
+					: '';
1238
+				$disabled                          = $registration->final_price() > 0 ? '' : ' disabled';
1239
+				$registrations_to_apply_payment_to .= EEH_HTML::tr(
1240
+					EEH_HTML::td($registration->ID()) .
1241
+					EEH_HTML::td($attendee_name) .
1242
+					EEH_HTML::td(
1243
+						$registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1244
+					) .
1245
+					EEH_HTML::td($registration->event_name()) .
1246
+					EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1247
+					EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') .
1248
+					EEH_HTML::td(
1249
+						'<input type="checkbox" value="' . $registration->ID()
1250
+						. '" name="txn_admin_payment[registrations]"'
1251
+						. $checked . $disabled . '>',
1252
+						'',
1253
+						'jst-cntr'
1254
+					),
1255
+					'apply-payment-registration-row-' . $registration->ID()
1256
+				);
1257
+			}
1258
+		}
1259
+		$registrations_to_apply_payment_to                         .= EEH_HTML::tbodyx();
1260
+		$registrations_to_apply_payment_to                         .= EEH_HTML::tablex();
1261
+		$registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1262
+		$registrations_to_apply_payment_to                         .= EEH_HTML::p(
1263
+			esc_html__(
1264
+				'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.',
1265
+				'event_espresso'
1266
+			),
1267
+			'',
1268
+			'clear description'
1269
+		);
1270
+		$registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1271
+		$this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1272
+	}
1273
+
1274
+
1275
+	/**
1276
+	 * _get_reg_status_selection
1277
+	 *
1278
+	 * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1279
+	 *         instead of events.
1280
+	 * @access protected
1281
+	 * @return void
1282
+	 * @throws EE_Error
1283
+	 */
1284
+	protected function _get_reg_status_selection()
1285
+	{
1286
+		//first get all possible statuses
1287
+		$statuses = EEM_Registration::reg_status_array(array(), true);
1288
+		//let's add a "don't change" option.
1289
+		$status_array['NAN']                                 = esc_html__('Leave the Same', 'event_espresso');
1290
+		$status_array                                        = array_merge($status_array, $statuses);
1291
+		$this->_template_args['status_change_select']        = EEH_Form_Fields::select_input(
1292
+			'txn_reg_status_change[reg_status]',
1293
+			$status_array,
1294
+			'NAN',
1295
+			'id="txn-admin-payment-reg-status-inp"',
1296
+			'txn-reg-status-change-reg-status'
1297
+		);
1298
+		$this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input(
1299
+			'delete_txn_reg_status_change[reg_status]',
1300
+			$status_array,
1301
+			'NAN',
1302
+			'delete-txn-admin-payment-reg-status-inp',
1303
+			'delete-txn-reg-status-change-reg-status'
1304
+		);
1305
+	}
1306
+
1307
+
1308
+	/**
1309
+	 *    _get_payment_methods
1310
+	 * Gets all the payment methods available generally, or the ones that are already
1311
+	 * selected on these payments (in case their payment methods are no longer active).
1312
+	 * Has the side-effect of updating the template args' payment_methods item
1313
+	 *
1314
+	 * @access private
1315
+	 * @param EE_Payment[] to show on this page
1316
+	 * @return void
1317
+	 * @throws EE_Error
1318
+	 * @throws InvalidArgumentException
1319
+	 * @throws InvalidDataTypeException
1320
+	 * @throws InvalidInterfaceException
1321
+	 * @throws ReflectionException
1322
+	 */
1323
+	private function _get_payment_methods($payments = array())
1324
+	{
1325
+		$payment_methods_of_payments = array();
1326
+		foreach ($payments as $payment) {
1327
+			if ($payment instanceof EE_Payment) {
1328
+				$payment_methods_of_payments[] = $payment->get('PMD_ID');
1329
+			}
1330
+		}
1331
+		if ($payment_methods_of_payments) {
1332
+			$query_args = array(
1333
+				array(
1334
+					'OR*payment_method_for_payment' => array(
1335
+						'PMD_ID'    => array('IN', $payment_methods_of_payments),
1336
+						'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'),
1337
+					),
1338
+				),
1339
+			);
1340
+		} else {
1341
+			$query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1342
+		}
1343
+		$this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1344
+	}
1345
+
1346
+
1347
+	/**
1348
+	 * txn_attendees_meta_box
1349
+	 *    generates HTML for the Attendees Transaction main meta box
1350
+	 *
1351
+	 * @access public
1352
+	 * @param WP_Post $post
1353
+	 * @param array   $metabox
1354
+	 * @return void
1355
+	 * @throws DomainException
1356
+	 * @throws EE_Error
1357
+	 */
1358
+	public function txn_attendees_meta_box($post, $metabox = array('args' => array()))
1359
+	{
1360
+
1361
+		/** @noinspection NonSecureExtractUsageInspection */
1362
+		extract($metabox['args']);
1363
+		$this->_template_args['post']            = $post;
1364
+		$this->_template_args['event_attendees'] = array();
1365
+		// process items in cart
1366
+		$line_items = $this->_transaction->get_many_related(
1367
+			'Line_Item',
1368
+			array(array('LIN_type' => 'line-item'))
1369
+		);
1370
+		if (! empty($line_items)) {
1371
+			foreach ($line_items as $item) {
1372
+				if ($item instanceof EE_Line_Item) {
1373
+					switch ($item->OBJ_type()) {
1374
+						case 'Event':
1375
+							break;
1376
+						case 'Ticket':
1377
+							$ticket = $item->ticket();
1378
+							//right now we're only handling tickets here.
1379
+							//Cause its expected that only tickets will have attendees right?
1380
+							if (! $ticket instanceof EE_Ticket) {
1381
+								continue;
1382
+							}
1383
+							try {
1384
+								$event_name = $ticket->get_event_name();
1385
+							} catch (Exception $e) {
1386
+								EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1387
+								$event_name = esc_html__('Unknown Event', 'event_espresso');
1388
+							}
1389
+							$event_name   .= ' - ' . $item->get('LIN_name');
1390
+							$ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price'));
1391
+							// now get all of the registrations for this transaction that use this ticket
1392
+							$registrations = $ticket->get_many_related(
1393
+								'Registration',
1394
+								array(array('TXN_ID' => $this->_transaction->ID()))
1395
+							);
1396
+							foreach ($registrations as $registration) {
1397
+								if (! $registration instanceof EE_Registration) {
1398
+									continue;
1399
+								}
1400
+								$this->_template_args['event_attendees'][$registration->ID()]['STS_ID']
1401
+									= $registration->status_ID();
1402
+								$this->_template_args['event_attendees'][$registration->ID()]['att_num']
1403
+									= $registration->count();
1404
+								$this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name']
1405
+									= $event_name;
1406
+								$this->_template_args['event_attendees'][$registration->ID()]['ticket_price']
1407
+									= $ticket_price;
1408
+								// attendee info
1409
+								$attendee = $registration->get_first_related('Attendee');
1410
+								if ($attendee instanceof EE_Attendee) {
1411
+									$this->_template_args['event_attendees'][$registration->ID()]['att_id']
1412
+										= $attendee->ID();
1413
+									$this->_template_args['event_attendees'][$registration->ID()]['attendee']
1414
+										= $attendee->full_name();
1415
+									$this->_template_args['event_attendees'][$registration->ID()]['email']
1416
+										= '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1417
+										  . esc_html__(
1418
+											  ' Event',
1419
+											  'event_espresso'
1420
+										  )
1421
+										  . '">' . $attendee->email() . '</a>';
1422
+									$this->_template_args['event_attendees'][$registration->ID()]['address']
1423
+										= EEH_Address::format($attendee, 'inline', false, false);
1424
+								} else {
1425
+									$this->_template_args['event_attendees'][$registration->ID()]['att_id']   = '';
1426
+									$this->_template_args['event_attendees'][$registration->ID()]['attendee'] = '';
1427
+									$this->_template_args['event_attendees'][$registration->ID()]['email']    = '';
1428
+									$this->_template_args['event_attendees'][$registration->ID()]['address']  = '';
1429
+								}
1430
+							}
1431
+							break;
1432
+
1433
+					}
1434
+				}
1435
+			}
1436
+
1437
+			$this->_template_args['transaction_form_url'] = add_query_arg(
1438
+				array(
1439
+					'action'  => 'edit_transaction',
1440
+					'process' => 'attendees',
1441
+				),
1442
+				TXN_ADMIN_URL
1443
+			);
1444
+			echo EEH_Template::display_template(
1445
+				TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1446
+				$this->_template_args,
1447
+				true
1448
+			);
1449
+
1450
+		} else {
1451
+			echo sprintf(
1452
+				esc_html__(
1453
+					'%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1454
+					'event_espresso'
1455
+				),
1456
+				'<p class="important-notice">',
1457
+				'</p>'
1458
+			);
1459
+		}
1460
+	}
1461
+
1462
+
1463
+	/**
1464
+	 * txn_registrant_side_meta_box
1465
+	 * generates HTML for the Edit Transaction side meta box
1466
+	 *
1467
+	 * @access public
1468
+	 * @return void
1469
+	 * @throws DomainException
1470
+	 * @throws EE_Error
1471
+	 * @throws InvalidArgumentException
1472
+	 * @throws InvalidDataTypeException
1473
+	 * @throws InvalidInterfaceException
1474
+	 * @throws ReflectionException
1475
+	 */
1476
+	public function txn_registrant_side_meta_box()
1477
+	{
1478
+		$primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1479
+			? $this->_transaction->primary_registration()->get_first_related('Attendee')
1480
+			: null;
1481
+		if (! $primary_att instanceof EE_Attendee) {
1482
+			$this->_template_args['no_attendee_message'] = esc_html__(
1483
+				'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1484
+				'event_espresso'
1485
+			);
1486
+			$primary_att                                 = EEM_Attendee::instance()->create_default_object();
1487
+		}
1488
+		$this->_template_args['ATT_ID']            = $primary_att->ID();
1489
+		$this->_template_args['prime_reg_fname']   = $primary_att->fname();
1490
+		$this->_template_args['prime_reg_lname']   = $primary_att->lname();
1491
+		$this->_template_args['prime_reg_email']   = $primary_att->email();
1492
+		$this->_template_args['prime_reg_phone']   = $primary_att->phone();
1493
+		$this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array(
1494
+			'action' => 'edit_attendee',
1495
+			'post'   => $primary_att->ID(),
1496
+		), REG_ADMIN_URL);
1497
+		// get formatted address for registrant
1498
+		$this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1499
+		echo EEH_Template::display_template(
1500
+			TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1501
+			$this->_template_args,
1502
+			true
1503
+		);
1504
+	}
1505
+
1506
+
1507
+	/**
1508
+	 * txn_billing_info_side_meta_box
1509
+	 *    generates HTML for the Edit Transaction side meta box
1510
+	 *
1511
+	 * @access public
1512
+	 * @return void
1513
+	 * @throws DomainException
1514
+	 * @throws EE_Error
1515
+	 */
1516
+	public function txn_billing_info_side_meta_box()
1517
+	{
1518
+
1519
+		$this->_template_args['billing_form']     = $this->_transaction->billing_info();
1520
+		$this->_template_args['billing_form_url'] = add_query_arg(
1521
+			array('action' => 'edit_transaction', 'process' => 'billing'),
1522
+			TXN_ADMIN_URL
1523
+		);
1524
+
1525
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1526
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/
1527
+	}
1528
+
1529
+
1530
+	/**
1531
+	 * apply_payments_or_refunds
1532
+	 *    registers a payment or refund made towards a transaction
1533
+	 *
1534
+	 * @access public
1535
+	 * @return void
1536
+	 * @throws EE_Error
1537
+	 * @throws InvalidArgumentException
1538
+	 * @throws ReflectionException
1539
+	 * @throws RuntimeException
1540
+	 * @throws InvalidDataTypeException
1541
+	 * @throws InvalidInterfaceException
1542
+	 */
1543
+	public function apply_payments_or_refunds()
1544
+	{
1545
+		$json_response_data = array('return_data' => false);
1546
+		$valid_data         = $this->_validate_payment_request_data();
1547
+		$has_access = EE_Registry::instance()->CAP->current_user_can(
1548
+			'ee_edit_payments',
1549
+			'apply_payment_or_refund_from_registration_details'
1550
+		);
1551
+		if (! empty($valid_data) && $has_access) {
1552
+			$PAY_ID = $valid_data['PAY_ID'];
1553
+			//save  the new payment
1554
+			$payment = $this->_create_payment_from_request_data($valid_data);
1555
+			// get the TXN for this payment
1556
+			$transaction = $payment->transaction();
1557
+			// verify transaction
1558
+			if ($transaction instanceof EE_Transaction) {
1559
+				// calculate_total_payments_and_update_status
1560
+				$this->_process_transaction_payments($transaction);
1561
+				$REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1562
+				$this->_remove_existing_registration_payments($payment, $PAY_ID);
1563
+				// apply payment to registrations (if applicable)
1564
+				if (! empty($REG_IDs)) {
1565
+					$this->_update_registration_payments($transaction, $payment, $REG_IDs);
1566
+					$this->_maybe_send_notifications();
1567
+					// now process status changes for the same registrations
1568
+					$this->_process_registration_status_change($transaction, $REG_IDs);
1569
+				}
1570
+				$this->_maybe_send_notifications($payment);
1571
+				//prepare to render page
1572
+				$json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1573
+				do_action(
1574
+					'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording',
1575
+					$transaction,
1576
+					$payment
1577
+				);
1578
+			} else {
1579
+				EE_Error::add_error(
1580
+					esc_html__(
1581
+						'A valid Transaction for this payment could not be retrieved.',
1582
+						'event_espresso'
1583
+					),
1584
+					__FILE__,
1585
+					__FUNCTION__,
1586
+					__LINE__
1587
+				);
1588
+			}
1589
+		} else {
1590
+			if ($has_access) {
1591
+				EE_Error::add_error(
1592
+					esc_html__(
1593
+						'The payment form data could not be processed. Please try again.',
1594
+						'event_espresso'
1595
+					),
1596
+					__FILE__,
1597
+					__FUNCTION__,
1598
+					__LINE__
1599
+				);
1600
+			} else {
1601
+				EE_Error::add_error(
1602
+					esc_html__(
1603
+						'You do not have access to apply payments or refunds to a registration.',
1604
+						'event_espresso'
1605
+					),
1606
+					__FILE__,
1607
+					__FUNCTION__,
1608
+					__LINE__
1609
+				);
1610
+			}
1611
+		}
1612
+		$notices              = EE_Error::get_notices(
1613
+			false,
1614
+			false,
1615
+			false
1616
+		);
1617
+		$this->_template_args = array(
1618
+			'data'    => $json_response_data,
1619
+			'error'   => $notices['errors'],
1620
+			'success' => $notices['success'],
1621
+		);
1622
+		$this->_return_json();
1623
+	}
1624
+
1625
+
1626
+	/**
1627
+	 * _validate_payment_request_data
1628
+	 *
1629
+	 * @return array
1630
+	 * @throws EE_Error
1631
+	 */
1632
+	protected function _validate_payment_request_data()
1633
+	{
1634
+		if (! isset($this->_req_data['txn_admin_payment'])) {
1635
+			return false;
1636
+		}
1637
+		$payment_form = $this->_generate_payment_form_section();
1638
+		try {
1639
+			if ($payment_form->was_submitted()) {
1640
+				$payment_form->receive_form_submission();
1641
+				if (! $payment_form->is_valid()) {
1642
+					$submission_error_messages = array();
1643
+					foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1644
+						if ($validation_error instanceof EE_Validation_Error) {
1645
+							$submission_error_messages[] = sprintf(
1646
+								_x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1647
+								$validation_error->get_form_section()->html_label_text(),
1648
+								$validation_error->getMessage()
1649
+							);
1650
+						}
1651
+					}
1652
+					EE_Error::add_error(
1653
+						implode('<br />', $submission_error_messages),
1654
+						__FILE__,
1655
+						__FUNCTION__,
1656
+						__LINE__
1657
+					);
1658
+
1659
+					return array();
1660
+				}
1661
+			}
1662
+		} catch (EE_Error $e) {
1663
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1664
+
1665
+			return array();
1666
+		}
1667
+
1668
+		return $payment_form->valid_data();
1669
+	}
1670
+
1671
+
1672
+	/**
1673
+	 * _generate_payment_form_section
1674
+	 *
1675
+	 * @return EE_Form_Section_Proper
1676
+	 * @throws EE_Error
1677
+	 */
1678
+	protected function _generate_payment_form_section()
1679
+	{
1680
+		return new EE_Form_Section_Proper(
1681
+			array(
1682
+				'name'        => 'txn_admin_payment',
1683
+				'subsections' => array(
1684
+					'PAY_ID'          => new EE_Text_Input(
1685
+						array(
1686
+							'default'               => 0,
1687
+							'required'              => false,
1688
+							'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1689
+							'validation_strategies' => array(new EE_Int_Normalization()),
1690
+						)
1691
+					),
1692
+					'TXN_ID'          => new EE_Text_Input(
1693
+						array(
1694
+							'default'               => 0,
1695
+							'required'              => true,
1696
+							'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1697
+							'validation_strategies' => array(new EE_Int_Normalization()),
1698
+						)
1699
+					),
1700
+					'type'            => new EE_Text_Input(
1701
+						array(
1702
+							'default'               => 1,
1703
+							'required'              => true,
1704
+							'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1705
+							'validation_strategies' => array(new EE_Int_Normalization()),
1706
+						)
1707
+					),
1708
+					'amount'          => new EE_Text_Input(
1709
+						array(
1710
+							'default'               => 0,
1711
+							'required'              => true,
1712
+							'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1713
+							'validation_strategies' => array(new EE_Float_Normalization()),
1714
+						)
1715
+					),
1716
+					'status'          => new EE_Text_Input(
1717
+						array(
1718
+							'default'         => EEM_Payment::status_id_approved,
1719
+							'required'        => true,
1720
+							'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1721
+						)
1722
+					),
1723
+					'PMD_ID'          => new EE_Text_Input(
1724
+						array(
1725
+							'default'               => 2,
1726
+							'required'              => true,
1727
+							'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1728
+							'validation_strategies' => array(new EE_Int_Normalization()),
1729
+						)
1730
+					),
1731
+					'date'            => new EE_Text_Input(
1732
+						array(
1733
+							'default'         => time(),
1734
+							'required'        => true,
1735
+							'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1736
+						)
1737
+					),
1738
+					'txn_id_chq_nmbr' => new EE_Text_Input(
1739
+						array(
1740
+							'default'               => '',
1741
+							'required'              => false,
1742
+							'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1743
+							'validation_strategies' => array(
1744
+								new EE_Max_Length_Validation_Strategy(
1745
+									esc_html__('Input too long', 'event_espresso'),
1746
+									100
1747
+								),
1748
+							),
1749
+						)
1750
+					),
1751
+					'po_number'       => new EE_Text_Input(
1752
+						array(
1753
+							'default'               => '',
1754
+							'required'              => false,
1755
+							'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1756
+							'validation_strategies' => array(
1757
+								new EE_Max_Length_Validation_Strategy(
1758
+									esc_html__('Input too long', 'event_espresso'),
1759
+									100
1760
+								),
1761
+							),
1762
+						)
1763
+					),
1764
+					'accounting'      => new EE_Text_Input(
1765
+						array(
1766
+							'default'               => '',
1767
+							'required'              => false,
1768
+							'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1769
+							'validation_strategies' => array(
1770
+								new EE_Max_Length_Validation_Strategy(
1771
+									esc_html__('Input too long', 'event_espresso'),
1772
+									100
1773
+								),
1774
+							),
1775
+						)
1776
+					),
1777
+				),
1778
+			)
1779
+		);
1780
+	}
1781
+
1782
+
1783
+	/**
1784
+	 * _create_payment_from_request_data
1785
+	 *
1786
+	 * @param array $valid_data
1787
+	 * @return EE_Payment
1788
+	 * @throws EE_Error
1789
+	 */
1790
+	protected function _create_payment_from_request_data($valid_data)
1791
+	{
1792
+		$PAY_ID = $valid_data['PAY_ID'];
1793
+		// get payment amount
1794
+		$amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1795
+		// payments have a type value of 1 and refunds have a type value of -1
1796
+		// so multiplying amount by type will give a positive value for payments, and negative values for refunds
1797
+		$amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1798
+		// for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1799
+		$date    = $valid_data['date']
1800
+			? preg_replace('/\s+/', ' ', $valid_data['date'])
1801
+			: date('Y-m-d g:i a', current_time('timestamp'));
1802
+		$payment = EE_Payment::new_instance(
1803
+			array(
1804
+				'TXN_ID'              => $valid_data['TXN_ID'],
1805
+				'STS_ID'              => $valid_data['status'],
1806
+				'PAY_timestamp'       => $date,
1807
+				'PAY_source'          => EEM_Payment_Method::scope_admin,
1808
+				'PMD_ID'              => $valid_data['PMD_ID'],
1809
+				'PAY_amount'          => $amount,
1810
+				'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1811
+				'PAY_po_number'       => $valid_data['po_number'],
1812
+				'PAY_extra_accntng'   => $valid_data['accounting'],
1813
+				'PAY_details'         => $valid_data,
1814
+				'PAY_ID'              => $PAY_ID,
1815
+			),
1816
+			'',
1817
+			array('Y-m-d', 'g:i a')
1818
+		);
1819
+
1820
+		if (! $payment->save()) {
1821
+			EE_Error::add_error(
1822
+				sprintf(
1823
+					esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1824
+					$payment->ID()
1825
+				),
1826
+				__FILE__, __FUNCTION__, __LINE__
1827
+			);
1828
+		}
1829
+
1830
+		return $payment;
1831
+	}
1832
+
1833
+
1834
+	/**
1835
+	 * _process_transaction_payments
1836
+	 *
1837
+	 * @param \EE_Transaction $transaction
1838
+	 * @return void
1839
+	 * @throws EE_Error
1840
+	 * @throws InvalidArgumentException
1841
+	 * @throws ReflectionException
1842
+	 * @throws InvalidDataTypeException
1843
+	 * @throws InvalidInterfaceException
1844
+	 */
1845
+	protected function _process_transaction_payments(EE_Transaction $transaction)
1846
+	{
1847
+		/** @type EE_Transaction_Payments $transaction_payments */
1848
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1849
+		//update the transaction with this payment
1850
+		if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1851
+			EE_Error::add_success(esc_html__(
1852
+				'The payment has been processed successfully.', 'event_espresso'),
1853
+				__FILE__,
1854
+				__FUNCTION__,
1855
+				__LINE__
1856
+			);
1857
+		} else {
1858
+			EE_Error::add_error(
1859
+				esc_html__(
1860
+					'The payment was processed successfully but the amount paid for the transaction was not updated.',
1861
+					'event_espresso'
1862
+				)
1863
+				,
1864
+				__FILE__,
1865
+				__FUNCTION__,
1866
+				__LINE__
1867
+			);
1868
+		}
1869
+	}
1870
+
1871
+
1872
+	/**
1873
+	 * _get_REG_IDs_to_apply_payment_to
1874
+	 * returns a list of registration IDs that the payment will apply to
1875
+	 *
1876
+	 * @param \EE_Payment $payment
1877
+	 * @return array
1878
+	 * @throws EE_Error
1879
+	 */
1880
+	protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1881
+	{
1882
+		$REG_IDs = array();
1883
+		// grab array of IDs for specific registrations to apply changes to
1884
+		if (isset($this->_req_data['txn_admin_payment']['registrations'])) {
1885
+			$REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations'];
1886
+		}
1887
+		//nothing specified ? then get all reg IDs
1888
+		if (empty($REG_IDs)) {
1889
+			$registrations = $payment->transaction()->registrations();
1890
+			$REG_IDs       = ! empty($registrations)
1891
+				? array_keys($registrations)
1892
+				: $this->_get_existing_reg_payment_REG_IDs($payment);
1893
+		}
1894
+
1895
+		// ensure that REG_IDs are integers and NOT strings
1896
+		return array_map('intval', $REG_IDs);
1897
+	}
1898
+
1899
+
1900
+	/**
1901
+	 * @return array
1902
+	 */
1903
+	public function existing_reg_payment_REG_IDs()
1904
+	{
1905
+		return $this->_existing_reg_payment_REG_IDs;
1906
+	}
1907
+
1908
+
1909
+	/**
1910
+	 * @param array $existing_reg_payment_REG_IDs
1911
+	 */
1912
+	public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1913
+	{
1914
+		$this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1915
+	}
1916
+
1917
+
1918
+	/**
1919
+	 * _get_existing_reg_payment_REG_IDs
1920
+	 * returns a list of registration IDs that the payment is currently related to
1921
+	 * as recorded in the database
1922
+	 *
1923
+	 * @param \EE_Payment $payment
1924
+	 * @return array
1925
+	 * @throws EE_Error
1926
+	 */
1927
+	protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
1928
+	{
1929
+		if ($this->existing_reg_payment_REG_IDs() === null) {
1930
+			// let's get any existing reg payment records for this payment
1931
+			$existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
1932
+			// but we only want the REG IDs, so grab the array keys
1933
+			$existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs)
1934
+				? array_keys($existing_reg_payment_REG_IDs)
1935
+				: array();
1936
+			$this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
1937
+		}
1938
+
1939
+		return $this->existing_reg_payment_REG_IDs();
1940
+	}
1941
+
1942
+
1943
+	/**
1944
+	 * _remove_existing_registration_payments
1945
+	 * this calculates the difference between existing relations
1946
+	 * to the supplied payment and the new list registration IDs,
1947
+	 * removes any related registrations that no longer apply,
1948
+	 * and then updates the registration paid fields
1949
+	 *
1950
+	 * @param \EE_Payment $payment
1951
+	 * @param int         $PAY_ID
1952
+	 * @return bool;
1953
+	 * @throws EE_Error
1954
+	 * @throws InvalidArgumentException
1955
+	 * @throws ReflectionException
1956
+	 * @throws InvalidDataTypeException
1957
+	 * @throws InvalidInterfaceException
1958
+	 */
1959
+	protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
1960
+	{
1961
+		// newly created payments will have nothing recorded for $PAY_ID
1962
+		if ($PAY_ID == 0) {
1963
+			return false;
1964
+		}
1965
+		$existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
1966
+		if (empty($existing_reg_payment_REG_IDs)) {
1967
+			return false;
1968
+		}
1969
+		/** @type EE_Transaction_Payments $transaction_payments */
1970
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1971
+
1972
+		return $transaction_payments->delete_registration_payments_and_update_registrations(
1973
+			$payment,
1974
+			array(
1975
+				array(
1976
+					'PAY_ID' => $payment->ID(),
1977
+					'REG_ID' => array('IN', $existing_reg_payment_REG_IDs),
1978
+				),
1979
+			)
1980
+		);
1981
+	}
1982
+
1983
+
1984
+	/**
1985
+	 * _update_registration_payments
1986
+	 * this applies the payments to the selected registrations
1987
+	 * but only if they have not already been paid for
1988
+	 *
1989
+	 * @param  EE_Transaction $transaction
1990
+	 * @param \EE_Payment     $payment
1991
+	 * @param array           $REG_IDs
1992
+	 * @return void
1993
+	 * @throws EE_Error
1994
+	 * @throws InvalidArgumentException
1995
+	 * @throws ReflectionException
1996
+	 * @throws RuntimeException
1997
+	 * @throws InvalidDataTypeException
1998
+	 * @throws InvalidInterfaceException
1999
+	 */
2000
+	protected function _update_registration_payments(
2001
+		EE_Transaction $transaction,
2002
+		EE_Payment $payment,
2003
+		$REG_IDs = array()
2004
+	) {
2005
+		// we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
2006
+		// so let's do that using our set of REG_IDs from the form
2007
+		$registration_query_where_params = array(
2008
+			'REG_ID' => array('IN', $REG_IDs),
2009
+		);
2010
+		// but add in some conditions regarding payment,
2011
+		// so that we don't apply payments to registrations that are free or have already been paid for
2012
+		// but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
2013
+		if (! $payment->is_a_refund()) {
2014
+			$registration_query_where_params['REG_final_price']  = array('!=', 0);
2015
+			$registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true);
2016
+		}
2017
+		$registrations = $transaction->registrations(array($registration_query_where_params));
2018
+		if (! empty($registrations)) {
2019
+			/** @type EE_Payment_Processor $payment_processor */
2020
+			$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2021
+			$payment_processor->process_registration_payments($transaction, $payment, $registrations);
2022
+		}
2023
+	}
2024
+
2025
+
2026
+	/**
2027
+	 * _process_registration_status_change
2028
+	 * This processes requested registration status changes for all the registrations
2029
+	 * on a given transaction and (optionally) sends out notifications for the changes.
2030
+	 *
2031
+	 * @param  EE_Transaction $transaction
2032
+	 * @param array           $REG_IDs
2033
+	 * @return bool
2034
+	 * @throws EE_Error
2035
+	 * @throws InvalidArgumentException
2036
+	 * @throws ReflectionException
2037
+	 * @throws InvalidDataTypeException
2038
+	 * @throws InvalidInterfaceException
2039
+	 */
2040
+	protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array())
2041
+	{
2042
+		// first if there is no change in status then we get out.
2043
+		if (
2044
+			! isset($this->_req_data['txn_reg_status_change']['reg_status'])
2045
+			|| $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN'
2046
+		) {
2047
+			//no error message, no change requested, just nothing to do man.
2048
+			return false;
2049
+		}
2050
+		/** @type EE_Transaction_Processor $transaction_processor */
2051
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
2052
+
2053
+		// made it here dude?  Oh WOW.  K, let's take care of changing the statuses
2054
+		return $transaction_processor->manually_update_registration_statuses(
2055
+			$transaction,
2056
+			sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']),
2057
+			array(array('REG_ID' => array('IN', $REG_IDs)))
2058
+		);
2059
+	}
2060
+
2061
+
2062
+	/**
2063
+	 * _build_payment_json_response
2064
+	 *
2065
+	 * @access public
2066
+	 * @param \EE_Payment $payment
2067
+	 * @param array       $REG_IDs
2068
+	 * @param bool | null $delete_txn_reg_status_change
2069
+	 * @return array
2070
+	 * @throws EE_Error
2071
+	 * @throws InvalidArgumentException
2072
+	 * @throws InvalidDataTypeException
2073
+	 * @throws InvalidInterfaceException
2074
+	 * @throws ReflectionException
2075
+	 */
2076
+	protected function _build_payment_json_response(
2077
+		EE_Payment $payment,
2078
+		$REG_IDs = array(),
2079
+		$delete_txn_reg_status_change = null
2080
+	) {
2081
+		// was the payment deleted ?
2082
+		if (is_bool($delete_txn_reg_status_change)) {
2083
+			return array(
2084
+				'PAY_ID'                       => $payment->ID(),
2085
+				'amount'                       => $payment->amount(),
2086
+				'total_paid'                   => $payment->transaction()->paid(),
2087
+				'txn_status'                   => $payment->transaction()->status_ID(),
2088
+				'pay_status'                   => $payment->STS_ID(),
2089
+				'registrations'                => $this->_registration_payment_data_array($REG_IDs),
2090
+				'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
2091
+			);
2092
+		} else {
2093
+			$this->_get_payment_status_array();
2094
+
2095
+			return array(
2096
+				'amount'           => $payment->amount(),
2097
+				'total_paid'       => $payment->transaction()->paid(),
2098
+				'txn_status'       => $payment->transaction()->status_ID(),
2099
+				'pay_status'       => $payment->STS_ID(),
2100
+				'PAY_ID'           => $payment->ID(),
2101
+				'STS_ID'           => $payment->STS_ID(),
2102
+				'status'           => self::$_pay_status[$payment->STS_ID()],
2103
+				'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
2104
+				'method'           => strtoupper($payment->source()),
2105
+				'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
2106
+				'gateway'          => $payment->payment_method()
2107
+					? $payment->payment_method()->admin_name()
2108
+					: esc_html__("Unknown", 'event_espresso'),
2109
+				'gateway_response' => $payment->gateway_response(),
2110
+				'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
2111
+				'po_number'        => $payment->po_number(),
2112
+				'extra_accntng'    => $payment->extra_accntng(),
2113
+				'registrations'    => $this->_registration_payment_data_array($REG_IDs),
2114
+			);
2115
+		}
2116
+	}
2117
+
2118
+
2119
+	/**
2120
+	 * delete_payment
2121
+	 *    delete a payment or refund made towards a transaction
2122
+	 *
2123
+	 * @access public
2124
+	 * @return void
2125
+	 * @throws EE_Error
2126
+	 * @throws InvalidArgumentException
2127
+	 * @throws ReflectionException
2128
+	 * @throws InvalidDataTypeException
2129
+	 * @throws InvalidInterfaceException
2130
+	 */
2131
+	public function delete_payment()
2132
+	{
2133
+		$json_response_data = array('return_data' => false);
2134
+		$PAY_ID             = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2135
+			? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID'])
2136
+			: 0;
2137
+		$can_delete = EE_Registry::instance()->CAP->current_user_can(
2138
+			'ee_delete_payments',
2139
+			'delete_payment_from_registration_details'
2140
+		);
2141
+		if ($PAY_ID && $can_delete) {
2142
+			$delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change'])
2143
+				? $this->_req_data['delete_txn_reg_status_change']
2144
+				: false;
2145
+			$payment                      = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
2146
+			if ($payment instanceof EE_Payment) {
2147
+				$REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2148
+				/** @type EE_Transaction_Payments $transaction_payments */
2149
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2150
+				if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
2151
+					$json_response_data['return_data'] = $this->_build_payment_json_response(
2152
+						$payment,
2153
+						$REG_IDs,
2154
+						$delete_txn_reg_status_change
2155
+					);
2156
+					if ($delete_txn_reg_status_change) {
2157
+						$this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change;
2158
+						//MAKE sure we also add the delete_txn_req_status_change to the
2159
+						//$_REQUEST global because that's how messages will be looking for it.
2160
+						$_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change;
2161
+						$this->_maybe_send_notifications();
2162
+						$this->_process_registration_status_change($payment->transaction(), $REG_IDs);
2163
+					}
2164
+				}
2165
+			} else {
2166
+				EE_Error::add_error(
2167
+					esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
2168
+					__FILE__, __FUNCTION__, __LINE__
2169
+				);
2170
+			}
2171
+		} else {
2172
+			if ($can_delete) {
2173
+				EE_Error::add_error(
2174
+					esc_html__(
2175
+						'A valid Payment ID was not received, therefore payment form data could not be loaded.',
2176
+						'event_espresso'
2177
+					),
2178
+					__FILE__, __FUNCTION__, __LINE__
2179
+				);
2180
+			} else {
2181
+				EE_Error::add_error(
2182
+					esc_html__(
2183
+						'You do not have access to delete a payment.',
2184
+						'event_espresso'
2185
+					),
2186
+					__FILE__,
2187
+					__FUNCTION__,
2188
+					__LINE__
2189
+				);
2190
+			}
2191
+		}
2192
+		$notices              = EE_Error::get_notices(false, false, false);
2193
+		$this->_template_args = array(
2194
+			'data'      => $json_response_data,
2195
+			'success'   => $notices['success'],
2196
+			'error'     => $notices['errors'],
2197
+			'attention' => $notices['attention'],
2198
+		);
2199
+		$this->_return_json();
2200
+	}
2201
+
2202
+
2203
+	/**
2204
+	 * _registration_payment_data_array
2205
+	 * adds info for 'owing' and 'paid' for each registration to the json response
2206
+	 *
2207
+	 * @access protected
2208
+	 * @param array $REG_IDs
2209
+	 * @return array
2210
+	 * @throws EE_Error
2211
+	 * @throws InvalidArgumentException
2212
+	 * @throws InvalidDataTypeException
2213
+	 * @throws InvalidInterfaceException
2214
+	 * @throws ReflectionException
2215
+	 */
2216
+	protected function _registration_payment_data_array($REG_IDs)
2217
+	{
2218
+		$registration_payment_data = array();
2219
+		//if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2220
+		if (! empty($REG_IDs)) {
2221
+			$registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs))));
2222
+			foreach ($registrations as $registration) {
2223
+				if ($registration instanceof EE_Registration) {
2224
+					$registration_payment_data[$registration->ID()] = array(
2225
+						'paid'  => $registration->pretty_paid(),
2226
+						'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
2227
+					);
2228
+				}
2229
+			}
2230
+		}
2231
+
2232
+		return $registration_payment_data;
2233
+	}
2234
+
2235
+
2236
+	/**
2237
+	 * _maybe_send_notifications
2238
+	 * determines whether or not the admin has indicated that notifications should be sent.
2239
+	 * If so, will toggle a filter switch for delivering registration notices.
2240
+	 * If passed an EE_Payment object, then it will trigger payment notifications instead.
2241
+	 *
2242
+	 * @access protected
2243
+	 * @param \EE_Payment | null $payment
2244
+	 */
2245
+	protected function _maybe_send_notifications($payment = null)
2246
+	{
2247
+		switch ($payment instanceof EE_Payment) {
2248
+			// payment notifications
2249
+			case true :
2250
+				if (
2251
+					isset(
2252
+						$this->_req_data['txn_payments'],
2253
+						$this->_req_data['txn_payments']['send_notifications']
2254
+					) &&
2255
+					filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
2256
+				) {
2257
+					$this->_process_payment_notification($payment);
2258
+				}
2259
+				break;
2260
+			// registration notifications
2261
+			case false :
2262
+				if (
2263
+					isset(
2264
+						$this->_req_data['txn_reg_status_change'],
2265
+						$this->_req_data['txn_reg_status_change']['send_notifications']
2266
+					) &&
2267
+					filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN)
2268
+				) {
2269
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
2270
+				}
2271
+				break;
2272
+		}
2273
+	}
2274
+
2275
+
2276
+	/**
2277
+	 * _send_payment_reminder
2278
+	 *    generates HTML for the View Transaction Details Admin page
2279
+	 *
2280
+	 * @access protected
2281
+	 * @return void
2282
+	 * @throws EE_Error
2283
+	 * @throws InvalidArgumentException
2284
+	 * @throws InvalidDataTypeException
2285
+	 * @throws InvalidInterfaceException
2286
+	 */
2287
+	protected function _send_payment_reminder()
2288
+	{
2289
+		$TXN_ID      = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false;
2290
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2291
+		$query_args  = isset($this->_req_data['redirect_to']) ? array(
2292
+			'action' => $this->_req_data['redirect_to'],
2293
+			'TXN_ID' => $this->_req_data['TXN_ID'],
2294
+		) : array();
2295
+		do_action(
2296
+			'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
2297
+			$transaction
2298
+		);
2299
+		$this->_redirect_after_action(
2300
+			false,
2301
+			esc_html__('payment reminder', 'event_espresso'),
2302
+			esc_html__('sent', 'event_espresso'),
2303
+			$query_args,
2304
+			true
2305
+		);
2306
+	}
2307
+
2308
+
2309
+	/**
2310
+	 *  get_transactions
2311
+	 *    get transactions for given parameters (used by list table)
2312
+	 *
2313
+	 * @param  int     $perpage how many transactions displayed per page
2314
+	 * @param  boolean $count   return the count or objects
2315
+	 * @param string   $view
2316
+	 * @return mixed int = count || array of transaction objects
2317
+	 * @throws EE_Error
2318
+	 * @throws InvalidArgumentException
2319
+	 * @throws InvalidDataTypeException
2320
+	 * @throws InvalidInterfaceException
2321
+	 */
2322
+	public function get_transactions($perpage, $count = false, $view = '')
2323
+	{
2324
+
2325
+		$TXN = EEM_Transaction::instance();
2326
+
2327
+		$start_date = isset($this->_req_data['txn-filter-start-date'])
2328
+			? wp_strip_all_tags($this->_req_data['txn-filter-start-date'])
2329
+			: date(
2330
+				'm/d/Y',
2331
+				strtotime('-10 year')
2332
+			);
2333
+		$end_date   = isset($this->_req_data['txn-filter-end-date'])
2334
+			? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
2335
+			: date('m/d/Y');
2336
+
2337
+		//make sure our timestamps start and end right at the boundaries for each day
2338
+		$start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2339
+		$end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2340
+
2341
+
2342
+		//convert to timestamps
2343
+		$start_date = strtotime($start_date);
2344
+		$end_date   = strtotime($end_date);
2345
+
2346
+		//makes sure start date is the lowest value and vice versa
2347
+		$start_date = min($start_date, $end_date);
2348
+		$end_date   = max($start_date, $end_date);
2349
+
2350
+		//convert to correct format for query
2351
+		$start_date = EEM_Transaction::instance()->convert_datetime_for_query(
2352
+			'TXN_timestamp',
2353
+			date('Y-m-d H:i:s', $start_date),
2354
+			'Y-m-d H:i:s'
2355
+		);
2356
+		$end_date   = EEM_Transaction::instance()->convert_datetime_for_query(
2357
+			'TXN_timestamp',
2358
+			date('Y-m-d H:i:s', $end_date),
2359
+			'Y-m-d H:i:s'
2360
+		);
2361
+
2362
+
2363
+		//set orderby
2364
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2365
+
2366
+		switch ($this->_req_data['orderby']) {
2367
+			case 'TXN_ID':
2368
+				$orderby = 'TXN_ID';
2369
+				break;
2370
+			case 'ATT_fname':
2371
+				$orderby = 'Registration.Attendee.ATT_fname';
2372
+				break;
2373
+			case 'event_name':
2374
+				$orderby = 'Registration.Event.EVT_name';
2375
+				break;
2376
+			default: //'TXN_timestamp'
2377
+				$orderby = 'TXN_timestamp';
2378
+		}
2379
+
2380
+		$sort         = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2381
+		$current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
2382
+		$per_page     = ! empty($perpage) ? $perpage : 10;
2383
+		$per_page     = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page;
2384
+
2385
+		$offset = ($current_page - 1) * $per_page;
2386
+		$limit  = array($offset, $per_page);
2387
+
2388
+		$_where = array(
2389
+			'TXN_timestamp'          => array('BETWEEN', array($start_date, $end_date)),
2390
+			'Registration.REG_count' => 1,
2391
+		);
2392
+
2393
+		if (isset($this->_req_data['EVT_ID'])) {
2394
+			$_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID'];
2395
+		}
2396
+
2397
+		if (isset($this->_req_data['s'])) {
2398
+			$search_string = '%' . $this->_req_data['s'] . '%';
2399
+			$_where['OR']  = array(
2400
+				'Registration.Event.EVT_name'         => array('LIKE', $search_string),
2401
+				'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
2402
+				'Registration.Event.EVT_short_desc'   => array('LIKE', $search_string),
2403
+				'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string),
2404
+				'Registration.Attendee.ATT_fname'     => array('LIKE', $search_string),
2405
+				'Registration.Attendee.ATT_lname'     => array('LIKE', $search_string),
2406
+				'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string),
2407
+				'Registration.Attendee.ATT_email'     => array('LIKE', $search_string),
2408
+				'Registration.Attendee.ATT_address'   => array('LIKE', $search_string),
2409
+				'Registration.Attendee.ATT_address2'  => array('LIKE', $search_string),
2410
+				'Registration.Attendee.ATT_city'      => array('LIKE', $search_string),
2411
+				'Registration.REG_final_price'        => array('LIKE', $search_string),
2412
+				'Registration.REG_code'               => array('LIKE', $search_string),
2413
+				'Registration.REG_count'              => array('LIKE', $search_string),
2414
+				'Registration.REG_group_size'         => array('LIKE', $search_string),
2415
+				'Registration.Ticket.TKT_name'        => array('LIKE', $search_string),
2416
+				'Registration.Ticket.TKT_description' => array('LIKE', $search_string),
2417
+				'Payment.PAY_source'                  => array('LIKE', $search_string),
2418
+				'Payment.Payment_Method.PMD_name'     => array('LIKE', $search_string),
2419
+				'TXN_session_data'                    => array('LIKE', $search_string),
2420
+				'Payment.PAY_txn_id_chq_nmbr'         => array('LIKE', $search_string),
2421
+			);
2422
+		}
2423
+
2424
+		//failed transactions
2425
+		$failed    = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count)
2426
+					 || ($count && $view === 'failed');
2427
+		$abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count)
2428
+					 || ($count && $view === 'abandoned');
2429
+
2430
+		if ($failed) {
2431
+			$_where['STS_ID'] = EEM_Transaction::failed_status_code;
2432
+		} else if ($abandoned) {
2433
+			$_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
2434
+		} else {
2435
+			$_where['STS_ID']  = array('!=', EEM_Transaction::failed_status_code);
2436
+			$_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code);
2437
+		}
2438
+
2439
+		$query_params = array(
2440
+			$_where,
2441
+			'order_by'                 => array($orderby => $sort),
2442
+			'limit'                    => $limit,
2443
+			'default_where_conditions' => EEM_Base::default_where_conditions_this_only,
2444
+		);
2445
+
2446
+		$transactions = $count
2447
+			? $TXN->count(array($_where), 'TXN_ID', true)
2448
+			: $TXN->get_all($query_params);
2449
+
2450
+		return $transactions;
2451
+	}
2452 2452
 }
Please login to merge, or discard this patch.
Spacing   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
             'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
267 267
             'event_espresso'
268 268
         );
269
-        EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__(
269
+        EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__(
270 270
             'An error occurred! Please refresh the page and try again.',
271 271
             'event_espresso'
272 272
         );
@@ -364,13 +364,13 @@  discard block
 block discarded – undo
364 364
         //enqueue style
365 365
         wp_register_style(
366 366
             'espresso_txn',
367
-            TXN_ASSETS_URL . 'espresso_transactions_admin.css',
367
+            TXN_ASSETS_URL.'espresso_transactions_admin.css',
368 368
             array(),
369 369
             EVENT_ESPRESSO_VERSION
370 370
         );
371 371
         wp_enqueue_style('espresso_txn');
372 372
         //scripts
373
-        wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array(
373
+        wp_register_script('espresso_txn', TXN_ASSETS_URL.'espresso_transactions_admin.js', array(
374 374
             'ee_admin_js',
375 375
             'ee-datepicker',
376 376
             'jquery-ui-datepicker',
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
             : null;
468 468
         $this->_transaction->verify_abandoned_transaction_status();
469 469
 
470
-        if (! $this->_transaction instanceof EE_Transaction) {
470
+        if ( ! $this->_transaction instanceof EE_Transaction) {
471 471
             $error_msg = sprintf(
472 472
                 esc_html__(
473 473
                     'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
             'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
566 566
             array(
567 567
                 'overpaid'   => array(
568
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
568
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::overpaid_status_code,
569 569
                     'desc'  => EEH_Template::pretty_status(
570 570
                         EEM_Transaction::overpaid_status_code,
571 571
                         false,
@@ -573,7 +573,7 @@  discard block
 block discarded – undo
573 573
                     ),
574 574
                 ),
575 575
                 'complete'   => array(
576
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
576
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::complete_status_code,
577 577
                     'desc'  => EEH_Template::pretty_status(
578 578
                         EEM_Transaction::complete_status_code,
579 579
                         false,
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
                     ),
582 582
                 ),
583 583
                 'incomplete' => array(
584
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
584
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::incomplete_status_code,
585 585
                     'desc'  => EEH_Template::pretty_status(
586 586
                         EEM_Transaction::incomplete_status_code,
587 587
                         false,
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
                     ),
590 590
                 ),
591 591
                 'abandoned'  => array(
592
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
592
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::abandoned_status_code,
593 593
                     'desc'  => EEH_Template::pretty_status(
594 594
                         EEM_Transaction::abandoned_status_code,
595 595
                         false,
@@ -597,7 +597,7 @@  discard block
 block discarded – undo
597 597
                     ),
598 598
                 ),
599 599
                 'failed'     => array(
600
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
600
+                    'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::failed_status_code,
601 601
                     'desc'  => EEH_Template::pretty_status(
602 602
                         EEM_Transaction::failed_status_code,
603 603
                         false,
@@ -646,11 +646,11 @@  discard block
 block discarded – undo
646 646
                     'Click to Edit event',
647 647
                     'event_espresso'
648 648
                 )
649
-                . '">' . $event->get('EVT_name') . '</a>',
649
+                . '">'.$event->get('EVT_name').'</a>',
650 650
                 '</h3>'
651 651
             )
652 652
             : '';
653
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
653
+        $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items());
654 654
         $this->display_admin_list_table_page_with_no_sidebar();
655 655
     }
656 656
 
@@ -693,7 +693,7 @@  discard block
 block discarded – undo
693 693
 
694 694
         $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')];
695 695
         $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
696
-        $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID');
696
+        $this->_template_args['txn_status']['class'] = 'status-'.$this->_transaction->get('STS_ID');
697 697
 
698 698
         $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total');
699 699
         $this->_template_args['total_paid']  = $this->_transaction->get('TXN_paid');
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
 
747 747
 
748 748
         // next link
749
-        $next_txn                                 = $this->_transaction->next(
749
+        $next_txn = $this->_transaction->next(
750 750
             null,
751 751
             array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
752 752
             'TXN_ID'
@@ -761,7 +761,7 @@  discard block
 block discarded – undo
761 761
             )
762 762
             : '';
763 763
         // previous link
764
-        $previous_txn                                 = $this->_transaction->previous(
764
+        $previous_txn = $this->_transaction->previous(
765 765
             null,
766 766
             array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))),
767 767
             'TXN_ID'
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
         // grab messages at the last second
812 812
         $this->_template_args['notices'] = EE_Error::get_notices();
813 813
         // path to template
814
-        $template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
814
+        $template_path                             = TXN_TEMPLATE_PATH.'txn_admin_details_header.template.php';
815 815
         $this->_template_args['admin_page_header'] = EEH_Template::display_template(
816 816
             $template_path,
817 817
             $this->_template_args,
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
     {
894 894
         $content = '';
895 895
         $actions = array();
896
-        if (! $transaction instanceof EE_Transaction) {
896
+        if ( ! $transaction instanceof EE_Transaction) {
897 897
             return $content;
898 898
         }
899 899
         /** @var EE_Registration $primary_registration */
@@ -954,7 +954,7 @@  discard block
 block discarded – undo
954 954
         );
955 955
         if ($actions) {
956 956
             $content = '<ul>';
957
-            $content .= '<li>' . implode('</li><li>', $actions) . '</li>';
957
+            $content .= '<li>'.implode('</li><li>', $actions).'</li>';
958 958
             $content .= '</uL>';
959 959
         }
960 960
         return $content;
@@ -992,7 +992,7 @@  discard block
 block discarded – undo
992 992
 
993 993
         //get line table
994 994
         EEH_Autoloader::register_line_item_display_autoloaders();
995
-        $Line_Item_Display                       = new EE_Line_Item_Display(
995
+        $Line_Item_Display = new EE_Line_Item_Display(
996 996
             'admin_table',
997 997
             'EE_Admin_Table_Line_Item_Display_Strategy'
998 998
         );
@@ -1003,13 +1003,13 @@  discard block
 block discarded – undo
1003 1003
                                                                       ->get('REG_code');
1004 1004
 
1005 1005
         // process taxes
1006
-        $taxes                         = $this->_transaction->get_many_related(
1006
+        $taxes = $this->_transaction->get_many_related(
1007 1007
             'Line_Item',
1008 1008
             array(array('LIN_type' => EEM_Line_Item::type_tax))
1009 1009
         );
1010 1010
         $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
1011 1011
 
1012
-        $this->_template_args['grand_total']     = EEH_Template::format_currency(
1012
+        $this->_template_args['grand_total'] = EEH_Template::format_currency(
1013 1013
             $this->_transaction->get('TXN_total'),
1014 1014
             false,
1015 1015
             false
@@ -1019,7 +1019,7 @@  discard block
 block discarded – undo
1019 1019
 
1020 1020
         // process payment details
1021 1021
         $payments = $this->_transaction->get_many_related('Payment');
1022
-        if (! empty($payments)) {
1022
+        if ( ! empty($payments)) {
1023 1023
             $this->_template_args['payments']              = $payments;
1024 1024
             $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
1025 1025
         } else {
@@ -1080,7 +1080,7 @@  discard block
 block discarded – undo
1080 1080
                                   esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1081 1081
                                   ucwords(str_replace('_', ' ', $reg_step)),
1082 1082
                                   date(
1083
-                                      get_option('date_format') . ' ' . get_option('time_format'),
1083
+                                      get_option('date_format').' '.get_option('time_format'),
1084 1084
                                       ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))
1085 1085
                                   )
1086 1086
                               )
@@ -1094,7 +1094,7 @@  discard block
 block discarded – undo
1094 1094
                               . '</li>';
1095 1095
             }
1096 1096
         }
1097
-        $reg_steps                                                 .= '</ul>';
1097
+        $reg_steps .= '</ul>';
1098 1098
         $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
1099 1099
         $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__(
1100 1100
             'Registration Step Progress',
@@ -1107,11 +1107,11 @@  discard block
 block discarded – undo
1107 1107
         $this->_get_payment_status_array();
1108 1108
         $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction.
1109 1109
 
1110
-        $this->_template_args['transaction_form_url']    = add_query_arg(array(
1110
+        $this->_template_args['transaction_form_url'] = add_query_arg(array(
1111 1111
             'action'  => 'edit_transaction',
1112 1112
             'process' => 'transaction',
1113 1113
         ), TXN_ADMIN_URL);
1114
-        $this->_template_args['apply_payment_form_url']  = add_query_arg(array(
1114
+        $this->_template_args['apply_payment_form_url'] = add_query_arg(array(
1115 1115
             'page'   => 'espresso_transactions',
1116 1116
             'action' => 'espresso_apply_payment',
1117 1117
         ), WP_AJAX_URL);
@@ -1124,7 +1124,7 @@  discard block
 block discarded – undo
1124 1124
 
1125 1125
         // 'espresso_delete_payment_nonce'
1126 1126
 
1127
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1127
+        $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_txn_details.template.php';
1128 1128
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
1129 1129
     }
1130 1130
 
@@ -1154,11 +1154,11 @@  discard block
 block discarded – undo
1154 1154
                 ),
1155 1155
             ),
1156 1156
         ));
1157
-        if (! empty($reg_payments)) {
1157
+        if ( ! empty($reg_payments)) {
1158 1158
             foreach ($payments as $payment) {
1159
-                if (! $payment instanceof EE_Payment) {
1159
+                if ( ! $payment instanceof EE_Payment) {
1160 1160
                     continue;
1161
-                } elseif (! isset($existing_reg_payments[$payment->ID()])) {
1161
+                } elseif ( ! isset($existing_reg_payments[$payment->ID()])) {
1162 1162
                     $existing_reg_payments[$payment->ID()] = array();
1163 1163
                 }
1164 1164
                 foreach ($reg_payments as $reg_payment) {
@@ -1187,7 +1187,7 @@  discard block
 block discarded – undo
1187 1187
     protected function _get_registrations_to_apply_payment_to()
1188 1188
     {
1189 1189
         // we want any registration with an active status (ie: not deleted or cancelled)
1190
-        $query_params                      = array(
1190
+        $query_params = array(
1191 1191
             array(
1192 1192
                 'STS_ID' => array(
1193 1193
                     'IN',
@@ -1206,16 +1206,16 @@  discard block
 block discarded – undo
1206 1206
                                                  '',
1207 1207
                                                  'clear: both; margin: 1.5em 0 0; display: none;'
1208 1208
                                              );
1209
-        $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1209
+        $registrations_to_apply_payment_to .= EEH_HTML::br().EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1210 1210
         $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
1211 1211
         $registrations_to_apply_payment_to .= EEH_HTML::thead(
1212 1212
             EEH_HTML::tr(
1213
-                EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1214
-                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1215
-                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1216
-                EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1217
-                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1218
-                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1213
+                EEH_HTML::th(esc_html__('ID', 'event_espresso')).
1214
+                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')).
1215
+                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')).
1216
+                EEH_HTML::th(esc_html__('Event', 'event_espresso')).
1217
+                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr').
1218
+                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr').
1219 1219
                 EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1220 1220
             )
1221 1221
         );
@@ -1230,29 +1230,29 @@  discard block
 block discarded – undo
1230 1230
                     : esc_html__('Unknown Attendee', 'event_espresso');
1231 1231
                 $owing                             = $registration->final_price() - $registration->paid();
1232 1232
                 $taxable                           = $registration->ticket()->taxable()
1233
-                    ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1233
+                    ? ' <span class="smaller-text lt-grey-text"> '.esc_html__('+ tax', 'event_espresso').'</span>'
1234 1234
                     : '';
1235 1235
                 $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments)
1236 1236
                     ? ' checked="checked"'
1237 1237
                     : '';
1238
-                $disabled                          = $registration->final_price() > 0 ? '' : ' disabled';
1238
+                $disabled = $registration->final_price() > 0 ? '' : ' disabled';
1239 1239
                 $registrations_to_apply_payment_to .= EEH_HTML::tr(
1240
-                    EEH_HTML::td($registration->ID()) .
1241
-                    EEH_HTML::td($attendee_name) .
1240
+                    EEH_HTML::td($registration->ID()).
1241
+                    EEH_HTML::td($attendee_name).
1242 1242
                     EEH_HTML::td(
1243
-                        $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1244
-                    ) .
1245
-                    EEH_HTML::td($registration->event_name()) .
1246
-                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1247
-                    EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') .
1243
+                        $registration->ticket()->name().' : '.$registration->ticket()->pretty_price().$taxable
1244
+                    ).
1245
+                    EEH_HTML::td($registration->event_name()).
1246
+                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr').
1247
+                    EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr').
1248 1248
                     EEH_HTML::td(
1249
-                        '<input type="checkbox" value="' . $registration->ID()
1249
+                        '<input type="checkbox" value="'.$registration->ID()
1250 1250
                         . '" name="txn_admin_payment[registrations]"'
1251
-                        . $checked . $disabled . '>',
1251
+                        . $checked.$disabled.'>',
1252 1252
                         '',
1253 1253
                         'jst-cntr'
1254 1254
                     ),
1255
-                    'apply-payment-registration-row-' . $registration->ID()
1255
+                    'apply-payment-registration-row-'.$registration->ID()
1256 1256
                 );
1257 1257
             }
1258 1258
         }
@@ -1267,7 +1267,7 @@  discard block
 block discarded – undo
1267 1267
             '',
1268 1268
             'clear description'
1269 1269
         );
1270
-        $registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1270
+        $registrations_to_apply_payment_to .= EEH_HTML::divx();
1271 1271
         $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1272 1272
     }
1273 1273
 
@@ -1333,12 +1333,12 @@  discard block
 block discarded – undo
1333 1333
                 array(
1334 1334
                     'OR*payment_method_for_payment' => array(
1335 1335
                         'PMD_ID'    => array('IN', $payment_methods_of_payments),
1336
-                        'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'),
1336
+                        'PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%'),
1337 1337
                     ),
1338 1338
                 ),
1339 1339
             );
1340 1340
         } else {
1341
-            $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%')));
1341
+            $query_args = array(array('PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%')));
1342 1342
         }
1343 1343
         $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1344 1344
     }
@@ -1367,7 +1367,7 @@  discard block
 block discarded – undo
1367 1367
             'Line_Item',
1368 1368
             array(array('LIN_type' => 'line-item'))
1369 1369
         );
1370
-        if (! empty($line_items)) {
1370
+        if ( ! empty($line_items)) {
1371 1371
             foreach ($line_items as $item) {
1372 1372
                 if ($item instanceof EE_Line_Item) {
1373 1373
                     switch ($item->OBJ_type()) {
@@ -1377,7 +1377,7 @@  discard block
 block discarded – undo
1377 1377
                             $ticket = $item->ticket();
1378 1378
                             //right now we're only handling tickets here.
1379 1379
                             //Cause its expected that only tickets will have attendees right?
1380
-                            if (! $ticket instanceof EE_Ticket) {
1380
+                            if ( ! $ticket instanceof EE_Ticket) {
1381 1381
                                 continue;
1382 1382
                             }
1383 1383
                             try {
@@ -1386,7 +1386,7 @@  discard block
 block discarded – undo
1386 1386
                                 EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1387 1387
                                 $event_name = esc_html__('Unknown Event', 'event_espresso');
1388 1388
                             }
1389
-                            $event_name   .= ' - ' . $item->get('LIN_name');
1389
+                            $event_name   .= ' - '.$item->get('LIN_name');
1390 1390
                             $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price'));
1391 1391
                             // now get all of the registrations for this transaction that use this ticket
1392 1392
                             $registrations = $ticket->get_many_related(
@@ -1394,7 +1394,7 @@  discard block
 block discarded – undo
1394 1394
                                 array(array('TXN_ID' => $this->_transaction->ID()))
1395 1395
                             );
1396 1396
                             foreach ($registrations as $registration) {
1397
-                                if (! $registration instanceof EE_Registration) {
1397
+                                if ( ! $registration instanceof EE_Registration) {
1398 1398
                                     continue;
1399 1399
                                 }
1400 1400
                                 $this->_template_args['event_attendees'][$registration->ID()]['STS_ID']
@@ -1413,12 +1413,12 @@  discard block
 block discarded – undo
1413 1413
                                     $this->_template_args['event_attendees'][$registration->ID()]['attendee']
1414 1414
                                         = $attendee->full_name();
1415 1415
                                     $this->_template_args['event_attendees'][$registration->ID()]['email']
1416
-                                        = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1416
+                                        = '<a href="mailto:'.$attendee->email().'?subject='.$event_name
1417 1417
                                           . esc_html__(
1418 1418
                                               ' Event',
1419 1419
                                               'event_espresso'
1420 1420
                                           )
1421
-                                          . '">' . $attendee->email() . '</a>';
1421
+                                          . '">'.$attendee->email().'</a>';
1422 1422
                                     $this->_template_args['event_attendees'][$registration->ID()]['address']
1423 1423
                                         = EEH_Address::format($attendee, 'inline', false, false);
1424 1424
                                 } else {
@@ -1442,7 +1442,7 @@  discard block
 block discarded – undo
1442 1442
                 TXN_ADMIN_URL
1443 1443
             );
1444 1444
             echo EEH_Template::display_template(
1445
-                TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1445
+                TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_attendees.template.php',
1446 1446
                 $this->_template_args,
1447 1447
                 true
1448 1448
             );
@@ -1478,12 +1478,12 @@  discard block
 block discarded – undo
1478 1478
         $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1479 1479
             ? $this->_transaction->primary_registration()->get_first_related('Attendee')
1480 1480
             : null;
1481
-        if (! $primary_att instanceof EE_Attendee) {
1481
+        if ( ! $primary_att instanceof EE_Attendee) {
1482 1482
             $this->_template_args['no_attendee_message'] = esc_html__(
1483 1483
                 'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1484 1484
                 'event_espresso'
1485 1485
             );
1486
-            $primary_att                                 = EEM_Attendee::instance()->create_default_object();
1486
+            $primary_att = EEM_Attendee::instance()->create_default_object();
1487 1487
         }
1488 1488
         $this->_template_args['ATT_ID']            = $primary_att->ID();
1489 1489
         $this->_template_args['prime_reg_fname']   = $primary_att->fname();
@@ -1497,7 +1497,7 @@  discard block
 block discarded – undo
1497 1497
         // get formatted address for registrant
1498 1498
         $this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1499 1499
         echo EEH_Template::display_template(
1500
-            TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1500
+            TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_registrant.template.php',
1501 1501
             $this->_template_args,
1502 1502
             true
1503 1503
         );
@@ -1522,8 +1522,8 @@  discard block
 block discarded – undo
1522 1522
             TXN_ADMIN_URL
1523 1523
         );
1524 1524
 
1525
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1526
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/
1525
+        $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_billing_info.template.php';
1526
+        echo EEH_Template::display_template($template_path, $this->_template_args, true); /**/
1527 1527
     }
1528 1528
 
1529 1529
 
@@ -1548,7 +1548,7 @@  discard block
 block discarded – undo
1548 1548
             'ee_edit_payments',
1549 1549
             'apply_payment_or_refund_from_registration_details'
1550 1550
         );
1551
-        if (! empty($valid_data) && $has_access) {
1551
+        if ( ! empty($valid_data) && $has_access) {
1552 1552
             $PAY_ID = $valid_data['PAY_ID'];
1553 1553
             //save  the new payment
1554 1554
             $payment = $this->_create_payment_from_request_data($valid_data);
@@ -1561,7 +1561,7 @@  discard block
 block discarded – undo
1561 1561
                 $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1562 1562
                 $this->_remove_existing_registration_payments($payment, $PAY_ID);
1563 1563
                 // apply payment to registrations (if applicable)
1564
-                if (! empty($REG_IDs)) {
1564
+                if ( ! empty($REG_IDs)) {
1565 1565
                     $this->_update_registration_payments($transaction, $payment, $REG_IDs);
1566 1566
                     $this->_maybe_send_notifications();
1567 1567
                     // now process status changes for the same registrations
@@ -1609,7 +1609,7 @@  discard block
 block discarded – undo
1609 1609
                 );
1610 1610
             }
1611 1611
         }
1612
-        $notices              = EE_Error::get_notices(
1612
+        $notices = EE_Error::get_notices(
1613 1613
             false,
1614 1614
             false,
1615 1615
             false
@@ -1631,14 +1631,14 @@  discard block
 block discarded – undo
1631 1631
      */
1632 1632
     protected function _validate_payment_request_data()
1633 1633
     {
1634
-        if (! isset($this->_req_data['txn_admin_payment'])) {
1634
+        if ( ! isset($this->_req_data['txn_admin_payment'])) {
1635 1635
             return false;
1636 1636
         }
1637 1637
         $payment_form = $this->_generate_payment_form_section();
1638 1638
         try {
1639 1639
             if ($payment_form->was_submitted()) {
1640 1640
                 $payment_form->receive_form_submission();
1641
-                if (! $payment_form->is_valid()) {
1641
+                if ( ! $payment_form->is_valid()) {
1642 1642
                     $submission_error_messages = array();
1643 1643
                     foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1644 1644
                         if ($validation_error instanceof EE_Validation_Error) {
@@ -1817,7 +1817,7 @@  discard block
 block discarded – undo
1817 1817
             array('Y-m-d', 'g:i a')
1818 1818
         );
1819 1819
 
1820
-        if (! $payment->save()) {
1820
+        if ( ! $payment->save()) {
1821 1821
             EE_Error::add_error(
1822 1822
                 sprintf(
1823 1823
                     esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
@@ -1882,7 +1882,7 @@  discard block
 block discarded – undo
1882 1882
         $REG_IDs = array();
1883 1883
         // grab array of IDs for specific registrations to apply changes to
1884 1884
         if (isset($this->_req_data['txn_admin_payment']['registrations'])) {
1885
-            $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations'];
1885
+            $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations'];
1886 1886
         }
1887 1887
         //nothing specified ? then get all reg IDs
1888 1888
         if (empty($REG_IDs)) {
@@ -2010,12 +2010,12 @@  discard block
 block discarded – undo
2010 2010
         // but add in some conditions regarding payment,
2011 2011
         // so that we don't apply payments to registrations that are free or have already been paid for
2012 2012
         // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
2013
-        if (! $payment->is_a_refund()) {
2013
+        if ( ! $payment->is_a_refund()) {
2014 2014
             $registration_query_where_params['REG_final_price']  = array('!=', 0);
2015 2015
             $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true);
2016 2016
         }
2017 2017
         $registrations = $transaction->registrations(array($registration_query_where_params));
2018
-        if (! empty($registrations)) {
2018
+        if ( ! empty($registrations)) {
2019 2019
             /** @type EE_Payment_Processor $payment_processor */
2020 2020
             $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2021 2021
             $payment_processor->process_registration_payments($transaction, $payment, $registrations);
@@ -2217,7 +2217,7 @@  discard block
 block discarded – undo
2217 2217
     {
2218 2218
         $registration_payment_data = array();
2219 2219
         //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2220
-        if (! empty($REG_IDs)) {
2220
+        if ( ! empty($REG_IDs)) {
2221 2221
             $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs))));
2222 2222
             foreach ($registrations as $registration) {
2223 2223
                 if ($registration instanceof EE_Registration) {
@@ -2330,13 +2330,13 @@  discard block
 block discarded – undo
2330 2330
                 'm/d/Y',
2331 2331
                 strtotime('-10 year')
2332 2332
             );
2333
-        $end_date   = isset($this->_req_data['txn-filter-end-date'])
2333
+        $end_date = isset($this->_req_data['txn-filter-end-date'])
2334 2334
             ? wp_strip_all_tags($this->_req_data['txn-filter-end-date'])
2335 2335
             : date('m/d/Y');
2336 2336
 
2337 2337
         //make sure our timestamps start and end right at the boundaries for each day
2338
-        $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2339
-        $end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2338
+        $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00';
2339
+        $end_date   = date('Y-m-d', strtotime($end_date)).' 23:59:59';
2340 2340
 
2341 2341
 
2342 2342
         //convert to timestamps
@@ -2353,7 +2353,7 @@  discard block
 block discarded – undo
2353 2353
             date('Y-m-d H:i:s', $start_date),
2354 2354
             'Y-m-d H:i:s'
2355 2355
         );
2356
-        $end_date   = EEM_Transaction::instance()->convert_datetime_for_query(
2356
+        $end_date = EEM_Transaction::instance()->convert_datetime_for_query(
2357 2357
             'TXN_timestamp',
2358 2358
             date('Y-m-d H:i:s', $end_date),
2359 2359
             'Y-m-d H:i:s'
@@ -2395,7 +2395,7 @@  discard block
 block discarded – undo
2395 2395
         }
2396 2396
 
2397 2397
         if (isset($this->_req_data['s'])) {
2398
-            $search_string = '%' . $this->_req_data['s'] . '%';
2398
+            $search_string = '%'.$this->_req_data['s'].'%';
2399 2399
             $_where['OR']  = array(
2400 2400
                 'Registration.Event.EVT_name'         => array('LIKE', $search_string),
2401 2401
                 'Registration.Event.EVT_desc'         => array('LIKE', $search_string),
@@ -2422,9 +2422,9 @@  discard block
 block discarded – undo
2422 2422
         }
2423 2423
 
2424 2424
         //failed transactions
2425
-        $failed    = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count)
2425
+        $failed    = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count)
2426 2426
                      || ($count && $view === 'failed');
2427
-        $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count)
2427
+        $abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count)
2428 2428
                      || ($count && $view === 'abandoned');
2429 2429
 
2430 2430
         if ($failed) {
Please login to merge, or discard this patch.
core/request_stack/EE_Request.core.php 1 patch
Indentation   +363 added lines, -363 removed lines patch added patch discarded remove patch
@@ -22,369 +22,369 @@
 block discarded – undo
22 22
 class EE_Request implements LegacyRequestInterface, InterminableInterface
23 23
 {
24 24
 
25
-    /**
26
-     * @var RequestInterface $request
27
-     */
28
-    private $request;
29
-
30
-    /**
31
-     * whether current request is for the admin but NOT via AJAX
32
-     *
33
-     * @var boolean $admin
34
-     */
35
-    public $admin = false;
36
-
37
-    /**
38
-     * whether current request is via AJAX
39
-     *
40
-     * @var boolean $ajax
41
-     */
42
-    public $ajax = false;
43
-
44
-    /**
45
-     * whether current request is via AJAX from the frontend of the site
46
-     *
47
-     * @var boolean $front_ajax
48
-     */
49
-    public $front_ajax = false;
50
-
51
-
52
-    /**
53
-     * @deprecated 4.9.53
54
-     * @param array $get
55
-     * @param array $post
56
-     * @param array $cookie
57
-     * @param array $server
58
-     */
59
-    public function __construct(
60
-        array $get = array(),
61
-        array $post = array(),
62
-        array $cookie = array(),
63
-        array $server = array()
64
-    ) {
65
-    }
66
-
67
-
68
-    /**
69
-     * @return RequestInterface
70
-     * @throws InvalidArgumentException
71
-     * @throws InvalidInterfaceException
72
-     * @throws InvalidDataTypeException
73
-     */
74
-    private function request()
75
-    {
76
-        if($this->request instanceof RequestInterface){
77
-            return $this->request;
78
-        }
79
-        $loader = LoaderFactory::getLoader();
80
-        $this->request = $loader->getShared('EventEspresso\core\services\request\RequestInterface');
81
-        return $this->request;
82
-    }
83
-
84
-
85
-    /**
86
-     * @param RequestInterface $request
87
-     */
88
-    public function setRequest(RequestInterface $request)
89
-    {
90
-        $this->request = $request;
91
-    }
92
-
93
-
94
-
95
-    /**
96
-     * @deprecated 4.9.53
97
-     * @return array
98
-     * @throws InvalidArgumentException
99
-     * @throws InvalidDataTypeException
100
-     * @throws InvalidInterfaceException
101
-     */
102
-    public function get_params()
103
-    {
104
-        return $this->request()->getParams();
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * @deprecated 4.9.53
111
-     * @return array
112
-     * @throws InvalidArgumentException
113
-     * @throws InvalidDataTypeException
114
-     * @throws InvalidInterfaceException
115
-     */
116
-    public function post_params()
117
-    {
118
-        return $this->request()->postParams();
119
-    }
120
-
121
-
122
-
123
-    /**
124
-     * @deprecated 4.9.53
125
-     * @return array
126
-     * @throws InvalidArgumentException
127
-     * @throws InvalidDataTypeException
128
-     * @throws InvalidInterfaceException
129
-     */
130
-    public function cookie_params()
131
-    {
132
-        return $this->request()->cookieParams();
133
-    }
134
-
135
-
136
-    /**
137
-     * @deprecated 4.9.53
138
-     * @return array
139
-     * @throws InvalidArgumentException
140
-     * @throws InvalidDataTypeException
141
-     * @throws InvalidInterfaceException
142
-     */
143
-    public function server_params()
144
-    {
145
-        return $this->request()->serverParams();
146
-    }
147
-
148
-
149
-
150
-    /**
151
-     * returns contents of $_REQUEST
152
-     *
153
-     * @deprecated 4.9.53
154
-     * @return array
155
-     * @throws InvalidArgumentException
156
-     * @throws InvalidDataTypeException
157
-     * @throws InvalidInterfaceException
158
-     */
159
-    public function params()
160
-    {
161
-        return $this->request()->requestParams();
162
-    }
163
-
164
-
165
-
166
-    /**
167
-     * @deprecated 4.9.53
168
-     * @param      $key
169
-     * @param      $value
170
-     * @param bool $override_ee
171
-     * @return void
172
-     * @throws InvalidArgumentException
173
-     * @throws InvalidDataTypeException
174
-     * @throws InvalidInterfaceException
175
-     */
176
-    public function set($key, $value, $override_ee = false)
177
-    {
178
-        $this->request()->setRequestParam($key, $value, $override_ee);
179
-    }
180
-
181
-
182
-
183
-    /**
184
-     * returns   the value for a request param if the given key exists
185
-     *
186
-     * @deprecated 4.9.53
187
-     * @param      $key
188
-     * @param null $default
189
-     * @return mixed
190
-     * @throws InvalidArgumentException
191
-     * @throws InvalidDataTypeException
192
-     * @throws InvalidInterfaceException
193
-     */
194
-    public function get($key, $default = null)
195
-    {
196
-        return $this->request()->getRequestParam($key, $default);
197
-    }
198
-
199
-
200
-
201
-    /**
202
-     * check if param exists
203
-     *
204
-     * @deprecated 4.9.53
205
-     * @param $key
206
-     * @return bool
207
-     * @throws InvalidArgumentException
208
-     * @throws InvalidDataTypeException
209
-     * @throws InvalidInterfaceException
210
-     */
211
-    public function is_set($key)
212
-    {
213
-        return $this->request()->requestParamIsSet($key);
214
-    }
215
-
216
-
217
-    /**
218
-     * remove param
219
-     *
220
-     * @deprecated 4.9.53
221
-     * @param      $key
222
-     * @param bool $unset_from_global_too
223
-     * @throws InvalidArgumentException
224
-     * @throws InvalidDataTypeException
225
-     * @throws InvalidInterfaceException
226
-     */
227
-    public function un_set($key, $unset_from_global_too = false)
228
-    {
229
-        $this->request()->unSetRequestParam($key, $unset_from_global_too);
230
-    }
231
-
232
-
233
-
234
-    /**
235
-     * @deprecated 4.9.53
236
-     * @return string
237
-     * @throws InvalidArgumentException
238
-     * @throws InvalidDataTypeException
239
-     * @throws InvalidInterfaceException
240
-     */
241
-    public function ip_address()
242
-    {
243
-        return $this->request()->ipAddress();
244
-    }
245
-
246
-
247
-    /**
248
-     * @deprecated 4.9.53
249
-     * @return bool
250
-     * @throws InvalidArgumentException
251
-     * @throws InvalidDataTypeException
252
-     * @throws InvalidInterfaceException
253
-     */
254
-    public function isAdmin()
255
-    {
256
-        return $this->request()->isAdmin();
257
-    }
258
-
259
-
260
-    /**
261
-     * @deprecated 4.9.53
262
-     * @return mixed
263
-     * @throws InvalidArgumentException
264
-     * @throws InvalidDataTypeException
265
-     * @throws InvalidInterfaceException
266
-     */
267
-    public function isAjax()
268
-    {
269
-        return $this->request()->isAjax();
270
-    }
271
-
272
-
273
-    /**
274
-     * @deprecated 4.9.53
275
-     * @return mixed
276
-     * @throws InvalidArgumentException
277
-     * @throws InvalidDataTypeException
278
-     * @throws InvalidInterfaceException
279
-     */
280
-    public function isFrontAjax()
281
-    {
282
-        return $this->request()->isFrontAjax();
283
-    }
284
-
285
-
286
-    /**
287
-     * @deprecated 4.9.53
288
-     * @return mixed|string
289
-     * @throws InvalidArgumentException
290
-     * @throws InvalidDataTypeException
291
-     * @throws InvalidInterfaceException
292
-     */
293
-    public function requestUri()
294
-    {
295
-        return $this->request()->requestUri();
296
-    }
297
-
298
-
299
-    /**
300
-     * @deprecated 4.9.53
301
-     * @return string
302
-     * @throws InvalidArgumentException
303
-     * @throws InvalidDataTypeException
304
-     * @throws InvalidInterfaceException
305
-     */
306
-    public function userAgent()
307
-    {
308
-        return $this->request()->userAgent();
309
-    }
310
-
311
-
312
-    /**
313
-     * @deprecated 4.9.53
314
-     * @param string $user_agent
315
-     * @throws InvalidArgumentException
316
-     * @throws InvalidDataTypeException
317
-     * @throws InvalidInterfaceException
318
-     */
319
-    public function setUserAgent($user_agent = '')
320
-    {
321
-        $this->request()->setUserAgent($user_agent);
322
-    }
323
-
324
-
325
-    /**
326
-     * @deprecated 4.9.53
327
-     * @return bool
328
-     * @throws InvalidArgumentException
329
-     * @throws InvalidDataTypeException
330
-     * @throws InvalidInterfaceException
331
-     */
332
-    public function isBot()
333
-    {
334
-        return $this->request()->isBot();
335
-    }
336
-
337
-
338
-    /**
339
-     * @deprecated 4.9.53
340
-     * @param bool $is_bot
341
-     * @throws InvalidArgumentException
342
-     * @throws InvalidDataTypeException
343
-     * @throws InvalidInterfaceException
344
-     */
345
-    public function setIsBot($is_bot)
346
-    {
347
-        $this->request()->setIsBot($is_bot);
348
-    }
349
-
350
-
351
-    /**
352
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
353
-     * and return the value for the first match found
354
-     * wildcards can be either of the following:
355
-     *      ? to represent a single character of any type
356
-     *      * to represent one or more characters of any type
357
-     *
358
-     * @param string     $pattern
359
-     * @param null|mixed $default
360
-     * @return false|int
361
-     * @throws InvalidArgumentException
362
-     * @throws InvalidInterfaceException
363
-     * @throws InvalidDataTypeException
364
-     */
365
-    public function getMatch($pattern, $default = null)
366
-    {
367
-        return $this->request()->getMatch($pattern, $default);
368
-    }
369
-
370
-
371
-    /**
372
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
373
-     * wildcards can be either of the following:
374
-     *      ? to represent a single character of any type
375
-     *      * to represent one or more characters of any type
376
-     * returns true if a match is found or false if not
377
-     *
378
-     * @param string $pattern
379
-     * @return false|int
380
-     * @throws InvalidArgumentException
381
-     * @throws InvalidInterfaceException
382
-     * @throws InvalidDataTypeException
383
-     */
384
-    public function matches($pattern)
385
-    {
386
-        return $this->request()->matches($pattern);
387
-    }
25
+	/**
26
+	 * @var RequestInterface $request
27
+	 */
28
+	private $request;
29
+
30
+	/**
31
+	 * whether current request is for the admin but NOT via AJAX
32
+	 *
33
+	 * @var boolean $admin
34
+	 */
35
+	public $admin = false;
36
+
37
+	/**
38
+	 * whether current request is via AJAX
39
+	 *
40
+	 * @var boolean $ajax
41
+	 */
42
+	public $ajax = false;
43
+
44
+	/**
45
+	 * whether current request is via AJAX from the frontend of the site
46
+	 *
47
+	 * @var boolean $front_ajax
48
+	 */
49
+	public $front_ajax = false;
50
+
51
+
52
+	/**
53
+	 * @deprecated 4.9.53
54
+	 * @param array $get
55
+	 * @param array $post
56
+	 * @param array $cookie
57
+	 * @param array $server
58
+	 */
59
+	public function __construct(
60
+		array $get = array(),
61
+		array $post = array(),
62
+		array $cookie = array(),
63
+		array $server = array()
64
+	) {
65
+	}
66
+
67
+
68
+	/**
69
+	 * @return RequestInterface
70
+	 * @throws InvalidArgumentException
71
+	 * @throws InvalidInterfaceException
72
+	 * @throws InvalidDataTypeException
73
+	 */
74
+	private function request()
75
+	{
76
+		if($this->request instanceof RequestInterface){
77
+			return $this->request;
78
+		}
79
+		$loader = LoaderFactory::getLoader();
80
+		$this->request = $loader->getShared('EventEspresso\core\services\request\RequestInterface');
81
+		return $this->request;
82
+	}
83
+
84
+
85
+	/**
86
+	 * @param RequestInterface $request
87
+	 */
88
+	public function setRequest(RequestInterface $request)
89
+	{
90
+		$this->request = $request;
91
+	}
92
+
93
+
94
+
95
+	/**
96
+	 * @deprecated 4.9.53
97
+	 * @return array
98
+	 * @throws InvalidArgumentException
99
+	 * @throws InvalidDataTypeException
100
+	 * @throws InvalidInterfaceException
101
+	 */
102
+	public function get_params()
103
+	{
104
+		return $this->request()->getParams();
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * @deprecated 4.9.53
111
+	 * @return array
112
+	 * @throws InvalidArgumentException
113
+	 * @throws InvalidDataTypeException
114
+	 * @throws InvalidInterfaceException
115
+	 */
116
+	public function post_params()
117
+	{
118
+		return $this->request()->postParams();
119
+	}
120
+
121
+
122
+
123
+	/**
124
+	 * @deprecated 4.9.53
125
+	 * @return array
126
+	 * @throws InvalidArgumentException
127
+	 * @throws InvalidDataTypeException
128
+	 * @throws InvalidInterfaceException
129
+	 */
130
+	public function cookie_params()
131
+	{
132
+		return $this->request()->cookieParams();
133
+	}
134
+
135
+
136
+	/**
137
+	 * @deprecated 4.9.53
138
+	 * @return array
139
+	 * @throws InvalidArgumentException
140
+	 * @throws InvalidDataTypeException
141
+	 * @throws InvalidInterfaceException
142
+	 */
143
+	public function server_params()
144
+	{
145
+		return $this->request()->serverParams();
146
+	}
147
+
148
+
149
+
150
+	/**
151
+	 * returns contents of $_REQUEST
152
+	 *
153
+	 * @deprecated 4.9.53
154
+	 * @return array
155
+	 * @throws InvalidArgumentException
156
+	 * @throws InvalidDataTypeException
157
+	 * @throws InvalidInterfaceException
158
+	 */
159
+	public function params()
160
+	{
161
+		return $this->request()->requestParams();
162
+	}
163
+
164
+
165
+
166
+	/**
167
+	 * @deprecated 4.9.53
168
+	 * @param      $key
169
+	 * @param      $value
170
+	 * @param bool $override_ee
171
+	 * @return void
172
+	 * @throws InvalidArgumentException
173
+	 * @throws InvalidDataTypeException
174
+	 * @throws InvalidInterfaceException
175
+	 */
176
+	public function set($key, $value, $override_ee = false)
177
+	{
178
+		$this->request()->setRequestParam($key, $value, $override_ee);
179
+	}
180
+
181
+
182
+
183
+	/**
184
+	 * returns   the value for a request param if the given key exists
185
+	 *
186
+	 * @deprecated 4.9.53
187
+	 * @param      $key
188
+	 * @param null $default
189
+	 * @return mixed
190
+	 * @throws InvalidArgumentException
191
+	 * @throws InvalidDataTypeException
192
+	 * @throws InvalidInterfaceException
193
+	 */
194
+	public function get($key, $default = null)
195
+	{
196
+		return $this->request()->getRequestParam($key, $default);
197
+	}
198
+
199
+
200
+
201
+	/**
202
+	 * check if param exists
203
+	 *
204
+	 * @deprecated 4.9.53
205
+	 * @param $key
206
+	 * @return bool
207
+	 * @throws InvalidArgumentException
208
+	 * @throws InvalidDataTypeException
209
+	 * @throws InvalidInterfaceException
210
+	 */
211
+	public function is_set($key)
212
+	{
213
+		return $this->request()->requestParamIsSet($key);
214
+	}
215
+
216
+
217
+	/**
218
+	 * remove param
219
+	 *
220
+	 * @deprecated 4.9.53
221
+	 * @param      $key
222
+	 * @param bool $unset_from_global_too
223
+	 * @throws InvalidArgumentException
224
+	 * @throws InvalidDataTypeException
225
+	 * @throws InvalidInterfaceException
226
+	 */
227
+	public function un_set($key, $unset_from_global_too = false)
228
+	{
229
+		$this->request()->unSetRequestParam($key, $unset_from_global_too);
230
+	}
231
+
232
+
233
+
234
+	/**
235
+	 * @deprecated 4.9.53
236
+	 * @return string
237
+	 * @throws InvalidArgumentException
238
+	 * @throws InvalidDataTypeException
239
+	 * @throws InvalidInterfaceException
240
+	 */
241
+	public function ip_address()
242
+	{
243
+		return $this->request()->ipAddress();
244
+	}
245
+
246
+
247
+	/**
248
+	 * @deprecated 4.9.53
249
+	 * @return bool
250
+	 * @throws InvalidArgumentException
251
+	 * @throws InvalidDataTypeException
252
+	 * @throws InvalidInterfaceException
253
+	 */
254
+	public function isAdmin()
255
+	{
256
+		return $this->request()->isAdmin();
257
+	}
258
+
259
+
260
+	/**
261
+	 * @deprecated 4.9.53
262
+	 * @return mixed
263
+	 * @throws InvalidArgumentException
264
+	 * @throws InvalidDataTypeException
265
+	 * @throws InvalidInterfaceException
266
+	 */
267
+	public function isAjax()
268
+	{
269
+		return $this->request()->isAjax();
270
+	}
271
+
272
+
273
+	/**
274
+	 * @deprecated 4.9.53
275
+	 * @return mixed
276
+	 * @throws InvalidArgumentException
277
+	 * @throws InvalidDataTypeException
278
+	 * @throws InvalidInterfaceException
279
+	 */
280
+	public function isFrontAjax()
281
+	{
282
+		return $this->request()->isFrontAjax();
283
+	}
284
+
285
+
286
+	/**
287
+	 * @deprecated 4.9.53
288
+	 * @return mixed|string
289
+	 * @throws InvalidArgumentException
290
+	 * @throws InvalidDataTypeException
291
+	 * @throws InvalidInterfaceException
292
+	 */
293
+	public function requestUri()
294
+	{
295
+		return $this->request()->requestUri();
296
+	}
297
+
298
+
299
+	/**
300
+	 * @deprecated 4.9.53
301
+	 * @return string
302
+	 * @throws InvalidArgumentException
303
+	 * @throws InvalidDataTypeException
304
+	 * @throws InvalidInterfaceException
305
+	 */
306
+	public function userAgent()
307
+	{
308
+		return $this->request()->userAgent();
309
+	}
310
+
311
+
312
+	/**
313
+	 * @deprecated 4.9.53
314
+	 * @param string $user_agent
315
+	 * @throws InvalidArgumentException
316
+	 * @throws InvalidDataTypeException
317
+	 * @throws InvalidInterfaceException
318
+	 */
319
+	public function setUserAgent($user_agent = '')
320
+	{
321
+		$this->request()->setUserAgent($user_agent);
322
+	}
323
+
324
+
325
+	/**
326
+	 * @deprecated 4.9.53
327
+	 * @return bool
328
+	 * @throws InvalidArgumentException
329
+	 * @throws InvalidDataTypeException
330
+	 * @throws InvalidInterfaceException
331
+	 */
332
+	public function isBot()
333
+	{
334
+		return $this->request()->isBot();
335
+	}
336
+
337
+
338
+	/**
339
+	 * @deprecated 4.9.53
340
+	 * @param bool $is_bot
341
+	 * @throws InvalidArgumentException
342
+	 * @throws InvalidDataTypeException
343
+	 * @throws InvalidInterfaceException
344
+	 */
345
+	public function setIsBot($is_bot)
346
+	{
347
+		$this->request()->setIsBot($is_bot);
348
+	}
349
+
350
+
351
+	/**
352
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
353
+	 * and return the value for the first match found
354
+	 * wildcards can be either of the following:
355
+	 *      ? to represent a single character of any type
356
+	 *      * to represent one or more characters of any type
357
+	 *
358
+	 * @param string     $pattern
359
+	 * @param null|mixed $default
360
+	 * @return false|int
361
+	 * @throws InvalidArgumentException
362
+	 * @throws InvalidInterfaceException
363
+	 * @throws InvalidDataTypeException
364
+	 */
365
+	public function getMatch($pattern, $default = null)
366
+	{
367
+		return $this->request()->getMatch($pattern, $default);
368
+	}
369
+
370
+
371
+	/**
372
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
373
+	 * wildcards can be either of the following:
374
+	 *      ? to represent a single character of any type
375
+	 *      * to represent one or more characters of any type
376
+	 * returns true if a match is found or false if not
377
+	 *
378
+	 * @param string $pattern
379
+	 * @return false|int
380
+	 * @throws InvalidArgumentException
381
+	 * @throws InvalidInterfaceException
382
+	 * @throws InvalidDataTypeException
383
+	 */
384
+	public function matches($pattern)
385
+	{
386
+		return $this->request()->matches($pattern);
387
+	}
388 388
 
389 389
 
390 390
 }
Please login to merge, or discard this patch.
core/libraries/iframe_display/Iframe.php 2 patches
Indentation   +347 added lines, -347 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 use EEH_Template;
8 8
 
9 9
 if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
10
-    exit( 'No direct script access allowed' );
10
+	exit( 'No direct script access allowed' );
11 11
 }
12 12
 
13 13
 
@@ -23,387 +23,387 @@  discard block
 block discarded – undo
23 23
 class Iframe
24 24
 {
25 25
 
26
-    /*
26
+	/*
27 27
     * HTML for notices and ajax gif
28 28
     * @var string $title
29 29
     */
30
-    protected $title = '';
30
+	protected $title = '';
31 31
 
32
-    /*
32
+	/*
33 33
     * HTML for the content being displayed
34 34
     * @var string $content
35 35
     */
36
-    protected $content = '';
36
+	protected $content = '';
37 37
 
38
-    /*
38
+	/*
39 39
     * whether or not to call wp_head() and wp_footer()
40 40
     * @var boolean $enqueue_wp_assets
41 41
     */
42
-    protected $enqueue_wp_assets = false;
42
+	protected $enqueue_wp_assets = false;
43 43
 
44
-    /*
44
+	/*
45 45
     * an array of CSS URLs
46 46
     * @var array $css
47 47
     */
48
-    protected $css = array();
48
+	protected $css = array();
49 49
 
50
-    /*
50
+	/*
51 51
     * an array of JS URLs to be set in the HTML header.
52 52
     * @var array $header_js
53 53
     */
54
-    protected $header_js = array();
54
+	protected $header_js = array();
55 55
 
56
-    /*
56
+	/*
57 57
     * an array of additional attributes to be added to <script> tags for header JS
58 58
     * @var array $footer_js
59 59
     */
60
-    protected $header_js_attributes = array();
60
+	protected $header_js_attributes = array();
61 61
 
62
-    /*
62
+	/*
63 63
     * an array of JS URLs to be displayed before the HTML </body> tag
64 64
     * @var array $footer_js
65 65
     */
66
-    protected $footer_js = array();
66
+	protected $footer_js = array();
67 67
 
68
-    /*
68
+	/*
69 69
     * an array of additional attributes to be added to <script> tags for footer JS
70 70
     * @var array $footer_js_attributes
71 71
     */
72
-    protected $footer_js_attributes = array();
72
+	protected $footer_js_attributes = array();
73 73
 
74
-    /*
74
+	/*
75 75
     * an array of JSON vars to be set in the HTML header.
76 76
     * @var array $localized_vars
77 77
     */
78
-    protected $localized_vars = array();
79
-
80
-
81
-
82
-    /**
83
-     * Iframe constructor
84
-     *
85
-     * @param string $title
86
-     * @param string $content
87
-     * @throws DomainException
88
-     */
89
-    public function __construct( $title, $content )
90
-    {
91
-        global $wp_version;
92
-        if ( ! defined( 'EE_IFRAME_DIR_URL' ) ) {
93
-            define( 'EE_IFRAME_DIR_URL', plugin_dir_url( __FILE__ ) );
94
-        }
95
-        $this->setContent( $content );
96
-        $this->setTitle( $title );
97
-        $this->addStylesheets(
98
-            apply_filters(
99
-                'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css',
100
-                array(
101
-                    'site_theme'       => get_stylesheet_directory_uri() . DS
102
-                                          . 'style.css?ver=' . EVENT_ESPRESSO_VERSION,
103
-                    'dashicons'        => includes_url( 'css/dashicons.min.css?ver=' . $wp_version ),
104
-                    'espresso_default' => EE_GLOBAL_ASSETS_URL
105
-                                          . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION,
106
-                ),
107
-                $this
108
-            )
109
-        );
110
-        $this->addScripts(
111
-            apply_filters(
112
-                'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js',
113
-                array(
114
-                    'jquery'        => includes_url( 'js/jquery/jquery.js?ver=' . $wp_version ),
115
-                    'espresso_core' => EE_GLOBAL_ASSETS_URL
116
-                                       . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION,
117
-                ),
118
-                $this
119
-            )
120
-        );
121
-        if (
122
-            apply_filters(
123
-                'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet',
124
-                false
125
-            )
126
-        ) {
127
-            $this->addStylesheets(
128
-                apply_filters(
129
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet',
130
-                    array('default_theme_stylesheet' => get_stylesheet_uri()),
131
-                    $this
132
-                )
133
-            );
134
-        }
135
-    }
136
-
137
-
138
-
139
-    /**
140
-     * @param string $title
141
-     * @throws DomainException
142
-     */
143
-    public function setTitle( $title )
144
-    {
145
-        if ( empty( $title ) ) {
146
-            throw new DomainException(
147
-                esc_html__( 'You must provide a page title in order to create an iframe.', 'event_espresso' )
148
-            );
149
-        }
150
-        $this->title = $title;
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * @param string $content
157
-     * @throws DomainException
158
-     */
159
-    public function setContent( $content )
160
-    {
161
-        if ( empty( $content ) ) {
162
-            throw new DomainException(
163
-                esc_html__( 'You must provide content in order to create an iframe.', 'event_espresso' )
164
-            );
165
-        }
166
-        $this->content = $content;
167
-    }
168
-
169
-
170
-
171
-    /**
172
-     * @param boolean $enqueue_wp_assets
173
-     */
174
-    public function setEnqueueWpAssets( $enqueue_wp_assets )
175
-    {
176
-        $this->enqueue_wp_assets = filter_var( $enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN );
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     * @param array $stylesheets
183
-     * @throws DomainException
184
-     */
185
-    public function addStylesheets( array $stylesheets )
186
-    {
187
-        if ( empty( $stylesheets ) ) {
188
-            throw new DomainException(
189
-                esc_html__(
190
-                    'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.',
191
-                    'event_espresso'
192
-                )
193
-            );
194
-        }
195
-        foreach ( $stylesheets as $handle => $stylesheet ) {
196
-            $this->css[ $handle ] = $stylesheet;
197
-        }
198
-    }
199
-
200
-
201
-
202
-    /**
203
-     * @param array $scripts
204
-     * @param bool  $add_to_header
205
-     * @throws DomainException
206
-     */
207
-    public function addScripts( array $scripts, $add_to_header = false )
208
-    {
209
-        if ( empty( $scripts ) ) {
210
-            throw new DomainException(
211
-                esc_html__(
212
-                    'A non-empty array of URLs, is required to add Javascript to an iframe.',
213
-                    'event_espresso'
214
-                )
215
-            );
216
-        }
217
-        foreach ( $scripts as $handle => $script ) {
218
-            if ( $add_to_header ) {
219
-                $this->header_js[ $handle ] = $script;
220
-            } else {
221
-                $this->footer_js[ $handle ] = $script;
222
-            }
223
-        }
224
-    }
225
-
226
-
227
-
228
-    /**
229
-     * @param array $script_attributes
230
-     * @param bool  $add_to_header
231
-     * @throws DomainException
232
-     */
233
-    public function addScriptAttributes( array $script_attributes, $add_to_header = false )
234
-    {
235
-        if ( empty($script_attributes ) ) {
236
-            throw new DomainException(
237
-                esc_html__(
238
-                    'A non-empty array of strings, is required to add attributes to iframe Javascript.',
239
-                    'event_espresso'
240
-                )
241
-            );
242
-        }
243
-        foreach ($script_attributes as $handle => $script_attribute ) {
244
-            if ( $add_to_header ) {
245
-                $this->header_js_attributes[ $handle ] = $script_attribute;
246
-            } else {
247
-                $this->footer_js_attributes[ $handle ] = $script_attribute;
248
-            }
249
-        }
250
-    }
251
-
252
-
253
-
254
-    /**
255
-     * @param array  $vars
256
-     * @param string $var_name
257
-     * @throws DomainException
258
-     */
259
-    public function addLocalizedVars( array $vars, $var_name = 'eei18n' )
260
-    {
261
-        if ( empty( $vars ) ) {
262
-            throw new DomainException(
263
-                esc_html__(
264
-                    'A non-empty array of vars, is required to add localized Javascript vars to an iframe.',
265
-                    'event_espresso'
266
-                )
267
-            );
268
-        }
269
-        foreach ( $vars as $handle => $var ) {
270
-            if ( $var_name === 'eei18n' ) {
271
-                EE_Registry::$i18n_js_strings[ $handle ] = $var;
272
-            } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') {
273
-                $this->localized_vars[ $var_name ] = $var;
274
-            } else {
275
-                if ( ! isset( $this->localized_vars[ $var_name ] ) ) {
276
-                    $this->localized_vars[ $var_name ] = array();
277
-                }
278
-                $this->localized_vars[ $var_name ][ $handle ] = $var;
279
-            }
280
-        }
281
-    }
282
-
283
-
284
-
285
-    /**
286
-     * @param string $utm_content
287
-     * @throws DomainException
288
-     */
289
-    public function display($utm_content = '')
290
-    {
291
-        $this->content .= EEH_Template::powered_by_event_espresso(
292
-            '',
293
-            '',
294
-            ! empty($utm_content) ? array('utm_content' => $utm_content) : array()
295
-        );
296
-        EE_System::do_not_cache();
297
-        echo $this->getTemplate();
298
-        exit;
299
-    }
300
-
301
-
302
-
303
-    /**
304
-     * @return string
305
-     * @throws DomainException
306
-     */
307
-    public function getTemplate()
308
-    {
309
-        return EEH_Template::display_template(
310
-            __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php',
311
-            array(
312
-                'title'             => apply_filters(
313
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title',
314
-                    $this->title,
315
-                    $this
316
-                ),
317
-                'content'           => apply_filters(
318
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content',
319
-                    $this->content,
320
-                    $this
321
-                ),
322
-                'enqueue_wp_assets' => apply_filters(
323
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets',
324
-                    $this->enqueue_wp_assets,
325
-                    $this
326
-                ),
327
-                'css'               => (array)apply_filters(
328
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls',
329
-                    $this->css,
330
-                    $this
331
-                ),
332
-                'header_js'         => (array)apply_filters(
333
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls',
334
-                    $this->header_js,
335
-                    $this
336
-                ),
337
-                'header_js_attributes' => (array) apply_filters(
338
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_attributes',
339
-                    $this->header_js_attributes,
340
-                    $this
341
-                ),
342
-                'footer_js'         => (array)apply_filters(
343
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls',
344
-                    $this->footer_js,
345
-                    $this
346
-                ),
347
-                'footer_js_attributes'         => (array)apply_filters(
348
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes',
349
-                    $this->footer_js_attributes,
350
-                    $this
351
-                ),
352
-                'eei18n'            => apply_filters(
353
-                    'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings',
354
-                    EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(),
355
-                    $this
356
-                ),
357
-                'notices'           => EEH_Template::display_template(
358
-                    EE_TEMPLATES . 'espresso-ajax-notices.template.php',
359
-                    array(),
360
-                    true
361
-                ),
362
-            ),
363
-            true,
364
-            true
365
-        );
366
-    }
367
-
368
-
369
-
370
-    /**
371
-     * localizeJsonVars
372
-     *
373
-     * @return string
374
-     */
375
-    public function localizeJsonVars()
376
-    {
377
-        $JSON = '';
378
-        foreach ( (array)$this->localized_vars as $var_name => $vars ) {
379
-            $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars );
380
-            $JSON .= "/* <![CDATA[ */ var {$var_name} = ";
381
-            $JSON .= wp_json_encode( $this->localized_vars[ $var_name ] );
382
-            $JSON .= '; /* ]]> */';
383
-        }
384
-        return $JSON;
385
-    }
386
-
387
-
388
-
389
-    /**
390
-     * @param bool|int|float|string|array $var
391
-     * @return array
392
-     */
393
-    public function encodeJsonVars( $var )
394
-    {
395
-        if ( is_array( $var ) ) {
396
-            $localized_vars = array();
397
-            foreach ( (array)$var as $key => $value ) {
398
-                $localized_vars[ $key ] = $this->encodeJsonVars( $value );
399
-            }
400
-            return $localized_vars;
401
-        }
402
-        if ( is_scalar( $var ) ) {
403
-            return html_entity_decode( (string)$var, ENT_QUOTES, 'UTF-8' );
404
-        }
405
-        return null;
406
-    }
78
+	protected $localized_vars = array();
79
+
80
+
81
+
82
+	/**
83
+	 * Iframe constructor
84
+	 *
85
+	 * @param string $title
86
+	 * @param string $content
87
+	 * @throws DomainException
88
+	 */
89
+	public function __construct( $title, $content )
90
+	{
91
+		global $wp_version;
92
+		if ( ! defined( 'EE_IFRAME_DIR_URL' ) ) {
93
+			define( 'EE_IFRAME_DIR_URL', plugin_dir_url( __FILE__ ) );
94
+		}
95
+		$this->setContent( $content );
96
+		$this->setTitle( $title );
97
+		$this->addStylesheets(
98
+			apply_filters(
99
+				'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css',
100
+				array(
101
+					'site_theme'       => get_stylesheet_directory_uri() . DS
102
+										  . 'style.css?ver=' . EVENT_ESPRESSO_VERSION,
103
+					'dashicons'        => includes_url( 'css/dashicons.min.css?ver=' . $wp_version ),
104
+					'espresso_default' => EE_GLOBAL_ASSETS_URL
105
+										  . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION,
106
+				),
107
+				$this
108
+			)
109
+		);
110
+		$this->addScripts(
111
+			apply_filters(
112
+				'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js',
113
+				array(
114
+					'jquery'        => includes_url( 'js/jquery/jquery.js?ver=' . $wp_version ),
115
+					'espresso_core' => EE_GLOBAL_ASSETS_URL
116
+									   . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION,
117
+				),
118
+				$this
119
+			)
120
+		);
121
+		if (
122
+			apply_filters(
123
+				'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet',
124
+				false
125
+			)
126
+		) {
127
+			$this->addStylesheets(
128
+				apply_filters(
129
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet',
130
+					array('default_theme_stylesheet' => get_stylesheet_uri()),
131
+					$this
132
+				)
133
+			);
134
+		}
135
+	}
136
+
137
+
138
+
139
+	/**
140
+	 * @param string $title
141
+	 * @throws DomainException
142
+	 */
143
+	public function setTitle( $title )
144
+	{
145
+		if ( empty( $title ) ) {
146
+			throw new DomainException(
147
+				esc_html__( 'You must provide a page title in order to create an iframe.', 'event_espresso' )
148
+			);
149
+		}
150
+		$this->title = $title;
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * @param string $content
157
+	 * @throws DomainException
158
+	 */
159
+	public function setContent( $content )
160
+	{
161
+		if ( empty( $content ) ) {
162
+			throw new DomainException(
163
+				esc_html__( 'You must provide content in order to create an iframe.', 'event_espresso' )
164
+			);
165
+		}
166
+		$this->content = $content;
167
+	}
168
+
169
+
170
+
171
+	/**
172
+	 * @param boolean $enqueue_wp_assets
173
+	 */
174
+	public function setEnqueueWpAssets( $enqueue_wp_assets )
175
+	{
176
+		$this->enqueue_wp_assets = filter_var( $enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN );
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 * @param array $stylesheets
183
+	 * @throws DomainException
184
+	 */
185
+	public function addStylesheets( array $stylesheets )
186
+	{
187
+		if ( empty( $stylesheets ) ) {
188
+			throw new DomainException(
189
+				esc_html__(
190
+					'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.',
191
+					'event_espresso'
192
+				)
193
+			);
194
+		}
195
+		foreach ( $stylesheets as $handle => $stylesheet ) {
196
+			$this->css[ $handle ] = $stylesheet;
197
+		}
198
+	}
199
+
200
+
201
+
202
+	/**
203
+	 * @param array $scripts
204
+	 * @param bool  $add_to_header
205
+	 * @throws DomainException
206
+	 */
207
+	public function addScripts( array $scripts, $add_to_header = false )
208
+	{
209
+		if ( empty( $scripts ) ) {
210
+			throw new DomainException(
211
+				esc_html__(
212
+					'A non-empty array of URLs, is required to add Javascript to an iframe.',
213
+					'event_espresso'
214
+				)
215
+			);
216
+		}
217
+		foreach ( $scripts as $handle => $script ) {
218
+			if ( $add_to_header ) {
219
+				$this->header_js[ $handle ] = $script;
220
+			} else {
221
+				$this->footer_js[ $handle ] = $script;
222
+			}
223
+		}
224
+	}
225
+
226
+
227
+
228
+	/**
229
+	 * @param array $script_attributes
230
+	 * @param bool  $add_to_header
231
+	 * @throws DomainException
232
+	 */
233
+	public function addScriptAttributes( array $script_attributes, $add_to_header = false )
234
+	{
235
+		if ( empty($script_attributes ) ) {
236
+			throw new DomainException(
237
+				esc_html__(
238
+					'A non-empty array of strings, is required to add attributes to iframe Javascript.',
239
+					'event_espresso'
240
+				)
241
+			);
242
+		}
243
+		foreach ($script_attributes as $handle => $script_attribute ) {
244
+			if ( $add_to_header ) {
245
+				$this->header_js_attributes[ $handle ] = $script_attribute;
246
+			} else {
247
+				$this->footer_js_attributes[ $handle ] = $script_attribute;
248
+			}
249
+		}
250
+	}
251
+
252
+
253
+
254
+	/**
255
+	 * @param array  $vars
256
+	 * @param string $var_name
257
+	 * @throws DomainException
258
+	 */
259
+	public function addLocalizedVars( array $vars, $var_name = 'eei18n' )
260
+	{
261
+		if ( empty( $vars ) ) {
262
+			throw new DomainException(
263
+				esc_html__(
264
+					'A non-empty array of vars, is required to add localized Javascript vars to an iframe.',
265
+					'event_espresso'
266
+				)
267
+			);
268
+		}
269
+		foreach ( $vars as $handle => $var ) {
270
+			if ( $var_name === 'eei18n' ) {
271
+				EE_Registry::$i18n_js_strings[ $handle ] = $var;
272
+			} elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') {
273
+				$this->localized_vars[ $var_name ] = $var;
274
+			} else {
275
+				if ( ! isset( $this->localized_vars[ $var_name ] ) ) {
276
+					$this->localized_vars[ $var_name ] = array();
277
+				}
278
+				$this->localized_vars[ $var_name ][ $handle ] = $var;
279
+			}
280
+		}
281
+	}
282
+
283
+
284
+
285
+	/**
286
+	 * @param string $utm_content
287
+	 * @throws DomainException
288
+	 */
289
+	public function display($utm_content = '')
290
+	{
291
+		$this->content .= EEH_Template::powered_by_event_espresso(
292
+			'',
293
+			'',
294
+			! empty($utm_content) ? array('utm_content' => $utm_content) : array()
295
+		);
296
+		EE_System::do_not_cache();
297
+		echo $this->getTemplate();
298
+		exit;
299
+	}
300
+
301
+
302
+
303
+	/**
304
+	 * @return string
305
+	 * @throws DomainException
306
+	 */
307
+	public function getTemplate()
308
+	{
309
+		return EEH_Template::display_template(
310
+			__DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php',
311
+			array(
312
+				'title'             => apply_filters(
313
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title',
314
+					$this->title,
315
+					$this
316
+				),
317
+				'content'           => apply_filters(
318
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content',
319
+					$this->content,
320
+					$this
321
+				),
322
+				'enqueue_wp_assets' => apply_filters(
323
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets',
324
+					$this->enqueue_wp_assets,
325
+					$this
326
+				),
327
+				'css'               => (array)apply_filters(
328
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls',
329
+					$this->css,
330
+					$this
331
+				),
332
+				'header_js'         => (array)apply_filters(
333
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls',
334
+					$this->header_js,
335
+					$this
336
+				),
337
+				'header_js_attributes' => (array) apply_filters(
338
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_attributes',
339
+					$this->header_js_attributes,
340
+					$this
341
+				),
342
+				'footer_js'         => (array)apply_filters(
343
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls',
344
+					$this->footer_js,
345
+					$this
346
+				),
347
+				'footer_js_attributes'         => (array)apply_filters(
348
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes',
349
+					$this->footer_js_attributes,
350
+					$this
351
+				),
352
+				'eei18n'            => apply_filters(
353
+					'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings',
354
+					EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(),
355
+					$this
356
+				),
357
+				'notices'           => EEH_Template::display_template(
358
+					EE_TEMPLATES . 'espresso-ajax-notices.template.php',
359
+					array(),
360
+					true
361
+				),
362
+			),
363
+			true,
364
+			true
365
+		);
366
+	}
367
+
368
+
369
+
370
+	/**
371
+	 * localizeJsonVars
372
+	 *
373
+	 * @return string
374
+	 */
375
+	public function localizeJsonVars()
376
+	{
377
+		$JSON = '';
378
+		foreach ( (array)$this->localized_vars as $var_name => $vars ) {
379
+			$this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars );
380
+			$JSON .= "/* <![CDATA[ */ var {$var_name} = ";
381
+			$JSON .= wp_json_encode( $this->localized_vars[ $var_name ] );
382
+			$JSON .= '; /* ]]> */';
383
+		}
384
+		return $JSON;
385
+	}
386
+
387
+
388
+
389
+	/**
390
+	 * @param bool|int|float|string|array $var
391
+	 * @return array
392
+	 */
393
+	public function encodeJsonVars( $var )
394
+	{
395
+		if ( is_array( $var ) ) {
396
+			$localized_vars = array();
397
+			foreach ( (array)$var as $key => $value ) {
398
+				$localized_vars[ $key ] = $this->encodeJsonVars( $value );
399
+			}
400
+			return $localized_vars;
401
+		}
402
+		if ( is_scalar( $var ) ) {
403
+			return html_entity_decode( (string)$var, ENT_QUOTES, 'UTF-8' );
404
+		}
405
+		return null;
406
+	}
407 407
 
408 408
 
409 409
 
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -6,8 +6,8 @@  discard block
 block discarded – undo
6 6
 use EE_System;
7 7
 use EEH_Template;
8 8
 
9
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
10
-    exit( 'No direct script access allowed' );
9
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
10
+    exit('No direct script access allowed');
11 11
 }
12 12
 
13 13
 
@@ -86,23 +86,23 @@  discard block
 block discarded – undo
86 86
      * @param string $content
87 87
      * @throws DomainException
88 88
      */
89
-    public function __construct( $title, $content )
89
+    public function __construct($title, $content)
90 90
     {
91 91
         global $wp_version;
92
-        if ( ! defined( 'EE_IFRAME_DIR_URL' ) ) {
93
-            define( 'EE_IFRAME_DIR_URL', plugin_dir_url( __FILE__ ) );
92
+        if ( ! defined('EE_IFRAME_DIR_URL')) {
93
+            define('EE_IFRAME_DIR_URL', plugin_dir_url(__FILE__));
94 94
         }
95
-        $this->setContent( $content );
96
-        $this->setTitle( $title );
95
+        $this->setContent($content);
96
+        $this->setTitle($title);
97 97
         $this->addStylesheets(
98 98
             apply_filters(
99 99
                 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css',
100 100
                 array(
101
-                    'site_theme'       => get_stylesheet_directory_uri() . DS
102
-                                          . 'style.css?ver=' . EVENT_ESPRESSO_VERSION,
103
-                    'dashicons'        => includes_url( 'css/dashicons.min.css?ver=' . $wp_version ),
101
+                    'site_theme'       => get_stylesheet_directory_uri().DS
102
+                                          . 'style.css?ver='.EVENT_ESPRESSO_VERSION,
103
+                    'dashicons'        => includes_url('css/dashicons.min.css?ver='.$wp_version),
104 104
                     'espresso_default' => EE_GLOBAL_ASSETS_URL
105
-                                          . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION,
105
+                                          . 'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION,
106 106
                 ),
107 107
                 $this
108 108
             )
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
             apply_filters(
112 112
                 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js',
113 113
                 array(
114
-                    'jquery'        => includes_url( 'js/jquery/jquery.js?ver=' . $wp_version ),
114
+                    'jquery'        => includes_url('js/jquery/jquery.js?ver='.$wp_version),
115 115
                     'espresso_core' => EE_GLOBAL_ASSETS_URL
116
-                                       . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION,
116
+                                       . 'scripts/espresso_core.js?ver='.EVENT_ESPRESSO_VERSION,
117 117
                 ),
118 118
                 $this
119 119
             )
@@ -140,11 +140,11 @@  discard block
 block discarded – undo
140 140
      * @param string $title
141 141
      * @throws DomainException
142 142
      */
143
-    public function setTitle( $title )
143
+    public function setTitle($title)
144 144
     {
145
-        if ( empty( $title ) ) {
145
+        if (empty($title)) {
146 146
             throw new DomainException(
147
-                esc_html__( 'You must provide a page title in order to create an iframe.', 'event_espresso' )
147
+                esc_html__('You must provide a page title in order to create an iframe.', 'event_espresso')
148 148
             );
149 149
         }
150 150
         $this->title = $title;
@@ -156,11 +156,11 @@  discard block
 block discarded – undo
156 156
      * @param string $content
157 157
      * @throws DomainException
158 158
      */
159
-    public function setContent( $content )
159
+    public function setContent($content)
160 160
     {
161
-        if ( empty( $content ) ) {
161
+        if (empty($content)) {
162 162
             throw new DomainException(
163
-                esc_html__( 'You must provide content in order to create an iframe.', 'event_espresso' )
163
+                esc_html__('You must provide content in order to create an iframe.', 'event_espresso')
164 164
             );
165 165
         }
166 166
         $this->content = $content;
@@ -171,9 +171,9 @@  discard block
 block discarded – undo
171 171
     /**
172 172
      * @param boolean $enqueue_wp_assets
173 173
      */
174
-    public function setEnqueueWpAssets( $enqueue_wp_assets )
174
+    public function setEnqueueWpAssets($enqueue_wp_assets)
175 175
     {
176
-        $this->enqueue_wp_assets = filter_var( $enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN );
176
+        $this->enqueue_wp_assets = filter_var($enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN);
177 177
     }
178 178
 
179 179
 
@@ -182,9 +182,9 @@  discard block
 block discarded – undo
182 182
      * @param array $stylesheets
183 183
      * @throws DomainException
184 184
      */
185
-    public function addStylesheets( array $stylesheets )
185
+    public function addStylesheets(array $stylesheets)
186 186
     {
187
-        if ( empty( $stylesheets ) ) {
187
+        if (empty($stylesheets)) {
188 188
             throw new DomainException(
189 189
                 esc_html__(
190 190
                     'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.',
@@ -192,8 +192,8 @@  discard block
 block discarded – undo
192 192
                 )
193 193
             );
194 194
         }
195
-        foreach ( $stylesheets as $handle => $stylesheet ) {
196
-            $this->css[ $handle ] = $stylesheet;
195
+        foreach ($stylesheets as $handle => $stylesheet) {
196
+            $this->css[$handle] = $stylesheet;
197 197
         }
198 198
     }
199 199
 
@@ -204,9 +204,9 @@  discard block
 block discarded – undo
204 204
      * @param bool  $add_to_header
205 205
      * @throws DomainException
206 206
      */
207
-    public function addScripts( array $scripts, $add_to_header = false )
207
+    public function addScripts(array $scripts, $add_to_header = false)
208 208
     {
209
-        if ( empty( $scripts ) ) {
209
+        if (empty($scripts)) {
210 210
             throw new DomainException(
211 211
                 esc_html__(
212 212
                     'A non-empty array of URLs, is required to add Javascript to an iframe.',
@@ -214,11 +214,11 @@  discard block
 block discarded – undo
214 214
                 )
215 215
             );
216 216
         }
217
-        foreach ( $scripts as $handle => $script ) {
218
-            if ( $add_to_header ) {
219
-                $this->header_js[ $handle ] = $script;
217
+        foreach ($scripts as $handle => $script) {
218
+            if ($add_to_header) {
219
+                $this->header_js[$handle] = $script;
220 220
             } else {
221
-                $this->footer_js[ $handle ] = $script;
221
+                $this->footer_js[$handle] = $script;
222 222
             }
223 223
         }
224 224
     }
@@ -230,9 +230,9 @@  discard block
 block discarded – undo
230 230
      * @param bool  $add_to_header
231 231
      * @throws DomainException
232 232
      */
233
-    public function addScriptAttributes( array $script_attributes, $add_to_header = false )
233
+    public function addScriptAttributes(array $script_attributes, $add_to_header = false)
234 234
     {
235
-        if ( empty($script_attributes ) ) {
235
+        if (empty($script_attributes)) {
236 236
             throw new DomainException(
237 237
                 esc_html__(
238 238
                     'A non-empty array of strings, is required to add attributes to iframe Javascript.',
@@ -240,11 +240,11 @@  discard block
 block discarded – undo
240 240
                 )
241 241
             );
242 242
         }
243
-        foreach ($script_attributes as $handle => $script_attribute ) {
244
-            if ( $add_to_header ) {
245
-                $this->header_js_attributes[ $handle ] = $script_attribute;
243
+        foreach ($script_attributes as $handle => $script_attribute) {
244
+            if ($add_to_header) {
245
+                $this->header_js_attributes[$handle] = $script_attribute;
246 246
             } else {
247
-                $this->footer_js_attributes[ $handle ] = $script_attribute;
247
+                $this->footer_js_attributes[$handle] = $script_attribute;
248 248
             }
249 249
         }
250 250
     }
@@ -256,9 +256,9 @@  discard block
 block discarded – undo
256 256
      * @param string $var_name
257 257
      * @throws DomainException
258 258
      */
259
-    public function addLocalizedVars( array $vars, $var_name = 'eei18n' )
259
+    public function addLocalizedVars(array $vars, $var_name = 'eei18n')
260 260
     {
261
-        if ( empty( $vars ) ) {
261
+        if (empty($vars)) {
262 262
             throw new DomainException(
263 263
                 esc_html__(
264 264
                     'A non-empty array of vars, is required to add localized Javascript vars to an iframe.',
@@ -266,16 +266,16 @@  discard block
 block discarded – undo
266 266
                 )
267 267
             );
268 268
         }
269
-        foreach ( $vars as $handle => $var ) {
270
-            if ( $var_name === 'eei18n' ) {
271
-                EE_Registry::$i18n_js_strings[ $handle ] = $var;
269
+        foreach ($vars as $handle => $var) {
270
+            if ($var_name === 'eei18n') {
271
+                EE_Registry::$i18n_js_strings[$handle] = $var;
272 272
             } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') {
273
-                $this->localized_vars[ $var_name ] = $var;
273
+                $this->localized_vars[$var_name] = $var;
274 274
             } else {
275
-                if ( ! isset( $this->localized_vars[ $var_name ] ) ) {
276
-                    $this->localized_vars[ $var_name ] = array();
275
+                if ( ! isset($this->localized_vars[$var_name])) {
276
+                    $this->localized_vars[$var_name] = array();
277 277
                 }
278
-                $this->localized_vars[ $var_name ][ $handle ] = $var;
278
+                $this->localized_vars[$var_name][$handle] = $var;
279 279
             }
280 280
         }
281 281
     }
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
     public function getTemplate()
308 308
     {
309 309
         return EEH_Template::display_template(
310
-            __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php',
310
+            __DIR__.DIRECTORY_SEPARATOR.'iframe_wrapper.template.php',
311 311
             array(
312 312
                 'title'             => apply_filters(
313 313
                     'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title',
@@ -324,12 +324,12 @@  discard block
 block discarded – undo
324 324
                     $this->enqueue_wp_assets,
325 325
                     $this
326 326
                 ),
327
-                'css'               => (array)apply_filters(
327
+                'css'               => (array) apply_filters(
328 328
                     'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls',
329 329
                     $this->css,
330 330
                     $this
331 331
                 ),
332
-                'header_js'         => (array)apply_filters(
332
+                'header_js'         => (array) apply_filters(
333 333
                     'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls',
334 334
                     $this->header_js,
335 335
                     $this
@@ -339,23 +339,23 @@  discard block
 block discarded – undo
339 339
                     $this->header_js_attributes,
340 340
                     $this
341 341
                 ),
342
-                'footer_js'         => (array)apply_filters(
342
+                'footer_js'         => (array) apply_filters(
343 343
                     'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls',
344 344
                     $this->footer_js,
345 345
                     $this
346 346
                 ),
347
-                'footer_js_attributes'         => (array)apply_filters(
347
+                'footer_js_attributes'         => (array) apply_filters(
348 348
                     'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes',
349 349
                     $this->footer_js_attributes,
350 350
                     $this
351 351
                 ),
352 352
                 'eei18n'            => apply_filters(
353 353
                     'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings',
354
-                    EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(),
354
+                    EE_Registry::localize_i18n_js_strings().$this->localizeJsonVars(),
355 355
                     $this
356 356
                 ),
357 357
                 'notices'           => EEH_Template::display_template(
358
-                    EE_TEMPLATES . 'espresso-ajax-notices.template.php',
358
+                    EE_TEMPLATES.'espresso-ajax-notices.template.php',
359 359
                     array(),
360 360
                     true
361 361
                 ),
@@ -375,10 +375,10 @@  discard block
 block discarded – undo
375 375
     public function localizeJsonVars()
376 376
     {
377 377
         $JSON = '';
378
-        foreach ( (array)$this->localized_vars as $var_name => $vars ) {
379
-            $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars );
378
+        foreach ((array) $this->localized_vars as $var_name => $vars) {
379
+            $this->localized_vars[$var_name] = $this->encodeJsonVars($vars);
380 380
             $JSON .= "/* <![CDATA[ */ var {$var_name} = ";
381
-            $JSON .= wp_json_encode( $this->localized_vars[ $var_name ] );
381
+            $JSON .= wp_json_encode($this->localized_vars[$var_name]);
382 382
             $JSON .= '; /* ]]> */';
383 383
         }
384 384
         return $JSON;
@@ -390,17 +390,17 @@  discard block
 block discarded – undo
390 390
      * @param bool|int|float|string|array $var
391 391
      * @return array
392 392
      */
393
-    public function encodeJsonVars( $var )
393
+    public function encodeJsonVars($var)
394 394
     {
395
-        if ( is_array( $var ) ) {
395
+        if (is_array($var)) {
396 396
             $localized_vars = array();
397
-            foreach ( (array)$var as $key => $value ) {
398
-                $localized_vars[ $key ] = $this->encodeJsonVars( $value );
397
+            foreach ((array) $var as $key => $value) {
398
+                $localized_vars[$key] = $this->encodeJsonVars($value);
399 399
             }
400 400
             return $localized_vars;
401 401
         }
402
-        if ( is_scalar( $var ) ) {
403
-            return html_entity_decode( (string)$var, ENT_QUOTES, 'UTF-8' );
402
+        if (is_scalar($var)) {
403
+            return html_entity_decode((string) $var, ENT_QUOTES, 'UTF-8');
404 404
         }
405 405
         return null;
406 406
     }
Please login to merge, or discard this patch.