Completed
Branch dev (b9e2d5)
by
unknown
19:26 queued 17:20
created
admin/extend/messages/espresso_events_Messages_Hooks_Extend.class.php 1 patch
Indentation   +265 added lines, -265 removed lines patch added patch discarded remove patch
@@ -12,274 +12,274 @@
 block discarded – undo
12 12
  */
13 13
 class espresso_events_Messages_Hooks_Extend extends espresso_events_Messages_Hooks
14 14
 {
15
-    /**
16
-     * espresso_events_Messages_Hooks_Extend constructor.
17
-     *
18
-     * @param \EE_Admin_Page $admin_page
19
-     */
20
-    public function __construct(EE_Admin_Page $admin_page)
21
-    {
22
-        /**
23
-         * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages
24
-         */
25
-        if (
26
-            ! EE_Registry::instance()->CAP->current_user_can(
27
-                'ee_edit_messages',
28
-                'messages_events_editor_metabox'
29
-            )
30
-        ) {
31
-            return;
32
-        }
33
-        add_filter(
34
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
35
-            array($this, 'caf_updates'),
36
-            10
37
-        );
38
-        add_action(
39
-            'AHEE__Extend_Events_Admin_Page___duplicate_event__after',
40
-            array($this, 'duplicate_custom_message_settings'),
41
-            10,
42
-            2
43
-        );
44
-        parent::__construct($admin_page);
45
-    }
46
-
47
-
48
-    /**
49
-     * extending the properties set in espresso_events_Messages_Hooks
50
-     *
51
-     * @access protected
52
-     * @return void
53
-     */
54
-    protected function _extend_properties()
55
-    {
56
-        define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/');
57
-        $this->_ajax_func = array(
58
-            'ee_msgs_create_new_custom' => 'create_new_custom',
59
-        );
60
-        $this->_metaboxes = array(
61
-            0 => array(
62
-                'page_route' => array('edit', 'create_new'),
63
-                'func'       => 'messages_metabox',
64
-                'label'      => esc_html__('Notifications', 'event_espresso'),
65
-                'priority'   => 'high',
66
-            ),
67
-        );
68
-
69
-        // see explanation for layout in EE_Admin_Hooks
70
-        $this->_scripts_styles = array(
71
-            'registers' => array(
72
-                'events_msg_admin'     => array(
73
-                    'url'     => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js',
74
-                    'depends' => array('ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'),
75
-                ),
76
-                'events_msg_admin_css' => array(
77
-                    'url'  => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css',
78
-                    'type' => 'css',
79
-                ),
80
-            ),
81
-            'enqueues'  => array(
82
-                'events_msg_admin'     => array('edit', 'create_new'),
83
-                'events_msg_admin_css' => array('edit', 'create_new'),
84
-            ),
85
-        );
86
-    }
87
-
88
-
89
-    public function caf_updates($update_callbacks)
90
-    {
91
-        $update_callbacks[] = array($this, 'attach_evt_message_templates');
92
-        return $update_callbacks;
93
-    }
94
-
95
-
96
-    /**
97
-     * Handles attaching Message Templates to the Event on save.
98
-     *
99
-     * @param  EE_Event $event EE event object
100
-     * @param  array    $data  The request data from the form
101
-     * @return bool success or fail
102
-     * @throws EE_Error
103
-     */
104
-    public function attach_evt_message_templates($event, $data)
105
-    {
106
-        // first we remove all existing relations on the Event for message types.
107
-        $event->_remove_relations('Message_Template_Group');
108
-        // now let's just loop through the selected templates and add relations!
109
-        if (isset($data['event_message_templates_relation'])) {
110
-            foreach ($data['event_message_templates_relation'] as $grp_ID) {
111
-                $event->_add_relation_to($grp_ID, 'Message_Template_Group');
112
-            }
113
-        }
114
-        // now save
115
-        return $event->save();
116
-    }
117
-
118
-
119
-    /**
120
-     * @param $event
121
-     * @param $callback_args
122
-     * @return string
123
-     * @throws \EE_Error
124
-     */
125
-    public function messages_metabox($event, $callback_args)
126
-    {
127
-        // let's get the active messengers (b/c messenger objects have the active message templates)
128
-        // convert 'evt_id' to 'EVT_ID'
129
-        $this->_req_data['EVT_ID'] = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null;
130
-        $this->_req_data['EVT_ID'] = isset($this->_req_data['post']) && empty($this->_req_data['EVT_ID'])
131
-            ? $this->_req_data['post']
132
-            : $this->_req_data['EVT_ID'];
133
-
134
-        $this->_req_data['EVT_ID'] = empty($this->_req_data['EVT_ID']) && isset($this->_req_data['evt_id'])
135
-            ? $this->_req_data['evt_id']
136
-            : $this->_req_data['EVT_ID'];
137
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
138
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
139
-        $active_messengers = $message_resource_manager->active_messengers();
140
-        $tabs = array();
141
-
142
-        // empty messengers?
143
-        // Note message types will always have at least one available because every messenger has a default message type
144
-        // associated with it (payment) if no other message types are selected.
145
-        if (empty($active_messengers)) {
146
-            $msg_activate_url = EE_Admin_Page::add_query_args_and_nonce(
147
-                array('action' => 'settings'),
148
-                EE_MSG_ADMIN_URL
149
-            );
150
-            $error_msg = sprintf(
151
-                esc_html__(
152
-                    'There are no active messengers. So no notifications will go out for %1$sany%2$s events.  You will want to %3$sActivate a Messenger%4$s.',
153
-                    'event_espresso'
154
-                ),
155
-                '<strong>',
156
-                '</strong>',
157
-                '<a href="' . $msg_activate_url . '">',
158
-                '</a>'
159
-            );
160
-            $error_content = '<div class="error"><p>' . $error_msg . '</p></div>';
161
-            $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>';
162
-
163
-            echo $error_content;
164
-            echo $internal_content;
165
-            return '';
166
-        }
167
-
168
-        $event_id = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null;
169
-        // get content for active messengers
170
-        foreach ($active_messengers as $name => $messenger) {
171
-            // first check if there are any active message types for this messenger.
172
-            $active_mts = $message_resource_manager->get_active_message_types_for_messenger($name);
173
-            if (empty($active_mts)) {
174
-                continue;
175
-            }
176
-
177
-            $tab_content = $messenger->get_messenger_admin_page_content(
178
-                'events',
179
-                'edit',
180
-                array('event' => $event_id)
181
-            );
182
-
183
-            if (! empty($tab_content)) {
184
-                $tabs[ $name ] = $tab_content;
185
-            }
186
-        }
187
-
188
-
189
-        // we want this to be tabbed content so let's use the EEH_Tabbed_Content::display helper.
190
-        $tabbed_content = EEH_Tabbed_Content::display($tabs);
191
-        if ($tabbed_content instanceof WP_Error) {
192
-            $tabbed_content = $tabbed_content->get_error_message();
193
-        }
194
-
195
-        $notices = '
15
+	/**
16
+	 * espresso_events_Messages_Hooks_Extend constructor.
17
+	 *
18
+	 * @param \EE_Admin_Page $admin_page
19
+	 */
20
+	public function __construct(EE_Admin_Page $admin_page)
21
+	{
22
+		/**
23
+		 * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages
24
+		 */
25
+		if (
26
+			! EE_Registry::instance()->CAP->current_user_can(
27
+				'ee_edit_messages',
28
+				'messages_events_editor_metabox'
29
+			)
30
+		) {
31
+			return;
32
+		}
33
+		add_filter(
34
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
35
+			array($this, 'caf_updates'),
36
+			10
37
+		);
38
+		add_action(
39
+			'AHEE__Extend_Events_Admin_Page___duplicate_event__after',
40
+			array($this, 'duplicate_custom_message_settings'),
41
+			10,
42
+			2
43
+		);
44
+		parent::__construct($admin_page);
45
+	}
46
+
47
+
48
+	/**
49
+	 * extending the properties set in espresso_events_Messages_Hooks
50
+	 *
51
+	 * @access protected
52
+	 * @return void
53
+	 */
54
+	protected function _extend_properties()
55
+	{
56
+		define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/');
57
+		$this->_ajax_func = array(
58
+			'ee_msgs_create_new_custom' => 'create_new_custom',
59
+		);
60
+		$this->_metaboxes = array(
61
+			0 => array(
62
+				'page_route' => array('edit', 'create_new'),
63
+				'func'       => 'messages_metabox',
64
+				'label'      => esc_html__('Notifications', 'event_espresso'),
65
+				'priority'   => 'high',
66
+			),
67
+		);
68
+
69
+		// see explanation for layout in EE_Admin_Hooks
70
+		$this->_scripts_styles = array(
71
+			'registers' => array(
72
+				'events_msg_admin'     => array(
73
+					'url'     => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js',
74
+					'depends' => array('ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'),
75
+				),
76
+				'events_msg_admin_css' => array(
77
+					'url'  => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css',
78
+					'type' => 'css',
79
+				),
80
+			),
81
+			'enqueues'  => array(
82
+				'events_msg_admin'     => array('edit', 'create_new'),
83
+				'events_msg_admin_css' => array('edit', 'create_new'),
84
+			),
85
+		);
86
+	}
87
+
88
+
89
+	public function caf_updates($update_callbacks)
90
+	{
91
+		$update_callbacks[] = array($this, 'attach_evt_message_templates');
92
+		return $update_callbacks;
93
+	}
94
+
95
+
96
+	/**
97
+	 * Handles attaching Message Templates to the Event on save.
98
+	 *
99
+	 * @param  EE_Event $event EE event object
100
+	 * @param  array    $data  The request data from the form
101
+	 * @return bool success or fail
102
+	 * @throws EE_Error
103
+	 */
104
+	public function attach_evt_message_templates($event, $data)
105
+	{
106
+		// first we remove all existing relations on the Event for message types.
107
+		$event->_remove_relations('Message_Template_Group');
108
+		// now let's just loop through the selected templates and add relations!
109
+		if (isset($data['event_message_templates_relation'])) {
110
+			foreach ($data['event_message_templates_relation'] as $grp_ID) {
111
+				$event->_add_relation_to($grp_ID, 'Message_Template_Group');
112
+			}
113
+		}
114
+		// now save
115
+		return $event->save();
116
+	}
117
+
118
+
119
+	/**
120
+	 * @param $event
121
+	 * @param $callback_args
122
+	 * @return string
123
+	 * @throws \EE_Error
124
+	 */
125
+	public function messages_metabox($event, $callback_args)
126
+	{
127
+		// let's get the active messengers (b/c messenger objects have the active message templates)
128
+		// convert 'evt_id' to 'EVT_ID'
129
+		$this->_req_data['EVT_ID'] = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null;
130
+		$this->_req_data['EVT_ID'] = isset($this->_req_data['post']) && empty($this->_req_data['EVT_ID'])
131
+			? $this->_req_data['post']
132
+			: $this->_req_data['EVT_ID'];
133
+
134
+		$this->_req_data['EVT_ID'] = empty($this->_req_data['EVT_ID']) && isset($this->_req_data['evt_id'])
135
+			? $this->_req_data['evt_id']
136
+			: $this->_req_data['EVT_ID'];
137
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
138
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
139
+		$active_messengers = $message_resource_manager->active_messengers();
140
+		$tabs = array();
141
+
142
+		// empty messengers?
143
+		// Note message types will always have at least one available because every messenger has a default message type
144
+		// associated with it (payment) if no other message types are selected.
145
+		if (empty($active_messengers)) {
146
+			$msg_activate_url = EE_Admin_Page::add_query_args_and_nonce(
147
+				array('action' => 'settings'),
148
+				EE_MSG_ADMIN_URL
149
+			);
150
+			$error_msg = sprintf(
151
+				esc_html__(
152
+					'There are no active messengers. So no notifications will go out for %1$sany%2$s events.  You will want to %3$sActivate a Messenger%4$s.',
153
+					'event_espresso'
154
+				),
155
+				'<strong>',
156
+				'</strong>',
157
+				'<a href="' . $msg_activate_url . '">',
158
+				'</a>'
159
+			);
160
+			$error_content = '<div class="error"><p>' . $error_msg . '</p></div>';
161
+			$internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>';
162
+
163
+			echo $error_content;
164
+			echo $internal_content;
165
+			return '';
166
+		}
167
+
168
+		$event_id = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null;
169
+		// get content for active messengers
170
+		foreach ($active_messengers as $name => $messenger) {
171
+			// first check if there are any active message types for this messenger.
172
+			$active_mts = $message_resource_manager->get_active_message_types_for_messenger($name);
173
+			if (empty($active_mts)) {
174
+				continue;
175
+			}
176
+
177
+			$tab_content = $messenger->get_messenger_admin_page_content(
178
+				'events',
179
+				'edit',
180
+				array('event' => $event_id)
181
+			);
182
+
183
+			if (! empty($tab_content)) {
184
+				$tabs[ $name ] = $tab_content;
185
+			}
186
+		}
187
+
188
+
189
+		// we want this to be tabbed content so let's use the EEH_Tabbed_Content::display helper.
190
+		$tabbed_content = EEH_Tabbed_Content::display($tabs);
191
+		if ($tabbed_content instanceof WP_Error) {
192
+			$tabbed_content = $tabbed_content->get_error_message();
193
+		}
194
+
195
+		$notices = '
196 196
 	<div id="espresso-ajax-loading" class="ajax-loader-grey">
197 197
 		<span class="ee-spinner ee-spin"></span><span class="hidden">'
198
-                   . esc_html__('loading...', 'event_espresso')
199
-                   . '</span>
198
+				   . esc_html__('loading...', 'event_espresso')
199
+				   . '</span>
200 200
 	</div>
201 201
 	<div class="ee-notices"></div>';
202 202
 
203
-        if (defined('DOING_AJAX')) {
204
-            return $tabbed_content;
205
-        }
206
-
207
-        do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content');
208
-        echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>';
209
-        do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content');
210
-    }
211
-
212
-
213
-    /**
214
-     * Ajax callback for ee_msgs_create_new_custom ajax request.
215
-     * Takes incoming GRP_ID and name and description values from ajax request
216
-     * to create a new custom template based off of the incoming GRP_ID.
217
-     *
218
-     * @access public
219
-     * @return string either an html string will be returned or a success message
220
-     * @throws EE_Error
221
-     */
222
-    public function create_new_custom()
223
-    {
224
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) {
225
-            wp_die(__('You don\'t have privileges to do this action', 'event_espresso'));
226
-        }
227
-
228
-        // let's clean up the _POST global a bit for downstream usage of name and description.
229
-        $_POST['templateName'] = ! empty($this->_req_data['custom_template_args']['MTP_name'])
230
-            ? $this->_req_data['custom_template_args']['MTP_name']
231
-            : '';
232
-        $_POST['templateDescription'] = ! empty($this->_req_data['custom_template_args']['MTP_description'])
233
-            ? $this->_req_data['custom_template_args']['MTP_description']
234
-            : '';
235
-
236
-        // is this a template switch if so EE_Admin_Page child needs this object
237
-        $this->_page_object->set_hook_object($this);
238
-
239
-        $this->_page_object->add_message_template(
240
-            $this->_req_data['messageType'],
241
-            $this->_req_data['messenger'],
242
-            $this->_req_data['group_ID']
243
-        );
244
-    }
245
-
246
-
247
-    public function create_new_admin_footer()
248
-    {
249
-        $this->edit_admin_footer();
250
-    }
251
-
252
-
253
-    /**
254
-     * This is the dynamic method for this class
255
-     * that will end up hooking into the 'admin_footer' hook on the 'edit_event' route in the events page.
256
-     *
257
-     * @return string
258
-     * @throws DomainException
259
-     */
260
-    public function edit_admin_footer()
261
-    {
262
-        EEH_Template::display_template(
263
-            EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php'
264
-        );
265
-    }
266
-
267
-
268
-    /**
269
-     * Callback for AHEE__Extend_Events_Admin_Page___duplicate_event__after hook used to ensure new events duplicate
270
-     * the assigned custom message templates.
271
-     *
272
-     * @param EE_Event $new_event
273
-     * @param EE_Event $original_event
274
-     * @throws EE_Error
275
-     */
276
-    public function duplicate_custom_message_settings(EE_Event $new_event, EE_Event $original_event)
277
-    {
278
-        $message_template_groups = $original_event->get_many_related('Message_Template_Group');
279
-        foreach ($message_template_groups as $message_template_group) {
280
-            $new_event->_add_relation_to($message_template_group, 'Message_Template_Group');
281
-        }
282
-        // save new event
283
-        $new_event->save();
284
-    }
203
+		if (defined('DOING_AJAX')) {
204
+			return $tabbed_content;
205
+		}
206
+
207
+		do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content');
208
+		echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>';
209
+		do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content');
210
+	}
211
+
212
+
213
+	/**
214
+	 * Ajax callback for ee_msgs_create_new_custom ajax request.
215
+	 * Takes incoming GRP_ID and name and description values from ajax request
216
+	 * to create a new custom template based off of the incoming GRP_ID.
217
+	 *
218
+	 * @access public
219
+	 * @return string either an html string will be returned or a success message
220
+	 * @throws EE_Error
221
+	 */
222
+	public function create_new_custom()
223
+	{
224
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) {
225
+			wp_die(__('You don\'t have privileges to do this action', 'event_espresso'));
226
+		}
227
+
228
+		// let's clean up the _POST global a bit for downstream usage of name and description.
229
+		$_POST['templateName'] = ! empty($this->_req_data['custom_template_args']['MTP_name'])
230
+			? $this->_req_data['custom_template_args']['MTP_name']
231
+			: '';
232
+		$_POST['templateDescription'] = ! empty($this->_req_data['custom_template_args']['MTP_description'])
233
+			? $this->_req_data['custom_template_args']['MTP_description']
234
+			: '';
235
+
236
+		// is this a template switch if so EE_Admin_Page child needs this object
237
+		$this->_page_object->set_hook_object($this);
238
+
239
+		$this->_page_object->add_message_template(
240
+			$this->_req_data['messageType'],
241
+			$this->_req_data['messenger'],
242
+			$this->_req_data['group_ID']
243
+		);
244
+	}
245
+
246
+
247
+	public function create_new_admin_footer()
248
+	{
249
+		$this->edit_admin_footer();
250
+	}
251
+
252
+
253
+	/**
254
+	 * This is the dynamic method for this class
255
+	 * that will end up hooking into the 'admin_footer' hook on the 'edit_event' route in the events page.
256
+	 *
257
+	 * @return string
258
+	 * @throws DomainException
259
+	 */
260
+	public function edit_admin_footer()
261
+	{
262
+		EEH_Template::display_template(
263
+			EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php'
264
+		);
265
+	}
266
+
267
+
268
+	/**
269
+	 * Callback for AHEE__Extend_Events_Admin_Page___duplicate_event__after hook used to ensure new events duplicate
270
+	 * the assigned custom message templates.
271
+	 *
272
+	 * @param EE_Event $new_event
273
+	 * @param EE_Event $original_event
274
+	 * @throws EE_Error
275
+	 */
276
+	public function duplicate_custom_message_settings(EE_Event $new_event, EE_Event $original_event)
277
+	{
278
+		$message_template_groups = $original_event->get_many_related('Message_Template_Group');
279
+		foreach ($message_template_groups as $message_template_group) {
280
+			$new_event->_add_relation_to($message_template_group, 'Message_Template_Group');
281
+		}
282
+		// save new event
283
+		$new_event->save();
284
+	}
285 285
 }
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 2 patches
Spacing   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
         ];
536 536
         // only load EE_Event_Editor_Decaf_Tips if domain is not caffeinated
537 537
         $domain = $this->loader->getShared('EventEspresso\core\domain\Domain');
538
-        if (! $domain->isCaffeinated()) {
538
+        if ( ! $domain->isCaffeinated()) {
539 539
             $this->_page_config['create_new']['qtips'] = ['EE_Event_Editor_Decaf_Tips'];
540 540
             $this->_page_config['edit']['qtips']       = ['EE_Event_Editor_Decaf_Tips'];
541 541
         }
@@ -594,13 +594,13 @@  discard block
 block discarded – undo
594 594
     {
595 595
         wp_register_style(
596 596
             'events-admin-css',
597
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
597
+            EVENTS_ASSETS_URL.'events-admin-page.css',
598 598
             [],
599 599
             EVENT_ESPRESSO_VERSION
600 600
         );
601 601
         wp_register_style(
602 602
             'ee-cat-admin',
603
-            EVENTS_ASSETS_URL . 'ee-cat-admin.css',
603
+            EVENTS_ASSETS_URL.'ee-cat-admin.css',
604 604
             [],
605 605
             EVENT_ESPRESSO_VERSION
606 606
         );
@@ -609,7 +609,7 @@  discard block
 block discarded – undo
609 609
         // scripts
610 610
         wp_register_script(
611 611
             'event_editor_js',
612
-            EVENTS_ASSETS_URL . 'event_editor.js',
612
+            EVENTS_ASSETS_URL.'event_editor.js',
613 613
             ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
614 614
             EVENT_ESPRESSO_VERSION,
615 615
             true
@@ -635,16 +635,16 @@  discard block
 block discarded – undo
635 635
         wp_enqueue_style('espresso-ui-theme');
636 636
         wp_register_style(
637 637
             'event-editor-css',
638
-            EVENTS_ASSETS_URL . 'event-editor.css',
638
+            EVENTS_ASSETS_URL.'event-editor.css',
639 639
             ['ee-admin-css'],
640 640
             EVENT_ESPRESSO_VERSION
641 641
         );
642 642
         wp_enqueue_style('event-editor-css');
643 643
         // scripts
644
-        if (! $this->admin_config->useAdvancedEditor()) {
644
+        if ( ! $this->admin_config->useAdvancedEditor()) {
645 645
             wp_register_script(
646 646
                 'event-datetime-metabox',
647
-                EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
647
+                EVENTS_ASSETS_URL.'event-datetime-metabox.js',
648 648
                 ['event_editor_js', 'ee-datepicker'],
649 649
                 EVENT_ESPRESSO_VERSION
650 650
             );
@@ -714,15 +714,15 @@  discard block
 block discarded – undo
714 714
     public function verify_event_edit($event = null, $req_type = '')
715 715
     {
716 716
         // don't need to do this when processing
717
-        if (! empty($req_type)) {
717
+        if ( ! empty($req_type)) {
718 718
             return;
719 719
         }
720 720
         // no event?
721
-        if (! $event instanceof EE_Event) {
721
+        if ( ! $event instanceof EE_Event) {
722 722
             $event = $this->_cpt_model_obj;
723 723
         }
724 724
         // STILL no event?
725
-        if (! $event instanceof EE_Event) {
725
+        if ( ! $event instanceof EE_Event) {
726 726
             return;
727 727
         }
728 728
         $orig_status = $event->status();
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
             );
763 763
         }
764 764
         // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
765
-        if (! $event->tickets_on_sale()) {
765
+        if ( ! $event->tickets_on_sale()) {
766 766
             return;
767 767
         }
768 768
         // made it here so show warning
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
     {
811 811
         $has_timezone_string = get_option('timezone_string');
812 812
         // only nag them about setting their timezone if it's their first event, and they haven't already done it
813
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
813
+        if ( ! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
814 814
             EE_Error::add_attention(
815 815
                 sprintf(
816 816
                     __(
@@ -877,7 +877,7 @@  discard block
 block discarded – undo
877 877
      */
878 878
     protected function _event_legend_items()
879 879
     {
880
-        $items    = [
880
+        $items = [
881 881
             'view_details'   => [
882 882
                 'class' => 'dashicons dashicons-search',
883 883
                 'desc'  => esc_html__('View Event', 'event_espresso'),
@@ -894,31 +894,31 @@  discard block
 block discarded – undo
894 894
         $items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
895 895
         $statuses = [
896 896
             'sold_out_status'  => [
897
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
897
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out,
898 898
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
899 899
             ],
900 900
             'active_status'    => [
901
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
901
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active,
902 902
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
903 903
             ],
904 904
             'upcoming_status'  => [
905
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
905
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming,
906 906
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
907 907
             ],
908 908
             'postponed_status' => [
909
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
909
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed,
910 910
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
911 911
             ],
912 912
             'cancelled_status' => [
913
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
913
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled,
914 914
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
915 915
             ],
916 916
             'expired_status'   => [
917
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
917
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired,
918 918
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
919 919
             ],
920 920
             'inactive_status'  => [
921
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
921
+                'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive,
922 922
                 'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
923 923
             ],
924 924
         ];
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
      */
938 938
     private function _event_model()
939 939
     {
940
-        if (! $this->_event_model instanceof EEM_Event) {
940
+        if ( ! $this->_event_model instanceof EEM_Event) {
941 941
             $this->_event_model = EE_Registry::instance()->load_model('Event');
942 942
         }
943 943
         return $this->_event_model;
@@ -957,8 +957,8 @@  discard block
 block discarded – undo
957 957
     public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
958 958
     {
959 959
         // make sure this is only when editing
960
-        if (! empty($id)) {
961
-            $post   = get_post($id);
960
+        if ( ! empty($id)) {
961
+            $post = get_post($id);
962 962
             $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
963 963
                        . esc_html__('Shortcode', 'event_espresso')
964 964
                        . '</a> ';
@@ -985,7 +985,7 @@  discard block
 block discarded – undo
985 985
     protected function _events_overview_list_table()
986 986
     {
987 987
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
988
-        $this->_template_args['after_list_table']                           =
988
+        $this->_template_args['after_list_table'] =
989 989
             ! empty($this->_template_args['after_list_table'])
990 990
                 ? (array) $this->_template_args['after_list_table']
991 991
                 : [];
@@ -995,9 +995,9 @@  discard block
 block discarded – undo
995 995
                 esc_html__('View Event Archive Page', 'event_espresso'),
996 996
                 'button'
997 997
             );
998
-        $this->_template_args['after_list_table']['legend']                 =
998
+        $this->_template_args['after_list_table']['legend'] =
999 999
             $this->_display_legend($this->_event_legend_items());
1000
-        $this->_admin_page_title                                            .= ' '
1000
+        $this->_admin_page_title .= ' '
1001 1001
             . $this->get_action_link_or_button(
1002 1002
                 'create_new',
1003 1003
                 'add',
@@ -1061,12 +1061,12 @@  discard block
 block discarded – undo
1061 1061
         /** @var FeatureFlags $flags */
1062 1062
         $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1063 1063
         // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1064
-        if (! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1065
-            $event_values['EVT_display_ticket_selector']     =
1064
+        if ( ! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1065
+            $event_values['EVT_display_ticket_selector'] =
1066 1066
                 ! empty($this->_req_data['display_ticket_selector'])
1067 1067
                     ? 1
1068 1068
                     : 0;
1069
-            $event_values['EVT_additional_limit']            = min(
1069
+            $event_values['EVT_additional_limit'] = min(
1070 1070
                 apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1071 1071
                 ! empty($this->_req_data['additional_limit'])
1072 1072
                     ? absint($this->_req_data['additional_limit'])
@@ -1098,7 +1098,7 @@  discard block
 block discarded – undo
1098 1098
                 'status*1' => $this->_req_data['original_post_status'],
1099 1099
             ],
1100 1100
         ];
1101
-        $event         = $this->_event_model()->get_one([$get_one_where]);
1101
+        $event = $this->_event_model()->get_one([$get_one_where]);
1102 1102
         // the following are default callbacks for event attachment updates
1103 1103
         // that can be overridden by caffeinated functionality and/or addons.
1104 1104
         $event_update_callbacks = apply_filters(
@@ -1108,7 +1108,7 @@  discard block
 block discarded – undo
1108 1108
                 [$this, '_default_tickets_update'],
1109 1109
             ]
1110 1110
         );
1111
-        $att_success            = true;
1111
+        $att_success = true;
1112 1112
         foreach ($event_update_callbacks as $e_callback) {
1113 1113
             $_success = is_callable($e_callback)
1114 1114
                 ? $e_callback($event, $this->_req_data)
@@ -1175,7 +1175,7 @@  discard block
 block discarded – undo
1175 1175
      */
1176 1176
     protected function _default_venue_update(EE_Event $evtobj, $data)
1177 1177
     {
1178
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1178
+        require_once(EE_MODELS.'EEM_Venue.model.php');
1179 1179
         $venue_model   = EE_Registry::instance()->load_model('Venue');
1180 1180
         $rows_affected = null;
1181 1181
         $venue_id      = ! empty($data['venue_id']) ? $data['venue_id'] : null;
@@ -1206,7 +1206,7 @@  discard block
 block discarded – undo
1206 1206
             'status'              => 'publish',
1207 1207
         ];
1208 1208
         // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1209
-        if (! empty($venue_id)) {
1209
+        if ( ! empty($venue_id)) {
1210 1210
             $update_where  = [$venue_model->primary_key_name() => $venue_id];
1211 1211
             $rows_affected = $venue_model->update($venue_array, [$update_where]);
1212 1212
             // we've gotta make sure that the venue is always attached to a revision..
@@ -1258,7 +1258,7 @@  discard block
 block discarded – undo
1258 1258
             ];
1259 1259
             // if we have an id then let's get existing object first and then set the new values.
1260 1260
             //  Otherwise we instantiate a new object for save.
1261
-            if (! empty($dtt['DTT_ID'])) {
1261
+            if ( ! empty($dtt['DTT_ID'])) {
1262 1262
                 $DTM = EE_Registry::instance()
1263 1263
                                   ->load_model('Datetime', [$evtobj->get_timezone()])
1264 1264
                                   ->get_one_by_ID($dtt['DTT_ID']);
@@ -1269,7 +1269,7 @@  discard block
 block discarded – undo
1269 1269
                 }
1270 1270
                 // make sure the $dtt_id here is saved in case after the add_relation_to() the autosave replaces it.
1271 1271
                 // We need to do this so we dont' TRASH the parent DTT.
1272
-                $saved_dtts[ $DTM->ID() ] = $DTM;
1272
+                $saved_dtts[$DTM->ID()] = $DTM;
1273 1273
             } else {
1274 1274
                 $DTM = EE_Registry::instance()->load_class(
1275 1275
                     'Datetime',
@@ -1304,15 +1304,15 @@  discard block
 block discarded – undo
1304 1304
         foreach ($data['edit_tickets'] as $row => $tkt) {
1305 1305
             $incoming_date_formats = ['Y-m-d', 'h:i a'];
1306 1306
             $update_prices         = false;
1307
-            $ticket_price          = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1308
-                ? $data['edit_prices'][ $row ][1]['PRC_amount']
1307
+            $ticket_price          = isset($data['edit_prices'][$row][1]['PRC_amount'])
1308
+                ? $data['edit_prices'][$row][1]['PRC_amount']
1309 1309
                 : 0;
1310 1310
             // trim inputs to ensure any excess whitespace is removed.
1311 1311
             $tkt = array_map('trim', $tkt);
1312 1312
             if (empty($tkt['TKT_start_date'])) {
1313 1313
                 // let's use now in the set timezone.
1314 1314
                 $now                   = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1315
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1315
+                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]);
1316 1316
             }
1317 1317
             if (empty($tkt['TKT_end_date'])) {
1318 1318
                 // use the start date of the first datetime
@@ -1350,7 +1350,7 @@  discard block
 block discarded – undo
1350 1350
             // that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1351 1351
             // keep in mind that if the TKT has been sold (and we have changed pricing information),
1352 1352
             // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1353
-            if (! empty($tkt['TKT_ID'])) {
1353
+            if ( ! empty($tkt['TKT_ID'])) {
1354 1354
                 $TKT = EE_Registry::instance()
1355 1355
                                   ->load_model('Ticket', [$evtobj->get_timezone()])
1356 1356
                                   ->get_one_by_ID($tkt['TKT_ID']);
@@ -1394,7 +1394,7 @@  discard block
 block discarded – undo
1394 1394
                         $TKT->save();
1395 1395
                         // make sure this ticket is still recorded in our saved_tkts
1396 1396
                         // so we don't run it through the regular trash routine.
1397
-                        $saved_tickets[ $TKT->ID() ] = $TKT;
1397
+                        $saved_tickets[$TKT->ID()] = $TKT;
1398 1398
                         // create new ticket that's a copy of the existing except a new id of course
1399 1399
                         // (and not archived) AND has the new TKT_price associated with it.
1400 1400
                         $TKT = clone $TKT;
@@ -1441,9 +1441,9 @@  discard block
 block discarded – undo
1441 1441
             }
1442 1442
             // initially let's add the ticket to the dtt
1443 1443
             $saved_dtt->_add_relation_to($TKT, 'Ticket');
1444
-            $saved_tickets[ $TKT->ID() ] = $TKT;
1444
+            $saved_tickets[$TKT->ID()] = $TKT;
1445 1445
             // add prices to ticket
1446
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1446
+            $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1447 1447
         }
1448 1448
         // however now we need to handle permanently deleting tickets via the ui.
1449 1449
         //  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
@@ -1548,13 +1548,13 @@  discard block
 block discarded – undo
1548 1548
     {
1549 1549
         // load formatter helper
1550 1550
         // args for getting related registrations
1551
-        $approved_query_args        = [
1551
+        $approved_query_args = [
1552 1552
             [
1553 1553
                 'REG_deleted' => 0,
1554 1554
                 'STS_ID'      => EEM_Registration::status_id_approved,
1555 1555
             ],
1556 1556
         ];
1557
-        $not_approved_query_args    = [
1557
+        $not_approved_query_args = [
1558 1558
             [
1559 1559
                 'REG_deleted' => 0,
1560 1560
                 'STS_ID'      => EEM_Registration::status_id_not_approved,
@@ -1617,7 +1617,7 @@  discard block
 block discarded – undo
1617 1617
         $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1618 1618
         // load template
1619 1619
         EEH_Template::display_template(
1620
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1620
+            EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php',
1621 1621
             $publish_box_extra_args
1622 1622
         );
1623 1623
     }
@@ -1653,7 +1653,7 @@  discard block
 block discarded – undo
1653 1653
         /** @var FeatureFlags $flags */
1654 1654
         $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1655 1655
         // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1656
-        if (! $use_advanced_editor || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1656
+        if ( ! $use_advanced_editor || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1657 1657
             add_meta_box(
1658 1658
                 'espresso_event_editor_event_options',
1659 1659
                 esc_html__('Event Registration Options', 'event_espresso'),
@@ -1662,7 +1662,7 @@  discard block
 block discarded – undo
1662 1662
                 'side'
1663 1663
             );
1664 1664
         }
1665
-        if (! $use_advanced_editor) {
1665
+        if ( ! $use_advanced_editor) {
1666 1666
             add_meta_box(
1667 1667
                 'espresso_event_editor_tickets',
1668 1668
                 esc_html__('Event Datetime & Ticket', 'event_espresso'),
@@ -1675,7 +1675,7 @@  discard block
 block discarded – undo
1675 1675
             if ($flags->featureAllowed('use_reg_options_meta_box')) {
1676 1676
                 add_action(
1677 1677
                     'add_meta_boxes_espresso_events',
1678
-                    function () {
1678
+                    function() {
1679 1679
                         global $current_screen;
1680 1680
                         remove_meta_box('authordiv', $current_screen, 'normal');
1681 1681
                     },
@@ -1714,7 +1714,7 @@  discard block
 block discarded – undo
1714 1714
             'trash_icon'               => 'ee-lock-icon',
1715 1715
             'disabled'                 => '',
1716 1716
         ];
1717
-        $event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1717
+        $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1718 1718
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1719 1719
         /**
1720 1720
          * 1. Start with retrieving Datetimes
@@ -1737,24 +1737,24 @@  discard block
 block discarded – undo
1737 1737
                     'default_where_conditions' => 'none',
1738 1738
                 ]
1739 1739
             );
1740
-            if (! empty($related_tickets)) {
1740
+            if ( ! empty($related_tickets)) {
1741 1741
                 $template_args['total_ticket_rows'] = count($related_tickets);
1742 1742
                 $row                                = 0;
1743 1743
                 foreach ($related_tickets as $ticket) {
1744
-                    $existing_ticket_ids[]        = $ticket->get('TKT_ID');
1744
+                    $existing_ticket_ids[] = $ticket->get('TKT_ID');
1745 1745
                     $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1746 1746
                     $row++;
1747 1747
                 }
1748 1748
             } else {
1749 1749
                 $template_args['total_ticket_rows'] = 1;
1750 1750
                 /** @type EE_Ticket $ticket */
1751
-                $ticket                       = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1751
+                $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1752 1752
                 $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1753 1753
             }
1754 1754
         } else {
1755 1755
             $template_args['time'] = $times[0];
1756 1756
             /** @type EE_Ticket $ticket */
1757
-            $ticket                       = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1757
+            $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1758 1758
             $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1759 1759
             // NOTE: we're just sending the first default row
1760 1760
             // (decaf can't manage default tickets so this should be sufficient);
@@ -1769,9 +1769,9 @@  discard block
 block discarded – undo
1769 1769
             EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1770 1770
             true
1771 1771
         );
1772
-        $template                                  = apply_filters(
1772
+        $template = apply_filters(
1773 1773
             'FHEE__Events_Admin_Page__ticket_metabox__template',
1774
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1774
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php'
1775 1775
         );
1776 1776
         EEH_Template::display_template($template, $template_args);
1777 1777
     }
@@ -1795,7 +1795,7 @@  discard block
 block discarded – undo
1795 1795
     private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1796 1796
     {
1797 1797
         $template_args = [
1798
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1798
+            'tkt_status_class'    => ' tkt-status-'.$ticket->ticket_status(),
1799 1799
             'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1800 1800
                 : '',
1801 1801
             'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
@@ -1807,10 +1807,10 @@  discard block
 block discarded – undo
1807 1807
             'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1808 1808
             'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1809 1809
             'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1810
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1811
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1810
+            'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1811
+                                     && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1812 1812
                 ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1813
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1813
+            'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1814 1814
                 : ' disabled=disabled',
1815 1815
         ];
1816 1816
         $price         = $ticket->ID() !== 0
@@ -1837,7 +1837,7 @@  discard block
 block discarded – undo
1837 1837
                     ['order_by' => ['DTT_EVT_start' => 'ASC']]
1838 1838
                 )
1839 1839
                 : null;
1840
-            if (! empty($earliest_dtt)) {
1840
+            if ( ! empty($earliest_dtt)) {
1841 1841
                 $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1842 1842
             } else {
1843 1843
                 $template_args['TKT_end_date'] = date(
@@ -1849,7 +1849,7 @@  discard block
 block discarded – undo
1849 1849
         $template_args = array_merge($template_args, $price_args);
1850 1850
         $template      = apply_filters(
1851 1851
             'FHEE__Events_Admin_Page__get_ticket_row__template',
1852
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1852
+            EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php',
1853 1853
             $ticket
1854 1854
         );
1855 1855
         return EEH_Template::display_template($template, $template_args, true);
@@ -1862,7 +1862,7 @@  discard block
 block discarded – undo
1862 1862
      */
1863 1863
     public function registration_options_meta_box()
1864 1864
     {
1865
-        $yes_no_values             = [
1865
+        $yes_no_values = [
1866 1866
             ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1867 1867
             ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1868 1868
         ];
@@ -1883,12 +1883,12 @@  discard block
 block discarded – undo
1883 1883
             $default_reg_status_values,
1884 1884
             $this->_cpt_model_obj->default_registration_status()
1885 1885
         );
1886
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1886
+        $template_args['display_description'] = EEH_Form_Fields::select_input(
1887 1887
             'display_desc',
1888 1888
             $yes_no_values,
1889 1889
             $this->_cpt_model_obj->display_description()
1890 1890
         );
1891
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1891
+        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1892 1892
             'display_ticket_selector',
1893 1893
             $yes_no_values,
1894 1894
             $this->_cpt_model_obj->display_ticket_selector(),
@@ -1904,7 +1904,7 @@  discard block
 block discarded – undo
1904 1904
             $default_reg_status_values
1905 1905
         );
1906 1906
         EEH_Template::display_template(
1907
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1907
+            EVENTS_TEMPLATE_PATH.'event_registration_options.template.php',
1908 1908
             $template_args
1909 1909
         );
1910 1910
     }
@@ -1934,7 +1934,7 @@  discard block
 block discarded – undo
1934 1934
     {
1935 1935
         $EEME    = $this->_event_model();
1936 1936
         $offset  = ($current_page - 1) * $per_page;
1937
-        $limit   = $count ? null : $offset . ',' . $per_page;
1937
+        $limit   = $count ? null : $offset.','.$per_page;
1938 1938
         $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1939 1939
         $order   = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
1940 1940
         if (isset($this->_req_data['month_range'])) {
@@ -1963,7 +1963,7 @@  discard block
 block discarded – undo
1963 1963
         // categories?
1964 1964
         $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1965 1965
             ? $this->_req_data['EVT_CAT'] : null;
1966
-        if (! empty($category)) {
1966
+        if ( ! empty($category)) {
1967 1967
             $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1968 1968
             $where['Term_Taxonomy.term_id']  = $category;
1969 1969
         }
@@ -1971,10 +1971,10 @@  discard block
 block discarded – undo
1971 1971
         $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1972 1972
         if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') {
1973 1973
             $DateTime = new DateTime(
1974
-                $year_r . '-' . $month_r . '-01 00:00:00',
1974
+                $year_r.'-'.$month_r.'-01 00:00:00',
1975 1975
                 new DateTimeZone('UTC')
1976 1976
             );
1977
-            $start    = $DateTime->getTimestamp();
1977
+            $start = $DateTime->getTimestamp();
1978 1978
             // set the datetime to be the end of the month
1979 1979
             $DateTime->setDate(
1980 1980
                 $year_r,
@@ -1999,7 +1999,7 @@  discard block
 block discarded – undo
1999 1999
                                                         ->format(implode(' ', $start_formats));
2000 2000
             $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
2001 2001
         }
2002
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
2002
+        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
2003 2003
             $where['EVT_wp_user'] = get_current_user_id();
2004 2004
         } elseif (
2005 2005
             ! isset($where['status'])
@@ -2023,7 +2023,7 @@  discard block
 block discarded – undo
2023 2023
         }
2024 2024
         // search query handling
2025 2025
         if (isset($this->_req_data['s'])) {
2026
-            $search_string = '%' . $this->_req_data['s'] . '%';
2026
+            $search_string = '%'.$this->_req_data['s'].'%';
2027 2027
             $where['OR']   = [
2028 2028
                 'EVT_name'       => ['LIKE', $search_string],
2029 2029
                 'EVT_desc'       => ['LIKE', $search_string],
@@ -2139,7 +2139,7 @@  discard block
 block discarded – undo
2139 2139
             // clean status
2140 2140
             $event_status = sanitize_key($event_status);
2141 2141
             // grab status
2142
-            if (! empty($event_status)) {
2142
+            if ( ! empty($event_status)) {
2143 2143
                 $success = $this->_change_event_status($EVT_ID, $event_status);
2144 2144
             } else {
2145 2145
                 $success = false;
@@ -2181,7 +2181,7 @@  discard block
 block discarded – undo
2181 2181
         // clean status
2182 2182
         $event_status = sanitize_key($event_status);
2183 2183
         // grab status
2184
-        if (! empty($event_status)) {
2184
+        if ( ! empty($event_status)) {
2185 2185
             $success = true;
2186 2186
             // determine the event id and set to array.
2187 2187
             $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : [];
@@ -2233,7 +2233,7 @@  discard block
 block discarded – undo
2233 2233
     private function _change_event_status($EVT_ID = 0, $event_status = '')
2234 2234
     {
2235 2235
         // grab event id
2236
-        if (! $EVT_ID) {
2236
+        if ( ! $EVT_ID) {
2237 2237
             $msg = esc_html__(
2238 2238
                 'An error occurred. No Event ID or an invalid Event ID was received.',
2239 2239
                 'event_espresso'
@@ -2306,7 +2306,7 @@  discard block
 block discarded – undo
2306 2306
      */
2307 2307
     protected function getModelObjNodeGroupPersister()
2308 2308
     {
2309
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2309
+        if ( ! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2310 2310
             $this->model_obj_node_group_persister =
2311 2311
                 $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2312 2312
         }
@@ -2341,7 +2341,7 @@  discard block
 block discarded – undo
2341 2341
             ],
2342 2342
             $this->_admin_base_url
2343 2343
         );
2344
-        $event_ids         = array_map(
2344
+        $event_ids = array_map(
2345 2345
             'intval',
2346 2346
             $event_ids
2347 2347
         );
@@ -2590,7 +2590,7 @@  discard block
 block discarded – undo
2590 2590
                                                 . esc_html__(
2591 2591
                                                     'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2592 2592
                                                     'event_espresso'
2593
-                                                ) . '</strong>';
2593
+                                                ).'</strong>';
2594 2594
         $this->display_admin_caf_preview_page('template_settings_tab');
2595 2595
     }
2596 2596
 
@@ -2610,12 +2610,12 @@  discard block
 block discarded – undo
2610 2610
         // set default category object
2611 2611
         $this->_set_empty_category_object();
2612 2612
         // only set if we've got an id
2613
-        if (! isset($this->_req_data['EVT_CAT_ID'])) {
2613
+        if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2614 2614
             return;
2615 2615
         }
2616 2616
         $category_id = absint($this->_req_data['EVT_CAT_ID']);
2617 2617
         $term        = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2618
-        if (! empty($term)) {
2618
+        if ( ! empty($term)) {
2619 2619
             $this->_category->category_name       = $term->name;
2620 2620
             $this->_category->category_identifier = $term->slug;
2621 2621
             $this->_category->category_desc       = $term->description;
@@ -2723,7 +2723,7 @@  discard block
 block discarded – undo
2723 2723
             $category_select_values,
2724 2724
             $this->_category->parent
2725 2725
         );
2726
-        $template_args   = [
2726
+        $template_args = [
2727 2727
             'category'                 => $this->_category,
2728 2728
             'category_select'          => $category_select,
2729 2729
             'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
@@ -2731,7 +2731,7 @@  discard block
 block discarded – undo
2731 2731
             'disable'                  => '',
2732 2732
             'disabled_message'         => false,
2733 2733
         ];
2734
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2734
+        $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php';
2735 2735
         return EEH_Template::display_template($template, $template_args, true);
2736 2736
     }
2737 2737
 
@@ -2820,7 +2820,7 @@  discard block
 block discarded – undo
2820 2820
         $insert_ids = $update
2821 2821
             ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2822 2822
             : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2823
-        if (! is_array($insert_ids)) {
2823
+        if ( ! is_array($insert_ids)) {
2824 2824
             $msg = esc_html__(
2825 2825
                 'An error occurred and the category has not been saved to the database.',
2826 2826
                 'event_espresso'
@@ -2855,7 +2855,7 @@  discard block
 block discarded – undo
2855 2855
         $limit   = ($current_page - 1) * $per_page;
2856 2856
         $where   = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2857 2857
         if (isset($this->_req_data['s'])) {
2858
-            $sstr        = '%' . $this->_req_data['s'] . '%';
2858
+            $sstr        = '%'.$this->_req_data['s'].'%';
2859 2859
             $where['OR'] = [
2860 2860
                 'Term.name'   => ['LIKE', $sstr],
2861 2861
                 'description' => ['LIKE', $sstr],
@@ -2864,7 +2864,7 @@  discard block
 block discarded – undo
2864 2864
         $query_params = [
2865 2865
             $where,
2866 2866
             'order_by'   => [$orderby => $order],
2867
-            'limit'      => $limit . ',' . $per_page,
2867
+            'limit'      => $limit.','.$per_page,
2868 2868
             'force_join' => ['Term'],
2869 2869
         ];
2870 2870
         return $count
Please login to merge, or discard this patch.
Indentation   +2890 added lines, -2890 removed lines patch added patch discarded remove patch
@@ -17,2894 +17,2894 @@
 block discarded – undo
17 17
 class Events_Admin_Page extends EE_Admin_Page_CPT
18 18
 {
19 19
 
20
-    /**
21
-     * This will hold the event object for event_details screen.
22
-     *
23
-     * @access protected
24
-     * @var EE_Event $_event
25
-     */
26
-    protected $_event;
27
-
28
-
29
-    /**
30
-     * This will hold the category object for category_details screen.
31
-     *
32
-     * @var stdClass $_category
33
-     */
34
-    protected $_category;
35
-
36
-
37
-    /**
38
-     * This will hold the event model instance
39
-     *
40
-     * @var EEM_Event $_event_model
41
-     */
42
-    protected $_event_model;
43
-
44
-
45
-    /**
46
-     * @var EE_Event
47
-     */
48
-    protected $_cpt_model_obj = false;
49
-
50
-
51
-    /**
52
-     * @var NodeGroupDao
53
-     */
54
-    protected $model_obj_node_group_persister;
55
-
56
-
57
-    /**
58
-     * Initialize page props for this admin page group.
59
-     */
60
-    protected function _init_page_props()
61
-    {
62
-        $this->page_slug        = EVENTS_PG_SLUG;
63
-        $this->page_label       = EVENTS_LABEL;
64
-        $this->_admin_base_url  = EVENTS_ADMIN_URL;
65
-        $this->_admin_base_path = EVENTS_ADMIN;
66
-        $this->_cpt_model_names = [
67
-            'create_new' => 'EEM_Event',
68
-            'edit'       => 'EEM_Event',
69
-        ];
70
-        $this->_cpt_edit_routes = [
71
-            'espresso_events' => 'edit',
72
-        ];
73
-        add_action(
74
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
75
-            [$this, 'verify_event_edit'],
76
-            10,
77
-            2
78
-        );
79
-    }
80
-
81
-
82
-    /**
83
-     * Sets the ajax hooks used for this admin page group.
84
-     */
85
-    protected function _ajax_hooks()
86
-    {
87
-        add_action('wp_ajax_ee_save_timezone_setting', [$this, 'save_timezonestring_setting']);
88
-    }
89
-
90
-
91
-    /**
92
-     * Sets the page properties for this admin page group.
93
-     */
94
-    protected function _define_page_props()
95
-    {
96
-        $this->_admin_page_title = EVENTS_LABEL;
97
-        $this->_labels           = [
98
-            'buttons'      => [
99
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
100
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
101
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
102
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
103
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
104
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
105
-            ],
106
-            'editor_title' => [
107
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
108
-            ],
109
-            'publishbox'   => [
110
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
111
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
112
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
113
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
114
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
115
-            ],
116
-        ];
117
-    }
118
-
119
-
120
-    /**
121
-     * Sets the page routes property for this admin page group.
122
-     */
123
-    protected function _set_page_routes()
124
-    {
125
-        // load formatter helper
126
-        // load field generator helper
127
-        // is there a evt_id in the request?
128
-        $evt_id             = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
129
-            ? $this->_req_data['EVT_ID']
130
-            : 0;
131
-        $evt_id             = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
132
-        $this->_page_routes = [
133
-            'default'                       => [
134
-                'func'       => '_events_overview_list_table',
135
-                'capability' => 'ee_read_events',
136
-            ],
137
-            'create_new'                    => [
138
-                'func'       => '_create_new_cpt_item',
139
-                'capability' => 'ee_edit_events',
140
-            ],
141
-            'edit'                          => [
142
-                'func'       => '_edit_cpt_item',
143
-                'capability' => 'ee_edit_event',
144
-                'obj_id'     => $evt_id,
145
-            ],
146
-            'copy_event'                    => [
147
-                'func'       => '_copy_events',
148
-                'capability' => 'ee_edit_event',
149
-                'obj_id'     => $evt_id,
150
-                'noheader'   => true,
151
-            ],
152
-            'trash_event'                   => [
153
-                'func'       => '_trash_or_restore_event',
154
-                'args'       => ['event_status' => 'trash'],
155
-                'capability' => 'ee_delete_event',
156
-                'obj_id'     => $evt_id,
157
-                'noheader'   => true,
158
-            ],
159
-            'trash_events'                  => [
160
-                'func'       => '_trash_or_restore_events',
161
-                'args'       => ['event_status' => 'trash'],
162
-                'capability' => 'ee_delete_events',
163
-                'noheader'   => true,
164
-            ],
165
-            'restore_event'                 => [
166
-                'func'       => '_trash_or_restore_event',
167
-                'args'       => ['event_status' => 'draft'],
168
-                'capability' => 'ee_delete_event',
169
-                'obj_id'     => $evt_id,
170
-                'noheader'   => true,
171
-            ],
172
-            'restore_events'                => [
173
-                'func'       => '_trash_or_restore_events',
174
-                'args'       => ['event_status' => 'draft'],
175
-                'capability' => 'ee_delete_events',
176
-                'noheader'   => true,
177
-            ],
178
-            'delete_event'                  => [
179
-                'func'       => '_delete_event',
180
-                'capability' => 'ee_delete_event',
181
-                'obj_id'     => $evt_id,
182
-                'noheader'   => true,
183
-            ],
184
-            'delete_events'                 => [
185
-                'func'       => '_delete_events',
186
-                'capability' => 'ee_delete_events',
187
-                'noheader'   => true,
188
-            ],
189
-            'view_report'                   => [
190
-                'func'       => '_view_report',
191
-                'capability' => 'ee_edit_events',
192
-            ],
193
-            'default_event_settings'        => [
194
-                'func'       => '_default_event_settings',
195
-                'capability' => 'manage_options',
196
-            ],
197
-            'update_default_event_settings' => [
198
-                'func'       => '_update_default_event_settings',
199
-                'capability' => 'manage_options',
200
-                'noheader'   => true,
201
-            ],
202
-            'template_settings'             => [
203
-                'func'       => '_template_settings',
204
-                'capability' => 'manage_options',
205
-            ],
206
-            // event category tab related
207
-            'add_category'                  => [
208
-                'func'       => '_category_details',
209
-                'capability' => 'ee_edit_event_category',
210
-                'args'       => ['add'],
211
-            ],
212
-            'edit_category'                 => [
213
-                'func'       => '_category_details',
214
-                'capability' => 'ee_edit_event_category',
215
-                'args'       => ['edit'],
216
-            ],
217
-            'delete_categories'             => [
218
-                'func'       => '_delete_categories',
219
-                'capability' => 'ee_delete_event_category',
220
-                'noheader'   => true,
221
-            ],
222
-            'delete_category'               => [
223
-                'func'       => '_delete_categories',
224
-                'capability' => 'ee_delete_event_category',
225
-                'noheader'   => true,
226
-            ],
227
-            'insert_category'               => [
228
-                'func'       => '_insert_or_update_category',
229
-                'args'       => ['new_category' => true],
230
-                'capability' => 'ee_edit_event_category',
231
-                'noheader'   => true,
232
-            ],
233
-            'update_category'               => [
234
-                'func'       => '_insert_or_update_category',
235
-                'args'       => ['new_category' => false],
236
-                'capability' => 'ee_edit_event_category',
237
-                'noheader'   => true,
238
-            ],
239
-            'category_list'                 => [
240
-                'func'       => '_category_list_table',
241
-                'capability' => 'ee_manage_event_categories',
242
-            ],
243
-            'preview_deletion'              => [
244
-                'func'       => 'previewDeletion',
245
-                'capability' => 'ee_delete_events',
246
-            ],
247
-            'confirm_deletion'              => [
248
-                'func'       => 'confirmDeletion',
249
-                'capability' => 'ee_delete_events',
250
-                'noheader'   => true,
251
-            ],
252
-        ];
253
-    }
254
-
255
-
256
-    /**
257
-     * Set the _page_config property for this admin page group.
258
-     */
259
-    protected function _set_page_config()
260
-    {
261
-        $this->_page_config = [
262
-            'default'                => [
263
-                'nav'           => [
264
-                    'label' => esc_html__('Overview', 'event_espresso'),
265
-                    'order' => 10,
266
-                ],
267
-                'list_table'    => 'Events_Admin_List_Table',
268
-                'help_tabs'     => [
269
-                    'events_overview_help_tab'                       => [
270
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
271
-                        'filename' => 'events_overview',
272
-                    ],
273
-                    'events_overview_table_column_headings_help_tab' => [
274
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
275
-                        'filename' => 'events_overview_table_column_headings',
276
-                    ],
277
-                    'events_overview_filters_help_tab'               => [
278
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
279
-                        'filename' => 'events_overview_filters',
280
-                    ],
281
-                    'events_overview_view_help_tab'                  => [
282
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
283
-                        'filename' => 'events_overview_views',
284
-                    ],
285
-                    'events_overview_other_help_tab'                 => [
286
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
287
-                        'filename' => 'events_overview_other',
288
-                    ],
289
-                ],
290
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
291
-                // 'help_tour'     => [
292
-                //     'Event_Overview_Help_Tour',
293
-                //     // 'New_Features_Test_Help_Tour' for testing multiple help tour
294
-                // ],
295
-                'qtips'         => ['EE_Event_List_Table_Tips'],
296
-                'require_nonce' => false,
297
-            ],
298
-            'create_new'             => [
299
-                'nav'           => [
300
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
301
-                    'order'      => 5,
302
-                    'persistent' => false,
303
-                ],
304
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
305
-                'help_tabs'     => [
306
-                    'event_editor_help_tab'                            => [
307
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
308
-                        'filename' => 'event_editor',
309
-                    ],
310
-                    'event_editor_title_richtexteditor_help_tab'       => [
311
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
312
-                        'filename' => 'event_editor_title_richtexteditor',
313
-                    ],
314
-                    'event_editor_venue_details_help_tab'              => [
315
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
316
-                        'filename' => 'event_editor_venue_details',
317
-                    ],
318
-                    'event_editor_event_datetimes_help_tab'            => [
319
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
320
-                        'filename' => 'event_editor_event_datetimes',
321
-                    ],
322
-                    'event_editor_event_tickets_help_tab'              => [
323
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
324
-                        'filename' => 'event_editor_event_tickets',
325
-                    ],
326
-                    'event_editor_event_registration_options_help_tab' => [
327
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
328
-                        'filename' => 'event_editor_event_registration_options',
329
-                    ],
330
-                    'event_editor_tags_categories_help_tab'            => [
331
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
332
-                        'filename' => 'event_editor_tags_categories',
333
-                    ],
334
-                    'event_editor_questions_registrants_help_tab'      => [
335
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
336
-                        'filename' => 'event_editor_questions_registrants',
337
-                    ],
338
-                    'event_editor_save_new_event_help_tab'             => [
339
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
340
-                        'filename' => 'event_editor_save_new_event',
341
-                    ],
342
-                    'event_editor_other_help_tab'                      => [
343
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
344
-                        'filename' => 'event_editor_other',
345
-                    ],
346
-                ],
347
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
348
-                // 'help_tour'     => [
349
-                //     'Event_Editor_Help_Tour',
350
-                // ],
351
-                'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
352
-                'require_nonce' => false,
353
-            ],
354
-            'edit'                   => [
355
-                'nav'           => [
356
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
357
-                    'order'      => 5,
358
-                    'persistent' => false,
359
-                    'url'        => isset($this->_req_data['post'])
360
-                        ? EE_Admin_Page::add_query_args_and_nonce(
361
-                            ['post' => $this->_req_data['post'], 'action' => 'edit'],
362
-                            $this->_current_page_view_url
363
-                        )
364
-                        : $this->_admin_base_url,
365
-                ],
366
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
367
-                'help_tabs'     => [
368
-                    'event_editor_help_tab'                            => [
369
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
370
-                        'filename' => 'event_editor',
371
-                    ],
372
-                    'event_editor_title_richtexteditor_help_tab'       => [
373
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
374
-                        'filename' => 'event_editor_title_richtexteditor',
375
-                    ],
376
-                    'event_editor_venue_details_help_tab'              => [
377
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
378
-                        'filename' => 'event_editor_venue_details',
379
-                    ],
380
-                    'event_editor_event_datetimes_help_tab'            => [
381
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
382
-                        'filename' => 'event_editor_event_datetimes',
383
-                    ],
384
-                    'event_editor_event_tickets_help_tab'              => [
385
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
386
-                        'filename' => 'event_editor_event_tickets',
387
-                    ],
388
-                    'event_editor_event_registration_options_help_tab' => [
389
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
390
-                        'filename' => 'event_editor_event_registration_options',
391
-                    ],
392
-                    'event_editor_tags_categories_help_tab'            => [
393
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
394
-                        'filename' => 'event_editor_tags_categories',
395
-                    ],
396
-                    'event_editor_questions_registrants_help_tab'      => [
397
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
398
-                        'filename' => 'event_editor_questions_registrants',
399
-                    ],
400
-                    'event_editor_save_new_event_help_tab'             => [
401
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
402
-                        'filename' => 'event_editor_save_new_event',
403
-                    ],
404
-                    'event_editor_other_help_tab'                      => [
405
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
406
-                        'filename' => 'event_editor_other',
407
-                    ],
408
-                ],
409
-                'require_nonce' => false,
410
-            ],
411
-            'default_event_settings' => [
412
-                'nav'           => [
413
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
414
-                    'order' => 40,
415
-                ],
416
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
417
-                'labels'        => [
418
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
419
-                ],
420
-                'help_tabs'     => [
421
-                    'default_settings_help_tab'        => [
422
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
423
-                        'filename' => 'events_default_settings',
424
-                    ],
425
-                    'default_settings_status_help_tab' => [
426
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
427
-                        'filename' => 'events_default_settings_status',
428
-                    ],
429
-                    'default_maximum_tickets_help_tab' => [
430
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
431
-                        'filename' => 'events_default_settings_max_tickets',
432
-                    ],
433
-                ],
434
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
435
-                // 'help_tour'     => ['Event_Default_Settings_Help_Tour'],
436
-                'require_nonce' => false,
437
-            ],
438
-            // template settings
439
-            'template_settings'      => [
440
-                'nav'           => [
441
-                    'label' => esc_html__('Templates', 'event_espresso'),
442
-                    'order' => 30,
443
-                ],
444
-                'metaboxes'     => $this->_default_espresso_metaboxes,
445
-                'help_tabs'     => [
446
-                    'general_settings_templates_help_tab' => [
447
-                        'title'    => esc_html__('Templates', 'event_espresso'),
448
-                        'filename' => 'general_settings_templates',
449
-                    ],
450
-                ],
451
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
452
-                // 'help_tour'     => ['Templates_Help_Tour'],
453
-                'require_nonce' => false,
454
-            ],
455
-            // event category stuff
456
-            'add_category'           => [
457
-                'nav'           => [
458
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
459
-                    'order'      => 15,
460
-                    'persistent' => false,
461
-                ],
462
-                'help_tabs'     => [
463
-                    'add_category_help_tab' => [
464
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
465
-                        'filename' => 'events_add_category',
466
-                    ],
467
-                ],
468
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
469
-                // 'help_tour'     => ['Event_Add_Category_Help_Tour'],
470
-                'metaboxes'     => ['_publish_post_box'],
471
-                'require_nonce' => false,
472
-            ],
473
-            'edit_category'          => [
474
-                'nav'           => [
475
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
476
-                    'order'      => 15,
477
-                    'persistent' => false,
478
-                    'url'        => isset($this->_req_data['EVT_CAT_ID'])
479
-                        ? add_query_arg(
480
-                            ['EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']],
481
-                            $this->_current_page_view_url
482
-                        )
483
-                        : $this->_admin_base_url,
484
-                ],
485
-                'help_tabs'     => [
486
-                    'edit_category_help_tab' => [
487
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
488
-                        'filename' => 'events_edit_category',
489
-                    ],
490
-                ],
491
-                /*'help_tour' => ['Event_Edit_Category_Help_Tour'],*/
492
-                'metaboxes'     => ['_publish_post_box'],
493
-                'require_nonce' => false,
494
-            ],
495
-            'category_list'          => [
496
-                'nav'           => [
497
-                    'label' => esc_html__('Categories', 'event_espresso'),
498
-                    'order' => 20,
499
-                ],
500
-                'list_table'    => 'Event_Categories_Admin_List_Table',
501
-                'help_tabs'     => [
502
-                    'events_categories_help_tab'                       => [
503
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
504
-                        'filename' => 'events_categories',
505
-                    ],
506
-                    'events_categories_table_column_headings_help_tab' => [
507
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
508
-                        'filename' => 'events_categories_table_column_headings',
509
-                    ],
510
-                    'events_categories_view_help_tab'                  => [
511
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
512
-                        'filename' => 'events_categories_views',
513
-                    ],
514
-                    'events_categories_other_help_tab'                 => [
515
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
516
-                        'filename' => 'events_categories_other',
517
-                    ],
518
-                ],
519
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
520
-                // 'help_tour'     => [
521
-                //     'Event_Categories_Help_Tour',
522
-                // ],
523
-                'metaboxes'     => $this->_default_espresso_metaboxes,
524
-                'require_nonce' => false,
525
-            ],
526
-            'preview_deletion'       => [
527
-                'nav'           => [
528
-                    'label'      => esc_html__('Preview Deletion', 'event_espresso'),
529
-                    'order'      => 15,
530
-                    'persistent' => false,
531
-                    'url'        => '',
532
-                ],
533
-                'require_nonce' => false,
534
-            ],
535
-        ];
536
-        // only load EE_Event_Editor_Decaf_Tips if domain is not caffeinated
537
-        $domain = $this->loader->getShared('EventEspresso\core\domain\Domain');
538
-        if (! $domain->isCaffeinated()) {
539
-            $this->_page_config['create_new']['qtips'] = ['EE_Event_Editor_Decaf_Tips'];
540
-            $this->_page_config['edit']['qtips']       = ['EE_Event_Editor_Decaf_Tips'];
541
-        }
542
-    }
543
-
544
-
545
-    /**
546
-     * Used to register any global screen options if necessary for every route in this admin page group.
547
-     */
548
-    protected function _add_screen_options()
549
-    {
550
-    }
551
-
552
-
553
-    /**
554
-     * Implementing the screen options for the 'default' route.
555
-     *
556
-     * @throws InvalidArgumentException
557
-     * @throws InvalidDataTypeException
558
-     * @throws InvalidInterfaceException
559
-     */
560
-    protected function _add_screen_options_default()
561
-    {
562
-        $this->_per_page_screen_option();
563
-    }
564
-
565
-
566
-    /**
567
-     * Implementing screen options for the category list route.
568
-     *
569
-     * @throws InvalidArgumentException
570
-     * @throws InvalidDataTypeException
571
-     * @throws InvalidInterfaceException
572
-     */
573
-    protected function _add_screen_options_category_list()
574
-    {
575
-        $page_title              = $this->_admin_page_title;
576
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
577
-        $this->_per_page_screen_option();
578
-        $this->_admin_page_title = $page_title;
579
-    }
580
-
581
-
582
-    /**
583
-     * Used to register any global feature pointers for the admin page group.
584
-     */
585
-    protected function _add_feature_pointers()
586
-    {
587
-    }
588
-
589
-
590
-    /**
591
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
592
-     */
593
-    public function load_scripts_styles()
594
-    {
595
-        wp_register_style(
596
-            'events-admin-css',
597
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
598
-            [],
599
-            EVENT_ESPRESSO_VERSION
600
-        );
601
-        wp_register_style(
602
-            'ee-cat-admin',
603
-            EVENTS_ASSETS_URL . 'ee-cat-admin.css',
604
-            [],
605
-            EVENT_ESPRESSO_VERSION
606
-        );
607
-        wp_enqueue_style('events-admin-css');
608
-        wp_enqueue_style('ee-cat-admin');
609
-        // scripts
610
-        wp_register_script(
611
-            'event_editor_js',
612
-            EVENTS_ASSETS_URL . 'event_editor.js',
613
-            ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
614
-            EVENT_ESPRESSO_VERSION,
615
-            true
616
-        );
617
-    }
618
-
619
-
620
-    /**
621
-     * Enqueuing scripts and styles specific to this view
622
-     */
623
-    public function load_scripts_styles_create_new()
624
-    {
625
-        $this->load_scripts_styles_edit();
626
-    }
627
-
628
-
629
-    /**
630
-     * Enqueuing scripts and styles specific to this view
631
-     */
632
-    public function load_scripts_styles_edit()
633
-    {
634
-        // styles
635
-        wp_enqueue_style('espresso-ui-theme');
636
-        wp_register_style(
637
-            'event-editor-css',
638
-            EVENTS_ASSETS_URL . 'event-editor.css',
639
-            ['ee-admin-css'],
640
-            EVENT_ESPRESSO_VERSION
641
-        );
642
-        wp_enqueue_style('event-editor-css');
643
-        // scripts
644
-        if (! $this->admin_config->useAdvancedEditor()) {
645
-            wp_register_script(
646
-                'event-datetime-metabox',
647
-                EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
648
-                ['event_editor_js', 'ee-datepicker'],
649
-                EVENT_ESPRESSO_VERSION
650
-            );
651
-            wp_enqueue_script('event-datetime-metabox');
652
-        }
653
-    }
654
-
655
-
656
-    /**
657
-     * Populating the _views property for the category list table view.
658
-     */
659
-    protected function _set_list_table_views_category_list()
660
-    {
661
-        $this->_views = [
662
-            'all' => [
663
-                'slug'        => 'all',
664
-                'label'       => esc_html__('All', 'event_espresso'),
665
-                'count'       => 0,
666
-                'bulk_action' => [
667
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
668
-                ],
669
-            ],
670
-        ];
671
-    }
672
-
673
-
674
-    /**
675
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
676
-     */
677
-    public function admin_init()
678
-    {
679
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
680
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
681
-            'event_espresso'
682
-        );
683
-    }
684
-
685
-
686
-    /**
687
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
688
-     * group.
689
-     */
690
-    public function admin_notices()
691
-    {
692
-    }
693
-
694
-
695
-    /**
696
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
697
-     * this admin page group.
698
-     */
699
-    public function admin_footer_scripts()
700
-    {
701
-    }
702
-
703
-
704
-    /**
705
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
706
-     * warning (via EE_Error::add_error());
707
-     *
708
-     * @param EE_Event $event Event object
709
-     * @param string   $req_type
710
-     * @return void
711
-     * @throws EE_Error
712
-     * @access public
713
-     */
714
-    public function verify_event_edit($event = null, $req_type = '')
715
-    {
716
-        // don't need to do this when processing
717
-        if (! empty($req_type)) {
718
-            return;
719
-        }
720
-        // no event?
721
-        if (! $event instanceof EE_Event) {
722
-            $event = $this->_cpt_model_obj;
723
-        }
724
-        // STILL no event?
725
-        if (! $event instanceof EE_Event) {
726
-            return;
727
-        }
728
-        $orig_status = $event->status();
729
-        // first check if event is active.
730
-        if (
731
-            $orig_status === EEM_Event::cancelled
732
-            || $orig_status === EEM_Event::postponed
733
-            || $event->is_expired()
734
-            || $event->is_inactive()
735
-        ) {
736
-            return;
737
-        }
738
-        // made it here so it IS active... next check that any of the tickets are sold.
739
-        if ($event->is_sold_out(true)) {
740
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
741
-                EE_Error::add_attention(
742
-                    sprintf(
743
-                        esc_html__(
744
-                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
745
-                            'event_espresso'
746
-                        ),
747
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
748
-                    )
749
-                );
750
-            }
751
-            return;
752
-        }
753
-        if ($orig_status === EEM_Event::sold_out) {
754
-            EE_Error::add_attention(
755
-                sprintf(
756
-                    esc_html__(
757
-                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
758
-                        'event_espresso'
759
-                    ),
760
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
761
-                )
762
-            );
763
-        }
764
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
765
-        if (! $event->tickets_on_sale()) {
766
-            return;
767
-        }
768
-        // made it here so show warning
769
-        $this->_edit_event_warning();
770
-    }
771
-
772
-
773
-    /**
774
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
775
-     * When needed, hook this into a EE_Error::add_error() notice.
776
-     *
777
-     * @access protected
778
-     * @return void
779
-     */
780
-    protected function _edit_event_warning()
781
-    {
782
-        // we don't want to add warnings during these requests
783
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
784
-            return;
785
-        }
786
-        EE_Error::add_attention(
787
-            sprintf(
788
-                esc_html__(
789
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
790
-                    'event_espresso'
791
-                ),
792
-                '<a class="espresso-help-tab-lnk">',
793
-                '</a>'
794
-            )
795
-        );
796
-    }
797
-
798
-
799
-    /**
800
-     * When a user is creating a new event, notify them if they haven't set their timezone.
801
-     * Otherwise, do the normal logic
802
-     *
803
-     * @return void
804
-     * @throws EE_Error
805
-     * @throws InvalidArgumentException
806
-     * @throws InvalidDataTypeException
807
-     * @throws InvalidInterfaceException
808
-     */
809
-    protected function _create_new_cpt_item()
810
-    {
811
-        $has_timezone_string = get_option('timezone_string');
812
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
813
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
814
-            EE_Error::add_attention(
815
-                sprintf(
816
-                    __(
817
-                        'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
818
-                        'event_espresso'
819
-                    ),
820
-                    '<br>',
821
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
822
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
823
-                    . '</select>',
824
-                    '<button class="button button-secondary timezone-submit">',
825
-                    '</button><span class="spinner"></span>'
826
-                ),
827
-                __FILE__,
828
-                __FUNCTION__,
829
-                __LINE__
830
-            );
831
-        }
832
-        parent::_create_new_cpt_item();
833
-    }
834
-
835
-
836
-    /**
837
-     * Sets the _views property for the default route in this admin page group.
838
-     */
839
-    protected function _set_list_table_views_default()
840
-    {
841
-        $this->_views = [
842
-            'all'   => [
843
-                'slug'        => 'all',
844
-                'label'       => esc_html__('View All Events', 'event_espresso'),
845
-                'count'       => 0,
846
-                'bulk_action' => [
847
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
848
-                ],
849
-            ],
850
-            'draft' => [
851
-                'slug'        => 'draft',
852
-                'label'       => esc_html__('Draft', 'event_espresso'),
853
-                'count'       => 0,
854
-                'bulk_action' => [
855
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
856
-                ],
857
-            ],
858
-        ];
859
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
860
-            $this->_views['trash'] = [
861
-                'slug'        => 'trash',
862
-                'label'       => esc_html__('Trash', 'event_espresso'),
863
-                'count'       => 0,
864
-                'bulk_action' => [
865
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
866
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
867
-                ],
868
-            ];
869
-        }
870
-    }
871
-
872
-
873
-    /**
874
-     * Provides the legend item array for the default list table view.
875
-     *
876
-     * @return array
877
-     */
878
-    protected function _event_legend_items()
879
-    {
880
-        $items    = [
881
-            'view_details'   => [
882
-                'class' => 'dashicons dashicons-search',
883
-                'desc'  => esc_html__('View Event', 'event_espresso'),
884
-            ],
885
-            'edit_event'     => [
886
-                'class' => 'ee-icon ee-icon-calendar-edit',
887
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
888
-            ],
889
-            'view_attendees' => [
890
-                'class' => 'dashicons dashicons-groups',
891
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
892
-            ],
893
-        ];
894
-        $items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
895
-        $statuses = [
896
-            'sold_out_status'  => [
897
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
898
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
899
-            ],
900
-            'active_status'    => [
901
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
902
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
903
-            ],
904
-            'upcoming_status'  => [
905
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
906
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
907
-            ],
908
-            'postponed_status' => [
909
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
910
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
911
-            ],
912
-            'cancelled_status' => [
913
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
914
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
915
-            ],
916
-            'expired_status'   => [
917
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
918
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
919
-            ],
920
-            'inactive_status'  => [
921
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
922
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
923
-            ],
924
-        ];
925
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
926
-        return array_merge($items, $statuses);
927
-    }
928
-
929
-
930
-    /**
931
-     * @return EEM_Event
932
-     * @throws EE_Error
933
-     * @throws InvalidArgumentException
934
-     * @throws InvalidDataTypeException
935
-     * @throws InvalidInterfaceException
936
-     * @throws ReflectionException
937
-     */
938
-    private function _event_model()
939
-    {
940
-        if (! $this->_event_model instanceof EEM_Event) {
941
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
942
-        }
943
-        return $this->_event_model;
944
-    }
945
-
946
-
947
-    /**
948
-     * Adds extra buttons to the WP CPT permalink field row.
949
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
950
-     *
951
-     * @param string $return    the current html
952
-     * @param int    $id        the post id for the page
953
-     * @param string $new_title What the title is
954
-     * @param string $new_slug  what the slug is
955
-     * @return string            The new html string for the permalink area
956
-     */
957
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
958
-    {
959
-        // make sure this is only when editing
960
-        if (! empty($id)) {
961
-            $post   = get_post($id);
962
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
963
-                       . esc_html__('Shortcode', 'event_espresso')
964
-                       . '</a> ';
965
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
966
-                       . $post->ID
967
-                       . ']">';
968
-        }
969
-        return $return;
970
-    }
971
-
972
-
973
-    /**
974
-     * _events_overview_list_table
975
-     * This contains the logic for showing the events_overview list
976
-     *
977
-     * @access protected
978
-     * @return void
979
-     * @throws DomainException
980
-     * @throws EE_Error
981
-     * @throws InvalidArgumentException
982
-     * @throws InvalidDataTypeException
983
-     * @throws InvalidInterfaceException
984
-     */
985
-    protected function _events_overview_list_table()
986
-    {
987
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
988
-        $this->_template_args['after_list_table']                           =
989
-            ! empty($this->_template_args['after_list_table'])
990
-                ? (array) $this->_template_args['after_list_table']
991
-                : [];
992
-        $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
993
-            . EEH_Template::get_button_or_link(
994
-                get_post_type_archive_link('espresso_events'),
995
-                esc_html__('View Event Archive Page', 'event_espresso'),
996
-                'button'
997
-            );
998
-        $this->_template_args['after_list_table']['legend']                 =
999
-            $this->_display_legend($this->_event_legend_items());
1000
-        $this->_admin_page_title                                            .= ' '
1001
-            . $this->get_action_link_or_button(
1002
-                'create_new',
1003
-                'add',
1004
-                [],
1005
-                'add-new-h2'
1006
-            );
1007
-        $this->display_admin_list_table_page_with_no_sidebar();
1008
-    }
1009
-
1010
-
1011
-    /**
1012
-     * this allows for extra misc actions in the default WP publish box
1013
-     *
1014
-     * @return void
1015
-     * @throws DomainException
1016
-     * @throws EE_Error
1017
-     * @throws InvalidArgumentException
1018
-     * @throws InvalidDataTypeException
1019
-     * @throws InvalidInterfaceException
1020
-     * @throws ReflectionException
1021
-     */
1022
-    public function extra_misc_actions_publish_box()
1023
-    {
1024
-        $this->_generate_publish_box_extra_content();
1025
-    }
1026
-
1027
-
1028
-    /**
1029
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1030
-     * saved.
1031
-     * Typically you would use this to save any additional data.
1032
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
1033
-     * ALSO very important.  When a post transitions from scheduled to published,
1034
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1035
-     * other meta saves. So MAKE sure that you handle this accordingly.
1036
-     *
1037
-     * @access protected
1038
-     * @abstract
1039
-     * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
1040
-     * @param object $post    The post object of the cpt that was saved.
1041
-     * @return void
1042
-     * @throws EE_Error
1043
-     * @throws InvalidArgumentException
1044
-     * @throws InvalidDataTypeException
1045
-     * @throws InvalidInterfaceException
1046
-     * @throws ReflectionException
1047
-     */
1048
-    protected function _insert_update_cpt_item($post_id, $post)
1049
-    {
1050
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1051
-            // get out we're not processing an event save.
1052
-            return;
1053
-        }
1054
-        $event_values = [
1055
-            'EVT_member_only'     => ! empty($this->_req_data['member_only']) ? 1 : 0,
1056
-            'EVT_allow_overflow'  => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
1057
-            'EVT_timezone_string' => ! empty($this->_req_data['timezone_string'])
1058
-                ? sanitize_text_field($this->_req_data['timezone_string'])
1059
-                : null,
1060
-        ];
1061
-        /** @var FeatureFlags $flags */
1062
-        $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1063
-        // check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1064
-        if (! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1065
-            $event_values['EVT_display_ticket_selector']     =
1066
-                ! empty($this->_req_data['display_ticket_selector'])
1067
-                    ? 1
1068
-                    : 0;
1069
-            $event_values['EVT_additional_limit']            = min(
1070
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1071
-                ! empty($this->_req_data['additional_limit'])
1072
-                    ? absint($this->_req_data['additional_limit'])
1073
-                    : null
1074
-            );
1075
-            $event_values['EVT_default_registration_status'] =
1076
-                ! empty($this->_req_data['EVT_default_registration_status'])
1077
-                    ? sanitize_text_field($this->_req_data['EVT_default_registration_status'])
1078
-                    : EE_Registry::instance()->CFG->registration->default_STS_ID;
1079
-            $event_values['EVT_external_URL']                = ! empty($this->_req_data['externalURL'])
1080
-                ? esc_url_raw($this->_req_data['externalURL'])
1081
-                : null;
1082
-            $event_values['EVT_phone']                       = ! empty($this->_req_data['event_phone'])
1083
-                ? sanitize_text_field($this->_req_data['event_phone'])
1084
-                : null;
1085
-        }
1086
-        // update event
1087
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1088
-        // get event_object for other metaboxes...
1089
-        // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1090
-        // i have to setup where conditions to override the filters in the model that filter out autodraft
1091
-        // and inherit statuses so we GET the inherit id!
1092
-        $get_one_where = [
1093
-            $this->_event_model()->primary_key_name() => $post_id,
1094
-            'OR'                                      => [
1095
-                'status'   => $post->post_status,
1096
-                // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1097
-                // but the returned object here has a status of "publish", so use the original post status as well
1098
-                'status*1' => $this->_req_data['original_post_status'],
1099
-            ],
1100
-        ];
1101
-        $event         = $this->_event_model()->get_one([$get_one_where]);
1102
-        // the following are default callbacks for event attachment updates
1103
-        // that can be overridden by caffeinated functionality and/or addons.
1104
-        $event_update_callbacks = apply_filters(
1105
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1106
-            [
1107
-                [$this, '_default_venue_update'],
1108
-                [$this, '_default_tickets_update'],
1109
-            ]
1110
-        );
1111
-        $att_success            = true;
1112
-        foreach ($event_update_callbacks as $e_callback) {
1113
-            $_success = is_callable($e_callback)
1114
-                ? $e_callback($event, $this->_req_data)
1115
-                : false;
1116
-            // if ANY of these updates fail then we want the appropriate global error message
1117
-            $att_success = ! $att_success ? $att_success : $_success;
1118
-        }
1119
-        // any errors?
1120
-        if ($success && false === $att_success) {
1121
-            EE_Error::add_error(
1122
-                esc_html__(
1123
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1124
-                    'event_espresso'
1125
-                ),
1126
-                __FILE__,
1127
-                __FUNCTION__,
1128
-                __LINE__
1129
-            );
1130
-        } elseif ($success === false) {
1131
-            EE_Error::add_error(
1132
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1133
-                __FILE__,
1134
-                __FUNCTION__,
1135
-                __LINE__
1136
-            );
1137
-        }
1138
-    }
1139
-
1140
-
1141
-    /**
1142
-     * @param int $post_id
1143
-     * @param int $revision_id
1144
-     * @throws EE_Error
1145
-     * @throws InvalidArgumentException
1146
-     * @throws InvalidDataTypeException
1147
-     * @throws InvalidInterfaceException
1148
-     * @throws ReflectionException
1149
-     * @see parent::restore_item()
1150
-     */
1151
-    protected function _restore_cpt_item($post_id, $revision_id)
1152
-    {
1153
-        // copy existing event meta to new post
1154
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1155
-        if ($post_evt instanceof EE_Event) {
1156
-            // meta revision restore
1157
-            $post_evt->restore_revision($revision_id);
1158
-            // related objs restore
1159
-            $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1160
-        }
1161
-    }
1162
-
1163
-
1164
-    /**
1165
-     * Attach the venue to the Event
1166
-     *
1167
-     * @param EE_Event $evtobj Event Object to add the venue to
1168
-     * @param array    $data   The request data from the form
1169
-     * @return bool           Success or fail.
1170
-     * @throws EE_Error
1171
-     * @throws InvalidArgumentException
1172
-     * @throws InvalidDataTypeException
1173
-     * @throws InvalidInterfaceException
1174
-     * @throws ReflectionException
1175
-     */
1176
-    protected function _default_venue_update(EE_Event $evtobj, $data)
1177
-    {
1178
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1179
-        $venue_model   = EE_Registry::instance()->load_model('Venue');
1180
-        $rows_affected = null;
1181
-        $venue_id      = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1182
-        // very important.  If we don't have a venue name...
1183
-        // then we'll get out because not necessary to create empty venue
1184
-        if (empty($data['venue_title'])) {
1185
-            return false;
1186
-        }
1187
-        $venue_array = [
1188
-            'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1189
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1190
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1191
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1192
-            'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1193
-                : null,
1194
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1195
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1196
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1197
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1198
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1199
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1200
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1201
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1202
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1203
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1204
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1205
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1206
-            'status'              => 'publish',
1207
-        ];
1208
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1209
-        if (! empty($venue_id)) {
1210
-            $update_where  = [$venue_model->primary_key_name() => $venue_id];
1211
-            $rows_affected = $venue_model->update($venue_array, [$update_where]);
1212
-            // we've gotta make sure that the venue is always attached to a revision..
1213
-            // add_relation_to should take care of making sure that the relation is already present.
1214
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1215
-            return $rows_affected > 0;
1216
-        }
1217
-        // we insert the venue
1218
-        $venue_id = $venue_model->insert($venue_array);
1219
-        $evtobj->_add_relation_to($venue_id, 'Venue');
1220
-        return ! empty($venue_id);
1221
-        // when we have the ancestor come in it's already been handled by the revision save.
1222
-    }
1223
-
1224
-
1225
-    /**
1226
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1227
-     *
1228
-     * @param EE_Event $evtobj The Event object we're attaching data to
1229
-     * @param array    $data   The request data from the form
1230
-     * @return array
1231
-     * @throws EE_Error
1232
-     * @throws InvalidArgumentException
1233
-     * @throws InvalidDataTypeException
1234
-     * @throws InvalidInterfaceException
1235
-     * @throws ReflectionException
1236
-     * @throws Exception
1237
-     */
1238
-    protected function _default_tickets_update(EE_Event $evtobj, $data)
1239
-    {
1240
-        if ($this->admin_config->useAdvancedEditor()) {
1241
-            return [];
1242
-        }
1243
-        $success               = true;
1244
-        $saved_dtt             = null;
1245
-        $saved_tickets         = [];
1246
-        $incoming_date_formats = ['Y-m-d', 'h:i a'];
1247
-        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1248
-            // trim all values to ensure any excess whitespace is removed.
1249
-            $dtt                = array_map('trim', $dtt);
1250
-            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1251
-                : $dtt['DTT_EVT_start'];
1252
-            $datetime_values    = [
1253
-                'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1254
-                'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1255
-                'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1256
-                'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1257
-                'DTT_order'     => $row,
1258
-            ];
1259
-            // if we have an id then let's get existing object first and then set the new values.
1260
-            //  Otherwise we instantiate a new object for save.
1261
-            if (! empty($dtt['DTT_ID'])) {
1262
-                $DTM = EE_Registry::instance()
1263
-                                  ->load_model('Datetime', [$evtobj->get_timezone()])
1264
-                                  ->get_one_by_ID($dtt['DTT_ID']);
1265
-                $DTM->set_date_format($incoming_date_formats[0]);
1266
-                $DTM->set_time_format($incoming_date_formats[1]);
1267
-                foreach ($datetime_values as $field => $value) {
1268
-                    $DTM->set($field, $value);
1269
-                }
1270
-                // make sure the $dtt_id here is saved in case after the add_relation_to() the autosave replaces it.
1271
-                // We need to do this so we dont' TRASH the parent DTT.
1272
-                $saved_dtts[ $DTM->ID() ] = $DTM;
1273
-            } else {
1274
-                $DTM = EE_Registry::instance()->load_class(
1275
-                    'Datetime',
1276
-                    [$datetime_values, $evtobj->get_timezone(), $incoming_date_formats],
1277
-                    false,
1278
-                    false
1279
-                );
1280
-                foreach ($datetime_values as $field => $value) {
1281
-                    $DTM->set($field, $value);
1282
-                }
1283
-            }
1284
-            $DTM->save();
1285
-            $DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1286
-            // load DTT helper
1287
-            // before going any further make sure our dates are setup correctly
1288
-            // so that the end date is always equal or greater than the start date.
1289
-            if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1290
-                $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1291
-                $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1292
-                $DTT->save();
1293
-            }
1294
-            // now we got to make sure we add the new DTT_ID to the $saved_dtts array
1295
-            //  because it is possible there was a new one created for the autosave.
1296
-            $saved_dtt = $DTT;
1297
-            $success   = ! $success ? $success : $DTT;
1298
-            // if ANY of these updates fail then we want the appropriate global error message.
1299
-            // //todo this is actually sucky we need a better error message but this is what it is for now.
1300
-        }
1301
-        // no dtts get deleted so we don't do any of that logic here.
1302
-        // update tickets next
1303
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1304
-        foreach ($data['edit_tickets'] as $row => $tkt) {
1305
-            $incoming_date_formats = ['Y-m-d', 'h:i a'];
1306
-            $update_prices         = false;
1307
-            $ticket_price          = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1308
-                ? $data['edit_prices'][ $row ][1]['PRC_amount']
1309
-                : 0;
1310
-            // trim inputs to ensure any excess whitespace is removed.
1311
-            $tkt = array_map('trim', $tkt);
1312
-            if (empty($tkt['TKT_start_date'])) {
1313
-                // let's use now in the set timezone.
1314
-                $now                   = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1315
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1316
-            }
1317
-            if (empty($tkt['TKT_end_date'])) {
1318
-                // use the start date of the first datetime
1319
-                $dtt                 = $evtobj->first_datetime();
1320
-                $tkt['TKT_end_date'] = $dtt->start_date_and_time(
1321
-                    $incoming_date_formats[0],
1322
-                    $incoming_date_formats[1]
1323
-                );
1324
-            }
1325
-            $TKT_values = [
1326
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1327
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1328
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1329
-                'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1330
-                'TKT_start_date'  => $tkt['TKT_start_date'],
1331
-                'TKT_end_date'    => $tkt['TKT_end_date'],
1332
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1333
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1334
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1335
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1336
-                'TKT_row'         => $row,
1337
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1338
-                'TKT_price'       => $ticket_price,
1339
-            ];
1340
-            // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
1341
-            // which means in turn that the prices will become new prices as well.
1342
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1343
-                $TKT_values['TKT_ID']         = 0;
1344
-                $TKT_values['TKT_is_default'] = 0;
1345
-                $TKT_values['TKT_price']      = $ticket_price;
1346
-                $update_prices                = true;
1347
-            }
1348
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1349
-            // we actually do our saves a head of doing any add_relations to because its entirely possible
1350
-            // that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1351
-            // keep in mind that if the TKT has been sold (and we have changed pricing information),
1352
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1353
-            if (! empty($tkt['TKT_ID'])) {
1354
-                $TKT = EE_Registry::instance()
1355
-                                  ->load_model('Ticket', [$evtobj->get_timezone()])
1356
-                                  ->get_one_by_ID($tkt['TKT_ID']);
1357
-                if ($TKT instanceof EE_Ticket) {
1358
-                    $ticket_sold = $TKT->count_related(
1359
-                        'Registration',
1360
-                        [
1361
-                            [
1362
-                                'STS_ID' => [
1363
-                                    'NOT IN',
1364
-                                    [EEM_Registration::status_id_incomplete],
1365
-                                ],
1366
-                            ],
1367
-                        ]
1368
-                    ) > 0;
1369
-                    // let's just check the total price for the existing ticket and determine if it matches the new
1370
-                    // total price.  if they are different then we create a new ticket (if tickets sold)
1371
-                    // if they aren't different then we go ahead and modify existing ticket.
1372
-                    $create_new_TKT = $ticket_sold
1373
-                                      && ! $TKT->deleted()
1374
-                                      && EEH_Money::compare_floats(
1375
-                                          $ticket_price,
1376
-                                          $TKT->get('TKT_price'),
1377
-                                          '!=='
1378
-                                      );
1379
-                    $TKT->set_date_format($incoming_date_formats[0]);
1380
-                    $TKT->set_time_format($incoming_date_formats[1]);
1381
-                    // set new values
1382
-                    foreach ($TKT_values as $field => $value) {
1383
-                        if ($field === 'TKT_qty') {
1384
-                            $TKT->set_qty($value);
1385
-                        } else {
1386
-                            $TKT->set($field, $value);
1387
-                        }
1388
-                    }
1389
-                    // if $create_new_TKT is false then we can safely update the existing ticket.
1390
-                    //  Otherwise we have to create a new ticket.
1391
-                    if ($create_new_TKT) {
1392
-                        // archive the old ticket first
1393
-                        $TKT->set('TKT_deleted', 1);
1394
-                        $TKT->save();
1395
-                        // make sure this ticket is still recorded in our saved_tkts
1396
-                        // so we don't run it through the regular trash routine.
1397
-                        $saved_tickets[ $TKT->ID() ] = $TKT;
1398
-                        // create new ticket that's a copy of the existing except a new id of course
1399
-                        // (and not archived) AND has the new TKT_price associated with it.
1400
-                        $TKT = clone $TKT;
1401
-                        $TKT->set('TKT_ID', 0);
1402
-                        $TKT->set('TKT_deleted', 0);
1403
-                        $TKT->set('TKT_price', $ticket_price);
1404
-                        $TKT->set('TKT_sold', 0);
1405
-                        // now we need to make sure that $new prices are created as well and attached to new ticket.
1406
-                        $update_prices = true;
1407
-                    }
1408
-                    // make sure price is set if it hasn't been already
1409
-                    $TKT->set('TKT_price', $ticket_price);
1410
-                }
1411
-            } else {
1412
-                // no TKT_id so a new TKT
1413
-                $TKT_values['TKT_price'] = $ticket_price;
1414
-                $TKT                     = EE_Registry::instance()->load_class('Ticket', [$TKT_values], false, false);
1415
-                if ($TKT instanceof EE_Ticket) {
1416
-                    // need to reset values to properly account for the date formats
1417
-                    $TKT->set_date_format($incoming_date_formats[0]);
1418
-                    $TKT->set_time_format($incoming_date_formats[1]);
1419
-                    $TKT->set_timezone($evtobj->get_timezone());
1420
-                    // set new values
1421
-                    foreach ($TKT_values as $field => $value) {
1422
-                        if ($field === 'TKT_qty') {
1423
-                            $TKT->set_qty($value);
1424
-                        } else {
1425
-                            $TKT->set($field, $value);
1426
-                        }
1427
-                    }
1428
-                    $update_prices = true;
1429
-                }
1430
-            }
1431
-            // cap ticket qty by datetime reg limits
1432
-            $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1433
-            // update ticket.
1434
-            $TKT->save();
1435
-            // before going any further make sure our dates are setup correctly
1436
-            // so that the end date is always equal or greater than the start date.
1437
-            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1438
-                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1439
-                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1440
-                $TKT->save();
1441
-            }
1442
-            // initially let's add the ticket to the dtt
1443
-            $saved_dtt->_add_relation_to($TKT, 'Ticket');
1444
-            $saved_tickets[ $TKT->ID() ] = $TKT;
1445
-            // add prices to ticket
1446
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1447
-        }
1448
-        // however now we need to handle permanently deleting tickets via the ui.
1449
-        //  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1450
-        //  However, it does allow for deleting tickets that have no tickets sold,
1451
-        // in which case we want to get rid of permanently because there is no need to save in db.
1452
-        $old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1453
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1454
-        foreach ($tickets_removed as $id) {
1455
-            $id = absint($id);
1456
-            // get the ticket for this id
1457
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1458
-            // need to get all the related datetimes on this ticket and remove from every single one of them
1459
-            // (remember this process can ONLY kick off if there are NO tkts_sold)
1460
-            $dtts = $tkt_to_remove->get_many_related('Datetime');
1461
-            foreach ($dtts as $dtt) {
1462
-                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1463
-            }
1464
-            // need to do the same for prices (except these prices can also be deleted because again,
1465
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1466
-            $tkt_to_remove->delete_related_permanently('Price');
1467
-            // finally let's delete this ticket
1468
-            // (which should not be blocked at this point b/c we've removed all our relationships)
1469
-            $tkt_to_remove->delete_permanently();
1470
-        }
1471
-        return [$saved_dtt, $saved_tickets];
1472
-    }
1473
-
1474
-
1475
-    /**
1476
-     * This attaches a list of given prices to a ticket.
1477
-     * Note we dont' have to worry about ever removing relationships (or archiving prices)
1478
-     * because if there is a change in price information on a ticket, a new ticket is created anyways
1479
-     * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket.
1480
-     *
1481
-     * @access  private
1482
-     * @param array     $prices     Array of prices from the form.
1483
-     * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1484
-     * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1485
-     * @return  void
1486
-     * @throws EE_Error
1487
-     * @throws InvalidArgumentException
1488
-     * @throws InvalidDataTypeException
1489
-     * @throws InvalidInterfaceException
1490
-     * @throws ReflectionException
1491
-     */
1492
-    private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1493
-    {
1494
-        foreach ($prices as $row => $prc) {
1495
-            $PRC_values = [
1496
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1497
-                'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1498
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1499
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1500
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1501
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1502
-                'PRC_order'      => $row,
1503
-            ];
1504
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
1505
-                $PRC_values['PRC_ID'] = 0;
1506
-                $PRC                  = EE_Registry::instance()->load_class('Price', [$PRC_values], false, false);
1507
-            } else {
1508
-                $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1509
-                // update this price with new values
1510
-                foreach ($PRC_values as $field => $newprc) {
1511
-                    $PRC->set($field, $newprc);
1512
-                }
1513
-                $PRC->save();
1514
-            }
1515
-            $ticket->_add_relation_to($PRC, 'Price');
1516
-        }
1517
-    }
1518
-
1519
-
1520
-    /**
1521
-     * Add in our autosave ajax handlers
1522
-     *
1523
-     */
1524
-    protected function _ee_autosave_create_new()
1525
-    {
1526
-    }
1527
-
1528
-
1529
-    /**
1530
-     * More autosave handlers.
1531
-     */
1532
-    protected function _ee_autosave_edit()
1533
-    {
1534
-    }
1535
-
1536
-
1537
-    /**
1538
-     *    _generate_publish_box_extra_content
1539
-     *
1540
-     * @throws DomainException
1541
-     * @throws EE_Error
1542
-     * @throws InvalidArgumentException
1543
-     * @throws InvalidDataTypeException
1544
-     * @throws InvalidInterfaceException
1545
-     * @throws ReflectionException
1546
-     */
1547
-    private function _generate_publish_box_extra_content()
1548
-    {
1549
-        // load formatter helper
1550
-        // args for getting related registrations
1551
-        $approved_query_args        = [
1552
-            [
1553
-                'REG_deleted' => 0,
1554
-                'STS_ID'      => EEM_Registration::status_id_approved,
1555
-            ],
1556
-        ];
1557
-        $not_approved_query_args    = [
1558
-            [
1559
-                'REG_deleted' => 0,
1560
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1561
-            ],
1562
-        ];
1563
-        $pending_payment_query_args = [
1564
-            [
1565
-                'REG_deleted' => 0,
1566
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1567
-            ],
1568
-        ];
1569
-        // publish box
1570
-        $publish_box_extra_args = [
1571
-            'view_approved_reg_url'        => add_query_arg(
1572
-                [
1573
-                    'action'      => 'default',
1574
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1575
-                    '_reg_status' => EEM_Registration::status_id_approved,
1576
-                ],
1577
-                REG_ADMIN_URL
1578
-            ),
1579
-            'view_not_approved_reg_url'    => add_query_arg(
1580
-                [
1581
-                    'action'      => 'default',
1582
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1583
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1584
-                ],
1585
-                REG_ADMIN_URL
1586
-            ),
1587
-            'view_pending_payment_reg_url' => add_query_arg(
1588
-                [
1589
-                    'action'      => 'default',
1590
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1591
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1592
-                ],
1593
-                REG_ADMIN_URL
1594
-            ),
1595
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1596
-                'Registration',
1597
-                $approved_query_args
1598
-            ),
1599
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1600
-                'Registration',
1601
-                $not_approved_query_args
1602
-            ),
1603
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1604
-                'Registration',
1605
-                $pending_payment_query_args
1606
-            ),
1607
-            'misc_pub_section_class'       => apply_filters(
1608
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1609
-                'misc-pub-section'
1610
-            ),
1611
-        ];
1612
-        ob_start();
1613
-        do_action(
1614
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1615
-            $this->_cpt_model_obj
1616
-        );
1617
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1618
-        // load template
1619
-        EEH_Template::display_template(
1620
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1621
-            $publish_box_extra_args
1622
-        );
1623
-    }
1624
-
1625
-
1626
-    /**
1627
-     * @return EE_Event
1628
-     */
1629
-    public function get_event_object()
1630
-    {
1631
-        return $this->_cpt_model_obj;
1632
-    }
1633
-
1634
-
1635
-
1636
-
1637
-    /** METABOXES * */
1638
-    /**
1639
-     * _register_event_editor_meta_boxes
1640
-     * add all metaboxes related to the event_editor
1641
-     *
1642
-     * @return void
1643
-     * @throws EE_Error
1644
-     * @throws InvalidArgumentException
1645
-     * @throws InvalidDataTypeException
1646
-     * @throws InvalidInterfaceException
1647
-     * @throws ReflectionException
1648
-     */
1649
-    protected function _register_event_editor_meta_boxes()
1650
-    {
1651
-        $this->verify_cpt_object();
1652
-        $use_advanced_editor = $this->admin_config->useAdvancedEditor();
1653
-        /** @var FeatureFlags $flags */
1654
-        $flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1655
-        // check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1656
-        if (! $use_advanced_editor || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1657
-            add_meta_box(
1658
-                'espresso_event_editor_event_options',
1659
-                esc_html__('Event Registration Options', 'event_espresso'),
1660
-                [$this, 'registration_options_meta_box'],
1661
-                $this->page_slug,
1662
-                'side'
1663
-            );
1664
-        }
1665
-        if (! $use_advanced_editor) {
1666
-            add_meta_box(
1667
-                'espresso_event_editor_tickets',
1668
-                esc_html__('Event Datetime & Ticket', 'event_espresso'),
1669
-                [$this, 'ticket_metabox'],
1670
-                $this->page_slug,
1671
-                'normal',
1672
-                'high'
1673
-            );
1674
-        } else {
1675
-            if ($flags->featureAllowed('use_reg_options_meta_box')) {
1676
-                add_action(
1677
-                    'add_meta_boxes_espresso_events',
1678
-                    function () {
1679
-                        global $current_screen;
1680
-                        remove_meta_box('authordiv', $current_screen, 'normal');
1681
-                    },
1682
-                    99
1683
-                );
1684
-            }
1685
-        }
1686
-        // NOTE: if you're looking for other metaboxes in here,
1687
-        // where a metabox has a related management page in the admin
1688
-        // you will find it setup in the related management page's "_Hooks" file.
1689
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1690
-    }
1691
-
1692
-
1693
-    /**
1694
-     * @throws DomainException
1695
-     * @throws EE_Error
1696
-     * @throws InvalidArgumentException
1697
-     * @throws InvalidDataTypeException
1698
-     * @throws InvalidInterfaceException
1699
-     * @throws ReflectionException
1700
-     */
1701
-    public function ticket_metabox()
1702
-    {
1703
-        $existing_datetime_ids = $existing_ticket_ids = [];
1704
-        // defaults for template args
1705
-        $template_args = [
1706
-            'existing_datetime_ids'    => '',
1707
-            'event_datetime_help_link' => '',
1708
-            'ticket_options_help_link' => '',
1709
-            'time'                     => null,
1710
-            'ticket_rows'              => '',
1711
-            'existing_ticket_ids'      => '',
1712
-            'total_ticket_rows'        => 1,
1713
-            'ticket_js_structure'      => '',
1714
-            'trash_icon'               => 'ee-lock-icon',
1715
-            'disabled'                 => '',
1716
-        ];
1717
-        $event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1718
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1719
-        /**
1720
-         * 1. Start with retrieving Datetimes
1721
-         * 2. Fore each datetime get related tickets
1722
-         * 3. For each ticket get related prices
1723
-         */
1724
-        $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1725
-        /** @type EE_Datetime $first_datetime */
1726
-        $first_datetime = reset($times);
1727
-        // do we get related tickets?
1728
-        if (
1729
-            $first_datetime instanceof EE_Datetime
1730
-            && $first_datetime->ID() !== 0
1731
-        ) {
1732
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1733
-            $template_args['time']   = $first_datetime;
1734
-            $related_tickets         = $first_datetime->tickets(
1735
-                [
1736
-                    ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1737
-                    'default_where_conditions' => 'none',
1738
-                ]
1739
-            );
1740
-            if (! empty($related_tickets)) {
1741
-                $template_args['total_ticket_rows'] = count($related_tickets);
1742
-                $row                                = 0;
1743
-                foreach ($related_tickets as $ticket) {
1744
-                    $existing_ticket_ids[]        = $ticket->get('TKT_ID');
1745
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1746
-                    $row++;
1747
-                }
1748
-            } else {
1749
-                $template_args['total_ticket_rows'] = 1;
1750
-                /** @type EE_Ticket $ticket */
1751
-                $ticket                       = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1752
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1753
-            }
1754
-        } else {
1755
-            $template_args['time'] = $times[0];
1756
-            /** @type EE_Ticket $ticket */
1757
-            $ticket                       = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1758
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1759
-            // NOTE: we're just sending the first default row
1760
-            // (decaf can't manage default tickets so this should be sufficient);
1761
-        }
1762
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1763
-            'event_editor_event_datetimes_help_tab'
1764
-        );
1765
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1766
-        $template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1767
-        $template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1768
-        $template_args['ticket_js_structure']      = $this->_get_ticket_row(
1769
-            EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1770
-            true
1771
-        );
1772
-        $template                                  = apply_filters(
1773
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1774
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1775
-        );
1776
-        EEH_Template::display_template($template, $template_args);
1777
-    }
1778
-
1779
-
1780
-    /**
1781
-     * Setup an individual ticket form for the decaf event editor page
1782
-     *
1783
-     * @access private
1784
-     * @param EE_Ticket $ticket   the ticket object
1785
-     * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1786
-     * @param int       $row
1787
-     * @return string generated html for the ticket row.
1788
-     * @throws DomainException
1789
-     * @throws EE_Error
1790
-     * @throws InvalidArgumentException
1791
-     * @throws InvalidDataTypeException
1792
-     * @throws InvalidInterfaceException
1793
-     * @throws ReflectionException
1794
-     */
1795
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1796
-    {
1797
-        $template_args = [
1798
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1799
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1800
-                : '',
1801
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1802
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1803
-            'TKT_name'            => $ticket->get('TKT_name'),
1804
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1805
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1806
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1807
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1808
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1809
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1810
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1811
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1812
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1813
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1814
-                : ' disabled=disabled',
1815
-        ];
1816
-        $price         = $ticket->ID() !== 0
1817
-            ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1818
-            : EE_Registry::instance()->load_model('Price')->create_default_object();
1819
-        $price_args    = [
1820
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1821
-            'PRC_amount'            => $price->get('PRC_amount'),
1822
-            'PRT_ID'                => $price->get('PRT_ID'),
1823
-            'PRC_ID'                => $price->get('PRC_ID'),
1824
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1825
-        ];
1826
-        // make sure we have default start and end dates if skeleton
1827
-        // handle rows that should NOT be empty
1828
-        if (empty($template_args['TKT_start_date'])) {
1829
-            // if empty then the start date will be now.
1830
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1831
-        }
1832
-        if (empty($template_args['TKT_end_date'])) {
1833
-            // get the earliest datetime (if present);
1834
-            $earliest_dtt = $this->_cpt_model_obj->ID() > 0
1835
-                ? $this->_cpt_model_obj->get_first_related(
1836
-                    'Datetime',
1837
-                    ['order_by' => ['DTT_EVT_start' => 'ASC']]
1838
-                )
1839
-                : null;
1840
-            if (! empty($earliest_dtt)) {
1841
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1842
-            } else {
1843
-                $template_args['TKT_end_date'] = date(
1844
-                    'Y-m-d h:i a',
1845
-                    mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))
1846
-                );
1847
-            }
1848
-        }
1849
-        $template_args = array_merge($template_args, $price_args);
1850
-        $template      = apply_filters(
1851
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1852
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1853
-            $ticket
1854
-        );
1855
-        return EEH_Template::display_template($template, $template_args, true);
1856
-    }
1857
-
1858
-
1859
-    /**
1860
-     * @throws DomainException
1861
-     * @throws EE_Error
1862
-     */
1863
-    public function registration_options_meta_box()
1864
-    {
1865
-        $yes_no_values             = [
1866
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1867
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1868
-        ];
1869
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1870
-            [
1871
-                EEM_Registration::status_id_cancelled,
1872
-                EEM_Registration::status_id_declined,
1873
-                EEM_Registration::status_id_incomplete,
1874
-            ],
1875
-            true
1876
-        );
1877
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1878
-        $template_args['_event']                          = $this->_cpt_model_obj;
1879
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1880
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1881
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1882
-            'default_reg_status',
1883
-            $default_reg_status_values,
1884
-            $this->_cpt_model_obj->default_registration_status()
1885
-        );
1886
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1887
-            'display_desc',
1888
-            $yes_no_values,
1889
-            $this->_cpt_model_obj->display_description()
1890
-        );
1891
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1892
-            'display_ticket_selector',
1893
-            $yes_no_values,
1894
-            $this->_cpt_model_obj->display_ticket_selector(),
1895
-            '',
1896
-            '',
1897
-            false
1898
-        );
1899
-        $template_args['additional_registration_options'] = apply_filters(
1900
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1901
-            '',
1902
-            $template_args,
1903
-            $yes_no_values,
1904
-            $default_reg_status_values
1905
-        );
1906
-        EEH_Template::display_template(
1907
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1908
-            $template_args
1909
-        );
1910
-    }
1911
-
1912
-
1913
-    /**
1914
-     * _get_events()
1915
-     * This method simply returns all the events (for the given _view and paging)
1916
-     *
1917
-     * @access public
1918
-     * @param int  $per_page     count of items per page (20 default);
1919
-     * @param int  $current_page what is the current page being viewed.
1920
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1921
-     *                           If FALSE then we return an array of event objects
1922
-     *                           that match the given _view and paging parameters.
1923
-     * @return array|int an array of event objects.
1924
-     * @throws EE_Error
1925
-     * @throws InvalidArgumentException
1926
-     * @throws InvalidDataTypeException
1927
-     * @throws InvalidInterfaceException
1928
-     * @throws ReflectionException
1929
-     * @throws Exception
1930
-     * @throws Exception
1931
-     * @throws Exception
1932
-     */
1933
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1934
-    {
1935
-        $EEME    = $this->_event_model();
1936
-        $offset  = ($current_page - 1) * $per_page;
1937
-        $limit   = $count ? null : $offset . ',' . $per_page;
1938
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1939
-        $order   = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
1940
-        if (isset($this->_req_data['month_range'])) {
1941
-            $pieces = explode(' ', $this->_req_data['month_range'], 3);
1942
-            // simulate the FIRST day of the month, that fixes issues for months like February
1943
-            // where PHP doesn't know what to assume for date.
1944
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1945
-            $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1946
-            $year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1947
-        }
1948
-        $where  = [];
1949
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1950
-        // determine what post_status our condition will have for the query.
1951
-        switch ($status) {
1952
-            case 'month':
1953
-            case 'today':
1954
-            case null:
1955
-            case 'all':
1956
-                break;
1957
-            case 'draft':
1958
-                $where['status'] = ['IN', ['draft', 'auto-draft']];
1959
-                break;
1960
-            default:
1961
-                $where['status'] = $status;
1962
-        }
1963
-        // categories?
1964
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1965
-            ? $this->_req_data['EVT_CAT'] : null;
1966
-        if (! empty($category)) {
1967
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1968
-            $where['Term_Taxonomy.term_id']  = $category;
1969
-        }
1970
-        // date where conditions
1971
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1972
-        if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') {
1973
-            $DateTime = new DateTime(
1974
-                $year_r . '-' . $month_r . '-01 00:00:00',
1975
-                new DateTimeZone('UTC')
1976
-            );
1977
-            $start    = $DateTime->getTimestamp();
1978
-            // set the datetime to be the end of the month
1979
-            $DateTime->setDate(
1980
-                $year_r,
1981
-                $month_r,
1982
-                $DateTime->format('t')
1983
-            )->setTime(23, 59, 59);
1984
-            $end                             = $DateTime->getTimestamp();
1985
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1986
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'today') {
1987
-            $DateTime                        =
1988
-                new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1989
-            $start                           = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1990
-            $end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1991
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1992
-        } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'month') {
1993
-            $now                             = date('Y-m-01');
1994
-            $DateTime                        =
1995
-                new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1996
-            $start                           = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1997
-            $end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1998
-                                                        ->setTime(23, 59, 59)
1999
-                                                        ->format(implode(' ', $start_formats));
2000
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
2001
-        }
2002
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
2003
-            $where['EVT_wp_user'] = get_current_user_id();
2004
-        } elseif (
2005
-            ! isset($where['status'])
2006
-            && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')
2007
-        ) {
2008
-            $where['OR'] = [
2009
-                'status*restrict_private' => ['!=', 'private'],
2010
-                'AND'                     => [
2011
-                    'status*inclusive' => ['=', 'private'],
2012
-                    'EVT_wp_user'      => get_current_user_id(),
2013
-                ],
2014
-            ];
2015
-        }
2016
-
2017
-        if (
2018
-            isset($this->_req_data['EVT_wp_user'])
2019
-            && (int) $this->_req_data['EVT_wp_user'] !== (int) get_current_user_id()
2020
-            && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
2021
-        ) {
2022
-            $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
2023
-        }
2024
-        // search query handling
2025
-        if (isset($this->_req_data['s'])) {
2026
-            $search_string = '%' . $this->_req_data['s'] . '%';
2027
-            $where['OR']   = [
2028
-                'EVT_name'       => ['LIKE', $search_string],
2029
-                'EVT_desc'       => ['LIKE', $search_string],
2030
-                'EVT_short_desc' => ['LIKE', $search_string],
2031
-            ];
2032
-        }
2033
-        // filter events by venue.
2034
-        if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) {
2035
-            $where['Venue.VNU_ID'] = absint($this->_req_data['venue']);
2036
-        }
2037
-        $where        = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
2038
-        $query_params = apply_filters(
2039
-            'FHEE__Events_Admin_Page__get_events__query_params',
2040
-            [
2041
-                $where,
2042
-                'limit'    => $limit,
2043
-                'order_by' => $orderby,
2044
-                'order'    => $order,
2045
-                'group_by' => 'EVT_ID',
2046
-            ],
2047
-            $this->_req_data
2048
-        );
2049
-
2050
-        // let's first check if we have special requests coming in.
2051
-        if (isset($this->_req_data['active_status'])) {
2052
-            switch ($this->_req_data['active_status']) {
2053
-                case 'upcoming':
2054
-                    return $EEME->get_upcoming_events($query_params, $count);
2055
-                case 'expired':
2056
-                    return $EEME->get_expired_events($query_params, $count);
2057
-                case 'active':
2058
-                    return $EEME->get_active_events($query_params, $count);
2059
-                case 'inactive':
2060
-                    return $EEME->get_inactive_events($query_params, $count);
2061
-            }
2062
-        }
2063
-
2064
-        return $count ? $EEME->count([$where], 'EVT_ID', true) : $EEME->get_all($query_params);
2065
-    }
2066
-
2067
-
2068
-    /**
2069
-     * handling for WordPress CPT actions (trash, restore, delete)
2070
-     *
2071
-     * @param string $post_id
2072
-     * @throws EE_Error
2073
-     * @throws InvalidArgumentException
2074
-     * @throws InvalidDataTypeException
2075
-     * @throws InvalidInterfaceException
2076
-     * @throws ReflectionException
2077
-     */
2078
-    public function trash_cpt_item($post_id)
2079
-    {
2080
-        $this->_req_data['EVT_ID'] = $post_id;
2081
-        $this->_trash_or_restore_event('trash', false);
2082
-    }
2083
-
2084
-
2085
-    /**
2086
-     * @param string $post_id
2087
-     * @throws EE_Error
2088
-     * @throws InvalidArgumentException
2089
-     * @throws InvalidDataTypeException
2090
-     * @throws InvalidInterfaceException
2091
-     * @throws ReflectionException
2092
-     */
2093
-    public function restore_cpt_item($post_id)
2094
-    {
2095
-        $this->_req_data['EVT_ID'] = $post_id;
2096
-        $this->_trash_or_restore_event('draft', false);
2097
-    }
2098
-
2099
-
2100
-    /**
2101
-     * @param string $post_id
2102
-     * @throws EE_Error
2103
-     * @throws InvalidArgumentException
2104
-     * @throws InvalidDataTypeException
2105
-     * @throws InvalidInterfaceException
2106
-     * @throws ReflectionException
2107
-     */
2108
-    public function delete_cpt_item($post_id)
2109
-    {
2110
-        throw new EE_Error(
2111
-            esc_html__(
2112
-                'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2113
-                'event_espresso'
2114
-            )
2115
-        );
2116
-        $this->_req_data['EVT_ID'] = $post_id;
2117
-        $this->_delete_event();
2118
-    }
2119
-
2120
-
2121
-    /**
2122
-     * _trash_or_restore_event
2123
-     *
2124
-     * @access protected
2125
-     * @param string $event_status
2126
-     * @param bool   $redirect_after
2127
-     * @throws EE_Error
2128
-     * @throws InvalidArgumentException
2129
-     * @throws InvalidDataTypeException
2130
-     * @throws InvalidInterfaceException
2131
-     * @throws ReflectionException
2132
-     */
2133
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2134
-    {
2135
-        // determine the event id and set to array.
2136
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
2137
-        // loop thru events
2138
-        if ($EVT_ID) {
2139
-            // clean status
2140
-            $event_status = sanitize_key($event_status);
2141
-            // grab status
2142
-            if (! empty($event_status)) {
2143
-                $success = $this->_change_event_status($EVT_ID, $event_status);
2144
-            } else {
2145
-                $success = false;
2146
-                $msg     = esc_html__(
2147
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2148
-                    'event_espresso'
2149
-                );
2150
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2151
-            }
2152
-        } else {
2153
-            $success = false;
2154
-            $msg     = esc_html__(
2155
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2156
-                'event_espresso'
2157
-            );
2158
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2159
-        }
2160
-        $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2161
-        if ($redirect_after) {
2162
-            $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2163
-        }
2164
-    }
2165
-
2166
-
2167
-    /**
2168
-     * _trash_or_restore_events
2169
-     *
2170
-     * @access protected
2171
-     * @param string $event_status
2172
-     * @return void
2173
-     * @throws EE_Error
2174
-     * @throws InvalidArgumentException
2175
-     * @throws InvalidDataTypeException
2176
-     * @throws InvalidInterfaceException
2177
-     * @throws ReflectionException
2178
-     */
2179
-    protected function _trash_or_restore_events($event_status = 'trash')
2180
-    {
2181
-        // clean status
2182
-        $event_status = sanitize_key($event_status);
2183
-        // grab status
2184
-        if (! empty($event_status)) {
2185
-            $success = true;
2186
-            // determine the event id and set to array.
2187
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : [];
2188
-            // loop thru events
2189
-            foreach ($EVT_IDs as $EVT_ID) {
2190
-                if ($EVT_ID = absint($EVT_ID)) {
2191
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
2192
-                    $success = $results !== false ? $success : false;
2193
-                } else {
2194
-                    $msg = sprintf(
2195
-                        esc_html__(
2196
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2197
-                            'event_espresso'
2198
-                        ),
2199
-                        $EVT_ID
2200
-                    );
2201
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2202
-                    $success = false;
2203
-                }
2204
-            }
2205
-        } else {
2206
-            $success = false;
2207
-            $msg     = esc_html__(
2208
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2209
-                'event_espresso'
2210
-            );
2211
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2212
-        }
2213
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2214
-        $success = $success ? 2 : false;
2215
-        $action  = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2216
-        $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2217
-    }
2218
-
2219
-
2220
-    /**
2221
-     * _trash_or_restore_events
2222
-     *
2223
-     * @access  private
2224
-     * @param int    $EVT_ID
2225
-     * @param string $event_status
2226
-     * @return bool
2227
-     * @throws EE_Error
2228
-     * @throws InvalidArgumentException
2229
-     * @throws InvalidDataTypeException
2230
-     * @throws InvalidInterfaceException
2231
-     * @throws ReflectionException
2232
-     */
2233
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2234
-    {
2235
-        // grab event id
2236
-        if (! $EVT_ID) {
2237
-            $msg = esc_html__(
2238
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2239
-                'event_espresso'
2240
-            );
2241
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2242
-            return false;
2243
-        }
2244
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2245
-        // clean status
2246
-        $event_status = sanitize_key($event_status);
2247
-        // grab status
2248
-        if (empty($event_status)) {
2249
-            $msg = esc_html__(
2250
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2251
-                'event_espresso'
2252
-            );
2253
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2254
-            return false;
2255
-        }
2256
-        // was event trashed or restored ?
2257
-        switch ($event_status) {
2258
-            case 'draft':
2259
-                $action = 'restored from the trash';
2260
-                $hook   = 'AHEE_event_restored_from_trash';
2261
-                break;
2262
-            case 'trash':
2263
-                $action = 'moved to the trash';
2264
-                $hook   = 'AHEE_event_moved_to_trash';
2265
-                break;
2266
-            default:
2267
-                $action = 'updated';
2268
-                $hook   = false;
2269
-        }
2270
-        // use class to change status
2271
-        $this->_cpt_model_obj->set_status($event_status);
2272
-        $success = $this->_cpt_model_obj->save();
2273
-        if ($success === false) {
2274
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2275
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2276
-            return false;
2277
-        }
2278
-        if ($hook) {
2279
-            do_action($hook);
2280
-        }
2281
-        return true;
2282
-    }
2283
-
2284
-
2285
-    /**
2286
-     * _delete_event
2287
-     *
2288
-     * @throws InvalidArgumentException
2289
-     * @throws InvalidDataTypeException
2290
-     * @throws InvalidInterfaceException
2291
-     */
2292
-    protected function _delete_event()
2293
-    {
2294
-        $this->generateDeletionPreview(isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : []);
2295
-    }
2296
-
2297
-
2298
-    /**
2299
-     * Gets the tree traversal batch persister.
2300
-     *
2301
-     * @return NodeGroupDao
2302
-     * @throws InvalidArgumentException
2303
-     * @throws InvalidDataTypeException
2304
-     * @throws InvalidInterfaceException
2305
-     * @since 4.10.12.p
2306
-     */
2307
-    protected function getModelObjNodeGroupPersister()
2308
-    {
2309
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2310
-            $this->model_obj_node_group_persister =
2311
-                $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2312
-        }
2313
-        return $this->model_obj_node_group_persister;
2314
-    }
2315
-
2316
-
2317
-    /**
2318
-     * _delete_events
2319
-     *
2320
-     * @access protected
2321
-     * @return void
2322
-     * @throws InvalidArgumentException
2323
-     * @throws InvalidDataTypeException
2324
-     * @throws InvalidInterfaceException
2325
-     */
2326
-    protected function _delete_events()
2327
-    {
2328
-        $this->generateDeletionPreview(isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : []);
2329
-    }
2330
-
2331
-
2332
-    protected function generateDeletionPreview($event_ids)
2333
-    {
2334
-        $event_ids = (array) $event_ids;
2335
-        // Set a code we can use to reference this deletion task in the batch jobs and preview page.
2336
-        $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2337
-        $return_url        = EE_Admin_Page::add_query_args_and_nonce(
2338
-            [
2339
-                'action'            => 'preview_deletion',
2340
-                'deletion_job_code' => $deletion_job_code,
2341
-            ],
2342
-            $this->_admin_base_url
2343
-        );
2344
-        $event_ids         = array_map(
2345
-            'intval',
2346
-            $event_ids
2347
-        );
2348
-
2349
-        EEH_URL::safeRedirectAndExit(
2350
-            EE_Admin_Page::add_query_args_and_nonce(
2351
-                [
2352
-                    'page'              => 'espresso_batch',
2353
-                    'batch'             => EED_Batch::batch_job,
2354
-                    'EVT_IDs'           => $event_ids,
2355
-                    'deletion_job_code' => $deletion_job_code,
2356
-                    'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2357
-                    'return_url'        => urlencode($return_url),
2358
-                ],
2359
-                admin_url()
2360
-            )
2361
-        );
2362
-    }
2363
-
2364
-
2365
-    /**
2366
-     * Checks for a POST submission
2367
-     *
2368
-     * @since 4.10.12.p
2369
-     */
2370
-    protected function confirmDeletion()
2371
-    {
2372
-        $deletion_redirect_logic =
2373
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2374
-        $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2375
-    }
2376
-
2377
-
2378
-    /**
2379
-     * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2380
-     *
2381
-     * @throws EE_Error
2382
-     * @since 4.10.12.p
2383
-     */
2384
-    protected function previewDeletion()
2385
-    {
2386
-        $preview_deletion_logic =
2387
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2388
-        $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2389
-        $this->display_admin_page_with_no_sidebar();
2390
-    }
2391
-
2392
-
2393
-    /**
2394
-     * get total number of events
2395
-     *
2396
-     * @access public
2397
-     * @return int
2398
-     * @throws EE_Error
2399
-     * @throws InvalidArgumentException
2400
-     * @throws InvalidDataTypeException
2401
-     * @throws InvalidInterfaceException
2402
-     */
2403
-    public function total_events()
2404
-    {
2405
-        return EEM_Event::instance()->count(['caps' => 'read_admin'], 'EVT_ID', true);
2406
-    }
2407
-
2408
-
2409
-    /**
2410
-     * get total number of draft events
2411
-     *
2412
-     * @access public
2413
-     * @return int
2414
-     * @throws EE_Error
2415
-     * @throws InvalidArgumentException
2416
-     * @throws InvalidDataTypeException
2417
-     * @throws InvalidInterfaceException
2418
-     */
2419
-    public function total_events_draft()
2420
-    {
2421
-        $where = [
2422
-            'status' => ['IN', ['draft', 'auto-draft']],
2423
-        ];
2424
-        return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
2425
-    }
2426
-
2427
-
2428
-    /**
2429
-     * get total number of trashed events
2430
-     *
2431
-     * @access public
2432
-     * @return int
2433
-     * @throws EE_Error
2434
-     * @throws InvalidArgumentException
2435
-     * @throws InvalidDataTypeException
2436
-     * @throws InvalidInterfaceException
2437
-     */
2438
-    public function total_trashed_events()
2439
-    {
2440
-        $where = [
2441
-            'status' => 'trash',
2442
-        ];
2443
-        return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
2444
-    }
2445
-
2446
-
2447
-    /**
2448
-     *    _default_event_settings
2449
-     *    This generates the Default Settings Tab
2450
-     *
2451
-     * @return void
2452
-     * @throws DomainException
2453
-     * @throws EE_Error
2454
-     * @throws InvalidArgumentException
2455
-     * @throws InvalidDataTypeException
2456
-     * @throws InvalidInterfaceException
2457
-     */
2458
-    protected function _default_event_settings()
2459
-    {
2460
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2461
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2462
-        $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2463
-        $this->display_admin_page_with_sidebar();
2464
-    }
2465
-
2466
-
2467
-    /**
2468
-     * Return the form for event settings.
2469
-     *
2470
-     * @return EE_Form_Section_Proper
2471
-     * @throws EE_Error
2472
-     */
2473
-    protected function _default_event_settings_form()
2474
-    {
2475
-        $registration_config              = EE_Registry::instance()->CFG->registration;
2476
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2477
-        // exclude
2478
-            [
2479
-                EEM_Registration::status_id_cancelled,
2480
-                EEM_Registration::status_id_declined,
2481
-                EEM_Registration::status_id_incomplete,
2482
-                EEM_Registration::status_id_wait_list,
2483
-            ],
2484
-            true
2485
-        );
2486
-        return new EE_Form_Section_Proper(
2487
-            [
2488
-                'name'            => 'update_default_event_settings',
2489
-                'html_id'         => 'update_default_event_settings',
2490
-                'html_class'      => 'form-table',
2491
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2492
-                'subsections'     => apply_filters(
2493
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2494
-                    [
2495
-                        'default_reg_status'  => new EE_Select_Input(
2496
-                            $registration_stati_for_selection,
2497
-                            [
2498
-                                'default'         => isset($registration_config->default_STS_ID)
2499
-                                                     && array_key_exists(
2500
-                                                         $registration_config->default_STS_ID,
2501
-                                                         $registration_stati_for_selection
2502
-                                                     )
2503
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2504
-                                    : EEM_Registration::status_id_pending_payment,
2505
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2506
-                                                        . EEH_Template::get_help_tab_link(
2507
-                                                            'default_settings_status_help_tab'
2508
-                                                        ),
2509
-                                'html_help_text'  => esc_html__(
2510
-                                    'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2511
-                                    'event_espresso'
2512
-                                ),
2513
-                            ]
2514
-                        ),
2515
-                        'default_max_tickets' => new EE_Integer_Input(
2516
-                            [
2517
-                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2518
-                                    ? $registration_config->default_maximum_number_of_tickets
2519
-                                    : EEM_Event::get_default_additional_limit(),
2520
-                                'html_label_text' => esc_html__(
2521
-                                    'Default Maximum Tickets Allowed Per Order:',
2522
-                                    'event_espresso'
2523
-                                )
2524
-                                . EEH_Template::get_help_tab_link(
2525
-                                    'default_maximum_tickets_help_tab"'
2526
-                                ),
2527
-                                'html_help_text'  => esc_html__(
2528
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2529
-                                    'event_espresso'
2530
-                                ),
2531
-                            ]
2532
-                        ),
2533
-                    ]
2534
-                ),
2535
-            ]
2536
-        );
2537
-    }
2538
-
2539
-
2540
-    /**
2541
-     * @return void
2542
-     * @throws EE_Error
2543
-     * @throws InvalidArgumentException
2544
-     * @throws InvalidDataTypeException
2545
-     * @throws InvalidInterfaceException
2546
-     */
2547
-    protected function _update_default_event_settings()
2548
-    {
2549
-        $form = $this->_default_event_settings_form();
2550
-        if ($form->was_submitted()) {
2551
-            $form->receive_form_submission();
2552
-            if ($form->is_valid()) {
2553
-                $registration_config = EE_Registry::instance()->CFG->registration;
2554
-                $valid_data          = $form->valid_data();
2555
-                if (isset($valid_data['default_reg_status'])) {
2556
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2557
-                }
2558
-                if (isset($valid_data['default_max_tickets'])) {
2559
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2560
-                }
2561
-                do_action(
2562
-                    'AHEE__Events_Admin_Page___update_default_event_settings',
2563
-                    $valid_data,
2564
-                    EE_Registry::instance()->CFG,
2565
-                    $this
2566
-                );
2567
-                // update because data was valid!
2568
-                EE_Registry::instance()->CFG->update_espresso_config();
2569
-                EE_Error::overwrite_success();
2570
-                EE_Error::add_success(
2571
-                    __('Default Event Settings were updated', 'event_espresso')
2572
-                );
2573
-            }
2574
-        }
2575
-        $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2576
-    }
2577
-
2578
-
2579
-    /*************        Templates        *************/
2580
-    protected function _template_settings()
2581
-    {
2582
-        $this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2583
-        $this->_template_args['preview_img']  = '<img src="'
2584
-                                                . EVENTS_ASSETS_URL
2585
-                                                . '/images/'
2586
-                                                . 'caffeinated_template_features.jpg" alt="'
2587
-                                                . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2588
-                                                . '" />';
2589
-        $this->_template_args['preview_text'] = '<strong>'
2590
-                                                . esc_html__(
2591
-                                                    'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2592
-                                                    'event_espresso'
2593
-                                                ) . '</strong>';
2594
-        $this->display_admin_caf_preview_page('template_settings_tab');
2595
-    }
2596
-
2597
-
2598
-    /** Event Category Stuff **/
2599
-    /**
2600
-     * set the _category property with the category object for the loaded page.
2601
-     *
2602
-     * @access private
2603
-     * @return void
2604
-     */
2605
-    private function _set_category_object()
2606
-    {
2607
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2608
-            return;
2609
-        } //already have the category object so get out.
2610
-        // set default category object
2611
-        $this->_set_empty_category_object();
2612
-        // only set if we've got an id
2613
-        if (! isset($this->_req_data['EVT_CAT_ID'])) {
2614
-            return;
2615
-        }
2616
-        $category_id = absint($this->_req_data['EVT_CAT_ID']);
2617
-        $term        = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2618
-        if (! empty($term)) {
2619
-            $this->_category->category_name       = $term->name;
2620
-            $this->_category->category_identifier = $term->slug;
2621
-            $this->_category->category_desc       = $term->description;
2622
-            $this->_category->id                  = $term->term_id;
2623
-            $this->_category->parent              = $term->parent;
2624
-        }
2625
-    }
2626
-
2627
-
2628
-    /**
2629
-     * Clears out category properties.
2630
-     */
2631
-    private function _set_empty_category_object()
2632
-    {
2633
-        $this->_category                = new stdClass();
2634
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2635
-        $this->_category->id            = $this->_category->parent = 0;
2636
-    }
2637
-
2638
-
2639
-    /**
2640
-     * @throws DomainException
2641
-     * @throws EE_Error
2642
-     * @throws InvalidArgumentException
2643
-     * @throws InvalidDataTypeException
2644
-     * @throws InvalidInterfaceException
2645
-     */
2646
-    protected function _category_list_table()
2647
-    {
2648
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2649
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2650
-        $this->_admin_page_title .= ' ';
2651
-        $this->_admin_page_title .= $this->get_action_link_or_button(
2652
-            'add_category',
2653
-            'add_category',
2654
-            [],
2655
-            'add-new-h2'
2656
-        );
2657
-        $this->display_admin_list_table_page_with_sidebar();
2658
-    }
2659
-
2660
-
2661
-    /**
2662
-     * Output category details view.
2663
-     *
2664
-     * @param string $view
2665
-     * @throws DomainException
2666
-     * @throws EE_Error
2667
-     * @throws InvalidArgumentException
2668
-     * @throws InvalidDataTypeException
2669
-     * @throws InvalidInterfaceException
2670
-     */
2671
-    protected function _category_details($view)
2672
-    {
2673
-        // load formatter helper
2674
-        // load field generator helper
2675
-        $route = $view === 'edit' ? 'update_category' : 'insert_category';
2676
-        $this->_set_add_edit_form_tags($route);
2677
-        $this->_set_category_object();
2678
-        $id            = ! empty($this->_category->id) ? $this->_category->id : '';
2679
-        $delete_action = 'delete_category';
2680
-        // custom redirect
2681
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2682
-            ['action' => 'category_list'],
2683
-            $this->_admin_base_url
2684
-        );
2685
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2686
-        // take care of contents
2687
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2688
-        $this->display_admin_page_with_sidebar();
2689
-    }
2690
-
2691
-
2692
-    /**
2693
-     * Output category details content.
2694
-     *
2695
-     * @throws DomainException
2696
-     */
2697
-    protected function _category_details_content()
2698
-    {
2699
-        $editor_args['category_desc'] = [
2700
-            'type'          => 'wp_editor',
2701
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2702
-            'class'         => 'my_editor_custom',
2703
-            'wpeditor_args' => ['media_buttons' => false],
2704
-        ];
2705
-        $_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2706
-        $all_terms                    = get_terms(
2707
-            [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2708
-            ['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2709
-        );
2710
-        // setup category select for term parents.
2711
-        $category_select_values[] = [
2712
-            'text' => esc_html__('No Parent', 'event_espresso'),
2713
-            'id'   => 0,
2714
-        ];
2715
-        foreach ($all_terms as $term) {
2716
-            $category_select_values[] = [
2717
-                'text' => $term->name,
2718
-                'id'   => $term->term_id,
2719
-            ];
2720
-        }
2721
-        $category_select = EEH_Form_Fields::select_input(
2722
-            'category_parent',
2723
-            $category_select_values,
2724
-            $this->_category->parent
2725
-        );
2726
-        $template_args   = [
2727
-            'category'                 => $this->_category,
2728
-            'category_select'          => $category_select,
2729
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2730
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2731
-            'disable'                  => '',
2732
-            'disabled_message'         => false,
2733
-        ];
2734
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2735
-        return EEH_Template::display_template($template, $template_args, true);
2736
-    }
2737
-
2738
-
2739
-    /**
2740
-     * Handles deleting categories.
2741
-     */
2742
-    protected function _delete_categories()
2743
-    {
2744
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2745
-            : (array) $this->_req_data['category_id'];
2746
-        foreach ($cat_ids as $cat_id) {
2747
-            $this->_delete_category($cat_id);
2748
-        }
2749
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2750
-        $query_args = [
2751
-            'action' => 'category_list',
2752
-        ];
2753
-        $this->_redirect_after_action(0, '', '', $query_args);
2754
-    }
2755
-
2756
-
2757
-    /**
2758
-     * Handles deleting specific category.
2759
-     *
2760
-     * @param int $cat_id
2761
-     */
2762
-    protected function _delete_category($cat_id)
2763
-    {
2764
-        $cat_id = absint($cat_id);
2765
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2766
-    }
2767
-
2768
-
2769
-    /**
2770
-     * Handles triggering the update or insertion of a new category.
2771
-     *
2772
-     * @param bool $new_category true means we're triggering the insert of a new category.
2773
-     * @throws EE_Error
2774
-     * @throws InvalidArgumentException
2775
-     * @throws InvalidDataTypeException
2776
-     * @throws InvalidInterfaceException
2777
-     */
2778
-    protected function _insert_or_update_category($new_category)
2779
-    {
2780
-        $cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2781
-        $success = 0; // we already have a success message so lets not send another.
2782
-        if ($cat_id) {
2783
-            $query_args = [
2784
-                'action'     => 'edit_category',
2785
-                'EVT_CAT_ID' => $cat_id,
2786
-            ];
2787
-        } else {
2788
-            $query_args = ['action' => 'add_category'];
2789
-        }
2790
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2791
-    }
2792
-
2793
-
2794
-    /**
2795
-     * Inserts or updates category
2796
-     *
2797
-     * @param bool $update (true indicates we're updating a category).
2798
-     * @return bool|mixed|string
2799
-     */
2800
-    private function _insert_category($update = false)
2801
-    {
2802
-        $cat_id          = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2803
-        $category_name   = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2804
-        $category_desc   = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2805
-        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2806
-        if (empty($category_name)) {
2807
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2808
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2809
-            return false;
2810
-        }
2811
-        $term_args = [
2812
-            'name'        => $category_name,
2813
-            'description' => $category_desc,
2814
-            'parent'      => $category_parent,
2815
-        ];
2816
-        // was the category_identifier input disabled?
2817
-        if (isset($this->_req_data['category_identifier'])) {
2818
-            $term_args['slug'] = $this->_req_data['category_identifier'];
2819
-        }
2820
-        $insert_ids = $update
2821
-            ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2822
-            : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2823
-        if (! is_array($insert_ids)) {
2824
-            $msg = esc_html__(
2825
-                'An error occurred and the category has not been saved to the database.',
2826
-                'event_espresso'
2827
-            );
2828
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2829
-        } else {
2830
-            $cat_id = $insert_ids['term_id'];
2831
-            $msg    = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2832
-            EE_Error::add_success($msg);
2833
-        }
2834
-        return $cat_id;
2835
-    }
2836
-
2837
-
2838
-    /**
2839
-     * Gets categories or count of categories matching the arguments in the request.
2840
-     *
2841
-     * @param int  $per_page
2842
-     * @param int  $current_page
2843
-     * @param bool $count
2844
-     * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2845
-     * @throws EE_Error
2846
-     * @throws InvalidArgumentException
2847
-     * @throws InvalidDataTypeException
2848
-     * @throws InvalidInterfaceException
2849
-     */
2850
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2851
-    {
2852
-        // testing term stuff
2853
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2854
-        $order   = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2855
-        $limit   = ($current_page - 1) * $per_page;
2856
-        $where   = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2857
-        if (isset($this->_req_data['s'])) {
2858
-            $sstr        = '%' . $this->_req_data['s'] . '%';
2859
-            $where['OR'] = [
2860
-                'Term.name'   => ['LIKE', $sstr],
2861
-                'description' => ['LIKE', $sstr],
2862
-            ];
2863
-        }
2864
-        $query_params = [
2865
-            $where,
2866
-            'order_by'   => [$orderby => $order],
2867
-            'limit'      => $limit . ',' . $per_page,
2868
-            'force_join' => ['Term'],
2869
-        ];
2870
-        return $count
2871
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2872
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2873
-    }
2874
-
2875
-    /* end category stuff */
2876
-    /**************/
2877
-
2878
-
2879
-    /**
2880
-     * Callback for the `ee_save_timezone_setting` ajax action.
2881
-     *
2882
-     * @throws EE_Error
2883
-     * @throws InvalidArgumentException
2884
-     * @throws InvalidDataTypeException
2885
-     * @throws InvalidInterfaceException
2886
-     */
2887
-    public function save_timezonestring_setting()
2888
-    {
2889
-        $timezone_string = isset($this->_req_data['timezone_selected'])
2890
-            ? $this->_req_data['timezone_selected']
2891
-            : '';
2892
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2893
-            EE_Error::add_error(
2894
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2895
-                __FILE__,
2896
-                __FUNCTION__,
2897
-                __LINE__
2898
-            );
2899
-            $this->_template_args['error'] = true;
2900
-            $this->_return_json();
2901
-        }
2902
-
2903
-        update_option('timezone_string', $timezone_string);
2904
-        EE_Error::add_success(
2905
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2906
-        );
2907
-        $this->_template_args['success'] = true;
2908
-        $this->_return_json(true, ['action' => 'create_new']);
2909
-    }
20
+	/**
21
+	 * This will hold the event object for event_details screen.
22
+	 *
23
+	 * @access protected
24
+	 * @var EE_Event $_event
25
+	 */
26
+	protected $_event;
27
+
28
+
29
+	/**
30
+	 * This will hold the category object for category_details screen.
31
+	 *
32
+	 * @var stdClass $_category
33
+	 */
34
+	protected $_category;
35
+
36
+
37
+	/**
38
+	 * This will hold the event model instance
39
+	 *
40
+	 * @var EEM_Event $_event_model
41
+	 */
42
+	protected $_event_model;
43
+
44
+
45
+	/**
46
+	 * @var EE_Event
47
+	 */
48
+	protected $_cpt_model_obj = false;
49
+
50
+
51
+	/**
52
+	 * @var NodeGroupDao
53
+	 */
54
+	protected $model_obj_node_group_persister;
55
+
56
+
57
+	/**
58
+	 * Initialize page props for this admin page group.
59
+	 */
60
+	protected function _init_page_props()
61
+	{
62
+		$this->page_slug        = EVENTS_PG_SLUG;
63
+		$this->page_label       = EVENTS_LABEL;
64
+		$this->_admin_base_url  = EVENTS_ADMIN_URL;
65
+		$this->_admin_base_path = EVENTS_ADMIN;
66
+		$this->_cpt_model_names = [
67
+			'create_new' => 'EEM_Event',
68
+			'edit'       => 'EEM_Event',
69
+		];
70
+		$this->_cpt_edit_routes = [
71
+			'espresso_events' => 'edit',
72
+		];
73
+		add_action(
74
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
75
+			[$this, 'verify_event_edit'],
76
+			10,
77
+			2
78
+		);
79
+	}
80
+
81
+
82
+	/**
83
+	 * Sets the ajax hooks used for this admin page group.
84
+	 */
85
+	protected function _ajax_hooks()
86
+	{
87
+		add_action('wp_ajax_ee_save_timezone_setting', [$this, 'save_timezonestring_setting']);
88
+	}
89
+
90
+
91
+	/**
92
+	 * Sets the page properties for this admin page group.
93
+	 */
94
+	protected function _define_page_props()
95
+	{
96
+		$this->_admin_page_title = EVENTS_LABEL;
97
+		$this->_labels           = [
98
+			'buttons'      => [
99
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
100
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
101
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
102
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
103
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
104
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
105
+			],
106
+			'editor_title' => [
107
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
108
+			],
109
+			'publishbox'   => [
110
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
111
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
112
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
113
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
114
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
115
+			],
116
+		];
117
+	}
118
+
119
+
120
+	/**
121
+	 * Sets the page routes property for this admin page group.
122
+	 */
123
+	protected function _set_page_routes()
124
+	{
125
+		// load formatter helper
126
+		// load field generator helper
127
+		// is there a evt_id in the request?
128
+		$evt_id             = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
129
+			? $this->_req_data['EVT_ID']
130
+			: 0;
131
+		$evt_id             = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
132
+		$this->_page_routes = [
133
+			'default'                       => [
134
+				'func'       => '_events_overview_list_table',
135
+				'capability' => 'ee_read_events',
136
+			],
137
+			'create_new'                    => [
138
+				'func'       => '_create_new_cpt_item',
139
+				'capability' => 'ee_edit_events',
140
+			],
141
+			'edit'                          => [
142
+				'func'       => '_edit_cpt_item',
143
+				'capability' => 'ee_edit_event',
144
+				'obj_id'     => $evt_id,
145
+			],
146
+			'copy_event'                    => [
147
+				'func'       => '_copy_events',
148
+				'capability' => 'ee_edit_event',
149
+				'obj_id'     => $evt_id,
150
+				'noheader'   => true,
151
+			],
152
+			'trash_event'                   => [
153
+				'func'       => '_trash_or_restore_event',
154
+				'args'       => ['event_status' => 'trash'],
155
+				'capability' => 'ee_delete_event',
156
+				'obj_id'     => $evt_id,
157
+				'noheader'   => true,
158
+			],
159
+			'trash_events'                  => [
160
+				'func'       => '_trash_or_restore_events',
161
+				'args'       => ['event_status' => 'trash'],
162
+				'capability' => 'ee_delete_events',
163
+				'noheader'   => true,
164
+			],
165
+			'restore_event'                 => [
166
+				'func'       => '_trash_or_restore_event',
167
+				'args'       => ['event_status' => 'draft'],
168
+				'capability' => 'ee_delete_event',
169
+				'obj_id'     => $evt_id,
170
+				'noheader'   => true,
171
+			],
172
+			'restore_events'                => [
173
+				'func'       => '_trash_or_restore_events',
174
+				'args'       => ['event_status' => 'draft'],
175
+				'capability' => 'ee_delete_events',
176
+				'noheader'   => true,
177
+			],
178
+			'delete_event'                  => [
179
+				'func'       => '_delete_event',
180
+				'capability' => 'ee_delete_event',
181
+				'obj_id'     => $evt_id,
182
+				'noheader'   => true,
183
+			],
184
+			'delete_events'                 => [
185
+				'func'       => '_delete_events',
186
+				'capability' => 'ee_delete_events',
187
+				'noheader'   => true,
188
+			],
189
+			'view_report'                   => [
190
+				'func'       => '_view_report',
191
+				'capability' => 'ee_edit_events',
192
+			],
193
+			'default_event_settings'        => [
194
+				'func'       => '_default_event_settings',
195
+				'capability' => 'manage_options',
196
+			],
197
+			'update_default_event_settings' => [
198
+				'func'       => '_update_default_event_settings',
199
+				'capability' => 'manage_options',
200
+				'noheader'   => true,
201
+			],
202
+			'template_settings'             => [
203
+				'func'       => '_template_settings',
204
+				'capability' => 'manage_options',
205
+			],
206
+			// event category tab related
207
+			'add_category'                  => [
208
+				'func'       => '_category_details',
209
+				'capability' => 'ee_edit_event_category',
210
+				'args'       => ['add'],
211
+			],
212
+			'edit_category'                 => [
213
+				'func'       => '_category_details',
214
+				'capability' => 'ee_edit_event_category',
215
+				'args'       => ['edit'],
216
+			],
217
+			'delete_categories'             => [
218
+				'func'       => '_delete_categories',
219
+				'capability' => 'ee_delete_event_category',
220
+				'noheader'   => true,
221
+			],
222
+			'delete_category'               => [
223
+				'func'       => '_delete_categories',
224
+				'capability' => 'ee_delete_event_category',
225
+				'noheader'   => true,
226
+			],
227
+			'insert_category'               => [
228
+				'func'       => '_insert_or_update_category',
229
+				'args'       => ['new_category' => true],
230
+				'capability' => 'ee_edit_event_category',
231
+				'noheader'   => true,
232
+			],
233
+			'update_category'               => [
234
+				'func'       => '_insert_or_update_category',
235
+				'args'       => ['new_category' => false],
236
+				'capability' => 'ee_edit_event_category',
237
+				'noheader'   => true,
238
+			],
239
+			'category_list'                 => [
240
+				'func'       => '_category_list_table',
241
+				'capability' => 'ee_manage_event_categories',
242
+			],
243
+			'preview_deletion'              => [
244
+				'func'       => 'previewDeletion',
245
+				'capability' => 'ee_delete_events',
246
+			],
247
+			'confirm_deletion'              => [
248
+				'func'       => 'confirmDeletion',
249
+				'capability' => 'ee_delete_events',
250
+				'noheader'   => true,
251
+			],
252
+		];
253
+	}
254
+
255
+
256
+	/**
257
+	 * Set the _page_config property for this admin page group.
258
+	 */
259
+	protected function _set_page_config()
260
+	{
261
+		$this->_page_config = [
262
+			'default'                => [
263
+				'nav'           => [
264
+					'label' => esc_html__('Overview', 'event_espresso'),
265
+					'order' => 10,
266
+				],
267
+				'list_table'    => 'Events_Admin_List_Table',
268
+				'help_tabs'     => [
269
+					'events_overview_help_tab'                       => [
270
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
271
+						'filename' => 'events_overview',
272
+					],
273
+					'events_overview_table_column_headings_help_tab' => [
274
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
275
+						'filename' => 'events_overview_table_column_headings',
276
+					],
277
+					'events_overview_filters_help_tab'               => [
278
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
279
+						'filename' => 'events_overview_filters',
280
+					],
281
+					'events_overview_view_help_tab'                  => [
282
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
283
+						'filename' => 'events_overview_views',
284
+					],
285
+					'events_overview_other_help_tab'                 => [
286
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
287
+						'filename' => 'events_overview_other',
288
+					],
289
+				],
290
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
291
+				// 'help_tour'     => [
292
+				//     'Event_Overview_Help_Tour',
293
+				//     // 'New_Features_Test_Help_Tour' for testing multiple help tour
294
+				// ],
295
+				'qtips'         => ['EE_Event_List_Table_Tips'],
296
+				'require_nonce' => false,
297
+			],
298
+			'create_new'             => [
299
+				'nav'           => [
300
+					'label'      => esc_html__('Add Event', 'event_espresso'),
301
+					'order'      => 5,
302
+					'persistent' => false,
303
+				],
304
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
305
+				'help_tabs'     => [
306
+					'event_editor_help_tab'                            => [
307
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
308
+						'filename' => 'event_editor',
309
+					],
310
+					'event_editor_title_richtexteditor_help_tab'       => [
311
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
312
+						'filename' => 'event_editor_title_richtexteditor',
313
+					],
314
+					'event_editor_venue_details_help_tab'              => [
315
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
316
+						'filename' => 'event_editor_venue_details',
317
+					],
318
+					'event_editor_event_datetimes_help_tab'            => [
319
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
320
+						'filename' => 'event_editor_event_datetimes',
321
+					],
322
+					'event_editor_event_tickets_help_tab'              => [
323
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
324
+						'filename' => 'event_editor_event_tickets',
325
+					],
326
+					'event_editor_event_registration_options_help_tab' => [
327
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
328
+						'filename' => 'event_editor_event_registration_options',
329
+					],
330
+					'event_editor_tags_categories_help_tab'            => [
331
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
332
+						'filename' => 'event_editor_tags_categories',
333
+					],
334
+					'event_editor_questions_registrants_help_tab'      => [
335
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
336
+						'filename' => 'event_editor_questions_registrants',
337
+					],
338
+					'event_editor_save_new_event_help_tab'             => [
339
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
340
+						'filename' => 'event_editor_save_new_event',
341
+					],
342
+					'event_editor_other_help_tab'                      => [
343
+						'title'    => esc_html__('Event Other', 'event_espresso'),
344
+						'filename' => 'event_editor_other',
345
+					],
346
+				],
347
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
348
+				// 'help_tour'     => [
349
+				//     'Event_Editor_Help_Tour',
350
+				// ],
351
+				'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
352
+				'require_nonce' => false,
353
+			],
354
+			'edit'                   => [
355
+				'nav'           => [
356
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
357
+					'order'      => 5,
358
+					'persistent' => false,
359
+					'url'        => isset($this->_req_data['post'])
360
+						? EE_Admin_Page::add_query_args_and_nonce(
361
+							['post' => $this->_req_data['post'], 'action' => 'edit'],
362
+							$this->_current_page_view_url
363
+						)
364
+						: $this->_admin_base_url,
365
+				],
366
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
367
+				'help_tabs'     => [
368
+					'event_editor_help_tab'                            => [
369
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
370
+						'filename' => 'event_editor',
371
+					],
372
+					'event_editor_title_richtexteditor_help_tab'       => [
373
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
374
+						'filename' => 'event_editor_title_richtexteditor',
375
+					],
376
+					'event_editor_venue_details_help_tab'              => [
377
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
378
+						'filename' => 'event_editor_venue_details',
379
+					],
380
+					'event_editor_event_datetimes_help_tab'            => [
381
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
382
+						'filename' => 'event_editor_event_datetimes',
383
+					],
384
+					'event_editor_event_tickets_help_tab'              => [
385
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
386
+						'filename' => 'event_editor_event_tickets',
387
+					],
388
+					'event_editor_event_registration_options_help_tab' => [
389
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
390
+						'filename' => 'event_editor_event_registration_options',
391
+					],
392
+					'event_editor_tags_categories_help_tab'            => [
393
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
394
+						'filename' => 'event_editor_tags_categories',
395
+					],
396
+					'event_editor_questions_registrants_help_tab'      => [
397
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
398
+						'filename' => 'event_editor_questions_registrants',
399
+					],
400
+					'event_editor_save_new_event_help_tab'             => [
401
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
402
+						'filename' => 'event_editor_save_new_event',
403
+					],
404
+					'event_editor_other_help_tab'                      => [
405
+						'title'    => esc_html__('Event Other', 'event_espresso'),
406
+						'filename' => 'event_editor_other',
407
+					],
408
+				],
409
+				'require_nonce' => false,
410
+			],
411
+			'default_event_settings' => [
412
+				'nav'           => [
413
+					'label' => esc_html__('Default Settings', 'event_espresso'),
414
+					'order' => 40,
415
+				],
416
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
417
+				'labels'        => [
418
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
419
+				],
420
+				'help_tabs'     => [
421
+					'default_settings_help_tab'        => [
422
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
423
+						'filename' => 'events_default_settings',
424
+					],
425
+					'default_settings_status_help_tab' => [
426
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
427
+						'filename' => 'events_default_settings_status',
428
+					],
429
+					'default_maximum_tickets_help_tab' => [
430
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
431
+						'filename' => 'events_default_settings_max_tickets',
432
+					],
433
+				],
434
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
435
+				// 'help_tour'     => ['Event_Default_Settings_Help_Tour'],
436
+				'require_nonce' => false,
437
+			],
438
+			// template settings
439
+			'template_settings'      => [
440
+				'nav'           => [
441
+					'label' => esc_html__('Templates', 'event_espresso'),
442
+					'order' => 30,
443
+				],
444
+				'metaboxes'     => $this->_default_espresso_metaboxes,
445
+				'help_tabs'     => [
446
+					'general_settings_templates_help_tab' => [
447
+						'title'    => esc_html__('Templates', 'event_espresso'),
448
+						'filename' => 'general_settings_templates',
449
+					],
450
+				],
451
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
452
+				// 'help_tour'     => ['Templates_Help_Tour'],
453
+				'require_nonce' => false,
454
+			],
455
+			// event category stuff
456
+			'add_category'           => [
457
+				'nav'           => [
458
+					'label'      => esc_html__('Add Category', 'event_espresso'),
459
+					'order'      => 15,
460
+					'persistent' => false,
461
+				],
462
+				'help_tabs'     => [
463
+					'add_category_help_tab' => [
464
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
465
+						'filename' => 'events_add_category',
466
+					],
467
+				],
468
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
469
+				// 'help_tour'     => ['Event_Add_Category_Help_Tour'],
470
+				'metaboxes'     => ['_publish_post_box'],
471
+				'require_nonce' => false,
472
+			],
473
+			'edit_category'          => [
474
+				'nav'           => [
475
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
476
+					'order'      => 15,
477
+					'persistent' => false,
478
+					'url'        => isset($this->_req_data['EVT_CAT_ID'])
479
+						? add_query_arg(
480
+							['EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']],
481
+							$this->_current_page_view_url
482
+						)
483
+						: $this->_admin_base_url,
484
+				],
485
+				'help_tabs'     => [
486
+					'edit_category_help_tab' => [
487
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
488
+						'filename' => 'events_edit_category',
489
+					],
490
+				],
491
+				/*'help_tour' => ['Event_Edit_Category_Help_Tour'],*/
492
+				'metaboxes'     => ['_publish_post_box'],
493
+				'require_nonce' => false,
494
+			],
495
+			'category_list'          => [
496
+				'nav'           => [
497
+					'label' => esc_html__('Categories', 'event_espresso'),
498
+					'order' => 20,
499
+				],
500
+				'list_table'    => 'Event_Categories_Admin_List_Table',
501
+				'help_tabs'     => [
502
+					'events_categories_help_tab'                       => [
503
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
504
+						'filename' => 'events_categories',
505
+					],
506
+					'events_categories_table_column_headings_help_tab' => [
507
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
508
+						'filename' => 'events_categories_table_column_headings',
509
+					],
510
+					'events_categories_view_help_tab'                  => [
511
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
512
+						'filename' => 'events_categories_views',
513
+					],
514
+					'events_categories_other_help_tab'                 => [
515
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
516
+						'filename' => 'events_categories_other',
517
+					],
518
+				],
519
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
520
+				// 'help_tour'     => [
521
+				//     'Event_Categories_Help_Tour',
522
+				// ],
523
+				'metaboxes'     => $this->_default_espresso_metaboxes,
524
+				'require_nonce' => false,
525
+			],
526
+			'preview_deletion'       => [
527
+				'nav'           => [
528
+					'label'      => esc_html__('Preview Deletion', 'event_espresso'),
529
+					'order'      => 15,
530
+					'persistent' => false,
531
+					'url'        => '',
532
+				],
533
+				'require_nonce' => false,
534
+			],
535
+		];
536
+		// only load EE_Event_Editor_Decaf_Tips if domain is not caffeinated
537
+		$domain = $this->loader->getShared('EventEspresso\core\domain\Domain');
538
+		if (! $domain->isCaffeinated()) {
539
+			$this->_page_config['create_new']['qtips'] = ['EE_Event_Editor_Decaf_Tips'];
540
+			$this->_page_config['edit']['qtips']       = ['EE_Event_Editor_Decaf_Tips'];
541
+		}
542
+	}
543
+
544
+
545
+	/**
546
+	 * Used to register any global screen options if necessary for every route in this admin page group.
547
+	 */
548
+	protected function _add_screen_options()
549
+	{
550
+	}
551
+
552
+
553
+	/**
554
+	 * Implementing the screen options for the 'default' route.
555
+	 *
556
+	 * @throws InvalidArgumentException
557
+	 * @throws InvalidDataTypeException
558
+	 * @throws InvalidInterfaceException
559
+	 */
560
+	protected function _add_screen_options_default()
561
+	{
562
+		$this->_per_page_screen_option();
563
+	}
564
+
565
+
566
+	/**
567
+	 * Implementing screen options for the category list route.
568
+	 *
569
+	 * @throws InvalidArgumentException
570
+	 * @throws InvalidDataTypeException
571
+	 * @throws InvalidInterfaceException
572
+	 */
573
+	protected function _add_screen_options_category_list()
574
+	{
575
+		$page_title              = $this->_admin_page_title;
576
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
577
+		$this->_per_page_screen_option();
578
+		$this->_admin_page_title = $page_title;
579
+	}
580
+
581
+
582
+	/**
583
+	 * Used to register any global feature pointers for the admin page group.
584
+	 */
585
+	protected function _add_feature_pointers()
586
+	{
587
+	}
588
+
589
+
590
+	/**
591
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
592
+	 */
593
+	public function load_scripts_styles()
594
+	{
595
+		wp_register_style(
596
+			'events-admin-css',
597
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
598
+			[],
599
+			EVENT_ESPRESSO_VERSION
600
+		);
601
+		wp_register_style(
602
+			'ee-cat-admin',
603
+			EVENTS_ASSETS_URL . 'ee-cat-admin.css',
604
+			[],
605
+			EVENT_ESPRESSO_VERSION
606
+		);
607
+		wp_enqueue_style('events-admin-css');
608
+		wp_enqueue_style('ee-cat-admin');
609
+		// scripts
610
+		wp_register_script(
611
+			'event_editor_js',
612
+			EVENTS_ASSETS_URL . 'event_editor.js',
613
+			['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
614
+			EVENT_ESPRESSO_VERSION,
615
+			true
616
+		);
617
+	}
618
+
619
+
620
+	/**
621
+	 * Enqueuing scripts and styles specific to this view
622
+	 */
623
+	public function load_scripts_styles_create_new()
624
+	{
625
+		$this->load_scripts_styles_edit();
626
+	}
627
+
628
+
629
+	/**
630
+	 * Enqueuing scripts and styles specific to this view
631
+	 */
632
+	public function load_scripts_styles_edit()
633
+	{
634
+		// styles
635
+		wp_enqueue_style('espresso-ui-theme');
636
+		wp_register_style(
637
+			'event-editor-css',
638
+			EVENTS_ASSETS_URL . 'event-editor.css',
639
+			['ee-admin-css'],
640
+			EVENT_ESPRESSO_VERSION
641
+		);
642
+		wp_enqueue_style('event-editor-css');
643
+		// scripts
644
+		if (! $this->admin_config->useAdvancedEditor()) {
645
+			wp_register_script(
646
+				'event-datetime-metabox',
647
+				EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
648
+				['event_editor_js', 'ee-datepicker'],
649
+				EVENT_ESPRESSO_VERSION
650
+			);
651
+			wp_enqueue_script('event-datetime-metabox');
652
+		}
653
+	}
654
+
655
+
656
+	/**
657
+	 * Populating the _views property for the category list table view.
658
+	 */
659
+	protected function _set_list_table_views_category_list()
660
+	{
661
+		$this->_views = [
662
+			'all' => [
663
+				'slug'        => 'all',
664
+				'label'       => esc_html__('All', 'event_espresso'),
665
+				'count'       => 0,
666
+				'bulk_action' => [
667
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
668
+				],
669
+			],
670
+		];
671
+	}
672
+
673
+
674
+	/**
675
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
676
+	 */
677
+	public function admin_init()
678
+	{
679
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
680
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
681
+			'event_espresso'
682
+		);
683
+	}
684
+
685
+
686
+	/**
687
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
688
+	 * group.
689
+	 */
690
+	public function admin_notices()
691
+	{
692
+	}
693
+
694
+
695
+	/**
696
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
697
+	 * this admin page group.
698
+	 */
699
+	public function admin_footer_scripts()
700
+	{
701
+	}
702
+
703
+
704
+	/**
705
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
706
+	 * warning (via EE_Error::add_error());
707
+	 *
708
+	 * @param EE_Event $event Event object
709
+	 * @param string   $req_type
710
+	 * @return void
711
+	 * @throws EE_Error
712
+	 * @access public
713
+	 */
714
+	public function verify_event_edit($event = null, $req_type = '')
715
+	{
716
+		// don't need to do this when processing
717
+		if (! empty($req_type)) {
718
+			return;
719
+		}
720
+		// no event?
721
+		if (! $event instanceof EE_Event) {
722
+			$event = $this->_cpt_model_obj;
723
+		}
724
+		// STILL no event?
725
+		if (! $event instanceof EE_Event) {
726
+			return;
727
+		}
728
+		$orig_status = $event->status();
729
+		// first check if event is active.
730
+		if (
731
+			$orig_status === EEM_Event::cancelled
732
+			|| $orig_status === EEM_Event::postponed
733
+			|| $event->is_expired()
734
+			|| $event->is_inactive()
735
+		) {
736
+			return;
737
+		}
738
+		// made it here so it IS active... next check that any of the tickets are sold.
739
+		if ($event->is_sold_out(true)) {
740
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
741
+				EE_Error::add_attention(
742
+					sprintf(
743
+						esc_html__(
744
+							'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
745
+							'event_espresso'
746
+						),
747
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
748
+					)
749
+				);
750
+			}
751
+			return;
752
+		}
753
+		if ($orig_status === EEM_Event::sold_out) {
754
+			EE_Error::add_attention(
755
+				sprintf(
756
+					esc_html__(
757
+						'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
758
+						'event_espresso'
759
+					),
760
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
761
+				)
762
+			);
763
+		}
764
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
765
+		if (! $event->tickets_on_sale()) {
766
+			return;
767
+		}
768
+		// made it here so show warning
769
+		$this->_edit_event_warning();
770
+	}
771
+
772
+
773
+	/**
774
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
775
+	 * When needed, hook this into a EE_Error::add_error() notice.
776
+	 *
777
+	 * @access protected
778
+	 * @return void
779
+	 */
780
+	protected function _edit_event_warning()
781
+	{
782
+		// we don't want to add warnings during these requests
783
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
784
+			return;
785
+		}
786
+		EE_Error::add_attention(
787
+			sprintf(
788
+				esc_html__(
789
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
790
+					'event_espresso'
791
+				),
792
+				'<a class="espresso-help-tab-lnk">',
793
+				'</a>'
794
+			)
795
+		);
796
+	}
797
+
798
+
799
+	/**
800
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
801
+	 * Otherwise, do the normal logic
802
+	 *
803
+	 * @return void
804
+	 * @throws EE_Error
805
+	 * @throws InvalidArgumentException
806
+	 * @throws InvalidDataTypeException
807
+	 * @throws InvalidInterfaceException
808
+	 */
809
+	protected function _create_new_cpt_item()
810
+	{
811
+		$has_timezone_string = get_option('timezone_string');
812
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
813
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
814
+			EE_Error::add_attention(
815
+				sprintf(
816
+					__(
817
+						'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
818
+						'event_espresso'
819
+					),
820
+					'<br>',
821
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
822
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
823
+					. '</select>',
824
+					'<button class="button button-secondary timezone-submit">',
825
+					'</button><span class="spinner"></span>'
826
+				),
827
+				__FILE__,
828
+				__FUNCTION__,
829
+				__LINE__
830
+			);
831
+		}
832
+		parent::_create_new_cpt_item();
833
+	}
834
+
835
+
836
+	/**
837
+	 * Sets the _views property for the default route in this admin page group.
838
+	 */
839
+	protected function _set_list_table_views_default()
840
+	{
841
+		$this->_views = [
842
+			'all'   => [
843
+				'slug'        => 'all',
844
+				'label'       => esc_html__('View All Events', 'event_espresso'),
845
+				'count'       => 0,
846
+				'bulk_action' => [
847
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
848
+				],
849
+			],
850
+			'draft' => [
851
+				'slug'        => 'draft',
852
+				'label'       => esc_html__('Draft', 'event_espresso'),
853
+				'count'       => 0,
854
+				'bulk_action' => [
855
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
856
+				],
857
+			],
858
+		];
859
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
860
+			$this->_views['trash'] = [
861
+				'slug'        => 'trash',
862
+				'label'       => esc_html__('Trash', 'event_espresso'),
863
+				'count'       => 0,
864
+				'bulk_action' => [
865
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
866
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
867
+				],
868
+			];
869
+		}
870
+	}
871
+
872
+
873
+	/**
874
+	 * Provides the legend item array for the default list table view.
875
+	 *
876
+	 * @return array
877
+	 */
878
+	protected function _event_legend_items()
879
+	{
880
+		$items    = [
881
+			'view_details'   => [
882
+				'class' => 'dashicons dashicons-search',
883
+				'desc'  => esc_html__('View Event', 'event_espresso'),
884
+			],
885
+			'edit_event'     => [
886
+				'class' => 'ee-icon ee-icon-calendar-edit',
887
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
888
+			],
889
+			'view_attendees' => [
890
+				'class' => 'dashicons dashicons-groups',
891
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
892
+			],
893
+		];
894
+		$items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
895
+		$statuses = [
896
+			'sold_out_status'  => [
897
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
898
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
899
+			],
900
+			'active_status'    => [
901
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
902
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
903
+			],
904
+			'upcoming_status'  => [
905
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
906
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
907
+			],
908
+			'postponed_status' => [
909
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
910
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
911
+			],
912
+			'cancelled_status' => [
913
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
914
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
915
+			],
916
+			'expired_status'   => [
917
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
918
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
919
+			],
920
+			'inactive_status'  => [
921
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
922
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
923
+			],
924
+		];
925
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
926
+		return array_merge($items, $statuses);
927
+	}
928
+
929
+
930
+	/**
931
+	 * @return EEM_Event
932
+	 * @throws EE_Error
933
+	 * @throws InvalidArgumentException
934
+	 * @throws InvalidDataTypeException
935
+	 * @throws InvalidInterfaceException
936
+	 * @throws ReflectionException
937
+	 */
938
+	private function _event_model()
939
+	{
940
+		if (! $this->_event_model instanceof EEM_Event) {
941
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
942
+		}
943
+		return $this->_event_model;
944
+	}
945
+
946
+
947
+	/**
948
+	 * Adds extra buttons to the WP CPT permalink field row.
949
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
950
+	 *
951
+	 * @param string $return    the current html
952
+	 * @param int    $id        the post id for the page
953
+	 * @param string $new_title What the title is
954
+	 * @param string $new_slug  what the slug is
955
+	 * @return string            The new html string for the permalink area
956
+	 */
957
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
958
+	{
959
+		// make sure this is only when editing
960
+		if (! empty($id)) {
961
+			$post   = get_post($id);
962
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
963
+					   . esc_html__('Shortcode', 'event_espresso')
964
+					   . '</a> ';
965
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
966
+					   . $post->ID
967
+					   . ']">';
968
+		}
969
+		return $return;
970
+	}
971
+
972
+
973
+	/**
974
+	 * _events_overview_list_table
975
+	 * This contains the logic for showing the events_overview list
976
+	 *
977
+	 * @access protected
978
+	 * @return void
979
+	 * @throws DomainException
980
+	 * @throws EE_Error
981
+	 * @throws InvalidArgumentException
982
+	 * @throws InvalidDataTypeException
983
+	 * @throws InvalidInterfaceException
984
+	 */
985
+	protected function _events_overview_list_table()
986
+	{
987
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
988
+		$this->_template_args['after_list_table']                           =
989
+			! empty($this->_template_args['after_list_table'])
990
+				? (array) $this->_template_args['after_list_table']
991
+				: [];
992
+		$this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
993
+			. EEH_Template::get_button_or_link(
994
+				get_post_type_archive_link('espresso_events'),
995
+				esc_html__('View Event Archive Page', 'event_espresso'),
996
+				'button'
997
+			);
998
+		$this->_template_args['after_list_table']['legend']                 =
999
+			$this->_display_legend($this->_event_legend_items());
1000
+		$this->_admin_page_title                                            .= ' '
1001
+			. $this->get_action_link_or_button(
1002
+				'create_new',
1003
+				'add',
1004
+				[],
1005
+				'add-new-h2'
1006
+			);
1007
+		$this->display_admin_list_table_page_with_no_sidebar();
1008
+	}
1009
+
1010
+
1011
+	/**
1012
+	 * this allows for extra misc actions in the default WP publish box
1013
+	 *
1014
+	 * @return void
1015
+	 * @throws DomainException
1016
+	 * @throws EE_Error
1017
+	 * @throws InvalidArgumentException
1018
+	 * @throws InvalidDataTypeException
1019
+	 * @throws InvalidInterfaceException
1020
+	 * @throws ReflectionException
1021
+	 */
1022
+	public function extra_misc_actions_publish_box()
1023
+	{
1024
+		$this->_generate_publish_box_extra_content();
1025
+	}
1026
+
1027
+
1028
+	/**
1029
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
1030
+	 * saved.
1031
+	 * Typically you would use this to save any additional data.
1032
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
1033
+	 * ALSO very important.  When a post transitions from scheduled to published,
1034
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
1035
+	 * other meta saves. So MAKE sure that you handle this accordingly.
1036
+	 *
1037
+	 * @access protected
1038
+	 * @abstract
1039
+	 * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
1040
+	 * @param object $post    The post object of the cpt that was saved.
1041
+	 * @return void
1042
+	 * @throws EE_Error
1043
+	 * @throws InvalidArgumentException
1044
+	 * @throws InvalidDataTypeException
1045
+	 * @throws InvalidInterfaceException
1046
+	 * @throws ReflectionException
1047
+	 */
1048
+	protected function _insert_update_cpt_item($post_id, $post)
1049
+	{
1050
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
1051
+			// get out we're not processing an event save.
1052
+			return;
1053
+		}
1054
+		$event_values = [
1055
+			'EVT_member_only'     => ! empty($this->_req_data['member_only']) ? 1 : 0,
1056
+			'EVT_allow_overflow'  => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
1057
+			'EVT_timezone_string' => ! empty($this->_req_data['timezone_string'])
1058
+				? sanitize_text_field($this->_req_data['timezone_string'])
1059
+				: null,
1060
+		];
1061
+		/** @var FeatureFlags $flags */
1062
+		$flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1063
+		// check if the new EDTR reg options meta box is being used, and if so, don't run updates for legacy version
1064
+		if (! $this->admin_config->useAdvancedEditor() || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1065
+			$event_values['EVT_display_ticket_selector']     =
1066
+				! empty($this->_req_data['display_ticket_selector'])
1067
+					? 1
1068
+					: 0;
1069
+			$event_values['EVT_additional_limit']            = min(
1070
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1071
+				! empty($this->_req_data['additional_limit'])
1072
+					? absint($this->_req_data['additional_limit'])
1073
+					: null
1074
+			);
1075
+			$event_values['EVT_default_registration_status'] =
1076
+				! empty($this->_req_data['EVT_default_registration_status'])
1077
+					? sanitize_text_field($this->_req_data['EVT_default_registration_status'])
1078
+					: EE_Registry::instance()->CFG->registration->default_STS_ID;
1079
+			$event_values['EVT_external_URL']                = ! empty($this->_req_data['externalURL'])
1080
+				? esc_url_raw($this->_req_data['externalURL'])
1081
+				: null;
1082
+			$event_values['EVT_phone']                       = ! empty($this->_req_data['event_phone'])
1083
+				? sanitize_text_field($this->_req_data['event_phone'])
1084
+				: null;
1085
+		}
1086
+		// update event
1087
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1088
+		// get event_object for other metaboxes...
1089
+		// though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1090
+		// i have to setup where conditions to override the filters in the model that filter out autodraft
1091
+		// and inherit statuses so we GET the inherit id!
1092
+		$get_one_where = [
1093
+			$this->_event_model()->primary_key_name() => $post_id,
1094
+			'OR'                                      => [
1095
+				'status'   => $post->post_status,
1096
+				// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1097
+				// but the returned object here has a status of "publish", so use the original post status as well
1098
+				'status*1' => $this->_req_data['original_post_status'],
1099
+			],
1100
+		];
1101
+		$event         = $this->_event_model()->get_one([$get_one_where]);
1102
+		// the following are default callbacks for event attachment updates
1103
+		// that can be overridden by caffeinated functionality and/or addons.
1104
+		$event_update_callbacks = apply_filters(
1105
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1106
+			[
1107
+				[$this, '_default_venue_update'],
1108
+				[$this, '_default_tickets_update'],
1109
+			]
1110
+		);
1111
+		$att_success            = true;
1112
+		foreach ($event_update_callbacks as $e_callback) {
1113
+			$_success = is_callable($e_callback)
1114
+				? $e_callback($event, $this->_req_data)
1115
+				: false;
1116
+			// if ANY of these updates fail then we want the appropriate global error message
1117
+			$att_success = ! $att_success ? $att_success : $_success;
1118
+		}
1119
+		// any errors?
1120
+		if ($success && false === $att_success) {
1121
+			EE_Error::add_error(
1122
+				esc_html__(
1123
+					'Event Details saved successfully but something went wrong with saving attachments.',
1124
+					'event_espresso'
1125
+				),
1126
+				__FILE__,
1127
+				__FUNCTION__,
1128
+				__LINE__
1129
+			);
1130
+		} elseif ($success === false) {
1131
+			EE_Error::add_error(
1132
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1133
+				__FILE__,
1134
+				__FUNCTION__,
1135
+				__LINE__
1136
+			);
1137
+		}
1138
+	}
1139
+
1140
+
1141
+	/**
1142
+	 * @param int $post_id
1143
+	 * @param int $revision_id
1144
+	 * @throws EE_Error
1145
+	 * @throws InvalidArgumentException
1146
+	 * @throws InvalidDataTypeException
1147
+	 * @throws InvalidInterfaceException
1148
+	 * @throws ReflectionException
1149
+	 * @see parent::restore_item()
1150
+	 */
1151
+	protected function _restore_cpt_item($post_id, $revision_id)
1152
+	{
1153
+		// copy existing event meta to new post
1154
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1155
+		if ($post_evt instanceof EE_Event) {
1156
+			// meta revision restore
1157
+			$post_evt->restore_revision($revision_id);
1158
+			// related objs restore
1159
+			$post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1160
+		}
1161
+	}
1162
+
1163
+
1164
+	/**
1165
+	 * Attach the venue to the Event
1166
+	 *
1167
+	 * @param EE_Event $evtobj Event Object to add the venue to
1168
+	 * @param array    $data   The request data from the form
1169
+	 * @return bool           Success or fail.
1170
+	 * @throws EE_Error
1171
+	 * @throws InvalidArgumentException
1172
+	 * @throws InvalidDataTypeException
1173
+	 * @throws InvalidInterfaceException
1174
+	 * @throws ReflectionException
1175
+	 */
1176
+	protected function _default_venue_update(EE_Event $evtobj, $data)
1177
+	{
1178
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1179
+		$venue_model   = EE_Registry::instance()->load_model('Venue');
1180
+		$rows_affected = null;
1181
+		$venue_id      = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1182
+		// very important.  If we don't have a venue name...
1183
+		// then we'll get out because not necessary to create empty venue
1184
+		if (empty($data['venue_title'])) {
1185
+			return false;
1186
+		}
1187
+		$venue_array = [
1188
+			'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1189
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1190
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1191
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1192
+			'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1193
+				: null,
1194
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1195
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1196
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1197
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1198
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1199
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1200
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1201
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1202
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1203
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1204
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1205
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1206
+			'status'              => 'publish',
1207
+		];
1208
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1209
+		if (! empty($venue_id)) {
1210
+			$update_where  = [$venue_model->primary_key_name() => $venue_id];
1211
+			$rows_affected = $venue_model->update($venue_array, [$update_where]);
1212
+			// we've gotta make sure that the venue is always attached to a revision..
1213
+			// add_relation_to should take care of making sure that the relation is already present.
1214
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1215
+			return $rows_affected > 0;
1216
+		}
1217
+		// we insert the venue
1218
+		$venue_id = $venue_model->insert($venue_array);
1219
+		$evtobj->_add_relation_to($venue_id, 'Venue');
1220
+		return ! empty($venue_id);
1221
+		// when we have the ancestor come in it's already been handled by the revision save.
1222
+	}
1223
+
1224
+
1225
+	/**
1226
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1227
+	 *
1228
+	 * @param EE_Event $evtobj The Event object we're attaching data to
1229
+	 * @param array    $data   The request data from the form
1230
+	 * @return array
1231
+	 * @throws EE_Error
1232
+	 * @throws InvalidArgumentException
1233
+	 * @throws InvalidDataTypeException
1234
+	 * @throws InvalidInterfaceException
1235
+	 * @throws ReflectionException
1236
+	 * @throws Exception
1237
+	 */
1238
+	protected function _default_tickets_update(EE_Event $evtobj, $data)
1239
+	{
1240
+		if ($this->admin_config->useAdvancedEditor()) {
1241
+			return [];
1242
+		}
1243
+		$success               = true;
1244
+		$saved_dtt             = null;
1245
+		$saved_tickets         = [];
1246
+		$incoming_date_formats = ['Y-m-d', 'h:i a'];
1247
+		foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1248
+			// trim all values to ensure any excess whitespace is removed.
1249
+			$dtt                = array_map('trim', $dtt);
1250
+			$dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1251
+				: $dtt['DTT_EVT_start'];
1252
+			$datetime_values    = [
1253
+				'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1254
+				'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1255
+				'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1256
+				'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1257
+				'DTT_order'     => $row,
1258
+			];
1259
+			// if we have an id then let's get existing object first and then set the new values.
1260
+			//  Otherwise we instantiate a new object for save.
1261
+			if (! empty($dtt['DTT_ID'])) {
1262
+				$DTM = EE_Registry::instance()
1263
+								  ->load_model('Datetime', [$evtobj->get_timezone()])
1264
+								  ->get_one_by_ID($dtt['DTT_ID']);
1265
+				$DTM->set_date_format($incoming_date_formats[0]);
1266
+				$DTM->set_time_format($incoming_date_formats[1]);
1267
+				foreach ($datetime_values as $field => $value) {
1268
+					$DTM->set($field, $value);
1269
+				}
1270
+				// make sure the $dtt_id here is saved in case after the add_relation_to() the autosave replaces it.
1271
+				// We need to do this so we dont' TRASH the parent DTT.
1272
+				$saved_dtts[ $DTM->ID() ] = $DTM;
1273
+			} else {
1274
+				$DTM = EE_Registry::instance()->load_class(
1275
+					'Datetime',
1276
+					[$datetime_values, $evtobj->get_timezone(), $incoming_date_formats],
1277
+					false,
1278
+					false
1279
+				);
1280
+				foreach ($datetime_values as $field => $value) {
1281
+					$DTM->set($field, $value);
1282
+				}
1283
+			}
1284
+			$DTM->save();
1285
+			$DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1286
+			// load DTT helper
1287
+			// before going any further make sure our dates are setup correctly
1288
+			// so that the end date is always equal or greater than the start date.
1289
+			if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1290
+				$DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1291
+				$DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1292
+				$DTT->save();
1293
+			}
1294
+			// now we got to make sure we add the new DTT_ID to the $saved_dtts array
1295
+			//  because it is possible there was a new one created for the autosave.
1296
+			$saved_dtt = $DTT;
1297
+			$success   = ! $success ? $success : $DTT;
1298
+			// if ANY of these updates fail then we want the appropriate global error message.
1299
+			// //todo this is actually sucky we need a better error message but this is what it is for now.
1300
+		}
1301
+		// no dtts get deleted so we don't do any of that logic here.
1302
+		// update tickets next
1303
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1304
+		foreach ($data['edit_tickets'] as $row => $tkt) {
1305
+			$incoming_date_formats = ['Y-m-d', 'h:i a'];
1306
+			$update_prices         = false;
1307
+			$ticket_price          = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1308
+				? $data['edit_prices'][ $row ][1]['PRC_amount']
1309
+				: 0;
1310
+			// trim inputs to ensure any excess whitespace is removed.
1311
+			$tkt = array_map('trim', $tkt);
1312
+			if (empty($tkt['TKT_start_date'])) {
1313
+				// let's use now in the set timezone.
1314
+				$now                   = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1315
+				$tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1316
+			}
1317
+			if (empty($tkt['TKT_end_date'])) {
1318
+				// use the start date of the first datetime
1319
+				$dtt                 = $evtobj->first_datetime();
1320
+				$tkt['TKT_end_date'] = $dtt->start_date_and_time(
1321
+					$incoming_date_formats[0],
1322
+					$incoming_date_formats[1]
1323
+				);
1324
+			}
1325
+			$TKT_values = [
1326
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1327
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1328
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1329
+				'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1330
+				'TKT_start_date'  => $tkt['TKT_start_date'],
1331
+				'TKT_end_date'    => $tkt['TKT_end_date'],
1332
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1333
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1334
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1335
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1336
+				'TKT_row'         => $row,
1337
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1338
+				'TKT_price'       => $ticket_price,
1339
+			];
1340
+			// if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly,
1341
+			// which means in turn that the prices will become new prices as well.
1342
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1343
+				$TKT_values['TKT_ID']         = 0;
1344
+				$TKT_values['TKT_is_default'] = 0;
1345
+				$TKT_values['TKT_price']      = $ticket_price;
1346
+				$update_prices                = true;
1347
+			}
1348
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1349
+			// we actually do our saves a head of doing any add_relations to because its entirely possible
1350
+			// that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1351
+			// keep in mind that if the TKT has been sold (and we have changed pricing information),
1352
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1353
+			if (! empty($tkt['TKT_ID'])) {
1354
+				$TKT = EE_Registry::instance()
1355
+								  ->load_model('Ticket', [$evtobj->get_timezone()])
1356
+								  ->get_one_by_ID($tkt['TKT_ID']);
1357
+				if ($TKT instanceof EE_Ticket) {
1358
+					$ticket_sold = $TKT->count_related(
1359
+						'Registration',
1360
+						[
1361
+							[
1362
+								'STS_ID' => [
1363
+									'NOT IN',
1364
+									[EEM_Registration::status_id_incomplete],
1365
+								],
1366
+							],
1367
+						]
1368
+					) > 0;
1369
+					// let's just check the total price for the existing ticket and determine if it matches the new
1370
+					// total price.  if they are different then we create a new ticket (if tickets sold)
1371
+					// if they aren't different then we go ahead and modify existing ticket.
1372
+					$create_new_TKT = $ticket_sold
1373
+									  && ! $TKT->deleted()
1374
+									  && EEH_Money::compare_floats(
1375
+										  $ticket_price,
1376
+										  $TKT->get('TKT_price'),
1377
+										  '!=='
1378
+									  );
1379
+					$TKT->set_date_format($incoming_date_formats[0]);
1380
+					$TKT->set_time_format($incoming_date_formats[1]);
1381
+					// set new values
1382
+					foreach ($TKT_values as $field => $value) {
1383
+						if ($field === 'TKT_qty') {
1384
+							$TKT->set_qty($value);
1385
+						} else {
1386
+							$TKT->set($field, $value);
1387
+						}
1388
+					}
1389
+					// if $create_new_TKT is false then we can safely update the existing ticket.
1390
+					//  Otherwise we have to create a new ticket.
1391
+					if ($create_new_TKT) {
1392
+						// archive the old ticket first
1393
+						$TKT->set('TKT_deleted', 1);
1394
+						$TKT->save();
1395
+						// make sure this ticket is still recorded in our saved_tkts
1396
+						// so we don't run it through the regular trash routine.
1397
+						$saved_tickets[ $TKT->ID() ] = $TKT;
1398
+						// create new ticket that's a copy of the existing except a new id of course
1399
+						// (and not archived) AND has the new TKT_price associated with it.
1400
+						$TKT = clone $TKT;
1401
+						$TKT->set('TKT_ID', 0);
1402
+						$TKT->set('TKT_deleted', 0);
1403
+						$TKT->set('TKT_price', $ticket_price);
1404
+						$TKT->set('TKT_sold', 0);
1405
+						// now we need to make sure that $new prices are created as well and attached to new ticket.
1406
+						$update_prices = true;
1407
+					}
1408
+					// make sure price is set if it hasn't been already
1409
+					$TKT->set('TKT_price', $ticket_price);
1410
+				}
1411
+			} else {
1412
+				// no TKT_id so a new TKT
1413
+				$TKT_values['TKT_price'] = $ticket_price;
1414
+				$TKT                     = EE_Registry::instance()->load_class('Ticket', [$TKT_values], false, false);
1415
+				if ($TKT instanceof EE_Ticket) {
1416
+					// need to reset values to properly account for the date formats
1417
+					$TKT->set_date_format($incoming_date_formats[0]);
1418
+					$TKT->set_time_format($incoming_date_formats[1]);
1419
+					$TKT->set_timezone($evtobj->get_timezone());
1420
+					// set new values
1421
+					foreach ($TKT_values as $field => $value) {
1422
+						if ($field === 'TKT_qty') {
1423
+							$TKT->set_qty($value);
1424
+						} else {
1425
+							$TKT->set($field, $value);
1426
+						}
1427
+					}
1428
+					$update_prices = true;
1429
+				}
1430
+			}
1431
+			// cap ticket qty by datetime reg limits
1432
+			$TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1433
+			// update ticket.
1434
+			$TKT->save();
1435
+			// before going any further make sure our dates are setup correctly
1436
+			// so that the end date is always equal or greater than the start date.
1437
+			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1438
+				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1439
+				$TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1440
+				$TKT->save();
1441
+			}
1442
+			// initially let's add the ticket to the dtt
1443
+			$saved_dtt->_add_relation_to($TKT, 'Ticket');
1444
+			$saved_tickets[ $TKT->ID() ] = $TKT;
1445
+			// add prices to ticket
1446
+			$this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices);
1447
+		}
1448
+		// however now we need to handle permanently deleting tickets via the ui.
1449
+		//  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1450
+		//  However, it does allow for deleting tickets that have no tickets sold,
1451
+		// in which case we want to get rid of permanently because there is no need to save in db.
1452
+		$old_tickets     = isset($old_tickets[0]) && $old_tickets[0] === '' ? [] : $old_tickets;
1453
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1454
+		foreach ($tickets_removed as $id) {
1455
+			$id = absint($id);
1456
+			// get the ticket for this id
1457
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1458
+			// need to get all the related datetimes on this ticket and remove from every single one of them
1459
+			// (remember this process can ONLY kick off if there are NO tkts_sold)
1460
+			$dtts = $tkt_to_remove->get_many_related('Datetime');
1461
+			foreach ($dtts as $dtt) {
1462
+				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1463
+			}
1464
+			// need to do the same for prices (except these prices can also be deleted because again,
1465
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1466
+			$tkt_to_remove->delete_related_permanently('Price');
1467
+			// finally let's delete this ticket
1468
+			// (which should not be blocked at this point b/c we've removed all our relationships)
1469
+			$tkt_to_remove->delete_permanently();
1470
+		}
1471
+		return [$saved_dtt, $saved_tickets];
1472
+	}
1473
+
1474
+
1475
+	/**
1476
+	 * This attaches a list of given prices to a ticket.
1477
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices)
1478
+	 * because if there is a change in price information on a ticket, a new ticket is created anyways
1479
+	 * so the archived ticket will retain the old price info and prices are automatically "archived" via the ticket.
1480
+	 *
1481
+	 * @access  private
1482
+	 * @param array     $prices     Array of prices from the form.
1483
+	 * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1484
+	 * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1485
+	 * @return  void
1486
+	 * @throws EE_Error
1487
+	 * @throws InvalidArgumentException
1488
+	 * @throws InvalidDataTypeException
1489
+	 * @throws InvalidInterfaceException
1490
+	 * @throws ReflectionException
1491
+	 */
1492
+	private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1493
+	{
1494
+		foreach ($prices as $row => $prc) {
1495
+			$PRC_values = [
1496
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1497
+				'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1498
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1499
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1500
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1501
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1502
+				'PRC_order'      => $row,
1503
+			];
1504
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
1505
+				$PRC_values['PRC_ID'] = 0;
1506
+				$PRC                  = EE_Registry::instance()->load_class('Price', [$PRC_values], false, false);
1507
+			} else {
1508
+				$PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1509
+				// update this price with new values
1510
+				foreach ($PRC_values as $field => $newprc) {
1511
+					$PRC->set($field, $newprc);
1512
+				}
1513
+				$PRC->save();
1514
+			}
1515
+			$ticket->_add_relation_to($PRC, 'Price');
1516
+		}
1517
+	}
1518
+
1519
+
1520
+	/**
1521
+	 * Add in our autosave ajax handlers
1522
+	 *
1523
+	 */
1524
+	protected function _ee_autosave_create_new()
1525
+	{
1526
+	}
1527
+
1528
+
1529
+	/**
1530
+	 * More autosave handlers.
1531
+	 */
1532
+	protected function _ee_autosave_edit()
1533
+	{
1534
+	}
1535
+
1536
+
1537
+	/**
1538
+	 *    _generate_publish_box_extra_content
1539
+	 *
1540
+	 * @throws DomainException
1541
+	 * @throws EE_Error
1542
+	 * @throws InvalidArgumentException
1543
+	 * @throws InvalidDataTypeException
1544
+	 * @throws InvalidInterfaceException
1545
+	 * @throws ReflectionException
1546
+	 */
1547
+	private function _generate_publish_box_extra_content()
1548
+	{
1549
+		// load formatter helper
1550
+		// args for getting related registrations
1551
+		$approved_query_args        = [
1552
+			[
1553
+				'REG_deleted' => 0,
1554
+				'STS_ID'      => EEM_Registration::status_id_approved,
1555
+			],
1556
+		];
1557
+		$not_approved_query_args    = [
1558
+			[
1559
+				'REG_deleted' => 0,
1560
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1561
+			],
1562
+		];
1563
+		$pending_payment_query_args = [
1564
+			[
1565
+				'REG_deleted' => 0,
1566
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1567
+			],
1568
+		];
1569
+		// publish box
1570
+		$publish_box_extra_args = [
1571
+			'view_approved_reg_url'        => add_query_arg(
1572
+				[
1573
+					'action'      => 'default',
1574
+					'event_id'    => $this->_cpt_model_obj->ID(),
1575
+					'_reg_status' => EEM_Registration::status_id_approved,
1576
+				],
1577
+				REG_ADMIN_URL
1578
+			),
1579
+			'view_not_approved_reg_url'    => add_query_arg(
1580
+				[
1581
+					'action'      => 'default',
1582
+					'event_id'    => $this->_cpt_model_obj->ID(),
1583
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1584
+				],
1585
+				REG_ADMIN_URL
1586
+			),
1587
+			'view_pending_payment_reg_url' => add_query_arg(
1588
+				[
1589
+					'action'      => 'default',
1590
+					'event_id'    => $this->_cpt_model_obj->ID(),
1591
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1592
+				],
1593
+				REG_ADMIN_URL
1594
+			),
1595
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1596
+				'Registration',
1597
+				$approved_query_args
1598
+			),
1599
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1600
+				'Registration',
1601
+				$not_approved_query_args
1602
+			),
1603
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1604
+				'Registration',
1605
+				$pending_payment_query_args
1606
+			),
1607
+			'misc_pub_section_class'       => apply_filters(
1608
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1609
+				'misc-pub-section'
1610
+			),
1611
+		];
1612
+		ob_start();
1613
+		do_action(
1614
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1615
+			$this->_cpt_model_obj
1616
+		);
1617
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1618
+		// load template
1619
+		EEH_Template::display_template(
1620
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1621
+			$publish_box_extra_args
1622
+		);
1623
+	}
1624
+
1625
+
1626
+	/**
1627
+	 * @return EE_Event
1628
+	 */
1629
+	public function get_event_object()
1630
+	{
1631
+		return $this->_cpt_model_obj;
1632
+	}
1633
+
1634
+
1635
+
1636
+
1637
+	/** METABOXES * */
1638
+	/**
1639
+	 * _register_event_editor_meta_boxes
1640
+	 * add all metaboxes related to the event_editor
1641
+	 *
1642
+	 * @return void
1643
+	 * @throws EE_Error
1644
+	 * @throws InvalidArgumentException
1645
+	 * @throws InvalidDataTypeException
1646
+	 * @throws InvalidInterfaceException
1647
+	 * @throws ReflectionException
1648
+	 */
1649
+	protected function _register_event_editor_meta_boxes()
1650
+	{
1651
+		$this->verify_cpt_object();
1652
+		$use_advanced_editor = $this->admin_config->useAdvancedEditor();
1653
+		/** @var FeatureFlags $flags */
1654
+		$flags = $this->loader->getShared('EventEspresso\core\domain\services\capabilities\FeatureFlags');
1655
+		// check if the new EDTR reg options meta box is being used, and if so, don't load the legacy version
1656
+		if (! $use_advanced_editor || ! $flags->featureAllowed('use_reg_options_meta_box')) {
1657
+			add_meta_box(
1658
+				'espresso_event_editor_event_options',
1659
+				esc_html__('Event Registration Options', 'event_espresso'),
1660
+				[$this, 'registration_options_meta_box'],
1661
+				$this->page_slug,
1662
+				'side'
1663
+			);
1664
+		}
1665
+		if (! $use_advanced_editor) {
1666
+			add_meta_box(
1667
+				'espresso_event_editor_tickets',
1668
+				esc_html__('Event Datetime & Ticket', 'event_espresso'),
1669
+				[$this, 'ticket_metabox'],
1670
+				$this->page_slug,
1671
+				'normal',
1672
+				'high'
1673
+			);
1674
+		} else {
1675
+			if ($flags->featureAllowed('use_reg_options_meta_box')) {
1676
+				add_action(
1677
+					'add_meta_boxes_espresso_events',
1678
+					function () {
1679
+						global $current_screen;
1680
+						remove_meta_box('authordiv', $current_screen, 'normal');
1681
+					},
1682
+					99
1683
+				);
1684
+			}
1685
+		}
1686
+		// NOTE: if you're looking for other metaboxes in here,
1687
+		// where a metabox has a related management page in the admin
1688
+		// you will find it setup in the related management page's "_Hooks" file.
1689
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1690
+	}
1691
+
1692
+
1693
+	/**
1694
+	 * @throws DomainException
1695
+	 * @throws EE_Error
1696
+	 * @throws InvalidArgumentException
1697
+	 * @throws InvalidDataTypeException
1698
+	 * @throws InvalidInterfaceException
1699
+	 * @throws ReflectionException
1700
+	 */
1701
+	public function ticket_metabox()
1702
+	{
1703
+		$existing_datetime_ids = $existing_ticket_ids = [];
1704
+		// defaults for template args
1705
+		$template_args = [
1706
+			'existing_datetime_ids'    => '',
1707
+			'event_datetime_help_link' => '',
1708
+			'ticket_options_help_link' => '',
1709
+			'time'                     => null,
1710
+			'ticket_rows'              => '',
1711
+			'existing_ticket_ids'      => '',
1712
+			'total_ticket_rows'        => 1,
1713
+			'ticket_js_structure'      => '',
1714
+			'trash_icon'               => 'ee-lock-icon',
1715
+			'disabled'                 => '',
1716
+		];
1717
+		$event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1718
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1719
+		/**
1720
+		 * 1. Start with retrieving Datetimes
1721
+		 * 2. Fore each datetime get related tickets
1722
+		 * 3. For each ticket get related prices
1723
+		 */
1724
+		$times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1725
+		/** @type EE_Datetime $first_datetime */
1726
+		$first_datetime = reset($times);
1727
+		// do we get related tickets?
1728
+		if (
1729
+			$first_datetime instanceof EE_Datetime
1730
+			&& $first_datetime->ID() !== 0
1731
+		) {
1732
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1733
+			$template_args['time']   = $first_datetime;
1734
+			$related_tickets         = $first_datetime->tickets(
1735
+				[
1736
+					['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1737
+					'default_where_conditions' => 'none',
1738
+				]
1739
+			);
1740
+			if (! empty($related_tickets)) {
1741
+				$template_args['total_ticket_rows'] = count($related_tickets);
1742
+				$row                                = 0;
1743
+				foreach ($related_tickets as $ticket) {
1744
+					$existing_ticket_ids[]        = $ticket->get('TKT_ID');
1745
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1746
+					$row++;
1747
+				}
1748
+			} else {
1749
+				$template_args['total_ticket_rows'] = 1;
1750
+				/** @type EE_Ticket $ticket */
1751
+				$ticket                       = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1752
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1753
+			}
1754
+		} else {
1755
+			$template_args['time'] = $times[0];
1756
+			/** @type EE_Ticket $ticket */
1757
+			$ticket                       = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1758
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1759
+			// NOTE: we're just sending the first default row
1760
+			// (decaf can't manage default tickets so this should be sufficient);
1761
+		}
1762
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1763
+			'event_editor_event_datetimes_help_tab'
1764
+		);
1765
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1766
+		$template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1767
+		$template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1768
+		$template_args['ticket_js_structure']      = $this->_get_ticket_row(
1769
+			EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1770
+			true
1771
+		);
1772
+		$template                                  = apply_filters(
1773
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1774
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1775
+		);
1776
+		EEH_Template::display_template($template, $template_args);
1777
+	}
1778
+
1779
+
1780
+	/**
1781
+	 * Setup an individual ticket form for the decaf event editor page
1782
+	 *
1783
+	 * @access private
1784
+	 * @param EE_Ticket $ticket   the ticket object
1785
+	 * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1786
+	 * @param int       $row
1787
+	 * @return string generated html for the ticket row.
1788
+	 * @throws DomainException
1789
+	 * @throws EE_Error
1790
+	 * @throws InvalidArgumentException
1791
+	 * @throws InvalidDataTypeException
1792
+	 * @throws InvalidInterfaceException
1793
+	 * @throws ReflectionException
1794
+	 */
1795
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1796
+	{
1797
+		$template_args = [
1798
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1799
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1800
+				: '',
1801
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1802
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1803
+			'TKT_name'            => $ticket->get('TKT_name'),
1804
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1805
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1806
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1807
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1808
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1809
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1810
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1811
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1812
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1813
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1814
+				: ' disabled=disabled',
1815
+		];
1816
+		$price         = $ticket->ID() !== 0
1817
+			? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1818
+			: EE_Registry::instance()->load_model('Price')->create_default_object();
1819
+		$price_args    = [
1820
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1821
+			'PRC_amount'            => $price->get('PRC_amount'),
1822
+			'PRT_ID'                => $price->get('PRT_ID'),
1823
+			'PRC_ID'                => $price->get('PRC_ID'),
1824
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1825
+		];
1826
+		// make sure we have default start and end dates if skeleton
1827
+		// handle rows that should NOT be empty
1828
+		if (empty($template_args['TKT_start_date'])) {
1829
+			// if empty then the start date will be now.
1830
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1831
+		}
1832
+		if (empty($template_args['TKT_end_date'])) {
1833
+			// get the earliest datetime (if present);
1834
+			$earliest_dtt = $this->_cpt_model_obj->ID() > 0
1835
+				? $this->_cpt_model_obj->get_first_related(
1836
+					'Datetime',
1837
+					['order_by' => ['DTT_EVT_start' => 'ASC']]
1838
+				)
1839
+				: null;
1840
+			if (! empty($earliest_dtt)) {
1841
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1842
+			} else {
1843
+				$template_args['TKT_end_date'] = date(
1844
+					'Y-m-d h:i a',
1845
+					mktime(0, 0, 0, date('m'), date('d') + 7, date('Y'))
1846
+				);
1847
+			}
1848
+		}
1849
+		$template_args = array_merge($template_args, $price_args);
1850
+		$template      = apply_filters(
1851
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1852
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1853
+			$ticket
1854
+		);
1855
+		return EEH_Template::display_template($template, $template_args, true);
1856
+	}
1857
+
1858
+
1859
+	/**
1860
+	 * @throws DomainException
1861
+	 * @throws EE_Error
1862
+	 */
1863
+	public function registration_options_meta_box()
1864
+	{
1865
+		$yes_no_values             = [
1866
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1867
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1868
+		];
1869
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1870
+			[
1871
+				EEM_Registration::status_id_cancelled,
1872
+				EEM_Registration::status_id_declined,
1873
+				EEM_Registration::status_id_incomplete,
1874
+			],
1875
+			true
1876
+		);
1877
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1878
+		$template_args['_event']                          = $this->_cpt_model_obj;
1879
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1880
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1881
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1882
+			'default_reg_status',
1883
+			$default_reg_status_values,
1884
+			$this->_cpt_model_obj->default_registration_status()
1885
+		);
1886
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
1887
+			'display_desc',
1888
+			$yes_no_values,
1889
+			$this->_cpt_model_obj->display_description()
1890
+		);
1891
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1892
+			'display_ticket_selector',
1893
+			$yes_no_values,
1894
+			$this->_cpt_model_obj->display_ticket_selector(),
1895
+			'',
1896
+			'',
1897
+			false
1898
+		);
1899
+		$template_args['additional_registration_options'] = apply_filters(
1900
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1901
+			'',
1902
+			$template_args,
1903
+			$yes_no_values,
1904
+			$default_reg_status_values
1905
+		);
1906
+		EEH_Template::display_template(
1907
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1908
+			$template_args
1909
+		);
1910
+	}
1911
+
1912
+
1913
+	/**
1914
+	 * _get_events()
1915
+	 * This method simply returns all the events (for the given _view and paging)
1916
+	 *
1917
+	 * @access public
1918
+	 * @param int  $per_page     count of items per page (20 default);
1919
+	 * @param int  $current_page what is the current page being viewed.
1920
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1921
+	 *                           If FALSE then we return an array of event objects
1922
+	 *                           that match the given _view and paging parameters.
1923
+	 * @return array|int an array of event objects.
1924
+	 * @throws EE_Error
1925
+	 * @throws InvalidArgumentException
1926
+	 * @throws InvalidDataTypeException
1927
+	 * @throws InvalidInterfaceException
1928
+	 * @throws ReflectionException
1929
+	 * @throws Exception
1930
+	 * @throws Exception
1931
+	 * @throws Exception
1932
+	 */
1933
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1934
+	{
1935
+		$EEME    = $this->_event_model();
1936
+		$offset  = ($current_page - 1) * $per_page;
1937
+		$limit   = $count ? null : $offset . ',' . $per_page;
1938
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1939
+		$order   = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
1940
+		if (isset($this->_req_data['month_range'])) {
1941
+			$pieces = explode(' ', $this->_req_data['month_range'], 3);
1942
+			// simulate the FIRST day of the month, that fixes issues for months like February
1943
+			// where PHP doesn't know what to assume for date.
1944
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1945
+			$month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1946
+			$year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1947
+		}
1948
+		$where  = [];
1949
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1950
+		// determine what post_status our condition will have for the query.
1951
+		switch ($status) {
1952
+			case 'month':
1953
+			case 'today':
1954
+			case null:
1955
+			case 'all':
1956
+				break;
1957
+			case 'draft':
1958
+				$where['status'] = ['IN', ['draft', 'auto-draft']];
1959
+				break;
1960
+			default:
1961
+				$where['status'] = $status;
1962
+		}
1963
+		// categories?
1964
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1965
+			? $this->_req_data['EVT_CAT'] : null;
1966
+		if (! empty($category)) {
1967
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1968
+			$where['Term_Taxonomy.term_id']  = $category;
1969
+		}
1970
+		// date where conditions
1971
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1972
+		if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') {
1973
+			$DateTime = new DateTime(
1974
+				$year_r . '-' . $month_r . '-01 00:00:00',
1975
+				new DateTimeZone('UTC')
1976
+			);
1977
+			$start    = $DateTime->getTimestamp();
1978
+			// set the datetime to be the end of the month
1979
+			$DateTime->setDate(
1980
+				$year_r,
1981
+				$month_r,
1982
+				$DateTime->format('t')
1983
+			)->setTime(23, 59, 59);
1984
+			$end                             = $DateTime->getTimestamp();
1985
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1986
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'today') {
1987
+			$DateTime                        =
1988
+				new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1989
+			$start                           = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1990
+			$end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1991
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1992
+		} elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'month') {
1993
+			$now                             = date('Y-m-01');
1994
+			$DateTime                        =
1995
+				new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1996
+			$start                           = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1997
+			$end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1998
+														->setTime(23, 59, 59)
1999
+														->format(implode(' ', $start_formats));
2000
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
2001
+		}
2002
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
2003
+			$where['EVT_wp_user'] = get_current_user_id();
2004
+		} elseif (
2005
+			! isset($where['status'])
2006
+			&& ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')
2007
+		) {
2008
+			$where['OR'] = [
2009
+				'status*restrict_private' => ['!=', 'private'],
2010
+				'AND'                     => [
2011
+					'status*inclusive' => ['=', 'private'],
2012
+					'EVT_wp_user'      => get_current_user_id(),
2013
+				],
2014
+			];
2015
+		}
2016
+
2017
+		if (
2018
+			isset($this->_req_data['EVT_wp_user'])
2019
+			&& (int) $this->_req_data['EVT_wp_user'] !== (int) get_current_user_id()
2020
+			&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
2021
+		) {
2022
+			$where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
2023
+		}
2024
+		// search query handling
2025
+		if (isset($this->_req_data['s'])) {
2026
+			$search_string = '%' . $this->_req_data['s'] . '%';
2027
+			$where['OR']   = [
2028
+				'EVT_name'       => ['LIKE', $search_string],
2029
+				'EVT_desc'       => ['LIKE', $search_string],
2030
+				'EVT_short_desc' => ['LIKE', $search_string],
2031
+			];
2032
+		}
2033
+		// filter events by venue.
2034
+		if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) {
2035
+			$where['Venue.VNU_ID'] = absint($this->_req_data['venue']);
2036
+		}
2037
+		$where        = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
2038
+		$query_params = apply_filters(
2039
+			'FHEE__Events_Admin_Page__get_events__query_params',
2040
+			[
2041
+				$where,
2042
+				'limit'    => $limit,
2043
+				'order_by' => $orderby,
2044
+				'order'    => $order,
2045
+				'group_by' => 'EVT_ID',
2046
+			],
2047
+			$this->_req_data
2048
+		);
2049
+
2050
+		// let's first check if we have special requests coming in.
2051
+		if (isset($this->_req_data['active_status'])) {
2052
+			switch ($this->_req_data['active_status']) {
2053
+				case 'upcoming':
2054
+					return $EEME->get_upcoming_events($query_params, $count);
2055
+				case 'expired':
2056
+					return $EEME->get_expired_events($query_params, $count);
2057
+				case 'active':
2058
+					return $EEME->get_active_events($query_params, $count);
2059
+				case 'inactive':
2060
+					return $EEME->get_inactive_events($query_params, $count);
2061
+			}
2062
+		}
2063
+
2064
+		return $count ? $EEME->count([$where], 'EVT_ID', true) : $EEME->get_all($query_params);
2065
+	}
2066
+
2067
+
2068
+	/**
2069
+	 * handling for WordPress CPT actions (trash, restore, delete)
2070
+	 *
2071
+	 * @param string $post_id
2072
+	 * @throws EE_Error
2073
+	 * @throws InvalidArgumentException
2074
+	 * @throws InvalidDataTypeException
2075
+	 * @throws InvalidInterfaceException
2076
+	 * @throws ReflectionException
2077
+	 */
2078
+	public function trash_cpt_item($post_id)
2079
+	{
2080
+		$this->_req_data['EVT_ID'] = $post_id;
2081
+		$this->_trash_or_restore_event('trash', false);
2082
+	}
2083
+
2084
+
2085
+	/**
2086
+	 * @param string $post_id
2087
+	 * @throws EE_Error
2088
+	 * @throws InvalidArgumentException
2089
+	 * @throws InvalidDataTypeException
2090
+	 * @throws InvalidInterfaceException
2091
+	 * @throws ReflectionException
2092
+	 */
2093
+	public function restore_cpt_item($post_id)
2094
+	{
2095
+		$this->_req_data['EVT_ID'] = $post_id;
2096
+		$this->_trash_or_restore_event('draft', false);
2097
+	}
2098
+
2099
+
2100
+	/**
2101
+	 * @param string $post_id
2102
+	 * @throws EE_Error
2103
+	 * @throws InvalidArgumentException
2104
+	 * @throws InvalidDataTypeException
2105
+	 * @throws InvalidInterfaceException
2106
+	 * @throws ReflectionException
2107
+	 */
2108
+	public function delete_cpt_item($post_id)
2109
+	{
2110
+		throw new EE_Error(
2111
+			esc_html__(
2112
+				'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2113
+				'event_espresso'
2114
+			)
2115
+		);
2116
+		$this->_req_data['EVT_ID'] = $post_id;
2117
+		$this->_delete_event();
2118
+	}
2119
+
2120
+
2121
+	/**
2122
+	 * _trash_or_restore_event
2123
+	 *
2124
+	 * @access protected
2125
+	 * @param string $event_status
2126
+	 * @param bool   $redirect_after
2127
+	 * @throws EE_Error
2128
+	 * @throws InvalidArgumentException
2129
+	 * @throws InvalidDataTypeException
2130
+	 * @throws InvalidInterfaceException
2131
+	 * @throws ReflectionException
2132
+	 */
2133
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2134
+	{
2135
+		// determine the event id and set to array.
2136
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
2137
+		// loop thru events
2138
+		if ($EVT_ID) {
2139
+			// clean status
2140
+			$event_status = sanitize_key($event_status);
2141
+			// grab status
2142
+			if (! empty($event_status)) {
2143
+				$success = $this->_change_event_status($EVT_ID, $event_status);
2144
+			} else {
2145
+				$success = false;
2146
+				$msg     = esc_html__(
2147
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2148
+					'event_espresso'
2149
+				);
2150
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2151
+			}
2152
+		} else {
2153
+			$success = false;
2154
+			$msg     = esc_html__(
2155
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2156
+				'event_espresso'
2157
+			);
2158
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2159
+		}
2160
+		$action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2161
+		if ($redirect_after) {
2162
+			$this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2163
+		}
2164
+	}
2165
+
2166
+
2167
+	/**
2168
+	 * _trash_or_restore_events
2169
+	 *
2170
+	 * @access protected
2171
+	 * @param string $event_status
2172
+	 * @return void
2173
+	 * @throws EE_Error
2174
+	 * @throws InvalidArgumentException
2175
+	 * @throws InvalidDataTypeException
2176
+	 * @throws InvalidInterfaceException
2177
+	 * @throws ReflectionException
2178
+	 */
2179
+	protected function _trash_or_restore_events($event_status = 'trash')
2180
+	{
2181
+		// clean status
2182
+		$event_status = sanitize_key($event_status);
2183
+		// grab status
2184
+		if (! empty($event_status)) {
2185
+			$success = true;
2186
+			// determine the event id and set to array.
2187
+			$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : [];
2188
+			// loop thru events
2189
+			foreach ($EVT_IDs as $EVT_ID) {
2190
+				if ($EVT_ID = absint($EVT_ID)) {
2191
+					$results = $this->_change_event_status($EVT_ID, $event_status);
2192
+					$success = $results !== false ? $success : false;
2193
+				} else {
2194
+					$msg = sprintf(
2195
+						esc_html__(
2196
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2197
+							'event_espresso'
2198
+						),
2199
+						$EVT_ID
2200
+					);
2201
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2202
+					$success = false;
2203
+				}
2204
+			}
2205
+		} else {
2206
+			$success = false;
2207
+			$msg     = esc_html__(
2208
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2209
+				'event_espresso'
2210
+			);
2211
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2212
+		}
2213
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2214
+		$success = $success ? 2 : false;
2215
+		$action  = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash';
2216
+		$this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2217
+	}
2218
+
2219
+
2220
+	/**
2221
+	 * _trash_or_restore_events
2222
+	 *
2223
+	 * @access  private
2224
+	 * @param int    $EVT_ID
2225
+	 * @param string $event_status
2226
+	 * @return bool
2227
+	 * @throws EE_Error
2228
+	 * @throws InvalidArgumentException
2229
+	 * @throws InvalidDataTypeException
2230
+	 * @throws InvalidInterfaceException
2231
+	 * @throws ReflectionException
2232
+	 */
2233
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2234
+	{
2235
+		// grab event id
2236
+		if (! $EVT_ID) {
2237
+			$msg = esc_html__(
2238
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2239
+				'event_espresso'
2240
+			);
2241
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2242
+			return false;
2243
+		}
2244
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2245
+		// clean status
2246
+		$event_status = sanitize_key($event_status);
2247
+		// grab status
2248
+		if (empty($event_status)) {
2249
+			$msg = esc_html__(
2250
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2251
+				'event_espresso'
2252
+			);
2253
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2254
+			return false;
2255
+		}
2256
+		// was event trashed or restored ?
2257
+		switch ($event_status) {
2258
+			case 'draft':
2259
+				$action = 'restored from the trash';
2260
+				$hook   = 'AHEE_event_restored_from_trash';
2261
+				break;
2262
+			case 'trash':
2263
+				$action = 'moved to the trash';
2264
+				$hook   = 'AHEE_event_moved_to_trash';
2265
+				break;
2266
+			default:
2267
+				$action = 'updated';
2268
+				$hook   = false;
2269
+		}
2270
+		// use class to change status
2271
+		$this->_cpt_model_obj->set_status($event_status);
2272
+		$success = $this->_cpt_model_obj->save();
2273
+		if ($success === false) {
2274
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2275
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2276
+			return false;
2277
+		}
2278
+		if ($hook) {
2279
+			do_action($hook);
2280
+		}
2281
+		return true;
2282
+	}
2283
+
2284
+
2285
+	/**
2286
+	 * _delete_event
2287
+	 *
2288
+	 * @throws InvalidArgumentException
2289
+	 * @throws InvalidDataTypeException
2290
+	 * @throws InvalidInterfaceException
2291
+	 */
2292
+	protected function _delete_event()
2293
+	{
2294
+		$this->generateDeletionPreview(isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : []);
2295
+	}
2296
+
2297
+
2298
+	/**
2299
+	 * Gets the tree traversal batch persister.
2300
+	 *
2301
+	 * @return NodeGroupDao
2302
+	 * @throws InvalidArgumentException
2303
+	 * @throws InvalidDataTypeException
2304
+	 * @throws InvalidInterfaceException
2305
+	 * @since 4.10.12.p
2306
+	 */
2307
+	protected function getModelObjNodeGroupPersister()
2308
+	{
2309
+		if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2310
+			$this->model_obj_node_group_persister =
2311
+				$this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2312
+		}
2313
+		return $this->model_obj_node_group_persister;
2314
+	}
2315
+
2316
+
2317
+	/**
2318
+	 * _delete_events
2319
+	 *
2320
+	 * @access protected
2321
+	 * @return void
2322
+	 * @throws InvalidArgumentException
2323
+	 * @throws InvalidDataTypeException
2324
+	 * @throws InvalidInterfaceException
2325
+	 */
2326
+	protected function _delete_events()
2327
+	{
2328
+		$this->generateDeletionPreview(isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : []);
2329
+	}
2330
+
2331
+
2332
+	protected function generateDeletionPreview($event_ids)
2333
+	{
2334
+		$event_ids = (array) $event_ids;
2335
+		// Set a code we can use to reference this deletion task in the batch jobs and preview page.
2336
+		$deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2337
+		$return_url        = EE_Admin_Page::add_query_args_and_nonce(
2338
+			[
2339
+				'action'            => 'preview_deletion',
2340
+				'deletion_job_code' => $deletion_job_code,
2341
+			],
2342
+			$this->_admin_base_url
2343
+		);
2344
+		$event_ids         = array_map(
2345
+			'intval',
2346
+			$event_ids
2347
+		);
2348
+
2349
+		EEH_URL::safeRedirectAndExit(
2350
+			EE_Admin_Page::add_query_args_and_nonce(
2351
+				[
2352
+					'page'              => 'espresso_batch',
2353
+					'batch'             => EED_Batch::batch_job,
2354
+					'EVT_IDs'           => $event_ids,
2355
+					'deletion_job_code' => $deletion_job_code,
2356
+					'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2357
+					'return_url'        => urlencode($return_url),
2358
+				],
2359
+				admin_url()
2360
+			)
2361
+		);
2362
+	}
2363
+
2364
+
2365
+	/**
2366
+	 * Checks for a POST submission
2367
+	 *
2368
+	 * @since 4.10.12.p
2369
+	 */
2370
+	protected function confirmDeletion()
2371
+	{
2372
+		$deletion_redirect_logic =
2373
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2374
+		$deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2375
+	}
2376
+
2377
+
2378
+	/**
2379
+	 * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2380
+	 *
2381
+	 * @throws EE_Error
2382
+	 * @since 4.10.12.p
2383
+	 */
2384
+	protected function previewDeletion()
2385
+	{
2386
+		$preview_deletion_logic =
2387
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2388
+		$this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2389
+		$this->display_admin_page_with_no_sidebar();
2390
+	}
2391
+
2392
+
2393
+	/**
2394
+	 * get total number of events
2395
+	 *
2396
+	 * @access public
2397
+	 * @return int
2398
+	 * @throws EE_Error
2399
+	 * @throws InvalidArgumentException
2400
+	 * @throws InvalidDataTypeException
2401
+	 * @throws InvalidInterfaceException
2402
+	 */
2403
+	public function total_events()
2404
+	{
2405
+		return EEM_Event::instance()->count(['caps' => 'read_admin'], 'EVT_ID', true);
2406
+	}
2407
+
2408
+
2409
+	/**
2410
+	 * get total number of draft events
2411
+	 *
2412
+	 * @access public
2413
+	 * @return int
2414
+	 * @throws EE_Error
2415
+	 * @throws InvalidArgumentException
2416
+	 * @throws InvalidDataTypeException
2417
+	 * @throws InvalidInterfaceException
2418
+	 */
2419
+	public function total_events_draft()
2420
+	{
2421
+		$where = [
2422
+			'status' => ['IN', ['draft', 'auto-draft']],
2423
+		];
2424
+		return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
2425
+	}
2426
+
2427
+
2428
+	/**
2429
+	 * get total number of trashed events
2430
+	 *
2431
+	 * @access public
2432
+	 * @return int
2433
+	 * @throws EE_Error
2434
+	 * @throws InvalidArgumentException
2435
+	 * @throws InvalidDataTypeException
2436
+	 * @throws InvalidInterfaceException
2437
+	 */
2438
+	public function total_trashed_events()
2439
+	{
2440
+		$where = [
2441
+			'status' => 'trash',
2442
+		];
2443
+		return EEM_Event::instance()->count([$where, 'caps' => 'read_admin'], 'EVT_ID', true);
2444
+	}
2445
+
2446
+
2447
+	/**
2448
+	 *    _default_event_settings
2449
+	 *    This generates the Default Settings Tab
2450
+	 *
2451
+	 * @return void
2452
+	 * @throws DomainException
2453
+	 * @throws EE_Error
2454
+	 * @throws InvalidArgumentException
2455
+	 * @throws InvalidDataTypeException
2456
+	 * @throws InvalidInterfaceException
2457
+	 */
2458
+	protected function _default_event_settings()
2459
+	{
2460
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2461
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2462
+		$this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2463
+		$this->display_admin_page_with_sidebar();
2464
+	}
2465
+
2466
+
2467
+	/**
2468
+	 * Return the form for event settings.
2469
+	 *
2470
+	 * @return EE_Form_Section_Proper
2471
+	 * @throws EE_Error
2472
+	 */
2473
+	protected function _default_event_settings_form()
2474
+	{
2475
+		$registration_config              = EE_Registry::instance()->CFG->registration;
2476
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2477
+		// exclude
2478
+			[
2479
+				EEM_Registration::status_id_cancelled,
2480
+				EEM_Registration::status_id_declined,
2481
+				EEM_Registration::status_id_incomplete,
2482
+				EEM_Registration::status_id_wait_list,
2483
+			],
2484
+			true
2485
+		);
2486
+		return new EE_Form_Section_Proper(
2487
+			[
2488
+				'name'            => 'update_default_event_settings',
2489
+				'html_id'         => 'update_default_event_settings',
2490
+				'html_class'      => 'form-table',
2491
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2492
+				'subsections'     => apply_filters(
2493
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2494
+					[
2495
+						'default_reg_status'  => new EE_Select_Input(
2496
+							$registration_stati_for_selection,
2497
+							[
2498
+								'default'         => isset($registration_config->default_STS_ID)
2499
+													 && array_key_exists(
2500
+														 $registration_config->default_STS_ID,
2501
+														 $registration_stati_for_selection
2502
+													 )
2503
+									? sanitize_text_field($registration_config->default_STS_ID)
2504
+									: EEM_Registration::status_id_pending_payment,
2505
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2506
+														. EEH_Template::get_help_tab_link(
2507
+															'default_settings_status_help_tab'
2508
+														),
2509
+								'html_help_text'  => esc_html__(
2510
+									'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2511
+									'event_espresso'
2512
+								),
2513
+							]
2514
+						),
2515
+						'default_max_tickets' => new EE_Integer_Input(
2516
+							[
2517
+								'default'         => isset($registration_config->default_maximum_number_of_tickets)
2518
+									? $registration_config->default_maximum_number_of_tickets
2519
+									: EEM_Event::get_default_additional_limit(),
2520
+								'html_label_text' => esc_html__(
2521
+									'Default Maximum Tickets Allowed Per Order:',
2522
+									'event_espresso'
2523
+								)
2524
+								. EEH_Template::get_help_tab_link(
2525
+									'default_maximum_tickets_help_tab"'
2526
+								),
2527
+								'html_help_text'  => esc_html__(
2528
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2529
+									'event_espresso'
2530
+								),
2531
+							]
2532
+						),
2533
+					]
2534
+				),
2535
+			]
2536
+		);
2537
+	}
2538
+
2539
+
2540
+	/**
2541
+	 * @return void
2542
+	 * @throws EE_Error
2543
+	 * @throws InvalidArgumentException
2544
+	 * @throws InvalidDataTypeException
2545
+	 * @throws InvalidInterfaceException
2546
+	 */
2547
+	protected function _update_default_event_settings()
2548
+	{
2549
+		$form = $this->_default_event_settings_form();
2550
+		if ($form->was_submitted()) {
2551
+			$form->receive_form_submission();
2552
+			if ($form->is_valid()) {
2553
+				$registration_config = EE_Registry::instance()->CFG->registration;
2554
+				$valid_data          = $form->valid_data();
2555
+				if (isset($valid_data['default_reg_status'])) {
2556
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2557
+				}
2558
+				if (isset($valid_data['default_max_tickets'])) {
2559
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2560
+				}
2561
+				do_action(
2562
+					'AHEE__Events_Admin_Page___update_default_event_settings',
2563
+					$valid_data,
2564
+					EE_Registry::instance()->CFG,
2565
+					$this
2566
+				);
2567
+				// update because data was valid!
2568
+				EE_Registry::instance()->CFG->update_espresso_config();
2569
+				EE_Error::overwrite_success();
2570
+				EE_Error::add_success(
2571
+					__('Default Event Settings were updated', 'event_espresso')
2572
+				);
2573
+			}
2574
+		}
2575
+		$this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2576
+	}
2577
+
2578
+
2579
+	/*************        Templates        *************/
2580
+	protected function _template_settings()
2581
+	{
2582
+		$this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2583
+		$this->_template_args['preview_img']  = '<img src="'
2584
+												. EVENTS_ASSETS_URL
2585
+												. '/images/'
2586
+												. 'caffeinated_template_features.jpg" alt="'
2587
+												. esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2588
+												. '" />';
2589
+		$this->_template_args['preview_text'] = '<strong>'
2590
+												. esc_html__(
2591
+													'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2592
+													'event_espresso'
2593
+												) . '</strong>';
2594
+		$this->display_admin_caf_preview_page('template_settings_tab');
2595
+	}
2596
+
2597
+
2598
+	/** Event Category Stuff **/
2599
+	/**
2600
+	 * set the _category property with the category object for the loaded page.
2601
+	 *
2602
+	 * @access private
2603
+	 * @return void
2604
+	 */
2605
+	private function _set_category_object()
2606
+	{
2607
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2608
+			return;
2609
+		} //already have the category object so get out.
2610
+		// set default category object
2611
+		$this->_set_empty_category_object();
2612
+		// only set if we've got an id
2613
+		if (! isset($this->_req_data['EVT_CAT_ID'])) {
2614
+			return;
2615
+		}
2616
+		$category_id = absint($this->_req_data['EVT_CAT_ID']);
2617
+		$term        = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2618
+		if (! empty($term)) {
2619
+			$this->_category->category_name       = $term->name;
2620
+			$this->_category->category_identifier = $term->slug;
2621
+			$this->_category->category_desc       = $term->description;
2622
+			$this->_category->id                  = $term->term_id;
2623
+			$this->_category->parent              = $term->parent;
2624
+		}
2625
+	}
2626
+
2627
+
2628
+	/**
2629
+	 * Clears out category properties.
2630
+	 */
2631
+	private function _set_empty_category_object()
2632
+	{
2633
+		$this->_category                = new stdClass();
2634
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2635
+		$this->_category->id            = $this->_category->parent = 0;
2636
+	}
2637
+
2638
+
2639
+	/**
2640
+	 * @throws DomainException
2641
+	 * @throws EE_Error
2642
+	 * @throws InvalidArgumentException
2643
+	 * @throws InvalidDataTypeException
2644
+	 * @throws InvalidInterfaceException
2645
+	 */
2646
+	protected function _category_list_table()
2647
+	{
2648
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2649
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2650
+		$this->_admin_page_title .= ' ';
2651
+		$this->_admin_page_title .= $this->get_action_link_or_button(
2652
+			'add_category',
2653
+			'add_category',
2654
+			[],
2655
+			'add-new-h2'
2656
+		);
2657
+		$this->display_admin_list_table_page_with_sidebar();
2658
+	}
2659
+
2660
+
2661
+	/**
2662
+	 * Output category details view.
2663
+	 *
2664
+	 * @param string $view
2665
+	 * @throws DomainException
2666
+	 * @throws EE_Error
2667
+	 * @throws InvalidArgumentException
2668
+	 * @throws InvalidDataTypeException
2669
+	 * @throws InvalidInterfaceException
2670
+	 */
2671
+	protected function _category_details($view)
2672
+	{
2673
+		// load formatter helper
2674
+		// load field generator helper
2675
+		$route = $view === 'edit' ? 'update_category' : 'insert_category';
2676
+		$this->_set_add_edit_form_tags($route);
2677
+		$this->_set_category_object();
2678
+		$id            = ! empty($this->_category->id) ? $this->_category->id : '';
2679
+		$delete_action = 'delete_category';
2680
+		// custom redirect
2681
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2682
+			['action' => 'category_list'],
2683
+			$this->_admin_base_url
2684
+		);
2685
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2686
+		// take care of contents
2687
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2688
+		$this->display_admin_page_with_sidebar();
2689
+	}
2690
+
2691
+
2692
+	/**
2693
+	 * Output category details content.
2694
+	 *
2695
+	 * @throws DomainException
2696
+	 */
2697
+	protected function _category_details_content()
2698
+	{
2699
+		$editor_args['category_desc'] = [
2700
+			'type'          => 'wp_editor',
2701
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2702
+			'class'         => 'my_editor_custom',
2703
+			'wpeditor_args' => ['media_buttons' => false],
2704
+		];
2705
+		$_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2706
+		$all_terms                    = get_terms(
2707
+			[EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2708
+			['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2709
+		);
2710
+		// setup category select for term parents.
2711
+		$category_select_values[] = [
2712
+			'text' => esc_html__('No Parent', 'event_espresso'),
2713
+			'id'   => 0,
2714
+		];
2715
+		foreach ($all_terms as $term) {
2716
+			$category_select_values[] = [
2717
+				'text' => $term->name,
2718
+				'id'   => $term->term_id,
2719
+			];
2720
+		}
2721
+		$category_select = EEH_Form_Fields::select_input(
2722
+			'category_parent',
2723
+			$category_select_values,
2724
+			$this->_category->parent
2725
+		);
2726
+		$template_args   = [
2727
+			'category'                 => $this->_category,
2728
+			'category_select'          => $category_select,
2729
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2730
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2731
+			'disable'                  => '',
2732
+			'disabled_message'         => false,
2733
+		];
2734
+		$template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2735
+		return EEH_Template::display_template($template, $template_args, true);
2736
+	}
2737
+
2738
+
2739
+	/**
2740
+	 * Handles deleting categories.
2741
+	 */
2742
+	protected function _delete_categories()
2743
+	{
2744
+		$cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID']
2745
+			: (array) $this->_req_data['category_id'];
2746
+		foreach ($cat_ids as $cat_id) {
2747
+			$this->_delete_category($cat_id);
2748
+		}
2749
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2750
+		$query_args = [
2751
+			'action' => 'category_list',
2752
+		];
2753
+		$this->_redirect_after_action(0, '', '', $query_args);
2754
+	}
2755
+
2756
+
2757
+	/**
2758
+	 * Handles deleting specific category.
2759
+	 *
2760
+	 * @param int $cat_id
2761
+	 */
2762
+	protected function _delete_category($cat_id)
2763
+	{
2764
+		$cat_id = absint($cat_id);
2765
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2766
+	}
2767
+
2768
+
2769
+	/**
2770
+	 * Handles triggering the update or insertion of a new category.
2771
+	 *
2772
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2773
+	 * @throws EE_Error
2774
+	 * @throws InvalidArgumentException
2775
+	 * @throws InvalidDataTypeException
2776
+	 * @throws InvalidInterfaceException
2777
+	 */
2778
+	protected function _insert_or_update_category($new_category)
2779
+	{
2780
+		$cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2781
+		$success = 0; // we already have a success message so lets not send another.
2782
+		if ($cat_id) {
2783
+			$query_args = [
2784
+				'action'     => 'edit_category',
2785
+				'EVT_CAT_ID' => $cat_id,
2786
+			];
2787
+		} else {
2788
+			$query_args = ['action' => 'add_category'];
2789
+		}
2790
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2791
+	}
2792
+
2793
+
2794
+	/**
2795
+	 * Inserts or updates category
2796
+	 *
2797
+	 * @param bool $update (true indicates we're updating a category).
2798
+	 * @return bool|mixed|string
2799
+	 */
2800
+	private function _insert_category($update = false)
2801
+	{
2802
+		$cat_id          = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2803
+		$category_name   = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2804
+		$category_desc   = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2805
+		$category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2806
+		if (empty($category_name)) {
2807
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2808
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2809
+			return false;
2810
+		}
2811
+		$term_args = [
2812
+			'name'        => $category_name,
2813
+			'description' => $category_desc,
2814
+			'parent'      => $category_parent,
2815
+		];
2816
+		// was the category_identifier input disabled?
2817
+		if (isset($this->_req_data['category_identifier'])) {
2818
+			$term_args['slug'] = $this->_req_data['category_identifier'];
2819
+		}
2820
+		$insert_ids = $update
2821
+			? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2822
+			: wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2823
+		if (! is_array($insert_ids)) {
2824
+			$msg = esc_html__(
2825
+				'An error occurred and the category has not been saved to the database.',
2826
+				'event_espresso'
2827
+			);
2828
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2829
+		} else {
2830
+			$cat_id = $insert_ids['term_id'];
2831
+			$msg    = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2832
+			EE_Error::add_success($msg);
2833
+		}
2834
+		return $cat_id;
2835
+	}
2836
+
2837
+
2838
+	/**
2839
+	 * Gets categories or count of categories matching the arguments in the request.
2840
+	 *
2841
+	 * @param int  $per_page
2842
+	 * @param int  $current_page
2843
+	 * @param bool $count
2844
+	 * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int
2845
+	 * @throws EE_Error
2846
+	 * @throws InvalidArgumentException
2847
+	 * @throws InvalidDataTypeException
2848
+	 * @throws InvalidInterfaceException
2849
+	 */
2850
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2851
+	{
2852
+		// testing term stuff
2853
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2854
+		$order   = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2855
+		$limit   = ($current_page - 1) * $per_page;
2856
+		$where   = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2857
+		if (isset($this->_req_data['s'])) {
2858
+			$sstr        = '%' . $this->_req_data['s'] . '%';
2859
+			$where['OR'] = [
2860
+				'Term.name'   => ['LIKE', $sstr],
2861
+				'description' => ['LIKE', $sstr],
2862
+			];
2863
+		}
2864
+		$query_params = [
2865
+			$where,
2866
+			'order_by'   => [$orderby => $order],
2867
+			'limit'      => $limit . ',' . $per_page,
2868
+			'force_join' => ['Term'],
2869
+		];
2870
+		return $count
2871
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2872
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2873
+	}
2874
+
2875
+	/* end category stuff */
2876
+	/**************/
2877
+
2878
+
2879
+	/**
2880
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2881
+	 *
2882
+	 * @throws EE_Error
2883
+	 * @throws InvalidArgumentException
2884
+	 * @throws InvalidDataTypeException
2885
+	 * @throws InvalidInterfaceException
2886
+	 */
2887
+	public function save_timezonestring_setting()
2888
+	{
2889
+		$timezone_string = isset($this->_req_data['timezone_selected'])
2890
+			? $this->_req_data['timezone_selected']
2891
+			: '';
2892
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2893
+			EE_Error::add_error(
2894
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2895
+				__FILE__,
2896
+				__FUNCTION__,
2897
+				__LINE__
2898
+			);
2899
+			$this->_template_args['error'] = true;
2900
+			$this->_return_json();
2901
+		}
2902
+
2903
+		update_option('timezone_string', $timezone_string);
2904
+		EE_Error::add_success(
2905
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2906
+		);
2907
+		$this->_template_args['success'] = true;
2908
+		$this->_return_json(true, ['action' => 'create_new']);
2909
+	}
2910 2910
 }
Please login to merge, or discard this patch.
admin_pages/messages/Messages_Admin_Page.core.php 1 patch
Indentation   +4555 added lines, -4555 removed lines patch added patch discarded remove patch
@@ -19,2650 +19,2650 @@  discard block
 block discarded – undo
19 19
 class Messages_Admin_Page extends EE_Admin_Page
20 20
 {
21 21
 
22
-    /**
23
-     * @type EE_Message_Resource_Manager $_message_resource_manager
24
-     */
25
-    protected $_message_resource_manager;
26
-
27
-    /**
28
-     * @type string $_active_message_type_name
29
-     */
30
-    protected $_active_message_type_name = '';
31
-
32
-    /**
33
-     * @type EE_messenger $_active_messenger
34
-     */
35
-    protected $_active_messenger;
36
-    protected $_activate_state;
37
-    protected $_activate_meta_box_type;
38
-    protected $_current_message_meta_box;
39
-    protected $_current_message_meta_box_object;
40
-    protected $_context_switcher;
41
-    protected $_shortcodes = array();
42
-    protected $_active_messengers = array();
43
-    protected $_active_message_types = array();
44
-
45
-    /**
46
-     * @var EE_Message_Template_Group $_message_template_group
47
-     */
48
-    protected $_message_template_group;
49
-    protected $_m_mt_settings = array();
50
-
51
-
52
-    /**
53
-     * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
54
-     * IF there is no group then it gets automatically set to the Default template pack.
55
-     *
56
-     * @since 4.5.0
57
-     *
58
-     * @var EE_Messages_Template_Pack
59
-     */
60
-    protected $_template_pack;
61
-
62
-
63
-    /**
64
-     * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
65
-     * group is.  If there is no group then it automatically gets set to default.
66
-     *
67
-     * @since 4.5.0
68
-     *
69
-     * @var string
70
-     */
71
-    protected $_variation;
72
-
73
-
74
-    /**
75
-     * @param bool $routing
76
-     * @throws EE_Error
77
-     */
78
-    public function __construct($routing = true)
79
-    {
80
-        // make sure messages autoloader is running
81
-        EED_Messages::set_autoloaders();
82
-        parent::__construct($routing);
83
-    }
84
-
85
-
86
-    protected function _init_page_props()
87
-    {
88
-        $this->page_slug = EE_MSG_PG_SLUG;
89
-        $this->page_label = esc_html__('Messages Settings', 'event_espresso');
90
-        $this->_admin_base_url = EE_MSG_ADMIN_URL;
91
-        $this->_admin_base_path = EE_MSG_ADMIN;
92
-
93
-        $this->_activate_state = isset($this->_req_data['activate_state']) ? (array) $this->_req_data['activate_state']
94
-            : array();
95
-
96
-        $this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
97
-        $this->_load_message_resource_manager();
98
-    }
99
-
100
-
101
-    /**
102
-     * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
103
-     *
104
-     * @throws EE_Error
105
-     * @throws InvalidDataTypeException
106
-     * @throws InvalidInterfaceException
107
-     * @throws InvalidArgumentException
108
-     * @throws ReflectionException
109
-     */
110
-    protected function _load_message_resource_manager()
111
-    {
112
-        $this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
113
-    }
114
-
115
-
116
-    /**
117
-     * @deprecated 4.9.9.rc.014
118
-     * @return array
119
-     * @throws EE_Error
120
-     * @throws InvalidArgumentException
121
-     * @throws InvalidDataTypeException
122
-     * @throws InvalidInterfaceException
123
-     */
124
-    public function get_messengers_for_list_table()
125
-    {
126
-        EE_Error::doing_it_wrong(
127
-            __METHOD__,
128
-            sprintf(
129
-                esc_html__(
130
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
131
-                    'event_espresso'
132
-                ),
133
-                'Messages_Admin_Page::get_messengers_select_input()'
134
-            ),
135
-            '4.9.9.rc.014'
136
-        );
137
-
138
-        $m_values = array();
139
-        $active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
140
-        // setup messengers for selects
141
-        $i = 1;
142
-        foreach ($active_messengers as $active_messenger) {
143
-            if ($active_messenger instanceof EE_Message) {
144
-                $m_values[ $i ]['id'] = $active_messenger->messenger();
145
-                $m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
146
-                $i++;
147
-            }
148
-        }
149
-
150
-        return $m_values;
151
-    }
152
-
153
-
154
-    /**
155
-     * @deprecated 4.9.9.rc.014
156
-     * @return array
157
-     * @throws EE_Error
158
-     * @throws InvalidArgumentException
159
-     * @throws InvalidDataTypeException
160
-     * @throws InvalidInterfaceException
161
-     */
162
-    public function get_message_types_for_list_table()
163
-    {
164
-        EE_Error::doing_it_wrong(
165
-            __METHOD__,
166
-            sprintf(
167
-                esc_html__(
168
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
169
-                    'event_espresso'
170
-                ),
171
-                'Messages_Admin_Page::get_message_types_select_input()'
172
-            ),
173
-            '4.9.9.rc.014'
174
-        );
175
-
176
-        $mt_values = array();
177
-        $active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
178
-        $i = 1;
179
-        foreach ($active_messages as $active_message) {
180
-            if ($active_message instanceof EE_Message) {
181
-                $mt_values[ $i ]['id'] = $active_message->message_type();
182
-                $mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
183
-                $i++;
184
-            }
185
-        }
186
-
187
-        return $mt_values;
188
-    }
189
-
190
-
191
-    /**
192
-     * @deprecated 4.9.9.rc.014
193
-     * @return array
194
-     * @throws EE_Error
195
-     * @throws InvalidArgumentException
196
-     * @throws InvalidDataTypeException
197
-     * @throws InvalidInterfaceException
198
-     */
199
-    public function get_contexts_for_message_types_for_list_table()
200
-    {
201
-        EE_Error::doing_it_wrong(
202
-            __METHOD__,
203
-            sprintf(
204
-                esc_html__(
205
-                    'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
206
-                    'event_espresso'
207
-                ),
208
-                'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
209
-            ),
210
-            '4.9.9.rc.014'
211
-        );
212
-
213
-        $contexts = array();
214
-        $active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
215
-        foreach ($active_message_contexts as $active_message) {
216
-            if ($active_message instanceof EE_Message) {
217
-                $message_type = $active_message->message_type_object();
218
-                if ($message_type instanceof EE_message_type) {
219
-                    $message_type_contexts = $message_type->get_contexts();
220
-                    foreach ($message_type_contexts as $context => $context_details) {
221
-                        $contexts[ $context ] = $context_details['label'];
222
-                    }
223
-                }
224
-            }
225
-        }
226
-
227
-        return $contexts;
228
-    }
229
-
230
-
231
-    /**
232
-     * Generate select input with provided messenger options array.
233
-     *
234
-     * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
235
-     *                                 labels.
236
-     * @return string
237
-     * @throws EE_Error
238
-     */
239
-    public function get_messengers_select_input($messenger_options)
240
-    {
241
-        // if empty or just one value then just return an empty string
242
-        if (
243
-            empty($messenger_options)
244
-            || ! is_array($messenger_options)
245
-            || count($messenger_options) === 1
246
-        ) {
247
-            return '';
248
-        }
249
-        // merge in default
250
-        $messenger_options = array_merge(
251
-            array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')),
252
-            $messenger_options
253
-        );
254
-        $input = new EE_Select_Input(
255
-            $messenger_options,
256
-            array(
257
-                'html_name'  => 'ee_messenger_filter_by',
258
-                'html_id'    => 'ee_messenger_filter_by',
259
-                'html_class' => 'wide',
260
-                'default'    => isset($this->_req_data['ee_messenger_filter_by'])
261
-                    ? sanitize_title($this->_req_data['ee_messenger_filter_by'])
262
-                    : 'none_selected',
263
-            )
264
-        );
265
-
266
-        return $input->get_html_for_input();
267
-    }
268
-
269
-
270
-    /**
271
-     * Generate select input with provided message type options array.
272
-     *
273
-     * @param array $message_type_options Array of message types indexed by message type slug, and values are the
274
-     *                                    message type labels
275
-     * @return string
276
-     * @throws EE_Error
277
-     */
278
-    public function get_message_types_select_input($message_type_options)
279
-    {
280
-        // if empty or count of options is 1 then just return an empty string
281
-        if (
282
-            empty($message_type_options)
283
-            || ! is_array($message_type_options)
284
-            || count($message_type_options) === 1
285
-        ) {
286
-            return '';
287
-        }
288
-        // merge in default
289
-        $message_type_options = array_merge(
290
-            array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')),
291
-            $message_type_options
292
-        );
293
-        $input = new EE_Select_Input(
294
-            $message_type_options,
295
-            array(
296
-                'html_name'  => 'ee_message_type_filter_by',
297
-                'html_id'    => 'ee_message_type_filter_by',
298
-                'html_class' => 'wide',
299
-                'default'    => isset($this->_req_data['ee_message_type_filter_by'])
300
-                    ? sanitize_title($this->_req_data['ee_message_type_filter_by'])
301
-                    : 'none_selected',
302
-            )
303
-        );
304
-
305
-        return $input->get_html_for_input();
306
-    }
307
-
308
-
309
-    /**
310
-     * Generate select input with provide message type contexts array.
311
-     *
312
-     * @param array $context_options Array of message type contexts indexed by context slug, and values are the
313
-     *                               context label.
314
-     * @return string
315
-     * @throws EE_Error
316
-     */
317
-    public function get_contexts_for_message_types_select_input($context_options)
318
-    {
319
-        // if empty or count of options is one then just return empty string
320
-        if (
321
-            empty($context_options)
322
-            || ! is_array($context_options)
323
-            || count($context_options) === 1
324
-        ) {
325
-            return '';
326
-        }
327
-        // merge in default
328
-        $context_options = array_merge(
329
-            array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')),
330
-            $context_options
331
-        );
332
-        $input = new EE_Select_Input(
333
-            $context_options,
334
-            array(
335
-                'html_name'  => 'ee_context_filter_by',
336
-                'html_id'    => 'ee_context_filter_by',
337
-                'html_class' => 'wide',
338
-                'default'    => isset($this->_req_data['ee_context_filter_by'])
339
-                    ? sanitize_title($this->_req_data['ee_context_filter_by'])
340
-                    : 'none_selected',
341
-            )
342
-        );
343
-
344
-        return $input->get_html_for_input();
345
-    }
346
-
347
-
348
-    protected function _ajax_hooks()
349
-    {
350
-        add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
351
-        add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
352
-        add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
353
-        add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
354
-        add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
355
-        add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template'));
356
-    }
357
-
358
-
359
-    protected function _define_page_props()
360
-    {
361
-        $this->_admin_page_title = $this->page_label;
362
-        $this->_labels = array(
363
-            'buttons'    => array(
364
-                'add'    => esc_html__('Add New Message Template', 'event_espresso'),
365
-                'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
366
-                'delete' => esc_html__('Delete Message Template', 'event_espresso'),
367
-            ),
368
-            'publishbox' => esc_html__('Update Actions', 'event_espresso'),
369
-        );
370
-    }
371
-
372
-
373
-    /**
374
-     *        an array for storing key => value pairs of request actions and their corresponding methods
375
-     *
376
-     * @access protected
377
-     * @return void
378
-     */
379
-    protected function _set_page_routes()
380
-    {
381
-        $grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
382
-            ? $this->_req_data['GRP_ID']
383
-            : 0;
384
-        $grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
385
-            ? $this->_req_data['id']
386
-            : $grp_id;
387
-        $msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
388
-            ? $this->_req_data['MSG_ID']
389
-            : 0;
390
-
391
-        $this->_page_routes = array(
392
-            'default'                          => array(
393
-                'func'       => '_message_queue_list_table',
394
-                'capability' => 'ee_read_global_messages',
395
-            ),
396
-            'global_mtps'                      => array(
397
-                'func'       => '_ee_default_messages_overview_list_table',
398
-                'capability' => 'ee_read_global_messages',
399
-            ),
400
-            'custom_mtps'                      => array(
401
-                'func'       => '_custom_mtps_preview',
402
-                'capability' => 'ee_read_messages',
403
-            ),
404
-            'add_new_message_template'         => array(
405
-                'func'       => '_add_message_template',
406
-                'capability' => 'ee_edit_messages',
407
-                'noheader'   => true,
408
-            ),
409
-            'edit_message_template'            => array(
410
-                'func'       => '_edit_message_template',
411
-                'capability' => 'ee_edit_message',
412
-                'obj_id'     => $grp_id,
413
-            ),
414
-            'preview_message'                  => array(
415
-                'func'               => '_preview_message',
416
-                'capability'         => 'ee_read_message',
417
-                'obj_id'             => $grp_id,
418
-                'noheader'           => true,
419
-                'headers_sent_route' => 'display_preview_message',
420
-            ),
421
-            'display_preview_message'          => array(
422
-                'func'       => '_display_preview_message',
423
-                'capability' => 'ee_read_message',
424
-                'obj_id'     => $grp_id,
425
-            ),
426
-            'insert_message_template'          => array(
427
-                'func'       => '_insert_or_update_message_template',
428
-                'capability' => 'ee_edit_messages',
429
-                'args'       => array('new_template' => true),
430
-                'noheader'   => true,
431
-            ),
432
-            'update_message_template'          => array(
433
-                'func'       => '_insert_or_update_message_template',
434
-                'capability' => 'ee_edit_message',
435
-                'obj_id'     => $grp_id,
436
-                'args'       => array('new_template' => false),
437
-                'noheader'   => true,
438
-            ),
439
-            'trash_message_template'           => array(
440
-                'func'       => '_trash_or_restore_message_template',
441
-                'capability' => 'ee_delete_message',
442
-                'obj_id'     => $grp_id,
443
-                'args'       => array('trash' => true, 'all' => true),
444
-                'noheader'   => true,
445
-            ),
446
-            'trash_message_template_context'   => array(
447
-                'func'       => '_trash_or_restore_message_template',
448
-                'capability' => 'ee_delete_message',
449
-                'obj_id'     => $grp_id,
450
-                'args'       => array('trash' => true),
451
-                'noheader'   => true,
452
-            ),
453
-            'restore_message_template'         => array(
454
-                'func'       => '_trash_or_restore_message_template',
455
-                'capability' => 'ee_delete_message',
456
-                'obj_id'     => $grp_id,
457
-                'args'       => array('trash' => false, 'all' => true),
458
-                'noheader'   => true,
459
-            ),
460
-            'restore_message_template_context' => array(
461
-                'func'       => '_trash_or_restore_message_template',
462
-                'capability' => 'ee_delete_message',
463
-                'obj_id'     => $grp_id,
464
-                'args'       => array('trash' => false),
465
-                'noheader'   => true,
466
-            ),
467
-            'delete_message_template'          => array(
468
-                'func'       => '_delete_message_template',
469
-                'capability' => 'ee_delete_message',
470
-                'obj_id'     => $grp_id,
471
-                'noheader'   => true,
472
-            ),
473
-            'reset_to_default'                 => array(
474
-                'func'       => '_reset_to_default_template',
475
-                'capability' => 'ee_edit_message',
476
-                'obj_id'     => $grp_id,
477
-                'noheader'   => true,
478
-            ),
479
-            'settings'                         => array(
480
-                'func'       => '_settings',
481
-                'capability' => 'manage_options',
482
-            ),
483
-            'update_global_settings'           => array(
484
-                'func'       => '_update_global_settings',
485
-                'capability' => 'manage_options',
486
-                'noheader'   => true,
487
-            ),
488
-            'generate_now'                     => array(
489
-                'func'       => '_generate_now',
490
-                'capability' => 'ee_send_message',
491
-                'noheader'   => true,
492
-            ),
493
-            'generate_and_send_now'            => array(
494
-                'func'       => '_generate_and_send_now',
495
-                'capability' => 'ee_send_message',
496
-                'noheader'   => true,
497
-            ),
498
-            'queue_for_resending'              => array(
499
-                'func'       => '_queue_for_resending',
500
-                'capability' => 'ee_send_message',
501
-                'noheader'   => true,
502
-            ),
503
-            'send_now'                         => array(
504
-                'func'       => '_send_now',
505
-                'capability' => 'ee_send_message',
506
-                'noheader'   => true,
507
-            ),
508
-            'delete_ee_message'                => array(
509
-                'func'       => '_delete_ee_messages',
510
-                'capability' => 'ee_delete_messages',
511
-                'noheader'   => true,
512
-            ),
513
-            'delete_ee_messages'               => array(
514
-                'func'       => '_delete_ee_messages',
515
-                'capability' => 'ee_delete_messages',
516
-                'noheader'   => true,
517
-                'obj_id'     => $msg_id,
518
-            ),
519
-        );
520
-    }
521
-
522
-
523
-    protected function _set_page_config()
524
-    {
525
-        $this->_page_config = array(
526
-            'default'                  => array(
527
-                'nav'           => array(
528
-                    'label' => esc_html__('Message Activity', 'event_espresso'),
529
-                    'order' => 10,
530
-                ),
531
-                'list_table'    => 'EE_Message_List_Table',
532
-                // 'qtips' => array( 'EE_Message_List_Table_Tips' ),
533
-                'require_nonce' => false,
534
-            ),
535
-            'global_mtps'              => array(
536
-                'nav'           => array(
537
-                    'label' => esc_html__('Default Message Templates', 'event_espresso'),
538
-                    'order' => 20,
539
-                ),
540
-                'list_table'    => 'Messages_Template_List_Table',
541
-                'help_tabs'     => array(
542
-                    'messages_overview_help_tab'                                => array(
543
-                        'title'    => esc_html__('Messages Overview', 'event_espresso'),
544
-                        'filename' => 'messages_overview',
545
-                    ),
546
-                    'messages_overview_messages_table_column_headings_help_tab' => array(
547
-                        'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
548
-                        'filename' => 'messages_overview_table_column_headings',
549
-                    ),
550
-                    'messages_overview_messages_filters_help_tab'               => array(
551
-                        'title'    => esc_html__('Message Filters', 'event_espresso'),
552
-                        'filename' => 'messages_overview_filters',
553
-                    ),
554
-                    'messages_overview_messages_views_help_tab'                 => array(
555
-                        'title'    => esc_html__('Message Views', 'event_espresso'),
556
-                        'filename' => 'messages_overview_views',
557
-                    ),
558
-                    'message_overview_message_types_help_tab'                   => array(
559
-                        'title'    => esc_html__('Message Types', 'event_espresso'),
560
-                        'filename' => 'messages_overview_types',
561
-                    ),
562
-                    'messages_overview_messengers_help_tab'                     => array(
563
-                        'title'    => esc_html__('Messengers', 'event_espresso'),
564
-                        'filename' => 'messages_overview_messengers',
565
-                    ),
566
-                ),
567
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
568
-                // 'help_tour'     => array('Messages_Overview_Help_Tour'),
569
-                'require_nonce' => false,
570
-            ),
571
-            'custom_mtps'              => array(
572
-                'nav'           => array(
573
-                    'label' => esc_html__('Custom Message Templates', 'event_espresso'),
574
-                    'order' => 30,
575
-                ),
576
-                'help_tabs'     => array(),
577
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
578
-                // 'help_tour'     => array(),
579
-                'require_nonce' => false,
580
-            ),
581
-            'add_new_message_template' => array(
582
-                'nav'           => array(
583
-                    'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
584
-                    'order'      => 5,
585
-                    'persistent' => false,
586
-                ),
587
-                'require_nonce' => false,
588
-            ),
589
-            'edit_message_template'    => array(
590
-                'labels'        => array(
591
-                    'buttons'    => array(
592
-                        'reset' => esc_html__('Reset Templates', 'event_espresso'),
593
-                    ),
594
-                    'publishbox' => esc_html__('Update Actions', 'event_espresso'),
595
-                ),
596
-                'nav'           => array(
597
-                    'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
598
-                    'order'      => 5,
599
-                    'persistent' => false,
600
-                    'url'        => '',
601
-                ),
602
-                'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
603
-                'has_metaboxes' => true,
604
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
605
-                // 'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
606
-                'help_tabs'     => array(
607
-                    'edit_message_template'            => array(
608
-                        'title'    => esc_html__('Message Template Editor', 'event_espresso'),
609
-                        'callback' => 'edit_message_template_help_tab',
610
-                    ),
611
-                    'message_templates_help_tab'       => array(
612
-                        'title'    => esc_html__('Message Templates', 'event_espresso'),
613
-                        'filename' => 'messages_templates',
614
-                    ),
615
-                    'message_template_shortcodes'      => array(
616
-                        'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
617
-                        'callback' => 'message_template_shortcodes_help_tab',
618
-                    ),
619
-                    'message_preview_help_tab'         => array(
620
-                        'title'    => esc_html__('Message Preview', 'event_espresso'),
621
-                        'filename' => 'messages_preview',
622
-                    ),
623
-                    'messages_overview_other_help_tab' => array(
624
-                        'title'    => esc_html__('Messages Other', 'event_espresso'),
625
-                        'filename' => 'messages_overview_other',
626
-                    ),
627
-                ),
628
-                'require_nonce' => false,
629
-            ),
630
-            'display_preview_message'  => array(
631
-                'nav'           => array(
632
-                    'label'      => esc_html__('Message Preview', 'event_espresso'),
633
-                    'order'      => 5,
634
-                    'url'        => '',
635
-                    'persistent' => false,
636
-                ),
637
-                'help_tabs'     => array(
638
-                    'preview_message' => array(
639
-                        'title'    => esc_html__('About Previews', 'event_espresso'),
640
-                        'callback' => 'preview_message_help_tab',
641
-                    ),
642
-                ),
643
-                'require_nonce' => false,
644
-            ),
645
-            'settings'                 => array(
646
-                'nav'           => array(
647
-                    'label' => esc_html__('Settings', 'event_espresso'),
648
-                    'order' => 40,
649
-                ),
650
-                'metaboxes'     => array('_messages_settings_metaboxes'),
651
-                'help_tabs'     => array(
652
-                    'messages_settings_help_tab'               => array(
653
-                        'title'    => esc_html__('Messages Settings', 'event_espresso'),
654
-                        'filename' => 'messages_settings',
655
-                    ),
656
-                    'messages_settings_message_types_help_tab' => array(
657
-                        'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
658
-                        'filename' => 'messages_settings_message_types',
659
-                    ),
660
-                    'messages_settings_messengers_help_tab'    => array(
661
-                        'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
662
-                        'filename' => 'messages_settings_messengers',
663
-                    ),
664
-                ),
665
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
666
-                // 'help_tour'     => array('Messages_Settings_Help_Tour'),
667
-                'require_nonce' => false,
668
-            ),
669
-        );
670
-    }
671
-
672
-
673
-    protected function _add_screen_options()
674
-    {
675
-        // todo
676
-    }
677
-
678
-
679
-    protected function _add_screen_options_global_mtps()
680
-    {
681
-        /**
682
-         * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
683
-         * uses the $_admin_page_title property and we want different outputs in the different spots.
684
-         */
685
-        $page_title = $this->_admin_page_title;
686
-        $this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
687
-        $this->_per_page_screen_option();
688
-        $this->_admin_page_title = $page_title;
689
-    }
690
-
691
-
692
-    protected function _add_screen_options_default()
693
-    {
694
-        $this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
695
-        $this->_per_page_screen_option();
696
-    }
697
-
698
-
699
-    // none of the below group are currently used for Messages
700
-    protected function _add_feature_pointers()
701
-    {
702
-    }
703
-
704
-    public function admin_init()
705
-    {
706
-    }
707
-
708
-    public function admin_notices()
709
-    {
710
-    }
711
-
712
-    public function admin_footer_scripts()
713
-    {
714
-    }
715
-
716
-
717
-    public function messages_help_tab()
718
-    {
719
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
720
-    }
721
-
722
-
723
-    public function messengers_help_tab()
724
-    {
725
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
726
-    }
727
-
728
-
729
-    public function message_types_help_tab()
730
-    {
731
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
732
-    }
733
-
734
-
735
-    public function messages_overview_help_tab()
736
-    {
737
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
738
-    }
739
-
740
-
741
-    public function message_templates_help_tab()
742
-    {
743
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
744
-    }
745
-
746
-
747
-    public function edit_message_template_help_tab()
748
-    {
749
-        $args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
750
-                        . esc_attr__('Editor Title', 'event_espresso')
751
-                        . '" />';
752
-        $args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
753
-                        . esc_attr__('Context Switcher and Preview', 'event_espresso')
754
-                        . '" />';
755
-        $args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
756
-                        . esc_attr__('Message Template Form Fields', 'event_espresso')
757
-                        . '" />';
758
-        $args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
759
-                        . esc_attr__('Shortcodes Metabox', 'event_espresso')
760
-                        . '" />';
761
-        $args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
762
-                        . esc_attr__('Publish Metabox', 'event_espresso')
763
-                        . '" />';
764
-        EEH_Template::display_template(
765
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
766
-            $args
767
-        );
768
-    }
769
-
770
-
771
-    public function message_template_shortcodes_help_tab()
772
-    {
773
-        $this->_set_shortcodes();
774
-        $args['shortcodes'] = $this->_shortcodes;
775
-        EEH_Template::display_template(
776
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
777
-            $args
778
-        );
779
-    }
780
-
781
-
782
-    public function preview_message_help_tab()
783
-    {
784
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
785
-    }
786
-
787
-
788
-    public function settings_help_tab()
789
-    {
790
-        $args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
791
-                        . '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
792
-        $args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
793
-                        . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
794
-        $args['img3'] = '<div class="switch">'
795
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
796
-                        . ' type="checkbox" checked="checked">'
797
-                        . '<label for="ee-on-off-toggle-on"></label>'
798
-                        . '</div>';
799
-        $args['img4'] = '<div class="switch">'
800
-                        . '<input class="ee-on-off-toggle ee-toggle-round-flat"'
801
-                        . ' type="checkbox">'
802
-                        . '<label for="ee-on-off-toggle-on"></label>'
803
-                        . '</div>';
804
-        EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
805
-    }
806
-
807
-
808
-    public function load_scripts_styles()
809
-    {
810
-        wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
811
-        wp_enqueue_style('espresso_ee_msg');
812
-
813
-        wp_register_script(
814
-            'ee-messages-settings',
815
-            EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
816
-            array('jquery-ui-droppable', 'ee-serialize-full-array'),
817
-            EVENT_ESPRESSO_VERSION,
818
-            true
819
-        );
820
-        wp_register_script(
821
-            'ee-msg-list-table-js',
822
-            EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
823
-            array('ee-dialog'),
824
-            EVENT_ESPRESSO_VERSION
825
-        );
826
-    }
827
-
828
-
829
-    public function load_scripts_styles_default()
830
-    {
831
-        wp_enqueue_script('ee-msg-list-table-js');
832
-    }
833
-
834
-
835
-    public function wp_editor_css($mce_css)
836
-    {
837
-        // if we're on the edit_message_template route
838
-        if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
839
-            $message_type_name = $this->_active_message_type_name;
840
-
841
-            // we're going to REPLACE the existing mce css
842
-            // we need to get the css file location from the active messenger
843
-            $mce_css = $this->_active_messenger->get_variation(
844
-                $this->_template_pack,
845
-                $message_type_name,
846
-                true,
847
-                'wpeditor',
848
-                $this->_variation
849
-            );
850
-        }
851
-
852
-        return $mce_css;
853
-    }
854
-
855
-
856
-    public function load_scripts_styles_edit_message_template()
857
-    {
858
-
859
-        $this->_set_shortcodes();
860
-
861
-        EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(
862
-            esc_html__(
863
-                'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
864
-                'event_espresso'
865
-            ),
866
-            $this->_message_template_group->messenger_obj()->label['singular'],
867
-            $this->_message_template_group->message_type_obj()->label['singular']
868
-        );
869
-        EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
870
-            'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
871
-            'event_espresso'
872
-        );
873
-        EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
874
-            'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
875
-            'event_espresso'
876
-        );
877
-
878
-        wp_register_script(
879
-            'ee_msgs_edit_js',
880
-            EE_MSG_ASSETS_URL . 'ee_message_editor.js',
881
-            array('jquery'),
882
-            EVENT_ESPRESSO_VERSION
883
-        );
884
-
885
-        wp_enqueue_script('ee_admin_js');
886
-        wp_enqueue_script('ee_msgs_edit_js');
887
-
888
-        // add in special css for tiny_mce
889
-        add_filter('mce_css', array($this, 'wp_editor_css'));
890
-    }
891
-
892
-
893
-    public function load_scripts_styles_display_preview_message()
894
-    {
895
-
896
-        $this->_set_message_template_group();
897
-
898
-        if (isset($this->_req_data['messenger'])) {
899
-            $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
900
-                $this->_req_data['messenger']
901
-            );
902
-        }
903
-
904
-        $message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
905
-
906
-
907
-        wp_enqueue_style(
908
-            'espresso_preview_css',
909
-            $this->_active_messenger->get_variation(
910
-                $this->_template_pack,
911
-                $message_type_name,
912
-                true,
913
-                'preview',
914
-                $this->_variation
915
-            )
916
-        );
917
-    }
918
-
919
-
920
-    public function load_scripts_styles_settings()
921
-    {
922
-        wp_register_style(
923
-            'ee-message-settings',
924
-            EE_MSG_ASSETS_URL . 'ee_message_settings.css',
925
-            array(),
926
-            EVENT_ESPRESSO_VERSION
927
-        );
928
-        wp_enqueue_style('ee-text-links');
929
-        wp_enqueue_style('ee-message-settings');
930
-        wp_enqueue_script('ee-messages-settings');
931
-    }
932
-
933
-
934
-    /**
935
-     * set views array for List Table
936
-     */
937
-    public function _set_list_table_views_global_mtps()
938
-    {
939
-        $this->_views = array(
940
-            'in_use' => array(
941
-                'slug'  => 'in_use',
942
-                'label' => esc_html__('In Use', 'event_espresso'),
943
-                'count' => 0,
944
-            ),
945
-        );
946
-    }
947
-
948
-
949
-    /**
950
-     * Set views array for the Custom Template List Table
951
-     */
952
-    public function _set_list_table_views_custom_mtps()
953
-    {
954
-        $this->_set_list_table_views_global_mtps();
955
-        $this->_views['in_use']['bulk_action'] = array(
956
-            'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
957
-        );
958
-    }
959
-
960
-
961
-    /**
962
-     * set views array for message queue list table
963
-     *
964
-     * @throws InvalidDataTypeException
965
-     * @throws InvalidInterfaceException
966
-     * @throws InvalidArgumentException
967
-     * @throws EE_Error
968
-     * @throws ReflectionException
969
-     */
970
-    public function _set_list_table_views_default()
971
-    {
972
-        EE_Registry::instance()->load_helper('Template');
973
-
974
-        $common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
975
-            'ee_send_message',
976
-            'message_list_table_bulk_actions'
977
-        )
978
-            ? array(
979
-                'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
980
-                'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
981
-                'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
982
-                'send_now'              => esc_html__('Send Now', 'event_espresso'),
983
-            )
984
-            : array();
985
-
986
-        $delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
987
-            'ee_delete_messages',
988
-            'message_list_table_bulk_actions'
989
-        )
990
-            ? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso'))
991
-            : array();
992
-
993
-
994
-        $this->_views = array(
995
-            'all' => array(
996
-                'slug'        => 'all',
997
-                'label'       => esc_html__('All', 'event_espresso'),
998
-                'count'       => 0,
999
-                'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1000
-            ),
1001
-        );
1002
-
1003
-
1004
-        foreach (EEM_Message::instance()->all_statuses() as $status) {
1005
-            if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1006
-                continue;
1007
-            }
1008
-            $status_bulk_actions = $common_bulk_actions;
1009
-            // unset bulk actions not applying to status
1010
-            if (! empty($status_bulk_actions)) {
1011
-                switch ($status) {
1012
-                    case EEM_Message::status_idle:
1013
-                    case EEM_Message::status_resend:
1014
-                        $status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1015
-                        break;
1016
-
1017
-                    case EEM_Message::status_failed:
1018
-                    case EEM_Message::status_debug_only:
1019
-                    case EEM_Message::status_messenger_executing:
1020
-                        $status_bulk_actions = array();
1021
-                        break;
1022
-
1023
-                    case EEM_Message::status_incomplete:
1024
-                        unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1025
-                        break;
1026
-
1027
-                    case EEM_Message::status_retry:
1028
-                    case EEM_Message::status_sent:
1029
-                        unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1030
-                        break;
1031
-                }
1032
-            }
1033
-
1034
-            // skip adding messenger executing status to views because it will be included with the Failed view.
1035
-            if ($status === EEM_Message::status_messenger_executing) {
1036
-                continue;
1037
-            }
1038
-
1039
-            $this->_views[ strtolower($status) ] = array(
1040
-                'slug'        => strtolower($status),
1041
-                'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1042
-                'count'       => 0,
1043
-                'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1044
-            );
1045
-        }
1046
-    }
1047
-
1048
-
1049
-    protected function _ee_default_messages_overview_list_table()
1050
-    {
1051
-        $this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1052
-        $this->display_admin_list_table_page_with_no_sidebar();
1053
-    }
1054
-
1055
-
1056
-    protected function _message_queue_list_table()
1057
-    {
1058
-        $this->_search_btn_label = esc_html__('Message Activity', 'event_espresso');
1059
-        $this->_template_args['per_column'] = 6;
1060
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items());
1061
-        $this->_template_args['before_list_table'] = '<h3>'
1062
-                                                     . EEM_Message::instance()->get_pretty_label_for_results()
1063
-                                                     . '</h3>';
1064
-        $this->display_admin_list_table_page_with_no_sidebar();
1065
-    }
1066
-
1067
-
1068
-    protected function _message_legend_items()
1069
-    {
1070
-
1071
-        $action_css_classes = EEH_MSG_Template::get_message_action_icons();
1072
-        $action_items = array();
1073
-
1074
-        foreach ($action_css_classes as $action_item => $action_details) {
1075
-            if ($action_item === 'see_notifications_for') {
1076
-                continue;
1077
-            }
1078
-            $action_items[ $action_item ] = array(
1079
-                'class' => $action_details['css_class'],
1080
-                'desc'  => $action_details['label'],
1081
-            );
1082
-        }
1083
-
1084
-        /** @type array $status_items status legend setup */
1085
-        $status_items = array(
1086
-            'incomplete_status'          => array(
1087
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1088
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1089
-            ),
1090
-            'idle_status'                => array(
1091
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1092
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1093
-            ),
1094
-            'resend_status'              => array(
1095
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1096
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1097
-            ),
1098
-            'messenger_executing_status' => array(
1099
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1100
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1101
-            ),
1102
-            'sent_status'                => array(
1103
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1104
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1105
-            ),
1106
-            'retry_status'               => array(
1107
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1108
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1109
-            ),
1110
-            'failed_status'              => array(
1111
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1112
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1113
-            ),
1114
-        );
1115
-        if (EEM_Message::debug()) {
1116
-            $status_items['debug_only_status'] = array(
1117
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1118
-                'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1119
-            );
1120
-        }
1121
-
1122
-        return array_merge($action_items, $status_items);
1123
-    }
1124
-
1125
-
1126
-    protected function _custom_mtps_preview()
1127
-    {
1128
-        $this->_admin_page_title = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1129
-        $this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1130
-                                               . ' alt="' . esc_attr__(
1131
-                                                   'Preview Custom Message Templates screenshot',
1132
-                                                   'event_espresso'
1133
-                                               ) . '" />';
1134
-        $this->_template_args['preview_text'] = '<strong>'
1135
-                                                . esc_html__(
1136
-                                                    'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1137
-                                                    'event_espresso'
1138
-                                                )
1139
-                                                . '</strong>';
1140
-
1141
-        $this->display_admin_caf_preview_page('custom_message_types', false);
1142
-    }
1143
-
1144
-
1145
-    /**
1146
-     * get_message_templates
1147
-     * This gets all the message templates for listing on the overview list.
1148
-     *
1149
-     * @access public
1150
-     * @param int    $perpage the amount of templates groups to show per page
1151
-     * @param string $type    the current _view we're getting templates for
1152
-     * @param bool   $count   return count?
1153
-     * @param bool   $all     disregard any paging info (get all data);
1154
-     * @param bool   $global  whether to return just global (true) or custom templates (false)
1155
-     * @return array
1156
-     * @throws EE_Error
1157
-     * @throws InvalidArgumentException
1158
-     * @throws InvalidDataTypeException
1159
-     * @throws InvalidInterfaceException
1160
-     */
1161
-    public function get_message_templates(
1162
-        $perpage = 10,
1163
-        $type = 'in_use',
1164
-        $count = false,
1165
-        $all = false,
1166
-        $global = true
1167
-    ) {
1168
-
1169
-        $MTP = EEM_Message_Template_Group::instance();
1170
-
1171
-        $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1172
-        $orderby = $this->_req_data['orderby'];
1173
-
1174
-        $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
1175
-            ? $this->_req_data['order']
1176
-            : 'ASC';
1177
-
1178
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1179
-            ? $this->_req_data['paged']
1180
-            : 1;
1181
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1182
-            ? $this->_req_data['perpage']
1183
-            : $perpage;
1184
-
1185
-        $offset = ($current_page - 1) * $per_page;
1186
-        $limit = $all ? null : array($offset, $per_page);
1187
-
1188
-
1189
-        // options will match what is in the _views array property
1190
-        switch ($type) {
1191
-            case 'in_use':
1192
-                $templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1193
-                break;
1194
-            default:
1195
-                $templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1196
-        }
1197
-
1198
-        return $templates;
1199
-    }
1200
-
1201
-
1202
-    /**
1203
-     * filters etc might need a list of installed message_types
1204
-     *
1205
-     * @return array an array of message type objects
1206
-     */
1207
-    public function get_installed_message_types()
1208
-    {
1209
-        $installed_message_types = $this->_message_resource_manager->installed_message_types();
1210
-        $installed = array();
1211
-
1212
-        foreach ($installed_message_types as $message_type) {
1213
-            $installed[ $message_type->name ] = $message_type;
1214
-        }
1215
-
1216
-        return $installed;
1217
-    }
1218
-
1219
-
1220
-    /**
1221
-     * _add_message_template
1222
-     *
1223
-     * This is used when creating a custom template. All Custom Templates start based off another template.
1224
-     *
1225
-     * @param string $message_type
1226
-     * @param string $messenger
1227
-     * @param string $GRP_ID
1228
-     *
1229
-     * @throws EE_error
1230
-     */
1231
-    protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1232
-    {
1233
-        // set values override any request data
1234
-        $message_type = ! empty($message_type) ? $message_type : '';
1235
-        $message_type = empty($message_type) && ! empty($this->_req_data['message_type'])
1236
-            ? $this->_req_data['message_type']
1237
-            : $message_type;
1238
-
1239
-        $messenger = ! empty($messenger) ? $messenger : '';
1240
-        $messenger = empty($messenger) && ! empty($this->_req_data['messenger'])
1241
-            ? $this->_req_data['messenger']
1242
-            : $messenger;
1243
-
1244
-        $GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1245
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1246
-
1247
-        // we need messenger and message type.  They should be coming from the event editor. If not here then return error
1248
-        if (empty($message_type) || empty($messenger)) {
1249
-            throw new EE_Error(
1250
-                esc_html__(
1251
-                    'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1252
-                    'event_espresso'
1253
-                )
1254
-            );
1255
-        }
1256
-
1257
-        // we need the GRP_ID for the template being used as the base for the new template
1258
-        if (empty($GRP_ID)) {
1259
-            throw new EE_Error(
1260
-                esc_html__(
1261
-                    'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1262
-                    'event_espresso'
1263
-                )
1264
-            );
1265
-        }
1266
-
1267
-        // let's just make sure the template gets generated!
1268
-
1269
-        // we need to reassign some variables for what the insert is expecting
1270
-        $this->_req_data['MTP_messenger'] = $messenger;
1271
-        $this->_req_data['MTP_message_type'] = $message_type;
1272
-        $this->_req_data['GRP_ID'] = $GRP_ID;
1273
-        $this->_insert_or_update_message_template(true);
1274
-    }
1275
-
1276
-
1277
-    /**
1278
-     * public wrapper for the _add_message_template method
1279
-     *
1280
-     * @param string $message_type     message type slug
1281
-     * @param string $messenger        messenger slug
1282
-     * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1283
-     *                                 off of.
1284
-     * @throws EE_error
1285
-     */
1286
-    public function add_message_template($message_type, $messenger, $GRP_ID)
1287
-    {
1288
-        $this->_add_message_template($message_type, $messenger, $GRP_ID);
1289
-    }
1290
-
1291
-
1292
-    /**
1293
-     * _edit_message_template
1294
-     *
1295
-     * @access protected
1296
-     * @return void
1297
-     * @throws InvalidIdentifierException
1298
-     * @throws DomainException
1299
-     * @throws EE_Error
1300
-     * @throws InvalidArgumentException
1301
-     * @throws ReflectionException
1302
-     * @throws InvalidDataTypeException
1303
-     * @throws InvalidInterfaceException
1304
-     */
1305
-    protected function _edit_message_template()
1306
-    {
1307
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1308
-        $template_fields = '';
1309
-        $sidebar_fields = '';
1310
-        // we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1311
-        // valid html in the templates.
1312
-        add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1313
-
1314
-        $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1315
-            ? absint($this->_req_data['id'])
1316
-            : false;
1317
-
1318
-        $EVT_ID = isset($this->_req_data['evt_id']) && ! empty($this->_req_data['evt_id'])
1319
-        ? absint($this->_req_data['evt_id'])
1320
-        : false;
1321
-
1322
-        $this->_set_shortcodes(); // this also sets the _message_template property.
1323
-        $message_template_group = $this->_message_template_group;
1324
-        $c_label = $message_template_group->context_label();
1325
-        $c_config = $message_template_group->contexts_config();
1326
-
1327
-        reset($c_config);
1328
-        $context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1329
-            ? strtolower($this->_req_data['context'])
1330
-            : key($c_config);
1331
-
1332
-
1333
-        if (empty($GRP_ID)) {
1334
-            $action = 'insert_message_template';
1335
-            $edit_message_template_form_url = add_query_arg(
1336
-                array('action' => $action, 'noheader' => true),
1337
-                EE_MSG_ADMIN_URL
1338
-            );
1339
-        } else {
1340
-            $action = 'update_message_template';
1341
-            $edit_message_template_form_url = add_query_arg(
1342
-                array('action' => $action, 'noheader' => true),
1343
-                EE_MSG_ADMIN_URL
1344
-            );
1345
-        }
1346
-
1347
-        // set active messenger for this view
1348
-        $this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
1349
-            $message_template_group->messenger()
1350
-        );
1351
-        $this->_active_message_type_name = $message_template_group->message_type();
1352
-
1353
-
1354
-        // Do we have any validation errors?
1355
-        $validators = $this->_get_transient();
1356
-        $v_fields = ! empty($validators) ? array_keys($validators) : array();
1357
-
1358
-
1359
-        // we need to assemble the title from Various details
1360
-        $context_label = sprintf(
1361
-            esc_html__('(%s %s)', 'event_espresso'),
1362
-            $c_config[ $context ]['label'],
1363
-            ucwords($c_label['label'])
1364
-        );
1365
-
1366
-        $title = sprintf(
1367
-            esc_html__(' %s %s Template %s', 'event_espresso'),
1368
-            ucwords($message_template_group->messenger_obj()->label['singular']),
1369
-            ucwords($message_template_group->message_type_obj()->label['singular']),
1370
-            $context_label
1371
-        );
1372
-
1373
-        $this->_template_args['GRP_ID'] = $GRP_ID;
1374
-        $this->_template_args['message_template'] = $message_template_group;
1375
-        $this->_template_args['is_extra_fields'] = false;
1376
-
1377
-
1378
-        // let's get EEH_MSG_Template so we can get template form fields
1379
-        $template_field_structure = EEH_MSG_Template::get_fields(
1380
-            $message_template_group->messenger(),
1381
-            $message_template_group->message_type()
1382
-        );
1383
-
1384
-        if (! $template_field_structure) {
1385
-            $template_field_structure = false;
1386
-            $template_fields = esc_html__(
1387
-                'There was an error in assembling the fields for this display (you should see an error message)',
1388
-                'event_espresso'
1389
-            );
1390
-        }
1391
-
1392
-
1393
-        $message_templates = $message_template_group->context_templates();
1394
-
1395
-
1396
-        // if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1397
-        // will get handled in the "extra" array.
1398
-        if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1399
-            foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1400
-                unset($template_field_structure[ $context ][ $reference_field ]);
1401
-            }
1402
-        }
1403
-
1404
-        // let's loop through the template_field_structure and actually assemble the input fields!
1405
-        if (! empty($template_field_structure)) {
1406
-            foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1407
-                // if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1408
-                // the extra array and reset them.
1409
-                if ($template_field === 'extra') {
1410
-                    $this->_template_args['is_extra_fields'] = true;
1411
-                    foreach ($field_setup_array as $reference_field => $new_fields_array) {
1412
-                        $message_template = $message_templates[ $context ][ $reference_field ];
1413
-                        $content = $message_template instanceof EE_Message_Template
1414
-                            ? $message_template->get('MTP_content')
1415
-                            : '';
1416
-                        foreach ($new_fields_array as $extra_field => $extra_array) {
1417
-                            // let's verify if we need this extra field via the shortcodes parameter.
1418
-                            $continue = false;
1419
-                            if (isset($extra_array['shortcodes_required'])) {
1420
-                                foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1421
-                                    if (! array_key_exists($shortcode, $this->_shortcodes)) {
1422
-                                        $continue = true;
1423
-                                    }
1424
-                                }
1425
-                                if ($continue) {
1426
-                                    continue;
1427
-                                }
1428
-                            }
1429
-
1430
-                            $field_id = $reference_field
1431
-                                        . '-'
1432
-                                        . $extra_field
1433
-                                        . '-content';
1434
-                            $template_form_fields[ $field_id ] = $extra_array;
1435
-                            $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1436
-                                                                         . $reference_field
1437
-                                                                         . '][content]['
1438
-                                                                         . $extra_field . ']';
1439
-                            $css_class = isset($extra_array['css_class'])
1440
-                                ? $extra_array['css_class']
1441
-                                : '';
1442
-
1443
-                            $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1444
-                                                                              && in_array($extra_field, $v_fields, true)
1445
-                                                                              &&
1446
-                                                                              (
1447
-                                                                                  is_array($validators[ $extra_field ])
1448
-                                                                                  && isset($validators[ $extra_field ]['msg'])
1449
-                                                                              )
1450
-                                ? 'validate-error ' . $css_class
1451
-                                : $css_class;
1452
-
1453
-                            $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1454
-                                                                          && isset($content[ $extra_field ])
1455
-                                ? $content[ $extra_field ]
1456
-                                : '';
1457
-
1458
-                            // do we have a validation error?  if we do then let's use that value instead
1459
-                            $template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1460
-                                ? $validators[ $extra_field ]['value']
1461
-                                : $template_form_fields[ $field_id ]['value'];
1462
-
1463
-
1464
-                            $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1465
-
1466
-                            // shortcode selector
1467
-                            $field_name_to_use = $extra_field === 'main'
1468
-                                ? 'content'
1469
-                                : $extra_field;
1470
-                            $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1471
-                                $field_name_to_use,
1472
-                                $field_id
1473
-                            );
1474
-
1475
-                            if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') {
1476
-                                // we want to decode the entities
1477
-                                $template_form_fields[ $field_id ]['value'] = $template_form_fields[ $field_id ]['value'];
1478
-                            }/**/
1479
-                        }
1480
-                        $templatefield_MTP_id = $reference_field . '-MTP_ID';
1481
-                        $templatefield_templatename_id = $reference_field . '-name';
1482
-
1483
-                        $template_form_fields[ $templatefield_MTP_id ] = array(
1484
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1485
-                            'label'      => null,
1486
-                            'input'      => 'hidden',
1487
-                            'type'       => 'int',
1488
-                            'required'   => false,
1489
-                            'validation' => false,
1490
-                            'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1491
-                            'css_class'  => '',
1492
-                            'format'     => '%d',
1493
-                            'db-col'     => 'MTP_ID',
1494
-                        );
1495
-
1496
-                        $template_form_fields[ $templatefield_templatename_id ] = array(
1497
-                            'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1498
-                            'label'      => null,
1499
-                            'input'      => 'hidden',
1500
-                            'type'       => 'string',
1501
-                            'required'   => false,
1502
-                            'validation' => true,
1503
-                            'value'      => $reference_field,
1504
-                            'css_class'  => '',
1505
-                            'format'     => '%s',
1506
-                            'db-col'     => 'MTP_template_field',
1507
-                        );
1508
-                    }
1509
-                    continue; // skip the next stuff, we got the necessary fields here for this dataset.
1510
-                } else {
1511
-                    $field_id = $template_field . '-content';
1512
-                    $template_form_fields[ $field_id ] = $field_setup_array;
1513
-                    $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields[' . $template_field . '][content]';
1514
-                    $message_template = isset($message_templates[ $context ][ $template_field ])
1515
-                        ? $message_templates[ $context ][ $template_field ]
1516
-                        : null;
1517
-                    $template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1518
-                                                                  && is_array($message_templates[ $context ])
1519
-                                                                  && $message_template instanceof EE_Message_Template
1520
-                        ? $message_template->get('MTP_content')
1521
-                        : '';
1522
-
1523
-                    // do we have a validator error for this field?  if we do then we'll use that value instead
1524
-                    $template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1525
-                        ? $validators[ $template_field ]['value']
1526
-                        : $template_form_fields[ $field_id ]['value'];
1527
-
1528
-
1529
-                    $template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1530
-                    $css_class = isset($field_setup_array['css_class'])
1531
-                        ? $field_setup_array['css_class']
1532
-                        : '';
1533
-                    $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1534
-                                                                      && in_array($template_field, $v_fields, true)
1535
-                                                                      && isset($validators[ $template_field ]['msg'])
1536
-                        ? 'validate-error ' . $css_class
1537
-                        : $css_class;
1538
-
1539
-                    // shortcode selector
1540
-                    $template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1541
-                        $template_field,
1542
-                        $field_id
1543
-                    );
1544
-                }
1545
-
1546
-                // k took care of content field(s) now let's take care of others.
1547
-
1548
-                $templatefield_MTP_id = $template_field . '-MTP_ID';
1549
-                $templatefield_field_templatename_id = $template_field . '-name';
1550
-
1551
-                // foreach template field there are actually two form fields created
1552
-                $template_form_fields[ $templatefield_MTP_id ] = array(
1553
-                    'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1554
-                    'label'      => null,
1555
-                    'input'      => 'hidden',
1556
-                    'type'       => 'int',
1557
-                    'required'   => false,
1558
-                    'validation' => true,
1559
-                    'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1560
-                    'css_class'  => '',
1561
-                    'format'     => '%d',
1562
-                    'db-col'     => 'MTP_ID',
1563
-                );
1564
-
1565
-                $template_form_fields[ $templatefield_field_templatename_id ] = array(
1566
-                    'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1567
-                    'label'      => null,
1568
-                    'input'      => 'hidden',
1569
-                    'type'       => 'string',
1570
-                    'required'   => false,
1571
-                    'validation' => true,
1572
-                    'value'      => $template_field,
1573
-                    'css_class'  => '',
1574
-                    'format'     => '%s',
1575
-                    'db-col'     => 'MTP_template_field',
1576
-                );
1577
-            }
1578
-
1579
-            // add other fields
1580
-            $template_form_fields['ee-msg-current-context'] = array(
1581
-                'name'       => 'MTP_context',
1582
-                'label'      => null,
1583
-                'input'      => 'hidden',
1584
-                'type'       => 'string',
1585
-                'required'   => false,
1586
-                'validation' => true,
1587
-                'value'      => $context,
1588
-                'css_class'  => '',
1589
-                'format'     => '%s',
1590
-                'db-col'     => 'MTP_context',
1591
-            );
1592
-
1593
-            $template_form_fields['ee-msg-grp-id'] = array(
1594
-                'name'       => 'GRP_ID',
1595
-                'label'      => null,
1596
-                'input'      => 'hidden',
1597
-                'type'       => 'int',
1598
-                'required'   => false,
1599
-                'validation' => true,
1600
-                'value'      => $GRP_ID,
1601
-                'css_class'  => '',
1602
-                'format'     => '%d',
1603
-                'db-col'     => 'GRP_ID',
1604
-            );
1605
-
1606
-            $template_form_fields['ee-msg-messenger'] = array(
1607
-                'name'       => 'MTP_messenger',
1608
-                'label'      => null,
1609
-                'input'      => 'hidden',
1610
-                'type'       => 'string',
1611
-                'required'   => false,
1612
-                'validation' => true,
1613
-                'value'      => $message_template_group->messenger(),
1614
-                'css_class'  => '',
1615
-                'format'     => '%s',
1616
-                'db-col'     => 'MTP_messenger',
1617
-            );
1618
-
1619
-            $template_form_fields['ee-msg-message-type'] = array(
1620
-                'name'       => 'MTP_message_type',
1621
-                'label'      => null,
1622
-                'input'      => 'hidden',
1623
-                'type'       => 'string',
1624
-                'required'   => false,
1625
-                'validation' => true,
1626
-                'value'      => $message_template_group->message_type(),
1627
-                'css_class'  => '',
1628
-                'format'     => '%s',
1629
-                'db-col'     => 'MTP_message_type',
1630
-            );
1631
-
1632
-            $sidebar_form_fields['ee-msg-is-global'] = array(
1633
-                'name'       => 'MTP_is_global',
1634
-                'label'      => esc_html__('Global Template', 'event_espresso'),
1635
-                'input'      => 'hidden',
1636
-                'type'       => 'int',
1637
-                'required'   => false,
1638
-                'validation' => true,
1639
-                'value'      => $message_template_group->get('MTP_is_global'),
1640
-                'css_class'  => '',
1641
-                'format'     => '%d',
1642
-                'db-col'     => 'MTP_is_global',
1643
-            );
1644
-
1645
-            $sidebar_form_fields['ee-msg-is-override'] = array(
1646
-                'name'       => 'MTP_is_override',
1647
-                'label'      => esc_html__('Override all custom', 'event_espresso'),
1648
-                'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1649
-                'type'       => 'int',
1650
-                'required'   => false,
1651
-                'validation' => true,
1652
-                'value'      => $message_template_group->get('MTP_is_override'),
1653
-                'css_class'  => '',
1654
-                'format'     => '%d',
1655
-                'db-col'     => 'MTP_is_override',
1656
-            );
1657
-
1658
-            $sidebar_form_fields['ee-msg-is-active'] = array(
1659
-                'name'       => 'MTP_is_active',
1660
-                'label'      => esc_html__('Active Template', 'event_espresso'),
1661
-                'input'      => 'hidden',
1662
-                'type'       => 'int',
1663
-                'required'   => false,
1664
-                'validation' => true,
1665
-                'value'      => $message_template_group->is_active(),
1666
-                'css_class'  => '',
1667
-                'format'     => '%d',
1668
-                'db-col'     => 'MTP_is_active',
1669
-            );
1670
-
1671
-            $sidebar_form_fields['ee-msg-deleted'] = array(
1672
-                'name'       => 'MTP_deleted',
1673
-                'label'      => null,
1674
-                'input'      => 'hidden',
1675
-                'type'       => 'int',
1676
-                'required'   => false,
1677
-                'validation' => true,
1678
-                'value'      => $message_template_group->get('MTP_deleted'),
1679
-                'css_class'  => '',
1680
-                'format'     => '%d',
1681
-                'db-col'     => 'MTP_deleted',
1682
-            );
1683
-            $sidebar_form_fields['ee-msg-author'] = array(
1684
-                'name'       => 'MTP_user_id',
1685
-                'label'      => esc_html__('Author', 'event_espresso'),
1686
-                'input'      => 'hidden',
1687
-                'type'       => 'int',
1688
-                'required'   => false,
1689
-                'validation' => false,
1690
-                'value'      => $message_template_group->user(),
1691
-                'format'     => '%d',
1692
-                'db-col'     => 'MTP_user_id',
1693
-            );
1694
-
1695
-            $sidebar_form_fields['ee-msg-route'] = array(
1696
-                'name'  => 'action',
1697
-                'input' => 'hidden',
1698
-                'type'  => 'string',
1699
-                'value' => $action,
1700
-            );
1701
-
1702
-            $sidebar_form_fields['ee-msg-id'] = array(
1703
-                'name'  => 'id',
1704
-                'input' => 'hidden',
1705
-                'type'  => 'int',
1706
-                'value' => $GRP_ID,
1707
-            );
1708
-            $sidebar_form_fields['ee-msg-evt-nonce'] = array(
1709
-                'name'  => $action . '_nonce',
1710
-                'input' => 'hidden',
1711
-                'type'  => 'string',
1712
-                'value' => wp_create_nonce($action . '_nonce'),
1713
-            );
1714
-
1715
-            if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1716
-                $sidebar_form_fields['ee-msg-template-switch'] = array(
1717
-                    'name'  => 'template_switch',
1718
-                    'input' => 'hidden',
1719
-                    'type'  => 'int',
1720
-                    'value' => 1,
1721
-                );
1722
-            }
1723
-
1724
-
1725
-            $template_fields = $this->_generate_admin_form_fields($template_form_fields);
1726
-            $sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields);
1727
-        } //end if ( !empty($template_field_structure) )
1728
-
1729
-        // set extra content for publish box
1730
-        $this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1731
-        $this->_set_publish_post_box_vars(
1732
-            'id',
1733
-            $GRP_ID,
1734
-            false,
1735
-            add_query_arg(
1736
-                array('action' => 'global_mtps'),
1737
-                $this->_admin_base_url
1738
-            )
1739
-        );
1740
-
1741
-        // add preview button
1742
-        $preview_url = parent::add_query_args_and_nonce(
1743
-            array(
1744
-                'message_type' => $message_template_group->message_type(),
1745
-                'messenger'    => $message_template_group->messenger(),
1746
-                'context'      => $context,
1747
-                'GRP_ID'       => $GRP_ID,
1748
-                'evt_id'       => $EVT_ID,
1749
-                'action'       => 'preview_message',
1750
-            ),
1751
-            $this->_admin_base_url
1752
-        );
1753
-        $preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1754
-                          . esc_html__('Preview', 'event_espresso')
1755
-                          . '</a>';
1756
-
1757
-
1758
-        // setup context switcher
1759
-        $context_switcher_args = array(
1760
-            'page'    => 'espresso_messages',
1761
-            'action'  => 'edit_message_template',
1762
-            'id'      => $GRP_ID,
1763
-            'evt_id'  => $EVT_ID,
1764
-            'context' => $context,
1765
-            'extra'   => $preview_button,
1766
-        );
1767
-        $this->_set_context_switcher($message_template_group, $context_switcher_args);
1768
-
1769
-
1770
-        // main box
1771
-        $this->_template_args['template_fields'] = $template_fields;
1772
-        $this->_template_args['sidebar_box_id'] = 'details';
1773
-        $this->_template_args['action'] = $action;
1774
-        $this->_template_args['context'] = $context;
1775
-        $this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url;
1776
-        $this->_template_args['learn_more_about_message_templates_link'] =
1777
-            $this->_learn_more_about_message_templates_link();
1778
-
1779
-
1780
-        $this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1781
-        $this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1782
-            $message_template_group,
1783
-            $context,
1784
-            $context_label
1785
-        );
1786
-        $this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1787
-        $this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1788
-
1789
-        $this->_template_path = $this->_template_args['GRP_ID']
1790
-            ? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1791
-            : EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1792
-
1793
-        // send along EE_Message_Template_Group object for further template use.
1794
-        $this->_template_args['MTP'] = $message_template_group;
1795
-
1796
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
1797
-            $this->_template_path,
1798
-            $this->_template_args,
1799
-            true
1800
-        );
1801
-
1802
-
1803
-        // finally, let's set the admin_page title
1804
-        $this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1805
-
1806
-
1807
-        // we need to take care of setting the shortcodes property for use elsewhere.
1808
-        $this->_set_shortcodes();
1809
-
1810
-
1811
-        // final template wrapper
1812
-        $this->display_admin_page_with_sidebar();
1813
-    }
1814
-
1815
-
1816
-    public function filter_tinymce_init($mceInit, $editor_id)
1817
-    {
1818
-        return $mceInit;
1819
-    }
1820
-
1821
-
1822
-    public function add_context_switcher()
1823
-    {
1824
-        return $this->_context_switcher;
1825
-    }
1826
-
1827
-
1828
-    /**
1829
-     * Adds the activation/deactivation toggle for the message template context.
1830
-     *
1831
-     * @param EE_Message_Template_Group $message_template_group
1832
-     * @param string                    $context
1833
-     * @param string                    $context_label
1834
-     * @return string
1835
-     * @throws DomainException
1836
-     * @throws EE_Error
1837
-     * @throws InvalidIdentifierException
1838
-     */
1839
-    protected function add_active_context_element(
1840
-        EE_Message_Template_Group $message_template_group,
1841
-        $context,
1842
-        $context_label
1843
-    ) {
1844
-        $template_args = array(
1845
-            'context'                   => $context,
1846
-            'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1847
-            'is_active'                 => $message_template_group->is_context_active($context),
1848
-            'on_off_action'             => $message_template_group->is_context_active($context)
1849
-                ? 'context-off'
1850
-                : 'context-on',
1851
-            'context_label'             => str_replace(array('(', ')'), '', $context_label),
1852
-            'message_template_group_id' => $message_template_group->ID(),
1853
-        );
1854
-        return EEH_Template::display_template(
1855
-            EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1856
-            $template_args,
1857
-            true
1858
-        );
1859
-    }
1860
-
1861
-
1862
-    /**
1863
-     * Ajax callback for `toggle_context_template` ajax action.
1864
-     * Handles toggling the message context on or off.
1865
-     *
1866
-     * @throws EE_Error
1867
-     * @throws InvalidArgumentException
1868
-     * @throws InvalidDataTypeException
1869
-     * @throws InvalidIdentifierException
1870
-     * @throws InvalidInterfaceException
1871
-     */
1872
-    public function toggle_context_template()
1873
-    {
1874
-        $success = true;
1875
-        // check for required data
1876
-        if (
1877
-            ! isset(
1878
-                $this->_req_data['message_template_group_id'],
1879
-                $this->_req_data['context'],
1880
-                $this->_req_data['status']
1881
-            )
1882
-        ) {
1883
-            EE_Error::add_error(
1884
-                esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1885
-                __FILE__,
1886
-                __FUNCTION__,
1887
-                __LINE__
1888
-            );
1889
-            $success = false;
1890
-        }
1891
-
1892
-        $nonce = isset($this->_req_data['toggle_context_nonce'])
1893
-            ? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1894
-            : '';
1895
-        $nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1896
-        $this->_verify_nonce($nonce, $nonce_ref);
1897
-        $status = $this->_req_data['status'];
1898
-        if ($status !== 'off' && $status !== 'on') {
1899
-            EE_Error::add_error(
1900
-                sprintf(
1901
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1902
-                    $this->_req_data['status']
1903
-                ),
1904
-                __FILE__,
1905
-                __FUNCTION__,
1906
-                __LINE__
1907
-            );
1908
-            $success = false;
1909
-        }
1910
-        $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1911
-            $this->_req_data['message_template_group_id']
1912
-        );
1913
-        if (! $message_template_group instanceof EE_Message_Template_Group) {
1914
-            EE_Error::add_error(
1915
-                sprintf(
1916
-                    esc_html__(
1917
-                        'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1918
-                        'event_espresso'
1919
-                    ),
1920
-                    $this->_req_data['message_template_group_id'],
1921
-                    'EE_Message_Template_Group'
1922
-                ),
1923
-                __FILE__,
1924
-                __FUNCTION__,
1925
-                __LINE__
1926
-            );
1927
-            $success = false;
1928
-        }
1929
-        if ($success) {
1930
-            $success = $status === 'off'
1931
-                ? $message_template_group->deactivate_context($this->_req_data['context'])
1932
-                : $message_template_group->activate_context($this->_req_data['context']);
1933
-        }
1934
-        $this->_template_args['success'] = $success;
1935
-        $this->_return_json();
1936
-    }
1937
-
1938
-
1939
-    public function _add_form_element_before()
1940
-    {
1941
-        return '<form method="post" action="'
1942
-               . $this->_template_args["edit_message_template_form_url"]
1943
-               . '" id="ee-msg-edit-frm">';
1944
-    }
1945
-
1946
-    public function _add_form_element_after()
1947
-    {
1948
-        return '</form>';
1949
-    }
1950
-
1951
-
1952
-    /**
1953
-     * This executes switching the template pack for a message template.
1954
-     *
1955
-     * @since 4.5.0
1956
-     * @throws EE_Error
1957
-     * @throws InvalidDataTypeException
1958
-     * @throws InvalidInterfaceException
1959
-     * @throws InvalidArgumentException
1960
-     * @throws ReflectionException
1961
-     */
1962
-    public function switch_template_pack()
1963
-    {
1964
-        $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1965
-        $template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1966
-
1967
-        // verify we have needed values.
1968
-        if (empty($GRP_ID) || empty($template_pack)) {
1969
-            $this->_template_args['error'] = true;
1970
-            EE_Error::add_error(
1971
-                esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1972
-                __FILE__,
1973
-                __FUNCTION__,
1974
-                __LINE__
1975
-            );
1976
-        } else {
1977
-            // get template, set the new template_pack and then reset to default
1978
-            /** @type EE_Message_Template_Group $message_template_group */
1979
-            $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1980
-
1981
-            $message_template_group->set_template_pack_name($template_pack);
1982
-            $this->_req_data['msgr'] = $message_template_group->messenger();
1983
-            $this->_req_data['mt'] = $message_template_group->message_type();
1984
-
1985
-            $query_args = $this->_reset_to_default_template();
1986
-
1987
-            if (empty($query_args['id'])) {
1988
-                EE_Error::add_error(
1989
-                    esc_html__(
1990
-                        'Something went wrong with switching the template pack. Please try again or contact EE support',
1991
-                        'event_espresso'
1992
-                    ),
1993
-                    __FILE__,
1994
-                    __FUNCTION__,
1995
-                    __LINE__
1996
-                );
1997
-                $this->_template_args['error'] = true;
1998
-            } else {
1999
-                $template_label = $message_template_group->get_template_pack()->label;
2000
-                $template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2001
-                EE_Error::add_success(
2002
-                    sprintf(
2003
-                        esc_html__(
2004
-                            'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2005
-                            'event_espresso'
2006
-                        ),
2007
-                        $template_label,
2008
-                        $template_pack_labels->template_pack
2009
-                    )
2010
-                );
2011
-                // generate the redirect url for js.
2012
-                $url = self::add_query_args_and_nonce(
2013
-                    $query_args,
2014
-                    $this->_admin_base_url
2015
-                );
2016
-                $this->_template_args['data']['redirect_url'] = $url;
2017
-                $this->_template_args['success'] = true;
2018
-            }
2019
-
2020
-            $this->_return_json();
2021
-        }
2022
-    }
2023
-
2024
-
2025
-    /**
2026
-     * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2027
-     * they want.
2028
-     *
2029
-     * @access protected
2030
-     * @return array|null
2031
-     * @throws EE_Error
2032
-     * @throws InvalidArgumentException
2033
-     * @throws InvalidDataTypeException
2034
-     * @throws InvalidInterfaceException
2035
-     */
2036
-    protected function _reset_to_default_template()
2037
-    {
2038
-
2039
-        $templates = array();
2040
-        $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2041
-        // we need to make sure we've got the info we need.
2042
-        if (! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2043
-            EE_Error::add_error(
2044
-                esc_html__(
2045
-                    'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
2046
-                    'event_espresso'
2047
-                ),
2048
-                __FILE__,
2049
-                __FUNCTION__,
2050
-                __LINE__
2051
-            );
2052
-        }
2053
-
2054
-        // all templates will be reset to whatever the defaults are
2055
-        // for the global template matching the messenger and message type.
2056
-        $success = ! empty($GRP_ID) ? true : false;
2057
-
2058
-        if ($success) {
2059
-            // let's first determine if the incoming template is a global template,
2060
-            // if it isn't then we need to get the global template matching messenger and message type.
2061
-            // $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
2062
-
2063
-
2064
-            // note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2065
-            $success = $this->_delete_mtp_permanently($GRP_ID, false);
2066
-
2067
-            if ($success) {
2068
-                // if successfully deleted, lets generate the new ones.
2069
-                // Note. We set GLOBAL to true, because resets on ANY template
2070
-                // will use the related global template defaults for regeneration.
2071
-                // This means that if a custom template is reset it resets to whatever the related global template is.
2072
-                // HOWEVER, we DO keep the template pack and template variation set
2073
-                // for the current custom template when resetting.
2074
-                $templates = $this->_generate_new_templates(
2075
-                    $this->_req_data['msgr'],
2076
-                    $this->_req_data['mt'],
2077
-                    $GRP_ID,
2078
-                    true
2079
-                );
2080
-            }
2081
-        }
2082
-
2083
-        // any error messages?
2084
-        if (! $success) {
2085
-            EE_Error::add_error(
2086
-                esc_html__(
2087
-                    'Something went wrong with deleting existing templates. Unable to reset to default',
2088
-                    'event_espresso'
2089
-                ),
2090
-                __FILE__,
2091
-                __FUNCTION__,
2092
-                __LINE__
2093
-            );
2094
-        }
2095
-
2096
-        // all good, let's add a success message!
2097
-        if ($success && ! empty($templates)) {
2098
-            // the info for the template we generated is the first element in the returned array
2099
-            // $templates = $templates[0];
2100
-            EE_Error::overwrite_success();
2101
-            EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
2102
-        }
2103
-
2104
-
2105
-        $query_args = array(
2106
-            'id'      => isset($templates[0]['GRP_ID']) ? $templates[0]['GRP_ID'] : null,
2107
-            'context' => isset($templates[0]['MTP_context']) ? $templates[0]['MTP_context'] : null,
2108
-            'action'  => isset($templates[0]['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2109
-        );
2110
-
2111
-        // if called via ajax then we return query args otherwise redirect
2112
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2113
-            return $query_args;
2114
-        } else {
2115
-            $this->_redirect_after_action(false, '', '', $query_args, true);
2116
-
2117
-            return null;
2118
-        }
2119
-    }
2120
-
2121
-
2122
-    /**
2123
-     * Retrieve and set the message preview for display.
2124
-     *
2125
-     * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2126
-     * @return string
2127
-     * @throws ReflectionException
2128
-     * @throws EE_Error
2129
-     * @throws InvalidArgumentException
2130
-     * @throws InvalidDataTypeException
2131
-     * @throws InvalidInterfaceException
2132
-     */
2133
-    public function _preview_message($send = false)
2134
-    {
2135
-        // first make sure we've got the necessary parameters
2136
-        if (
2137
-            ! isset(
2138
-                $this->_req_data['message_type'],
2139
-                $this->_req_data['messenger'],
2140
-                $this->_req_data['messenger'],
2141
-                $this->_req_data['GRP_ID']
2142
-            )
2143
-        ) {
2144
-            EE_Error::add_error(
2145
-                esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2146
-                __FILE__,
2147
-                __FUNCTION__,
2148
-                __LINE__
2149
-            );
2150
-        }
2151
-
2152
-        EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
2153
-
2154
-        // if we have an evt_id set on the request, use it.
2155
-        $EVT_ID = isset($this->_req_data['evt_id']) && ! empty($this->_req_data['evt_id'])
2156
-        ? absint($this->_req_data['evt_id'])
2157
-        : false;
2158
-
2159
-
2160
-        // get the preview!
2161
-        $preview = EED_Messages::preview_message(
2162
-            $this->_req_data['message_type'],
2163
-            $this->_req_data['context'],
2164
-            $this->_req_data['messenger'],
2165
-            $send
2166
-        );
2167
-
2168
-        if ($send) {
2169
-            return $preview;
2170
-        }
2171
-
2172
-        // let's add a button to go back to the edit view
2173
-        $query_args = array(
2174
-            'id'      => $this->_req_data['GRP_ID'],
2175
-            'evt_id'  => $EVT_ID,
2176
-            'context' => $this->_req_data['context'],
2177
-            'action'  => 'edit_message_template',
2178
-        );
2179
-        $go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2180
-        $preview_button = '<a href="'
2181
-                          . $go_back_url
2182
-                          . '" class="button-secondary messages-preview-go-back-button">'
2183
-                          . esc_html__('Go Back to Edit', 'event_espresso')
2184
-                          . '</a>';
2185
-        $message_types = $this->get_installed_message_types();
2186
-        $active_messenger = $this->_message_resource_manager->get_active_messenger(
2187
-            $this->_req_data['messenger']
2188
-        );
2189
-        $active_messenger_label = $active_messenger instanceof EE_messenger
2190
-            ? ucwords($active_messenger->label['singular'])
2191
-            : esc_html__('Unknown Messenger', 'event_espresso');
2192
-        // let's provide a helpful title for context
2193
-        $preview_title = sprintf(
2194
-            esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2195
-            $active_messenger_label,
2196
-            ucwords($message_types[ $this->_req_data['message_type'] ]->label['singular'])
2197
-        );
2198
-        if (empty($preview)) {
2199
-            $this->noEventsErrorMessage();
2200
-        }
2201
-        // setup display of preview.
2202
-        $this->_admin_page_title = $preview_title;
2203
-        $this->_template_args['admin_page_title'] = $preview_title;
2204
-        $this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2205
-        $this->_template_args['data']['force_json'] = true;
2206
-
2207
-        return '';
2208
-    }
2209
-
2210
-
2211
-    /**
2212
-     * Used to set an error if there are no events available for generating a preview/test send.
2213
-     *
2214
-     * @param bool $test_send  Whether the error should be generated for the context of a test send.
2215
-     */
2216
-    protected function noEventsErrorMessage($test_send = false)
2217
-    {
2218
-        $events_url = parent::add_query_args_and_nonce(
2219
-            array(
2220
-                'action' => 'default',
2221
-                'page'   => 'espresso_events',
2222
-            ),
2223
-            admin_url('admin.php')
2224
-        );
2225
-        $message = $test_send
2226
-            ? __(
2227
-                'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2228
-                'event_espresso'
2229
-            )
2230
-            : __(
2231
-                'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!',
2232
-                'event_espresso'
2233
-            );
2234
-
2235
-        EE_Error::add_attention(
2236
-            sprintf(
2237
-                $message,
2238
-                "<a href='{$events_url}'>",
2239
-                '</a>'
2240
-            )
2241
-        );
2242
-    }
2243
-
2244
-
2245
-    /**
2246
-     * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2247
-     * gets called automatically.
2248
-     *
2249
-     * @since 4.5.0
2250
-     *
2251
-     * @return string
2252
-     */
2253
-    protected function _display_preview_message()
2254
-    {
2255
-        $this->display_admin_page_with_no_sidebar();
2256
-    }
2257
-
2258
-
2259
-    /**
2260
-     * registers metaboxes that should show up on the "edit_message_template" page
2261
-     *
2262
-     * @access protected
2263
-     * @return void
2264
-     */
2265
-    protected function _register_edit_meta_boxes()
2266
-    {
2267
-        add_meta_box(
2268
-            'mtp_valid_shortcodes',
2269
-            esc_html__('Valid Shortcodes', 'event_espresso'),
2270
-            array($this, 'shortcode_meta_box'),
2271
-            $this->_current_screen->id,
2272
-            'side',
2273
-            'default'
2274
-        );
2275
-        add_meta_box(
2276
-            'mtp_extra_actions',
2277
-            esc_html__('Extra Actions', 'event_espresso'),
2278
-            array($this, 'extra_actions_meta_box'),
2279
-            $this->_current_screen->id,
2280
-            'side',
2281
-            'high'
2282
-        );
2283
-        add_meta_box(
2284
-            'mtp_templates',
2285
-            esc_html__('Template Styles', 'event_espresso'),
2286
-            array($this, 'template_pack_meta_box'),
2287
-            $this->_current_screen->id,
2288
-            'side',
2289
-            'high'
2290
-        );
2291
-    }
2292
-
2293
-
2294
-    /**
2295
-     * metabox content for all template pack and variation selection.
2296
-     *
2297
-     * @since 4.5.0
2298
-     * @return string
2299
-     * @throws DomainException
2300
-     * @throws EE_Error
2301
-     * @throws InvalidArgumentException
2302
-     * @throws ReflectionException
2303
-     * @throws InvalidDataTypeException
2304
-     * @throws InvalidInterfaceException
2305
-     */
2306
-    public function template_pack_meta_box()
2307
-    {
2308
-        $this->_set_message_template_group();
2309
-
2310
-        $tp_collection = EEH_MSG_Template::get_template_pack_collection();
2311
-
2312
-        $tp_select_values = array();
2313
-
2314
-        foreach ($tp_collection as $tp) {
2315
-            // only include template packs that support this messenger and message type!
2316
-            $supports = $tp->get_supports();
2317
-            if (
2318
-                ! isset($supports[ $this->_message_template_group->messenger() ])
2319
-                || ! in_array(
2320
-                    $this->_message_template_group->message_type(),
2321
-                    $supports[ $this->_message_template_group->messenger() ],
2322
-                    true
2323
-                )
2324
-            ) {
2325
-                // not supported
2326
-                continue;
2327
-            }
2328
-
2329
-            $tp_select_values[] = array(
2330
-                'text' => $tp->label,
2331
-                'id'   => $tp->dbref,
2332
-            );
2333
-        }
2334
-
2335
-        // if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2336
-        // the default template pack.  This still allows for the odd template pack to override.
2337
-        if (empty($tp_select_values)) {
2338
-            $tp_select_values[] = array(
2339
-                'text' => esc_html__('Default', 'event_espresso'),
2340
-                'id'   => 'default',
2341
-            );
2342
-        }
2343
-
2344
-        // setup variation select values for the currently selected template.
2345
-        $variations = $this->_message_template_group->get_template_pack()->get_variations(
2346
-            $this->_message_template_group->messenger(),
2347
-            $this->_message_template_group->message_type()
2348
-        );
2349
-        $variations_select_values = array();
2350
-        foreach ($variations as $variation => $label) {
2351
-            $variations_select_values[] = array(
2352
-                'text' => $label,
2353
-                'id'   => $variation,
2354
-            );
2355
-        }
2356
-
2357
-        $template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2358
-
2359
-        $template_args['template_packs_selector'] = EEH_Form_Fields::select_input(
2360
-            'MTP_template_pack',
2361
-            $tp_select_values,
2362
-            $this->_message_template_group->get_template_pack_name()
2363
-        );
2364
-        $template_args['variations_selector'] = EEH_Form_Fields::select_input(
2365
-            'MTP_template_variation',
2366
-            $variations_select_values,
2367
-            $this->_message_template_group->get_template_pack_variation()
2368
-        );
2369
-        $template_args['template_pack_label'] = $template_pack_labels->template_pack;
2370
-        $template_args['template_variation_label'] = $template_pack_labels->template_variation;
2371
-        $template_args['template_pack_description'] = $template_pack_labels->template_pack_description;
2372
-        $template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2373
-
2374
-        $template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2375
-
2376
-        EEH_Template::display_template($template, $template_args);
2377
-    }
2378
-
2379
-
2380
-    /**
2381
-     * This meta box holds any extra actions related to Message Templates
2382
-     * For now, this includes Resetting templates to defaults and sending a test email.
2383
-     *
2384
-     * @access  public
2385
-     * @return void
2386
-     * @throws EE_Error
2387
-     */
2388
-    public function extra_actions_meta_box()
2389
-    {
2390
-        $template_form_fields = array();
2391
-
2392
-        $extra_args = array(
2393
-            'msgr'   => $this->_message_template_group->messenger(),
2394
-            'mt'     => $this->_message_template_group->message_type(),
2395
-            'GRP_ID' => $this->_message_template_group->GRP_ID(),
2396
-        );
2397
-        // first we need to see if there are any fields
2398
-        $fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2399
-
2400
-        if (! empty($fields)) {
2401
-            // yup there be fields
2402
-            foreach ($fields as $field => $config) {
2403
-                $field_id = $this->_message_template_group->messenger() . '_' . $field;
2404
-                $existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2405
-                $default = isset($config['default']) ? $config['default'] : '';
2406
-                $default = isset($config['value']) ? $config['value'] : $default;
2407
-
2408
-                // if type is hidden and the value is empty
2409
-                // something may have gone wrong so let's correct with the defaults
2410
-                $fix = $config['input'] === 'hidden'
2411
-                       && isset($existing[ $field ])
2412
-                       && empty($existing[ $field ])
2413
-                    ? $default
2414
-                    : '';
2415
-                $existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2416
-                    ? $existing[ $field ]
2417
-                    : $fix;
2418
-
2419
-                $template_form_fields[ $field_id ] = array(
2420
-                    'name'       => 'test_settings_fld[' . $field . ']',
2421
-                    'label'      => $config['label'],
2422
-                    'input'      => $config['input'],
2423
-                    'type'       => $config['type'],
2424
-                    'required'   => $config['required'],
2425
-                    'validation' => $config['validation'],
2426
-                    'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2427
-                    'css_class'  => $config['css_class'],
2428
-                    'options'    => isset($config['options']) ? $config['options'] : array(),
2429
-                    'default'    => $default,
2430
-                    'format'     => $config['format'],
2431
-                );
2432
-            }
2433
-        }
2434
-
2435
-        $test_settings_fields = ! empty($template_form_fields)
2436
-            ? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2437
-            : '';
2438
-
2439
-        $test_settings_html = '';
2440
-        // print out $test_settings_fields
2441
-        if (! empty($test_settings_fields)) {
2442
-            echo $test_settings_fields;
2443
-            $test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2444
-            $test_settings_html .= 'name="test_button" value="';
2445
-            $test_settings_html .= esc_html__('Test Send', 'event_espresso');
2446
-            $test_settings_html .= '" /><div style="clear:both"></div>';
2447
-        }
2448
-
2449
-        // and button
2450
-        $test_settings_html .= '<p>'
2451
-                               . esc_html__('Need to reset this message type and start over?', 'event_espresso')
2452
-                               . '</p>';
2453
-        $test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2454
-        $test_settings_html .= $this->get_action_link_or_button(
2455
-            'reset_to_default',
2456
-            'reset',
2457
-            $extra_args,
2458
-            'button-primary reset-default-button'
2459
-        );
2460
-        $test_settings_html .= '</div><div style="clear:both"></div>';
2461
-        echo $test_settings_html;
2462
-    }
2463
-
2464
-
2465
-    /**
2466
-     * This returns the shortcode selector skeleton for a given context and field.
2467
-     *
2468
-     * @since 4.9.rc.000
2469
-     * @param string $field           The name of the field retrieving shortcodes for.
2470
-     * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2471
-     * @return string
2472
-     * @throws DomainException
2473
-     * @throws EE_Error
2474
-     * @throws InvalidArgumentException
2475
-     * @throws ReflectionException
2476
-     * @throws InvalidDataTypeException
2477
-     * @throws InvalidInterfaceException
2478
-     */
2479
-    protected function _get_shortcode_selector($field, $linked_input_id)
2480
-    {
2481
-        $template_args = array(
2482
-            'shortcodes'      => $this->_get_shortcodes(array($field), true),
2483
-            'fieldname'       => $field,
2484
-            'linked_input_id' => $linked_input_id,
2485
-        );
2486
-
2487
-        return EEH_Template::display_template(
2488
-            EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2489
-            $template_args,
2490
-            true
2491
-        );
2492
-    }
2493
-
2494
-
2495
-    /**
2496
-     * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2497
-     * page)
2498
-     *
2499
-     * @access public
2500
-     * @return void
2501
-     * @throws EE_Error
2502
-     * @throws InvalidArgumentException
2503
-     * @throws ReflectionException
2504
-     * @throws InvalidDataTypeException
2505
-     * @throws InvalidInterfaceException
2506
-     */
2507
-    public function shortcode_meta_box()
2508
-    {
2509
-        $shortcodes = $this->_get_shortcodes(array(), false); // just make sure shortcodes property is set
2510
-        // $messenger = $this->_message_template_group->messenger_obj();
2511
-        // now let's set the content depending on the status of the shortcodes array
2512
-        if (empty($shortcodes)) {
2513
-            $content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2514
-            echo $content;
2515
-        } else {
2516
-            // $alt = 0;
2517
-            ?>
22
+	/**
23
+	 * @type EE_Message_Resource_Manager $_message_resource_manager
24
+	 */
25
+	protected $_message_resource_manager;
26
+
27
+	/**
28
+	 * @type string $_active_message_type_name
29
+	 */
30
+	protected $_active_message_type_name = '';
31
+
32
+	/**
33
+	 * @type EE_messenger $_active_messenger
34
+	 */
35
+	protected $_active_messenger;
36
+	protected $_activate_state;
37
+	protected $_activate_meta_box_type;
38
+	protected $_current_message_meta_box;
39
+	protected $_current_message_meta_box_object;
40
+	protected $_context_switcher;
41
+	protected $_shortcodes = array();
42
+	protected $_active_messengers = array();
43
+	protected $_active_message_types = array();
44
+
45
+	/**
46
+	 * @var EE_Message_Template_Group $_message_template_group
47
+	 */
48
+	protected $_message_template_group;
49
+	protected $_m_mt_settings = array();
50
+
51
+
52
+	/**
53
+	 * This is set via the _set_message_template_group method and holds whatever the template pack for the group is.
54
+	 * IF there is no group then it gets automatically set to the Default template pack.
55
+	 *
56
+	 * @since 4.5.0
57
+	 *
58
+	 * @var EE_Messages_Template_Pack
59
+	 */
60
+	protected $_template_pack;
61
+
62
+
63
+	/**
64
+	 * This is set via the _set_message_template_group method and holds whatever the template pack variation for the
65
+	 * group is.  If there is no group then it automatically gets set to default.
66
+	 *
67
+	 * @since 4.5.0
68
+	 *
69
+	 * @var string
70
+	 */
71
+	protected $_variation;
72
+
73
+
74
+	/**
75
+	 * @param bool $routing
76
+	 * @throws EE_Error
77
+	 */
78
+	public function __construct($routing = true)
79
+	{
80
+		// make sure messages autoloader is running
81
+		EED_Messages::set_autoloaders();
82
+		parent::__construct($routing);
83
+	}
84
+
85
+
86
+	protected function _init_page_props()
87
+	{
88
+		$this->page_slug = EE_MSG_PG_SLUG;
89
+		$this->page_label = esc_html__('Messages Settings', 'event_espresso');
90
+		$this->_admin_base_url = EE_MSG_ADMIN_URL;
91
+		$this->_admin_base_path = EE_MSG_ADMIN;
92
+
93
+		$this->_activate_state = isset($this->_req_data['activate_state']) ? (array) $this->_req_data['activate_state']
94
+			: array();
95
+
96
+		$this->_active_messenger = isset($this->_req_data['messenger']) ? $this->_req_data['messenger'] : null;
97
+		$this->_load_message_resource_manager();
98
+	}
99
+
100
+
101
+	/**
102
+	 * loads messenger objects into the $_active_messengers property (so we can access the needed methods)
103
+	 *
104
+	 * @throws EE_Error
105
+	 * @throws InvalidDataTypeException
106
+	 * @throws InvalidInterfaceException
107
+	 * @throws InvalidArgumentException
108
+	 * @throws ReflectionException
109
+	 */
110
+	protected function _load_message_resource_manager()
111
+	{
112
+		$this->_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
113
+	}
114
+
115
+
116
+	/**
117
+	 * @deprecated 4.9.9.rc.014
118
+	 * @return array
119
+	 * @throws EE_Error
120
+	 * @throws InvalidArgumentException
121
+	 * @throws InvalidDataTypeException
122
+	 * @throws InvalidInterfaceException
123
+	 */
124
+	public function get_messengers_for_list_table()
125
+	{
126
+		EE_Error::doing_it_wrong(
127
+			__METHOD__,
128
+			sprintf(
129
+				esc_html__(
130
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a messenger filter dropdown which is now generated differently via %s',
131
+					'event_espresso'
132
+				),
133
+				'Messages_Admin_Page::get_messengers_select_input()'
134
+			),
135
+			'4.9.9.rc.014'
136
+		);
137
+
138
+		$m_values = array();
139
+		$active_messengers = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
140
+		// setup messengers for selects
141
+		$i = 1;
142
+		foreach ($active_messengers as $active_messenger) {
143
+			if ($active_messenger instanceof EE_Message) {
144
+				$m_values[ $i ]['id'] = $active_messenger->messenger();
145
+				$m_values[ $i ]['text'] = ucwords($active_messenger->messenger_label());
146
+				$i++;
147
+			}
148
+		}
149
+
150
+		return $m_values;
151
+	}
152
+
153
+
154
+	/**
155
+	 * @deprecated 4.9.9.rc.014
156
+	 * @return array
157
+	 * @throws EE_Error
158
+	 * @throws InvalidArgumentException
159
+	 * @throws InvalidDataTypeException
160
+	 * @throws InvalidInterfaceException
161
+	 */
162
+	public function get_message_types_for_list_table()
163
+	{
164
+		EE_Error::doing_it_wrong(
165
+			__METHOD__,
166
+			sprintf(
167
+				esc_html__(
168
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type filter dropdown which is now generated differently via %s',
169
+					'event_espresso'
170
+				),
171
+				'Messages_Admin_Page::get_message_types_select_input()'
172
+			),
173
+			'4.9.9.rc.014'
174
+		);
175
+
176
+		$mt_values = array();
177
+		$active_messages = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
178
+		$i = 1;
179
+		foreach ($active_messages as $active_message) {
180
+			if ($active_message instanceof EE_Message) {
181
+				$mt_values[ $i ]['id'] = $active_message->message_type();
182
+				$mt_values[ $i ]['text'] = ucwords($active_message->message_type_label());
183
+				$i++;
184
+			}
185
+		}
186
+
187
+		return $mt_values;
188
+	}
189
+
190
+
191
+	/**
192
+	 * @deprecated 4.9.9.rc.014
193
+	 * @return array
194
+	 * @throws EE_Error
195
+	 * @throws InvalidArgumentException
196
+	 * @throws InvalidDataTypeException
197
+	 * @throws InvalidInterfaceException
198
+	 */
199
+	public function get_contexts_for_message_types_for_list_table()
200
+	{
201
+		EE_Error::doing_it_wrong(
202
+			__METHOD__,
203
+			sprintf(
204
+				esc_html__(
205
+					'This method is no longer in use.  There is no replacement for it. The method was used to generate a set of values for use in creating a message type context filter dropdown which is now generated differently via %s',
206
+					'event_espresso'
207
+				),
208
+				'Messages_Admin_Page::get_contexts_for_message_types_select_input()'
209
+			),
210
+			'4.9.9.rc.014'
211
+		);
212
+
213
+		$contexts = array();
214
+		$active_message_contexts = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
215
+		foreach ($active_message_contexts as $active_message) {
216
+			if ($active_message instanceof EE_Message) {
217
+				$message_type = $active_message->message_type_object();
218
+				if ($message_type instanceof EE_message_type) {
219
+					$message_type_contexts = $message_type->get_contexts();
220
+					foreach ($message_type_contexts as $context => $context_details) {
221
+						$contexts[ $context ] = $context_details['label'];
222
+					}
223
+				}
224
+			}
225
+		}
226
+
227
+		return $contexts;
228
+	}
229
+
230
+
231
+	/**
232
+	 * Generate select input with provided messenger options array.
233
+	 *
234
+	 * @param array $messenger_options Array of messengers indexed by messenger slug and values are the messenger
235
+	 *                                 labels.
236
+	 * @return string
237
+	 * @throws EE_Error
238
+	 */
239
+	public function get_messengers_select_input($messenger_options)
240
+	{
241
+		// if empty or just one value then just return an empty string
242
+		if (
243
+			empty($messenger_options)
244
+			|| ! is_array($messenger_options)
245
+			|| count($messenger_options) === 1
246
+		) {
247
+			return '';
248
+		}
249
+		// merge in default
250
+		$messenger_options = array_merge(
251
+			array('none_selected' => esc_html__('Show All Messengers', 'event_espresso')),
252
+			$messenger_options
253
+		);
254
+		$input = new EE_Select_Input(
255
+			$messenger_options,
256
+			array(
257
+				'html_name'  => 'ee_messenger_filter_by',
258
+				'html_id'    => 'ee_messenger_filter_by',
259
+				'html_class' => 'wide',
260
+				'default'    => isset($this->_req_data['ee_messenger_filter_by'])
261
+					? sanitize_title($this->_req_data['ee_messenger_filter_by'])
262
+					: 'none_selected',
263
+			)
264
+		);
265
+
266
+		return $input->get_html_for_input();
267
+	}
268
+
269
+
270
+	/**
271
+	 * Generate select input with provided message type options array.
272
+	 *
273
+	 * @param array $message_type_options Array of message types indexed by message type slug, and values are the
274
+	 *                                    message type labels
275
+	 * @return string
276
+	 * @throws EE_Error
277
+	 */
278
+	public function get_message_types_select_input($message_type_options)
279
+	{
280
+		// if empty or count of options is 1 then just return an empty string
281
+		if (
282
+			empty($message_type_options)
283
+			|| ! is_array($message_type_options)
284
+			|| count($message_type_options) === 1
285
+		) {
286
+			return '';
287
+		}
288
+		// merge in default
289
+		$message_type_options = array_merge(
290
+			array('none_selected' => esc_html__('Show All Message Types', 'event_espresso')),
291
+			$message_type_options
292
+		);
293
+		$input = new EE_Select_Input(
294
+			$message_type_options,
295
+			array(
296
+				'html_name'  => 'ee_message_type_filter_by',
297
+				'html_id'    => 'ee_message_type_filter_by',
298
+				'html_class' => 'wide',
299
+				'default'    => isset($this->_req_data['ee_message_type_filter_by'])
300
+					? sanitize_title($this->_req_data['ee_message_type_filter_by'])
301
+					: 'none_selected',
302
+			)
303
+		);
304
+
305
+		return $input->get_html_for_input();
306
+	}
307
+
308
+
309
+	/**
310
+	 * Generate select input with provide message type contexts array.
311
+	 *
312
+	 * @param array $context_options Array of message type contexts indexed by context slug, and values are the
313
+	 *                               context label.
314
+	 * @return string
315
+	 * @throws EE_Error
316
+	 */
317
+	public function get_contexts_for_message_types_select_input($context_options)
318
+	{
319
+		// if empty or count of options is one then just return empty string
320
+		if (
321
+			empty($context_options)
322
+			|| ! is_array($context_options)
323
+			|| count($context_options) === 1
324
+		) {
325
+			return '';
326
+		}
327
+		// merge in default
328
+		$context_options = array_merge(
329
+			array('none_selected' => esc_html__('Show all Contexts', 'event_espresso')),
330
+			$context_options
331
+		);
332
+		$input = new EE_Select_Input(
333
+			$context_options,
334
+			array(
335
+				'html_name'  => 'ee_context_filter_by',
336
+				'html_id'    => 'ee_context_filter_by',
337
+				'html_class' => 'wide',
338
+				'default'    => isset($this->_req_data['ee_context_filter_by'])
339
+					? sanitize_title($this->_req_data['ee_context_filter_by'])
340
+					: 'none_selected',
341
+			)
342
+		);
343
+
344
+		return $input->get_html_for_input();
345
+	}
346
+
347
+
348
+	protected function _ajax_hooks()
349
+	{
350
+		add_action('wp_ajax_activate_messenger', array($this, 'activate_messenger_toggle'));
351
+		add_action('wp_ajax_activate_mt', array($this, 'activate_mt_toggle'));
352
+		add_action('wp_ajax_ee_msgs_save_settings', array($this, 'save_settings'));
353
+		add_action('wp_ajax_ee_msgs_update_mt_form', array($this, 'update_mt_form'));
354
+		add_action('wp_ajax_switch_template_pack', array($this, 'switch_template_pack'));
355
+		add_action('wp_ajax_toggle_context_template', array($this, 'toggle_context_template'));
356
+	}
357
+
358
+
359
+	protected function _define_page_props()
360
+	{
361
+		$this->_admin_page_title = $this->page_label;
362
+		$this->_labels = array(
363
+			'buttons'    => array(
364
+				'add'    => esc_html__('Add New Message Template', 'event_espresso'),
365
+				'edit'   => esc_html__('Edit Message Template', 'event_espresso'),
366
+				'delete' => esc_html__('Delete Message Template', 'event_espresso'),
367
+			),
368
+			'publishbox' => esc_html__('Update Actions', 'event_espresso'),
369
+		);
370
+	}
371
+
372
+
373
+	/**
374
+	 *        an array for storing key => value pairs of request actions and their corresponding methods
375
+	 *
376
+	 * @access protected
377
+	 * @return void
378
+	 */
379
+	protected function _set_page_routes()
380
+	{
381
+		$grp_id = ! empty($this->_req_data['GRP_ID']) && ! is_array($this->_req_data['GRP_ID'])
382
+			? $this->_req_data['GRP_ID']
383
+			: 0;
384
+		$grp_id = empty($grp_id) && ! empty($this->_req_data['id'])
385
+			? $this->_req_data['id']
386
+			: $grp_id;
387
+		$msg_id = ! empty($this->_req_data['MSG_ID']) && ! is_array($this->_req_data['MSG_ID'])
388
+			? $this->_req_data['MSG_ID']
389
+			: 0;
390
+
391
+		$this->_page_routes = array(
392
+			'default'                          => array(
393
+				'func'       => '_message_queue_list_table',
394
+				'capability' => 'ee_read_global_messages',
395
+			),
396
+			'global_mtps'                      => array(
397
+				'func'       => '_ee_default_messages_overview_list_table',
398
+				'capability' => 'ee_read_global_messages',
399
+			),
400
+			'custom_mtps'                      => array(
401
+				'func'       => '_custom_mtps_preview',
402
+				'capability' => 'ee_read_messages',
403
+			),
404
+			'add_new_message_template'         => array(
405
+				'func'       => '_add_message_template',
406
+				'capability' => 'ee_edit_messages',
407
+				'noheader'   => true,
408
+			),
409
+			'edit_message_template'            => array(
410
+				'func'       => '_edit_message_template',
411
+				'capability' => 'ee_edit_message',
412
+				'obj_id'     => $grp_id,
413
+			),
414
+			'preview_message'                  => array(
415
+				'func'               => '_preview_message',
416
+				'capability'         => 'ee_read_message',
417
+				'obj_id'             => $grp_id,
418
+				'noheader'           => true,
419
+				'headers_sent_route' => 'display_preview_message',
420
+			),
421
+			'display_preview_message'          => array(
422
+				'func'       => '_display_preview_message',
423
+				'capability' => 'ee_read_message',
424
+				'obj_id'     => $grp_id,
425
+			),
426
+			'insert_message_template'          => array(
427
+				'func'       => '_insert_or_update_message_template',
428
+				'capability' => 'ee_edit_messages',
429
+				'args'       => array('new_template' => true),
430
+				'noheader'   => true,
431
+			),
432
+			'update_message_template'          => array(
433
+				'func'       => '_insert_or_update_message_template',
434
+				'capability' => 'ee_edit_message',
435
+				'obj_id'     => $grp_id,
436
+				'args'       => array('new_template' => false),
437
+				'noheader'   => true,
438
+			),
439
+			'trash_message_template'           => array(
440
+				'func'       => '_trash_or_restore_message_template',
441
+				'capability' => 'ee_delete_message',
442
+				'obj_id'     => $grp_id,
443
+				'args'       => array('trash' => true, 'all' => true),
444
+				'noheader'   => true,
445
+			),
446
+			'trash_message_template_context'   => array(
447
+				'func'       => '_trash_or_restore_message_template',
448
+				'capability' => 'ee_delete_message',
449
+				'obj_id'     => $grp_id,
450
+				'args'       => array('trash' => true),
451
+				'noheader'   => true,
452
+			),
453
+			'restore_message_template'         => array(
454
+				'func'       => '_trash_or_restore_message_template',
455
+				'capability' => 'ee_delete_message',
456
+				'obj_id'     => $grp_id,
457
+				'args'       => array('trash' => false, 'all' => true),
458
+				'noheader'   => true,
459
+			),
460
+			'restore_message_template_context' => array(
461
+				'func'       => '_trash_or_restore_message_template',
462
+				'capability' => 'ee_delete_message',
463
+				'obj_id'     => $grp_id,
464
+				'args'       => array('trash' => false),
465
+				'noheader'   => true,
466
+			),
467
+			'delete_message_template'          => array(
468
+				'func'       => '_delete_message_template',
469
+				'capability' => 'ee_delete_message',
470
+				'obj_id'     => $grp_id,
471
+				'noheader'   => true,
472
+			),
473
+			'reset_to_default'                 => array(
474
+				'func'       => '_reset_to_default_template',
475
+				'capability' => 'ee_edit_message',
476
+				'obj_id'     => $grp_id,
477
+				'noheader'   => true,
478
+			),
479
+			'settings'                         => array(
480
+				'func'       => '_settings',
481
+				'capability' => 'manage_options',
482
+			),
483
+			'update_global_settings'           => array(
484
+				'func'       => '_update_global_settings',
485
+				'capability' => 'manage_options',
486
+				'noheader'   => true,
487
+			),
488
+			'generate_now'                     => array(
489
+				'func'       => '_generate_now',
490
+				'capability' => 'ee_send_message',
491
+				'noheader'   => true,
492
+			),
493
+			'generate_and_send_now'            => array(
494
+				'func'       => '_generate_and_send_now',
495
+				'capability' => 'ee_send_message',
496
+				'noheader'   => true,
497
+			),
498
+			'queue_for_resending'              => array(
499
+				'func'       => '_queue_for_resending',
500
+				'capability' => 'ee_send_message',
501
+				'noheader'   => true,
502
+			),
503
+			'send_now'                         => array(
504
+				'func'       => '_send_now',
505
+				'capability' => 'ee_send_message',
506
+				'noheader'   => true,
507
+			),
508
+			'delete_ee_message'                => array(
509
+				'func'       => '_delete_ee_messages',
510
+				'capability' => 'ee_delete_messages',
511
+				'noheader'   => true,
512
+			),
513
+			'delete_ee_messages'               => array(
514
+				'func'       => '_delete_ee_messages',
515
+				'capability' => 'ee_delete_messages',
516
+				'noheader'   => true,
517
+				'obj_id'     => $msg_id,
518
+			),
519
+		);
520
+	}
521
+
522
+
523
+	protected function _set_page_config()
524
+	{
525
+		$this->_page_config = array(
526
+			'default'                  => array(
527
+				'nav'           => array(
528
+					'label' => esc_html__('Message Activity', 'event_espresso'),
529
+					'order' => 10,
530
+				),
531
+				'list_table'    => 'EE_Message_List_Table',
532
+				// 'qtips' => array( 'EE_Message_List_Table_Tips' ),
533
+				'require_nonce' => false,
534
+			),
535
+			'global_mtps'              => array(
536
+				'nav'           => array(
537
+					'label' => esc_html__('Default Message Templates', 'event_espresso'),
538
+					'order' => 20,
539
+				),
540
+				'list_table'    => 'Messages_Template_List_Table',
541
+				'help_tabs'     => array(
542
+					'messages_overview_help_tab'                                => array(
543
+						'title'    => esc_html__('Messages Overview', 'event_espresso'),
544
+						'filename' => 'messages_overview',
545
+					),
546
+					'messages_overview_messages_table_column_headings_help_tab' => array(
547
+						'title'    => esc_html__('Messages Table Column Headings', 'event_espresso'),
548
+						'filename' => 'messages_overview_table_column_headings',
549
+					),
550
+					'messages_overview_messages_filters_help_tab'               => array(
551
+						'title'    => esc_html__('Message Filters', 'event_espresso'),
552
+						'filename' => 'messages_overview_filters',
553
+					),
554
+					'messages_overview_messages_views_help_tab'                 => array(
555
+						'title'    => esc_html__('Message Views', 'event_espresso'),
556
+						'filename' => 'messages_overview_views',
557
+					),
558
+					'message_overview_message_types_help_tab'                   => array(
559
+						'title'    => esc_html__('Message Types', 'event_espresso'),
560
+						'filename' => 'messages_overview_types',
561
+					),
562
+					'messages_overview_messengers_help_tab'                     => array(
563
+						'title'    => esc_html__('Messengers', 'event_espresso'),
564
+						'filename' => 'messages_overview_messengers',
565
+					),
566
+				),
567
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
568
+				// 'help_tour'     => array('Messages_Overview_Help_Tour'),
569
+				'require_nonce' => false,
570
+			),
571
+			'custom_mtps'              => array(
572
+				'nav'           => array(
573
+					'label' => esc_html__('Custom Message Templates', 'event_espresso'),
574
+					'order' => 30,
575
+				),
576
+				'help_tabs'     => array(),
577
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
578
+				// 'help_tour'     => array(),
579
+				'require_nonce' => false,
580
+			),
581
+			'add_new_message_template' => array(
582
+				'nav'           => array(
583
+					'label'      => esc_html__('Add New Message Templates', 'event_espresso'),
584
+					'order'      => 5,
585
+					'persistent' => false,
586
+				),
587
+				'require_nonce' => false,
588
+			),
589
+			'edit_message_template'    => array(
590
+				'labels'        => array(
591
+					'buttons'    => array(
592
+						'reset' => esc_html__('Reset Templates', 'event_espresso'),
593
+					),
594
+					'publishbox' => esc_html__('Update Actions', 'event_espresso'),
595
+				),
596
+				'nav'           => array(
597
+					'label'      => esc_html__('Edit Message Templates', 'event_espresso'),
598
+					'order'      => 5,
599
+					'persistent' => false,
600
+					'url'        => '',
601
+				),
602
+				'metaboxes'     => array('_publish_post_box', '_register_edit_meta_boxes'),
603
+				'has_metaboxes' => true,
604
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
605
+				// 'help_tour'     => array('Message_Templates_Edit_Help_Tour'),
606
+				'help_tabs'     => array(
607
+					'edit_message_template'            => array(
608
+						'title'    => esc_html__('Message Template Editor', 'event_espresso'),
609
+						'callback' => 'edit_message_template_help_tab',
610
+					),
611
+					'message_templates_help_tab'       => array(
612
+						'title'    => esc_html__('Message Templates', 'event_espresso'),
613
+						'filename' => 'messages_templates',
614
+					),
615
+					'message_template_shortcodes'      => array(
616
+						'title'    => esc_html__('Message Shortcodes', 'event_espresso'),
617
+						'callback' => 'message_template_shortcodes_help_tab',
618
+					),
619
+					'message_preview_help_tab'         => array(
620
+						'title'    => esc_html__('Message Preview', 'event_espresso'),
621
+						'filename' => 'messages_preview',
622
+					),
623
+					'messages_overview_other_help_tab' => array(
624
+						'title'    => esc_html__('Messages Other', 'event_espresso'),
625
+						'filename' => 'messages_overview_other',
626
+					),
627
+				),
628
+				'require_nonce' => false,
629
+			),
630
+			'display_preview_message'  => array(
631
+				'nav'           => array(
632
+					'label'      => esc_html__('Message Preview', 'event_espresso'),
633
+					'order'      => 5,
634
+					'url'        => '',
635
+					'persistent' => false,
636
+				),
637
+				'help_tabs'     => array(
638
+					'preview_message' => array(
639
+						'title'    => esc_html__('About Previews', 'event_espresso'),
640
+						'callback' => 'preview_message_help_tab',
641
+					),
642
+				),
643
+				'require_nonce' => false,
644
+			),
645
+			'settings'                 => array(
646
+				'nav'           => array(
647
+					'label' => esc_html__('Settings', 'event_espresso'),
648
+					'order' => 40,
649
+				),
650
+				'metaboxes'     => array('_messages_settings_metaboxes'),
651
+				'help_tabs'     => array(
652
+					'messages_settings_help_tab'               => array(
653
+						'title'    => esc_html__('Messages Settings', 'event_espresso'),
654
+						'filename' => 'messages_settings',
655
+					),
656
+					'messages_settings_message_types_help_tab' => array(
657
+						'title'    => esc_html__('Activating / Deactivating Message Types', 'event_espresso'),
658
+						'filename' => 'messages_settings_message_types',
659
+					),
660
+					'messages_settings_messengers_help_tab'    => array(
661
+						'title'    => esc_html__('Activating / Deactivating Messengers', 'event_espresso'),
662
+						'filename' => 'messages_settings_messengers',
663
+					),
664
+				),
665
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
666
+				// 'help_tour'     => array('Messages_Settings_Help_Tour'),
667
+				'require_nonce' => false,
668
+			),
669
+		);
670
+	}
671
+
672
+
673
+	protected function _add_screen_options()
674
+	{
675
+		// todo
676
+	}
677
+
678
+
679
+	protected function _add_screen_options_global_mtps()
680
+	{
681
+		/**
682
+		 * Note: the reason for the value swap here on $this->_admin_page_title is because $this->_per_page_screen_options
683
+		 * uses the $_admin_page_title property and we want different outputs in the different spots.
684
+		 */
685
+		$page_title = $this->_admin_page_title;
686
+		$this->_admin_page_title = esc_html__('Global Message Templates', 'event_espresso');
687
+		$this->_per_page_screen_option();
688
+		$this->_admin_page_title = $page_title;
689
+	}
690
+
691
+
692
+	protected function _add_screen_options_default()
693
+	{
694
+		$this->_admin_page_title = esc_html__('Message Activity', 'event_espresso');
695
+		$this->_per_page_screen_option();
696
+	}
697
+
698
+
699
+	// none of the below group are currently used for Messages
700
+	protected function _add_feature_pointers()
701
+	{
702
+	}
703
+
704
+	public function admin_init()
705
+	{
706
+	}
707
+
708
+	public function admin_notices()
709
+	{
710
+	}
711
+
712
+	public function admin_footer_scripts()
713
+	{
714
+	}
715
+
716
+
717
+	public function messages_help_tab()
718
+	{
719
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_help_tab.template.php');
720
+	}
721
+
722
+
723
+	public function messengers_help_tab()
724
+	{
725
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messenger_help_tab.template.php');
726
+	}
727
+
728
+
729
+	public function message_types_help_tab()
730
+	{
731
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_type_help_tab.template.php');
732
+	}
733
+
734
+
735
+	public function messages_overview_help_tab()
736
+	{
737
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_overview_help_tab.template.php');
738
+	}
739
+
740
+
741
+	public function message_templates_help_tab()
742
+	{
743
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_message_templates_help_tab.template.php');
744
+	}
745
+
746
+
747
+	public function edit_message_template_help_tab()
748
+	{
749
+		$args['img1'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/editor.png' . '" alt="'
750
+						. esc_attr__('Editor Title', 'event_espresso')
751
+						. '" />';
752
+		$args['img2'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/switch-context.png' . '" alt="'
753
+						. esc_attr__('Context Switcher and Preview', 'event_espresso')
754
+						. '" />';
755
+		$args['img3'] = '<img class="left" src="' . EE_MSG_ASSETS_URL . 'images/form-fields.png' . '" alt="'
756
+						. esc_attr__('Message Template Form Fields', 'event_espresso')
757
+						. '" />';
758
+		$args['img4'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/shortcodes-metabox.png' . '" alt="'
759
+						. esc_attr__('Shortcodes Metabox', 'event_espresso')
760
+						. '" />';
761
+		$args['img5'] = '<img class="right" src="' . EE_MSG_ASSETS_URL . 'images/publish-meta-box.png' . '" alt="'
762
+						. esc_attr__('Publish Metabox', 'event_espresso')
763
+						. '" />';
764
+		EEH_Template::display_template(
765
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_templates_editor_help_tab.template.php',
766
+			$args
767
+		);
768
+	}
769
+
770
+
771
+	public function message_template_shortcodes_help_tab()
772
+	{
773
+		$this->_set_shortcodes();
774
+		$args['shortcodes'] = $this->_shortcodes;
775
+		EEH_Template::display_template(
776
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_shortcodes_help_tab.template.php',
777
+			$args
778
+		);
779
+	}
780
+
781
+
782
+	public function preview_message_help_tab()
783
+	{
784
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_preview_help_tab.template.php');
785
+	}
786
+
787
+
788
+	public function settings_help_tab()
789
+	{
790
+		$args['img1'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png'
791
+						. '" alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />';
792
+		$args['img2'] = '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png'
793
+						. '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />';
794
+		$args['img3'] = '<div class="switch">'
795
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
796
+						. ' type="checkbox" checked="checked">'
797
+						. '<label for="ee-on-off-toggle-on"></label>'
798
+						. '</div>';
799
+		$args['img4'] = '<div class="switch">'
800
+						. '<input class="ee-on-off-toggle ee-toggle-round-flat"'
801
+						. ' type="checkbox">'
802
+						. '<label for="ee-on-off-toggle-on"></label>'
803
+						. '</div>';
804
+		EEH_Template::display_template(EE_MSG_TEMPLATE_PATH . 'ee_msg_messages_settings_help_tab.template.php', $args);
805
+	}
806
+
807
+
808
+	public function load_scripts_styles()
809
+	{
810
+		wp_register_style('espresso_ee_msg', EE_MSG_ASSETS_URL . 'ee_message_admin.css', EVENT_ESPRESSO_VERSION);
811
+		wp_enqueue_style('espresso_ee_msg');
812
+
813
+		wp_register_script(
814
+			'ee-messages-settings',
815
+			EE_MSG_ASSETS_URL . 'ee-messages-settings.js',
816
+			array('jquery-ui-droppable', 'ee-serialize-full-array'),
817
+			EVENT_ESPRESSO_VERSION,
818
+			true
819
+		);
820
+		wp_register_script(
821
+			'ee-msg-list-table-js',
822
+			EE_MSG_ASSETS_URL . 'ee_message_admin_list_table.js',
823
+			array('ee-dialog'),
824
+			EVENT_ESPRESSO_VERSION
825
+		);
826
+	}
827
+
828
+
829
+	public function load_scripts_styles_default()
830
+	{
831
+		wp_enqueue_script('ee-msg-list-table-js');
832
+	}
833
+
834
+
835
+	public function wp_editor_css($mce_css)
836
+	{
837
+		// if we're on the edit_message_template route
838
+		if ($this->_req_action === 'edit_message_template' && $this->_active_messenger instanceof EE_messenger) {
839
+			$message_type_name = $this->_active_message_type_name;
840
+
841
+			// we're going to REPLACE the existing mce css
842
+			// we need to get the css file location from the active messenger
843
+			$mce_css = $this->_active_messenger->get_variation(
844
+				$this->_template_pack,
845
+				$message_type_name,
846
+				true,
847
+				'wpeditor',
848
+				$this->_variation
849
+			);
850
+		}
851
+
852
+		return $mce_css;
853
+	}
854
+
855
+
856
+	public function load_scripts_styles_edit_message_template()
857
+	{
858
+
859
+		$this->_set_shortcodes();
860
+
861
+		EE_Registry::$i18n_js_strings['confirm_default_reset'] = sprintf(
862
+			esc_html__(
863
+				'Are you sure you want to reset the %s %s message templates?  Remember continuing will reset the templates for all contexts in this messenger and message type group.',
864
+				'event_espresso'
865
+			),
866
+			$this->_message_template_group->messenger_obj()->label['singular'],
867
+			$this->_message_template_group->message_type_obj()->label['singular']
868
+		);
869
+		EE_Registry::$i18n_js_strings['confirm_switch_template_pack'] = esc_html__(
870
+			'Switching the template pack for a messages template will reset the content for the template so the new layout is loaded.  Any custom content in the existing template will be lost. Are you sure you wish to do this?',
871
+			'event_espresso'
872
+		);
873
+		EE_Registry::$i18n_js_strings['server_error'] = esc_html__(
874
+			'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.',
875
+			'event_espresso'
876
+		);
877
+
878
+		wp_register_script(
879
+			'ee_msgs_edit_js',
880
+			EE_MSG_ASSETS_URL . 'ee_message_editor.js',
881
+			array('jquery'),
882
+			EVENT_ESPRESSO_VERSION
883
+		);
884
+
885
+		wp_enqueue_script('ee_admin_js');
886
+		wp_enqueue_script('ee_msgs_edit_js');
887
+
888
+		// add in special css for tiny_mce
889
+		add_filter('mce_css', array($this, 'wp_editor_css'));
890
+	}
891
+
892
+
893
+	public function load_scripts_styles_display_preview_message()
894
+	{
895
+
896
+		$this->_set_message_template_group();
897
+
898
+		if (isset($this->_req_data['messenger'])) {
899
+			$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
900
+				$this->_req_data['messenger']
901
+			);
902
+		}
903
+
904
+		$message_type_name = isset($this->_req_data['message_type']) ? $this->_req_data['message_type'] : '';
905
+
906
+
907
+		wp_enqueue_style(
908
+			'espresso_preview_css',
909
+			$this->_active_messenger->get_variation(
910
+				$this->_template_pack,
911
+				$message_type_name,
912
+				true,
913
+				'preview',
914
+				$this->_variation
915
+			)
916
+		);
917
+	}
918
+
919
+
920
+	public function load_scripts_styles_settings()
921
+	{
922
+		wp_register_style(
923
+			'ee-message-settings',
924
+			EE_MSG_ASSETS_URL . 'ee_message_settings.css',
925
+			array(),
926
+			EVENT_ESPRESSO_VERSION
927
+		);
928
+		wp_enqueue_style('ee-text-links');
929
+		wp_enqueue_style('ee-message-settings');
930
+		wp_enqueue_script('ee-messages-settings');
931
+	}
932
+
933
+
934
+	/**
935
+	 * set views array for List Table
936
+	 */
937
+	public function _set_list_table_views_global_mtps()
938
+	{
939
+		$this->_views = array(
940
+			'in_use' => array(
941
+				'slug'  => 'in_use',
942
+				'label' => esc_html__('In Use', 'event_espresso'),
943
+				'count' => 0,
944
+			),
945
+		);
946
+	}
947
+
948
+
949
+	/**
950
+	 * Set views array for the Custom Template List Table
951
+	 */
952
+	public function _set_list_table_views_custom_mtps()
953
+	{
954
+		$this->_set_list_table_views_global_mtps();
955
+		$this->_views['in_use']['bulk_action'] = array(
956
+			'trash_message_template' => esc_html__('Move to Trash', 'event_espresso'),
957
+		);
958
+	}
959
+
960
+
961
+	/**
962
+	 * set views array for message queue list table
963
+	 *
964
+	 * @throws InvalidDataTypeException
965
+	 * @throws InvalidInterfaceException
966
+	 * @throws InvalidArgumentException
967
+	 * @throws EE_Error
968
+	 * @throws ReflectionException
969
+	 */
970
+	public function _set_list_table_views_default()
971
+	{
972
+		EE_Registry::instance()->load_helper('Template');
973
+
974
+		$common_bulk_actions = EE_Registry::instance()->CAP->current_user_can(
975
+			'ee_send_message',
976
+			'message_list_table_bulk_actions'
977
+		)
978
+			? array(
979
+				'generate_now'          => esc_html__('Generate Now', 'event_espresso'),
980
+				'generate_and_send_now' => esc_html__('Generate and Send Now', 'event_espresso'),
981
+				'queue_for_resending'   => esc_html__('Queue for Resending', 'event_espresso'),
982
+				'send_now'              => esc_html__('Send Now', 'event_espresso'),
983
+			)
984
+			: array();
985
+
986
+		$delete_bulk_action = EE_Registry::instance()->CAP->current_user_can(
987
+			'ee_delete_messages',
988
+			'message_list_table_bulk_actions'
989
+		)
990
+			? array('delete_ee_messages' => esc_html__('Delete Messages', 'event_espresso'))
991
+			: array();
992
+
993
+
994
+		$this->_views = array(
995
+			'all' => array(
996
+				'slug'        => 'all',
997
+				'label'       => esc_html__('All', 'event_espresso'),
998
+				'count'       => 0,
999
+				'bulk_action' => array_merge($common_bulk_actions, $delete_bulk_action),
1000
+			),
1001
+		);
1002
+
1003
+
1004
+		foreach (EEM_Message::instance()->all_statuses() as $status) {
1005
+			if ($status === EEM_Message::status_debug_only && ! EEM_Message::debug()) {
1006
+				continue;
1007
+			}
1008
+			$status_bulk_actions = $common_bulk_actions;
1009
+			// unset bulk actions not applying to status
1010
+			if (! empty($status_bulk_actions)) {
1011
+				switch ($status) {
1012
+					case EEM_Message::status_idle:
1013
+					case EEM_Message::status_resend:
1014
+						$status_bulk_actions['send_now'] = $common_bulk_actions['send_now'];
1015
+						break;
1016
+
1017
+					case EEM_Message::status_failed:
1018
+					case EEM_Message::status_debug_only:
1019
+					case EEM_Message::status_messenger_executing:
1020
+						$status_bulk_actions = array();
1021
+						break;
1022
+
1023
+					case EEM_Message::status_incomplete:
1024
+						unset($status_bulk_actions['queue_for_resending'], $status_bulk_actions['send_now']);
1025
+						break;
1026
+
1027
+					case EEM_Message::status_retry:
1028
+					case EEM_Message::status_sent:
1029
+						unset($status_bulk_actions['generate_now'], $status_bulk_actions['generate_and_send_now']);
1030
+						break;
1031
+				}
1032
+			}
1033
+
1034
+			// skip adding messenger executing status to views because it will be included with the Failed view.
1035
+			if ($status === EEM_Message::status_messenger_executing) {
1036
+				continue;
1037
+			}
1038
+
1039
+			$this->_views[ strtolower($status) ] = array(
1040
+				'slug'        => strtolower($status),
1041
+				'label'       => EEH_Template::pretty_status($status, false, 'sentence'),
1042
+				'count'       => 0,
1043
+				'bulk_action' => array_merge($status_bulk_actions, $delete_bulk_action),
1044
+			);
1045
+		}
1046
+	}
1047
+
1048
+
1049
+	protected function _ee_default_messages_overview_list_table()
1050
+	{
1051
+		$this->_admin_page_title = esc_html__('Default Message Templates', 'event_espresso');
1052
+		$this->display_admin_list_table_page_with_no_sidebar();
1053
+	}
1054
+
1055
+
1056
+	protected function _message_queue_list_table()
1057
+	{
1058
+		$this->_search_btn_label = esc_html__('Message Activity', 'event_espresso');
1059
+		$this->_template_args['per_column'] = 6;
1060
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_message_legend_items());
1061
+		$this->_template_args['before_list_table'] = '<h3>'
1062
+													 . EEM_Message::instance()->get_pretty_label_for_results()
1063
+													 . '</h3>';
1064
+		$this->display_admin_list_table_page_with_no_sidebar();
1065
+	}
1066
+
1067
+
1068
+	protected function _message_legend_items()
1069
+	{
1070
+
1071
+		$action_css_classes = EEH_MSG_Template::get_message_action_icons();
1072
+		$action_items = array();
1073
+
1074
+		foreach ($action_css_classes as $action_item => $action_details) {
1075
+			if ($action_item === 'see_notifications_for') {
1076
+				continue;
1077
+			}
1078
+			$action_items[ $action_item ] = array(
1079
+				'class' => $action_details['css_class'],
1080
+				'desc'  => $action_details['label'],
1081
+			);
1082
+		}
1083
+
1084
+		/** @type array $status_items status legend setup */
1085
+		$status_items = array(
1086
+			'incomplete_status'          => array(
1087
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_incomplete,
1088
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_incomplete, false, 'sentence'),
1089
+			),
1090
+			'idle_status'                => array(
1091
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_idle,
1092
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_idle, false, 'sentence'),
1093
+			),
1094
+			'resend_status'              => array(
1095
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_resend,
1096
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_resend, false, 'sentence'),
1097
+			),
1098
+			'messenger_executing_status' => array(
1099
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_messenger_executing,
1100
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_messenger_executing, false, 'sentence'),
1101
+			),
1102
+			'sent_status'                => array(
1103
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_sent,
1104
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_sent, false, 'sentence'),
1105
+			),
1106
+			'retry_status'               => array(
1107
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_retry,
1108
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_retry, false, 'sentence'),
1109
+			),
1110
+			'failed_status'              => array(
1111
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_failed,
1112
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_failed, false, 'sentence'),
1113
+			),
1114
+		);
1115
+		if (EEM_Message::debug()) {
1116
+			$status_items['debug_only_status'] = array(
1117
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Message::status_debug_only,
1118
+				'desc'  => EEH_Template::pretty_status(EEM_Message::status_debug_only, false, 'sentence'),
1119
+			);
1120
+		}
1121
+
1122
+		return array_merge($action_items, $status_items);
1123
+	}
1124
+
1125
+
1126
+	protected function _custom_mtps_preview()
1127
+	{
1128
+		$this->_admin_page_title = esc_html__('Custom Message Templates (Preview)', 'event_espresso');
1129
+		$this->_template_args['preview_img'] = '<img src="' . EE_MSG_ASSETS_URL . 'images/custom_mtps_preview.png"'
1130
+											   . ' alt="' . esc_attr__(
1131
+												   'Preview Custom Message Templates screenshot',
1132
+												   'event_espresso'
1133
+											   ) . '" />';
1134
+		$this->_template_args['preview_text'] = '<strong>'
1135
+												. esc_html__(
1136
+													'Custom Message Templates is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Custom Message Templates feature, you are able to create custom message templates and assign them on a per-event basis.',
1137
+													'event_espresso'
1138
+												)
1139
+												. '</strong>';
1140
+
1141
+		$this->display_admin_caf_preview_page('custom_message_types', false);
1142
+	}
1143
+
1144
+
1145
+	/**
1146
+	 * get_message_templates
1147
+	 * This gets all the message templates for listing on the overview list.
1148
+	 *
1149
+	 * @access public
1150
+	 * @param int    $perpage the amount of templates groups to show per page
1151
+	 * @param string $type    the current _view we're getting templates for
1152
+	 * @param bool   $count   return count?
1153
+	 * @param bool   $all     disregard any paging info (get all data);
1154
+	 * @param bool   $global  whether to return just global (true) or custom templates (false)
1155
+	 * @return array
1156
+	 * @throws EE_Error
1157
+	 * @throws InvalidArgumentException
1158
+	 * @throws InvalidDataTypeException
1159
+	 * @throws InvalidInterfaceException
1160
+	 */
1161
+	public function get_message_templates(
1162
+		$perpage = 10,
1163
+		$type = 'in_use',
1164
+		$count = false,
1165
+		$all = false,
1166
+		$global = true
1167
+	) {
1168
+
1169
+		$MTP = EEM_Message_Template_Group::instance();
1170
+
1171
+		$this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? 'GRP_ID' : $this->_req_data['orderby'];
1172
+		$orderby = $this->_req_data['orderby'];
1173
+
1174
+		$order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
1175
+			? $this->_req_data['order']
1176
+			: 'ASC';
1177
+
1178
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1179
+			? $this->_req_data['paged']
1180
+			: 1;
1181
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1182
+			? $this->_req_data['perpage']
1183
+			: $perpage;
1184
+
1185
+		$offset = ($current_page - 1) * $per_page;
1186
+		$limit = $all ? null : array($offset, $per_page);
1187
+
1188
+
1189
+		// options will match what is in the _views array property
1190
+		switch ($type) {
1191
+			case 'in_use':
1192
+				$templates = $MTP->get_all_active_message_templates($orderby, $order, $limit, $count, $global, true);
1193
+				break;
1194
+			default:
1195
+				$templates = $MTP->get_all_trashed_grouped_message_templates($orderby, $order, $limit, $count, $global);
1196
+		}
1197
+
1198
+		return $templates;
1199
+	}
1200
+
1201
+
1202
+	/**
1203
+	 * filters etc might need a list of installed message_types
1204
+	 *
1205
+	 * @return array an array of message type objects
1206
+	 */
1207
+	public function get_installed_message_types()
1208
+	{
1209
+		$installed_message_types = $this->_message_resource_manager->installed_message_types();
1210
+		$installed = array();
1211
+
1212
+		foreach ($installed_message_types as $message_type) {
1213
+			$installed[ $message_type->name ] = $message_type;
1214
+		}
1215
+
1216
+		return $installed;
1217
+	}
1218
+
1219
+
1220
+	/**
1221
+	 * _add_message_template
1222
+	 *
1223
+	 * This is used when creating a custom template. All Custom Templates start based off another template.
1224
+	 *
1225
+	 * @param string $message_type
1226
+	 * @param string $messenger
1227
+	 * @param string $GRP_ID
1228
+	 *
1229
+	 * @throws EE_error
1230
+	 */
1231
+	protected function _add_message_template($message_type = '', $messenger = '', $GRP_ID = '')
1232
+	{
1233
+		// set values override any request data
1234
+		$message_type = ! empty($message_type) ? $message_type : '';
1235
+		$message_type = empty($message_type) && ! empty($this->_req_data['message_type'])
1236
+			? $this->_req_data['message_type']
1237
+			: $message_type;
1238
+
1239
+		$messenger = ! empty($messenger) ? $messenger : '';
1240
+		$messenger = empty($messenger) && ! empty($this->_req_data['messenger'])
1241
+			? $this->_req_data['messenger']
1242
+			: $messenger;
1243
+
1244
+		$GRP_ID = ! empty($GRP_ID) ? $GRP_ID : '';
1245
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : $GRP_ID;
1246
+
1247
+		// we need messenger and message type.  They should be coming from the event editor. If not here then return error
1248
+		if (empty($message_type) || empty($messenger)) {
1249
+			throw new EE_Error(
1250
+				esc_html__(
1251
+					'Sorry, but we can\'t create new templates because we\'re missing the messenger or message type',
1252
+					'event_espresso'
1253
+				)
1254
+			);
1255
+		}
1256
+
1257
+		// we need the GRP_ID for the template being used as the base for the new template
1258
+		if (empty($GRP_ID)) {
1259
+			throw new EE_Error(
1260
+				esc_html__(
1261
+					'In order to create a custom message template the GRP_ID of the template being used as a base is needed',
1262
+					'event_espresso'
1263
+				)
1264
+			);
1265
+		}
1266
+
1267
+		// let's just make sure the template gets generated!
1268
+
1269
+		// we need to reassign some variables for what the insert is expecting
1270
+		$this->_req_data['MTP_messenger'] = $messenger;
1271
+		$this->_req_data['MTP_message_type'] = $message_type;
1272
+		$this->_req_data['GRP_ID'] = $GRP_ID;
1273
+		$this->_insert_or_update_message_template(true);
1274
+	}
1275
+
1276
+
1277
+	/**
1278
+	 * public wrapper for the _add_message_template method
1279
+	 *
1280
+	 * @param string $message_type     message type slug
1281
+	 * @param string $messenger        messenger slug
1282
+	 * @param int    $GRP_ID           GRP_ID for the related message template group this new template will be based
1283
+	 *                                 off of.
1284
+	 * @throws EE_error
1285
+	 */
1286
+	public function add_message_template($message_type, $messenger, $GRP_ID)
1287
+	{
1288
+		$this->_add_message_template($message_type, $messenger, $GRP_ID);
1289
+	}
1290
+
1291
+
1292
+	/**
1293
+	 * _edit_message_template
1294
+	 *
1295
+	 * @access protected
1296
+	 * @return void
1297
+	 * @throws InvalidIdentifierException
1298
+	 * @throws DomainException
1299
+	 * @throws EE_Error
1300
+	 * @throws InvalidArgumentException
1301
+	 * @throws ReflectionException
1302
+	 * @throws InvalidDataTypeException
1303
+	 * @throws InvalidInterfaceException
1304
+	 */
1305
+	protected function _edit_message_template()
1306
+	{
1307
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1308
+		$template_fields = '';
1309
+		$sidebar_fields = '';
1310
+		// we filter the tinyMCE settings to remove the validation since message templates by their nature will not have
1311
+		// valid html in the templates.
1312
+		add_filter('tiny_mce_before_init', array($this, 'filter_tinymce_init'), 10, 2);
1313
+
1314
+		$GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
1315
+			? absint($this->_req_data['id'])
1316
+			: false;
1317
+
1318
+		$EVT_ID = isset($this->_req_data['evt_id']) && ! empty($this->_req_data['evt_id'])
1319
+		? absint($this->_req_data['evt_id'])
1320
+		: false;
1321
+
1322
+		$this->_set_shortcodes(); // this also sets the _message_template property.
1323
+		$message_template_group = $this->_message_template_group;
1324
+		$c_label = $message_template_group->context_label();
1325
+		$c_config = $message_template_group->contexts_config();
1326
+
1327
+		reset($c_config);
1328
+		$context = isset($this->_req_data['context']) && ! empty($this->_req_data['context'])
1329
+			? strtolower($this->_req_data['context'])
1330
+			: key($c_config);
1331
+
1332
+
1333
+		if (empty($GRP_ID)) {
1334
+			$action = 'insert_message_template';
1335
+			$edit_message_template_form_url = add_query_arg(
1336
+				array('action' => $action, 'noheader' => true),
1337
+				EE_MSG_ADMIN_URL
1338
+			);
1339
+		} else {
1340
+			$action = 'update_message_template';
1341
+			$edit_message_template_form_url = add_query_arg(
1342
+				array('action' => $action, 'noheader' => true),
1343
+				EE_MSG_ADMIN_URL
1344
+			);
1345
+		}
1346
+
1347
+		// set active messenger for this view
1348
+		$this->_active_messenger = $this->_message_resource_manager->get_active_messenger(
1349
+			$message_template_group->messenger()
1350
+		);
1351
+		$this->_active_message_type_name = $message_template_group->message_type();
1352
+
1353
+
1354
+		// Do we have any validation errors?
1355
+		$validators = $this->_get_transient();
1356
+		$v_fields = ! empty($validators) ? array_keys($validators) : array();
1357
+
1358
+
1359
+		// we need to assemble the title from Various details
1360
+		$context_label = sprintf(
1361
+			esc_html__('(%s %s)', 'event_espresso'),
1362
+			$c_config[ $context ]['label'],
1363
+			ucwords($c_label['label'])
1364
+		);
1365
+
1366
+		$title = sprintf(
1367
+			esc_html__(' %s %s Template %s', 'event_espresso'),
1368
+			ucwords($message_template_group->messenger_obj()->label['singular']),
1369
+			ucwords($message_template_group->message_type_obj()->label['singular']),
1370
+			$context_label
1371
+		);
1372
+
1373
+		$this->_template_args['GRP_ID'] = $GRP_ID;
1374
+		$this->_template_args['message_template'] = $message_template_group;
1375
+		$this->_template_args['is_extra_fields'] = false;
1376
+
1377
+
1378
+		// let's get EEH_MSG_Template so we can get template form fields
1379
+		$template_field_structure = EEH_MSG_Template::get_fields(
1380
+			$message_template_group->messenger(),
1381
+			$message_template_group->message_type()
1382
+		);
1383
+
1384
+		if (! $template_field_structure) {
1385
+			$template_field_structure = false;
1386
+			$template_fields = esc_html__(
1387
+				'There was an error in assembling the fields for this display (you should see an error message)',
1388
+				'event_espresso'
1389
+			);
1390
+		}
1391
+
1392
+
1393
+		$message_templates = $message_template_group->context_templates();
1394
+
1395
+
1396
+		// if we have the extra key.. then we need to remove the content index from the template_field_structure as it
1397
+		// will get handled in the "extra" array.
1398
+		if (is_array($template_field_structure[ $context ]) && isset($template_field_structure[ $context ]['extra'])) {
1399
+			foreach ($template_field_structure[ $context ]['extra'] as $reference_field => $new_fields) {
1400
+				unset($template_field_structure[ $context ][ $reference_field ]);
1401
+			}
1402
+		}
1403
+
1404
+		// let's loop through the template_field_structure and actually assemble the input fields!
1405
+		if (! empty($template_field_structure)) {
1406
+			foreach ($template_field_structure[ $context ] as $template_field => $field_setup_array) {
1407
+				// if this is an 'extra' template field then we need to remove any existing fields that are keyed up in
1408
+				// the extra array and reset them.
1409
+				if ($template_field === 'extra') {
1410
+					$this->_template_args['is_extra_fields'] = true;
1411
+					foreach ($field_setup_array as $reference_field => $new_fields_array) {
1412
+						$message_template = $message_templates[ $context ][ $reference_field ];
1413
+						$content = $message_template instanceof EE_Message_Template
1414
+							? $message_template->get('MTP_content')
1415
+							: '';
1416
+						foreach ($new_fields_array as $extra_field => $extra_array) {
1417
+							// let's verify if we need this extra field via the shortcodes parameter.
1418
+							$continue = false;
1419
+							if (isset($extra_array['shortcodes_required'])) {
1420
+								foreach ((array) $extra_array['shortcodes_required'] as $shortcode) {
1421
+									if (! array_key_exists($shortcode, $this->_shortcodes)) {
1422
+										$continue = true;
1423
+									}
1424
+								}
1425
+								if ($continue) {
1426
+									continue;
1427
+								}
1428
+							}
1429
+
1430
+							$field_id = $reference_field
1431
+										. '-'
1432
+										. $extra_field
1433
+										. '-content';
1434
+							$template_form_fields[ $field_id ] = $extra_array;
1435
+							$template_form_fields[ $field_id ]['name'] = 'MTP_template_fields['
1436
+																		 . $reference_field
1437
+																		 . '][content]['
1438
+																		 . $extra_field . ']';
1439
+							$css_class = isset($extra_array['css_class'])
1440
+								? $extra_array['css_class']
1441
+								: '';
1442
+
1443
+							$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1444
+																			  && in_array($extra_field, $v_fields, true)
1445
+																			  &&
1446
+																			  (
1447
+																				  is_array($validators[ $extra_field ])
1448
+																				  && isset($validators[ $extra_field ]['msg'])
1449
+																			  )
1450
+								? 'validate-error ' . $css_class
1451
+								: $css_class;
1452
+
1453
+							$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1454
+																		  && isset($content[ $extra_field ])
1455
+								? $content[ $extra_field ]
1456
+								: '';
1457
+
1458
+							// do we have a validation error?  if we do then let's use that value instead
1459
+							$template_form_fields[ $field_id ]['value'] = isset($validators[ $extra_field ])
1460
+								? $validators[ $extra_field ]['value']
1461
+								: $template_form_fields[ $field_id ]['value'];
1462
+
1463
+
1464
+							$template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1465
+
1466
+							// shortcode selector
1467
+							$field_name_to_use = $extra_field === 'main'
1468
+								? 'content'
1469
+								: $extra_field;
1470
+							$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1471
+								$field_name_to_use,
1472
+								$field_id
1473
+							);
1474
+
1475
+							if (isset($extra_array['input']) && $extra_array['input'] === 'wp_editor') {
1476
+								// we want to decode the entities
1477
+								$template_form_fields[ $field_id ]['value'] = $template_form_fields[ $field_id ]['value'];
1478
+							}/**/
1479
+						}
1480
+						$templatefield_MTP_id = $reference_field . '-MTP_ID';
1481
+						$templatefield_templatename_id = $reference_field . '-name';
1482
+
1483
+						$template_form_fields[ $templatefield_MTP_id ] = array(
1484
+							'name'       => 'MTP_template_fields[' . $reference_field . '][MTP_ID]',
1485
+							'label'      => null,
1486
+							'input'      => 'hidden',
1487
+							'type'       => 'int',
1488
+							'required'   => false,
1489
+							'validation' => false,
1490
+							'value'      => ! empty($message_templates) ? $message_template->ID() : '',
1491
+							'css_class'  => '',
1492
+							'format'     => '%d',
1493
+							'db-col'     => 'MTP_ID',
1494
+						);
1495
+
1496
+						$template_form_fields[ $templatefield_templatename_id ] = array(
1497
+							'name'       => 'MTP_template_fields[' . $reference_field . '][name]',
1498
+							'label'      => null,
1499
+							'input'      => 'hidden',
1500
+							'type'       => 'string',
1501
+							'required'   => false,
1502
+							'validation' => true,
1503
+							'value'      => $reference_field,
1504
+							'css_class'  => '',
1505
+							'format'     => '%s',
1506
+							'db-col'     => 'MTP_template_field',
1507
+						);
1508
+					}
1509
+					continue; // skip the next stuff, we got the necessary fields here for this dataset.
1510
+				} else {
1511
+					$field_id = $template_field . '-content';
1512
+					$template_form_fields[ $field_id ] = $field_setup_array;
1513
+					$template_form_fields[ $field_id ]['name'] = 'MTP_template_fields[' . $template_field . '][content]';
1514
+					$message_template = isset($message_templates[ $context ][ $template_field ])
1515
+						? $message_templates[ $context ][ $template_field ]
1516
+						: null;
1517
+					$template_form_fields[ $field_id ]['value'] = ! empty($message_templates)
1518
+																  && is_array($message_templates[ $context ])
1519
+																  && $message_template instanceof EE_Message_Template
1520
+						? $message_template->get('MTP_content')
1521
+						: '';
1522
+
1523
+					// do we have a validator error for this field?  if we do then we'll use that value instead
1524
+					$template_form_fields[ $field_id ]['value'] = isset($validators[ $template_field ])
1525
+						? $validators[ $template_field ]['value']
1526
+						: $template_form_fields[ $field_id ]['value'];
1527
+
1528
+
1529
+					$template_form_fields[ $field_id ]['db-col'] = 'MTP_content';
1530
+					$css_class = isset($field_setup_array['css_class'])
1531
+						? $field_setup_array['css_class']
1532
+						: '';
1533
+					$template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields)
1534
+																	  && in_array($template_field, $v_fields, true)
1535
+																	  && isset($validators[ $template_field ]['msg'])
1536
+						? 'validate-error ' . $css_class
1537
+						: $css_class;
1538
+
1539
+					// shortcode selector
1540
+					$template_form_fields[ $field_id ]['append_content'] = $this->_get_shortcode_selector(
1541
+						$template_field,
1542
+						$field_id
1543
+					);
1544
+				}
1545
+
1546
+				// k took care of content field(s) now let's take care of others.
1547
+
1548
+				$templatefield_MTP_id = $template_field . '-MTP_ID';
1549
+				$templatefield_field_templatename_id = $template_field . '-name';
1550
+
1551
+				// foreach template field there are actually two form fields created
1552
+				$template_form_fields[ $templatefield_MTP_id ] = array(
1553
+					'name'       => 'MTP_template_fields[' . $template_field . '][MTP_ID]',
1554
+					'label'      => null,
1555
+					'input'      => 'hidden',
1556
+					'type'       => 'int',
1557
+					'required'   => false,
1558
+					'validation' => true,
1559
+					'value'      => $message_template instanceof EE_Message_Template ? $message_template->ID() : '',
1560
+					'css_class'  => '',
1561
+					'format'     => '%d',
1562
+					'db-col'     => 'MTP_ID',
1563
+				);
1564
+
1565
+				$template_form_fields[ $templatefield_field_templatename_id ] = array(
1566
+					'name'       => 'MTP_template_fields[' . $template_field . '][name]',
1567
+					'label'      => null,
1568
+					'input'      => 'hidden',
1569
+					'type'       => 'string',
1570
+					'required'   => false,
1571
+					'validation' => true,
1572
+					'value'      => $template_field,
1573
+					'css_class'  => '',
1574
+					'format'     => '%s',
1575
+					'db-col'     => 'MTP_template_field',
1576
+				);
1577
+			}
1578
+
1579
+			// add other fields
1580
+			$template_form_fields['ee-msg-current-context'] = array(
1581
+				'name'       => 'MTP_context',
1582
+				'label'      => null,
1583
+				'input'      => 'hidden',
1584
+				'type'       => 'string',
1585
+				'required'   => false,
1586
+				'validation' => true,
1587
+				'value'      => $context,
1588
+				'css_class'  => '',
1589
+				'format'     => '%s',
1590
+				'db-col'     => 'MTP_context',
1591
+			);
1592
+
1593
+			$template_form_fields['ee-msg-grp-id'] = array(
1594
+				'name'       => 'GRP_ID',
1595
+				'label'      => null,
1596
+				'input'      => 'hidden',
1597
+				'type'       => 'int',
1598
+				'required'   => false,
1599
+				'validation' => true,
1600
+				'value'      => $GRP_ID,
1601
+				'css_class'  => '',
1602
+				'format'     => '%d',
1603
+				'db-col'     => 'GRP_ID',
1604
+			);
1605
+
1606
+			$template_form_fields['ee-msg-messenger'] = array(
1607
+				'name'       => 'MTP_messenger',
1608
+				'label'      => null,
1609
+				'input'      => 'hidden',
1610
+				'type'       => 'string',
1611
+				'required'   => false,
1612
+				'validation' => true,
1613
+				'value'      => $message_template_group->messenger(),
1614
+				'css_class'  => '',
1615
+				'format'     => '%s',
1616
+				'db-col'     => 'MTP_messenger',
1617
+			);
1618
+
1619
+			$template_form_fields['ee-msg-message-type'] = array(
1620
+				'name'       => 'MTP_message_type',
1621
+				'label'      => null,
1622
+				'input'      => 'hidden',
1623
+				'type'       => 'string',
1624
+				'required'   => false,
1625
+				'validation' => true,
1626
+				'value'      => $message_template_group->message_type(),
1627
+				'css_class'  => '',
1628
+				'format'     => '%s',
1629
+				'db-col'     => 'MTP_message_type',
1630
+			);
1631
+
1632
+			$sidebar_form_fields['ee-msg-is-global'] = array(
1633
+				'name'       => 'MTP_is_global',
1634
+				'label'      => esc_html__('Global Template', 'event_espresso'),
1635
+				'input'      => 'hidden',
1636
+				'type'       => 'int',
1637
+				'required'   => false,
1638
+				'validation' => true,
1639
+				'value'      => $message_template_group->get('MTP_is_global'),
1640
+				'css_class'  => '',
1641
+				'format'     => '%d',
1642
+				'db-col'     => 'MTP_is_global',
1643
+			);
1644
+
1645
+			$sidebar_form_fields['ee-msg-is-override'] = array(
1646
+				'name'       => 'MTP_is_override',
1647
+				'label'      => esc_html__('Override all custom', 'event_espresso'),
1648
+				'input'      => $message_template_group->is_global() ? 'checkbox' : 'hidden',
1649
+				'type'       => 'int',
1650
+				'required'   => false,
1651
+				'validation' => true,
1652
+				'value'      => $message_template_group->get('MTP_is_override'),
1653
+				'css_class'  => '',
1654
+				'format'     => '%d',
1655
+				'db-col'     => 'MTP_is_override',
1656
+			);
1657
+
1658
+			$sidebar_form_fields['ee-msg-is-active'] = array(
1659
+				'name'       => 'MTP_is_active',
1660
+				'label'      => esc_html__('Active Template', 'event_espresso'),
1661
+				'input'      => 'hidden',
1662
+				'type'       => 'int',
1663
+				'required'   => false,
1664
+				'validation' => true,
1665
+				'value'      => $message_template_group->is_active(),
1666
+				'css_class'  => '',
1667
+				'format'     => '%d',
1668
+				'db-col'     => 'MTP_is_active',
1669
+			);
1670
+
1671
+			$sidebar_form_fields['ee-msg-deleted'] = array(
1672
+				'name'       => 'MTP_deleted',
1673
+				'label'      => null,
1674
+				'input'      => 'hidden',
1675
+				'type'       => 'int',
1676
+				'required'   => false,
1677
+				'validation' => true,
1678
+				'value'      => $message_template_group->get('MTP_deleted'),
1679
+				'css_class'  => '',
1680
+				'format'     => '%d',
1681
+				'db-col'     => 'MTP_deleted',
1682
+			);
1683
+			$sidebar_form_fields['ee-msg-author'] = array(
1684
+				'name'       => 'MTP_user_id',
1685
+				'label'      => esc_html__('Author', 'event_espresso'),
1686
+				'input'      => 'hidden',
1687
+				'type'       => 'int',
1688
+				'required'   => false,
1689
+				'validation' => false,
1690
+				'value'      => $message_template_group->user(),
1691
+				'format'     => '%d',
1692
+				'db-col'     => 'MTP_user_id',
1693
+			);
1694
+
1695
+			$sidebar_form_fields['ee-msg-route'] = array(
1696
+				'name'  => 'action',
1697
+				'input' => 'hidden',
1698
+				'type'  => 'string',
1699
+				'value' => $action,
1700
+			);
1701
+
1702
+			$sidebar_form_fields['ee-msg-id'] = array(
1703
+				'name'  => 'id',
1704
+				'input' => 'hidden',
1705
+				'type'  => 'int',
1706
+				'value' => $GRP_ID,
1707
+			);
1708
+			$sidebar_form_fields['ee-msg-evt-nonce'] = array(
1709
+				'name'  => $action . '_nonce',
1710
+				'input' => 'hidden',
1711
+				'type'  => 'string',
1712
+				'value' => wp_create_nonce($action . '_nonce'),
1713
+			);
1714
+
1715
+			if (isset($this->_req_data['template_switch']) && $this->_req_data['template_switch']) {
1716
+				$sidebar_form_fields['ee-msg-template-switch'] = array(
1717
+					'name'  => 'template_switch',
1718
+					'input' => 'hidden',
1719
+					'type'  => 'int',
1720
+					'value' => 1,
1721
+				);
1722
+			}
1723
+
1724
+
1725
+			$template_fields = $this->_generate_admin_form_fields($template_form_fields);
1726
+			$sidebar_fields = $this->_generate_admin_form_fields($sidebar_form_fields);
1727
+		} //end if ( !empty($template_field_structure) )
1728
+
1729
+		// set extra content for publish box
1730
+		$this->_template_args['publish_box_extra_content'] = $sidebar_fields;
1731
+		$this->_set_publish_post_box_vars(
1732
+			'id',
1733
+			$GRP_ID,
1734
+			false,
1735
+			add_query_arg(
1736
+				array('action' => 'global_mtps'),
1737
+				$this->_admin_base_url
1738
+			)
1739
+		);
1740
+
1741
+		// add preview button
1742
+		$preview_url = parent::add_query_args_and_nonce(
1743
+			array(
1744
+				'message_type' => $message_template_group->message_type(),
1745
+				'messenger'    => $message_template_group->messenger(),
1746
+				'context'      => $context,
1747
+				'GRP_ID'       => $GRP_ID,
1748
+				'evt_id'       => $EVT_ID,
1749
+				'action'       => 'preview_message',
1750
+			),
1751
+			$this->_admin_base_url
1752
+		);
1753
+		$preview_button = '<a href="' . $preview_url . '" class="button-secondary messages-preview-button">'
1754
+						  . esc_html__('Preview', 'event_espresso')
1755
+						  . '</a>';
1756
+
1757
+
1758
+		// setup context switcher
1759
+		$context_switcher_args = array(
1760
+			'page'    => 'espresso_messages',
1761
+			'action'  => 'edit_message_template',
1762
+			'id'      => $GRP_ID,
1763
+			'evt_id'  => $EVT_ID,
1764
+			'context' => $context,
1765
+			'extra'   => $preview_button,
1766
+		);
1767
+		$this->_set_context_switcher($message_template_group, $context_switcher_args);
1768
+
1769
+
1770
+		// main box
1771
+		$this->_template_args['template_fields'] = $template_fields;
1772
+		$this->_template_args['sidebar_box_id'] = 'details';
1773
+		$this->_template_args['action'] = $action;
1774
+		$this->_template_args['context'] = $context;
1775
+		$this->_template_args['edit_message_template_form_url'] = $edit_message_template_form_url;
1776
+		$this->_template_args['learn_more_about_message_templates_link'] =
1777
+			$this->_learn_more_about_message_templates_link();
1778
+
1779
+
1780
+		$this->_template_args['before_admin_page_content'] = $this->add_context_switcher();
1781
+		$this->_template_args['before_admin_page_content'] .= $this->add_active_context_element(
1782
+			$message_template_group,
1783
+			$context,
1784
+			$context_label
1785
+		);
1786
+		$this->_template_args['before_admin_page_content'] .= $this->_add_form_element_before();
1787
+		$this->_template_args['after_admin_page_content'] = $this->_add_form_element_after();
1788
+
1789
+		$this->_template_path = $this->_template_args['GRP_ID']
1790
+			? EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_edit_meta_box.template.php'
1791
+			: EE_MSG_TEMPLATE_PATH . 'ee_msg_details_main_add_meta_box.template.php';
1792
+
1793
+		// send along EE_Message_Template_Group object for further template use.
1794
+		$this->_template_args['MTP'] = $message_template_group;
1795
+
1796
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
1797
+			$this->_template_path,
1798
+			$this->_template_args,
1799
+			true
1800
+		);
1801
+
1802
+
1803
+		// finally, let's set the admin_page title
1804
+		$this->_admin_page_title = sprintf(__('Editing %s', 'event_espresso'), $title);
1805
+
1806
+
1807
+		// we need to take care of setting the shortcodes property for use elsewhere.
1808
+		$this->_set_shortcodes();
1809
+
1810
+
1811
+		// final template wrapper
1812
+		$this->display_admin_page_with_sidebar();
1813
+	}
1814
+
1815
+
1816
+	public function filter_tinymce_init($mceInit, $editor_id)
1817
+	{
1818
+		return $mceInit;
1819
+	}
1820
+
1821
+
1822
+	public function add_context_switcher()
1823
+	{
1824
+		return $this->_context_switcher;
1825
+	}
1826
+
1827
+
1828
+	/**
1829
+	 * Adds the activation/deactivation toggle for the message template context.
1830
+	 *
1831
+	 * @param EE_Message_Template_Group $message_template_group
1832
+	 * @param string                    $context
1833
+	 * @param string                    $context_label
1834
+	 * @return string
1835
+	 * @throws DomainException
1836
+	 * @throws EE_Error
1837
+	 * @throws InvalidIdentifierException
1838
+	 */
1839
+	protected function add_active_context_element(
1840
+		EE_Message_Template_Group $message_template_group,
1841
+		$context,
1842
+		$context_label
1843
+	) {
1844
+		$template_args = array(
1845
+			'context'                   => $context,
1846
+			'nonce'                     => wp_create_nonce('activate_' . $context . '_toggle_nonce'),
1847
+			'is_active'                 => $message_template_group->is_context_active($context),
1848
+			'on_off_action'             => $message_template_group->is_context_active($context)
1849
+				? 'context-off'
1850
+				: 'context-on',
1851
+			'context_label'             => str_replace(array('(', ')'), '', $context_label),
1852
+			'message_template_group_id' => $message_template_group->ID(),
1853
+		);
1854
+		return EEH_Template::display_template(
1855
+			EE_MSG_TEMPLATE_PATH . 'ee_msg_editor_active_context_element.template.php',
1856
+			$template_args,
1857
+			true
1858
+		);
1859
+	}
1860
+
1861
+
1862
+	/**
1863
+	 * Ajax callback for `toggle_context_template` ajax action.
1864
+	 * Handles toggling the message context on or off.
1865
+	 *
1866
+	 * @throws EE_Error
1867
+	 * @throws InvalidArgumentException
1868
+	 * @throws InvalidDataTypeException
1869
+	 * @throws InvalidIdentifierException
1870
+	 * @throws InvalidInterfaceException
1871
+	 */
1872
+	public function toggle_context_template()
1873
+	{
1874
+		$success = true;
1875
+		// check for required data
1876
+		if (
1877
+			! isset(
1878
+				$this->_req_data['message_template_group_id'],
1879
+				$this->_req_data['context'],
1880
+				$this->_req_data['status']
1881
+			)
1882
+		) {
1883
+			EE_Error::add_error(
1884
+				esc_html__('Required data for doing this action is not available.', 'event_espresso'),
1885
+				__FILE__,
1886
+				__FUNCTION__,
1887
+				__LINE__
1888
+			);
1889
+			$success = false;
1890
+		}
1891
+
1892
+		$nonce = isset($this->_req_data['toggle_context_nonce'])
1893
+			? sanitize_text_field($this->_req_data['toggle_context_nonce'])
1894
+			: '';
1895
+		$nonce_ref = 'activate_' . $this->_req_data['context'] . '_toggle_nonce';
1896
+		$this->_verify_nonce($nonce, $nonce_ref);
1897
+		$status = $this->_req_data['status'];
1898
+		if ($status !== 'off' && $status !== 'on') {
1899
+			EE_Error::add_error(
1900
+				sprintf(
1901
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
1902
+					$this->_req_data['status']
1903
+				),
1904
+				__FILE__,
1905
+				__FUNCTION__,
1906
+				__LINE__
1907
+			);
1908
+			$success = false;
1909
+		}
1910
+		$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID(
1911
+			$this->_req_data['message_template_group_id']
1912
+		);
1913
+		if (! $message_template_group instanceof EE_Message_Template_Group) {
1914
+			EE_Error::add_error(
1915
+				sprintf(
1916
+					esc_html__(
1917
+						'Unable to change the active state because the given id "%1$d" does not match a valid "%2$s"',
1918
+						'event_espresso'
1919
+					),
1920
+					$this->_req_data['message_template_group_id'],
1921
+					'EE_Message_Template_Group'
1922
+				),
1923
+				__FILE__,
1924
+				__FUNCTION__,
1925
+				__LINE__
1926
+			);
1927
+			$success = false;
1928
+		}
1929
+		if ($success) {
1930
+			$success = $status === 'off'
1931
+				? $message_template_group->deactivate_context($this->_req_data['context'])
1932
+				: $message_template_group->activate_context($this->_req_data['context']);
1933
+		}
1934
+		$this->_template_args['success'] = $success;
1935
+		$this->_return_json();
1936
+	}
1937
+
1938
+
1939
+	public function _add_form_element_before()
1940
+	{
1941
+		return '<form method="post" action="'
1942
+			   . $this->_template_args["edit_message_template_form_url"]
1943
+			   . '" id="ee-msg-edit-frm">';
1944
+	}
1945
+
1946
+	public function _add_form_element_after()
1947
+	{
1948
+		return '</form>';
1949
+	}
1950
+
1951
+
1952
+	/**
1953
+	 * This executes switching the template pack for a message template.
1954
+	 *
1955
+	 * @since 4.5.0
1956
+	 * @throws EE_Error
1957
+	 * @throws InvalidDataTypeException
1958
+	 * @throws InvalidInterfaceException
1959
+	 * @throws InvalidArgumentException
1960
+	 * @throws ReflectionException
1961
+	 */
1962
+	public function switch_template_pack()
1963
+	{
1964
+		$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
1965
+		$template_pack = ! empty($this->_req_data['template_pack']) ? $this->_req_data['template_pack'] : '';
1966
+
1967
+		// verify we have needed values.
1968
+		if (empty($GRP_ID) || empty($template_pack)) {
1969
+			$this->_template_args['error'] = true;
1970
+			EE_Error::add_error(
1971
+				esc_html__('The required date for switching templates is not available.', 'event_espresso'),
1972
+				__FILE__,
1973
+				__FUNCTION__,
1974
+				__LINE__
1975
+			);
1976
+		} else {
1977
+			// get template, set the new template_pack and then reset to default
1978
+			/** @type EE_Message_Template_Group $message_template_group */
1979
+			$message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID);
1980
+
1981
+			$message_template_group->set_template_pack_name($template_pack);
1982
+			$this->_req_data['msgr'] = $message_template_group->messenger();
1983
+			$this->_req_data['mt'] = $message_template_group->message_type();
1984
+
1985
+			$query_args = $this->_reset_to_default_template();
1986
+
1987
+			if (empty($query_args['id'])) {
1988
+				EE_Error::add_error(
1989
+					esc_html__(
1990
+						'Something went wrong with switching the template pack. Please try again or contact EE support',
1991
+						'event_espresso'
1992
+					),
1993
+					__FILE__,
1994
+					__FUNCTION__,
1995
+					__LINE__
1996
+				);
1997
+				$this->_template_args['error'] = true;
1998
+			} else {
1999
+				$template_label = $message_template_group->get_template_pack()->label;
2000
+				$template_pack_labels = $message_template_group->messenger_obj()->get_supports_labels();
2001
+				EE_Error::add_success(
2002
+					sprintf(
2003
+						esc_html__(
2004
+							'This message template has been successfully switched to use the %1$s %2$s.  Please wait while the page reloads with your new template.',
2005
+							'event_espresso'
2006
+						),
2007
+						$template_label,
2008
+						$template_pack_labels->template_pack
2009
+					)
2010
+				);
2011
+				// generate the redirect url for js.
2012
+				$url = self::add_query_args_and_nonce(
2013
+					$query_args,
2014
+					$this->_admin_base_url
2015
+				);
2016
+				$this->_template_args['data']['redirect_url'] = $url;
2017
+				$this->_template_args['success'] = true;
2018
+			}
2019
+
2020
+			$this->_return_json();
2021
+		}
2022
+	}
2023
+
2024
+
2025
+	/**
2026
+	 * This handles resetting the template for the given messenger/message_type so that users can start from scratch if
2027
+	 * they want.
2028
+	 *
2029
+	 * @access protected
2030
+	 * @return array|null
2031
+	 * @throws EE_Error
2032
+	 * @throws InvalidArgumentException
2033
+	 * @throws InvalidDataTypeException
2034
+	 * @throws InvalidInterfaceException
2035
+	 */
2036
+	protected function _reset_to_default_template()
2037
+	{
2038
+
2039
+		$templates = array();
2040
+		$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2041
+		// we need to make sure we've got the info we need.
2042
+		if (! isset($this->_req_data['msgr'], $this->_req_data['mt'], $this->_req_data['GRP_ID'])) {
2043
+			EE_Error::add_error(
2044
+				esc_html__(
2045
+					'In order to reset the template to its default we require the messenger, message type, and message template GRP_ID to know what is being reset.  At least one of these is missing.',
2046
+					'event_espresso'
2047
+				),
2048
+				__FILE__,
2049
+				__FUNCTION__,
2050
+				__LINE__
2051
+			);
2052
+		}
2053
+
2054
+		// all templates will be reset to whatever the defaults are
2055
+		// for the global template matching the messenger and message type.
2056
+		$success = ! empty($GRP_ID) ? true : false;
2057
+
2058
+		if ($success) {
2059
+			// let's first determine if the incoming template is a global template,
2060
+			// if it isn't then we need to get the global template matching messenger and message type.
2061
+			// $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID( $GRP_ID );
2062
+
2063
+
2064
+			// note this is ONLY deleting the template fields (Message Template rows) NOT the message template group.
2065
+			$success = $this->_delete_mtp_permanently($GRP_ID, false);
2066
+
2067
+			if ($success) {
2068
+				// if successfully deleted, lets generate the new ones.
2069
+				// Note. We set GLOBAL to true, because resets on ANY template
2070
+				// will use the related global template defaults for regeneration.
2071
+				// This means that if a custom template is reset it resets to whatever the related global template is.
2072
+				// HOWEVER, we DO keep the template pack and template variation set
2073
+				// for the current custom template when resetting.
2074
+				$templates = $this->_generate_new_templates(
2075
+					$this->_req_data['msgr'],
2076
+					$this->_req_data['mt'],
2077
+					$GRP_ID,
2078
+					true
2079
+				);
2080
+			}
2081
+		}
2082
+
2083
+		// any error messages?
2084
+		if (! $success) {
2085
+			EE_Error::add_error(
2086
+				esc_html__(
2087
+					'Something went wrong with deleting existing templates. Unable to reset to default',
2088
+					'event_espresso'
2089
+				),
2090
+				__FILE__,
2091
+				__FUNCTION__,
2092
+				__LINE__
2093
+			);
2094
+		}
2095
+
2096
+		// all good, let's add a success message!
2097
+		if ($success && ! empty($templates)) {
2098
+			// the info for the template we generated is the first element in the returned array
2099
+			// $templates = $templates[0];
2100
+			EE_Error::overwrite_success();
2101
+			EE_Error::add_success(__('Templates have been reset to defaults.', 'event_espresso'));
2102
+		}
2103
+
2104
+
2105
+		$query_args = array(
2106
+			'id'      => isset($templates[0]['GRP_ID']) ? $templates[0]['GRP_ID'] : null,
2107
+			'context' => isset($templates[0]['MTP_context']) ? $templates[0]['MTP_context'] : null,
2108
+			'action'  => isset($templates[0]['GRP_ID']) ? 'edit_message_template' : 'global_mtps',
2109
+		);
2110
+
2111
+		// if called via ajax then we return query args otherwise redirect
2112
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2113
+			return $query_args;
2114
+		} else {
2115
+			$this->_redirect_after_action(false, '', '', $query_args, true);
2116
+
2117
+			return null;
2118
+		}
2119
+	}
2120
+
2121
+
2122
+	/**
2123
+	 * Retrieve and set the message preview for display.
2124
+	 *
2125
+	 * @param bool $send if TRUE then we are doing an actual TEST send with the results of the preview.
2126
+	 * @return string
2127
+	 * @throws ReflectionException
2128
+	 * @throws EE_Error
2129
+	 * @throws InvalidArgumentException
2130
+	 * @throws InvalidDataTypeException
2131
+	 * @throws InvalidInterfaceException
2132
+	 */
2133
+	public function _preview_message($send = false)
2134
+	{
2135
+		// first make sure we've got the necessary parameters
2136
+		if (
2137
+			! isset(
2138
+				$this->_req_data['message_type'],
2139
+				$this->_req_data['messenger'],
2140
+				$this->_req_data['messenger'],
2141
+				$this->_req_data['GRP_ID']
2142
+			)
2143
+		) {
2144
+			EE_Error::add_error(
2145
+				esc_html__('Missing necessary parameters for displaying preview', 'event_espresso'),
2146
+				__FILE__,
2147
+				__FUNCTION__,
2148
+				__LINE__
2149
+			);
2150
+		}
2151
+
2152
+		EE_Registry::instance()->REQ->set('GRP_ID', $this->_req_data['GRP_ID']);
2153
+
2154
+		// if we have an evt_id set on the request, use it.
2155
+		$EVT_ID = isset($this->_req_data['evt_id']) && ! empty($this->_req_data['evt_id'])
2156
+		? absint($this->_req_data['evt_id'])
2157
+		: false;
2158
+
2159
+
2160
+		// get the preview!
2161
+		$preview = EED_Messages::preview_message(
2162
+			$this->_req_data['message_type'],
2163
+			$this->_req_data['context'],
2164
+			$this->_req_data['messenger'],
2165
+			$send
2166
+		);
2167
+
2168
+		if ($send) {
2169
+			return $preview;
2170
+		}
2171
+
2172
+		// let's add a button to go back to the edit view
2173
+		$query_args = array(
2174
+			'id'      => $this->_req_data['GRP_ID'],
2175
+			'evt_id'  => $EVT_ID,
2176
+			'context' => $this->_req_data['context'],
2177
+			'action'  => 'edit_message_template',
2178
+		);
2179
+		$go_back_url = parent::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2180
+		$preview_button = '<a href="'
2181
+						  . $go_back_url
2182
+						  . '" class="button-secondary messages-preview-go-back-button">'
2183
+						  . esc_html__('Go Back to Edit', 'event_espresso')
2184
+						  . '</a>';
2185
+		$message_types = $this->get_installed_message_types();
2186
+		$active_messenger = $this->_message_resource_manager->get_active_messenger(
2187
+			$this->_req_data['messenger']
2188
+		);
2189
+		$active_messenger_label = $active_messenger instanceof EE_messenger
2190
+			? ucwords($active_messenger->label['singular'])
2191
+			: esc_html__('Unknown Messenger', 'event_espresso');
2192
+		// let's provide a helpful title for context
2193
+		$preview_title = sprintf(
2194
+			esc_html__('Viewing Preview for %s %s Message Template', 'event_espresso'),
2195
+			$active_messenger_label,
2196
+			ucwords($message_types[ $this->_req_data['message_type'] ]->label['singular'])
2197
+		);
2198
+		if (empty($preview)) {
2199
+			$this->noEventsErrorMessage();
2200
+		}
2201
+		// setup display of preview.
2202
+		$this->_admin_page_title = $preview_title;
2203
+		$this->_template_args['admin_page_title'] = $preview_title;
2204
+		$this->_template_args['admin_page_content'] = $preview_button . '<br />' . $preview;
2205
+		$this->_template_args['data']['force_json'] = true;
2206
+
2207
+		return '';
2208
+	}
2209
+
2210
+
2211
+	/**
2212
+	 * Used to set an error if there are no events available for generating a preview/test send.
2213
+	 *
2214
+	 * @param bool $test_send  Whether the error should be generated for the context of a test send.
2215
+	 */
2216
+	protected function noEventsErrorMessage($test_send = false)
2217
+	{
2218
+		$events_url = parent::add_query_args_and_nonce(
2219
+			array(
2220
+				'action' => 'default',
2221
+				'page'   => 'espresso_events',
2222
+			),
2223
+			admin_url('admin.php')
2224
+		);
2225
+		$message = $test_send
2226
+			? __(
2227
+				'A test message could not be sent for this message template because there are no events created yet. The preview system uses actual events for generating the test message. %1$sGo see your events%2$s!',
2228
+				'event_espresso'
2229
+			)
2230
+			: __(
2231
+				'There is no preview for this message template available because there are no events created yet. The preview system uses actual events for generating the preview. %1$sGo see your events%2$s!',
2232
+				'event_espresso'
2233
+			);
2234
+
2235
+		EE_Error::add_attention(
2236
+			sprintf(
2237
+				$message,
2238
+				"<a href='{$events_url}'>",
2239
+				'</a>'
2240
+			)
2241
+		);
2242
+	}
2243
+
2244
+
2245
+	/**
2246
+	 * The initial _preview_message is on a no headers route.  It will optionally call this if necessary otherwise it
2247
+	 * gets called automatically.
2248
+	 *
2249
+	 * @since 4.5.0
2250
+	 *
2251
+	 * @return string
2252
+	 */
2253
+	protected function _display_preview_message()
2254
+	{
2255
+		$this->display_admin_page_with_no_sidebar();
2256
+	}
2257
+
2258
+
2259
+	/**
2260
+	 * registers metaboxes that should show up on the "edit_message_template" page
2261
+	 *
2262
+	 * @access protected
2263
+	 * @return void
2264
+	 */
2265
+	protected function _register_edit_meta_boxes()
2266
+	{
2267
+		add_meta_box(
2268
+			'mtp_valid_shortcodes',
2269
+			esc_html__('Valid Shortcodes', 'event_espresso'),
2270
+			array($this, 'shortcode_meta_box'),
2271
+			$this->_current_screen->id,
2272
+			'side',
2273
+			'default'
2274
+		);
2275
+		add_meta_box(
2276
+			'mtp_extra_actions',
2277
+			esc_html__('Extra Actions', 'event_espresso'),
2278
+			array($this, 'extra_actions_meta_box'),
2279
+			$this->_current_screen->id,
2280
+			'side',
2281
+			'high'
2282
+		);
2283
+		add_meta_box(
2284
+			'mtp_templates',
2285
+			esc_html__('Template Styles', 'event_espresso'),
2286
+			array($this, 'template_pack_meta_box'),
2287
+			$this->_current_screen->id,
2288
+			'side',
2289
+			'high'
2290
+		);
2291
+	}
2292
+
2293
+
2294
+	/**
2295
+	 * metabox content for all template pack and variation selection.
2296
+	 *
2297
+	 * @since 4.5.0
2298
+	 * @return string
2299
+	 * @throws DomainException
2300
+	 * @throws EE_Error
2301
+	 * @throws InvalidArgumentException
2302
+	 * @throws ReflectionException
2303
+	 * @throws InvalidDataTypeException
2304
+	 * @throws InvalidInterfaceException
2305
+	 */
2306
+	public function template_pack_meta_box()
2307
+	{
2308
+		$this->_set_message_template_group();
2309
+
2310
+		$tp_collection = EEH_MSG_Template::get_template_pack_collection();
2311
+
2312
+		$tp_select_values = array();
2313
+
2314
+		foreach ($tp_collection as $tp) {
2315
+			// only include template packs that support this messenger and message type!
2316
+			$supports = $tp->get_supports();
2317
+			if (
2318
+				! isset($supports[ $this->_message_template_group->messenger() ])
2319
+				|| ! in_array(
2320
+					$this->_message_template_group->message_type(),
2321
+					$supports[ $this->_message_template_group->messenger() ],
2322
+					true
2323
+				)
2324
+			) {
2325
+				// not supported
2326
+				continue;
2327
+			}
2328
+
2329
+			$tp_select_values[] = array(
2330
+				'text' => $tp->label,
2331
+				'id'   => $tp->dbref,
2332
+			);
2333
+		}
2334
+
2335
+		// if empty $tp_select_values then we make sure default is set because EVERY message type should be supported by
2336
+		// the default template pack.  This still allows for the odd template pack to override.
2337
+		if (empty($tp_select_values)) {
2338
+			$tp_select_values[] = array(
2339
+				'text' => esc_html__('Default', 'event_espresso'),
2340
+				'id'   => 'default',
2341
+			);
2342
+		}
2343
+
2344
+		// setup variation select values for the currently selected template.
2345
+		$variations = $this->_message_template_group->get_template_pack()->get_variations(
2346
+			$this->_message_template_group->messenger(),
2347
+			$this->_message_template_group->message_type()
2348
+		);
2349
+		$variations_select_values = array();
2350
+		foreach ($variations as $variation => $label) {
2351
+			$variations_select_values[] = array(
2352
+				'text' => $label,
2353
+				'id'   => $variation,
2354
+			);
2355
+		}
2356
+
2357
+		$template_pack_labels = $this->_message_template_group->messenger_obj()->get_supports_labels();
2358
+
2359
+		$template_args['template_packs_selector'] = EEH_Form_Fields::select_input(
2360
+			'MTP_template_pack',
2361
+			$tp_select_values,
2362
+			$this->_message_template_group->get_template_pack_name()
2363
+		);
2364
+		$template_args['variations_selector'] = EEH_Form_Fields::select_input(
2365
+			'MTP_template_variation',
2366
+			$variations_select_values,
2367
+			$this->_message_template_group->get_template_pack_variation()
2368
+		);
2369
+		$template_args['template_pack_label'] = $template_pack_labels->template_pack;
2370
+		$template_args['template_variation_label'] = $template_pack_labels->template_variation;
2371
+		$template_args['template_pack_description'] = $template_pack_labels->template_pack_description;
2372
+		$template_args['template_variation_description'] = $template_pack_labels->template_variation_description;
2373
+
2374
+		$template = EE_MSG_TEMPLATE_PATH . 'template_pack_and_variations_metabox.template.php';
2375
+
2376
+		EEH_Template::display_template($template, $template_args);
2377
+	}
2378
+
2379
+
2380
+	/**
2381
+	 * This meta box holds any extra actions related to Message Templates
2382
+	 * For now, this includes Resetting templates to defaults and sending a test email.
2383
+	 *
2384
+	 * @access  public
2385
+	 * @return void
2386
+	 * @throws EE_Error
2387
+	 */
2388
+	public function extra_actions_meta_box()
2389
+	{
2390
+		$template_form_fields = array();
2391
+
2392
+		$extra_args = array(
2393
+			'msgr'   => $this->_message_template_group->messenger(),
2394
+			'mt'     => $this->_message_template_group->message_type(),
2395
+			'GRP_ID' => $this->_message_template_group->GRP_ID(),
2396
+		);
2397
+		// first we need to see if there are any fields
2398
+		$fields = $this->_message_template_group->messenger_obj()->get_test_settings_fields();
2399
+
2400
+		if (! empty($fields)) {
2401
+			// yup there be fields
2402
+			foreach ($fields as $field => $config) {
2403
+				$field_id = $this->_message_template_group->messenger() . '_' . $field;
2404
+				$existing = $this->_message_template_group->messenger_obj()->get_existing_test_settings();
2405
+				$default = isset($config['default']) ? $config['default'] : '';
2406
+				$default = isset($config['value']) ? $config['value'] : $default;
2407
+
2408
+				// if type is hidden and the value is empty
2409
+				// something may have gone wrong so let's correct with the defaults
2410
+				$fix = $config['input'] === 'hidden'
2411
+					   && isset($existing[ $field ])
2412
+					   && empty($existing[ $field ])
2413
+					? $default
2414
+					: '';
2415
+				$existing[ $field ] = isset($existing[ $field ]) && empty($fix)
2416
+					? $existing[ $field ]
2417
+					: $fix;
2418
+
2419
+				$template_form_fields[ $field_id ] = array(
2420
+					'name'       => 'test_settings_fld[' . $field . ']',
2421
+					'label'      => $config['label'],
2422
+					'input'      => $config['input'],
2423
+					'type'       => $config['type'],
2424
+					'required'   => $config['required'],
2425
+					'validation' => $config['validation'],
2426
+					'value'      => isset($existing[ $field ]) ? $existing[ $field ] : $default,
2427
+					'css_class'  => $config['css_class'],
2428
+					'options'    => isset($config['options']) ? $config['options'] : array(),
2429
+					'default'    => $default,
2430
+					'format'     => $config['format'],
2431
+				);
2432
+			}
2433
+		}
2434
+
2435
+		$test_settings_fields = ! empty($template_form_fields)
2436
+			? $this->_generate_admin_form_fields($template_form_fields, 'string', 'ee_tst_settings_flds')
2437
+			: '';
2438
+
2439
+		$test_settings_html = '';
2440
+		// print out $test_settings_fields
2441
+		if (! empty($test_settings_fields)) {
2442
+			echo $test_settings_fields;
2443
+			$test_settings_html = '<input type="submit" class="button-primary mtp-test-button alignright" ';
2444
+			$test_settings_html .= 'name="test_button" value="';
2445
+			$test_settings_html .= esc_html__('Test Send', 'event_espresso');
2446
+			$test_settings_html .= '" /><div style="clear:both"></div>';
2447
+		}
2448
+
2449
+		// and button
2450
+		$test_settings_html .= '<p>'
2451
+							   . esc_html__('Need to reset this message type and start over?', 'event_espresso')
2452
+							   . '</p>';
2453
+		$test_settings_html .= '<div class="publishing-action alignright resetbutton">';
2454
+		$test_settings_html .= $this->get_action_link_or_button(
2455
+			'reset_to_default',
2456
+			'reset',
2457
+			$extra_args,
2458
+			'button-primary reset-default-button'
2459
+		);
2460
+		$test_settings_html .= '</div><div style="clear:both"></div>';
2461
+		echo $test_settings_html;
2462
+	}
2463
+
2464
+
2465
+	/**
2466
+	 * This returns the shortcode selector skeleton for a given context and field.
2467
+	 *
2468
+	 * @since 4.9.rc.000
2469
+	 * @param string $field           The name of the field retrieving shortcodes for.
2470
+	 * @param string $linked_input_id The css id of the input that the shortcodes get added to.
2471
+	 * @return string
2472
+	 * @throws DomainException
2473
+	 * @throws EE_Error
2474
+	 * @throws InvalidArgumentException
2475
+	 * @throws ReflectionException
2476
+	 * @throws InvalidDataTypeException
2477
+	 * @throws InvalidInterfaceException
2478
+	 */
2479
+	protected function _get_shortcode_selector($field, $linked_input_id)
2480
+	{
2481
+		$template_args = array(
2482
+			'shortcodes'      => $this->_get_shortcodes(array($field), true),
2483
+			'fieldname'       => $field,
2484
+			'linked_input_id' => $linked_input_id,
2485
+		);
2486
+
2487
+		return EEH_Template::display_template(
2488
+			EE_MSG_TEMPLATE_PATH . 'shortcode_selector_skeleton.template.php',
2489
+			$template_args,
2490
+			true
2491
+		);
2492
+	}
2493
+
2494
+
2495
+	/**
2496
+	 * This just takes care of returning the meta box content for shortcodes (only used on the edit message template
2497
+	 * page)
2498
+	 *
2499
+	 * @access public
2500
+	 * @return void
2501
+	 * @throws EE_Error
2502
+	 * @throws InvalidArgumentException
2503
+	 * @throws ReflectionException
2504
+	 * @throws InvalidDataTypeException
2505
+	 * @throws InvalidInterfaceException
2506
+	 */
2507
+	public function shortcode_meta_box()
2508
+	{
2509
+		$shortcodes = $this->_get_shortcodes(array(), false); // just make sure shortcodes property is set
2510
+		// $messenger = $this->_message_template_group->messenger_obj();
2511
+		// now let's set the content depending on the status of the shortcodes array
2512
+		if (empty($shortcodes)) {
2513
+			$content = '<p>' . esc_html__('There are no valid shortcodes available', 'event_espresso') . '</p>';
2514
+			echo $content;
2515
+		} else {
2516
+			// $alt = 0;
2517
+			?>
2518 2518
             <div style="float:right; margin-top:10px"><?php
2519
-                            echo $this->_get_help_tab_link('message_template_shortcodes');
2520
-            ?></div>
2519
+							echo $this->_get_help_tab_link('message_template_shortcodes');
2520
+			?></div>
2521 2521
             <p class="small-text"><?php
2522
-                                  printf(
2523
-                                      esc_html__(
2524
-                                          'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2525
-                                          'event_espresso'
2526
-                                      ),
2527
-                                      '<span class="dashicons dashicons-menu"></span>'
2528
-                                  );
2529
-                                    ?>
2522
+								  printf(
2523
+									  esc_html__(
2524
+										  'You can view the shortcodes usable in your template by clicking the %s icon next to each field.',
2525
+										  'event_espresso'
2526
+									  ),
2527
+									  '<span class="dashicons dashicons-menu"></span>'
2528
+								  );
2529
+									?>
2530 2530
             </p>
2531 2531
             <?php
2532
-        }
2533
-    }
2534
-
2535
-
2536
-    /**
2537
-     * used to set the $_shortcodes property for when its needed elsewhere.
2538
-     *
2539
-     * @access protected
2540
-     * @return void
2541
-     * @throws EE_Error
2542
-     * @throws InvalidArgumentException
2543
-     * @throws ReflectionException
2544
-     * @throws InvalidDataTypeException
2545
-     * @throws InvalidInterfaceException
2546
-     */
2547
-    protected function _set_shortcodes()
2548
-    {
2549
-
2550
-        // no need to run this if the property is already set
2551
-        if (! empty($this->_shortcodes)) {
2552
-            return;
2553
-        }
2554
-
2555
-        $this->_shortcodes = $this->_get_shortcodes();
2556
-    }
2557
-
2558
-
2559
-    /**
2560
-     * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2561
-     * property)
2562
-     *
2563
-     * @access  protected
2564
-     * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2565
-     *                         for. Defaults to all (for the given context)
2566
-     * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2567
-     * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2568
-     *                         true just an array of shortcode/label pairs.
2569
-     * @throws EE_Error
2570
-     * @throws InvalidArgumentException
2571
-     * @throws ReflectionException
2572
-     * @throws InvalidDataTypeException
2573
-     * @throws InvalidInterfaceException
2574
-     */
2575
-    protected function _get_shortcodes($fields = array(), $merged = true)
2576
-    {
2577
-        $this->_set_message_template_group();
2578
-
2579
-        // we need the messenger and message template to retrieve the valid shortcodes array.
2580
-        $GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
2581
-            ? absint($this->_req_data['id'])
2582
-            : false;
2583
-        $context = isset($this->_req_data['context'])
2584
-            ? $this->_req_data['context']
2585
-            : key($this->_message_template_group->contexts_config());
2586
-
2587
-        return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2588
-    }
2589
-
2590
-
2591
-    /**
2592
-     * This sets the _message_template property (containing the called message_template object)
2593
-     *
2594
-     * @access protected
2595
-     * @return void
2596
-     * @throws EE_Error
2597
-     * @throws InvalidArgumentException
2598
-     * @throws ReflectionException
2599
-     * @throws InvalidDataTypeException
2600
-     * @throws InvalidInterfaceException
2601
-     */
2602
-    protected function _set_message_template_group()
2603
-    {
2604
-
2605
-        if (! empty($this->_message_template_group)) {
2606
-            return;
2607
-        } //get out if this is already set.
2608
-
2609
-        $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2610
-        $GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2611
-
2612
-        // let's get the message templates
2613
-        $MTP = EEM_Message_Template_Group::instance();
2614
-
2615
-        if (empty($GRP_ID)) {
2616
-            $this->_message_template_group = $MTP->create_default_object();
2617
-        } else {
2618
-            $this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2619
-        }
2620
-
2621
-        $this->_template_pack = $this->_message_template_group->get_template_pack();
2622
-        $this->_variation = $this->_message_template_group->get_template_pack_variation();
2623
-    }
2624
-
2625
-
2626
-    /**
2627
-     * sets up a context switcher for edit forms
2628
-     *
2629
-     * @access  protected
2630
-     * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2631
-     * @param array                      $args                  various things the context switcher needs.
2632
-     * @throws EE_Error
2633
-     */
2634
-    protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2635
-    {
2636
-        $context_details = $template_group_object->contexts_config();
2637
-        $context_label = $template_group_object->context_label();
2638
-        ob_start();
2639
-        ?>
2532
+		}
2533
+	}
2534
+
2535
+
2536
+	/**
2537
+	 * used to set the $_shortcodes property for when its needed elsewhere.
2538
+	 *
2539
+	 * @access protected
2540
+	 * @return void
2541
+	 * @throws EE_Error
2542
+	 * @throws InvalidArgumentException
2543
+	 * @throws ReflectionException
2544
+	 * @throws InvalidDataTypeException
2545
+	 * @throws InvalidInterfaceException
2546
+	 */
2547
+	protected function _set_shortcodes()
2548
+	{
2549
+
2550
+		// no need to run this if the property is already set
2551
+		if (! empty($this->_shortcodes)) {
2552
+			return;
2553
+		}
2554
+
2555
+		$this->_shortcodes = $this->_get_shortcodes();
2556
+	}
2557
+
2558
+
2559
+	/**
2560
+	 * get's all shortcodes for a given template group. (typically used by _set_shortcodes to set the $_shortcodes
2561
+	 * property)
2562
+	 *
2563
+	 * @access  protected
2564
+	 * @param  array   $fields include an array of specific field names that you want to be used to get the shortcodes
2565
+	 *                         for. Defaults to all (for the given context)
2566
+	 * @param  boolean $merged Whether to merge all the shortcodes into one list of unique shortcodes
2567
+	 * @return array Shortcodes indexed by fieldname and the an array of shortcode/label pairs OR if merged is
2568
+	 *                         true just an array of shortcode/label pairs.
2569
+	 * @throws EE_Error
2570
+	 * @throws InvalidArgumentException
2571
+	 * @throws ReflectionException
2572
+	 * @throws InvalidDataTypeException
2573
+	 * @throws InvalidInterfaceException
2574
+	 */
2575
+	protected function _get_shortcodes($fields = array(), $merged = true)
2576
+	{
2577
+		$this->_set_message_template_group();
2578
+
2579
+		// we need the messenger and message template to retrieve the valid shortcodes array.
2580
+		$GRP_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id'])
2581
+			? absint($this->_req_data['id'])
2582
+			: false;
2583
+		$context = isset($this->_req_data['context'])
2584
+			? $this->_req_data['context']
2585
+			: key($this->_message_template_group->contexts_config());
2586
+
2587
+		return ! empty($GRP_ID) ? $this->_message_template_group->get_shortcodes($context, $fields, $merged) : array();
2588
+	}
2589
+
2590
+
2591
+	/**
2592
+	 * This sets the _message_template property (containing the called message_template object)
2593
+	 *
2594
+	 * @access protected
2595
+	 * @return void
2596
+	 * @throws EE_Error
2597
+	 * @throws InvalidArgumentException
2598
+	 * @throws ReflectionException
2599
+	 * @throws InvalidDataTypeException
2600
+	 * @throws InvalidInterfaceException
2601
+	 */
2602
+	protected function _set_message_template_group()
2603
+	{
2604
+
2605
+		if (! empty($this->_message_template_group)) {
2606
+			return;
2607
+		} //get out if this is already set.
2608
+
2609
+		$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? absint($this->_req_data['GRP_ID']) : false;
2610
+		$GRP_ID = empty($GRP_ID) && ! empty($this->_req_data['id']) ? $this->_req_data['id'] : $GRP_ID;
2611
+
2612
+		// let's get the message templates
2613
+		$MTP = EEM_Message_Template_Group::instance();
2614
+
2615
+		if (empty($GRP_ID)) {
2616
+			$this->_message_template_group = $MTP->create_default_object();
2617
+		} else {
2618
+			$this->_message_template_group = $MTP->get_one_by_ID($GRP_ID);
2619
+		}
2620
+
2621
+		$this->_template_pack = $this->_message_template_group->get_template_pack();
2622
+		$this->_variation = $this->_message_template_group->get_template_pack_variation();
2623
+	}
2624
+
2625
+
2626
+	/**
2627
+	 * sets up a context switcher for edit forms
2628
+	 *
2629
+	 * @access  protected
2630
+	 * @param  EE_Message_Template_Group $template_group_object the template group object being displayed on the form
2631
+	 * @param array                      $args                  various things the context switcher needs.
2632
+	 * @throws EE_Error
2633
+	 */
2634
+	protected function _set_context_switcher(EE_Message_Template_Group $template_group_object, $args)
2635
+	{
2636
+		$context_details = $template_group_object->contexts_config();
2637
+		$context_label = $template_group_object->context_label();
2638
+		ob_start();
2639
+		?>
2640 2640
         <div class="ee-msg-switcher-container">
2641 2641
             <form method="get" action="<?php echo EE_MSG_ADMIN_URL; ?>" id="ee-msg-context-switcher-frm">
2642 2642
                 <?php
2643
-                foreach ($args as $name => $value) {
2644
-                    if ($name === 'context' || empty($value) || $name === 'extra') {
2645
-                        continue;
2646
-                    }
2647
-                    ?>
2643
+				foreach ($args as $name => $value) {
2644
+					if ($name === 'context' || empty($value) || $name === 'extra') {
2645
+						continue;
2646
+					}
2647
+					?>
2648 2648
                     <input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>"/>
2649 2649
                     <?php
2650
-                }
2651
-                // setup nonce_url
2652
-                wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2653
-                ?>
2650
+				}
2651
+				// setup nonce_url
2652
+				wp_nonce_field($args['action'] . '_nonce', $args['action'] . '_nonce', false);
2653
+				?>
2654 2654
                 <select name="context">
2655 2655
                     <?php
2656
-                    $context_templates = $template_group_object->context_templates();
2657
-                    if (is_array($context_templates)) :
2658
-                        foreach ($context_templates as $context => $template_fields) :
2659
-                            $checked = ($context === $args['context']) ? 'selected="selected"' : '';
2660
-                            ?>
2656
+					$context_templates = $template_group_object->context_templates();
2657
+					if (is_array($context_templates)) :
2658
+						foreach ($context_templates as $context => $template_fields) :
2659
+							$checked = ($context === $args['context']) ? 'selected="selected"' : '';
2660
+							?>
2661 2661
                             <option value="<?php echo $context; ?>" <?php echo $checked; ?>>
2662 2662
                                 <?php echo $context_details[ $context ]['label']; ?>
2663 2663
                             </option>
2664 2664
                         <?php endforeach;
2665
-                    endif; ?>
2665
+					endif; ?>
2666 2666
                 </select>
2667 2667
                 <?php $button_text = sprintf(__('Switch %s', 'event_espresso'), ucwords($context_label['label'])); ?>
2668 2668
                 <input id="submit-msg-context-switcher-sbmt" class="button-secondary" type="submit"
@@ -2671,1930 +2671,1930 @@  discard block
 block discarded – undo
2671 2671
             <?php echo $args['extra']; ?>
2672 2672
         </div> <!-- end .ee-msg-switcher-container -->
2673 2673
         <?php
2674
-        $output = ob_get_contents();
2675
-        ob_clean();
2676
-        $this->_context_switcher = $output;
2677
-    }
2678
-
2679
-
2680
-    /**
2681
-     * utility for sanitizing new values coming in.
2682
-     * Note: this is only used when updating a context.
2683
-     *
2684
-     * @access protected
2685
-     *
2686
-     * @param int $index This helps us know which template field to select from the request array.
2687
-     *
2688
-     * @return array
2689
-     */
2690
-    protected function _set_message_template_column_values($index)
2691
-    {
2692
-        if (is_array($this->_req_data['MTP_template_fields'][ $index ]['content'])) {
2693
-            foreach ($this->_req_data['MTP_template_fields'][ $index ]['content'] as $field => $value) {
2694
-                $this->_req_data['MTP_template_fields'][ $index ]['content'][ $field ] = $value;
2695
-            }
2696
-        }
2697
-
2698
-
2699
-        $set_column_values = array(
2700
-            'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][ $index ]['MTP_ID']),
2701
-            'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2702
-            'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2703
-            'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2704
-            'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2705
-            'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][ $index ]['name']),
2706
-            'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2707
-            'MTP_content'        => $this->_req_data['MTP_template_fields'][ $index ]['content'],
2708
-            'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2709
-                ? absint($this->_req_data['MTP_is_global'])
2710
-                : 0,
2711
-            'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2712
-                ? absint($this->_req_data['MTP_is_override'])
2713
-                : 0,
2714
-            'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2715
-            'MTP_is_active'      => absint($this->_req_data['MTP_is_active']),
2716
-        );
2717
-
2718
-
2719
-        return $set_column_values;
2720
-    }
2721
-
2722
-
2723
-    protected function _insert_or_update_message_template($new = false)
2724
-    {
2725
-        $success = 0;
2726
-        $override = false;
2727
-
2728
-        // setup notices description
2729
-        $messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2730
-
2731
-        // need the message type and messenger objects to be able to use the labels for the notices
2732
-        $messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2733
-        $messenger_label = $messenger_object instanceof EE_messenger
2734
-            ? ucwords($messenger_object->label['singular'])
2735
-            : '';
2736
-
2737
-        $message_type_slug = ! empty($this->_req_data['MTP_message_type'])
2738
-            ? $this->_req_data['MTP_message_type']
2739
-            : '';
2740
-        $message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2741
-
2742
-        $message_type_label = $message_type_object instanceof EE_message_type
2743
-            ? ucwords($message_type_object->label['singular'])
2744
-            : '';
2745
-
2746
-        $context_slug = ! empty($this->_req_data['MTP_context'])
2747
-            ? $this->_req_data['MTP_context']
2748
-            : '';
2749
-        $context = ucwords(str_replace('_', ' ', $context_slug));
2750
-
2751
-        $item_desc = $messenger_label && $message_type_label
2752
-            ? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2753
-            : '';
2754
-        $item_desc .= 'Message Template';
2755
-        $query_args = array();
2756
-        $edit_array = array();
2757
-        $action_desc = '';
2758
-
2759
-        // if this is "new" then we need to generate the default contexts for the selected messenger/message_type for
2760
-        // user to edit.
2761
-        if ($new) {
2762
-            $GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2763
-            if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2764
-                if (empty($edit_array)) {
2765
-                    $success = 0;
2766
-                } else {
2767
-                    $success = 1;
2768
-                    $edit_array = $edit_array[0];
2769
-                    $query_args = array(
2770
-                        'id'      => $edit_array['GRP_ID'],
2771
-                        'context' => $edit_array['MTP_context'],
2772
-                        'action'  => 'edit_message_template',
2773
-                    );
2774
-                }
2775
-            }
2776
-            $action_desc = 'created';
2777
-        } else {
2778
-            $MTPG = EEM_Message_Template_Group::instance();
2779
-            $MTP = EEM_Message_Template::instance();
2780
-
2781
-
2782
-            // run update for each template field in displayed context
2783
-            if (! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2784
-                EE_Error::add_error(
2785
-                    esc_html__(
2786
-                        'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2787
-                        'event_espresso'
2788
-                    ),
2789
-                    __FILE__,
2790
-                    __FUNCTION__,
2791
-                    __LINE__
2792
-                );
2793
-                $success = 0;
2794
-            } else {
2795
-                // first validate all fields!
2796
-                // this filter allows client code to add its own validation to the template fields as well.
2797
-                // returning an empty array means everything passed validation.
2798
-                // errors in validation should be represented in an array with the following shape:
2799
-                // array(
2800
-                //   'fieldname' => array(
2801
-                //          'msg' => 'error message'
2802
-                //          'value' => 'value for field producing error'
2803
-                // )
2804
-                $custom_validation = (array) apply_filters(
2805
-                    'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2806
-                    array(),
2807
-                    $this->_req_data['MTP_template_fields'],
2808
-                    $context_slug,
2809
-                    $messenger_slug,
2810
-                    $message_type_slug
2811
-                );
2812
-
2813
-                $system_validation = $MTPG->validate(
2814
-                    $this->_req_data['MTP_template_fields'],
2815
-                    $context_slug,
2816
-                    $messenger_slug,
2817
-                    $message_type_slug
2818
-                );
2819
-
2820
-                $system_validation = ! is_array($system_validation) && $system_validation ? array()
2821
-                    : $system_validation;
2822
-                $validates = array_merge($custom_validation, $system_validation);
2823
-
2824
-                // if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2825
-                // appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2826
-                //  WE need to make sure there is no actual error messages in validates.
2827
-                if (is_array($validates) && ! empty($validates)) {
2828
-                    // add the transient so when the form loads we know which fields to highlight
2829
-                    $this->_add_transient('edit_message_template', $validates);
2830
-
2831
-                    $success = 0;
2832
-
2833
-                    // setup notices
2834
-                    foreach ($validates as $field => $error) {
2835
-                        if (isset($error['msg'])) {
2836
-                            EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2837
-                        }
2838
-                    }
2839
-                } else {
2840
-                    $set_column_values = array();
2841
-                    foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2842
-                        $set_column_values = $this->_set_message_template_column_values($template_field);
2843
-
2844
-                        $where_cols_n_values = array(
2845
-                            'MTP_ID' => $this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'],
2846
-                        );
2847
-                        // if they aren't allowed to use all JS, restrict them to just posty-y tags
2848
-                        if (! current_user_can('unfiltered_html')) {
2849
-                            if (is_array($set_column_values['MTP_content'])) {
2850
-                                foreach ($set_column_values['MTP_content'] as $key => $value) {
2851
-                                    // remove slashes so wp_kses works properly (its wp_kses_stripslashes() function
2852
-                                    // only removes slashes from double-quotes, so attributes using single quotes always
2853
-                                    // appear invalid.) But currently the models expect slashed data, so after wp_kses
2854
-                                    // runs we need to re-slash the data. Sheesh. See
2855
-                                    // https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
2856
-                                    $set_column_values['MTP_content'][ $key ] = addslashes(
2857
-                                        wp_kses(
2858
-                                            stripslashes($value),
2859
-                                            wp_kses_allowed_html('post')
2860
-                                        )
2861
-                                    );
2862
-                                }
2863
-                            } else {
2864
-                                $set_column_values['MTP_content'] = wp_kses(
2865
-                                    $set_column_values['MTP_content'],
2866
-                                    wp_kses_allowed_html('post')
2867
-                                );
2868
-                            }
2869
-                        }
2870
-                        $message_template_fields = array(
2871
-                            'GRP_ID'             => $set_column_values['GRP_ID'],
2872
-                            'MTP_template_field' => $set_column_values['MTP_template_field'],
2873
-                            'MTP_context'        => $set_column_values['MTP_context'],
2874
-                            'MTP_content'        => $set_column_values['MTP_content'],
2875
-                        );
2876
-                        if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2877
-                            if ($updated === false) {
2878
-                                EE_Error::add_error(
2879
-                                    sprintf(
2880
-                                        esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2881
-                                        $template_field
2882
-                                    ),
2883
-                                    __FILE__,
2884
-                                    __FUNCTION__,
2885
-                                    __LINE__
2886
-                                );
2887
-                            } else {
2888
-                                $success = 1;
2889
-                            }
2890
-                        } else {
2891
-                            // only do this logic if we don't have a MTP_ID for this field
2892
-                            if (empty($this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'])) {
2893
-                                // this has already been through the template field validator and sanitized, so it will be
2894
-                                // safe to insert this field.  Why insert?  This typically happens when we introduce a new
2895
-                                // message template field in a messenger/message type and existing users don't have the
2896
-                                // default setup for it.
2897
-                                // @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2898
-                                $updated = $MTP->insert($message_template_fields);
2899
-                                if (! $updated || is_wp_error($updated)) {
2900
-                                    EE_Error::add_error(
2901
-                                        sprintf(
2902
-                                            esc_html__('%s field could not be updated.', 'event_espresso'),
2903
-                                            $template_field
2904
-                                        ),
2905
-                                        __FILE__,
2906
-                                        __FUNCTION__,
2907
-                                        __LINE__
2908
-                                    );
2909
-                                    $success = 0;
2910
-                                } else {
2911
-                                    $success = 1;
2912
-                                }
2913
-                            }
2914
-                        }
2915
-                        $action_desc = 'updated';
2916
-                    }
2917
-
2918
-                    // we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2919
-                    $mtpg_fields = array(
2920
-                        'MTP_user_id'      => $set_column_values['MTP_user_id'],
2921
-                        'MTP_messenger'    => $set_column_values['MTP_messenger'],
2922
-                        'MTP_message_type' => $set_column_values['MTP_message_type'],
2923
-                        'MTP_is_global'    => $set_column_values['MTP_is_global'],
2924
-                        'MTP_is_override'  => $set_column_values['MTP_is_override'],
2925
-                        'MTP_deleted'      => $set_column_values['MTP_deleted'],
2926
-                        'MTP_is_active'    => $set_column_values['MTP_is_active'],
2927
-                        'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2928
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2929
-                            : '',
2930
-                        'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2931
-                            ? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2932
-                            : '',
2933
-                    );
2934
-
2935
-                    $mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2936
-                    $updated = $MTPG->update($mtpg_fields, array($mtpg_where));
2937
-
2938
-                    if ($updated === false) {
2939
-                        EE_Error::add_error(
2940
-                            sprintf(
2941
-                                esc_html__(
2942
-                                    'The Message Template Group (%d) was NOT updated for some reason',
2943
-                                    'event_espresso'
2944
-                                ),
2945
-                                $set_column_values['GRP_ID']
2946
-                            ),
2947
-                            __FILE__,
2948
-                            __FUNCTION__,
2949
-                            __LINE__
2950
-                        );
2951
-                    } else {
2952
-                        // k now we need to ensure the template_pack and template_variation fields are set.
2953
-                        $template_pack = ! empty($this->_req_data['MTP_template_pack'])
2954
-                            ? $this->_req_data['MTP_template_pack']
2955
-                            : 'default';
2956
-
2957
-                        $template_variation = ! empty($this->_req_data['MTP_template_variation'])
2958
-                            ? $this->_req_data['MTP_template_variation']
2959
-                            : 'default';
2960
-
2961
-                        $mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2962
-                        if ($mtpg_obj instanceof EE_Message_Template_Group) {
2963
-                            $mtpg_obj->set_template_pack_name($template_pack);
2964
-                            $mtpg_obj->set_template_pack_variation($template_variation);
2965
-                        }
2966
-                        $success = 1;
2967
-                    }
2968
-                }
2969
-            }
2970
-        }
2971
-
2972
-        // we return things differently if doing ajax
2973
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2974
-            $this->_template_args['success'] = $success;
2975
-            $this->_template_args['error'] = ! $success ? true : false;
2976
-            $this->_template_args['content'] = '';
2977
-            $this->_template_args['data'] = array(
2978
-                'grpID'        => $edit_array['GRP_ID'],
2979
-                'templateName' => $edit_array['template_name'],
2980
-            );
2981
-            if ($success) {
2982
-                EE_Error::overwrite_success();
2983
-                EE_Error::add_success(
2984
-                    esc_html__(
2985
-                        'The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2986
-                        'event_espresso'
2987
-                    )
2988
-                );
2989
-            }
2990
-
2991
-            $this->_return_json();
2992
-        }
2993
-
2994
-
2995
-        // was a test send triggered?
2996
-        if (isset($this->_req_data['test_button'])) {
2997
-            EE_Error::overwrite_success();
2998
-            $this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2999
-            $override = true;
3000
-        }
3001
-
3002
-        if (empty($query_args)) {
3003
-            $query_args = array(
3004
-                'id'      => $this->_req_data['GRP_ID'],
3005
-                'context' => $context_slug,
3006
-                'action'  => 'edit_message_template',
3007
-            );
3008
-        }
3009
-
3010
-        $this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
3011
-    }
3012
-
3013
-
3014
-    /**
3015
-     * processes a test send request to do an actual messenger delivery test for the given message template being tested
3016
-     *
3017
-     * @param  string $context      what context being tested
3018
-     * @param  string $messenger    messenger being tested
3019
-     * @param  string $message_type message type being tested
3020
-     * @throws EE_Error
3021
-     * @throws InvalidArgumentException
3022
-     * @throws InvalidDataTypeException
3023
-     * @throws InvalidInterfaceException
3024
-     */
3025
-    protected function _do_test_send($context, $messenger, $message_type)
3026
-    {
3027
-        // set things up for preview
3028
-        $this->_req_data['messenger'] = $messenger;
3029
-        $this->_req_data['message_type'] = $message_type;
3030
-        $this->_req_data['context'] = $context;
3031
-        $this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
3032
-        $active_messenger = $this->_message_resource_manager->get_active_messenger($messenger);
3033
-
3034
-        // let's save any existing fields that might be required by the messenger
3035
-        if (
3036
-            isset($this->_req_data['test_settings_fld'])
3037
-            && $active_messenger instanceof EE_messenger
3038
-            && apply_filters(
3039
-                'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3040
-                true,
3041
-                $this->_req_data['test_settings_fld'],
3042
-                $active_messenger
3043
-            )
3044
-        ) {
3045
-            $active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
3046
-        }
3047
-
3048
-        /**
3049
-         * Use filter to add additional controls on whether message can send or not
3050
-         */
3051
-        if (
3052
-            apply_filters(
3053
-                'FHEE__Messages_Admin_Page__do_test_send__can_send',
3054
-                true,
3055
-                $context,
3056
-                $this->_req_data,
3057
-                $messenger,
3058
-                $message_type
3059
-            )
3060
-        ) {
3061
-            if (EEM_Event::instance()->count() > 0) {
3062
-                $success = $this->_preview_message(true);
3063
-                if ($success) {
3064
-                    EE_Error::add_success(__('Test message sent', 'event_espresso'));
3065
-                } else {
3066
-                    EE_Error::add_error(
3067
-                        esc_html__('The test message was not sent', 'event_espresso'),
3068
-                        __FILE__,
3069
-                        __FUNCTION__,
3070
-                        __LINE__
3071
-                    );
3072
-                }
3073
-            } else {
3074
-                $this->noEventsErrorMessage(true);
3075
-            }
3076
-        }
3077
-    }
3078
-
3079
-
3080
-    /**
3081
-     * _generate_new_templates
3082
-     * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3083
-     * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3084
-     * for the event.
3085
-     *
3086
-     *
3087
-     * @param  string $messenger     the messenger we are generating templates for
3088
-     * @param array   $message_types array of message types that the templates are generated for.
3089
-     * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
3090
-     *                               indicate the message_template_group being used as the base.
3091
-     *
3092
-     * @param bool    $global
3093
-     *
3094
-     * @return array|bool array of data required for the redirect to the correct edit page or bool if
3095
-     *                               encountering problems.
3096
-     * @throws EE_Error
3097
-     */
3098
-    protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3099
-    {
3100
-
3101
-        // if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3102
-        // just don't generate any templates.
3103
-        if (empty($message_types)) {
3104
-            return true;
3105
-        }
3106
-
3107
-        return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3108
-    }
3109
-
3110
-
3111
-    /**
3112
-     * [_trash_or_restore_message_template]
3113
-     *
3114
-     * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3115
-     * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3116
-     *                        an individual context (FALSE).
3117
-     * @return void
3118
-     * @throws EE_Error
3119
-     * @throws InvalidArgumentException
3120
-     * @throws InvalidDataTypeException
3121
-     * @throws InvalidInterfaceException
3122
-     */
3123
-    protected function _trash_or_restore_message_template($trash = true, $all = false)
3124
-    {
3125
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3126
-        $MTP = EEM_Message_Template_Group::instance();
3127
-
3128
-        $success = 1;
3129
-
3130
-        // incoming GRP_IDs
3131
-        if ($all) {
3132
-            // Checkboxes
3133
-            if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3134
-                // if array has more than one element then success message should be plural.
3135
-                // todo: what about nonce?
3136
-                $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3137
-
3138
-                // cycle through checkboxes
3139
-                while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3140
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3141
-                    if (! $trashed_or_restored) {
3142
-                        $success = 0;
3143
-                    }
3144
-                }
3145
-            } else {
3146
-                // grab single GRP_ID and handle
3147
-                $GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
3148
-                if (! empty($GRP_ID)) {
3149
-                    $trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3150
-                    if (! $trashed_or_restored) {
3151
-                        $success = 0;
3152
-                    }
3153
-                } else {
3154
-                    $success = 0;
3155
-                }
3156
-            }
3157
-        }
3158
-
3159
-        $action_desc = $trash
3160
-            ? esc_html__('moved to the trash', 'event_espresso')
3161
-            : esc_html__('restored', 'event_espresso');
3162
-
3163
-        $action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched', 'event_espresso') : $action_desc;
3164
-
3165
-        $item_desc = $all ? _n(
3166
-            'Message Template Group',
3167
-            'Message Template Groups',
3168
-            $success,
3169
-            'event_espresso'
3170
-        ) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3171
-
3172
-        $item_desc = ! empty($this->_req_data['template_switch']) ? _n(
3173
-            'template',
3174
-            'templates',
3175
-            $success,
3176
-            'event_espresso'
3177
-        ) : $item_desc;
3178
-
3179
-        $this->_redirect_after_action($success, $item_desc, $action_desc, array());
3180
-    }
3181
-
3182
-
3183
-    /**
3184
-     * [_delete_message_template]
3185
-     * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3186
-     *
3187
-     * @return void
3188
-     * @throws EE_Error
3189
-     * @throws InvalidArgumentException
3190
-     * @throws InvalidDataTypeException
3191
-     * @throws InvalidInterfaceException
3192
-     */
3193
-    protected function _delete_message_template()
3194
-    {
3195
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3196
-
3197
-        // checkboxes
3198
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3199
-            // if array has more than one element then success message should be plural
3200
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3201
-
3202
-            // cycle through bulk action checkboxes
3203
-            while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3204
-                $success = $this->_delete_mtp_permanently($GRP_ID);
3205
-            }
3206
-        } else {
3207
-            // grab single grp_id and delete
3208
-            $GRP_ID = absint($this->_req_data['id']);
3209
-            $success = $this->_delete_mtp_permanently($GRP_ID);
3210
-        }
3211
-
3212
-        $this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
3213
-    }
3214
-
3215
-
3216
-    /**
3217
-     * helper for permanently deleting a mtP group and all related message_templates
3218
-     *
3219
-     * @param  int  $GRP_ID        The group being deleted
3220
-     * @param  bool $include_group whether to delete the Message Template Group as well.
3221
-     * @return bool boolean to indicate the success of the deletes or not.
3222
-     * @throws EE_Error
3223
-     * @throws InvalidArgumentException
3224
-     * @throws InvalidDataTypeException
3225
-     * @throws InvalidInterfaceException
3226
-     */
3227
-    private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3228
-    {
3229
-        $success = 1;
3230
-        $MTPG = EEM_Message_Template_Group::instance();
3231
-        // first let's GET this group
3232
-        $MTG = $MTPG->get_one_by_ID($GRP_ID);
3233
-        // then delete permanently all the related Message Templates
3234
-        $deleted = $MTG->delete_related_permanently('Message_Template');
3235
-
3236
-        if ($deleted === 0) {
3237
-            $success = 0;
3238
-        }
3239
-
3240
-        // now delete permanently this particular group
3241
-
3242
-        if ($include_group && ! $MTG->delete_permanently()) {
3243
-            $success = 0;
3244
-        }
3245
-
3246
-        return $success;
3247
-    }
3248
-
3249
-
3250
-    /**
3251
-     *    _learn_more_about_message_templates_link
3252
-     *
3253
-     * @access protected
3254
-     * @return string
3255
-     */
3256
-    protected function _learn_more_about_message_templates_link()
3257
-    {
3258
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3259
-               . esc_html__('learn more about how message templates works', 'event_espresso')
3260
-               . '</a>';
3261
-    }
3262
-
3263
-
3264
-    /**
3265
-     * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3266
-     * ajax and other routes.
3267
-     *
3268
-     * @return void
3269
-     * @throws DomainException
3270
-     */
3271
-    protected function _settings()
3272
-    {
3273
-
3274
-
3275
-        $this->_set_m_mt_settings();
3276
-
3277
-        $selected_messenger = isset($this->_req_data['selected_messenger'])
3278
-            ? $this->_req_data['selected_messenger']
3279
-            : 'email';
3280
-
3281
-        // let's setup the messenger tabs
3282
-        $this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3283
-            $this->_m_mt_settings['messenger_tabs'],
3284
-            'messenger_links',
3285
-            '|',
3286
-            $selected_messenger
3287
-        );
3288
-        $this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3289
-        $this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->';
3290
-
3291
-        $this->display_admin_page_with_sidebar();
3292
-    }
3293
-
3294
-
3295
-    /**
3296
-     * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3297
-     *
3298
-     * @access protected
3299
-     * @return void
3300
-     * @throws DomainException
3301
-     */
3302
-    protected function _set_m_mt_settings()
3303
-    {
3304
-        // first if this is already set then lets get out no need to regenerate data.
3305
-        if (! empty($this->_m_mt_settings)) {
3306
-            return;
3307
-        }
3308
-
3309
-        // get all installed messengers and message_types
3310
-        /** @type EE_messenger[] $messengers */
3311
-        $messengers = $this->_message_resource_manager->installed_messengers();
3312
-        /** @type EE_message_type[] $message_types */
3313
-        $message_types = $this->_message_resource_manager->installed_message_types();
3314
-
3315
-
3316
-        // assemble the array for the _tab_text_links helper
3317
-
3318
-        foreach ($messengers as $messenger) {
3319
-            $this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = array(
3320
-                'label' => ucwords($messenger->label['singular']),
3321
-                'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3322
-                    ? 'messenger-active'
3323
-                    : '',
3324
-                'href'  => $messenger->name,
3325
-                'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3326
-                'slug'  => $messenger->name,
3327
-                'obj'   => $messenger,
3328
-            );
3329
-
3330
-
3331
-            $message_types_for_messenger = $messenger->get_valid_message_types();
3332
-
3333
-            foreach ($message_types as $message_type) {
3334
-                // first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3335
-                // it shouldn't show in either the inactive OR active metabox.
3336
-                if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3337
-                    continue;
3338
-                }
3339
-
3340
-                $a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3341
-                    $messenger->name,
3342
-                    $message_type->name
3343
-                )
3344
-                    ? 'active'
3345
-                    : 'inactive';
3346
-
3347
-                $this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = array(
3348
-                    'label'    => ucwords($message_type->label['singular']),
3349
-                    'class'    => 'message-type-' . $a_or_i,
3350
-                    'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3351
-                    'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3352
-                    'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3353
-                    'title'    => $a_or_i === 'active'
3354
-                        ? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3355
-                        : esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3356
-                    'content'  => $a_or_i === 'active'
3357
-                        ? $this->_message_type_settings_content($message_type, $messenger, true)
3358
-                        : $this->_message_type_settings_content($message_type, $messenger),
3359
-                    'slug'     => $message_type->name,
3360
-                    'active'   => $a_or_i === 'active',
3361
-                    'obj'      => $message_type,
3362
-                );
3363
-            }
3364
-        }
3365
-    }
3366
-
3367
-
3368
-    /**
3369
-     * This just prepares the content for the message type settings
3370
-     *
3371
-     * @param  EE_message_type $message_type The message type object
3372
-     * @param  EE_messenger    $messenger    The messenger object
3373
-     * @param  boolean         $active       Whether the message type is active or not
3374
-     * @return string html output for the content
3375
-     * @throws DomainException
3376
-     */
3377
-    protected function _message_type_settings_content($message_type, $messenger, $active = false)
3378
-    {
3379
-        // get message type fields
3380
-        $fields = $message_type->get_admin_settings_fields();
3381
-        $settings_template_args['template_form_fields'] = '';
3382
-
3383
-        if (! empty($fields) && $active) {
3384
-            $existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3385
-            foreach ($fields as $fldname => $fldprops) {
3386
-                $field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3387
-                $template_form_field[ $field_id ] = array(
3388
-                    'name'       => 'message_type_settings[' . $fldname . ']',
3389
-                    'label'      => $fldprops['label'],
3390
-                    'input'      => $fldprops['field_type'],
3391
-                    'type'       => $fldprops['value_type'],
3392
-                    'required'   => $fldprops['required'],
3393
-                    'validation' => $fldprops['validation'],
3394
-                    'value'      => isset($existing_settings[ $fldname ])
3395
-                        ? $existing_settings[ $fldname ]
3396
-                        : $fldprops['default'],
3397
-                    'options'    => isset($fldprops['options'])
3398
-                        ? $fldprops['options']
3399
-                        : array(),
3400
-                    'default'    => isset($existing_settings[ $fldname ])
3401
-                        ? $existing_settings[ $fldname ]
3402
-                        : $fldprops['default'],
3403
-                    'css_class'  => 'no-drag',
3404
-                    'format'     => $fldprops['format'],
3405
-                );
3406
-            }
3407
-
3408
-
3409
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3410
-                ? $this->_generate_admin_form_fields(
3411
-                    $template_form_field,
3412
-                    'string',
3413
-                    'ee_mt_activate_form'
3414
-                )
3415
-                : '';
3416
-        }
3417
-
3418
-        $settings_template_args['description'] = $message_type->description;
3419
-        // we also need some hidden fields
3420
-        $settings_template_args['hidden_fields'] = array(
3421
-            'message_type_settings[messenger]'    => array(
3422
-                'type'  => 'hidden',
3423
-                'value' => $messenger->name,
3424
-            ),
3425
-            'message_type_settings[message_type]' => array(
3426
-                'type'  => 'hidden',
3427
-                'value' => $message_type->name,
3428
-            ),
3429
-            'type'                                => array(
3430
-                'type'  => 'hidden',
3431
-                'value' => 'message_type',
3432
-            ),
3433
-        );
3434
-
3435
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3436
-            $settings_template_args['hidden_fields'],
3437
-            'array'
3438
-        );
3439
-        $settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])
3440
-            ? ' hidden'
3441
-            : '';
3442
-
3443
-
3444
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3445
-        $content = EEH_Template::display_template($template, $settings_template_args, true);
3446
-
3447
-        return $content;
3448
-    }
3449
-
3450
-
3451
-    /**
3452
-     * Generate all the metaboxes for the message types and register them for the messages settings page.
3453
-     *
3454
-     * @access protected
3455
-     * @return void
3456
-     * @throws DomainException
3457
-     */
3458
-    protected function _messages_settings_metaboxes()
3459
-    {
3460
-        $this->_set_m_mt_settings();
3461
-        $m_boxes = $mt_boxes = array();
3462
-        $m_template_args = $mt_template_args = array();
3463
-
3464
-        $selected_messenger = isset($this->_req_data['selected_messenger'])
3465
-            ? $this->_req_data['selected_messenger']
3466
-            : 'email';
3467
-
3468
-        if (isset($this->_m_mt_settings['messenger_tabs'])) {
3469
-            foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3470
-                $hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
3471
-                $hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
3472
-                // messenger meta boxes
3473
-                $active = $selected_messenger === $messenger;
3474
-                $active_mt_tabs = isset(
3475
-                    $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3476
-                )
3477
-                    ? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3478
-                    : '';
3479
-                $m_boxes[ $messenger . '_a_box' ] = sprintf(
3480
-                    esc_html__('%s Settings', 'event_espresso'),
3481
-                    $tab_array['label']
3482
-                );
3483
-                $m_template_args[ $messenger . '_a_box' ] = array(
3484
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3485
-                    'inactive_message_types' => isset(
3486
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3487
-                    )
3488
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3489
-                        : '',
3490
-                    'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3491
-                    'hidden'                 => $active ? '' : ' hidden',
3492
-                    'hide_on_message'        => $hide_on_message,
3493
-                    'messenger'              => $messenger,
3494
-                    'active'                 => $active,
3495
-                );
3496
-                // message type meta boxes
3497
-                // (which is really just the inactive container for each messenger
3498
-                // showing inactive message types for that messenger)
3499
-                $mt_boxes[ $messenger . '_i_box' ] = esc_html__('Inactive Message Types', 'event_espresso');
3500
-                $mt_template_args[ $messenger . '_i_box' ] = array(
3501
-                    'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3502
-                    'inactive_message_types' => isset(
3503
-                        $this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3504
-                    )
3505
-                        ? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3506
-                        : '',
3507
-                    'hidden'                 => $active ? '' : ' hidden',
3508
-                    'hide_on_message'        => $hide_on_message,
3509
-                    'hide_off_message'       => $hide_off_message,
3510
-                    'messenger'              => $messenger,
3511
-                    'active'                 => $active,
3512
-                );
3513
-            }
3514
-        }
3515
-
3516
-
3517
-        // register messenger metaboxes
3518
-        $m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3519
-        foreach ($m_boxes as $box => $label) {
3520
-            $callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]);
3521
-            $msgr = str_replace('_a_box', '', $box);
3522
-            add_meta_box(
3523
-                'espresso_' . $msgr . '_settings',
3524
-                $label,
3525
-                function ($post, $metabox) {
3526
-                    echo EEH_Template::display_template(
3527
-                        $metabox["args"]["template_path"],
3528
-                        $metabox["args"]["template_args"],
3529
-                        true
3530
-                    );
3531
-                },
3532
-                $this->_current_screen->id,
3533
-                'normal',
3534
-                'high',
3535
-                $callback_args
3536
-            );
3537
-        }
3538
-
3539
-        // register message type metaboxes
3540
-        $mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3541
-        foreach ($mt_boxes as $box => $label) {
3542
-            $callback_args = array(
3543
-                'template_path' => $mt_template_path,
3544
-                'template_args' => $mt_template_args[ $box ],
3545
-            );
3546
-            $mt = str_replace('_i_box', '', $box);
3547
-            add_meta_box(
3548
-                'espresso_' . $mt . '_inactive_mts',
3549
-                $label,
3550
-                function ($post, $metabox) {
3551
-                    echo EEH_Template::display_template(
3552
-                        $metabox["args"]["template_path"],
3553
-                        $metabox["args"]["template_args"],
3554
-                        true
3555
-                    );
3556
-                },
3557
-                $this->_current_screen->id,
3558
-                'side',
3559
-                'high',
3560
-                $callback_args
3561
-            );
3562
-        }
3563
-
3564
-        // register metabox for global messages settings but only when on the main site.  On single site installs this
3565
-        // will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3566
-        if (is_main_site()) {
3567
-            add_meta_box(
3568
-                'espresso_global_message_settings',
3569
-                esc_html__('Global Message Settings', 'event_espresso'),
3570
-                array($this, 'global_messages_settings_metabox_content'),
3571
-                $this->_current_screen->id,
3572
-                'normal',
3573
-                'low',
3574
-                array()
3575
-            );
3576
-        }
3577
-    }
3578
-
3579
-
3580
-    /**
3581
-     *  This generates the content for the global messages settings metabox.
3582
-     *
3583
-     * @return string
3584
-     * @throws EE_Error
3585
-     * @throws InvalidArgumentException
3586
-     * @throws ReflectionException
3587
-     * @throws InvalidDataTypeException
3588
-     * @throws InvalidInterfaceException
3589
-     */
3590
-    public function global_messages_settings_metabox_content()
3591
-    {
3592
-        $form = $this->_generate_global_settings_form();
3593
-        echo $form->form_open(
3594
-            $this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
3595
-            'POST'
3596
-        )
3597
-             . $form->get_html()
3598
-             . $form->form_close();
3599
-    }
3600
-
3601
-
3602
-    /**
3603
-     * This generates and returns the form object for the global messages settings.
3604
-     *
3605
-     * @return EE_Form_Section_Proper
3606
-     * @throws EE_Error
3607
-     * @throws InvalidArgumentException
3608
-     * @throws ReflectionException
3609
-     * @throws InvalidDataTypeException
3610
-     * @throws InvalidInterfaceException
3611
-     */
3612
-    protected function _generate_global_settings_form()
3613
-    {
3614
-        EE_Registry::instance()->load_helper('HTML');
3615
-        /** @var EE_Network_Core_Config $network_config */
3616
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3617
-
3618
-        return new EE_Form_Section_Proper(
3619
-            array(
3620
-                'name'            => 'global_messages_settings',
3621
-                'html_id'         => 'global_messages_settings',
3622
-                'html_class'      => 'form-table',
3623
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3624
-                'subsections'     => apply_filters(
3625
-                    'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3626
-                    array(
3627
-                        'do_messages_on_same_request' => new EE_Select_Input(
3628
-                            array(
3629
-                                true  => esc_html__("On the same request", "event_espresso"),
3630
-                                false => esc_html__("On a separate request", "event_espresso"),
3631
-                            ),
3632
-                            array(
3633
-                                'default'         => $network_config->do_messages_on_same_request,
3634
-                                'html_label_text' => esc_html__(
3635
-                                    'Generate and send all messages:',
3636
-                                    'event_espresso'
3637
-                                ),
3638
-                                'html_help_text'  => esc_html__(
3639
-                                    'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system.  This makes things execute faster for people registering for your events.  However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',
3640
-                                    'event_espresso'
3641
-                                ),
3642
-                            )
3643
-                        ),
3644
-                        'delete_threshold'            => new EE_Select_Input(
3645
-                            array(
3646
-                                0  => esc_html__('Forever', 'event_espresso'),
3647
-                                3  => esc_html__('3 Months', 'event_espresso'),
3648
-                                6  => esc_html__('6 Months', 'event_espresso'),
3649
-                                9  => esc_html__('9 Months', 'event_espresso'),
3650
-                                12 => esc_html__('12 Months', 'event_espresso'),
3651
-                                24 => esc_html__('24 Months', 'event_espresso'),
3652
-                                36 => esc_html__('36 Months', 'event_espresso'),
3653
-                            ),
3654
-                            array(
3655
-                                'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3656
-                                'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3657
-                                'html_help_text'  => esc_html__(
3658
-                                    'You can control how long a record of processed messages is kept via this option.',
3659
-                                    'event_espresso'
3660
-                                ),
3661
-                            )
3662
-                        ),
3663
-                        'update_settings'             => new EE_Submit_Input(
3664
-                            array(
3665
-                                'default'         => esc_html__('Update', 'event_espresso'),
3666
-                                'html_label_text' => '&nbsp',
3667
-                            )
3668
-                        ),
3669
-                    )
3670
-                ),
3671
-            )
3672
-        );
3673
-    }
3674
-
3675
-
3676
-    /**
3677
-     * This handles updating the global settings set on the admin page.
3678
-     *
3679
-     * @throws EE_Error
3680
-     * @throws InvalidDataTypeException
3681
-     * @throws InvalidInterfaceException
3682
-     * @throws InvalidArgumentException
3683
-     * @throws ReflectionException
3684
-     */
3685
-    protected function _update_global_settings()
3686
-    {
3687
-        /** @var EE_Network_Core_Config $network_config */
3688
-        $network_config = EE_Registry::instance()->NET_CFG->core;
3689
-        $messages_config = EE_Registry::instance()->CFG->messages;
3690
-        $form = $this->_generate_global_settings_form();
3691
-        if ($form->was_submitted()) {
3692
-            $form->receive_form_submission();
3693
-            if ($form->is_valid()) {
3694
-                $valid_data = $form->valid_data();
3695
-                foreach ($valid_data as $property => $value) {
3696
-                    $setter = 'set_' . $property;
3697
-                    if (method_exists($network_config, $setter)) {
3698
-                        $network_config->{$setter}($value);
3699
-                    } elseif (
3700
-                        property_exists($network_config, $property)
3701
-                        && $network_config->{$property} !== $value
3702
-                    ) {
3703
-                        $network_config->{$property} = $value;
3704
-                    } elseif (
3705
-                        property_exists($messages_config, $property)
3706
-                        && $messages_config->{$property} !== $value
3707
-                    ) {
3708
-                        $messages_config->{$property} = $value;
3709
-                    }
3710
-                }
3711
-                // only update if the form submission was valid!
3712
-                EE_Registry::instance()->NET_CFG->update_config(true, false);
3713
-                EE_Registry::instance()->CFG->update_espresso_config();
3714
-                EE_Error::overwrite_success();
3715
-                EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3716
-            }
3717
-        }
3718
-        $this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3719
-    }
3720
-
3721
-
3722
-    /**
3723
-     * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3724
-     *
3725
-     * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3726
-     * @return string html formatted tabs
3727
-     * @throws DomainException
3728
-     */
3729
-    protected function _get_mt_tabs($tab_array)
3730
-    {
3731
-        $tab_array = (array) $tab_array;
3732
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3733
-        $tabs = '';
3734
-
3735
-        foreach ($tab_array as $tab) {
3736
-            $tabs .= EEH_Template::display_template($template, $tab, true);
3737
-        }
3738
-
3739
-        return $tabs;
3740
-    }
3741
-
3742
-
3743
-    /**
3744
-     * This prepares the content of the messenger meta box admin settings
3745
-     *
3746
-     * @param  EE_messenger $messenger The messenger we're setting up content for
3747
-     * @return string html formatted content
3748
-     * @throws DomainException
3749
-     */
3750
-    protected function _get_messenger_box_content(EE_messenger $messenger)
3751
-    {
3752
-
3753
-        $fields = $messenger->get_admin_settings_fields();
3754
-        $settings_template_args['template_form_fields'] = '';
3755
-
3756
-        // is $messenger active?
3757
-        $settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3758
-
3759
-
3760
-        if (! empty($fields)) {
3761
-            $existing_settings = $messenger->get_existing_admin_settings();
3762
-
3763
-            foreach ($fields as $fldname => $fldprops) {
3764
-                $field_id = $messenger->name . '-' . $fldname;
3765
-                $template_form_field[ $field_id ] = array(
3766
-                    'name'       => 'messenger_settings[' . $field_id . ']',
3767
-                    'label'      => $fldprops['label'],
3768
-                    'input'      => $fldprops['field_type'],
3769
-                    'type'       => $fldprops['value_type'],
3770
-                    'required'   => $fldprops['required'],
3771
-                    'validation' => $fldprops['validation'],
3772
-                    'value'      => isset($existing_settings[ $field_id ])
3773
-                        ? $existing_settings[ $field_id ]
3774
-                        : $fldprops['default'],
3775
-                    'css_class'  => '',
3776
-                    'format'     => $fldprops['format'],
3777
-                );
3778
-            }
3779
-
3780
-
3781
-            $settings_template_args['template_form_fields'] = ! empty($template_form_field)
3782
-                ? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3783
-                : '';
3784
-        }
3785
-
3786
-        // we also need some hidden fields
3787
-        $settings_template_args['hidden_fields'] = array(
3788
-            'messenger_settings[messenger]' => array(
3789
-                'type'  => 'hidden',
3790
-                'value' => $messenger->name,
3791
-            ),
3792
-            'type'                          => array(
3793
-                'type'  => 'hidden',
3794
-                'value' => 'messenger',
3795
-            ),
3796
-        );
3797
-
3798
-        // make sure any active message types that are existing are included in the hidden fields
3799
-        if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3800
-            foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3801
-                $settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = array(
3802
-                    'type'  => 'hidden',
3803
-                    'value' => $mt,
3804
-                );
3805
-            }
3806
-        }
3807
-        $settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3808
-            $settings_template_args['hidden_fields'],
3809
-            'array'
3810
-        );
3811
-        $active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3812
-
3813
-        $settings_template_args['messenger'] = $messenger->name;
3814
-        $settings_template_args['description'] = $messenger->description;
3815
-        $settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3816
-
3817
-
3818
-        $settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3819
-            $messenger->name
3820
-        )
3821
-            ? $settings_template_args['show_hide_edit_form']
3822
-            : ' hidden';
3823
-
3824
-        $settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3825
-            ? ' hidden'
3826
-            : $settings_template_args['show_hide_edit_form'];
3827
-
3828
-
3829
-        $settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3830
-        $settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3831
-        $settings_template_args['on_off_status'] = $active ? true : false;
3832
-        $template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3833
-        $content = EEH_Template::display_template(
3834
-            $template,
3835
-            $settings_template_args,
3836
-            true
3837
-        );
3838
-
3839
-        return $content;
3840
-    }
3841
-
3842
-
3843
-    /**
3844
-     * used by ajax on the messages settings page to activate|deactivate the messenger
3845
-     *
3846
-     * @throws DomainException
3847
-     * @throws EE_Error
3848
-     * @throws InvalidDataTypeException
3849
-     * @throws InvalidInterfaceException
3850
-     * @throws InvalidArgumentException
3851
-     * @throws ReflectionException
3852
-     */
3853
-    public function activate_messenger_toggle()
3854
-    {
3855
-        $success = true;
3856
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3857
-        // let's check that we have required data
3858
-        if (! isset($this->_req_data['messenger'])) {
3859
-            EE_Error::add_error(
3860
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3861
-                __FILE__,
3862
-                __FUNCTION__,
3863
-                __LINE__
3864
-            );
3865
-            $success = false;
3866
-        }
3867
-
3868
-        // do a nonce check here since we're not arriving via a normal route
3869
-        $nonce = isset($this->_req_data['activate_nonce'])
3870
-            ? sanitize_text_field($this->_req_data['activate_nonce'])
3871
-            : '';
3872
-        $nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3873
-
3874
-        $this->_verify_nonce($nonce, $nonce_ref);
3875
-
3876
-
3877
-        if (! isset($this->_req_data['status'])) {
3878
-            EE_Error::add_error(
3879
-                esc_html__(
3880
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3881
-                    'event_espresso'
3882
-                ),
3883
-                __FILE__,
3884
-                __FUNCTION__,
3885
-                __LINE__
3886
-            );
3887
-            $success = false;
3888
-        }
3889
-
3890
-        // do check to verify we have a valid status.
3891
-        $status = $this->_req_data['status'];
3892
-
3893
-        if ($status !== 'off' && $status !== 'on') {
3894
-            EE_Error::add_error(
3895
-                sprintf(
3896
-                    esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3897
-                    $this->_req_data['status']
3898
-                ),
3899
-                __FILE__,
3900
-                __FUNCTION__,
3901
-                __LINE__
3902
-            );
3903
-            $success = false;
3904
-        }
3905
-
3906
-        if ($success) {
3907
-            // made it here?  Stop dawdling then!!
3908
-            $success = $status === 'off'
3909
-                ? $this->_deactivate_messenger($this->_req_data['messenger'])
3910
-                : $this->_activate_messenger($this->_req_data['messenger']);
3911
-        }
3912
-
3913
-        $this->_template_args['success'] = $success;
3914
-
3915
-        // no special instructions so let's just do the json return (which should automatically do all the special stuff).
3916
-        $this->_return_json();
3917
-    }
3918
-
3919
-
3920
-    /**
3921
-     * used by ajax from the messages settings page to activate|deactivate a message type
3922
-     *
3923
-     * @throws DomainException
3924
-     * @throws EE_Error
3925
-     * @throws ReflectionException
3926
-     * @throws InvalidDataTypeException
3927
-     * @throws InvalidInterfaceException
3928
-     * @throws InvalidArgumentException
3929
-     */
3930
-    public function activate_mt_toggle()
3931
-    {
3932
-        $success = true;
3933
-        $this->_prep_default_response_for_messenger_or_message_type_toggle();
3934
-
3935
-        // let's make sure we have the necessary data
3936
-        if (! isset($this->_req_data['message_type'])) {
3937
-            EE_Error::add_error(
3938
-                esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3939
-                __FILE__,
3940
-                __FUNCTION__,
3941
-                __LINE__
3942
-            );
3943
-            $success = false;
3944
-        }
3945
-
3946
-        if (! isset($this->_req_data['messenger'])) {
3947
-            EE_Error::add_error(
3948
-                esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3949
-                __FILE__,
3950
-                __FUNCTION__,
3951
-                __LINE__
3952
-            );
3953
-            $success = false;
3954
-        }
3955
-
3956
-        if (! isset($this->_req_data['status'])) {
3957
-            EE_Error::add_error(
3958
-                esc_html__(
3959
-                    'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3960
-                    'event_espresso'
3961
-                ),
3962
-                __FILE__,
3963
-                __FUNCTION__,
3964
-                __LINE__
3965
-            );
3966
-            $success = false;
3967
-        }
3968
-
3969
-
3970
-        // do check to verify we have a valid status.
3971
-        $status = $this->_req_data['status'];
3972
-
3973
-        if ($status !== 'activate' && $status !== 'deactivate') {
3974
-            EE_Error::add_error(
3975
-                sprintf(
3976
-                    esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3977
-                    $this->_req_data['status']
3978
-                ),
3979
-                __FILE__,
3980
-                __FUNCTION__,
3981
-                __LINE__
3982
-            );
3983
-            $success = false;
3984
-        }
3985
-
3986
-
3987
-        // do a nonce check here since we're not arriving via a normal route
3988
-        $nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3989
-        $nonce_ref = $this->_req_data['message_type'] . '_nonce';
3990
-
3991
-        $this->_verify_nonce($nonce, $nonce_ref);
3992
-
3993
-        if ($success) {
3994
-            // made it here? um, what are you waiting for then?
3995
-            $success = $status === 'deactivate'
3996
-                ? $this->_deactivate_message_type_for_messenger(
3997
-                    $this->_req_data['messenger'],
3998
-                    $this->_req_data['message_type']
3999
-                )
4000
-                : $this->_activate_message_type_for_messenger(
4001
-                    $this->_req_data['messenger'],
4002
-                    $this->_req_data['message_type']
4003
-                );
4004
-        }
4005
-
4006
-        $this->_template_args['success'] = $success;
4007
-        $this->_return_json();
4008
-    }
4009
-
4010
-
4011
-    /**
4012
-     * Takes care of processing activating a messenger and preparing the appropriate response.
4013
-     *
4014
-     * @param string $messenger_name The name of the messenger being activated
4015
-     * @return bool
4016
-     * @throws DomainException
4017
-     * @throws EE_Error
4018
-     * @throws InvalidArgumentException
4019
-     * @throws ReflectionException
4020
-     * @throws InvalidDataTypeException
4021
-     * @throws InvalidInterfaceException
4022
-     */
4023
-    protected function _activate_messenger($messenger_name)
4024
-    {
4025
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4026
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4027
-        $message_types_to_activate = $active_messenger instanceof EE_Messenger
4028
-            ? $active_messenger->get_default_message_types()
4029
-            : array();
4030
-
4031
-        // ensure is active
4032
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
4033
-
4034
-        // set response_data for reload
4035
-        foreach ($message_types_to_activate as $message_type_name) {
4036
-            /** @var EE_message_type $message_type */
4037
-            $message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4038
-            if (
4039
-                $this->_message_resource_manager->is_message_type_active_for_messenger(
4040
-                    $messenger_name,
4041
-                    $message_type_name
4042
-                )
4043
-                && $message_type instanceof EE_message_type
4044
-            ) {
4045
-                $this->_template_args['data']['active_mts'][] = $message_type_name;
4046
-                if ($message_type->get_admin_settings_fields()) {
4047
-                    $this->_template_args['data']['mt_reload'][] = $message_type_name;
4048
-                }
4049
-            }
4050
-        }
4051
-
4052
-        // add success message for activating messenger
4053
-        return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4054
-    }
4055
-
4056
-
4057
-    /**
4058
-     * Takes care of processing deactivating a messenger and preparing the appropriate response.
4059
-     *
4060
-     * @param string $messenger_name The name of the messenger being activated
4061
-     * @return bool
4062
-     * @throws DomainException
4063
-     * @throws EE_Error
4064
-     * @throws InvalidArgumentException
4065
-     * @throws ReflectionException
4066
-     * @throws InvalidDataTypeException
4067
-     * @throws InvalidInterfaceException
4068
-     */
4069
-    protected function _deactivate_messenger($messenger_name)
4070
-    {
4071
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4072
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4073
-        $this->_message_resource_manager->deactivate_messenger($messenger_name);
4074
-
4075
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4076
-    }
4077
-
4078
-
4079
-    /**
4080
-     * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4081
-     *
4082
-     * @param string $messenger_name    The name of the messenger the message type is being activated for.
4083
-     * @param string $message_type_name The name of the message type being activated for the messenger
4084
-     * @return bool
4085
-     * @throws DomainException
4086
-     * @throws EE_Error
4087
-     * @throws InvalidArgumentException
4088
-     * @throws ReflectionException
4089
-     * @throws InvalidDataTypeException
4090
-     * @throws InvalidInterfaceException
4091
-     */
4092
-    protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4093
-    {
4094
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4095
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4096
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4097
-        $message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4098
-
4099
-        // ensure is active
4100
-        $this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
4101
-
4102
-        // set response for load
4103
-        if (
4104
-            $this->_message_resource_manager->is_message_type_active_for_messenger(
4105
-                $messenger_name,
4106
-                $message_type_name
4107
-            )
4108
-        ) {
4109
-            $this->_template_args['data']['active_mts'][] = $message_type_name;
4110
-            if ($message_type_to_activate->get_admin_settings_fields()) {
4111
-                $this->_template_args['data']['mt_reload'][] = $message_type_name;
4112
-            }
4113
-        }
4114
-
4115
-        return $this->_setup_response_message_for_activating_messenger_with_message_types(
4116
-            $active_messenger,
4117
-            $message_type_to_activate
4118
-        );
4119
-    }
4120
-
4121
-
4122
-    /**
4123
-     * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4124
-     *
4125
-     * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4126
-     * @param string $message_type_name The name of the message type being deactivated for the messenger
4127
-     * @return bool
4128
-     * @throws DomainException
4129
-     * @throws EE_Error
4130
-     * @throws InvalidArgumentException
4131
-     * @throws ReflectionException
4132
-     * @throws InvalidDataTypeException
4133
-     * @throws InvalidInterfaceException
4134
-     */
4135
-    protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4136
-    {
4137
-        /** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4138
-        $active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4139
-        /** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4140
-        $message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4141
-        $this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4142
-
4143
-        return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4144
-            $active_messenger,
4145
-            $message_type_to_deactivate
4146
-        );
4147
-    }
4148
-
4149
-
4150
-    /**
4151
-     * This just initializes the defaults for activating messenger and message type responses.
4152
-     */
4153
-    protected function _prep_default_response_for_messenger_or_message_type_toggle()
4154
-    {
4155
-        $this->_template_args['data']['active_mts'] = array();
4156
-        $this->_template_args['data']['mt_reload'] = array();
4157
-    }
4158
-
4159
-
4160
-    /**
4161
-     * Setup appropriate response for activating a messenger and/or message types
4162
-     *
4163
-     * @param EE_messenger         $messenger
4164
-     * @param EE_message_type|null $message_type
4165
-     * @return bool
4166
-     * @throws DomainException
4167
-     * @throws EE_Error
4168
-     * @throws InvalidArgumentException
4169
-     * @throws ReflectionException
4170
-     * @throws InvalidDataTypeException
4171
-     * @throws InvalidInterfaceException
4172
-     */
4173
-    protected function _setup_response_message_for_activating_messenger_with_message_types(
4174
-        $messenger,
4175
-        EE_Message_Type $message_type = null
4176
-    ) {
4177
-        // if $messenger isn't a valid messenger object then get out.
4178
-        if (! $messenger instanceof EE_Messenger) {
4179
-            EE_Error::add_error(
4180
-                esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4181
-                __FILE__,
4182
-                __FUNCTION__,
4183
-                __LINE__
4184
-            );
4185
-
4186
-            return false;
4187
-        }
4188
-        // activated
4189
-        if ($this->_template_args['data']['active_mts']) {
4190
-            EE_Error::overwrite_success();
4191
-            // activated a message type with the messenger
4192
-            if ($message_type instanceof EE_message_type) {
4193
-                EE_Error::add_success(
4194
-                    sprintf(
4195
-                        esc_html__(
4196
-                            '%s message type has been successfully activated with the %s messenger',
4197
-                            'event_espresso'
4198
-                        ),
4199
-                        ucwords($message_type->label['singular']),
4200
-                        ucwords($messenger->label['singular'])
4201
-                    )
4202
-                );
4203
-
4204
-                // if message type was invoice then let's make sure we activate the invoice payment method.
4205
-                if ($message_type->name === 'invoice') {
4206
-                    EE_Registry::instance()->load_lib('Payment_Method_Manager');
4207
-                    $pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4208
-                    if ($pm instanceof EE_Payment_Method) {
4209
-                        EE_Error::add_attention(
4210
-                            esc_html__(
4211
-                                'Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.',
4212
-                                'event_espresso'
4213
-                            )
4214
-                        );
4215
-                    }
4216
-                }
4217
-                // just toggles the entire messenger
4218
-            } else {
4219
-                EE_Error::add_success(
4220
-                    sprintf(
4221
-                        esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4222
-                        ucwords($messenger->label['singular'])
4223
-                    )
4224
-                );
4225
-            }
4226
-
4227
-            return true;
4228
-
4229
-            // possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4230
-            // message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4231
-            // in which case we just give a success message for the messenger being successfully activated.
4232
-        } else {
4233
-            if (! $messenger->get_default_message_types()) {
4234
-                // messenger doesn't have any default message types so still a success.
4235
-                EE_Error::add_success(
4236
-                    sprintf(
4237
-                        esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4238
-                        ucwords($messenger->label['singular'])
4239
-                    )
4240
-                );
4241
-
4242
-                return true;
4243
-            } else {
4244
-                EE_Error::add_error(
4245
-                    $message_type instanceof EE_message_type
4246
-                        ? sprintf(
4247
-                            esc_html__(
4248
-                                '%s message type was not successfully activated with the %s messenger',
4249
-                                'event_espresso'
4250
-                            ),
4251
-                            ucwords($message_type->label['singular']),
4252
-                            ucwords($messenger->label['singular'])
4253
-                        )
4254
-                        : sprintf(
4255
-                            esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4256
-                            ucwords($messenger->label['singular'])
4257
-                        ),
4258
-                    __FILE__,
4259
-                    __FUNCTION__,
4260
-                    __LINE__
4261
-                );
4262
-
4263
-                return false;
4264
-            }
4265
-        }
4266
-    }
4267
-
4268
-
4269
-    /**
4270
-     * This sets up the appropriate response for deactivating a messenger and/or message type.
4271
-     *
4272
-     * @param EE_messenger         $messenger
4273
-     * @param EE_message_type|null $message_type
4274
-     * @return bool
4275
-     * @throws DomainException
4276
-     * @throws EE_Error
4277
-     * @throws InvalidArgumentException
4278
-     * @throws ReflectionException
4279
-     * @throws InvalidDataTypeException
4280
-     * @throws InvalidInterfaceException
4281
-     */
4282
-    protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4283
-        $messenger,
4284
-        EE_message_type $message_type = null
4285
-    ) {
4286
-        EE_Error::overwrite_success();
4287
-
4288
-        // if $messenger isn't a valid messenger object then get out.
4289
-        if (! $messenger instanceof EE_Messenger) {
4290
-            EE_Error::add_error(
4291
-                esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4292
-                __FILE__,
4293
-                __FUNCTION__,
4294
-                __LINE__
4295
-            );
4296
-
4297
-            return false;
4298
-        }
4299
-
4300
-        if ($message_type instanceof EE_message_type) {
4301
-            $message_type_name = $message_type->name;
4302
-            EE_Error::add_success(
4303
-                sprintf(
4304
-                    esc_html__(
4305
-                        '%s message type has been successfully deactivated for the %s messenger.',
4306
-                        'event_espresso'
4307
-                    ),
4308
-                    ucwords($message_type->label['singular']),
4309
-                    ucwords($messenger->label['singular'])
4310
-                )
4311
-            );
4312
-        } else {
4313
-            $message_type_name = '';
4314
-            EE_Error::add_success(
4315
-                sprintf(
4316
-                    esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4317
-                    ucwords($messenger->label['singular'])
4318
-                )
4319
-            );
4320
-        }
4321
-
4322
-        // if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4323
-        if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4324
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
4325
-            $count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4326
-            if ($count_updated > 0) {
4327
-                $msg = $message_type_name === 'invoice'
4328
-                    ? esc_html__(
4329
-                        'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.',
4330
-                        'event_espresso'
4331
-                    )
4332
-                    : esc_html__(
4333
-                        'Deactivating the html messenger also automatically deactivates the invoice payment method.  In order for invoices to be generated the html messenger must be be active.  If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.',
4334
-                        'event_espresso'
4335
-                    );
4336
-                EE_Error::add_attention($msg);
4337
-            }
4338
-        }
4339
-
4340
-        return true;
4341
-    }
4342
-
4343
-
4344
-    /**
4345
-     * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4346
-     *
4347
-     * @throws DomainException
4348
-     */
4349
-    public function update_mt_form()
4350
-    {
4351
-        if (! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4352
-            EE_Error::add_error(
4353
-                esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4354
-                __FILE__,
4355
-                __FUNCTION__,
4356
-                __LINE__
4357
-            );
4358
-            $this->_return_json();
4359
-        }
4360
-
4361
-        $message_types = $this->get_installed_message_types();
4362
-
4363
-        $message_type = $message_types[ $this->_req_data['message_type'] ];
4364
-        $messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4365
-
4366
-        $content = $this->_message_type_settings_content(
4367
-            $message_type,
4368
-            $messenger,
4369
-            true
4370
-        );
4371
-        $this->_template_args['success'] = true;
4372
-        $this->_template_args['content'] = $content;
4373
-        $this->_return_json();
4374
-    }
4375
-
4376
-
4377
-    /**
4378
-     * this handles saving the settings for a messenger or message type
4379
-     *
4380
-     */
4381
-    public function save_settings()
4382
-    {
4383
-        if (! isset($this->_req_data['type'])) {
4384
-            EE_Error::add_error(
4385
-                esc_html__(
4386
-                    'Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
4387
-                    'event_espresso'
4388
-                ),
4389
-                __FILE__,
4390
-                __FUNCTION__,
4391
-                __LINE__
4392
-            );
4393
-            $this->_template_args['error'] = true;
4394
-            $this->_return_json();
4395
-        }
4396
-
4397
-
4398
-        if ($this->_req_data['type'] === 'messenger') {
4399
-            // this should be an array.
4400
-            $settings = $this->_req_data['messenger_settings'];
4401
-            $messenger = $settings['messenger'];
4402
-            // let's setup the settings data
4403
-            foreach ($settings as $key => $value) {
4404
-                switch ($key) {
4405
-                    case 'messenger':
4406
-                        unset($settings['messenger']);
4407
-                        break;
4408
-                    case 'message_types':
4409
-                        unset($settings['message_types']);
4410
-                        break;
4411
-                    default:
4412
-                        $settings[ $key ] = $value;
4413
-                        break;
4414
-                }
4415
-            }
4416
-            $this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4417
-        } elseif ($this->_req_data['type'] === 'message_type') {
4418
-            $settings = $this->_req_data['message_type_settings'];
4419
-            $messenger = $settings['messenger'];
4420
-            $message_type = $settings['message_type'];
4421
-
4422
-            foreach ($settings as $key => $value) {
4423
-                switch ($key) {
4424
-                    case 'messenger':
4425
-                        unset($settings['messenger']);
4426
-                        break;
4427
-                    case 'message_type':
4428
-                        unset($settings['message_type']);
4429
-                        break;
4430
-                    default:
4431
-                        $settings[ $key ] = $value;
4432
-                        break;
4433
-                }
4434
-            }
4435
-
4436
-            $this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4437
-        }
4438
-
4439
-        // okay we should have the data all setup.  Now we just update!
4440
-        $success = $this->_message_resource_manager->update_active_messengers_option();
4441
-
4442
-        if ($success) {
4443
-            EE_Error::add_success(__('Settings updated', 'event_espresso'));
4444
-        } else {
4445
-            EE_Error::add_error(
4446
-                esc_html__(
4447
-                    'Settings did not get updated',
4448
-                    'event_espresso'
4449
-                ),
4450
-                __FILE__,
4451
-                __FUNCTION__,
4452
-                __LINE__
4453
-            );
4454
-        }
4455
-
4456
-        $this->_template_args['success'] = $success;
4457
-        $this->_return_json();
4458
-    }
4459
-
4460
-
4461
-
4462
-
4463
-    /**  EE MESSAGE PROCESSING ACTIONS **/
4464
-
4465
-
4466
-    /**
4467
-     * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4468
-     * However, this does not send immediately, it just queues for sending.
4469
-     *
4470
-     * @since 4.9.0
4471
-     * @throws EE_Error
4472
-     * @throws InvalidDataTypeException
4473
-     * @throws InvalidInterfaceException
4474
-     * @throws InvalidArgumentException
4475
-     * @throws ReflectionException
4476
-     */
4477
-    protected function _generate_now()
4478
-    {
4479
-        EED_Messages::generate_now($this->_get_msg_ids_from_request());
4480
-        $this->_redirect_after_action(false, '', '', array(), true);
4481
-    }
4482
-
4483
-
4484
-    /**
4485
-     * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4486
-     * are EEM_Message::status_resend or EEM_Message::status_idle
4487
-     *
4488
-     * @since 4.9.0
4489
-     * @throws EE_Error
4490
-     * @throws InvalidDataTypeException
4491
-     * @throws InvalidInterfaceException
4492
-     * @throws InvalidArgumentException
4493
-     * @throws ReflectionException
4494
-     */
4495
-    protected function _generate_and_send_now()
4496
-    {
4497
-        EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4498
-        $this->_redirect_after_action(false, '', '', array(), true);
4499
-    }
4500
-
4501
-
4502
-    /**
4503
-     * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4504
-     *
4505
-     * @since 4.9.0
4506
-     * @throws EE_Error
4507
-     * @throws InvalidDataTypeException
4508
-     * @throws InvalidInterfaceException
4509
-     * @throws InvalidArgumentException
4510
-     * @throws ReflectionException
4511
-     */
4512
-    protected function _queue_for_resending()
4513
-    {
4514
-        EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4515
-        $this->_redirect_after_action(false, '', '', array(), true);
4516
-    }
4517
-
4518
-
4519
-    /**
4520
-     *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4521
-     *
4522
-     * @since 4.9.0
4523
-     * @throws EE_Error
4524
-     * @throws InvalidDataTypeException
4525
-     * @throws InvalidInterfaceException
4526
-     * @throws InvalidArgumentException
4527
-     * @throws ReflectionException
4528
-     */
4529
-    protected function _send_now()
4530
-    {
4531
-        EED_Messages::send_now($this->_get_msg_ids_from_request());
4532
-        $this->_redirect_after_action(false, '', '', array(), true);
4533
-    }
4534
-
4535
-
4536
-    /**
4537
-     * Deletes EE_messages for IDs in the request.
4538
-     *
4539
-     * @since 4.9.0
4540
-     * @throws EE_Error
4541
-     * @throws InvalidDataTypeException
4542
-     * @throws InvalidInterfaceException
4543
-     * @throws InvalidArgumentException
4544
-     */
4545
-    protected function _delete_ee_messages()
4546
-    {
4547
-        $msg_ids = $this->_get_msg_ids_from_request();
4548
-        $deleted_count = 0;
4549
-        foreach ($msg_ids as $msg_id) {
4550
-            if (EEM_Message::instance()->delete_by_ID($msg_id)) {
4551
-                $deleted_count++;
4552
-            }
4553
-        }
4554
-        if ($deleted_count) {
4555
-            EE_Error::add_success(
4556
-                esc_html(
4557
-                    _n(
4558
-                        'Message successfully deleted',
4559
-                        'Messages successfully deleted',
4560
-                        $deleted_count,
4561
-                        'event_espresso'
4562
-                    )
4563
-                )
4564
-            );
4565
-            $this->_redirect_after_action(
4566
-                false,
4567
-                '',
4568
-                '',
4569
-                array(),
4570
-                true
4571
-            );
4572
-        } else {
4573
-            EE_Error::add_error(
4574
-                _n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
4575
-                __FILE__,
4576
-                __FUNCTION__,
4577
-                __LINE__
4578
-            );
4579
-            $this->_redirect_after_action(false, '', '', array(), true);
4580
-        }
4581
-    }
4582
-
4583
-
4584
-    /**
4585
-     *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4586
-     *
4587
-     * @since 4.9.0
4588
-     * @return array
4589
-     */
4590
-    protected function _get_msg_ids_from_request()
4591
-    {
4592
-        if (! isset($this->_req_data['MSG_ID'])) {
4593
-            return array();
4594
-        }
4595
-
4596
-        return is_array($this->_req_data['MSG_ID'])
4597
-            ? array_keys($this->_req_data['MSG_ID'])
4598
-            : array($this->_req_data['MSG_ID']);
4599
-    }
2674
+		$output = ob_get_contents();
2675
+		ob_clean();
2676
+		$this->_context_switcher = $output;
2677
+	}
2678
+
2679
+
2680
+	/**
2681
+	 * utility for sanitizing new values coming in.
2682
+	 * Note: this is only used when updating a context.
2683
+	 *
2684
+	 * @access protected
2685
+	 *
2686
+	 * @param int $index This helps us know which template field to select from the request array.
2687
+	 *
2688
+	 * @return array
2689
+	 */
2690
+	protected function _set_message_template_column_values($index)
2691
+	{
2692
+		if (is_array($this->_req_data['MTP_template_fields'][ $index ]['content'])) {
2693
+			foreach ($this->_req_data['MTP_template_fields'][ $index ]['content'] as $field => $value) {
2694
+				$this->_req_data['MTP_template_fields'][ $index ]['content'][ $field ] = $value;
2695
+			}
2696
+		}
2697
+
2698
+
2699
+		$set_column_values = array(
2700
+			'MTP_ID'             => absint($this->_req_data['MTP_template_fields'][ $index ]['MTP_ID']),
2701
+			'GRP_ID'             => absint($this->_req_data['GRP_ID']),
2702
+			'MTP_user_id'        => absint($this->_req_data['MTP_user_id']),
2703
+			'MTP_messenger'      => strtolower($this->_req_data['MTP_messenger']),
2704
+			'MTP_message_type'   => strtolower($this->_req_data['MTP_message_type']),
2705
+			'MTP_template_field' => strtolower($this->_req_data['MTP_template_fields'][ $index ]['name']),
2706
+			'MTP_context'        => strtolower($this->_req_data['MTP_context']),
2707
+			'MTP_content'        => $this->_req_data['MTP_template_fields'][ $index ]['content'],
2708
+			'MTP_is_global'      => isset($this->_req_data['MTP_is_global'])
2709
+				? absint($this->_req_data['MTP_is_global'])
2710
+				: 0,
2711
+			'MTP_is_override'    => isset($this->_req_data['MTP_is_override'])
2712
+				? absint($this->_req_data['MTP_is_override'])
2713
+				: 0,
2714
+			'MTP_deleted'        => absint($this->_req_data['MTP_deleted']),
2715
+			'MTP_is_active'      => absint($this->_req_data['MTP_is_active']),
2716
+		);
2717
+
2718
+
2719
+		return $set_column_values;
2720
+	}
2721
+
2722
+
2723
+	protected function _insert_or_update_message_template($new = false)
2724
+	{
2725
+		$success = 0;
2726
+		$override = false;
2727
+
2728
+		// setup notices description
2729
+		$messenger_slug = ! empty($this->_req_data['MTP_messenger']) ? $this->_req_data['MTP_messenger'] : '';
2730
+
2731
+		// need the message type and messenger objects to be able to use the labels for the notices
2732
+		$messenger_object = $this->_message_resource_manager->get_messenger($messenger_slug);
2733
+		$messenger_label = $messenger_object instanceof EE_messenger
2734
+			? ucwords($messenger_object->label['singular'])
2735
+			: '';
2736
+
2737
+		$message_type_slug = ! empty($this->_req_data['MTP_message_type'])
2738
+			? $this->_req_data['MTP_message_type']
2739
+			: '';
2740
+		$message_type_object = $this->_message_resource_manager->get_message_type($message_type_slug);
2741
+
2742
+		$message_type_label = $message_type_object instanceof EE_message_type
2743
+			? ucwords($message_type_object->label['singular'])
2744
+			: '';
2745
+
2746
+		$context_slug = ! empty($this->_req_data['MTP_context'])
2747
+			? $this->_req_data['MTP_context']
2748
+			: '';
2749
+		$context = ucwords(str_replace('_', ' ', $context_slug));
2750
+
2751
+		$item_desc = $messenger_label && $message_type_label
2752
+			? $messenger_label . ' ' . $message_type_label . ' ' . $context . ' '
2753
+			: '';
2754
+		$item_desc .= 'Message Template';
2755
+		$query_args = array();
2756
+		$edit_array = array();
2757
+		$action_desc = '';
2758
+
2759
+		// if this is "new" then we need to generate the default contexts for the selected messenger/message_type for
2760
+		// user to edit.
2761
+		if ($new) {
2762
+			$GRP_ID = ! empty($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : 0;
2763
+			if ($edit_array = $this->_generate_new_templates($messenger_slug, $message_type_slug, $GRP_ID)) {
2764
+				if (empty($edit_array)) {
2765
+					$success = 0;
2766
+				} else {
2767
+					$success = 1;
2768
+					$edit_array = $edit_array[0];
2769
+					$query_args = array(
2770
+						'id'      => $edit_array['GRP_ID'],
2771
+						'context' => $edit_array['MTP_context'],
2772
+						'action'  => 'edit_message_template',
2773
+					);
2774
+				}
2775
+			}
2776
+			$action_desc = 'created';
2777
+		} else {
2778
+			$MTPG = EEM_Message_Template_Group::instance();
2779
+			$MTP = EEM_Message_Template::instance();
2780
+
2781
+
2782
+			// run update for each template field in displayed context
2783
+			if (! isset($this->_req_data['MTP_template_fields']) && empty($this->_req_data['MTP_template_fields'])) {
2784
+				EE_Error::add_error(
2785
+					esc_html__(
2786
+						'There was a problem saving the template fields from the form because I didn\'t receive any actual template field data.',
2787
+						'event_espresso'
2788
+					),
2789
+					__FILE__,
2790
+					__FUNCTION__,
2791
+					__LINE__
2792
+				);
2793
+				$success = 0;
2794
+			} else {
2795
+				// first validate all fields!
2796
+				// this filter allows client code to add its own validation to the template fields as well.
2797
+				// returning an empty array means everything passed validation.
2798
+				// errors in validation should be represented in an array with the following shape:
2799
+				// array(
2800
+				//   'fieldname' => array(
2801
+				//          'msg' => 'error message'
2802
+				//          'value' => 'value for field producing error'
2803
+				// )
2804
+				$custom_validation = (array) apply_filters(
2805
+					'FHEE__Messages_Admin_Page___insert_or_update_message_template__validates',
2806
+					array(),
2807
+					$this->_req_data['MTP_template_fields'],
2808
+					$context_slug,
2809
+					$messenger_slug,
2810
+					$message_type_slug
2811
+				);
2812
+
2813
+				$system_validation = $MTPG->validate(
2814
+					$this->_req_data['MTP_template_fields'],
2815
+					$context_slug,
2816
+					$messenger_slug,
2817
+					$message_type_slug
2818
+				);
2819
+
2820
+				$system_validation = ! is_array($system_validation) && $system_validation ? array()
2821
+					: $system_validation;
2822
+				$validates = array_merge($custom_validation, $system_validation);
2823
+
2824
+				// if $validate returned error messages (i.e. is_array()) then we need to process them and setup an
2825
+				// appropriate response. HMM, dang this isn't correct, $validates will ALWAYS be an array.
2826
+				//  WE need to make sure there is no actual error messages in validates.
2827
+				if (is_array($validates) && ! empty($validates)) {
2828
+					// add the transient so when the form loads we know which fields to highlight
2829
+					$this->_add_transient('edit_message_template', $validates);
2830
+
2831
+					$success = 0;
2832
+
2833
+					// setup notices
2834
+					foreach ($validates as $field => $error) {
2835
+						if (isset($error['msg'])) {
2836
+							EE_Error::add_error($error['msg'], __FILE__, __FUNCTION__, __LINE__);
2837
+						}
2838
+					}
2839
+				} else {
2840
+					$set_column_values = array();
2841
+					foreach ($this->_req_data['MTP_template_fields'] as $template_field => $content) {
2842
+						$set_column_values = $this->_set_message_template_column_values($template_field);
2843
+
2844
+						$where_cols_n_values = array(
2845
+							'MTP_ID' => $this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'],
2846
+						);
2847
+						// if they aren't allowed to use all JS, restrict them to just posty-y tags
2848
+						if (! current_user_can('unfiltered_html')) {
2849
+							if (is_array($set_column_values['MTP_content'])) {
2850
+								foreach ($set_column_values['MTP_content'] as $key => $value) {
2851
+									// remove slashes so wp_kses works properly (its wp_kses_stripslashes() function
2852
+									// only removes slashes from double-quotes, so attributes using single quotes always
2853
+									// appear invalid.) But currently the models expect slashed data, so after wp_kses
2854
+									// runs we need to re-slash the data. Sheesh. See
2855
+									// https://events.codebasehq.com/projects/event-espresso/tickets/11211#update-47321587
2856
+									$set_column_values['MTP_content'][ $key ] = addslashes(
2857
+										wp_kses(
2858
+											stripslashes($value),
2859
+											wp_kses_allowed_html('post')
2860
+										)
2861
+									);
2862
+								}
2863
+							} else {
2864
+								$set_column_values['MTP_content'] = wp_kses(
2865
+									$set_column_values['MTP_content'],
2866
+									wp_kses_allowed_html('post')
2867
+								);
2868
+							}
2869
+						}
2870
+						$message_template_fields = array(
2871
+							'GRP_ID'             => $set_column_values['GRP_ID'],
2872
+							'MTP_template_field' => $set_column_values['MTP_template_field'],
2873
+							'MTP_context'        => $set_column_values['MTP_context'],
2874
+							'MTP_content'        => $set_column_values['MTP_content'],
2875
+						);
2876
+						if ($updated = $MTP->update($message_template_fields, array($where_cols_n_values))) {
2877
+							if ($updated === false) {
2878
+								EE_Error::add_error(
2879
+									sprintf(
2880
+										esc_html__('%s field was NOT updated for some reason', 'event_espresso'),
2881
+										$template_field
2882
+									),
2883
+									__FILE__,
2884
+									__FUNCTION__,
2885
+									__LINE__
2886
+								);
2887
+							} else {
2888
+								$success = 1;
2889
+							}
2890
+						} else {
2891
+							// only do this logic if we don't have a MTP_ID for this field
2892
+							if (empty($this->_req_data['MTP_template_fields'][ $template_field ]['MTP_ID'])) {
2893
+								// this has already been through the template field validator and sanitized, so it will be
2894
+								// safe to insert this field.  Why insert?  This typically happens when we introduce a new
2895
+								// message template field in a messenger/message type and existing users don't have the
2896
+								// default setup for it.
2897
+								// @link https://events.codebasehq.com/projects/event-espresso/tickets/9465
2898
+								$updated = $MTP->insert($message_template_fields);
2899
+								if (! $updated || is_wp_error($updated)) {
2900
+									EE_Error::add_error(
2901
+										sprintf(
2902
+											esc_html__('%s field could not be updated.', 'event_espresso'),
2903
+											$template_field
2904
+										),
2905
+										__FILE__,
2906
+										__FUNCTION__,
2907
+										__LINE__
2908
+									);
2909
+									$success = 0;
2910
+								} else {
2911
+									$success = 1;
2912
+								}
2913
+							}
2914
+						}
2915
+						$action_desc = 'updated';
2916
+					}
2917
+
2918
+					// we can use the last set_column_values for the MTPG update (because its the same for all of these specific MTPs)
2919
+					$mtpg_fields = array(
2920
+						'MTP_user_id'      => $set_column_values['MTP_user_id'],
2921
+						'MTP_messenger'    => $set_column_values['MTP_messenger'],
2922
+						'MTP_message_type' => $set_column_values['MTP_message_type'],
2923
+						'MTP_is_global'    => $set_column_values['MTP_is_global'],
2924
+						'MTP_is_override'  => $set_column_values['MTP_is_override'],
2925
+						'MTP_deleted'      => $set_column_values['MTP_deleted'],
2926
+						'MTP_is_active'    => $set_column_values['MTP_is_active'],
2927
+						'MTP_name'         => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_name'])
2928
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_name']
2929
+							: '',
2930
+						'MTP_description'  => ! empty($this->_req_data['ee_msg_non_global_fields']['MTP_description'])
2931
+							? $this->_req_data['ee_msg_non_global_fields']['MTP_description']
2932
+							: '',
2933
+					);
2934
+
2935
+					$mtpg_where = array('GRP_ID' => $set_column_values['GRP_ID']);
2936
+					$updated = $MTPG->update($mtpg_fields, array($mtpg_where));
2937
+
2938
+					if ($updated === false) {
2939
+						EE_Error::add_error(
2940
+							sprintf(
2941
+								esc_html__(
2942
+									'The Message Template Group (%d) was NOT updated for some reason',
2943
+									'event_espresso'
2944
+								),
2945
+								$set_column_values['GRP_ID']
2946
+							),
2947
+							__FILE__,
2948
+							__FUNCTION__,
2949
+							__LINE__
2950
+						);
2951
+					} else {
2952
+						// k now we need to ensure the template_pack and template_variation fields are set.
2953
+						$template_pack = ! empty($this->_req_data['MTP_template_pack'])
2954
+							? $this->_req_data['MTP_template_pack']
2955
+							: 'default';
2956
+
2957
+						$template_variation = ! empty($this->_req_data['MTP_template_variation'])
2958
+							? $this->_req_data['MTP_template_variation']
2959
+							: 'default';
2960
+
2961
+						$mtpg_obj = $MTPG->get_one_by_ID($set_column_values['GRP_ID']);
2962
+						if ($mtpg_obj instanceof EE_Message_Template_Group) {
2963
+							$mtpg_obj->set_template_pack_name($template_pack);
2964
+							$mtpg_obj->set_template_pack_variation($template_variation);
2965
+						}
2966
+						$success = 1;
2967
+					}
2968
+				}
2969
+			}
2970
+		}
2971
+
2972
+		// we return things differently if doing ajax
2973
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2974
+			$this->_template_args['success'] = $success;
2975
+			$this->_template_args['error'] = ! $success ? true : false;
2976
+			$this->_template_args['content'] = '';
2977
+			$this->_template_args['data'] = array(
2978
+				'grpID'        => $edit_array['GRP_ID'],
2979
+				'templateName' => $edit_array['template_name'],
2980
+			);
2981
+			if ($success) {
2982
+				EE_Error::overwrite_success();
2983
+				EE_Error::add_success(
2984
+					esc_html__(
2985
+						'The new template has been created and automatically selected for this event.  You can edit the new template by clicking the edit button.  Note before this template is assigned to this event, the event must be saved.',
2986
+						'event_espresso'
2987
+					)
2988
+				);
2989
+			}
2990
+
2991
+			$this->_return_json();
2992
+		}
2993
+
2994
+
2995
+		// was a test send triggered?
2996
+		if (isset($this->_req_data['test_button'])) {
2997
+			EE_Error::overwrite_success();
2998
+			$this->_do_test_send($context_slug, $messenger_slug, $message_type_slug);
2999
+			$override = true;
3000
+		}
3001
+
3002
+		if (empty($query_args)) {
3003
+			$query_args = array(
3004
+				'id'      => $this->_req_data['GRP_ID'],
3005
+				'context' => $context_slug,
3006
+				'action'  => 'edit_message_template',
3007
+			);
3008
+		}
3009
+
3010
+		$this->_redirect_after_action($success, $item_desc, $action_desc, $query_args, $override);
3011
+	}
3012
+
3013
+
3014
+	/**
3015
+	 * processes a test send request to do an actual messenger delivery test for the given message template being tested
3016
+	 *
3017
+	 * @param  string $context      what context being tested
3018
+	 * @param  string $messenger    messenger being tested
3019
+	 * @param  string $message_type message type being tested
3020
+	 * @throws EE_Error
3021
+	 * @throws InvalidArgumentException
3022
+	 * @throws InvalidDataTypeException
3023
+	 * @throws InvalidInterfaceException
3024
+	 */
3025
+	protected function _do_test_send($context, $messenger, $message_type)
3026
+	{
3027
+		// set things up for preview
3028
+		$this->_req_data['messenger'] = $messenger;
3029
+		$this->_req_data['message_type'] = $message_type;
3030
+		$this->_req_data['context'] = $context;
3031
+		$this->_req_data['GRP_ID'] = isset($this->_req_data['GRP_ID']) ? $this->_req_data['GRP_ID'] : '';
3032
+		$active_messenger = $this->_message_resource_manager->get_active_messenger($messenger);
3033
+
3034
+		// let's save any existing fields that might be required by the messenger
3035
+		if (
3036
+			isset($this->_req_data['test_settings_fld'])
3037
+			&& $active_messenger instanceof EE_messenger
3038
+			&& apply_filters(
3039
+				'FHEE__Messages_Admin_Page__do_test_send__set_existing_test_settings',
3040
+				true,
3041
+				$this->_req_data['test_settings_fld'],
3042
+				$active_messenger
3043
+			)
3044
+		) {
3045
+			$active_messenger->set_existing_test_settings($this->_req_data['test_settings_fld']);
3046
+		}
3047
+
3048
+		/**
3049
+		 * Use filter to add additional controls on whether message can send or not
3050
+		 */
3051
+		if (
3052
+			apply_filters(
3053
+				'FHEE__Messages_Admin_Page__do_test_send__can_send',
3054
+				true,
3055
+				$context,
3056
+				$this->_req_data,
3057
+				$messenger,
3058
+				$message_type
3059
+			)
3060
+		) {
3061
+			if (EEM_Event::instance()->count() > 0) {
3062
+				$success = $this->_preview_message(true);
3063
+				if ($success) {
3064
+					EE_Error::add_success(__('Test message sent', 'event_espresso'));
3065
+				} else {
3066
+					EE_Error::add_error(
3067
+						esc_html__('The test message was not sent', 'event_espresso'),
3068
+						__FILE__,
3069
+						__FUNCTION__,
3070
+						__LINE__
3071
+					);
3072
+				}
3073
+			} else {
3074
+				$this->noEventsErrorMessage(true);
3075
+			}
3076
+		}
3077
+	}
3078
+
3079
+
3080
+	/**
3081
+	 * _generate_new_templates
3082
+	 * This will handle the messenger, message_type selection when "adding a new custom template" for an event and will
3083
+	 * automatically create the defaults for the event.  The user would then be redirected to edit the default context
3084
+	 * for the event.
3085
+	 *
3086
+	 *
3087
+	 * @param  string $messenger     the messenger we are generating templates for
3088
+	 * @param array   $message_types array of message types that the templates are generated for.
3089
+	 * @param int     $GRP_ID        If this is a custom template being generated then a GRP_ID needs to be included to
3090
+	 *                               indicate the message_template_group being used as the base.
3091
+	 *
3092
+	 * @param bool    $global
3093
+	 *
3094
+	 * @return array|bool array of data required for the redirect to the correct edit page or bool if
3095
+	 *                               encountering problems.
3096
+	 * @throws EE_Error
3097
+	 */
3098
+	protected function _generate_new_templates($messenger, $message_types, $GRP_ID = 0, $global = false)
3099
+	{
3100
+
3101
+		// if no $message_types are given then that's okay... this may be a messenger that just adds shortcodes, so we
3102
+		// just don't generate any templates.
3103
+		if (empty($message_types)) {
3104
+			return true;
3105
+		}
3106
+
3107
+		return EEH_MSG_Template::generate_new_templates($messenger, $message_types, $GRP_ID, $global);
3108
+	}
3109
+
3110
+
3111
+	/**
3112
+	 * [_trash_or_restore_message_template]
3113
+	 *
3114
+	 * @param  boolean $trash whether to move an item to trash/restore (TRUE) or restore it (FALSE)
3115
+	 * @param boolean  $all   whether this is going to trash/restore all contexts within a template group (TRUE) OR just
3116
+	 *                        an individual context (FALSE).
3117
+	 * @return void
3118
+	 * @throws EE_Error
3119
+	 * @throws InvalidArgumentException
3120
+	 * @throws InvalidDataTypeException
3121
+	 * @throws InvalidInterfaceException
3122
+	 */
3123
+	protected function _trash_or_restore_message_template($trash = true, $all = false)
3124
+	{
3125
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3126
+		$MTP = EEM_Message_Template_Group::instance();
3127
+
3128
+		$success = 1;
3129
+
3130
+		// incoming GRP_IDs
3131
+		if ($all) {
3132
+			// Checkboxes
3133
+			if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3134
+				// if array has more than one element then success message should be plural.
3135
+				// todo: what about nonce?
3136
+				$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3137
+
3138
+				// cycle through checkboxes
3139
+				while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3140
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3141
+					if (! $trashed_or_restored) {
3142
+						$success = 0;
3143
+					}
3144
+				}
3145
+			} else {
3146
+				// grab single GRP_ID and handle
3147
+				$GRP_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
3148
+				if (! empty($GRP_ID)) {
3149
+					$trashed_or_restored = $trash ? $MTP->delete_by_ID($GRP_ID) : $MTP->restore_by_ID($GRP_ID);
3150
+					if (! $trashed_or_restored) {
3151
+						$success = 0;
3152
+					}
3153
+				} else {
3154
+					$success = 0;
3155
+				}
3156
+			}
3157
+		}
3158
+
3159
+		$action_desc = $trash
3160
+			? esc_html__('moved to the trash', 'event_espresso')
3161
+			: esc_html__('restored', 'event_espresso');
3162
+
3163
+		$action_desc = ! empty($this->_req_data['template_switch']) ? esc_html__('switched', 'event_espresso') : $action_desc;
3164
+
3165
+		$item_desc = $all ? _n(
3166
+			'Message Template Group',
3167
+			'Message Template Groups',
3168
+			$success,
3169
+			'event_espresso'
3170
+		) : _n('Message Template Context', 'Message Template Contexts', $success, 'event_espresso');
3171
+
3172
+		$item_desc = ! empty($this->_req_data['template_switch']) ? _n(
3173
+			'template',
3174
+			'templates',
3175
+			$success,
3176
+			'event_espresso'
3177
+		) : $item_desc;
3178
+
3179
+		$this->_redirect_after_action($success, $item_desc, $action_desc, array());
3180
+	}
3181
+
3182
+
3183
+	/**
3184
+	 * [_delete_message_template]
3185
+	 * NOTE: this handles not only the deletion of the groups but also all the templates belonging to that group.
3186
+	 *
3187
+	 * @return void
3188
+	 * @throws EE_Error
3189
+	 * @throws InvalidArgumentException
3190
+	 * @throws InvalidDataTypeException
3191
+	 * @throws InvalidInterfaceException
3192
+	 */
3193
+	protected function _delete_message_template()
3194
+	{
3195
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3196
+
3197
+		// checkboxes
3198
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3199
+			// if array has more than one element then success message should be plural
3200
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3201
+
3202
+			// cycle through bulk action checkboxes
3203
+			while (list($GRP_ID, $value) = each($this->_req_data['checkbox'])) {
3204
+				$success = $this->_delete_mtp_permanently($GRP_ID);
3205
+			}
3206
+		} else {
3207
+			// grab single grp_id and delete
3208
+			$GRP_ID = absint($this->_req_data['id']);
3209
+			$success = $this->_delete_mtp_permanently($GRP_ID);
3210
+		}
3211
+
3212
+		$this->_redirect_after_action($success, 'Message Templates', 'deleted', array());
3213
+	}
3214
+
3215
+
3216
+	/**
3217
+	 * helper for permanently deleting a mtP group and all related message_templates
3218
+	 *
3219
+	 * @param  int  $GRP_ID        The group being deleted
3220
+	 * @param  bool $include_group whether to delete the Message Template Group as well.
3221
+	 * @return bool boolean to indicate the success of the deletes or not.
3222
+	 * @throws EE_Error
3223
+	 * @throws InvalidArgumentException
3224
+	 * @throws InvalidDataTypeException
3225
+	 * @throws InvalidInterfaceException
3226
+	 */
3227
+	private function _delete_mtp_permanently($GRP_ID, $include_group = true)
3228
+	{
3229
+		$success = 1;
3230
+		$MTPG = EEM_Message_Template_Group::instance();
3231
+		// first let's GET this group
3232
+		$MTG = $MTPG->get_one_by_ID($GRP_ID);
3233
+		// then delete permanently all the related Message Templates
3234
+		$deleted = $MTG->delete_related_permanently('Message_Template');
3235
+
3236
+		if ($deleted === 0) {
3237
+			$success = 0;
3238
+		}
3239
+
3240
+		// now delete permanently this particular group
3241
+
3242
+		if ($include_group && ! $MTG->delete_permanently()) {
3243
+			$success = 0;
3244
+		}
3245
+
3246
+		return $success;
3247
+	}
3248
+
3249
+
3250
+	/**
3251
+	 *    _learn_more_about_message_templates_link
3252
+	 *
3253
+	 * @access protected
3254
+	 * @return string
3255
+	 */
3256
+	protected function _learn_more_about_message_templates_link()
3257
+	{
3258
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >'
3259
+			   . esc_html__('learn more about how message templates works', 'event_espresso')
3260
+			   . '</a>';
3261
+	}
3262
+
3263
+
3264
+	/**
3265
+	 * Used for setting up messenger/message type activation.  This loads up the initial view.  The rest is handled by
3266
+	 * ajax and other routes.
3267
+	 *
3268
+	 * @return void
3269
+	 * @throws DomainException
3270
+	 */
3271
+	protected function _settings()
3272
+	{
3273
+
3274
+
3275
+		$this->_set_m_mt_settings();
3276
+
3277
+		$selected_messenger = isset($this->_req_data['selected_messenger'])
3278
+			? $this->_req_data['selected_messenger']
3279
+			: 'email';
3280
+
3281
+		// let's setup the messenger tabs
3282
+		$this->_template_args['admin_page_header'] = EEH_Tabbed_Content::tab_text_links(
3283
+			$this->_m_mt_settings['messenger_tabs'],
3284
+			'messenger_links',
3285
+			'|',
3286
+			$selected_messenger
3287
+		);
3288
+		$this->_template_args['before_admin_page_content'] = '<div class="ui-widget ui-helper-clearfix">';
3289
+		$this->_template_args['after_admin_page_content'] = '</div><!-- end .ui-widget -->';
3290
+
3291
+		$this->display_admin_page_with_sidebar();
3292
+	}
3293
+
3294
+
3295
+	/**
3296
+	 * This sets the $_m_mt_settings property for when needed (used on the Messages settings page)
3297
+	 *
3298
+	 * @access protected
3299
+	 * @return void
3300
+	 * @throws DomainException
3301
+	 */
3302
+	protected function _set_m_mt_settings()
3303
+	{
3304
+		// first if this is already set then lets get out no need to regenerate data.
3305
+		if (! empty($this->_m_mt_settings)) {
3306
+			return;
3307
+		}
3308
+
3309
+		// get all installed messengers and message_types
3310
+		/** @type EE_messenger[] $messengers */
3311
+		$messengers = $this->_message_resource_manager->installed_messengers();
3312
+		/** @type EE_message_type[] $message_types */
3313
+		$message_types = $this->_message_resource_manager->installed_message_types();
3314
+
3315
+
3316
+		// assemble the array for the _tab_text_links helper
3317
+
3318
+		foreach ($messengers as $messenger) {
3319
+			$this->_m_mt_settings['messenger_tabs'][ $messenger->name ] = array(
3320
+				'label' => ucwords($messenger->label['singular']),
3321
+				'class' => $this->_message_resource_manager->is_messenger_active($messenger->name)
3322
+					? 'messenger-active'
3323
+					: '',
3324
+				'href'  => $messenger->name,
3325
+				'title' => esc_html__('Modify this Messenger', 'event_espresso'),
3326
+				'slug'  => $messenger->name,
3327
+				'obj'   => $messenger,
3328
+			);
3329
+
3330
+
3331
+			$message_types_for_messenger = $messenger->get_valid_message_types();
3332
+
3333
+			foreach ($message_types as $message_type) {
3334
+				// first we need to verify that this message type is valid with this messenger. Cause if it isn't then
3335
+				// it shouldn't show in either the inactive OR active metabox.
3336
+				if (! in_array($message_type->name, $message_types_for_messenger, true)) {
3337
+					continue;
3338
+				}
3339
+
3340
+				$a_or_i = $this->_message_resource_manager->is_message_type_active_for_messenger(
3341
+					$messenger->name,
3342
+					$message_type->name
3343
+				)
3344
+					? 'active'
3345
+					: 'inactive';
3346
+
3347
+				$this->_m_mt_settings['message_type_tabs'][ $messenger->name ][ $a_or_i ][ $message_type->name ] = array(
3348
+					'label'    => ucwords($message_type->label['singular']),
3349
+					'class'    => 'message-type-' . $a_or_i,
3350
+					'slug_id'  => $message_type->name . '-messagetype-' . $messenger->name,
3351
+					'mt_nonce' => wp_create_nonce($message_type->name . '_nonce'),
3352
+					'href'     => 'espresso_' . $message_type->name . '_message_type_settings',
3353
+					'title'    => $a_or_i === 'active'
3354
+						? esc_html__('Drag this message type to the Inactive window to deactivate', 'event_espresso')
3355
+						: esc_html__('Drag this message type to the messenger to activate', 'event_espresso'),
3356
+					'content'  => $a_or_i === 'active'
3357
+						? $this->_message_type_settings_content($message_type, $messenger, true)
3358
+						: $this->_message_type_settings_content($message_type, $messenger),
3359
+					'slug'     => $message_type->name,
3360
+					'active'   => $a_or_i === 'active',
3361
+					'obj'      => $message_type,
3362
+				);
3363
+			}
3364
+		}
3365
+	}
3366
+
3367
+
3368
+	/**
3369
+	 * This just prepares the content for the message type settings
3370
+	 *
3371
+	 * @param  EE_message_type $message_type The message type object
3372
+	 * @param  EE_messenger    $messenger    The messenger object
3373
+	 * @param  boolean         $active       Whether the message type is active or not
3374
+	 * @return string html output for the content
3375
+	 * @throws DomainException
3376
+	 */
3377
+	protected function _message_type_settings_content($message_type, $messenger, $active = false)
3378
+	{
3379
+		// get message type fields
3380
+		$fields = $message_type->get_admin_settings_fields();
3381
+		$settings_template_args['template_form_fields'] = '';
3382
+
3383
+		if (! empty($fields) && $active) {
3384
+			$existing_settings = $message_type->get_existing_admin_settings($messenger->name);
3385
+			foreach ($fields as $fldname => $fldprops) {
3386
+				$field_id = $messenger->name . '-' . $message_type->name . '-' . $fldname;
3387
+				$template_form_field[ $field_id ] = array(
3388
+					'name'       => 'message_type_settings[' . $fldname . ']',
3389
+					'label'      => $fldprops['label'],
3390
+					'input'      => $fldprops['field_type'],
3391
+					'type'       => $fldprops['value_type'],
3392
+					'required'   => $fldprops['required'],
3393
+					'validation' => $fldprops['validation'],
3394
+					'value'      => isset($existing_settings[ $fldname ])
3395
+						? $existing_settings[ $fldname ]
3396
+						: $fldprops['default'],
3397
+					'options'    => isset($fldprops['options'])
3398
+						? $fldprops['options']
3399
+						: array(),
3400
+					'default'    => isset($existing_settings[ $fldname ])
3401
+						? $existing_settings[ $fldname ]
3402
+						: $fldprops['default'],
3403
+					'css_class'  => 'no-drag',
3404
+					'format'     => $fldprops['format'],
3405
+				);
3406
+			}
3407
+
3408
+
3409
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3410
+				? $this->_generate_admin_form_fields(
3411
+					$template_form_field,
3412
+					'string',
3413
+					'ee_mt_activate_form'
3414
+				)
3415
+				: '';
3416
+		}
3417
+
3418
+		$settings_template_args['description'] = $message_type->description;
3419
+		// we also need some hidden fields
3420
+		$settings_template_args['hidden_fields'] = array(
3421
+			'message_type_settings[messenger]'    => array(
3422
+				'type'  => 'hidden',
3423
+				'value' => $messenger->name,
3424
+			),
3425
+			'message_type_settings[message_type]' => array(
3426
+				'type'  => 'hidden',
3427
+				'value' => $message_type->name,
3428
+			),
3429
+			'type'                                => array(
3430
+				'type'  => 'hidden',
3431
+				'value' => 'message_type',
3432
+			),
3433
+		);
3434
+
3435
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3436
+			$settings_template_args['hidden_fields'],
3437
+			'array'
3438
+		);
3439
+		$settings_template_args['show_form'] = empty($settings_template_args['template_form_fields'])
3440
+			? ' hidden'
3441
+			: '';
3442
+
3443
+
3444
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_mt_settings_content.template.php';
3445
+		$content = EEH_Template::display_template($template, $settings_template_args, true);
3446
+
3447
+		return $content;
3448
+	}
3449
+
3450
+
3451
+	/**
3452
+	 * Generate all the metaboxes for the message types and register them for the messages settings page.
3453
+	 *
3454
+	 * @access protected
3455
+	 * @return void
3456
+	 * @throws DomainException
3457
+	 */
3458
+	protected function _messages_settings_metaboxes()
3459
+	{
3460
+		$this->_set_m_mt_settings();
3461
+		$m_boxes = $mt_boxes = array();
3462
+		$m_template_args = $mt_template_args = array();
3463
+
3464
+		$selected_messenger = isset($this->_req_data['selected_messenger'])
3465
+			? $this->_req_data['selected_messenger']
3466
+			: 'email';
3467
+
3468
+		if (isset($this->_m_mt_settings['messenger_tabs'])) {
3469
+			foreach ($this->_m_mt_settings['messenger_tabs'] as $messenger => $tab_array) {
3470
+				$hide_on_message = $this->_message_resource_manager->is_messenger_active($messenger) ? '' : 'hidden';
3471
+				$hide_off_message = $this->_message_resource_manager->is_messenger_active($messenger) ? 'hidden' : '';
3472
+				// messenger meta boxes
3473
+				$active = $selected_messenger === $messenger;
3474
+				$active_mt_tabs = isset(
3475
+					$this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3476
+				)
3477
+					? $this->_m_mt_settings['message_type_tabs'][ $messenger ]['active']
3478
+					: '';
3479
+				$m_boxes[ $messenger . '_a_box' ] = sprintf(
3480
+					esc_html__('%s Settings', 'event_espresso'),
3481
+					$tab_array['label']
3482
+				);
3483
+				$m_template_args[ $messenger . '_a_box' ] = array(
3484
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3485
+					'inactive_message_types' => isset(
3486
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3487
+					)
3488
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3489
+						: '',
3490
+					'content'                => $this->_get_messenger_box_content($tab_array['obj']),
3491
+					'hidden'                 => $active ? '' : ' hidden',
3492
+					'hide_on_message'        => $hide_on_message,
3493
+					'messenger'              => $messenger,
3494
+					'active'                 => $active,
3495
+				);
3496
+				// message type meta boxes
3497
+				// (which is really just the inactive container for each messenger
3498
+				// showing inactive message types for that messenger)
3499
+				$mt_boxes[ $messenger . '_i_box' ] = esc_html__('Inactive Message Types', 'event_espresso');
3500
+				$mt_template_args[ $messenger . '_i_box' ] = array(
3501
+					'active_message_types'   => ! empty($active_mt_tabs) ? $this->_get_mt_tabs($active_mt_tabs) : '',
3502
+					'inactive_message_types' => isset(
3503
+						$this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive']
3504
+					)
3505
+						? $this->_get_mt_tabs($this->_m_mt_settings['message_type_tabs'][ $messenger ]['inactive'])
3506
+						: '',
3507
+					'hidden'                 => $active ? '' : ' hidden',
3508
+					'hide_on_message'        => $hide_on_message,
3509
+					'hide_off_message'       => $hide_off_message,
3510
+					'messenger'              => $messenger,
3511
+					'active'                 => $active,
3512
+				);
3513
+			}
3514
+		}
3515
+
3516
+
3517
+		// register messenger metaboxes
3518
+		$m_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_mt_meta_box.template.php';
3519
+		foreach ($m_boxes as $box => $label) {
3520
+			$callback_args = array('template_path' => $m_template_path, 'template_args' => $m_template_args[ $box ]);
3521
+			$msgr = str_replace('_a_box', '', $box);
3522
+			add_meta_box(
3523
+				'espresso_' . $msgr . '_settings',
3524
+				$label,
3525
+				function ($post, $metabox) {
3526
+					echo EEH_Template::display_template(
3527
+						$metabox["args"]["template_path"],
3528
+						$metabox["args"]["template_args"],
3529
+						true
3530
+					);
3531
+				},
3532
+				$this->_current_screen->id,
3533
+				'normal',
3534
+				'high',
3535
+				$callback_args
3536
+			);
3537
+		}
3538
+
3539
+		// register message type metaboxes
3540
+		$mt_template_path = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_messenger_meta_box.template.php';
3541
+		foreach ($mt_boxes as $box => $label) {
3542
+			$callback_args = array(
3543
+				'template_path' => $mt_template_path,
3544
+				'template_args' => $mt_template_args[ $box ],
3545
+			);
3546
+			$mt = str_replace('_i_box', '', $box);
3547
+			add_meta_box(
3548
+				'espresso_' . $mt . '_inactive_mts',
3549
+				$label,
3550
+				function ($post, $metabox) {
3551
+					echo EEH_Template::display_template(
3552
+						$metabox["args"]["template_path"],
3553
+						$metabox["args"]["template_args"],
3554
+						true
3555
+					);
3556
+				},
3557
+				$this->_current_screen->id,
3558
+				'side',
3559
+				'high',
3560
+				$callback_args
3561
+			);
3562
+		}
3563
+
3564
+		// register metabox for global messages settings but only when on the main site.  On single site installs this
3565
+		// will always result in the metabox showing, on multisite installs the metabox will only show on the main site.
3566
+		if (is_main_site()) {
3567
+			add_meta_box(
3568
+				'espresso_global_message_settings',
3569
+				esc_html__('Global Message Settings', 'event_espresso'),
3570
+				array($this, 'global_messages_settings_metabox_content'),
3571
+				$this->_current_screen->id,
3572
+				'normal',
3573
+				'low',
3574
+				array()
3575
+			);
3576
+		}
3577
+	}
3578
+
3579
+
3580
+	/**
3581
+	 *  This generates the content for the global messages settings metabox.
3582
+	 *
3583
+	 * @return string
3584
+	 * @throws EE_Error
3585
+	 * @throws InvalidArgumentException
3586
+	 * @throws ReflectionException
3587
+	 * @throws InvalidDataTypeException
3588
+	 * @throws InvalidInterfaceException
3589
+	 */
3590
+	public function global_messages_settings_metabox_content()
3591
+	{
3592
+		$form = $this->_generate_global_settings_form();
3593
+		echo $form->form_open(
3594
+			$this->add_query_args_and_nonce(array('action' => 'update_global_settings'), EE_MSG_ADMIN_URL),
3595
+			'POST'
3596
+		)
3597
+			 . $form->get_html()
3598
+			 . $form->form_close();
3599
+	}
3600
+
3601
+
3602
+	/**
3603
+	 * This generates and returns the form object for the global messages settings.
3604
+	 *
3605
+	 * @return EE_Form_Section_Proper
3606
+	 * @throws EE_Error
3607
+	 * @throws InvalidArgumentException
3608
+	 * @throws ReflectionException
3609
+	 * @throws InvalidDataTypeException
3610
+	 * @throws InvalidInterfaceException
3611
+	 */
3612
+	protected function _generate_global_settings_form()
3613
+	{
3614
+		EE_Registry::instance()->load_helper('HTML');
3615
+		/** @var EE_Network_Core_Config $network_config */
3616
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3617
+
3618
+		return new EE_Form_Section_Proper(
3619
+			array(
3620
+				'name'            => 'global_messages_settings',
3621
+				'html_id'         => 'global_messages_settings',
3622
+				'html_class'      => 'form-table',
3623
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
3624
+				'subsections'     => apply_filters(
3625
+					'FHEE__Messages_Admin_Page__global_messages_settings_metabox_content__form_subsections',
3626
+					array(
3627
+						'do_messages_on_same_request' => new EE_Select_Input(
3628
+							array(
3629
+								true  => esc_html__("On the same request", "event_espresso"),
3630
+								false => esc_html__("On a separate request", "event_espresso"),
3631
+							),
3632
+							array(
3633
+								'default'         => $network_config->do_messages_on_same_request,
3634
+								'html_label_text' => esc_html__(
3635
+									'Generate and send all messages:',
3636
+									'event_espresso'
3637
+								),
3638
+								'html_help_text'  => esc_html__(
3639
+									'By default the messages system uses a more efficient means of processing messages on separate requests and utilizes the wp-cron scheduling system.  This makes things execute faster for people registering for your events.  However, if the wp-cron system is disabled on your site and there is no alternative in place, then you can change this so messages are always executed on the same request.',
3640
+									'event_espresso'
3641
+								),
3642
+							)
3643
+						),
3644
+						'delete_threshold'            => new EE_Select_Input(
3645
+							array(
3646
+								0  => esc_html__('Forever', 'event_espresso'),
3647
+								3  => esc_html__('3 Months', 'event_espresso'),
3648
+								6  => esc_html__('6 Months', 'event_espresso'),
3649
+								9  => esc_html__('9 Months', 'event_espresso'),
3650
+								12 => esc_html__('12 Months', 'event_espresso'),
3651
+								24 => esc_html__('24 Months', 'event_espresso'),
3652
+								36 => esc_html__('36 Months', 'event_espresso'),
3653
+							),
3654
+							array(
3655
+								'default'         => EE_Registry::instance()->CFG->messages->delete_threshold,
3656
+								'html_label_text' => esc_html__('Cleanup of old messages:', 'event_espresso'),
3657
+								'html_help_text'  => esc_html__(
3658
+									'You can control how long a record of processed messages is kept via this option.',
3659
+									'event_espresso'
3660
+								),
3661
+							)
3662
+						),
3663
+						'update_settings'             => new EE_Submit_Input(
3664
+							array(
3665
+								'default'         => esc_html__('Update', 'event_espresso'),
3666
+								'html_label_text' => '&nbsp',
3667
+							)
3668
+						),
3669
+					)
3670
+				),
3671
+			)
3672
+		);
3673
+	}
3674
+
3675
+
3676
+	/**
3677
+	 * This handles updating the global settings set on the admin page.
3678
+	 *
3679
+	 * @throws EE_Error
3680
+	 * @throws InvalidDataTypeException
3681
+	 * @throws InvalidInterfaceException
3682
+	 * @throws InvalidArgumentException
3683
+	 * @throws ReflectionException
3684
+	 */
3685
+	protected function _update_global_settings()
3686
+	{
3687
+		/** @var EE_Network_Core_Config $network_config */
3688
+		$network_config = EE_Registry::instance()->NET_CFG->core;
3689
+		$messages_config = EE_Registry::instance()->CFG->messages;
3690
+		$form = $this->_generate_global_settings_form();
3691
+		if ($form->was_submitted()) {
3692
+			$form->receive_form_submission();
3693
+			if ($form->is_valid()) {
3694
+				$valid_data = $form->valid_data();
3695
+				foreach ($valid_data as $property => $value) {
3696
+					$setter = 'set_' . $property;
3697
+					if (method_exists($network_config, $setter)) {
3698
+						$network_config->{$setter}($value);
3699
+					} elseif (
3700
+						property_exists($network_config, $property)
3701
+						&& $network_config->{$property} !== $value
3702
+					) {
3703
+						$network_config->{$property} = $value;
3704
+					} elseif (
3705
+						property_exists($messages_config, $property)
3706
+						&& $messages_config->{$property} !== $value
3707
+					) {
3708
+						$messages_config->{$property} = $value;
3709
+					}
3710
+				}
3711
+				// only update if the form submission was valid!
3712
+				EE_Registry::instance()->NET_CFG->update_config(true, false);
3713
+				EE_Registry::instance()->CFG->update_espresso_config();
3714
+				EE_Error::overwrite_success();
3715
+				EE_Error::add_success(__('Global message settings were updated', 'event_espresso'));
3716
+			}
3717
+		}
3718
+		$this->_redirect_after_action(0, '', '', array('action' => 'settings'), true);
3719
+	}
3720
+
3721
+
3722
+	/**
3723
+	 * this prepares the messenger tabs that can be dragged in and out of messenger boxes to activate/deactivate
3724
+	 *
3725
+	 * @param  array $tab_array This is an array of message type tab details used to generate the tabs
3726
+	 * @return string html formatted tabs
3727
+	 * @throws DomainException
3728
+	 */
3729
+	protected function _get_mt_tabs($tab_array)
3730
+	{
3731
+		$tab_array = (array) $tab_array;
3732
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_details_mt_settings_tab_item.template.php';
3733
+		$tabs = '';
3734
+
3735
+		foreach ($tab_array as $tab) {
3736
+			$tabs .= EEH_Template::display_template($template, $tab, true);
3737
+		}
3738
+
3739
+		return $tabs;
3740
+	}
3741
+
3742
+
3743
+	/**
3744
+	 * This prepares the content of the messenger meta box admin settings
3745
+	 *
3746
+	 * @param  EE_messenger $messenger The messenger we're setting up content for
3747
+	 * @return string html formatted content
3748
+	 * @throws DomainException
3749
+	 */
3750
+	protected function _get_messenger_box_content(EE_messenger $messenger)
3751
+	{
3752
+
3753
+		$fields = $messenger->get_admin_settings_fields();
3754
+		$settings_template_args['template_form_fields'] = '';
3755
+
3756
+		// is $messenger active?
3757
+		$settings_template_args['active'] = $this->_message_resource_manager->is_messenger_active($messenger->name);
3758
+
3759
+
3760
+		if (! empty($fields)) {
3761
+			$existing_settings = $messenger->get_existing_admin_settings();
3762
+
3763
+			foreach ($fields as $fldname => $fldprops) {
3764
+				$field_id = $messenger->name . '-' . $fldname;
3765
+				$template_form_field[ $field_id ] = array(
3766
+					'name'       => 'messenger_settings[' . $field_id . ']',
3767
+					'label'      => $fldprops['label'],
3768
+					'input'      => $fldprops['field_type'],
3769
+					'type'       => $fldprops['value_type'],
3770
+					'required'   => $fldprops['required'],
3771
+					'validation' => $fldprops['validation'],
3772
+					'value'      => isset($existing_settings[ $field_id ])
3773
+						? $existing_settings[ $field_id ]
3774
+						: $fldprops['default'],
3775
+					'css_class'  => '',
3776
+					'format'     => $fldprops['format'],
3777
+				);
3778
+			}
3779
+
3780
+
3781
+			$settings_template_args['template_form_fields'] = ! empty($template_form_field)
3782
+				? $this->_generate_admin_form_fields($template_form_field, 'string', 'ee_m_activate_form')
3783
+				: '';
3784
+		}
3785
+
3786
+		// we also need some hidden fields
3787
+		$settings_template_args['hidden_fields'] = array(
3788
+			'messenger_settings[messenger]' => array(
3789
+				'type'  => 'hidden',
3790
+				'value' => $messenger->name,
3791
+			),
3792
+			'type'                          => array(
3793
+				'type'  => 'hidden',
3794
+				'value' => 'messenger',
3795
+			),
3796
+		);
3797
+
3798
+		// make sure any active message types that are existing are included in the hidden fields
3799
+		if (isset($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'])) {
3800
+			foreach ($this->_m_mt_settings['message_type_tabs'][ $messenger->name ]['active'] as $mt => $values) {
3801
+				$settings_template_args['hidden_fields'][ 'messenger_settings[message_types][' . $mt . ']' ] = array(
3802
+					'type'  => 'hidden',
3803
+					'value' => $mt,
3804
+				);
3805
+			}
3806
+		}
3807
+		$settings_template_args['hidden_fields'] = $this->_generate_admin_form_fields(
3808
+			$settings_template_args['hidden_fields'],
3809
+			'array'
3810
+		);
3811
+		$active = $this->_message_resource_manager->is_messenger_active($messenger->name);
3812
+
3813
+		$settings_template_args['messenger'] = $messenger->name;
3814
+		$settings_template_args['description'] = $messenger->description;
3815
+		$settings_template_args['show_hide_edit_form'] = $active ? '' : ' hidden';
3816
+
3817
+
3818
+		$settings_template_args['show_hide_edit_form'] = $this->_message_resource_manager->is_messenger_active(
3819
+			$messenger->name
3820
+		)
3821
+			? $settings_template_args['show_hide_edit_form']
3822
+			: ' hidden';
3823
+
3824
+		$settings_template_args['show_hide_edit_form'] = empty($settings_template_args['template_form_fields'])
3825
+			? ' hidden'
3826
+			: $settings_template_args['show_hide_edit_form'];
3827
+
3828
+
3829
+		$settings_template_args['on_off_action'] = $active ? 'messenger-off' : 'messenger-on';
3830
+		$settings_template_args['nonce'] = wp_create_nonce('activate_' . $messenger->name . '_toggle_nonce');
3831
+		$settings_template_args['on_off_status'] = $active ? true : false;
3832
+		$template = EE_MSG_TEMPLATE_PATH . 'ee_msg_m_settings_content.template.php';
3833
+		$content = EEH_Template::display_template(
3834
+			$template,
3835
+			$settings_template_args,
3836
+			true
3837
+		);
3838
+
3839
+		return $content;
3840
+	}
3841
+
3842
+
3843
+	/**
3844
+	 * used by ajax on the messages settings page to activate|deactivate the messenger
3845
+	 *
3846
+	 * @throws DomainException
3847
+	 * @throws EE_Error
3848
+	 * @throws InvalidDataTypeException
3849
+	 * @throws InvalidInterfaceException
3850
+	 * @throws InvalidArgumentException
3851
+	 * @throws ReflectionException
3852
+	 */
3853
+	public function activate_messenger_toggle()
3854
+	{
3855
+		$success = true;
3856
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3857
+		// let's check that we have required data
3858
+		if (! isset($this->_req_data['messenger'])) {
3859
+			EE_Error::add_error(
3860
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3861
+				__FILE__,
3862
+				__FUNCTION__,
3863
+				__LINE__
3864
+			);
3865
+			$success = false;
3866
+		}
3867
+
3868
+		// do a nonce check here since we're not arriving via a normal route
3869
+		$nonce = isset($this->_req_data['activate_nonce'])
3870
+			? sanitize_text_field($this->_req_data['activate_nonce'])
3871
+			: '';
3872
+		$nonce_ref = 'activate_' . $this->_req_data['messenger'] . '_toggle_nonce';
3873
+
3874
+		$this->_verify_nonce($nonce, $nonce_ref);
3875
+
3876
+
3877
+		if (! isset($this->_req_data['status'])) {
3878
+			EE_Error::add_error(
3879
+				esc_html__(
3880
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3881
+					'event_espresso'
3882
+				),
3883
+				__FILE__,
3884
+				__FUNCTION__,
3885
+				__LINE__
3886
+			);
3887
+			$success = false;
3888
+		}
3889
+
3890
+		// do check to verify we have a valid status.
3891
+		$status = $this->_req_data['status'];
3892
+
3893
+		if ($status !== 'off' && $status !== 'on') {
3894
+			EE_Error::add_error(
3895
+				sprintf(
3896
+					esc_html__('The given status (%s) is not valid. Must be "off" or "on"', 'event_espresso'),
3897
+					$this->_req_data['status']
3898
+				),
3899
+				__FILE__,
3900
+				__FUNCTION__,
3901
+				__LINE__
3902
+			);
3903
+			$success = false;
3904
+		}
3905
+
3906
+		if ($success) {
3907
+			// made it here?  Stop dawdling then!!
3908
+			$success = $status === 'off'
3909
+				? $this->_deactivate_messenger($this->_req_data['messenger'])
3910
+				: $this->_activate_messenger($this->_req_data['messenger']);
3911
+		}
3912
+
3913
+		$this->_template_args['success'] = $success;
3914
+
3915
+		// no special instructions so let's just do the json return (which should automatically do all the special stuff).
3916
+		$this->_return_json();
3917
+	}
3918
+
3919
+
3920
+	/**
3921
+	 * used by ajax from the messages settings page to activate|deactivate a message type
3922
+	 *
3923
+	 * @throws DomainException
3924
+	 * @throws EE_Error
3925
+	 * @throws ReflectionException
3926
+	 * @throws InvalidDataTypeException
3927
+	 * @throws InvalidInterfaceException
3928
+	 * @throws InvalidArgumentException
3929
+	 */
3930
+	public function activate_mt_toggle()
3931
+	{
3932
+		$success = true;
3933
+		$this->_prep_default_response_for_messenger_or_message_type_toggle();
3934
+
3935
+		// let's make sure we have the necessary data
3936
+		if (! isset($this->_req_data['message_type'])) {
3937
+			EE_Error::add_error(
3938
+				esc_html__('Message Type name needed to toggle activation. None given', 'event_espresso'),
3939
+				__FILE__,
3940
+				__FUNCTION__,
3941
+				__LINE__
3942
+			);
3943
+			$success = false;
3944
+		}
3945
+
3946
+		if (! isset($this->_req_data['messenger'])) {
3947
+			EE_Error::add_error(
3948
+				esc_html__('Messenger name needed to toggle activation. None given', 'event_espresso'),
3949
+				__FILE__,
3950
+				__FUNCTION__,
3951
+				__LINE__
3952
+			);
3953
+			$success = false;
3954
+		}
3955
+
3956
+		if (! isset($this->_req_data['status'])) {
3957
+			EE_Error::add_error(
3958
+				esc_html__(
3959
+					'Messenger status needed to know whether activation or deactivation is happening. No status is given',
3960
+					'event_espresso'
3961
+				),
3962
+				__FILE__,
3963
+				__FUNCTION__,
3964
+				__LINE__
3965
+			);
3966
+			$success = false;
3967
+		}
3968
+
3969
+
3970
+		// do check to verify we have a valid status.
3971
+		$status = $this->_req_data['status'];
3972
+
3973
+		if ($status !== 'activate' && $status !== 'deactivate') {
3974
+			EE_Error::add_error(
3975
+				sprintf(
3976
+					esc_html__('The given status (%s) is not valid. Must be "active" or "inactive"', 'event_espresso'),
3977
+					$this->_req_data['status']
3978
+				),
3979
+				__FILE__,
3980
+				__FUNCTION__,
3981
+				__LINE__
3982
+			);
3983
+			$success = false;
3984
+		}
3985
+
3986
+
3987
+		// do a nonce check here since we're not arriving via a normal route
3988
+		$nonce = isset($this->_req_data['mt_nonce']) ? sanitize_text_field($this->_req_data['mt_nonce']) : '';
3989
+		$nonce_ref = $this->_req_data['message_type'] . '_nonce';
3990
+
3991
+		$this->_verify_nonce($nonce, $nonce_ref);
3992
+
3993
+		if ($success) {
3994
+			// made it here? um, what are you waiting for then?
3995
+			$success = $status === 'deactivate'
3996
+				? $this->_deactivate_message_type_for_messenger(
3997
+					$this->_req_data['messenger'],
3998
+					$this->_req_data['message_type']
3999
+				)
4000
+				: $this->_activate_message_type_for_messenger(
4001
+					$this->_req_data['messenger'],
4002
+					$this->_req_data['message_type']
4003
+				);
4004
+		}
4005
+
4006
+		$this->_template_args['success'] = $success;
4007
+		$this->_return_json();
4008
+	}
4009
+
4010
+
4011
+	/**
4012
+	 * Takes care of processing activating a messenger and preparing the appropriate response.
4013
+	 *
4014
+	 * @param string $messenger_name The name of the messenger being activated
4015
+	 * @return bool
4016
+	 * @throws DomainException
4017
+	 * @throws EE_Error
4018
+	 * @throws InvalidArgumentException
4019
+	 * @throws ReflectionException
4020
+	 * @throws InvalidDataTypeException
4021
+	 * @throws InvalidInterfaceException
4022
+	 */
4023
+	protected function _activate_messenger($messenger_name)
4024
+	{
4025
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4026
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4027
+		$message_types_to_activate = $active_messenger instanceof EE_Messenger
4028
+			? $active_messenger->get_default_message_types()
4029
+			: array();
4030
+
4031
+		// ensure is active
4032
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_types_to_activate);
4033
+
4034
+		// set response_data for reload
4035
+		foreach ($message_types_to_activate as $message_type_name) {
4036
+			/** @var EE_message_type $message_type */
4037
+			$message_type = $this->_message_resource_manager->get_message_type($message_type_name);
4038
+			if (
4039
+				$this->_message_resource_manager->is_message_type_active_for_messenger(
4040
+					$messenger_name,
4041
+					$message_type_name
4042
+				)
4043
+				&& $message_type instanceof EE_message_type
4044
+			) {
4045
+				$this->_template_args['data']['active_mts'][] = $message_type_name;
4046
+				if ($message_type->get_admin_settings_fields()) {
4047
+					$this->_template_args['data']['mt_reload'][] = $message_type_name;
4048
+				}
4049
+			}
4050
+		}
4051
+
4052
+		// add success message for activating messenger
4053
+		return $this->_setup_response_message_for_activating_messenger_with_message_types($active_messenger);
4054
+	}
4055
+
4056
+
4057
+	/**
4058
+	 * Takes care of processing deactivating a messenger and preparing the appropriate response.
4059
+	 *
4060
+	 * @param string $messenger_name The name of the messenger being activated
4061
+	 * @return bool
4062
+	 * @throws DomainException
4063
+	 * @throws EE_Error
4064
+	 * @throws InvalidArgumentException
4065
+	 * @throws ReflectionException
4066
+	 * @throws InvalidDataTypeException
4067
+	 * @throws InvalidInterfaceException
4068
+	 */
4069
+	protected function _deactivate_messenger($messenger_name)
4070
+	{
4071
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4072
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4073
+		$this->_message_resource_manager->deactivate_messenger($messenger_name);
4074
+
4075
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types($active_messenger);
4076
+	}
4077
+
4078
+
4079
+	/**
4080
+	 * Takes care of processing activating a message type for a messenger and preparing the appropriate response.
4081
+	 *
4082
+	 * @param string $messenger_name    The name of the messenger the message type is being activated for.
4083
+	 * @param string $message_type_name The name of the message type being activated for the messenger
4084
+	 * @return bool
4085
+	 * @throws DomainException
4086
+	 * @throws EE_Error
4087
+	 * @throws InvalidArgumentException
4088
+	 * @throws ReflectionException
4089
+	 * @throws InvalidDataTypeException
4090
+	 * @throws InvalidInterfaceException
4091
+	 */
4092
+	protected function _activate_message_type_for_messenger($messenger_name, $message_type_name)
4093
+	{
4094
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4095
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4096
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4097
+		$message_type_to_activate = $this->_message_resource_manager->get_message_type($message_type_name);
4098
+
4099
+		// ensure is active
4100
+		$this->_message_resource_manager->activate_messenger($messenger_name, $message_type_name);
4101
+
4102
+		// set response for load
4103
+		if (
4104
+			$this->_message_resource_manager->is_message_type_active_for_messenger(
4105
+				$messenger_name,
4106
+				$message_type_name
4107
+			)
4108
+		) {
4109
+			$this->_template_args['data']['active_mts'][] = $message_type_name;
4110
+			if ($message_type_to_activate->get_admin_settings_fields()) {
4111
+				$this->_template_args['data']['mt_reload'][] = $message_type_name;
4112
+			}
4113
+		}
4114
+
4115
+		return $this->_setup_response_message_for_activating_messenger_with_message_types(
4116
+			$active_messenger,
4117
+			$message_type_to_activate
4118
+		);
4119
+	}
4120
+
4121
+
4122
+	/**
4123
+	 * Takes care of processing deactivating a message type for a messenger and preparing the appropriate response.
4124
+	 *
4125
+	 * @param string $messenger_name    The name of the messenger the message type is being deactivated for.
4126
+	 * @param string $message_type_name The name of the message type being deactivated for the messenger
4127
+	 * @return bool
4128
+	 * @throws DomainException
4129
+	 * @throws EE_Error
4130
+	 * @throws InvalidArgumentException
4131
+	 * @throws ReflectionException
4132
+	 * @throws InvalidDataTypeException
4133
+	 * @throws InvalidInterfaceException
4134
+	 */
4135
+	protected function _deactivate_message_type_for_messenger($messenger_name, $message_type_name)
4136
+	{
4137
+		/** @var EE_messenger $active_messenger This will be present because it can't be toggled if it isn't */
4138
+		$active_messenger = $this->_message_resource_manager->get_messenger($messenger_name);
4139
+		/** @var EE_message_type $message_type_to_activate This will be present because it can't be toggled if it isn't */
4140
+		$message_type_to_deactivate = $this->_message_resource_manager->get_message_type($message_type_name);
4141
+		$this->_message_resource_manager->deactivate_message_type_for_messenger($message_type_name, $messenger_name);
4142
+
4143
+		return $this->_setup_response_message_for_deactivating_messenger_with_message_types(
4144
+			$active_messenger,
4145
+			$message_type_to_deactivate
4146
+		);
4147
+	}
4148
+
4149
+
4150
+	/**
4151
+	 * This just initializes the defaults for activating messenger and message type responses.
4152
+	 */
4153
+	protected function _prep_default_response_for_messenger_or_message_type_toggle()
4154
+	{
4155
+		$this->_template_args['data']['active_mts'] = array();
4156
+		$this->_template_args['data']['mt_reload'] = array();
4157
+	}
4158
+
4159
+
4160
+	/**
4161
+	 * Setup appropriate response for activating a messenger and/or message types
4162
+	 *
4163
+	 * @param EE_messenger         $messenger
4164
+	 * @param EE_message_type|null $message_type
4165
+	 * @return bool
4166
+	 * @throws DomainException
4167
+	 * @throws EE_Error
4168
+	 * @throws InvalidArgumentException
4169
+	 * @throws ReflectionException
4170
+	 * @throws InvalidDataTypeException
4171
+	 * @throws InvalidInterfaceException
4172
+	 */
4173
+	protected function _setup_response_message_for_activating_messenger_with_message_types(
4174
+		$messenger,
4175
+		EE_Message_Type $message_type = null
4176
+	) {
4177
+		// if $messenger isn't a valid messenger object then get out.
4178
+		if (! $messenger instanceof EE_Messenger) {
4179
+			EE_Error::add_error(
4180
+				esc_html__('The messenger being activated is not a valid messenger', 'event_espresso'),
4181
+				__FILE__,
4182
+				__FUNCTION__,
4183
+				__LINE__
4184
+			);
4185
+
4186
+			return false;
4187
+		}
4188
+		// activated
4189
+		if ($this->_template_args['data']['active_mts']) {
4190
+			EE_Error::overwrite_success();
4191
+			// activated a message type with the messenger
4192
+			if ($message_type instanceof EE_message_type) {
4193
+				EE_Error::add_success(
4194
+					sprintf(
4195
+						esc_html__(
4196
+							'%s message type has been successfully activated with the %s messenger',
4197
+							'event_espresso'
4198
+						),
4199
+						ucwords($message_type->label['singular']),
4200
+						ucwords($messenger->label['singular'])
4201
+					)
4202
+				);
4203
+
4204
+				// if message type was invoice then let's make sure we activate the invoice payment method.
4205
+				if ($message_type->name === 'invoice') {
4206
+					EE_Registry::instance()->load_lib('Payment_Method_Manager');
4207
+					$pm = EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
4208
+					if ($pm instanceof EE_Payment_Method) {
4209
+						EE_Error::add_attention(
4210
+							esc_html__(
4211
+								'Activating the invoice message type also automatically activates the invoice payment method.  If you do not wish the invoice payment method to be active, or to change its settings, visit the payment method admin page.',
4212
+								'event_espresso'
4213
+							)
4214
+						);
4215
+					}
4216
+				}
4217
+				// just toggles the entire messenger
4218
+			} else {
4219
+				EE_Error::add_success(
4220
+					sprintf(
4221
+						esc_html__('%s messenger has been successfully activated', 'event_espresso'),
4222
+						ucwords($messenger->label['singular'])
4223
+					)
4224
+				);
4225
+			}
4226
+
4227
+			return true;
4228
+
4229
+			// possible error condition. This will happen when our active_mts data is empty because it is validated for actual active
4230
+			// message types after the activation process.  However its possible some messengers don't HAVE any default_message_types
4231
+			// in which case we just give a success message for the messenger being successfully activated.
4232
+		} else {
4233
+			if (! $messenger->get_default_message_types()) {
4234
+				// messenger doesn't have any default message types so still a success.
4235
+				EE_Error::add_success(
4236
+					sprintf(
4237
+						esc_html__('%s messenger was successfully activated.', 'event_espresso'),
4238
+						ucwords($messenger->label['singular'])
4239
+					)
4240
+				);
4241
+
4242
+				return true;
4243
+			} else {
4244
+				EE_Error::add_error(
4245
+					$message_type instanceof EE_message_type
4246
+						? sprintf(
4247
+							esc_html__(
4248
+								'%s message type was not successfully activated with the %s messenger',
4249
+								'event_espresso'
4250
+							),
4251
+							ucwords($message_type->label['singular']),
4252
+							ucwords($messenger->label['singular'])
4253
+						)
4254
+						: sprintf(
4255
+							esc_html__('%s messenger was not successfully activated', 'event_espresso'),
4256
+							ucwords($messenger->label['singular'])
4257
+						),
4258
+					__FILE__,
4259
+					__FUNCTION__,
4260
+					__LINE__
4261
+				);
4262
+
4263
+				return false;
4264
+			}
4265
+		}
4266
+	}
4267
+
4268
+
4269
+	/**
4270
+	 * This sets up the appropriate response for deactivating a messenger and/or message type.
4271
+	 *
4272
+	 * @param EE_messenger         $messenger
4273
+	 * @param EE_message_type|null $message_type
4274
+	 * @return bool
4275
+	 * @throws DomainException
4276
+	 * @throws EE_Error
4277
+	 * @throws InvalidArgumentException
4278
+	 * @throws ReflectionException
4279
+	 * @throws InvalidDataTypeException
4280
+	 * @throws InvalidInterfaceException
4281
+	 */
4282
+	protected function _setup_response_message_for_deactivating_messenger_with_message_types(
4283
+		$messenger,
4284
+		EE_message_type $message_type = null
4285
+	) {
4286
+		EE_Error::overwrite_success();
4287
+
4288
+		// if $messenger isn't a valid messenger object then get out.
4289
+		if (! $messenger instanceof EE_Messenger) {
4290
+			EE_Error::add_error(
4291
+				esc_html__('The messenger being deactivated is not a valid messenger', 'event_espresso'),
4292
+				__FILE__,
4293
+				__FUNCTION__,
4294
+				__LINE__
4295
+			);
4296
+
4297
+			return false;
4298
+		}
4299
+
4300
+		if ($message_type instanceof EE_message_type) {
4301
+			$message_type_name = $message_type->name;
4302
+			EE_Error::add_success(
4303
+				sprintf(
4304
+					esc_html__(
4305
+						'%s message type has been successfully deactivated for the %s messenger.',
4306
+						'event_espresso'
4307
+					),
4308
+					ucwords($message_type->label['singular']),
4309
+					ucwords($messenger->label['singular'])
4310
+				)
4311
+			);
4312
+		} else {
4313
+			$message_type_name = '';
4314
+			EE_Error::add_success(
4315
+				sprintf(
4316
+					esc_html__('%s messenger has been successfully deactivated.', 'event_espresso'),
4317
+					ucwords($messenger->label['singular'])
4318
+				)
4319
+			);
4320
+		}
4321
+
4322
+		// if messenger was html or message type was invoice then let's make sure we deactivate invoice payment method.
4323
+		if ($messenger->name === 'html' || $message_type_name === 'invoice') {
4324
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
4325
+			$count_updated = EE_Payment_Method_Manager::instance()->deactivate_payment_method('invoice');
4326
+			if ($count_updated > 0) {
4327
+				$msg = $message_type_name === 'invoice'
4328
+					? esc_html__(
4329
+						'Deactivating the invoice message type also automatically deactivates the invoice payment method. In order for invoices to be generated the invoice message type must be active. If you completed this action by mistake, simply reactivate the invoice message type and then visit the payment methods admin page to reactivate the invoice payment method.',
4330
+						'event_espresso'
4331
+					)
4332
+					: esc_html__(
4333
+						'Deactivating the html messenger also automatically deactivates the invoice payment method.  In order for invoices to be generated the html messenger must be be active.  If you completed this action by mistake, simply reactivate the html messenger, then visit the payment methods admin page to reactivate the invoice payment method.',
4334
+						'event_espresso'
4335
+					);
4336
+				EE_Error::add_attention($msg);
4337
+			}
4338
+		}
4339
+
4340
+		return true;
4341
+	}
4342
+
4343
+
4344
+	/**
4345
+	 * handles updating a message type form on messenger activation IF the message type has settings fields. (via ajax)
4346
+	 *
4347
+	 * @throws DomainException
4348
+	 */
4349
+	public function update_mt_form()
4350
+	{
4351
+		if (! isset($this->_req_data['messenger']) || ! isset($this->_req_data['message_type'])) {
4352
+			EE_Error::add_error(
4353
+				esc_html__('Require message type or messenger to send an updated form', 'event_espresso'),
4354
+				__FILE__,
4355
+				__FUNCTION__,
4356
+				__LINE__
4357
+			);
4358
+			$this->_return_json();
4359
+		}
4360
+
4361
+		$message_types = $this->get_installed_message_types();
4362
+
4363
+		$message_type = $message_types[ $this->_req_data['message_type'] ];
4364
+		$messenger = $this->_message_resource_manager->get_active_messenger($this->_req_data['messenger']);
4365
+
4366
+		$content = $this->_message_type_settings_content(
4367
+			$message_type,
4368
+			$messenger,
4369
+			true
4370
+		);
4371
+		$this->_template_args['success'] = true;
4372
+		$this->_template_args['content'] = $content;
4373
+		$this->_return_json();
4374
+	}
4375
+
4376
+
4377
+	/**
4378
+	 * this handles saving the settings for a messenger or message type
4379
+	 *
4380
+	 */
4381
+	public function save_settings()
4382
+	{
4383
+		if (! isset($this->_req_data['type'])) {
4384
+			EE_Error::add_error(
4385
+				esc_html__(
4386
+					'Cannot save settings because type is unknown (messenger settings or messsage type settings?)',
4387
+					'event_espresso'
4388
+				),
4389
+				__FILE__,
4390
+				__FUNCTION__,
4391
+				__LINE__
4392
+			);
4393
+			$this->_template_args['error'] = true;
4394
+			$this->_return_json();
4395
+		}
4396
+
4397
+
4398
+		if ($this->_req_data['type'] === 'messenger') {
4399
+			// this should be an array.
4400
+			$settings = $this->_req_data['messenger_settings'];
4401
+			$messenger = $settings['messenger'];
4402
+			// let's setup the settings data
4403
+			foreach ($settings as $key => $value) {
4404
+				switch ($key) {
4405
+					case 'messenger':
4406
+						unset($settings['messenger']);
4407
+						break;
4408
+					case 'message_types':
4409
+						unset($settings['message_types']);
4410
+						break;
4411
+					default:
4412
+						$settings[ $key ] = $value;
4413
+						break;
4414
+				}
4415
+			}
4416
+			$this->_message_resource_manager->add_settings_for_messenger($messenger, $settings);
4417
+		} elseif ($this->_req_data['type'] === 'message_type') {
4418
+			$settings = $this->_req_data['message_type_settings'];
4419
+			$messenger = $settings['messenger'];
4420
+			$message_type = $settings['message_type'];
4421
+
4422
+			foreach ($settings as $key => $value) {
4423
+				switch ($key) {
4424
+					case 'messenger':
4425
+						unset($settings['messenger']);
4426
+						break;
4427
+					case 'message_type':
4428
+						unset($settings['message_type']);
4429
+						break;
4430
+					default:
4431
+						$settings[ $key ] = $value;
4432
+						break;
4433
+				}
4434
+			}
4435
+
4436
+			$this->_message_resource_manager->add_settings_for_message_type($messenger, $message_type, $settings);
4437
+		}
4438
+
4439
+		// okay we should have the data all setup.  Now we just update!
4440
+		$success = $this->_message_resource_manager->update_active_messengers_option();
4441
+
4442
+		if ($success) {
4443
+			EE_Error::add_success(__('Settings updated', 'event_espresso'));
4444
+		} else {
4445
+			EE_Error::add_error(
4446
+				esc_html__(
4447
+					'Settings did not get updated',
4448
+					'event_espresso'
4449
+				),
4450
+				__FILE__,
4451
+				__FUNCTION__,
4452
+				__LINE__
4453
+			);
4454
+		}
4455
+
4456
+		$this->_template_args['success'] = $success;
4457
+		$this->_return_json();
4458
+	}
4459
+
4460
+
4461
+
4462
+
4463
+	/**  EE MESSAGE PROCESSING ACTIONS **/
4464
+
4465
+
4466
+	/**
4467
+	 * This immediately generates any EE_Message ID's that are selected that are EEM_Message::status_incomplete
4468
+	 * However, this does not send immediately, it just queues for sending.
4469
+	 *
4470
+	 * @since 4.9.0
4471
+	 * @throws EE_Error
4472
+	 * @throws InvalidDataTypeException
4473
+	 * @throws InvalidInterfaceException
4474
+	 * @throws InvalidArgumentException
4475
+	 * @throws ReflectionException
4476
+	 */
4477
+	protected function _generate_now()
4478
+	{
4479
+		EED_Messages::generate_now($this->_get_msg_ids_from_request());
4480
+		$this->_redirect_after_action(false, '', '', array(), true);
4481
+	}
4482
+
4483
+
4484
+	/**
4485
+	 * This immediately generates AND sends any EE_Message's selected that are EEM_Message::status_incomplete or that
4486
+	 * are EEM_Message::status_resend or EEM_Message::status_idle
4487
+	 *
4488
+	 * @since 4.9.0
4489
+	 * @throws EE_Error
4490
+	 * @throws InvalidDataTypeException
4491
+	 * @throws InvalidInterfaceException
4492
+	 * @throws InvalidArgumentException
4493
+	 * @throws ReflectionException
4494
+	 */
4495
+	protected function _generate_and_send_now()
4496
+	{
4497
+		EED_Messages::generate_and_send_now($this->_get_msg_ids_from_request());
4498
+		$this->_redirect_after_action(false, '', '', array(), true);
4499
+	}
4500
+
4501
+
4502
+	/**
4503
+	 * This queues any EEM_Message::status_sent EE_Message ids in the request for resending.
4504
+	 *
4505
+	 * @since 4.9.0
4506
+	 * @throws EE_Error
4507
+	 * @throws InvalidDataTypeException
4508
+	 * @throws InvalidInterfaceException
4509
+	 * @throws InvalidArgumentException
4510
+	 * @throws ReflectionException
4511
+	 */
4512
+	protected function _queue_for_resending()
4513
+	{
4514
+		EED_Messages::queue_for_resending($this->_get_msg_ids_from_request());
4515
+		$this->_redirect_after_action(false, '', '', array(), true);
4516
+	}
4517
+
4518
+
4519
+	/**
4520
+	 *  This sends immediately any EEM_Message::status_idle or EEM_Message::status_resend messages in the queue
4521
+	 *
4522
+	 * @since 4.9.0
4523
+	 * @throws EE_Error
4524
+	 * @throws InvalidDataTypeException
4525
+	 * @throws InvalidInterfaceException
4526
+	 * @throws InvalidArgumentException
4527
+	 * @throws ReflectionException
4528
+	 */
4529
+	protected function _send_now()
4530
+	{
4531
+		EED_Messages::send_now($this->_get_msg_ids_from_request());
4532
+		$this->_redirect_after_action(false, '', '', array(), true);
4533
+	}
4534
+
4535
+
4536
+	/**
4537
+	 * Deletes EE_messages for IDs in the request.
4538
+	 *
4539
+	 * @since 4.9.0
4540
+	 * @throws EE_Error
4541
+	 * @throws InvalidDataTypeException
4542
+	 * @throws InvalidInterfaceException
4543
+	 * @throws InvalidArgumentException
4544
+	 */
4545
+	protected function _delete_ee_messages()
4546
+	{
4547
+		$msg_ids = $this->_get_msg_ids_from_request();
4548
+		$deleted_count = 0;
4549
+		foreach ($msg_ids as $msg_id) {
4550
+			if (EEM_Message::instance()->delete_by_ID($msg_id)) {
4551
+				$deleted_count++;
4552
+			}
4553
+		}
4554
+		if ($deleted_count) {
4555
+			EE_Error::add_success(
4556
+				esc_html(
4557
+					_n(
4558
+						'Message successfully deleted',
4559
+						'Messages successfully deleted',
4560
+						$deleted_count,
4561
+						'event_espresso'
4562
+					)
4563
+				)
4564
+			);
4565
+			$this->_redirect_after_action(
4566
+				false,
4567
+				'',
4568
+				'',
4569
+				array(),
4570
+				true
4571
+			);
4572
+		} else {
4573
+			EE_Error::add_error(
4574
+				_n('The message was not deleted.', 'The messages were not deleted', count($msg_ids), 'event_espresso'),
4575
+				__FILE__,
4576
+				__FUNCTION__,
4577
+				__LINE__
4578
+			);
4579
+			$this->_redirect_after_action(false, '', '', array(), true);
4580
+		}
4581
+	}
4582
+
4583
+
4584
+	/**
4585
+	 *  This looks for 'MSG_ID' key in the request and returns an array of MSG_ID's if present.
4586
+	 *
4587
+	 * @since 4.9.0
4588
+	 * @return array
4589
+	 */
4590
+	protected function _get_msg_ids_from_request()
4591
+	{
4592
+		if (! isset($this->_req_data['MSG_ID'])) {
4593
+			return array();
4594
+		}
4595
+
4596
+		return is_array($this->_req_data['MSG_ID'])
4597
+			? array_keys($this->_req_data['MSG_ID'])
4598
+			: array($this->_req_data['MSG_ID']);
4599
+	}
4600 4600
 }
Please login to merge, or discard this patch.
core/db_classes/EE_Ticket.class.php 1 patch
Indentation   +1998 added lines, -1998 removed lines patch added patch discarded remove patch
@@ -14,2006 +14,2006 @@
 block discarded – undo
14 14
 class EE_Ticket extends EE_Soft_Delete_Base_Class implements EEI_Line_Item_Object, EEI_Event_Relation, EEI_Has_Icon
15 15
 {
16 16
 
17
-    /**
18
-     * TicKet Sold out:
19
-     * constant used by ticket_status() to indicate that a ticket is sold out
20
-     * and no longer available for purchases
21
-     */
22
-    const sold_out = 'TKS';
23
-
24
-    /**
25
-     * TicKet Expired:
26
-     * constant used by ticket_status() to indicate that a ticket is expired
27
-     * and no longer available for purchase
28
-     */
29
-    const expired = 'TKE';
30
-
31
-    /**
32
-     * TicKet Archived:
33
-     * constant used by ticket_status() to indicate that a ticket is archived
34
-     * and no longer available for purchase
35
-     */
36
-    const archived = 'TKA';
37
-
38
-    /**
39
-     * TicKet Pending:
40
-     * constant used by ticket_status() to indicate that a ticket is pending
41
-     * and is NOT YET available for purchase
42
-     */
43
-    const pending = 'TKP';
44
-
45
-    /**
46
-     * TicKet On sale:
47
-     * constant used by ticket_status() to indicate that a ticket is On Sale
48
-     * and IS available for purchase
49
-     */
50
-    const onsale = 'TKO';
51
-
52
-    /**
53
-     * extra meta key for tracking ticket reservations
54
-     *
55
-     * @type string
56
-     */
57
-    const META_KEY_TICKET_RESERVATIONS = 'ticket_reservations';
58
-
59
-    /**
60
-     * override of parent property
61
-     *
62
-     * @var EEM_Ticket
63
-     */
64
-    protected $_model;
65
-
66
-    /**
67
-     * cached result from method of the same name
68
-     *
69
-     * @var float $_ticket_total_with_taxes
70
-     */
71
-    private $_ticket_total_with_taxes;
72
-
73
-
74
-    /**
75
-     * @param array  $props_n_values          incoming values
76
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
77
-     *                                        used.)
78
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
79
-     *                                        date_format and the second value is the time format
80
-     * @return EE_Ticket
81
-     * @throws EE_Error
82
-     * @throws ReflectionException
83
-     */
84
-    public static function new_instance($props_n_values = [], $timezone = null, $date_formats = [])
85
-    {
86
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
87
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
88
-    }
89
-
90
-
91
-    /**
92
-     * @param array  $props_n_values  incoming values from the database
93
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
94
-     *                                the website will be used.
95
-     * @return EE_Ticket
96
-     * @throws EE_Error
97
-     * @throws ReflectionException
98
-     */
99
-    public static function new_instance_from_db($props_n_values = [], $timezone = null)
100
-    {
101
-        return new self($props_n_values, true, $timezone);
102
-    }
103
-
104
-
105
-    /**
106
-     * @return bool
107
-     * @throws EE_Error
108
-     * @throws ReflectionException
109
-     */
110
-    public function parent()
111
-    {
112
-        return $this->get('TKT_parent');
113
-    }
114
-
115
-
116
-    /**
117
-     * return if a ticket has quantities available for purchase
118
-     *
119
-     * @param int $DTT_ID the primary key for a particular datetime
120
-     * @return boolean
121
-     * @throws EE_Error
122
-     * @throws ReflectionException
123
-     */
124
-    public function available($DTT_ID = 0)
125
-    {
126
-        // are we checking availability for a particular datetime ?
127
-        if ($DTT_ID) {
128
-            // get that datetime object
129
-            $datetime = $this->get_first_related('Datetime', [['DTT_ID' => $DTT_ID]]);
130
-            // if  ticket sales for this datetime have exceeded the reg limit...
131
-            if ($datetime instanceof EE_Datetime && $datetime->sold_out()) {
132
-                return false;
133
-            }
134
-        }
135
-        // datetime is still open for registration, but is this ticket sold out ?
136
-        return $this->qty() < 1 || $this->qty() > $this->sold();
137
-    }
138
-
139
-
140
-    /**
141
-     * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired
142
-     *
143
-     * @param bool        $display   true = we'll return a localized string, otherwise we just return the value of the
144
-     *                               relevant status const
145
-     * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save
146
-     *                               further processing
147
-     * @return mixed status int if the display string isn't requested
148
-     * @throws EE_Error
149
-     * @throws ReflectionException
150
-     */
151
-    public function ticket_status($display = false, $remaining = null)
152
-    {
153
-        $remaining = is_bool($remaining) ? $remaining : $this->is_remaining();
154
-        if (! $remaining) {
155
-            return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out;
156
-        }
157
-        if ($this->get('TKT_deleted')) {
158
-            return $display ? EEH_Template::pretty_status(EE_Ticket::archived, false, 'sentence') : EE_Ticket::archived;
159
-        }
160
-        if ($this->is_expired()) {
161
-            return $display ? EEH_Template::pretty_status(EE_Ticket::expired, false, 'sentence') : EE_Ticket::expired;
162
-        }
163
-        if ($this->is_pending()) {
164
-            return $display ? EEH_Template::pretty_status(EE_Ticket::pending, false, 'sentence') : EE_Ticket::pending;
165
-        }
166
-        if ($this->is_on_sale()) {
167
-            return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence') : EE_Ticket::onsale;
168
-        }
169
-        return '';
170
-    }
171
-
172
-
173
-    /**
174
-     * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale
175
-     * considering ALL the factors used for figuring that out.
176
-     *
177
-     * @access public
178
-     * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt.
179
-     * @return boolean         true = tickets remaining, false not.
180
-     * @throws EE_Error
181
-     * @throws ReflectionException
182
-     */
183
-    public function is_remaining($DTT_ID = 0)
184
-    {
185
-        $num_remaining = $this->remaining($DTT_ID);
186
-        if ($num_remaining === 0) {
187
-            return false;
188
-        }
189
-        if ($num_remaining > 0 && $num_remaining < $this->min()) {
190
-            return false;
191
-        }
192
-        return true;
193
-    }
194
-
195
-
196
-    /**
197
-     * return the total number of tickets available for purchase
198
-     *
199
-     * @param int $DTT_ID  the primary key for a particular datetime.
200
-     *                     set to 0 for all related datetimes
201
-     * @return int
202
-     * @throws EE_Error
203
-     * @throws ReflectionException
204
-     */
205
-    public function remaining($DTT_ID = 0)
206
-    {
207
-        return $this->real_quantity_on_ticket('saleable', $DTT_ID);
208
-    }
209
-
210
-
211
-    /**
212
-     * Gets min
213
-     *
214
-     * @return int
215
-     * @throws EE_Error
216
-     * @throws ReflectionException
217
-     */
218
-    public function min()
219
-    {
220
-        return $this->get('TKT_min');
221
-    }
222
-
223
-
224
-    /**
225
-     * return if a ticket is no longer available cause its available dates have expired.
226
-     *
227
-     * @return boolean
228
-     * @throws EE_Error
229
-     * @throws ReflectionException
230
-     */
231
-    public function is_expired()
232
-    {
233
-        return ($this->get_raw('TKT_end_date') < time());
234
-    }
235
-
236
-
237
-    /**
238
-     * Return if a ticket is yet to go on sale or not
239
-     *
240
-     * @return boolean
241
-     * @throws EE_Error
242
-     * @throws ReflectionException
243
-     */
244
-    public function is_pending()
245
-    {
246
-        return ($this->get_raw('TKT_start_date') >= time());
247
-    }
248
-
249
-
250
-    /**
251
-     * Return if a ticket is on sale or not
252
-     *
253
-     * @return boolean
254
-     * @throws EE_Error
255
-     * @throws ReflectionException
256
-     */
257
-    public function is_on_sale()
258
-    {
259
-        return ($this->get_raw('TKT_start_date') <= time() && $this->get_raw('TKT_end_date') >= time());
260
-    }
261
-
262
-
263
-    /**
264
-     * This returns the chronologically last datetime that this ticket is associated with
265
-     *
266
-     * @param string $date_format
267
-     * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with
268
-     *                            the end date ie: Jan 01 "to" Dec 31
269
-     * @return string
270
-     * @throws EE_Error
271
-     * @throws ReflectionException
272
-     */
273
-    public function date_range($date_format = '', $conjunction = ' - ')
274
-    {
275
-        $date_format = ! empty($date_format) ? $date_format : $this->_dt_frmt;
276
-        $first_date  = $this->first_datetime() instanceof EE_Datetime
277
-            ? $this->first_datetime()->get_i18n_datetime('DTT_EVT_start', $date_format)
278
-            : '';
279
-        $last_date   = $this->last_datetime() instanceof EE_Datetime
280
-            ? $this->last_datetime()->get_i18n_datetime('DTT_EVT_end', $date_format)
281
-            : '';
282
-
283
-        return $first_date && $last_date ? $first_date . $conjunction . $last_date : '';
284
-    }
285
-
286
-
287
-    /**
288
-     * This returns the chronologically first datetime that this ticket is associated with
289
-     *
290
-     * @return EE_Datetime
291
-     * @throws EE_Error
292
-     * @throws ReflectionException
293
-     */
294
-    public function first_datetime()
295
-    {
296
-        $datetimes = $this->datetimes(['limit' => 1]);
297
-        return reset($datetimes);
298
-    }
299
-
300
-
301
-    /**
302
-     * Gets all the datetimes this ticket can be used for attending.
303
-     * Unless otherwise specified, orders datetimes by start date.
304
-     *
305
-     * @param array $query_params @see
306
-     *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
307
-     * @return EE_Datetime[]|EE_Base_Class[]
308
-     * @throws EE_Error
309
-     * @throws ReflectionException
310
-     */
311
-    public function datetimes($query_params = [])
312
-    {
313
-        if (! isset($query_params['order_by'])) {
314
-            $query_params['order_by']['DTT_order'] = 'ASC';
315
-        }
316
-        return $this->get_many_related('Datetime', $query_params);
317
-    }
318
-
319
-
320
-    /**
321
-     * This returns the chronologically last datetime that this ticket is associated with
322
-     *
323
-     * @return EE_Datetime
324
-     * @throws EE_Error
325
-     * @throws ReflectionException
326
-     */
327
-    public function last_datetime()
328
-    {
329
-        $datetimes = $this->datetimes(['limit' => 1, 'order_by' => ['DTT_EVT_start' => 'DESC']]);
330
-        return end($datetimes);
331
-    }
332
-
333
-
334
-    /**
335
-     * This returns the total tickets sold depending on the given parameters.
336
-     *
337
-     * @param string $what    Can be one of two options: 'ticket', 'datetime'.
338
-     *                        'ticket' = total ticket sales for all datetimes this ticket is related to
339
-     *                        'datetime' = total ticket sales for a specified datetime (required $dtt_id)
340
-     *                        'datetime' = total ticket sales in the datetime_ticket table.
341
-     *                        If $dtt_id is not given then we return an array of sales indexed by datetime.
342
-     *                        If $dtt_id IS given then we return the tickets sold for that given datetime.
343
-     * @param int    $dtt_id  [optional] include the dtt_id with $what = 'datetime'.
344
-     * @return mixed (array|int)          how many tickets have sold
345
-     * @throws EE_Error
346
-     * @throws ReflectionException
347
-     */
348
-    public function tickets_sold($what = 'ticket', $dtt_id = null)
349
-    {
350
-        $total        = 0;
351
-        $tickets_sold = $this->_all_tickets_sold();
352
-        switch ($what) {
353
-            case 'ticket':
354
-                return $tickets_sold['ticket'];
355
-                break;
356
-            case 'datetime':
357
-                if (empty($tickets_sold['datetime'])) {
358
-                    return $total;
359
-                }
360
-                if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) {
361
-                    EE_Error::add_error(
362
-                        __(
363
-                            'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included.  Are you SURE that is a datetime related to this ticket?',
364
-                            'event_espresso'
365
-                        ),
366
-                        __FILE__,
367
-                        __FUNCTION__,
368
-                        __LINE__
369
-                    );
370
-                    return $total;
371
-                }
372
-                return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ];
373
-                break;
374
-            default:
375
-                return $total;
376
-        }
377
-    }
378
-
379
-
380
-    /**
381
-     * This returns an array indexed by datetime_id for tickets sold with this ticket.
382
-     *
383
-     * @return EE_Ticket[]
384
-     * @throws EE_Error
385
-     * @throws ReflectionException
386
-     */
387
-    protected function _all_tickets_sold()
388
-    {
389
-        $datetimes    = $this->get_many_related('Datetime');
390
-        $tickets_sold = [];
391
-        if (! empty($datetimes)) {
392
-            foreach ($datetimes as $datetime) {
393
-                $tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold');
394
-            }
395
-        }
396
-        // Tickets sold
397
-        $tickets_sold['ticket'] = $this->sold();
398
-        return $tickets_sold;
399
-    }
400
-
401
-
402
-    /**
403
-     * This returns the base price object for the ticket.
404
-     *
405
-     * @param bool $return_array whether to return as an array indexed by price id or just the object.
406
-     * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[]
407
-     * @throws EE_Error
408
-     * @throws ReflectionException
409
-     */
410
-    public function base_price($return_array = false)
411
-    {
412
-        $_where = ['Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price];
413
-        return $return_array
414
-            ? $this->get_many_related('Price', [$_where])
415
-            : $this->get_first_related('Price', [$_where]);
416
-    }
417
-
418
-
419
-    /**
420
-     * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price)
421
-     *
422
-     * @access public
423
-     * @return EE_Price[]
424
-     * @throws EE_Error
425
-     * @throws ReflectionException
426
-     */
427
-    public function price_modifiers()
428
-    {
429
-        $query_params = [
430
-            0 => [
431
-                'Price_Type.PBT_ID' => [
432
-                    'NOT IN',
433
-                    [EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax],
434
-                ],
435
-            ],
436
-        ];
437
-        return $this->prices($query_params);
438
-    }
439
-
440
-
441
-    /**
442
-     * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price)
443
-     *
444
-     * @access public
445
-     * @return EE_Price[]
446
-     * @throws EE_Error
447
-     * @throws ReflectionException
448
-     */
449
-    public function tax_price_modifiers()
450
-    {
451
-        $query_params = [
452
-            0 => [
453
-                'Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax,
454
-            ],
455
-        ];
456
-        return $this->prices($query_params);
457
-    }
458
-
459
-
460
-    /**
461
-     * Gets all the prices that combine to form the final price of this ticket
462
-     *
463
-     * @param array $query_params @see
464
-     *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
465
-     * @return EE_Price[]|EE_Base_Class[]
466
-     * @throws EE_Error
467
-     * @throws ReflectionException
468
-     */
469
-    public function prices($query_params = [])
470
-    {
471
-        return $this->get_many_related('Price', $query_params);
472
-    }
473
-
474
-
475
-    /**
476
-     * Gets all the ticket datetimes (ie, relations between datetimes and tickets)
477
-     *
478
-     * @param array $query_params @see
479
-     *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
480
-     * @return EE_Datetime_Ticket|EE_Base_Class[]
481
-     * @throws EE_Error
482
-     * @throws ReflectionException
483
-     */
484
-    public function datetime_tickets($query_params = [])
485
-    {
486
-        return $this->get_many_related('Datetime_Ticket', $query_params);
487
-    }
488
-
489
-
490
-    /**
491
-     * Gets all the datetimes from the db ordered by DTT_order
492
-     *
493
-     * @param boolean $show_expired
494
-     * @param boolean $show_deleted
495
-     * @return EE_Datetime[]
496
-     * @throws EE_Error
497
-     * @throws ReflectionException
498
-     */
499
-    public function datetimes_ordered($show_expired = true, $show_deleted = false)
500
-    {
501
-        return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order(
502
-            $this->ID(),
503
-            $show_expired,
504
-            $show_deleted
505
-        );
506
-    }
507
-
508
-
509
-    /**
510
-     * Gets ID
511
-     *
512
-     * @return int
513
-     * @throws EE_Error
514
-     * @throws ReflectionException
515
-     */
516
-    public function ID()
517
-    {
518
-        return $this->get('TKT_ID');
519
-    }
520
-
521
-
522
-    /**
523
-     * get the author of the ticket.
524
-     *
525
-     * @return int
526
-     * @throws EE_Error
527
-     * @throws ReflectionException
528
-     * @since 4.5.0
529
-     */
530
-    public function wp_user()
531
-    {
532
-        return $this->get('TKT_wp_user');
533
-    }
534
-
535
-
536
-    /**
537
-     * Gets the template for the ticket
538
-     *
539
-     * @return EE_Ticket_Template|EE_Base_Class
540
-     * @throws EE_Error
541
-     * @throws ReflectionException
542
-     */
543
-    public function template()
544
-    {
545
-        return $this->get_first_related('Ticket_Template');
546
-    }
547
-
548
-
549
-    /**
550
-     * Simply returns an array of EE_Price objects that are taxes.
551
-     *
552
-     * @return EE_Price[]
553
-     * @throws EE_Error
554
-     */
555
-    public function get_ticket_taxes_for_admin()
556
-    {
557
-        return EE_Taxes::get_taxes_for_admin();
558
-    }
559
-
560
-
561
-    /**
562
-     * @return float
563
-     * @throws EE_Error
564
-     * @throws ReflectionException
565
-     */
566
-    public function ticket_price()
567
-    {
568
-        return $this->get('TKT_price');
569
-    }
570
-
571
-
572
-    /**
573
-     * @return mixed
574
-     * @throws EE_Error
575
-     * @throws ReflectionException
576
-     */
577
-    public function pretty_price()
578
-    {
579
-        return $this->get_pretty('TKT_price');
580
-    }
581
-
582
-
583
-    /**
584
-     * @return bool
585
-     * @throws EE_Error
586
-     * @throws ReflectionException
587
-     */
588
-    public function is_free()
589
-    {
590
-        return $this->get_ticket_total_with_taxes() === (float) 0;
591
-    }
592
-
593
-
594
-    /**
595
-     * get_ticket_total_with_taxes
596
-     *
597
-     * @param bool $no_cache
598
-     * @return float
599
-     * @throws EE_Error
600
-     * @throws ReflectionException
601
-     */
602
-    public function get_ticket_total_with_taxes($no_cache = false)
603
-    {
604
-        if ($this->_ticket_total_with_taxes === null || $no_cache) {
605
-            $this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin();
606
-        }
607
-        return (float) $this->_ticket_total_with_taxes;
608
-    }
609
-
610
-
611
-    /**
612
-     * @throws EE_Error
613
-     * @throws ReflectionException
614
-     */
615
-    public function ensure_TKT_Price_correct()
616
-    {
617
-        $this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this));
618
-        $this->save();
619
-    }
620
-
621
-
622
-    /**
623
-     * @return float
624
-     * @throws EE_Error
625
-     * @throws ReflectionException
626
-     */
627
-    public function get_ticket_subtotal()
628
-    {
629
-        return EE_Taxes::get_subtotal_for_admin($this);
630
-    }
631
-
632
-
633
-    /**
634
-     * Returns the total taxes applied to this ticket
635
-     *
636
-     * @return float
637
-     * @throws EE_Error
638
-     * @throws ReflectionException
639
-     */
640
-    public function get_ticket_taxes_total_for_admin()
641
-    {
642
-        return EE_Taxes::get_total_taxes_for_admin($this);
643
-    }
644
-
645
-
646
-    /**
647
-     * Sets name
648
-     *
649
-     * @param string $name
650
-     * @throws EE_Error
651
-     * @throws ReflectionException
652
-     */
653
-    public function set_name($name)
654
-    {
655
-        $this->set('TKT_name', $name);
656
-    }
657
-
658
-
659
-    /**
660
-     * Gets description
661
-     *
662
-     * @return string
663
-     * @throws EE_Error
664
-     * @throws ReflectionException
665
-     */
666
-    public function description()
667
-    {
668
-        return $this->get('TKT_description');
669
-    }
670
-
671
-
672
-    /**
673
-     * Sets description
674
-     *
675
-     * @param string $description
676
-     * @throws EE_Error
677
-     * @throws ReflectionException
678
-     */
679
-    public function set_description($description)
680
-    {
681
-        $this->set('TKT_description', $description);
682
-    }
683
-
684
-
685
-    /**
686
-     * Gets start_date
687
-     *
688
-     * @param string $date_format
689
-     * @param string $time_format
690
-     * @return string
691
-     * @throws EE_Error
692
-     * @throws ReflectionException
693
-     */
694
-    public function start_date($date_format = '', $time_format = '')
695
-    {
696
-        return $this->_get_datetime('TKT_start_date', $date_format, $time_format);
697
-    }
698
-
699
-
700
-    /**
701
-     * Sets start_date
702
-     *
703
-     * @param string $start_date
704
-     * @return void
705
-     * @throws EE_Error
706
-     * @throws ReflectionException
707
-     */
708
-    public function set_start_date($start_date)
709
-    {
710
-        $this->_set_date_time('B', $start_date, 'TKT_start_date');
711
-    }
712
-
713
-
714
-    /**
715
-     * Gets end_date
716
-     *
717
-     * @param string $date_format
718
-     * @param string $time_format
719
-     * @return string
720
-     * @throws EE_Error
721
-     * @throws ReflectionException
722
-     */
723
-    public function end_date($date_format = '', $time_format = '')
724
-    {
725
-        return $this->_get_datetime('TKT_end_date', $date_format, $time_format);
726
-    }
727
-
728
-
729
-    /**
730
-     * Sets end_date
731
-     *
732
-     * @param string $end_date
733
-     * @return void
734
-     * @throws EE_Error
735
-     * @throws ReflectionException
736
-     */
737
-    public function set_end_date($end_date)
738
-    {
739
-        $this->_set_date_time('B', $end_date, 'TKT_end_date');
740
-    }
741
-
742
-
743
-    /**
744
-     * Sets sell until time
745
-     *
746
-     * @param string $time a string representation of the sell until time (ex 9am or 7:30pm)
747
-     * @throws EE_Error
748
-     * @throws ReflectionException
749
-     * @since 4.5.0
750
-     */
751
-    public function set_end_time($time)
752
-    {
753
-        $this->_set_time_for($time, 'TKT_end_date');
754
-    }
755
-
756
-
757
-    /**
758
-     * Sets min
759
-     *
760
-     * @param int $min
761
-     * @return void
762
-     * @throws EE_Error
763
-     * @throws ReflectionException
764
-     */
765
-    public function set_min($min)
766
-    {
767
-        $this->set('TKT_min', $min);
768
-    }
769
-
770
-
771
-    /**
772
-     * Gets max
773
-     *
774
-     * @return int
775
-     * @throws EE_Error
776
-     * @throws ReflectionException
777
-     */
778
-    public function max()
779
-    {
780
-        return $this->get('TKT_max');
781
-    }
782
-
783
-
784
-    /**
785
-     * Sets max
786
-     *
787
-     * @param int $max
788
-     * @return void
789
-     * @throws EE_Error
790
-     * @throws ReflectionException
791
-     */
792
-    public function set_max($max)
793
-    {
794
-        $this->set('TKT_max', $max);
795
-    }
796
-
797
-
798
-    /**
799
-     * Sets price
800
-     *
801
-     * @param float $price
802
-     * @return void
803
-     * @throws EE_Error
804
-     * @throws ReflectionException
805
-     */
806
-    public function set_price($price)
807
-    {
808
-        $this->set('TKT_price', $price);
809
-    }
810
-
811
-
812
-    /**
813
-     * Gets sold
814
-     *
815
-     * @return int
816
-     * @throws EE_Error
817
-     * @throws ReflectionException
818
-     */
819
-    public function sold()
820
-    {
821
-        return $this->get_raw('TKT_sold');
822
-    }
823
-
824
-
825
-    /**
826
-     * Sets sold
827
-     *
828
-     * @param int $sold
829
-     * @return void
830
-     * @throws EE_Error
831
-     * @throws ReflectionException
832
-     */
833
-    public function set_sold($sold)
834
-    {
835
-        // sold can not go below zero
836
-        $sold = max(0, $sold);
837
-        $this->set('TKT_sold', $sold);
838
-    }
839
-
840
-
841
-    /**
842
-     * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its
843
-     * associated datetimes.
844
-     *
845
-     * @param int $qty
846
-     * @return boolean
847
-     * @throws EE_Error
848
-     * @throws InvalidArgumentException
849
-     * @throws InvalidDataTypeException
850
-     * @throws InvalidInterfaceException
851
-     * @throws ReflectionException
852
-     * @since 4.9.80.p
853
-     */
854
-    public function increaseSold($qty = 1)
855
-    {
856
-        $qty = absint($qty);
857
-        // increment sold and decrement reserved datetime quantities simultaneously
858
-        // don't worry about failures, because they must have already had a spot reserved
859
-        $this->increaseSoldForDatetimes($qty);
860
-        // Increment and decrement ticket quantities simultaneously
861
-        $success = $this->adjustNumericFieldsInDb(
862
-            [
863
-                'TKT_reserved' => $qty * -1,
864
-                'TKT_sold'     => $qty,
865
-            ]
866
-        );
867
-        do_action(
868
-            'AHEE__EE_Ticket__increase_sold',
869
-            $this,
870
-            $qty,
871
-            $this->sold(),
872
-            $success
873
-        );
874
-        return $success;
875
-    }
876
-
877
-
878
-    /**
879
-     * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty.
880
-     *
881
-     * @param int           $qty positive or negative. Positive means to increase sold counts (and decrease reserved
882
-     *                           counts), Negative means to decreases old counts (and increase reserved counts).
883
-     * @param EE_Datetime[] $datetimes
884
-     * @throws EE_Error
885
-     * @throws InvalidArgumentException
886
-     * @throws InvalidDataTypeException
887
-     * @throws InvalidInterfaceException
888
-     * @throws ReflectionException
889
-     * @since 4.9.80.p
890
-     */
891
-    protected function increaseSoldForDatetimes($qty, array $datetimes = [])
892
-    {
893
-        $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes();
894
-        foreach ($datetimes as $datetime) {
895
-            $datetime->increaseSold($qty);
896
-        }
897
-    }
898
-
899
-
900
-    /**
901
-     * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the
902
-     * DB and then updates the model objects.
903
-     * Does not affect the reserved counts.
904
-     *
905
-     * @param int $qty
906
-     * @return boolean
907
-     * @throws EE_Error
908
-     * @throws InvalidArgumentException
909
-     * @throws InvalidDataTypeException
910
-     * @throws InvalidInterfaceException
911
-     * @throws ReflectionException
912
-     * @since 4.9.80.p
913
-     */
914
-    public function decreaseSold($qty = 1)
915
-    {
916
-        $qty = absint($qty);
917
-        $this->decreaseSoldForDatetimes($qty);
918
-        $success = $this->adjustNumericFieldsInDb(
919
-            [
920
-                'TKT_sold' => $qty * -1,
921
-            ]
922
-        );
923
-        do_action(
924
-            'AHEE__EE_Ticket__decrease_sold',
925
-            $this,
926
-            $qty,
927
-            $this->sold(),
928
-            $success
929
-        );
930
-        return $success;
931
-    }
932
-
933
-
934
-    /**
935
-     * Decreases sold on related datetimes
936
-     *
937
-     * @param int           $qty
938
-     * @param EE_Datetime[] $datetimes
939
-     * @return void
940
-     * @throws EE_Error
941
-     * @throws InvalidArgumentException
942
-     * @throws InvalidDataTypeException
943
-     * @throws InvalidInterfaceException
944
-     * @throws ReflectionException
945
-     * @since 4.9.80.p
946
-     */
947
-    protected function decreaseSoldForDatetimes($qty = 1, array $datetimes = [])
948
-    {
949
-        $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes();
950
-        if (is_array($datetimes)) {
951
-            foreach ($datetimes as $datetime) {
952
-                if ($datetime instanceof EE_Datetime) {
953
-                    $datetime->decreaseSold($qty);
954
-                }
955
-            }
956
-        }
957
-    }
958
-
959
-
960
-    /**
961
-     * Gets qty of reserved tickets
962
-     *
963
-     * @return int
964
-     * @throws EE_Error
965
-     * @throws ReflectionException
966
-     */
967
-    public function reserved()
968
-    {
969
-        return $this->get_raw('TKT_reserved');
970
-    }
971
-
972
-
973
-    /**
974
-     * Sets reserved
975
-     *
976
-     * @param int $reserved
977
-     * @return void
978
-     * @throws EE_Error
979
-     * @throws ReflectionException
980
-     */
981
-    public function set_reserved($reserved)
982
-    {
983
-        // reserved can not go below zero
984
-        $reserved = max(0, (int) $reserved);
985
-        $this->set('TKT_reserved', $reserved);
986
-    }
987
-
988
-
989
-    /**
990
-     * Increments reserved by amount passed by $qty, and persists it immediately to the database.
991
-     *
992
-     * @param int    $qty
993
-     * @param string $source
994
-     * @return bool whether we successfully reserved the ticket or not.
995
-     * @throws EE_Error
996
-     * @throws InvalidArgumentException
997
-     * @throws ReflectionException
998
-     * @throws InvalidDataTypeException
999
-     * @throws InvalidInterfaceException
1000
-     * @since 4.9.80.p
1001
-     */
1002
-    public function increaseReserved($qty = 1, $source = 'unknown')
1003
-    {
1004
-        $qty = absint($qty);
1005
-        do_action(
1006
-            'AHEE__EE_Ticket__increase_reserved__begin',
1007
-            $this,
1008
-            $qty,
1009
-            $source
1010
-        );
1011
-        $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "{$qty} from {$source}");
1012
-        $success                         = false;
1013
-        $datetimes_adjusted_successfully = $this->increaseReservedForDatetimes($qty);
1014
-        if ($datetimes_adjusted_successfully) {
1015
-            $success = $this->incrementFieldConditionallyInDb(
1016
-                'TKT_reserved',
1017
-                'TKT_sold',
1018
-                'TKT_qty',
1019
-                $qty
1020
-            );
1021
-            if (! $success) {
1022
-                // The datetimes were successfully bumped, but not the
1023
-                // ticket. So we need to manually rollback the datetimes.
1024
-                $this->decreaseReservedForDatetimes($qty);
1025
-            }
1026
-        }
1027
-        do_action(
1028
-            'AHEE__EE_Ticket__increase_reserved',
1029
-            $this,
1030
-            $qty,
1031
-            $this->reserved(),
1032
-            $success
1033
-        );
1034
-        return $success;
1035
-    }
1036
-
1037
-
1038
-    /**
1039
-     * Increases reserved counts on related datetimes
1040
-     *
1041
-     * @param int           $qty
1042
-     * @param EE_Datetime[] $datetimes
1043
-     * @return boolean indicating success
1044
-     * @throws EE_Error
1045
-     * @throws InvalidArgumentException
1046
-     * @throws InvalidDataTypeException
1047
-     * @throws InvalidInterfaceException
1048
-     * @throws ReflectionException
1049
-     * @since 4.9.80.p
1050
-     */
1051
-    protected function increaseReservedForDatetimes($qty = 1, array $datetimes = [])
1052
-    {
1053
-        $datetimes         = ! empty($datetimes) ? $datetimes : $this->datetimes();
1054
-        $datetimes_updated = [];
1055
-        $limit_exceeded    = false;
1056
-        if (is_array($datetimes)) {
1057
-            foreach ($datetimes as $datetime) {
1058
-                if ($datetime instanceof EE_Datetime) {
1059
-                    if ($datetime->increaseReserved($qty)) {
1060
-                        $datetimes_updated[] = $datetime;
1061
-                    } else {
1062
-                        $limit_exceeded = true;
1063
-                        break;
1064
-                    }
1065
-                }
1066
-            }
1067
-            // If somewhere along the way we detected a datetime whose
1068
-            // limit was exceeded, do a manual rollback.
1069
-            if ($limit_exceeded) {
1070
-                $this->decreaseReservedForDatetimes($qty, $datetimes_updated);
1071
-                return false;
1072
-            }
1073
-        }
1074
-        return true;
1075
-    }
1076
-
1077
-
1078
-    /**
1079
-     * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database.
1080
-     *
1081
-     * @param int    $qty
1082
-     * @param bool   $adjust_datetimes
1083
-     * @param string $source
1084
-     * @return boolean
1085
-     * @throws EE_Error
1086
-     * @throws InvalidArgumentException
1087
-     * @throws ReflectionException
1088
-     * @throws InvalidDataTypeException
1089
-     * @throws InvalidInterfaceException
1090
-     * @since 4.9.80.p
1091
-     */
1092
-    public function decreaseReserved($qty = 1, $adjust_datetimes = true, $source = 'unknown')
1093
-    {
1094
-        $qty = absint($qty);
1095
-        $this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "-{$qty} from {$source}");
1096
-        if ($adjust_datetimes) {
1097
-            $this->decreaseReservedForDatetimes($qty);
1098
-        }
1099
-        $success = $this->adjustNumericFieldsInDb(
1100
-            [
1101
-                'TKT_reserved' => $qty * -1,
1102
-            ]
1103
-        );
1104
-        do_action(
1105
-            'AHEE__EE_Ticket__decrease_reserved',
1106
-            $this,
1107
-            $qty,
1108
-            $this->reserved(),
1109
-            $success
1110
-        );
1111
-        return $success;
1112
-    }
1113
-
1114
-
1115
-    /**
1116
-     * Decreases the reserved count on the specified datetimes.
1117
-     *
1118
-     * @param int           $qty
1119
-     * @param EE_Datetime[] $datetimes
1120
-     * @throws EE_Error
1121
-     * @throws InvalidArgumentException
1122
-     * @throws ReflectionException
1123
-     * @throws InvalidDataTypeException
1124
-     * @throws InvalidInterfaceException
1125
-     * @since 4.9.80.p
1126
-     */
1127
-    protected function decreaseReservedForDatetimes($qty = 1, array $datetimes = [])
1128
-    {
1129
-        $datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes();
1130
-        foreach ($datetimes as $datetime) {
1131
-            if ($datetime instanceof EE_Datetime) {
1132
-                $datetime->decreaseReserved($qty);
1133
-            }
1134
-        }
1135
-    }
1136
-
1137
-
1138
-    /**
1139
-     * Gets ticket quantity
1140
-     *
1141
-     * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
1142
-     *                            therefore $context can be one of three values: '', 'reg_limit', or 'saleable'
1143
-     *                            '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects
1144
-     *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
1145
-     *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
1146
-     *                            is therefore the truest measure of tickets that can be purchased at the moment
1147
-     * @return int
1148
-     * @throws EE_Error
1149
-     * @throws ReflectionException
1150
-     */
1151
-    public function qty($context = '')
1152
-    {
1153
-        switch ($context) {
1154
-            case 'reg_limit':
1155
-                return $this->real_quantity_on_ticket();
1156
-            case 'saleable':
1157
-                return $this->real_quantity_on_ticket('saleable');
1158
-            default:
1159
-                return $this->get_raw('TKT_qty');
1160
-        }
1161
-    }
1162
-
1163
-
1164
-    /**
1165
-     * Gets ticket quantity
1166
-     *
1167
-     * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
1168
-     *                            therefore $context can be one of two values: 'reg_limit', or 'saleable'
1169
-     *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
1170
-     *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
1171
-     *                            is therefore the truest measure of tickets that can be purchased at the moment
1172
-     * @param int    $DTT_ID      the primary key for a particular datetime.
1173
-     *                            set to 0 for all related datetimes
1174
-     * @return int
1175
-     * @throws EE_Error
1176
-     * @throws ReflectionException
1177
-     */
1178
-    public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0)
1179
-    {
1180
-        $raw = $this->get_raw('TKT_qty');
1181
-        // return immediately if it's zero
1182
-        if ($raw === 0) {
1183
-            return $raw;
1184
-        }
1185
-        // echo "\n\n<br />Ticket: " . $this->name() . '<br />';
1186
-        // ensure qty doesn't exceed raw value for THIS ticket
1187
-        $qty = min(EE_INF, $raw);
1188
-        // echo "\n . qty: " . $qty . '<br />';
1189
-        // calculate this ticket's total sales and reservations
1190
-        $sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved();
1191
-        // echo "\n . sold: " . $this->sold() . '<br />';
1192
-        // echo "\n . reserved: " . $this->reserved() . '<br />';
1193
-        // echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />';
1194
-        // first we need to calculate the maximum number of tickets available for the datetime
1195
-        // do we want data for one datetime or all of them ?
1196
-        $query_params = $DTT_ID ? [['DTT_ID' => $DTT_ID]] : [];
1197
-        $datetimes    = $this->datetimes($query_params);
1198
-        if (is_array($datetimes) && ! empty($datetimes)) {
1199
-            foreach ($datetimes as $datetime) {
1200
-                if ($datetime instanceof EE_Datetime) {
1201
-                    $datetime->refresh_from_db();
1202
-                    // echo "\n . . datetime name: " . $datetime->name() . '<br />';
1203
-                    // echo "\n . . datetime ID: " . $datetime->ID() . '<br />';
1204
-                    // initialize with no restrictions for each datetime
1205
-                    // but adjust datetime qty based on datetime reg limit
1206
-                    $datetime_qty = min(EE_INF, $datetime->reg_limit());
1207
-                    // echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />';
1208
-                    // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
1209
-                    // if we want the actual saleable amount, then we need to consider OTHER ticket sales
1210
-                    // and reservations for this datetime, that do NOT include sales and reservations
1211
-                    // for this ticket (so we add $this->sold() and $this->reserved() back in)
1212
-                    if ($context === 'saleable') {
1213
-                        $datetime_qty = max(
1214
-                            $datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket,
1215
-                            0
1216
-                        );
1217
-                        // echo "\n . . . datetime sold: " . $datetime->sold() . '<br />';
1218
-                        // echo "\n . . . datetime reserved: " . $datetime->reserved() . '<br />';
1219
-                        // echo "\n . . . datetime sold_and_reserved: " . $datetime->sold_and_reserved() . '<br />';
1220
-                        // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
1221
-                        $datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0;
1222
-                        // echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
1223
-                    }
1224
-                    $qty = min($datetime_qty, $qty);
1225
-                    // echo "\n . . qty: " . $qty . '<br />';
1226
-                }
1227
-            }
1228
-        }
1229
-        // NOW that we know the  maximum number of tickets available for the datetime
1230
-        // we can finally factor in the details for this specific ticket
1231
-        if ($qty > 0 && $context === 'saleable') {
1232
-            // and subtract the sales for THIS ticket
1233
-            $qty = max($qty - $sold_and_reserved_for_this_ticket, 0);
1234
-            // echo "\n . qty: " . $qty . '<br />';
1235
-        }
1236
-        // echo "\nFINAL QTY: " . $qty . "<br /><br />";
1237
-        return $qty;
1238
-    }
1239
-
1240
-
1241
-    /**
1242
-     * Sets qty - IMPORTANT!!! Does NOT allow QTY to be set higher than the lowest reg limit of any related datetimes
1243
-     *
1244
-     * @param int $qty
1245
-     * @return void
1246
-     * @throws EE_Error
1247
-     * @throws ReflectionException
1248
-     */
1249
-    public function set_qty($qty)
1250
-    {
1251
-        $datetimes = $this->datetimes();
1252
-        foreach ($datetimes as $datetime) {
1253
-            if ($datetime instanceof EE_Datetime) {
1254
-                $qty = min($qty, $datetime->reg_limit());
1255
-            }
1256
-        }
1257
-        $this->set('TKT_qty', $qty);
1258
-    }
1259
-
1260
-
1261
-    /**
1262
-     * Gets uses
1263
-     *
1264
-     * @return int
1265
-     * @throws EE_Error
1266
-     * @throws ReflectionException
1267
-     */
1268
-    public function uses()
1269
-    {
1270
-        return $this->get('TKT_uses');
1271
-    }
1272
-
1273
-
1274
-    /**
1275
-     * Sets uses
1276
-     *
1277
-     * @param int $uses
1278
-     * @return void
1279
-     * @throws EE_Error
1280
-     * @throws ReflectionException
1281
-     */
1282
-    public function set_uses($uses)
1283
-    {
1284
-        $this->set('TKT_uses', $uses);
1285
-    }
1286
-
1287
-
1288
-    /**
1289
-     * returns whether ticket is required or not.
1290
-     *
1291
-     * @return boolean
1292
-     * @throws EE_Error
1293
-     * @throws ReflectionException
1294
-     */
1295
-    public function required()
1296
-    {
1297
-        return $this->get('TKT_required');
1298
-    }
1299
-
1300
-
1301
-    /**
1302
-     * sets the TKT_required property
1303
-     *
1304
-     * @param boolean $required
1305
-     * @return void
1306
-     * @throws EE_Error
1307
-     * @throws ReflectionException
1308
-     */
1309
-    public function set_required($required)
1310
-    {
1311
-        $this->set('TKT_required', $required);
1312
-    }
1313
-
1314
-
1315
-    /**
1316
-     * Gets taxable
1317
-     *
1318
-     * @return boolean
1319
-     * @throws EE_Error
1320
-     * @throws ReflectionException
1321
-     */
1322
-    public function taxable()
1323
-    {
1324
-        return $this->get('TKT_taxable');
1325
-    }
1326
-
1327
-
1328
-    /**
1329
-     * Sets taxable
1330
-     *
1331
-     * @param boolean $taxable
1332
-     * @return void
1333
-     * @throws EE_Error
1334
-     * @throws ReflectionException
1335
-     */
1336
-    public function set_taxable($taxable)
1337
-    {
1338
-        $this->set('TKT_taxable', $taxable);
1339
-    }
1340
-
1341
-
1342
-    /**
1343
-     * Gets is_default
1344
-     *
1345
-     * @return boolean
1346
-     * @throws EE_Error
1347
-     * @throws ReflectionException
1348
-     */
1349
-    public function is_default()
1350
-    {
1351
-        return $this->get('TKT_is_default');
1352
-    }
1353
-
1354
-
1355
-    /**
1356
-     * Sets is_default
1357
-     *
1358
-     * @param boolean $is_default
1359
-     * @return void
1360
-     * @throws EE_Error
1361
-     * @throws ReflectionException
1362
-     */
1363
-    public function set_is_default($is_default)
1364
-    {
1365
-        $this->set('TKT_is_default', $is_default);
1366
-    }
1367
-
1368
-
1369
-    /**
1370
-     * Gets order
1371
-     *
1372
-     * @return int
1373
-     * @throws EE_Error
1374
-     * @throws ReflectionException
1375
-     */
1376
-    public function order()
1377
-    {
1378
-        return $this->get('TKT_order');
1379
-    }
1380
-
1381
-
1382
-    /**
1383
-     * Sets order
1384
-     *
1385
-     * @param int $order
1386
-     * @return void
1387
-     * @throws EE_Error
1388
-     * @throws ReflectionException
1389
-     */
1390
-    public function set_order($order)
1391
-    {
1392
-        $this->set('TKT_order', $order);
1393
-    }
1394
-
1395
-
1396
-    /**
1397
-     * Gets row
1398
-     *
1399
-     * @return int
1400
-     * @throws EE_Error
1401
-     * @throws ReflectionException
1402
-     */
1403
-    public function row()
1404
-    {
1405
-        return $this->get('TKT_row');
1406
-    }
1407
-
1408
-
1409
-    /**
1410
-     * Sets row
1411
-     *
1412
-     * @param int $row
1413
-     * @return void
1414
-     * @throws EE_Error
1415
-     * @throws ReflectionException
1416
-     */
1417
-    public function set_row($row)
1418
-    {
1419
-        $this->set('TKT_row', $row);
1420
-    }
1421
-
1422
-
1423
-    /**
1424
-     * Gets deleted
1425
-     *
1426
-     * @return boolean
1427
-     * @throws EE_Error
1428
-     * @throws ReflectionException
1429
-     */
1430
-    public function deleted()
1431
-    {
1432
-        return $this->get('TKT_deleted');
1433
-    }
1434
-
1435
-
1436
-    /**
1437
-     * Sets deleted
1438
-     *
1439
-     * @param boolean $deleted
1440
-     * @return void
1441
-     * @throws EE_Error
1442
-     * @throws ReflectionException
1443
-     */
1444
-    public function set_deleted($deleted)
1445
-    {
1446
-        $this->set('TKT_deleted', $deleted);
1447
-    }
1448
-
1449
-
1450
-    /**
1451
-     * Gets parent
1452
-     *
1453
-     * @return int
1454
-     * @throws EE_Error
1455
-     * @throws ReflectionException
1456
-     */
1457
-    public function parent_ID()
1458
-    {
1459
-        return $this->get('TKT_parent');
1460
-    }
1461
-
1462
-
1463
-    /**
1464
-     * Sets parent
1465
-     *
1466
-     * @param int $parent
1467
-     * @return void
1468
-     * @throws EE_Error
1469
-     * @throws ReflectionException
1470
-     */
1471
-    public function set_parent_ID($parent)
1472
-    {
1473
-        $this->set('TKT_parent', $parent);
1474
-    }
1475
-
1476
-
1477
-    /**
1478
-     * @return boolean
1479
-     * @throws EE_Error
1480
-     * @throws InvalidArgumentException
1481
-     * @throws InvalidDataTypeException
1482
-     * @throws InvalidInterfaceException
1483
-     * @throws ReflectionException
1484
-     */
1485
-    public function reverse_calculate()
1486
-    {
1487
-        return $this->get('TKT_reverse_calculate');
1488
-    }
1489
-
1490
-
1491
-    /**
1492
-     * @param boolean $reverse_calculate
1493
-     * @throws EE_Error
1494
-     * @throws InvalidArgumentException
1495
-     * @throws InvalidDataTypeException
1496
-     * @throws InvalidInterfaceException
1497
-     * @throws ReflectionException
1498
-     */
1499
-    public function set_reverse_calculate($reverse_calculate)
1500
-    {
1501
-        $this->set('TKT_reverse_calculate', $reverse_calculate);
1502
-    }
1503
-
1504
-
1505
-    /**
1506
-     * Gets a string which is handy for showing in gateways etc that describes the ticket.
1507
-     *
1508
-     * @return string
1509
-     * @throws EE_Error
1510
-     * @throws ReflectionException
1511
-     */
1512
-    public function name_and_info()
1513
-    {
1514
-        $times = [];
1515
-        foreach ($this->datetimes() as $datetime) {
1516
-            $times[] = $datetime->start_date_and_time();
1517
-        }
1518
-        return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price();
1519
-    }
1520
-
1521
-
1522
-    /**
1523
-     * Gets name
1524
-     *
1525
-     * @return string
1526
-     * @throws EE_Error
1527
-     * @throws ReflectionException
1528
-     */
1529
-    public function name()
1530
-    {
1531
-        return $this->get('TKT_name');
1532
-    }
1533
-
1534
-
1535
-    /**
1536
-     * Gets price
1537
-     *
1538
-     * @return float
1539
-     * @throws EE_Error
1540
-     * @throws ReflectionException
1541
-     */
1542
-    public function price()
1543
-    {
1544
-        return $this->get('TKT_price');
1545
-    }
1546
-
1547
-
1548
-    /**
1549
-     * Gets all the registrations for this ticket
1550
-     *
1551
-     * @param array $query_params @see
1552
-     *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1553
-     * @return EE_Registration[]|EE_Base_Class[]
1554
-     * @throws EE_Error
1555
-     * @throws ReflectionException
1556
-     */
1557
-    public function registrations($query_params = [])
1558
-    {
1559
-        return $this->get_many_related('Registration', $query_params);
1560
-    }
1561
-
1562
-
1563
-    /**
1564
-     * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket.
1565
-     *
1566
-     * @return int
1567
-     * @throws EE_Error
1568
-     * @throws ReflectionException
1569
-     */
1570
-    public function update_tickets_sold()
1571
-    {
1572
-        $count_regs_for_this_ticket = $this->count_registrations(
1573
-            [
1574
-                [
1575
-                    'STS_ID'      => EEM_Registration::status_id_approved,
1576
-                    'REG_deleted' => 0,
1577
-                ],
1578
-            ]
1579
-        );
1580
-        $this->set_sold($count_regs_for_this_ticket);
1581
-        $this->save();
1582
-        return $count_regs_for_this_ticket;
1583
-    }
1584
-
1585
-
1586
-    /**
1587
-     * Counts the registrations for this ticket
1588
-     *
1589
-     * @param array $query_params @see
1590
-     *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1591
-     * @return int
1592
-     * @throws EE_Error
1593
-     * @throws ReflectionException
1594
-     */
1595
-    public function count_registrations($query_params = [])
1596
-    {
1597
-        return $this->count_related('Registration', $query_params);
1598
-    }
1599
-
1600
-
1601
-    /**
1602
-     * Implementation for EEI_Has_Icon interface method.
1603
-     *
1604
-     * @return string
1605
-     * @see EEI_Visual_Representation for comments
1606
-     */
1607
-    public function get_icon()
1608
-    {
1609
-        return '<span class="dashicons dashicons-tickets-alt"/>';
1610
-    }
1611
-
1612
-
1613
-    /**
1614
-     * Implementation of the EEI_Event_Relation interface method
1615
-     *
1616
-     * @return EE_Event
1617
-     * @throws EE_Error
1618
-     * @throws UnexpectedEntityException
1619
-     * @throws ReflectionException
1620
-     * @see EEI_Event_Relation for comments
1621
-     */
1622
-    public function get_related_event()
1623
-    {
1624
-        // get one datetime to use for getting the event
1625
-        $datetime = $this->first_datetime();
1626
-        if (! $datetime instanceof EE_Datetime) {
1627
-            throw new UnexpectedEntityException(
1628
-                $datetime,
1629
-                'EE_Datetime',
1630
-                sprintf(
1631
-                    __('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'),
1632
-                    $this->name()
1633
-                )
1634
-            );
1635
-        }
1636
-        $event = $datetime->event();
1637
-        if (! $event instanceof EE_Event) {
1638
-            throw new UnexpectedEntityException(
1639
-                $event,
1640
-                'EE_Event',
1641
-                sprintf(
1642
-                    __('The ticket (%s) is not associated with a valid event.', 'event_espresso'),
1643
-                    $this->name()
1644
-                )
1645
-            );
1646
-        }
1647
-        return $event;
1648
-    }
1649
-
1650
-
1651
-    /**
1652
-     * Implementation of the EEI_Event_Relation interface method
1653
-     *
1654
-     * @return string
1655
-     * @throws UnexpectedEntityException
1656
-     * @throws EE_Error
1657
-     * @throws ReflectionException
1658
-     * @see EEI_Event_Relation for comments
1659
-     */
1660
-    public function get_event_name()
1661
-    {
1662
-        $event = $this->get_related_event();
1663
-        return $event instanceof EE_Event ? $event->name() : '';
1664
-    }
1665
-
1666
-
1667
-    /**
1668
-     * Implementation of the EEI_Event_Relation interface method
1669
-     *
1670
-     * @return int
1671
-     * @throws UnexpectedEntityException
1672
-     * @throws EE_Error
1673
-     * @throws ReflectionException
1674
-     * @see EEI_Event_Relation for comments
1675
-     */
1676
-    public function get_event_ID()
1677
-    {
1678
-        $event = $this->get_related_event();
1679
-        return $event instanceof EE_Event ? $event->ID() : 0;
1680
-    }
1681
-
1682
-
1683
-    /**
1684
-     * This simply returns whether a ticket can be permanently deleted or not.
1685
-     * The criteria for determining this is whether the ticket has any related registrations.
1686
-     * If there are none then it can be permanently deleted.
1687
-     *
1688
-     * @return bool
1689
-     * @throws EE_Error
1690
-     * @throws ReflectionException
1691
-     */
1692
-    public function is_permanently_deleteable()
1693
-    {
1694
-        return $this->count_registrations() === 0;
1695
-    }
1696
-
1697
-
1698
-    /**
1699
-     * @return int
1700
-     * @throws EE_Error
1701
-     * @throws ReflectionException
1702
-     * @since   $VID:$
1703
-     */
1704
-    public function visibility(): int
1705
-    {
1706
-        return $this->get('TKT_visibility');
1707
-    }
1708
-
1709
-
1710
-    /**
1711
-     * @return int
1712
-     * @throws EE_Error
1713
-     * @throws ReflectionException
1714
-     * @since   $VID:$
1715
-     */
1716
-    public function isHidden(): int
1717
-    {
1718
-        return $this->visibility() === EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE;
1719
-    }
1720
-
1721
-
1722
-    /**
1723
-     * @return int
1724
-     * @throws EE_Error
1725
-     * @throws ReflectionException
1726
-     * @since   $VID:$
1727
-     */
1728
-    public function isNotHidden(): int
1729
-    {
1730
-        return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE;
1731
-    }
1732
-
1733
-
1734
-    /**
1735
-     * @return int
1736
-     * @throws EE_Error
1737
-     * @throws ReflectionException
1738
-     * @since   $VID:$
1739
-     */
1740
-    public function isPublicOnly(): int
1741
-    {
1742
-        return $this->isNotHidden() && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE;
1743
-    }
1744
-
1745
-
1746
-    /**
1747
-     * @return int
1748
-     * @throws EE_Error
1749
-     * @throws ReflectionException
1750
-     * @since   $VID:$
1751
-     */
1752
-    public function isMembersOnly(): int
1753
-    {
1754
-        return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE
1755
-               && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_VALUE;
1756
-    }
1757
-
1758
-
1759
-    /**
1760
-     * @return int
1761
-     * @throws EE_Error
1762
-     * @throws ReflectionException
1763
-     * @since   $VID:$
1764
-     */
1765
-    public function isAdminsOnly(): int
1766
-    {
1767
-        return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_VALUE
1768
-               && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_VALUE;
1769
-    }
1770
-
1771
-
1772
-    /**
1773
-     * @return int
1774
-     * @throws EE_Error
1775
-     * @throws ReflectionException
1776
-     * @since   $VID:$
1777
-     */
1778
-    public function isAdminUiOnly(): int
1779
-    {
1780
-        return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_VALUE
1781
-               && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_ADMIN_UI_ONLY_VALUE;
1782
-    }
1783
-
1784
-
1785
-    /**
1786
-     * @param int $visibility
1787
-     * @throws EE_Error
1788
-     * @throws ReflectionException
1789
-     * @since   $VID:$
1790
-     */
1791
-    public function set_visibility(int $visibility)
1792
-    {
1793
-
1794
-        $ticket_visibility_options = $this->_model->ticketVisibilityOptions();
1795
-        $ticket_visibility         = -1;
1796
-        foreach ($ticket_visibility_options as $ticket_visibility_option) {
1797
-            if ($visibility === $ticket_visibility_option) {
1798
-                $ticket_visibility = $visibility;
1799
-            }
1800
-        }
1801
-        if ($ticket_visibility === -1) {
1802
-            throw new DomainException(
1803
-                sprintf(
1804
-                    esc_html__(
1805
-                        'The supplied ticket visibility setting of "%1$s" is not valid. It needs to match one of the keys in the following array:%2$s %3$s ',
1806
-                        'event_espresso'
1807
-                    ),
1808
-                    $visibility,
1809
-                    '<br />',
1810
-                    var_export($ticket_visibility_options, true)
1811
-                )
1812
-            );
1813
-        }
1814
-        $this->set('TKT_visibility', $ticket_visibility);
1815
-    }
1816
-
1817
-
1818
-    /*******************************************************************
17
+	/**
18
+	 * TicKet Sold out:
19
+	 * constant used by ticket_status() to indicate that a ticket is sold out
20
+	 * and no longer available for purchases
21
+	 */
22
+	const sold_out = 'TKS';
23
+
24
+	/**
25
+	 * TicKet Expired:
26
+	 * constant used by ticket_status() to indicate that a ticket is expired
27
+	 * and no longer available for purchase
28
+	 */
29
+	const expired = 'TKE';
30
+
31
+	/**
32
+	 * TicKet Archived:
33
+	 * constant used by ticket_status() to indicate that a ticket is archived
34
+	 * and no longer available for purchase
35
+	 */
36
+	const archived = 'TKA';
37
+
38
+	/**
39
+	 * TicKet Pending:
40
+	 * constant used by ticket_status() to indicate that a ticket is pending
41
+	 * and is NOT YET available for purchase
42
+	 */
43
+	const pending = 'TKP';
44
+
45
+	/**
46
+	 * TicKet On sale:
47
+	 * constant used by ticket_status() to indicate that a ticket is On Sale
48
+	 * and IS available for purchase
49
+	 */
50
+	const onsale = 'TKO';
51
+
52
+	/**
53
+	 * extra meta key for tracking ticket reservations
54
+	 *
55
+	 * @type string
56
+	 */
57
+	const META_KEY_TICKET_RESERVATIONS = 'ticket_reservations';
58
+
59
+	/**
60
+	 * override of parent property
61
+	 *
62
+	 * @var EEM_Ticket
63
+	 */
64
+	protected $_model;
65
+
66
+	/**
67
+	 * cached result from method of the same name
68
+	 *
69
+	 * @var float $_ticket_total_with_taxes
70
+	 */
71
+	private $_ticket_total_with_taxes;
72
+
73
+
74
+	/**
75
+	 * @param array  $props_n_values          incoming values
76
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
77
+	 *                                        used.)
78
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
79
+	 *                                        date_format and the second value is the time format
80
+	 * @return EE_Ticket
81
+	 * @throws EE_Error
82
+	 * @throws ReflectionException
83
+	 */
84
+	public static function new_instance($props_n_values = [], $timezone = null, $date_formats = [])
85
+	{
86
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
87
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
88
+	}
89
+
90
+
91
+	/**
92
+	 * @param array  $props_n_values  incoming values from the database
93
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
94
+	 *                                the website will be used.
95
+	 * @return EE_Ticket
96
+	 * @throws EE_Error
97
+	 * @throws ReflectionException
98
+	 */
99
+	public static function new_instance_from_db($props_n_values = [], $timezone = null)
100
+	{
101
+		return new self($props_n_values, true, $timezone);
102
+	}
103
+
104
+
105
+	/**
106
+	 * @return bool
107
+	 * @throws EE_Error
108
+	 * @throws ReflectionException
109
+	 */
110
+	public function parent()
111
+	{
112
+		return $this->get('TKT_parent');
113
+	}
114
+
115
+
116
+	/**
117
+	 * return if a ticket has quantities available for purchase
118
+	 *
119
+	 * @param int $DTT_ID the primary key for a particular datetime
120
+	 * @return boolean
121
+	 * @throws EE_Error
122
+	 * @throws ReflectionException
123
+	 */
124
+	public function available($DTT_ID = 0)
125
+	{
126
+		// are we checking availability for a particular datetime ?
127
+		if ($DTT_ID) {
128
+			// get that datetime object
129
+			$datetime = $this->get_first_related('Datetime', [['DTT_ID' => $DTT_ID]]);
130
+			// if  ticket sales for this datetime have exceeded the reg limit...
131
+			if ($datetime instanceof EE_Datetime && $datetime->sold_out()) {
132
+				return false;
133
+			}
134
+		}
135
+		// datetime is still open for registration, but is this ticket sold out ?
136
+		return $this->qty() < 1 || $this->qty() > $this->sold();
137
+	}
138
+
139
+
140
+	/**
141
+	 * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired
142
+	 *
143
+	 * @param bool        $display   true = we'll return a localized string, otherwise we just return the value of the
144
+	 *                               relevant status const
145
+	 * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save
146
+	 *                               further processing
147
+	 * @return mixed status int if the display string isn't requested
148
+	 * @throws EE_Error
149
+	 * @throws ReflectionException
150
+	 */
151
+	public function ticket_status($display = false, $remaining = null)
152
+	{
153
+		$remaining = is_bool($remaining) ? $remaining : $this->is_remaining();
154
+		if (! $remaining) {
155
+			return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, false, 'sentence') : EE_Ticket::sold_out;
156
+		}
157
+		if ($this->get('TKT_deleted')) {
158
+			return $display ? EEH_Template::pretty_status(EE_Ticket::archived, false, 'sentence') : EE_Ticket::archived;
159
+		}
160
+		if ($this->is_expired()) {
161
+			return $display ? EEH_Template::pretty_status(EE_Ticket::expired, false, 'sentence') : EE_Ticket::expired;
162
+		}
163
+		if ($this->is_pending()) {
164
+			return $display ? EEH_Template::pretty_status(EE_Ticket::pending, false, 'sentence') : EE_Ticket::pending;
165
+		}
166
+		if ($this->is_on_sale()) {
167
+			return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence') : EE_Ticket::onsale;
168
+		}
169
+		return '';
170
+	}
171
+
172
+
173
+	/**
174
+	 * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale
175
+	 * considering ALL the factors used for figuring that out.
176
+	 *
177
+	 * @access public
178
+	 * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt.
179
+	 * @return boolean         true = tickets remaining, false not.
180
+	 * @throws EE_Error
181
+	 * @throws ReflectionException
182
+	 */
183
+	public function is_remaining($DTT_ID = 0)
184
+	{
185
+		$num_remaining = $this->remaining($DTT_ID);
186
+		if ($num_remaining === 0) {
187
+			return false;
188
+		}
189
+		if ($num_remaining > 0 && $num_remaining < $this->min()) {
190
+			return false;
191
+		}
192
+		return true;
193
+	}
194
+
195
+
196
+	/**
197
+	 * return the total number of tickets available for purchase
198
+	 *
199
+	 * @param int $DTT_ID  the primary key for a particular datetime.
200
+	 *                     set to 0 for all related datetimes
201
+	 * @return int
202
+	 * @throws EE_Error
203
+	 * @throws ReflectionException
204
+	 */
205
+	public function remaining($DTT_ID = 0)
206
+	{
207
+		return $this->real_quantity_on_ticket('saleable', $DTT_ID);
208
+	}
209
+
210
+
211
+	/**
212
+	 * Gets min
213
+	 *
214
+	 * @return int
215
+	 * @throws EE_Error
216
+	 * @throws ReflectionException
217
+	 */
218
+	public function min()
219
+	{
220
+		return $this->get('TKT_min');
221
+	}
222
+
223
+
224
+	/**
225
+	 * return if a ticket is no longer available cause its available dates have expired.
226
+	 *
227
+	 * @return boolean
228
+	 * @throws EE_Error
229
+	 * @throws ReflectionException
230
+	 */
231
+	public function is_expired()
232
+	{
233
+		return ($this->get_raw('TKT_end_date') < time());
234
+	}
235
+
236
+
237
+	/**
238
+	 * Return if a ticket is yet to go on sale or not
239
+	 *
240
+	 * @return boolean
241
+	 * @throws EE_Error
242
+	 * @throws ReflectionException
243
+	 */
244
+	public function is_pending()
245
+	{
246
+		return ($this->get_raw('TKT_start_date') >= time());
247
+	}
248
+
249
+
250
+	/**
251
+	 * Return if a ticket is on sale or not
252
+	 *
253
+	 * @return boolean
254
+	 * @throws EE_Error
255
+	 * @throws ReflectionException
256
+	 */
257
+	public function is_on_sale()
258
+	{
259
+		return ($this->get_raw('TKT_start_date') <= time() && $this->get_raw('TKT_end_date') >= time());
260
+	}
261
+
262
+
263
+	/**
264
+	 * This returns the chronologically last datetime that this ticket is associated with
265
+	 *
266
+	 * @param string $date_format
267
+	 * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with
268
+	 *                            the end date ie: Jan 01 "to" Dec 31
269
+	 * @return string
270
+	 * @throws EE_Error
271
+	 * @throws ReflectionException
272
+	 */
273
+	public function date_range($date_format = '', $conjunction = ' - ')
274
+	{
275
+		$date_format = ! empty($date_format) ? $date_format : $this->_dt_frmt;
276
+		$first_date  = $this->first_datetime() instanceof EE_Datetime
277
+			? $this->first_datetime()->get_i18n_datetime('DTT_EVT_start', $date_format)
278
+			: '';
279
+		$last_date   = $this->last_datetime() instanceof EE_Datetime
280
+			? $this->last_datetime()->get_i18n_datetime('DTT_EVT_end', $date_format)
281
+			: '';
282
+
283
+		return $first_date && $last_date ? $first_date . $conjunction . $last_date : '';
284
+	}
285
+
286
+
287
+	/**
288
+	 * This returns the chronologically first datetime that this ticket is associated with
289
+	 *
290
+	 * @return EE_Datetime
291
+	 * @throws EE_Error
292
+	 * @throws ReflectionException
293
+	 */
294
+	public function first_datetime()
295
+	{
296
+		$datetimes = $this->datetimes(['limit' => 1]);
297
+		return reset($datetimes);
298
+	}
299
+
300
+
301
+	/**
302
+	 * Gets all the datetimes this ticket can be used for attending.
303
+	 * Unless otherwise specified, orders datetimes by start date.
304
+	 *
305
+	 * @param array $query_params @see
306
+	 *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
307
+	 * @return EE_Datetime[]|EE_Base_Class[]
308
+	 * @throws EE_Error
309
+	 * @throws ReflectionException
310
+	 */
311
+	public function datetimes($query_params = [])
312
+	{
313
+		if (! isset($query_params['order_by'])) {
314
+			$query_params['order_by']['DTT_order'] = 'ASC';
315
+		}
316
+		return $this->get_many_related('Datetime', $query_params);
317
+	}
318
+
319
+
320
+	/**
321
+	 * This returns the chronologically last datetime that this ticket is associated with
322
+	 *
323
+	 * @return EE_Datetime
324
+	 * @throws EE_Error
325
+	 * @throws ReflectionException
326
+	 */
327
+	public function last_datetime()
328
+	{
329
+		$datetimes = $this->datetimes(['limit' => 1, 'order_by' => ['DTT_EVT_start' => 'DESC']]);
330
+		return end($datetimes);
331
+	}
332
+
333
+
334
+	/**
335
+	 * This returns the total tickets sold depending on the given parameters.
336
+	 *
337
+	 * @param string $what    Can be one of two options: 'ticket', 'datetime'.
338
+	 *                        'ticket' = total ticket sales for all datetimes this ticket is related to
339
+	 *                        'datetime' = total ticket sales for a specified datetime (required $dtt_id)
340
+	 *                        'datetime' = total ticket sales in the datetime_ticket table.
341
+	 *                        If $dtt_id is not given then we return an array of sales indexed by datetime.
342
+	 *                        If $dtt_id IS given then we return the tickets sold for that given datetime.
343
+	 * @param int    $dtt_id  [optional] include the dtt_id with $what = 'datetime'.
344
+	 * @return mixed (array|int)          how many tickets have sold
345
+	 * @throws EE_Error
346
+	 * @throws ReflectionException
347
+	 */
348
+	public function tickets_sold($what = 'ticket', $dtt_id = null)
349
+	{
350
+		$total        = 0;
351
+		$tickets_sold = $this->_all_tickets_sold();
352
+		switch ($what) {
353
+			case 'ticket':
354
+				return $tickets_sold['ticket'];
355
+				break;
356
+			case 'datetime':
357
+				if (empty($tickets_sold['datetime'])) {
358
+					return $total;
359
+				}
360
+				if (! empty($dtt_id) && ! isset($tickets_sold['datetime'][ $dtt_id ])) {
361
+					EE_Error::add_error(
362
+						__(
363
+							'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included.  Are you SURE that is a datetime related to this ticket?',
364
+							'event_espresso'
365
+						),
366
+						__FILE__,
367
+						__FUNCTION__,
368
+						__LINE__
369
+					);
370
+					return $total;
371
+				}
372
+				return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][ $dtt_id ];
373
+				break;
374
+			default:
375
+				return $total;
376
+		}
377
+	}
378
+
379
+
380
+	/**
381
+	 * This returns an array indexed by datetime_id for tickets sold with this ticket.
382
+	 *
383
+	 * @return EE_Ticket[]
384
+	 * @throws EE_Error
385
+	 * @throws ReflectionException
386
+	 */
387
+	protected function _all_tickets_sold()
388
+	{
389
+		$datetimes    = $this->get_many_related('Datetime');
390
+		$tickets_sold = [];
391
+		if (! empty($datetimes)) {
392
+			foreach ($datetimes as $datetime) {
393
+				$tickets_sold['datetime'][ $datetime->ID() ] = $datetime->get('DTT_sold');
394
+			}
395
+		}
396
+		// Tickets sold
397
+		$tickets_sold['ticket'] = $this->sold();
398
+		return $tickets_sold;
399
+	}
400
+
401
+
402
+	/**
403
+	 * This returns the base price object for the ticket.
404
+	 *
405
+	 * @param bool $return_array whether to return as an array indexed by price id or just the object.
406
+	 * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[]
407
+	 * @throws EE_Error
408
+	 * @throws ReflectionException
409
+	 */
410
+	public function base_price($return_array = false)
411
+	{
412
+		$_where = ['Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price];
413
+		return $return_array
414
+			? $this->get_many_related('Price', [$_where])
415
+			: $this->get_first_related('Price', [$_where]);
416
+	}
417
+
418
+
419
+	/**
420
+	 * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price)
421
+	 *
422
+	 * @access public
423
+	 * @return EE_Price[]
424
+	 * @throws EE_Error
425
+	 * @throws ReflectionException
426
+	 */
427
+	public function price_modifiers()
428
+	{
429
+		$query_params = [
430
+			0 => [
431
+				'Price_Type.PBT_ID' => [
432
+					'NOT IN',
433
+					[EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax],
434
+				],
435
+			],
436
+		];
437
+		return $this->prices($query_params);
438
+	}
439
+
440
+
441
+	/**
442
+	 * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price)
443
+	 *
444
+	 * @access public
445
+	 * @return EE_Price[]
446
+	 * @throws EE_Error
447
+	 * @throws ReflectionException
448
+	 */
449
+	public function tax_price_modifiers()
450
+	{
451
+		$query_params = [
452
+			0 => [
453
+				'Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax,
454
+			],
455
+		];
456
+		return $this->prices($query_params);
457
+	}
458
+
459
+
460
+	/**
461
+	 * Gets all the prices that combine to form the final price of this ticket
462
+	 *
463
+	 * @param array $query_params @see
464
+	 *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
465
+	 * @return EE_Price[]|EE_Base_Class[]
466
+	 * @throws EE_Error
467
+	 * @throws ReflectionException
468
+	 */
469
+	public function prices($query_params = [])
470
+	{
471
+		return $this->get_many_related('Price', $query_params);
472
+	}
473
+
474
+
475
+	/**
476
+	 * Gets all the ticket datetimes (ie, relations between datetimes and tickets)
477
+	 *
478
+	 * @param array $query_params @see
479
+	 *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
480
+	 * @return EE_Datetime_Ticket|EE_Base_Class[]
481
+	 * @throws EE_Error
482
+	 * @throws ReflectionException
483
+	 */
484
+	public function datetime_tickets($query_params = [])
485
+	{
486
+		return $this->get_many_related('Datetime_Ticket', $query_params);
487
+	}
488
+
489
+
490
+	/**
491
+	 * Gets all the datetimes from the db ordered by DTT_order
492
+	 *
493
+	 * @param boolean $show_expired
494
+	 * @param boolean $show_deleted
495
+	 * @return EE_Datetime[]
496
+	 * @throws EE_Error
497
+	 * @throws ReflectionException
498
+	 */
499
+	public function datetimes_ordered($show_expired = true, $show_deleted = false)
500
+	{
501
+		return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order(
502
+			$this->ID(),
503
+			$show_expired,
504
+			$show_deleted
505
+		);
506
+	}
507
+
508
+
509
+	/**
510
+	 * Gets ID
511
+	 *
512
+	 * @return int
513
+	 * @throws EE_Error
514
+	 * @throws ReflectionException
515
+	 */
516
+	public function ID()
517
+	{
518
+		return $this->get('TKT_ID');
519
+	}
520
+
521
+
522
+	/**
523
+	 * get the author of the ticket.
524
+	 *
525
+	 * @return int
526
+	 * @throws EE_Error
527
+	 * @throws ReflectionException
528
+	 * @since 4.5.0
529
+	 */
530
+	public function wp_user()
531
+	{
532
+		return $this->get('TKT_wp_user');
533
+	}
534
+
535
+
536
+	/**
537
+	 * Gets the template for the ticket
538
+	 *
539
+	 * @return EE_Ticket_Template|EE_Base_Class
540
+	 * @throws EE_Error
541
+	 * @throws ReflectionException
542
+	 */
543
+	public function template()
544
+	{
545
+		return $this->get_first_related('Ticket_Template');
546
+	}
547
+
548
+
549
+	/**
550
+	 * Simply returns an array of EE_Price objects that are taxes.
551
+	 *
552
+	 * @return EE_Price[]
553
+	 * @throws EE_Error
554
+	 */
555
+	public function get_ticket_taxes_for_admin()
556
+	{
557
+		return EE_Taxes::get_taxes_for_admin();
558
+	}
559
+
560
+
561
+	/**
562
+	 * @return float
563
+	 * @throws EE_Error
564
+	 * @throws ReflectionException
565
+	 */
566
+	public function ticket_price()
567
+	{
568
+		return $this->get('TKT_price');
569
+	}
570
+
571
+
572
+	/**
573
+	 * @return mixed
574
+	 * @throws EE_Error
575
+	 * @throws ReflectionException
576
+	 */
577
+	public function pretty_price()
578
+	{
579
+		return $this->get_pretty('TKT_price');
580
+	}
581
+
582
+
583
+	/**
584
+	 * @return bool
585
+	 * @throws EE_Error
586
+	 * @throws ReflectionException
587
+	 */
588
+	public function is_free()
589
+	{
590
+		return $this->get_ticket_total_with_taxes() === (float) 0;
591
+	}
592
+
593
+
594
+	/**
595
+	 * get_ticket_total_with_taxes
596
+	 *
597
+	 * @param bool $no_cache
598
+	 * @return float
599
+	 * @throws EE_Error
600
+	 * @throws ReflectionException
601
+	 */
602
+	public function get_ticket_total_with_taxes($no_cache = false)
603
+	{
604
+		if ($this->_ticket_total_with_taxes === null || $no_cache) {
605
+			$this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin();
606
+		}
607
+		return (float) $this->_ticket_total_with_taxes;
608
+	}
609
+
610
+
611
+	/**
612
+	 * @throws EE_Error
613
+	 * @throws ReflectionException
614
+	 */
615
+	public function ensure_TKT_Price_correct()
616
+	{
617
+		$this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this));
618
+		$this->save();
619
+	}
620
+
621
+
622
+	/**
623
+	 * @return float
624
+	 * @throws EE_Error
625
+	 * @throws ReflectionException
626
+	 */
627
+	public function get_ticket_subtotal()
628
+	{
629
+		return EE_Taxes::get_subtotal_for_admin($this);
630
+	}
631
+
632
+
633
+	/**
634
+	 * Returns the total taxes applied to this ticket
635
+	 *
636
+	 * @return float
637
+	 * @throws EE_Error
638
+	 * @throws ReflectionException
639
+	 */
640
+	public function get_ticket_taxes_total_for_admin()
641
+	{
642
+		return EE_Taxes::get_total_taxes_for_admin($this);
643
+	}
644
+
645
+
646
+	/**
647
+	 * Sets name
648
+	 *
649
+	 * @param string $name
650
+	 * @throws EE_Error
651
+	 * @throws ReflectionException
652
+	 */
653
+	public function set_name($name)
654
+	{
655
+		$this->set('TKT_name', $name);
656
+	}
657
+
658
+
659
+	/**
660
+	 * Gets description
661
+	 *
662
+	 * @return string
663
+	 * @throws EE_Error
664
+	 * @throws ReflectionException
665
+	 */
666
+	public function description()
667
+	{
668
+		return $this->get('TKT_description');
669
+	}
670
+
671
+
672
+	/**
673
+	 * Sets description
674
+	 *
675
+	 * @param string $description
676
+	 * @throws EE_Error
677
+	 * @throws ReflectionException
678
+	 */
679
+	public function set_description($description)
680
+	{
681
+		$this->set('TKT_description', $description);
682
+	}
683
+
684
+
685
+	/**
686
+	 * Gets start_date
687
+	 *
688
+	 * @param string $date_format
689
+	 * @param string $time_format
690
+	 * @return string
691
+	 * @throws EE_Error
692
+	 * @throws ReflectionException
693
+	 */
694
+	public function start_date($date_format = '', $time_format = '')
695
+	{
696
+		return $this->_get_datetime('TKT_start_date', $date_format, $time_format);
697
+	}
698
+
699
+
700
+	/**
701
+	 * Sets start_date
702
+	 *
703
+	 * @param string $start_date
704
+	 * @return void
705
+	 * @throws EE_Error
706
+	 * @throws ReflectionException
707
+	 */
708
+	public function set_start_date($start_date)
709
+	{
710
+		$this->_set_date_time('B', $start_date, 'TKT_start_date');
711
+	}
712
+
713
+
714
+	/**
715
+	 * Gets end_date
716
+	 *
717
+	 * @param string $date_format
718
+	 * @param string $time_format
719
+	 * @return string
720
+	 * @throws EE_Error
721
+	 * @throws ReflectionException
722
+	 */
723
+	public function end_date($date_format = '', $time_format = '')
724
+	{
725
+		return $this->_get_datetime('TKT_end_date', $date_format, $time_format);
726
+	}
727
+
728
+
729
+	/**
730
+	 * Sets end_date
731
+	 *
732
+	 * @param string $end_date
733
+	 * @return void
734
+	 * @throws EE_Error
735
+	 * @throws ReflectionException
736
+	 */
737
+	public function set_end_date($end_date)
738
+	{
739
+		$this->_set_date_time('B', $end_date, 'TKT_end_date');
740
+	}
741
+
742
+
743
+	/**
744
+	 * Sets sell until time
745
+	 *
746
+	 * @param string $time a string representation of the sell until time (ex 9am or 7:30pm)
747
+	 * @throws EE_Error
748
+	 * @throws ReflectionException
749
+	 * @since 4.5.0
750
+	 */
751
+	public function set_end_time($time)
752
+	{
753
+		$this->_set_time_for($time, 'TKT_end_date');
754
+	}
755
+
756
+
757
+	/**
758
+	 * Sets min
759
+	 *
760
+	 * @param int $min
761
+	 * @return void
762
+	 * @throws EE_Error
763
+	 * @throws ReflectionException
764
+	 */
765
+	public function set_min($min)
766
+	{
767
+		$this->set('TKT_min', $min);
768
+	}
769
+
770
+
771
+	/**
772
+	 * Gets max
773
+	 *
774
+	 * @return int
775
+	 * @throws EE_Error
776
+	 * @throws ReflectionException
777
+	 */
778
+	public function max()
779
+	{
780
+		return $this->get('TKT_max');
781
+	}
782
+
783
+
784
+	/**
785
+	 * Sets max
786
+	 *
787
+	 * @param int $max
788
+	 * @return void
789
+	 * @throws EE_Error
790
+	 * @throws ReflectionException
791
+	 */
792
+	public function set_max($max)
793
+	{
794
+		$this->set('TKT_max', $max);
795
+	}
796
+
797
+
798
+	/**
799
+	 * Sets price
800
+	 *
801
+	 * @param float $price
802
+	 * @return void
803
+	 * @throws EE_Error
804
+	 * @throws ReflectionException
805
+	 */
806
+	public function set_price($price)
807
+	{
808
+		$this->set('TKT_price', $price);
809
+	}
810
+
811
+
812
+	/**
813
+	 * Gets sold
814
+	 *
815
+	 * @return int
816
+	 * @throws EE_Error
817
+	 * @throws ReflectionException
818
+	 */
819
+	public function sold()
820
+	{
821
+		return $this->get_raw('TKT_sold');
822
+	}
823
+
824
+
825
+	/**
826
+	 * Sets sold
827
+	 *
828
+	 * @param int $sold
829
+	 * @return void
830
+	 * @throws EE_Error
831
+	 * @throws ReflectionException
832
+	 */
833
+	public function set_sold($sold)
834
+	{
835
+		// sold can not go below zero
836
+		$sold = max(0, $sold);
837
+		$this->set('TKT_sold', $sold);
838
+	}
839
+
840
+
841
+	/**
842
+	 * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its
843
+	 * associated datetimes.
844
+	 *
845
+	 * @param int $qty
846
+	 * @return boolean
847
+	 * @throws EE_Error
848
+	 * @throws InvalidArgumentException
849
+	 * @throws InvalidDataTypeException
850
+	 * @throws InvalidInterfaceException
851
+	 * @throws ReflectionException
852
+	 * @since 4.9.80.p
853
+	 */
854
+	public function increaseSold($qty = 1)
855
+	{
856
+		$qty = absint($qty);
857
+		// increment sold and decrement reserved datetime quantities simultaneously
858
+		// don't worry about failures, because they must have already had a spot reserved
859
+		$this->increaseSoldForDatetimes($qty);
860
+		// Increment and decrement ticket quantities simultaneously
861
+		$success = $this->adjustNumericFieldsInDb(
862
+			[
863
+				'TKT_reserved' => $qty * -1,
864
+				'TKT_sold'     => $qty,
865
+			]
866
+		);
867
+		do_action(
868
+			'AHEE__EE_Ticket__increase_sold',
869
+			$this,
870
+			$qty,
871
+			$this->sold(),
872
+			$success
873
+		);
874
+		return $success;
875
+	}
876
+
877
+
878
+	/**
879
+	 * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty.
880
+	 *
881
+	 * @param int           $qty positive or negative. Positive means to increase sold counts (and decrease reserved
882
+	 *                           counts), Negative means to decreases old counts (and increase reserved counts).
883
+	 * @param EE_Datetime[] $datetimes
884
+	 * @throws EE_Error
885
+	 * @throws InvalidArgumentException
886
+	 * @throws InvalidDataTypeException
887
+	 * @throws InvalidInterfaceException
888
+	 * @throws ReflectionException
889
+	 * @since 4.9.80.p
890
+	 */
891
+	protected function increaseSoldForDatetimes($qty, array $datetimes = [])
892
+	{
893
+		$datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes();
894
+		foreach ($datetimes as $datetime) {
895
+			$datetime->increaseSold($qty);
896
+		}
897
+	}
898
+
899
+
900
+	/**
901
+	 * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the
902
+	 * DB and then updates the model objects.
903
+	 * Does not affect the reserved counts.
904
+	 *
905
+	 * @param int $qty
906
+	 * @return boolean
907
+	 * @throws EE_Error
908
+	 * @throws InvalidArgumentException
909
+	 * @throws InvalidDataTypeException
910
+	 * @throws InvalidInterfaceException
911
+	 * @throws ReflectionException
912
+	 * @since 4.9.80.p
913
+	 */
914
+	public function decreaseSold($qty = 1)
915
+	{
916
+		$qty = absint($qty);
917
+		$this->decreaseSoldForDatetimes($qty);
918
+		$success = $this->adjustNumericFieldsInDb(
919
+			[
920
+				'TKT_sold' => $qty * -1,
921
+			]
922
+		);
923
+		do_action(
924
+			'AHEE__EE_Ticket__decrease_sold',
925
+			$this,
926
+			$qty,
927
+			$this->sold(),
928
+			$success
929
+		);
930
+		return $success;
931
+	}
932
+
933
+
934
+	/**
935
+	 * Decreases sold on related datetimes
936
+	 *
937
+	 * @param int           $qty
938
+	 * @param EE_Datetime[] $datetimes
939
+	 * @return void
940
+	 * @throws EE_Error
941
+	 * @throws InvalidArgumentException
942
+	 * @throws InvalidDataTypeException
943
+	 * @throws InvalidInterfaceException
944
+	 * @throws ReflectionException
945
+	 * @since 4.9.80.p
946
+	 */
947
+	protected function decreaseSoldForDatetimes($qty = 1, array $datetimes = [])
948
+	{
949
+		$datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes();
950
+		if (is_array($datetimes)) {
951
+			foreach ($datetimes as $datetime) {
952
+				if ($datetime instanceof EE_Datetime) {
953
+					$datetime->decreaseSold($qty);
954
+				}
955
+			}
956
+		}
957
+	}
958
+
959
+
960
+	/**
961
+	 * Gets qty of reserved tickets
962
+	 *
963
+	 * @return int
964
+	 * @throws EE_Error
965
+	 * @throws ReflectionException
966
+	 */
967
+	public function reserved()
968
+	{
969
+		return $this->get_raw('TKT_reserved');
970
+	}
971
+
972
+
973
+	/**
974
+	 * Sets reserved
975
+	 *
976
+	 * @param int $reserved
977
+	 * @return void
978
+	 * @throws EE_Error
979
+	 * @throws ReflectionException
980
+	 */
981
+	public function set_reserved($reserved)
982
+	{
983
+		// reserved can not go below zero
984
+		$reserved = max(0, (int) $reserved);
985
+		$this->set('TKT_reserved', $reserved);
986
+	}
987
+
988
+
989
+	/**
990
+	 * Increments reserved by amount passed by $qty, and persists it immediately to the database.
991
+	 *
992
+	 * @param int    $qty
993
+	 * @param string $source
994
+	 * @return bool whether we successfully reserved the ticket or not.
995
+	 * @throws EE_Error
996
+	 * @throws InvalidArgumentException
997
+	 * @throws ReflectionException
998
+	 * @throws InvalidDataTypeException
999
+	 * @throws InvalidInterfaceException
1000
+	 * @since 4.9.80.p
1001
+	 */
1002
+	public function increaseReserved($qty = 1, $source = 'unknown')
1003
+	{
1004
+		$qty = absint($qty);
1005
+		do_action(
1006
+			'AHEE__EE_Ticket__increase_reserved__begin',
1007
+			$this,
1008
+			$qty,
1009
+			$source
1010
+		);
1011
+		$this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "{$qty} from {$source}");
1012
+		$success                         = false;
1013
+		$datetimes_adjusted_successfully = $this->increaseReservedForDatetimes($qty);
1014
+		if ($datetimes_adjusted_successfully) {
1015
+			$success = $this->incrementFieldConditionallyInDb(
1016
+				'TKT_reserved',
1017
+				'TKT_sold',
1018
+				'TKT_qty',
1019
+				$qty
1020
+			);
1021
+			if (! $success) {
1022
+				// The datetimes were successfully bumped, but not the
1023
+				// ticket. So we need to manually rollback the datetimes.
1024
+				$this->decreaseReservedForDatetimes($qty);
1025
+			}
1026
+		}
1027
+		do_action(
1028
+			'AHEE__EE_Ticket__increase_reserved',
1029
+			$this,
1030
+			$qty,
1031
+			$this->reserved(),
1032
+			$success
1033
+		);
1034
+		return $success;
1035
+	}
1036
+
1037
+
1038
+	/**
1039
+	 * Increases reserved counts on related datetimes
1040
+	 *
1041
+	 * @param int           $qty
1042
+	 * @param EE_Datetime[] $datetimes
1043
+	 * @return boolean indicating success
1044
+	 * @throws EE_Error
1045
+	 * @throws InvalidArgumentException
1046
+	 * @throws InvalidDataTypeException
1047
+	 * @throws InvalidInterfaceException
1048
+	 * @throws ReflectionException
1049
+	 * @since 4.9.80.p
1050
+	 */
1051
+	protected function increaseReservedForDatetimes($qty = 1, array $datetimes = [])
1052
+	{
1053
+		$datetimes         = ! empty($datetimes) ? $datetimes : $this->datetimes();
1054
+		$datetimes_updated = [];
1055
+		$limit_exceeded    = false;
1056
+		if (is_array($datetimes)) {
1057
+			foreach ($datetimes as $datetime) {
1058
+				if ($datetime instanceof EE_Datetime) {
1059
+					if ($datetime->increaseReserved($qty)) {
1060
+						$datetimes_updated[] = $datetime;
1061
+					} else {
1062
+						$limit_exceeded = true;
1063
+						break;
1064
+					}
1065
+				}
1066
+			}
1067
+			// If somewhere along the way we detected a datetime whose
1068
+			// limit was exceeded, do a manual rollback.
1069
+			if ($limit_exceeded) {
1070
+				$this->decreaseReservedForDatetimes($qty, $datetimes_updated);
1071
+				return false;
1072
+			}
1073
+		}
1074
+		return true;
1075
+	}
1076
+
1077
+
1078
+	/**
1079
+	 * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database.
1080
+	 *
1081
+	 * @param int    $qty
1082
+	 * @param bool   $adjust_datetimes
1083
+	 * @param string $source
1084
+	 * @return boolean
1085
+	 * @throws EE_Error
1086
+	 * @throws InvalidArgumentException
1087
+	 * @throws ReflectionException
1088
+	 * @throws InvalidDataTypeException
1089
+	 * @throws InvalidInterfaceException
1090
+	 * @since 4.9.80.p
1091
+	 */
1092
+	public function decreaseReserved($qty = 1, $adjust_datetimes = true, $source = 'unknown')
1093
+	{
1094
+		$qty = absint($qty);
1095
+		$this->add_extra_meta(EE_Ticket::META_KEY_TICKET_RESERVATIONS, "-{$qty} from {$source}");
1096
+		if ($adjust_datetimes) {
1097
+			$this->decreaseReservedForDatetimes($qty);
1098
+		}
1099
+		$success = $this->adjustNumericFieldsInDb(
1100
+			[
1101
+				'TKT_reserved' => $qty * -1,
1102
+			]
1103
+		);
1104
+		do_action(
1105
+			'AHEE__EE_Ticket__decrease_reserved',
1106
+			$this,
1107
+			$qty,
1108
+			$this->reserved(),
1109
+			$success
1110
+		);
1111
+		return $success;
1112
+	}
1113
+
1114
+
1115
+	/**
1116
+	 * Decreases the reserved count on the specified datetimes.
1117
+	 *
1118
+	 * @param int           $qty
1119
+	 * @param EE_Datetime[] $datetimes
1120
+	 * @throws EE_Error
1121
+	 * @throws InvalidArgumentException
1122
+	 * @throws ReflectionException
1123
+	 * @throws InvalidDataTypeException
1124
+	 * @throws InvalidInterfaceException
1125
+	 * @since 4.9.80.p
1126
+	 */
1127
+	protected function decreaseReservedForDatetimes($qty = 1, array $datetimes = [])
1128
+	{
1129
+		$datetimes = ! empty($datetimes) ? $datetimes : $this->datetimes();
1130
+		foreach ($datetimes as $datetime) {
1131
+			if ($datetime instanceof EE_Datetime) {
1132
+				$datetime->decreaseReserved($qty);
1133
+			}
1134
+		}
1135
+	}
1136
+
1137
+
1138
+	/**
1139
+	 * Gets ticket quantity
1140
+	 *
1141
+	 * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
1142
+	 *                            therefore $context can be one of three values: '', 'reg_limit', or 'saleable'
1143
+	 *                            '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects
1144
+	 *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
1145
+	 *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
1146
+	 *                            is therefore the truest measure of tickets that can be purchased at the moment
1147
+	 * @return int
1148
+	 * @throws EE_Error
1149
+	 * @throws ReflectionException
1150
+	 */
1151
+	public function qty($context = '')
1152
+	{
1153
+		switch ($context) {
1154
+			case 'reg_limit':
1155
+				return $this->real_quantity_on_ticket();
1156
+			case 'saleable':
1157
+				return $this->real_quantity_on_ticket('saleable');
1158
+			default:
1159
+				return $this->get_raw('TKT_qty');
1160
+		}
1161
+	}
1162
+
1163
+
1164
+	/**
1165
+	 * Gets ticket quantity
1166
+	 *
1167
+	 * @param string $context     ticket quantity is somewhat subjective depending on the exact information sought
1168
+	 *                            therefore $context can be one of two values: 'reg_limit', or 'saleable'
1169
+	 *                            REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes
1170
+	 *                            SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and
1171
+	 *                            is therefore the truest measure of tickets that can be purchased at the moment
1172
+	 * @param int    $DTT_ID      the primary key for a particular datetime.
1173
+	 *                            set to 0 for all related datetimes
1174
+	 * @return int
1175
+	 * @throws EE_Error
1176
+	 * @throws ReflectionException
1177
+	 */
1178
+	public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0)
1179
+	{
1180
+		$raw = $this->get_raw('TKT_qty');
1181
+		// return immediately if it's zero
1182
+		if ($raw === 0) {
1183
+			return $raw;
1184
+		}
1185
+		// echo "\n\n<br />Ticket: " . $this->name() . '<br />';
1186
+		// ensure qty doesn't exceed raw value for THIS ticket
1187
+		$qty = min(EE_INF, $raw);
1188
+		// echo "\n . qty: " . $qty . '<br />';
1189
+		// calculate this ticket's total sales and reservations
1190
+		$sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved();
1191
+		// echo "\n . sold: " . $this->sold() . '<br />';
1192
+		// echo "\n . reserved: " . $this->reserved() . '<br />';
1193
+		// echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />';
1194
+		// first we need to calculate the maximum number of tickets available for the datetime
1195
+		// do we want data for one datetime or all of them ?
1196
+		$query_params = $DTT_ID ? [['DTT_ID' => $DTT_ID]] : [];
1197
+		$datetimes    = $this->datetimes($query_params);
1198
+		if (is_array($datetimes) && ! empty($datetimes)) {
1199
+			foreach ($datetimes as $datetime) {
1200
+				if ($datetime instanceof EE_Datetime) {
1201
+					$datetime->refresh_from_db();
1202
+					// echo "\n . . datetime name: " . $datetime->name() . '<br />';
1203
+					// echo "\n . . datetime ID: " . $datetime->ID() . '<br />';
1204
+					// initialize with no restrictions for each datetime
1205
+					// but adjust datetime qty based on datetime reg limit
1206
+					$datetime_qty = min(EE_INF, $datetime->reg_limit());
1207
+					// echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />';
1208
+					// echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
1209
+					// if we want the actual saleable amount, then we need to consider OTHER ticket sales
1210
+					// and reservations for this datetime, that do NOT include sales and reservations
1211
+					// for this ticket (so we add $this->sold() and $this->reserved() back in)
1212
+					if ($context === 'saleable') {
1213
+						$datetime_qty = max(
1214
+							$datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket,
1215
+							0
1216
+						);
1217
+						// echo "\n . . . datetime sold: " . $datetime->sold() . '<br />';
1218
+						// echo "\n . . . datetime reserved: " . $datetime->reserved() . '<br />';
1219
+						// echo "\n . . . datetime sold_and_reserved: " . $datetime->sold_and_reserved() . '<br />';
1220
+						// echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
1221
+						$datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0;
1222
+						// echo "\n . . . datetime_qty: " . $datetime_qty . '<br />';
1223
+					}
1224
+					$qty = min($datetime_qty, $qty);
1225
+					// echo "\n . . qty: " . $qty . '<br />';
1226
+				}
1227
+			}
1228
+		}
1229
+		// NOW that we know the  maximum number of tickets available for the datetime
1230
+		// we can finally factor in the details for this specific ticket
1231
+		if ($qty > 0 && $context === 'saleable') {
1232
+			// and subtract the sales for THIS ticket
1233
+			$qty = max($qty - $sold_and_reserved_for_this_ticket, 0);
1234
+			// echo "\n . qty: " . $qty . '<br />';
1235
+		}
1236
+		// echo "\nFINAL QTY: " . $qty . "<br /><br />";
1237
+		return $qty;
1238
+	}
1239
+
1240
+
1241
+	/**
1242
+	 * Sets qty - IMPORTANT!!! Does NOT allow QTY to be set higher than the lowest reg limit of any related datetimes
1243
+	 *
1244
+	 * @param int $qty
1245
+	 * @return void
1246
+	 * @throws EE_Error
1247
+	 * @throws ReflectionException
1248
+	 */
1249
+	public function set_qty($qty)
1250
+	{
1251
+		$datetimes = $this->datetimes();
1252
+		foreach ($datetimes as $datetime) {
1253
+			if ($datetime instanceof EE_Datetime) {
1254
+				$qty = min($qty, $datetime->reg_limit());
1255
+			}
1256
+		}
1257
+		$this->set('TKT_qty', $qty);
1258
+	}
1259
+
1260
+
1261
+	/**
1262
+	 * Gets uses
1263
+	 *
1264
+	 * @return int
1265
+	 * @throws EE_Error
1266
+	 * @throws ReflectionException
1267
+	 */
1268
+	public function uses()
1269
+	{
1270
+		return $this->get('TKT_uses');
1271
+	}
1272
+
1273
+
1274
+	/**
1275
+	 * Sets uses
1276
+	 *
1277
+	 * @param int $uses
1278
+	 * @return void
1279
+	 * @throws EE_Error
1280
+	 * @throws ReflectionException
1281
+	 */
1282
+	public function set_uses($uses)
1283
+	{
1284
+		$this->set('TKT_uses', $uses);
1285
+	}
1286
+
1287
+
1288
+	/**
1289
+	 * returns whether ticket is required or not.
1290
+	 *
1291
+	 * @return boolean
1292
+	 * @throws EE_Error
1293
+	 * @throws ReflectionException
1294
+	 */
1295
+	public function required()
1296
+	{
1297
+		return $this->get('TKT_required');
1298
+	}
1299
+
1300
+
1301
+	/**
1302
+	 * sets the TKT_required property
1303
+	 *
1304
+	 * @param boolean $required
1305
+	 * @return void
1306
+	 * @throws EE_Error
1307
+	 * @throws ReflectionException
1308
+	 */
1309
+	public function set_required($required)
1310
+	{
1311
+		$this->set('TKT_required', $required);
1312
+	}
1313
+
1314
+
1315
+	/**
1316
+	 * Gets taxable
1317
+	 *
1318
+	 * @return boolean
1319
+	 * @throws EE_Error
1320
+	 * @throws ReflectionException
1321
+	 */
1322
+	public function taxable()
1323
+	{
1324
+		return $this->get('TKT_taxable');
1325
+	}
1326
+
1327
+
1328
+	/**
1329
+	 * Sets taxable
1330
+	 *
1331
+	 * @param boolean $taxable
1332
+	 * @return void
1333
+	 * @throws EE_Error
1334
+	 * @throws ReflectionException
1335
+	 */
1336
+	public function set_taxable($taxable)
1337
+	{
1338
+		$this->set('TKT_taxable', $taxable);
1339
+	}
1340
+
1341
+
1342
+	/**
1343
+	 * Gets is_default
1344
+	 *
1345
+	 * @return boolean
1346
+	 * @throws EE_Error
1347
+	 * @throws ReflectionException
1348
+	 */
1349
+	public function is_default()
1350
+	{
1351
+		return $this->get('TKT_is_default');
1352
+	}
1353
+
1354
+
1355
+	/**
1356
+	 * Sets is_default
1357
+	 *
1358
+	 * @param boolean $is_default
1359
+	 * @return void
1360
+	 * @throws EE_Error
1361
+	 * @throws ReflectionException
1362
+	 */
1363
+	public function set_is_default($is_default)
1364
+	{
1365
+		$this->set('TKT_is_default', $is_default);
1366
+	}
1367
+
1368
+
1369
+	/**
1370
+	 * Gets order
1371
+	 *
1372
+	 * @return int
1373
+	 * @throws EE_Error
1374
+	 * @throws ReflectionException
1375
+	 */
1376
+	public function order()
1377
+	{
1378
+		return $this->get('TKT_order');
1379
+	}
1380
+
1381
+
1382
+	/**
1383
+	 * Sets order
1384
+	 *
1385
+	 * @param int $order
1386
+	 * @return void
1387
+	 * @throws EE_Error
1388
+	 * @throws ReflectionException
1389
+	 */
1390
+	public function set_order($order)
1391
+	{
1392
+		$this->set('TKT_order', $order);
1393
+	}
1394
+
1395
+
1396
+	/**
1397
+	 * Gets row
1398
+	 *
1399
+	 * @return int
1400
+	 * @throws EE_Error
1401
+	 * @throws ReflectionException
1402
+	 */
1403
+	public function row()
1404
+	{
1405
+		return $this->get('TKT_row');
1406
+	}
1407
+
1408
+
1409
+	/**
1410
+	 * Sets row
1411
+	 *
1412
+	 * @param int $row
1413
+	 * @return void
1414
+	 * @throws EE_Error
1415
+	 * @throws ReflectionException
1416
+	 */
1417
+	public function set_row($row)
1418
+	{
1419
+		$this->set('TKT_row', $row);
1420
+	}
1421
+
1422
+
1423
+	/**
1424
+	 * Gets deleted
1425
+	 *
1426
+	 * @return boolean
1427
+	 * @throws EE_Error
1428
+	 * @throws ReflectionException
1429
+	 */
1430
+	public function deleted()
1431
+	{
1432
+		return $this->get('TKT_deleted');
1433
+	}
1434
+
1435
+
1436
+	/**
1437
+	 * Sets deleted
1438
+	 *
1439
+	 * @param boolean $deleted
1440
+	 * @return void
1441
+	 * @throws EE_Error
1442
+	 * @throws ReflectionException
1443
+	 */
1444
+	public function set_deleted($deleted)
1445
+	{
1446
+		$this->set('TKT_deleted', $deleted);
1447
+	}
1448
+
1449
+
1450
+	/**
1451
+	 * Gets parent
1452
+	 *
1453
+	 * @return int
1454
+	 * @throws EE_Error
1455
+	 * @throws ReflectionException
1456
+	 */
1457
+	public function parent_ID()
1458
+	{
1459
+		return $this->get('TKT_parent');
1460
+	}
1461
+
1462
+
1463
+	/**
1464
+	 * Sets parent
1465
+	 *
1466
+	 * @param int $parent
1467
+	 * @return void
1468
+	 * @throws EE_Error
1469
+	 * @throws ReflectionException
1470
+	 */
1471
+	public function set_parent_ID($parent)
1472
+	{
1473
+		$this->set('TKT_parent', $parent);
1474
+	}
1475
+
1476
+
1477
+	/**
1478
+	 * @return boolean
1479
+	 * @throws EE_Error
1480
+	 * @throws InvalidArgumentException
1481
+	 * @throws InvalidDataTypeException
1482
+	 * @throws InvalidInterfaceException
1483
+	 * @throws ReflectionException
1484
+	 */
1485
+	public function reverse_calculate()
1486
+	{
1487
+		return $this->get('TKT_reverse_calculate');
1488
+	}
1489
+
1490
+
1491
+	/**
1492
+	 * @param boolean $reverse_calculate
1493
+	 * @throws EE_Error
1494
+	 * @throws InvalidArgumentException
1495
+	 * @throws InvalidDataTypeException
1496
+	 * @throws InvalidInterfaceException
1497
+	 * @throws ReflectionException
1498
+	 */
1499
+	public function set_reverse_calculate($reverse_calculate)
1500
+	{
1501
+		$this->set('TKT_reverse_calculate', $reverse_calculate);
1502
+	}
1503
+
1504
+
1505
+	/**
1506
+	 * Gets a string which is handy for showing in gateways etc that describes the ticket.
1507
+	 *
1508
+	 * @return string
1509
+	 * @throws EE_Error
1510
+	 * @throws ReflectionException
1511
+	 */
1512
+	public function name_and_info()
1513
+	{
1514
+		$times = [];
1515
+		foreach ($this->datetimes() as $datetime) {
1516
+			$times[] = $datetime->start_date_and_time();
1517
+		}
1518
+		return $this->name() . ' @ ' . implode(', ', $times) . ' for ' . $this->pretty_price();
1519
+	}
1520
+
1521
+
1522
+	/**
1523
+	 * Gets name
1524
+	 *
1525
+	 * @return string
1526
+	 * @throws EE_Error
1527
+	 * @throws ReflectionException
1528
+	 */
1529
+	public function name()
1530
+	{
1531
+		return $this->get('TKT_name');
1532
+	}
1533
+
1534
+
1535
+	/**
1536
+	 * Gets price
1537
+	 *
1538
+	 * @return float
1539
+	 * @throws EE_Error
1540
+	 * @throws ReflectionException
1541
+	 */
1542
+	public function price()
1543
+	{
1544
+		return $this->get('TKT_price');
1545
+	}
1546
+
1547
+
1548
+	/**
1549
+	 * Gets all the registrations for this ticket
1550
+	 *
1551
+	 * @param array $query_params @see
1552
+	 *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1553
+	 * @return EE_Registration[]|EE_Base_Class[]
1554
+	 * @throws EE_Error
1555
+	 * @throws ReflectionException
1556
+	 */
1557
+	public function registrations($query_params = [])
1558
+	{
1559
+		return $this->get_many_related('Registration', $query_params);
1560
+	}
1561
+
1562
+
1563
+	/**
1564
+	 * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket.
1565
+	 *
1566
+	 * @return int
1567
+	 * @throws EE_Error
1568
+	 * @throws ReflectionException
1569
+	 */
1570
+	public function update_tickets_sold()
1571
+	{
1572
+		$count_regs_for_this_ticket = $this->count_registrations(
1573
+			[
1574
+				[
1575
+					'STS_ID'      => EEM_Registration::status_id_approved,
1576
+					'REG_deleted' => 0,
1577
+				],
1578
+			]
1579
+		);
1580
+		$this->set_sold($count_regs_for_this_ticket);
1581
+		$this->save();
1582
+		return $count_regs_for_this_ticket;
1583
+	}
1584
+
1585
+
1586
+	/**
1587
+	 * Counts the registrations for this ticket
1588
+	 *
1589
+	 * @param array $query_params @see
1590
+	 *                            https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1591
+	 * @return int
1592
+	 * @throws EE_Error
1593
+	 * @throws ReflectionException
1594
+	 */
1595
+	public function count_registrations($query_params = [])
1596
+	{
1597
+		return $this->count_related('Registration', $query_params);
1598
+	}
1599
+
1600
+
1601
+	/**
1602
+	 * Implementation for EEI_Has_Icon interface method.
1603
+	 *
1604
+	 * @return string
1605
+	 * @see EEI_Visual_Representation for comments
1606
+	 */
1607
+	public function get_icon()
1608
+	{
1609
+		return '<span class="dashicons dashicons-tickets-alt"/>';
1610
+	}
1611
+
1612
+
1613
+	/**
1614
+	 * Implementation of the EEI_Event_Relation interface method
1615
+	 *
1616
+	 * @return EE_Event
1617
+	 * @throws EE_Error
1618
+	 * @throws UnexpectedEntityException
1619
+	 * @throws ReflectionException
1620
+	 * @see EEI_Event_Relation for comments
1621
+	 */
1622
+	public function get_related_event()
1623
+	{
1624
+		// get one datetime to use for getting the event
1625
+		$datetime = $this->first_datetime();
1626
+		if (! $datetime instanceof EE_Datetime) {
1627
+			throw new UnexpectedEntityException(
1628
+				$datetime,
1629
+				'EE_Datetime',
1630
+				sprintf(
1631
+					__('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'),
1632
+					$this->name()
1633
+				)
1634
+			);
1635
+		}
1636
+		$event = $datetime->event();
1637
+		if (! $event instanceof EE_Event) {
1638
+			throw new UnexpectedEntityException(
1639
+				$event,
1640
+				'EE_Event',
1641
+				sprintf(
1642
+					__('The ticket (%s) is not associated with a valid event.', 'event_espresso'),
1643
+					$this->name()
1644
+				)
1645
+			);
1646
+		}
1647
+		return $event;
1648
+	}
1649
+
1650
+
1651
+	/**
1652
+	 * Implementation of the EEI_Event_Relation interface method
1653
+	 *
1654
+	 * @return string
1655
+	 * @throws UnexpectedEntityException
1656
+	 * @throws EE_Error
1657
+	 * @throws ReflectionException
1658
+	 * @see EEI_Event_Relation for comments
1659
+	 */
1660
+	public function get_event_name()
1661
+	{
1662
+		$event = $this->get_related_event();
1663
+		return $event instanceof EE_Event ? $event->name() : '';
1664
+	}
1665
+
1666
+
1667
+	/**
1668
+	 * Implementation of the EEI_Event_Relation interface method
1669
+	 *
1670
+	 * @return int
1671
+	 * @throws UnexpectedEntityException
1672
+	 * @throws EE_Error
1673
+	 * @throws ReflectionException
1674
+	 * @see EEI_Event_Relation for comments
1675
+	 */
1676
+	public function get_event_ID()
1677
+	{
1678
+		$event = $this->get_related_event();
1679
+		return $event instanceof EE_Event ? $event->ID() : 0;
1680
+	}
1681
+
1682
+
1683
+	/**
1684
+	 * This simply returns whether a ticket can be permanently deleted or not.
1685
+	 * The criteria for determining this is whether the ticket has any related registrations.
1686
+	 * If there are none then it can be permanently deleted.
1687
+	 *
1688
+	 * @return bool
1689
+	 * @throws EE_Error
1690
+	 * @throws ReflectionException
1691
+	 */
1692
+	public function is_permanently_deleteable()
1693
+	{
1694
+		return $this->count_registrations() === 0;
1695
+	}
1696
+
1697
+
1698
+	/**
1699
+	 * @return int
1700
+	 * @throws EE_Error
1701
+	 * @throws ReflectionException
1702
+	 * @since   $VID:$
1703
+	 */
1704
+	public function visibility(): int
1705
+	{
1706
+		return $this->get('TKT_visibility');
1707
+	}
1708
+
1709
+
1710
+	/**
1711
+	 * @return int
1712
+	 * @throws EE_Error
1713
+	 * @throws ReflectionException
1714
+	 * @since   $VID:$
1715
+	 */
1716
+	public function isHidden(): int
1717
+	{
1718
+		return $this->visibility() === EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE;
1719
+	}
1720
+
1721
+
1722
+	/**
1723
+	 * @return int
1724
+	 * @throws EE_Error
1725
+	 * @throws ReflectionException
1726
+	 * @since   $VID:$
1727
+	 */
1728
+	public function isNotHidden(): int
1729
+	{
1730
+		return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_NONE_VALUE;
1731
+	}
1732
+
1733
+
1734
+	/**
1735
+	 * @return int
1736
+	 * @throws EE_Error
1737
+	 * @throws ReflectionException
1738
+	 * @since   $VID:$
1739
+	 */
1740
+	public function isPublicOnly(): int
1741
+	{
1742
+		return $this->isNotHidden() && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE;
1743
+	}
1744
+
1745
+
1746
+	/**
1747
+	 * @return int
1748
+	 * @throws EE_Error
1749
+	 * @throws ReflectionException
1750
+	 * @since   $VID:$
1751
+	 */
1752
+	public function isMembersOnly(): int
1753
+	{
1754
+		return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_PUBLIC_VALUE
1755
+			   && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_VALUE;
1756
+	}
1757
+
1758
+
1759
+	/**
1760
+	 * @return int
1761
+	 * @throws EE_Error
1762
+	 * @throws ReflectionException
1763
+	 * @since   $VID:$
1764
+	 */
1765
+	public function isAdminsOnly(): int
1766
+	{
1767
+		return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY_VALUE
1768
+			   && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_VALUE;
1769
+	}
1770
+
1771
+
1772
+	/**
1773
+	 * @return int
1774
+	 * @throws EE_Error
1775
+	 * @throws ReflectionException
1776
+	 * @since   $VID:$
1777
+	 */
1778
+	public function isAdminUiOnly(): int
1779
+	{
1780
+		return $this->visibility() > EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY_VALUE
1781
+			   && $this->visibility() <= EEM_Ticket::TICKET_VISIBILITY_ADMIN_UI_ONLY_VALUE;
1782
+	}
1783
+
1784
+
1785
+	/**
1786
+	 * @param int $visibility
1787
+	 * @throws EE_Error
1788
+	 * @throws ReflectionException
1789
+	 * @since   $VID:$
1790
+	 */
1791
+	public function set_visibility(int $visibility)
1792
+	{
1793
+
1794
+		$ticket_visibility_options = $this->_model->ticketVisibilityOptions();
1795
+		$ticket_visibility         = -1;
1796
+		foreach ($ticket_visibility_options as $ticket_visibility_option) {
1797
+			if ($visibility === $ticket_visibility_option) {
1798
+				$ticket_visibility = $visibility;
1799
+			}
1800
+		}
1801
+		if ($ticket_visibility === -1) {
1802
+			throw new DomainException(
1803
+				sprintf(
1804
+					esc_html__(
1805
+						'The supplied ticket visibility setting of "%1$s" is not valid. It needs to match one of the keys in the following array:%2$s %3$s ',
1806
+						'event_espresso'
1807
+					),
1808
+					$visibility,
1809
+					'<br />',
1810
+					var_export($ticket_visibility_options, true)
1811
+				)
1812
+			);
1813
+		}
1814
+		$this->set('TKT_visibility', $ticket_visibility);
1815
+	}
1816
+
1817
+
1818
+	/*******************************************************************
1819 1819
      ***********************  DEPRECATED METHODS  **********************
1820 1820
      *******************************************************************/
1821 1821
 
1822 1822
 
1823
-    /**
1824
-     * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its
1825
-     * associated datetimes.
1826
-     *
1827
-     * @param int $qty
1828
-     * @return void
1829
-     * @throws EE_Error
1830
-     * @throws InvalidArgumentException
1831
-     * @throws InvalidDataTypeException
1832
-     * @throws InvalidInterfaceException
1833
-     * @throws ReflectionException
1834
-     * @deprecated 4.9.80.p
1835
-     */
1836
-    public function increase_sold($qty = 1)
1837
-    {
1838
-        EE_Error::doing_it_wrong(
1839
-            __FUNCTION__,
1840
-            esc_html__('Please use EE_Ticket::increaseSold() instead', 'event_espresso'),
1841
-            '4.9.80.p',
1842
-            '5.0.0.p'
1843
-        );
1844
-        $this->increaseSold($qty);
1845
-    }
1846
-
1847
-
1848
-    /**
1849
-     * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty.
1850
-     *
1851
-     * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved counts),
1852
-     *                 Negative means to decreases old counts (and increase reserved counts).
1853
-     * @throws EE_Error
1854
-     * @throws InvalidArgumentException
1855
-     * @throws InvalidDataTypeException
1856
-     * @throws InvalidInterfaceException
1857
-     * @throws ReflectionException
1858
-     * @deprecated 4.9.80.p
1859
-     */
1860
-    protected function _increase_sold_for_datetimes($qty)
1861
-    {
1862
-        EE_Error::doing_it_wrong(
1863
-            __FUNCTION__,
1864
-            esc_html__('Please use EE_Ticket::increaseSoldForDatetimes() instead', 'event_espresso'),
1865
-            '4.9.80.p',
1866
-            '5.0.0.p'
1867
-        );
1868
-        $this->increaseSoldForDatetimes($qty);
1869
-    }
1870
-
1871
-
1872
-    /**
1873
-     * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the
1874
-     * DB and then updates the model objects.
1875
-     * Does not affect the reserved counts.
1876
-     *
1877
-     * @param int $qty
1878
-     * @return void
1879
-     * @throws EE_Error
1880
-     * @throws InvalidArgumentException
1881
-     * @throws InvalidDataTypeException
1882
-     * @throws InvalidInterfaceException
1883
-     * @throws ReflectionException
1884
-     * @deprecated 4.9.80.p
1885
-     */
1886
-    public function decrease_sold($qty = 1)
1887
-    {
1888
-        EE_Error::doing_it_wrong(
1889
-            __FUNCTION__,
1890
-            esc_html__('Please use EE_Ticket::decreaseSold() instead', 'event_espresso'),
1891
-            '4.9.80.p',
1892
-            '5.0.0.p'
1893
-        );
1894
-        $this->decreaseSold($qty);
1895
-    }
1896
-
1897
-
1898
-    /**
1899
-     * Decreases sold on related datetimes
1900
-     *
1901
-     * @param int $qty
1902
-     * @return void
1903
-     * @throws EE_Error
1904
-     * @throws InvalidArgumentException
1905
-     * @throws InvalidDataTypeException
1906
-     * @throws InvalidInterfaceException
1907
-     * @throws ReflectionException
1908
-     * @deprecated 4.9.80.p
1909
-     */
1910
-    protected function _decrease_sold_for_datetimes($qty = 1)
1911
-    {
1912
-        EE_Error::doing_it_wrong(
1913
-            __FUNCTION__,
1914
-            esc_html__('Please use EE_Ticket::decreaseSoldForDatetimes() instead', 'event_espresso'),
1915
-            '4.9.80.p',
1916
-            '5.0.0.p'
1917
-        );
1918
-        $this->decreaseSoldForDatetimes($qty);
1919
-    }
1920
-
1921
-
1922
-    /**
1923
-     * Increments reserved by amount passed by $qty, and persists it immediately to the database.
1924
-     *
1925
-     * @param int    $qty
1926
-     * @param string $source
1927
-     * @return bool whether we successfully reserved the ticket or not.
1928
-     * @throws EE_Error
1929
-     * @throws InvalidArgumentException
1930
-     * @throws ReflectionException
1931
-     * @throws InvalidDataTypeException
1932
-     * @throws InvalidInterfaceException
1933
-     * @deprecated 4.9.80.p
1934
-     */
1935
-    public function increase_reserved($qty = 1, $source = 'unknown')
1936
-    {
1937
-        EE_Error::doing_it_wrong(
1938
-            __FUNCTION__,
1939
-            esc_html__('Please use EE_Ticket::increaseReserved() instead', 'event_espresso'),
1940
-            '4.9.80.p',
1941
-            '5.0.0.p'
1942
-        );
1943
-        return $this->increaseReserved($qty);
1944
-    }
1945
-
1946
-
1947
-    /**
1948
-     * Increases sold on related datetimes
1949
-     *
1950
-     * @param int $qty
1951
-     * @return boolean indicating success
1952
-     * @throws EE_Error
1953
-     * @throws InvalidArgumentException
1954
-     * @throws InvalidDataTypeException
1955
-     * @throws InvalidInterfaceException
1956
-     * @throws ReflectionException
1957
-     * @deprecated 4.9.80.p
1958
-     */
1959
-    protected function _increase_reserved_for_datetimes($qty = 1)
1960
-    {
1961
-        EE_Error::doing_it_wrong(
1962
-            __FUNCTION__,
1963
-            esc_html__('Please use EE_Ticket::increaseReservedForDatetimes() instead', 'event_espresso'),
1964
-            '4.9.80.p',
1965
-            '5.0.0.p'
1966
-        );
1967
-        return $this->increaseReservedForDatetimes($qty);
1968
-    }
1969
-
1970
-
1971
-    /**
1972
-     * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database.
1973
-     *
1974
-     * @param int    $qty
1975
-     * @param bool   $adjust_datetimes
1976
-     * @param string $source
1977
-     * @return void
1978
-     * @throws EE_Error
1979
-     * @throws InvalidArgumentException
1980
-     * @throws ReflectionException
1981
-     * @throws InvalidDataTypeException
1982
-     * @throws InvalidInterfaceException
1983
-     * @deprecated 4.9.80.p
1984
-     */
1985
-    public function decrease_reserved($qty = 1, $adjust_datetimes = true, $source = 'unknown')
1986
-    {
1987
-        EE_Error::doing_it_wrong(
1988
-            __FUNCTION__,
1989
-            esc_html__('Please use EE_Ticket::decreaseReserved() instead', 'event_espresso'),
1990
-            '4.9.80.p',
1991
-            '5.0.0.p'
1992
-        );
1993
-        $this->decreaseReserved($qty);
1994
-    }
1995
-
1996
-
1997
-    /**
1998
-     * Decreases reserved on related datetimes
1999
-     *
2000
-     * @param int $qty
2001
-     * @return void
2002
-     * @throws EE_Error
2003
-     * @throws InvalidArgumentException
2004
-     * @throws ReflectionException
2005
-     * @throws InvalidDataTypeException
2006
-     * @throws InvalidInterfaceException
2007
-     * @deprecated 4.9.80.p
2008
-     */
2009
-    protected function _decrease_reserved_for_datetimes($qty = 1)
2010
-    {
2011
-        EE_Error::doing_it_wrong(
2012
-            __FUNCTION__,
2013
-            esc_html__('Please use EE_Ticket::decreaseReservedForDatetimes() instead', 'event_espresso'),
2014
-            '4.9.80.p',
2015
-            '5.0.0.p'
2016
-        );
2017
-        $this->decreaseReservedForDatetimes($qty);
2018
-    }
1823
+	/**
1824
+	 * Increments sold by amount passed by $qty AND decrements the reserved count on both this ticket and its
1825
+	 * associated datetimes.
1826
+	 *
1827
+	 * @param int $qty
1828
+	 * @return void
1829
+	 * @throws EE_Error
1830
+	 * @throws InvalidArgumentException
1831
+	 * @throws InvalidDataTypeException
1832
+	 * @throws InvalidInterfaceException
1833
+	 * @throws ReflectionException
1834
+	 * @deprecated 4.9.80.p
1835
+	 */
1836
+	public function increase_sold($qty = 1)
1837
+	{
1838
+		EE_Error::doing_it_wrong(
1839
+			__FUNCTION__,
1840
+			esc_html__('Please use EE_Ticket::increaseSold() instead', 'event_espresso'),
1841
+			'4.9.80.p',
1842
+			'5.0.0.p'
1843
+		);
1844
+		$this->increaseSold($qty);
1845
+	}
1846
+
1847
+
1848
+	/**
1849
+	 * On each datetime related to this ticket, increases its sold count and decreases its reserved count by $qty.
1850
+	 *
1851
+	 * @param int $qty positive or negative. Positive means to increase sold counts (and decrease reserved counts),
1852
+	 *                 Negative means to decreases old counts (and increase reserved counts).
1853
+	 * @throws EE_Error
1854
+	 * @throws InvalidArgumentException
1855
+	 * @throws InvalidDataTypeException
1856
+	 * @throws InvalidInterfaceException
1857
+	 * @throws ReflectionException
1858
+	 * @deprecated 4.9.80.p
1859
+	 */
1860
+	protected function _increase_sold_for_datetimes($qty)
1861
+	{
1862
+		EE_Error::doing_it_wrong(
1863
+			__FUNCTION__,
1864
+			esc_html__('Please use EE_Ticket::increaseSoldForDatetimes() instead', 'event_espresso'),
1865
+			'4.9.80.p',
1866
+			'5.0.0.p'
1867
+		);
1868
+		$this->increaseSoldForDatetimes($qty);
1869
+	}
1870
+
1871
+
1872
+	/**
1873
+	 * Decrements (subtracts) sold by amount passed by $qty on both the ticket and its related datetimes directly in the
1874
+	 * DB and then updates the model objects.
1875
+	 * Does not affect the reserved counts.
1876
+	 *
1877
+	 * @param int $qty
1878
+	 * @return void
1879
+	 * @throws EE_Error
1880
+	 * @throws InvalidArgumentException
1881
+	 * @throws InvalidDataTypeException
1882
+	 * @throws InvalidInterfaceException
1883
+	 * @throws ReflectionException
1884
+	 * @deprecated 4.9.80.p
1885
+	 */
1886
+	public function decrease_sold($qty = 1)
1887
+	{
1888
+		EE_Error::doing_it_wrong(
1889
+			__FUNCTION__,
1890
+			esc_html__('Please use EE_Ticket::decreaseSold() instead', 'event_espresso'),
1891
+			'4.9.80.p',
1892
+			'5.0.0.p'
1893
+		);
1894
+		$this->decreaseSold($qty);
1895
+	}
1896
+
1897
+
1898
+	/**
1899
+	 * Decreases sold on related datetimes
1900
+	 *
1901
+	 * @param int $qty
1902
+	 * @return void
1903
+	 * @throws EE_Error
1904
+	 * @throws InvalidArgumentException
1905
+	 * @throws InvalidDataTypeException
1906
+	 * @throws InvalidInterfaceException
1907
+	 * @throws ReflectionException
1908
+	 * @deprecated 4.9.80.p
1909
+	 */
1910
+	protected function _decrease_sold_for_datetimes($qty = 1)
1911
+	{
1912
+		EE_Error::doing_it_wrong(
1913
+			__FUNCTION__,
1914
+			esc_html__('Please use EE_Ticket::decreaseSoldForDatetimes() instead', 'event_espresso'),
1915
+			'4.9.80.p',
1916
+			'5.0.0.p'
1917
+		);
1918
+		$this->decreaseSoldForDatetimes($qty);
1919
+	}
1920
+
1921
+
1922
+	/**
1923
+	 * Increments reserved by amount passed by $qty, and persists it immediately to the database.
1924
+	 *
1925
+	 * @param int    $qty
1926
+	 * @param string $source
1927
+	 * @return bool whether we successfully reserved the ticket or not.
1928
+	 * @throws EE_Error
1929
+	 * @throws InvalidArgumentException
1930
+	 * @throws ReflectionException
1931
+	 * @throws InvalidDataTypeException
1932
+	 * @throws InvalidInterfaceException
1933
+	 * @deprecated 4.9.80.p
1934
+	 */
1935
+	public function increase_reserved($qty = 1, $source = 'unknown')
1936
+	{
1937
+		EE_Error::doing_it_wrong(
1938
+			__FUNCTION__,
1939
+			esc_html__('Please use EE_Ticket::increaseReserved() instead', 'event_espresso'),
1940
+			'4.9.80.p',
1941
+			'5.0.0.p'
1942
+		);
1943
+		return $this->increaseReserved($qty);
1944
+	}
1945
+
1946
+
1947
+	/**
1948
+	 * Increases sold on related datetimes
1949
+	 *
1950
+	 * @param int $qty
1951
+	 * @return boolean indicating success
1952
+	 * @throws EE_Error
1953
+	 * @throws InvalidArgumentException
1954
+	 * @throws InvalidDataTypeException
1955
+	 * @throws InvalidInterfaceException
1956
+	 * @throws ReflectionException
1957
+	 * @deprecated 4.9.80.p
1958
+	 */
1959
+	protected function _increase_reserved_for_datetimes($qty = 1)
1960
+	{
1961
+		EE_Error::doing_it_wrong(
1962
+			__FUNCTION__,
1963
+			esc_html__('Please use EE_Ticket::increaseReservedForDatetimes() instead', 'event_espresso'),
1964
+			'4.9.80.p',
1965
+			'5.0.0.p'
1966
+		);
1967
+		return $this->increaseReservedForDatetimes($qty);
1968
+	}
1969
+
1970
+
1971
+	/**
1972
+	 * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database.
1973
+	 *
1974
+	 * @param int    $qty
1975
+	 * @param bool   $adjust_datetimes
1976
+	 * @param string $source
1977
+	 * @return void
1978
+	 * @throws EE_Error
1979
+	 * @throws InvalidArgumentException
1980
+	 * @throws ReflectionException
1981
+	 * @throws InvalidDataTypeException
1982
+	 * @throws InvalidInterfaceException
1983
+	 * @deprecated 4.9.80.p
1984
+	 */
1985
+	public function decrease_reserved($qty = 1, $adjust_datetimes = true, $source = 'unknown')
1986
+	{
1987
+		EE_Error::doing_it_wrong(
1988
+			__FUNCTION__,
1989
+			esc_html__('Please use EE_Ticket::decreaseReserved() instead', 'event_espresso'),
1990
+			'4.9.80.p',
1991
+			'5.0.0.p'
1992
+		);
1993
+		$this->decreaseReserved($qty);
1994
+	}
1995
+
1996
+
1997
+	/**
1998
+	 * Decreases reserved on related datetimes
1999
+	 *
2000
+	 * @param int $qty
2001
+	 * @return void
2002
+	 * @throws EE_Error
2003
+	 * @throws InvalidArgumentException
2004
+	 * @throws ReflectionException
2005
+	 * @throws InvalidDataTypeException
2006
+	 * @throws InvalidInterfaceException
2007
+	 * @deprecated 4.9.80.p
2008
+	 */
2009
+	protected function _decrease_reserved_for_datetimes($qty = 1)
2010
+	{
2011
+		EE_Error::doing_it_wrong(
2012
+			__FUNCTION__,
2013
+			esc_html__('Please use EE_Ticket::decreaseReservedForDatetimes() instead', 'event_espresso'),
2014
+			'4.9.80.p',
2015
+			'5.0.0.p'
2016
+		);
2017
+		$this->decreaseReservedForDatetimes($qty);
2018
+	}
2019 2019
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Hooks.core.php 1 patch
Indentation   +719 added lines, -719 removed lines patch added patch discarded remove patch
@@ -13,723 +13,723 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * we're just going to use this to hold the name of the caller class (child class name)
18
-     *
19
-     * @var string
20
-     */
21
-    public $caller;
22
-
23
-
24
-    /**
25
-     * this is just a flag set automatically to indicate whether we've got an extended hook class running (i.e.
26
-     * espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks).  This flag is
27
-     * used later to make sure we require the needed files.
28
-     *
29
-     * @var bool
30
-     */
31
-    protected $_extend;
32
-
33
-
34
-    /**
35
-     * child classes MUST set this property so that the page object can be loaded correctly
36
-     *
37
-     * @var string
38
-     */
39
-    protected $_name;
40
-
41
-
42
-    /**
43
-     * This is set by child classes and is an associative array of ajax hooks in the format:
44
-     * array(
45
-     *    'ajax_action_ref' => 'executing_method'; //must be public
46
-     * )
47
-     *
48
-     * @var array
49
-     */
50
-    protected $_ajax_func;
51
-
52
-
53
-    /**
54
-     * This is an array of methods that get executed on a page routes admin_init hook. Use the following format:
55
-     * array(
56
-     *    'page_route' => 'executing_method' //must be public
57
-     * )
58
-     *
59
-     * @var array
60
-     */
61
-    protected $_init_func;
62
-
63
-
64
-    /**
65
-     * This is an array of methods that output metabox content for the given page route.  Use the following format:
66
-     * array(
67
-     *    0 => array(
68
-     *        'page_route' => 'string_for_page_route', //must correspond to a page route in the class being connected
69
-     *        with (i.e. "edit_event") If this is in an array then the same params below will be used but the metabox
70
-     *        will be added to each route.
71
-     *        'func' =>  'executing_method',  //must be public (i.e. public function executing_method($post,
72
-     *        $callback_args){} ).  Note if you include callback args in the array then you need to declare them in the
73
-     *        method arguments.
74
-     *        'id' => 'identifier_for_metabox', //so it can be removed by addons (optional, class will set it
75
-     *        automatically)
76
-     *        'priority' => 'default', //default 'default' (optional)
77
-     *        'label' => __('Localized Title', 'event_espresso'),
78
-     *        'context' => 'advanced' //advanced is default (optional),
79
-     *    'callback_args' => array() //any callback args to include (optional)
80
-     * )
81
-     * Why are we indexing numerically?  Because it's possible there may be more than one metabox per page_route.
82
-     *
83
-     * @var array
84
-     */
85
-    protected $_metaboxes;
86
-
87
-
88
-    /**
89
-     * This is an array of values that indicate any metaboxes we want removed from a given page route.  Usually this is
90
-     * used when caffeinated functionality is replacing decaffeinated functionality.  Use the following format for the
91
-     * array: array(
92
-     *    0 => array(
93
-     *        'page_route' => 'string_for_page_route' //can be string or array of strings that match a page_route(s)
94
-     *        that are in the class being connected with (i.e. 'edit', or 'create_new').
95
-     *        'id' => 'identifier_for_metabox', //what the id is of the metabox being removed
96
-     *        'context' => 'normal', //the context for the metabox being removed (has to match)
97
-     *        'screen' => 'screen_id', //(optional), if not included then this class will attempt to remove the metabox
98
-     *        using the currently loaded screen object->id  however, there may be cases where you have to specify the
99
-     *        id for the screen the metabox is on.
100
-     *    )
101
-     * )
102
-     *
103
-     * @var array
104
-     */
105
-    protected $_remove_metaboxes;
106
-
107
-
108
-    /**
109
-     * This parent class takes care of loading the scripts and styles if the child class has set the properties for
110
-     * them in the following format.  Note, the first array index ('register') is for defining all the registers.  The
111
-     * second array index is for indicating what routes each script/style loads on. array(
112
-     * 'registers' => array(
113
-     *        'script_ref' => array( // if more than one script is to be loaded its best to use the 'dependency'
114
-     *        argument to link scripts together.
115
-     *            'type' => 'js' // 'js' or 'css' (defaults to js).  This tells us what type of wp_function to use
116
-     *            'url' => 'http://urltoscript.css.js',
117
-     *            'depends' => array('jquery'), //an array of dependencies for the scripts. REMEMBER, if a script has
118
-     *            already been registered elsewhere in the system.  You can just use the depends array to make sure it
119
-     *            gets loaded before the one you are setting here.
120
-     *            'footer' => TRUE //defaults to true (styles don't use this parameter)
121
-     *        ),
122
-     *    'enqueues' => array( //this time each key corresponds to the script ref followed by an array of page routes
123
-     *    the script gets enqueued on.
124
-     *        'script_ref' => array('route_one', 'route_two')
125
-     *    ),
126
-     *    'localize' => array( //this allows you to set a localize object.  Indicate which script the object is being
127
-     *    attached to and then include an array indexed by the name of the object and the array of key/value pairs for
128
-     *    the object.
129
-     *        'scrip_ref' => array(
130
-     *            'NAME_OF_JS_OBJECT' => array(
131
-     *                'translate_ref' => __('localized_string', 'event_espresso'),
132
-     *                'some_data' => 5
133
-     *            )
134
-     *        )
135
-     *    )
136
-     * )
137
-     *
138
-     * @var array
139
-     */
140
-    protected $_scripts_styles;
141
-
142
-
143
-    /**
144
-     * This is a property that will contain the current route.
145
-     *
146
-     * @var string;
147
-     */
148
-    protected $_current_route;
149
-
150
-
151
-    /**
152
-     * this optional property can be set by child classes to override the priority for the automatic action/filter hook
153
-     * loading in the `_load_routed_hooks()` method.  Please follow this format: array(
154
-     *    'wp_hook_reference' => 1
155
-     *    )
156
-     * )
157
-     *
158
-     * @var array
159
-     */
160
-    protected $_wp_action_filters_priority;
161
-
162
-
163
-    /**
164
-     * This just holds a merged array of the $_POST and $_GET vars in favor of $_POST
165
-     *
166
-     * @var array
167
-     */
168
-    protected $_req_data;
169
-
170
-
171
-    /**
172
-     * This just holds an instance of the page object for this hook
173
-     *
174
-     * @var EE_Admin_Page
175
-     */
176
-    protected $_page_object;
177
-
178
-
179
-    /**
180
-     * This holds the EE_Admin_Page object from the calling admin page that this object hooks into.
181
-     *
182
-     * @var EE_Admin_Page|EE_Admin_Page_CPT
183
-     */
184
-    protected $_adminpage_obj;
185
-
186
-
187
-    /**
188
-     * Holds EE_Registry object
189
-     *
190
-     * @var EE_Registry
191
-     */
192
-    protected $EE = null;
193
-
194
-
195
-    /**
196
-     * constructor
197
-     *
198
-     * @param EE_Admin_Page $admin_page the calling admin_page_object
199
-     */
200
-    public function __construct(EE_Admin_Page $adminpage)
201
-    {
202
-        $this->_adminpage_obj = $adminpage;
203
-        $this->_req_data = array_merge($_GET, $_POST);
204
-        $this->_set_defaults();
205
-        $this->_set_hooks_properties();
206
-        // first let's verify we're on the right page
207
-        if (
208
-            ! isset($this->_req_data['page'])
209
-            || (isset($this->_req_data['page'])
210
-                && $this->_adminpage_obj->page_slug
211
-                   != $this->_req_data['page'])
212
-        ) {
213
-            return;
214
-        } //get out nothing more to be done here.
215
-        // allow for extends to modify properties
216
-        if (method_exists($this, '_extend_properties')) {
217
-            $this->_extend_properties();
218
-        }
219
-        $this->_set_page_object();
220
-        $this->_init_hooks();
221
-        $this->_load_custom_methods();
222
-        $this->_load_routed_hooks();
223
-        add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
224
-        add_action('admin_enqueue_scripts', array($this, 'add_metaboxes'), 20);
225
-        add_action('admin_enqueue_scripts', array($this, 'remove_metaboxes'), 15);
226
-        $this->_ajax_hooks();
227
-    }
228
-
229
-
230
-    /**
231
-     * used by child classes to set the following properties:
232
-     * $_ajax_func (optional)
233
-     * $_init_func (optional)
234
-     * $_metaboxes (optional)
235
-     * $_scripts (optional)
236
-     * $_styles (optional)
237
-     * $_name (required)
238
-     * Also in this method will be registered any scripts or styles loaded on the targeted page (as indicated in the
239
-     * _scripts/_styles properties) Also children should place in this method any filters/actions that have to happen
240
-     * really early on page load (just after admin_init) if they want to have them registered for handling early.
241
-     *
242
-     * @access protected
243
-     * @abstract
244
-     * @return void
245
-     */
246
-    abstract protected function _set_hooks_properties();
247
-
248
-
249
-    /**
250
-     * The hooks for enqueue_scripts and enqueue_styles will be run in here.  Child classes need to define their
251
-     * scripts and styles in the relevant $_scripts and $_styles properties.  Child classes must have also already
252
-     * registered the scripts and styles using wp_register_script and wp_register_style functions.
253
-     *
254
-     * @access public
255
-     * @return void
256
-     */
257
-    public function enqueue_scripts_styles()
258
-    {
259
-        if (! empty($this->_scripts_styles)) {
260
-            // first let's do all the registrations
261
-            if (! isset($this->_scripts_styles['registers'])) {
262
-                $msg[] = __(
263
-                    'There is no "registers" index in the <code>$this->_scripts_styles</code> property.',
264
-                    'event_espresso'
265
-                );
266
-                $msg[] = sprintf(
267
-                    __(
268
-                        'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child',
269
-                        'event_espresso'
270
-                    ),
271
-                    '<strong>' . $this->caller . '</strong>'
272
-                );
273
-                throw new EE_Error(implode('||', $msg));
274
-            }
275
-            foreach ($this->_scripts_styles['registers'] as $ref => $details) {
276
-                $defaults = array(
277
-                    'type'    => 'js',
278
-                    'url'     => '',
279
-                    'depends' => array(),
280
-                    'version' => EVENT_ESPRESSO_VERSION,
281
-                    'footer'  => true,
282
-                );
283
-                $details = wp_parse_args($details, $defaults);
284
-                extract($details);
285
-                // let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do
286
-                $this->_scripts_styles['registers'][ $ref ]['type'] = $type;
287
-                // let's make sure we're not missing any REQUIRED parameters
288
-                if (empty($url)) {
289
-                    $msg[] = sprintf(
290
-                        __('Missing the url for the requested %s', 'event_espresso'),
291
-                        $type == 'js' ? 'script' : 'stylesheet'
292
-                    );
293
-                    $msg[] = sprintf(
294
-                        __(
295
-                            'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref',
296
-                            'event_espresso'
297
-                        ),
298
-                        '<strong>' . $this->caller . '</strong>',
299
-                        $ref
300
-                    );
301
-                    throw new EE_Error(implode('||', $msg));
302
-                }
303
-                // made it here so let's do the appropriate registration
304
-                $type == 'js'
305
-                    ? wp_register_script($ref, $url, $depends, $version, $footer)
306
-                    : wp_register_style(
307
-                        $ref,
308
-                        $url,
309
-                        $depends,
310
-                        $version
311
-                    );
312
-            }
313
-            // k now lets do the enqueues
314
-            if (! isset($this->_scripts_styles['enqueues'])) {
315
-                return;
316
-            }  //not sure if we should throw an error here or not.
317
-
318
-            foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) {
319
-                // make sure $routes is an array
320
-                $routes = (array) $routes;
321
-                if (in_array($this->_current_route, $routes)) {
322
-                    $this->_scripts_styles['registers'][ $ref ]['type'] == 'js' ? wp_enqueue_script($ref)
323
-                        : wp_enqueue_style($ref);
324
-                    // if we have a localization for the script let's do that too.
325
-                    if (isset($this->_scripts_styles['localize'][ $ref ])) {
326
-                        foreach ($this->_scripts_styles['localize'][ $ref ] as $object_name => $indexes) {
327
-                            wp_localize_script(
328
-                                $ref,
329
-                                $object_name,
330
-                                $this->_scripts_styles['localize'][ $ref ][ $object_name ]
331
-                            );
332
-                        }
333
-                    }
334
-                }
335
-            }
336
-            // let's do the deregisters
337
-            if (! isset($this->_scripts_styles['deregisters'])) {
338
-                return;
339
-            }
340
-            foreach ($this->_scripts_styles['deregisters'] as $ref => $details) {
341
-                $defaults = array(
342
-                    'type' => 'js',
343
-                );
344
-                $details = wp_parse_args($details, $defaults);
345
-                extract($details);
346
-                $type == 'js' ? wp_deregister_script($ref) : wp_deregister_style($ref);
347
-            }
348
-        }
349
-    }
350
-
351
-
352
-    /**
353
-     * just set the defaults for the hooks properties.
354
-     *
355
-     * @access private
356
-     * @return void
357
-     */
358
-    private function _set_defaults()
359
-    {
360
-        $this->_ajax_func = $this->_init_func = $this->_metaboxes = $this->_scripts = $this->_styles = $this->_wp_action_filters_priority = array();
361
-        $this->_current_route = $this->getCurrentRoute();
362
-        $this->caller = get_class($this);
363
-        $this->_extend = stripos($this->caller, 'Extend') ? true : false;
364
-    }
365
-
366
-
367
-    /**
368
-     * A helper for determining the current route.
369
-     * @return string
370
-     */
371
-    private function getCurrentRoute()
372
-    {
373
-        // list tables do something else with 'action' for bulk actions.
374
-        $action = ! empty($_REQUEST['action']) && $_REQUEST['action'] !== '-1' ? $_REQUEST['action'] : 'default';
375
-        // we set a 'route' variable in some cases where action is being used by something else.
376
-        $action = $action === 'default' && isset($_REQUEST['route']) ? $_REQUEST['route'] : $action;
377
-        return sanitize_key($action);
378
-    }
379
-
380
-
381
-    /**
382
-     * this sets the _page_object property
383
-     *
384
-     * @access protected
385
-     * @return void
386
-     */
387
-    protected function _set_page_object()
388
-    {
389
-        if ($this->_page_object instanceof EE_Admin_Page) {
390
-            return;
391
-        }
392
-        // first make sure $this->_name is set
393
-        if (empty($this->_name)) {
394
-            $msg[] = __('We can\'t load the page object', 'event_espresso');
395
-            $msg[] = sprintf(
396
-                __("This is because the %s child class has not set the '_name' property", 'event_espresso'),
397
-                $this->caller
398
-            );
399
-            throw new EE_Error(implode('||', $msg));
400
-        }
401
-        $ref = str_replace('_', ' ', $this->_name); // take the_message -> the message
402
-        $ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; // take the message -> The_Message
403
-        // first default file (if exists)
404
-        $decaf_file = EE_ADMIN_PAGES . $this->_name . '/' . $ref . '.core.php';
405
-        if (is_readable($decaf_file)) {
406
-            require_once($decaf_file);
407
-        }
408
-        // now we have to do require for extended file (if needed)
409
-        if ($this->_extend) {
410
-            require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . '/Extend_' . $ref . '.core.php');
411
-        }
412
-        // if we've got an extended class we use that!
413
-        $ref = $this->_extend ? 'Extend_' . $ref : $ref;
414
-        // let's make sure the class exists
415
-        if (! class_exists($ref)) {
416
-            $msg[] = __('We can\'t load the page object', 'event_espresso');
417
-            $msg[] = sprintf(
418
-                __(
419
-                    'The class name that was given is %s. Check the spelling and make sure its correct, also there needs to be an autoloader setup for the class',
420
-                    'event_espresso'
421
-                ),
422
-                $ref
423
-            );
424
-            throw new EE_Error(implode('||', $msg));
425
-        }
426
-        $a = new ReflectionClass($ref);
427
-        $this->_page_object = $a->newInstance(false);
428
-        $this->_page_object->initializePage();
429
-    }
430
-
431
-
432
-    /**
433
-     * Child "hook" classes can declare any methods that they want executed when a specific page route is loaded.  The
434
-     * advantage of this is when doing things like running our own db interactions on saves etc.  Remember that
435
-     * $this->_req_data (all the _POST and _GET data) is available to your methods.
436
-     *
437
-     * @access private
438
-     * @return void
439
-     */
440
-    private function _load_custom_methods()
441
-    {
442
-        /**
443
-         * method cannot be named 'default' (@see http://us3.php
444
-         * .net/manual/en/reserved.keywords.php) so need to
445
-         * handle routes that are "default"
446
-         *
447
-         * @since 4.3.0
448
-         */
449
-        $method_callback = $this->_current_route == 'default' ? 'default_callback' : $this->_current_route;
450
-        // these run before the Admin_Page route executes.
451
-        if (method_exists($this, $method_callback)) {
452
-            call_user_func(array($this, $method_callback));
453
-        }
454
-        // these run via the _redirect_after_action method in EE_Admin_Page which usually happens after non_UI methods in EE_Admin_Page classes.  There are two redirect actions, the first fires before $query_args might be manipulated by "save and close" actions and the seond fires right before the actual redirect happens.
455
-        // first the actions
456
-        // note that these action hooks will have the $query_args value available.
457
-        $admin_class_name = get_class($this->_adminpage_obj);
458
-        if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) {
459
-            add_action(
460
-                'AHEE__'
461
-                . $admin_class_name
462
-                . '___redirect_after_action__before_redirect_modification_'
463
-                . $this->_current_route,
464
-                array($this, '_redirect_action_early_' . $this->_current_route),
465
-                10
466
-            );
467
-        }
468
-        if (method_exists($this, '_redirect_action_' . $this->_current_route)) {
469
-            add_action(
470
-                'AHEE_redirect_' . $admin_class_name . $this->_current_route,
471
-                array($this, '_redirect_action_' . $this->_current_route),
472
-                10
473
-            );
474
-        }
475
-        // let's hook into the _redirect itself and allow for changing where the user goes after redirect.  This will have $query_args and $redirect_url available.
476
-        if (method_exists($this, '_redirect_filter_' . $this->_current_route)) {
477
-            add_filter(
478
-                'FHEE_redirect_' . $admin_class_name . $this->_current_route,
479
-                array($this, '_redirect_filter_' . $this->_current_route),
480
-                10,
481
-                2
482
-            );
483
-        }
484
-    }
485
-
486
-
487
-    /**
488
-     * This method will search for a corresponding method with a name matching the route and the wp_hook to run.  This
489
-     * allows child hook classes to target hooking into a specific wp action or filter hook ONLY on a certain route.
490
-     * just remember, methods MUST be public Future hooks should be added in here to be access by child classes.
491
-     *
492
-     * @return void
493
-     */
494
-    private function _load_routed_hooks()
495
-    {
496
-
497
-        // this array provides the hook action names that will be referenced.  Key is the action. Value is an array with the type (action or filter) and the number of parameters for the hook.  We'll default all priorities for automatic hooks to 10.
498
-        $hook_filter_array = array(
499
-            'admin_footer'                                                                            => array(
500
-                'type'     => 'action',
501
-                'argnum'   => 1,
502
-                'priority' => 10,
503
-            ),
504
-            'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array(
505
-                'type'     => 'filter',
506
-                'argnum'   => 1,
507
-                'priority' => 10,
508
-            ),
509
-            'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug                               => array(
510
-                'type'     => 'filter',
511
-                'argnum'   => 1,
512
-                'priority' => 10,
513
-            ),
514
-            'FHEE_list_table_views'                                                                   => array(
515
-                'type'     => 'filter',
516
-                'argnum'   => 1,
517
-                'priority' => 10,
518
-            ),
519
-            'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'                              => array(
520
-                'type'     => 'action',
521
-                'argnum'   => 1,
522
-                'priority' => 10,
523
-            ),
524
-        );
525
-        foreach ($hook_filter_array as $hook => $args) {
526
-            if (method_exists($this, $this->_current_route . '_' . $hook)) {
527
-                if (isset($this->_wp_action_filters_priority[ $hook ])) {
528
-                    $args['priority'] = $this->_wp_action_filters_priority[ $hook ];
529
-                }
530
-                if ($args['type'] == 'action') {
531
-                    add_action(
532
-                        $hook,
533
-                        array($this, $this->_current_route . '_' . $hook),
534
-                        $args['priority'],
535
-                        $args['argnum']
536
-                    );
537
-                } else {
538
-                    add_filter(
539
-                        $hook,
540
-                        array($this, $this->_current_route . '_' . $hook),
541
-                        $args['priority'],
542
-                        $args['argnum']
543
-                    );
544
-                }
545
-            }
546
-        }
547
-    }
548
-
549
-
550
-    /**
551
-     * Loop throught the $_ajax_func array and add_actions for the array.
552
-     *
553
-     * @return void
554
-     */
555
-    private function _ajax_hooks()
556
-    {
557
-        if (empty($this->_ajax_func)) {
558
-            return;
559
-        } //get out there's nothing to take care of.
560
-        foreach ($this->_ajax_func as $action => $method) {
561
-            // make sure method exists
562
-            if (! method_exists($this, $method)) {
563
-                $msg[] = __(
564
-                    'There is no corresponding method for the hook labeled in the _ajax_func array',
565
-                    'event_espresso'
566
-                ) . '<br />';
567
-                $msg[] = sprintf(
568
-                    __(
569
-                        'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
570
-                        'event_espresso'
571
-                    ),
572
-                    $method,
573
-                    $this->caller
574
-                );
575
-                throw new EE_Error(implode('||', $msg));
576
-            }
577
-            add_action('wp_ajax_' . $action, array($this, $method));
578
-        }
579
-    }
580
-
581
-
582
-    /**
583
-     * Loop throught the $_init_func array and add_actions for the array.
584
-     *
585
-     * @return void
586
-     */
587
-    protected function _init_hooks()
588
-    {
589
-        if (empty($this->_init_func)) {
590
-            return;
591
-        } //get out there's nothing to take care of.
592
-        // We need to determine what page_route we are on!
593
-        $current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default';
594
-        foreach ($this->_init_func as $route => $method) {
595
-            // make sure method exists
596
-            if (! method_exists($this, $method)) {
597
-                $msg[] = __(
598
-                    'There is no corresponding method for the hook labeled in the _init_func array',
599
-                    'event_espresso'
600
-                ) . '<br />';
601
-                $msg[] = sprintf(
602
-                    __(
603
-                        'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
604
-                        'event_espresso'
605
-                    ),
606
-                    $method,
607
-                    $this->caller
608
-                );
609
-                throw new EE_Error(implode('||', $msg));
610
-            }
611
-            if ($route == $this->_current_route) {
612
-                add_action('admin_init', array($this, $method));
613
-            }
614
-        }
615
-    }
616
-
617
-
618
-    /**
619
-     * Loop through the _metaboxes property and add_metaboxes accordingly
620
-     * //todo we could eventually make this a config component class (i.e. new EE_Metabox);
621
-     *
622
-     * @access public
623
-     * @return void
624
-     */
625
-    public function add_metaboxes()
626
-    {
627
-        if (empty($this->_metaboxes)) {
628
-            return;
629
-        } //get out we don't have any metaboxes to set for this connection
630
-        $this->_handle_metabox_array($this->_metaboxes);
631
-    }
632
-
633
-
634
-    private function _handle_metabox_array($boxes, $add = true)
635
-    {
636
-        foreach ($boxes as $box) {
637
-            if (! isset($box['page_route'])) {
638
-                continue;
639
-            } //we dont' have a valid array
640
-            // let's make sure $box['page_route'] is an array so the "foreach" will work.
641
-            $box['page_route'] = (array) $box['page_route'];
642
-            foreach ($box['page_route'] as $route) {
643
-                if ($route != $this->_current_route) {
644
-                    continue;
645
-                } //get out we only add metaboxes for set route.
646
-                if ($add) {
647
-                    $this->_add_metabox($box);
648
-                } else {
649
-                    $this->_remove_metabox($box);
650
-                }
651
-            }
652
-        }
653
-    }
654
-
655
-
656
-    /**
657
-     * Loop through the _remove_metaboxes property and remove metaboxes accordingly.
658
-     *
659
-     * @access public
660
-     * @return void
661
-     */
662
-    public function remove_metaboxes()
663
-    {
664
-        if (empty($this->_remove_metaboxes)) {
665
-            return;
666
-        } //get out there are no metaboxes to remove
667
-        $this->_handle_metabox_array($this->_remove_metaboxes, false);
668
-    }
669
-
670
-
671
-    /**
672
-     * This just handles adding a metabox
673
-     *
674
-     * @access private
675
-     * @param array $args an array of args that have been set for this metabox by the child class
676
-     */
677
-    private function _add_metabox($args)
678
-    {
679
-        $current_screen = get_current_screen();
680
-        $screen_id = is_object($current_screen) ? $current_screen->id : null;
681
-        $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback';
682
-        // set defaults
683
-        $defaults = array(
684
-            'func'          => $func,
685
-            'id'            => $this->caller . '_' . $func . '_metabox',
686
-            'priority'      => 'default',
687
-            'label'         => $this->caller,
688
-            'context'       => 'advanced',
689
-            'callback_args' => array(),
690
-            'page'          => isset($args['page']) ? $args['page'] : $screen_id,
691
-        );
692
-        $args = wp_parse_args($args, $defaults);
693
-        extract($args);
694
-        // make sure method exists
695
-        if (! method_exists($this, $func)) {
696
-            $msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />';
697
-            $msg[] = sprintf(
698
-                __(
699
-                    'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
700
-                    'event_espresso'
701
-                ),
702
-                $func,
703
-                $this->caller
704
-            );
705
-            throw new EE_Error(implode('||', $msg));
706
-        }
707
-        // everything checks out so lets add the metabox
708
-        add_meta_box($id, $label, array($this, $func), $page, $context, $priority, $callback_args);
709
-    }
710
-
711
-
712
-    private function _remove_metabox($args)
713
-    {
714
-        $current_screen = get_current_screen();
715
-        $screen_id = is_object($current_screen) ? $current_screen->id : null;
716
-        $func = isset($args['func']) ? $args['func'] : 'some_invalid_callback';
717
-        // set defaults
718
-        $defaults = array(
719
-            'id'      => isset($args['id'])
720
-                ? $args['id']
721
-                : $this->_current_route
722
-                  . '_'
723
-                  . $this->caller
724
-                  . '_'
725
-                  . $func
726
-                  . '_metabox',
727
-            'context' => 'default',
728
-            'screen'  => isset($args['screen']) ? $args['screen'] : $screen_id,
729
-        );
730
-        $args = wp_parse_args($args, $defaults);
731
-        extract($args);
732
-        // everything checks out so lets remove the box!
733
-        remove_meta_box($id, $screen, $context);
734
-    }
16
+	/**
17
+	 * we're just going to use this to hold the name of the caller class (child class name)
18
+	 *
19
+	 * @var string
20
+	 */
21
+	public $caller;
22
+
23
+
24
+	/**
25
+	 * this is just a flag set automatically to indicate whether we've got an extended hook class running (i.e.
26
+	 * espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks).  This flag is
27
+	 * used later to make sure we require the needed files.
28
+	 *
29
+	 * @var bool
30
+	 */
31
+	protected $_extend;
32
+
33
+
34
+	/**
35
+	 * child classes MUST set this property so that the page object can be loaded correctly
36
+	 *
37
+	 * @var string
38
+	 */
39
+	protected $_name;
40
+
41
+
42
+	/**
43
+	 * This is set by child classes and is an associative array of ajax hooks in the format:
44
+	 * array(
45
+	 *    'ajax_action_ref' => 'executing_method'; //must be public
46
+	 * )
47
+	 *
48
+	 * @var array
49
+	 */
50
+	protected $_ajax_func;
51
+
52
+
53
+	/**
54
+	 * This is an array of methods that get executed on a page routes admin_init hook. Use the following format:
55
+	 * array(
56
+	 *    'page_route' => 'executing_method' //must be public
57
+	 * )
58
+	 *
59
+	 * @var array
60
+	 */
61
+	protected $_init_func;
62
+
63
+
64
+	/**
65
+	 * This is an array of methods that output metabox content for the given page route.  Use the following format:
66
+	 * array(
67
+	 *    0 => array(
68
+	 *        'page_route' => 'string_for_page_route', //must correspond to a page route in the class being connected
69
+	 *        with (i.e. "edit_event") If this is in an array then the same params below will be used but the metabox
70
+	 *        will be added to each route.
71
+	 *        'func' =>  'executing_method',  //must be public (i.e. public function executing_method($post,
72
+	 *        $callback_args){} ).  Note if you include callback args in the array then you need to declare them in the
73
+	 *        method arguments.
74
+	 *        'id' => 'identifier_for_metabox', //so it can be removed by addons (optional, class will set it
75
+	 *        automatically)
76
+	 *        'priority' => 'default', //default 'default' (optional)
77
+	 *        'label' => __('Localized Title', 'event_espresso'),
78
+	 *        'context' => 'advanced' //advanced is default (optional),
79
+	 *    'callback_args' => array() //any callback args to include (optional)
80
+	 * )
81
+	 * Why are we indexing numerically?  Because it's possible there may be more than one metabox per page_route.
82
+	 *
83
+	 * @var array
84
+	 */
85
+	protected $_metaboxes;
86
+
87
+
88
+	/**
89
+	 * This is an array of values that indicate any metaboxes we want removed from a given page route.  Usually this is
90
+	 * used when caffeinated functionality is replacing decaffeinated functionality.  Use the following format for the
91
+	 * array: array(
92
+	 *    0 => array(
93
+	 *        'page_route' => 'string_for_page_route' //can be string or array of strings that match a page_route(s)
94
+	 *        that are in the class being connected with (i.e. 'edit', or 'create_new').
95
+	 *        'id' => 'identifier_for_metabox', //what the id is of the metabox being removed
96
+	 *        'context' => 'normal', //the context for the metabox being removed (has to match)
97
+	 *        'screen' => 'screen_id', //(optional), if not included then this class will attempt to remove the metabox
98
+	 *        using the currently loaded screen object->id  however, there may be cases where you have to specify the
99
+	 *        id for the screen the metabox is on.
100
+	 *    )
101
+	 * )
102
+	 *
103
+	 * @var array
104
+	 */
105
+	protected $_remove_metaboxes;
106
+
107
+
108
+	/**
109
+	 * This parent class takes care of loading the scripts and styles if the child class has set the properties for
110
+	 * them in the following format.  Note, the first array index ('register') is for defining all the registers.  The
111
+	 * second array index is for indicating what routes each script/style loads on. array(
112
+	 * 'registers' => array(
113
+	 *        'script_ref' => array( // if more than one script is to be loaded its best to use the 'dependency'
114
+	 *        argument to link scripts together.
115
+	 *            'type' => 'js' // 'js' or 'css' (defaults to js).  This tells us what type of wp_function to use
116
+	 *            'url' => 'http://urltoscript.css.js',
117
+	 *            'depends' => array('jquery'), //an array of dependencies for the scripts. REMEMBER, if a script has
118
+	 *            already been registered elsewhere in the system.  You can just use the depends array to make sure it
119
+	 *            gets loaded before the one you are setting here.
120
+	 *            'footer' => TRUE //defaults to true (styles don't use this parameter)
121
+	 *        ),
122
+	 *    'enqueues' => array( //this time each key corresponds to the script ref followed by an array of page routes
123
+	 *    the script gets enqueued on.
124
+	 *        'script_ref' => array('route_one', 'route_two')
125
+	 *    ),
126
+	 *    'localize' => array( //this allows you to set a localize object.  Indicate which script the object is being
127
+	 *    attached to and then include an array indexed by the name of the object and the array of key/value pairs for
128
+	 *    the object.
129
+	 *        'scrip_ref' => array(
130
+	 *            'NAME_OF_JS_OBJECT' => array(
131
+	 *                'translate_ref' => __('localized_string', 'event_espresso'),
132
+	 *                'some_data' => 5
133
+	 *            )
134
+	 *        )
135
+	 *    )
136
+	 * )
137
+	 *
138
+	 * @var array
139
+	 */
140
+	protected $_scripts_styles;
141
+
142
+
143
+	/**
144
+	 * This is a property that will contain the current route.
145
+	 *
146
+	 * @var string;
147
+	 */
148
+	protected $_current_route;
149
+
150
+
151
+	/**
152
+	 * this optional property can be set by child classes to override the priority for the automatic action/filter hook
153
+	 * loading in the `_load_routed_hooks()` method.  Please follow this format: array(
154
+	 *    'wp_hook_reference' => 1
155
+	 *    )
156
+	 * )
157
+	 *
158
+	 * @var array
159
+	 */
160
+	protected $_wp_action_filters_priority;
161
+
162
+
163
+	/**
164
+	 * This just holds a merged array of the $_POST and $_GET vars in favor of $_POST
165
+	 *
166
+	 * @var array
167
+	 */
168
+	protected $_req_data;
169
+
170
+
171
+	/**
172
+	 * This just holds an instance of the page object for this hook
173
+	 *
174
+	 * @var EE_Admin_Page
175
+	 */
176
+	protected $_page_object;
177
+
178
+
179
+	/**
180
+	 * This holds the EE_Admin_Page object from the calling admin page that this object hooks into.
181
+	 *
182
+	 * @var EE_Admin_Page|EE_Admin_Page_CPT
183
+	 */
184
+	protected $_adminpage_obj;
185
+
186
+
187
+	/**
188
+	 * Holds EE_Registry object
189
+	 *
190
+	 * @var EE_Registry
191
+	 */
192
+	protected $EE = null;
193
+
194
+
195
+	/**
196
+	 * constructor
197
+	 *
198
+	 * @param EE_Admin_Page $admin_page the calling admin_page_object
199
+	 */
200
+	public function __construct(EE_Admin_Page $adminpage)
201
+	{
202
+		$this->_adminpage_obj = $adminpage;
203
+		$this->_req_data = array_merge($_GET, $_POST);
204
+		$this->_set_defaults();
205
+		$this->_set_hooks_properties();
206
+		// first let's verify we're on the right page
207
+		if (
208
+			! isset($this->_req_data['page'])
209
+			|| (isset($this->_req_data['page'])
210
+				&& $this->_adminpage_obj->page_slug
211
+				   != $this->_req_data['page'])
212
+		) {
213
+			return;
214
+		} //get out nothing more to be done here.
215
+		// allow for extends to modify properties
216
+		if (method_exists($this, '_extend_properties')) {
217
+			$this->_extend_properties();
218
+		}
219
+		$this->_set_page_object();
220
+		$this->_init_hooks();
221
+		$this->_load_custom_methods();
222
+		$this->_load_routed_hooks();
223
+		add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts_styles'));
224
+		add_action('admin_enqueue_scripts', array($this, 'add_metaboxes'), 20);
225
+		add_action('admin_enqueue_scripts', array($this, 'remove_metaboxes'), 15);
226
+		$this->_ajax_hooks();
227
+	}
228
+
229
+
230
+	/**
231
+	 * used by child classes to set the following properties:
232
+	 * $_ajax_func (optional)
233
+	 * $_init_func (optional)
234
+	 * $_metaboxes (optional)
235
+	 * $_scripts (optional)
236
+	 * $_styles (optional)
237
+	 * $_name (required)
238
+	 * Also in this method will be registered any scripts or styles loaded on the targeted page (as indicated in the
239
+	 * _scripts/_styles properties) Also children should place in this method any filters/actions that have to happen
240
+	 * really early on page load (just after admin_init) if they want to have them registered for handling early.
241
+	 *
242
+	 * @access protected
243
+	 * @abstract
244
+	 * @return void
245
+	 */
246
+	abstract protected function _set_hooks_properties();
247
+
248
+
249
+	/**
250
+	 * The hooks for enqueue_scripts and enqueue_styles will be run in here.  Child classes need to define their
251
+	 * scripts and styles in the relevant $_scripts and $_styles properties.  Child classes must have also already
252
+	 * registered the scripts and styles using wp_register_script and wp_register_style functions.
253
+	 *
254
+	 * @access public
255
+	 * @return void
256
+	 */
257
+	public function enqueue_scripts_styles()
258
+	{
259
+		if (! empty($this->_scripts_styles)) {
260
+			// first let's do all the registrations
261
+			if (! isset($this->_scripts_styles['registers'])) {
262
+				$msg[] = __(
263
+					'There is no "registers" index in the <code>$this->_scripts_styles</code> property.',
264
+					'event_espresso'
265
+				);
266
+				$msg[] = sprintf(
267
+					__(
268
+						'Make sure you read the phpdoc comments above the definition of the $_scripts_styles property in the <code>EE_Admin_Hooks</code> class and modify according in the %s child',
269
+						'event_espresso'
270
+					),
271
+					'<strong>' . $this->caller . '</strong>'
272
+				);
273
+				throw new EE_Error(implode('||', $msg));
274
+			}
275
+			foreach ($this->_scripts_styles['registers'] as $ref => $details) {
276
+				$defaults = array(
277
+					'type'    => 'js',
278
+					'url'     => '',
279
+					'depends' => array(),
280
+					'version' => EVENT_ESPRESSO_VERSION,
281
+					'footer'  => true,
282
+				);
283
+				$details = wp_parse_args($details, $defaults);
284
+				extract($details);
285
+				// let's make sure that we set the 'registers' type if it's not set! We need it later to determine whhich enqueu we do
286
+				$this->_scripts_styles['registers'][ $ref ]['type'] = $type;
287
+				// let's make sure we're not missing any REQUIRED parameters
288
+				if (empty($url)) {
289
+					$msg[] = sprintf(
290
+						__('Missing the url for the requested %s', 'event_espresso'),
291
+						$type == 'js' ? 'script' : 'stylesheet'
292
+					);
293
+					$msg[] = sprintf(
294
+						__(
295
+							'Doublecheck your <code>$this->_scripts_styles</code> array in %s and make sure that there is a "url" set for the %s ref',
296
+							'event_espresso'
297
+						),
298
+						'<strong>' . $this->caller . '</strong>',
299
+						$ref
300
+					);
301
+					throw new EE_Error(implode('||', $msg));
302
+				}
303
+				// made it here so let's do the appropriate registration
304
+				$type == 'js'
305
+					? wp_register_script($ref, $url, $depends, $version, $footer)
306
+					: wp_register_style(
307
+						$ref,
308
+						$url,
309
+						$depends,
310
+						$version
311
+					);
312
+			}
313
+			// k now lets do the enqueues
314
+			if (! isset($this->_scripts_styles['enqueues'])) {
315
+				return;
316
+			}  //not sure if we should throw an error here or not.
317
+
318
+			foreach ($this->_scripts_styles['enqueues'] as $ref => $routes) {
319
+				// make sure $routes is an array
320
+				$routes = (array) $routes;
321
+				if (in_array($this->_current_route, $routes)) {
322
+					$this->_scripts_styles['registers'][ $ref ]['type'] == 'js' ? wp_enqueue_script($ref)
323
+						: wp_enqueue_style($ref);
324
+					// if we have a localization for the script let's do that too.
325
+					if (isset($this->_scripts_styles['localize'][ $ref ])) {
326
+						foreach ($this->_scripts_styles['localize'][ $ref ] as $object_name => $indexes) {
327
+							wp_localize_script(
328
+								$ref,
329
+								$object_name,
330
+								$this->_scripts_styles['localize'][ $ref ][ $object_name ]
331
+							);
332
+						}
333
+					}
334
+				}
335
+			}
336
+			// let's do the deregisters
337
+			if (! isset($this->_scripts_styles['deregisters'])) {
338
+				return;
339
+			}
340
+			foreach ($this->_scripts_styles['deregisters'] as $ref => $details) {
341
+				$defaults = array(
342
+					'type' => 'js',
343
+				);
344
+				$details = wp_parse_args($details, $defaults);
345
+				extract($details);
346
+				$type == 'js' ? wp_deregister_script($ref) : wp_deregister_style($ref);
347
+			}
348
+		}
349
+	}
350
+
351
+
352
+	/**
353
+	 * just set the defaults for the hooks properties.
354
+	 *
355
+	 * @access private
356
+	 * @return void
357
+	 */
358
+	private function _set_defaults()
359
+	{
360
+		$this->_ajax_func = $this->_init_func = $this->_metaboxes = $this->_scripts = $this->_styles = $this->_wp_action_filters_priority = array();
361
+		$this->_current_route = $this->getCurrentRoute();
362
+		$this->caller = get_class($this);
363
+		$this->_extend = stripos($this->caller, 'Extend') ? true : false;
364
+	}
365
+
366
+
367
+	/**
368
+	 * A helper for determining the current route.
369
+	 * @return string
370
+	 */
371
+	private function getCurrentRoute()
372
+	{
373
+		// list tables do something else with 'action' for bulk actions.
374
+		$action = ! empty($_REQUEST['action']) && $_REQUEST['action'] !== '-1' ? $_REQUEST['action'] : 'default';
375
+		// we set a 'route' variable in some cases where action is being used by something else.
376
+		$action = $action === 'default' && isset($_REQUEST['route']) ? $_REQUEST['route'] : $action;
377
+		return sanitize_key($action);
378
+	}
379
+
380
+
381
+	/**
382
+	 * this sets the _page_object property
383
+	 *
384
+	 * @access protected
385
+	 * @return void
386
+	 */
387
+	protected function _set_page_object()
388
+	{
389
+		if ($this->_page_object instanceof EE_Admin_Page) {
390
+			return;
391
+		}
392
+		// first make sure $this->_name is set
393
+		if (empty($this->_name)) {
394
+			$msg[] = __('We can\'t load the page object', 'event_espresso');
395
+			$msg[] = sprintf(
396
+				__("This is because the %s child class has not set the '_name' property", 'event_espresso'),
397
+				$this->caller
398
+			);
399
+			throw new EE_Error(implode('||', $msg));
400
+		}
401
+		$ref = str_replace('_', ' ', $this->_name); // take the_message -> the message
402
+		$ref = str_replace(' ', '_', ucwords($ref)) . '_Admin_Page'; // take the message -> The_Message
403
+		// first default file (if exists)
404
+		$decaf_file = EE_ADMIN_PAGES . $this->_name . '/' . $ref . '.core.php';
405
+		if (is_readable($decaf_file)) {
406
+			require_once($decaf_file);
407
+		}
408
+		// now we have to do require for extended file (if needed)
409
+		if ($this->_extend) {
410
+			require_once(EE_CORE_CAF_ADMIN_EXTEND . $this->_name . '/Extend_' . $ref . '.core.php');
411
+		}
412
+		// if we've got an extended class we use that!
413
+		$ref = $this->_extend ? 'Extend_' . $ref : $ref;
414
+		// let's make sure the class exists
415
+		if (! class_exists($ref)) {
416
+			$msg[] = __('We can\'t load the page object', 'event_espresso');
417
+			$msg[] = sprintf(
418
+				__(
419
+					'The class name that was given is %s. Check the spelling and make sure its correct, also there needs to be an autoloader setup for the class',
420
+					'event_espresso'
421
+				),
422
+				$ref
423
+			);
424
+			throw new EE_Error(implode('||', $msg));
425
+		}
426
+		$a = new ReflectionClass($ref);
427
+		$this->_page_object = $a->newInstance(false);
428
+		$this->_page_object->initializePage();
429
+	}
430
+
431
+
432
+	/**
433
+	 * Child "hook" classes can declare any methods that they want executed when a specific page route is loaded.  The
434
+	 * advantage of this is when doing things like running our own db interactions on saves etc.  Remember that
435
+	 * $this->_req_data (all the _POST and _GET data) is available to your methods.
436
+	 *
437
+	 * @access private
438
+	 * @return void
439
+	 */
440
+	private function _load_custom_methods()
441
+	{
442
+		/**
443
+		 * method cannot be named 'default' (@see http://us3.php
444
+		 * .net/manual/en/reserved.keywords.php) so need to
445
+		 * handle routes that are "default"
446
+		 *
447
+		 * @since 4.3.0
448
+		 */
449
+		$method_callback = $this->_current_route == 'default' ? 'default_callback' : $this->_current_route;
450
+		// these run before the Admin_Page route executes.
451
+		if (method_exists($this, $method_callback)) {
452
+			call_user_func(array($this, $method_callback));
453
+		}
454
+		// these run via the _redirect_after_action method in EE_Admin_Page which usually happens after non_UI methods in EE_Admin_Page classes.  There are two redirect actions, the first fires before $query_args might be manipulated by "save and close" actions and the seond fires right before the actual redirect happens.
455
+		// first the actions
456
+		// note that these action hooks will have the $query_args value available.
457
+		$admin_class_name = get_class($this->_adminpage_obj);
458
+		if (method_exists($this, '_redirect_action_early_' . $this->_current_route)) {
459
+			add_action(
460
+				'AHEE__'
461
+				. $admin_class_name
462
+				. '___redirect_after_action__before_redirect_modification_'
463
+				. $this->_current_route,
464
+				array($this, '_redirect_action_early_' . $this->_current_route),
465
+				10
466
+			);
467
+		}
468
+		if (method_exists($this, '_redirect_action_' . $this->_current_route)) {
469
+			add_action(
470
+				'AHEE_redirect_' . $admin_class_name . $this->_current_route,
471
+				array($this, '_redirect_action_' . $this->_current_route),
472
+				10
473
+			);
474
+		}
475
+		// let's hook into the _redirect itself and allow for changing where the user goes after redirect.  This will have $query_args and $redirect_url available.
476
+		if (method_exists($this, '_redirect_filter_' . $this->_current_route)) {
477
+			add_filter(
478
+				'FHEE_redirect_' . $admin_class_name . $this->_current_route,
479
+				array($this, '_redirect_filter_' . $this->_current_route),
480
+				10,
481
+				2
482
+			);
483
+		}
484
+	}
485
+
486
+
487
+	/**
488
+	 * This method will search for a corresponding method with a name matching the route and the wp_hook to run.  This
489
+	 * allows child hook classes to target hooking into a specific wp action or filter hook ONLY on a certain route.
490
+	 * just remember, methods MUST be public Future hooks should be added in here to be access by child classes.
491
+	 *
492
+	 * @return void
493
+	 */
494
+	private function _load_routed_hooks()
495
+	{
496
+
497
+		// this array provides the hook action names that will be referenced.  Key is the action. Value is an array with the type (action or filter) and the number of parameters for the hook.  We'll default all priorities for automatic hooks to 10.
498
+		$hook_filter_array = array(
499
+			'admin_footer'                                                                            => array(
500
+				'type'     => 'action',
501
+				'argnum'   => 1,
502
+				'priority' => 10,
503
+			),
504
+			'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug . '_' . $this->_current_route => array(
505
+				'type'     => 'filter',
506
+				'argnum'   => 1,
507
+				'priority' => 10,
508
+			),
509
+			'FHEE_list_table_views_' . $this->_adminpage_obj->page_slug                               => array(
510
+				'type'     => 'filter',
511
+				'argnum'   => 1,
512
+				'priority' => 10,
513
+			),
514
+			'FHEE_list_table_views'                                                                   => array(
515
+				'type'     => 'filter',
516
+				'argnum'   => 1,
517
+				'priority' => 10,
518
+			),
519
+			'AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes'                              => array(
520
+				'type'     => 'action',
521
+				'argnum'   => 1,
522
+				'priority' => 10,
523
+			),
524
+		);
525
+		foreach ($hook_filter_array as $hook => $args) {
526
+			if (method_exists($this, $this->_current_route . '_' . $hook)) {
527
+				if (isset($this->_wp_action_filters_priority[ $hook ])) {
528
+					$args['priority'] = $this->_wp_action_filters_priority[ $hook ];
529
+				}
530
+				if ($args['type'] == 'action') {
531
+					add_action(
532
+						$hook,
533
+						array($this, $this->_current_route . '_' . $hook),
534
+						$args['priority'],
535
+						$args['argnum']
536
+					);
537
+				} else {
538
+					add_filter(
539
+						$hook,
540
+						array($this, $this->_current_route . '_' . $hook),
541
+						$args['priority'],
542
+						$args['argnum']
543
+					);
544
+				}
545
+			}
546
+		}
547
+	}
548
+
549
+
550
+	/**
551
+	 * Loop throught the $_ajax_func array and add_actions for the array.
552
+	 *
553
+	 * @return void
554
+	 */
555
+	private function _ajax_hooks()
556
+	{
557
+		if (empty($this->_ajax_func)) {
558
+			return;
559
+		} //get out there's nothing to take care of.
560
+		foreach ($this->_ajax_func as $action => $method) {
561
+			// make sure method exists
562
+			if (! method_exists($this, $method)) {
563
+				$msg[] = __(
564
+					'There is no corresponding method for the hook labeled in the _ajax_func array',
565
+					'event_espresso'
566
+				) . '<br />';
567
+				$msg[] = sprintf(
568
+					__(
569
+						'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
570
+						'event_espresso'
571
+					),
572
+					$method,
573
+					$this->caller
574
+				);
575
+				throw new EE_Error(implode('||', $msg));
576
+			}
577
+			add_action('wp_ajax_' . $action, array($this, $method));
578
+		}
579
+	}
580
+
581
+
582
+	/**
583
+	 * Loop throught the $_init_func array and add_actions for the array.
584
+	 *
585
+	 * @return void
586
+	 */
587
+	protected function _init_hooks()
588
+	{
589
+		if (empty($this->_init_func)) {
590
+			return;
591
+		} //get out there's nothing to take care of.
592
+		// We need to determine what page_route we are on!
593
+		$current_route = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default';
594
+		foreach ($this->_init_func as $route => $method) {
595
+			// make sure method exists
596
+			if (! method_exists($this, $method)) {
597
+				$msg[] = __(
598
+					'There is no corresponding method for the hook labeled in the _init_func array',
599
+					'event_espresso'
600
+				) . '<br />';
601
+				$msg[] = sprintf(
602
+					__(
603
+						'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
604
+						'event_espresso'
605
+					),
606
+					$method,
607
+					$this->caller
608
+				);
609
+				throw new EE_Error(implode('||', $msg));
610
+			}
611
+			if ($route == $this->_current_route) {
612
+				add_action('admin_init', array($this, $method));
613
+			}
614
+		}
615
+	}
616
+
617
+
618
+	/**
619
+	 * Loop through the _metaboxes property and add_metaboxes accordingly
620
+	 * //todo we could eventually make this a config component class (i.e. new EE_Metabox);
621
+	 *
622
+	 * @access public
623
+	 * @return void
624
+	 */
625
+	public function add_metaboxes()
626
+	{
627
+		if (empty($this->_metaboxes)) {
628
+			return;
629
+		} //get out we don't have any metaboxes to set for this connection
630
+		$this->_handle_metabox_array($this->_metaboxes);
631
+	}
632
+
633
+
634
+	private function _handle_metabox_array($boxes, $add = true)
635
+	{
636
+		foreach ($boxes as $box) {
637
+			if (! isset($box['page_route'])) {
638
+				continue;
639
+			} //we dont' have a valid array
640
+			// let's make sure $box['page_route'] is an array so the "foreach" will work.
641
+			$box['page_route'] = (array) $box['page_route'];
642
+			foreach ($box['page_route'] as $route) {
643
+				if ($route != $this->_current_route) {
644
+					continue;
645
+				} //get out we only add metaboxes for set route.
646
+				if ($add) {
647
+					$this->_add_metabox($box);
648
+				} else {
649
+					$this->_remove_metabox($box);
650
+				}
651
+			}
652
+		}
653
+	}
654
+
655
+
656
+	/**
657
+	 * Loop through the _remove_metaboxes property and remove metaboxes accordingly.
658
+	 *
659
+	 * @access public
660
+	 * @return void
661
+	 */
662
+	public function remove_metaboxes()
663
+	{
664
+		if (empty($this->_remove_metaboxes)) {
665
+			return;
666
+		} //get out there are no metaboxes to remove
667
+		$this->_handle_metabox_array($this->_remove_metaboxes, false);
668
+	}
669
+
670
+
671
+	/**
672
+	 * This just handles adding a metabox
673
+	 *
674
+	 * @access private
675
+	 * @param array $args an array of args that have been set for this metabox by the child class
676
+	 */
677
+	private function _add_metabox($args)
678
+	{
679
+		$current_screen = get_current_screen();
680
+		$screen_id = is_object($current_screen) ? $current_screen->id : null;
681
+		$func = isset($args['func']) ? $args['func'] : 'some_invalid_callback';
682
+		// set defaults
683
+		$defaults = array(
684
+			'func'          => $func,
685
+			'id'            => $this->caller . '_' . $func . '_metabox',
686
+			'priority'      => 'default',
687
+			'label'         => $this->caller,
688
+			'context'       => 'advanced',
689
+			'callback_args' => array(),
690
+			'page'          => isset($args['page']) ? $args['page'] : $screen_id,
691
+		);
692
+		$args = wp_parse_args($args, $defaults);
693
+		extract($args);
694
+		// make sure method exists
695
+		if (! method_exists($this, $func)) {
696
+			$msg[] = __('There is no corresponding method to display the metabox content', 'event_espresso') . '<br />';
697
+			$msg[] = sprintf(
698
+				__(
699
+					'The method name given in the array is %s, check the spelling and make sure it exists in the %s class',
700
+					'event_espresso'
701
+				),
702
+				$func,
703
+				$this->caller
704
+			);
705
+			throw new EE_Error(implode('||', $msg));
706
+		}
707
+		// everything checks out so lets add the metabox
708
+		add_meta_box($id, $label, array($this, $func), $page, $context, $priority, $callback_args);
709
+	}
710
+
711
+
712
+	private function _remove_metabox($args)
713
+	{
714
+		$current_screen = get_current_screen();
715
+		$screen_id = is_object($current_screen) ? $current_screen->id : null;
716
+		$func = isset($args['func']) ? $args['func'] : 'some_invalid_callback';
717
+		// set defaults
718
+		$defaults = array(
719
+			'id'      => isset($args['id'])
720
+				? $args['id']
721
+				: $this->_current_route
722
+				  . '_'
723
+				  . $this->caller
724
+				  . '_'
725
+				  . $func
726
+				  . '_metabox',
727
+			'context' => 'default',
728
+			'screen'  => isset($args['screen']) ? $args['screen'] : $screen_id,
729
+		);
730
+		$args = wp_parse_args($args, $defaults);
731
+		extract($args);
732
+		// everything checks out so lets remove the box!
733
+		remove_meta_box($id, $screen, $context);
734
+	}
735 735
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page.core.php 1 patch
Indentation   +4093 added lines, -4093 removed lines patch added patch discarded remove patch
@@ -18,4163 +18,4163 @@
 block discarded – undo
18 18
  */
19 19
 abstract class EE_Admin_Page extends EE_Base implements InterminableInterface
20 20
 {
21
-    /**
22
-     * @var EE_Admin_Config
23
-     */
24
-    protected $admin_config;
21
+	/**
22
+	 * @var EE_Admin_Config
23
+	 */
24
+	protected $admin_config;
25 25
 
26
-    /**
27
-     * @var LoaderInterface $loader
28
-     */
29
-    protected $loader;
26
+	/**
27
+	 * @var LoaderInterface $loader
28
+	 */
29
+	protected $loader;
30 30
 
31
-    // set in _init_page_props()
32
-    public $page_slug;
31
+	// set in _init_page_props()
32
+	public $page_slug;
33 33
 
34
-    public $page_label;
34
+	public $page_label;
35 35
 
36
-    public $page_folder;
36
+	public $page_folder;
37 37
 
38
-    // set in define_page_props()
39
-    protected $_admin_base_url;
38
+	// set in define_page_props()
39
+	protected $_admin_base_url;
40 40
 
41
-    protected $_admin_base_path;
41
+	protected $_admin_base_path;
42 42
 
43
-    protected $_admin_page_title;
43
+	protected $_admin_page_title;
44 44
 
45
-    protected $_labels;
45
+	protected $_labels;
46 46
 
47 47
 
48
-    // set early within EE_Admin_Init
49
-    protected $_wp_page_slug;
48
+	// set early within EE_Admin_Init
49
+	protected $_wp_page_slug;
50 50
 
51
-    // nav tabs
52
-    protected $_nav_tabs;
51
+	// nav tabs
52
+	protected $_nav_tabs;
53 53
 
54
-    protected $_default_nav_tab_name;
54
+	protected $_default_nav_tab_name;
55 55
 
56
-    /**
57
-     * @var array $_help_tour
58
-     */
59
-    protected $_help_tour = array();
56
+	/**
57
+	 * @var array $_help_tour
58
+	 */
59
+	protected $_help_tour = array();
60 60
 
61 61
 
62
-    // template variables (used by templates)
63
-    protected $_template_path;
62
+	// template variables (used by templates)
63
+	protected $_template_path;
64 64
 
65
-    protected $_column_template_path;
65
+	protected $_column_template_path;
66 66
 
67
-    /**
68
-     * @var array $_template_args
69
-     */
70
-    protected $_template_args = array();
67
+	/**
68
+	 * @var array $_template_args
69
+	 */
70
+	protected $_template_args = array();
71 71
 
72
-    /**
73
-     * this will hold the list table object for a given view.
74
-     *
75
-     * @var EE_Admin_List_Table $_list_table_object
76
-     */
77
-    protected $_list_table_object;
72
+	/**
73
+	 * this will hold the list table object for a given view.
74
+	 *
75
+	 * @var EE_Admin_List_Table $_list_table_object
76
+	 */
77
+	protected $_list_table_object;
78 78
 
79
-    // boolean
80
-    protected $_is_UI_request; // this starts at null so we can have no header routes progress through two states.
79
+	// boolean
80
+	protected $_is_UI_request; // this starts at null so we can have no header routes progress through two states.
81 81
 
82
-    protected $_routing;
82
+	protected $_routing;
83 83
 
84
-    // list table args
85
-    protected $_view;
84
+	// list table args
85
+	protected $_view;
86 86
 
87
-    protected $_views;
87
+	protected $_views;
88 88
 
89 89
 
90
-    // action => method pairs used for routing incoming requests
91
-    protected $_page_routes;
90
+	// action => method pairs used for routing incoming requests
91
+	protected $_page_routes;
92 92
 
93
-    /**
94
-     * @var array $_page_config
95
-     */
96
-    protected $_page_config;
93
+	/**
94
+	 * @var array $_page_config
95
+	 */
96
+	protected $_page_config;
97 97
 
98
-    /**
99
-     * the current page route and route config
100
-     *
101
-     * @var string $_route
102
-     */
103
-    protected $_route;
98
+	/**
99
+	 * the current page route and route config
100
+	 *
101
+	 * @var string $_route
102
+	 */
103
+	protected $_route;
104 104
 
105
-    /**
106
-     * @var string $_cpt_route
107
-     */
108
-    protected $_cpt_route;
105
+	/**
106
+	 * @var string $_cpt_route
107
+	 */
108
+	protected $_cpt_route;
109 109
 
110
-    /**
111
-     * @var array $_route_config
112
-     */
113
-    protected $_route_config;
110
+	/**
111
+	 * @var array $_route_config
112
+	 */
113
+	protected $_route_config;
114 114
 
115
-    /**
116
-     * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
117
-     * actions.
118
-     *
119
-     * @since 4.6.x
120
-     * @var array.
121
-     */
122
-    protected $_default_route_query_args;
115
+	/**
116
+	 * Used to hold default query args for list table routes to help preserve stickiness of filters for carried out
117
+	 * actions.
118
+	 *
119
+	 * @since 4.6.x
120
+	 * @var array.
121
+	 */
122
+	protected $_default_route_query_args;
123 123
 
124
-    // set via request page and action args.
125
-    protected $_current_page;
126
-
127
-    protected $_current_view;
128
-
129
-    protected $_current_page_view_url;
130
-
131
-    // sanitized request action (and nonce)
132
-
133
-    /**
134
-     * @var string $_req_action
135
-     */
136
-    protected $_req_action;
137
-
138
-    /**
139
-     * @var string $_req_nonce
140
-     */
141
-    protected $_req_nonce;
142
-
143
-    // search related
144
-    protected $_search_btn_label;
145
-
146
-    protected $_search_box_callback;
147
-
148
-    /**
149
-     * WP Current Screen object
150
-     *
151
-     * @var WP_Screen
152
-     */
153
-    protected $_current_screen;
154
-
155
-    // for holding EE_Admin_Hooks object when needed (set via set_hook_object())
156
-    protected $_hook_obj;
157
-
158
-    // for holding incoming request data
159
-    protected $_req_data = [];
160
-
161
-    // yes / no array for admin form fields
162
-    protected $_yes_no_values = array();
163
-
164
-    // some default things shared by all child classes
165
-    protected $_default_espresso_metaboxes;
166
-
167
-    /**
168
-     *    EE_Registry Object
169
-     *
170
-     * @var    EE_Registry
171
-     */
172
-    protected $EE;
173
-
174
-
175
-    /**
176
-     * This is just a property that flags whether the given route is a caffeinated route or not.
177
-     *
178
-     * @var boolean
179
-     */
180
-    protected $_is_caf = false;
181
-
182
-    /**
183
-     * whether or not initializePage() has run
184
-     *
185
-     * @var boolean
186
-     */
187
-    protected $initialized = false;
188
-
189
-
190
-    /**
191
-     * @Constructor
192
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
193
-     * @throws InvalidArgumentException
194
-     * @throws InvalidDataTypeException
195
-     * @throws InvalidInterfaceException
196
-     * @throws ReflectionException
197
-     */
198
-    public function __construct($routing = true)
199
-    {
200
-        $this->loader = LoaderFactory::getLoader();
201
-        $this->admin_config = $this->loader->getShared('EE_Admin_Config');
202
-        if (strpos($this->_get_dir(), 'caffeinated') !== false) {
203
-            $this->_is_caf = true;
204
-        }
205
-        $this->_yes_no_values = array(
206
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
207
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
208
-        );
209
-        // set the _req_data property.
210
-        $this->_req_data = array_merge($_GET, $_POST);
211
-        // routing enabled?
212
-        $this->_routing = $routing;
213
-    }
214
-
215
-
216
-    /**
217
-     * This logic used to be in the constructor, but that caused a chicken <--> egg scenario
218
-     * for child classes that needed to set properties prior to these methods getting called,
219
-     * but also needed the parent class to have its construction completed as well.
220
-     * Bottom line is that constructors should ONLY be used for setting initial properties
221
-     * and any complex initialization logic should only run after instantiation is complete.
222
-     *
223
-     * This method gets called immediately after construction from within
224
-     *      EE_Admin_Page_Init::_initialize_admin_page()
225
-     *
226
-     * @throws EE_Error
227
-     * @throws InvalidArgumentException
228
-     * @throws InvalidDataTypeException
229
-     * @throws InvalidInterfaceException
230
-     * @throws ReflectionException
231
-     * @since $VID:$
232
-     */
233
-    public function initializePage()
234
-    {
235
-        if ($this->initialized) {
236
-            return;
237
-        }
238
-        // set initial page props (child method)
239
-        $this->_init_page_props();
240
-        // set global defaults
241
-        $this->_set_defaults();
242
-        // set early because incoming requests could be ajax related and we need to register those hooks.
243
-        $this->_global_ajax_hooks();
244
-        $this->_ajax_hooks();
245
-        // other_page_hooks have to be early too.
246
-        $this->_do_other_page_hooks();
247
-        // This just allows us to have extending classes do something specific
248
-        // before the parent constructor runs _page_setup().
249
-        if (method_exists($this, '_before_page_setup')) {
250
-            $this->_before_page_setup();
251
-        }
252
-        // set up page dependencies
253
-        $this->_page_setup();
254
-        $this->initialized = true;
255
-    }
256
-
257
-
258
-    /**
259
-     * _init_page_props
260
-     * Child classes use to set at least the following properties:
261
-     * $page_slug.
262
-     * $page_label.
263
-     *
264
-     * @abstract
265
-     * @return void
266
-     */
267
-    abstract protected function _init_page_props();
268
-
269
-
270
-    /**
271
-     * _ajax_hooks
272
-     * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
273
-     * Note: within the ajax callback methods.
274
-     *
275
-     * @abstract
276
-     * @return void
277
-     */
278
-    abstract protected function _ajax_hooks();
279
-
280
-
281
-    /**
282
-     * _define_page_props
283
-     * child classes define page properties in here.  Must include at least:
284
-     * $_admin_base_url = base_url for all admin pages
285
-     * $_admin_page_title = default admin_page_title for admin pages
286
-     * $_labels = array of default labels for various automatically generated elements:
287
-     *    array(
288
-     *        'buttons' => array(
289
-     *            'add' => esc_html__('label for add new button'),
290
-     *            'edit' => esc_html__('label for edit button'),
291
-     *            'delete' => esc_html__('label for delete button')
292
-     *            )
293
-     *        )
294
-     *
295
-     * @abstract
296
-     * @return void
297
-     */
298
-    abstract protected function _define_page_props();
299
-
300
-
301
-    /**
302
-     * _set_page_routes
303
-     * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
304
-     * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
305
-     * have a 'default' route. Here's the format
306
-     * $this->_page_routes = array(
307
-     *        'default' => array(
308
-     *            'func' => '_default_method_handling_route',
309
-     *            'args' => array('array','of','args'),
310
-     *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
311
-     *            ajax request, backend processing)
312
-     *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
313
-     *            headers route after.  The string you enter here should match the defined route reference for a
314
-     *            headers sent route.
315
-     *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
316
-     *            this route.
317
-     *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
318
-     *            checks).
319
-     *        ),
320
-     *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
321
-     *        handling method.
322
-     *        )
323
-     * )
324
-     *
325
-     * @abstract
326
-     * @return void
327
-     */
328
-    abstract protected function _set_page_routes();
329
-
330
-
331
-    /**
332
-     * _set_page_config
333
-     * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
334
-     * array corresponds to the page_route for the loaded page. Format:
335
-     * $this->_page_config = array(
336
-     *        'default' => array(
337
-     *            'labels' => array(
338
-     *                'buttons' => array(
339
-     *                    'add' => esc_html__('label for adding item'),
340
-     *                    'edit' => esc_html__('label for editing item'),
341
-     *                    'delete' => esc_html__('label for deleting item')
342
-     *                ),
343
-     *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
344
-     *            ), //optional an array of custom labels for various automatically generated elements to use on the
345
-     *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
346
-     *            _define_page_props() method
347
-     *            'nav' => array(
348
-     *                'label' => esc_html__('Label for Tab', 'event_espresso').
349
-     *                'url' => 'http://someurl', //automatically generated UNLESS you define
350
-     *                'css_class' => 'css-class', //automatically generated UNLESS you define
351
-     *                'order' => 10, //required to indicate tab position.
352
-     *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
353
-     *                displayed then add this parameter.
354
-     *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
355
-     *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
356
-     *            metaboxes set for eventespresso admin pages.
357
-     *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
358
-     *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
359
-     *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
360
-     *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
361
-     *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
362
-     *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
363
-     *            array indicates the max number of columns (4) and the default number of columns on page load (2).
364
-     *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
365
-     *            want to display.
366
-     *            'help_tabs' => array( //this is used for adding help tabs to a page
367
-     *                'tab_id' => array(
368
-     *                    'title' => 'tab_title',
369
-     *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
370
-     *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
371
-     *                    should match a file in the admin folder's "help_tabs" dir (ie..
372
-     *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
373
-     *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
374
-     *                    attempt to use the callback which should match the name of a method in the class
375
-     *                    ),
376
-     *                'tab2_id' => array(
377
-     *                    'title' => 'tab2 title',
378
-     *                    'filename' => 'file_name_2'
379
-     *                    'callback' => 'callback_method_for_content',
380
-     *                 ),
381
-     *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
382
-     *            help tab area on an admin page. @link
383
-     *            http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
384
-     *            'help_tour' => array(
385
-     *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located
386
-     *                in a folder for this admin page named "help_tours", a file name matching the key given here
387
-     *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
388
-     *            ),
389
-     *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is
390
-     *            true if it isn't present).  To remove the requirement for a nonce check when this route is visited
391
-     *            just set
392
-     *            'require_nonce' to FALSE
393
-     *            )
394
-     * )
395
-     *
396
-     * @abstract
397
-     * @return void
398
-     */
399
-    abstract protected function _set_page_config();
400
-
401
-
402
-
403
-
404
-
405
-    /** end sample help_tour methods **/
406
-    /**
407
-     * _add_screen_options
408
-     * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
409
-     * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
410
-     * to a particular view.
411
-     *
412
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
413
-     *         see also WP_Screen object documents...
414
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
415
-     * @abstract
416
-     * @return void
417
-     */
418
-    abstract protected function _add_screen_options();
419
-
420
-
421
-    /**
422
-     * _add_feature_pointers
423
-     * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
424
-     * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
425
-     * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
426
-     * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
427
-     * extended) also see:
428
-     *
429
-     * @link   http://eamann.com/tech/wordpress-portland/
430
-     * @abstract
431
-     * @return void
432
-     */
433
-    abstract protected function _add_feature_pointers();
434
-
435
-
436
-    /**
437
-     * load_scripts_styles
438
-     * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
439
-     * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
440
-     * scripts/styles per view by putting them in a dynamic function in this format
441
-     * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
442
-     *
443
-     * @abstract
444
-     * @return void
445
-     */
446
-    abstract public function load_scripts_styles();
447
-
448
-
449
-    /**
450
-     * admin_init
451
-     * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
452
-     * all pages/views loaded by child class.
453
-     *
454
-     * @abstract
455
-     * @return void
456
-     */
457
-    abstract public function admin_init();
458
-
459
-
460
-    /**
461
-     * admin_notices
462
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
463
-     * all pages/views loaded by child class.
464
-     *
465
-     * @abstract
466
-     * @return void
467
-     */
468
-    abstract public function admin_notices();
469
-
470
-
471
-    /**
472
-     * admin_footer_scripts
473
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
474
-     * will apply to all pages/views loaded by child class.
475
-     *
476
-     * @return void
477
-     */
478
-    abstract public function admin_footer_scripts();
479
-
480
-
481
-    /**
482
-     * admin_footer
483
-     * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
484
-     * apply to all pages/views loaded by child class.
485
-     *
486
-     * @return void
487
-     */
488
-    public function admin_footer()
489
-    {
490
-    }
491
-
492
-
493
-    /**
494
-     * _global_ajax_hooks
495
-     * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
496
-     * Note: within the ajax callback methods.
497
-     *
498
-     * @abstract
499
-     * @return void
500
-     */
501
-    protected function _global_ajax_hooks()
502
-    {
503
-        // for lazy loading of metabox content
504
-        add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
505
-
506
-        add_action(
507
-            'wp_ajax_espresso_hide_status_change_notice',
508
-            [$this, 'hideStatusChangeNotice']
509
-        );
510
-        add_action(
511
-            'wp_ajax_nopriv_espresso_hide_status_change_notice',
512
-            [$this, 'hideStatusChangeNotice']
513
-        );
514
-    }
515
-
516
-
517
-    public function ajax_metabox_content()
518
-    {
519
-        $contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
520
-        $url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
521
-        EE_Admin_Page::cached_rss_display($contentid, $url);
522
-        wp_die();
523
-    }
524
-
525
-
526
-    public function hideStatusChangeNotice()
527
-    {
528
-        $response = [];
529
-        try {
530
-            /** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */
531
-            $status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice');
532
-            $response['success'] = $status_change_notice->dismiss() > -1;
533
-        } catch (Exception $exception) {
534
-            $response['errors'] = $exception->getMessage();
535
-        }
536
-        echo wp_json_encode($response);
537
-        exit();
538
-    }
539
-
540
-
541
-    /**
542
-     * _page_setup
543
-     * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested
544
-     * doesn't match the object.
545
-     *
546
-     * @final
547
-     * @return void
548
-     * @throws EE_Error
549
-     * @throws InvalidArgumentException
550
-     * @throws ReflectionException
551
-     * @throws InvalidDataTypeException
552
-     * @throws InvalidInterfaceException
553
-     */
554
-    final protected function _page_setup()
555
-    {
556
-        // requires?
557
-        // admin_init stuff - global - we're setting this REALLY early
558
-        // so if EE_Admin pages have to hook into other WP pages they can.
559
-        // But keep in mind, not everything is available from the EE_Admin Page object at this point.
560
-        add_action('admin_init', array($this, 'admin_init_global'), 5);
561
-        // next verify if we need to load anything...
562
-        $this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
563
-        $this->page_folder = strtolower(
564
-            str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this))
565
-        );
566
-        global $ee_menu_slugs;
567
-        $ee_menu_slugs = (array) $ee_menu_slugs;
568
-        if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) {
569
-            return;
570
-        }
571
-        // becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
572
-        if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') {
573
-            $this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1'
574
-                ? $this->_req_data['action2']
575
-                : $this->_req_data['action'];
576
-        }
577
-        // then set blank or -1 action values to 'default'
578
-        $this->_req_action = isset($this->_req_data['action'])
579
-                             && ! empty($this->_req_data['action'])
580
-                             && $this->_req_data['action'] !== '-1'
581
-            ? sanitize_key($this->_req_data['action'])
582
-            : 'default';
583
-        // if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.
584
-        //  This covers cases where we're coming in from a list table that isn't on the default route.
585
-        $this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route'])
586
-            ? $this->_req_data['route'] : $this->_req_action;
587
-        // however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
588
-        $this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route'])
589
-            ? $this->_req_data['route']
590
-            : $this->_req_action;
591
-        $this->_current_view = $this->_req_action;
592
-        $this->_req_nonce = $this->_req_action . '_nonce';
593
-        $this->_define_page_props();
594
-        $this->_current_page_view_url = add_query_arg(
595
-            array('page' => $this->_current_page, 'action' => $this->_current_view),
596
-            $this->_admin_base_url
597
-        );
598
-        // default things
599
-        $this->_default_espresso_metaboxes = array(
600
-            '_espresso_news_post_box',
601
-            '_espresso_links_post_box',
602
-            '_espresso_ratings_request',
603
-            '_espresso_sponsors_post_box',
604
-        );
605
-        // set page configs
606
-        $this->_set_page_routes();
607
-        $this->_set_page_config();
608
-        // let's include any referrer data in our default_query_args for this route for "stickiness".
609
-        if (isset($this->_req_data['wp_referer'])) {
610
-            $this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
611
-        }
612
-        // for caffeinated and other extended functionality.
613
-        //  If there is a _extend_page_config method
614
-        // then let's run that to modify the all the various page configuration arrays
615
-        if (method_exists($this, '_extend_page_config')) {
616
-            $this->_extend_page_config();
617
-        }
618
-        // for CPT and other extended functionality.
619
-        // If there is an _extend_page_config_for_cpt
620
-        // then let's run that to modify all the various page configuration arrays.
621
-        if (method_exists($this, '_extend_page_config_for_cpt')) {
622
-            $this->_extend_page_config_for_cpt();
623
-        }
624
-        // filter routes and page_config so addons can add their stuff. Filtering done per class
625
-        $this->_page_routes = apply_filters(
626
-            'FHEE__' . get_class($this) . '__page_setup__page_routes',
627
-            $this->_page_routes,
628
-            $this
629
-        );
630
-        $this->_page_config = apply_filters(
631
-            'FHEE__' . get_class($this) . '__page_setup__page_config',
632
-            $this->_page_config,
633
-            $this
634
-        );
635
-        // if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
636
-        // then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
637
-        if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
638
-            add_action(
639
-                'AHEE__EE_Admin_Page__route_admin_request',
640
-                array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view),
641
-                10,
642
-                2
643
-            );
644
-        }
645
-        // next route only if routing enabled
646
-        if ($this->_routing && ! defined('DOING_AJAX')) {
647
-            $this->_verify_routes();
648
-            // next let's just check user_access and kill if no access
649
-            $this->check_user_access();
650
-            if ($this->_is_UI_request) {
651
-                // admin_init stuff - global, all views for this page class, specific view
652
-                add_action('admin_init', array($this, 'admin_init'), 10);
653
-                if (method_exists($this, 'admin_init_' . $this->_current_view)) {
654
-                    add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
655
-                }
656
-            } else {
657
-                // hijack regular WP loading and route admin request immediately
658
-                @ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
659
-                $this->route_admin_request();
660
-            }
661
-        }
662
-    }
663
-
664
-
665
-    /**
666
-     * Provides a way for related child admin pages to load stuff on the loaded admin page.
667
-     *
668
-     * @return void
669
-     * @throws EE_Error
670
-     */
671
-    private function _do_other_page_hooks()
672
-    {
673
-        $registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
674
-        foreach ($registered_pages as $page) {
675
-            // now let's setup the file name and class that should be present
676
-            $classname = str_replace('.class.php', '', $page);
677
-            // autoloaders should take care of loading file
678
-            if (! class_exists($classname)) {
679
-                $error_msg[] = sprintf(
680
-                    esc_html__(
681
-                        'Something went wrong with loading the %s admin hooks page.',
682
-                        'event_espresso'
683
-                    ),
684
-                    $page
685
-                );
686
-                $error_msg[] = $error_msg[0]
687
-                               . "\r\n"
688
-                               . sprintf(
689
-                                   esc_html__(
690
-                                       'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
691
-                                       'event_espresso'
692
-                                   ),
693
-                                   $page,
694
-                                   '<br />',
695
-                                   '<strong>' . $classname . '</strong>'
696
-                               );
697
-                throw new EE_Error(implode('||', $error_msg));
698
-            }
699
-            // // notice we are passing the instance of this class to the hook object.
700
-            $this->loader->getShared($classname, [$this]);
701
-        }
702
-    }
703
-
704
-
705
-    /**
706
-     * @throws DomainException
707
-     * @throws EE_Error
708
-     * @throws InvalidArgumentException
709
-     * @throws InvalidDataTypeException
710
-     * @throws InvalidInterfaceException
711
-     * @throws ReflectionException
712
-     * @since $VID:$
713
-     */
714
-    public function load_page_dependencies()
715
-    {
716
-        try {
717
-            $this->_load_page_dependencies();
718
-        } catch (EE_Error $e) {
719
-            $e->get_error();
720
-        }
721
-    }
722
-
723
-
724
-    /**
725
-     * load_page_dependencies
726
-     * loads things specific to this page class when its loaded.  Really helps with efficiency.
727
-     *
728
-     * @return void
729
-     * @throws DomainException
730
-     * @throws EE_Error
731
-     * @throws InvalidArgumentException
732
-     * @throws InvalidDataTypeException
733
-     * @throws InvalidInterfaceException
734
-     * @throws ReflectionException
735
-     */
736
-    protected function _load_page_dependencies()
737
-    {
738
-        // let's set the current_screen and screen options to override what WP set
739
-        $this->_current_screen = get_current_screen();
740
-        // load admin_notices - global, page class, and view specific
741
-        add_action('admin_notices', array($this, 'admin_notices_global'), 5);
742
-        add_action('admin_notices', array($this, 'admin_notices'), 10);
743
-        if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
744
-            add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
745
-        }
746
-        // load network admin_notices - global, page class, and view specific
747
-        add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
748
-        if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
749
-            add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
750
-        }
751
-        // this will save any per_page screen options if they are present
752
-        $this->_set_per_page_screen_options();
753
-        // setup list table properties
754
-        $this->_set_list_table();
755
-        // child classes can "register" a metabox to be automatically handled via the _page_config array property.
756
-        // However in some cases the metaboxes will need to be added within a route handling callback.
757
-        $this->_add_registered_meta_boxes();
758
-        $this->_add_screen_columns();
759
-        // add screen options - global, page child class, and view specific
760
-        $this->_add_global_screen_options();
761
-        $this->_add_screen_options();
762
-        $add_screen_options = "_add_screen_options_{$this->_current_view}";
763
-        if (method_exists($this, $add_screen_options)) {
764
-            $this->{$add_screen_options}();
765
-        }
766
-        // add help tab(s) and tours- set via page_config and qtips.
767
-        // $this->_add_help_tour();
768
-        $this->_add_help_tabs();
769
-        $this->_add_qtips();
770
-        // add feature_pointers - global, page child class, and view specific
771
-        $this->_add_feature_pointers();
772
-        $this->_add_global_feature_pointers();
773
-        $add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
774
-        if (method_exists($this, $add_feature_pointer)) {
775
-            $this->{$add_feature_pointer}();
776
-        }
777
-        // enqueue scripts/styles - global, page class, and view specific
778
-        add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
779
-        add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
780
-        if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
781
-            add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15);
782
-        }
783
-        add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
784
-        // admin_print_footer_scripts - global, page child class, and view specific.
785
-        // NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
786
-        // In most cases that's doing_it_wrong().  But adding hidden container elements etc.
787
-        // is a good use case. Notice the late priority we're giving these
788
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
789
-        add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
790
-        if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
791
-            add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101);
792
-        }
793
-        // admin footer scripts
794
-        add_action('admin_footer', array($this, 'admin_footer_global'), 99);
795
-        add_action('admin_footer', array($this, 'admin_footer'), 100);
796
-        if (method_exists($this, "admin_footer_{$this->_current_view}")) {
797
-            add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101);
798
-        }
799
-        do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
800
-        // targeted hook
801
-        do_action(
802
-            "FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
803
-        );
804
-    }
805
-
806
-
807
-    /**
808
-     * _set_defaults
809
-     * This sets some global defaults for class properties.
810
-     */
811
-    private function _set_defaults()
812
-    {
813
-        $this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
814
-        $this->_event = $this->_template_path = $this->_column_template_path = null;
815
-        $this->_nav_tabs = $this->_views = $this->_page_routes = array();
816
-        $this->_page_config = $this->_default_route_query_args = array();
817
-        $this->_default_nav_tab_name = 'overview';
818
-        // init template args
819
-        $this->_template_args = array(
820
-            'admin_page_header'  => '',
821
-            'admin_page_content' => '',
822
-            'post_body_content'  => '',
823
-            'before_list_table'  => '',
824
-            'after_list_table'   => '',
825
-        );
826
-    }
827
-
828
-
829
-    /**
830
-     * route_admin_request
831
-     *
832
-     * @see    _route_admin_request()
833
-     * @return exception|void error
834
-     * @throws InvalidArgumentException
835
-     * @throws InvalidInterfaceException
836
-     * @throws InvalidDataTypeException
837
-     * @throws EE_Error
838
-     * @throws ReflectionException
839
-     */
840
-    public function route_admin_request()
841
-    {
842
-        try {
843
-            $this->_route_admin_request();
844
-        } catch (EE_Error $e) {
845
-            $e->get_error();
846
-        }
847
-    }
848
-
849
-
850
-    public function set_wp_page_slug($wp_page_slug)
851
-    {
852
-        $this->_wp_page_slug = $wp_page_slug;
853
-        // if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
854
-        if (is_network_admin()) {
855
-            $this->_wp_page_slug .= '-network';
856
-        }
857
-    }
858
-
859
-
860
-    /**
861
-     * _verify_routes
862
-     * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
863
-     * we know if we need to drop out.
864
-     *
865
-     * @return bool
866
-     * @throws EE_Error
867
-     */
868
-    protected function _verify_routes()
869
-    {
870
-        if (! $this->_current_page && ! defined('DOING_AJAX')) {
871
-            return false;
872
-        }
873
-        $this->_route = false;
874
-        // check that the page_routes array is not empty
875
-        if (empty($this->_page_routes)) {
876
-            // user error msg
877
-            $error_msg = sprintf(
878
-                esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
879
-                $this->_admin_page_title
880
-            );
881
-            // developer error msg
882
-            $error_msg .= '||' . $error_msg
883
-                          . esc_html__(
884
-                              ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
885
-                              'event_espresso'
886
-                          );
887
-            throw new EE_Error($error_msg);
888
-        }
889
-        // and that the requested page route exists
890
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
891
-            $this->_route = $this->_page_routes[ $this->_req_action ];
892
-            $this->_route_config = isset($this->_page_config[ $this->_req_action ])
893
-                ? $this->_page_config[ $this->_req_action ] : array();
894
-        } else {
895
-            // user error msg
896
-            $error_msg = sprintf(
897
-                esc_html__(
898
-                    'The requested page route does not exist for the %s admin page.',
899
-                    'event_espresso'
900
-                ),
901
-                $this->_admin_page_title
902
-            );
903
-            // developer error msg
904
-            $error_msg .= '||' . $error_msg
905
-                          . sprintf(
906
-                              esc_html__(
907
-                                  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
908
-                                  'event_espresso'
909
-                              ),
910
-                              $this->_req_action
911
-                          );
912
-            throw new EE_Error($error_msg);
913
-        }
914
-        // and that a default route exists
915
-        if (! array_key_exists('default', $this->_page_routes)) {
916
-            // user error msg
917
-            $error_msg = sprintf(
918
-                esc_html__(
919
-                    'A default page route has not been set for the % admin page.',
920
-                    'event_espresso'
921
-                ),
922
-                $this->_admin_page_title
923
-            );
924
-            // developer error msg
925
-            $error_msg .= '||' . $error_msg
926
-                          . esc_html__(
927
-                              ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
928
-                              'event_espresso'
929
-                          );
930
-            throw new EE_Error($error_msg);
931
-        }
932
-
933
-        // first lets' catch if the UI request has EVER been set.
934
-        if ($this->_is_UI_request === null) {
935
-            // lets set if this is a UI request or not.
936
-            $this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true;
937
-            // wait a minute... we might have a noheader in the route array
938
-            $this->_is_UI_request = is_array($this->_route)
939
-                                    && isset($this->_route['noheader'])
940
-                                    && $this->_route['noheader'] ? false : $this->_is_UI_request;
941
-        }
942
-        $this->_set_current_labels();
943
-        return true;
944
-    }
945
-
946
-
947
-    /**
948
-     * this method simply verifies a given route and makes sure its an actual route available for the loaded page
949
-     *
950
-     * @param  string $route the route name we're verifying
951
-     * @return mixed (bool|Exception)      we'll throw an exception if this isn't a valid route.
952
-     * @throws EE_Error
953
-     */
954
-    protected function _verify_route($route)
955
-    {
956
-        if (array_key_exists($this->_req_action, $this->_page_routes)) {
957
-            return true;
958
-        }
959
-        // user error msg
960
-        $error_msg = sprintf(
961
-            esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
962
-            $this->_admin_page_title
963
-        );
964
-        // developer error msg
965
-        $error_msg .= '||' . $error_msg
966
-                      . sprintf(
967
-                          esc_html__(
968
-                              ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
969
-                              'event_espresso'
970
-                          ),
971
-                          $route
972
-                      );
973
-        throw new EE_Error($error_msg);
974
-    }
975
-
976
-
977
-    /**
978
-     * perform nonce verification
979
-     * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
980
-     * using this method (and save retyping!)
981
-     *
982
-     * @param string $nonce     The nonce sent
983
-     * @param string $nonce_ref The nonce reference string (name0)
984
-     * @return void
985
-     * @throws EE_Error
986
-     * @throws InvalidArgumentException
987
-     * @throws InvalidDataTypeException
988
-     * @throws InvalidInterfaceException
989
-     */
990
-    protected function _verify_nonce($nonce, $nonce_ref)
991
-    {
992
-        // verify nonce against expected value
993
-        if (! wp_verify_nonce($nonce, $nonce_ref)) {
994
-            // these are not the droids you are looking for !!!
995
-            $msg = sprintf(
996
-                esc_html__('%sNonce Fail.%s', 'event_espresso'),
997
-                '<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">',
998
-                '</a>'
999
-            );
1000
-            if (WP_DEBUG) {
1001
-                $msg .= "\n  "
1002
-                        . sprintf(
1003
-                            esc_html__(
1004
-                                'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
1005
-                                'event_espresso'
1006
-                            ),
1007
-                            EE_Admin_Page::class
1008
-                        );
1009
-            }
1010
-            if (! defined('DOING_AJAX')) {
1011
-                wp_die($msg);
1012
-            } else {
1013
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1014
-                $this->_return_json();
1015
-            }
1016
-        }
1017
-    }
1018
-
1019
-
1020
-    /**
1021
-     * _route_admin_request()
1022
-     * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if there are
1023
-     * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
1024
-     * in the page routes and then will try to load the corresponding method.
1025
-     *
1026
-     * @return void
1027
-     * @throws EE_Error
1028
-     * @throws InvalidArgumentException
1029
-     * @throws InvalidDataTypeException
1030
-     * @throws InvalidInterfaceException
1031
-     * @throws ReflectionException
1032
-     */
1033
-    protected function _route_admin_request()
1034
-    {
1035
-        if (! $this->_is_UI_request) {
1036
-            $this->_verify_routes();
1037
-        }
1038
-        $nonce_check = isset($this->_route_config['require_nonce'])
1039
-            ? $this->_route_config['require_nonce']
1040
-            : true;
1041
-        if ($this->_req_action !== 'default' && $nonce_check) {
1042
-            // set nonce from post data
1043
-            $nonce = isset($this->_req_data[ $this->_req_nonce ])
1044
-                ? sanitize_text_field($this->_req_data[ $this->_req_nonce ])
1045
-                : '';
1046
-            $this->_verify_nonce($nonce, $this->_req_nonce);
1047
-        }
1048
-        // set the nav_tabs array but ONLY if this is  UI_request
1049
-        if ($this->_is_UI_request) {
1050
-            $this->_set_nav_tabs();
1051
-        }
1052
-        // grab callback function
1053
-        $func = is_array($this->_route) && isset($this->_route['func']) ? $this->_route['func'] : $this->_route;
1054
-        // check if callback has args
1055
-        $args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
1056
-        $error_msg = '';
1057
-        // action right before calling route
1058
-        // (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1059
-        if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1060
-            do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1061
-        }
1062
-        // right before calling the route, let's remove _wp_http_referer from the
1063
-        // $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
1064
-        $_SERVER['REQUEST_URI'] = remove_query_arg(
1065
-            '_wp_http_referer',
1066
-            wp_unslash($_SERVER['REQUEST_URI'])
1067
-        );
1068
-        if (! empty($func)) {
1069
-            if (is_array($func)) {
1070
-                list($class, $method) = $func;
1071
-            } elseif (strpos($func, '::') !== false) {
1072
-                list($class, $method) = explode('::', $func);
1073
-            } else {
1074
-                $class = $this;
1075
-                $method = $func;
1076
-            }
1077
-            if (! (is_object($class) && $class === $this)) {
1078
-                // send along this admin page object for access by addons.
1079
-                $args['admin_page_object'] = $this;
1080
-            }
1081
-            // is it a method on a class that doesn't work?
1082
-            if (
1083
-                ((method_exists($class, $method)
1084
-                  && call_user_func_array(array($class, $method), $args) === false)
1085
-                 && (// is it a standalone function that doesn't work?
1086
-                     function_exists($method)
1087
-                     && call_user_func_array(
1088
-                         $func,
1089
-                         array_merge(array('admin_page_object' => $this), $args)
1090
-                     ) === false
1091
-                 )) || (// is it neither a class method NOR a standalone function?
1092
-                    ! function_exists($method)
1093
-                    && ! method_exists($class, $method)
1094
-                )
1095
-            ) {
1096
-                // user error msg
1097
-                $error_msg = esc_html__(
1098
-                    'An error occurred. The  requested page route could not be found.',
1099
-                    'event_espresso'
1100
-                );
1101
-                // developer error msg
1102
-                $error_msg .= '||';
1103
-                $error_msg .= sprintf(
1104
-                    esc_html__(
1105
-                        'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1106
-                        'event_espresso'
1107
-                    ),
1108
-                    $method
1109
-                );
1110
-            }
1111
-            if (! empty($error_msg)) {
1112
-                throw new EE_Error($error_msg);
1113
-            }
1114
-        }
1115
-        // if we've routed and this route has a no headers route AND a sent_headers_route,
1116
-        // then we need to reset the routing properties to the new route.
1117
-        // now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1118
-        if (
1119
-            $this->_is_UI_request === false
1120
-            && is_array($this->_route)
1121
-            && ! empty($this->_route['headers_sent_route'])
1122
-        ) {
1123
-            $this->_reset_routing_properties($this->_route['headers_sent_route']);
1124
-        }
1125
-    }
1126
-
1127
-
1128
-    /**
1129
-     * This method just allows the resetting of page properties in the case where a no headers
1130
-     * route redirects to a headers route in its route config.
1131
-     *
1132
-     * @since   4.3.0
1133
-     * @param  string $new_route New (non header) route to redirect to.
1134
-     * @return   void
1135
-     * @throws ReflectionException
1136
-     * @throws InvalidArgumentException
1137
-     * @throws InvalidInterfaceException
1138
-     * @throws InvalidDataTypeException
1139
-     * @throws EE_Error
1140
-     */
1141
-    protected function _reset_routing_properties($new_route)
1142
-    {
1143
-        $this->_is_UI_request = true;
1144
-        // now we set the current route to whatever the headers_sent_route is set at
1145
-        $this->_req_data['action'] = $new_route;
1146
-        // rerun page setup
1147
-        $this->_page_setup();
1148
-    }
1149
-
1150
-
1151
-    /**
1152
-     * _add_query_arg
1153
-     * adds nonce to array of arguments then calls WP add_query_arg function
1154
-     *(internally just uses EEH_URL's function with the same name)
1155
-     *
1156
-     * @param array  $args
1157
-     * @param string $url
1158
-     * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1159
-     *                                        generated url in an associative array indexed by the key 'wp_referer';
1160
-     *                                        Example usage: If the current page is:
1161
-     *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1162
-     *                                        &action=default&event_id=20&month_range=March%202015
1163
-     *                                        &_wpnonce=5467821
1164
-     *                                        and you call:
1165
-     *                                        EE_Admin_Page::add_query_args_and_nonce(
1166
-     *                                        array(
1167
-     *                                        'action' => 'resend_something',
1168
-     *                                        'page=>espresso_registrations'
1169
-     *                                        ),
1170
-     *                                        $some_url,
1171
-     *                                        true
1172
-     *                                        );
1173
-     *                                        It will produce a url in this structure:
1174
-     *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1175
-     *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1176
-     *                                        month_range]=March%202015
1177
-     * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1178
-     * @return string
1179
-     */
1180
-    public static function add_query_args_and_nonce(
1181
-        $args = array(),
1182
-        $url = '',
1183
-        $sticky = false,
1184
-        $exclude_nonce = false
1185
-    ) {
1186
-        // if there is a _wp_http_referer include the values from the request but only if sticky = true
1187
-        if ($sticky) {
1188
-            $request = $_REQUEST;
1189
-            unset($request['_wp_http_referer'], $request['wp_referer']);
1190
-            foreach ($request as $key => $value) {
1191
-                // do not add nonces
1192
-                if (strpos($key, 'nonce') !== false) {
1193
-                    continue;
1194
-                }
1195
-                $args[ 'wp_referer[' . $key . ']' ] = $value;
1196
-            }
1197
-        }
1198
-        return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1199
-    }
1200
-
1201
-
1202
-    /**
1203
-     * This returns a generated link that will load the related help tab.
1204
-     *
1205
-     * @param  string $help_tab_id the id for the connected help tab
1206
-     * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
1207
-     * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
1208
-     * @uses EEH_Template::get_help_tab_link()
1209
-     * @return string              generated link
1210
-     */
1211
-    protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1212
-    {
1213
-        return EEH_Template::get_help_tab_link(
1214
-            $help_tab_id,
1215
-            $this->page_slug,
1216
-            $this->_req_action,
1217
-            $icon_style,
1218
-            $help_text
1219
-        );
1220
-    }
1221
-
1222
-
1223
-    /**
1224
-     * _add_help_tabs
1225
-     * Note child classes define their help tabs within the page_config array.
1226
-     *
1227
-     * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1228
-     * @return void
1229
-     * @throws DomainException
1230
-     * @throws EE_Error
1231
-     * @throws ReflectionException
1232
-     */
1233
-    protected function _add_help_tabs()
1234
-    {
1235
-        $tour_buttons = '';
1236
-        if (isset($this->_page_config[ $this->_req_action ])) {
1237
-            $config = $this->_page_config[ $this->_req_action ];
1238
-            // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1239
-            // is there a help tour for the current route?  if there is let's setup the tour buttons
1240
-            // if (isset($this->_help_tour[ $this->_req_action ])) {
1241
-            //     $tb = array();
1242
-            //     $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1243
-            //     foreach ($this->_help_tour['tours'] as $tour) {
1244
-            //         // if this is the end tour then we don't need to setup a button
1245
-            //         if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) {
1246
-            //             continue;
1247
-            //         }
1248
-            //         $tb[] = '<button id="trigger-tour-'
1249
-            //                 . $tour->get_slug()
1250
-            //                 . '" class="button-primary trigger-ee-help-tour">'
1251
-            //                 . $tour->get_label()
1252
-            //                 . '</button>';
1253
-            //     }
1254
-            //     $tour_buttons .= implode('<br />', $tb);
1255
-            //     $tour_buttons .= '</div></div>';
1256
-            // }
1257
-            // let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1258
-            if (is_array($config) && isset($config['help_sidebar'])) {
1259
-                // check that the callback given is valid
1260
-                if (! method_exists($this, $config['help_sidebar'])) {
1261
-                    throw new EE_Error(
1262
-                        sprintf(
1263
-                            esc_html__(
1264
-                                'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1265
-                                'event_espresso'
1266
-                            ),
1267
-                            $config['help_sidebar'],
1268
-                            get_class($this)
1269
-                        )
1270
-                    );
1271
-                }
1272
-                $content = apply_filters(
1273
-                    'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1274
-                    $this->{$config['help_sidebar']}()
1275
-                );
1276
-                $content .= $tour_buttons; // add help tour buttons.
1277
-                // do we have any help tours setup?  Cause if we do we want to add the buttons
1278
-                $this->_current_screen->set_help_sidebar($content);
1279
-            }
1280
-            // if there ARE tour buttons...
1281
-            if (! empty($tour_buttons)) {
1282
-                // if we DON'T have config help sidebar then we'll just add the tour buttons to the sidebar.
1283
-                if (! isset($config['help_sidebar'])) {
1284
-                    $this->_current_screen->set_help_sidebar($tour_buttons);
1285
-                }
1286
-                // handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1287
-                if (! isset($config['help_tabs'])) {
1288
-                    $_ht['id'] = $this->page_slug;
1289
-                    $_ht['title'] = esc_html__('Help Tours', 'event_espresso');
1290
-                    $_ht['content'] = '<p>'
1291
-                                      . esc_html__(
1292
-                                          'The buttons to the right allow you to start/restart any help tours available for this page',
1293
-                                          'event_espresso'
1294
-                                      ) . '</p>';
1295
-                    $this->_current_screen->add_help_tab($_ht);
1296
-                }
1297
-            }
1298
-            if (! isset($config['help_tabs'])) {
1299
-                return;
1300
-            } //no help tabs for this route
1301
-            foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1302
-                // we're here so there ARE help tabs!
1303
-                // make sure we've got what we need
1304
-                if (! isset($cfg['title'])) {
1305
-                    throw new EE_Error(
1306
-                        esc_html__(
1307
-                            'The _page_config array is not set up properly for help tabs.  It is missing a title',
1308
-                            'event_espresso'
1309
-                        )
1310
-                    );
1311
-                }
1312
-                if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1313
-                    throw new EE_Error(
1314
-                        esc_html__(
1315
-                            'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1316
-                            'event_espresso'
1317
-                        )
1318
-                    );
1319
-                }
1320
-                // first priority goes to content.
1321
-                if (! empty($cfg['content'])) {
1322
-                    $content = ! empty($cfg['content']) ? $cfg['content'] : null;
1323
-                    // second priority goes to filename
1324
-                } elseif (! empty($cfg['filename'])) {
1325
-                    $file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1326
-                    // it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1327
-                    $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1328
-                                                             . basename($this->_get_dir())
1329
-                                                             . '/help_tabs/'
1330
-                                                             . $cfg['filename']
1331
-                                                             . '.help_tab.php' : $file_path;
1332
-                    // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1333
-                    if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1334
-                        EE_Error::add_error(
1335
-                            sprintf(
1336
-                                esc_html__(
1337
-                                    'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1338
-                                    'event_espresso'
1339
-                                ),
1340
-                                $tab_id,
1341
-                                key($config),
1342
-                                $file_path
1343
-                            ),
1344
-                            __FILE__,
1345
-                            __FUNCTION__,
1346
-                            __LINE__
1347
-                        );
1348
-                        return;
1349
-                    }
1350
-                    $template_args['admin_page_obj'] = $this;
1351
-                    $content = EEH_Template::display_template(
1352
-                        $file_path,
1353
-                        $template_args,
1354
-                        true
1355
-                    );
1356
-                } else {
1357
-                    $content = '';
1358
-                }
1359
-                // check if callback is valid
1360
-                if (
1361
-                    empty($content) && (
1362
-                        ! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1363
-                    )
1364
-                ) {
1365
-                    EE_Error::add_error(
1366
-                        sprintf(
1367
-                            esc_html__(
1368
-                                'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1369
-                                'event_espresso'
1370
-                            ),
1371
-                            $cfg['title']
1372
-                        ),
1373
-                        __FILE__,
1374
-                        __FUNCTION__,
1375
-                        __LINE__
1376
-                    );
1377
-                    return;
1378
-                }
1379
-                // setup config array for help tab method
1380
-                $id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1381
-                $_ht = array(
1382
-                    'id'       => $id,
1383
-                    'title'    => $cfg['title'],
1384
-                    'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1385
-                    'content'  => $content,
1386
-                );
1387
-                $this->_current_screen->add_help_tab($_ht);
1388
-            }
1389
-        }
1390
-    }
1391
-
1392
-
1393
-    /**
1394
-     * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is
1395
-     * an array with properties for setting up usage of the joyride plugin
1396
-     *
1397
-     * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1398
-     * @see    instructions regarding the format and construction of the "help_tour" array element is found in the
1399
-     *         _set_page_config() comments
1400
-     * @return void
1401
-     * @throws EE_Error
1402
-     * @throws InvalidArgumentException
1403
-     * @throws InvalidDataTypeException
1404
-     * @throws InvalidInterfaceException
1405
-     * @throws ReflectionException
1406
-     */
1407
-    protected function _add_help_tour()
1408
-    {
1409
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1410
-        // $tours = array();
1411
-        // $this->_help_tour = array();
1412
-        // // exit early if help tours are turned off globally
1413
-        // if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)
1414
-        //     || ! EE_Registry::instance()->CFG->admin->help_tour_activation
1415
-        // ) {
1416
-        //     return;
1417
-        // }
1418
-        // // loop through _page_config to find any help_tour defined
1419
-        // foreach ($this->_page_config as $route => $config) {
1420
-        //     // we're only going to set things up for this route
1421
-        //     if ($route !== $this->_req_action) {
1422
-        //         continue;
1423
-        //     }
1424
-        //     if (isset($config['help_tour'])) {
1425
-        //         foreach ($config['help_tour'] as $tour) {
1426
-        //             $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1427
-        //             // let's see if we can get that file...
1428
-        //             // if not its possible this is a decaf route not set in caffeinated
1429
-        //             // so lets try and get the caffeinated equivalent
1430
-        //             $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1431
-        //                                                      . basename($this->_get_dir())
1432
-        //                                                      . '/help_tours/'
1433
-        //                                                      . $tour
1434
-        //                                                      . '.class.php' : $file_path;
1435
-        //             // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1436
-        //             if (! is_readable($file_path)) {
1437
-        //                 EE_Error::add_error(
1438
-        //                     sprintf(
1439
-        //                         esc_html__(
1440
-        //                             'The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling',
1441
-        //                             'event_espresso'
1442
-        //                         ),
1443
-        //                         $file_path,
1444
-        //                         $tour
1445
-        //                     ),
1446
-        //                     __FILE__,
1447
-        //                     __FUNCTION__,
1448
-        //                     __LINE__
1449
-        //                 );
1450
-        //                 return;
1451
-        //             }
1452
-        //             require_once $file_path;
1453
-        //             if (! class_exists($tour)) {
1454
-        //                 $error_msg[] = sprintf(
1455
-        //                     esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'),
1456
-        //                     $tour
1457
-        //                 );
1458
-        //                 $error_msg[] = $error_msg[0] . "\r\n"
1459
-        //                                . sprintf(
1460
-        //                                    esc_html__(
1461
-        //                                        'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1462
-        //                                        'event_espresso'
1463
-        //                                    ),
1464
-        //                                    $tour,
1465
-        //                                    '<br />',
1466
-        //                                    $tour,
1467
-        //                                    $this->_req_action,
1468
-        //                                    get_class($this)
1469
-        //                                );
1470
-        //                 throw new EE_Error(implode('||', $error_msg));
1471
-        //             }
1472
-        //             $tour_obj = new $tour($this->_is_caf);
1473
-        //             $tours[] = $tour_obj;
1474
-        //             $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj);
1475
-        //         }
1476
-        //         // let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1477
-        //         $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1478
-        //         $tours[] = $end_stop_tour;
1479
-        //         $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1480
-        //     }
1481
-        // }
1482
-        //
1483
-        // if (! empty($tours)) {
1484
-        //     $this->_help_tour['tours'] = $tours;
1485
-        // }
1486
-        // // that's it!  Now that the $_help_tours property is set (or not)
1487
-        // // the scripts and html should be taken care of automatically.
1488
-        //
1489
-        // /**
1490
-        //  * Allow extending the help tours variable.
1491
-        //  *
1492
-        //  * @param Array $_help_tour The array containing all help tour information to be displayed.
1493
-        //  */
1494
-        // $this->_help_tour = apply_filters('FHEE__EE_Admin_Page___add_help_tour___help_tour', $this->_help_tour);
1495
-    }
1496
-
1497
-
1498
-    /**
1499
-     * This simply sets up any qtips that have been defined in the page config
1500
-     *
1501
-     * @return void
1502
-     * @throws ReflectionException
1503
-     * @throws EE_Error
1504
-     */
1505
-    protected function _add_qtips()
1506
-    {
1507
-        if (isset($this->_route_config['qtips'])) {
1508
-            $qtips = (array) $this->_route_config['qtips'];
1509
-            // load qtip loader
1510
-            $path = array(
1511
-                $this->_get_dir() . '/qtips/',
1512
-                EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1513
-            );
1514
-            $qtip_loader = EEH_Qtip_Loader::instance();
1515
-            if ($qtip_loader instanceof EEH_Qtip_Loader) {
1516
-                $qtip_loader->register($qtips, $path);
1517
-            }
1518
-        }
1519
-    }
1520
-
1521
-
1522
-    /**
1523
-     * _set_nav_tabs
1524
-     * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1525
-     * wish to add additional tabs or modify accordingly.
1526
-     *
1527
-     * @return void
1528
-     * @throws InvalidArgumentException
1529
-     * @throws InvalidInterfaceException
1530
-     * @throws InvalidDataTypeException
1531
-     */
1532
-    protected function _set_nav_tabs()
1533
-    {
1534
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1535
-        $i = 0;
1536
-        foreach ($this->_page_config as $slug => $config) {
1537
-            if (
1538
-                ! is_array($config)
1539
-                || (
1540
-                    is_array($config)
1541
-                    && (
1542
-                        (isset($config['nav']) && ! $config['nav'])
1543
-                        || ! isset($config['nav'])
1544
-                    )
1545
-                )
1546
-            ) {
1547
-                continue;
1548
-            }
1549
-            // no nav tab for this config
1550
-            // check for persistent flag
1551
-            if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1552
-                // nav tab is only to appear when route requested.
1553
-                continue;
1554
-            }
1555
-            if (! $this->check_user_access($slug, true)) {
1556
-                // no nav tab because current user does not have access.
1557
-                continue;
1558
-            }
1559
-            $css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1560
-            $this->_nav_tabs[ $slug ] = array(
1561
-                'url'       => isset($config['nav']['url'])
1562
-                    ? $config['nav']['url']
1563
-                    : EE_Admin_Page::add_query_args_and_nonce(
1564
-                        array('action' => $slug),
1565
-                        $this->_admin_base_url
1566
-                    ),
1567
-                'link_text' => isset($config['nav']['label'])
1568
-                    ? $config['nav']['label']
1569
-                    : ucwords(
1570
-                        str_replace('_', ' ', $slug)
1571
-                    ),
1572
-                'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1573
-                'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1574
-            );
1575
-            $i++;
1576
-        }
1577
-        // if $this->_nav_tabs is empty then lets set the default
1578
-        if (empty($this->_nav_tabs)) {
1579
-            $this->_nav_tabs[ $this->_default_nav_tab_name ] = array(
1580
-                'url'       => $this->_admin_base_url,
1581
-                'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1582
-                'css_class' => 'nav-tab-active',
1583
-                'order'     => 10,
1584
-            );
1585
-        }
1586
-        // now let's sort the tabs according to order
1587
-        usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1588
-    }
1589
-
1590
-
1591
-    /**
1592
-     * _set_current_labels
1593
-     * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1594
-     * property array
1595
-     *
1596
-     * @return void
1597
-     */
1598
-    private function _set_current_labels()
1599
-    {
1600
-        if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1601
-            foreach ($this->_route_config['labels'] as $label => $text) {
1602
-                if (is_array($text)) {
1603
-                    foreach ($text as $sublabel => $subtext) {
1604
-                        $this->_labels[ $label ][ $sublabel ] = $subtext;
1605
-                    }
1606
-                } else {
1607
-                    $this->_labels[ $label ] = $text;
1608
-                }
1609
-            }
1610
-        }
1611
-    }
1612
-
1613
-
1614
-    /**
1615
-     *        verifies user access for this admin page
1616
-     *
1617
-     * @param string $route_to_check if present then the capability for the route matching this string is checked.
1618
-     * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1619
-     *                               return false if verify fail.
1620
-     * @return bool
1621
-     * @throws InvalidArgumentException
1622
-     * @throws InvalidDataTypeException
1623
-     * @throws InvalidInterfaceException
1624
-     */
1625
-    public function check_user_access($route_to_check = '', $verify_only = false)
1626
-    {
1627
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1628
-        $route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1629
-        $capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1630
-                      && is_array(
1631
-                          $this->_page_routes[ $route_to_check ]
1632
-                      )
1633
-                      && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1634
-            ? $this->_page_routes[ $route_to_check ]['capability'] : null;
1635
-        if (empty($capability) && empty($route_to_check)) {
1636
-            $capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1637
-                : $this->_route['capability'];
1638
-        } else {
1639
-            $capability = empty($capability) ? 'manage_options' : $capability;
1640
-        }
1641
-        $id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1642
-        if (
1643
-            ! defined('DOING_AJAX')
1644
-            && (
1645
-                ! function_exists('is_admin')
1646
-                || ! EE_Registry::instance()->CAP->current_user_can(
1647
-                    $capability,
1648
-                    $this->page_slug
1649
-                    . '_'
1650
-                    . $route_to_check,
1651
-                    $id
1652
-                )
1653
-            )
1654
-        ) {
1655
-            if ($verify_only) {
1656
-                return false;
1657
-            }
1658
-            if (is_user_logged_in()) {
1659
-                wp_die(__('You do not have access to this route.', 'event_espresso'));
1660
-            } else {
1661
-                return false;
1662
-            }
1663
-        }
1664
-        return true;
1665
-    }
1666
-
1667
-
1668
-    /**
1669
-     * admin_init_global
1670
-     * This runs all the code that we want executed within the WP admin_init hook.
1671
-     * This method executes for ALL EE Admin pages.
1672
-     *
1673
-     * @return void
1674
-     */
1675
-    public function admin_init_global()
1676
-    {
1677
-    }
1678
-
1679
-
1680
-    /**
1681
-     * wp_loaded_global
1682
-     * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1683
-     * EE_Admin page and will execute on every EE Admin Page load
1684
-     *
1685
-     * @return void
1686
-     */
1687
-    public function wp_loaded()
1688
-    {
1689
-    }
1690
-
1691
-
1692
-    /**
1693
-     * admin_notices
1694
-     * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1695
-     * ALL EE_Admin pages.
1696
-     *
1697
-     * @return void
1698
-     */
1699
-    public function admin_notices_global()
1700
-    {
1701
-        $this->_display_no_javascript_warning();
1702
-        $this->_display_espresso_notices();
1703
-    }
1704
-
1705
-
1706
-    public function network_admin_notices_global()
1707
-    {
1708
-        $this->_display_no_javascript_warning();
1709
-        $this->_display_espresso_notices();
1710
-    }
1711
-
1712
-
1713
-    /**
1714
-     * admin_footer_scripts_global
1715
-     * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1716
-     * will apply on ALL EE_Admin pages.
1717
-     *
1718
-     * @return void
1719
-     */
1720
-    public function admin_footer_scripts_global()
1721
-    {
1722
-        $this->_add_admin_page_ajax_loading_img();
1723
-        $this->_add_admin_page_overlay();
1724
-        // if metaboxes are present we need to add the nonce field
1725
-        if (
1726
-            isset($this->_route_config['metaboxes'])
1727
-            || isset($this->_route_config['list_table'])
1728
-            || (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1729
-        ) {
1730
-            wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1731
-            wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1732
-        }
1733
-    }
1734
-
1735
-
1736
-    /**
1737
-     * admin_footer_global
1738
-     * Anything triggered by the wp 'admin_footer' wp hook should be put in here.
1739
-     * This particular method will apply on ALL EE_Admin Pages.
1740
-     *
1741
-     * @return void
1742
-     * @throws InvalidArgumentException
1743
-     * @throws InvalidDataTypeException
1744
-     * @throws InvalidInterfaceException
1745
-     */
1746
-    public function admin_footer_global()
1747
-    {
1748
-        // dialog container for dialog helper
1749
-        $d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1750
-        $d_cont .= '<div class="ee-notices"></div>';
1751
-        $d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1752
-        $d_cont .= '</div>';
1753
-        echo $d_cont;
1754
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1755
-        // help tour stuff?
1756
-        // if (isset($this->_help_tour[ $this->_req_action ])) {
1757
-        //     echo implode('<br />', $this->_help_tour[ $this->_req_action ]);
1758
-        // }
1759
-        // current set timezone for timezone js
1760
-        echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1761
-    }
1762
-
1763
-
1764
-    /**
1765
-     * This function sees if there is a method for help popup content existing for the given route.  If there is then
1766
-     * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1767
-     * help popups then in your templates or your content you set "triggers" for the content using the
1768
-     * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1769
-     * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1770
-     * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1771
-     * for the
1772
-     * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1773
-     * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1774
-     *    'help_trigger_id' => array(
1775
-     *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1776
-     *        'content' => esc_html__('localized content for popup', 'event_espresso')
1777
-     *    )
1778
-     * );
1779
-     * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1780
-     *
1781
-     * @param array $help_array
1782
-     * @param bool  $display
1783
-     * @return string content
1784
-     * @throws DomainException
1785
-     * @throws EE_Error
1786
-     */
1787
-    protected function _set_help_popup_content($help_array = array(), $display = false)
1788
-    {
1789
-        $content = '';
1790
-        $help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1791
-        // loop through the array and setup content
1792
-        foreach ($help_array as $trigger => $help) {
1793
-            // make sure the array is setup properly
1794
-            if (! isset($help['title'], $help['content'])) {
1795
-                throw new EE_Error(
1796
-                    esc_html__(
1797
-                        'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1798
-                        'event_espresso'
1799
-                    )
1800
-                );
1801
-            }
1802
-            // we're good so let'd setup the template vars and then assign parsed template content to our content.
1803
-            $template_args = array(
1804
-                'help_popup_id'      => $trigger,
1805
-                'help_popup_title'   => $help['title'],
1806
-                'help_popup_content' => $help['content'],
1807
-            );
1808
-            $content .= EEH_Template::display_template(
1809
-                EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1810
-                $template_args,
1811
-                true
1812
-            );
1813
-        }
1814
-        if ($display) {
1815
-            echo $content;
1816
-            return '';
1817
-        }
1818
-        return $content;
1819
-    }
1820
-
1821
-
1822
-    /**
1823
-     * All this does is retrieve the help content array if set by the EE_Admin_Page child
1824
-     *
1825
-     * @return array properly formatted array for help popup content
1826
-     * @throws EE_Error
1827
-     */
1828
-    private function _get_help_content()
1829
-    {
1830
-        // what is the method we're looking for?
1831
-        $method_name = '_help_popup_content_' . $this->_req_action;
1832
-        // if method doesn't exist let's get out.
1833
-        if (! method_exists($this, $method_name)) {
1834
-            return array();
1835
-        }
1836
-        // k we're good to go let's retrieve the help array
1837
-        $help_array = $this->{$method_name}();
1838
-        // make sure we've got an array!
1839
-        if (! is_array($help_array)) {
1840
-            throw new EE_Error(
1841
-                esc_html__(
1842
-                    'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1843
-                    'event_espresso'
1844
-                )
1845
-            );
1846
-        }
1847
-        return $help_array;
1848
-    }
1849
-
1850
-
1851
-    /**
1852
-     * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1853
-     * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1854
-     * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1855
-     *
1856
-     * @param string  $trigger_id reference for retrieving the trigger content for the popup
1857
-     * @param boolean $display    if false then we return the trigger string
1858
-     * @param array   $dimensions an array of dimensions for the box (array(h,w))
1859
-     * @return string
1860
-     * @throws DomainException
1861
-     * @throws EE_Error
1862
-     */
1863
-    protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1864
-    {
1865
-        if (defined('DOING_AJAX')) {
1866
-            return '';
1867
-        }
1868
-        // let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1869
-        $help_array = $this->_get_help_content();
1870
-        $help_content = '';
1871
-        if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1872
-            $help_array[ $trigger_id ] = array(
1873
-                'title'   => esc_html__('Missing Content', 'event_espresso'),
1874
-                'content' => esc_html__(
1875
-                    'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1876
-                    'event_espresso'
1877
-                ),
1878
-            );
1879
-            $help_content = $this->_set_help_popup_content($help_array);
1880
-        }
1881
-        // let's setup the trigger
1882
-        $content = '<a class="ee-dialog" href="?height='
1883
-                   . $dimensions[0]
1884
-                   . '&width='
1885
-                   . $dimensions[1]
1886
-                   . '&inlineId='
1887
-                   . $trigger_id
1888
-                   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1889
-        $content .= $help_content;
1890
-        if ($display) {
1891
-            echo $content;
1892
-            return '';
1893
-        }
1894
-        return $content;
1895
-    }
1896
-
1897
-
1898
-    /**
1899
-     * _add_global_screen_options
1900
-     * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1901
-     * This particular method will add_screen_options on ALL EE_Admin Pages
1902
-     *
1903
-     * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1904
-     *         see also WP_Screen object documents...
1905
-     * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1906
-     * @abstract
1907
-     * @return void
1908
-     */
1909
-    private function _add_global_screen_options()
1910
-    {
1911
-    }
1912
-
1913
-
1914
-    /**
1915
-     * _add_global_feature_pointers
1916
-     * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1917
-     * This particular method will implement feature pointers for ALL EE_Admin pages.
1918
-     * Note: this is just a placeholder for now.  Implementation will come down the road
1919
-     *
1920
-     * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1921
-     *         extended) also see:
1922
-     * @link   http://eamann.com/tech/wordpress-portland/
1923
-     * @abstract
1924
-     * @return void
1925
-     */
1926
-    private function _add_global_feature_pointers()
1927
-    {
1928
-    }
1929
-
1930
-
1931
-    /**
1932
-     * load_global_scripts_styles
1933
-     * The scripts and styles enqueued in here will be loaded on every EE Admin page
1934
-     *
1935
-     * @return void
1936
-     * @throws EE_Error
1937
-     */
1938
-    public function load_global_scripts_styles()
1939
-    {
1940
-        // add debugging styles
1941
-        if (WP_DEBUG) {
1942
-            add_action('admin_head', array($this, 'add_xdebug_style'));
1943
-        }
1944
-        // taking care of metaboxes
1945
-        if (
1946
-            empty($this->_cpt_route)
1947
-            && (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1948
-        ) {
1949
-            wp_enqueue_script('dashboard');
1950
-        }
1951
-
1952
-        // LOCALIZED DATA
1953
-        // localize script for ajax lazy loading
1954
-        wp_localize_script(
1955
-            EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN,
1956
-            'eeLazyLoadingContainers',
1957
-            apply_filters(
1958
-                'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1959
-                ['espresso_news_post_box_content']
1960
-            )
1961
-        );
1962
-        // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1963
-        // /**
1964
-        //  * help tour stuff
1965
-        //  */
1966
-        // if (! empty($this->_help_tour)) {
1967
-        //     // register the js for kicking things off
1968
-        //     wp_enqueue_script(
1969
-        //         'ee-help-tour',
1970
-        //         EE_ADMIN_URL . 'assets/ee-help-tour.js',
1971
-        //         array('jquery-joyride'),
1972
-        //         EVENT_ESPRESSO_VERSION,
1973
-        //         true
1974
-        //     );
1975
-        //     $tours = array();
1976
-        //     // setup tours for the js tour object
1977
-        //     foreach ($this->_help_tour['tours'] as $tour) {
1978
-        //         if ($tour instanceof EE_Help_Tour) {
1979
-        //             $tours[] = array(
1980
-        //                 'id'      => $tour->get_slug(),
1981
-        //                 'options' => $tour->get_options(),
1982
-        //             );
1983
-        //         }
1984
-        //     }
1985
-        //     wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1986
-        //     // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1987
-        // }
1988
-    }
1989
-
1990
-
1991
-    /**
1992
-     *        admin_footer_scripts_eei18n_js_strings
1993
-     *
1994
-     * @return        void
1995
-     */
1996
-    public function admin_footer_scripts_eei18n_js_strings()
1997
-    {
1998
-        EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1999
-        EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__(
2000
-            'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
2001
-            'event_espresso'
2002
-        );
2003
-        EE_Registry::$i18n_js_strings['January'] = esc_html__('January', 'event_espresso');
2004
-        EE_Registry::$i18n_js_strings['February'] = esc_html__('February', 'event_espresso');
2005
-        EE_Registry::$i18n_js_strings['March'] = esc_html__('March', 'event_espresso');
2006
-        EE_Registry::$i18n_js_strings['April'] = esc_html__('April', 'event_espresso');
2007
-        EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso');
2008
-        EE_Registry::$i18n_js_strings['June'] = esc_html__('June', 'event_espresso');
2009
-        EE_Registry::$i18n_js_strings['July'] = esc_html__('July', 'event_espresso');
2010
-        EE_Registry::$i18n_js_strings['August'] = esc_html__('August', 'event_espresso');
2011
-        EE_Registry::$i18n_js_strings['September'] = esc_html__('September', 'event_espresso');
2012
-        EE_Registry::$i18n_js_strings['October'] = esc_html__('October', 'event_espresso');
2013
-        EE_Registry::$i18n_js_strings['November'] = esc_html__('November', 'event_espresso');
2014
-        EE_Registry::$i18n_js_strings['December'] = esc_html__('December', 'event_espresso');
2015
-        EE_Registry::$i18n_js_strings['Jan'] = esc_html__('Jan', 'event_espresso');
2016
-        EE_Registry::$i18n_js_strings['Feb'] = esc_html__('Feb', 'event_espresso');
2017
-        EE_Registry::$i18n_js_strings['Mar'] = esc_html__('Mar', 'event_espresso');
2018
-        EE_Registry::$i18n_js_strings['Apr'] = esc_html__('Apr', 'event_espresso');
2019
-        EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso');
2020
-        EE_Registry::$i18n_js_strings['Jun'] = esc_html__('Jun', 'event_espresso');
2021
-        EE_Registry::$i18n_js_strings['Jul'] = esc_html__('Jul', 'event_espresso');
2022
-        EE_Registry::$i18n_js_strings['Aug'] = esc_html__('Aug', 'event_espresso');
2023
-        EE_Registry::$i18n_js_strings['Sep'] = esc_html__('Sep', 'event_espresso');
2024
-        EE_Registry::$i18n_js_strings['Oct'] = esc_html__('Oct', 'event_espresso');
2025
-        EE_Registry::$i18n_js_strings['Nov'] = esc_html__('Nov', 'event_espresso');
2026
-        EE_Registry::$i18n_js_strings['Dec'] = esc_html__('Dec', 'event_espresso');
2027
-        EE_Registry::$i18n_js_strings['Sunday'] = esc_html__('Sunday', 'event_espresso');
2028
-        EE_Registry::$i18n_js_strings['Monday'] = esc_html__('Monday', 'event_espresso');
2029
-        EE_Registry::$i18n_js_strings['Tuesday'] = esc_html__('Tuesday', 'event_espresso');
2030
-        EE_Registry::$i18n_js_strings['Wednesday'] = esc_html__('Wednesday', 'event_espresso');
2031
-        EE_Registry::$i18n_js_strings['Thursday'] = esc_html__('Thursday', 'event_espresso');
2032
-        EE_Registry::$i18n_js_strings['Friday'] = esc_html__('Friday', 'event_espresso');
2033
-        EE_Registry::$i18n_js_strings['Saturday'] = esc_html__('Saturday', 'event_espresso');
2034
-        EE_Registry::$i18n_js_strings['Sun'] = esc_html__('Sun', 'event_espresso');
2035
-        EE_Registry::$i18n_js_strings['Mon'] = esc_html__('Mon', 'event_espresso');
2036
-        EE_Registry::$i18n_js_strings['Tue'] = esc_html__('Tue', 'event_espresso');
2037
-        EE_Registry::$i18n_js_strings['Wed'] = esc_html__('Wed', 'event_espresso');
2038
-        EE_Registry::$i18n_js_strings['Thu'] = esc_html__('Thu', 'event_espresso');
2039
-        EE_Registry::$i18n_js_strings['Fri'] = esc_html__('Fri', 'event_espresso');
2040
-        EE_Registry::$i18n_js_strings['Sat'] = esc_html__('Sat', 'event_espresso');
2041
-    }
2042
-
2043
-
2044
-    /**
2045
-     *        load enhanced xdebug styles for ppl with failing eyesight
2046
-     *
2047
-     * @return        void
2048
-     */
2049
-    public function add_xdebug_style()
2050
-    {
2051
-        echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2052
-    }
2053
-
2054
-
2055
-    /************************/
2056
-    /** LIST TABLE METHODS **/
2057
-    /************************/
2058
-    /**
2059
-     * this sets up the list table if the current view requires it.
2060
-     *
2061
-     * @return void
2062
-     * @throws EE_Error
2063
-     * @throws InvalidArgumentException
2064
-     * @throws InvalidDataTypeException
2065
-     * @throws InvalidInterfaceException
2066
-     */
2067
-    protected function _set_list_table()
2068
-    {
2069
-        // first is this a list_table view?
2070
-        if (! isset($this->_route_config['list_table'])) {
2071
-            return;
2072
-        } //not a list_table view so get out.
2073
-        // list table functions are per view specific (because some admin pages might have more than one list table!)
2074
-        $list_table_view = '_set_list_table_views_' . $this->_req_action;
2075
-        if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2076
-            // user error msg
2077
-            $error_msg = esc_html__(
2078
-                'An error occurred. The requested list table views could not be found.',
2079
-                'event_espresso'
2080
-            );
2081
-            // developer error msg
2082
-            $error_msg .= '||'
2083
-                          . sprintf(
2084
-                              esc_html__(
2085
-                                  'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
2086
-                                  'event_espresso'
2087
-                              ),
2088
-                              $this->_req_action,
2089
-                              $list_table_view
2090
-                          );
2091
-            throw new EE_Error($error_msg);
2092
-        }
2093
-        // let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2094
-        $this->_views = apply_filters(
2095
-            'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2096
-            $this->_views
2097
-        );
2098
-        $this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2099
-        $this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2100
-        $this->_set_list_table_view();
2101
-        $this->_set_list_table_object();
2102
-    }
2103
-
2104
-
2105
-    /**
2106
-     * set current view for List Table
2107
-     *
2108
-     * @return void
2109
-     */
2110
-    protected function _set_list_table_view()
2111
-    {
2112
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2113
-        // looking at active items or dumpster diving ?
2114
-        if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
2115
-            $this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2116
-        } else {
2117
-            $this->_view = sanitize_key($this->_req_data['status']);
2118
-        }
2119
-    }
2120
-
2121
-
2122
-    /**
2123
-     * _set_list_table_object
2124
-     * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2125
-     *
2126
-     * @throws InvalidInterfaceException
2127
-     * @throws InvalidArgumentException
2128
-     * @throws InvalidDataTypeException
2129
-     * @throws EE_Error
2130
-     * @throws InvalidInterfaceException
2131
-     */
2132
-    protected function _set_list_table_object()
2133
-    {
2134
-        if (isset($this->_route_config['list_table'])) {
2135
-            if (! class_exists($this->_route_config['list_table'])) {
2136
-                throw new EE_Error(
2137
-                    sprintf(
2138
-                        esc_html__(
2139
-                            'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
2140
-                            'event_espresso'
2141
-                        ),
2142
-                        $this->_route_config['list_table'],
2143
-                        get_class($this)
2144
-                    )
2145
-                );
2146
-            }
2147
-            $this->_list_table_object = $this->loader->getShared(
2148
-                $this->_route_config['list_table'],
2149
-                array($this)
2150
-            );
2151
-        }
2152
-    }
2153
-
2154
-
2155
-    /**
2156
-     * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2157
-     *
2158
-     * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2159
-     *                                                    urls.  The array should be indexed by the view it is being
2160
-     *                                                    added to.
2161
-     * @return array
2162
-     */
2163
-    public function get_list_table_view_RLs($extra_query_args = array())
2164
-    {
2165
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2166
-        if (empty($this->_views)) {
2167
-            $this->_views = array();
2168
-        }
2169
-        // cycle thru views
2170
-        foreach ($this->_views as $key => $view) {
2171
-            $query_args = array();
2172
-            // check for current view
2173
-            $this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : '';
2174
-            $query_args['action'] = $this->_req_action;
2175
-            $query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2176
-            $query_args['status'] = $view['slug'];
2177
-            // merge any other arguments sent in.
2178
-            if (isset($extra_query_args[ $view['slug'] ])) {
2179
-                foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) {
2180
-                    $query_args[] = $extra_query_arg;
2181
-                }
2182
-            }
2183
-            $this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2184
-        }
2185
-        return $this->_views;
2186
-    }
2187
-
2188
-
2189
-    /**
2190
-     * _entries_per_page_dropdown
2191
-     * generates a drop down box for selecting the number of visible rows in an admin page list table
2192
-     *
2193
-     * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2194
-     *         WP does it.
2195
-     * @param int $max_entries total number of rows in the table
2196
-     * @return string
2197
-     */
2198
-    protected function _entries_per_page_dropdown($max_entries = 0)
2199
-    {
2200
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2201
-        $values = array(10, 25, 50, 100);
2202
-        $per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
2203
-        if ($max_entries) {
2204
-            $values[] = $max_entries;
2205
-            sort($values);
2206
-        }
2207
-        $entries_per_page_dropdown = '
124
+	// set via request page and action args.
125
+	protected $_current_page;
126
+
127
+	protected $_current_view;
128
+
129
+	protected $_current_page_view_url;
130
+
131
+	// sanitized request action (and nonce)
132
+
133
+	/**
134
+	 * @var string $_req_action
135
+	 */
136
+	protected $_req_action;
137
+
138
+	/**
139
+	 * @var string $_req_nonce
140
+	 */
141
+	protected $_req_nonce;
142
+
143
+	// search related
144
+	protected $_search_btn_label;
145
+
146
+	protected $_search_box_callback;
147
+
148
+	/**
149
+	 * WP Current Screen object
150
+	 *
151
+	 * @var WP_Screen
152
+	 */
153
+	protected $_current_screen;
154
+
155
+	// for holding EE_Admin_Hooks object when needed (set via set_hook_object())
156
+	protected $_hook_obj;
157
+
158
+	// for holding incoming request data
159
+	protected $_req_data = [];
160
+
161
+	// yes / no array for admin form fields
162
+	protected $_yes_no_values = array();
163
+
164
+	// some default things shared by all child classes
165
+	protected $_default_espresso_metaboxes;
166
+
167
+	/**
168
+	 *    EE_Registry Object
169
+	 *
170
+	 * @var    EE_Registry
171
+	 */
172
+	protected $EE;
173
+
174
+
175
+	/**
176
+	 * This is just a property that flags whether the given route is a caffeinated route or not.
177
+	 *
178
+	 * @var boolean
179
+	 */
180
+	protected $_is_caf = false;
181
+
182
+	/**
183
+	 * whether or not initializePage() has run
184
+	 *
185
+	 * @var boolean
186
+	 */
187
+	protected $initialized = false;
188
+
189
+
190
+	/**
191
+	 * @Constructor
192
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
193
+	 * @throws InvalidArgumentException
194
+	 * @throws InvalidDataTypeException
195
+	 * @throws InvalidInterfaceException
196
+	 * @throws ReflectionException
197
+	 */
198
+	public function __construct($routing = true)
199
+	{
200
+		$this->loader = LoaderFactory::getLoader();
201
+		$this->admin_config = $this->loader->getShared('EE_Admin_Config');
202
+		if (strpos($this->_get_dir(), 'caffeinated') !== false) {
203
+			$this->_is_caf = true;
204
+		}
205
+		$this->_yes_no_values = array(
206
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
207
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
208
+		);
209
+		// set the _req_data property.
210
+		$this->_req_data = array_merge($_GET, $_POST);
211
+		// routing enabled?
212
+		$this->_routing = $routing;
213
+	}
214
+
215
+
216
+	/**
217
+	 * This logic used to be in the constructor, but that caused a chicken <--> egg scenario
218
+	 * for child classes that needed to set properties prior to these methods getting called,
219
+	 * but also needed the parent class to have its construction completed as well.
220
+	 * Bottom line is that constructors should ONLY be used for setting initial properties
221
+	 * and any complex initialization logic should only run after instantiation is complete.
222
+	 *
223
+	 * This method gets called immediately after construction from within
224
+	 *      EE_Admin_Page_Init::_initialize_admin_page()
225
+	 *
226
+	 * @throws EE_Error
227
+	 * @throws InvalidArgumentException
228
+	 * @throws InvalidDataTypeException
229
+	 * @throws InvalidInterfaceException
230
+	 * @throws ReflectionException
231
+	 * @since $VID:$
232
+	 */
233
+	public function initializePage()
234
+	{
235
+		if ($this->initialized) {
236
+			return;
237
+		}
238
+		// set initial page props (child method)
239
+		$this->_init_page_props();
240
+		// set global defaults
241
+		$this->_set_defaults();
242
+		// set early because incoming requests could be ajax related and we need to register those hooks.
243
+		$this->_global_ajax_hooks();
244
+		$this->_ajax_hooks();
245
+		// other_page_hooks have to be early too.
246
+		$this->_do_other_page_hooks();
247
+		// This just allows us to have extending classes do something specific
248
+		// before the parent constructor runs _page_setup().
249
+		if (method_exists($this, '_before_page_setup')) {
250
+			$this->_before_page_setup();
251
+		}
252
+		// set up page dependencies
253
+		$this->_page_setup();
254
+		$this->initialized = true;
255
+	}
256
+
257
+
258
+	/**
259
+	 * _init_page_props
260
+	 * Child classes use to set at least the following properties:
261
+	 * $page_slug.
262
+	 * $page_label.
263
+	 *
264
+	 * @abstract
265
+	 * @return void
266
+	 */
267
+	abstract protected function _init_page_props();
268
+
269
+
270
+	/**
271
+	 * _ajax_hooks
272
+	 * child classes put all their add_action('wp_ajax_{name_of_hook}') hooks in here.
273
+	 * Note: within the ajax callback methods.
274
+	 *
275
+	 * @abstract
276
+	 * @return void
277
+	 */
278
+	abstract protected function _ajax_hooks();
279
+
280
+
281
+	/**
282
+	 * _define_page_props
283
+	 * child classes define page properties in here.  Must include at least:
284
+	 * $_admin_base_url = base_url for all admin pages
285
+	 * $_admin_page_title = default admin_page_title for admin pages
286
+	 * $_labels = array of default labels for various automatically generated elements:
287
+	 *    array(
288
+	 *        'buttons' => array(
289
+	 *            'add' => esc_html__('label for add new button'),
290
+	 *            'edit' => esc_html__('label for edit button'),
291
+	 *            'delete' => esc_html__('label for delete button')
292
+	 *            )
293
+	 *        )
294
+	 *
295
+	 * @abstract
296
+	 * @return void
297
+	 */
298
+	abstract protected function _define_page_props();
299
+
300
+
301
+	/**
302
+	 * _set_page_routes
303
+	 * child classes use this to define the page routes for all subpages handled by the class.  Page routes are
304
+	 * assigned to a action => method pairs in an array and to the $_page_routes property.  Each page route must also
305
+	 * have a 'default' route. Here's the format
306
+	 * $this->_page_routes = array(
307
+	 *        'default' => array(
308
+	 *            'func' => '_default_method_handling_route',
309
+	 *            'args' => array('array','of','args'),
310
+	 *            'noheader' => true, //add this in if this page route is processed before any headers are loaded (i.e.
311
+	 *            ajax request, backend processing)
312
+	 *            'headers_sent_route'=>'headers_route_reference', //add this if noheader=>true, and you want to load a
313
+	 *            headers route after.  The string you enter here should match the defined route reference for a
314
+	 *            headers sent route.
315
+	 *            'capability' => 'route_capability', //indicate a string for minimum capability required to access
316
+	 *            this route.
317
+	 *            'obj_id' => 10 // if this route has an object id, then this can include it (used for capability
318
+	 *            checks).
319
+	 *        ),
320
+	 *        'insert_item' => '_method_for_handling_insert_item' //this can be used if all we need to have is a
321
+	 *        handling method.
322
+	 *        )
323
+	 * )
324
+	 *
325
+	 * @abstract
326
+	 * @return void
327
+	 */
328
+	abstract protected function _set_page_routes();
329
+
330
+
331
+	/**
332
+	 * _set_page_config
333
+	 * child classes use this to define the _page_config array for all subpages handled by the class. Each key in the
334
+	 * array corresponds to the page_route for the loaded page. Format:
335
+	 * $this->_page_config = array(
336
+	 *        'default' => array(
337
+	 *            'labels' => array(
338
+	 *                'buttons' => array(
339
+	 *                    'add' => esc_html__('label for adding item'),
340
+	 *                    'edit' => esc_html__('label for editing item'),
341
+	 *                    'delete' => esc_html__('label for deleting item')
342
+	 *                ),
343
+	 *                'publishbox' => esc_html__('Localized Title for Publish metabox', 'event_espresso')
344
+	 *            ), //optional an array of custom labels for various automatically generated elements to use on the
345
+	 *            page. If this isn't present then the defaults will be used as set for the $this->_labels in
346
+	 *            _define_page_props() method
347
+	 *            'nav' => array(
348
+	 *                'label' => esc_html__('Label for Tab', 'event_espresso').
349
+	 *                'url' => 'http://someurl', //automatically generated UNLESS you define
350
+	 *                'css_class' => 'css-class', //automatically generated UNLESS you define
351
+	 *                'order' => 10, //required to indicate tab position.
352
+	 *                'persistent' => false //if you want the nav tab to ONLY display when the specific route is
353
+	 *                displayed then add this parameter.
354
+	 *            'list_table' => 'name_of_list_table' //string for list table class to be loaded for this admin_page.
355
+	 *            'metaboxes' => array('metabox1', 'metabox2'), //if present this key indicates we want to load
356
+	 *            metaboxes set for eventespresso admin pages.
357
+	 *            'has_metaboxes' => true, //this boolean flag can simply be used to indicate if the route will have
358
+	 *            metaboxes.  Typically this is used if the 'metaboxes' index is not used because metaboxes are added
359
+	 *            later.  We just use this flag to make sure the necessary js gets enqueued on page load.
360
+	 *            'has_help_popups' => false //defaults(true) //this boolean flag can simply be used to indicate if the
361
+	 *            given route has help popups setup and if it does then we need to make sure thickbox is enqueued.
362
+	 *            'columns' => array(4, 2), //this key triggers the setup of a page that uses columns (metaboxes).  The
363
+	 *            array indicates the max number of columns (4) and the default number of columns on page load (2).
364
+	 *            There is an option in the "screen_options" dropdown that is setup so users can pick what columns they
365
+	 *            want to display.
366
+	 *            'help_tabs' => array( //this is used for adding help tabs to a page
367
+	 *                'tab_id' => array(
368
+	 *                    'title' => 'tab_title',
369
+	 *                    'filename' => 'name_of_file_containing_content', //this is the primary method for setting
370
+	 *                    help tab content.  The fallback if it isn't present is to try a the callback.  Filename
371
+	 *                    should match a file in the admin folder's "help_tabs" dir (ie..
372
+	 *                    events/help_tabs/name_of_file_containing_content.help_tab.php)
373
+	 *                    'callback' => 'callback_method_for_content', //if 'filename' isn't present then system will
374
+	 *                    attempt to use the callback which should match the name of a method in the class
375
+	 *                    ),
376
+	 *                'tab2_id' => array(
377
+	 *                    'title' => 'tab2 title',
378
+	 *                    'filename' => 'file_name_2'
379
+	 *                    'callback' => 'callback_method_for_content',
380
+	 *                 ),
381
+	 *            'help_sidebar' => 'callback_for_sidebar_content', //this is used for setting up the sidebar in the
382
+	 *            help tab area on an admin page. @link
383
+	 *            http://make.wordpress.org/core/2011/12/06/help-and-screen-api-changes-in-3-3/
384
+	 *            'help_tour' => array(
385
+	 *                'name_of_help_tour_class', //all help tours shoudl be a child class of EE_Help_Tour and located
386
+	 *                in a folder for this admin page named "help_tours", a file name matching the key given here
387
+	 *                (name_of_help_tour_class.class.php), and class matching key given here (name_of_help_tour_class)
388
+	 *            ),
389
+	 *            'require_nonce' => TRUE //this is used if you want to set a route to NOT require a nonce (default is
390
+	 *            true if it isn't present).  To remove the requirement for a nonce check when this route is visited
391
+	 *            just set
392
+	 *            'require_nonce' to FALSE
393
+	 *            )
394
+	 * )
395
+	 *
396
+	 * @abstract
397
+	 * @return void
398
+	 */
399
+	abstract protected function _set_page_config();
400
+
401
+
402
+
403
+
404
+
405
+	/** end sample help_tour methods **/
406
+	/**
407
+	 * _add_screen_options
408
+	 * Child classes can add any extra wp_screen_options within this method using built-in WP functions/methods for
409
+	 * doing so. Note child classes can also define _add_screen_options_($this->_current_view) to limit screen options
410
+	 * to a particular view.
411
+	 *
412
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
413
+	 *         see also WP_Screen object documents...
414
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
415
+	 * @abstract
416
+	 * @return void
417
+	 */
418
+	abstract protected function _add_screen_options();
419
+
420
+
421
+	/**
422
+	 * _add_feature_pointers
423
+	 * Child classes should use this method for implementing any "feature pointers" (using built-in WP styling js).
424
+	 * Note child classes can also define _add_feature_pointers_($this->_current_view) to limit screen options to a
425
+	 * particular view. Note: this is just a placeholder for now.  Implementation will come down the road See:
426
+	 * WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
427
+	 * extended) also see:
428
+	 *
429
+	 * @link   http://eamann.com/tech/wordpress-portland/
430
+	 * @abstract
431
+	 * @return void
432
+	 */
433
+	abstract protected function _add_feature_pointers();
434
+
435
+
436
+	/**
437
+	 * load_scripts_styles
438
+	 * child classes put their wp_enqueue_script and wp_enqueue_style hooks in here for anything they need loaded for
439
+	 * their pages/subpages.  Note this is for all pages/subpages of the system.  You can also load only specific
440
+	 * scripts/styles per view by putting them in a dynamic function in this format
441
+	 * (load_scripts_styles_{$this->_current_view}) which matches your page route (action request arg)
442
+	 *
443
+	 * @abstract
444
+	 * @return void
445
+	 */
446
+	abstract public function load_scripts_styles();
447
+
448
+
449
+	/**
450
+	 * admin_init
451
+	 * Anything that should be set/executed at 'admin_init' WP hook runtime should be put in here.  This will apply to
452
+	 * all pages/views loaded by child class.
453
+	 *
454
+	 * @abstract
455
+	 * @return void
456
+	 */
457
+	abstract public function admin_init();
458
+
459
+
460
+	/**
461
+	 * admin_notices
462
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply to
463
+	 * all pages/views loaded by child class.
464
+	 *
465
+	 * @abstract
466
+	 * @return void
467
+	 */
468
+	abstract public function admin_notices();
469
+
470
+
471
+	/**
472
+	 * admin_footer_scripts
473
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
474
+	 * will apply to all pages/views loaded by child class.
475
+	 *
476
+	 * @return void
477
+	 */
478
+	abstract public function admin_footer_scripts();
479
+
480
+
481
+	/**
482
+	 * admin_footer
483
+	 * anything triggered by the 'admin_footer' WP action hook should be added to here. This particular method will
484
+	 * apply to all pages/views loaded by child class.
485
+	 *
486
+	 * @return void
487
+	 */
488
+	public function admin_footer()
489
+	{
490
+	}
491
+
492
+
493
+	/**
494
+	 * _global_ajax_hooks
495
+	 * all global add_action('wp_ajax_{name_of_hook}') hooks in here.
496
+	 * Note: within the ajax callback methods.
497
+	 *
498
+	 * @abstract
499
+	 * @return void
500
+	 */
501
+	protected function _global_ajax_hooks()
502
+	{
503
+		// for lazy loading of metabox content
504
+		add_action('wp_ajax_espresso-ajax-content', array($this, 'ajax_metabox_content'), 10);
505
+
506
+		add_action(
507
+			'wp_ajax_espresso_hide_status_change_notice',
508
+			[$this, 'hideStatusChangeNotice']
509
+		);
510
+		add_action(
511
+			'wp_ajax_nopriv_espresso_hide_status_change_notice',
512
+			[$this, 'hideStatusChangeNotice']
513
+		);
514
+	}
515
+
516
+
517
+	public function ajax_metabox_content()
518
+	{
519
+		$contentid = isset($this->_req_data['contentid']) ? $this->_req_data['contentid'] : '';
520
+		$url = isset($this->_req_data['contenturl']) ? $this->_req_data['contenturl'] : '';
521
+		EE_Admin_Page::cached_rss_display($contentid, $url);
522
+		wp_die();
523
+	}
524
+
525
+
526
+	public function hideStatusChangeNotice()
527
+	{
528
+		$response = [];
529
+		try {
530
+			/** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */
531
+			$status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice');
532
+			$response['success'] = $status_change_notice->dismiss() > -1;
533
+		} catch (Exception $exception) {
534
+			$response['errors'] = $exception->getMessage();
535
+		}
536
+		echo wp_json_encode($response);
537
+		exit();
538
+	}
539
+
540
+
541
+	/**
542
+	 * _page_setup
543
+	 * Makes sure any things that need to be loaded early get handled.  We also escape early here if the page requested
544
+	 * doesn't match the object.
545
+	 *
546
+	 * @final
547
+	 * @return void
548
+	 * @throws EE_Error
549
+	 * @throws InvalidArgumentException
550
+	 * @throws ReflectionException
551
+	 * @throws InvalidDataTypeException
552
+	 * @throws InvalidInterfaceException
553
+	 */
554
+	final protected function _page_setup()
555
+	{
556
+		// requires?
557
+		// admin_init stuff - global - we're setting this REALLY early
558
+		// so if EE_Admin pages have to hook into other WP pages they can.
559
+		// But keep in mind, not everything is available from the EE_Admin Page object at this point.
560
+		add_action('admin_init', array($this, 'admin_init_global'), 5);
561
+		// next verify if we need to load anything...
562
+		$this->_current_page = ! empty($_GET['page']) ? sanitize_key($_GET['page']) : '';
563
+		$this->page_folder = strtolower(
564
+			str_replace(array('_Admin_Page', 'Extend_'), '', get_class($this))
565
+		);
566
+		global $ee_menu_slugs;
567
+		$ee_menu_slugs = (array) $ee_menu_slugs;
568
+		if (! defined('DOING_AJAX') && (! $this->_current_page || ! isset($ee_menu_slugs[ $this->_current_page ]))) {
569
+			return;
570
+		}
571
+		// becuz WP List tables have two duplicate select inputs for choosing bulk actions, we need to copy the action from the second to the first
572
+		if (isset($this->_req_data['action2']) && $this->_req_data['action'] === '-1') {
573
+			$this->_req_data['action'] = ! empty($this->_req_data['action2']) && $this->_req_data['action2'] !== '-1'
574
+				? $this->_req_data['action2']
575
+				: $this->_req_data['action'];
576
+		}
577
+		// then set blank or -1 action values to 'default'
578
+		$this->_req_action = isset($this->_req_data['action'])
579
+							 && ! empty($this->_req_data['action'])
580
+							 && $this->_req_data['action'] !== '-1'
581
+			? sanitize_key($this->_req_data['action'])
582
+			: 'default';
583
+		// if action is 'default' after the above BUT we have  'route' var set, then let's use the route as the action.
584
+		//  This covers cases where we're coming in from a list table that isn't on the default route.
585
+		$this->_req_action = $this->_req_action === 'default' && isset($this->_req_data['route'])
586
+			? $this->_req_data['route'] : $this->_req_action;
587
+		// however if we are doing_ajax and we've got a 'route' set then that's what the req_action will be
588
+		$this->_req_action = defined('DOING_AJAX') && isset($this->_req_data['route'])
589
+			? $this->_req_data['route']
590
+			: $this->_req_action;
591
+		$this->_current_view = $this->_req_action;
592
+		$this->_req_nonce = $this->_req_action . '_nonce';
593
+		$this->_define_page_props();
594
+		$this->_current_page_view_url = add_query_arg(
595
+			array('page' => $this->_current_page, 'action' => $this->_current_view),
596
+			$this->_admin_base_url
597
+		);
598
+		// default things
599
+		$this->_default_espresso_metaboxes = array(
600
+			'_espresso_news_post_box',
601
+			'_espresso_links_post_box',
602
+			'_espresso_ratings_request',
603
+			'_espresso_sponsors_post_box',
604
+		);
605
+		// set page configs
606
+		$this->_set_page_routes();
607
+		$this->_set_page_config();
608
+		// let's include any referrer data in our default_query_args for this route for "stickiness".
609
+		if (isset($this->_req_data['wp_referer'])) {
610
+			$this->_default_route_query_args['wp_referer'] = $this->_req_data['wp_referer'];
611
+		}
612
+		// for caffeinated and other extended functionality.
613
+		//  If there is a _extend_page_config method
614
+		// then let's run that to modify the all the various page configuration arrays
615
+		if (method_exists($this, '_extend_page_config')) {
616
+			$this->_extend_page_config();
617
+		}
618
+		// for CPT and other extended functionality.
619
+		// If there is an _extend_page_config_for_cpt
620
+		// then let's run that to modify all the various page configuration arrays.
621
+		if (method_exists($this, '_extend_page_config_for_cpt')) {
622
+			$this->_extend_page_config_for_cpt();
623
+		}
624
+		// filter routes and page_config so addons can add their stuff. Filtering done per class
625
+		$this->_page_routes = apply_filters(
626
+			'FHEE__' . get_class($this) . '__page_setup__page_routes',
627
+			$this->_page_routes,
628
+			$this
629
+		);
630
+		$this->_page_config = apply_filters(
631
+			'FHEE__' . get_class($this) . '__page_setup__page_config',
632
+			$this->_page_config,
633
+			$this
634
+		);
635
+		// if AHEE__EE_Admin_Page__route_admin_request_$this->_current_view method is present
636
+		// then we call it hooked into the AHEE__EE_Admin_Page__route_admin_request action
637
+		if (method_exists($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view)) {
638
+			add_action(
639
+				'AHEE__EE_Admin_Page__route_admin_request',
640
+				array($this, 'AHEE__EE_Admin_Page__route_admin_request_' . $this->_current_view),
641
+				10,
642
+				2
643
+			);
644
+		}
645
+		// next route only if routing enabled
646
+		if ($this->_routing && ! defined('DOING_AJAX')) {
647
+			$this->_verify_routes();
648
+			// next let's just check user_access and kill if no access
649
+			$this->check_user_access();
650
+			if ($this->_is_UI_request) {
651
+				// admin_init stuff - global, all views for this page class, specific view
652
+				add_action('admin_init', array($this, 'admin_init'), 10);
653
+				if (method_exists($this, 'admin_init_' . $this->_current_view)) {
654
+					add_action('admin_init', array($this, 'admin_init_' . $this->_current_view), 15);
655
+				}
656
+			} else {
657
+				// hijack regular WP loading and route admin request immediately
658
+				@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
659
+				$this->route_admin_request();
660
+			}
661
+		}
662
+	}
663
+
664
+
665
+	/**
666
+	 * Provides a way for related child admin pages to load stuff on the loaded admin page.
667
+	 *
668
+	 * @return void
669
+	 * @throws EE_Error
670
+	 */
671
+	private function _do_other_page_hooks()
672
+	{
673
+		$registered_pages = apply_filters('FHEE_do_other_page_hooks_' . $this->page_slug, array());
674
+		foreach ($registered_pages as $page) {
675
+			// now let's setup the file name and class that should be present
676
+			$classname = str_replace('.class.php', '', $page);
677
+			// autoloaders should take care of loading file
678
+			if (! class_exists($classname)) {
679
+				$error_msg[] = sprintf(
680
+					esc_html__(
681
+						'Something went wrong with loading the %s admin hooks page.',
682
+						'event_espresso'
683
+					),
684
+					$page
685
+				);
686
+				$error_msg[] = $error_msg[0]
687
+							   . "\r\n"
688
+							   . sprintf(
689
+								   esc_html__(
690
+									   'There is no class in place for the %1$s admin hooks page.%2$sMake sure you have %3$s defined. If this is a non-EE-core admin page then you also must have an autoloader in place for your class',
691
+									   'event_espresso'
692
+								   ),
693
+								   $page,
694
+								   '<br />',
695
+								   '<strong>' . $classname . '</strong>'
696
+							   );
697
+				throw new EE_Error(implode('||', $error_msg));
698
+			}
699
+			// // notice we are passing the instance of this class to the hook object.
700
+			$this->loader->getShared($classname, [$this]);
701
+		}
702
+	}
703
+
704
+
705
+	/**
706
+	 * @throws DomainException
707
+	 * @throws EE_Error
708
+	 * @throws InvalidArgumentException
709
+	 * @throws InvalidDataTypeException
710
+	 * @throws InvalidInterfaceException
711
+	 * @throws ReflectionException
712
+	 * @since $VID:$
713
+	 */
714
+	public function load_page_dependencies()
715
+	{
716
+		try {
717
+			$this->_load_page_dependencies();
718
+		} catch (EE_Error $e) {
719
+			$e->get_error();
720
+		}
721
+	}
722
+
723
+
724
+	/**
725
+	 * load_page_dependencies
726
+	 * loads things specific to this page class when its loaded.  Really helps with efficiency.
727
+	 *
728
+	 * @return void
729
+	 * @throws DomainException
730
+	 * @throws EE_Error
731
+	 * @throws InvalidArgumentException
732
+	 * @throws InvalidDataTypeException
733
+	 * @throws InvalidInterfaceException
734
+	 * @throws ReflectionException
735
+	 */
736
+	protected function _load_page_dependencies()
737
+	{
738
+		// let's set the current_screen and screen options to override what WP set
739
+		$this->_current_screen = get_current_screen();
740
+		// load admin_notices - global, page class, and view specific
741
+		add_action('admin_notices', array($this, 'admin_notices_global'), 5);
742
+		add_action('admin_notices', array($this, 'admin_notices'), 10);
743
+		if (method_exists($this, 'admin_notices_' . $this->_current_view)) {
744
+			add_action('admin_notices', array($this, 'admin_notices_' . $this->_current_view), 15);
745
+		}
746
+		// load network admin_notices - global, page class, and view specific
747
+		add_action('network_admin_notices', array($this, 'network_admin_notices_global'), 5);
748
+		if (method_exists($this, 'network_admin_notices_' . $this->_current_view)) {
749
+			add_action('network_admin_notices', array($this, 'network_admin_notices_' . $this->_current_view));
750
+		}
751
+		// this will save any per_page screen options if they are present
752
+		$this->_set_per_page_screen_options();
753
+		// setup list table properties
754
+		$this->_set_list_table();
755
+		// child classes can "register" a metabox to be automatically handled via the _page_config array property.
756
+		// However in some cases the metaboxes will need to be added within a route handling callback.
757
+		$this->_add_registered_meta_boxes();
758
+		$this->_add_screen_columns();
759
+		// add screen options - global, page child class, and view specific
760
+		$this->_add_global_screen_options();
761
+		$this->_add_screen_options();
762
+		$add_screen_options = "_add_screen_options_{$this->_current_view}";
763
+		if (method_exists($this, $add_screen_options)) {
764
+			$this->{$add_screen_options}();
765
+		}
766
+		// add help tab(s) and tours- set via page_config and qtips.
767
+		// $this->_add_help_tour();
768
+		$this->_add_help_tabs();
769
+		$this->_add_qtips();
770
+		// add feature_pointers - global, page child class, and view specific
771
+		$this->_add_feature_pointers();
772
+		$this->_add_global_feature_pointers();
773
+		$add_feature_pointer = "_add_feature_pointer_{$this->_current_view}";
774
+		if (method_exists($this, $add_feature_pointer)) {
775
+			$this->{$add_feature_pointer}();
776
+		}
777
+		// enqueue scripts/styles - global, page class, and view specific
778
+		add_action('admin_enqueue_scripts', array($this, 'load_global_scripts_styles'), 5);
779
+		add_action('admin_enqueue_scripts', array($this, 'load_scripts_styles'), 10);
780
+		if (method_exists($this, "load_scripts_styles_{$this->_current_view}")) {
781
+			add_action('admin_enqueue_scripts', array($this, "load_scripts_styles_{$this->_current_view}"), 15);
782
+		}
783
+		add_action('admin_enqueue_scripts', array($this, 'admin_footer_scripts_eei18n_js_strings'), 100);
784
+		// admin_print_footer_scripts - global, page child class, and view specific.
785
+		// NOTE, despite the name, whenever possible, scripts should NOT be loaded using this.
786
+		// In most cases that's doing_it_wrong().  But adding hidden container elements etc.
787
+		// is a good use case. Notice the late priority we're giving these
788
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts_global'), 99);
789
+		add_action('admin_print_footer_scripts', array($this, 'admin_footer_scripts'), 100);
790
+		if (method_exists($this, "admin_footer_scripts_{$this->_current_view}")) {
791
+			add_action('admin_print_footer_scripts', array($this, "admin_footer_scripts_{$this->_current_view}"), 101);
792
+		}
793
+		// admin footer scripts
794
+		add_action('admin_footer', array($this, 'admin_footer_global'), 99);
795
+		add_action('admin_footer', array($this, 'admin_footer'), 100);
796
+		if (method_exists($this, "admin_footer_{$this->_current_view}")) {
797
+			add_action('admin_footer', array($this, "admin_footer_{$this->_current_view}"), 101);
798
+		}
799
+		do_action('FHEE__EE_Admin_Page___load_page_dependencies__after_load', $this->page_slug);
800
+		// targeted hook
801
+		do_action(
802
+			"FHEE__EE_Admin_Page___load_page_dependencies__after_load__{$this->page_slug}__{$this->_req_action}"
803
+		);
804
+	}
805
+
806
+
807
+	/**
808
+	 * _set_defaults
809
+	 * This sets some global defaults for class properties.
810
+	 */
811
+	private function _set_defaults()
812
+	{
813
+		$this->_current_screen = $this->_admin_page_title = $this->_req_action = $this->_req_nonce = null;
814
+		$this->_event = $this->_template_path = $this->_column_template_path = null;
815
+		$this->_nav_tabs = $this->_views = $this->_page_routes = array();
816
+		$this->_page_config = $this->_default_route_query_args = array();
817
+		$this->_default_nav_tab_name = 'overview';
818
+		// init template args
819
+		$this->_template_args = array(
820
+			'admin_page_header'  => '',
821
+			'admin_page_content' => '',
822
+			'post_body_content'  => '',
823
+			'before_list_table'  => '',
824
+			'after_list_table'   => '',
825
+		);
826
+	}
827
+
828
+
829
+	/**
830
+	 * route_admin_request
831
+	 *
832
+	 * @see    _route_admin_request()
833
+	 * @return exception|void error
834
+	 * @throws InvalidArgumentException
835
+	 * @throws InvalidInterfaceException
836
+	 * @throws InvalidDataTypeException
837
+	 * @throws EE_Error
838
+	 * @throws ReflectionException
839
+	 */
840
+	public function route_admin_request()
841
+	{
842
+		try {
843
+			$this->_route_admin_request();
844
+		} catch (EE_Error $e) {
845
+			$e->get_error();
846
+		}
847
+	}
848
+
849
+
850
+	public function set_wp_page_slug($wp_page_slug)
851
+	{
852
+		$this->_wp_page_slug = $wp_page_slug;
853
+		// if in network admin then we need to append "-network" to the page slug. Why? Because that's how WP rolls...
854
+		if (is_network_admin()) {
855
+			$this->_wp_page_slug .= '-network';
856
+		}
857
+	}
858
+
859
+
860
+	/**
861
+	 * _verify_routes
862
+	 * All this method does is verify the incoming request and make sure that routes exist for it.  We do this early so
863
+	 * we know if we need to drop out.
864
+	 *
865
+	 * @return bool
866
+	 * @throws EE_Error
867
+	 */
868
+	protected function _verify_routes()
869
+	{
870
+		if (! $this->_current_page && ! defined('DOING_AJAX')) {
871
+			return false;
872
+		}
873
+		$this->_route = false;
874
+		// check that the page_routes array is not empty
875
+		if (empty($this->_page_routes)) {
876
+			// user error msg
877
+			$error_msg = sprintf(
878
+				esc_html__('No page routes have been set for the %s admin page.', 'event_espresso'),
879
+				$this->_admin_page_title
880
+			);
881
+			// developer error msg
882
+			$error_msg .= '||' . $error_msg
883
+						  . esc_html__(
884
+							  ' Make sure the "set_page_routes()" method exists, and is setting the "_page_routes" array properly.',
885
+							  'event_espresso'
886
+						  );
887
+			throw new EE_Error($error_msg);
888
+		}
889
+		// and that the requested page route exists
890
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
891
+			$this->_route = $this->_page_routes[ $this->_req_action ];
892
+			$this->_route_config = isset($this->_page_config[ $this->_req_action ])
893
+				? $this->_page_config[ $this->_req_action ] : array();
894
+		} else {
895
+			// user error msg
896
+			$error_msg = sprintf(
897
+				esc_html__(
898
+					'The requested page route does not exist for the %s admin page.',
899
+					'event_espresso'
900
+				),
901
+				$this->_admin_page_title
902
+			);
903
+			// developer error msg
904
+			$error_msg .= '||' . $error_msg
905
+						  . sprintf(
906
+							  esc_html__(
907
+								  ' Create a key in the "_page_routes" array named "%s" and set its value to the appropriate method.',
908
+								  'event_espresso'
909
+							  ),
910
+							  $this->_req_action
911
+						  );
912
+			throw new EE_Error($error_msg);
913
+		}
914
+		// and that a default route exists
915
+		if (! array_key_exists('default', $this->_page_routes)) {
916
+			// user error msg
917
+			$error_msg = sprintf(
918
+				esc_html__(
919
+					'A default page route has not been set for the % admin page.',
920
+					'event_espresso'
921
+				),
922
+				$this->_admin_page_title
923
+			);
924
+			// developer error msg
925
+			$error_msg .= '||' . $error_msg
926
+						  . esc_html__(
927
+							  ' Create a key in the "_page_routes" array named "default" and set its value to your default page method.',
928
+							  'event_espresso'
929
+						  );
930
+			throw new EE_Error($error_msg);
931
+		}
932
+
933
+		// first lets' catch if the UI request has EVER been set.
934
+		if ($this->_is_UI_request === null) {
935
+			// lets set if this is a UI request or not.
936
+			$this->_is_UI_request = ! isset($this->_req_data['noheader']) || $this->_req_data['noheader'] !== true;
937
+			// wait a minute... we might have a noheader in the route array
938
+			$this->_is_UI_request = is_array($this->_route)
939
+									&& isset($this->_route['noheader'])
940
+									&& $this->_route['noheader'] ? false : $this->_is_UI_request;
941
+		}
942
+		$this->_set_current_labels();
943
+		return true;
944
+	}
945
+
946
+
947
+	/**
948
+	 * this method simply verifies a given route and makes sure its an actual route available for the loaded page
949
+	 *
950
+	 * @param  string $route the route name we're verifying
951
+	 * @return mixed (bool|Exception)      we'll throw an exception if this isn't a valid route.
952
+	 * @throws EE_Error
953
+	 */
954
+	protected function _verify_route($route)
955
+	{
956
+		if (array_key_exists($this->_req_action, $this->_page_routes)) {
957
+			return true;
958
+		}
959
+		// user error msg
960
+		$error_msg = sprintf(
961
+			esc_html__('The given page route does not exist for the %s admin page.', 'event_espresso'),
962
+			$this->_admin_page_title
963
+		);
964
+		// developer error msg
965
+		$error_msg .= '||' . $error_msg
966
+					  . sprintf(
967
+						  esc_html__(
968
+							  ' Check the route you are using in your method (%s) and make sure it matches a route set in your "_page_routes" array property',
969
+							  'event_espresso'
970
+						  ),
971
+						  $route
972
+					  );
973
+		throw new EE_Error($error_msg);
974
+	}
975
+
976
+
977
+	/**
978
+	 * perform nonce verification
979
+	 * This method has be encapsulated here so that any ajax requests that bypass normal routes can verify their nonces
980
+	 * using this method (and save retyping!)
981
+	 *
982
+	 * @param string $nonce     The nonce sent
983
+	 * @param string $nonce_ref The nonce reference string (name0)
984
+	 * @return void
985
+	 * @throws EE_Error
986
+	 * @throws InvalidArgumentException
987
+	 * @throws InvalidDataTypeException
988
+	 * @throws InvalidInterfaceException
989
+	 */
990
+	protected function _verify_nonce($nonce, $nonce_ref)
991
+	{
992
+		// verify nonce against expected value
993
+		if (! wp_verify_nonce($nonce, $nonce_ref)) {
994
+			// these are not the droids you are looking for !!!
995
+			$msg = sprintf(
996
+				esc_html__('%sNonce Fail.%s', 'event_espresso'),
997
+				'<a href="http://www.youtube.com/watch?v=56_S0WeTkzs">',
998
+				'</a>'
999
+			);
1000
+			if (WP_DEBUG) {
1001
+				$msg .= "\n  "
1002
+						. sprintf(
1003
+							esc_html__(
1004
+								'In order to dynamically generate nonces for your actions, use the %s::add_query_args_and_nonce() method. May the Nonce be with you!',
1005
+								'event_espresso'
1006
+							),
1007
+							EE_Admin_Page::class
1008
+						);
1009
+			}
1010
+			if (! defined('DOING_AJAX')) {
1011
+				wp_die($msg);
1012
+			} else {
1013
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1014
+				$this->_return_json();
1015
+			}
1016
+		}
1017
+	}
1018
+
1019
+
1020
+	/**
1021
+	 * _route_admin_request()
1022
+	 * Meat and potatoes of the class.  Basically, this dude checks out what's being requested and sees if there are
1023
+	 * some doodads to work the magic and handle the flingjangy. Translation:  Checks if the requested action is listed
1024
+	 * in the page routes and then will try to load the corresponding method.
1025
+	 *
1026
+	 * @return void
1027
+	 * @throws EE_Error
1028
+	 * @throws InvalidArgumentException
1029
+	 * @throws InvalidDataTypeException
1030
+	 * @throws InvalidInterfaceException
1031
+	 * @throws ReflectionException
1032
+	 */
1033
+	protected function _route_admin_request()
1034
+	{
1035
+		if (! $this->_is_UI_request) {
1036
+			$this->_verify_routes();
1037
+		}
1038
+		$nonce_check = isset($this->_route_config['require_nonce'])
1039
+			? $this->_route_config['require_nonce']
1040
+			: true;
1041
+		if ($this->_req_action !== 'default' && $nonce_check) {
1042
+			// set nonce from post data
1043
+			$nonce = isset($this->_req_data[ $this->_req_nonce ])
1044
+				? sanitize_text_field($this->_req_data[ $this->_req_nonce ])
1045
+				: '';
1046
+			$this->_verify_nonce($nonce, $this->_req_nonce);
1047
+		}
1048
+		// set the nav_tabs array but ONLY if this is  UI_request
1049
+		if ($this->_is_UI_request) {
1050
+			$this->_set_nav_tabs();
1051
+		}
1052
+		// grab callback function
1053
+		$func = is_array($this->_route) && isset($this->_route['func']) ? $this->_route['func'] : $this->_route;
1054
+		// check if callback has args
1055
+		$args = is_array($this->_route) && isset($this->_route['args']) ? $this->_route['args'] : array();
1056
+		$error_msg = '';
1057
+		// action right before calling route
1058
+		// (hook is something like 'AHEE__Registrations_Admin_Page__route_admin_request')
1059
+		if (! did_action('AHEE__EE_Admin_Page__route_admin_request')) {
1060
+			do_action('AHEE__EE_Admin_Page__route_admin_request', $this->_current_view, $this);
1061
+		}
1062
+		// right before calling the route, let's remove _wp_http_referer from the
1063
+		// $_SERVER[REQUEST_URI] global (its now in _req_data for route processing).
1064
+		$_SERVER['REQUEST_URI'] = remove_query_arg(
1065
+			'_wp_http_referer',
1066
+			wp_unslash($_SERVER['REQUEST_URI'])
1067
+		);
1068
+		if (! empty($func)) {
1069
+			if (is_array($func)) {
1070
+				list($class, $method) = $func;
1071
+			} elseif (strpos($func, '::') !== false) {
1072
+				list($class, $method) = explode('::', $func);
1073
+			} else {
1074
+				$class = $this;
1075
+				$method = $func;
1076
+			}
1077
+			if (! (is_object($class) && $class === $this)) {
1078
+				// send along this admin page object for access by addons.
1079
+				$args['admin_page_object'] = $this;
1080
+			}
1081
+			// is it a method on a class that doesn't work?
1082
+			if (
1083
+				((method_exists($class, $method)
1084
+				  && call_user_func_array(array($class, $method), $args) === false)
1085
+				 && (// is it a standalone function that doesn't work?
1086
+					 function_exists($method)
1087
+					 && call_user_func_array(
1088
+						 $func,
1089
+						 array_merge(array('admin_page_object' => $this), $args)
1090
+					 ) === false
1091
+				 )) || (// is it neither a class method NOR a standalone function?
1092
+					! function_exists($method)
1093
+					&& ! method_exists($class, $method)
1094
+				)
1095
+			) {
1096
+				// user error msg
1097
+				$error_msg = esc_html__(
1098
+					'An error occurred. The  requested page route could not be found.',
1099
+					'event_espresso'
1100
+				);
1101
+				// developer error msg
1102
+				$error_msg .= '||';
1103
+				$error_msg .= sprintf(
1104
+					esc_html__(
1105
+						'Page route "%s" could not be called. Check that the spelling for method names and actions in the "_page_routes" array are all correct.',
1106
+						'event_espresso'
1107
+					),
1108
+					$method
1109
+				);
1110
+			}
1111
+			if (! empty($error_msg)) {
1112
+				throw new EE_Error($error_msg);
1113
+			}
1114
+		}
1115
+		// if we've routed and this route has a no headers route AND a sent_headers_route,
1116
+		// then we need to reset the routing properties to the new route.
1117
+		// now if UI request is FALSE and noheader is true AND we have a headers_sent_route in the route array then let's set UI_request to true because the no header route has a second func after headers have been sent.
1118
+		if (
1119
+			$this->_is_UI_request === false
1120
+			&& is_array($this->_route)
1121
+			&& ! empty($this->_route['headers_sent_route'])
1122
+		) {
1123
+			$this->_reset_routing_properties($this->_route['headers_sent_route']);
1124
+		}
1125
+	}
1126
+
1127
+
1128
+	/**
1129
+	 * This method just allows the resetting of page properties in the case where a no headers
1130
+	 * route redirects to a headers route in its route config.
1131
+	 *
1132
+	 * @since   4.3.0
1133
+	 * @param  string $new_route New (non header) route to redirect to.
1134
+	 * @return   void
1135
+	 * @throws ReflectionException
1136
+	 * @throws InvalidArgumentException
1137
+	 * @throws InvalidInterfaceException
1138
+	 * @throws InvalidDataTypeException
1139
+	 * @throws EE_Error
1140
+	 */
1141
+	protected function _reset_routing_properties($new_route)
1142
+	{
1143
+		$this->_is_UI_request = true;
1144
+		// now we set the current route to whatever the headers_sent_route is set at
1145
+		$this->_req_data['action'] = $new_route;
1146
+		// rerun page setup
1147
+		$this->_page_setup();
1148
+	}
1149
+
1150
+
1151
+	/**
1152
+	 * _add_query_arg
1153
+	 * adds nonce to array of arguments then calls WP add_query_arg function
1154
+	 *(internally just uses EEH_URL's function with the same name)
1155
+	 *
1156
+	 * @param array  $args
1157
+	 * @param string $url
1158
+	 * @param bool   $sticky                  if true, then the existing Request params will be appended to the
1159
+	 *                                        generated url in an associative array indexed by the key 'wp_referer';
1160
+	 *                                        Example usage: If the current page is:
1161
+	 *                                        http://mydomain.com/wp-admin/admin.php?page=espresso_registrations
1162
+	 *                                        &action=default&event_id=20&month_range=March%202015
1163
+	 *                                        &_wpnonce=5467821
1164
+	 *                                        and you call:
1165
+	 *                                        EE_Admin_Page::add_query_args_and_nonce(
1166
+	 *                                        array(
1167
+	 *                                        'action' => 'resend_something',
1168
+	 *                                        'page=>espresso_registrations'
1169
+	 *                                        ),
1170
+	 *                                        $some_url,
1171
+	 *                                        true
1172
+	 *                                        );
1173
+	 *                                        It will produce a url in this structure:
1174
+	 *                                        http://{$some_url}/?page=espresso_registrations&action=resend_something
1175
+	 *                                        &wp_referer[action]=default&wp_referer[event_id]=20&wpreferer[
1176
+	 *                                        month_range]=March%202015
1177
+	 * @param   bool $exclude_nonce           If true, the the nonce will be excluded from the generated nonce.
1178
+	 * @return string
1179
+	 */
1180
+	public static function add_query_args_and_nonce(
1181
+		$args = array(),
1182
+		$url = '',
1183
+		$sticky = false,
1184
+		$exclude_nonce = false
1185
+	) {
1186
+		// if there is a _wp_http_referer include the values from the request but only if sticky = true
1187
+		if ($sticky) {
1188
+			$request = $_REQUEST;
1189
+			unset($request['_wp_http_referer'], $request['wp_referer']);
1190
+			foreach ($request as $key => $value) {
1191
+				// do not add nonces
1192
+				if (strpos($key, 'nonce') !== false) {
1193
+					continue;
1194
+				}
1195
+				$args[ 'wp_referer[' . $key . ']' ] = $value;
1196
+			}
1197
+		}
1198
+		return EEH_URL::add_query_args_and_nonce($args, $url, $exclude_nonce);
1199
+	}
1200
+
1201
+
1202
+	/**
1203
+	 * This returns a generated link that will load the related help tab.
1204
+	 *
1205
+	 * @param  string $help_tab_id the id for the connected help tab
1206
+	 * @param  string $icon_style  (optional) include css class for the style you want to use for the help icon.
1207
+	 * @param  string $help_text   (optional) send help text you want to use for the link if default not to be used
1208
+	 * @uses EEH_Template::get_help_tab_link()
1209
+	 * @return string              generated link
1210
+	 */
1211
+	protected function _get_help_tab_link($help_tab_id, $icon_style = '', $help_text = '')
1212
+	{
1213
+		return EEH_Template::get_help_tab_link(
1214
+			$help_tab_id,
1215
+			$this->page_slug,
1216
+			$this->_req_action,
1217
+			$icon_style,
1218
+			$help_text
1219
+		);
1220
+	}
1221
+
1222
+
1223
+	/**
1224
+	 * _add_help_tabs
1225
+	 * Note child classes define their help tabs within the page_config array.
1226
+	 *
1227
+	 * @link   http://codex.wordpress.org/Function_Reference/add_help_tab
1228
+	 * @return void
1229
+	 * @throws DomainException
1230
+	 * @throws EE_Error
1231
+	 * @throws ReflectionException
1232
+	 */
1233
+	protected function _add_help_tabs()
1234
+	{
1235
+		$tour_buttons = '';
1236
+		if (isset($this->_page_config[ $this->_req_action ])) {
1237
+			$config = $this->_page_config[ $this->_req_action ];
1238
+			// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1239
+			// is there a help tour for the current route?  if there is let's setup the tour buttons
1240
+			// if (isset($this->_help_tour[ $this->_req_action ])) {
1241
+			//     $tb = array();
1242
+			//     $tour_buttons = '<div class="ee-abs-container"><div class="ee-help-tour-restart-buttons">';
1243
+			//     foreach ($this->_help_tour['tours'] as $tour) {
1244
+			//         // if this is the end tour then we don't need to setup a button
1245
+			//         if ($tour instanceof EE_Help_Tour_final_stop || ! $tour instanceof EE_Help_Tour) {
1246
+			//             continue;
1247
+			//         }
1248
+			//         $tb[] = '<button id="trigger-tour-'
1249
+			//                 . $tour->get_slug()
1250
+			//                 . '" class="button-primary trigger-ee-help-tour">'
1251
+			//                 . $tour->get_label()
1252
+			//                 . '</button>';
1253
+			//     }
1254
+			//     $tour_buttons .= implode('<br />', $tb);
1255
+			//     $tour_buttons .= '</div></div>';
1256
+			// }
1257
+			// let's see if there is a help_sidebar set for the current route and we'll set that up for usage as well.
1258
+			if (is_array($config) && isset($config['help_sidebar'])) {
1259
+				// check that the callback given is valid
1260
+				if (! method_exists($this, $config['help_sidebar'])) {
1261
+					throw new EE_Error(
1262
+						sprintf(
1263
+							esc_html__(
1264
+								'The _page_config array has a callback set for the "help_sidebar" option.  However the callback given (%s) is not a valid callback.  Doublecheck the spelling and make sure this method exists for the class %s',
1265
+								'event_espresso'
1266
+							),
1267
+							$config['help_sidebar'],
1268
+							get_class($this)
1269
+						)
1270
+					);
1271
+				}
1272
+				$content = apply_filters(
1273
+					'FHEE__' . get_class($this) . '__add_help_tabs__help_sidebar',
1274
+					$this->{$config['help_sidebar']}()
1275
+				);
1276
+				$content .= $tour_buttons; // add help tour buttons.
1277
+				// do we have any help tours setup?  Cause if we do we want to add the buttons
1278
+				$this->_current_screen->set_help_sidebar($content);
1279
+			}
1280
+			// if there ARE tour buttons...
1281
+			if (! empty($tour_buttons)) {
1282
+				// if we DON'T have config help sidebar then we'll just add the tour buttons to the sidebar.
1283
+				if (! isset($config['help_sidebar'])) {
1284
+					$this->_current_screen->set_help_sidebar($tour_buttons);
1285
+				}
1286
+				// handle if no help_tabs are set so the sidebar will still show for the help tour buttons
1287
+				if (! isset($config['help_tabs'])) {
1288
+					$_ht['id'] = $this->page_slug;
1289
+					$_ht['title'] = esc_html__('Help Tours', 'event_espresso');
1290
+					$_ht['content'] = '<p>'
1291
+									  . esc_html__(
1292
+										  'The buttons to the right allow you to start/restart any help tours available for this page',
1293
+										  'event_espresso'
1294
+									  ) . '</p>';
1295
+					$this->_current_screen->add_help_tab($_ht);
1296
+				}
1297
+			}
1298
+			if (! isset($config['help_tabs'])) {
1299
+				return;
1300
+			} //no help tabs for this route
1301
+			foreach ((array) $config['help_tabs'] as $tab_id => $cfg) {
1302
+				// we're here so there ARE help tabs!
1303
+				// make sure we've got what we need
1304
+				if (! isset($cfg['title'])) {
1305
+					throw new EE_Error(
1306
+						esc_html__(
1307
+							'The _page_config array is not set up properly for help tabs.  It is missing a title',
1308
+							'event_espresso'
1309
+						)
1310
+					);
1311
+				}
1312
+				if (! isset($cfg['filename']) && ! isset($cfg['callback']) && ! isset($cfg['content'])) {
1313
+					throw new EE_Error(
1314
+						esc_html__(
1315
+							'The _page_config array is not setup properly for help tabs. It is missing a either a filename reference, or a callback reference or a content reference so there is no way to know the content for the help tab',
1316
+							'event_espresso'
1317
+						)
1318
+					);
1319
+				}
1320
+				// first priority goes to content.
1321
+				if (! empty($cfg['content'])) {
1322
+					$content = ! empty($cfg['content']) ? $cfg['content'] : null;
1323
+					// second priority goes to filename
1324
+				} elseif (! empty($cfg['filename'])) {
1325
+					$file_path = $this->_get_dir() . '/help_tabs/' . $cfg['filename'] . '.help_tab.php';
1326
+					// it's possible that the file is located on decaf route (and above sets up for caf route, if this is the case then lets check decaf route too)
1327
+					$file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1328
+															 . basename($this->_get_dir())
1329
+															 . '/help_tabs/'
1330
+															 . $cfg['filename']
1331
+															 . '.help_tab.php' : $file_path;
1332
+					// if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1333
+					if (! isset($cfg['callback']) && ! is_readable($file_path)) {
1334
+						EE_Error::add_error(
1335
+							sprintf(
1336
+								esc_html__(
1337
+									'The filename given for the help tab %s is not a valid file and there is no other configuration for the tab content.  Please check that the string you set for the help tab on this route (%s) is the correct spelling.  The file should be in %s',
1338
+									'event_espresso'
1339
+								),
1340
+								$tab_id,
1341
+								key($config),
1342
+								$file_path
1343
+							),
1344
+							__FILE__,
1345
+							__FUNCTION__,
1346
+							__LINE__
1347
+						);
1348
+						return;
1349
+					}
1350
+					$template_args['admin_page_obj'] = $this;
1351
+					$content = EEH_Template::display_template(
1352
+						$file_path,
1353
+						$template_args,
1354
+						true
1355
+					);
1356
+				} else {
1357
+					$content = '';
1358
+				}
1359
+				// check if callback is valid
1360
+				if (
1361
+					empty($content) && (
1362
+						! isset($cfg['callback']) || ! method_exists($this, $cfg['callback'])
1363
+					)
1364
+				) {
1365
+					EE_Error::add_error(
1366
+						sprintf(
1367
+							esc_html__(
1368
+								'The callback given for a %s help tab on this page does not content OR a corresponding method for generating the content.  Check the spelling or make sure the method is present.',
1369
+								'event_espresso'
1370
+							),
1371
+							$cfg['title']
1372
+						),
1373
+						__FILE__,
1374
+						__FUNCTION__,
1375
+						__LINE__
1376
+					);
1377
+					return;
1378
+				}
1379
+				// setup config array for help tab method
1380
+				$id = $this->page_slug . '-' . $this->_req_action . '-' . $tab_id;
1381
+				$_ht = array(
1382
+					'id'       => $id,
1383
+					'title'    => $cfg['title'],
1384
+					'callback' => isset($cfg['callback']) && empty($content) ? array($this, $cfg['callback']) : null,
1385
+					'content'  => $content,
1386
+				);
1387
+				$this->_current_screen->add_help_tab($_ht);
1388
+			}
1389
+		}
1390
+	}
1391
+
1392
+
1393
+	/**
1394
+	 * This basically checks loaded $_page_config property to see if there are any help_tours defined.  "help_tours" is
1395
+	 * an array with properties for setting up usage of the joyride plugin
1396
+	 *
1397
+	 * @link   http://zurb.com/playground/jquery-joyride-feature-tour-plugin
1398
+	 * @see    instructions regarding the format and construction of the "help_tour" array element is found in the
1399
+	 *         _set_page_config() comments
1400
+	 * @return void
1401
+	 * @throws EE_Error
1402
+	 * @throws InvalidArgumentException
1403
+	 * @throws InvalidDataTypeException
1404
+	 * @throws InvalidInterfaceException
1405
+	 * @throws ReflectionException
1406
+	 */
1407
+	protected function _add_help_tour()
1408
+	{
1409
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1410
+		// $tours = array();
1411
+		// $this->_help_tour = array();
1412
+		// // exit early if help tours are turned off globally
1413
+		// if ((defined('EE_DISABLE_HELP_TOURS') && EE_DISABLE_HELP_TOURS)
1414
+		//     || ! EE_Registry::instance()->CFG->admin->help_tour_activation
1415
+		// ) {
1416
+		//     return;
1417
+		// }
1418
+		// // loop through _page_config to find any help_tour defined
1419
+		// foreach ($this->_page_config as $route => $config) {
1420
+		//     // we're only going to set things up for this route
1421
+		//     if ($route !== $this->_req_action) {
1422
+		//         continue;
1423
+		//     }
1424
+		//     if (isset($config['help_tour'])) {
1425
+		//         foreach ($config['help_tour'] as $tour) {
1426
+		//             $file_path = $this->_get_dir() . '/help_tours/' . $tour . '.class.php';
1427
+		//             // let's see if we can get that file...
1428
+		//             // if not its possible this is a decaf route not set in caffeinated
1429
+		//             // so lets try and get the caffeinated equivalent
1430
+		//             $file_path = ! is_readable($file_path) ? EE_ADMIN_PAGES
1431
+		//                                                      . basename($this->_get_dir())
1432
+		//                                                      . '/help_tours/'
1433
+		//                                                      . $tour
1434
+		//                                                      . '.class.php' : $file_path;
1435
+		//             // if file is STILL not readable then let's do a EE_Error so its more graceful than a fatal error.
1436
+		//             if (! is_readable($file_path)) {
1437
+		//                 EE_Error::add_error(
1438
+		//                     sprintf(
1439
+		//                         esc_html__(
1440
+		//                             'The file path given for the help tour (%s) is not a valid path.  Please check that the string you set for the help tour on this route (%s) is the correct spelling',
1441
+		//                             'event_espresso'
1442
+		//                         ),
1443
+		//                         $file_path,
1444
+		//                         $tour
1445
+		//                     ),
1446
+		//                     __FILE__,
1447
+		//                     __FUNCTION__,
1448
+		//                     __LINE__
1449
+		//                 );
1450
+		//                 return;
1451
+		//             }
1452
+		//             require_once $file_path;
1453
+		//             if (! class_exists($tour)) {
1454
+		//                 $error_msg[] = sprintf(
1455
+		//                     esc_html__('Something went wrong with loading the %s Help Tour Class.', 'event_espresso'),
1456
+		//                     $tour
1457
+		//                 );
1458
+		//                 $error_msg[] = $error_msg[0] . "\r\n"
1459
+		//                                . sprintf(
1460
+		//                                    esc_html__(
1461
+		//                                        'There is no class in place for the %s help tour.%s Make sure you have <strong>%s</strong> defined in the "help_tour" array for the %s route of the % admin page.',
1462
+		//                                        'event_espresso'
1463
+		//                                    ),
1464
+		//                                    $tour,
1465
+		//                                    '<br />',
1466
+		//                                    $tour,
1467
+		//                                    $this->_req_action,
1468
+		//                                    get_class($this)
1469
+		//                                );
1470
+		//                 throw new EE_Error(implode('||', $error_msg));
1471
+		//             }
1472
+		//             $tour_obj = new $tour($this->_is_caf);
1473
+		//             $tours[] = $tour_obj;
1474
+		//             $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($tour_obj);
1475
+		//         }
1476
+		//         // let's inject the end tour stop element common to all pages... this will only get seen once per machine.
1477
+		//         $end_stop_tour = new EE_Help_Tour_final_stop($this->_is_caf);
1478
+		//         $tours[] = $end_stop_tour;
1479
+		//         $this->_help_tour[ $route ][] = EEH_Template::help_tour_stops_generator($end_stop_tour);
1480
+		//     }
1481
+		// }
1482
+		//
1483
+		// if (! empty($tours)) {
1484
+		//     $this->_help_tour['tours'] = $tours;
1485
+		// }
1486
+		// // that's it!  Now that the $_help_tours property is set (or not)
1487
+		// // the scripts and html should be taken care of automatically.
1488
+		//
1489
+		// /**
1490
+		//  * Allow extending the help tours variable.
1491
+		//  *
1492
+		//  * @param Array $_help_tour The array containing all help tour information to be displayed.
1493
+		//  */
1494
+		// $this->_help_tour = apply_filters('FHEE__EE_Admin_Page___add_help_tour___help_tour', $this->_help_tour);
1495
+	}
1496
+
1497
+
1498
+	/**
1499
+	 * This simply sets up any qtips that have been defined in the page config
1500
+	 *
1501
+	 * @return void
1502
+	 * @throws ReflectionException
1503
+	 * @throws EE_Error
1504
+	 */
1505
+	protected function _add_qtips()
1506
+	{
1507
+		if (isset($this->_route_config['qtips'])) {
1508
+			$qtips = (array) $this->_route_config['qtips'];
1509
+			// load qtip loader
1510
+			$path = array(
1511
+				$this->_get_dir() . '/qtips/',
1512
+				EE_ADMIN_PAGES . basename($this->_get_dir()) . '/qtips/',
1513
+			);
1514
+			$qtip_loader = EEH_Qtip_Loader::instance();
1515
+			if ($qtip_loader instanceof EEH_Qtip_Loader) {
1516
+				$qtip_loader->register($qtips, $path);
1517
+			}
1518
+		}
1519
+	}
1520
+
1521
+
1522
+	/**
1523
+	 * _set_nav_tabs
1524
+	 * This sets up the nav tabs from the page_routes array.  This method can be overwritten by child classes if you
1525
+	 * wish to add additional tabs or modify accordingly.
1526
+	 *
1527
+	 * @return void
1528
+	 * @throws InvalidArgumentException
1529
+	 * @throws InvalidInterfaceException
1530
+	 * @throws InvalidDataTypeException
1531
+	 */
1532
+	protected function _set_nav_tabs()
1533
+	{
1534
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1535
+		$i = 0;
1536
+		foreach ($this->_page_config as $slug => $config) {
1537
+			if (
1538
+				! is_array($config)
1539
+				|| (
1540
+					is_array($config)
1541
+					&& (
1542
+						(isset($config['nav']) && ! $config['nav'])
1543
+						|| ! isset($config['nav'])
1544
+					)
1545
+				)
1546
+			) {
1547
+				continue;
1548
+			}
1549
+			// no nav tab for this config
1550
+			// check for persistent flag
1551
+			if ($slug !== $this->_req_action && isset($config['nav']['persistent']) && ! $config['nav']['persistent']) {
1552
+				// nav tab is only to appear when route requested.
1553
+				continue;
1554
+			}
1555
+			if (! $this->check_user_access($slug, true)) {
1556
+				// no nav tab because current user does not have access.
1557
+				continue;
1558
+			}
1559
+			$css_class = isset($config['css_class']) ? $config['css_class'] . ' ' : '';
1560
+			$this->_nav_tabs[ $slug ] = array(
1561
+				'url'       => isset($config['nav']['url'])
1562
+					? $config['nav']['url']
1563
+					: EE_Admin_Page::add_query_args_and_nonce(
1564
+						array('action' => $slug),
1565
+						$this->_admin_base_url
1566
+					),
1567
+				'link_text' => isset($config['nav']['label'])
1568
+					? $config['nav']['label']
1569
+					: ucwords(
1570
+						str_replace('_', ' ', $slug)
1571
+					),
1572
+				'css_class' => $this->_req_action === $slug ? $css_class . 'nav-tab-active' : $css_class,
1573
+				'order'     => isset($config['nav']['order']) ? $config['nav']['order'] : $i,
1574
+			);
1575
+			$i++;
1576
+		}
1577
+		// if $this->_nav_tabs is empty then lets set the default
1578
+		if (empty($this->_nav_tabs)) {
1579
+			$this->_nav_tabs[ $this->_default_nav_tab_name ] = array(
1580
+				'url'       => $this->_admin_base_url,
1581
+				'link_text' => ucwords(str_replace('_', ' ', $this->_default_nav_tab_name)),
1582
+				'css_class' => 'nav-tab-active',
1583
+				'order'     => 10,
1584
+			);
1585
+		}
1586
+		// now let's sort the tabs according to order
1587
+		usort($this->_nav_tabs, array($this, '_sort_nav_tabs'));
1588
+	}
1589
+
1590
+
1591
+	/**
1592
+	 * _set_current_labels
1593
+	 * This method modifies the _labels property with any optional specific labels indicated in the _page_routes
1594
+	 * property array
1595
+	 *
1596
+	 * @return void
1597
+	 */
1598
+	private function _set_current_labels()
1599
+	{
1600
+		if (is_array($this->_route_config) && isset($this->_route_config['labels'])) {
1601
+			foreach ($this->_route_config['labels'] as $label => $text) {
1602
+				if (is_array($text)) {
1603
+					foreach ($text as $sublabel => $subtext) {
1604
+						$this->_labels[ $label ][ $sublabel ] = $subtext;
1605
+					}
1606
+				} else {
1607
+					$this->_labels[ $label ] = $text;
1608
+				}
1609
+			}
1610
+		}
1611
+	}
1612
+
1613
+
1614
+	/**
1615
+	 *        verifies user access for this admin page
1616
+	 *
1617
+	 * @param string $route_to_check if present then the capability for the route matching this string is checked.
1618
+	 * @param bool   $verify_only    Default is FALSE which means if user check fails then wp_die().  Otherwise just
1619
+	 *                               return false if verify fail.
1620
+	 * @return bool
1621
+	 * @throws InvalidArgumentException
1622
+	 * @throws InvalidDataTypeException
1623
+	 * @throws InvalidInterfaceException
1624
+	 */
1625
+	public function check_user_access($route_to_check = '', $verify_only = false)
1626
+	{
1627
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1628
+		$route_to_check = empty($route_to_check) ? $this->_req_action : $route_to_check;
1629
+		$capability = ! empty($route_to_check) && isset($this->_page_routes[ $route_to_check ])
1630
+					  && is_array(
1631
+						  $this->_page_routes[ $route_to_check ]
1632
+					  )
1633
+					  && ! empty($this->_page_routes[ $route_to_check ]['capability'])
1634
+			? $this->_page_routes[ $route_to_check ]['capability'] : null;
1635
+		if (empty($capability) && empty($route_to_check)) {
1636
+			$capability = is_array($this->_route) && empty($this->_route['capability']) ? 'manage_options'
1637
+				: $this->_route['capability'];
1638
+		} else {
1639
+			$capability = empty($capability) ? 'manage_options' : $capability;
1640
+		}
1641
+		$id = is_array($this->_route) && ! empty($this->_route['obj_id']) ? $this->_route['obj_id'] : 0;
1642
+		if (
1643
+			! defined('DOING_AJAX')
1644
+			&& (
1645
+				! function_exists('is_admin')
1646
+				|| ! EE_Registry::instance()->CAP->current_user_can(
1647
+					$capability,
1648
+					$this->page_slug
1649
+					. '_'
1650
+					. $route_to_check,
1651
+					$id
1652
+				)
1653
+			)
1654
+		) {
1655
+			if ($verify_only) {
1656
+				return false;
1657
+			}
1658
+			if (is_user_logged_in()) {
1659
+				wp_die(__('You do not have access to this route.', 'event_espresso'));
1660
+			} else {
1661
+				return false;
1662
+			}
1663
+		}
1664
+		return true;
1665
+	}
1666
+
1667
+
1668
+	/**
1669
+	 * admin_init_global
1670
+	 * This runs all the code that we want executed within the WP admin_init hook.
1671
+	 * This method executes for ALL EE Admin pages.
1672
+	 *
1673
+	 * @return void
1674
+	 */
1675
+	public function admin_init_global()
1676
+	{
1677
+	}
1678
+
1679
+
1680
+	/**
1681
+	 * wp_loaded_global
1682
+	 * This runs all the code that we want executed within the WP wp_loaded hook.  This method is optional for an
1683
+	 * EE_Admin page and will execute on every EE Admin Page load
1684
+	 *
1685
+	 * @return void
1686
+	 */
1687
+	public function wp_loaded()
1688
+	{
1689
+	}
1690
+
1691
+
1692
+	/**
1693
+	 * admin_notices
1694
+	 * Anything triggered by the 'admin_notices' WP hook should be put in here.  This particular method will apply on
1695
+	 * ALL EE_Admin pages.
1696
+	 *
1697
+	 * @return void
1698
+	 */
1699
+	public function admin_notices_global()
1700
+	{
1701
+		$this->_display_no_javascript_warning();
1702
+		$this->_display_espresso_notices();
1703
+	}
1704
+
1705
+
1706
+	public function network_admin_notices_global()
1707
+	{
1708
+		$this->_display_no_javascript_warning();
1709
+		$this->_display_espresso_notices();
1710
+	}
1711
+
1712
+
1713
+	/**
1714
+	 * admin_footer_scripts_global
1715
+	 * Anything triggered by the 'admin_print_footer_scripts' WP hook should be put in here. This particular method
1716
+	 * will apply on ALL EE_Admin pages.
1717
+	 *
1718
+	 * @return void
1719
+	 */
1720
+	public function admin_footer_scripts_global()
1721
+	{
1722
+		$this->_add_admin_page_ajax_loading_img();
1723
+		$this->_add_admin_page_overlay();
1724
+		// if metaboxes are present we need to add the nonce field
1725
+		if (
1726
+			isset($this->_route_config['metaboxes'])
1727
+			|| isset($this->_route_config['list_table'])
1728
+			|| (isset($this->_route_config['has_metaboxes']) && $this->_route_config['has_metaboxes'])
1729
+		) {
1730
+			wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false);
1731
+			wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false);
1732
+		}
1733
+	}
1734
+
1735
+
1736
+	/**
1737
+	 * admin_footer_global
1738
+	 * Anything triggered by the wp 'admin_footer' wp hook should be put in here.
1739
+	 * This particular method will apply on ALL EE_Admin Pages.
1740
+	 *
1741
+	 * @return void
1742
+	 * @throws InvalidArgumentException
1743
+	 * @throws InvalidDataTypeException
1744
+	 * @throws InvalidInterfaceException
1745
+	 */
1746
+	public function admin_footer_global()
1747
+	{
1748
+		// dialog container for dialog helper
1749
+		$d_cont = '<div class="ee-admin-dialog-container auto-hide hidden">' . "\n";
1750
+		$d_cont .= '<div class="ee-notices"></div>';
1751
+		$d_cont .= '<div class="ee-admin-dialog-container-inner-content"></div>';
1752
+		$d_cont .= '</div>';
1753
+		echo $d_cont;
1754
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1755
+		// help tour stuff?
1756
+		// if (isset($this->_help_tour[ $this->_req_action ])) {
1757
+		//     echo implode('<br />', $this->_help_tour[ $this->_req_action ]);
1758
+		// }
1759
+		// current set timezone for timezone js
1760
+		echo '<span id="current_timezone" class="hidden">' . EEH_DTT_Helper::get_timezone() . '</span>';
1761
+	}
1762
+
1763
+
1764
+	/**
1765
+	 * This function sees if there is a method for help popup content existing for the given route.  If there is then
1766
+	 * we'll use the retrieved array to output the content using the template. For child classes: If you want to have
1767
+	 * help popups then in your templates or your content you set "triggers" for the content using the
1768
+	 * "_set_help_trigger('help_trigger_id')" where "help_trigger_id" is what you will use later in your custom method
1769
+	 * for the help popup content on that page. Then in your Child_Admin_Page class you need to define a help popup
1770
+	 * method for the content in the format "_help_popup_content_{route_name}()"  So if you are setting help content
1771
+	 * for the
1772
+	 * 'edit_event' route you should have a method named "_help_popup_content_edit_route". In your defined
1773
+	 * "help_popup_content_..." method.  You must prepare and return an array in the following format array(
1774
+	 *    'help_trigger_id' => array(
1775
+	 *        'title' => esc_html__('localized title for popup', 'event_espresso'),
1776
+	 *        'content' => esc_html__('localized content for popup', 'event_espresso')
1777
+	 *    )
1778
+	 * );
1779
+	 * Then the EE_Admin_Parent will take care of making sure that is setup properly on the correct route.
1780
+	 *
1781
+	 * @param array $help_array
1782
+	 * @param bool  $display
1783
+	 * @return string content
1784
+	 * @throws DomainException
1785
+	 * @throws EE_Error
1786
+	 */
1787
+	protected function _set_help_popup_content($help_array = array(), $display = false)
1788
+	{
1789
+		$content = '';
1790
+		$help_array = empty($help_array) ? $this->_get_help_content() : $help_array;
1791
+		// loop through the array and setup content
1792
+		foreach ($help_array as $trigger => $help) {
1793
+			// make sure the array is setup properly
1794
+			if (! isset($help['title'], $help['content'])) {
1795
+				throw new EE_Error(
1796
+					esc_html__(
1797
+						'Does not look like the popup content array has been setup correctly.  Might want to double check that.  Read the comments for the _get_help_popup_content method found in "EE_Admin_Page" class',
1798
+						'event_espresso'
1799
+					)
1800
+				);
1801
+			}
1802
+			// we're good so let'd setup the template vars and then assign parsed template content to our content.
1803
+			$template_args = array(
1804
+				'help_popup_id'      => $trigger,
1805
+				'help_popup_title'   => $help['title'],
1806
+				'help_popup_content' => $help['content'],
1807
+			);
1808
+			$content .= EEH_Template::display_template(
1809
+				EE_ADMIN_TEMPLATE . 'admin_help_popup.template.php',
1810
+				$template_args,
1811
+				true
1812
+			);
1813
+		}
1814
+		if ($display) {
1815
+			echo $content;
1816
+			return '';
1817
+		}
1818
+		return $content;
1819
+	}
1820
+
1821
+
1822
+	/**
1823
+	 * All this does is retrieve the help content array if set by the EE_Admin_Page child
1824
+	 *
1825
+	 * @return array properly formatted array for help popup content
1826
+	 * @throws EE_Error
1827
+	 */
1828
+	private function _get_help_content()
1829
+	{
1830
+		// what is the method we're looking for?
1831
+		$method_name = '_help_popup_content_' . $this->_req_action;
1832
+		// if method doesn't exist let's get out.
1833
+		if (! method_exists($this, $method_name)) {
1834
+			return array();
1835
+		}
1836
+		// k we're good to go let's retrieve the help array
1837
+		$help_array = $this->{$method_name}();
1838
+		// make sure we've got an array!
1839
+		if (! is_array($help_array)) {
1840
+			throw new EE_Error(
1841
+				esc_html__(
1842
+					'Something went wrong with help popup content generation. Expecting an array and well, this ain\'t no array bub.',
1843
+					'event_espresso'
1844
+				)
1845
+			);
1846
+		}
1847
+		return $help_array;
1848
+	}
1849
+
1850
+
1851
+	/**
1852
+	 * EE Admin Pages can use this to set a properly formatted trigger for a help popup.
1853
+	 * By default the trigger html is printed.  Otherwise it can be returned if the $display flag is set "false"
1854
+	 * See comments made on the _set_help_content method for understanding other parts to the help popup tool.
1855
+	 *
1856
+	 * @param string  $trigger_id reference for retrieving the trigger content for the popup
1857
+	 * @param boolean $display    if false then we return the trigger string
1858
+	 * @param array   $dimensions an array of dimensions for the box (array(h,w))
1859
+	 * @return string
1860
+	 * @throws DomainException
1861
+	 * @throws EE_Error
1862
+	 */
1863
+	protected function _set_help_trigger($trigger_id, $display = true, $dimensions = array('400', '640'))
1864
+	{
1865
+		if (defined('DOING_AJAX')) {
1866
+			return '';
1867
+		}
1868
+		// let's check and see if there is any content set for this popup.  If there isn't then we'll include a default title and content so that developers know something needs to be corrected
1869
+		$help_array = $this->_get_help_content();
1870
+		$help_content = '';
1871
+		if (empty($help_array) || ! isset($help_array[ $trigger_id ])) {
1872
+			$help_array[ $trigger_id ] = array(
1873
+				'title'   => esc_html__('Missing Content', 'event_espresso'),
1874
+				'content' => esc_html__(
1875
+					'A trigger has been set that doesn\'t have any corresponding content. Make sure you have set the help content. (see the "_set_help_popup_content" method in the EE_Admin_Page for instructions.)',
1876
+					'event_espresso'
1877
+				),
1878
+			);
1879
+			$help_content = $this->_set_help_popup_content($help_array);
1880
+		}
1881
+		// let's setup the trigger
1882
+		$content = '<a class="ee-dialog" href="?height='
1883
+				   . $dimensions[0]
1884
+				   . '&width='
1885
+				   . $dimensions[1]
1886
+				   . '&inlineId='
1887
+				   . $trigger_id
1888
+				   . '" target="_blank"><span class="question ee-help-popup-question"></span></a>';
1889
+		$content .= $help_content;
1890
+		if ($display) {
1891
+			echo $content;
1892
+			return '';
1893
+		}
1894
+		return $content;
1895
+	}
1896
+
1897
+
1898
+	/**
1899
+	 * _add_global_screen_options
1900
+	 * Add any extra wp_screen_options within this method using built-in WP functions/methods for doing so.
1901
+	 * This particular method will add_screen_options on ALL EE_Admin Pages
1902
+	 *
1903
+	 * @link   http://chrismarslender.com/wp-tutorials/wordpress-screen-options-tutorial/
1904
+	 *         see also WP_Screen object documents...
1905
+	 * @link   http://codex.wordpress.org/Class_Reference/WP_Screen
1906
+	 * @abstract
1907
+	 * @return void
1908
+	 */
1909
+	private function _add_global_screen_options()
1910
+	{
1911
+	}
1912
+
1913
+
1914
+	/**
1915
+	 * _add_global_feature_pointers
1916
+	 * This method is used for implementing any "feature pointers" (using built-in WP styling js).
1917
+	 * This particular method will implement feature pointers for ALL EE_Admin pages.
1918
+	 * Note: this is just a placeholder for now.  Implementation will come down the road
1919
+	 *
1920
+	 * @see    WP_Internal_Pointers class in wp-admin/includes/template.php for example (its a final class so can't be
1921
+	 *         extended) also see:
1922
+	 * @link   http://eamann.com/tech/wordpress-portland/
1923
+	 * @abstract
1924
+	 * @return void
1925
+	 */
1926
+	private function _add_global_feature_pointers()
1927
+	{
1928
+	}
1929
+
1930
+
1931
+	/**
1932
+	 * load_global_scripts_styles
1933
+	 * The scripts and styles enqueued in here will be loaded on every EE Admin page
1934
+	 *
1935
+	 * @return void
1936
+	 * @throws EE_Error
1937
+	 */
1938
+	public function load_global_scripts_styles()
1939
+	{
1940
+		// add debugging styles
1941
+		if (WP_DEBUG) {
1942
+			add_action('admin_head', array($this, 'add_xdebug_style'));
1943
+		}
1944
+		// taking care of metaboxes
1945
+		if (
1946
+			empty($this->_cpt_route)
1947
+			&& (isset($this->_route_config['metaboxes']) || isset($this->_route_config['has_metaboxes']))
1948
+		) {
1949
+			wp_enqueue_script('dashboard');
1950
+		}
1951
+
1952
+		// LOCALIZED DATA
1953
+		// localize script for ajax lazy loading
1954
+		wp_localize_script(
1955
+			EspressoLegacyAdminAssetManager::JS_HANDLE_EE_ADMIN,
1956
+			'eeLazyLoadingContainers',
1957
+			apply_filters(
1958
+				'FHEE__EE_Admin_Page_Core__load_global_scripts_styles__loader_containers',
1959
+				['espresso_news_post_box_content']
1960
+			)
1961
+		);
1962
+		// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
1963
+		// /**
1964
+		//  * help tour stuff
1965
+		//  */
1966
+		// if (! empty($this->_help_tour)) {
1967
+		//     // register the js for kicking things off
1968
+		//     wp_enqueue_script(
1969
+		//         'ee-help-tour',
1970
+		//         EE_ADMIN_URL . 'assets/ee-help-tour.js',
1971
+		//         array('jquery-joyride'),
1972
+		//         EVENT_ESPRESSO_VERSION,
1973
+		//         true
1974
+		//     );
1975
+		//     $tours = array();
1976
+		//     // setup tours for the js tour object
1977
+		//     foreach ($this->_help_tour['tours'] as $tour) {
1978
+		//         if ($tour instanceof EE_Help_Tour) {
1979
+		//             $tours[] = array(
1980
+		//                 'id'      => $tour->get_slug(),
1981
+		//                 'options' => $tour->get_options(),
1982
+		//             );
1983
+		//         }
1984
+		//     }
1985
+		//     wp_localize_script('ee-help-tour', 'EE_HELP_TOUR', array('tours' => $tours));
1986
+		//     // admin_footer_global will take care of making sure our help_tour skeleton gets printed via the info stored in $this->_help_tour
1987
+		// }
1988
+	}
1989
+
1990
+
1991
+	/**
1992
+	 *        admin_footer_scripts_eei18n_js_strings
1993
+	 *
1994
+	 * @return        void
1995
+	 */
1996
+	public function admin_footer_scripts_eei18n_js_strings()
1997
+	{
1998
+		EE_Registry::$i18n_js_strings['ajax_url'] = WP_AJAX_URL;
1999
+		EE_Registry::$i18n_js_strings['confirm_delete'] = esc_html__(
2000
+			'Are you absolutely sure you want to delete this item?\nThis action will delete ALL DATA associated with this item!!!\nThis can NOT be undone!!!',
2001
+			'event_espresso'
2002
+		);
2003
+		EE_Registry::$i18n_js_strings['January'] = esc_html__('January', 'event_espresso');
2004
+		EE_Registry::$i18n_js_strings['February'] = esc_html__('February', 'event_espresso');
2005
+		EE_Registry::$i18n_js_strings['March'] = esc_html__('March', 'event_espresso');
2006
+		EE_Registry::$i18n_js_strings['April'] = esc_html__('April', 'event_espresso');
2007
+		EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso');
2008
+		EE_Registry::$i18n_js_strings['June'] = esc_html__('June', 'event_espresso');
2009
+		EE_Registry::$i18n_js_strings['July'] = esc_html__('July', 'event_espresso');
2010
+		EE_Registry::$i18n_js_strings['August'] = esc_html__('August', 'event_espresso');
2011
+		EE_Registry::$i18n_js_strings['September'] = esc_html__('September', 'event_espresso');
2012
+		EE_Registry::$i18n_js_strings['October'] = esc_html__('October', 'event_espresso');
2013
+		EE_Registry::$i18n_js_strings['November'] = esc_html__('November', 'event_espresso');
2014
+		EE_Registry::$i18n_js_strings['December'] = esc_html__('December', 'event_espresso');
2015
+		EE_Registry::$i18n_js_strings['Jan'] = esc_html__('Jan', 'event_espresso');
2016
+		EE_Registry::$i18n_js_strings['Feb'] = esc_html__('Feb', 'event_espresso');
2017
+		EE_Registry::$i18n_js_strings['Mar'] = esc_html__('Mar', 'event_espresso');
2018
+		EE_Registry::$i18n_js_strings['Apr'] = esc_html__('Apr', 'event_espresso');
2019
+		EE_Registry::$i18n_js_strings['May'] = esc_html__('May', 'event_espresso');
2020
+		EE_Registry::$i18n_js_strings['Jun'] = esc_html__('Jun', 'event_espresso');
2021
+		EE_Registry::$i18n_js_strings['Jul'] = esc_html__('Jul', 'event_espresso');
2022
+		EE_Registry::$i18n_js_strings['Aug'] = esc_html__('Aug', 'event_espresso');
2023
+		EE_Registry::$i18n_js_strings['Sep'] = esc_html__('Sep', 'event_espresso');
2024
+		EE_Registry::$i18n_js_strings['Oct'] = esc_html__('Oct', 'event_espresso');
2025
+		EE_Registry::$i18n_js_strings['Nov'] = esc_html__('Nov', 'event_espresso');
2026
+		EE_Registry::$i18n_js_strings['Dec'] = esc_html__('Dec', 'event_espresso');
2027
+		EE_Registry::$i18n_js_strings['Sunday'] = esc_html__('Sunday', 'event_espresso');
2028
+		EE_Registry::$i18n_js_strings['Monday'] = esc_html__('Monday', 'event_espresso');
2029
+		EE_Registry::$i18n_js_strings['Tuesday'] = esc_html__('Tuesday', 'event_espresso');
2030
+		EE_Registry::$i18n_js_strings['Wednesday'] = esc_html__('Wednesday', 'event_espresso');
2031
+		EE_Registry::$i18n_js_strings['Thursday'] = esc_html__('Thursday', 'event_espresso');
2032
+		EE_Registry::$i18n_js_strings['Friday'] = esc_html__('Friday', 'event_espresso');
2033
+		EE_Registry::$i18n_js_strings['Saturday'] = esc_html__('Saturday', 'event_espresso');
2034
+		EE_Registry::$i18n_js_strings['Sun'] = esc_html__('Sun', 'event_espresso');
2035
+		EE_Registry::$i18n_js_strings['Mon'] = esc_html__('Mon', 'event_espresso');
2036
+		EE_Registry::$i18n_js_strings['Tue'] = esc_html__('Tue', 'event_espresso');
2037
+		EE_Registry::$i18n_js_strings['Wed'] = esc_html__('Wed', 'event_espresso');
2038
+		EE_Registry::$i18n_js_strings['Thu'] = esc_html__('Thu', 'event_espresso');
2039
+		EE_Registry::$i18n_js_strings['Fri'] = esc_html__('Fri', 'event_espresso');
2040
+		EE_Registry::$i18n_js_strings['Sat'] = esc_html__('Sat', 'event_espresso');
2041
+	}
2042
+
2043
+
2044
+	/**
2045
+	 *        load enhanced xdebug styles for ppl with failing eyesight
2046
+	 *
2047
+	 * @return        void
2048
+	 */
2049
+	public function add_xdebug_style()
2050
+	{
2051
+		echo '<style>.xdebug-error { font-size:1.5em; }</style>';
2052
+	}
2053
+
2054
+
2055
+	/************************/
2056
+	/** LIST TABLE METHODS **/
2057
+	/************************/
2058
+	/**
2059
+	 * this sets up the list table if the current view requires it.
2060
+	 *
2061
+	 * @return void
2062
+	 * @throws EE_Error
2063
+	 * @throws InvalidArgumentException
2064
+	 * @throws InvalidDataTypeException
2065
+	 * @throws InvalidInterfaceException
2066
+	 */
2067
+	protected function _set_list_table()
2068
+	{
2069
+		// first is this a list_table view?
2070
+		if (! isset($this->_route_config['list_table'])) {
2071
+			return;
2072
+		} //not a list_table view so get out.
2073
+		// list table functions are per view specific (because some admin pages might have more than one list table!)
2074
+		$list_table_view = '_set_list_table_views_' . $this->_req_action;
2075
+		if (! method_exists($this, $list_table_view) || $this->{$list_table_view}() === false) {
2076
+			// user error msg
2077
+			$error_msg = esc_html__(
2078
+				'An error occurred. The requested list table views could not be found.',
2079
+				'event_espresso'
2080
+			);
2081
+			// developer error msg
2082
+			$error_msg .= '||'
2083
+						  . sprintf(
2084
+							  esc_html__(
2085
+								  'List table views for "%s" route could not be setup. Check that you have the corresponding method, "%s" set up for defining list_table_views for this route.',
2086
+								  'event_espresso'
2087
+							  ),
2088
+							  $this->_req_action,
2089
+							  $list_table_view
2090
+						  );
2091
+			throw new EE_Error($error_msg);
2092
+		}
2093
+		// let's provide the ability to filter the views per PAGE AND ROUTE, per PAGE, and globally
2094
+		$this->_views = apply_filters(
2095
+			'FHEE_list_table_views_' . $this->page_slug . '_' . $this->_req_action,
2096
+			$this->_views
2097
+		);
2098
+		$this->_views = apply_filters('FHEE_list_table_views_' . $this->page_slug, $this->_views);
2099
+		$this->_views = apply_filters('FHEE_list_table_views', $this->_views);
2100
+		$this->_set_list_table_view();
2101
+		$this->_set_list_table_object();
2102
+	}
2103
+
2104
+
2105
+	/**
2106
+	 * set current view for List Table
2107
+	 *
2108
+	 * @return void
2109
+	 */
2110
+	protected function _set_list_table_view()
2111
+	{
2112
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2113
+		// looking at active items or dumpster diving ?
2114
+		if (! isset($this->_req_data['status']) || ! array_key_exists($this->_req_data['status'], $this->_views)) {
2115
+			$this->_view = isset($this->_views['in_use']) ? 'in_use' : 'all';
2116
+		} else {
2117
+			$this->_view = sanitize_key($this->_req_data['status']);
2118
+		}
2119
+	}
2120
+
2121
+
2122
+	/**
2123
+	 * _set_list_table_object
2124
+	 * WP_List_Table objects need to be loaded fairly early so automatic stuff WP does is taken care of.
2125
+	 *
2126
+	 * @throws InvalidInterfaceException
2127
+	 * @throws InvalidArgumentException
2128
+	 * @throws InvalidDataTypeException
2129
+	 * @throws EE_Error
2130
+	 * @throws InvalidInterfaceException
2131
+	 */
2132
+	protected function _set_list_table_object()
2133
+	{
2134
+		if (isset($this->_route_config['list_table'])) {
2135
+			if (! class_exists($this->_route_config['list_table'])) {
2136
+				throw new EE_Error(
2137
+					sprintf(
2138
+						esc_html__(
2139
+							'The %s class defined for the list table does not exist.  Please check the spelling of the class ref in the $_page_config property on %s.',
2140
+							'event_espresso'
2141
+						),
2142
+						$this->_route_config['list_table'],
2143
+						get_class($this)
2144
+					)
2145
+				);
2146
+			}
2147
+			$this->_list_table_object = $this->loader->getShared(
2148
+				$this->_route_config['list_table'],
2149
+				array($this)
2150
+			);
2151
+		}
2152
+	}
2153
+
2154
+
2155
+	/**
2156
+	 * get_list_table_view_RLs - get it? View RL ?? VU-RL???  URL ??
2157
+	 *
2158
+	 * @param array $extra_query_args                     Optional. An array of extra query args to add to the generated
2159
+	 *                                                    urls.  The array should be indexed by the view it is being
2160
+	 *                                                    added to.
2161
+	 * @return array
2162
+	 */
2163
+	public function get_list_table_view_RLs($extra_query_args = array())
2164
+	{
2165
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2166
+		if (empty($this->_views)) {
2167
+			$this->_views = array();
2168
+		}
2169
+		// cycle thru views
2170
+		foreach ($this->_views as $key => $view) {
2171
+			$query_args = array();
2172
+			// check for current view
2173
+			$this->_views[ $key ]['class'] = $this->_view === $view['slug'] ? 'current' : '';
2174
+			$query_args['action'] = $this->_req_action;
2175
+			$query_args[ $this->_req_action . '_nonce' ] = wp_create_nonce($query_args['action'] . '_nonce');
2176
+			$query_args['status'] = $view['slug'];
2177
+			// merge any other arguments sent in.
2178
+			if (isset($extra_query_args[ $view['slug'] ])) {
2179
+				foreach ($extra_query_args[ $view['slug'] ] as $extra_query_arg) {
2180
+					$query_args[] = $extra_query_arg;
2181
+				}
2182
+			}
2183
+			$this->_views[ $key ]['url'] = EE_Admin_Page::add_query_args_and_nonce($query_args, $this->_admin_base_url);
2184
+		}
2185
+		return $this->_views;
2186
+	}
2187
+
2188
+
2189
+	/**
2190
+	 * _entries_per_page_dropdown
2191
+	 * generates a drop down box for selecting the number of visible rows in an admin page list table
2192
+	 *
2193
+	 * @todo   : Note: ideally this should be added to the screen options dropdown as that would be consistent with how
2194
+	 *         WP does it.
2195
+	 * @param int $max_entries total number of rows in the table
2196
+	 * @return string
2197
+	 */
2198
+	protected function _entries_per_page_dropdown($max_entries = 0)
2199
+	{
2200
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2201
+		$values = array(10, 25, 50, 100);
2202
+		$per_page = (! empty($this->_req_data['per_page'])) ? absint($this->_req_data['per_page']) : 10;
2203
+		if ($max_entries) {
2204
+			$values[] = $max_entries;
2205
+			sort($values);
2206
+		}
2207
+		$entries_per_page_dropdown = '
2208 2208
 			<div id="entries-per-page-dv" class="alignleft actions">
2209 2209
 				<label class="hide-if-no-js">
2210 2210
 					Show
2211 2211
 					<select id="entries-per-page-slct" name="entries-per-page-slct">';
2212
-        foreach ($values as $value) {
2213
-            if ($value < $max_entries) {
2214
-                $selected = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2215
-                $entries_per_page_dropdown .= '
2212
+		foreach ($values as $value) {
2213
+			if ($value < $max_entries) {
2214
+				$selected = $value === $per_page ? ' selected="' . $per_page . '"' : '';
2215
+				$entries_per_page_dropdown .= '
2216 2216
 						<option value="' . $value . '"' . $selected . '>' . $value . '&nbsp;&nbsp;</option>';
2217
-            }
2218
-        }
2219
-        $selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2220
-        $entries_per_page_dropdown .= '
2217
+			}
2218
+		}
2219
+		$selected = $max_entries === $per_page ? ' selected="' . $per_page . '"' : '';
2220
+		$entries_per_page_dropdown .= '
2221 2221
 						<option value="' . $max_entries . '"' . $selected . '>All&nbsp;&nbsp;</option>';
2222
-        $entries_per_page_dropdown .= '
2222
+		$entries_per_page_dropdown .= '
2223 2223
 					</select>
2224 2224
 					entries
2225 2225
 				</label>
2226 2226
 				<input id="entries-per-page-btn" class="button-secondary" type="submit" value="Go" >
2227 2227
 			</div>
2228 2228
 		';
2229
-        return $entries_per_page_dropdown;
2230
-    }
2231
-
2232
-
2233
-    /**
2234
-     *        _set_search_attributes
2235
-     *
2236
-     * @return        void
2237
-     */
2238
-    public function _set_search_attributes()
2239
-    {
2240
-        $this->_template_args['search']['btn_label'] = sprintf(
2241
-            esc_html__('Search %s', 'event_espresso'),
2242
-            empty($this->_search_btn_label) ? $this->page_label
2243
-                : $this->_search_btn_label
2244
-        );
2245
-        $this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
2246
-    }
2247
-
2248
-
2249
-
2250
-    /*** END LIST TABLE METHODS **/
2251
-
2252
-
2253
-    /**
2254
-     * _add_registered_metaboxes
2255
-     *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2256
-     *
2257
-     * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2258
-     * @return void
2259
-     * @throws EE_Error
2260
-     */
2261
-    private function _add_registered_meta_boxes()
2262
-    {
2263
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2264
-        // we only add meta boxes if the page_route calls for it
2265
-        if (
2266
-            is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2267
-            && is_array(
2268
-                $this->_route_config['metaboxes']
2269
-            )
2270
-        ) {
2271
-            // this simply loops through the callbacks provided
2272
-            // and checks if there is a corresponding callback registered by the child
2273
-            // if there is then we go ahead and process the metabox loader.
2274
-            foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2275
-                // first check for Closures
2276
-                if ($metabox_callback instanceof Closure) {
2277
-                    $result = $metabox_callback();
2278
-                } elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2279
-                    $result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
2280
-                } else {
2281
-                    $result = $this->{$metabox_callback}();
2282
-                }
2283
-                if ($result === false) {
2284
-                    // user error msg
2285
-                    $error_msg = esc_html__(
2286
-                        'An error occurred. The  requested metabox could not be found.',
2287
-                        'event_espresso'
2288
-                    );
2289
-                    // developer error msg
2290
-                    $error_msg .= '||'
2291
-                                  . sprintf(
2292
-                                      esc_html__(
2293
-                                          'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2294
-                                          'event_espresso'
2295
-                                      ),
2296
-                                      $metabox_callback
2297
-                                  );
2298
-                    throw new EE_Error($error_msg);
2299
-                }
2300
-            }
2301
-        }
2302
-    }
2303
-
2304
-
2305
-    /**
2306
-     * _add_screen_columns
2307
-     * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2308
-     * the dynamic column template and we'll setup the column options for the page.
2309
-     *
2310
-     * @return void
2311
-     */
2312
-    private function _add_screen_columns()
2313
-    {
2314
-        if (
2315
-            is_array($this->_route_config)
2316
-            && isset($this->_route_config['columns'])
2317
-            && is_array($this->_route_config['columns'])
2318
-            && count($this->_route_config['columns']) === 2
2319
-        ) {
2320
-            add_screen_option(
2321
-                'layout_columns',
2322
-                array(
2323
-                    'max'     => (int) $this->_route_config['columns'][0],
2324
-                    'default' => (int) $this->_route_config['columns'][1],
2325
-                )
2326
-            );
2327
-            $this->_template_args['num_columns'] = $this->_route_config['columns'][0];
2328
-            $screen_id = $this->_current_screen->id;
2329
-            $screen_columns = (int) get_user_option("screen_layout_{$screen_id}");
2330
-            $total_columns = ! empty($screen_columns)
2331
-                ? $screen_columns
2332
-                : $this->_route_config['columns'][1];
2333
-            $this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2334
-            $this->_template_args['current_page'] = $this->_wp_page_slug;
2335
-            $this->_template_args['screen'] = $this->_current_screen;
2336
-            $this->_column_template_path = EE_ADMIN_TEMPLATE
2337
-                                           . 'admin_details_metabox_column_wrapper.template.php';
2338
-            // finally if we don't have has_metaboxes set in the route config
2339
-            // let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2340
-            $this->_route_config['has_metaboxes'] = true;
2341
-        }
2342
-    }
2343
-
2344
-
2345
-
2346
-    /** GLOBALLY AVAILABLE METABOXES **/
2347
-
2348
-
2349
-    /**
2350
-     * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2351
-     * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2352
-     * these get loaded on.
2353
-     */
2354
-    private function _espresso_news_post_box()
2355
-    {
2356
-        $news_box_title = apply_filters(
2357
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2358
-            esc_html__('New @ Event Espresso', 'event_espresso')
2359
-        );
2360
-        add_meta_box(
2361
-            'espresso_news_post_box',
2362
-            $news_box_title,
2363
-            array(
2364
-                $this,
2365
-                'espresso_news_post_box',
2366
-            ),
2367
-            $this->_wp_page_slug,
2368
-            'side'
2369
-        );
2370
-    }
2371
-
2372
-
2373
-    /**
2374
-     * Code for setting up espresso ratings request metabox.
2375
-     */
2376
-    protected function _espresso_ratings_request()
2377
-    {
2378
-        if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2379
-            return;
2380
-        }
2381
-        $ratings_box_title = apply_filters(
2382
-            'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2383
-            esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2384
-        );
2385
-        add_meta_box(
2386
-            'espresso_ratings_request',
2387
-            $ratings_box_title,
2388
-            array(
2389
-                $this,
2390
-                'espresso_ratings_request',
2391
-            ),
2392
-            $this->_wp_page_slug,
2393
-            'side'
2394
-        );
2395
-    }
2396
-
2397
-
2398
-    /**
2399
-     * Code for setting up espresso ratings request metabox content.
2400
-     *
2401
-     * @throws DomainException
2402
-     */
2403
-    public function espresso_ratings_request()
2404
-    {
2405
-        EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php');
2406
-    }
2407
-
2408
-
2409
-    public static function cached_rss_display($rss_id, $url)
2410
-    {
2411
-        $loading = '<p class="widget-loading hide-if-no-js">'
2412
-                   . __('Loading&#8230;', 'event_espresso')
2413
-                   . '</p><p class="hide-if-js">'
2414
-                   . esc_html__('This widget requires JavaScript.', 'event_espresso')
2415
-                   . '</p>';
2416
-        $pre = '<div class="espresso-rss-display">' . "\n\t";
2417
-        $pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
2418
-        $post = '</div>' . "\n";
2419
-        $cache_key = 'ee_rss_' . md5($rss_id);
2420
-        $output = get_transient($cache_key);
2421
-        if ($output !== false) {
2422
-            echo $pre . $output . $post;
2423
-            return true;
2424
-        }
2425
-        if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2426
-            echo $pre . $loading . $post;
2427
-            return false;
2428
-        }
2429
-        ob_start();
2430
-        wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
2431
-        set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2432
-        return true;
2433
-    }
2434
-
2435
-
2436
-    public function espresso_news_post_box()
2437
-    {
2438
-        ?>
2229
+		return $entries_per_page_dropdown;
2230
+	}
2231
+
2232
+
2233
+	/**
2234
+	 *        _set_search_attributes
2235
+	 *
2236
+	 * @return        void
2237
+	 */
2238
+	public function _set_search_attributes()
2239
+	{
2240
+		$this->_template_args['search']['btn_label'] = sprintf(
2241
+			esc_html__('Search %s', 'event_espresso'),
2242
+			empty($this->_search_btn_label) ? $this->page_label
2243
+				: $this->_search_btn_label
2244
+		);
2245
+		$this->_template_args['search']['callback'] = 'search_' . $this->page_slug;
2246
+	}
2247
+
2248
+
2249
+
2250
+	/*** END LIST TABLE METHODS **/
2251
+
2252
+
2253
+	/**
2254
+	 * _add_registered_metaboxes
2255
+	 *  this loads any registered metaboxes via the 'metaboxes' index in the _page_config property array.
2256
+	 *
2257
+	 * @link   http://codex.wordpress.org/Function_Reference/add_meta_box
2258
+	 * @return void
2259
+	 * @throws EE_Error
2260
+	 */
2261
+	private function _add_registered_meta_boxes()
2262
+	{
2263
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2264
+		// we only add meta boxes if the page_route calls for it
2265
+		if (
2266
+			is_array($this->_route_config) && isset($this->_route_config['metaboxes'])
2267
+			&& is_array(
2268
+				$this->_route_config['metaboxes']
2269
+			)
2270
+		) {
2271
+			// this simply loops through the callbacks provided
2272
+			// and checks if there is a corresponding callback registered by the child
2273
+			// if there is then we go ahead and process the metabox loader.
2274
+			foreach ($this->_route_config['metaboxes'] as $metabox_callback) {
2275
+				// first check for Closures
2276
+				if ($metabox_callback instanceof Closure) {
2277
+					$result = $metabox_callback();
2278
+				} elseif (is_array($metabox_callback) && isset($metabox_callback[0], $metabox_callback[1])) {
2279
+					$result = call_user_func(array($metabox_callback[0], $metabox_callback[1]));
2280
+				} else {
2281
+					$result = $this->{$metabox_callback}();
2282
+				}
2283
+				if ($result === false) {
2284
+					// user error msg
2285
+					$error_msg = esc_html__(
2286
+						'An error occurred. The  requested metabox could not be found.',
2287
+						'event_espresso'
2288
+					);
2289
+					// developer error msg
2290
+					$error_msg .= '||'
2291
+								  . sprintf(
2292
+									  esc_html__(
2293
+										  'The metabox with the string "%s" could not be called. Check that the spelling for method names and actions in the "_page_config[\'metaboxes\']" array are all correct.',
2294
+										  'event_espresso'
2295
+									  ),
2296
+									  $metabox_callback
2297
+								  );
2298
+					throw new EE_Error($error_msg);
2299
+				}
2300
+			}
2301
+		}
2302
+	}
2303
+
2304
+
2305
+	/**
2306
+	 * _add_screen_columns
2307
+	 * This will check the _page_config array and if there is "columns" key index indicated, we'll set the template as
2308
+	 * the dynamic column template and we'll setup the column options for the page.
2309
+	 *
2310
+	 * @return void
2311
+	 */
2312
+	private function _add_screen_columns()
2313
+	{
2314
+		if (
2315
+			is_array($this->_route_config)
2316
+			&& isset($this->_route_config['columns'])
2317
+			&& is_array($this->_route_config['columns'])
2318
+			&& count($this->_route_config['columns']) === 2
2319
+		) {
2320
+			add_screen_option(
2321
+				'layout_columns',
2322
+				array(
2323
+					'max'     => (int) $this->_route_config['columns'][0],
2324
+					'default' => (int) $this->_route_config['columns'][1],
2325
+				)
2326
+			);
2327
+			$this->_template_args['num_columns'] = $this->_route_config['columns'][0];
2328
+			$screen_id = $this->_current_screen->id;
2329
+			$screen_columns = (int) get_user_option("screen_layout_{$screen_id}");
2330
+			$total_columns = ! empty($screen_columns)
2331
+				? $screen_columns
2332
+				: $this->_route_config['columns'][1];
2333
+			$this->_template_args['current_screen_widget_class'] = 'columns-' . $total_columns;
2334
+			$this->_template_args['current_page'] = $this->_wp_page_slug;
2335
+			$this->_template_args['screen'] = $this->_current_screen;
2336
+			$this->_column_template_path = EE_ADMIN_TEMPLATE
2337
+										   . 'admin_details_metabox_column_wrapper.template.php';
2338
+			// finally if we don't have has_metaboxes set in the route config
2339
+			// let's make sure it IS set other wise the necessary hidden fields for this won't be loaded.
2340
+			$this->_route_config['has_metaboxes'] = true;
2341
+		}
2342
+	}
2343
+
2344
+
2345
+
2346
+	/** GLOBALLY AVAILABLE METABOXES **/
2347
+
2348
+
2349
+	/**
2350
+	 * In this section we put any globally available EE metaboxes for all EE Admin pages.  They are called by simply
2351
+	 * referencing the callback in the _page_config array property.  This way you can be very specific about what pages
2352
+	 * these get loaded on.
2353
+	 */
2354
+	private function _espresso_news_post_box()
2355
+	{
2356
+		$news_box_title = apply_filters(
2357
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2358
+			esc_html__('New @ Event Espresso', 'event_espresso')
2359
+		);
2360
+		add_meta_box(
2361
+			'espresso_news_post_box',
2362
+			$news_box_title,
2363
+			array(
2364
+				$this,
2365
+				'espresso_news_post_box',
2366
+			),
2367
+			$this->_wp_page_slug,
2368
+			'side'
2369
+		);
2370
+	}
2371
+
2372
+
2373
+	/**
2374
+	 * Code for setting up espresso ratings request metabox.
2375
+	 */
2376
+	protected function _espresso_ratings_request()
2377
+	{
2378
+		if (! apply_filters('FHEE_show_ratings_request_meta_box', true)) {
2379
+			return;
2380
+		}
2381
+		$ratings_box_title = apply_filters(
2382
+			'FHEE__EE_Admin_Page___espresso_news_post_box__news_box_title',
2383
+			esc_html__('Keep Event Espresso Decaf Free', 'event_espresso')
2384
+		);
2385
+		add_meta_box(
2386
+			'espresso_ratings_request',
2387
+			$ratings_box_title,
2388
+			array(
2389
+				$this,
2390
+				'espresso_ratings_request',
2391
+			),
2392
+			$this->_wp_page_slug,
2393
+			'side'
2394
+		);
2395
+	}
2396
+
2397
+
2398
+	/**
2399
+	 * Code for setting up espresso ratings request metabox content.
2400
+	 *
2401
+	 * @throws DomainException
2402
+	 */
2403
+	public function espresso_ratings_request()
2404
+	{
2405
+		EEH_Template::display_template(EE_ADMIN_TEMPLATE . 'espresso_ratings_request_content.template.php');
2406
+	}
2407
+
2408
+
2409
+	public static function cached_rss_display($rss_id, $url)
2410
+	{
2411
+		$loading = '<p class="widget-loading hide-if-no-js">'
2412
+				   . __('Loading&#8230;', 'event_espresso')
2413
+				   . '</p><p class="hide-if-js">'
2414
+				   . esc_html__('This widget requires JavaScript.', 'event_espresso')
2415
+				   . '</p>';
2416
+		$pre = '<div class="espresso-rss-display">' . "\n\t";
2417
+		$pre .= '<span id="' . $rss_id . '_url" class="hidden">' . $url . '</span>';
2418
+		$post = '</div>' . "\n";
2419
+		$cache_key = 'ee_rss_' . md5($rss_id);
2420
+		$output = get_transient($cache_key);
2421
+		if ($output !== false) {
2422
+			echo $pre . $output . $post;
2423
+			return true;
2424
+		}
2425
+		if (! (defined('DOING_AJAX') && DOING_AJAX)) {
2426
+			echo $pre . $loading . $post;
2427
+			return false;
2428
+		}
2429
+		ob_start();
2430
+		wp_widget_rss_output($url, array('show_date' => 0, 'items' => 5));
2431
+		set_transient($cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS);
2432
+		return true;
2433
+	}
2434
+
2435
+
2436
+	public function espresso_news_post_box()
2437
+	{
2438
+		?>
2439 2439
         <div class="padding">
2440 2440
             <div id="espresso_news_post_box_content" class="infolinks">
2441 2441
                 <?php
2442
-                // Get RSS Feed(s)
2443
-                EE_Admin_Page::cached_rss_display(
2444
-                    'espresso_news_post_box_content',
2445
-                    urlencode(
2446
-                        apply_filters(
2447
-                            'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2448
-                            'http://eventespresso.com/feed/'
2449
-                        )
2450
-                    )
2451
-                );
2452
-                ?>
2442
+				// Get RSS Feed(s)
2443
+				EE_Admin_Page::cached_rss_display(
2444
+					'espresso_news_post_box_content',
2445
+					urlencode(
2446
+						apply_filters(
2447
+							'FHEE__EE_Admin_Page__espresso_news_post_box__feed_url',
2448
+							'http://eventespresso.com/feed/'
2449
+						)
2450
+					)
2451
+				);
2452
+				?>
2453 2453
             </div>
2454 2454
             <?php do_action('AHEE__EE_Admin_Page__espresso_news_post_box__after_content'); ?>
2455 2455
         </div>
2456 2456
         <?php
2457
-    }
2458
-
2459
-
2460
-    private function _espresso_links_post_box()
2461
-    {
2462
-        // Hiding until we actually have content to put in here...
2463
-        // add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2464
-    }
2465
-
2466
-
2467
-    public function espresso_links_post_box()
2468
-    {
2469
-        // Hiding until we actually have content to put in here...
2470
-        // EEH_Template::display_template(
2471
-        //     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2472
-        // );
2473
-    }
2474
-
2475
-
2476
-    protected function _espresso_sponsors_post_box()
2477
-    {
2478
-        if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2479
-            add_meta_box(
2480
-                'espresso_sponsors_post_box',
2481
-                esc_html__('Event Espresso Highlights', 'event_espresso'),
2482
-                array($this, 'espresso_sponsors_post_box'),
2483
-                $this->_wp_page_slug,
2484
-                'side'
2485
-            );
2486
-        }
2487
-    }
2488
-
2489
-
2490
-    public function espresso_sponsors_post_box()
2491
-    {
2492
-        EEH_Template::display_template(
2493
-            EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2494
-        );
2495
-    }
2496
-
2497
-
2498
-    private function _publish_post_box()
2499
-    {
2500
-        $meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2501
-        // if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2502
-        // then we'll use that for the metabox label.
2503
-        // Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2504
-        if (! empty($this->_labels['publishbox'])) {
2505
-            $box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2506
-                : $this->_labels['publishbox'];
2507
-        } else {
2508
-            $box_label = esc_html__('Publish', 'event_espresso');
2509
-        }
2510
-        $box_label = apply_filters(
2511
-            'FHEE__EE_Admin_Page___publish_post_box__box_label',
2512
-            $box_label,
2513
-            $this->_req_action,
2514
-            $this
2515
-        );
2516
-        add_meta_box(
2517
-            $meta_box_ref,
2518
-            $box_label,
2519
-            array($this, 'editor_overview'),
2520
-            $this->_current_screen->id,
2521
-            'side',
2522
-            'high'
2523
-        );
2524
-    }
2525
-
2526
-
2527
-    public function editor_overview()
2528
-    {
2529
-        // if we have extra content set let's add it in if not make sure its empty
2530
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2531
-            ? $this->_template_args['publish_box_extra_content']
2532
-            : '';
2533
-        echo EEH_Template::display_template(
2534
-            EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2535
-            $this->_template_args,
2536
-            true
2537
-        );
2538
-    }
2539
-
2540
-
2541
-    /** end of globally available metaboxes section **/
2542
-
2543
-
2544
-    /**
2545
-     * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2546
-     * protected method.
2547
-     *
2548
-     * @see   $this->_set_publish_post_box_vars for param details
2549
-     * @since 4.6.0
2550
-     * @param string $name
2551
-     * @param int    $id
2552
-     * @param bool   $delete
2553
-     * @param string $save_close_redirect_URL
2554
-     * @param bool   $both_btns
2555
-     * @throws EE_Error
2556
-     * @throws InvalidArgumentException
2557
-     * @throws InvalidDataTypeException
2558
-     * @throws InvalidInterfaceException
2559
-     */
2560
-    public function set_publish_post_box_vars(
2561
-        $name = '',
2562
-        $id = 0,
2563
-        $delete = false,
2564
-        $save_close_redirect_URL = '',
2565
-        $both_btns = true
2566
-    ) {
2567
-        $this->_set_publish_post_box_vars(
2568
-            $name,
2569
-            $id,
2570
-            $delete,
2571
-            $save_close_redirect_URL,
2572
-            $both_btns
2573
-        );
2574
-    }
2575
-
2576
-
2577
-    /**
2578
-     * Sets the _template_args arguments used by the _publish_post_box shortcut
2579
-     * Note: currently there is no validation for this.  However if you want the delete button, the
2580
-     * save, and save and close buttons to work properly, then you will want to include a
2581
-     * values for the name and id arguments.
2582
-     *
2583
-     * @todo  Add in validation for name/id arguments.
2584
-     * @param    string  $name                    key used for the action ID (i.e. event_id)
2585
-     * @param    int     $id                      id attached to the item published
2586
-     * @param    string  $delete                  page route callback for the delete action
2587
-     * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2588
-     * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just
2589
-     *                                            the Save button
2590
-     * @throws EE_Error
2591
-     * @throws InvalidArgumentException
2592
-     * @throws InvalidDataTypeException
2593
-     * @throws InvalidInterfaceException
2594
-     */
2595
-    protected function _set_publish_post_box_vars(
2596
-        $name = '',
2597
-        $id = 0,
2598
-        $delete = '',
2599
-        $save_close_redirect_URL = '',
2600
-        $both_btns = true
2601
-    ) {
2602
-        // if Save & Close, use a custom redirect URL or default to the main page?
2603
-        $save_close_redirect_URL = ! empty($save_close_redirect_URL)
2604
-            ? $save_close_redirect_URL
2605
-            : $this->_admin_base_url;
2606
-        // create the Save & Close and Save buttons
2607
-        $this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2608
-        // if we have extra content set let's add it in if not make sure its empty
2609
-        $this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2610
-            ? $this->_template_args['publish_box_extra_content']
2611
-            : '';
2612
-        if ($delete && ! empty($id)) {
2613
-            // make sure we have a default if just true is sent.
2614
-            $delete = ! empty($delete) ? $delete : 'delete';
2615
-            $delete_link_args = array($name => $id);
2616
-            $delete = $this->get_action_link_or_button(
2617
-                $delete,
2618
-                $delete,
2619
-                $delete_link_args,
2620
-                'submitdelete deletion'
2621
-            );
2622
-        }
2623
-        $this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2624
-        if (! empty($name) && ! empty($id)) {
2625
-            $hidden_field_arr[ $name ] = array(
2626
-                'type'  => 'hidden',
2627
-                'value' => $id,
2628
-            );
2629
-            $hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2630
-        } else {
2631
-            $hf = '';
2632
-        }
2633
-        // add hidden field
2634
-        $this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2635
-            ? $hf[ $name ]['field']
2636
-            : $hf;
2637
-    }
2638
-
2639
-
2640
-    /**
2641
-     * displays an error message to ppl who have javascript disabled
2642
-     *
2643
-     * @return void
2644
-     */
2645
-    private function _display_no_javascript_warning()
2646
-    {
2647
-        ?>
2457
+	}
2458
+
2459
+
2460
+	private function _espresso_links_post_box()
2461
+	{
2462
+		// Hiding until we actually have content to put in here...
2463
+		// add_meta_box('espresso_links_post_box', esc_html__('Helpful Plugin Links', 'event_espresso'), array( $this, 'espresso_links_post_box'), $this->_wp_page_slug, 'side');
2464
+	}
2465
+
2466
+
2467
+	public function espresso_links_post_box()
2468
+	{
2469
+		// Hiding until we actually have content to put in here...
2470
+		// EEH_Template::display_template(
2471
+		//     EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_links.template.php'
2472
+		// );
2473
+	}
2474
+
2475
+
2476
+	protected function _espresso_sponsors_post_box()
2477
+	{
2478
+		if (apply_filters('FHEE_show_sponsors_meta_box', true)) {
2479
+			add_meta_box(
2480
+				'espresso_sponsors_post_box',
2481
+				esc_html__('Event Espresso Highlights', 'event_espresso'),
2482
+				array($this, 'espresso_sponsors_post_box'),
2483
+				$this->_wp_page_slug,
2484
+				'side'
2485
+			);
2486
+		}
2487
+	}
2488
+
2489
+
2490
+	public function espresso_sponsors_post_box()
2491
+	{
2492
+		EEH_Template::display_template(
2493
+			EE_ADMIN_TEMPLATE . 'admin_general_metabox_contents_espresso_sponsors.template.php'
2494
+		);
2495
+	}
2496
+
2497
+
2498
+	private function _publish_post_box()
2499
+	{
2500
+		$meta_box_ref = 'espresso_' . $this->page_slug . '_editor_overview';
2501
+		// if there is a array('label' => array('publishbox' => 'some title') ) present in the _page_config array
2502
+		// then we'll use that for the metabox label.
2503
+		// Otherwise we'll just use publish (publishbox itself could be an array of labels indexed by routes)
2504
+		if (! empty($this->_labels['publishbox'])) {
2505
+			$box_label = is_array($this->_labels['publishbox']) ? $this->_labels['publishbox'][ $this->_req_action ]
2506
+				: $this->_labels['publishbox'];
2507
+		} else {
2508
+			$box_label = esc_html__('Publish', 'event_espresso');
2509
+		}
2510
+		$box_label = apply_filters(
2511
+			'FHEE__EE_Admin_Page___publish_post_box__box_label',
2512
+			$box_label,
2513
+			$this->_req_action,
2514
+			$this
2515
+		);
2516
+		add_meta_box(
2517
+			$meta_box_ref,
2518
+			$box_label,
2519
+			array($this, 'editor_overview'),
2520
+			$this->_current_screen->id,
2521
+			'side',
2522
+			'high'
2523
+		);
2524
+	}
2525
+
2526
+
2527
+	public function editor_overview()
2528
+	{
2529
+		// if we have extra content set let's add it in if not make sure its empty
2530
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2531
+			? $this->_template_args['publish_box_extra_content']
2532
+			: '';
2533
+		echo EEH_Template::display_template(
2534
+			EE_ADMIN_TEMPLATE . 'admin_details_publish_metabox.template.php',
2535
+			$this->_template_args,
2536
+			true
2537
+		);
2538
+	}
2539
+
2540
+
2541
+	/** end of globally available metaboxes section **/
2542
+
2543
+
2544
+	/**
2545
+	 * Public wrapper for the protected method.  Allows plugins/addons to externally call the
2546
+	 * protected method.
2547
+	 *
2548
+	 * @see   $this->_set_publish_post_box_vars for param details
2549
+	 * @since 4.6.0
2550
+	 * @param string $name
2551
+	 * @param int    $id
2552
+	 * @param bool   $delete
2553
+	 * @param string $save_close_redirect_URL
2554
+	 * @param bool   $both_btns
2555
+	 * @throws EE_Error
2556
+	 * @throws InvalidArgumentException
2557
+	 * @throws InvalidDataTypeException
2558
+	 * @throws InvalidInterfaceException
2559
+	 */
2560
+	public function set_publish_post_box_vars(
2561
+		$name = '',
2562
+		$id = 0,
2563
+		$delete = false,
2564
+		$save_close_redirect_URL = '',
2565
+		$both_btns = true
2566
+	) {
2567
+		$this->_set_publish_post_box_vars(
2568
+			$name,
2569
+			$id,
2570
+			$delete,
2571
+			$save_close_redirect_URL,
2572
+			$both_btns
2573
+		);
2574
+	}
2575
+
2576
+
2577
+	/**
2578
+	 * Sets the _template_args arguments used by the _publish_post_box shortcut
2579
+	 * Note: currently there is no validation for this.  However if you want the delete button, the
2580
+	 * save, and save and close buttons to work properly, then you will want to include a
2581
+	 * values for the name and id arguments.
2582
+	 *
2583
+	 * @todo  Add in validation for name/id arguments.
2584
+	 * @param    string  $name                    key used for the action ID (i.e. event_id)
2585
+	 * @param    int     $id                      id attached to the item published
2586
+	 * @param    string  $delete                  page route callback for the delete action
2587
+	 * @param    string  $save_close_redirect_URL custom URL to redirect to after Save & Close has been completed
2588
+	 * @param    boolean $both_btns               whether to display BOTH the "Save & Close" and "Save" buttons or just
2589
+	 *                                            the Save button
2590
+	 * @throws EE_Error
2591
+	 * @throws InvalidArgumentException
2592
+	 * @throws InvalidDataTypeException
2593
+	 * @throws InvalidInterfaceException
2594
+	 */
2595
+	protected function _set_publish_post_box_vars(
2596
+		$name = '',
2597
+		$id = 0,
2598
+		$delete = '',
2599
+		$save_close_redirect_URL = '',
2600
+		$both_btns = true
2601
+	) {
2602
+		// if Save & Close, use a custom redirect URL or default to the main page?
2603
+		$save_close_redirect_URL = ! empty($save_close_redirect_URL)
2604
+			? $save_close_redirect_URL
2605
+			: $this->_admin_base_url;
2606
+		// create the Save & Close and Save buttons
2607
+		$this->_set_save_buttons($both_btns, array(), array(), $save_close_redirect_URL);
2608
+		// if we have extra content set let's add it in if not make sure its empty
2609
+		$this->_template_args['publish_box_extra_content'] = isset($this->_template_args['publish_box_extra_content'])
2610
+			? $this->_template_args['publish_box_extra_content']
2611
+			: '';
2612
+		if ($delete && ! empty($id)) {
2613
+			// make sure we have a default if just true is sent.
2614
+			$delete = ! empty($delete) ? $delete : 'delete';
2615
+			$delete_link_args = array($name => $id);
2616
+			$delete = $this->get_action_link_or_button(
2617
+				$delete,
2618
+				$delete,
2619
+				$delete_link_args,
2620
+				'submitdelete deletion'
2621
+			);
2622
+		}
2623
+		$this->_template_args['publish_delete_link'] = ! empty($id) ? $delete : '';
2624
+		if (! empty($name) && ! empty($id)) {
2625
+			$hidden_field_arr[ $name ] = array(
2626
+				'type'  => 'hidden',
2627
+				'value' => $id,
2628
+			);
2629
+			$hf = $this->_generate_admin_form_fields($hidden_field_arr, 'array');
2630
+		} else {
2631
+			$hf = '';
2632
+		}
2633
+		// add hidden field
2634
+		$this->_template_args['publish_hidden_fields'] = is_array($hf) && ! empty($name)
2635
+			? $hf[ $name ]['field']
2636
+			: $hf;
2637
+	}
2638
+
2639
+
2640
+	/**
2641
+	 * displays an error message to ppl who have javascript disabled
2642
+	 *
2643
+	 * @return void
2644
+	 */
2645
+	private function _display_no_javascript_warning()
2646
+	{
2647
+		?>
2648 2648
         <noscript>
2649 2649
             <div id="no-js-message" class="error">
2650 2650
                 <p style="font-size:1.3em;">
2651 2651
                     <span style="color:red;"><?php esc_html_e('Warning!', 'event_espresso'); ?></span>
2652 2652
                     <?php esc_html_e(
2653
-                        'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2654
-                        'event_espresso'
2655
-                    ); ?>
2653
+						'Javascript is currently turned off for your browser. Javascript must be enabled in order for all of the features on this page to function properly. Please turn your javascript back on.',
2654
+						'event_espresso'
2655
+					); ?>
2656 2656
                 </p>
2657 2657
             </div>
2658 2658
         </noscript>
2659 2659
         <?php
2660
-    }
2661
-
2662
-
2663
-    /**
2664
-     * displays espresso success and/or error notices
2665
-     *
2666
-     * @return void
2667
-     */
2668
-    private function _display_espresso_notices()
2669
-    {
2670
-        $notices = $this->_get_transient(true);
2671
-        echo stripslashes($notices);
2672
-    }
2673
-
2674
-
2675
-    /**
2676
-     * spinny things pacify the masses
2677
-     *
2678
-     * @return void
2679
-     */
2680
-    protected function _add_admin_page_ajax_loading_img()
2681
-    {
2682
-        ?>
2660
+	}
2661
+
2662
+
2663
+	/**
2664
+	 * displays espresso success and/or error notices
2665
+	 *
2666
+	 * @return void
2667
+	 */
2668
+	private function _display_espresso_notices()
2669
+	{
2670
+		$notices = $this->_get_transient(true);
2671
+		echo stripslashes($notices);
2672
+	}
2673
+
2674
+
2675
+	/**
2676
+	 * spinny things pacify the masses
2677
+	 *
2678
+	 * @return void
2679
+	 */
2680
+	protected function _add_admin_page_ajax_loading_img()
2681
+	{
2682
+		?>
2683 2683
         <div id="espresso-ajax-loading" class="ajax-loading-grey">
2684 2684
             <span class="ee-spinner ee-spin"></span><span class="hidden"><?php
2685
-                esc_html_e('loading...', 'event_espresso'); ?></span>
2685
+				esc_html_e('loading...', 'event_espresso'); ?></span>
2686 2686
         </div>
2687 2687
         <?php
2688
-    }
2688
+	}
2689 2689
 
2690 2690
 
2691
-    /**
2692
-     * add admin page overlay for modal boxes
2693
-     *
2694
-     * @return void
2695
-     */
2696
-    protected function _add_admin_page_overlay()
2697
-    {
2698
-        ?>
2691
+	/**
2692
+	 * add admin page overlay for modal boxes
2693
+	 *
2694
+	 * @return void
2695
+	 */
2696
+	protected function _add_admin_page_overlay()
2697
+	{
2698
+		?>
2699 2699
         <div id="espresso-admin-page-overlay-dv" class=""></div>
2700 2700
         <?php
2701
-    }
2702
-
2703
-
2704
-    /**
2705
-     * facade for add_meta_box
2706
-     *
2707
-     * @param string  $action        where the metabox get's displayed
2708
-     * @param string  $title         Title of Metabox (output in metabox header)
2709
-     * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2710
-     *                               instead of the one created in here.
2711
-     * @param array   $callback_args an array of args supplied for the metabox
2712
-     * @param string  $column        what metabox column
2713
-     * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2714
-     * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2715
-     *                               created but just set our own callback for wp's add_meta_box.
2716
-     * @throws DomainException
2717
-     */
2718
-    public function _add_admin_page_meta_box(
2719
-        $action,
2720
-        $title,
2721
-        $callback,
2722
-        $callback_args,
2723
-        $column = 'normal',
2724
-        $priority = 'high',
2725
-        $create_func = true
2726
-    ) {
2727
-        do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2728
-        // if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2729
-        if (empty($callback_args) && $create_func) {
2730
-            $callback_args = array(
2731
-                'template_path' => $this->_template_path,
2732
-                'template_args' => $this->_template_args,
2733
-            );
2734
-        }
2735
-        // if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2736
-        $call_back_func = $create_func
2737
-            ? static function ($post, $metabox) {
2738
-                do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2739
-                echo EEH_Template::display_template(
2740
-                    $metabox['args']['template_path'],
2741
-                    $metabox['args']['template_args'],
2742
-                    true
2743
-                );
2744
-            }
2745
-            : $callback;
2746
-        add_meta_box(
2747
-            str_replace('_', '-', $action) . '-mbox',
2748
-            $title,
2749
-            $call_back_func,
2750
-            $this->_wp_page_slug,
2751
-            $column,
2752
-            $priority,
2753
-            $callback_args
2754
-        );
2755
-    }
2756
-
2757
-
2758
-    /**
2759
-     * generates HTML wrapper for and admin details page that contains metaboxes in columns
2760
-     *
2761
-     * @throws DomainException
2762
-     * @throws EE_Error
2763
-     * @throws InvalidArgumentException
2764
-     * @throws InvalidDataTypeException
2765
-     * @throws InvalidInterfaceException
2766
-     */
2767
-    public function display_admin_page_with_metabox_columns()
2768
-    {
2769
-        $this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2770
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2771
-            $this->_column_template_path,
2772
-            $this->_template_args,
2773
-            true
2774
-        );
2775
-        // the final wrapper
2776
-        $this->admin_page_wrapper();
2777
-    }
2778
-
2779
-
2780
-    /**
2781
-     * generates  HTML wrapper for an admin details page
2782
-     *
2783
-     * @return void
2784
-     * @throws DomainException
2785
-     * @throws EE_Error
2786
-     * @throws InvalidArgumentException
2787
-     * @throws InvalidDataTypeException
2788
-     * @throws InvalidInterfaceException
2789
-     */
2790
-    public function display_admin_page_with_sidebar()
2791
-    {
2792
-        $this->_display_admin_page(true);
2793
-    }
2794
-
2795
-
2796
-    /**
2797
-     * generates  HTML wrapper for an admin details page (except no sidebar)
2798
-     *
2799
-     * @return void
2800
-     * @throws DomainException
2801
-     * @throws EE_Error
2802
-     * @throws InvalidArgumentException
2803
-     * @throws InvalidDataTypeException
2804
-     * @throws InvalidInterfaceException
2805
-     */
2806
-    public function display_admin_page_with_no_sidebar()
2807
-    {
2808
-        $this->_display_admin_page();
2809
-    }
2810
-
2811
-
2812
-    /**
2813
-     * generates HTML wrapper for an EE about admin page (no sidebar)
2814
-     *
2815
-     * @return void
2816
-     * @throws DomainException
2817
-     * @throws EE_Error
2818
-     * @throws InvalidArgumentException
2819
-     * @throws InvalidDataTypeException
2820
-     * @throws InvalidInterfaceException
2821
-     */
2822
-    public function display_about_admin_page()
2823
-    {
2824
-        $this->_display_admin_page(false, true);
2825
-    }
2826
-
2827
-
2828
-    /**
2829
-     * display_admin_page
2830
-     * contains the code for actually displaying an admin page
2831
-     *
2832
-     * @param boolean $sidebar true with sidebar, false without
2833
-     * @param boolean $about   use the about admin wrapper instead of the default.
2834
-     * @return void
2835
-     * @throws DomainException
2836
-     * @throws EE_Error
2837
-     * @throws InvalidArgumentException
2838
-     * @throws InvalidDataTypeException
2839
-     * @throws InvalidInterfaceException
2840
-     */
2841
-    private function _display_admin_page($sidebar = false, $about = false)
2842
-    {
2843
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2844
-        // custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2845
-        do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2846
-        // set current wp page slug - looks like: event-espresso_page_event_categories
2847
-        // keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2848
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2849
-        $this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2850
-            ? 'poststuff'
2851
-            : 'espresso-default-admin';
2852
-        $template_path = $sidebar
2853
-            ? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2854
-            : EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2855
-        if (defined('DOING_AJAX') && DOING_AJAX) {
2856
-            $template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2857
-        }
2858
-        $template_path = ! empty($this->_column_template_path)
2859
-            ? $this->_column_template_path : $template_path;
2860
-        $this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content'])
2861
-            ? $this->_template_args['admin_page_content']
2862
-            : '';
2863
-        $this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2864
-            ? $this->_template_args['before_admin_page_content']
2865
-            : '';
2866
-        $this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content'])
2867
-            ? $this->_template_args['after_admin_page_content']
2868
-            : '';
2869
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2870
-            $template_path,
2871
-            $this->_template_args,
2872
-            true
2873
-        );
2874
-        // the final template wrapper
2875
-        $this->admin_page_wrapper($about);
2876
-    }
2877
-
2878
-
2879
-    /**
2880
-     * This is used to display caf preview pages.
2881
-     *
2882
-     * @since 4.3.2
2883
-     * @param string $utm_campaign_source what is the key used for google analytics link
2884
-     * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2885
-     *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2886
-     * @return void
2887
-     * @throws DomainException
2888
-     * @throws EE_Error
2889
-     * @throws InvalidArgumentException
2890
-     * @throws InvalidDataTypeException
2891
-     * @throws InvalidInterfaceException
2892
-     */
2893
-    public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2894
-    {
2895
-        // let's generate a default preview action button if there isn't one already present.
2896
-        $this->_labels['buttons']['buy_now'] = esc_html__(
2897
-            'Upgrade to Event Espresso 4 Right Now',
2898
-            'event_espresso'
2899
-        );
2900
-        $buy_now_url = add_query_arg(
2901
-            array(
2902
-                'ee_ver'       => 'ee4',
2903
-                'utm_source'   => 'ee4_plugin_admin',
2904
-                'utm_medium'   => 'link',
2905
-                'utm_campaign' => $utm_campaign_source,
2906
-                'utm_content'  => 'buy_now_button',
2907
-            ),
2908
-            'http://eventespresso.com/pricing/'
2909
-        );
2910
-        $this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2911
-            ? $this->get_action_link_or_button(
2912
-                '',
2913
-                'buy_now',
2914
-                array(),
2915
-                'button-primary button-large',
2916
-                $buy_now_url,
2917
-                true
2918
-            )
2919
-            : $this->_template_args['preview_action_button'];
2920
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2921
-            EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2922
-            $this->_template_args,
2923
-            true
2924
-        );
2925
-        $this->_display_admin_page($display_sidebar);
2926
-    }
2927
-
2928
-
2929
-    /**
2930
-     * display_admin_list_table_page_with_sidebar
2931
-     * generates HTML wrapper for an admin_page with list_table
2932
-     *
2933
-     * @return void
2934
-     * @throws DomainException
2935
-     * @throws EE_Error
2936
-     * @throws InvalidArgumentException
2937
-     * @throws InvalidDataTypeException
2938
-     * @throws InvalidInterfaceException
2939
-     */
2940
-    public function display_admin_list_table_page_with_sidebar()
2941
-    {
2942
-        $this->_display_admin_list_table_page(true);
2943
-    }
2944
-
2945
-
2946
-    /**
2947
-     * display_admin_list_table_page_with_no_sidebar
2948
-     * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2949
-     *
2950
-     * @return void
2951
-     * @throws DomainException
2952
-     * @throws EE_Error
2953
-     * @throws InvalidArgumentException
2954
-     * @throws InvalidDataTypeException
2955
-     * @throws InvalidInterfaceException
2956
-     */
2957
-    public function display_admin_list_table_page_with_no_sidebar()
2958
-    {
2959
-        $this->_display_admin_list_table_page();
2960
-    }
2961
-
2962
-
2963
-    /**
2964
-     * generates html wrapper for an admin_list_table page
2965
-     *
2966
-     * @param boolean $sidebar whether to display with sidebar or not.
2967
-     * @return void
2968
-     * @throws DomainException
2969
-     * @throws EE_Error
2970
-     * @throws InvalidArgumentException
2971
-     * @throws InvalidDataTypeException
2972
-     * @throws InvalidInterfaceException
2973
-     */
2974
-    private function _display_admin_list_table_page($sidebar = false)
2975
-    {
2976
-        // setup search attributes
2977
-        $this->_set_search_attributes();
2978
-        $this->_template_args['current_page'] = $this->_wp_page_slug;
2979
-        $template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2980
-        $this->_template_args['table_url'] = defined('DOING_AJAX')
2981
-            ? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2982
-            : add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2983
-        $this->_template_args['list_table'] = $this->_list_table_object;
2984
-        $this->_template_args['current_route'] = $this->_req_action;
2985
-        $this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2986
-        $ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2987
-        if (! empty($ajax_sorting_callback)) {
2988
-            $sortable_list_table_form_fields = wp_nonce_field(
2989
-                $ajax_sorting_callback . '_nonce',
2990
-                $ajax_sorting_callback . '_nonce',
2991
-                false,
2992
-                false
2993
-            );
2994
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2995
-                                                . $this->page_slug
2996
-                                                . '" />';
2997
-            $sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2998
-                                                . $ajax_sorting_callback
2999
-                                                . '" />';
3000
-        } else {
3001
-            $sortable_list_table_form_fields = '';
3002
-        }
3003
-        $this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
3004
-        $hidden_form_fields = isset($this->_template_args['list_table_hidden_fields'])
3005
-            ? $this->_template_args['list_table_hidden_fields']
3006
-            : '';
3007
-        $nonce_ref = $this->_req_action . '_nonce';
3008
-        $hidden_form_fields .= '<input type="hidden" name="'
3009
-                               . $nonce_ref
3010
-                               . '" value="'
3011
-                               . wp_create_nonce($nonce_ref)
3012
-                               . '">';
3013
-        $this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
3014
-        // display message about search results?
3015
-        $this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
3016
-            ? '<p class="ee-search-results">' . sprintf(
3017
-                esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3018
-                trim($this->_req_data['s'], '%')
3019
-            ) . '</p>'
3020
-            : '';
3021
-        // filter before_list_table template arg
3022
-        $this->_template_args['before_list_table'] = apply_filters(
3023
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3024
-            $this->_template_args['before_list_table'],
3025
-            $this->page_slug,
3026
-            $this->_req_data,
3027
-            $this->_req_action
3028
-        );
3029
-        // convert to array and filter again
3030
-        // arrays are easier to inject new items in a specific location,
3031
-        // but would not be backwards compatible, so we have to add a new filter
3032
-        $this->_template_args['before_list_table'] = implode(
3033
-            " \n",
3034
-            (array) apply_filters(
3035
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3036
-                (array) $this->_template_args['before_list_table'],
3037
-                $this->page_slug,
3038
-                $this->_req_data,
3039
-                $this->_req_action
3040
-            )
3041
-        );
3042
-        // filter after_list_table template arg
3043
-        $this->_template_args['after_list_table'] = apply_filters(
3044
-            'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3045
-            $this->_template_args['after_list_table'],
3046
-            $this->page_slug,
3047
-            $this->_req_data,
3048
-            $this->_req_action
3049
-        );
3050
-        // convert to array and filter again
3051
-        // arrays are easier to inject new items in a specific location,
3052
-        // but would not be backwards compatible, so we have to add a new filter
3053
-        $this->_template_args['after_list_table'] = implode(
3054
-            " \n",
3055
-            (array) apply_filters(
3056
-                'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3057
-                (array) $this->_template_args['after_list_table'],
3058
-                $this->page_slug,
3059
-                $this->_req_data,
3060
-                $this->_req_action
3061
-            )
3062
-        );
3063
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3064
-            $template_path,
3065
-            $this->_template_args,
3066
-            true
3067
-        );
3068
-        // the final template wrapper
3069
-        if ($sidebar) {
3070
-            $this->display_admin_page_with_sidebar();
3071
-        } else {
3072
-            $this->display_admin_page_with_no_sidebar();
3073
-        }
3074
-    }
3075
-
3076
-
3077
-    /**
3078
-     * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3079
-     * html string for the legend.
3080
-     * $items are expected in an array in the following format:
3081
-     * $legend_items = array(
3082
-     *        'item_id' => array(
3083
-     *            'icon' => 'http://url_to_icon_being_described.png',
3084
-     *            'desc' => esc_html__('localized description of item');
3085
-     *        )
3086
-     * );
3087
-     *
3088
-     * @param  array $items see above for format of array
3089
-     * @return string html string of legend
3090
-     * @throws DomainException
3091
-     */
3092
-    protected function _display_legend($items)
3093
-    {
3094
-        $this->_template_args['items'] = apply_filters(
3095
-            'FHEE__EE_Admin_Page___display_legend__items',
3096
-            (array) $items,
3097
-            $this
3098
-        );
3099
-        /** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */
3100
-        $status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice');
3101
-        if (! $status_change_notice->isDismissed()) {
3102
-            $this->_template_args['status_change_notice'] = EEH_Template::display_template(
3103
-                EE_ADMIN_TEMPLATE . 'status_change_notice.template.php',
3104
-                [ 'context' => '__admin-legend', 'page_slug' => $this->page_slug ],
3105
-                true
3106
-            );
3107
-        }
3108
-        return EEH_Template::display_template(
3109
-            EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3110
-            $this->_template_args,
3111
-            true
3112
-        );
3113
-    }
3114
-
3115
-
3116
-    /**
3117
-     * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3118
-     * The returned json object is created from an array in the following format:
3119
-     * array(
3120
-     *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3121
-     *  'success' => FALSE, //(default FALSE) - contains any special success message.
3122
-     *  'notices' => '', // - contains any EE_Error formatted notices
3123
-     *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3124
-     *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3125
-     *  We're also going to include the template args with every package (so js can pick out any specific template args
3126
-     *  that might be included in here)
3127
-     * )
3128
-     * The json object is populated by whatever is set in the $_template_args property.
3129
-     *
3130
-     * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3131
-     *                                 instead of displayed.
3132
-     * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3133
-     * @return void
3134
-     * @throws EE_Error
3135
-     * @throws InvalidArgumentException
3136
-     * @throws InvalidDataTypeException
3137
-     * @throws InvalidInterfaceException
3138
-     */
3139
-    protected function _return_json($sticky_notices = false, $notices_arguments = array())
3140
-    {
3141
-        // make sure any EE_Error notices have been handled.
3142
-        $this->_process_notices($notices_arguments, true, $sticky_notices);
3143
-        $data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
3144
-        unset($this->_template_args['data']);
3145
-        $json = array(
3146
-            'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3147
-            'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3148
-            'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3149
-            'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3150
-            'notices'   => EE_Error::get_notices(),
3151
-            'content'   => isset($this->_template_args['admin_page_content'])
3152
-                ? $this->_template_args['admin_page_content'] : '',
3153
-            'data'      => array_merge($data, array('template_args' => $this->_template_args)),
3154
-            'isEEajax'  => true
3155
-            // special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3156
-        );
3157
-        // make sure there are no php errors or headers_sent.  Then we can set correct json header.
3158
-        if (null === error_get_last() || ! headers_sent()) {
3159
-            header('Content-Type: application/json; charset=UTF-8');
3160
-        }
3161
-        echo wp_json_encode($json);
3162
-        exit();
3163
-    }
3164
-
3165
-
3166
-    /**
3167
-     * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3168
-     *
3169
-     * @return void
3170
-     * @throws EE_Error
3171
-     * @throws InvalidArgumentException
3172
-     * @throws InvalidDataTypeException
3173
-     * @throws InvalidInterfaceException
3174
-     */
3175
-    public function return_json()
3176
-    {
3177
-        if (defined('DOING_AJAX') && DOING_AJAX) {
3178
-            $this->_return_json();
3179
-        } else {
3180
-            throw new EE_Error(
3181
-                sprintf(
3182
-                    esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3183
-                    __FUNCTION__
3184
-                )
3185
-            );
3186
-        }
3187
-    }
3188
-
3189
-
3190
-    /**
3191
-     * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3192
-     * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3193
-     *
3194
-     * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3195
-     */
3196
-    public function set_hook_object(EE_Admin_Hooks $hook_obj)
3197
-    {
3198
-        $this->_hook_obj = $hook_obj;
3199
-    }
3200
-
3201
-
3202
-    /**
3203
-     *        generates  HTML wrapper with Tabbed nav for an admin page
3204
-     *
3205
-     * @param boolean $about whether to use the special about page wrapper or default.
3206
-     * @return void
3207
-     * @throws DomainException
3208
-     * @throws EE_Error
3209
-     * @throws InvalidArgumentException
3210
-     * @throws InvalidDataTypeException
3211
-     * @throws InvalidInterfaceException
3212
-     */
3213
-    public function admin_page_wrapper($about = false)
3214
-    {
3215
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3216
-        $this->_nav_tabs = $this->_get_main_nav_tabs();
3217
-        $this->_template_args['nav_tabs'] = $this->_nav_tabs;
3218
-        $this->_template_args['admin_page_title'] = $this->_admin_page_title;
3219
-        $this->_template_args['before_admin_page_content'] = apply_filters(
3220
-            "FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3221
-            isset($this->_template_args['before_admin_page_content'])
3222
-                ? $this->_template_args['before_admin_page_content']
3223
-                : ''
3224
-        );
3225
-        $this->_template_args['after_admin_page_content'] = apply_filters(
3226
-            "FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3227
-            isset($this->_template_args['after_admin_page_content'])
3228
-                ? $this->_template_args['after_admin_page_content']
3229
-                : ''
3230
-        );
3231
-        $this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
3232
-        // load settings page wrapper template
3233
-        $template_path = ! defined('DOING_AJAX')
3234
-            ? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'
3235
-            : EE_ADMIN_TEMPLATE
3236
-              . 'admin_wrapper_ajax.template.php';
3237
-        // about page?
3238
-        $template_path = $about
3239
-            ? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3240
-            : $template_path;
3241
-        if (defined('DOING_AJAX')) {
3242
-            $this->_template_args['admin_page_content'] = EEH_Template::display_template(
3243
-                $template_path,
3244
-                $this->_template_args,
3245
-                true
3246
-            );
3247
-            $this->_return_json();
3248
-        } else {
3249
-            EEH_Template::display_template($template_path, $this->_template_args);
3250
-        }
3251
-    }
3252
-
3253
-
3254
-    /**
3255
-     * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3256
-     *
3257
-     * @return string html
3258
-     * @throws EE_Error
3259
-     */
3260
-    protected function _get_main_nav_tabs()
3261
-    {
3262
-        // let's generate the html using the EEH_Tabbed_Content helper.
3263
-        // We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3264
-        // (rather than setting in the page_routes array)
3265
-        return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3266
-    }
3267
-
3268
-
3269
-    /**
3270
-     *        sort nav tabs
3271
-     *
3272
-     * @param $a
3273
-     * @param $b
3274
-     * @return int
3275
-     */
3276
-    private function _sort_nav_tabs($a, $b)
3277
-    {
3278
-        if ($a['order'] === $b['order']) {
3279
-            return 0;
3280
-        }
3281
-        return ($a['order'] < $b['order']) ? -1 : 1;
3282
-    }
3283
-
3284
-
3285
-    /**
3286
-     *    generates HTML for the forms used on admin pages
3287
-     *
3288
-     * @param    array $input_vars - array of input field details
3289
-     * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to
3290
-     *                             use)
3291
-     * @param bool     $id
3292
-     * @return string
3293
-     * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3294
-     * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3295
-     */
3296
-    protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
3297
-    {
3298
-        return $generator === 'string'
3299
-            ? EEH_Form_Fields::get_form_fields($input_vars, $id)
3300
-            : EEH_Form_Fields::get_form_fields_array($input_vars);
3301
-    }
3302
-
3303
-
3304
-    /**
3305
-     * generates the "Save" and "Save & Close" buttons for edit forms
3306
-     *
3307
-     * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3308
-     *                                   Close" button.
3309
-     * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3310
-     *                                   'Save', [1] => 'save & close')
3311
-     * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3312
-     *                                   via the "name" value in the button).  We can also use this to just dump
3313
-     *                                   default actions by submitting some other value.
3314
-     * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3315
-     *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3316
-     *                                   close (normal form handling).
3317
-     */
3318
-    protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
3319
-    {
3320
-        // make sure $text and $actions are in an array
3321
-        $text = (array) $text;
3322
-        $actions = (array) $actions;
3323
-        $referrer_url = empty($referrer)
3324
-            ? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3325
-              . $_SERVER['REQUEST_URI']
3326
-              . '" />'
3327
-            : '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3328
-              . $referrer
3329
-              . '" />';
3330
-        $button_text = ! empty($text)
3331
-            ? $text
3332
-            : array(
3333
-                esc_html__('Save', 'event_espresso'),
3334
-                esc_html__('Save and Close', 'event_espresso'),
3335
-            );
3336
-        $default_names = array('save', 'save_and_close');
3337
-        // add in a hidden index for the current page (so save and close redirects properly)
3338
-        $this->_template_args['save_buttons'] = $referrer_url;
3339
-        foreach ($button_text as $key => $button) {
3340
-            $ref = $default_names[ $key ];
3341
-            $this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '
3342
-                                                     . $ref
3343
-                                                     . '" value="'
3344
-                                                     . $button
3345
-                                                     . '" name="'
3346
-                                                     . (! empty($actions) ? $actions[ $key ] : $ref)
3347
-                                                     . '" id="'
3348
-                                                     . $this->_current_view . '_' . $ref
3349
-                                                     . '" />';
3350
-            if (! $both) {
3351
-                break;
3352
-            }
3353
-        }
3354
-    }
3355
-
3356
-
3357
-    /**
3358
-     * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3359
-     *
3360
-     * @see   $this->_set_add_edit_form_tags() for details on params
3361
-     * @since 4.6.0
3362
-     * @param string $route
3363
-     * @param array  $additional_hidden_fields
3364
-     */
3365
-    public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3366
-    {
3367
-        $this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3368
-    }
3369
-
3370
-
3371
-    /**
3372
-     * set form open and close tags on add/edit pages.
3373
-     *
3374
-     * @param string $route                    the route you want the form to direct to
3375
-     * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3376
-     * @return void
3377
-     */
3378
-    protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3379
-    {
3380
-        if (empty($route)) {
3381
-            $user_msg = esc_html__(
3382
-                'An error occurred. No action was set for this page\'s form.',
3383
-                'event_espresso'
3384
-            );
3385
-            $dev_msg = $user_msg . "\n"
3386
-                       . sprintf(
3387
-                           esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3388
-                           __FUNCTION__,
3389
-                           EE_Admin_Page::class
3390
-                       );
3391
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3392
-        }
3393
-        // open form
3394
-        $this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3395
-                                                             . $this->_admin_base_url
3396
-                                                             . '" id="'
3397
-                                                             . $route
3398
-                                                             . '_event_form" >';
3399
-        // add nonce
3400
-        $nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3401
-        $this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3402
-        // add REQUIRED form action
3403
-        $hidden_fields = array(
3404
-            'action' => array('type' => 'hidden', 'value' => $route),
3405
-        );
3406
-        // merge arrays
3407
-        $hidden_fields = is_array($additional_hidden_fields)
3408
-            ? array_merge($hidden_fields, $additional_hidden_fields)
3409
-            : $hidden_fields;
3410
-        // generate form fields
3411
-        $form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3412
-        // add fields to form
3413
-        foreach ((array) $form_fields as $field_name => $form_field) {
3414
-            $this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3415
-        }
3416
-        // close form
3417
-        $this->_template_args['after_admin_page_content'] = '</form>';
3418
-    }
3419
-
3420
-
3421
-    /**
3422
-     * Public Wrapper for _redirect_after_action() method since its
3423
-     * discovered it would be useful for external code to have access.
3424
-     *
3425
-     * @param bool   $success
3426
-     * @param string $what
3427
-     * @param string $action_desc
3428
-     * @param array  $query_args
3429
-     * @param bool   $override_overwrite
3430
-     * @throws EE_Error
3431
-     * @throws InvalidArgumentException
3432
-     * @throws InvalidDataTypeException
3433
-     * @throws InvalidInterfaceException
3434
-     * @see   EE_Admin_Page::_redirect_after_action() for params.
3435
-     * @since 4.5.0
3436
-     */
3437
-    public function redirect_after_action(
3438
-        $success = false,
3439
-        $what = 'item',
3440
-        $action_desc = 'processed',
3441
-        $query_args = array(),
3442
-        $override_overwrite = false
3443
-    ) {
3444
-        $this->_redirect_after_action(
3445
-            $success,
3446
-            $what,
3447
-            $action_desc,
3448
-            $query_args,
3449
-            $override_overwrite
3450
-        );
3451
-    }
3452
-
3453
-
3454
-    /**
3455
-     * Helper method for merging existing request data with the returned redirect url.
3456
-     *
3457
-     * This is typically used for redirects after an action so that if the original view was a filtered view those
3458
-     * filters are still applied.
3459
-     *
3460
-     * @param array $new_route_data
3461
-     * @return array
3462
-     */
3463
-    protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3464
-    {
3465
-        foreach ($this->_req_data as $ref => $value) {
3466
-            // unset nonces
3467
-            if (strpos($ref, 'nonce') !== false) {
3468
-                unset($this->_req_data[ $ref ]);
3469
-                continue;
3470
-            }
3471
-            // urlencode values.
3472
-            $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3473
-            $this->_req_data[ $ref ] = $value;
3474
-        }
3475
-        return array_merge($this->_req_data, $new_route_data);
3476
-    }
3477
-
3478
-
3479
-    /**
3480
-     *    _redirect_after_action
3481
-     *
3482
-     * @param int    $success            - whether success was for two or more records, or just one, or none
3483
-     * @param string $what               - what the action was performed on
3484
-     * @param string $action_desc        - what was done ie: updated, deleted, etc
3485
-     * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3486
-     *                                   action is completed
3487
-     * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3488
-     *                                   override this so that they show.
3489
-     * @return void
3490
-     * @throws EE_Error
3491
-     * @throws InvalidArgumentException
3492
-     * @throws InvalidDataTypeException
3493
-     * @throws InvalidInterfaceException
3494
-     */
3495
-    protected function _redirect_after_action(
3496
-        $success = 0,
3497
-        $what = 'item',
3498
-        $action_desc = 'processed',
3499
-        $query_args = array(),
3500
-        $override_overwrite = false
3501
-    ) {
3502
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3503
-        // class name for actions/filters.
3504
-        $classname = get_class($this);
3505
-        // set redirect url.
3506
-        // Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3507
-        // otherwise we go with whatever is set as the _admin_base_url
3508
-        $redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3509
-        $notices = EE_Error::get_notices(false);
3510
-        // overwrite default success messages //BUT ONLY if overwrite not overridden
3511
-        if (! $override_overwrite || ! empty($notices['errors'])) {
3512
-            EE_Error::overwrite_success();
3513
-        }
3514
-        if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3515
-            // how many records affected ? more than one record ? or just one ?
3516
-            if ($success > 1) {
3517
-                // set plural msg
3518
-                EE_Error::add_success(
3519
-                    sprintf(
3520
-                        esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3521
-                        $what,
3522
-                        $action_desc
3523
-                    ),
3524
-                    __FILE__,
3525
-                    __FUNCTION__,
3526
-                    __LINE__
3527
-                );
3528
-            } elseif ($success === 1) {
3529
-                // set singular msg
3530
-                EE_Error::add_success(
3531
-                    sprintf(
3532
-                        esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3533
-                        $what,
3534
-                        $action_desc
3535
-                    ),
3536
-                    __FILE__,
3537
-                    __FUNCTION__,
3538
-                    __LINE__
3539
-                );
3540
-            }
3541
-        }
3542
-        // check that $query_args isn't something crazy
3543
-        if (! is_array($query_args)) {
3544
-            $query_args = array();
3545
-        }
3546
-        /**
3547
-         * Allow injecting actions before the query_args are modified for possible different
3548
-         * redirections on save and close actions
3549
-         *
3550
-         * @since 4.2.0
3551
-         * @param array $query_args       The original query_args array coming into the
3552
-         *                                method.
3553
-         */
3554
-        do_action(
3555
-            "AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3556
-            $query_args
3557
-        );
3558
-        // calculate where we're going (if we have a "save and close" button pushed)
3559
-        if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) {
3560
-            // even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3561
-            $parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
3562
-            // regenerate query args array from referrer URL
3563
-            parse_str($parsed_url['query'], $query_args);
3564
-            // correct page and action will be in the query args now
3565
-            $redirect_url = admin_url('admin.php');
3566
-        }
3567
-        // merge any default query_args set in _default_route_query_args property
3568
-        if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3569
-            $args_to_merge = array();
3570
-            foreach ($this->_default_route_query_args as $query_param => $query_value) {
3571
-                // is there a wp_referer array in our _default_route_query_args property?
3572
-                if ($query_param === 'wp_referer') {
3573
-                    $query_value = (array) $query_value;
3574
-                    foreach ($query_value as $reference => $value) {
3575
-                        if (strpos($reference, 'nonce') !== false) {
3576
-                            continue;
3577
-                        }
3578
-                        // finally we will override any arguments in the referer with
3579
-                        // what might be set on the _default_route_query_args array.
3580
-                        if (isset($this->_default_route_query_args[ $reference ])) {
3581
-                            $args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3582
-                        } else {
3583
-                            $args_to_merge[ $reference ] = urlencode($value);
3584
-                        }
3585
-                    }
3586
-                    continue;
3587
-                }
3588
-                $args_to_merge[ $query_param ] = $query_value;
3589
-            }
3590
-            // now let's merge these arguments but override with what was specifically sent in to the
3591
-            // redirect.
3592
-            $query_args = array_merge($args_to_merge, $query_args);
3593
-        }
3594
-        $this->_process_notices($query_args);
3595
-        // generate redirect url
3596
-        // if redirecting to anything other than the main page, add a nonce
3597
-        if (isset($query_args['action'])) {
3598
-            // manually generate wp_nonce and merge that with the query vars
3599
-            // becuz the wp_nonce_url function wrecks havoc on some vars
3600
-            $query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3601
-        }
3602
-        // we're adding some hooks and filters in here for processing any things just before redirects
3603
-        // (example: an admin page has done an insert or update and we want to run something after that).
3604
-        do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3605
-        $redirect_url = apply_filters(
3606
-            'FHEE_redirect_' . $classname . $this->_req_action,
3607
-            EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url),
3608
-            $query_args
3609
-        );
3610
-        // check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3611
-        if (defined('DOING_AJAX')) {
3612
-            $default_data = array(
3613
-                'close'        => true,
3614
-                'redirect_url' => $redirect_url,
3615
-                'where'        => 'main',
3616
-                'what'         => 'append',
3617
-            );
3618
-            $this->_template_args['success'] = $success;
3619
-            $this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge(
3620
-                $default_data,
3621
-                $this->_template_args['data']
3622
-            ) : $default_data;
3623
-            $this->_return_json();
3624
-        }
3625
-        wp_safe_redirect($redirect_url);
3626
-        exit();
3627
-    }
3628
-
3629
-
3630
-    /**
3631
-     * process any notices before redirecting (or returning ajax request)
3632
-     * This method sets the $this->_template_args['notices'] attribute;
3633
-     *
3634
-     * @param array $query_args         any query args that need to be used for notice transient ('action')
3635
-     * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3636
-     *                                  page_routes haven't been defined yet.
3637
-     * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3638
-     *                                  still save a transient for the notice.
3639
-     * @return void
3640
-     * @throws EE_Error
3641
-     * @throws InvalidArgumentException
3642
-     * @throws InvalidDataTypeException
3643
-     * @throws InvalidInterfaceException
3644
-     */
3645
-    protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
3646
-    {
3647
-        // first let's set individual error properties if doing_ajax and the properties aren't already set.
3648
-        if (defined('DOING_AJAX') && DOING_AJAX) {
3649
-            $notices = EE_Error::get_notices(false);
3650
-            if (empty($this->_template_args['success'])) {
3651
-                $this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3652
-            }
3653
-            if (empty($this->_template_args['errors'])) {
3654
-                $this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3655
-            }
3656
-            if (empty($this->_template_args['attention'])) {
3657
-                $this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3658
-            }
3659
-        }
3660
-        $this->_template_args['notices'] = EE_Error::get_notices();
3661
-        // IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3662
-        if (! defined('DOING_AJAX') || $sticky_notices) {
3663
-            $route = isset($query_args['action']) ? $query_args['action'] : 'default';
3664
-            $this->_add_transient(
3665
-                $route,
3666
-                $this->_template_args['notices'],
3667
-                true,
3668
-                $skip_route_verify
3669
-            );
3670
-        }
3671
-    }
3672
-
3673
-
3674
-    /**
3675
-     * get_action_link_or_button
3676
-     * returns the button html for adding, editing, or deleting an item (depending on given type)
3677
-     *
3678
-     * @param string $action        use this to indicate which action the url is generated with.
3679
-     * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3680
-     *                              property.
3681
-     * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3682
-     * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3683
-     * @param string $base_url      If this is not provided
3684
-     *                              the _admin_base_url will be used as the default for the button base_url.
3685
-     *                              Otherwise this value will be used.
3686
-     * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3687
-     * @return string
3688
-     * @throws InvalidArgumentException
3689
-     * @throws InvalidInterfaceException
3690
-     * @throws InvalidDataTypeException
3691
-     * @throws EE_Error
3692
-     */
3693
-    public function get_action_link_or_button(
3694
-        $action,
3695
-        $type = 'add',
3696
-        $extra_request = array(),
3697
-        $class = 'button-primary',
3698
-        $base_url = '',
3699
-        $exclude_nonce = false
3700
-    ) {
3701
-        // first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3702
-        if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3703
-            throw new EE_Error(
3704
-                sprintf(
3705
-                    esc_html__(
3706
-                        'There is no page route for given action for the button.  This action was given: %s',
3707
-                        'event_espresso'
3708
-                    ),
3709
-                    $action
3710
-                )
3711
-            );
3712
-        }
3713
-        if (! isset($this->_labels['buttons'][ $type ])) {
3714
-            throw new EE_Error(
3715
-                sprintf(
3716
-                    __(
3717
-                        'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3718
-                        'event_espresso'
3719
-                    ),
3720
-                    $type
3721
-                )
3722
-            );
3723
-        }
3724
-        // finally check user access for this button.
3725
-        $has_access = $this->check_user_access($action, true);
3726
-        if (! $has_access) {
3727
-            return '';
3728
-        }
3729
-        $_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
3730
-        $query_args = array(
3731
-            'action' => $action,
3732
-        );
3733
-        // merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3734
-        if (! empty($extra_request)) {
3735
-            $query_args = array_merge($extra_request, $query_args);
3736
-        }
3737
-        $url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3738
-        return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3739
-    }
3740
-
3741
-
3742
-    /**
3743
-     * _per_page_screen_option
3744
-     * Utility function for adding in a per_page_option in the screen_options_dropdown.
3745
-     *
3746
-     * @return void
3747
-     * @throws InvalidArgumentException
3748
-     * @throws InvalidInterfaceException
3749
-     * @throws InvalidDataTypeException
3750
-     */
3751
-    protected function _per_page_screen_option()
3752
-    {
3753
-        $option = 'per_page';
3754
-        $args = array(
3755
-            'label'   => apply_filters(
3756
-                'FHEE__EE_Admin_Page___per_page_screen_options___label',
3757
-                $this->_admin_page_title,
3758
-                $this
3759
-            ),
3760
-            'default' => (int) apply_filters(
3761
-                'FHEE__EE_Admin_Page___per_page_screen_options__default',
3762
-                20
3763
-            ),
3764
-            'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3765
-        );
3766
-        // ONLY add the screen option if the user has access to it.
3767
-        if ($this->check_user_access($this->_current_view, true)) {
3768
-            add_screen_option($option, $args);
3769
-        }
3770
-    }
3771
-
3772
-
3773
-    /**
3774
-     * set_per_page_screen_option
3775
-     * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3776
-     * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3777
-     * admin_menu.
3778
-     *
3779
-     * @return void
3780
-     */
3781
-    private function _set_per_page_screen_options()
3782
-    {
3783
-        if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3784
-            check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3785
-            if (! $user = wp_get_current_user()) {
3786
-                return;
3787
-            }
3788
-            $option = $_POST['wp_screen_options']['option'];
3789
-            $value = $_POST['wp_screen_options']['value'];
3790
-            if ($option !== sanitize_key($option)) {
3791
-                return;
3792
-            }
3793
-            $map_option = $option;
3794
-            $option = str_replace('-', '_', $option);
3795
-            switch ($map_option) {
3796
-                case $this->_current_page . '_' . $this->_current_view . '_per_page':
3797
-                    $value = (int) $value;
3798
-                    $max_value = apply_filters(
3799
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3800
-                        999,
3801
-                        $this->_current_page,
3802
-                        $this->_current_view
3803
-                    );
3804
-                    if ($value < 1) {
3805
-                        return;
3806
-                    }
3807
-                    $value = min($value, $max_value);
3808
-                    break;
3809
-                default:
3810
-                    $value = apply_filters(
3811
-                        'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3812
-                        false,
3813
-                        $option,
3814
-                        $value
3815
-                    );
3816
-                    if (false === $value) {
3817
-                        return;
3818
-                    }
3819
-                    break;
3820
-            }
3821
-            update_user_meta($user->ID, $option, $value);
3822
-            wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3823
-            exit;
3824
-        }
3825
-    }
3826
-
3827
-
3828
-    /**
3829
-     * This just allows for setting the $_template_args property if it needs to be set outside the object
3830
-     *
3831
-     * @param array $data array that will be assigned to template args.
3832
-     */
3833
-    public function set_template_args($data)
3834
-    {
3835
-        $this->_template_args = array_merge($this->_template_args, (array) $data);
3836
-    }
3837
-
3838
-
3839
-    /**
3840
-     * This makes available the WP transient system for temporarily moving data between routes
3841
-     *
3842
-     * @param string $route             the route that should receive the transient
3843
-     * @param array  $data              the data that gets sent
3844
-     * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3845
-     *                                  normal route transient.
3846
-     * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3847
-     *                                  when we are adding a transient before page_routes have been defined.
3848
-     * @return void
3849
-     * @throws EE_Error
3850
-     */
3851
-    protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3852
-    {
3853
-        $user_id = get_current_user_id();
3854
-        if (! $skip_route_verify) {
3855
-            $this->_verify_route($route);
3856
-        }
3857
-        // now let's set the string for what kind of transient we're setting
3858
-        $transient = $notices
3859
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3860
-            : 'rte_tx_' . $route . '_' . $user_id;
3861
-        $data = $notices ? array('notices' => $data) : $data;
3862
-        // is there already a transient for this route?  If there is then let's ADD to that transient
3863
-        $existing = is_multisite() && is_network_admin()
3864
-            ? get_site_transient($transient)
3865
-            : get_transient($transient);
3866
-        if ($existing) {
3867
-            $data = array_merge((array) $data, (array) $existing);
3868
-        }
3869
-        if (is_multisite() && is_network_admin()) {
3870
-            set_site_transient($transient, $data, 8);
3871
-        } else {
3872
-            set_transient($transient, $data, 8);
3873
-        }
3874
-    }
3875
-
3876
-
3877
-    /**
3878
-     * this retrieves the temporary transient that has been set for moving data between routes.
3879
-     *
3880
-     * @param bool   $notices true we get notices transient. False we just return normal route transient
3881
-     * @param string $route
3882
-     * @return mixed data
3883
-     */
3884
-    protected function _get_transient($notices = false, $route = '')
3885
-    {
3886
-        $user_id = get_current_user_id();
3887
-        $route = ! $route ? $this->_req_action : $route;
3888
-        $transient = $notices
3889
-            ? 'ee_rte_n_tx_' . $route . '_' . $user_id
3890
-            : 'rte_tx_' . $route . '_' . $user_id;
3891
-        $data = is_multisite() && is_network_admin()
3892
-            ? get_site_transient($transient)
3893
-            : get_transient($transient);
3894
-        // delete transient after retrieval (just in case it hasn't expired);
3895
-        if (is_multisite() && is_network_admin()) {
3896
-            delete_site_transient($transient);
3897
-        } else {
3898
-            delete_transient($transient);
3899
-        }
3900
-        return $notices && isset($data['notices']) ? $data['notices'] : $data;
3901
-    }
3902
-
3903
-
3904
-    /**
3905
-     * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3906
-     * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3907
-     * default route callback on the EE_Admin page you want it run.)
3908
-     *
3909
-     * @return void
3910
-     */
3911
-    protected function _transient_garbage_collection()
3912
-    {
3913
-        global $wpdb;
3914
-        // retrieve all existing transients
3915
-        $query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3916
-        if ($results = $wpdb->get_results($query)) {
3917
-            foreach ($results as $result) {
3918
-                $transient = str_replace('_transient_', '', $result->option_name);
3919
-                get_transient($transient);
3920
-                if (is_multisite() && is_network_admin()) {
3921
-                    get_site_transient($transient);
3922
-                }
3923
-            }
3924
-        }
3925
-    }
3926
-
3927
-
3928
-    /**
3929
-     * get_view
3930
-     *
3931
-     * @return string content of _view property
3932
-     */
3933
-    public function get_view()
3934
-    {
3935
-        return $this->_view;
3936
-    }
3937
-
3938
-
3939
-    /**
3940
-     * getter for the protected $_views property
3941
-     *
3942
-     * @return array
3943
-     */
3944
-    public function get_views()
3945
-    {
3946
-        return $this->_views;
3947
-    }
3948
-
3949
-
3950
-    /**
3951
-     * get_current_page
3952
-     *
3953
-     * @return string _current_page property value
3954
-     */
3955
-    public function get_current_page()
3956
-    {
3957
-        return $this->_current_page;
3958
-    }
3959
-
3960
-
3961
-    /**
3962
-     * get_current_view
3963
-     *
3964
-     * @return string _current_view property value
3965
-     */
3966
-    public function get_current_view()
3967
-    {
3968
-        return $this->_current_view;
3969
-    }
3970
-
3971
-
3972
-    /**
3973
-     * get_current_screen
3974
-     *
3975
-     * @return object The current WP_Screen object
3976
-     */
3977
-    public function get_current_screen()
3978
-    {
3979
-        return $this->_current_screen;
3980
-    }
3981
-
3982
-
3983
-    /**
3984
-     * get_current_page_view_url
3985
-     *
3986
-     * @return string This returns the url for the current_page_view.
3987
-     */
3988
-    public function get_current_page_view_url()
3989
-    {
3990
-        return $this->_current_page_view_url;
3991
-    }
3992
-
3993
-
3994
-    /**
3995
-     * just returns the _req_data property
3996
-     *
3997
-     * @return array
3998
-     */
3999
-    public function get_request_data()
4000
-    {
4001
-        return $this->_req_data;
4002
-    }
4003
-
4004
-
4005
-    /**
4006
-     * returns the _req_data protected property
4007
-     *
4008
-     * @return string
4009
-     */
4010
-    public function get_req_action()
4011
-    {
4012
-        return $this->_req_action;
4013
-    }
4014
-
4015
-
4016
-    /**
4017
-     * @return bool  value of $_is_caf property
4018
-     */
4019
-    public function is_caf()
4020
-    {
4021
-        return $this->_is_caf;
4022
-    }
4023
-
4024
-
4025
-    /**
4026
-     * @return mixed
4027
-     */
4028
-    public function default_espresso_metaboxes()
4029
-    {
4030
-        return $this->_default_espresso_metaboxes;
4031
-    }
4032
-
4033
-
4034
-    /**
4035
-     * @return mixed
4036
-     */
4037
-    public function admin_base_url()
4038
-    {
4039
-        return $this->_admin_base_url;
4040
-    }
4041
-
4042
-
4043
-    /**
4044
-     * @return mixed
4045
-     */
4046
-    public function wp_page_slug()
4047
-    {
4048
-        return $this->_wp_page_slug;
4049
-    }
4050
-
4051
-
4052
-    /**
4053
-     * updates  espresso configuration settings
4054
-     *
4055
-     * @param string                   $tab
4056
-     * @param EE_Config_Base|EE_Config $config
4057
-     * @param string                   $file file where error occurred
4058
-     * @param string                   $func function  where error occurred
4059
-     * @param string                   $line line no where error occurred
4060
-     * @return boolean
4061
-     */
4062
-    protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4063
-    {
4064
-        // remove any options that are NOT going to be saved with the config settings.
4065
-        if (isset($config->core->ee_ueip_optin)) {
4066
-            // TODO: remove the following two lines and make sure values are migrated from 3.1
4067
-            update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4068
-            update_option('ee_ueip_has_notified', true);
4069
-        }
4070
-        // and save it (note we're also doing the network save here)
4071
-        $net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
4072
-        $config_saved = EE_Config::instance()->update_espresso_config(false, false);
4073
-        if ($config_saved && $net_saved) {
4074
-            EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4075
-            return true;
4076
-        }
4077
-        EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
4078
-        return false;
4079
-    }
4080
-
4081
-
4082
-    /**
4083
-     * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4084
-     *
4085
-     * @return array
4086
-     */
4087
-    public function get_yes_no_values()
4088
-    {
4089
-        return $this->_yes_no_values;
4090
-    }
4091
-
4092
-
4093
-    /**
4094
-     * @return string
4095
-     * @throws ReflectionException
4096
-     * @since $VID:$
4097
-     */
4098
-    protected function _get_dir()
4099
-    {
4100
-        $reflector = new ReflectionClass(get_class($this));
4101
-        return dirname($reflector->getFileName());
4102
-    }
4103
-
4104
-
4105
-    /**
4106
-     * A helper for getting a "next link".
4107
-     *
4108
-     * @param string $url   The url to link to
4109
-     * @param string $class The class to use.
4110
-     * @return string
4111
-     */
4112
-    protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4113
-    {
4114
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4115
-    }
4116
-
4117
-
4118
-    /**
4119
-     * A helper for getting a "previous link".
4120
-     *
4121
-     * @param string $url   The url to link to
4122
-     * @param string $class The class to use.
4123
-     * @return string
4124
-     */
4125
-    protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4126
-    {
4127
-        return '<a class="' . $class . '" href="' . $url . '"></a>';
4128
-    }
4129
-
4130
-
4131
-
4132
-
4133
-
4134
-
4135
-
4136
-    // below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4137
-
4138
-
4139
-    /**
4140
-     * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4141
-     * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the
4142
-     * _req_data array.
4143
-     *
4144
-     * @return bool success/fail
4145
-     * @throws EE_Error
4146
-     * @throws InvalidArgumentException
4147
-     * @throws ReflectionException
4148
-     * @throws InvalidDataTypeException
4149
-     * @throws InvalidInterfaceException
4150
-     */
4151
-    protected function _process_resend_registration()
4152
-    {
4153
-        $this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4154
-        do_action(
4155
-            'AHEE__EE_Admin_Page___process_resend_registration',
4156
-            $this->_template_args['success'],
4157
-            $this->_req_data
4158
-        );
4159
-        return $this->_template_args['success'];
4160
-    }
4161
-
4162
-
4163
-    /**
4164
-     * This automatically processes any payment message notifications when manual payment has been applied.
4165
-     *
4166
-     * @param EE_Payment $payment
4167
-     * @return bool success/fail
4168
-     */
4169
-    protected function _process_payment_notification(EE_Payment $payment)
4170
-    {
4171
-        add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4172
-        do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4173
-        $this->_template_args['success'] = apply_filters(
4174
-            'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4175
-            false,
4176
-            $payment
4177
-        );
4178
-        return $this->_template_args['success'];
4179
-    }
2701
+	}
2702
+
2703
+
2704
+	/**
2705
+	 * facade for add_meta_box
2706
+	 *
2707
+	 * @param string  $action        where the metabox get's displayed
2708
+	 * @param string  $title         Title of Metabox (output in metabox header)
2709
+	 * @param string  $callback      If not empty and $create_fun is set to false then we'll use a custom callback
2710
+	 *                               instead of the one created in here.
2711
+	 * @param array   $callback_args an array of args supplied for the metabox
2712
+	 * @param string  $column        what metabox column
2713
+	 * @param string  $priority      give this metabox a priority (using accepted priorities for wp meta boxes)
2714
+	 * @param boolean $create_func   default is true.  Basically we can say we don't WANT to have the runtime function
2715
+	 *                               created but just set our own callback for wp's add_meta_box.
2716
+	 * @throws DomainException
2717
+	 */
2718
+	public function _add_admin_page_meta_box(
2719
+		$action,
2720
+		$title,
2721
+		$callback,
2722
+		$callback_args,
2723
+		$column = 'normal',
2724
+		$priority = 'high',
2725
+		$create_func = true
2726
+	) {
2727
+		do_action('AHEE_log', __FILE__, __FUNCTION__, $callback);
2728
+		// if we have empty callback args and we want to automatically create the metabox callback then we need to make sure the callback args are generated.
2729
+		if (empty($callback_args) && $create_func) {
2730
+			$callback_args = array(
2731
+				'template_path' => $this->_template_path,
2732
+				'template_args' => $this->_template_args,
2733
+			);
2734
+		}
2735
+		// if $create_func is true (default) then we automatically create the function for displaying the actual meta box.  If false then we take the $callback reference passed through and use it instead (so callers can define their own callback function/method if they wish)
2736
+		$call_back_func = $create_func
2737
+			? static function ($post, $metabox) {
2738
+				do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2739
+				echo EEH_Template::display_template(
2740
+					$metabox['args']['template_path'],
2741
+					$metabox['args']['template_args'],
2742
+					true
2743
+				);
2744
+			}
2745
+			: $callback;
2746
+		add_meta_box(
2747
+			str_replace('_', '-', $action) . '-mbox',
2748
+			$title,
2749
+			$call_back_func,
2750
+			$this->_wp_page_slug,
2751
+			$column,
2752
+			$priority,
2753
+			$callback_args
2754
+		);
2755
+	}
2756
+
2757
+
2758
+	/**
2759
+	 * generates HTML wrapper for and admin details page that contains metaboxes in columns
2760
+	 *
2761
+	 * @throws DomainException
2762
+	 * @throws EE_Error
2763
+	 * @throws InvalidArgumentException
2764
+	 * @throws InvalidDataTypeException
2765
+	 * @throws InvalidInterfaceException
2766
+	 */
2767
+	public function display_admin_page_with_metabox_columns()
2768
+	{
2769
+		$this->_template_args['post_body_content'] = $this->_template_args['admin_page_content'];
2770
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2771
+			$this->_column_template_path,
2772
+			$this->_template_args,
2773
+			true
2774
+		);
2775
+		// the final wrapper
2776
+		$this->admin_page_wrapper();
2777
+	}
2778
+
2779
+
2780
+	/**
2781
+	 * generates  HTML wrapper for an admin details page
2782
+	 *
2783
+	 * @return void
2784
+	 * @throws DomainException
2785
+	 * @throws EE_Error
2786
+	 * @throws InvalidArgumentException
2787
+	 * @throws InvalidDataTypeException
2788
+	 * @throws InvalidInterfaceException
2789
+	 */
2790
+	public function display_admin_page_with_sidebar()
2791
+	{
2792
+		$this->_display_admin_page(true);
2793
+	}
2794
+
2795
+
2796
+	/**
2797
+	 * generates  HTML wrapper for an admin details page (except no sidebar)
2798
+	 *
2799
+	 * @return void
2800
+	 * @throws DomainException
2801
+	 * @throws EE_Error
2802
+	 * @throws InvalidArgumentException
2803
+	 * @throws InvalidDataTypeException
2804
+	 * @throws InvalidInterfaceException
2805
+	 */
2806
+	public function display_admin_page_with_no_sidebar()
2807
+	{
2808
+		$this->_display_admin_page();
2809
+	}
2810
+
2811
+
2812
+	/**
2813
+	 * generates HTML wrapper for an EE about admin page (no sidebar)
2814
+	 *
2815
+	 * @return void
2816
+	 * @throws DomainException
2817
+	 * @throws EE_Error
2818
+	 * @throws InvalidArgumentException
2819
+	 * @throws InvalidDataTypeException
2820
+	 * @throws InvalidInterfaceException
2821
+	 */
2822
+	public function display_about_admin_page()
2823
+	{
2824
+		$this->_display_admin_page(false, true);
2825
+	}
2826
+
2827
+
2828
+	/**
2829
+	 * display_admin_page
2830
+	 * contains the code for actually displaying an admin page
2831
+	 *
2832
+	 * @param boolean $sidebar true with sidebar, false without
2833
+	 * @param boolean $about   use the about admin wrapper instead of the default.
2834
+	 * @return void
2835
+	 * @throws DomainException
2836
+	 * @throws EE_Error
2837
+	 * @throws InvalidArgumentException
2838
+	 * @throws InvalidDataTypeException
2839
+	 * @throws InvalidInterfaceException
2840
+	 */
2841
+	private function _display_admin_page($sidebar = false, $about = false)
2842
+	{
2843
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2844
+		// custom remove metaboxes hook to add or remove any metaboxes to/from Admin pages.
2845
+		do_action('AHEE__EE_Admin_Page___display_admin_page__modify_metaboxes');
2846
+		// set current wp page slug - looks like: event-espresso_page_event_categories
2847
+		// keep in mind "event-espresso" COULD be something else if the top level menu label has been translated.
2848
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2849
+		$this->_template_args['admin_page_wrapper_div_id'] = $this->_cpt_route
2850
+			? 'poststuff'
2851
+			: 'espresso-default-admin';
2852
+		$template_path = $sidebar
2853
+			? EE_ADMIN_TEMPLATE . 'admin_details_wrapper.template.php'
2854
+			: EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar.template.php';
2855
+		if (defined('DOING_AJAX') && DOING_AJAX) {
2856
+			$template_path = EE_ADMIN_TEMPLATE . 'admin_details_wrapper_no_sidebar_ajax.template.php';
2857
+		}
2858
+		$template_path = ! empty($this->_column_template_path)
2859
+			? $this->_column_template_path : $template_path;
2860
+		$this->_template_args['post_body_content'] = isset($this->_template_args['admin_page_content'])
2861
+			? $this->_template_args['admin_page_content']
2862
+			: '';
2863
+		$this->_template_args['before_admin_page_content'] = isset($this->_template_args['before_admin_page_content'])
2864
+			? $this->_template_args['before_admin_page_content']
2865
+			: '';
2866
+		$this->_template_args['after_admin_page_content'] = isset($this->_template_args['after_admin_page_content'])
2867
+			? $this->_template_args['after_admin_page_content']
2868
+			: '';
2869
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2870
+			$template_path,
2871
+			$this->_template_args,
2872
+			true
2873
+		);
2874
+		// the final template wrapper
2875
+		$this->admin_page_wrapper($about);
2876
+	}
2877
+
2878
+
2879
+	/**
2880
+	 * This is used to display caf preview pages.
2881
+	 *
2882
+	 * @since 4.3.2
2883
+	 * @param string $utm_campaign_source what is the key used for google analytics link
2884
+	 * @param bool   $display_sidebar     whether to use the sidebar template or the full template for the page.  TRUE
2885
+	 *                                    = SHOW sidebar, FALSE = no sidebar. Default no sidebar.
2886
+	 * @return void
2887
+	 * @throws DomainException
2888
+	 * @throws EE_Error
2889
+	 * @throws InvalidArgumentException
2890
+	 * @throws InvalidDataTypeException
2891
+	 * @throws InvalidInterfaceException
2892
+	 */
2893
+	public function display_admin_caf_preview_page($utm_campaign_source = '', $display_sidebar = true)
2894
+	{
2895
+		// let's generate a default preview action button if there isn't one already present.
2896
+		$this->_labels['buttons']['buy_now'] = esc_html__(
2897
+			'Upgrade to Event Espresso 4 Right Now',
2898
+			'event_espresso'
2899
+		);
2900
+		$buy_now_url = add_query_arg(
2901
+			array(
2902
+				'ee_ver'       => 'ee4',
2903
+				'utm_source'   => 'ee4_plugin_admin',
2904
+				'utm_medium'   => 'link',
2905
+				'utm_campaign' => $utm_campaign_source,
2906
+				'utm_content'  => 'buy_now_button',
2907
+			),
2908
+			'http://eventespresso.com/pricing/'
2909
+		);
2910
+		$this->_template_args['preview_action_button'] = ! isset($this->_template_args['preview_action_button'])
2911
+			? $this->get_action_link_or_button(
2912
+				'',
2913
+				'buy_now',
2914
+				array(),
2915
+				'button-primary button-large',
2916
+				$buy_now_url,
2917
+				true
2918
+			)
2919
+			: $this->_template_args['preview_action_button'];
2920
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2921
+			EE_ADMIN_TEMPLATE . 'admin_caf_full_page_preview.template.php',
2922
+			$this->_template_args,
2923
+			true
2924
+		);
2925
+		$this->_display_admin_page($display_sidebar);
2926
+	}
2927
+
2928
+
2929
+	/**
2930
+	 * display_admin_list_table_page_with_sidebar
2931
+	 * generates HTML wrapper for an admin_page with list_table
2932
+	 *
2933
+	 * @return void
2934
+	 * @throws DomainException
2935
+	 * @throws EE_Error
2936
+	 * @throws InvalidArgumentException
2937
+	 * @throws InvalidDataTypeException
2938
+	 * @throws InvalidInterfaceException
2939
+	 */
2940
+	public function display_admin_list_table_page_with_sidebar()
2941
+	{
2942
+		$this->_display_admin_list_table_page(true);
2943
+	}
2944
+
2945
+
2946
+	/**
2947
+	 * display_admin_list_table_page_with_no_sidebar
2948
+	 * generates HTML wrapper for an admin_page with list_table (but with no sidebar)
2949
+	 *
2950
+	 * @return void
2951
+	 * @throws DomainException
2952
+	 * @throws EE_Error
2953
+	 * @throws InvalidArgumentException
2954
+	 * @throws InvalidDataTypeException
2955
+	 * @throws InvalidInterfaceException
2956
+	 */
2957
+	public function display_admin_list_table_page_with_no_sidebar()
2958
+	{
2959
+		$this->_display_admin_list_table_page();
2960
+	}
2961
+
2962
+
2963
+	/**
2964
+	 * generates html wrapper for an admin_list_table page
2965
+	 *
2966
+	 * @param boolean $sidebar whether to display with sidebar or not.
2967
+	 * @return void
2968
+	 * @throws DomainException
2969
+	 * @throws EE_Error
2970
+	 * @throws InvalidArgumentException
2971
+	 * @throws InvalidDataTypeException
2972
+	 * @throws InvalidInterfaceException
2973
+	 */
2974
+	private function _display_admin_list_table_page($sidebar = false)
2975
+	{
2976
+		// setup search attributes
2977
+		$this->_set_search_attributes();
2978
+		$this->_template_args['current_page'] = $this->_wp_page_slug;
2979
+		$template_path = EE_ADMIN_TEMPLATE . 'admin_list_wrapper.template.php';
2980
+		$this->_template_args['table_url'] = defined('DOING_AJAX')
2981
+			? add_query_arg(array('noheader' => 'true', 'route' => $this->_req_action), $this->_admin_base_url)
2982
+			: add_query_arg(array('route' => $this->_req_action), $this->_admin_base_url);
2983
+		$this->_template_args['list_table'] = $this->_list_table_object;
2984
+		$this->_template_args['current_route'] = $this->_req_action;
2985
+		$this->_template_args['list_table_class'] = get_class($this->_list_table_object);
2986
+		$ajax_sorting_callback = $this->_list_table_object->get_ajax_sorting_callback();
2987
+		if (! empty($ajax_sorting_callback)) {
2988
+			$sortable_list_table_form_fields = wp_nonce_field(
2989
+				$ajax_sorting_callback . '_nonce',
2990
+				$ajax_sorting_callback . '_nonce',
2991
+				false,
2992
+				false
2993
+			);
2994
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_page" name="ajax_table_sort_page" value="'
2995
+												. $this->page_slug
2996
+												. '" />';
2997
+			$sortable_list_table_form_fields .= '<input type="hidden" id="ajax_table_sort_action" name="ajax_table_sort_action" value="'
2998
+												. $ajax_sorting_callback
2999
+												. '" />';
3000
+		} else {
3001
+			$sortable_list_table_form_fields = '';
3002
+		}
3003
+		$this->_template_args['sortable_list_table_form_fields'] = $sortable_list_table_form_fields;
3004
+		$hidden_form_fields = isset($this->_template_args['list_table_hidden_fields'])
3005
+			? $this->_template_args['list_table_hidden_fields']
3006
+			: '';
3007
+		$nonce_ref = $this->_req_action . '_nonce';
3008
+		$hidden_form_fields .= '<input type="hidden" name="'
3009
+							   . $nonce_ref
3010
+							   . '" value="'
3011
+							   . wp_create_nonce($nonce_ref)
3012
+							   . '">';
3013
+		$this->_template_args['list_table_hidden_fields'] = $hidden_form_fields;
3014
+		// display message about search results?
3015
+		$this->_template_args['before_list_table'] .= ! empty($this->_req_data['s'])
3016
+			? '<p class="ee-search-results">' . sprintf(
3017
+				esc_html__('Displaying search results for the search string: %1$s', 'event_espresso'),
3018
+				trim($this->_req_data['s'], '%')
3019
+			) . '</p>'
3020
+			: '';
3021
+		// filter before_list_table template arg
3022
+		$this->_template_args['before_list_table'] = apply_filters(
3023
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg',
3024
+			$this->_template_args['before_list_table'],
3025
+			$this->page_slug,
3026
+			$this->_req_data,
3027
+			$this->_req_action
3028
+		);
3029
+		// convert to array and filter again
3030
+		// arrays are easier to inject new items in a specific location,
3031
+		// but would not be backwards compatible, so we have to add a new filter
3032
+		$this->_template_args['before_list_table'] = implode(
3033
+			" \n",
3034
+			(array) apply_filters(
3035
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_args_array',
3036
+				(array) $this->_template_args['before_list_table'],
3037
+				$this->page_slug,
3038
+				$this->_req_data,
3039
+				$this->_req_action
3040
+			)
3041
+		);
3042
+		// filter after_list_table template arg
3043
+		$this->_template_args['after_list_table'] = apply_filters(
3044
+			'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_arg',
3045
+			$this->_template_args['after_list_table'],
3046
+			$this->page_slug,
3047
+			$this->_req_data,
3048
+			$this->_req_action
3049
+		);
3050
+		// convert to array and filter again
3051
+		// arrays are easier to inject new items in a specific location,
3052
+		// but would not be backwards compatible, so we have to add a new filter
3053
+		$this->_template_args['after_list_table'] = implode(
3054
+			" \n",
3055
+			(array) apply_filters(
3056
+				'FHEE__EE_Admin_Page___display_admin_list_table_page__after_list_table__template_args_array',
3057
+				(array) $this->_template_args['after_list_table'],
3058
+				$this->page_slug,
3059
+				$this->_req_data,
3060
+				$this->_req_action
3061
+			)
3062
+		);
3063
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3064
+			$template_path,
3065
+			$this->_template_args,
3066
+			true
3067
+		);
3068
+		// the final template wrapper
3069
+		if ($sidebar) {
3070
+			$this->display_admin_page_with_sidebar();
3071
+		} else {
3072
+			$this->display_admin_page_with_no_sidebar();
3073
+		}
3074
+	}
3075
+
3076
+
3077
+	/**
3078
+	 * This just prepares a legend using the given items and the admin_details_legend.template.php file and returns the
3079
+	 * html string for the legend.
3080
+	 * $items are expected in an array in the following format:
3081
+	 * $legend_items = array(
3082
+	 *        'item_id' => array(
3083
+	 *            'icon' => 'http://url_to_icon_being_described.png',
3084
+	 *            'desc' => esc_html__('localized description of item');
3085
+	 *        )
3086
+	 * );
3087
+	 *
3088
+	 * @param  array $items see above for format of array
3089
+	 * @return string html string of legend
3090
+	 * @throws DomainException
3091
+	 */
3092
+	protected function _display_legend($items)
3093
+	{
3094
+		$this->_template_args['items'] = apply_filters(
3095
+			'FHEE__EE_Admin_Page___display_legend__items',
3096
+			(array) $items,
3097
+			$this
3098
+		);
3099
+		/** @var EventEspresso\core\admin\StatusChangeNotice $status_change_notice */
3100
+		$status_change_notice = $this->loader->getShared('EventEspresso\core\admin\StatusChangeNotice');
3101
+		if (! $status_change_notice->isDismissed()) {
3102
+			$this->_template_args['status_change_notice'] = EEH_Template::display_template(
3103
+				EE_ADMIN_TEMPLATE . 'status_change_notice.template.php',
3104
+				[ 'context' => '__admin-legend', 'page_slug' => $this->page_slug ],
3105
+				true
3106
+			);
3107
+		}
3108
+		return EEH_Template::display_template(
3109
+			EE_ADMIN_TEMPLATE . 'admin_details_legend.template.php',
3110
+			$this->_template_args,
3111
+			true
3112
+		);
3113
+	}
3114
+
3115
+
3116
+	/**
3117
+	 * This is used whenever we're DOING_AJAX to return a formatted json array that our calling javascript can expect
3118
+	 * The returned json object is created from an array in the following format:
3119
+	 * array(
3120
+	 *  'error' => FALSE, //(default FALSE), contains any errors and/or exceptions (exceptions return json early),
3121
+	 *  'success' => FALSE, //(default FALSE) - contains any special success message.
3122
+	 *  'notices' => '', // - contains any EE_Error formatted notices
3123
+	 *  'content' => 'string can be html', //this is a string of formatted content (can be html)
3124
+	 *  'data' => array() //this can be any key/value pairs that a method returns for later json parsing by the js.
3125
+	 *  We're also going to include the template args with every package (so js can pick out any specific template args
3126
+	 *  that might be included in here)
3127
+	 * )
3128
+	 * The json object is populated by whatever is set in the $_template_args property.
3129
+	 *
3130
+	 * @param bool  $sticky_notices    Used to indicate whether you want to ensure notices are added to a transient
3131
+	 *                                 instead of displayed.
3132
+	 * @param array $notices_arguments Use this to pass any additional args on to the _process_notices.
3133
+	 * @return void
3134
+	 * @throws EE_Error
3135
+	 * @throws InvalidArgumentException
3136
+	 * @throws InvalidDataTypeException
3137
+	 * @throws InvalidInterfaceException
3138
+	 */
3139
+	protected function _return_json($sticky_notices = false, $notices_arguments = array())
3140
+	{
3141
+		// make sure any EE_Error notices have been handled.
3142
+		$this->_process_notices($notices_arguments, true, $sticky_notices);
3143
+		$data = isset($this->_template_args['data']) ? $this->_template_args['data'] : array();
3144
+		unset($this->_template_args['data']);
3145
+		$json = array(
3146
+			'error'     => isset($this->_template_args['error']) ? $this->_template_args['error'] : false,
3147
+			'success'   => isset($this->_template_args['success']) ? $this->_template_args['success'] : false,
3148
+			'errors'    => isset($this->_template_args['errors']) ? $this->_template_args['errors'] : false,
3149
+			'attention' => isset($this->_template_args['attention']) ? $this->_template_args['attention'] : false,
3150
+			'notices'   => EE_Error::get_notices(),
3151
+			'content'   => isset($this->_template_args['admin_page_content'])
3152
+				? $this->_template_args['admin_page_content'] : '',
3153
+			'data'      => array_merge($data, array('template_args' => $this->_template_args)),
3154
+			'isEEajax'  => true
3155
+			// special flag so any ajax.Success methods in js can identify this return package as a EEajax package.
3156
+		);
3157
+		// make sure there are no php errors or headers_sent.  Then we can set correct json header.
3158
+		if (null === error_get_last() || ! headers_sent()) {
3159
+			header('Content-Type: application/json; charset=UTF-8');
3160
+		}
3161
+		echo wp_json_encode($json);
3162
+		exit();
3163
+	}
3164
+
3165
+
3166
+	/**
3167
+	 * Simply a wrapper for the protected method so we can call this outside the class (ONLY when doing ajax)
3168
+	 *
3169
+	 * @return void
3170
+	 * @throws EE_Error
3171
+	 * @throws InvalidArgumentException
3172
+	 * @throws InvalidDataTypeException
3173
+	 * @throws InvalidInterfaceException
3174
+	 */
3175
+	public function return_json()
3176
+	{
3177
+		if (defined('DOING_AJAX') && DOING_AJAX) {
3178
+			$this->_return_json();
3179
+		} else {
3180
+			throw new EE_Error(
3181
+				sprintf(
3182
+					esc_html__('The public %s method can only be called when DOING_AJAX = TRUE', 'event_espresso'),
3183
+					__FUNCTION__
3184
+				)
3185
+			);
3186
+		}
3187
+	}
3188
+
3189
+
3190
+	/**
3191
+	 * This provides a way for child hook classes to send along themselves by reference so methods/properties within
3192
+	 * them can be accessed by EE_Admin_child pages. This is assigned to the $_hook_obj property.
3193
+	 *
3194
+	 * @param EE_Admin_Hooks $hook_obj This will be the object for the EE_Admin_Hooks child
3195
+	 */
3196
+	public function set_hook_object(EE_Admin_Hooks $hook_obj)
3197
+	{
3198
+		$this->_hook_obj = $hook_obj;
3199
+	}
3200
+
3201
+
3202
+	/**
3203
+	 *        generates  HTML wrapper with Tabbed nav for an admin page
3204
+	 *
3205
+	 * @param boolean $about whether to use the special about page wrapper or default.
3206
+	 * @return void
3207
+	 * @throws DomainException
3208
+	 * @throws EE_Error
3209
+	 * @throws InvalidArgumentException
3210
+	 * @throws InvalidDataTypeException
3211
+	 * @throws InvalidInterfaceException
3212
+	 */
3213
+	public function admin_page_wrapper($about = false)
3214
+	{
3215
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3216
+		$this->_nav_tabs = $this->_get_main_nav_tabs();
3217
+		$this->_template_args['nav_tabs'] = $this->_nav_tabs;
3218
+		$this->_template_args['admin_page_title'] = $this->_admin_page_title;
3219
+		$this->_template_args['before_admin_page_content'] = apply_filters(
3220
+			"FHEE_before_admin_page_content{$this->_current_page}{$this->_current_view}",
3221
+			isset($this->_template_args['before_admin_page_content'])
3222
+				? $this->_template_args['before_admin_page_content']
3223
+				: ''
3224
+		);
3225
+		$this->_template_args['after_admin_page_content'] = apply_filters(
3226
+			"FHEE_after_admin_page_content{$this->_current_page}{$this->_current_view}",
3227
+			isset($this->_template_args['after_admin_page_content'])
3228
+				? $this->_template_args['after_admin_page_content']
3229
+				: ''
3230
+		);
3231
+		$this->_template_args['after_admin_page_content'] .= $this->_set_help_popup_content();
3232
+		// load settings page wrapper template
3233
+		$template_path = ! defined('DOING_AJAX')
3234
+			? EE_ADMIN_TEMPLATE . 'admin_wrapper.template.php'
3235
+			: EE_ADMIN_TEMPLATE
3236
+			  . 'admin_wrapper_ajax.template.php';
3237
+		// about page?
3238
+		$template_path = $about
3239
+			? EE_ADMIN_TEMPLATE . 'about_admin_wrapper.template.php'
3240
+			: $template_path;
3241
+		if (defined('DOING_AJAX')) {
3242
+			$this->_template_args['admin_page_content'] = EEH_Template::display_template(
3243
+				$template_path,
3244
+				$this->_template_args,
3245
+				true
3246
+			);
3247
+			$this->_return_json();
3248
+		} else {
3249
+			EEH_Template::display_template($template_path, $this->_template_args);
3250
+		}
3251
+	}
3252
+
3253
+
3254
+	/**
3255
+	 * This returns the admin_nav tabs html using the configuration in the _nav_tabs property
3256
+	 *
3257
+	 * @return string html
3258
+	 * @throws EE_Error
3259
+	 */
3260
+	protected function _get_main_nav_tabs()
3261
+	{
3262
+		// let's generate the html using the EEH_Tabbed_Content helper.
3263
+		// We do this here so that it's possible for child classes to add in nav tabs dynamically at the last minute
3264
+		// (rather than setting in the page_routes array)
3265
+		return EEH_Tabbed_Content::display_admin_nav_tabs($this->_nav_tabs);
3266
+	}
3267
+
3268
+
3269
+	/**
3270
+	 *        sort nav tabs
3271
+	 *
3272
+	 * @param $a
3273
+	 * @param $b
3274
+	 * @return int
3275
+	 */
3276
+	private function _sort_nav_tabs($a, $b)
3277
+	{
3278
+		if ($a['order'] === $b['order']) {
3279
+			return 0;
3280
+		}
3281
+		return ($a['order'] < $b['order']) ? -1 : 1;
3282
+	}
3283
+
3284
+
3285
+	/**
3286
+	 *    generates HTML for the forms used on admin pages
3287
+	 *
3288
+	 * @param    array $input_vars - array of input field details
3289
+	 * @param string   $generator  (options are 'string' or 'array', basically use this to indicate which generator to
3290
+	 *                             use)
3291
+	 * @param bool     $id
3292
+	 * @return string
3293
+	 * @uses   EEH_Form_Fields::get_form_fields (/helper/EEH_Form_Fields.helper.php)
3294
+	 * @uses   EEH_Form_Fields::get_form_fields_array (/helper/EEH_Form_Fields.helper.php)
3295
+	 */
3296
+	protected function _generate_admin_form_fields($input_vars = array(), $generator = 'string', $id = false)
3297
+	{
3298
+		return $generator === 'string'
3299
+			? EEH_Form_Fields::get_form_fields($input_vars, $id)
3300
+			: EEH_Form_Fields::get_form_fields_array($input_vars);
3301
+	}
3302
+
3303
+
3304
+	/**
3305
+	 * generates the "Save" and "Save & Close" buttons for edit forms
3306
+	 *
3307
+	 * @param bool             $both     if true then both buttons will be generated.  If false then just the "Save &
3308
+	 *                                   Close" button.
3309
+	 * @param array            $text     if included, generator will use the given text for the buttons ( array([0] =>
3310
+	 *                                   'Save', [1] => 'save & close')
3311
+	 * @param array            $actions  if included allows us to set the actions that each button will carry out (i.e.
3312
+	 *                                   via the "name" value in the button).  We can also use this to just dump
3313
+	 *                                   default actions by submitting some other value.
3314
+	 * @param bool|string|null $referrer if false then we just do the default action on save and close.  Other wise it
3315
+	 *                                   will use the $referrer string. IF null, then we don't do ANYTHING on save and
3316
+	 *                                   close (normal form handling).
3317
+	 */
3318
+	protected function _set_save_buttons($both = true, $text = array(), $actions = array(), $referrer = null)
3319
+	{
3320
+		// make sure $text and $actions are in an array
3321
+		$text = (array) $text;
3322
+		$actions = (array) $actions;
3323
+		$referrer_url = empty($referrer)
3324
+			? '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3325
+			  . $_SERVER['REQUEST_URI']
3326
+			  . '" />'
3327
+			: '<input type="hidden" id="save_and_close_referrer" name="save_and_close_referrer" value="'
3328
+			  . $referrer
3329
+			  . '" />';
3330
+		$button_text = ! empty($text)
3331
+			? $text
3332
+			: array(
3333
+				esc_html__('Save', 'event_espresso'),
3334
+				esc_html__('Save and Close', 'event_espresso'),
3335
+			);
3336
+		$default_names = array('save', 'save_and_close');
3337
+		// add in a hidden index for the current page (so save and close redirects properly)
3338
+		$this->_template_args['save_buttons'] = $referrer_url;
3339
+		foreach ($button_text as $key => $button) {
3340
+			$ref = $default_names[ $key ];
3341
+			$this->_template_args['save_buttons'] .= '<input type="submit" class="button-primary '
3342
+													 . $ref
3343
+													 . '" value="'
3344
+													 . $button
3345
+													 . '" name="'
3346
+													 . (! empty($actions) ? $actions[ $key ] : $ref)
3347
+													 . '" id="'
3348
+													 . $this->_current_view . '_' . $ref
3349
+													 . '" />';
3350
+			if (! $both) {
3351
+				break;
3352
+			}
3353
+		}
3354
+	}
3355
+
3356
+
3357
+	/**
3358
+	 * Wrapper for the protected function.  Allows plugins/addons to call this to set the form tags.
3359
+	 *
3360
+	 * @see   $this->_set_add_edit_form_tags() for details on params
3361
+	 * @since 4.6.0
3362
+	 * @param string $route
3363
+	 * @param array  $additional_hidden_fields
3364
+	 */
3365
+	public function set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3366
+	{
3367
+		$this->_set_add_edit_form_tags($route, $additional_hidden_fields);
3368
+	}
3369
+
3370
+
3371
+	/**
3372
+	 * set form open and close tags on add/edit pages.
3373
+	 *
3374
+	 * @param string $route                    the route you want the form to direct to
3375
+	 * @param array  $additional_hidden_fields any additional hidden fields required in the form header
3376
+	 * @return void
3377
+	 */
3378
+	protected function _set_add_edit_form_tags($route = '', $additional_hidden_fields = array())
3379
+	{
3380
+		if (empty($route)) {
3381
+			$user_msg = esc_html__(
3382
+				'An error occurred. No action was set for this page\'s form.',
3383
+				'event_espresso'
3384
+			);
3385
+			$dev_msg = $user_msg . "\n"
3386
+					   . sprintf(
3387
+						   esc_html__('The $route argument is required for the %s->%s method.', 'event_espresso'),
3388
+						   __FUNCTION__,
3389
+						   EE_Admin_Page::class
3390
+					   );
3391
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
3392
+		}
3393
+		// open form
3394
+		$this->_template_args['before_admin_page_content'] = '<form name="form" method="post" action="'
3395
+															 . $this->_admin_base_url
3396
+															 . '" id="'
3397
+															 . $route
3398
+															 . '_event_form" >';
3399
+		// add nonce
3400
+		$nonce = wp_nonce_field($route . '_nonce', $route . '_nonce', false, false);
3401
+		$this->_template_args['before_admin_page_content'] .= "\n\t" . $nonce;
3402
+		// add REQUIRED form action
3403
+		$hidden_fields = array(
3404
+			'action' => array('type' => 'hidden', 'value' => $route),
3405
+		);
3406
+		// merge arrays
3407
+		$hidden_fields = is_array($additional_hidden_fields)
3408
+			? array_merge($hidden_fields, $additional_hidden_fields)
3409
+			: $hidden_fields;
3410
+		// generate form fields
3411
+		$form_fields = $this->_generate_admin_form_fields($hidden_fields, 'array');
3412
+		// add fields to form
3413
+		foreach ((array) $form_fields as $field_name => $form_field) {
3414
+			$this->_template_args['before_admin_page_content'] .= "\n\t" . $form_field['field'];
3415
+		}
3416
+		// close form
3417
+		$this->_template_args['after_admin_page_content'] = '</form>';
3418
+	}
3419
+
3420
+
3421
+	/**
3422
+	 * Public Wrapper for _redirect_after_action() method since its
3423
+	 * discovered it would be useful for external code to have access.
3424
+	 *
3425
+	 * @param bool   $success
3426
+	 * @param string $what
3427
+	 * @param string $action_desc
3428
+	 * @param array  $query_args
3429
+	 * @param bool   $override_overwrite
3430
+	 * @throws EE_Error
3431
+	 * @throws InvalidArgumentException
3432
+	 * @throws InvalidDataTypeException
3433
+	 * @throws InvalidInterfaceException
3434
+	 * @see   EE_Admin_Page::_redirect_after_action() for params.
3435
+	 * @since 4.5.0
3436
+	 */
3437
+	public function redirect_after_action(
3438
+		$success = false,
3439
+		$what = 'item',
3440
+		$action_desc = 'processed',
3441
+		$query_args = array(),
3442
+		$override_overwrite = false
3443
+	) {
3444
+		$this->_redirect_after_action(
3445
+			$success,
3446
+			$what,
3447
+			$action_desc,
3448
+			$query_args,
3449
+			$override_overwrite
3450
+		);
3451
+	}
3452
+
3453
+
3454
+	/**
3455
+	 * Helper method for merging existing request data with the returned redirect url.
3456
+	 *
3457
+	 * This is typically used for redirects after an action so that if the original view was a filtered view those
3458
+	 * filters are still applied.
3459
+	 *
3460
+	 * @param array $new_route_data
3461
+	 * @return array
3462
+	 */
3463
+	protected function mergeExistingRequestParamsWithRedirectArgs(array $new_route_data)
3464
+	{
3465
+		foreach ($this->_req_data as $ref => $value) {
3466
+			// unset nonces
3467
+			if (strpos($ref, 'nonce') !== false) {
3468
+				unset($this->_req_data[ $ref ]);
3469
+				continue;
3470
+			}
3471
+			// urlencode values.
3472
+			$value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
3473
+			$this->_req_data[ $ref ] = $value;
3474
+		}
3475
+		return array_merge($this->_req_data, $new_route_data);
3476
+	}
3477
+
3478
+
3479
+	/**
3480
+	 *    _redirect_after_action
3481
+	 *
3482
+	 * @param int    $success            - whether success was for two or more records, or just one, or none
3483
+	 * @param string $what               - what the action was performed on
3484
+	 * @param string $action_desc        - what was done ie: updated, deleted, etc
3485
+	 * @param array  $query_args         - an array of query_args to be added to the URL to redirect to after the admin
3486
+	 *                                   action is completed
3487
+	 * @param BOOL   $override_overwrite by default all EE_Error::success messages are overwritten, this allows you to
3488
+	 *                                   override this so that they show.
3489
+	 * @return void
3490
+	 * @throws EE_Error
3491
+	 * @throws InvalidArgumentException
3492
+	 * @throws InvalidDataTypeException
3493
+	 * @throws InvalidInterfaceException
3494
+	 */
3495
+	protected function _redirect_after_action(
3496
+		$success = 0,
3497
+		$what = 'item',
3498
+		$action_desc = 'processed',
3499
+		$query_args = array(),
3500
+		$override_overwrite = false
3501
+	) {
3502
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3503
+		// class name for actions/filters.
3504
+		$classname = get_class($this);
3505
+		// set redirect url.
3506
+		// Note if there is a "page" index in the $query_args then we go with vanilla admin.php route,
3507
+		// otherwise we go with whatever is set as the _admin_base_url
3508
+		$redirect_url = isset($query_args['page']) ? admin_url('admin.php') : $this->_admin_base_url;
3509
+		$notices = EE_Error::get_notices(false);
3510
+		// overwrite default success messages //BUT ONLY if overwrite not overridden
3511
+		if (! $override_overwrite || ! empty($notices['errors'])) {
3512
+			EE_Error::overwrite_success();
3513
+		}
3514
+		if (! empty($what) && ! empty($action_desc) && empty($notices['errors'])) {
3515
+			// how many records affected ? more than one record ? or just one ?
3516
+			if ($success > 1) {
3517
+				// set plural msg
3518
+				EE_Error::add_success(
3519
+					sprintf(
3520
+						esc_html__('The "%s" have been successfully %s.', 'event_espresso'),
3521
+						$what,
3522
+						$action_desc
3523
+					),
3524
+					__FILE__,
3525
+					__FUNCTION__,
3526
+					__LINE__
3527
+				);
3528
+			} elseif ($success === 1) {
3529
+				// set singular msg
3530
+				EE_Error::add_success(
3531
+					sprintf(
3532
+						esc_html__('The "%s" has been successfully %s.', 'event_espresso'),
3533
+						$what,
3534
+						$action_desc
3535
+					),
3536
+					__FILE__,
3537
+					__FUNCTION__,
3538
+					__LINE__
3539
+				);
3540
+			}
3541
+		}
3542
+		// check that $query_args isn't something crazy
3543
+		if (! is_array($query_args)) {
3544
+			$query_args = array();
3545
+		}
3546
+		/**
3547
+		 * Allow injecting actions before the query_args are modified for possible different
3548
+		 * redirections on save and close actions
3549
+		 *
3550
+		 * @since 4.2.0
3551
+		 * @param array $query_args       The original query_args array coming into the
3552
+		 *                                method.
3553
+		 */
3554
+		do_action(
3555
+			"AHEE__{$classname}___redirect_after_action__before_redirect_modification_{$this->_req_action}",
3556
+			$query_args
3557
+		);
3558
+		// calculate where we're going (if we have a "save and close" button pushed)
3559
+		if (isset($this->_req_data['save_and_close'], $this->_req_data['save_and_close_referrer'])) {
3560
+			// even though we have the save_and_close referrer, we need to parse the url for the action in order to generate a nonce
3561
+			$parsed_url = parse_url($this->_req_data['save_and_close_referrer']);
3562
+			// regenerate query args array from referrer URL
3563
+			parse_str($parsed_url['query'], $query_args);
3564
+			// correct page and action will be in the query args now
3565
+			$redirect_url = admin_url('admin.php');
3566
+		}
3567
+		// merge any default query_args set in _default_route_query_args property
3568
+		if (! empty($this->_default_route_query_args) && ! $this->_is_UI_request) {
3569
+			$args_to_merge = array();
3570
+			foreach ($this->_default_route_query_args as $query_param => $query_value) {
3571
+				// is there a wp_referer array in our _default_route_query_args property?
3572
+				if ($query_param === 'wp_referer') {
3573
+					$query_value = (array) $query_value;
3574
+					foreach ($query_value as $reference => $value) {
3575
+						if (strpos($reference, 'nonce') !== false) {
3576
+							continue;
3577
+						}
3578
+						// finally we will override any arguments in the referer with
3579
+						// what might be set on the _default_route_query_args array.
3580
+						if (isset($this->_default_route_query_args[ $reference ])) {
3581
+							$args_to_merge[ $reference ] = urlencode($this->_default_route_query_args[ $reference ]);
3582
+						} else {
3583
+							$args_to_merge[ $reference ] = urlencode($value);
3584
+						}
3585
+					}
3586
+					continue;
3587
+				}
3588
+				$args_to_merge[ $query_param ] = $query_value;
3589
+			}
3590
+			// now let's merge these arguments but override with what was specifically sent in to the
3591
+			// redirect.
3592
+			$query_args = array_merge($args_to_merge, $query_args);
3593
+		}
3594
+		$this->_process_notices($query_args);
3595
+		// generate redirect url
3596
+		// if redirecting to anything other than the main page, add a nonce
3597
+		if (isset($query_args['action'])) {
3598
+			// manually generate wp_nonce and merge that with the query vars
3599
+			// becuz the wp_nonce_url function wrecks havoc on some vars
3600
+			$query_args['_wpnonce'] = wp_create_nonce($query_args['action'] . '_nonce');
3601
+		}
3602
+		// we're adding some hooks and filters in here for processing any things just before redirects
3603
+		// (example: an admin page has done an insert or update and we want to run something after that).
3604
+		do_action('AHEE_redirect_' . $classname . $this->_req_action, $query_args);
3605
+		$redirect_url = apply_filters(
3606
+			'FHEE_redirect_' . $classname . $this->_req_action,
3607
+			EE_Admin_Page::add_query_args_and_nonce($query_args, $redirect_url),
3608
+			$query_args
3609
+		);
3610
+		// check if we're doing ajax.  If we are then lets just return the results and js can handle how it wants.
3611
+		if (defined('DOING_AJAX')) {
3612
+			$default_data = array(
3613
+				'close'        => true,
3614
+				'redirect_url' => $redirect_url,
3615
+				'where'        => 'main',
3616
+				'what'         => 'append',
3617
+			);
3618
+			$this->_template_args['success'] = $success;
3619
+			$this->_template_args['data'] = ! empty($this->_template_args['data']) ? array_merge(
3620
+				$default_data,
3621
+				$this->_template_args['data']
3622
+			) : $default_data;
3623
+			$this->_return_json();
3624
+		}
3625
+		wp_safe_redirect($redirect_url);
3626
+		exit();
3627
+	}
3628
+
3629
+
3630
+	/**
3631
+	 * process any notices before redirecting (or returning ajax request)
3632
+	 * This method sets the $this->_template_args['notices'] attribute;
3633
+	 *
3634
+	 * @param array $query_args         any query args that need to be used for notice transient ('action')
3635
+	 * @param bool  $skip_route_verify  This is typically used when we are processing notices REALLY early and
3636
+	 *                                  page_routes haven't been defined yet.
3637
+	 * @param bool  $sticky_notices     This is used to flag that regardless of whether this is doing_ajax or not, we
3638
+	 *                                  still save a transient for the notice.
3639
+	 * @return void
3640
+	 * @throws EE_Error
3641
+	 * @throws InvalidArgumentException
3642
+	 * @throws InvalidDataTypeException
3643
+	 * @throws InvalidInterfaceException
3644
+	 */
3645
+	protected function _process_notices($query_args = array(), $skip_route_verify = false, $sticky_notices = true)
3646
+	{
3647
+		// first let's set individual error properties if doing_ajax and the properties aren't already set.
3648
+		if (defined('DOING_AJAX') && DOING_AJAX) {
3649
+			$notices = EE_Error::get_notices(false);
3650
+			if (empty($this->_template_args['success'])) {
3651
+				$this->_template_args['success'] = isset($notices['success']) ? $notices['success'] : false;
3652
+			}
3653
+			if (empty($this->_template_args['errors'])) {
3654
+				$this->_template_args['errors'] = isset($notices['errors']) ? $notices['errors'] : false;
3655
+			}
3656
+			if (empty($this->_template_args['attention'])) {
3657
+				$this->_template_args['attention'] = isset($notices['attention']) ? $notices['attention'] : false;
3658
+			}
3659
+		}
3660
+		$this->_template_args['notices'] = EE_Error::get_notices();
3661
+		// IF this isn't ajax we need to create a transient for the notices using the route (however, overridden if $sticky_notices == true)
3662
+		if (! defined('DOING_AJAX') || $sticky_notices) {
3663
+			$route = isset($query_args['action']) ? $query_args['action'] : 'default';
3664
+			$this->_add_transient(
3665
+				$route,
3666
+				$this->_template_args['notices'],
3667
+				true,
3668
+				$skip_route_verify
3669
+			);
3670
+		}
3671
+	}
3672
+
3673
+
3674
+	/**
3675
+	 * get_action_link_or_button
3676
+	 * returns the button html for adding, editing, or deleting an item (depending on given type)
3677
+	 *
3678
+	 * @param string $action        use this to indicate which action the url is generated with.
3679
+	 * @param string $type          accepted strings must be defined in the $_labels['button'] array(as the key)
3680
+	 *                              property.
3681
+	 * @param array  $extra_request if the button requires extra params you can include them in $key=>$value pairs.
3682
+	 * @param string $class         Use this to give the class for the button. Defaults to 'button-primary'
3683
+	 * @param string $base_url      If this is not provided
3684
+	 *                              the _admin_base_url will be used as the default for the button base_url.
3685
+	 *                              Otherwise this value will be used.
3686
+	 * @param bool   $exclude_nonce If true then no nonce will be in the generated button link.
3687
+	 * @return string
3688
+	 * @throws InvalidArgumentException
3689
+	 * @throws InvalidInterfaceException
3690
+	 * @throws InvalidDataTypeException
3691
+	 * @throws EE_Error
3692
+	 */
3693
+	public function get_action_link_or_button(
3694
+		$action,
3695
+		$type = 'add',
3696
+		$extra_request = array(),
3697
+		$class = 'button-primary',
3698
+		$base_url = '',
3699
+		$exclude_nonce = false
3700
+	) {
3701
+		// first let's validate the action (if $base_url is FALSE otherwise validation will happen further along)
3702
+		if (empty($base_url) && ! isset($this->_page_routes[ $action ])) {
3703
+			throw new EE_Error(
3704
+				sprintf(
3705
+					esc_html__(
3706
+						'There is no page route for given action for the button.  This action was given: %s',
3707
+						'event_espresso'
3708
+					),
3709
+					$action
3710
+				)
3711
+			);
3712
+		}
3713
+		if (! isset($this->_labels['buttons'][ $type ])) {
3714
+			throw new EE_Error(
3715
+				sprintf(
3716
+					__(
3717
+						'There is no label for the given button type (%s). Labels are set in the <code>_page_config</code> property.',
3718
+						'event_espresso'
3719
+					),
3720
+					$type
3721
+				)
3722
+			);
3723
+		}
3724
+		// finally check user access for this button.
3725
+		$has_access = $this->check_user_access($action, true);
3726
+		if (! $has_access) {
3727
+			return '';
3728
+		}
3729
+		$_base_url = ! $base_url ? $this->_admin_base_url : $base_url;
3730
+		$query_args = array(
3731
+			'action' => $action,
3732
+		);
3733
+		// merge extra_request args but make sure our original action takes precedence and doesn't get overwritten.
3734
+		if (! empty($extra_request)) {
3735
+			$query_args = array_merge($extra_request, $query_args);
3736
+		}
3737
+		$url = EE_Admin_Page::add_query_args_and_nonce($query_args, $_base_url, false, $exclude_nonce);
3738
+		return EEH_Template::get_button_or_link($url, $this->_labels['buttons'][ $type ], $class);
3739
+	}
3740
+
3741
+
3742
+	/**
3743
+	 * _per_page_screen_option
3744
+	 * Utility function for adding in a per_page_option in the screen_options_dropdown.
3745
+	 *
3746
+	 * @return void
3747
+	 * @throws InvalidArgumentException
3748
+	 * @throws InvalidInterfaceException
3749
+	 * @throws InvalidDataTypeException
3750
+	 */
3751
+	protected function _per_page_screen_option()
3752
+	{
3753
+		$option = 'per_page';
3754
+		$args = array(
3755
+			'label'   => apply_filters(
3756
+				'FHEE__EE_Admin_Page___per_page_screen_options___label',
3757
+				$this->_admin_page_title,
3758
+				$this
3759
+			),
3760
+			'default' => (int) apply_filters(
3761
+				'FHEE__EE_Admin_Page___per_page_screen_options__default',
3762
+				20
3763
+			),
3764
+			'option'  => $this->_current_page . '_' . $this->_current_view . '_per_page',
3765
+		);
3766
+		// ONLY add the screen option if the user has access to it.
3767
+		if ($this->check_user_access($this->_current_view, true)) {
3768
+			add_screen_option($option, $args);
3769
+		}
3770
+	}
3771
+
3772
+
3773
+	/**
3774
+	 * set_per_page_screen_option
3775
+	 * All this does is make sure that WordPress saves any per_page screen options (if set) for the current page.
3776
+	 * we have to do this rather than running inside the 'set-screen-options' hook because it runs earlier than
3777
+	 * admin_menu.
3778
+	 *
3779
+	 * @return void
3780
+	 */
3781
+	private function _set_per_page_screen_options()
3782
+	{
3783
+		if (isset($_POST['wp_screen_options']) && is_array($_POST['wp_screen_options'])) {
3784
+			check_admin_referer('screen-options-nonce', 'screenoptionnonce');
3785
+			if (! $user = wp_get_current_user()) {
3786
+				return;
3787
+			}
3788
+			$option = $_POST['wp_screen_options']['option'];
3789
+			$value = $_POST['wp_screen_options']['value'];
3790
+			if ($option !== sanitize_key($option)) {
3791
+				return;
3792
+			}
3793
+			$map_option = $option;
3794
+			$option = str_replace('-', '_', $option);
3795
+			switch ($map_option) {
3796
+				case $this->_current_page . '_' . $this->_current_view . '_per_page':
3797
+					$value = (int) $value;
3798
+					$max_value = apply_filters(
3799
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__max_value',
3800
+						999,
3801
+						$this->_current_page,
3802
+						$this->_current_view
3803
+					);
3804
+					if ($value < 1) {
3805
+						return;
3806
+					}
3807
+					$value = min($value, $max_value);
3808
+					break;
3809
+				default:
3810
+					$value = apply_filters(
3811
+						'FHEE__EE_Admin_Page___set_per_page_screen_options__value',
3812
+						false,
3813
+						$option,
3814
+						$value
3815
+					);
3816
+					if (false === $value) {
3817
+						return;
3818
+					}
3819
+					break;
3820
+			}
3821
+			update_user_meta($user->ID, $option, $value);
3822
+			wp_safe_redirect(remove_query_arg(array('pagenum', 'apage', 'paged'), wp_get_referer()));
3823
+			exit;
3824
+		}
3825
+	}
3826
+
3827
+
3828
+	/**
3829
+	 * This just allows for setting the $_template_args property if it needs to be set outside the object
3830
+	 *
3831
+	 * @param array $data array that will be assigned to template args.
3832
+	 */
3833
+	public function set_template_args($data)
3834
+	{
3835
+		$this->_template_args = array_merge($this->_template_args, (array) $data);
3836
+	}
3837
+
3838
+
3839
+	/**
3840
+	 * This makes available the WP transient system for temporarily moving data between routes
3841
+	 *
3842
+	 * @param string $route             the route that should receive the transient
3843
+	 * @param array  $data              the data that gets sent
3844
+	 * @param bool   $notices           If this is for notices then we use this to indicate so, otherwise its just a
3845
+	 *                                  normal route transient.
3846
+	 * @param bool   $skip_route_verify Used to indicate we want to skip route verification.  This is usually ONLY used
3847
+	 *                                  when we are adding a transient before page_routes have been defined.
3848
+	 * @return void
3849
+	 * @throws EE_Error
3850
+	 */
3851
+	protected function _add_transient($route, $data, $notices = false, $skip_route_verify = false)
3852
+	{
3853
+		$user_id = get_current_user_id();
3854
+		if (! $skip_route_verify) {
3855
+			$this->_verify_route($route);
3856
+		}
3857
+		// now let's set the string for what kind of transient we're setting
3858
+		$transient = $notices
3859
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3860
+			: 'rte_tx_' . $route . '_' . $user_id;
3861
+		$data = $notices ? array('notices' => $data) : $data;
3862
+		// is there already a transient for this route?  If there is then let's ADD to that transient
3863
+		$existing = is_multisite() && is_network_admin()
3864
+			? get_site_transient($transient)
3865
+			: get_transient($transient);
3866
+		if ($existing) {
3867
+			$data = array_merge((array) $data, (array) $existing);
3868
+		}
3869
+		if (is_multisite() && is_network_admin()) {
3870
+			set_site_transient($transient, $data, 8);
3871
+		} else {
3872
+			set_transient($transient, $data, 8);
3873
+		}
3874
+	}
3875
+
3876
+
3877
+	/**
3878
+	 * this retrieves the temporary transient that has been set for moving data between routes.
3879
+	 *
3880
+	 * @param bool   $notices true we get notices transient. False we just return normal route transient
3881
+	 * @param string $route
3882
+	 * @return mixed data
3883
+	 */
3884
+	protected function _get_transient($notices = false, $route = '')
3885
+	{
3886
+		$user_id = get_current_user_id();
3887
+		$route = ! $route ? $this->_req_action : $route;
3888
+		$transient = $notices
3889
+			? 'ee_rte_n_tx_' . $route . '_' . $user_id
3890
+			: 'rte_tx_' . $route . '_' . $user_id;
3891
+		$data = is_multisite() && is_network_admin()
3892
+			? get_site_transient($transient)
3893
+			: get_transient($transient);
3894
+		// delete transient after retrieval (just in case it hasn't expired);
3895
+		if (is_multisite() && is_network_admin()) {
3896
+			delete_site_transient($transient);
3897
+		} else {
3898
+			delete_transient($transient);
3899
+		}
3900
+		return $notices && isset($data['notices']) ? $data['notices'] : $data;
3901
+	}
3902
+
3903
+
3904
+	/**
3905
+	 * The purpose of this method is just to run garbage collection on any EE transients that might have expired but
3906
+	 * would not be called later. This will be assigned to run on a specific EE Admin page. (place the method in the
3907
+	 * default route callback on the EE_Admin page you want it run.)
3908
+	 *
3909
+	 * @return void
3910
+	 */
3911
+	protected function _transient_garbage_collection()
3912
+	{
3913
+		global $wpdb;
3914
+		// retrieve all existing transients
3915
+		$query = "SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE '%rte_tx_%' OR option_name LIKE '%rte_n_tx_%'";
3916
+		if ($results = $wpdb->get_results($query)) {
3917
+			foreach ($results as $result) {
3918
+				$transient = str_replace('_transient_', '', $result->option_name);
3919
+				get_transient($transient);
3920
+				if (is_multisite() && is_network_admin()) {
3921
+					get_site_transient($transient);
3922
+				}
3923
+			}
3924
+		}
3925
+	}
3926
+
3927
+
3928
+	/**
3929
+	 * get_view
3930
+	 *
3931
+	 * @return string content of _view property
3932
+	 */
3933
+	public function get_view()
3934
+	{
3935
+		return $this->_view;
3936
+	}
3937
+
3938
+
3939
+	/**
3940
+	 * getter for the protected $_views property
3941
+	 *
3942
+	 * @return array
3943
+	 */
3944
+	public function get_views()
3945
+	{
3946
+		return $this->_views;
3947
+	}
3948
+
3949
+
3950
+	/**
3951
+	 * get_current_page
3952
+	 *
3953
+	 * @return string _current_page property value
3954
+	 */
3955
+	public function get_current_page()
3956
+	{
3957
+		return $this->_current_page;
3958
+	}
3959
+
3960
+
3961
+	/**
3962
+	 * get_current_view
3963
+	 *
3964
+	 * @return string _current_view property value
3965
+	 */
3966
+	public function get_current_view()
3967
+	{
3968
+		return $this->_current_view;
3969
+	}
3970
+
3971
+
3972
+	/**
3973
+	 * get_current_screen
3974
+	 *
3975
+	 * @return object The current WP_Screen object
3976
+	 */
3977
+	public function get_current_screen()
3978
+	{
3979
+		return $this->_current_screen;
3980
+	}
3981
+
3982
+
3983
+	/**
3984
+	 * get_current_page_view_url
3985
+	 *
3986
+	 * @return string This returns the url for the current_page_view.
3987
+	 */
3988
+	public function get_current_page_view_url()
3989
+	{
3990
+		return $this->_current_page_view_url;
3991
+	}
3992
+
3993
+
3994
+	/**
3995
+	 * just returns the _req_data property
3996
+	 *
3997
+	 * @return array
3998
+	 */
3999
+	public function get_request_data()
4000
+	{
4001
+		return $this->_req_data;
4002
+	}
4003
+
4004
+
4005
+	/**
4006
+	 * returns the _req_data protected property
4007
+	 *
4008
+	 * @return string
4009
+	 */
4010
+	public function get_req_action()
4011
+	{
4012
+		return $this->_req_action;
4013
+	}
4014
+
4015
+
4016
+	/**
4017
+	 * @return bool  value of $_is_caf property
4018
+	 */
4019
+	public function is_caf()
4020
+	{
4021
+		return $this->_is_caf;
4022
+	}
4023
+
4024
+
4025
+	/**
4026
+	 * @return mixed
4027
+	 */
4028
+	public function default_espresso_metaboxes()
4029
+	{
4030
+		return $this->_default_espresso_metaboxes;
4031
+	}
4032
+
4033
+
4034
+	/**
4035
+	 * @return mixed
4036
+	 */
4037
+	public function admin_base_url()
4038
+	{
4039
+		return $this->_admin_base_url;
4040
+	}
4041
+
4042
+
4043
+	/**
4044
+	 * @return mixed
4045
+	 */
4046
+	public function wp_page_slug()
4047
+	{
4048
+		return $this->_wp_page_slug;
4049
+	}
4050
+
4051
+
4052
+	/**
4053
+	 * updates  espresso configuration settings
4054
+	 *
4055
+	 * @param string                   $tab
4056
+	 * @param EE_Config_Base|EE_Config $config
4057
+	 * @param string                   $file file where error occurred
4058
+	 * @param string                   $func function  where error occurred
4059
+	 * @param string                   $line line no where error occurred
4060
+	 * @return boolean
4061
+	 */
4062
+	protected function _update_espresso_configuration($tab, $config, $file = '', $func = '', $line = '')
4063
+	{
4064
+		// remove any options that are NOT going to be saved with the config settings.
4065
+		if (isset($config->core->ee_ueip_optin)) {
4066
+			// TODO: remove the following two lines and make sure values are migrated from 3.1
4067
+			update_option('ee_ueip_optin', $config->core->ee_ueip_optin);
4068
+			update_option('ee_ueip_has_notified', true);
4069
+		}
4070
+		// and save it (note we're also doing the network save here)
4071
+		$net_saved = is_main_site() ? EE_Network_Config::instance()->update_config(false, false) : true;
4072
+		$config_saved = EE_Config::instance()->update_espresso_config(false, false);
4073
+		if ($config_saved && $net_saved) {
4074
+			EE_Error::add_success(sprintf(__('"%s" have been successfully updated.', 'event_espresso'), $tab));
4075
+			return true;
4076
+		}
4077
+		EE_Error::add_error(sprintf(__('The "%s" were not updated.', 'event_espresso'), $tab), $file, $func, $line);
4078
+		return false;
4079
+	}
4080
+
4081
+
4082
+	/**
4083
+	 * Returns an array to be used for EE_FOrm_Fields.helper.php's select_input as the $values argument.
4084
+	 *
4085
+	 * @return array
4086
+	 */
4087
+	public function get_yes_no_values()
4088
+	{
4089
+		return $this->_yes_no_values;
4090
+	}
4091
+
4092
+
4093
+	/**
4094
+	 * @return string
4095
+	 * @throws ReflectionException
4096
+	 * @since $VID:$
4097
+	 */
4098
+	protected function _get_dir()
4099
+	{
4100
+		$reflector = new ReflectionClass(get_class($this));
4101
+		return dirname($reflector->getFileName());
4102
+	}
4103
+
4104
+
4105
+	/**
4106
+	 * A helper for getting a "next link".
4107
+	 *
4108
+	 * @param string $url   The url to link to
4109
+	 * @param string $class The class to use.
4110
+	 * @return string
4111
+	 */
4112
+	protected function _next_link($url, $class = 'dashicons dashicons-arrow-right')
4113
+	{
4114
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4115
+	}
4116
+
4117
+
4118
+	/**
4119
+	 * A helper for getting a "previous link".
4120
+	 *
4121
+	 * @param string $url   The url to link to
4122
+	 * @param string $class The class to use.
4123
+	 * @return string
4124
+	 */
4125
+	protected function _previous_link($url, $class = 'dashicons dashicons-arrow-left')
4126
+	{
4127
+		return '<a class="' . $class . '" href="' . $url . '"></a>';
4128
+	}
4129
+
4130
+
4131
+
4132
+
4133
+
4134
+
4135
+
4136
+	// below are some messages related methods that should be available across the EE_Admin system.  Note, these methods are NOT page specific
4137
+
4138
+
4139
+	/**
4140
+	 * This processes an request to resend a registration and assumes we have a _REG_ID for doing so. So if the caller
4141
+	 * knows that the _REG_ID isn't in the req_data array but CAN obtain it, the caller should ADD the _REG_ID to the
4142
+	 * _req_data array.
4143
+	 *
4144
+	 * @return bool success/fail
4145
+	 * @throws EE_Error
4146
+	 * @throws InvalidArgumentException
4147
+	 * @throws ReflectionException
4148
+	 * @throws InvalidDataTypeException
4149
+	 * @throws InvalidInterfaceException
4150
+	 */
4151
+	protected function _process_resend_registration()
4152
+	{
4153
+		$this->_template_args['success'] = EED_Messages::process_resend($this->_req_data);
4154
+		do_action(
4155
+			'AHEE__EE_Admin_Page___process_resend_registration',
4156
+			$this->_template_args['success'],
4157
+			$this->_req_data
4158
+		);
4159
+		return $this->_template_args['success'];
4160
+	}
4161
+
4162
+
4163
+	/**
4164
+	 * This automatically processes any payment message notifications when manual payment has been applied.
4165
+	 *
4166
+	 * @param EE_Payment $payment
4167
+	 * @return bool success/fail
4168
+	 */
4169
+	protected function _process_payment_notification(EE_Payment $payment)
4170
+	{
4171
+		add_filter('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', '__return_true');
4172
+		do_action('AHEE__EE_Admin_Page___process_admin_payment_notification', $payment);
4173
+		$this->_template_args['success'] = apply_filters(
4174
+			'FHEE__EE_Admin_Page___process_admin_payment_notification__success',
4175
+			false,
4176
+			$payment
4177
+		);
4178
+		return $this->_template_args['success'];
4179
+	}
4180 4180
 }
Please login to merge, or discard this patch.
core/admin/EE_Admin_Page_Init.core.php 2 patches
Indentation   +451 added lines, -451 removed lines patch added patch discarded remove patch
@@ -17,455 +17,455 @@
 block discarded – undo
17 17
 abstract class EE_Admin_Page_Init extends EE_Base
18 18
 {
19 19
 
20
-    /**
21
-     * @var LoaderInterface $loader
22
-     */
23
-    protected $loader;
24
-
25
-    // identity properties (set in _set_defaults and _set_init_properties)
26
-    public $label;
27
-
28
-    /**
29
-     * Menu map has a capability.  However, this allows admin pages to have separate capability requirements for menus
30
-     * and accessing pages.  If capability is NOT set, then it defaults to the menu_map capability.
31
-     *
32
-     * @var string
33
-     */
34
-    public $capability;
35
-
36
-
37
-    /**
38
-     * This holds the menu map object for this admin page.
39
-     *
40
-     * @var EE_Admin_Page_Menu_Map
41
-     */
42
-    protected $_menu_map;
43
-
44
-    /**
45
-     * deprecated
46
-     */
47
-    public $menu_label;
48
-    public $menu_slug;
49
-
50
-
51
-    // set in _set_defaults
52
-    protected $_folder_name;
53
-    protected $_folder_path;
54
-    protected $_file_name;
55
-    public $hook_file;
56
-    protected $_wp_page_slug;
57
-    protected $_routing;
58
-
59
-
60
-    /**
61
-     * This holds the page object.
62
-     *
63
-     * @var EE_Admin_Page
64
-     */
65
-    protected $_loaded_page_object;
66
-
67
-
68
-    // for caf
69
-    protected $_files_hooked;
70
-    protected $_hook_paths;
71
-
72
-    // load_page?
73
-    private $_load_page;
74
-
75
-
76
-    /**
77
-     * @throws InvalidArgumentException
78
-     * @throws InvalidDataTypeException
79
-     * @throws InvalidInterfaceException
80
-     */
81
-    public function __construct()
82
-    {
83
-        $this->loader = LoaderFactory::getLoader();
84
-        // set global defaults
85
-        $this->_set_defaults();
86
-        // set properties that are always available with objects.
87
-        $this->_set_init_properties();
88
-        // global styles/scripts across all wp admin pages
89
-        add_action('admin_enqueue_scripts', array($this, 'load_wp_global_scripts_styles'), 5);
90
-        // load initial stuff.
91
-        $this->_set_file_and_folder_name();
92
-        $this->_set_menu_map();
93
-        if (empty($this->_menu_map) || is_array($this->_menu_map)) {
94
-            EE_Error::doing_it_wrong(
95
-                get_class($this) . '::$_menu_map',
96
-                sprintf(
97
-                    __(
98
-                        'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core.  Please see Admin_Page_Init class examples in core for the new way of setting this property up.',
99
-                        'event_espresso'
100
-                    ),
101
-                    get_class($this)
102
-                ),
103
-                '4.4.0'
104
-            );
105
-            return;
106
-        }
107
-        // set default capability
108
-        $this->_set_capability();
109
-    }
110
-
111
-
112
-    /**
113
-     * _set_init_properties
114
-     * Child classes use to set the following properties:
115
-     * $label
116
-     *
117
-     * @abstract
118
-     * @access protected
119
-     * @return void
120
-     */
121
-    abstract protected function _set_init_properties();
122
-
123
-
124
-    /**
125
-     * _set_menu_map is a function that child classes use to set the menu_map property (which should be an instance of
126
-     * EE_Admin_Page_Menu_Map.  Their menu can either be EE_Admin_Page_Main_Menu or EE_Admin_Page_Sub_Menu.
127
-     *
128
-     * @since 4.4.0
129
-     * @ return void.
130
-     */
131
-    protected function _set_menu_map()
132
-    {
133
-        return array();
134
-    }
135
-
136
-
137
-    /**
138
-     * returns the menu map for this admin page
139
-     *
140
-     * @since 4.4.0
141
-     * @return EE_Admin_Page_Menu_Map
142
-     */
143
-    public function get_menu_map()
144
-    {
145
-        return $this->_menu_map;
146
-    }
147
-
148
-
149
-    /**
150
-     * This loads scripts and styles for the EE_Admin system
151
-     * that must be available on ALL WP admin pages (i.e. EE_menu items)
152
-     *
153
-     * @return void
154
-     */
155
-    public function load_wp_global_scripts_styles()
156
-    {
157
-        wp_register_style(
158
-            'espresso_menu',
159
-            EE_ADMIN_URL . 'assets/admin-menu-styles.css',
160
-            array('dashicons'),
161
-            EVENT_ESPRESSO_VERSION
162
-        );
163
-        wp_enqueue_style('espresso_menu');
164
-    }
165
-
166
-
167
-    /**
168
-     * this sets default properties (might be overridden in _set_init_properties);
169
-     *
170
-     * @access private
171
-     * @return  void
172
-     */
173
-    private function _set_defaults()
174
-    {
175
-        $this->_file_name = $this->_folder_name = $this->_wp_page_slug = $this->capability = null;
176
-        $this->_routing = true;
177
-        $this->_load_page = false;
178
-        $this->_files_hooked = $this->_hook_paths = array();
179
-        // menu_map
180
-        $this->_menu_map = $this->get_menu_map();
181
-    }
182
-
183
-
184
-    protected function _set_capability()
185
-    {
186
-        $capability = empty($this->capability) ? $this->_menu_map->capability : $this->capability;
187
-        $this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability);
188
-    }
189
-
190
-
191
-    /**
192
-     * initialize_admin_page
193
-     * This method is what executes the loading of the specific page class for the given dir_name as called by the
194
-     * EE_Admin_Init class.
195
-     *
196
-     * @access  public
197
-     * @return void
198
-     * @throws EE_Error
199
-     * @throws InvalidArgumentException
200
-     * @throws InvalidDataTypeException
201
-     * @throws InvalidInterfaceException
202
-     * @throws ReflectionException
203
-     * @uses    _initialize_admin_page()
204
-     */
205
-    public function initialize_admin_page()
206
-    {
207
-        // let's check user access first
208
-        $this->_check_user_access();
209
-        if (! is_object($this->_loaded_page_object)) {
210
-            return;
211
-        }
212
-        $this->_loaded_page_object->route_admin_request();
213
-    }
214
-
215
-
216
-    /**
217
-     * @param string $wp_page_slug
218
-     * @throws EE_Error
219
-     * @since $VID:$
220
-     */
221
-    public function set_page_dependencies($wp_page_slug)
222
-    {
223
-        if (! $this->_load_page) {
224
-            return;
225
-        }
226
-        if (! is_object($this->_loaded_page_object)) {
227
-            $msg[] = __(
228
-                'We can\'t load the page because we\'re missing a valid page object that tells us what to load',
229
-                'event_espresso'
230
-            );
231
-            $msg[] = $msg[0] . "\r\n"
232
-                     . sprintf(
233
-                         __(
234
-                             'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory',
235
-                             'event_espresso'
236
-                         ),
237
-                         $this->_file_name,
238
-                         $this->_file_name,
239
-                         $this->_folder_path . $this->_file_name,
240
-                         $this->_menu_map->menu_slug
241
-                     );
242
-            throw new EE_Error(implode('||', $msg));
243
-        }
244
-        $this->_loaded_page_object->set_wp_page_slug($wp_page_slug);
245
-        $page_hook = 'load-' . $wp_page_slug;
246
-        // hook into page load hook so all page specific stuff get's loaded.
247
-        if (! empty($wp_page_slug)) {
248
-            add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies'));
249
-        }
250
-    }
251
-
252
-
253
-    /**
254
-     * This executes the initial page loads for EE_Admin pages to take care of any ajax or other code needing to run
255
-     * before the load-page... hook. Note, the page loads are happening around the wp_init hook.
256
-     *
257
-     * @return void
258
-     * @throws EE_Error
259
-     * @throws InvalidArgumentException
260
-     * @throws InvalidDataTypeException
261
-     * @throws InvalidInterfaceException
262
-     * @throws ReflectionException
263
-     */
264
-    public function do_initial_loads()
265
-    {
266
-        // no loading or initializing if menu map is setup incorrectly.
267
-        if (empty($this->_menu_map) || is_array($this->_menu_map)) {
268
-            return;
269
-        }
270
-        $this->_initialize_admin_page();
271
-    }
272
-
273
-
274
-    /**
275
-     * all we're doing here is setting the $_file_name property for later use.
276
-     *
277
-     * @access private
278
-     * @return void
279
-     */
280
-    private function _set_file_and_folder_name()
281
-    {
282
-        $bt = debug_backtrace();
283
-        // for more reliable determination of folder name
284
-        // we're using this to get the actual folder name of the CALLING class (i.e. the child class that extends this).  Why?  Because $this->menu_slug may be different than the folder name (to avoid conflicts with other plugins)
285
-        $class = get_class($this);
286
-        foreach ($bt as $index => $values) {
287
-            if (isset($values['class']) && $values['class'] === $class) {
288
-                $file_index = $index - 1;
289
-                $this->_folder_name = basename(dirname($bt[ $file_index ]['file']));
290
-                if (! empty($this->_folder_name)) {
291
-                    break;
292
-                }
293
-            }
294
-        }
295
-        $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . '/';
296
-        $this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name);
297
-        $this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name));
298
-        $this->_file_name = str_replace(' ', '_', $this->_file_name);
299
-    }
300
-
301
-
302
-    /**
303
-     * This automatically checks if we have a hook class in the loaded child directory.  If we DO then we will register
304
-     * it with the appropriate pages.  That way all we have to do is make sure the file is named correctly and
305
-     * "dropped" in. Example: if we wanted to set this up for Messages hooking into Events then we would do:
306
-     * events_Messages_Hooks.class.php
307
-     *
308
-     * @param bool $extend This indicates whether we're checking the extend directory for any register_hooks
309
-     *                     files/classes
310
-     * @return array
311
-     */
312
-    public function register_hooks($extend = false)
313
-    {
314
-
315
-        // get a list of files in the directory that have the "Hook" in their name an
316
-        // if this is an extended check (i.e. caf is active) then we will scan the caffeinated/extend directory first and any hook files that are found will be have their reference added to the $_files_hook array property.  Then, we make sure that when we loop through the core decaf directories to find hook files that we skip over any hooks files that have already been set by caf.
317
-        if ($extend) {
318
-            $hook_files_glob_path = apply_filters(
319
-                'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path__extend',
320
-                EE_CORE_CAF_ADMIN_EXTEND
321
-                . $this->_folder_name
322
-                . '/*'
323
-                . $this->_file_name
324
-                . '_Hooks_Extend.class.php'
325
-            );
326
-            $this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend);
327
-        }
328
-        // loop through decaf folders
329
-        $hook_files_glob_path = apply_filters(
330
-            'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path',
331
-            $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php'
332
-        );
333
-        $this->_hook_paths = array_merge(
334
-            $this->_register_hook_files($hook_files_glob_path),
335
-            $this->_hook_paths
336
-        );  // making sure any extended hook paths are later in the array than the core hook paths!
337
-        return $this->_hook_paths;
338
-    }
339
-
340
-
341
-    protected function _register_hook_files($hook_files_glob_path, $extend = false)
342
-    {
343
-        $hook_paths = array();
344
-        if ($hook_files = glob($hook_files_glob_path)) {
345
-            if (empty($hook_files)) {
346
-                return array();
347
-            }
348
-            foreach ($hook_files as $file) {
349
-                // lets get the linked admin.
350
-                $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . '/', '', $file)
351
-                    : str_replace($this->_folder_path, '', $file);
352
-                $replace = $extend
353
-                    ? '_' . $this->_file_name . '_Hooks_Extend.class.php'
354
-                    : '_'
355
-                      . $this->_file_name
356
-                      . '_Hooks.class.php';
357
-                $rel_admin = str_replace($replace, '', $hook_file);
358
-                $rel_admin = strtolower($rel_admin);
359
-                $hook_paths[] = $file;
360
-                // make sure we haven't already got a hook setup for this page path
361
-                if (in_array($rel_admin, $this->_files_hooked, true)) {
362
-                    continue;
363
-                }
364
-                $this->hook_file = $hook_file;
365
-                $rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin;
366
-                add_filter($rel_admin_hook, array($this, 'load_admin_hook'));
367
-                $this->_files_hooked[] = $rel_admin;
368
-            }
369
-        }
370
-        return $hook_paths;
371
-    }
372
-
373
-
374
-    public function load_admin_hook($registered_pages)
375
-    {
376
-        $this->hook_file;
377
-        $hook_file = (array) $this->hook_file;
378
-        return array_merge($hook_file, $registered_pages);
379
-    }
380
-
381
-
382
-    /**
383
-     * _initialize_admin_page
384
-     *
385
-     * @throws EE_Error
386
-     * @throws InvalidArgumentException
387
-     * @throws InvalidDataTypeException
388
-     * @throws InvalidInterfaceException
389
-     * @throws ReflectionException
390
-     * @see  initialize_admin_page() for info
391
-     */
392
-    protected function _initialize_admin_page()
393
-    {
394
-        // just check we're on right page and if not get out
395
-        if ((! isset($_REQUEST['page']) || $_REQUEST['page'] !== $this->_menu_map->menu_slug) && $this->_routing) {
396
-            return;
397
-        }
398
-        $this->_load_page = true;
399
-
400
-        // we don't need to do a page_request check here because it's only called via WP menu system.
401
-        $admin_page = $this->_file_name . '_Admin_Page';
402
-        $hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page;
403
-        $admin_page = apply_filters(
404
-            "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}",
405
-            $admin_page
406
-        );
407
-        // define requested admin page class name then load the file and instantiate
408
-        $path_to_file = str_replace(array('\\', '/'), '/', $this->_folder_path . $admin_page . '.core.php');
409
-        $path_to_file = apply_filters(
410
-            "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}",
411
-            $path_to_file
412
-        );
413
-        // so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php,
414
-        // the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page
415
-        if (is_readable($path_to_file)) {
416
-            // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place
417
-            do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization');
418
-            do_action(
419
-                'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug
420
-            );
421
-            require_once($path_to_file);
422
-            $this->_loaded_page_object = $this->loader->getShared($admin_page, [$this->_routing]);
423
-            $this->_loaded_page_object->initializePage();
424
-        }
425
-        do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization');
426
-        do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug);
427
-    }
428
-
429
-
430
-    public function get_admin_page_name()
431
-    {
432
-        return $this->_file_name . '_Admin_Page';
433
-    }
434
-
435
-
436
-    /**
437
-     * @return mixed
438
-     */
439
-    public function loaded_page_object()
440
-    {
441
-        return $this->_loaded_page_object;
442
-    }
443
-
444
-
445
-    // public function set_autoloaders($className)
446
-    // {
447
-    //     $dir_ref = array(
448
-    //         $this->_folder_path => array('core', 'class'),
449
-    //     );
450
-    //     EEH_Autoloader::try_autoload($dir_ref, $className);
451
-    // }
452
-    /**
453
-     * _check_user_access
454
-     * verifies user access for this admin page.  If no user access is available then let's gracefully exit with a
455
-     * WordPress die message.
456
-     *
457
-     * @return bool true if pass (or admin) wp_die if fail
458
-     */
459
-    private function _check_user_access()
460
-    {
461
-        if (
462
-            ! EE_Registry::instance()->CAP->current_user_can(
463
-                $this->_menu_map->capability,
464
-                $this->_menu_map->menu_slug
465
-            )
466
-        ) {
467
-            wp_die(__('You don\'t have access to this page.', 'event_espresso'), '', array('back_link' => true));
468
-        }
469
-        return true;
470
-    }
20
+	/**
21
+	 * @var LoaderInterface $loader
22
+	 */
23
+	protected $loader;
24
+
25
+	// identity properties (set in _set_defaults and _set_init_properties)
26
+	public $label;
27
+
28
+	/**
29
+	 * Menu map has a capability.  However, this allows admin pages to have separate capability requirements for menus
30
+	 * and accessing pages.  If capability is NOT set, then it defaults to the menu_map capability.
31
+	 *
32
+	 * @var string
33
+	 */
34
+	public $capability;
35
+
36
+
37
+	/**
38
+	 * This holds the menu map object for this admin page.
39
+	 *
40
+	 * @var EE_Admin_Page_Menu_Map
41
+	 */
42
+	protected $_menu_map;
43
+
44
+	/**
45
+	 * deprecated
46
+	 */
47
+	public $menu_label;
48
+	public $menu_slug;
49
+
50
+
51
+	// set in _set_defaults
52
+	protected $_folder_name;
53
+	protected $_folder_path;
54
+	protected $_file_name;
55
+	public $hook_file;
56
+	protected $_wp_page_slug;
57
+	protected $_routing;
58
+
59
+
60
+	/**
61
+	 * This holds the page object.
62
+	 *
63
+	 * @var EE_Admin_Page
64
+	 */
65
+	protected $_loaded_page_object;
66
+
67
+
68
+	// for caf
69
+	protected $_files_hooked;
70
+	protected $_hook_paths;
71
+
72
+	// load_page?
73
+	private $_load_page;
74
+
75
+
76
+	/**
77
+	 * @throws InvalidArgumentException
78
+	 * @throws InvalidDataTypeException
79
+	 * @throws InvalidInterfaceException
80
+	 */
81
+	public function __construct()
82
+	{
83
+		$this->loader = LoaderFactory::getLoader();
84
+		// set global defaults
85
+		$this->_set_defaults();
86
+		// set properties that are always available with objects.
87
+		$this->_set_init_properties();
88
+		// global styles/scripts across all wp admin pages
89
+		add_action('admin_enqueue_scripts', array($this, 'load_wp_global_scripts_styles'), 5);
90
+		// load initial stuff.
91
+		$this->_set_file_and_folder_name();
92
+		$this->_set_menu_map();
93
+		if (empty($this->_menu_map) || is_array($this->_menu_map)) {
94
+			EE_Error::doing_it_wrong(
95
+				get_class($this) . '::$_menu_map',
96
+				sprintf(
97
+					__(
98
+						'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core.  Please see Admin_Page_Init class examples in core for the new way of setting this property up.',
99
+						'event_espresso'
100
+					),
101
+					get_class($this)
102
+				),
103
+				'4.4.0'
104
+			);
105
+			return;
106
+		}
107
+		// set default capability
108
+		$this->_set_capability();
109
+	}
110
+
111
+
112
+	/**
113
+	 * _set_init_properties
114
+	 * Child classes use to set the following properties:
115
+	 * $label
116
+	 *
117
+	 * @abstract
118
+	 * @access protected
119
+	 * @return void
120
+	 */
121
+	abstract protected function _set_init_properties();
122
+
123
+
124
+	/**
125
+	 * _set_menu_map is a function that child classes use to set the menu_map property (which should be an instance of
126
+	 * EE_Admin_Page_Menu_Map.  Their menu can either be EE_Admin_Page_Main_Menu or EE_Admin_Page_Sub_Menu.
127
+	 *
128
+	 * @since 4.4.0
129
+	 * @ return void.
130
+	 */
131
+	protected function _set_menu_map()
132
+	{
133
+		return array();
134
+	}
135
+
136
+
137
+	/**
138
+	 * returns the menu map for this admin page
139
+	 *
140
+	 * @since 4.4.0
141
+	 * @return EE_Admin_Page_Menu_Map
142
+	 */
143
+	public function get_menu_map()
144
+	{
145
+		return $this->_menu_map;
146
+	}
147
+
148
+
149
+	/**
150
+	 * This loads scripts and styles for the EE_Admin system
151
+	 * that must be available on ALL WP admin pages (i.e. EE_menu items)
152
+	 *
153
+	 * @return void
154
+	 */
155
+	public function load_wp_global_scripts_styles()
156
+	{
157
+		wp_register_style(
158
+			'espresso_menu',
159
+			EE_ADMIN_URL . 'assets/admin-menu-styles.css',
160
+			array('dashicons'),
161
+			EVENT_ESPRESSO_VERSION
162
+		);
163
+		wp_enqueue_style('espresso_menu');
164
+	}
165
+
166
+
167
+	/**
168
+	 * this sets default properties (might be overridden in _set_init_properties);
169
+	 *
170
+	 * @access private
171
+	 * @return  void
172
+	 */
173
+	private function _set_defaults()
174
+	{
175
+		$this->_file_name = $this->_folder_name = $this->_wp_page_slug = $this->capability = null;
176
+		$this->_routing = true;
177
+		$this->_load_page = false;
178
+		$this->_files_hooked = $this->_hook_paths = array();
179
+		// menu_map
180
+		$this->_menu_map = $this->get_menu_map();
181
+	}
182
+
183
+
184
+	protected function _set_capability()
185
+	{
186
+		$capability = empty($this->capability) ? $this->_menu_map->capability : $this->capability;
187
+		$this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability);
188
+	}
189
+
190
+
191
+	/**
192
+	 * initialize_admin_page
193
+	 * This method is what executes the loading of the specific page class for the given dir_name as called by the
194
+	 * EE_Admin_Init class.
195
+	 *
196
+	 * @access  public
197
+	 * @return void
198
+	 * @throws EE_Error
199
+	 * @throws InvalidArgumentException
200
+	 * @throws InvalidDataTypeException
201
+	 * @throws InvalidInterfaceException
202
+	 * @throws ReflectionException
203
+	 * @uses    _initialize_admin_page()
204
+	 */
205
+	public function initialize_admin_page()
206
+	{
207
+		// let's check user access first
208
+		$this->_check_user_access();
209
+		if (! is_object($this->_loaded_page_object)) {
210
+			return;
211
+		}
212
+		$this->_loaded_page_object->route_admin_request();
213
+	}
214
+
215
+
216
+	/**
217
+	 * @param string $wp_page_slug
218
+	 * @throws EE_Error
219
+	 * @since $VID:$
220
+	 */
221
+	public function set_page_dependencies($wp_page_slug)
222
+	{
223
+		if (! $this->_load_page) {
224
+			return;
225
+		}
226
+		if (! is_object($this->_loaded_page_object)) {
227
+			$msg[] = __(
228
+				'We can\'t load the page because we\'re missing a valid page object that tells us what to load',
229
+				'event_espresso'
230
+			);
231
+			$msg[] = $msg[0] . "\r\n"
232
+					 . sprintf(
233
+						 __(
234
+							 'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory',
235
+							 'event_espresso'
236
+						 ),
237
+						 $this->_file_name,
238
+						 $this->_file_name,
239
+						 $this->_folder_path . $this->_file_name,
240
+						 $this->_menu_map->menu_slug
241
+					 );
242
+			throw new EE_Error(implode('||', $msg));
243
+		}
244
+		$this->_loaded_page_object->set_wp_page_slug($wp_page_slug);
245
+		$page_hook = 'load-' . $wp_page_slug;
246
+		// hook into page load hook so all page specific stuff get's loaded.
247
+		if (! empty($wp_page_slug)) {
248
+			add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies'));
249
+		}
250
+	}
251
+
252
+
253
+	/**
254
+	 * This executes the initial page loads for EE_Admin pages to take care of any ajax or other code needing to run
255
+	 * before the load-page... hook. Note, the page loads are happening around the wp_init hook.
256
+	 *
257
+	 * @return void
258
+	 * @throws EE_Error
259
+	 * @throws InvalidArgumentException
260
+	 * @throws InvalidDataTypeException
261
+	 * @throws InvalidInterfaceException
262
+	 * @throws ReflectionException
263
+	 */
264
+	public function do_initial_loads()
265
+	{
266
+		// no loading or initializing if menu map is setup incorrectly.
267
+		if (empty($this->_menu_map) || is_array($this->_menu_map)) {
268
+			return;
269
+		}
270
+		$this->_initialize_admin_page();
271
+	}
272
+
273
+
274
+	/**
275
+	 * all we're doing here is setting the $_file_name property for later use.
276
+	 *
277
+	 * @access private
278
+	 * @return void
279
+	 */
280
+	private function _set_file_and_folder_name()
281
+	{
282
+		$bt = debug_backtrace();
283
+		// for more reliable determination of folder name
284
+		// we're using this to get the actual folder name of the CALLING class (i.e. the child class that extends this).  Why?  Because $this->menu_slug may be different than the folder name (to avoid conflicts with other plugins)
285
+		$class = get_class($this);
286
+		foreach ($bt as $index => $values) {
287
+			if (isset($values['class']) && $values['class'] === $class) {
288
+				$file_index = $index - 1;
289
+				$this->_folder_name = basename(dirname($bt[ $file_index ]['file']));
290
+				if (! empty($this->_folder_name)) {
291
+					break;
292
+				}
293
+			}
294
+		}
295
+		$this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . '/';
296
+		$this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name);
297
+		$this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name));
298
+		$this->_file_name = str_replace(' ', '_', $this->_file_name);
299
+	}
300
+
301
+
302
+	/**
303
+	 * This automatically checks if we have a hook class in the loaded child directory.  If we DO then we will register
304
+	 * it with the appropriate pages.  That way all we have to do is make sure the file is named correctly and
305
+	 * "dropped" in. Example: if we wanted to set this up for Messages hooking into Events then we would do:
306
+	 * events_Messages_Hooks.class.php
307
+	 *
308
+	 * @param bool $extend This indicates whether we're checking the extend directory for any register_hooks
309
+	 *                     files/classes
310
+	 * @return array
311
+	 */
312
+	public function register_hooks($extend = false)
313
+	{
314
+
315
+		// get a list of files in the directory that have the "Hook" in their name an
316
+		// if this is an extended check (i.e. caf is active) then we will scan the caffeinated/extend directory first and any hook files that are found will be have their reference added to the $_files_hook array property.  Then, we make sure that when we loop through the core decaf directories to find hook files that we skip over any hooks files that have already been set by caf.
317
+		if ($extend) {
318
+			$hook_files_glob_path = apply_filters(
319
+				'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path__extend',
320
+				EE_CORE_CAF_ADMIN_EXTEND
321
+				. $this->_folder_name
322
+				. '/*'
323
+				. $this->_file_name
324
+				. '_Hooks_Extend.class.php'
325
+			);
326
+			$this->_hook_paths = $this->_register_hook_files($hook_files_glob_path, $extend);
327
+		}
328
+		// loop through decaf folders
329
+		$hook_files_glob_path = apply_filters(
330
+			'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path',
331
+			$this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php'
332
+		);
333
+		$this->_hook_paths = array_merge(
334
+			$this->_register_hook_files($hook_files_glob_path),
335
+			$this->_hook_paths
336
+		);  // making sure any extended hook paths are later in the array than the core hook paths!
337
+		return $this->_hook_paths;
338
+	}
339
+
340
+
341
+	protected function _register_hook_files($hook_files_glob_path, $extend = false)
342
+	{
343
+		$hook_paths = array();
344
+		if ($hook_files = glob($hook_files_glob_path)) {
345
+			if (empty($hook_files)) {
346
+				return array();
347
+			}
348
+			foreach ($hook_files as $file) {
349
+				// lets get the linked admin.
350
+				$hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . '/', '', $file)
351
+					: str_replace($this->_folder_path, '', $file);
352
+				$replace = $extend
353
+					? '_' . $this->_file_name . '_Hooks_Extend.class.php'
354
+					: '_'
355
+					  . $this->_file_name
356
+					  . '_Hooks.class.php';
357
+				$rel_admin = str_replace($replace, '', $hook_file);
358
+				$rel_admin = strtolower($rel_admin);
359
+				$hook_paths[] = $file;
360
+				// make sure we haven't already got a hook setup for this page path
361
+				if (in_array($rel_admin, $this->_files_hooked, true)) {
362
+					continue;
363
+				}
364
+				$this->hook_file = $hook_file;
365
+				$rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin;
366
+				add_filter($rel_admin_hook, array($this, 'load_admin_hook'));
367
+				$this->_files_hooked[] = $rel_admin;
368
+			}
369
+		}
370
+		return $hook_paths;
371
+	}
372
+
373
+
374
+	public function load_admin_hook($registered_pages)
375
+	{
376
+		$this->hook_file;
377
+		$hook_file = (array) $this->hook_file;
378
+		return array_merge($hook_file, $registered_pages);
379
+	}
380
+
381
+
382
+	/**
383
+	 * _initialize_admin_page
384
+	 *
385
+	 * @throws EE_Error
386
+	 * @throws InvalidArgumentException
387
+	 * @throws InvalidDataTypeException
388
+	 * @throws InvalidInterfaceException
389
+	 * @throws ReflectionException
390
+	 * @see  initialize_admin_page() for info
391
+	 */
392
+	protected function _initialize_admin_page()
393
+	{
394
+		// just check we're on right page and if not get out
395
+		if ((! isset($_REQUEST['page']) || $_REQUEST['page'] !== $this->_menu_map->menu_slug) && $this->_routing) {
396
+			return;
397
+		}
398
+		$this->_load_page = true;
399
+
400
+		// we don't need to do a page_request check here because it's only called via WP menu system.
401
+		$admin_page = $this->_file_name . '_Admin_Page';
402
+		$hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page;
403
+		$admin_page = apply_filters(
404
+			"FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}",
405
+			$admin_page
406
+		);
407
+		// define requested admin page class name then load the file and instantiate
408
+		$path_to_file = str_replace(array('\\', '/'), '/', $this->_folder_path . $admin_page . '.core.php');
409
+		$path_to_file = apply_filters(
410
+			"FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}",
411
+			$path_to_file
412
+		);
413
+		// so if the file would be in EE_ADMIN/attendees/Attendee_Admin_Page.core.php,
414
+		// the filter would be FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__attendees_Attendee_Admin_Page
415
+		if (is_readable($path_to_file)) {
416
+			// This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place
417
+			do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization');
418
+			do_action(
419
+				'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug
420
+			);
421
+			require_once($path_to_file);
422
+			$this->_loaded_page_object = $this->loader->getShared($admin_page, [$this->_routing]);
423
+			$this->_loaded_page_object->initializePage();
424
+		}
425
+		do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization');
426
+		do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug);
427
+	}
428
+
429
+
430
+	public function get_admin_page_name()
431
+	{
432
+		return $this->_file_name . '_Admin_Page';
433
+	}
434
+
435
+
436
+	/**
437
+	 * @return mixed
438
+	 */
439
+	public function loaded_page_object()
440
+	{
441
+		return $this->_loaded_page_object;
442
+	}
443
+
444
+
445
+	// public function set_autoloaders($className)
446
+	// {
447
+	//     $dir_ref = array(
448
+	//         $this->_folder_path => array('core', 'class'),
449
+	//     );
450
+	//     EEH_Autoloader::try_autoload($dir_ref, $className);
451
+	// }
452
+	/**
453
+	 * _check_user_access
454
+	 * verifies user access for this admin page.  If no user access is available then let's gracefully exit with a
455
+	 * WordPress die message.
456
+	 *
457
+	 * @return bool true if pass (or admin) wp_die if fail
458
+	 */
459
+	private function _check_user_access()
460
+	{
461
+		if (
462
+			! EE_Registry::instance()->CAP->current_user_can(
463
+				$this->_menu_map->capability,
464
+				$this->_menu_map->menu_slug
465
+			)
466
+		) {
467
+			wp_die(__('You don\'t have access to this page.', 'event_espresso'), '', array('back_link' => true));
468
+		}
469
+		return true;
470
+	}
471 471
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
         $this->_set_menu_map();
93 93
         if (empty($this->_menu_map) || is_array($this->_menu_map)) {
94 94
             EE_Error::doing_it_wrong(
95
-                get_class($this) . '::$_menu_map',
95
+                get_class($this).'::$_menu_map',
96 96
                 sprintf(
97 97
                     __(
98 98
                         'The EE4 addon with the class %s is setting up the _menu_map property incorrectly for this version of EE core.  Please see Admin_Page_Init class examples in core for the new way of setting this property up.',
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
     {
157 157
         wp_register_style(
158 158
             'espresso_menu',
159
-            EE_ADMIN_URL . 'assets/admin-menu-styles.css',
159
+            EE_ADMIN_URL.'assets/admin-menu-styles.css',
160 160
             array('dashicons'),
161 161
             EVENT_ESPRESSO_VERSION
162 162
         );
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
     protected function _set_capability()
185 185
     {
186 186
         $capability = empty($this->capability) ? $this->_menu_map->capability : $this->capability;
187
-        $this->capability = apply_filters('FHEE_' . $this->_menu_map->menu_slug . '_capability', $capability);
187
+        $this->capability = apply_filters('FHEE_'.$this->_menu_map->menu_slug.'_capability', $capability);
188 188
     }
189 189
 
190 190
 
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
     {
207 207
         // let's check user access first
208 208
         $this->_check_user_access();
209
-        if (! is_object($this->_loaded_page_object)) {
209
+        if ( ! is_object($this->_loaded_page_object)) {
210 210
             return;
211 211
         }
212 212
         $this->_loaded_page_object->route_admin_request();
@@ -220,15 +220,15 @@  discard block
 block discarded – undo
220 220
      */
221 221
     public function set_page_dependencies($wp_page_slug)
222 222
     {
223
-        if (! $this->_load_page) {
223
+        if ( ! $this->_load_page) {
224 224
             return;
225 225
         }
226
-        if (! is_object($this->_loaded_page_object)) {
226
+        if ( ! is_object($this->_loaded_page_object)) {
227 227
             $msg[] = __(
228 228
                 'We can\'t load the page because we\'re missing a valid page object that tells us what to load',
229 229
                 'event_espresso'
230 230
             );
231
-            $msg[] = $msg[0] . "\r\n"
231
+            $msg[] = $msg[0]."\r\n"
232 232
                      . sprintf(
233 233
                          __(
234 234
                              'The custom slug you have set for this page is %s. This means we\'re looking for the class %s_Admin_Page (found in %s_Admin_Page.core.php) within your %s directory',
@@ -236,15 +236,15 @@  discard block
 block discarded – undo
236 236
                          ),
237 237
                          $this->_file_name,
238 238
                          $this->_file_name,
239
-                         $this->_folder_path . $this->_file_name,
239
+                         $this->_folder_path.$this->_file_name,
240 240
                          $this->_menu_map->menu_slug
241 241
                      );
242 242
             throw new EE_Error(implode('||', $msg));
243 243
         }
244 244
         $this->_loaded_page_object->set_wp_page_slug($wp_page_slug);
245
-        $page_hook = 'load-' . $wp_page_slug;
245
+        $page_hook = 'load-'.$wp_page_slug;
246 246
         // hook into page load hook so all page specific stuff get's loaded.
247
-        if (! empty($wp_page_slug)) {
247
+        if ( ! empty($wp_page_slug)) {
248 248
             add_action($page_hook, array($this->_loaded_page_object, 'load_page_dependencies'));
249 249
         }
250 250
     }
@@ -286,13 +286,13 @@  discard block
 block discarded – undo
286 286
         foreach ($bt as $index => $values) {
287 287
             if (isset($values['class']) && $values['class'] === $class) {
288 288
                 $file_index = $index - 1;
289
-                $this->_folder_name = basename(dirname($bt[ $file_index ]['file']));
290
-                if (! empty($this->_folder_name)) {
289
+                $this->_folder_name = basename(dirname($bt[$file_index]['file']));
290
+                if ( ! empty($this->_folder_name)) {
291 291
                     break;
292 292
                 }
293 293
             }
294 294
         }
295
-        $this->_folder_path = EE_ADMIN_PAGES . $this->_folder_name . '/';
295
+        $this->_folder_path = EE_ADMIN_PAGES.$this->_folder_name.'/';
296 296
         $this->_file_name = preg_replace('/^ee/', 'EE', $this->_folder_name);
297 297
         $this->_file_name = ucwords(str_replace('_', ' ', $this->_file_name));
298 298
         $this->_file_name = str_replace(' ', '_', $this->_file_name);
@@ -328,12 +328,12 @@  discard block
 block discarded – undo
328 328
         // loop through decaf folders
329 329
         $hook_files_glob_path = apply_filters(
330 330
             'FHEE__EE_Admin_Page_Init__register_hooks__hook_files_glob_path',
331
-            $this->_folder_path . '*' . $this->_file_name . '_Hooks.class.php'
331
+            $this->_folder_path.'*'.$this->_file_name.'_Hooks.class.php'
332 332
         );
333 333
         $this->_hook_paths = array_merge(
334 334
             $this->_register_hook_files($hook_files_glob_path),
335 335
             $this->_hook_paths
336
-        );  // making sure any extended hook paths are later in the array than the core hook paths!
336
+        ); // making sure any extended hook paths are later in the array than the core hook paths!
337 337
         return $this->_hook_paths;
338 338
     }
339 339
 
@@ -347,10 +347,10 @@  discard block
 block discarded – undo
347 347
             }
348 348
             foreach ($hook_files as $file) {
349 349
                 // lets get the linked admin.
350
-                $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND . $this->_folder_name . '/', '', $file)
350
+                $hook_file = $extend ? str_replace(EE_CORE_CAF_ADMIN_EXTEND.$this->_folder_name.'/', '', $file)
351 351
                     : str_replace($this->_folder_path, '', $file);
352 352
                 $replace = $extend
353
-                    ? '_' . $this->_file_name . '_Hooks_Extend.class.php'
353
+                    ? '_'.$this->_file_name.'_Hooks_Extend.class.php'
354 354
                     : '_'
355 355
                       . $this->_file_name
356 356
                       . '_Hooks.class.php';
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
                     continue;
363 363
                 }
364 364
                 $this->hook_file = $hook_file;
365
-                $rel_admin_hook = 'FHEE_do_other_page_hooks_' . $rel_admin;
365
+                $rel_admin_hook = 'FHEE_do_other_page_hooks_'.$rel_admin;
366 366
                 add_filter($rel_admin_hook, array($this, 'load_admin_hook'));
367 367
                 $this->_files_hooked[] = $rel_admin;
368 368
             }
@@ -392,20 +392,20 @@  discard block
 block discarded – undo
392 392
     protected function _initialize_admin_page()
393 393
     {
394 394
         // just check we're on right page and if not get out
395
-        if ((! isset($_REQUEST['page']) || $_REQUEST['page'] !== $this->_menu_map->menu_slug) && $this->_routing) {
395
+        if (( ! isset($_REQUEST['page']) || $_REQUEST['page'] !== $this->_menu_map->menu_slug) && $this->_routing) {
396 396
             return;
397 397
         }
398 398
         $this->_load_page = true;
399 399
 
400 400
         // we don't need to do a page_request check here because it's only called via WP menu system.
401
-        $admin_page = $this->_file_name . '_Admin_Page';
402
-        $hook_suffix = $this->_menu_map->menu_slug . '_' . $admin_page;
401
+        $admin_page = $this->_file_name.'_Admin_Page';
402
+        $hook_suffix = $this->_menu_map->menu_slug.'_'.$admin_page;
403 403
         $admin_page = apply_filters(
404 404
             "FHEE__EE_Admin_Page_Init___initialize_admin_page__admin_page__{$hook_suffix}",
405 405
             $admin_page
406 406
         );
407 407
         // define requested admin page class name then load the file and instantiate
408
-        $path_to_file = str_replace(array('\\', '/'), '/', $this->_folder_path . $admin_page . '.core.php');
408
+        $path_to_file = str_replace(array('\\', '/'), '/', $this->_folder_path.$admin_page.'.core.php');
409 409
         $path_to_file = apply_filters(
410 410
             "FHEE__EE_Admin_Page_Init___initialize_admin_page__path_to_file__{$hook_suffix}",
411 411
             $path_to_file
@@ -416,20 +416,20 @@  discard block
 block discarded – undo
416 416
             // This is a place where EE plugins can hook in to make sure their own files are required in the appropriate place
417 417
             do_action('AHEE__EE_Admin_Page___initialize_admin_page__before_initialization');
418 418
             do_action(
419
-                'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_' . $this->_menu_map->menu_slug
419
+                'AHEE__EE_Admin_Page___initialize_admin_page__before_initialization_'.$this->_menu_map->menu_slug
420 420
             );
421 421
             require_once($path_to_file);
422 422
             $this->_loaded_page_object = $this->loader->getShared($admin_page, [$this->_routing]);
423 423
             $this->_loaded_page_object->initializePage();
424 424
         }
425 425
         do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization');
426
-        do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_' . $this->_menu_map->menu_slug);
426
+        do_action('AHEE__EE_Admin_Page___initialize_admin_page__after_initialization_'.$this->_menu_map->menu_slug);
427 427
     }
428 428
 
429 429
 
430 430
     public function get_admin_page_name()
431 431
     {
432
-        return $this->_file_name . '_Admin_Page';
432
+        return $this->_file_name.'_Admin_Page';
433 433
     }
434 434
 
435 435
 
Please login to merge, or discard this patch.
core/helpers/EEH_Debug_Tools.helper.php 2 patches
Indentation   +700 added lines, -700 removed lines patch added patch discarded remove patch
@@ -13,691 +13,691 @@  discard block
 block discarded – undo
13 13
 class EEH_Debug_Tools
14 14
 {
15 15
 
16
-    /**
17
-     *    instance of the EEH_Autoloader object
18
-     *
19
-     * @var    $_instance
20
-     * @access    private
21
-     */
22
-    private static $_instance;
23
-
24
-    /**
25
-     * @var array
26
-     */
27
-    protected $_memory_usage_points = array();
28
-
29
-
30
-
31
-    /**
32
-     * @singleton method used to instantiate class object
33
-     * @access    public
34
-     * @return EEH_Debug_Tools
35
-     */
36
-    public static function instance()
37
-    {
38
-        // check if class object is instantiated, and instantiated properly
39
-        if (! self::$_instance instanceof EEH_Debug_Tools) {
40
-            self::$_instance = new self();
41
-        }
42
-        return self::$_instance;
43
-    }
44
-
45
-
46
-
47
-    /**
48
-     * private class constructor
49
-     */
50
-    private function __construct()
51
-    {
52
-        // load Kint PHP debugging library
53
-        if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php')) {
54
-            // despite EE4 having a check for an existing copy of the Kint debugging class,
55
-            // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
56
-            // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
57
-            // so we've moved it to our test folder so that it is not included with production releases
58
-            // plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
59
-            require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php');
60
-        }
61
-        // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
62
-        // add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
63
-        // }
64
-        $plugin = basename(EE_PLUGIN_DIR_PATH);
65
-        add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
66
-        add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
67
-        add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name'));
68
-    }
69
-
70
-
71
-
72
-    /**
73
-     *    show_db_name
74
-     *
75
-     * @return void
76
-     */
77
-    public static function show_db_name()
78
-    {
79
-        if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
80
-            echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
81
-                 . DB_NAME
82
-                 . '</p>';
83
-        }
84
-        if (EE_DEBUG) {
85
-            Benchmark::displayResults();
86
-        }
87
-    }
88
-
89
-
90
-
91
-    /**
92
-     *    dump EE_Session object at bottom of page after everything else has happened
93
-     *
94
-     * @return void
95
-     */
96
-    public function espresso_session_footer_dump()
97
-    {
98
-        if (
99
-            (defined('WP_DEBUG') && WP_DEBUG)
100
-            && ! defined('DOING_AJAX')
101
-            && class_exists('Kint')
102
-            && function_exists('wp_get_current_user')
103
-            && current_user_can('update_core')
104
-            && class_exists('EE_Registry')
105
-        ) {
106
-            Kint::dump(EE_Registry::instance()->SSN->id());
107
-            Kint::dump(EE_Registry::instance()->SSN);
108
-            //          Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() );
109
-            $this->espresso_list_hooked_functions();
110
-            Benchmark::displayResults();
111
-        }
112
-    }
113
-
114
-
115
-
116
-    /**
117
-     *    List All Hooked Functions
118
-     *    to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL
119
-     *    http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/
120
-     *
121
-     * @param string $tag
122
-     * @return void
123
-     */
124
-    public function espresso_list_hooked_functions($tag = '')
125
-    {
126
-        global $wp_filter;
127
-        echo '<br/><br/><br/><h3>Hooked Functions</h3>';
128
-        if ($tag) {
129
-            $hook[ $tag ] = $wp_filter[ $tag ];
130
-            if (! is_array($hook[ $tag ])) {
131
-                trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
132
-                return;
133
-            }
134
-            echo '<h5>For Tag: ' . $tag . '</h5>';
135
-        } else {
136
-            $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
137
-            ksort($hook);
138
-        }
139
-        foreach ($hook as $tag_name => $priorities) {
140
-            echo "<br />&gt;&gt;&gt;&gt;&gt;\t<strong>$tag_name</strong><br />";
141
-            ksort($priorities);
142
-            foreach ($priorities as $priority => $function) {
143
-                echo $priority;
144
-                foreach ($function as $name => $properties) {
145
-                    echo "\t$name<br />";
146
-                }
147
-            }
148
-        }
149
-    }
150
-
151
-
152
-
153
-    /**
154
-     *    registered_filter_callbacks
155
-     *
156
-     * @param string $hook_name
157
-     * @return array
158
-     */
159
-    public static function registered_filter_callbacks($hook_name = '')
160
-    {
161
-        $filters = array();
162
-        global $wp_filter;
163
-        if (isset($wp_filter[ $hook_name ])) {
164
-            $filters[ $hook_name ] = array();
165
-            foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) {
166
-                $filters[ $hook_name ][ $priority ] = array();
167
-                foreach ($callbacks as $callback) {
168
-                    $filters[ $hook_name ][ $priority ][] = $callback['function'];
169
-                }
170
-            }
171
-        }
172
-        return $filters;
173
-    }
174
-
175
-
176
-
177
-    /**
178
-     *    captures plugin activation errors for debugging
179
-     *
180
-     * @return void
181
-     * @throws EE_Error
182
-     */
183
-    public static function ee_plugin_activation_errors()
184
-    {
185
-        if (WP_DEBUG) {
186
-            $activation_errors = ob_get_contents();
187
-            if (empty($activation_errors)) {
188
-                return;
189
-            }
190
-            $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
191
-            espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
192
-            if (class_exists('EEH_File')) {
193
-                try {
194
-                    EEH_File::ensure_file_exists_and_is_writable(
195
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html'
196
-                    );
197
-                    EEH_File::write_to_file(
198
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html',
199
-                        $activation_errors
200
-                    );
201
-                } catch (EE_Error $e) {
202
-                    EE_Error::add_error(
203
-                        sprintf(
204
-                            __(
205
-                                'The Event Espresso activation errors file could not be setup because: %s',
206
-                                'event_espresso'
207
-                            ),
208
-                            $e->getMessage()
209
-                        ),
210
-                        __FILE__,
211
-                        __FUNCTION__,
212
-                        __LINE__
213
-                    );
214
-                }
215
-            } else {
216
-                // old school attempt
217
-                file_put_contents(
218
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html',
219
-                    $activation_errors
220
-                );
221
-            }
222
-            $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
223
-            update_option('ee_plugin_activation_errors', $activation_errors);
224
-        }
225
-    }
226
-
227
-
228
-
229
-    /**
230
-     * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc.
231
-     * Very useful for providing helpful messages to developers when the method of doing something has been deprecated,
232
-     * or we want to make sure they use something the right way.
233
-     *
234
-     * @access public
235
-     * @param string $function      The function that was called
236
-     * @param string $message       A message explaining what has been done incorrectly
237
-     * @param string $version       The version of Event Espresso where the error was added
238
-     * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
239
-     *                              for a deprecated function. This allows deprecation to occur during one version,
240
-     *                              but not have any notices appear until a later version. This allows developers
241
-     *                              extra time to update their code before notices appear.
242
-     * @param int    $error_type
243
-     * @uses   trigger_error()
244
-     */
245
-    public function doing_it_wrong(
246
-        $function,
247
-        $message,
248
-        $version,
249
-        $applies_when = '',
250
-        $error_type = null
251
-    ) {
252
-        $applies_when = ! empty($applies_when) ? $applies_when : espresso_version();
253
-        $error_type = $error_type !== null ? $error_type : E_USER_NOTICE;
254
-        // because we swapped the parameter order around for the last two params,
255
-        // let's verify that some third party isn't still passing an error type value for the third param
256
-        if (is_int($applies_when)) {
257
-            $error_type = $applies_when;
258
-            $applies_when = espresso_version();
259
-        }
260
-        // if not displaying notices yet, then just leave
261
-        if (version_compare(espresso_version(), $applies_when, '<')) {
262
-            return;
263
-        }
264
-        do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version);
265
-        $version = $version === null
266
-            ? ''
267
-            : sprintf(
268
-                __('(This message was added in version %s of Event Espresso)', 'event_espresso'),
269
-                $version
270
-            );
271
-        $error_message = sprintf(
272
-            esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'),
273
-            $function,
274
-            '<strong>',
275
-            '</strong>',
276
-            $message,
277
-            $version
278
-        );
279
-        // don't trigger error if doing ajax,
280
-        // instead we'll add a transient EE_Error notice that in theory should show on the next request.
281
-        if (defined('DOING_AJAX') && DOING_AJAX) {
282
-            $error_message .= ' ' . esc_html__(
283
-                'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
284
-                'event_espresso'
285
-            );
286
-            $error_message .= '<ul><li>';
287
-            $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params());
288
-            $error_message .= '</ul>';
289
-            EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42');
290
-            // now we set this on the transient so it shows up on the next request.
291
-            EE_Error::get_notices(false, true);
292
-        } else {
293
-            trigger_error($error_message, $error_type);
294
-        }
295
-    }
296
-
297
-
298
-
299
-
300
-    /**
301
-     * Logger helpers
302
-     */
303
-    /**
304
-     * debug
305
-     *
306
-     * @param string $class
307
-     * @param string $func
308
-     * @param string $line
309
-     * @param array  $info
310
-     * @param bool   $display_request
311
-     * @param string $debug_index
312
-     * @param string $debug_key
313
-     * @throws EE_Error
314
-     * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
315
-     */
316
-    public static function log(
317
-        $class = '',
318
-        $func = '',
319
-        $line = '',
320
-        $info = array(),
321
-        $display_request = false,
322
-        $debug_index = '',
323
-        $debug_key = 'EE_DEBUG_SPCO'
324
-    ) {
325
-        if (WP_DEBUG) {
326
-            $debug_key = $debug_key . '_' . EE_Session::instance()->id();
327
-            $debug_data = get_option($debug_key, array());
328
-            $default_data = array(
329
-                $class => $func . '() : ' . $line,
330
-                'REQ'  => $display_request ? $_REQUEST : '',
331
-            );
332
-            // don't serialize objects
333
-            $info = self::strip_objects($info);
334
-            $index = ! empty($debug_index) ? $debug_index : 0;
335
-            if (! isset($debug_data[ $index ])) {
336
-                $debug_data[ $index ] = array();
337
-            }
338
-            $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info);
339
-            update_option($debug_key, $debug_data);
340
-        }
341
-    }
342
-
343
-
344
-
345
-    /**
346
-     * strip_objects
347
-     *
348
-     * @param array $info
349
-     * @return array
350
-     */
351
-    public static function strip_objects($info = array())
352
-    {
353
-        foreach ($info as $key => $value) {
354
-            if (is_array($value)) {
355
-                $info[ $key ] = self::strip_objects($value);
356
-            } elseif (is_object($value)) {
357
-                $object_class = get_class($value);
358
-                $info[ $object_class ] = array();
359
-                $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
360
-                if (method_exists($value, 'ID')) {
361
-                    $info[ $object_class ]['ID'] = $value->ID();
362
-                }
363
-                if (method_exists($value, 'status')) {
364
-                    $info[ $object_class ]['status'] = $value->status();
365
-                } elseif (method_exists($value, 'status_ID')) {
366
-                    $info[ $object_class ]['status'] = $value->status_ID();
367
-                }
368
-                unset($info[ $key ]);
369
-            }
370
-        }
371
-        return (array) $info;
372
-    }
373
-
374
-
375
-
376
-    /**
377
-     * @param mixed      $var
378
-     * @param string     $var_name
379
-     * @param string     $file
380
-     * @param int|string $line
381
-     * @param int|string $heading_tag
382
-     * @param bool       $die
383
-     * @param string     $margin
384
-     */
385
-    public static function printv(
386
-        $var,
387
-        $var_name = '',
388
-        $file = '',
389
-        $line = '',
390
-        $heading_tag = 5,
391
-        $die = false,
392
-        $margin = ''
393
-    ) {
394
-        $var_name = ! $var_name ? 'string' : $var_name;
395
-        $var_name = ucwords(str_replace('$', '', $var_name));
396
-        $is_method = method_exists($var_name, $var);
397
-        $var_name = ucwords(str_replace('_', ' ', $var_name));
398
-        $heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
399
-        // $result = EEH_Debug_Tools::headingSpacer($heading_tag);
400
-        $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
401
-        $result .= $is_method
402
-            ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
403
-            : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
404
-        $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
405
-        $result .= EEH_Debug_Tools::headingX($heading_tag);
406
-        if ($die) {
407
-            die($result);
408
-        }
409
-        echo $result;
410
-    }
411
-
412
-
413
-    protected static function headingTag($heading_tag)
414
-    {
415
-        $heading_tag = absint($heading_tag);
416
-        return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5';
417
-    }
418
-
419
-
420
-    protected static function headingSpacer($heading_tag)
421
-    {
422
-        return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2')
423
-            ? "\n"
424
-            : '';
425
-    }
426
-
427
-
428
-    protected static function plainOutput()
429
-    {
430
-        return defined('EE_TESTS_DIR')
431
-               || (defined('DOING_AJAX') && DOING_AJAX && ! isset($_REQUEST['pretty_output']))
432
-               || (
433
-                   isset($_SERVER['REQUEST_URI'])
434
-                   && strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'wp-json') !== false
435
-               );
436
-    }
437
-
438
-
439
-    /**
440
-     * @param string $var_name
441
-     * @param string $heading_tag
442
-     * @param string $margin
443
-     * @param int    $line
444
-     * @return string
445
-     */
446
-    protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0)
447
-    {
448
-        if (EEH_Debug_Tools::plainOutput()) {
449
-            switch ($heading_tag) {
450
-                case 'h1':
451
-                    $line_breaks = EEH_Debug_Tools::lineBreak(3);
452
-                    break;
453
-                case 'h2':
454
-                    $line_breaks = EEH_Debug_Tools::lineBreak(2);
455
-                    break;
456
-                default:
457
-                    $line_breaks = EEH_Debug_Tools::lineBreak();
458
-                    break;
459
-            }
460
-            return "{$line_breaks}{$line}) {$var_name}";
461
-        }
462
-        $margin = "25px 0 0 {$margin}";
463
-        return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
464
-    }
465
-
466
-
467
-
468
-    /**
469
-     * @param string $heading_tag
470
-     * @return string
471
-     */
472
-    protected static function headingX($heading_tag = 'h5')
473
-    {
474
-        if (EEH_Debug_Tools::plainOutput()) {
475
-            return '';
476
-        }
477
-        return '</' . $heading_tag . '>';
478
-    }
479
-
480
-
481
-
482
-    /**
483
-     * @param string $content
484
-     * @return string
485
-     */
486
-    protected static function grey_span($content = '')
487
-    {
488
-        if (EEH_Debug_Tools::plainOutput()) {
489
-            return $content;
490
-        }
491
-        return '<span style="color:#999">' . $content . '</span>';
492
-    }
493
-
494
-
495
-
496
-    /**
497
-     * @param string $file
498
-     * @param int    $line
499
-     * @return string
500
-     */
501
-    protected static function file_and_line($file, $line, $heading_tag)
502
-    {
503
-        if ($file === '' || $line === '') {
504
-            return '';
505
-        }
506
-        $file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file);
507
-        if (EEH_Debug_Tools::plainOutput()) {
508
-            if ($heading_tag === 'h1' || $heading_tag === 'h2') {
509
-                return " ({$file})";
510
-            }
511
-            return '';
512
-        }
513
-        return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
514
-               . $file
515
-               . '<br />line no: '
516
-               . $line
517
-               . '</span>';
518
-    }
519
-
520
-
521
-
522
-    /**
523
-     * @param string $content
524
-     * @return string
525
-     */
526
-    protected static function orange_span($content = '')
527
-    {
528
-        if (EEH_Debug_Tools::plainOutput()) {
529
-            return $content;
530
-        }
531
-        return '<span style="color:#E76700">' . $content . '</span>';
532
-    }
533
-
534
-
535
-
536
-    /**
537
-     * @param mixed $var
538
-     * @return string
539
-     */
540
-    protected static function pre_span($var)
541
-    {
542
-        ob_start();
543
-        var_dump($var);
544
-        $var = ob_get_clean();
545
-        if (EEH_Debug_Tools::plainOutput()) {
546
-            return $var;
547
-        }
548
-        return '<pre style="color: #9C3; display: inline-block; padding:.4em .6em; background: #334">' . $var . '</pre>';
549
-    }
550
-
551
-
552
-
553
-    /**
554
-     * @param mixed      $var
555
-     * @param string     $var_name
556
-     * @param string     $file
557
-     * @param int|string $line
558
-     * @param int|string $heading_tag
559
-     * @param bool       $die
560
-     */
561
-    public static function printr(
562
-        $var,
563
-        $var_name = '',
564
-        $file = '',
565
-        $line = '',
566
-        $heading_tag = 5,
567
-        $die = false
568
-    ) {
569
-        // return;
570
-        $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file);
571
-        if (empty($var) && empty($var_name)) {
572
-            $var = $file;
573
-            $var_name = "line $line";
574
-            $file = '';
575
-            $line = '';
576
-        }
577
-        $margin = is_admin() ? ' 180px' : '0';
578
-        // $print_r = false;
579
-        if (is_string($var)) {
580
-            EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin);
581
-            return;
582
-        }
583
-        if (is_object($var)) {
584
-            $var_name = ! $var_name ? 'object' : $var_name;
585
-            // $print_r = true;
586
-        } elseif (is_array($var)) {
587
-            $var_name = ! $var_name ? 'array' : $var_name;
588
-            // $print_r = true;
589
-        } elseif (is_numeric($var)) {
590
-            $var_name = ! $var_name ? 'numeric' : $var_name;
591
-        } elseif ($var === null) {
592
-            $var_name = ! $var_name ? 'null' : $var_name;
593
-        }
594
-        $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
595
-        $heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
596
-        // $result = EEH_Debug_Tools::headingSpacer($heading_tag);
597
-        $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
598
-        $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
599
-            EEH_Debug_Tools::pre_span($var)
600
-        );
601
-        $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
602
-        $result .= EEH_Debug_Tools::headingX($heading_tag);
603
-        if ($die) {
604
-            die($result);
605
-        }
606
-        echo $result;
607
-    }
608
-
609
-
610
-    private static function lineBreak($lines = 1): string
611
-    {
612
-        $linebreak = defined('DOING_AJAX') && DOING_AJAX ? '<br />' : PHP_EOL;
613
-        return str_repeat($linebreak, $lines);
614
-    }
615
-
616
-
617
-
618
-    /******************** deprecated ********************/
619
-
620
-
621
-
622
-    /**
623
-     * @deprecated 4.9.39.rc.034
624
-     */
625
-    public function reset_times()
626
-    {
627
-        Benchmark::resetTimes();
628
-    }
629
-
630
-
631
-
632
-    /**
633
-     * @deprecated 4.9.39.rc.034
634
-     * @param null $timer_name
635
-     */
636
-    public function start_timer($timer_name = null)
637
-    {
638
-        Benchmark::startTimer($timer_name);
639
-    }
640
-
641
-
642
-
643
-    /**
644
-     * @deprecated 4.9.39.rc.034
645
-     * @param string $timer_name
646
-     */
647
-    public function stop_timer($timer_name = '')
648
-    {
649
-        Benchmark::stopTimer($timer_name);
650
-    }
651
-
652
-
653
-
654
-    /**
655
-     * @deprecated 4.9.39.rc.034
656
-     * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
657
-     * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
658
-     * @return void
659
-     */
660
-    public function measure_memory($label, $output_now = false)
661
-    {
662
-        Benchmark::measureMemory($label, $output_now);
663
-    }
664
-
665
-
666
-
667
-    /**
668
-     * @deprecated 4.9.39.rc.034
669
-     * @param int $size
670
-     * @return string
671
-     */
672
-    public function convert($size)
673
-    {
674
-        return Benchmark::convert($size);
675
-    }
676
-
677
-
678
-
679
-    /**
680
-     * @deprecated 4.9.39.rc.034
681
-     * @param bool $output_now
682
-     * @return string
683
-     */
684
-    public function show_times($output_now = true)
685
-    {
686
-        return Benchmark::displayResults($output_now);
687
-    }
688
-
689
-
690
-
691
-    /**
692
-     * @deprecated 4.9.39.rc.034
693
-     * @param string $timer_name
694
-     * @param float  $total_time
695
-     * @return string
696
-     */
697
-    public function format_time($timer_name, $total_time)
698
-    {
699
-        return Benchmark::formatTime($timer_name, $total_time);
700
-    }
16
+	/**
17
+	 *    instance of the EEH_Autoloader object
18
+	 *
19
+	 * @var    $_instance
20
+	 * @access    private
21
+	 */
22
+	private static $_instance;
23
+
24
+	/**
25
+	 * @var array
26
+	 */
27
+	protected $_memory_usage_points = array();
28
+
29
+
30
+
31
+	/**
32
+	 * @singleton method used to instantiate class object
33
+	 * @access    public
34
+	 * @return EEH_Debug_Tools
35
+	 */
36
+	public static function instance()
37
+	{
38
+		// check if class object is instantiated, and instantiated properly
39
+		if (! self::$_instance instanceof EEH_Debug_Tools) {
40
+			self::$_instance = new self();
41
+		}
42
+		return self::$_instance;
43
+	}
44
+
45
+
46
+
47
+	/**
48
+	 * private class constructor
49
+	 */
50
+	private function __construct()
51
+	{
52
+		// load Kint PHP debugging library
53
+		if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php')) {
54
+			// despite EE4 having a check for an existing copy of the Kint debugging class,
55
+			// if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
56
+			// then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
57
+			// so we've moved it to our test folder so that it is not included with production releases
58
+			// plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
59
+			require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php');
60
+		}
61
+		// if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
62
+		// add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
63
+		// }
64
+		$plugin = basename(EE_PLUGIN_DIR_PATH);
65
+		add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
66
+		add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors'));
67
+		add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name'));
68
+	}
69
+
70
+
71
+
72
+	/**
73
+	 *    show_db_name
74
+	 *
75
+	 * @return void
76
+	 */
77
+	public static function show_db_name()
78
+	{
79
+		if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
80
+			echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
81
+				 . DB_NAME
82
+				 . '</p>';
83
+		}
84
+		if (EE_DEBUG) {
85
+			Benchmark::displayResults();
86
+		}
87
+	}
88
+
89
+
90
+
91
+	/**
92
+	 *    dump EE_Session object at bottom of page after everything else has happened
93
+	 *
94
+	 * @return void
95
+	 */
96
+	public function espresso_session_footer_dump()
97
+	{
98
+		if (
99
+			(defined('WP_DEBUG') && WP_DEBUG)
100
+			&& ! defined('DOING_AJAX')
101
+			&& class_exists('Kint')
102
+			&& function_exists('wp_get_current_user')
103
+			&& current_user_can('update_core')
104
+			&& class_exists('EE_Registry')
105
+		) {
106
+			Kint::dump(EE_Registry::instance()->SSN->id());
107
+			Kint::dump(EE_Registry::instance()->SSN);
108
+			//          Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() );
109
+			$this->espresso_list_hooked_functions();
110
+			Benchmark::displayResults();
111
+		}
112
+	}
113
+
114
+
115
+
116
+	/**
117
+	 *    List All Hooked Functions
118
+	 *    to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL
119
+	 *    http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/
120
+	 *
121
+	 * @param string $tag
122
+	 * @return void
123
+	 */
124
+	public function espresso_list_hooked_functions($tag = '')
125
+	{
126
+		global $wp_filter;
127
+		echo '<br/><br/><br/><h3>Hooked Functions</h3>';
128
+		if ($tag) {
129
+			$hook[ $tag ] = $wp_filter[ $tag ];
130
+			if (! is_array($hook[ $tag ])) {
131
+				trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
132
+				return;
133
+			}
134
+			echo '<h5>For Tag: ' . $tag . '</h5>';
135
+		} else {
136
+			$hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
137
+			ksort($hook);
138
+		}
139
+		foreach ($hook as $tag_name => $priorities) {
140
+			echo "<br />&gt;&gt;&gt;&gt;&gt;\t<strong>$tag_name</strong><br />";
141
+			ksort($priorities);
142
+			foreach ($priorities as $priority => $function) {
143
+				echo $priority;
144
+				foreach ($function as $name => $properties) {
145
+					echo "\t$name<br />";
146
+				}
147
+			}
148
+		}
149
+	}
150
+
151
+
152
+
153
+	/**
154
+	 *    registered_filter_callbacks
155
+	 *
156
+	 * @param string $hook_name
157
+	 * @return array
158
+	 */
159
+	public static function registered_filter_callbacks($hook_name = '')
160
+	{
161
+		$filters = array();
162
+		global $wp_filter;
163
+		if (isset($wp_filter[ $hook_name ])) {
164
+			$filters[ $hook_name ] = array();
165
+			foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) {
166
+				$filters[ $hook_name ][ $priority ] = array();
167
+				foreach ($callbacks as $callback) {
168
+					$filters[ $hook_name ][ $priority ][] = $callback['function'];
169
+				}
170
+			}
171
+		}
172
+		return $filters;
173
+	}
174
+
175
+
176
+
177
+	/**
178
+	 *    captures plugin activation errors for debugging
179
+	 *
180
+	 * @return void
181
+	 * @throws EE_Error
182
+	 */
183
+	public static function ee_plugin_activation_errors()
184
+	{
185
+		if (WP_DEBUG) {
186
+			$activation_errors = ob_get_contents();
187
+			if (empty($activation_errors)) {
188
+				return;
189
+			}
190
+			$activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
191
+			espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
192
+			if (class_exists('EEH_File')) {
193
+				try {
194
+					EEH_File::ensure_file_exists_and_is_writable(
195
+						EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html'
196
+					);
197
+					EEH_File::write_to_file(
198
+						EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html',
199
+						$activation_errors
200
+					);
201
+				} catch (EE_Error $e) {
202
+					EE_Error::add_error(
203
+						sprintf(
204
+							__(
205
+								'The Event Espresso activation errors file could not be setup because: %s',
206
+								'event_espresso'
207
+							),
208
+							$e->getMessage()
209
+						),
210
+						__FILE__,
211
+						__FUNCTION__,
212
+						__LINE__
213
+					);
214
+				}
215
+			} else {
216
+				// old school attempt
217
+				file_put_contents(
218
+					EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html',
219
+					$activation_errors
220
+				);
221
+			}
222
+			$activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
223
+			update_option('ee_plugin_activation_errors', $activation_errors);
224
+		}
225
+	}
226
+
227
+
228
+
229
+	/**
230
+	 * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc.
231
+	 * Very useful for providing helpful messages to developers when the method of doing something has been deprecated,
232
+	 * or we want to make sure they use something the right way.
233
+	 *
234
+	 * @access public
235
+	 * @param string $function      The function that was called
236
+	 * @param string $message       A message explaining what has been done incorrectly
237
+	 * @param string $version       The version of Event Espresso where the error was added
238
+	 * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
239
+	 *                              for a deprecated function. This allows deprecation to occur during one version,
240
+	 *                              but not have any notices appear until a later version. This allows developers
241
+	 *                              extra time to update their code before notices appear.
242
+	 * @param int    $error_type
243
+	 * @uses   trigger_error()
244
+	 */
245
+	public function doing_it_wrong(
246
+		$function,
247
+		$message,
248
+		$version,
249
+		$applies_when = '',
250
+		$error_type = null
251
+	) {
252
+		$applies_when = ! empty($applies_when) ? $applies_when : espresso_version();
253
+		$error_type = $error_type !== null ? $error_type : E_USER_NOTICE;
254
+		// because we swapped the parameter order around for the last two params,
255
+		// let's verify that some third party isn't still passing an error type value for the third param
256
+		if (is_int($applies_when)) {
257
+			$error_type = $applies_when;
258
+			$applies_when = espresso_version();
259
+		}
260
+		// if not displaying notices yet, then just leave
261
+		if (version_compare(espresso_version(), $applies_when, '<')) {
262
+			return;
263
+		}
264
+		do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version);
265
+		$version = $version === null
266
+			? ''
267
+			: sprintf(
268
+				__('(This message was added in version %s of Event Espresso)', 'event_espresso'),
269
+				$version
270
+			);
271
+		$error_message = sprintf(
272
+			esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'),
273
+			$function,
274
+			'<strong>',
275
+			'</strong>',
276
+			$message,
277
+			$version
278
+		);
279
+		// don't trigger error if doing ajax,
280
+		// instead we'll add a transient EE_Error notice that in theory should show on the next request.
281
+		if (defined('DOING_AJAX') && DOING_AJAX) {
282
+			$error_message .= ' ' . esc_html__(
283
+				'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
284
+				'event_espresso'
285
+			);
286
+			$error_message .= '<ul><li>';
287
+			$error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params());
288
+			$error_message .= '</ul>';
289
+			EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42');
290
+			// now we set this on the transient so it shows up on the next request.
291
+			EE_Error::get_notices(false, true);
292
+		} else {
293
+			trigger_error($error_message, $error_type);
294
+		}
295
+	}
296
+
297
+
298
+
299
+
300
+	/**
301
+	 * Logger helpers
302
+	 */
303
+	/**
304
+	 * debug
305
+	 *
306
+	 * @param string $class
307
+	 * @param string $func
308
+	 * @param string $line
309
+	 * @param array  $info
310
+	 * @param bool   $display_request
311
+	 * @param string $debug_index
312
+	 * @param string $debug_key
313
+	 * @throws EE_Error
314
+	 * @throws \EventEspresso\core\exceptions\InvalidSessionDataException
315
+	 */
316
+	public static function log(
317
+		$class = '',
318
+		$func = '',
319
+		$line = '',
320
+		$info = array(),
321
+		$display_request = false,
322
+		$debug_index = '',
323
+		$debug_key = 'EE_DEBUG_SPCO'
324
+	) {
325
+		if (WP_DEBUG) {
326
+			$debug_key = $debug_key . '_' . EE_Session::instance()->id();
327
+			$debug_data = get_option($debug_key, array());
328
+			$default_data = array(
329
+				$class => $func . '() : ' . $line,
330
+				'REQ'  => $display_request ? $_REQUEST : '',
331
+			);
332
+			// don't serialize objects
333
+			$info = self::strip_objects($info);
334
+			$index = ! empty($debug_index) ? $debug_index : 0;
335
+			if (! isset($debug_data[ $index ])) {
336
+				$debug_data[ $index ] = array();
337
+			}
338
+			$debug_data[ $index ][ microtime() ] = array_merge($default_data, $info);
339
+			update_option($debug_key, $debug_data);
340
+		}
341
+	}
342
+
343
+
344
+
345
+	/**
346
+	 * strip_objects
347
+	 *
348
+	 * @param array $info
349
+	 * @return array
350
+	 */
351
+	public static function strip_objects($info = array())
352
+	{
353
+		foreach ($info as $key => $value) {
354
+			if (is_array($value)) {
355
+				$info[ $key ] = self::strip_objects($value);
356
+			} elseif (is_object($value)) {
357
+				$object_class = get_class($value);
358
+				$info[ $object_class ] = array();
359
+				$info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
360
+				if (method_exists($value, 'ID')) {
361
+					$info[ $object_class ]['ID'] = $value->ID();
362
+				}
363
+				if (method_exists($value, 'status')) {
364
+					$info[ $object_class ]['status'] = $value->status();
365
+				} elseif (method_exists($value, 'status_ID')) {
366
+					$info[ $object_class ]['status'] = $value->status_ID();
367
+				}
368
+				unset($info[ $key ]);
369
+			}
370
+		}
371
+		return (array) $info;
372
+	}
373
+
374
+
375
+
376
+	/**
377
+	 * @param mixed      $var
378
+	 * @param string     $var_name
379
+	 * @param string     $file
380
+	 * @param int|string $line
381
+	 * @param int|string $heading_tag
382
+	 * @param bool       $die
383
+	 * @param string     $margin
384
+	 */
385
+	public static function printv(
386
+		$var,
387
+		$var_name = '',
388
+		$file = '',
389
+		$line = '',
390
+		$heading_tag = 5,
391
+		$die = false,
392
+		$margin = ''
393
+	) {
394
+		$var_name = ! $var_name ? 'string' : $var_name;
395
+		$var_name = ucwords(str_replace('$', '', $var_name));
396
+		$is_method = method_exists($var_name, $var);
397
+		$var_name = ucwords(str_replace('_', ' ', $var_name));
398
+		$heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
399
+		// $result = EEH_Debug_Tools::headingSpacer($heading_tag);
400
+		$result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
401
+		$result .= $is_method
402
+			? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
403
+			: EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
404
+		$result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
405
+		$result .= EEH_Debug_Tools::headingX($heading_tag);
406
+		if ($die) {
407
+			die($result);
408
+		}
409
+		echo $result;
410
+	}
411
+
412
+
413
+	protected static function headingTag($heading_tag)
414
+	{
415
+		$heading_tag = absint($heading_tag);
416
+		return $heading_tag > 0 && $heading_tag < 7 ? "h{$heading_tag}" : 'h5';
417
+	}
418
+
419
+
420
+	protected static function headingSpacer($heading_tag)
421
+	{
422
+		return EEH_Debug_Tools::plainOutput() && ($heading_tag === 'h1' || $heading_tag === 'h2')
423
+			? "\n"
424
+			: '';
425
+	}
426
+
427
+
428
+	protected static function plainOutput()
429
+	{
430
+		return defined('EE_TESTS_DIR')
431
+			   || (defined('DOING_AJAX') && DOING_AJAX && ! isset($_REQUEST['pretty_output']))
432
+			   || (
433
+				   isset($_SERVER['REQUEST_URI'])
434
+				   && strpos(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), 'wp-json') !== false
435
+			   );
436
+	}
437
+
438
+
439
+	/**
440
+	 * @param string $var_name
441
+	 * @param string $heading_tag
442
+	 * @param string $margin
443
+	 * @param int    $line
444
+	 * @return string
445
+	 */
446
+	protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '', $line = 0)
447
+	{
448
+		if (EEH_Debug_Tools::plainOutput()) {
449
+			switch ($heading_tag) {
450
+				case 'h1':
451
+					$line_breaks = EEH_Debug_Tools::lineBreak(3);
452
+					break;
453
+				case 'h2':
454
+					$line_breaks = EEH_Debug_Tools::lineBreak(2);
455
+					break;
456
+				default:
457
+					$line_breaks = EEH_Debug_Tools::lineBreak();
458
+					break;
459
+			}
460
+			return "{$line_breaks}{$line}) {$var_name}";
461
+		}
462
+		$margin = "25px 0 0 {$margin}";
463
+		return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
464
+	}
465
+
466
+
467
+
468
+	/**
469
+	 * @param string $heading_tag
470
+	 * @return string
471
+	 */
472
+	protected static function headingX($heading_tag = 'h5')
473
+	{
474
+		if (EEH_Debug_Tools::plainOutput()) {
475
+			return '';
476
+		}
477
+		return '</' . $heading_tag . '>';
478
+	}
479
+
480
+
481
+
482
+	/**
483
+	 * @param string $content
484
+	 * @return string
485
+	 */
486
+	protected static function grey_span($content = '')
487
+	{
488
+		if (EEH_Debug_Tools::plainOutput()) {
489
+			return $content;
490
+		}
491
+		return '<span style="color:#999">' . $content . '</span>';
492
+	}
493
+
494
+
495
+
496
+	/**
497
+	 * @param string $file
498
+	 * @param int    $line
499
+	 * @return string
500
+	 */
501
+	protected static function file_and_line($file, $line, $heading_tag)
502
+	{
503
+		if ($file === '' || $line === '') {
504
+			return '';
505
+		}
506
+		$file = str_replace(EE_PLUGIN_DIR_PATH, '/', $file);
507
+		if (EEH_Debug_Tools::plainOutput()) {
508
+			if ($heading_tag === 'h1' || $heading_tag === 'h2') {
509
+				return " ({$file})";
510
+			}
511
+			return '';
512
+		}
513
+		return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'
514
+			   . $file
515
+			   . '<br />line no: '
516
+			   . $line
517
+			   . '</span>';
518
+	}
519
+
520
+
521
+
522
+	/**
523
+	 * @param string $content
524
+	 * @return string
525
+	 */
526
+	protected static function orange_span($content = '')
527
+	{
528
+		if (EEH_Debug_Tools::plainOutput()) {
529
+			return $content;
530
+		}
531
+		return '<span style="color:#E76700">' . $content . '</span>';
532
+	}
533
+
534
+
535
+
536
+	/**
537
+	 * @param mixed $var
538
+	 * @return string
539
+	 */
540
+	protected static function pre_span($var)
541
+	{
542
+		ob_start();
543
+		var_dump($var);
544
+		$var = ob_get_clean();
545
+		if (EEH_Debug_Tools::plainOutput()) {
546
+			return $var;
547
+		}
548
+		return '<pre style="color: #9C3; display: inline-block; padding:.4em .6em; background: #334">' . $var . '</pre>';
549
+	}
550
+
551
+
552
+
553
+	/**
554
+	 * @param mixed      $var
555
+	 * @param string     $var_name
556
+	 * @param string     $file
557
+	 * @param int|string $line
558
+	 * @param int|string $heading_tag
559
+	 * @param bool       $die
560
+	 */
561
+	public static function printr(
562
+		$var,
563
+		$var_name = '',
564
+		$file = '',
565
+		$line = '',
566
+		$heading_tag = 5,
567
+		$die = false
568
+	) {
569
+		// return;
570
+		$file = str_replace(rtrim(ABSPATH, '\\/'), '', $file);
571
+		if (empty($var) && empty($var_name)) {
572
+			$var = $file;
573
+			$var_name = "line $line";
574
+			$file = '';
575
+			$line = '';
576
+		}
577
+		$margin = is_admin() ? ' 180px' : '0';
578
+		// $print_r = false;
579
+		if (is_string($var)) {
580
+			EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin);
581
+			return;
582
+		}
583
+		if (is_object($var)) {
584
+			$var_name = ! $var_name ? 'object' : $var_name;
585
+			// $print_r = true;
586
+		} elseif (is_array($var)) {
587
+			$var_name = ! $var_name ? 'array' : $var_name;
588
+			// $print_r = true;
589
+		} elseif (is_numeric($var)) {
590
+			$var_name = ! $var_name ? 'numeric' : $var_name;
591
+		} elseif ($var === null) {
592
+			$var_name = ! $var_name ? 'null' : $var_name;
593
+		}
594
+		$var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name));
595
+		$heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
596
+		// $result = EEH_Debug_Tools::headingSpacer($heading_tag);
597
+		$result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
598
+		$result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
599
+			EEH_Debug_Tools::pre_span($var)
600
+		);
601
+		$result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
602
+		$result .= EEH_Debug_Tools::headingX($heading_tag);
603
+		if ($die) {
604
+			die($result);
605
+		}
606
+		echo $result;
607
+	}
608
+
609
+
610
+	private static function lineBreak($lines = 1): string
611
+	{
612
+		$linebreak = defined('DOING_AJAX') && DOING_AJAX ? '<br />' : PHP_EOL;
613
+		return str_repeat($linebreak, $lines);
614
+	}
615
+
616
+
617
+
618
+	/******************** deprecated ********************/
619
+
620
+
621
+
622
+	/**
623
+	 * @deprecated 4.9.39.rc.034
624
+	 */
625
+	public function reset_times()
626
+	{
627
+		Benchmark::resetTimes();
628
+	}
629
+
630
+
631
+
632
+	/**
633
+	 * @deprecated 4.9.39.rc.034
634
+	 * @param null $timer_name
635
+	 */
636
+	public function start_timer($timer_name = null)
637
+	{
638
+		Benchmark::startTimer($timer_name);
639
+	}
640
+
641
+
642
+
643
+	/**
644
+	 * @deprecated 4.9.39.rc.034
645
+	 * @param string $timer_name
646
+	 */
647
+	public function stop_timer($timer_name = '')
648
+	{
649
+		Benchmark::stopTimer($timer_name);
650
+	}
651
+
652
+
653
+
654
+	/**
655
+	 * @deprecated 4.9.39.rc.034
656
+	 * @param string  $label      The label to show for this time eg "Start of calling Some_Class::some_function"
657
+	 * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called
658
+	 * @return void
659
+	 */
660
+	public function measure_memory($label, $output_now = false)
661
+	{
662
+		Benchmark::measureMemory($label, $output_now);
663
+	}
664
+
665
+
666
+
667
+	/**
668
+	 * @deprecated 4.9.39.rc.034
669
+	 * @param int $size
670
+	 * @return string
671
+	 */
672
+	public function convert($size)
673
+	{
674
+		return Benchmark::convert($size);
675
+	}
676
+
677
+
678
+
679
+	/**
680
+	 * @deprecated 4.9.39.rc.034
681
+	 * @param bool $output_now
682
+	 * @return string
683
+	 */
684
+	public function show_times($output_now = true)
685
+	{
686
+		return Benchmark::displayResults($output_now);
687
+	}
688
+
689
+
690
+
691
+	/**
692
+	 * @deprecated 4.9.39.rc.034
693
+	 * @param string $timer_name
694
+	 * @param float  $total_time
695
+	 * @return string
696
+	 */
697
+	public function format_time($timer_name, $total_time)
698
+	{
699
+		return Benchmark::formatTime($timer_name, $total_time);
700
+	}
701 701
 }
702 702
 
703 703
 
@@ -707,31 +707,31 @@  discard block
 block discarded – undo
707 707
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
708 708
  */
709 709
 if (class_exists('Kint') && ! function_exists('dump_wp_query')) {
710
-    function dump_wp_query()
711
-    {
712
-        global $wp_query;
713
-        d($wp_query);
714
-    }
710
+	function dump_wp_query()
711
+	{
712
+		global $wp_query;
713
+		d($wp_query);
714
+	}
715 715
 }
716 716
 /**
717 717
  * borrowed from Kint Debugger
718 718
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
719 719
  */
720 720
 if (class_exists('Kint') && ! function_exists('dump_wp')) {
721
-    function dump_wp()
722
-    {
723
-        global $wp;
724
-        d($wp);
725
-    }
721
+	function dump_wp()
722
+	{
723
+		global $wp;
724
+		d($wp);
725
+	}
726 726
 }
727 727
 /**
728 728
  * borrowed from Kint Debugger
729 729
  * Plugin URI: http://upthemes.com/plugins/kint-debugger/
730 730
  */
731 731
 if (class_exists('Kint') && ! function_exists('dump_post')) {
732
-    function dump_post()
733
-    {
734
-        global $post;
735
-        d($post);
736
-    }
732
+	function dump_post()
733
+	{
734
+		global $post;
735
+		d($post);
736
+	}
737 737
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
     public static function instance()
37 37
     {
38 38
         // check if class object is instantiated, and instantiated properly
39
-        if (! self::$_instance instanceof EEH_Debug_Tools) {
39
+        if ( ! self::$_instance instanceof EEH_Debug_Tools) {
40 40
             self::$_instance = new self();
41 41
         }
42 42
         return self::$_instance;
@@ -50,13 +50,13 @@  discard block
 block discarded – undo
50 50
     private function __construct()
51 51
     {
52 52
         // load Kint PHP debugging library
53
-        if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php')) {
53
+        if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests/kint/Kint.class.php')) {
54 54
             // despite EE4 having a check for an existing copy of the Kint debugging class,
55 55
             // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check,
56 56
             // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error
57 57
             // so we've moved it to our test folder so that it is not included with production releases
58 58
             // plz use https://wordpress.org/plugins/kint-debugger/  if testing production versions of EE
59
-            require_once(EE_PLUGIN_DIR_PATH . 'tests/kint/Kint.class.php');
59
+            require_once(EE_PLUGIN_DIR_PATH.'tests/kint/Kint.class.php');
60 60
         }
61 61
         // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) {
62 62
         // add_action( 'shutdown', array($this,'espresso_session_footer_dump') );
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      */
77 77
     public static function show_db_name()
78 78
     {
79
-        if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
79
+        if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) {
80 80
             echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '
81 81
                  . DB_NAME
82 82
                  . '</p>';
@@ -126,12 +126,12 @@  discard block
 block discarded – undo
126 126
         global $wp_filter;
127 127
         echo '<br/><br/><br/><h3>Hooked Functions</h3>';
128 128
         if ($tag) {
129
-            $hook[ $tag ] = $wp_filter[ $tag ];
130
-            if (! is_array($hook[ $tag ])) {
129
+            $hook[$tag] = $wp_filter[$tag];
130
+            if ( ! is_array($hook[$tag])) {
131 131
                 trigger_error("Nothing found for '$tag' hook", E_USER_WARNING);
132 132
                 return;
133 133
             }
134
-            echo '<h5>For Tag: ' . $tag . '</h5>';
134
+            echo '<h5>For Tag: '.$tag.'</h5>';
135 135
         } else {
136 136
             $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter);
137 137
             ksort($hook);
@@ -160,12 +160,12 @@  discard block
 block discarded – undo
160 160
     {
161 161
         $filters = array();
162 162
         global $wp_filter;
163
-        if (isset($wp_filter[ $hook_name ])) {
164
-            $filters[ $hook_name ] = array();
165
-            foreach ($wp_filter[ $hook_name ] as $priority => $callbacks) {
166
-                $filters[ $hook_name ][ $priority ] = array();
163
+        if (isset($wp_filter[$hook_name])) {
164
+            $filters[$hook_name] = array();
165
+            foreach ($wp_filter[$hook_name] as $priority => $callbacks) {
166
+                $filters[$hook_name][$priority] = array();
167 167
                 foreach ($callbacks as $callback) {
168
-                    $filters[ $hook_name ][ $priority ][] = $callback['function'];
168
+                    $filters[$hook_name][$priority][] = $callback['function'];
169 169
                 }
170 170
             }
171 171
         }
@@ -187,15 +187,15 @@  discard block
 block discarded – undo
187 187
             if (empty($activation_errors)) {
188 188
                 return;
189 189
             }
190
-            $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors;
191
-            espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php');
190
+            $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors;
191
+            espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php');
192 192
             if (class_exists('EEH_File')) {
193 193
                 try {
194 194
                     EEH_File::ensure_file_exists_and_is_writable(
195
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html'
195
+                        EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html'
196 196
                     );
197 197
                     EEH_File::write_to_file(
198
-                        EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html',
198
+                        EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html',
199 199
                         $activation_errors
200 200
                     );
201 201
                 } catch (EE_Error $e) {
@@ -215,11 +215,11 @@  discard block
 block discarded – undo
215 215
             } else {
216 216
                 // old school attempt
217 217
                 file_put_contents(
218
-                    EVENT_ESPRESSO_UPLOAD_DIR . 'logs/espresso_plugin_activation_errors.html',
218
+                    EVENT_ESPRESSO_UPLOAD_DIR.'logs/espresso_plugin_activation_errors.html',
219 219
                     $activation_errors
220 220
                 );
221 221
             }
222
-            $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors;
222
+            $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors;
223 223
             update_option('ee_plugin_activation_errors', $activation_errors);
224 224
         }
225 225
     }
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
         // don't trigger error if doing ajax,
280 280
         // instead we'll add a transient EE_Error notice that in theory should show on the next request.
281 281
         if (defined('DOING_AJAX') && DOING_AJAX) {
282
-            $error_message .= ' ' . esc_html__(
282
+            $error_message .= ' '.esc_html__(
283 283
                 'This is a doing_it_wrong message that was triggered during an ajax request.  The request params on this request were: ',
284 284
                 'event_espresso'
285 285
             );
@@ -323,19 +323,19 @@  discard block
 block discarded – undo
323 323
         $debug_key = 'EE_DEBUG_SPCO'
324 324
     ) {
325 325
         if (WP_DEBUG) {
326
-            $debug_key = $debug_key . '_' . EE_Session::instance()->id();
326
+            $debug_key = $debug_key.'_'.EE_Session::instance()->id();
327 327
             $debug_data = get_option($debug_key, array());
328 328
             $default_data = array(
329
-                $class => $func . '() : ' . $line,
329
+                $class => $func.'() : '.$line,
330 330
                 'REQ'  => $display_request ? $_REQUEST : '',
331 331
             );
332 332
             // don't serialize objects
333 333
             $info = self::strip_objects($info);
334 334
             $index = ! empty($debug_index) ? $debug_index : 0;
335
-            if (! isset($debug_data[ $index ])) {
336
-                $debug_data[ $index ] = array();
335
+            if ( ! isset($debug_data[$index])) {
336
+                $debug_data[$index] = array();
337 337
             }
338
-            $debug_data[ $index ][ microtime() ] = array_merge($default_data, $info);
338
+            $debug_data[$index][microtime()] = array_merge($default_data, $info);
339 339
             update_option($debug_key, $debug_data);
340 340
         }
341 341
     }
@@ -352,20 +352,20 @@  discard block
 block discarded – undo
352 352
     {
353 353
         foreach ($info as $key => $value) {
354 354
             if (is_array($value)) {
355
-                $info[ $key ] = self::strip_objects($value);
355
+                $info[$key] = self::strip_objects($value);
356 356
             } elseif (is_object($value)) {
357 357
                 $object_class = get_class($value);
358
-                $info[ $object_class ] = array();
359
-                $info[ $object_class ]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
358
+                $info[$object_class] = array();
359
+                $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value);
360 360
                 if (method_exists($value, 'ID')) {
361
-                    $info[ $object_class ]['ID'] = $value->ID();
361
+                    $info[$object_class]['ID'] = $value->ID();
362 362
                 }
363 363
                 if (method_exists($value, 'status')) {
364
-                    $info[ $object_class ]['status'] = $value->status();
364
+                    $info[$object_class]['status'] = $value->status();
365 365
                 } elseif (method_exists($value, 'status_ID')) {
366
-                    $info[ $object_class ]['status'] = $value->status_ID();
366
+                    $info[$object_class]['status'] = $value->status_ID();
367 367
                 }
368
-                unset($info[ $key ]);
368
+                unset($info[$key]);
369 369
             }
370 370
         }
371 371
         return (array) $info;
@@ -399,8 +399,8 @@  discard block
 block discarded – undo
399 399
         // $result = EEH_Debug_Tools::headingSpacer($heading_tag);
400 400
         $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
401 401
         $result .= $is_method
402
-            ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()')
403
-            : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var);
402
+            ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()')
403
+            : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var);
404 404
         $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
405 405
         $result .= EEH_Debug_Tools::headingX($heading_tag);
406 406
         if ($die) {
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
             return "{$line_breaks}{$line}) {$var_name}";
461 461
         }
462 462
         $margin = "25px 0 0 {$margin}";
463
-        return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>';
463
+        return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>';
464 464
     }
465 465
 
466 466
 
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
         if (EEH_Debug_Tools::plainOutput()) {
475 475
             return '';
476 476
         }
477
-        return '</' . $heading_tag . '>';
477
+        return '</'.$heading_tag.'>';
478 478
     }
479 479
 
480 480
 
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
         if (EEH_Debug_Tools::plainOutput()) {
489 489
             return $content;
490 490
         }
491
-        return '<span style="color:#999">' . $content . '</span>';
491
+        return '<span style="color:#999">'.$content.'</span>';
492 492
     }
493 493
 
494 494
 
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
         if (EEH_Debug_Tools::plainOutput()) {
529 529
             return $content;
530 530
         }
531
-        return '<span style="color:#E76700">' . $content . '</span>';
531
+        return '<span style="color:#E76700">'.$content.'</span>';
532 532
     }
533 533
 
534 534
 
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
         if (EEH_Debug_Tools::plainOutput()) {
546 546
             return $var;
547 547
         }
548
-        return '<pre style="color: #9C3; display: inline-block; padding:.4em .6em; background: #334">' . $var . '</pre>';
548
+        return '<pre style="color: #9C3; display: inline-block; padding:.4em .6em; background: #334">'.$var.'</pre>';
549 549
     }
550 550
 
551 551
 
@@ -595,7 +595,7 @@  discard block
 block discarded – undo
595 595
         $heading_tag = EEH_Debug_Tools::headingTag($heading_tag);
596 596
         // $result = EEH_Debug_Tools::headingSpacer($heading_tag);
597 597
         $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin, $line);
598
-        $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span(
598
+        $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span(
599 599
             EEH_Debug_Tools::pre_span($var)
600 600
         );
601 601
         $result .= EEH_Debug_Tools::file_and_line($file, $line, $heading_tag);
Please login to merge, or discard this patch.
core/services/orm/tree_traversal/NodeGroupDao.php 2 patches
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -22,123 +22,123 @@
 block discarded – undo
22 22
  */
23 23
 class NodeGroupDao
24 24
 {
25
-    /**
26
-     * @return mixed|void
27
-     */
28
-    public function generateGroupCode()
29
-    {
30
-        return wp_generate_password(6, false);
31
-    }
25
+	/**
26
+	 * @return mixed|void
27
+	 */
28
+	public function generateGroupCode()
29
+	{
30
+		return wp_generate_password(6, false);
31
+	}
32 32
 
33 33
 
34
-    /**
35
-     * Gets the string we put in front of the WP Option name used to store the jobs.
36
-     *
37
-     * @return string
38
-     */
39
-    private function getOptionPrefix()
40
-    {
41
-        return 'ee_deletion_';
42
-    }
34
+	/**
35
+	 * Gets the string we put in front of the WP Option name used to store the jobs.
36
+	 *
37
+	 * @return string
38
+	 */
39
+	private function getOptionPrefix()
40
+	{
41
+		return 'ee_deletion_';
42
+	}
43 43
 
44 44
 
45
-    /**
46
-     * @param $code
47
-     * @return ModelObjNode[]
48
-     * @throws UnexpectedEntityException
49
-     * @throws Exception
50
-     */
51
-    public function getModelObjNodesInGroup($code)
52
-    {
53
-        if (! $code) {
54
-            throw new Exception(
55
-                esc_html__(
56
-                    'We aren’t sure which job you are performing. Please press back in your browser and try again.',
57
-                    'event_espresso'
58
-                )
59
-            );
60
-        }
61
-        $deletion_data = get_option($this->getOptionPrefix() . $code, []);
62
-        foreach ($deletion_data as $root) {
63
-            if (! $root instanceof ModelObjNode) {
64
-                throw new UnexpectedEntityException($root, 'ModelObjNode');
65
-            }
66
-        }
67
-        return $deletion_data;
68
-    }
45
+	/**
46
+	 * @param $code
47
+	 * @return ModelObjNode[]
48
+	 * @throws UnexpectedEntityException
49
+	 * @throws Exception
50
+	 */
51
+	public function getModelObjNodesInGroup($code)
52
+	{
53
+		if (! $code) {
54
+			throw new Exception(
55
+				esc_html__(
56
+					'We aren’t sure which job you are performing. Please press back in your browser and try again.',
57
+					'event_espresso'
58
+				)
59
+			);
60
+		}
61
+		$deletion_data = get_option($this->getOptionPrefix() . $code, []);
62
+		foreach ($deletion_data as $root) {
63
+			if (! $root instanceof ModelObjNode) {
64
+				throw new UnexpectedEntityException($root, 'ModelObjNode');
65
+			}
66
+		}
67
+		return $deletion_data;
68
+	}
69 69
 
70 70
 
71
-    /**
72
-     * Gets an array indicating what database rows are contained in the job.
73
-     * Each top-level key is a model name, and its value is an array of IDs.
74
-     *
75
-     * @param ModelObjNode[] $model_obj_nodes
76
-     * @return array
77
-     * @throws EE_Error
78
-     * @throws InvalidDataTypeException
79
-     * @throws InvalidInterfaceException
80
-     * @throws InvalidArgumentException
81
-     * @throws ReflectionException
82
-     */
83
-    public function getModelsAndIdsContainedIn(array $model_obj_nodes)
84
-    {
85
-        $models_and_ids_to_delete = [];
86
-        foreach ($model_obj_nodes as $root) {
87
-            $models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds());
88
-        }
89
-        return $models_and_ids_to_delete;
90
-    }
71
+	/**
72
+	 * Gets an array indicating what database rows are contained in the job.
73
+	 * Each top-level key is a model name, and its value is an array of IDs.
74
+	 *
75
+	 * @param ModelObjNode[] $model_obj_nodes
76
+	 * @return array
77
+	 * @throws EE_Error
78
+	 * @throws InvalidDataTypeException
79
+	 * @throws InvalidInterfaceException
80
+	 * @throws InvalidArgumentException
81
+	 * @throws ReflectionException
82
+	 */
83
+	public function getModelsAndIdsContainedIn(array $model_obj_nodes)
84
+	{
85
+		$models_and_ids_to_delete = [];
86
+		foreach ($model_obj_nodes as $root) {
87
+			$models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds());
88
+		}
89
+		return $models_and_ids_to_delete;
90
+	}
91 91
 
92 92
 
93
-    /**
94
-     * Gets an array indicating what database rows are contained in the job.
95
-     * Each top-level key is a model name, and its value is an array of IDs.
96
-     *
97
-     * @param string $code
98
-     * @return array
99
-     * @throws EE_Error
100
-     * @throws InvalidArgumentException
101
-     * @throws InvalidDataTypeException
102
-     * @throws InvalidInterfaceException
103
-     * @throws ReflectionException
104
-     * @throws UnexpectedEntityException
105
-     * @throws Exception
106
-     */
107
-    public function getModelsAndIdsFromGroup($code)
108
-    {
109
-        $model_obj_nodes = $this->getModelObjNodesInGroup($code);
110
-        return $this->getModelsAndIdsContainedIn($model_obj_nodes);
111
-    }
93
+	/**
94
+	 * Gets an array indicating what database rows are contained in the job.
95
+	 * Each top-level key is a model name, and its value is an array of IDs.
96
+	 *
97
+	 * @param string $code
98
+	 * @return array
99
+	 * @throws EE_Error
100
+	 * @throws InvalidArgumentException
101
+	 * @throws InvalidDataTypeException
102
+	 * @throws InvalidInterfaceException
103
+	 * @throws ReflectionException
104
+	 * @throws UnexpectedEntityException
105
+	 * @throws Exception
106
+	 */
107
+	public function getModelsAndIdsFromGroup($code)
108
+	{
109
+		$model_obj_nodes = $this->getModelObjNodesInGroup($code);
110
+		return $this->getModelsAndIdsContainedIn($model_obj_nodes);
111
+	}
112 112
 
113 113
 
114
-    /**
115
-     * Persists the ModelObjNodes for future requests, using the code for reference.
116
-     *
117
-     * @param ModelObjNode[] $model_obj_nodes
118
-     * @param string         $code
119
-     * @return bool
120
-     */
121
-    public function persistModelObjNodesGroup(array $model_obj_nodes, $code)
122
-    {
123
-        return add_option(
124
-            $this->getOptionPrefix() . $code,
125
-            $model_obj_nodes,
126
-            null,
127
-            'no'
128
-        );
129
-    }
114
+	/**
115
+	 * Persists the ModelObjNodes for future requests, using the code for reference.
116
+	 *
117
+	 * @param ModelObjNode[] $model_obj_nodes
118
+	 * @param string         $code
119
+	 * @return bool
120
+	 */
121
+	public function persistModelObjNodesGroup(array $model_obj_nodes, $code)
122
+	{
123
+		return add_option(
124
+			$this->getOptionPrefix() . $code,
125
+			$model_obj_nodes,
126
+			null,
127
+			'no'
128
+		);
129
+	}
130 130
 
131 131
 
132
-    /**
133
-     * Forgets about the group of ModelObjNodes. Doesn't delete the rows in the database they reference though.
134
-     *
135
-     * @param $code
136
-     * @return bool
137
-     */
138
-    public function deleteModelObjNodesInGroup($code)
139
-    {
140
-        return delete_option($this->getOptionPrefix() . $code);
141
-    }
132
+	/**
133
+	 * Forgets about the group of ModelObjNodes. Doesn't delete the rows in the database they reference though.
134
+	 *
135
+	 * @param $code
136
+	 * @return bool
137
+	 */
138
+	public function deleteModelObjNodesInGroup($code)
139
+	{
140
+		return delete_option($this->getOptionPrefix() . $code);
141
+	}
142 142
 }
143 143
 // End of file NodeGroupDao.php
144 144
 // Location: EventEspresso\core\services\orm\tree_traversal/NodeGroupDao.php
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
      */
51 51
     public function getModelObjNodesInGroup($code)
52 52
     {
53
-        if (! $code) {
53
+        if ( ! $code) {
54 54
             throw new Exception(
55 55
                 esc_html__(
56 56
                     'We aren’t sure which job you are performing. Please press back in your browser and try again.',
@@ -58,9 +58,9 @@  discard block
 block discarded – undo
58 58
                 )
59 59
             );
60 60
         }
61
-        $deletion_data = get_option($this->getOptionPrefix() . $code, []);
61
+        $deletion_data = get_option($this->getOptionPrefix().$code, []);
62 62
         foreach ($deletion_data as $root) {
63
-            if (! $root instanceof ModelObjNode) {
63
+            if ( ! $root instanceof ModelObjNode) {
64 64
                 throw new UnexpectedEntityException($root, 'ModelObjNode');
65 65
             }
66 66
         }
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
     public function persistModelObjNodesGroup(array $model_obj_nodes, $code)
122 122
     {
123 123
         return add_option(
124
-            $this->getOptionPrefix() . $code,
124
+            $this->getOptionPrefix().$code,
125 125
             $model_obj_nodes,
126 126
             null,
127 127
             'no'
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
      */
138 138
     public function deleteModelObjNodesInGroup($code)
139 139
     {
140
-        return delete_option($this->getOptionPrefix() . $code);
140
+        return delete_option($this->getOptionPrefix().$code);
141 141
     }
142 142
 }
143 143
 // End of file NodeGroupDao.php
Please login to merge, or discard this patch.